Files
openmotion/shared/transcript-workflow.ts
open-design-crew[bot] 69032477fe feat(mcp,studio): unify cloud MCP onboarding, handoff prompts, and workspace-scoped OAuth access (#1094)
* feat(mcp,studio): unify cloud MCP onboarding, handoff prompts, and workspace-scoped OAuth access

- Point all cloud Agent handoff prompts (editor MCP button, templates, skills, platform export, review comments, transcript workflow, design handoff) to <ORIGIN>/install.md and <ORIGIN>/mcp instead of auth-gated /connect/guide or SPA /mcp-setup.
- Make GET /connect/guide public with browser 302 redirect to /mcp-setup and non-HTML 200 text/markdown serving /install.md; add public GET /connect/integration for guest cloud discovery on /mcp-setup and make GET /connect/config public.
- Remove per-project manual project_grants enforcement for OAuth 2.1 clients so authorized OAuth Agents have workspace-scoped access to the authenticated user's projects (matching PAT behavior while preserving ownerUserId isolation and preview_token single-project pinning), and remove the obsolete per-project Agent access menu entry.
- Add Mode A (pure setup) vs Mode B (task-driven handoff) guidance to docs/install.md and skills/openmotion/SKILL.md, plus structured 401 authGuidance and PROJECT_NOT_FOUND origin/workspace diagnostics.
- Refine /mcp-setup UX: hide DesktopConnectPanel in ordinary cloud browsers without a desktop or helper bridge, fix hero endpoint pill spacing, align Claude Desktop (Connectors UI), Cursor/MCP OAuth 2.1, and Claude Code (--scope user) manual instructions, and remove contradictory wait-for-brief text from task examples.

* test(studio): replace internal staging hostname fixture with motion.example.com

* test(mcp): include cloud server origin line in mcp-registry instructions check

* fix(mcp,studio): address review feedback and remove DesktopConnectPanel from /mcp-setup

- Send Vary: Accept on both branches of GET /connect/guide (plus Cache-Control: no-store on the 302 redirect) and assert both headers in cloud API tests.
- Restrict Step 3 onboarding mechanics and the Installation-success reply in docs/install.md explicitly to Mode A so Mode B task handoffs skip onboarding unambiguously.
- Remove the orphaned ProjectAgentGrantsDialog component and test, drop the unused onOpenMcpSetup parameter from useProjectArchives, stop writing inert project_grants rows in workspace-service and catalog-service, and document the retained /motion-api/projects/:id/grants routes as inert legacy compatibility endpoints.
- Remove DesktopConnectPanel and /motion-api/connections polling completely from /mcp-setup (McpConnectionPage) across both web and desktop hosts.

* chore(studio): remove orphaned DesktopConnectPanel, test, and architecture-map entry

---------

Co-authored-by: 罗高 <luogao@users.noreply.github.com>
2026-11-25 01:39:03 -08:00

40 lines
6.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<TranscriptDocument, 'id' | 'revision'> | null };
/** A saved-project handoff composes public operations; it is not an automatic publishing job. */
export function transcriptWorkflowPrompt(input: TranscriptWorkflow, info?: (Pick<IntegrationInfo, 'previewUrl' | 'dataDirectory'> & 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.`;
}