import { spawn } from 'child_process'; import { PIPELINE_SCRIPT, PROJECT_ROOT } from './shared'; import type { ToolDefinition } from './types'; export const runPipelinePhase: ToolDefinition = { name: 'run_pipeline_phase', description: '执行视频创作 pipeline 的指定阶段。阶段顺序: images(生图) → upload(上传) → videos(生视频) → tts(配音) → assemble(成片组装)。执行前需确认 manifest.json 已存在。', input_schema: { type: 'object', properties: { manifest: { type: 'string', description: 'manifest.json 的绝对路径' }, phase: { type: 'string', description: '要执行的阶段: images, upload, videos, tts, assemble。多个阶段用逗号分隔如 images,upload' }, }, required: ['manifest', 'phase'], }, execute: async (params) => { const { manifest, phase } = params as { manifest: string; phase: string }; return new Promise((resolve, reject) => { const proc = spawn('node', [PIPELINE_SCRIPT, 'run', '--manifest', manifest, '--phase', phase], { cwd: PROJECT_ROOT, env: { ...process.env }, }); let output = ''; proc.stdout.on('data', (d: Buffer) => { output += d.toString(); }); proc.stderr.on('data', (d: Buffer) => { output += d.toString(); }); proc.on('close', (code) => { code === 0 ? resolve(output || '执行成功') : reject(new Error(`Pipeline exit code ${code}: ${output.slice(-500)}`)); }); }); }, };