cerevox 4.0.0-alpha.2 → 4.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/servers/prompts/outlines-backup.md +41 -13
- package/dist/mcp/servers/prompts/skills//344/270/200/351/224/256/346/210/220/347/211/207.md +13 -21
- package/dist/mcp/servers/zerocut.d.ts.map +1 -1
- package/dist/mcp/servers/zerocut.js +29 -859
- package/dist/mcp/servers/zerocut.js.map +1 -1
- package/package.json +1 -1
- /package/dist/mcp/servers/prompts/{zerocut-core copy.md → zerocut-core-web.md} +0 -0
|
@@ -140,6 +140,8 @@ async function saveMaterial(session, url, saveToFileName) {
|
|
|
140
140
|
const terminal = session.terminal;
|
|
141
141
|
const saveToPath = `/home/user/cerevox-zerocut/projects/${terminal.id}/materials/${saveToFileName}`;
|
|
142
142
|
const saveLocalPath = (0, node_path_1.resolve)(projectLocalDir, 'materials', saveToFileName);
|
|
143
|
+
// 确保目录存在
|
|
144
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(saveLocalPath), { recursive: true });
|
|
143
145
|
// 先下载到本地,再上传 sandbox,比直接 sandbox 更好,也以免下载超时
|
|
144
146
|
// 通过 fetch 下载到本地
|
|
145
147
|
const res = await fetch(url);
|
|
@@ -261,7 +263,7 @@ async function filterMaterialsForUpload(materials, projectLocalDir) {
|
|
|
261
263
|
regularFiles.push(material);
|
|
262
264
|
}
|
|
263
265
|
}
|
|
264
|
-
//
|
|
266
|
+
// 处理分镜文件(scXX_ 前缀)
|
|
265
267
|
if (sceneFiles.length > 0 && mediaLogs.length > 0) {
|
|
266
268
|
// 按前缀和扩展名分组
|
|
267
269
|
const groupedFiles = new Map();
|
|
@@ -309,7 +311,7 @@ async function filterMaterialsForUpload(materials, projectLocalDir) {
|
|
|
309
311
|
}
|
|
310
312
|
}
|
|
311
313
|
else {
|
|
312
|
-
// 如果没有 media_logs.json
|
|
314
|
+
// 如果没有 media_logs.json 或没有分镜文件,全部上传
|
|
313
315
|
filesToUpload.push(...sceneFiles);
|
|
314
316
|
}
|
|
315
317
|
// 处理普通文件(全量上传)
|
|
@@ -341,7 +343,7 @@ server.registerPrompt('zerocut-guideline', {
|
|
|
341
343
|
description: '专业的短视频创作 Agent 指导规范,包含完整的工作流程、工具说明和质量建议',
|
|
342
344
|
}, async () => {
|
|
343
345
|
try {
|
|
344
|
-
const promptPath = (0, node_path_1.resolve)(__dirname, './prompts/zerocut-core.md');
|
|
346
|
+
const promptPath = (0, node_path_1.resolve)(__dirname, './prompts/zerocut-core-web.md');
|
|
345
347
|
const promptContent = await (0, promises_1.readFile)(promptPath, 'utf-8');
|
|
346
348
|
return {
|
|
347
349
|
messages: [
|
|
@@ -356,8 +358,8 @@ server.registerPrompt('zerocut-guideline', {
|
|
|
356
358
|
};
|
|
357
359
|
}
|
|
358
360
|
catch (error) {
|
|
359
|
-
console.error('Failed to load zerocut-guideline prompt:', error);
|
|
360
|
-
throw new Error(`Failed to load zerocut-guideline prompt: ${error}`);
|
|
361
|
+
console.error('Failed to load zerocut-guideline-web prompt:', error);
|
|
362
|
+
throw new Error(`Failed to load zerocut-guideline-web prompt: ${error}`);
|
|
361
363
|
}
|
|
362
364
|
});
|
|
363
365
|
server.registerTool('project-open', {
|
|
@@ -1020,12 +1022,12 @@ server.registerTool('generate-image', {
|
|
|
1020
1022
|
.default('seedream-pro'),
|
|
1021
1023
|
prompt: zod_1.z
|
|
1022
1024
|
.string()
|
|
1023
|
-
.describe('The prompt to generate. 一般要严格对应 storyboard
|
|
1025
|
+
.describe('The prompt to generate. 一般要严格对应 storyboard 中当前分镜的 start_frame 或 end_frame 中的字段描述,如果是生成线稿,则 type 使用 line-sketch,如果是生成故事板印样或人物镜头宫格,则 type 使用 shot-grid'),
|
|
1024
1026
|
sceneIndex: zod_1.z
|
|
1025
1027
|
.number()
|
|
1026
1028
|
.min(1)
|
|
1027
1029
|
.optional()
|
|
1028
|
-
.describe('
|
|
1030
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
1029
1031
|
storyBoardFile: zod_1.z
|
|
1030
1032
|
.string()
|
|
1031
1033
|
.optional()
|
|
@@ -1131,14 +1133,7 @@ server.registerTool('generate-image', {
|
|
|
1131
1133
|
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
1132
1134
|
const outlineSheetImagePath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'materials', 'outline_sheet.png');
|
|
1133
1135
|
const hasOutlineSheet = (0, node_fs_1.existsSync)(outlineSheetImagePath);
|
|
1134
|
-
//
|
|
1135
|
-
if (!hasOutlineSheet &&
|
|
1136
|
-
!checkStoryboardFlag &&
|
|
1137
|
-
(0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
1138
|
-
checkStoryboardFlag = true;
|
|
1139
|
-
return createErrorResponse('必须先审查生成的 storyboard.json 内容,确保每个场景中的stage_atmosphere内容按照规则被正确融合到start_frame和video_prompt中,不得遗漏,检查完成后先汇报,如果有问题,应当先修改 storyboard.json 内容,然后再调用 generate-image 生成图片。注意修改 storyboard 内容时,仅修改相应字段的字符串值,不要破坏JSON格式!', 'generate-image');
|
|
1140
|
-
}
|
|
1141
|
-
// 校验 prompt 与 storyboard.json 中场景设定的一致性
|
|
1136
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性
|
|
1142
1137
|
if (sceneIndex && !skipConsistencyCheck) {
|
|
1143
1138
|
try {
|
|
1144
1139
|
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
@@ -1226,73 +1221,6 @@ server.registerTool('generate-image', {
|
|
|
1226
1221
|
// 检查并替换英文单引号包裹的中文内容为中文双引号
|
|
1227
1222
|
// 这样才能让 seedream 生成更好的中文文字
|
|
1228
1223
|
let processedPrompt = prompt.replace(/'([^']*[\u4e00-\u9fff][^']*)'/g, '“$1”');
|
|
1229
|
-
try {
|
|
1230
|
-
const ai = currentSession.ai;
|
|
1231
|
-
const promptOptimizer = await (0, promises_1.readFile)((0, node_path_1.resolve)(__dirname, './prompts/image-prompt-optimizer.md'), 'utf8');
|
|
1232
|
-
if (!hasOutlineSheet) {
|
|
1233
|
-
const schema = {
|
|
1234
|
-
name: 'optimize_image_prompt',
|
|
1235
|
-
schema: {
|
|
1236
|
-
type: 'object',
|
|
1237
|
-
properties: {
|
|
1238
|
-
prompt_optimized: {
|
|
1239
|
-
type: 'string',
|
|
1240
|
-
description: '优化后的提示词',
|
|
1241
|
-
},
|
|
1242
|
-
metaphor_modifiers: {
|
|
1243
|
-
type: 'array',
|
|
1244
|
-
description: '从 prompt_optimized 中抽取的所有比喻修饰词(字符串数组)',
|
|
1245
|
-
items: {
|
|
1246
|
-
type: 'string',
|
|
1247
|
-
description: '比喻性修饰词,例如 “如羽毛般轻盈”、“像晨雾一样柔和”',
|
|
1248
|
-
},
|
|
1249
|
-
},
|
|
1250
|
-
},
|
|
1251
|
-
required: ['prompt_optimized', 'metaphor_modifiers'],
|
|
1252
|
-
},
|
|
1253
|
-
};
|
|
1254
|
-
const completion = await ai.getCompletions({
|
|
1255
|
-
model: 'Doubao-Seed-1.6',
|
|
1256
|
-
messages: [
|
|
1257
|
-
{
|
|
1258
|
-
role: 'system',
|
|
1259
|
-
content: promptOptimizer,
|
|
1260
|
-
},
|
|
1261
|
-
{
|
|
1262
|
-
role: 'user',
|
|
1263
|
-
content: `## 用户指令
|
|
1264
|
-
|
|
1265
|
-
${processedPrompt.trim()}
|
|
1266
|
-
|
|
1267
|
-
## 参考图
|
|
1268
|
-
|
|
1269
|
-
${referenceImages?.map((ref, index) => `图${index + 1}:${ref.image}`).join('\n') || '无'}`,
|
|
1270
|
-
},
|
|
1271
|
-
],
|
|
1272
|
-
response_format: {
|
|
1273
|
-
type: 'json_schema',
|
|
1274
|
-
json_schema: schema,
|
|
1275
|
-
},
|
|
1276
|
-
});
|
|
1277
|
-
const optimizedPrompt = completion.choices[0]?.message?.content.trim();
|
|
1278
|
-
if (optimizedPrompt) {
|
|
1279
|
-
try {
|
|
1280
|
-
const { prompt_optimized, metaphor_modifiers } = JSON.parse(optimizedPrompt);
|
|
1281
|
-
processedPrompt = `${prompt_optimized}`;
|
|
1282
|
-
if (metaphor_modifiers?.length) {
|
|
1283
|
-
processedPrompt += `\n\n注意:下面这些是形象比喻,并不是输出内容。\n${metaphor_modifiers}`;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
catch (ex) {
|
|
1287
|
-
console.error('Failed to parse optimized prompt:', ex);
|
|
1288
|
-
processedPrompt = optimizedPrompt;
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
catch (error) {
|
|
1294
|
-
console.error('Failed to optimize prompt:', error);
|
|
1295
|
-
}
|
|
1296
1224
|
if (imageCount > 1) {
|
|
1297
1225
|
processedPrompt = `请生成${imageCount}张${size}大小的关联图片,每张图分别生成,不要拼接为大图 ${processedPrompt}`;
|
|
1298
1226
|
}
|
|
@@ -1365,7 +1293,7 @@ server.registerTool('generate-image', {
|
|
|
1365
1293
|
if (objectPrefix.length > 0) {
|
|
1366
1294
|
processedPrompt = `${objectPrefix.join('\n')}
|
|
1367
1295
|
|
|
1368
|
-
${turnaroundMessage}
|
|
1296
|
+
${turnaroundMessage}参考以上图片,执行以下绘图指令:
|
|
1369
1297
|
${processedPrompt}`.trim();
|
|
1370
1298
|
}
|
|
1371
1299
|
}
|
|
@@ -1402,7 +1330,7 @@ ${processedPrompt}`.trim();
|
|
|
1402
1330
|
];
|
|
1403
1331
|
}
|
|
1404
1332
|
else {
|
|
1405
|
-
//
|
|
1333
|
+
// 多图
|
|
1406
1334
|
uris = await Promise.all(res.urls.map((url, i) => {
|
|
1407
1335
|
if (!url)
|
|
1408
1336
|
return '';
|
|
@@ -2026,695 +1954,6 @@ server.registerTool('text-to-speech', {
|
|
|
2026
1954
|
return createErrorResponse(error, 'text-to-speech');
|
|
2027
1955
|
}
|
|
2028
1956
|
});
|
|
2029
|
-
// server.registerTool(
|
|
2030
|
-
// 'generate-scene-tts',
|
|
2031
|
-
// {
|
|
2032
|
-
// title: 'Generate Scene TTS',
|
|
2033
|
-
// description: `生成场景配音`,
|
|
2034
|
-
// inputSchema: {
|
|
2035
|
-
// text: z.string().describe('The text to generate.'),
|
|
2036
|
-
// sceneIndex: z
|
|
2037
|
-
// .number()
|
|
2038
|
-
// .min(1)
|
|
2039
|
-
// .optional()
|
|
2040
|
-
// .describe(
|
|
2041
|
-
// '场景索引,从1开始的下标,如果非场景对应素材,则可不传,场景素材必传'
|
|
2042
|
-
// ),
|
|
2043
|
-
// storyBoardFile: z
|
|
2044
|
-
// .string()
|
|
2045
|
-
// .optional()
|
|
2046
|
-
// .default('storyboard.json')
|
|
2047
|
-
// .describe('故事板文件路径'),
|
|
2048
|
-
// skipConsistencyCheck: z
|
|
2049
|
-
// .boolean()
|
|
2050
|
-
// .optional()
|
|
2051
|
-
// .default(false)
|
|
2052
|
-
// .describe('是否跳过一致性检查,默认为false(即默认进行一致性检查)'),
|
|
2053
|
-
// skipCheckWithSceneReason: z
|
|
2054
|
-
// .string()
|
|
2055
|
-
// .optional()
|
|
2056
|
-
// .describe(
|
|
2057
|
-
// '跳过校验的理由,如果skipConsistencyCheck设为true,必须要传这个参数'
|
|
2058
|
-
// ),
|
|
2059
|
-
// saveToFileName: z
|
|
2060
|
-
// .string()
|
|
2061
|
-
// .describe('The filename to save. 应该是mp3文件'),
|
|
2062
|
-
// speed: z
|
|
2063
|
-
// .number()
|
|
2064
|
-
// .min(0.5)
|
|
2065
|
-
// .max(2)
|
|
2066
|
-
// .optional()
|
|
2067
|
-
// .default(1)
|
|
2068
|
-
// .describe('The speed of the tts.'),
|
|
2069
|
-
// pitch: z
|
|
2070
|
-
// .number()
|
|
2071
|
-
// .min(-12)
|
|
2072
|
-
// .max(12)
|
|
2073
|
-
// .optional()
|
|
2074
|
-
// .default(0)
|
|
2075
|
-
// .describe('The pitch of the tts.'),
|
|
2076
|
-
// volume: z
|
|
2077
|
-
// .number()
|
|
2078
|
-
// .min(0)
|
|
2079
|
-
// .max(10)
|
|
2080
|
-
// .optional()
|
|
2081
|
-
// .default(1.0)
|
|
2082
|
-
// .describe('The volume of the tts.'),
|
|
2083
|
-
// voiceID: z
|
|
2084
|
-
// .string()
|
|
2085
|
-
// .describe(
|
|
2086
|
-
// `适合作为视频配音的音色ID,除非用户指定,否则你必须确保已通过 pick-voice 工具挑选出真实存在的音色。`
|
|
2087
|
-
// ),
|
|
2088
|
-
// context_texts: z
|
|
2089
|
-
// .array(z.string())
|
|
2090
|
-
// .default([])
|
|
2091
|
-
// .describe(
|
|
2092
|
-
// `语音合成的辅助信息,用于模型对话式合成,能更好的体现语音情感
|
|
2093
|
-
// 可以探索,比如常见示例有以下几种:
|
|
2094
|
-
// 1. 语速调整
|
|
2095
|
-
// - context_texts: ["你可以说慢一点吗?"]
|
|
2096
|
-
// 2. 情绪/语气调整
|
|
2097
|
-
// - context_texts=["你可以用特别特别痛心的语气说话吗?"]
|
|
2098
|
-
// - context_texts=["嗯,你的语气再欢乐一点"]
|
|
2099
|
-
// 3. 音量调整
|
|
2100
|
-
// - context_texts=["你嗓门再小点。"]
|
|
2101
|
-
// 4. 音感调整
|
|
2102
|
-
// - context_texts=["你能用骄傲的语气来说话吗?"]
|
|
2103
|
-
// `
|
|
2104
|
-
// ),
|
|
2105
|
-
// explicit_language: z.enum(['zh', 'en', 'ja']).optional().default('zh'),
|
|
2106
|
-
// },
|
|
2107
|
-
// },
|
|
2108
|
-
// async ({
|
|
2109
|
-
// text,
|
|
2110
|
-
// sceneIndex,
|
|
2111
|
-
// storyBoardFile,
|
|
2112
|
-
// skipConsistencyCheck,
|
|
2113
|
-
// voiceID,
|
|
2114
|
-
// saveToFileName,
|
|
2115
|
-
// speed,
|
|
2116
|
-
// pitch,
|
|
2117
|
-
// volume,
|
|
2118
|
-
// context_texts,
|
|
2119
|
-
// explicit_language,
|
|
2120
|
-
// }) => {
|
|
2121
|
-
// try {
|
|
2122
|
-
// // 验证session状态
|
|
2123
|
-
// const currentSession = await validateSession('generate-scene-tts');
|
|
2124
|
-
// const validatedFileName = validateFileName(saveToFileName);
|
|
2125
|
-
// const finalSpeed = speed ?? 1;
|
|
2126
|
-
// volume = volume ?? 1;
|
|
2127
|
-
// const ai = currentSession.ai;
|
|
2128
|
-
// let scene = null;
|
|
2129
|
-
// // 校验 text 与 storyboard.json 中场景设定的一致性
|
|
2130
|
-
// if (sceneIndex && !skipConsistencyCheck) {
|
|
2131
|
-
// try {
|
|
2132
|
-
// const voice = (await ai.listVoices()).find(v => v.id === voiceID);
|
|
2133
|
-
// if (!voice) {
|
|
2134
|
-
// return createErrorResponse(
|
|
2135
|
-
// `Voice ${voiceID} not found in voice-list. Use pick-voice tool to pick an available voice. 若用户坚持要使用该音色,需跳过一致性检查。`,
|
|
2136
|
-
// 'generate-scene-tts'
|
|
2137
|
-
// );
|
|
2138
|
-
// }
|
|
2139
|
-
// const storyBoardPath = resolve(
|
|
2140
|
-
// process.env.ZEROCUT_PROJECT_CWD || process.cwd(),
|
|
2141
|
-
// projectLocalDir,
|
|
2142
|
-
// storyBoardFile
|
|
2143
|
-
// );
|
|
2144
|
-
// if (existsSync(storyBoardPath)) {
|
|
2145
|
-
// const storyBoardContent = await readFile(storyBoardPath, 'utf8');
|
|
2146
|
-
// // 检查 storyBoard JSON 语法合法性
|
|
2147
|
-
// let storyBoard;
|
|
2148
|
-
// try {
|
|
2149
|
-
// storyBoard = JSON.parse(storyBoardContent);
|
|
2150
|
-
// } catch (jsonError) {
|
|
2151
|
-
// return createErrorResponse(
|
|
2152
|
-
// `storyBoard 文件 ${storyBoardFile} 存在 JSON 语法错误,请修复后重试。错误详情: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
|
2153
|
-
// 'generate-scene-tts'
|
|
2154
|
-
// );
|
|
2155
|
-
// }
|
|
2156
|
-
// if (storyBoard.scenes && Array.isArray(storyBoard.scenes)) {
|
|
2157
|
-
// scene = storyBoard.scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2158
|
-
// if (scene) {
|
|
2159
|
-
// const script = scene.script;
|
|
2160
|
-
// let isValidText = false;
|
|
2161
|
-
// // 检查 text 是否严格等于 script
|
|
2162
|
-
// if (script && text === script) {
|
|
2163
|
-
// isValidText = true;
|
|
2164
|
-
// }
|
|
2165
|
-
// // 检查 text 是否严格等于 dialog 数组中某个元素的 script
|
|
2166
|
-
// if (
|
|
2167
|
-
// !isValidText &&
|
|
2168
|
-
// scene.dialog &&
|
|
2169
|
-
// Array.isArray(scene.dialog)
|
|
2170
|
-
// ) {
|
|
2171
|
-
// for (const dialogItem of scene.dialog) {
|
|
2172
|
-
// if (dialogItem.script && text === dialogItem.script) {
|
|
2173
|
-
// isValidText = true;
|
|
2174
|
-
// break;
|
|
2175
|
-
// }
|
|
2176
|
-
// }
|
|
2177
|
-
// }
|
|
2178
|
-
// if (!isValidText) {
|
|
2179
|
-
// return createErrorResponse(
|
|
2180
|
-
// '配音文本必须严格遵照storyboard的设定,如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用',
|
|
2181
|
-
// 'generate-scene-tts'
|
|
2182
|
-
// );
|
|
2183
|
-
// }
|
|
2184
|
-
// } else {
|
|
2185
|
-
// console.warn(
|
|
2186
|
-
// `Scene index ${sceneIndex} not found in storyboard.json`
|
|
2187
|
-
// );
|
|
2188
|
-
// }
|
|
2189
|
-
// }
|
|
2190
|
-
// } else {
|
|
2191
|
-
// console.warn(`Story board file not found: ${storyBoardPath}`);
|
|
2192
|
-
// }
|
|
2193
|
-
// } catch (error) {
|
|
2194
|
-
// console.error('Failed to validate text with story board:', error);
|
|
2195
|
-
// // 如果读取或解析 storyboard.json 失败,继续执行但记录警告
|
|
2196
|
-
// }
|
|
2197
|
-
// }
|
|
2198
|
-
// console.log(
|
|
2199
|
-
// `Generating TTS with voice: ${voiceID}, speed: ${finalSpeed}, text: ${text.substring(0, 100)}...`
|
|
2200
|
-
// );
|
|
2201
|
-
// if (voiceID.startsWith('BV0')) {
|
|
2202
|
-
// throw new Error(
|
|
2203
|
-
// `BV0* 系列音色已弃用,你必须通过 pick-voice 工具挑选一个真实存在的音色。`
|
|
2204
|
-
// );
|
|
2205
|
-
// }
|
|
2206
|
-
// const type =
|
|
2207
|
-
// voiceID.startsWith('zh_') ||
|
|
2208
|
-
// voiceID.startsWith('en_') ||
|
|
2209
|
-
// voiceID.startsWith('multi_') ||
|
|
2210
|
-
// voiceID.startsWith('saturn_') ||
|
|
2211
|
-
// voiceID.startsWith('ICL_')
|
|
2212
|
-
// ? 'volcano'
|
|
2213
|
-
// : 'minimax';
|
|
2214
|
-
// let res;
|
|
2215
|
-
// let emotion = 'auto';
|
|
2216
|
-
// if (type === 'volcano') {
|
|
2217
|
-
// volume = Math.max(Math.min(volume, 2.0), 0.5);
|
|
2218
|
-
// res = await ai.textToSpeechVolc({
|
|
2219
|
-
// text: text.trim(),
|
|
2220
|
-
// speaker: voiceID,
|
|
2221
|
-
// speed: Math.floor(100 * (finalSpeed - 1)),
|
|
2222
|
-
// volume: Math.floor(100 * (volume - 1)),
|
|
2223
|
-
// context_texts,
|
|
2224
|
-
// explicit_language,
|
|
2225
|
-
// voice_to_caption:
|
|
2226
|
-
// explicit_language === 'zh' || explicit_language === 'en',
|
|
2227
|
-
// });
|
|
2228
|
-
// } else {
|
|
2229
|
-
// emotion = 'neutral';
|
|
2230
|
-
// if (context_texts.length > 0) {
|
|
2231
|
-
// const prompt = `根据用户输入语音内容和上下文内容,从文字判断语音合理的情感,然后选择以下情感**之一**返回结果:
|
|
2232
|
-
// "happy", "sad", "angry", "fearful", "disgusted", "surprised", "calm", "fluent", "whisper", "neutral"
|
|
2233
|
-
// ## 要求
|
|
2234
|
-
// 输出 JSON 格式,包含一个 emotion 字段,值为以上情感之一。
|
|
2235
|
-
// `;
|
|
2236
|
-
// const schema = {
|
|
2237
|
-
// name: 'emotion_schema',
|
|
2238
|
-
// schema: {
|
|
2239
|
-
// type: 'object',
|
|
2240
|
-
// properties: {
|
|
2241
|
-
// emotion: {
|
|
2242
|
-
// type: 'string',
|
|
2243
|
-
// enum: [
|
|
2244
|
-
// 'neutral',
|
|
2245
|
-
// 'happy',
|
|
2246
|
-
// 'sad',
|
|
2247
|
-
// 'angry',
|
|
2248
|
-
// 'fearful',
|
|
2249
|
-
// 'disgusted',
|
|
2250
|
-
// 'surprised',
|
|
2251
|
-
// 'calm',
|
|
2252
|
-
// 'fluent',
|
|
2253
|
-
// 'whisper',
|
|
2254
|
-
// ],
|
|
2255
|
-
// description: '用户输入语音的情感',
|
|
2256
|
-
// },
|
|
2257
|
-
// },
|
|
2258
|
-
// required: ['emotion'],
|
|
2259
|
-
// },
|
|
2260
|
-
// };
|
|
2261
|
-
// const payload: any = {
|
|
2262
|
-
// model: 'Doubao-Seed-1.6',
|
|
2263
|
-
// messages: [
|
|
2264
|
-
// {
|
|
2265
|
-
// role: 'system',
|
|
2266
|
-
// content: prompt,
|
|
2267
|
-
// },
|
|
2268
|
-
// {
|
|
2269
|
-
// role: 'user',
|
|
2270
|
-
// content: `## 语音内容:
|
|
2271
|
-
// ${text.trim()}
|
|
2272
|
-
// ## 语音上下文
|
|
2273
|
-
// ${context_texts.join('\n')}
|
|
2274
|
-
// `,
|
|
2275
|
-
// },
|
|
2276
|
-
// ],
|
|
2277
|
-
// response_format: {
|
|
2278
|
-
// type: 'json_schema',
|
|
2279
|
-
// json_schema: schema,
|
|
2280
|
-
// },
|
|
2281
|
-
// };
|
|
2282
|
-
// const completion = await ai.getCompletions(payload);
|
|
2283
|
-
// const emotionObj = JSON.parse(
|
|
2284
|
-
// completion.choices[0]?.message?.content ?? '{}'
|
|
2285
|
-
// );
|
|
2286
|
-
// emotion = emotionObj.emotion ?? 'neutral';
|
|
2287
|
-
// }
|
|
2288
|
-
// res = await ai.textToSpeech({
|
|
2289
|
-
// text: text.trim(),
|
|
2290
|
-
// voiceName: voiceID,
|
|
2291
|
-
// speed: finalSpeed,
|
|
2292
|
-
// pitch,
|
|
2293
|
-
// volume,
|
|
2294
|
-
// emotion,
|
|
2295
|
-
// voice_to_caption:
|
|
2296
|
-
// explicit_language === 'zh' || explicit_language === 'en',
|
|
2297
|
-
// });
|
|
2298
|
-
// }
|
|
2299
|
-
// if (!res) {
|
|
2300
|
-
// throw new Error('Failed to generate TTS: no response from AI service');
|
|
2301
|
-
// }
|
|
2302
|
-
// if (res.url) {
|
|
2303
|
-
// console.log('TTS generated successfully, saving to materials...');
|
|
2304
|
-
// const { url, duration, ...opts } = res;
|
|
2305
|
-
// if (!skipConsistencyCheck && duration > 16) {
|
|
2306
|
-
// return createErrorResponse(
|
|
2307
|
-
// 'TTS duration exceeds 16 seconds, 建议调整文本长度、提升语速或拆分场景...,⚠️如简化文本内容或拆分文本,需要立即更新 storyboard 以保持内容同步!如仍要生成,可设置 skipConsistencyCheck 为 true,跳过一致性检查。',
|
|
2308
|
-
// 'generate-scene-tts'
|
|
2309
|
-
// );
|
|
2310
|
-
// }
|
|
2311
|
-
// if (!duration) {
|
|
2312
|
-
// return createErrorResponse(
|
|
2313
|
-
// 'TTS duration not returned from AI service',
|
|
2314
|
-
// 'generate-scene-tts'
|
|
2315
|
-
// );
|
|
2316
|
-
// }
|
|
2317
|
-
// const uri = await saveMaterial(currentSession, url, validatedFileName);
|
|
2318
|
-
// let warn = '';
|
|
2319
|
-
// if (scene) {
|
|
2320
|
-
// const minDur = Math.ceil(duration);
|
|
2321
|
-
// if (scene.audio_mode === 'vo_sync' && scene.duration !== minDur) {
|
|
2322
|
-
// warn = `场景${sceneIndex}设定的时长${scene.duration}秒与实际生成的语音时长${minDur}秒不一致,音画同步将有问题,建议修改场景时长为${minDur}秒`;
|
|
2323
|
-
// } else if (scene.duration < minDur) {
|
|
2324
|
-
// warn = `场景${sceneIndex}设定的时长${scene.duration}秒小于实际生成的语音时长${duration}秒,可能会导致场景结束时音频未播放完成,建议修改场景时长为${minDur}秒`;
|
|
2325
|
-
// }
|
|
2326
|
-
// }
|
|
2327
|
-
// const result = {
|
|
2328
|
-
// success: true,
|
|
2329
|
-
// warn,
|
|
2330
|
-
// source: url, // 方便调试
|
|
2331
|
-
// uri,
|
|
2332
|
-
// durationMs: Math.floor((duration || 0) * 1000),
|
|
2333
|
-
// text,
|
|
2334
|
-
// emotion,
|
|
2335
|
-
// context_texts,
|
|
2336
|
-
// voiceName: voiceID,
|
|
2337
|
-
// speed: finalSpeed,
|
|
2338
|
-
// timestamp: new Date().toISOString(),
|
|
2339
|
-
// ...opts,
|
|
2340
|
-
// };
|
|
2341
|
-
// // Update media_logs.json
|
|
2342
|
-
// try {
|
|
2343
|
-
// await updateMediaLogs(
|
|
2344
|
-
// currentSession,
|
|
2345
|
-
// validatedFileName,
|
|
2346
|
-
// result,
|
|
2347
|
-
// 'audio'
|
|
2348
|
-
// );
|
|
2349
|
-
// } catch (error) {
|
|
2350
|
-
// console.warn(
|
|
2351
|
-
// `Failed to update media_logs.json for ${validatedFileName}:`,
|
|
2352
|
-
// error
|
|
2353
|
-
// );
|
|
2354
|
-
// }
|
|
2355
|
-
// return {
|
|
2356
|
-
// content: [
|
|
2357
|
-
// {
|
|
2358
|
-
// type: 'text' as const,
|
|
2359
|
-
// text: JSON.stringify(result),
|
|
2360
|
-
// },
|
|
2361
|
-
// ],
|
|
2362
|
-
// };
|
|
2363
|
-
// } else {
|
|
2364
|
-
// console.warn('TTS generation completed but no URL returned');
|
|
2365
|
-
// return {
|
|
2366
|
-
// content: [
|
|
2367
|
-
// {
|
|
2368
|
-
// type: 'text' as const,
|
|
2369
|
-
// text: JSON.stringify({
|
|
2370
|
-
// success: false,
|
|
2371
|
-
// error:
|
|
2372
|
-
// 'No TTS URL returned from AI service. You should use pick-voice tool to pick an available voice.',
|
|
2373
|
-
// response: res,
|
|
2374
|
-
// timestamp: new Date().toISOString(),
|
|
2375
|
-
// }),
|
|
2376
|
-
// },
|
|
2377
|
-
// ],
|
|
2378
|
-
// };
|
|
2379
|
-
// }
|
|
2380
|
-
// } catch (error) {
|
|
2381
|
-
// return createErrorResponse(error, 'generate-scene-tts');
|
|
2382
|
-
// }
|
|
2383
|
-
// }
|
|
2384
|
-
// );
|
|
2385
|
-
// server.registerTool(
|
|
2386
|
-
// 'compile-and-run',
|
|
2387
|
-
// {
|
|
2388
|
-
// title: 'Compile And Run',
|
|
2389
|
-
// description: 'Compile project to ffmpeg command and run it.',
|
|
2390
|
-
// inputSchema: {
|
|
2391
|
-
// projectFileName: z
|
|
2392
|
-
// .string()
|
|
2393
|
-
// .describe('The VideoProject configuration object.'),
|
|
2394
|
-
// outputFileName: z
|
|
2395
|
-
// .string()
|
|
2396
|
-
// .optional()
|
|
2397
|
-
// .describe('Output video filename (optional, defaults to output.mp4).'),
|
|
2398
|
-
// },
|
|
2399
|
-
// },
|
|
2400
|
-
// async ({ projectFileName, outputFileName }) => {
|
|
2401
|
-
// try {
|
|
2402
|
-
// // 验证session状态
|
|
2403
|
-
// const currentSession = await validateSession('compile-and-run');
|
|
2404
|
-
// // 检查字幕内容匹配标记
|
|
2405
|
-
// if (!checkStoryboardSubtitlesFlag) {
|
|
2406
|
-
// checkStoryboardSubtitlesFlag = true;
|
|
2407
|
-
// return createErrorResponse(
|
|
2408
|
-
// `请先对 draft_content 进行以下一致性检查:
|
|
2409
|
-
// 1. 检查字幕文字内容是否与 storyboard 中各个场景的 script 或 dialog 内容完全一致(⚠️ 允许字幕分段展示,只要最终文本保持一致就行)
|
|
2410
|
-
// 2. 检查视频 resolution 设定是否与 storyboard 的 orientation 设置一致,默认 720p 情况下视频尺寸应为横屏 1280x720,竖屏 720x1280,若视频为 1080p 则尺寸应分别为横屏 1920x1080 和竖屏 1080x1920,切勿设反
|
|
2411
|
-
// 3. 除非用户明确表示不要背景音乐,否则应检查是否有生成并配置了 BGM,若无,则生成 BGM 并将其加入素材和轨道配置
|
|
2412
|
-
// 以上检查任何一项有问题,先修复 draft_content 使其符合要求后再进行合成`,
|
|
2413
|
-
// 'compile-and-run'
|
|
2414
|
-
// );
|
|
2415
|
-
// }
|
|
2416
|
-
// console.log('Starting video compilation and rendering...');
|
|
2417
|
-
// // 验证terminal可用性
|
|
2418
|
-
// const terminal = currentSession.terminal;
|
|
2419
|
-
// if (!terminal) {
|
|
2420
|
-
// throw new Error('Terminal not available in current session');
|
|
2421
|
-
// }
|
|
2422
|
-
// const localProjectFile = resolve(
|
|
2423
|
-
// projectLocalDir,
|
|
2424
|
-
// basename(projectFileName)
|
|
2425
|
-
// );
|
|
2426
|
-
// const project = JSON.parse(await readFile(localProjectFile, 'utf-8'));
|
|
2427
|
-
// // 验证输出文件名安全性
|
|
2428
|
-
// const outFile = outputFileName || project.export.outFile || 'output.mp4';
|
|
2429
|
-
// const validatedFileName = validateFileName(outFile);
|
|
2430
|
-
// console.log(`Output file: ${validatedFileName}`);
|
|
2431
|
-
// // 构建工作目录路径
|
|
2432
|
-
// const workDir = `/home/user/cerevox-zerocut/projects/${terminal.id}`;
|
|
2433
|
-
// const outputDir = `${workDir}/output`;
|
|
2434
|
-
// const outputPath = `${outputDir}/${validatedFileName}`;
|
|
2435
|
-
// // Project已经通过zVideoProject schema验证
|
|
2436
|
-
// const validated = { ...project };
|
|
2437
|
-
// // 更新导出配置
|
|
2438
|
-
// validated.export = {
|
|
2439
|
-
// ...validated.export,
|
|
2440
|
-
// outFile: outputPath,
|
|
2441
|
-
// };
|
|
2442
|
-
// console.log('Compiling VideoProject to FFmpeg command...');
|
|
2443
|
-
// // 编译为FFmpeg命令
|
|
2444
|
-
// let compiled: CompileResult;
|
|
2445
|
-
// try {
|
|
2446
|
-
// compiled = await compileToFfmpeg(validated, {
|
|
2447
|
-
// workingDir: outputDir,
|
|
2448
|
-
// subtitleStrategy: 'ass',
|
|
2449
|
-
// subtitlesFileName: `${outFile.replace(/\.mp4$/, '')}.subtitles.ass`,
|
|
2450
|
-
// });
|
|
2451
|
-
// } catch (compileError) {
|
|
2452
|
-
// console.error('Failed to compile VideoProject:', compileError);
|
|
2453
|
-
// throw new Error(`Failed to compile VideoProject: ${compileError}`);
|
|
2454
|
-
// }
|
|
2455
|
-
// console.log(`FFmpeg command generated (${compiled.cmd.length} chars)`);
|
|
2456
|
-
// console.log('FFmpeg Command:', compiled.cmd.substring(0, 200) + '...');
|
|
2457
|
-
// // 执行FFmpeg命令
|
|
2458
|
-
// console.log('Executing FFmpeg command...');
|
|
2459
|
-
// const result = await runFfmpeg(currentSession, compiled);
|
|
2460
|
-
// if (result.exitCode === 0) {
|
|
2461
|
-
// console.log('Video compilation completed successfully');
|
|
2462
|
-
// // 自动下载输出文件
|
|
2463
|
-
// console.log('Starting automatic download of output files...');
|
|
2464
|
-
// let downloadResult = null;
|
|
2465
|
-
// try {
|
|
2466
|
-
// const workDir = `/home/user/cerevox-zerocut/projects/${terminal.id}/output`;
|
|
2467
|
-
// let outputs: string[] = [];
|
|
2468
|
-
// try {
|
|
2469
|
-
// outputs = (await currentSession.files.listFiles(workDir)) || [];
|
|
2470
|
-
// } catch (listError) {
|
|
2471
|
-
// console.warn('Failed to list output files:', listError);
|
|
2472
|
-
// outputs = [];
|
|
2473
|
-
// }
|
|
2474
|
-
// if (outputs.length > 0) {
|
|
2475
|
-
// const outputDir = resolve(
|
|
2476
|
-
// process.env.ZEROCUT_PROJECT_CWD || process.cwd(),
|
|
2477
|
-
// projectLocalDir,
|
|
2478
|
-
// 'output'
|
|
2479
|
-
// );
|
|
2480
|
-
// await mkdir(outputDir, { recursive: true });
|
|
2481
|
-
// const downloadErrors: string[] = [];
|
|
2482
|
-
// const successfulDownloads: string[] = [];
|
|
2483
|
-
// const promises = outputs.map(async output => {
|
|
2484
|
-
// try {
|
|
2485
|
-
// await currentSession.files.download(
|
|
2486
|
-
// `${workDir}/${output}`,
|
|
2487
|
-
// `${outputDir}/${output}`
|
|
2488
|
-
// );
|
|
2489
|
-
// successfulDownloads.push(output);
|
|
2490
|
-
// return output;
|
|
2491
|
-
// } catch (downloadError) {
|
|
2492
|
-
// const errorMsg = `Failed to download ${output}: ${downloadError}`;
|
|
2493
|
-
// console.error(errorMsg);
|
|
2494
|
-
// downloadErrors.push(errorMsg);
|
|
2495
|
-
// return null;
|
|
2496
|
-
// }
|
|
2497
|
-
// });
|
|
2498
|
-
// const results = await Promise.all(promises);
|
|
2499
|
-
// const sources = results.filter(
|
|
2500
|
-
// output => output !== null
|
|
2501
|
-
// ) as string[];
|
|
2502
|
-
// downloadResult = {
|
|
2503
|
-
// totalFiles: outputs.length,
|
|
2504
|
-
// successfulDownloads: sources.length,
|
|
2505
|
-
// failedDownloads: downloadErrors.length,
|
|
2506
|
-
// downloadErrors:
|
|
2507
|
-
// downloadErrors.length > 0 ? downloadErrors : undefined,
|
|
2508
|
-
// downloadPath: outputDir,
|
|
2509
|
-
// sources,
|
|
2510
|
-
// };
|
|
2511
|
-
// console.log(
|
|
2512
|
-
// `Download completed: ${sources.length}/${outputs.length} files successful`
|
|
2513
|
-
// );
|
|
2514
|
-
// } else {
|
|
2515
|
-
// console.log('No output files found to download');
|
|
2516
|
-
// downloadResult = {
|
|
2517
|
-
// totalFiles: 0,
|
|
2518
|
-
// successfulDownloads: 0,
|
|
2519
|
-
// failedDownloads: 0,
|
|
2520
|
-
// message: 'No output files found to download',
|
|
2521
|
-
// };
|
|
2522
|
-
// }
|
|
2523
|
-
// } catch (downloadError) {
|
|
2524
|
-
// console.error('Download process failed:', downloadError);
|
|
2525
|
-
// downloadResult = {
|
|
2526
|
-
// error: `Download failed: ${downloadError}`,
|
|
2527
|
-
// totalFiles: 0,
|
|
2528
|
-
// successfulDownloads: 0,
|
|
2529
|
-
// failedDownloads: 1,
|
|
2530
|
-
// };
|
|
2531
|
-
// }
|
|
2532
|
-
// const successResult = {
|
|
2533
|
-
// success: true,
|
|
2534
|
-
// outputPath,
|
|
2535
|
-
// outputFileName: validatedFileName,
|
|
2536
|
-
// command: compiled.cmd,
|
|
2537
|
-
// message: 'Video compilation and download completed successfully',
|
|
2538
|
-
// download: downloadResult,
|
|
2539
|
-
// timestamp: new Date().toISOString(),
|
|
2540
|
-
// };
|
|
2541
|
-
// return {
|
|
2542
|
-
// content: [
|
|
2543
|
-
// {
|
|
2544
|
-
// type: 'text' as const,
|
|
2545
|
-
// text: JSON.stringify(successResult),
|
|
2546
|
-
// },
|
|
2547
|
-
// ],
|
|
2548
|
-
// };
|
|
2549
|
-
// } else {
|
|
2550
|
-
// console.error(`FFmpeg failed with exit code: ${result.exitCode}`);
|
|
2551
|
-
// const failureResult = {
|
|
2552
|
-
// success: false,
|
|
2553
|
-
// exitCode: result.exitCode,
|
|
2554
|
-
// outputPath,
|
|
2555
|
-
// // command: compiled.cmd,
|
|
2556
|
-
// stderr: result.stderr,
|
|
2557
|
-
// message: `FFmpeg exited with code ${result.exitCode}`,
|
|
2558
|
-
// timestamp: new Date().toISOString(),
|
|
2559
|
-
// };
|
|
2560
|
-
// if (result.exitCode === 254) {
|
|
2561
|
-
// failureResult.message =
|
|
2562
|
-
// 'FFmpeg failed with code 254. Close current session immediately (inMinutes = 0) and re-open a new session to try again.';
|
|
2563
|
-
// }
|
|
2564
|
-
// return {
|
|
2565
|
-
// content: [
|
|
2566
|
-
// {
|
|
2567
|
-
// type: 'text' as const,
|
|
2568
|
-
// text: JSON.stringify(failureResult),
|
|
2569
|
-
// },
|
|
2570
|
-
// ],
|
|
2571
|
-
// };
|
|
2572
|
-
// }
|
|
2573
|
-
// } catch (error) {
|
|
2574
|
-
// return createErrorResponse(error, 'compile-and-run');
|
|
2575
|
-
// }
|
|
2576
|
-
// }
|
|
2577
|
-
// );
|
|
2578
|
-
// server.registerTool(
|
|
2579
|
-
// 'get-schema',
|
|
2580
|
-
// {
|
|
2581
|
-
// title: 'Get Storyboard Schema or Draft Content Schema',
|
|
2582
|
-
// description:
|
|
2583
|
-
// 'Get the complete Storyboard or Draft Content JSON Schema definition. Use this schema to validate storyboard.json or draft_content.json files.',
|
|
2584
|
-
// inputSchema: {
|
|
2585
|
-
// type: z
|
|
2586
|
-
// .enum(['storyboard', 'draft_content'])
|
|
2587
|
-
// .describe(
|
|
2588
|
-
// 'The type of schema to retrieve. Must be either "storyboard" or "draft_content". 用 type: storyboard 的 schema 生成 storyboard.json;用 type: draft_content 的 schema 生成 draft_content.json'
|
|
2589
|
-
// ),
|
|
2590
|
-
// },
|
|
2591
|
-
// },
|
|
2592
|
-
// async ({ type }) => {
|
|
2593
|
-
// try {
|
|
2594
|
-
// const schemaPath = resolve(__dirname, `./prompts/${type}-schema.json`);
|
|
2595
|
-
// const schemaContent = await readFile(schemaPath, 'utf-8');
|
|
2596
|
-
// const schema = JSON.parse(schemaContent);
|
|
2597
|
-
// let important_guidelines = '';
|
|
2598
|
-
// if (type === 'draft_content') {
|
|
2599
|
-
// important_guidelines = `⚠️ 生成文件时请严格遵守输出规范,字幕文本内容必须与 storyboard.json 中的 script(或dialog) 字段的文本内容完全一致。
|
|
2600
|
-
// ** 字幕优化 **
|
|
2601
|
-
// * 在保证字幕文本内容与 storyboard.json 中的 script(或dialog) 字段的文本内容完全一致的前提下,可根据 tts 返回的 \`captions.utterances\` 字段对字幕的显示进行优化,将过长的字幕分段显示,在 draft_content.json 中使用分段字幕,captions 的内容在 media_logs.json 中可查询到。
|
|
2602
|
-
// * 如用户未特殊指定,字幕样式(字体及大小)务必遵守输出规范
|
|
2603
|
-
// `;
|
|
2604
|
-
// }
|
|
2605
|
-
// return {
|
|
2606
|
-
// content: [
|
|
2607
|
-
// {
|
|
2608
|
-
// type: 'text' as const,
|
|
2609
|
-
// text: JSON.stringify({
|
|
2610
|
-
// success: true,
|
|
2611
|
-
// schema,
|
|
2612
|
-
// important_guidelines,
|
|
2613
|
-
// timestamp: new Date().toISOString(),
|
|
2614
|
-
// }),
|
|
2615
|
-
// },
|
|
2616
|
-
// ],
|
|
2617
|
-
// };
|
|
2618
|
-
// } catch (error) {
|
|
2619
|
-
// return createErrorResponse(error, 'get-schema');
|
|
2620
|
-
// }
|
|
2621
|
-
// }
|
|
2622
|
-
// );
|
|
2623
|
-
// server.registerTool(
|
|
2624
|
-
// 'pick-voice',
|
|
2625
|
-
// {
|
|
2626
|
-
// title: 'Pick Voice',
|
|
2627
|
-
// description:
|
|
2628
|
-
// '根据用户需求,选择尽可能符合要求的语音,在合适的情况下,优先采用 volcano_tts_2 类型的语音',
|
|
2629
|
-
// inputSchema: {
|
|
2630
|
-
// prompt: z
|
|
2631
|
-
// .string()
|
|
2632
|
-
// .describe('用户需求描述,例如:一个有亲和力的,适合给孩子讲故事的语音'),
|
|
2633
|
-
// custom_design: z
|
|
2634
|
-
// .boolean()
|
|
2635
|
-
// .optional()
|
|
2636
|
-
// .describe(
|
|
2637
|
-
// '是否自定义语音,由于要消耗较多积分,因此**只有用户明确要求自己设计语音**,才将该参数设为true'
|
|
2638
|
-
// ),
|
|
2639
|
-
// custom_design_preview: z
|
|
2640
|
-
// .string()
|
|
2641
|
-
// .optional()
|
|
2642
|
-
// .describe(
|
|
2643
|
-
// '用户自定义语音的预览文本,用于展示自定义语音的效果,只有 custom_design 为 true 时才需要'
|
|
2644
|
-
// ),
|
|
2645
|
-
// custom_design_save_to: z
|
|
2646
|
-
// .string()
|
|
2647
|
-
// .optional()
|
|
2648
|
-
// .describe(
|
|
2649
|
-
// '自定义语音的保存路径,例如:custom_voice.mp3 custom_voice_{id}.mp3'
|
|
2650
|
-
// ),
|
|
2651
|
-
// },
|
|
2652
|
-
// },
|
|
2653
|
-
// async ({
|
|
2654
|
-
// prompt,
|
|
2655
|
-
// custom_design,
|
|
2656
|
-
// custom_design_preview,
|
|
2657
|
-
// custom_design_save_to,
|
|
2658
|
-
// }) => {
|
|
2659
|
-
// try {
|
|
2660
|
-
// // 验证session状态
|
|
2661
|
-
// const currentSession = await validateSession('pick-voice');
|
|
2662
|
-
// const ai = currentSession.ai;
|
|
2663
|
-
// if (custom_design) {
|
|
2664
|
-
// if (!custom_design_preview) {
|
|
2665
|
-
// throw new Error(
|
|
2666
|
-
// 'custom_design_preview is required when custom_design is true'
|
|
2667
|
-
// );
|
|
2668
|
-
// }
|
|
2669
|
-
// const data = await currentSession.ai.voiceDesign({
|
|
2670
|
-
// prompt,
|
|
2671
|
-
// previewText: custom_design_preview,
|
|
2672
|
-
// });
|
|
2673
|
-
// if (data.voice_id) {
|
|
2674
|
-
// const trial_audio = data.trial_audio;
|
|
2675
|
-
// let uri = '';
|
|
2676
|
-
// if (trial_audio) {
|
|
2677
|
-
// uri = await saveMaterial(
|
|
2678
|
-
// currentSession,
|
|
2679
|
-
// trial_audio,
|
|
2680
|
-
// custom_design_save_to || `custom_voice_${data.voice_id}.mp3`
|
|
2681
|
-
// );
|
|
2682
|
-
// }
|
|
2683
|
-
// return {
|
|
2684
|
-
// content: [
|
|
2685
|
-
// {
|
|
2686
|
-
// type: 'text' as const,
|
|
2687
|
-
// text: JSON.stringify({
|
|
2688
|
-
// success: true,
|
|
2689
|
-
// ...data,
|
|
2690
|
-
// uri,
|
|
2691
|
-
// timestamp: new Date().toISOString(),
|
|
2692
|
-
// }),
|
|
2693
|
-
// },
|
|
2694
|
-
// ],
|
|
2695
|
-
// };
|
|
2696
|
-
// } else {
|
|
2697
|
-
// throw new Error(`Voice design failed, ${JSON.stringify(data)}`);
|
|
2698
|
-
// }
|
|
2699
|
-
// }
|
|
2700
|
-
// const data = await ai.pickVoice({ prompt });
|
|
2701
|
-
// return {
|
|
2702
|
-
// content: [
|
|
2703
|
-
// {
|
|
2704
|
-
// type: 'text' as const,
|
|
2705
|
-
// text: JSON.stringify({
|
|
2706
|
-
// success: true,
|
|
2707
|
-
// ...data,
|
|
2708
|
-
// timestamp: new Date().toISOString(),
|
|
2709
|
-
// }),
|
|
2710
|
-
// },
|
|
2711
|
-
// ],
|
|
2712
|
-
// };
|
|
2713
|
-
// } catch (error) {
|
|
2714
|
-
// return createErrorResponse(error, 'pick-voice');
|
|
2715
|
-
// }
|
|
2716
|
-
// }
|
|
2717
|
-
// );
|
|
2718
1957
|
let lastEffect = '';
|
|
2719
1958
|
server.registerTool('generate-video', {
|
|
2720
1959
|
title: 'Generate Video',
|
|
@@ -2722,12 +1961,12 @@ server.registerTool('generate-video', {
|
|
|
2722
1961
|
inputSchema: {
|
|
2723
1962
|
prompt: zod_1.z
|
|
2724
1963
|
.string()
|
|
2725
|
-
.describe('The prompt to generate. 一般要严格对应 storyboard
|
|
1964
|
+
.describe('The prompt to generate. 一般要严格对应 storyboard 中当前分镜的 video_prompt 字段描述;传这个参数时,若跳过了一致性检查,记得保留镜头切换语言,如“切镜至第二镜头”这样的指令不应当省略。'),
|
|
2726
1965
|
sceneIndex: zod_1.z
|
|
2727
1966
|
.number()
|
|
2728
1967
|
.min(1)
|
|
2729
1968
|
.optional()
|
|
2730
|
-
.describe('
|
|
1969
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
2731
1970
|
storyBoardFile: zod_1.z
|
|
2732
1971
|
.string()
|
|
2733
1972
|
.optional()
|
|
@@ -2823,7 +2062,7 @@ server.registerTool('generate-video', {
|
|
|
2823
2062
|
console.warn(`zero 模型的视频仅支持 1080p 分辨率,用户指定的分辨率为 %s,已自动将 ${resolution} 转换为 1080p`, resolution);
|
|
2824
2063
|
resolution = '1080p';
|
|
2825
2064
|
}
|
|
2826
|
-
// 校验 prompt 与 storyboard.json
|
|
2065
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性
|
|
2827
2066
|
if (sceneIndex && !skipConsistencyCheck) {
|
|
2828
2067
|
try {
|
|
2829
2068
|
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
@@ -2845,7 +2084,7 @@ server.registerTool('generate-video', {
|
|
|
2845
2084
|
return createErrorResponse('视频提示词必须严格遵照storyboard的设定,如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用', 'generate-video');
|
|
2846
2085
|
}
|
|
2847
2086
|
if (scene.is_continuous && !end_frame) {
|
|
2848
|
-
return createErrorResponse('
|
|
2087
|
+
return createErrorResponse('连续分镜必须指定end_frame参数,如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用', 'generate-video');
|
|
2849
2088
|
}
|
|
2850
2089
|
if (scene.video_duration != null &&
|
|
2851
2090
|
duration !== scene.video_duration) {
|
|
@@ -2854,14 +2093,14 @@ server.registerTool('generate-video', {
|
|
|
2854
2093
|
if (storyBoard.voice_type &&
|
|
2855
2094
|
storyBoard.voice_type !== 'slient') {
|
|
2856
2095
|
if (mute) {
|
|
2857
|
-
return createErrorResponse('
|
|
2096
|
+
return createErrorResponse('有对话和旁白的分镜不能静音,请将mute设为false再重新使用工具。如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用', 'generate-video');
|
|
2858
2097
|
}
|
|
2859
2098
|
}
|
|
2860
2099
|
// 检查 use_video_model 与 type 参数的一致性
|
|
2861
2100
|
if (scene.use_video_model &&
|
|
2862
2101
|
type &&
|
|
2863
2102
|
scene.use_video_model !== type) {
|
|
2864
|
-
return createErrorResponse(
|
|
2103
|
+
return createErrorResponse(`分镜建议的视频模型(${scene.use_video_model})与传入的type参数(${type})不一致。请确保use_video_model与type参数值相同,或将skipConsistencyCheck设置为true后再次调用`, 'generate-video');
|
|
2865
2104
|
}
|
|
2866
2105
|
}
|
|
2867
2106
|
else {
|
|
@@ -2877,60 +2116,6 @@ server.registerTool('generate-video', {
|
|
|
2877
2116
|
console.error('Failed to validate prompt with story board:', error);
|
|
2878
2117
|
// 如果读取或解析 storyboard.json 失败,继续执行但记录警告
|
|
2879
2118
|
}
|
|
2880
|
-
// 校验视频时长与 timeline_analysis.json 中 proposed_video_scenes 的匹配
|
|
2881
|
-
try {
|
|
2882
|
-
const timelineAnalysisPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'timeline_analysis.json');
|
|
2883
|
-
if ((0, node_fs_1.existsSync)(timelineAnalysisPath)) {
|
|
2884
|
-
const timelineAnalysisContent = await (0, promises_1.readFile)(timelineAnalysisPath, 'utf8');
|
|
2885
|
-
const timelineAnalysis = JSON.parse(timelineAnalysisContent);
|
|
2886
|
-
if (timelineAnalysis.proposed_video_scenes &&
|
|
2887
|
-
Array.isArray(timelineAnalysis.proposed_video_scenes)) {
|
|
2888
|
-
const videoScene = timelineAnalysis.proposed_video_scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2889
|
-
if (videoScene && videoScene.video_duration_s) {
|
|
2890
|
-
const expectedDuration = videoScene.video_duration_s;
|
|
2891
|
-
if (duration !== expectedDuration) {
|
|
2892
|
-
return createErrorResponse(`视频时长必须与timeline_analysis中的设定匹配。当前场景${videoScene.scene_id}要求时长为${expectedDuration}秒,但传入的duration为${duration}秒。请调整duration参数为${expectedDuration}秒后重试。如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用。`, 'generate-video');
|
|
2893
|
-
}
|
|
2894
|
-
}
|
|
2895
|
-
else {
|
|
2896
|
-
console.warn(`Scene ${sceneIndex} (scene_${sceneIndex.toString().padStart(2, '0')}) not found in timeline_analysis.json proposed_video_scenes`);
|
|
2897
|
-
}
|
|
2898
|
-
}
|
|
2899
|
-
}
|
|
2900
|
-
else {
|
|
2901
|
-
// 检查音频时长标志
|
|
2902
|
-
try {
|
|
2903
|
-
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
2904
|
-
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
2905
|
-
const storyBoardContent = await (0, promises_1.readFile)(storyBoardPath, 'utf8');
|
|
2906
|
-
const storyBoard = JSON.parse(storyBoardContent);
|
|
2907
|
-
if (storyBoard.scenes && Array.isArray(storyBoard.scenes)) {
|
|
2908
|
-
const scene = storyBoard.scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2909
|
-
if (scene &&
|
|
2910
|
-
((scene.script && scene.script.trim() !== '') ||
|
|
2911
|
-
scene.dialog)) {
|
|
2912
|
-
if (!checkAudioVideoDurationFlag) {
|
|
2913
|
-
checkAudioVideoDurationFlag = true;
|
|
2914
|
-
if (scene.audio_mode === 'vo_sync') {
|
|
2915
|
-
return createErrorResponse('请先自我检查 media_logs 中的音频时长,确保 storyboard 中视频时长为音频时长向上取整 即 ceil(音频时长),然后再按照正确的视频时长创建视频', 'generate-video');
|
|
2916
|
-
}
|
|
2917
|
-
else if (scene.audio_mode === 'dialogue') {
|
|
2918
|
-
return createErrorResponse('请先自我检查 media_logs 中的音频时长,确保 storyboard 中视频时长**不小于**音频时长向上取整 即 ceil(音频时长),然后再按照正确的视频时长创建视频', 'generate-video');
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
}
|
|
2922
|
-
}
|
|
2923
|
-
}
|
|
2924
|
-
}
|
|
2925
|
-
catch (error) {
|
|
2926
|
-
console.error('Failed to check audio duration flag:', error);
|
|
2927
|
-
}
|
|
2928
|
-
}
|
|
2929
|
-
}
|
|
2930
|
-
catch (error) {
|
|
2931
|
-
console.error('Failed to validate duration with timeline analysis:', error);
|
|
2932
|
-
// 如果读取或解析 timeline_analysis.json 失败,继续执行但记录警告
|
|
2933
|
-
}
|
|
2934
2119
|
}
|
|
2935
2120
|
const validatedFileName = validateFileName(saveToFileName);
|
|
2936
2121
|
console.log(`Generating video with prompt: ${prompt.substring(0, 100)}...`);
|
|
@@ -3652,7 +2837,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3652
2837
|
inputSchema: {
|
|
3653
2838
|
prompt: zod_1.z
|
|
3654
2839
|
.string()
|
|
3655
|
-
.describe('The prompt to generate video with or without reference images. 一般要严格对应 storyboard
|
|
2840
|
+
.describe('The prompt to generate video with or without reference images. 一般要严格对应 storyboard 中当前分镜的 video_prompt 字段描述;传这个参数时,若跳过了一致性检查,记得保留镜头切换语言,如“切镜至第二镜头”这样的指令不应当省略。'),
|
|
3656
2841
|
rewritePrompt: zod_1.z
|
|
3657
2842
|
.boolean()
|
|
3658
2843
|
.optional()
|
|
@@ -3713,7 +2898,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3713
2898
|
.number()
|
|
3714
2899
|
.min(1)
|
|
3715
2900
|
.optional()
|
|
3716
|
-
.describe('
|
|
2901
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
3717
2902
|
storyBoardFile: zod_1.z
|
|
3718
2903
|
.string()
|
|
3719
2904
|
.optional()
|
|
@@ -3745,24 +2930,9 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3745
2930
|
const outlineSheetImagePath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'materials', 'outline_sheet.png');
|
|
3746
2931
|
const hasOutlineSheet = (0, node_fs_1.existsSync)(outlineSheetImagePath);
|
|
3747
2932
|
if (hasOutlineSheet && !skipConsistencyCheck) {
|
|
3748
|
-
return createErrorResponse('
|
|
3749
|
-
}
|
|
3750
|
-
// 检查 storyboard 标志
|
|
3751
|
-
if (!hasOutlineSheet &&
|
|
3752
|
-
!checkStoryboardFlag &&
|
|
3753
|
-
(0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
3754
|
-
checkStoryboardFlag = true;
|
|
3755
|
-
return createErrorResponse(`必须先审查生成的 storyboard.json 内容,按照如下步骤:
|
|
3756
|
-
|
|
3757
|
-
1. 确保每个场景中的stage_atmosphere内容按照规则被正确融合到video_prompt中,不得遗漏
|
|
3758
|
-
2. 如有main_characters设定且包含了reference_image,或有reference_objects,需确保video_prompt描述已包含该场景相关main_characters和所有reference_objects中的物品或背景,并确保参考图具体内容已经在video_prompt中有明确描述,如果没有,可忽略。
|
|
3759
|
-
3. 如有配音,先自我检查 media_logs 中的查音频时长,确保以匹配音频时长来生成视频
|
|
3760
|
-
|
|
3761
|
-
检查完上述问题后先汇报,如果有需要,应当先修改 storyboard.json 内容,然后再调用 generate-video-by-ref 生成视频。注意修改 storyboard 内容时,仅修改相应字段的字符串值,不要破坏JSON格式!
|
|
3762
|
-
|
|
3763
|
-
再次调用 generate-video-by-ref 时,如需要参考图,要确保referenceImages使用正确(main_characters中的reference_image作为参考人物,reference_objects中的image作为参考物品或参考背景)`, 'generate-image');
|
|
2933
|
+
return createErrorResponse('监测到素材中存在outline_sheet.png这张图(由outline工具生成的),应采用 generate-video 图生视频。若用户明确要用参考生视频,则跳过一致性检查。', 'generate-video');
|
|
3764
2934
|
}
|
|
3765
|
-
// 校验 prompt 与 storyboard.json
|
|
2935
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性(如果提供了 sceneIndex)
|
|
3766
2936
|
if (!skipConsistencyCheck && sceneIndex) {
|
|
3767
2937
|
try {
|
|
3768
2938
|
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
@@ -3784,16 +2954,16 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3784
2954
|
}
|
|
3785
2955
|
// 检查 scene.is_continuous 是否为 true
|
|
3786
2956
|
if (scene.is_continuous === true) {
|
|
3787
|
-
return createErrorResponse('
|
|
2957
|
+
return createErrorResponse('连续镜头应使用首尾帧,请修改连续镜头设置,或将本分镜改为首尾帧方式实现', 'generate-video-by-ref');
|
|
3788
2958
|
}
|
|
3789
2959
|
if (scene.video_type !== 'references') {
|
|
3790
|
-
return createErrorResponse(
|
|
2960
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中的 video_type (${scene.video_type}) 未设置为 'references',不应当使用参考生视频,请使用图生视频 generate-video 方式生成`, 'generate-video-by-ref');
|
|
3791
2961
|
}
|
|
3792
2962
|
// 检查 use_video_model 与 type 参数的一致性
|
|
3793
2963
|
if (scene.use_video_model &&
|
|
3794
2964
|
type &&
|
|
3795
2965
|
scene.use_video_model !== type) {
|
|
3796
|
-
return createErrorResponse(
|
|
2966
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中的 use_video_model (${scene.use_video_model}) 必须与 type 参数 (${type}) 保持一致`, 'generate-video-by-ref');
|
|
3797
2967
|
}
|
|
3798
2968
|
// 检查 scene.references 的一致性
|
|
3799
2969
|
if (scene.references &&
|
|
@@ -3809,7 +2979,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3809
2979
|
const character = mainCharacters.find((char) => char.name === referenceName);
|
|
3810
2980
|
if (character) {
|
|
3811
2981
|
if (!character.reference_image) {
|
|
3812
|
-
return createErrorResponse(
|
|
2982
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的角色 "${referenceName}" 在 main_characters 中没有 reference_image 属性`, 'generate-video-by-ref');
|
|
3813
2983
|
}
|
|
3814
2984
|
requiredImage = character.reference_image;
|
|
3815
2985
|
found = true;
|
|
@@ -3819,7 +2989,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3819
2989
|
const refObject = referenceObjects.find((obj) => obj.name === referenceName);
|
|
3820
2990
|
if (refObject) {
|
|
3821
2991
|
if (!refObject.image) {
|
|
3822
|
-
return createErrorResponse(
|
|
2992
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的物品/背景 "${referenceName}" 在 reference_objects 中没有 image 属性`, 'generate-video-by-ref');
|
|
3823
2993
|
}
|
|
3824
2994
|
requiredImage = refObject.image;
|
|
3825
2995
|
found = true;
|
|
@@ -3827,11 +2997,11 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3827
2997
|
}
|
|
3828
2998
|
// 如果既不在 main_characters 也不在 reference_objects 中
|
|
3829
2999
|
if (!found) {
|
|
3830
|
-
return createErrorResponse(
|
|
3000
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的 "${referenceName}" 在 main_characters 或 reference_objects 中都找不到对应的定义`, 'generate-video-by-ref');
|
|
3831
3001
|
}
|
|
3832
3002
|
// 检查对应的图片是否在 referenceImages 参数中
|
|
3833
3003
|
if (!referenceImages.some(ref => ref.fileName === requiredImage)) {
|
|
3834
|
-
return createErrorResponse(
|
|
3004
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的 "${referenceName}" 对应的图片 "${requiredImage}" 不在 referenceImages 参数中,请确保传入正确的参考图片`, 'generate-video-by-ref');
|
|
3835
3005
|
}
|
|
3836
3006
|
}
|
|
3837
3007
|
}
|