diff options
| author | Adam Malczewski <[email protected]> | 2026-06-21 14:58:38 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-21 14:58:38 +0900 |
| commit | dfb3a61afa545b67b85dbefe6b217affd14c16a7 (patch) | |
| tree | fbe0d18323136cc19d971e18f0801428bcd2e4a7 /packages/tool-youtube-transcript/src/validate.ts | |
| parent | d56fe9cf64719bb330c17b2daee58c0bafa057c9 (diff) | |
| download | dispatch-dfb3a61afa545b67b85dbefe6b217affd14c16a7.tar.gz dispatch-dfb3a61afa545b67b85dbefe6b217affd14c16a7.zip | |
feat(tool-youtube-transcript): YouTube transcription tool
New standard tool extension backed by a self-hosted transcriber service
(http://100.102.55.49:41090, Tailscale, no API key). One tool
youtube_transcript — fetches transcripts for YouTube videos. Returns
completed (full text + timestamped segments), queued/processing (position
+ ETA + .youtube_subtitles_pending retry convention), or failed (error).
Pure core: validateUrl + format* functions + truncateOutput. Injected
edge: TranscriptClient (injectable fetchFn, AbortSignal.any for
cancellation). concurrencySafe true, capabilities network. 30 tests.
Verified: tsc EXIT 0, 1152 vitest, biome clean (327 files). Boot smoke
clean.
Diffstat (limited to 'packages/tool-youtube-transcript/src/validate.ts')
| -rw-r--r-- | packages/tool-youtube-transcript/src/validate.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/tool-youtube-transcript/src/validate.ts b/packages/tool-youtube-transcript/src/validate.ts new file mode 100644 index 0000000..3a9d919 --- /dev/null +++ b/packages/tool-youtube-transcript/src/validate.ts @@ -0,0 +1,30 @@ +/** + * Pure argument validation for the youtube_transcript tool — input → output, no I/O. + * + * Validates that args is an object with a non-empty `url` string. Does NOT + * validate URL format — the transcriber service handles that (mirrors the + * opencode youtube-subtitles tool's contract). Returns the URL string on + * success or `{ error }` for invalid input, so the tool surfaces the message + * verbatim as an `isError` result. + */ + +export type ValidationError = { readonly error: string }; + +/** + * Validate raw tool args. Returns the URL string, or `{ error }` for invalid + * input — the tool surfaces the message verbatim. + */ +export function validateUrl(args: unknown): string | ValidationError { + if (args === null || args === undefined || typeof args !== "object") { + return { error: "Error: Arguments must be an object with a 'url' string." }; + } + const obj = args as Record<string, unknown>; + const raw = obj.url; + if (typeof raw !== "string") { + return { error: "Error: 'url' is required and must be a string." }; + } + if (raw.trim().length === 0) { + return { error: "Error: 'url' must not be empty." }; + } + return raw; +} |
