cerevox 4.0.0-alpha.1 → 4.0.0-alpha.11
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/core/ai.d.ts +2 -0
- package/dist/core/ai.d.ts.map +1 -1
- package/dist/core/ai.js +11 -1
- package/dist/core/ai.js.map +1 -1
- package/dist/mcp/servers/prompts/outlines-backup.md +41 -14
- 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/prompts/skills//345/210/206/351/225/234/345/270/210.md +10 -8
- package/dist/mcp/servers/prompts/skills//347/264/240/346/235/220/345/210/233/344/275/234/357/274/210/351/200/232/347/224/250/357/274/211.md +1 -1
- package/dist/mcp/servers/prompts/zerocut-core.md +24 -0
- package/dist/mcp/servers/zerocut.d.ts.map +1 -1
- package/dist/mcp/servers/zerocut.js +75 -988
- 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-old.md} +0 -0
|
@@ -54,6 +54,7 @@ const node_fs_1 = require("node:fs");
|
|
|
54
54
|
const mp3_duration_1 = __importDefault(require("mp3-duration"));
|
|
55
55
|
const image_size_1 = __importDefault(require("image-size"));
|
|
56
56
|
const seed_1 = require("../../utils/seed");
|
|
57
|
+
const uuid_1 = require("uuid");
|
|
57
58
|
function createErrorResponse(error, operation, details) {
|
|
58
59
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
59
60
|
console.error(`[${operation}] Error:`, error);
|
|
@@ -140,6 +141,8 @@ async function saveMaterial(session, url, saveToFileName) {
|
|
|
140
141
|
const terminal = session.terminal;
|
|
141
142
|
const saveToPath = `/home/user/cerevox-zerocut/projects/${terminal.id}/materials/${saveToFileName}`;
|
|
142
143
|
const saveLocalPath = (0, node_path_1.resolve)(projectLocalDir, 'materials', saveToFileName);
|
|
144
|
+
// 确保目录存在
|
|
145
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(saveLocalPath), { recursive: true });
|
|
143
146
|
// 先下载到本地,再上传 sandbox,比直接 sandbox 更好,也以免下载超时
|
|
144
147
|
// 通过 fetch 下载到本地
|
|
145
148
|
const res = await fetch(url);
|
|
@@ -261,7 +264,7 @@ async function filterMaterialsForUpload(materials, projectLocalDir) {
|
|
|
261
264
|
regularFiles.push(material);
|
|
262
265
|
}
|
|
263
266
|
}
|
|
264
|
-
//
|
|
267
|
+
// 处理分镜文件(scXX_ 前缀)
|
|
265
268
|
if (sceneFiles.length > 0 && mediaLogs.length > 0) {
|
|
266
269
|
// 按前缀和扩展名分组
|
|
267
270
|
const groupedFiles = new Map();
|
|
@@ -309,7 +312,7 @@ async function filterMaterialsForUpload(materials, projectLocalDir) {
|
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
314
|
else {
|
|
312
|
-
// 如果没有 media_logs.json
|
|
315
|
+
// 如果没有 media_logs.json 或没有分镜文件,全部上传
|
|
313
316
|
filesToUpload.push(...sceneFiles);
|
|
314
317
|
}
|
|
315
318
|
// 处理普通文件(全量上传)
|
|
@@ -356,19 +359,14 @@ server.registerPrompt('zerocut-guideline', {
|
|
|
356
359
|
};
|
|
357
360
|
}
|
|
358
361
|
catch (error) {
|
|
359
|
-
console.error('Failed to load zerocut-guideline prompt:', error);
|
|
360
|
-
throw new Error(`Failed to load zerocut-guideline prompt: ${error}`);
|
|
362
|
+
console.error('Failed to load zerocut-guideline-web prompt:', error);
|
|
363
|
+
throw new Error(`Failed to load zerocut-guideline-web prompt: ${error}`);
|
|
361
364
|
}
|
|
362
365
|
});
|
|
363
366
|
server.registerTool('project-open', {
|
|
364
367
|
title: 'Open Project',
|
|
365
368
|
description: 'Launch a new Cerevox session with a Chromium browser instance and open a new project context. Supports smart file filtering to optimize upload performance.',
|
|
366
369
|
inputSchema: {
|
|
367
|
-
localDir: zod_1.z
|
|
368
|
-
.string()
|
|
369
|
-
.optional()
|
|
370
|
-
.default('.')
|
|
371
|
-
.describe('The path of the file to upload.'),
|
|
372
370
|
tosFiles: zod_1.z
|
|
373
371
|
.array(zod_1.z.string())
|
|
374
372
|
.optional()
|
|
@@ -380,7 +378,7 @@ server.registerTool('project-open', {
|
|
|
380
378
|
.default(false)
|
|
381
379
|
.describe('Whether to upload all files without filtering. If true, skips the smart filtering logic.'),
|
|
382
380
|
},
|
|
383
|
-
}, async ({
|
|
381
|
+
}, async ({ uploadAllFiles, tosFiles }, context) => {
|
|
384
382
|
try {
|
|
385
383
|
if (closeSessionTimerId) {
|
|
386
384
|
clearTimeout(closeSessionTimerId);
|
|
@@ -426,7 +424,13 @@ server.registerTool('project-open', {
|
|
|
426
424
|
}
|
|
427
425
|
console.log('Initializing project...');
|
|
428
426
|
const workDir = await initProject(session);
|
|
429
|
-
|
|
427
|
+
if (!process.env.ZEROCUT_PROJECT_CWD &&
|
|
428
|
+
!process.env.ZEROCUT_WORKSPACE_DIR) {
|
|
429
|
+
throw new Error('ZEROCUT_WORKSPACE_DIR environment variable is required');
|
|
430
|
+
}
|
|
431
|
+
projectLocalDir = process.env.ZEROCUT_PROJECT_CWD
|
|
432
|
+
? (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD, '.')
|
|
433
|
+
: (0, node_path_1.resolve)(process.env.ZEROCUT_WORKSPACE_DIR, (0, uuid_1.v4)());
|
|
430
434
|
const syncDir = (0, node_path_1.resolve)(projectLocalDir, 'materials');
|
|
431
435
|
try {
|
|
432
436
|
await (0, promises_1.mkdir)(syncDir, { recursive: true });
|
|
@@ -439,25 +443,23 @@ server.registerTool('project-open', {
|
|
|
439
443
|
// 文件过滤逻辑
|
|
440
444
|
let filesToUpload = [];
|
|
441
445
|
let skippedFiles = [];
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
skippedFiles = filterResult.skippedFiles;
|
|
460
|
-
}
|
|
446
|
+
try {
|
|
447
|
+
materials = await listFiles(syncDir);
|
|
448
|
+
}
|
|
449
|
+
catch (listError) {
|
|
450
|
+
console.warn('Failed to list materials:', listError);
|
|
451
|
+
materials = [];
|
|
452
|
+
}
|
|
453
|
+
if (uploadAllFiles) {
|
|
454
|
+
// 如果 uploadAllFiles 为 true,跳过智能过滤,上传所有文件
|
|
455
|
+
filesToUpload = materials;
|
|
456
|
+
skippedFiles = [];
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
// 智能文件过滤逻辑
|
|
460
|
+
const filterResult = await filterMaterialsForUpload(materials, projectLocalDir);
|
|
461
|
+
filesToUpload = filterResult.filesToUpload;
|
|
462
|
+
skippedFiles = filterResult.skippedFiles;
|
|
461
463
|
}
|
|
462
464
|
const files = session.files;
|
|
463
465
|
let progress = 0;
|
|
@@ -586,56 +588,6 @@ server.registerTool('retrieve-rules-context', {
|
|
|
586
588
|
const ai = currentSession.ai;
|
|
587
589
|
const { data: rules } = await ai.listContextRules();
|
|
588
590
|
if (!promptContent) {
|
|
589
|
-
const rulesList = rules
|
|
590
|
-
.filter((rule) => !rule.name.startsWith('skill-'))
|
|
591
|
-
.map((rule) => ({
|
|
592
|
-
name: rule.name,
|
|
593
|
-
trigger: rule.trigger,
|
|
594
|
-
}));
|
|
595
|
-
const chooseRulePrompt = `当前ZeroCut版本:${constants_1.VERSION}
|
|
596
|
-
|
|
597
|
-
请分析用户具体指令,匹配可用规则中的trigger,选择最合适的规则。
|
|
598
|
-
|
|
599
|
-
## 可用规则:
|
|
600
|
-
${JSON.stringify(rulesList, null, 2)}
|
|
601
|
-
|
|
602
|
-
请返回一个 JSON 字符串,包含用户意图对应的规则名称。格式为:{"rule_name": "规则名称"}
|
|
603
|
-
`;
|
|
604
|
-
const schema = {
|
|
605
|
-
name: 'choose_rule',
|
|
606
|
-
schema: {
|
|
607
|
-
type: 'object',
|
|
608
|
-
properties: {
|
|
609
|
-
rule_name: {
|
|
610
|
-
type: 'string',
|
|
611
|
-
description: '用户意图对应的规则名称',
|
|
612
|
-
},
|
|
613
|
-
},
|
|
614
|
-
required: ['rule_name'],
|
|
615
|
-
},
|
|
616
|
-
};
|
|
617
|
-
const completion = await ai.getCompletions({
|
|
618
|
-
model: 'Doubao-Seed-1.6-flash',
|
|
619
|
-
messages: [
|
|
620
|
-
{
|
|
621
|
-
role: 'system',
|
|
622
|
-
content: chooseRulePrompt,
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
role: 'user',
|
|
626
|
-
content: request,
|
|
627
|
-
},
|
|
628
|
-
],
|
|
629
|
-
response_format: {
|
|
630
|
-
type: 'json_schema',
|
|
631
|
-
json_schema: schema,
|
|
632
|
-
},
|
|
633
|
-
});
|
|
634
|
-
const ruleName = JSON.parse(completion.choices[0].message.content).rule_name;
|
|
635
|
-
// let rule = rules.find((rule: any) => rule.name === ruleName);
|
|
636
|
-
// if (!rule) {
|
|
637
|
-
// rule = rules.find((rule: any) => rule.name === '通用视频助手');
|
|
638
|
-
// }
|
|
639
591
|
const rule = rules.find((rule) => rule.name === 'core-rules');
|
|
640
592
|
promptContent = rule.prompt;
|
|
641
593
|
// 确保目录存在
|
|
@@ -1070,26 +1022,17 @@ server.registerTool('generate-image', {
|
|
|
1070
1022
|
.default('seedream-pro'),
|
|
1071
1023
|
prompt: zod_1.z
|
|
1072
1024
|
.string()
|
|
1073
|
-
.describe('The prompt to generate. 一般要严格对应 storyboard
|
|
1025
|
+
.describe('The prompt to generate. 一般要严格对应 storyboard 中当前分镜的 start_frame 或 end_frame 中的字段描述,如果是生成线稿,则 type 使用 line-sketch,如果是生成故事板印样或人物镜头宫格,则 type 使用 shot-grid'),
|
|
1074
1026
|
sceneIndex: zod_1.z
|
|
1075
1027
|
.number()
|
|
1076
1028
|
.min(1)
|
|
1077
1029
|
.optional()
|
|
1078
|
-
.describe('
|
|
1030
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
1079
1031
|
storyBoardFile: zod_1.z
|
|
1080
1032
|
.string()
|
|
1081
1033
|
.optional()
|
|
1082
1034
|
.default('storyboard.json')
|
|
1083
1035
|
.describe('故事板文件路径'),
|
|
1084
|
-
skipConsistencyCheck: zod_1.z
|
|
1085
|
-
.boolean()
|
|
1086
|
-
.optional()
|
|
1087
|
-
.default(false)
|
|
1088
|
-
.describe('是否跳过一致性检查,默认为false(即默认进行一致性检查)'),
|
|
1089
|
-
skipCheckWithSceneReason: zod_1.z
|
|
1090
|
-
.string()
|
|
1091
|
-
.optional()
|
|
1092
|
-
.describe('跳过校验的理由,如果skipConsistencyCheck设为true,必须要传这个参数'),
|
|
1093
1036
|
size: zod_1.z
|
|
1094
1037
|
.enum([
|
|
1095
1038
|
'1024x1024',
|
|
@@ -1174,22 +1117,15 @@ server.registerTool('generate-image', {
|
|
|
1174
1117
|
\`\`\`
|
|
1175
1118
|
`),
|
|
1176
1119
|
},
|
|
1177
|
-
}, async ({ type = 'seedream', prompt, sceneIndex, storyBoardFile = 'storyboard.json',
|
|
1120
|
+
}, async ({ type = 'seedream', prompt, sceneIndex, storyBoardFile = 'storyboard.json', size = '720x1280', imageCount = 1, saveToFileNames, watermark, referenceImages, }, context) => {
|
|
1178
1121
|
try {
|
|
1179
1122
|
// 验证session状态
|
|
1180
1123
|
const currentSession = await validateSession('generate-image');
|
|
1181
1124
|
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
1182
1125
|
const outlineSheetImagePath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'materials', 'outline_sheet.png');
|
|
1183
1126
|
const hasOutlineSheet = (0, node_fs_1.existsSync)(outlineSheetImagePath);
|
|
1184
|
-
//
|
|
1185
|
-
if (
|
|
1186
|
-
!checkStoryboardFlag &&
|
|
1187
|
-
(0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
1188
|
-
checkStoryboardFlag = true;
|
|
1189
|
-
return createErrorResponse('必须先审查生成的 storyboard.json 内容,确保每个场景中的stage_atmosphere内容按照规则被正确融合到start_frame和video_prompt中,不得遗漏,检查完成后先汇报,如果有问题,应当先修改 storyboard.json 内容,然后再调用 generate-image 生成图片。注意修改 storyboard 内容时,仅修改相应字段的字符串值,不要破坏JSON格式!', 'generate-image');
|
|
1190
|
-
}
|
|
1191
|
-
// 校验 prompt 与 storyboard.json 中场景设定的一致性
|
|
1192
|
-
if (sceneIndex && !skipConsistencyCheck) {
|
|
1127
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性
|
|
1128
|
+
if (sceneIndex) {
|
|
1193
1129
|
try {
|
|
1194
1130
|
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
1195
1131
|
const storyBoardContent = await (0, promises_1.readFile)(storyBoardPath, 'utf8');
|
|
@@ -1208,7 +1144,7 @@ server.registerTool('generate-image', {
|
|
|
1208
1144
|
const endFrame = scene.end_frame;
|
|
1209
1145
|
// 检查 prompt 是否严格等于 start_frame 或 end_frame
|
|
1210
1146
|
if (prompt !== startFrame && prompt !== endFrame) {
|
|
1211
|
-
return createErrorResponse('图片提示词必须严格遵照storyboard
|
|
1147
|
+
return createErrorResponse('图片提示词必须严格遵照storyboard的设定', 'generate-image');
|
|
1212
1148
|
}
|
|
1213
1149
|
if (hasOutlineSheet &&
|
|
1214
1150
|
(!referenceImages ||
|
|
@@ -1276,73 +1212,6 @@ server.registerTool('generate-image', {
|
|
|
1276
1212
|
// 检查并替换英文单引号包裹的中文内容为中文双引号
|
|
1277
1213
|
// 这样才能让 seedream 生成更好的中文文字
|
|
1278
1214
|
let processedPrompt = prompt.replace(/'([^']*[\u4e00-\u9fff][^']*)'/g, '“$1”');
|
|
1279
|
-
try {
|
|
1280
|
-
const ai = currentSession.ai;
|
|
1281
|
-
const promptOptimizer = await (0, promises_1.readFile)((0, node_path_1.resolve)(__dirname, './prompts/image-prompt-optimizer.md'), 'utf8');
|
|
1282
|
-
if (!hasOutlineSheet) {
|
|
1283
|
-
const schema = {
|
|
1284
|
-
name: 'optimize_image_prompt',
|
|
1285
|
-
schema: {
|
|
1286
|
-
type: 'object',
|
|
1287
|
-
properties: {
|
|
1288
|
-
prompt_optimized: {
|
|
1289
|
-
type: 'string',
|
|
1290
|
-
description: '优化后的提示词',
|
|
1291
|
-
},
|
|
1292
|
-
metaphor_modifiers: {
|
|
1293
|
-
type: 'array',
|
|
1294
|
-
description: '从 prompt_optimized 中抽取的所有比喻修饰词(字符串数组)',
|
|
1295
|
-
items: {
|
|
1296
|
-
type: 'string',
|
|
1297
|
-
description: '比喻性修饰词,例如 “如羽毛般轻盈”、“像晨雾一样柔和”',
|
|
1298
|
-
},
|
|
1299
|
-
},
|
|
1300
|
-
},
|
|
1301
|
-
required: ['prompt_optimized', 'metaphor_modifiers'],
|
|
1302
|
-
},
|
|
1303
|
-
};
|
|
1304
|
-
const completion = await ai.getCompletions({
|
|
1305
|
-
model: 'Doubao-Seed-1.6',
|
|
1306
|
-
messages: [
|
|
1307
|
-
{
|
|
1308
|
-
role: 'system',
|
|
1309
|
-
content: promptOptimizer,
|
|
1310
|
-
},
|
|
1311
|
-
{
|
|
1312
|
-
role: 'user',
|
|
1313
|
-
content: `## 用户指令
|
|
1314
|
-
|
|
1315
|
-
${processedPrompt.trim()}
|
|
1316
|
-
|
|
1317
|
-
## 参考图
|
|
1318
|
-
|
|
1319
|
-
${referenceImages?.map((ref, index) => `图${index + 1}:${ref.image}`).join('\n') || '无'}`,
|
|
1320
|
-
},
|
|
1321
|
-
],
|
|
1322
|
-
response_format: {
|
|
1323
|
-
type: 'json_schema',
|
|
1324
|
-
json_schema: schema,
|
|
1325
|
-
},
|
|
1326
|
-
});
|
|
1327
|
-
const optimizedPrompt = completion.choices[0]?.message?.content.trim();
|
|
1328
|
-
if (optimizedPrompt) {
|
|
1329
|
-
try {
|
|
1330
|
-
const { prompt_optimized, metaphor_modifiers } = JSON.parse(optimizedPrompt);
|
|
1331
|
-
processedPrompt = `${prompt_optimized}`;
|
|
1332
|
-
if (metaphor_modifiers?.length) {
|
|
1333
|
-
processedPrompt += `\n\n注意:下面这些是形象比喻,并不是输出内容。\n${metaphor_modifiers}`;
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
catch (ex) {
|
|
1337
|
-
console.error('Failed to parse optimized prompt:', ex);
|
|
1338
|
-
processedPrompt = optimizedPrompt;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
catch (error) {
|
|
1344
|
-
console.error('Failed to optimize prompt:', error);
|
|
1345
|
-
}
|
|
1346
1215
|
if (imageCount > 1) {
|
|
1347
1216
|
processedPrompt = `请生成${imageCount}张${size}大小的关联图片,每张图分别生成,不要拼接为大图 ${processedPrompt}`;
|
|
1348
1217
|
}
|
|
@@ -1415,7 +1284,7 @@ server.registerTool('generate-image', {
|
|
|
1415
1284
|
if (objectPrefix.length > 0) {
|
|
1416
1285
|
processedPrompt = `${objectPrefix.join('\n')}
|
|
1417
1286
|
|
|
1418
|
-
${turnaroundMessage}
|
|
1287
|
+
${turnaroundMessage}参考以上图片,执行以下绘图指令:
|
|
1419
1288
|
${processedPrompt}`.trim();
|
|
1420
1289
|
}
|
|
1421
1290
|
}
|
|
@@ -1452,7 +1321,7 @@ ${processedPrompt}`.trim();
|
|
|
1452
1321
|
];
|
|
1453
1322
|
}
|
|
1454
1323
|
else {
|
|
1455
|
-
//
|
|
1324
|
+
// 多图
|
|
1456
1325
|
uris = await Promise.all(res.urls.map((url, i) => {
|
|
1457
1326
|
if (!url)
|
|
1458
1327
|
return '';
|
|
@@ -1717,14 +1586,8 @@ server.registerTool('generate-short-video-outlines', {
|
|
|
1717
1586
|
voice_type,
|
|
1718
1587
|
scenes: scenes.map((scene) => {
|
|
1719
1588
|
let video_prompt = scene.video_prompt;
|
|
1720
|
-
if (video_prompt.includes('画外音')
|
|
1721
|
-
video_prompt.
|
|
1722
|
-
if (voiceover_tone) {
|
|
1723
|
-
video_prompt = video_prompt.replace(/画外音[::]\s*“([^”]*)”/g, `画外音(${voiceover_tone})镜头内所有角色都不言语,从远处传来广播声<广播开始>$1——</广播结束>`);
|
|
1724
|
-
}
|
|
1725
|
-
else {
|
|
1726
|
-
video_prompt = video_prompt.replace(/画外音[::]\s*“([^”]*)”/g, `镜头内所有角色都不言语,从远处传来广播声<广播开始>$1——</广播结束>`);
|
|
1727
|
-
}
|
|
1589
|
+
if (voiceover_tone && video_prompt.includes('画外音')) {
|
|
1590
|
+
video_prompt = video_prompt.replace(/画外音[::]/g, `画外音(${voiceover_tone}):`);
|
|
1728
1591
|
}
|
|
1729
1592
|
return {
|
|
1730
1593
|
...scene,
|
|
@@ -2076,722 +1939,22 @@ server.registerTool('text-to-speech', {
|
|
|
2076
1939
|
return createErrorResponse(error, 'text-to-speech');
|
|
2077
1940
|
}
|
|
2078
1941
|
});
|
|
2079
|
-
// server.registerTool(
|
|
2080
|
-
// 'generate-scene-tts',
|
|
2081
|
-
// {
|
|
2082
|
-
// title: 'Generate Scene TTS',
|
|
2083
|
-
// description: `生成场景配音`,
|
|
2084
|
-
// inputSchema: {
|
|
2085
|
-
// text: z.string().describe('The text to generate.'),
|
|
2086
|
-
// sceneIndex: z
|
|
2087
|
-
// .number()
|
|
2088
|
-
// .min(1)
|
|
2089
|
-
// .optional()
|
|
2090
|
-
// .describe(
|
|
2091
|
-
// '场景索引,从1开始的下标,如果非场景对应素材,则可不传,场景素材必传'
|
|
2092
|
-
// ),
|
|
2093
|
-
// storyBoardFile: z
|
|
2094
|
-
// .string()
|
|
2095
|
-
// .optional()
|
|
2096
|
-
// .default('storyboard.json')
|
|
2097
|
-
// .describe('故事板文件路径'),
|
|
2098
|
-
// skipConsistencyCheck: z
|
|
2099
|
-
// .boolean()
|
|
2100
|
-
// .optional()
|
|
2101
|
-
// .default(false)
|
|
2102
|
-
// .describe('是否跳过一致性检查,默认为false(即默认进行一致性检查)'),
|
|
2103
|
-
// skipCheckWithSceneReason: z
|
|
2104
|
-
// .string()
|
|
2105
|
-
// .optional()
|
|
2106
|
-
// .describe(
|
|
2107
|
-
// '跳过校验的理由,如果skipConsistencyCheck设为true,必须要传这个参数'
|
|
2108
|
-
// ),
|
|
2109
|
-
// saveToFileName: z
|
|
2110
|
-
// .string()
|
|
2111
|
-
// .describe('The filename to save. 应该是mp3文件'),
|
|
2112
|
-
// speed: z
|
|
2113
|
-
// .number()
|
|
2114
|
-
// .min(0.5)
|
|
2115
|
-
// .max(2)
|
|
2116
|
-
// .optional()
|
|
2117
|
-
// .default(1)
|
|
2118
|
-
// .describe('The speed of the tts.'),
|
|
2119
|
-
// pitch: z
|
|
2120
|
-
// .number()
|
|
2121
|
-
// .min(-12)
|
|
2122
|
-
// .max(12)
|
|
2123
|
-
// .optional()
|
|
2124
|
-
// .default(0)
|
|
2125
|
-
// .describe('The pitch of the tts.'),
|
|
2126
|
-
// volume: z
|
|
2127
|
-
// .number()
|
|
2128
|
-
// .min(0)
|
|
2129
|
-
// .max(10)
|
|
2130
|
-
// .optional()
|
|
2131
|
-
// .default(1.0)
|
|
2132
|
-
// .describe('The volume of the tts.'),
|
|
2133
|
-
// voiceID: z
|
|
2134
|
-
// .string()
|
|
2135
|
-
// .describe(
|
|
2136
|
-
// `适合作为视频配音的音色ID,除非用户指定,否则你必须确保已通过 pick-voice 工具挑选出真实存在的音色。`
|
|
2137
|
-
// ),
|
|
2138
|
-
// context_texts: z
|
|
2139
|
-
// .array(z.string())
|
|
2140
|
-
// .default([])
|
|
2141
|
-
// .describe(
|
|
2142
|
-
// `语音合成的辅助信息,用于模型对话式合成,能更好的体现语音情感
|
|
2143
|
-
// 可以探索,比如常见示例有以下几种:
|
|
2144
|
-
// 1. 语速调整
|
|
2145
|
-
// - context_texts: ["你可以说慢一点吗?"]
|
|
2146
|
-
// 2. 情绪/语气调整
|
|
2147
|
-
// - context_texts=["你可以用特别特别痛心的语气说话吗?"]
|
|
2148
|
-
// - context_texts=["嗯,你的语气再欢乐一点"]
|
|
2149
|
-
// 3. 音量调整
|
|
2150
|
-
// - context_texts=["你嗓门再小点。"]
|
|
2151
|
-
// 4. 音感调整
|
|
2152
|
-
// - context_texts=["你能用骄傲的语气来说话吗?"]
|
|
2153
|
-
// `
|
|
2154
|
-
// ),
|
|
2155
|
-
// explicit_language: z.enum(['zh', 'en', 'ja']).optional().default('zh'),
|
|
2156
|
-
// },
|
|
2157
|
-
// },
|
|
2158
|
-
// async ({
|
|
2159
|
-
// text,
|
|
2160
|
-
// sceneIndex,
|
|
2161
|
-
// storyBoardFile,
|
|
2162
|
-
// skipConsistencyCheck,
|
|
2163
|
-
// voiceID,
|
|
2164
|
-
// saveToFileName,
|
|
2165
|
-
// speed,
|
|
2166
|
-
// pitch,
|
|
2167
|
-
// volume,
|
|
2168
|
-
// context_texts,
|
|
2169
|
-
// explicit_language,
|
|
2170
|
-
// }) => {
|
|
2171
|
-
// try {
|
|
2172
|
-
// // 验证session状态
|
|
2173
|
-
// const currentSession = await validateSession('generate-scene-tts');
|
|
2174
|
-
// const validatedFileName = validateFileName(saveToFileName);
|
|
2175
|
-
// const finalSpeed = speed ?? 1;
|
|
2176
|
-
// volume = volume ?? 1;
|
|
2177
|
-
// const ai = currentSession.ai;
|
|
2178
|
-
// let scene = null;
|
|
2179
|
-
// // 校验 text 与 storyboard.json 中场景设定的一致性
|
|
2180
|
-
// if (sceneIndex && !skipConsistencyCheck) {
|
|
2181
|
-
// try {
|
|
2182
|
-
// const voice = (await ai.listVoices()).find(v => v.id === voiceID);
|
|
2183
|
-
// if (!voice) {
|
|
2184
|
-
// return createErrorResponse(
|
|
2185
|
-
// `Voice ${voiceID} not found in voice-list. Use pick-voice tool to pick an available voice. 若用户坚持要使用该音色,需跳过一致性检查。`,
|
|
2186
|
-
// 'generate-scene-tts'
|
|
2187
|
-
// );
|
|
2188
|
-
// }
|
|
2189
|
-
// const storyBoardPath = resolve(
|
|
2190
|
-
// process.env.ZEROCUT_PROJECT_CWD || process.cwd(),
|
|
2191
|
-
// projectLocalDir,
|
|
2192
|
-
// storyBoardFile
|
|
2193
|
-
// );
|
|
2194
|
-
// if (existsSync(storyBoardPath)) {
|
|
2195
|
-
// const storyBoardContent = await readFile(storyBoardPath, 'utf8');
|
|
2196
|
-
// // 检查 storyBoard JSON 语法合法性
|
|
2197
|
-
// let storyBoard;
|
|
2198
|
-
// try {
|
|
2199
|
-
// storyBoard = JSON.parse(storyBoardContent);
|
|
2200
|
-
// } catch (jsonError) {
|
|
2201
|
-
// return createErrorResponse(
|
|
2202
|
-
// `storyBoard 文件 ${storyBoardFile} 存在 JSON 语法错误,请修复后重试。错误详情: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`,
|
|
2203
|
-
// 'generate-scene-tts'
|
|
2204
|
-
// );
|
|
2205
|
-
// }
|
|
2206
|
-
// if (storyBoard.scenes && Array.isArray(storyBoard.scenes)) {
|
|
2207
|
-
// scene = storyBoard.scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2208
|
-
// if (scene) {
|
|
2209
|
-
// const script = scene.script;
|
|
2210
|
-
// let isValidText = false;
|
|
2211
|
-
// // 检查 text 是否严格等于 script
|
|
2212
|
-
// if (script && text === script) {
|
|
2213
|
-
// isValidText = true;
|
|
2214
|
-
// }
|
|
2215
|
-
// // 检查 text 是否严格等于 dialog 数组中某个元素的 script
|
|
2216
|
-
// if (
|
|
2217
|
-
// !isValidText &&
|
|
2218
|
-
// scene.dialog &&
|
|
2219
|
-
// Array.isArray(scene.dialog)
|
|
2220
|
-
// ) {
|
|
2221
|
-
// for (const dialogItem of scene.dialog) {
|
|
2222
|
-
// if (dialogItem.script && text === dialogItem.script) {
|
|
2223
|
-
// isValidText = true;
|
|
2224
|
-
// break;
|
|
2225
|
-
// }
|
|
2226
|
-
// }
|
|
2227
|
-
// }
|
|
2228
|
-
// if (!isValidText) {
|
|
2229
|
-
// return createErrorResponse(
|
|
2230
|
-
// '配音文本必须严格遵照storyboard的设定,如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用',
|
|
2231
|
-
// 'generate-scene-tts'
|
|
2232
|
-
// );
|
|
2233
|
-
// }
|
|
2234
|
-
// } else {
|
|
2235
|
-
// console.warn(
|
|
2236
|
-
// `Scene index ${sceneIndex} not found in storyboard.json`
|
|
2237
|
-
// );
|
|
2238
|
-
// }
|
|
2239
|
-
// }
|
|
2240
|
-
// } else {
|
|
2241
|
-
// console.warn(`Story board file not found: ${storyBoardPath}`);
|
|
2242
|
-
// }
|
|
2243
|
-
// } catch (error) {
|
|
2244
|
-
// console.error('Failed to validate text with story board:', error);
|
|
2245
|
-
// // 如果读取或解析 storyboard.json 失败,继续执行但记录警告
|
|
2246
|
-
// }
|
|
2247
|
-
// }
|
|
2248
|
-
// console.log(
|
|
2249
|
-
// `Generating TTS with voice: ${voiceID}, speed: ${finalSpeed}, text: ${text.substring(0, 100)}...`
|
|
2250
|
-
// );
|
|
2251
|
-
// if (voiceID.startsWith('BV0')) {
|
|
2252
|
-
// throw new Error(
|
|
2253
|
-
// `BV0* 系列音色已弃用,你必须通过 pick-voice 工具挑选一个真实存在的音色。`
|
|
2254
|
-
// );
|
|
2255
|
-
// }
|
|
2256
|
-
// const type =
|
|
2257
|
-
// voiceID.startsWith('zh_') ||
|
|
2258
|
-
// voiceID.startsWith('en_') ||
|
|
2259
|
-
// voiceID.startsWith('multi_') ||
|
|
2260
|
-
// voiceID.startsWith('saturn_') ||
|
|
2261
|
-
// voiceID.startsWith('ICL_')
|
|
2262
|
-
// ? 'volcano'
|
|
2263
|
-
// : 'minimax';
|
|
2264
|
-
// let res;
|
|
2265
|
-
// let emotion = 'auto';
|
|
2266
|
-
// if (type === 'volcano') {
|
|
2267
|
-
// volume = Math.max(Math.min(volume, 2.0), 0.5);
|
|
2268
|
-
// res = await ai.textToSpeechVolc({
|
|
2269
|
-
// text: text.trim(),
|
|
2270
|
-
// speaker: voiceID,
|
|
2271
|
-
// speed: Math.floor(100 * (finalSpeed - 1)),
|
|
2272
|
-
// volume: Math.floor(100 * (volume - 1)),
|
|
2273
|
-
// context_texts,
|
|
2274
|
-
// explicit_language,
|
|
2275
|
-
// voice_to_caption:
|
|
2276
|
-
// explicit_language === 'zh' || explicit_language === 'en',
|
|
2277
|
-
// });
|
|
2278
|
-
// } else {
|
|
2279
|
-
// emotion = 'neutral';
|
|
2280
|
-
// if (context_texts.length > 0) {
|
|
2281
|
-
// const prompt = `根据用户输入语音内容和上下文内容,从文字判断语音合理的情感,然后选择以下情感**之一**返回结果:
|
|
2282
|
-
// "happy", "sad", "angry", "fearful", "disgusted", "surprised", "calm", "fluent", "whisper", "neutral"
|
|
2283
|
-
// ## 要求
|
|
2284
|
-
// 输出 JSON 格式,包含一个 emotion 字段,值为以上情感之一。
|
|
2285
|
-
// `;
|
|
2286
|
-
// const schema = {
|
|
2287
|
-
// name: 'emotion_schema',
|
|
2288
|
-
// schema: {
|
|
2289
|
-
// type: 'object',
|
|
2290
|
-
// properties: {
|
|
2291
|
-
// emotion: {
|
|
2292
|
-
// type: 'string',
|
|
2293
|
-
// enum: [
|
|
2294
|
-
// 'neutral',
|
|
2295
|
-
// 'happy',
|
|
2296
|
-
// 'sad',
|
|
2297
|
-
// 'angry',
|
|
2298
|
-
// 'fearful',
|
|
2299
|
-
// 'disgusted',
|
|
2300
|
-
// 'surprised',
|
|
2301
|
-
// 'calm',
|
|
2302
|
-
// 'fluent',
|
|
2303
|
-
// 'whisper',
|
|
2304
|
-
// ],
|
|
2305
|
-
// description: '用户输入语音的情感',
|
|
2306
|
-
// },
|
|
2307
|
-
// },
|
|
2308
|
-
// required: ['emotion'],
|
|
2309
|
-
// },
|
|
2310
|
-
// };
|
|
2311
|
-
// const payload: any = {
|
|
2312
|
-
// model: 'Doubao-Seed-1.6',
|
|
2313
|
-
// messages: [
|
|
2314
|
-
// {
|
|
2315
|
-
// role: 'system',
|
|
2316
|
-
// content: prompt,
|
|
2317
|
-
// },
|
|
2318
|
-
// {
|
|
2319
|
-
// role: 'user',
|
|
2320
|
-
// content: `## 语音内容:
|
|
2321
|
-
// ${text.trim()}
|
|
2322
|
-
// ## 语音上下文
|
|
2323
|
-
// ${context_texts.join('\n')}
|
|
2324
|
-
// `,
|
|
2325
|
-
// },
|
|
2326
|
-
// ],
|
|
2327
|
-
// response_format: {
|
|
2328
|
-
// type: 'json_schema',
|
|
2329
|
-
// json_schema: schema,
|
|
2330
|
-
// },
|
|
2331
|
-
// };
|
|
2332
|
-
// const completion = await ai.getCompletions(payload);
|
|
2333
|
-
// const emotionObj = JSON.parse(
|
|
2334
|
-
// completion.choices[0]?.message?.content ?? '{}'
|
|
2335
|
-
// );
|
|
2336
|
-
// emotion = emotionObj.emotion ?? 'neutral';
|
|
2337
|
-
// }
|
|
2338
|
-
// res = await ai.textToSpeech({
|
|
2339
|
-
// text: text.trim(),
|
|
2340
|
-
// voiceName: voiceID,
|
|
2341
|
-
// speed: finalSpeed,
|
|
2342
|
-
// pitch,
|
|
2343
|
-
// volume,
|
|
2344
|
-
// emotion,
|
|
2345
|
-
// voice_to_caption:
|
|
2346
|
-
// explicit_language === 'zh' || explicit_language === 'en',
|
|
2347
|
-
// });
|
|
2348
|
-
// }
|
|
2349
|
-
// if (!res) {
|
|
2350
|
-
// throw new Error('Failed to generate TTS: no response from AI service');
|
|
2351
|
-
// }
|
|
2352
|
-
// if (res.url) {
|
|
2353
|
-
// console.log('TTS generated successfully, saving to materials...');
|
|
2354
|
-
// const { url, duration, ...opts } = res;
|
|
2355
|
-
// if (!skipConsistencyCheck && duration > 16) {
|
|
2356
|
-
// return createErrorResponse(
|
|
2357
|
-
// 'TTS duration exceeds 16 seconds, 建议调整文本长度、提升语速或拆分场景...,⚠️如简化文本内容或拆分文本,需要立即更新 storyboard 以保持内容同步!如仍要生成,可设置 skipConsistencyCheck 为 true,跳过一致性检查。',
|
|
2358
|
-
// 'generate-scene-tts'
|
|
2359
|
-
// );
|
|
2360
|
-
// }
|
|
2361
|
-
// if (!duration) {
|
|
2362
|
-
// return createErrorResponse(
|
|
2363
|
-
// 'TTS duration not returned from AI service',
|
|
2364
|
-
// 'generate-scene-tts'
|
|
2365
|
-
// );
|
|
2366
|
-
// }
|
|
2367
|
-
// const uri = await saveMaterial(currentSession, url, validatedFileName);
|
|
2368
|
-
// let warn = '';
|
|
2369
|
-
// if (scene) {
|
|
2370
|
-
// const minDur = Math.ceil(duration);
|
|
2371
|
-
// if (scene.audio_mode === 'vo_sync' && scene.duration !== minDur) {
|
|
2372
|
-
// warn = `场景${sceneIndex}设定的时长${scene.duration}秒与实际生成的语音时长${minDur}秒不一致,音画同步将有问题,建议修改场景时长为${minDur}秒`;
|
|
2373
|
-
// } else if (scene.duration < minDur) {
|
|
2374
|
-
// warn = `场景${sceneIndex}设定的时长${scene.duration}秒小于实际生成的语音时长${duration}秒,可能会导致场景结束时音频未播放完成,建议修改场景时长为${minDur}秒`;
|
|
2375
|
-
// }
|
|
2376
|
-
// }
|
|
2377
|
-
// const result = {
|
|
2378
|
-
// success: true,
|
|
2379
|
-
// warn,
|
|
2380
|
-
// source: url, // 方便调试
|
|
2381
|
-
// uri,
|
|
2382
|
-
// durationMs: Math.floor((duration || 0) * 1000),
|
|
2383
|
-
// text,
|
|
2384
|
-
// emotion,
|
|
2385
|
-
// context_texts,
|
|
2386
|
-
// voiceName: voiceID,
|
|
2387
|
-
// speed: finalSpeed,
|
|
2388
|
-
// timestamp: new Date().toISOString(),
|
|
2389
|
-
// ...opts,
|
|
2390
|
-
// };
|
|
2391
|
-
// // Update media_logs.json
|
|
2392
|
-
// try {
|
|
2393
|
-
// await updateMediaLogs(
|
|
2394
|
-
// currentSession,
|
|
2395
|
-
// validatedFileName,
|
|
2396
|
-
// result,
|
|
2397
|
-
// 'audio'
|
|
2398
|
-
// );
|
|
2399
|
-
// } catch (error) {
|
|
2400
|
-
// console.warn(
|
|
2401
|
-
// `Failed to update media_logs.json for ${validatedFileName}:`,
|
|
2402
|
-
// error
|
|
2403
|
-
// );
|
|
2404
|
-
// }
|
|
2405
|
-
// return {
|
|
2406
|
-
// content: [
|
|
2407
|
-
// {
|
|
2408
|
-
// type: 'text' as const,
|
|
2409
|
-
// text: JSON.stringify(result),
|
|
2410
|
-
// },
|
|
2411
|
-
// ],
|
|
2412
|
-
// };
|
|
2413
|
-
// } else {
|
|
2414
|
-
// console.warn('TTS generation completed but no URL returned');
|
|
2415
|
-
// return {
|
|
2416
|
-
// content: [
|
|
2417
|
-
// {
|
|
2418
|
-
// type: 'text' as const,
|
|
2419
|
-
// text: JSON.stringify({
|
|
2420
|
-
// success: false,
|
|
2421
|
-
// error:
|
|
2422
|
-
// 'No TTS URL returned from AI service. You should use pick-voice tool to pick an available voice.',
|
|
2423
|
-
// response: res,
|
|
2424
|
-
// timestamp: new Date().toISOString(),
|
|
2425
|
-
// }),
|
|
2426
|
-
// },
|
|
2427
|
-
// ],
|
|
2428
|
-
// };
|
|
2429
|
-
// }
|
|
2430
|
-
// } catch (error) {
|
|
2431
|
-
// return createErrorResponse(error, 'generate-scene-tts');
|
|
2432
|
-
// }
|
|
2433
|
-
// }
|
|
2434
|
-
// );
|
|
2435
|
-
// server.registerTool(
|
|
2436
|
-
// 'compile-and-run',
|
|
2437
|
-
// {
|
|
2438
|
-
// title: 'Compile And Run',
|
|
2439
|
-
// description: 'Compile project to ffmpeg command and run it.',
|
|
2440
|
-
// inputSchema: {
|
|
2441
|
-
// projectFileName: z
|
|
2442
|
-
// .string()
|
|
2443
|
-
// .describe('The VideoProject configuration object.'),
|
|
2444
|
-
// outputFileName: z
|
|
2445
|
-
// .string()
|
|
2446
|
-
// .optional()
|
|
2447
|
-
// .describe('Output video filename (optional, defaults to output.mp4).'),
|
|
2448
|
-
// },
|
|
2449
|
-
// },
|
|
2450
|
-
// async ({ projectFileName, outputFileName }) => {
|
|
2451
|
-
// try {
|
|
2452
|
-
// // 验证session状态
|
|
2453
|
-
// const currentSession = await validateSession('compile-and-run');
|
|
2454
|
-
// // 检查字幕内容匹配标记
|
|
2455
|
-
// if (!checkStoryboardSubtitlesFlag) {
|
|
2456
|
-
// checkStoryboardSubtitlesFlag = true;
|
|
2457
|
-
// return createErrorResponse(
|
|
2458
|
-
// `请先对 draft_content 进行以下一致性检查:
|
|
2459
|
-
// 1. 检查字幕文字内容是否与 storyboard 中各个场景的 script 或 dialog 内容完全一致(⚠️ 允许字幕分段展示,只要最终文本保持一致就行)
|
|
2460
|
-
// 2. 检查视频 resolution 设定是否与 storyboard 的 orientation 设置一致,默认 720p 情况下视频尺寸应为横屏 1280x720,竖屏 720x1280,若视频为 1080p 则尺寸应分别为横屏 1920x1080 和竖屏 1080x1920,切勿设反
|
|
2461
|
-
// 3. 除非用户明确表示不要背景音乐,否则应检查是否有生成并配置了 BGM,若无,则生成 BGM 并将其加入素材和轨道配置
|
|
2462
|
-
// 以上检查任何一项有问题,先修复 draft_content 使其符合要求后再进行合成`,
|
|
2463
|
-
// 'compile-and-run'
|
|
2464
|
-
// );
|
|
2465
|
-
// }
|
|
2466
|
-
// console.log('Starting video compilation and rendering...');
|
|
2467
|
-
// // 验证terminal可用性
|
|
2468
|
-
// const terminal = currentSession.terminal;
|
|
2469
|
-
// if (!terminal) {
|
|
2470
|
-
// throw new Error('Terminal not available in current session');
|
|
2471
|
-
// }
|
|
2472
|
-
// const localProjectFile = resolve(
|
|
2473
|
-
// projectLocalDir,
|
|
2474
|
-
// basename(projectFileName)
|
|
2475
|
-
// );
|
|
2476
|
-
// const project = JSON.parse(await readFile(localProjectFile, 'utf-8'));
|
|
2477
|
-
// // 验证输出文件名安全性
|
|
2478
|
-
// const outFile = outputFileName || project.export.outFile || 'output.mp4';
|
|
2479
|
-
// const validatedFileName = validateFileName(outFile);
|
|
2480
|
-
// console.log(`Output file: ${validatedFileName}`);
|
|
2481
|
-
// // 构建工作目录路径
|
|
2482
|
-
// const workDir = `/home/user/cerevox-zerocut/projects/${terminal.id}`;
|
|
2483
|
-
// const outputDir = `${workDir}/output`;
|
|
2484
|
-
// const outputPath = `${outputDir}/${validatedFileName}`;
|
|
2485
|
-
// // Project已经通过zVideoProject schema验证
|
|
2486
|
-
// const validated = { ...project };
|
|
2487
|
-
// // 更新导出配置
|
|
2488
|
-
// validated.export = {
|
|
2489
|
-
// ...validated.export,
|
|
2490
|
-
// outFile: outputPath,
|
|
2491
|
-
// };
|
|
2492
|
-
// console.log('Compiling VideoProject to FFmpeg command...');
|
|
2493
|
-
// // 编译为FFmpeg命令
|
|
2494
|
-
// let compiled: CompileResult;
|
|
2495
|
-
// try {
|
|
2496
|
-
// compiled = await compileToFfmpeg(validated, {
|
|
2497
|
-
// workingDir: outputDir,
|
|
2498
|
-
// subtitleStrategy: 'ass',
|
|
2499
|
-
// subtitlesFileName: `${outFile.replace(/\.mp4$/, '')}.subtitles.ass`,
|
|
2500
|
-
// });
|
|
2501
|
-
// } catch (compileError) {
|
|
2502
|
-
// console.error('Failed to compile VideoProject:', compileError);
|
|
2503
|
-
// throw new Error(`Failed to compile VideoProject: ${compileError}`);
|
|
2504
|
-
// }
|
|
2505
|
-
// console.log(`FFmpeg command generated (${compiled.cmd.length} chars)`);
|
|
2506
|
-
// console.log('FFmpeg Command:', compiled.cmd.substring(0, 200) + '...');
|
|
2507
|
-
// // 执行FFmpeg命令
|
|
2508
|
-
// console.log('Executing FFmpeg command...');
|
|
2509
|
-
// const result = await runFfmpeg(currentSession, compiled);
|
|
2510
|
-
// if (result.exitCode === 0) {
|
|
2511
|
-
// console.log('Video compilation completed successfully');
|
|
2512
|
-
// // 自动下载输出文件
|
|
2513
|
-
// console.log('Starting automatic download of output files...');
|
|
2514
|
-
// let downloadResult = null;
|
|
2515
|
-
// try {
|
|
2516
|
-
// const workDir = `/home/user/cerevox-zerocut/projects/${terminal.id}/output`;
|
|
2517
|
-
// let outputs: string[] = [];
|
|
2518
|
-
// try {
|
|
2519
|
-
// outputs = (await currentSession.files.listFiles(workDir)) || [];
|
|
2520
|
-
// } catch (listError) {
|
|
2521
|
-
// console.warn('Failed to list output files:', listError);
|
|
2522
|
-
// outputs = [];
|
|
2523
|
-
// }
|
|
2524
|
-
// if (outputs.length > 0) {
|
|
2525
|
-
// const outputDir = resolve(
|
|
2526
|
-
// process.env.ZEROCUT_PROJECT_CWD || process.cwd(),
|
|
2527
|
-
// projectLocalDir,
|
|
2528
|
-
// 'output'
|
|
2529
|
-
// );
|
|
2530
|
-
// await mkdir(outputDir, { recursive: true });
|
|
2531
|
-
// const downloadErrors: string[] = [];
|
|
2532
|
-
// const successfulDownloads: string[] = [];
|
|
2533
|
-
// const promises = outputs.map(async output => {
|
|
2534
|
-
// try {
|
|
2535
|
-
// await currentSession.files.download(
|
|
2536
|
-
// `${workDir}/${output}`,
|
|
2537
|
-
// `${outputDir}/${output}`
|
|
2538
|
-
// );
|
|
2539
|
-
// successfulDownloads.push(output);
|
|
2540
|
-
// return output;
|
|
2541
|
-
// } catch (downloadError) {
|
|
2542
|
-
// const errorMsg = `Failed to download ${output}: ${downloadError}`;
|
|
2543
|
-
// console.error(errorMsg);
|
|
2544
|
-
// downloadErrors.push(errorMsg);
|
|
2545
|
-
// return null;
|
|
2546
|
-
// }
|
|
2547
|
-
// });
|
|
2548
|
-
// const results = await Promise.all(promises);
|
|
2549
|
-
// const sources = results.filter(
|
|
2550
|
-
// output => output !== null
|
|
2551
|
-
// ) as string[];
|
|
2552
|
-
// downloadResult = {
|
|
2553
|
-
// totalFiles: outputs.length,
|
|
2554
|
-
// successfulDownloads: sources.length,
|
|
2555
|
-
// failedDownloads: downloadErrors.length,
|
|
2556
|
-
// downloadErrors:
|
|
2557
|
-
// downloadErrors.length > 0 ? downloadErrors : undefined,
|
|
2558
|
-
// downloadPath: outputDir,
|
|
2559
|
-
// sources,
|
|
2560
|
-
// };
|
|
2561
|
-
// console.log(
|
|
2562
|
-
// `Download completed: ${sources.length}/${outputs.length} files successful`
|
|
2563
|
-
// );
|
|
2564
|
-
// } else {
|
|
2565
|
-
// console.log('No output files found to download');
|
|
2566
|
-
// downloadResult = {
|
|
2567
|
-
// totalFiles: 0,
|
|
2568
|
-
// successfulDownloads: 0,
|
|
2569
|
-
// failedDownloads: 0,
|
|
2570
|
-
// message: 'No output files found to download',
|
|
2571
|
-
// };
|
|
2572
|
-
// }
|
|
2573
|
-
// } catch (downloadError) {
|
|
2574
|
-
// console.error('Download process failed:', downloadError);
|
|
2575
|
-
// downloadResult = {
|
|
2576
|
-
// error: `Download failed: ${downloadError}`,
|
|
2577
|
-
// totalFiles: 0,
|
|
2578
|
-
// successfulDownloads: 0,
|
|
2579
|
-
// failedDownloads: 1,
|
|
2580
|
-
// };
|
|
2581
|
-
// }
|
|
2582
|
-
// const successResult = {
|
|
2583
|
-
// success: true,
|
|
2584
|
-
// outputPath,
|
|
2585
|
-
// outputFileName: validatedFileName,
|
|
2586
|
-
// command: compiled.cmd,
|
|
2587
|
-
// message: 'Video compilation and download completed successfully',
|
|
2588
|
-
// download: downloadResult,
|
|
2589
|
-
// timestamp: new Date().toISOString(),
|
|
2590
|
-
// };
|
|
2591
|
-
// return {
|
|
2592
|
-
// content: [
|
|
2593
|
-
// {
|
|
2594
|
-
// type: 'text' as const,
|
|
2595
|
-
// text: JSON.stringify(successResult),
|
|
2596
|
-
// },
|
|
2597
|
-
// ],
|
|
2598
|
-
// };
|
|
2599
|
-
// } else {
|
|
2600
|
-
// console.error(`FFmpeg failed with exit code: ${result.exitCode}`);
|
|
2601
|
-
// const failureResult = {
|
|
2602
|
-
// success: false,
|
|
2603
|
-
// exitCode: result.exitCode,
|
|
2604
|
-
// outputPath,
|
|
2605
|
-
// // command: compiled.cmd,
|
|
2606
|
-
// stderr: result.stderr,
|
|
2607
|
-
// message: `FFmpeg exited with code ${result.exitCode}`,
|
|
2608
|
-
// timestamp: new Date().toISOString(),
|
|
2609
|
-
// };
|
|
2610
|
-
// if (result.exitCode === 254) {
|
|
2611
|
-
// failureResult.message =
|
|
2612
|
-
// 'FFmpeg failed with code 254. Close current session immediately (inMinutes = 0) and re-open a new session to try again.';
|
|
2613
|
-
// }
|
|
2614
|
-
// return {
|
|
2615
|
-
// content: [
|
|
2616
|
-
// {
|
|
2617
|
-
// type: 'text' as const,
|
|
2618
|
-
// text: JSON.stringify(failureResult),
|
|
2619
|
-
// },
|
|
2620
|
-
// ],
|
|
2621
|
-
// };
|
|
2622
|
-
// }
|
|
2623
|
-
// } catch (error) {
|
|
2624
|
-
// return createErrorResponse(error, 'compile-and-run');
|
|
2625
|
-
// }
|
|
2626
|
-
// }
|
|
2627
|
-
// );
|
|
2628
|
-
// server.registerTool(
|
|
2629
|
-
// 'get-schema',
|
|
2630
|
-
// {
|
|
2631
|
-
// title: 'Get Storyboard Schema or Draft Content Schema',
|
|
2632
|
-
// description:
|
|
2633
|
-
// 'Get the complete Storyboard or Draft Content JSON Schema definition. Use this schema to validate storyboard.json or draft_content.json files.',
|
|
2634
|
-
// inputSchema: {
|
|
2635
|
-
// type: z
|
|
2636
|
-
// .enum(['storyboard', 'draft_content'])
|
|
2637
|
-
// .describe(
|
|
2638
|
-
// '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'
|
|
2639
|
-
// ),
|
|
2640
|
-
// },
|
|
2641
|
-
// },
|
|
2642
|
-
// async ({ type }) => {
|
|
2643
|
-
// try {
|
|
2644
|
-
// const schemaPath = resolve(__dirname, `./prompts/${type}-schema.json`);
|
|
2645
|
-
// const schemaContent = await readFile(schemaPath, 'utf-8');
|
|
2646
|
-
// const schema = JSON.parse(schemaContent);
|
|
2647
|
-
// let important_guidelines = '';
|
|
2648
|
-
// if (type === 'draft_content') {
|
|
2649
|
-
// important_guidelines = `⚠️ 生成文件时请严格遵守输出规范,字幕文本内容必须与 storyboard.json 中的 script(或dialog) 字段的文本内容完全一致。
|
|
2650
|
-
// ** 字幕优化 **
|
|
2651
|
-
// * 在保证字幕文本内容与 storyboard.json 中的 script(或dialog) 字段的文本内容完全一致的前提下,可根据 tts 返回的 \`captions.utterances\` 字段对字幕的显示进行优化,将过长的字幕分段显示,在 draft_content.json 中使用分段字幕,captions 的内容在 media_logs.json 中可查询到。
|
|
2652
|
-
// * 如用户未特殊指定,字幕样式(字体及大小)务必遵守输出规范
|
|
2653
|
-
// `;
|
|
2654
|
-
// }
|
|
2655
|
-
// return {
|
|
2656
|
-
// content: [
|
|
2657
|
-
// {
|
|
2658
|
-
// type: 'text' as const,
|
|
2659
|
-
// text: JSON.stringify({
|
|
2660
|
-
// success: true,
|
|
2661
|
-
// schema,
|
|
2662
|
-
// important_guidelines,
|
|
2663
|
-
// timestamp: new Date().toISOString(),
|
|
2664
|
-
// }),
|
|
2665
|
-
// },
|
|
2666
|
-
// ],
|
|
2667
|
-
// };
|
|
2668
|
-
// } catch (error) {
|
|
2669
|
-
// return createErrorResponse(error, 'get-schema');
|
|
2670
|
-
// }
|
|
2671
|
-
// }
|
|
2672
|
-
// );
|
|
2673
|
-
// server.registerTool(
|
|
2674
|
-
// 'pick-voice',
|
|
2675
|
-
// {
|
|
2676
|
-
// title: 'Pick Voice',
|
|
2677
|
-
// description:
|
|
2678
|
-
// '根据用户需求,选择尽可能符合要求的语音,在合适的情况下,优先采用 volcano_tts_2 类型的语音',
|
|
2679
|
-
// inputSchema: {
|
|
2680
|
-
// prompt: z
|
|
2681
|
-
// .string()
|
|
2682
|
-
// .describe('用户需求描述,例如:一个有亲和力的,适合给孩子讲故事的语音'),
|
|
2683
|
-
// custom_design: z
|
|
2684
|
-
// .boolean()
|
|
2685
|
-
// .optional()
|
|
2686
|
-
// .describe(
|
|
2687
|
-
// '是否自定义语音,由于要消耗较多积分,因此**只有用户明确要求自己设计语音**,才将该参数设为true'
|
|
2688
|
-
// ),
|
|
2689
|
-
// custom_design_preview: z
|
|
2690
|
-
// .string()
|
|
2691
|
-
// .optional()
|
|
2692
|
-
// .describe(
|
|
2693
|
-
// '用户自定义语音的预览文本,用于展示自定义语音的效果,只有 custom_design 为 true 时才需要'
|
|
2694
|
-
// ),
|
|
2695
|
-
// custom_design_save_to: z
|
|
2696
|
-
// .string()
|
|
2697
|
-
// .optional()
|
|
2698
|
-
// .describe(
|
|
2699
|
-
// '自定义语音的保存路径,例如:custom_voice.mp3 custom_voice_{id}.mp3'
|
|
2700
|
-
// ),
|
|
2701
|
-
// },
|
|
2702
|
-
// },
|
|
2703
|
-
// async ({
|
|
2704
|
-
// prompt,
|
|
2705
|
-
// custom_design,
|
|
2706
|
-
// custom_design_preview,
|
|
2707
|
-
// custom_design_save_to,
|
|
2708
|
-
// }) => {
|
|
2709
|
-
// try {
|
|
2710
|
-
// // 验证session状态
|
|
2711
|
-
// const currentSession = await validateSession('pick-voice');
|
|
2712
|
-
// const ai = currentSession.ai;
|
|
2713
|
-
// if (custom_design) {
|
|
2714
|
-
// if (!custom_design_preview) {
|
|
2715
|
-
// throw new Error(
|
|
2716
|
-
// 'custom_design_preview is required when custom_design is true'
|
|
2717
|
-
// );
|
|
2718
|
-
// }
|
|
2719
|
-
// const data = await currentSession.ai.voiceDesign({
|
|
2720
|
-
// prompt,
|
|
2721
|
-
// previewText: custom_design_preview,
|
|
2722
|
-
// });
|
|
2723
|
-
// if (data.voice_id) {
|
|
2724
|
-
// const trial_audio = data.trial_audio;
|
|
2725
|
-
// let uri = '';
|
|
2726
|
-
// if (trial_audio) {
|
|
2727
|
-
// uri = await saveMaterial(
|
|
2728
|
-
// currentSession,
|
|
2729
|
-
// trial_audio,
|
|
2730
|
-
// custom_design_save_to || `custom_voice_${data.voice_id}.mp3`
|
|
2731
|
-
// );
|
|
2732
|
-
// }
|
|
2733
|
-
// return {
|
|
2734
|
-
// content: [
|
|
2735
|
-
// {
|
|
2736
|
-
// type: 'text' as const,
|
|
2737
|
-
// text: JSON.stringify({
|
|
2738
|
-
// success: true,
|
|
2739
|
-
// ...data,
|
|
2740
|
-
// uri,
|
|
2741
|
-
// timestamp: new Date().toISOString(),
|
|
2742
|
-
// }),
|
|
2743
|
-
// },
|
|
2744
|
-
// ],
|
|
2745
|
-
// };
|
|
2746
|
-
// } else {
|
|
2747
|
-
// throw new Error(`Voice design failed, ${JSON.stringify(data)}`);
|
|
2748
|
-
// }
|
|
2749
|
-
// }
|
|
2750
|
-
// const data = await ai.pickVoice({ prompt });
|
|
2751
|
-
// return {
|
|
2752
|
-
// content: [
|
|
2753
|
-
// {
|
|
2754
|
-
// type: 'text' as const,
|
|
2755
|
-
// text: JSON.stringify({
|
|
2756
|
-
// success: true,
|
|
2757
|
-
// ...data,
|
|
2758
|
-
// timestamp: new Date().toISOString(),
|
|
2759
|
-
// }),
|
|
2760
|
-
// },
|
|
2761
|
-
// ],
|
|
2762
|
-
// };
|
|
2763
|
-
// } catch (error) {
|
|
2764
|
-
// return createErrorResponse(error, 'pick-voice');
|
|
2765
|
-
// }
|
|
2766
|
-
// }
|
|
2767
|
-
// );
|
|
2768
1942
|
let lastEffect = '';
|
|
2769
1943
|
server.registerTool('generate-video', {
|
|
2770
1944
|
title: 'Generate Video',
|
|
2771
1945
|
description: `图生视频和首尾帧生视频工具`,
|
|
2772
1946
|
inputSchema: {
|
|
2773
|
-
prompt: zod_1.z
|
|
2774
|
-
.string()
|
|
2775
|
-
.describe('The prompt to generate. 一般要严格对应 storyboard 中当前场景的 video_prompt 字段描述;传这个参数时,若跳过了一致性检查,记得保留镜头切换语言,如“切镜至第二镜头”这样的指令不应当省略。'),
|
|
1947
|
+
prompt: zod_1.z.string().describe('The prompt to generate. '),
|
|
2776
1948
|
sceneIndex: zod_1.z
|
|
2777
1949
|
.number()
|
|
2778
1950
|
.min(1)
|
|
2779
1951
|
.optional()
|
|
2780
|
-
.describe('
|
|
1952
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
2781
1953
|
storyBoardFile: zod_1.z
|
|
2782
1954
|
.string()
|
|
2783
1955
|
.optional()
|
|
2784
1956
|
.default('storyboard.json')
|
|
2785
1957
|
.describe('故事板文件路径'),
|
|
2786
|
-
skipConsistencyCheck: zod_1.z
|
|
2787
|
-
.boolean()
|
|
2788
|
-
.optional()
|
|
2789
|
-
.default(false)
|
|
2790
|
-
.describe('是否跳过一致性检查,默认为false(即默认进行一致性检查)'),
|
|
2791
|
-
skipCheckWithSceneReason: zod_1.z
|
|
2792
|
-
.string()
|
|
2793
|
-
.optional()
|
|
2794
|
-
.describe('跳过校验的理由,如果skipConsistencyCheck设为true,必须要传这个参数'),
|
|
2795
1958
|
type: zod_1.z
|
|
2796
1959
|
.enum([
|
|
2797
1960
|
'pro',
|
|
@@ -2852,7 +2015,7 @@ server.registerTool('generate-video', {
|
|
|
2852
2015
|
.default(false)
|
|
2853
2016
|
.describe('Whether to optimize the prompt.'),
|
|
2854
2017
|
},
|
|
2855
|
-
}, async ({ prompt, sceneIndex, storyBoardFile = 'storyboard.json',
|
|
2018
|
+
}, async ({ prompt, sceneIndex, storyBoardFile = 'storyboard.json', saveToFileName, start_frame, end_frame, duration, resolution, type = 'vidu', optimizePrompt, saveLastFrameAs, mute = true, seed, }, context) => {
|
|
2856
2019
|
try {
|
|
2857
2020
|
// 验证session状态
|
|
2858
2021
|
const currentSession = await validateSession('generate-video');
|
|
@@ -2873,8 +2036,8 @@ server.registerTool('generate-video', {
|
|
|
2873
2036
|
console.warn(`zero 模型的视频仅支持 1080p 分辨率,用户指定的分辨率为 %s,已自动将 ${resolution} 转换为 1080p`, resolution);
|
|
2874
2037
|
resolution = '1080p';
|
|
2875
2038
|
}
|
|
2876
|
-
// 校验 prompt 与 storyboard.json
|
|
2877
|
-
if (sceneIndex
|
|
2039
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性
|
|
2040
|
+
if (sceneIndex) {
|
|
2878
2041
|
try {
|
|
2879
2042
|
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
2880
2043
|
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
@@ -2892,26 +2055,26 @@ server.registerTool('generate-video', {
|
|
|
2892
2055
|
if (scene) {
|
|
2893
2056
|
const videoPrompt = scene.video_prompt;
|
|
2894
2057
|
if (videoPrompt && prompt !== videoPrompt) {
|
|
2895
|
-
return createErrorResponse('视频提示词必须严格遵照storyboard
|
|
2058
|
+
return createErrorResponse('视频提示词必须严格遵照storyboard的设定', 'generate-video');
|
|
2896
2059
|
}
|
|
2897
2060
|
if (scene.is_continuous && !end_frame) {
|
|
2898
|
-
return createErrorResponse('
|
|
2061
|
+
return createErrorResponse('连续分镜必须指定end_frame参数', 'generate-video');
|
|
2899
2062
|
}
|
|
2900
2063
|
if (scene.video_duration != null &&
|
|
2901
2064
|
duration !== scene.video_duration) {
|
|
2902
|
-
return createErrorResponse(`视频时长必须严格遵照storyboard的设定,用户指定的时长为 ${duration} 秒,而 storyboard 中建议的时长为 ${scene.video_duration}
|
|
2065
|
+
return createErrorResponse(`视频时长必须严格遵照storyboard的设定,用户指定的时长为 ${duration} 秒,而 storyboard 中建议的时长为 ${scene.video_duration} 秒。`, 'generate-video');
|
|
2903
2066
|
}
|
|
2904
2067
|
if (storyBoard.voice_type &&
|
|
2905
2068
|
storyBoard.voice_type !== 'slient') {
|
|
2906
2069
|
if (mute) {
|
|
2907
|
-
return createErrorResponse('
|
|
2070
|
+
return createErrorResponse('有对话和旁白的分镜不能静音,请将mute设为false再重新使用工具。', 'generate-video');
|
|
2908
2071
|
}
|
|
2909
2072
|
}
|
|
2910
2073
|
// 检查 use_video_model 与 type 参数的一致性
|
|
2911
2074
|
if (scene.use_video_model &&
|
|
2912
2075
|
type &&
|
|
2913
2076
|
scene.use_video_model !== type) {
|
|
2914
|
-
return createErrorResponse(
|
|
2077
|
+
return createErrorResponse(`分镜建议的视频模型(${scene.use_video_model})与传入的type参数(${type})不一致。请确保use_video_model与type参数值相同。`, 'generate-video');
|
|
2915
2078
|
}
|
|
2916
2079
|
}
|
|
2917
2080
|
else {
|
|
@@ -2927,60 +2090,6 @@ server.registerTool('generate-video', {
|
|
|
2927
2090
|
console.error('Failed to validate prompt with story board:', error);
|
|
2928
2091
|
// 如果读取或解析 storyboard.json 失败,继续执行但记录警告
|
|
2929
2092
|
}
|
|
2930
|
-
// 校验视频时长与 timeline_analysis.json 中 proposed_video_scenes 的匹配
|
|
2931
|
-
try {
|
|
2932
|
-
const timelineAnalysisPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'timeline_analysis.json');
|
|
2933
|
-
if ((0, node_fs_1.existsSync)(timelineAnalysisPath)) {
|
|
2934
|
-
const timelineAnalysisContent = await (0, promises_1.readFile)(timelineAnalysisPath, 'utf8');
|
|
2935
|
-
const timelineAnalysis = JSON.parse(timelineAnalysisContent);
|
|
2936
|
-
if (timelineAnalysis.proposed_video_scenes &&
|
|
2937
|
-
Array.isArray(timelineAnalysis.proposed_video_scenes)) {
|
|
2938
|
-
const videoScene = timelineAnalysis.proposed_video_scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2939
|
-
if (videoScene && videoScene.video_duration_s) {
|
|
2940
|
-
const expectedDuration = videoScene.video_duration_s;
|
|
2941
|
-
if (duration !== expectedDuration) {
|
|
2942
|
-
return createErrorResponse(`视频时长必须与timeline_analysis中的设定匹配。当前场景${videoScene.scene_id}要求时长为${expectedDuration}秒,但传入的duration为${duration}秒。请调整duration参数为${expectedDuration}秒后重试。如果用户明确指出不需要遵守,请将skipConsistencyCheck设置为true后再次调用。`, 'generate-video');
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
else {
|
|
2946
|
-
console.warn(`Scene ${sceneIndex} (scene_${sceneIndex.toString().padStart(2, '0')}) not found in timeline_analysis.json proposed_video_scenes`);
|
|
2947
|
-
}
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
else {
|
|
2951
|
-
// 检查音频时长标志
|
|
2952
|
-
try {
|
|
2953
|
-
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
2954
|
-
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
2955
|
-
const storyBoardContent = await (0, promises_1.readFile)(storyBoardPath, 'utf8');
|
|
2956
|
-
const storyBoard = JSON.parse(storyBoardContent);
|
|
2957
|
-
if (storyBoard.scenes && Array.isArray(storyBoard.scenes)) {
|
|
2958
|
-
const scene = storyBoard.scenes[sceneIndex - 1]; // sceneIndex 从1开始,数组从0开始
|
|
2959
|
-
if (scene &&
|
|
2960
|
-
((scene.script && scene.script.trim() !== '') ||
|
|
2961
|
-
scene.dialog)) {
|
|
2962
|
-
if (!checkAudioVideoDurationFlag) {
|
|
2963
|
-
checkAudioVideoDurationFlag = true;
|
|
2964
|
-
if (scene.audio_mode === 'vo_sync') {
|
|
2965
|
-
return createErrorResponse('请先自我检查 media_logs 中的音频时长,确保 storyboard 中视频时长为音频时长向上取整 即 ceil(音频时长),然后再按照正确的视频时长创建视频', 'generate-video');
|
|
2966
|
-
}
|
|
2967
|
-
else if (scene.audio_mode === 'dialogue') {
|
|
2968
|
-
return createErrorResponse('请先自我检查 media_logs 中的音频时长,确保 storyboard 中视频时长**不小于**音频时长向上取整 即 ceil(音频时长),然后再按照正确的视频时长创建视频', 'generate-video');
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
catch (error) {
|
|
2976
|
-
console.error('Failed to check audio duration flag:', error);
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
catch (error) {
|
|
2981
|
-
console.error('Failed to validate duration with timeline analysis:', error);
|
|
2982
|
-
// 如果读取或解析 timeline_analysis.json 失败,继续执行但记录警告
|
|
2983
|
-
}
|
|
2984
2093
|
}
|
|
2985
2094
|
const validatedFileName = validateFileName(saveToFileName);
|
|
2986
2095
|
console.log(`Generating video with prompt: ${prompt.substring(0, 100)}...`);
|
|
@@ -3617,11 +2726,15 @@ server.registerTool('audio-video-sync', {
|
|
|
3617
2726
|
.describe('The volume of video audio. 0.0 to 2.0.'),
|
|
3618
2727
|
loopAudio: zod_1.z.boolean().optional().default(true),
|
|
3619
2728
|
addSubtitles: zod_1.z.boolean().optional().default(false),
|
|
2729
|
+
subtitlesContext: zod_1.z
|
|
2730
|
+
.string()
|
|
2731
|
+
.optional()
|
|
2732
|
+
.describe('字幕的参考上下文(非必需),用于提升字幕准确性'),
|
|
3620
2733
|
saveToFileName: zod_1.z
|
|
3621
2734
|
.string()
|
|
3622
2735
|
.describe('The filename to save the audio-video-synced video. 应该是mp4文件'),
|
|
3623
2736
|
},
|
|
3624
|
-
}, async ({ videos, audio, audioInMs, audioFadeOutMs, audioVolume, videoAudioVolume, saveToFileName, loopAudio, addSubtitles, }, context) => {
|
|
2737
|
+
}, async ({ videos, audio, audioInMs, audioFadeOutMs, audioVolume, videoAudioVolume, saveToFileName, loopAudio, addSubtitles, subtitlesContext, }, context) => {
|
|
3625
2738
|
try {
|
|
3626
2739
|
// 验证session状态
|
|
3627
2740
|
const currentSession = await validateSession('audio-video-sync');
|
|
@@ -3655,6 +2768,7 @@ server.registerTool('audio-video-sync', {
|
|
|
3655
2768
|
videoAudioVolume,
|
|
3656
2769
|
loopAudio,
|
|
3657
2770
|
subtitles: addSubtitles,
|
|
2771
|
+
subtitlesContext,
|
|
3658
2772
|
});
|
|
3659
2773
|
if (result.url) {
|
|
3660
2774
|
console.log('Audio sync completed successfully');
|
|
@@ -3702,7 +2816,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3702
2816
|
inputSchema: {
|
|
3703
2817
|
prompt: zod_1.z
|
|
3704
2818
|
.string()
|
|
3705
|
-
.describe('The prompt to generate video with or without reference images.
|
|
2819
|
+
.describe('The prompt to generate video with or without reference images. '),
|
|
3706
2820
|
rewritePrompt: zod_1.z
|
|
3707
2821
|
.boolean()
|
|
3708
2822
|
.optional()
|
|
@@ -3727,7 +2841,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3727
2841
|
.max(16)
|
|
3728
2842
|
.optional()
|
|
3729
2843
|
.default(5)
|
|
3730
|
-
.describe('The duration of the video in seconds
|
|
2844
|
+
.describe('The duration of the video in seconds.可以传0,此时会根据视频提示词内容自动确定时长'),
|
|
3731
2845
|
aspectRatio: zod_1.z
|
|
3732
2846
|
.enum(['16:9', '9:16'])
|
|
3733
2847
|
.describe('The aspect ratio of the video.'),
|
|
@@ -3763,58 +2877,31 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3763
2877
|
.number()
|
|
3764
2878
|
.min(1)
|
|
3765
2879
|
.optional()
|
|
3766
|
-
.describe('
|
|
2880
|
+
.describe('分镜索引,从1开始的下标,如果非分镜对应素材,则可不传,分镜素材必传'),
|
|
3767
2881
|
storyBoardFile: zod_1.z
|
|
3768
2882
|
.string()
|
|
3769
2883
|
.optional()
|
|
3770
2884
|
.default('storyboard.json')
|
|
3771
2885
|
.describe('故事板文件路径'),
|
|
3772
|
-
skipConsistencyCheck: zod_1.z
|
|
3773
|
-
.boolean()
|
|
3774
|
-
.optional()
|
|
3775
|
-
.default(false)
|
|
3776
|
-
.describe('是否跳过一致性检查,默认为false(即默认进行一致性检查)'),
|
|
3777
|
-
skipCheckWithSceneReason: zod_1.z
|
|
3778
|
-
.string()
|
|
3779
|
-
.optional()
|
|
3780
|
-
.describe('跳过校验的理由,如果skipConsistencyCheck设为true,必须要传这个参数'),
|
|
3781
2886
|
optimizePrompt: zod_1.z
|
|
3782
2887
|
.boolean()
|
|
3783
2888
|
.optional()
|
|
3784
2889
|
.default(false)
|
|
3785
2890
|
.describe('Whether to optimize the prompt.'),
|
|
3786
2891
|
},
|
|
3787
|
-
}, async ({ prompt, rewritePrompt, referenceImages, duration, aspectRatio, resolution, type = 'vidu', mute, saveToFileName, sceneIndex, storyBoardFile,
|
|
2892
|
+
}, async ({ prompt, rewritePrompt, referenceImages, duration, aspectRatio, resolution, type = 'vidu', mute, saveToFileName, sceneIndex, storyBoardFile, optimizePrompt, seed, }, context) => {
|
|
3788
2893
|
try {
|
|
3789
2894
|
// 验证session状态
|
|
3790
2895
|
const currentSession = await validateSession('generate-video-by-ref');
|
|
3791
2896
|
const storyBoardPath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, storyBoardFile);
|
|
3792
|
-
if (type !== 'pro' && duration === 0) {
|
|
3793
|
-
return createErrorResponse('非 pro 模型的视频时长不能为 0', 'generate-video');
|
|
3794
|
-
}
|
|
3795
2897
|
const outlineSheetImagePath = (0, node_path_1.resolve)(process.env.ZEROCUT_PROJECT_CWD || process.cwd(), projectLocalDir, 'materials', 'outline_sheet.png');
|
|
3796
2898
|
const hasOutlineSheet = (0, node_fs_1.existsSync)(outlineSheetImagePath);
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
}
|
|
3800
|
-
// 检查 storyboard 标志
|
|
3801
|
-
if (!hasOutlineSheet &&
|
|
3802
|
-
!checkStoryboardFlag &&
|
|
3803
|
-
(0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
3804
|
-
checkStoryboardFlag = true;
|
|
3805
|
-
return createErrorResponse(`必须先审查生成的 storyboard.json 内容,按照如下步骤:
|
|
3806
|
-
|
|
3807
|
-
1. 确保每个场景中的stage_atmosphere内容按照规则被正确融合到video_prompt中,不得遗漏
|
|
3808
|
-
2. 如有main_characters设定且包含了reference_image,或有reference_objects,需确保video_prompt描述已包含该场景相关main_characters和所有reference_objects中的物品或背景,并确保参考图具体内容已经在video_prompt中有明确描述,如果没有,可忽略。
|
|
3809
|
-
3. 如有配音,先自我检查 media_logs 中的查音频时长,确保以匹配音频时长来生成视频
|
|
3810
|
-
|
|
3811
|
-
检查完上述问题后先汇报,如果有需要,应当先修改 storyboard.json 内容,然后再调用 generate-video-by-ref 生成视频。注意修改 storyboard 内容时,仅修改相应字段的字符串值,不要破坏JSON格式!
|
|
3812
|
-
|
|
3813
|
-
再次调用 generate-video-by-ref 时,如需要参考图,要确保referenceImages使用正确(main_characters中的reference_image作为参考人物,reference_objects中的image作为参考物品或参考背景)`, 'generate-image');
|
|
3814
|
-
}
|
|
3815
|
-
// 校验 prompt 与 storyboard.json 中场景设定的一致性(如果提供了 sceneIndex)
|
|
3816
|
-
if (!skipConsistencyCheck && sceneIndex) {
|
|
2899
|
+
// 校验 prompt 与 storyboard.json 中分镜设定的一致性(如果提供了 sceneIndex)
|
|
2900
|
+
if (sceneIndex) {
|
|
3817
2901
|
try {
|
|
2902
|
+
if (hasOutlineSheet) {
|
|
2903
|
+
return createErrorResponse('监测到素材中存在outline_sheet.png这张图(由outline工具生成的),应采用 generate-video 图生视频。', 'generate-video-by-ref');
|
|
2904
|
+
}
|
|
3818
2905
|
if ((0, node_fs_1.existsSync)(storyBoardPath)) {
|
|
3819
2906
|
const storyBoardContent = await (0, promises_1.readFile)(storyBoardPath, 'utf8');
|
|
3820
2907
|
// 检查 storyBoard JSON 语法合法性
|
|
@@ -3830,20 +2917,20 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3830
2917
|
if (scene) {
|
|
3831
2918
|
const videoPrompt = scene.video_prompt;
|
|
3832
2919
|
if (videoPrompt && prompt !== videoPrompt) {
|
|
3833
|
-
return createErrorResponse('视频提示词必须严格遵照storyboard
|
|
2920
|
+
return createErrorResponse('视频提示词必须严格遵照storyboard的设定', 'generate-video-by-ref');
|
|
3834
2921
|
}
|
|
3835
2922
|
// 检查 scene.is_continuous 是否为 true
|
|
3836
2923
|
if (scene.is_continuous === true) {
|
|
3837
|
-
return createErrorResponse('
|
|
2924
|
+
return createErrorResponse('连续镜头应使用首尾帧,请修改连续镜头设置,或将本分镜改为首尾帧方式实现', 'generate-video-by-ref');
|
|
3838
2925
|
}
|
|
3839
2926
|
if (scene.video_type !== 'references') {
|
|
3840
|
-
return createErrorResponse(
|
|
2927
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中的 video_type (${scene.video_type}) 未设置为 'references',不应当使用参考生视频,请使用图生视频 generate-video 方式生成`, 'generate-video-by-ref');
|
|
3841
2928
|
}
|
|
3842
2929
|
// 检查 use_video_model 与 type 参数的一致性
|
|
3843
2930
|
if (scene.use_video_model &&
|
|
3844
2931
|
type &&
|
|
3845
2932
|
scene.use_video_model !== type) {
|
|
3846
|
-
return createErrorResponse(
|
|
2933
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中的 use_video_model (${scene.use_video_model}) 必须与 type 参数 (${type}) 保持一致`, 'generate-video-by-ref');
|
|
3847
2934
|
}
|
|
3848
2935
|
// 检查 scene.references 的一致性
|
|
3849
2936
|
if (scene.references &&
|
|
@@ -3859,7 +2946,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3859
2946
|
const character = mainCharacters.find((char) => char.name === referenceName);
|
|
3860
2947
|
if (character) {
|
|
3861
2948
|
if (!character.reference_image) {
|
|
3862
|
-
return createErrorResponse(
|
|
2949
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的角色 "${referenceName}" 在 main_characters 中没有 reference_image 属性`, 'generate-video-by-ref');
|
|
3863
2950
|
}
|
|
3864
2951
|
requiredImage = character.reference_image;
|
|
3865
2952
|
found = true;
|
|
@@ -3869,7 +2956,7 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3869
2956
|
const refObject = referenceObjects.find((obj) => obj.name === referenceName);
|
|
3870
2957
|
if (refObject) {
|
|
3871
2958
|
if (!refObject.image) {
|
|
3872
|
-
return createErrorResponse(
|
|
2959
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的物品/背景 "${referenceName}" 在 reference_objects 中没有 image 属性`, 'generate-video-by-ref');
|
|
3873
2960
|
}
|
|
3874
2961
|
requiredImage = refObject.image;
|
|
3875
2962
|
found = true;
|
|
@@ -3877,11 +2964,11 @@ server.registerTool('generate-video-by-ref', {
|
|
|
3877
2964
|
}
|
|
3878
2965
|
// 如果既不在 main_characters 也不在 reference_objects 中
|
|
3879
2966
|
if (!found) {
|
|
3880
|
-
return createErrorResponse(
|
|
2967
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的 "${referenceName}" 在 main_characters 或 reference_objects 中都找不到对应的定义`, 'generate-video-by-ref');
|
|
3881
2968
|
}
|
|
3882
2969
|
// 检查对应的图片是否在 referenceImages 参数中
|
|
3883
2970
|
if (!referenceImages.some(ref => ref.fileName === requiredImage)) {
|
|
3884
|
-
return createErrorResponse(
|
|
2971
|
+
return createErrorResponse(`分镜 ${sceneIndex} 中引用的 "${referenceName}" 对应的图片 "${requiredImage}" 不在 referenceImages 参数中,请确保传入正确的参考图片`, 'generate-video-by-ref');
|
|
3885
2972
|
}
|
|
3886
2973
|
}
|
|
3887
2974
|
}
|