mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Implement auto youtube tool (#1594)
This commit is contained in:
parent
ecf8eeff53
commit
ccf2c3f34a
2 changed files with 20 additions and 12 deletions
|
|
@ -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 },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Reference in a new issue