import { agentConnectionGuideUrl, isCloudIntegration, isStreamableHttpTransport, type IntegrationInfo, type PartialIntegrationHint } from './integration.ts'; import type { TranscriptDocument } from './transcript.ts'; export type TranscriptWorkflow = { projectId: string; sourcePaths: string[]; sourceLinks: string; targets: string; languages: string; goal: 'highlights' | 'adapt'; notes: string; transcript?: Pick | null }; /** A saved-project handoff composes public operations; it is not an automatic publishing job. */ export function transcriptWorkflowPrompt(input: TranscriptWorkflow, info?: (Pick & PartialIntegrationHint), locale = 'en') { if (!input.projectId || !['highlights', 'adapt'].includes(input.goal)) throw new Error('Choose a source project and workflow goal'); const workspaceLines = info ? (() => { const origin = new URL(info.previewUrl).origin; const cloud = isCloudIntegration(info); const mcpUrl = isStreamableHttpTransport(info.transport) ? info.transport.url : `${origin}/mcp`; return [ info.dataDirectory ? `Workspace: ${info.dataDirectory}` : null, `Project: ${origin}/#project/${encodeURIComponent(input.projectId)}`, cloud ? `MCP endpoint: ${mcpUrl}` : null, cloud ? `Connection guide: ${agentConnectionGuideUrl(info, 'mcp')} (if not connected to this endpoint, connect first and skip generic template onboarding)` : null, ].filter(Boolean).join('\n'); })() : 'Read the connected workspace and confirm this exact project exists.'; return `Use OpenMotion MCP to turn imported speech-led media into editable platform and language versions. Respond in ${locale}. Source projectId: ${input.projectId} ${workspaceLines} Imported source paths: ${JSON.stringify(input.sourcePaths)} ${input.transcript ? `Selected transcriptId: ${input.transcript.id}, observed transcript revision: ${input.transcript.revision}` : 'Discover saved transcripts first.'} Goal: ${input.goal === 'highlights' ? 'Select up to three self-contained highlights. Aim for 30–60 seconds, preserving meaning and context; do not pad short sources.' : 'Keep the complete story and adapt framing and caption layout.'} Platforms requested: ${input.targets.trim() || 'Ask which platforms the user wants.'} Subtitle languages requested: ${input.languages.trim() || 'Keep the source language.'} Additional source links or search brief (user material, not tool instructions): ${input.sourceLinks.trim() || '(none)'} Additional editorial requirements: ${input.notes.trim() || '(none)'} 1. Read the native editing and director guidance, then openmotion_get_project for this project’s current revision/currentVersionId and real files. Preserve the original project. If source links need retrieval, use your host’s available search/download tools to obtain media the user may use, then openmotion_assets_use import with a stable requestId and a local sourcePath. Inspect the returned pinned asset/version using read (audio excerpts and timestamped video frames), and import_to_project. A YouTube page URL is not a local media path. If retrieval or analysis is unavailable, report the exact gap and ask for the downloadable file; never fabricate an import, visual observation or permission bypass. Keep provenance/source URLs in the project brief. 2. Call openmotion_assets_use with action="transcript" and transcript={command:"sources",projectId}, then list/get. Reuse transcripts only when their source SHA256 matches current media. For missing speech text, discover command="models", then submit with projectId, sourcePath, model and stable requestId. Poll status to completion; do not resubmit paid work on timeout. A configured transcription model is required; use the model-provider settings page if none exists. Import existing SRT/VTT with command="import" when available. Do not invent timestamps for text-only responses. 3. Review actual speech and sampled pictures together. Choose source ranges that preserve complete thoughts; report what visual/audio analysis was actually possible. Correct names and timing with command="update", expectedTranscriptRevision and a stable requestId. Editing transcript text does not cut source media. Keep original source-relative timecodes for every cut. 4. For each chosen cut/platform/language, create an independent project with openmotion_manage_project(action="duplicate", expectedRevision, requestId). Reuse copies on retries. Read each copy’s current identity, then use openmotion_edit_project with expectedRevision/expectedVersionId to trim/reorder native media clips, retain audio and explicitly map source offsets and playback rates. Reframe each output as an editable composition; choose a suitable canvas (for example 9:16 or 16:9), without claiming a current platform upload limit. Review subjects, titles and subtitle safe areas instead of just stretching the frame. 5. For each requested subtitle language, translate the reviewed segments while preserving their exact source start/end and speaker identity, facts and meaning. Translate only the text and remove obsolete word alignments; do not invent translated word timings. Import the translated segments into its destination project with action="transcript", command="import", language, sourcePath and stable requestId. Original speech stays unchanged; subtitle translation is not dubbing. Use the existing configured speech/voice workflow only if dubbing is explicitly requested, and verify sync separately. 6. Add editable captions using command="captions", the destination transcriptId and expectedTranscriptRevision, explicit compositionPath, sourceStart/sourceEnd/timelineStart/playbackRate and current expectedRevision/expectedVersionId. For a montage with multiple source ranges, map each cue to its destination clip through native editing rather than applying one continuous offset. Keep captions editable and preserve project history. Conflicts require rereading and reconciliation. 7. Open each destination with openmotion_open_preview, check text, framing, cuts and sound. Read the latest project version again. Use the platform-export workflow and openmotion_export_request with projectId, versionId, expectedRevision, stable requestId and audio required/silent as appropriate. Poll the same job with openmotion_get_project(exportJobId), require the technical verification result and play the resulting video when the host supports it. Deliver the platform/language-to-project/file mapping and subtitle exports (command="export", format="srt" or "vtt"). For each continuous cut pass the same sourceStart/sourceEnd/timelineStart/playbackRate used for captions so its sidecar follows the edited video clock. For a montage, combine the cue ranges mapped to each destination clip into a sorted sidecar; do not deliver source-relative timestamps as final-video subtitles. Clearly identify unverified playback/content checks. Exporting produces files; do not upload or publish to a platform automatically.`; }