Files
video-create/web/server/agent/tools/update-manifest-items.ts
sion123 e16305840b feat(agent): 添加视频创作工作流技能系统和流程工具
新增基于 SKILL.md 的视频创作工作流系统,Agent 可通过 skills 目录加载结构化的导演指令;实现 validate_storyboard、update_manifest_items、confirm_images 三个流程工具支撑分镜校验、提示词更新和图片确认。
2026-05-08 01:54:04 +08:00

46 lines
1.8 KiB
TypeScript
Raw 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 path from 'path';
import fs from 'fs';
import { PROJECT_ROOT, loadJSON } from './shared';
import type { ToolDefinition } from './types';
export const updateManifestItems: ToolDefinition = {
name: 'update_manifest_items',
description: '更新 manifest.json 中指定 items 的字段(如 imagePrompt、videoPrompt。只更新提供的字段不覆盖其他字段。',
input_schema: {
type: 'object',
properties: {
manifestPath: { type: 'string', description: 'manifest.json 路径' },
updates: { type: 'string', description: 'JSON 数组,每个元素需包含 idshot 序号)和要更新的字段,如 [{id:1,imagePrompt:"..."},{id:2,imagePrompt:"..."}]' },
},
required: ['manifestPath', 'updates'],
},
execute: async (params) => {
const { manifestPath, updates } = params as { manifestPath: string; updates: string };
const resolved = path.isAbsolute(manifestPath)
? manifestPath
: path.resolve(PROJECT_ROOT, manifestPath);
if (!fs.existsSync(resolved)) return `manifest 不存在: ${resolved}`;
let updateList: any[];
try { updateList = JSON.parse(updates); } catch { return '错误: updates 不是合法 JSON'; }
if (!Array.isArray(updateList)) return '错误: updates 必须是数组';
const manifest = loadJSON(resolved) as { items: any[] };
if (!manifest.items) return '错误: manifest 无 items 数组';
let updated = 0;
for (const upd of updateList) {
const idx = manifest.items.findIndex((item: any) => item.id === upd.id);
if (idx === -1) return `错误: 找不到 id=${upd.id} 的 item`;
const { id, ...fields } = upd;
Object.assign(manifest.items[idx], fields);
updated++;
}
fs.writeFileSync(resolved, JSON.stringify(manifest, null, 2), 'utf-8');
return `已更新 ${updated}/${manifest.items.length} 个 item`;
},
};