2.9 KiB
2.9 KiB
Tasks: transcribe_video Phase 1
Phase 1: Foundation
- 1.1 Add
resolveAssetFile(assetId?: string): File | nulltoEditorContextAdapterinapps/web/src/agent/context.ts— usesEditorCore.media.getAssets()to find by ID or first video/audio, returnsnullon no match - 1.2 Add
TranscriptionToolResultandTranscribeVideoArgsinterfaces at top of new fileapps/web/src/agent/tools/transcribe-video.tool.ts
Phase 2: Core Tool
- 2.1 Implement
transcribe_videotool inapps/web/src/agent/tools/transcribe-video.tool.ts— validatecontext.mediaAssets, callresolveAssetFile, guard onhasAudio/type/ambiguity, thendecodeAudioToFloat32→transcriptionService.transcribe→ returnTranscriptionToolResult - 2.2 Register tool via side-effect
toolRegistry.register("transcribe_video", …)at module level (same pattern asmock.tool.ts)
Phase 3: Wiring
- 3.1 Add
import "@/agent/tools/transcribe-video.tool"toapps/web/src/agent/orchestrator.ts(side-effect registration) - 3.2 Update
apps/web/src/app/api/agent/chat/route.ts— if last user message contains "transcri" (case-insensitive), returntranscribe_videotool call; else keepecho_contextfallback - 3.3 Update
apps/web/src/components/editor/panels/chat/message-bubble.tsx— fortool_resultrole, tryJSON.parse(content)and if it hasfullText+segments, render transcript card with asset name, language, duration, and[MM:SS] textsegments; else render plain text
Phase 4: Testing
- 4.1 Unit test
resolveAssetFile()inapps/web/src/agent/__tests__/context.test.ts— mockEditorCore.media.getAssets()for: match by ID, fallback to first video, no assets → null - 4.2 Unit test asset selection + error branches in
apps/web/src/agent/tools/__tests__/transcribe-video.test.ts— mockdecodeAudioToFloat32+transcriptionService; cover: success path, no audio, no asset, multiple candidates, service failure - 4.3 Contract test
toolRegistry.has("transcribe_video")in same test file — verifies registration side-effect - 4.4 Unit test API route in
apps/web/src/app/api/agent/chat/__tests__/route.test.ts— "transcribe this" → returnstranscribe_videocall; other message → returnsecho_contextcall
Phase 5: Post-Verify Fixes
- 5.1 Fix TypeScript errors:
jest.fntype references in test files replaced with explicitMockFn/MockFnFactorytypes;TranscribeVideoArgs.languagetyped asTranscriptionLanguageinstead ofstring - 5.2 Align tool error messages with spec:
"No active media asset"for no-asset,"Asset has no audio track"for image-only and no-audio-track cases - 5.3 Wrap decode+transcribe in try/catch — service failures now return
{ error: message }instead of throwing - 5.4 Extract
isTranscriptData+formatTimestamptotranscript-utils.ts; add 17 behavioral tests proving transcript detection and timestamp formatting