diff options
| author | Adam Malczewski <[email protected]> | 2026-06-21 15:15:59 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-21 15:15:59 +0900 |
| commit | 6cfe0dc1df99c46407b0784576c3d4b0f1cb7349 (patch) | |
| tree | b9c3bb058037e9841e474b16034ca28316f42fb6 | |
| parent | 64823e68e8c6c3bc199f9cb82d97321c830687c3 (diff) | |
| download | dispatch-6cfe0dc1df99c46407b0784576c3d4b0f1cb7349.tar.gz dispatch-6cfe0dc1df99c46407b0784576c3d4b0f1cb7349.zip | |
refactor(tool-youtube-transcript): always save full transcript, fix description
- Always write the full transcript to /tmp/dispatch/youtube-transcribe/{video_id}.txt
(not just on truncation)
- Description no longer claims to return the full transcript; instead says
it returns transcript text (truncated if very long) and the full version is
always saved to the file path
| -rw-r--r-- | packages/tool-youtube-transcript/src/tool.test.ts | 27 | ||||
| -rw-r--r-- | packages/tool-youtube-transcript/src/tool.ts | 16 |
2 files changed, 34 insertions, 9 deletions
diff --git a/packages/tool-youtube-transcript/src/tool.test.ts b/packages/tool-youtube-transcript/src/tool.test.ts index 59d90fa..7cdfd0e 100644 --- a/packages/tool-youtube-transcript/src/tool.test.ts +++ b/packages/tool-youtube-transcript/src/tool.test.ts @@ -111,7 +111,7 @@ describe("youtube_transcript", () => { expect(spanOpen?.conversationId).toBe("conv-xyz"); }); - it("writes full transcript to /tmp/dispatch/{video_id}.txt when truncated", async () => { + it("writes full transcript to /tmp/dispatch/youtube-transcribe/{video_id}.txt when truncated", async () => { const longText = "x".repeat(60_000); const client = makeStubClient(async () => ({ status: "completed", @@ -130,10 +130,31 @@ describe("youtube_transcript", () => { }, }); const result = await tool.execute({ url: "https://youtu.be/vid5" }, stubCtx()); - expect(writtenPath).toBe("/tmp/dispatch/vid5.txt"); + expect(writtenPath).toBe("/tmp/dispatch/youtube-transcribe/vid5.txt"); expect(writtenContent).toContain("x".repeat(60_000)); - expect(result.content).toContain("/tmp/dispatch/vid5.txt"); + expect(result.content).toContain("/tmp/dispatch/youtube-transcribe/vid5.txt"); expect(result.content).toContain("use read_file to access it"); expect(result.content.length).toBeLessThan(writtenContent.length); }); + + it("writes transcript to file even when not truncated", async () => { + const client = makeStubClient(async () => ({ + status: "completed", + video_id: "vid6", + full_text: "short transcript", + segments: [{ text: "short transcript", start: 0, duration: 2 }], + })); + let writtenPath = ""; + let writtenContent = ""; + const tool = createYoutubeTranscriptTool({ + client, + writeFile: (path, content) => { + writtenPath = path; + writtenContent = content; + }, + }); + const result = await tool.execute({ url: "https://youtu.be/vid6" }, stubCtx()); + expect(writtenPath).toBe("/tmp/dispatch/youtube-transcribe/vid6.txt"); + expect(writtenContent).toBe(result.content); + }); }); diff --git a/packages/tool-youtube-transcript/src/tool.ts b/packages/tool-youtube-transcript/src/tool.ts index a47d693..a11f739 100644 --- a/packages/tool-youtube-transcript/src/tool.ts +++ b/packages/tool-youtube-transcript/src/tool.ts @@ -20,7 +20,7 @@ import { import { validateUrl } from "./validate.js"; const OUTPUT_CAP = 50_000; -const FULL_OUTPUT_DIR = "/tmp/dispatch"; +const FULL_OUTPUT_DIR = "/tmp/dispatch/youtube-transcribe"; export interface YoutubeTranscriptToolDeps { readonly client: TranscriptClient; @@ -33,8 +33,10 @@ const DESCRIPTION = "Fetch the transcript/subtitles for a YouTube video from the local transcriber " + "service. If the transcript has not been downloaded before, the video will be " + "queued for processing and the tool will return the estimated time when the " + - "transcript will be available. Once available, the tool returns the full " + - "transcript text and timestamped segments. Accepted URL formats: " + + "transcript will be available. Once available, the tool returns the transcript " + + "text and timestamped segments (truncated if very long). The full transcript " + + "is always saved to /tmp/dispatch/youtube-transcribe/{video_id}.txt — use " + + "read_file to access it. Accepted URL formats: " + "youtube.com/watch?v=, youtu.be/, youtube.com/embed/, youtube.com/shorts/"; /** @@ -91,13 +93,15 @@ export function createYoutubeTranscriptTool(deps: YoutubeTranscriptToolDeps): To } span.end(); - if (output.length > cap && videoId !== undefined) { + if (videoId !== undefined) { const filePath = `${FULL_OUTPUT_DIR}/${videoId}.txt`; try { writeFile(filePath, output); - return { content: truncateOutput(output, cap, filePath) }; } catch { - return { content: truncateOutput(output, cap) }; + // File write failed — continue with truncated output only. + } + if (output.length > cap) { + return { content: truncateOutput(output, cap, filePath) }; } } return { content: truncateOutput(output, cap) }; |
