diff --git a/src/LLMProviders/intentAnalyzer.ts b/src/LLMProviders/intentAnalyzer.ts index 4b0e83d0..45e5a3c1 100644 --- a/src/LLMProviders/intentAnalyzer.ts +++ b/src/LLMProviders/intentAnalyzer.ts @@ -1,3 +1,6 @@ +import ProjectManager from "@/LLMProviders/projectManager"; +import { isProjectMode } from "@/aiParams"; +import { createGetFileTreeTool } from "@/tools/FileTreeTools"; import { indexTool, localSearchTool, webSearchTool } from "@/tools/SearchTools"; import { getCurrentTimeTool, @@ -6,14 +9,11 @@ import { pomodoroTool, TimeInfo, } from "@/tools/TimeTools"; -import { createGetFileTreeTool } from "@/tools/FileTreeTools"; import { simpleYoutubeTranscriptionTool } from "@/tools/YoutubeTools"; import { ToolManager } from "@/tools/toolManager"; -import { extractChatHistory, extractYoutubeUrl } from "@/utils"; -import { BrevilabsClient } from "./brevilabsClient"; +import { extractAllYoutubeUrls, extractChatHistory } from "@/utils"; import { Vault } from "obsidian"; -import ProjectManager from "@/LLMProviders/projectManager"; -import { isProjectMode } from "@/aiParams"; +import { BrevilabsClient } from "./brevilabsClient"; // TODO: Add @index with explicit pdf files in chat context menu export const COPILOT_TOOL_NAMES = ["@vault", "@composer", "@websearch", "@youtube", "@pomodoro"]; @@ -144,15 +144,18 @@ export class IntentAnalyzer { }); } - // Handle @youtube command - if (message.includes("@youtube")) { - const youtubeUrl = extractYoutubeUrl(originalMessage); - if (youtubeUrl) { + // Auto-detect YouTube URLs (handles both @youtube command and auto-detection) + const youtubeUrls = extractAllYoutubeUrls(originalMessage); + for (const url of youtubeUrls) { + // Check if we already have a YouTube tool call for this URL + const hasYoutubeToolForUrl = processedToolCalls.some( + (tc) => tc.tool.name === simpleYoutubeTranscriptionTool.name && tc.args.url === url + ); + + if (!hasYoutubeToolForUrl) { processedToolCalls.push({ tool: simpleYoutubeTranscriptionTool, - args: { - url: youtubeUrl, - }, + args: { url }, }); } } diff --git a/src/utils.ts b/src/utils.ts index fced5072..ff9df432 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -477,6 +477,11 @@ export function extractYoutubeUrl(text: string): string | null { return match ? match[0] : null; } +export function extractAllYoutubeUrls(text: string): string[] { + const matches = text.matchAll(new RegExp(YOUTUBE_URL_REGEX, "g")); + return Array.from(matches, (match) => match[0]); +} + /** Proxy function to use in place of fetch() to bypass CORS restrictions. * It currently doesn't support streaming until this is implemented * https://forum.obsidian.md/t/support-streaming-the-request-and-requesturl-response-body/87381 */