将 `tools.ts` 拆分为按功能划分的独立文件,并存放于 `tools/` 目录下,同时更新导入路径;优化 agent 系统提示语,移除冗余的「美图 Agent」前缀。
32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
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)}`));
|
|
});
|
|
});
|
|
},
|
|
};
|