dsh-game-material-master 0.7.0 → 0.9.0

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/lib/pipeline.js CHANGED
@@ -17,13 +17,13 @@
17
17
  * 所有耗时操作都通过 kick() 丢到后台,远程调用只负责「启动」和「读状态」,
18
18
  * 界面靠自己轮询 getState 看进度——一次 Hailuo 生成要几分钟,绝不能同步阻塞。
19
19
  */
20
- import { mkdir, readFile, writeFile } from "node:fs/promises";
20
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
21
21
  import { dirname } from "node:path";
22
22
  import { loadConfig } from "./config.js";
23
23
  import { DEFAULT_TURN_PROMPT, DIRECTIONS, DIRECTION_KEYS, TURN_DIRECTION_DEFAULT, TURN_FRAME_COUNT_MAX, TURN_FRAME_COUNT_MIN, directionOf, turnOrder } from "./directions.js";
24
24
  import { assertImageProviderReady, generateImageWithProvider, imageModelOf, imageSizeOf, imageWatermarkOf } from "./imageprovider.js";
25
- import { downloadVideo, queryVideo, retrieveFile, submitVideo } from "./minimax.js";
26
25
  import { extractFrames, mimeOf, sniffVideo, toDataUri, toJpegDataUri } from "./media.js";
26
+ import { assertVideoBackendReady, downloadVideoTask, queryVideoTask, submitVideoTask, videoFailureReason } from "./videogen.js";
27
27
  import { composeSheet, keyGreen } from "./chroma.js";
28
28
  import { encodePng } from "./png.js";
29
29
  import { zipEntries } from "./zip.js";
@@ -46,20 +46,34 @@ export function disposePipeline() {
46
46
  pollers.clear();
47
47
  jobs.clear();
48
48
  }
49
+ /**
50
+ * 复位后台任务表。
51
+ *
52
+ * 插件被 DSH 重载时,`ctx.effect` 的清理会跑 `disposePipeline()`;只要 Node 的模块缓存
53
+ * 还留着这个模块(同一份 lib 被再次 apply),`disposed` 就会一直停在 true——此后每一次
54
+ * 生成类调用都只得到一句「任务已在进行中」,界面看着像按钮点了没反应,其实一个任务都没建。
55
+ * 所以**每次 apply 都必须复位**,不能只依赖进程重启。
56
+ */
57
+ export function activatePipeline() {
58
+ disposed = false;
59
+ jobs.clear();
60
+ }
61
+ /**
62
+ * `kick` 返回 false 时的理由。
63
+ *
64
+ * 必须区分「真的已经在跑」与「实例已废」:后者只说「任务已在进行中」的话,
65
+ * 用户会一直等一个根本不存在的任务。
66
+ */
67
+ const PIPELINE_DISPOSED_REASON = "插件实例已被 DSH 重载(旧实例已卸载),请重启 DSH 后再试";
68
+ function kickFailure(detail) {
69
+ return { started: false, reason: disposed ? PIPELINE_DISPOSED_REASON : detail };
70
+ }
49
71
  export function listJobs(projectId) {
50
72
  return [...(jobs.get(projectId)?.values() ?? [])];
51
73
  }
52
74
  function messageOf(error) {
53
75
  return error instanceof Error ? error.message : String(error);
54
76
  }
55
- function miniMaxRequest(config) {
56
- return {
57
- baseUrl: config.minimaxBaseUrl,
58
- apiKey: config.minimaxApiKey,
59
- model: config.minimaxModel,
60
- timeoutMs: config.minimaxTimeoutMs
61
- };
62
- }
63
77
  /** 把一个后台任务登记进运行表并立刻返回;重复的 taskKey 会被拒绝。 */
64
78
  function kick(projectId, taskKey, label, fn) {
65
79
  if (disposed)
@@ -123,7 +137,7 @@ export function startImage(projectId, key, options = {}) {
123
137
  if (jobs.get(projectId)?.has(`image:${key}`) === true)
124
138
  return { started: false, reason: "该方向正在生成中" };
125
139
  const started = kick(projectId, `image:${key}`, `生成「${direction.label}」`, () => generateOne(projectId, key, options.prompt));
126
- return started ? { started: true } : { started: false, reason: "任务已在进行中" };
140
+ return started ? { started: true } : kickFailure("任务已在进行中");
127
141
  }
128
142
  async function generateOne(projectId, key, promptOverride) {
129
143
  const direction = directionOf(key);
@@ -240,7 +254,7 @@ export function startAllImages(projectId, force = false) {
240
254
  });
241
255
  }
242
256
  });
243
- return started ? { started: true } : { started: false, reason: "批量生成已在进行中" };
257
+ return started ? { started: true } : kickFailure("批量生成已在进行中");
244
258
  }
245
259
  // ── 阶段 1b:转圈截帧(八方向绿幕图的默认生成方式)──────────────────────
246
260
  //
@@ -252,35 +266,64 @@ function clampInt(value, min, max) {
252
266
  return min;
253
267
  return Math.min(max, Math.max(min, Math.round(value)));
254
268
  }
269
+ /** 取文件的修改时间;读不到(还没落盘 / 已经被删)时返回 null。 */
270
+ async function fileMtimeMs(absolute) {
271
+ try {
272
+ return (await stat(absolute)).mtimeMs;
273
+ }
274
+ catch {
275
+ return null;
276
+ }
277
+ }
255
278
  /**
256
279
  * 转圈视频的首帧。
257
280
  *
258
281
  * 优先用已经有的正面绿幕图,没有就退回源图:源图不一定是绿幕,但提示词里
259
282
  * 已经明确要求「纯色绿幕 #00FF00」,模型会照着重画背景。把实际用的那张记进
260
283
  * `turn.video.firstFrame`,排查「第一帧就不是正面」时才有据可依。
284
+ *
285
+ * ⚠️ 正面绿幕图如果比源图还旧,说明源图是后来换的(换源图会作废派生产物,
286
+ * 但历史项目、手工替换文件、以及从前留下的旧数据都可能带着这种状态):
287
+ * 那一张画的是**上一个角色**,用它当首帧就会「新角色配旧脸」——生成的图
288
+ * 看着没问题,只有肉眼看内容才发现。所以这里拿文件时间兜一道,宁可退回
289
+ * 源图(哪怕不是绿幕),也不拿旧角色的脸去生成。
261
290
  */
262
- function turnFirstFrame(project) {
291
+ async function turnFirstFrame(projectId, project) {
263
292
  const front = project.images["front"]?.file;
264
- if (front !== undefined)
293
+ const source = project.source?.file;
294
+ if (front !== undefined) {
295
+ if (source !== undefined) {
296
+ const [frontAt, sourceAt] = await Promise.all([
297
+ fileMtimeMs(assetPath(projectId, front)),
298
+ fileMtimeMs(assetPath(projectId, source))
299
+ ]);
300
+ if (frontAt !== null && sourceAt !== null && sourceAt > frontAt + 1000) {
301
+ return {
302
+ file: source,
303
+ label: "源图",
304
+ note: "正面绿幕图比源图旧(源图是后来换的),这次改用源图当首帧——否则会拿上一个角色的脸去生成。"
305
+ };
306
+ }
307
+ }
265
308
  return { file: front, label: "正面绿幕图" };
266
- if (project.source !== null)
267
- return { file: project.source.file, label: "源图" };
309
+ }
310
+ if (source !== undefined)
311
+ return { file: source, label: "源图" };
268
312
  return undefined;
269
313
  }
270
314
  export function startTurnVideo(projectId) {
271
315
  if (jobs.get(projectId)?.has("turn:video") === true)
272
316
  return { started: false, reason: "转圈视频正在生成中" };
273
317
  const started = kick(projectId, "turn:video", "生成转圈视频", () => submitTurnVideo(projectId));
274
- return started ? { started: true } : { started: false, reason: "任务已在进行中" };
318
+ return started ? { started: true } : kickFailure("任务已在进行中");
275
319
  }
276
320
  async function submitTurnVideo(projectId) {
277
321
  const project = await readProject(projectId);
278
322
  if (project === undefined)
279
323
  throw new Error(`项目不存在:${projectId}`);
280
324
  const config = await loadConfig();
281
- if (config.minimaxApiKey.trim() === "")
282
- throw new Error("尚未配置 MiniMax API Key");
283
- const first = turnFirstFrame(project);
325
+ assertVideoBackendReady(config);
326
+ const first = await turnFirstFrame(projectId, project);
284
327
  if (first === undefined)
285
328
  throw new Error("还没有源图,无法生成转圈视频");
286
329
  const base = (project.prompts.turn ?? DEFAULT_TURN_PROMPT).trim();
@@ -301,13 +344,14 @@ async function submitTurnVideo(projectId) {
301
344
  if (current.turn.frames.frames.length > 0)
302
345
  current.turn.frames.stale = true;
303
346
  log(current, "info", `开始生成转圈视频(首帧:${first.label})`);
347
+ if (first.note !== undefined)
348
+ log(current, "warn", first.note);
304
349
  });
305
350
  const startedAt = Date.now();
306
351
  try {
307
352
  const jpegRel = "videos/turn-first-frame.jpg";
308
353
  const dataUri = await toJpegDataUri(assetPath(projectId, first.file), assetPath(projectId, jpegRel));
309
- const taskId = await submitVideo({
310
- ...miniMaxRequest(config),
354
+ const submitted = await submitVideoTask(config, {
311
355
  prompt,
312
356
  firstFrameImage: dataUri,
313
357
  duration: config.minimaxDuration,
@@ -318,12 +362,17 @@ async function submitTurnVideo(projectId) {
318
362
  current.turn.video = {
319
363
  ...current.turn.video,
320
364
  status: "running",
321
- taskId,
365
+ taskId: submitted.taskId,
366
+ backend: submitted.backend,
322
367
  remoteStatus: "已提交",
323
368
  elapsedMs: Date.now() - startedAt,
324
369
  updatedAt: Date.now()
325
370
  };
326
- log(current, "info", `转圈视频任务已提交(${taskId})`);
371
+ log(current, "info", `转圈视频任务已提交(${submitted.taskId})`);
372
+ // 自动探测出来的注入点(改了哪个节点的哪个输入)记进日志:
373
+ // 生成结果不对时,第一件要确认的事就是「提示词和首帧到底注进去了没有」。
374
+ for (const note of submitted.notes)
375
+ log(current, "info", note);
327
376
  });
328
377
  ensurePoller(projectId);
329
378
  }
@@ -341,14 +390,16 @@ async function pollTurnVideoOnce(projectId, config) {
341
390
  const project = await readProject(projectId);
342
391
  if (project === undefined)
343
392
  return;
344
- const taskId = project.turn?.video?.taskId;
345
- if (project.turn?.video?.status !== "running" || taskId === undefined)
393
+ const node = project.turn?.video;
394
+ const taskId = node?.taskId;
395
+ if (node?.status !== "running" || taskId === undefined)
346
396
  return;
347
- const request = miniMaxRequest(config);
397
+ // 后端按节点上记的那个值走,不按当前配置:任务可能是改设置之前提交的。
398
+ const backend = node.backend ?? "minimax";
348
399
  try {
349
- const query = await queryVideo({ ...request, taskId });
400
+ const query = await queryVideoTask(config, backend, taskId);
350
401
  if (query.status === "failed") {
351
- const reason = query.error ?? "MiniMax 报告该任务失败";
402
+ const reason = videoFailureReason(backend, query.error);
352
403
  await patchProject(projectId, (current) => {
353
404
  current.turn.video = { ...current.turn.video, status: "error", error: reason, remoteStatus: query.remoteStatus, updatedAt: Date.now() };
354
405
  log(current, "error", `转圈视频生成失败:${reason}`);
@@ -361,11 +412,10 @@ async function pollTurnVideoOnce(projectId, config) {
361
412
  });
362
413
  return;
363
414
  }
364
- const url = query.videoUrl ??
365
- (query.fileId !== undefined ? await retrieveFile({ ...request, fileId: query.fileId }) : undefined);
415
+ const url = query.url;
366
416
  if (url === undefined)
367
- throw new Error("任务已成功,但响应里既没有视频地址也没有 file_id");
368
- const bytes = await downloadVideo(url, config.minimaxTimeoutMs);
417
+ throw new Error("任务已成功,但查询结果里没有视频地址");
418
+ const bytes = await downloadVideoTask(config, backend, url);
369
419
  const relative = "videos/turn.mp4";
370
420
  await writeFile(assetPath(projectId, relative), bytes);
371
421
  await patchProject(projectId, (current) => {
@@ -402,7 +452,7 @@ export function startTurnFrames(projectId, count) {
402
452
  setJobTargets(projectId, "turn:frames", DIRECTION_KEYS);
403
453
  await extractTurnFrames(projectId, count);
404
454
  });
405
- return started ? { started: true } : { started: false, reason: "任务已在进行中" };
455
+ return started ? { started: true } : kickFailure("任务已在进行中");
406
456
  }
407
457
  /**
408
458
  * 候选帧数变了之后,把用户拖过的位置按比例换算过去。
@@ -834,8 +884,7 @@ export function startVideos(projectId, keys) {
834
884
  if (project === undefined)
835
885
  throw new Error(`项目不存在:${projectId}`);
836
886
  const config = await loadConfig();
837
- if (config.minimaxApiKey.trim() === "")
838
- throw new Error("尚未配置 MiniMax API Key");
887
+ assertVideoBackendReady(config);
839
888
  const targets = (keys ?? DIRECTION_KEYS).filter((key) => {
840
889
  const image = project.images[key];
841
890
  const video = project.videos[key];
@@ -873,8 +922,7 @@ export function startVideos(projectId, keys) {
873
922
  const jpegRel = `videos/${key}-first-frame.jpg`;
874
923
  const dataUri = await toJpegDataUri(assetPath(projectId, image.file), assetPath(projectId, jpegRel));
875
924
  const prompt = (fresh.prompts.videoPerDirection?.[key] ?? fresh.prompts.video).trim();
876
- const taskId = await submitVideo({
877
- ...miniMaxRequest(config),
925
+ const submitted = await submitVideoTask(config, {
878
926
  prompt,
879
927
  firstFrameImage: dataUri,
880
928
  duration: config.minimaxDuration,
@@ -885,11 +933,14 @@ export function startVideos(projectId, keys) {
885
933
  current.videos[key] = {
886
934
  ...current.videos[key],
887
935
  status: "running",
888
- taskId,
936
+ taskId: submitted.taskId,
937
+ backend: submitted.backend,
889
938
  remoteStatus: "已提交",
890
939
  updatedAt: Date.now()
891
940
  };
892
- log(current, "info", `「${label}」视频任务已提交(${taskId})`);
941
+ log(current, "info", `「${label}」视频任务已提交(${submitted.taskId})`);
942
+ for (const note of submitted.notes)
943
+ log(current, "info", `「${label}」${note}`);
893
944
  });
894
945
  }
895
946
  catch (error) {
@@ -907,7 +958,7 @@ export function startVideos(projectId, keys) {
907
958
  });
908
959
  ensurePoller(projectId);
909
960
  });
910
- return started ? { started: true } : { started: false, reason: "视频任务提交已在进行中" };
961
+ return started ? { started: true } : kickFailure("视频任务提交已在进行中");
911
962
  }
912
963
  export function ensurePoller(projectId) {
913
964
  if (pollers.has(projectId))
@@ -947,10 +998,11 @@ export async function pollVideosOnce(projectId) {
947
998
  await Promise.all(pending.map(async (key) => {
948
999
  const label = directionOf(key)?.label ?? key;
949
1000
  const taskId = project.videos[key].taskId;
1001
+ const backend = project.videos[key].backend ?? "minimax";
950
1002
  try {
951
- const query = await queryVideo({ ...miniMaxRequest(config), taskId });
1003
+ const query = await queryVideoTask(config, backend, taskId);
952
1004
  if (query.status === "failed") {
953
- const reason = query.error ?? "MiniMax 报告该任务失败";
1005
+ const reason = videoFailureReason(backend, query.error);
954
1006
  await patchProject(projectId, (current) => {
955
1007
  current.videos[key] = { ...current.videos[key], status: "error", error: reason, remoteStatus: query.remoteStatus, updatedAt: Date.now() };
956
1008
  log(current, "error", `「${label}」视频生成失败:${reason}`);
@@ -964,11 +1016,10 @@ export async function pollVideosOnce(projectId) {
964
1016
  return;
965
1017
  }
966
1018
  // v2(H3)在查询结果里直接给地址;v1 还要拿 file_id 再换一次。
967
- const url = query.videoUrl ??
968
- (query.fileId !== undefined ? await retrieveFile({ ...miniMaxRequest(config), fileId: query.fileId }) : undefined);
1019
+ const url = query.url;
969
1020
  if (url === undefined)
970
- throw new Error("任务已成功,但响应里既没有视频地址也没有 file_id");
971
- const bytes = await downloadVideo(url, config.minimaxTimeoutMs);
1021
+ throw new Error("任务已成功,但查询结果里没有视频地址");
1022
+ const bytes = await downloadVideoTask(config, backend, url);
972
1023
  const relative = `videos/${key}.mp4`;
973
1024
  await writeFile(assetPath(projectId, relative), bytes);
974
1025
  await patchProject(projectId, (current) => {
@@ -1207,7 +1258,7 @@ export async function startFramePick(projectId, key, count) {
1207
1258
  dropJobTarget(projectId, taskKey, key);
1208
1259
  }
1209
1260
  });
1210
- return started ? { started: true } : { started: false, reason: "这个方向正在手动选帧" };
1261
+ return started ? { started: true } : kickFailure("这个方向正在手动选帧");
1211
1262
  }
1212
1263
  /** 改这个方向某一个输出帧落在哪张候选帧上(圆圈松手时调用)。 */
1213
1264
  export async function setFramePick(projectId, key, slot, index) {
@@ -1370,7 +1421,7 @@ export function startExtract(projectId, keys) {
1370
1421
  // 抽完帧立刻按当前参数出一次抠像结果与预览带。
1371
1422
  await renderSheet(projectId);
1372
1423
  });
1373
- return started ? { started: true } : { started: false, reason: "抽帧任务已在进行中" };
1424
+ return started ? { started: true } : kickFailure("抽帧任务已在进行中");
1374
1425
  }
1375
1426
  // ── 阶段 4:抠像 + 合成整图 ──────────────────────────────────────────────
1376
1427
  /** 只按当前参数重跑抠像与合成(不重新解码视频)。 */
@@ -1378,13 +1429,13 @@ export function startRekey(projectId) {
1378
1429
  const started = kick(projectId, "sheet:key", "重新抠像", async () => {
1379
1430
  await renderSheet(projectId, { requireFrames: true });
1380
1431
  });
1381
- return started ? { started: true } : { started: false, reason: "抠像任务已在进行中" };
1432
+ return started ? { started: true } : kickFailure("抠像任务已在进行中");
1382
1433
  }
1383
1434
  export function startCompose(projectId) {
1384
1435
  const started = kick(projectId, "sheet:compose", "合成整图", async () => {
1385
1436
  await renderSheet(projectId, { requireFrames: true });
1386
1437
  });
1387
- return started ? { started: true } : { started: false, reason: "合成任务已在进行中" };
1438
+ return started ? { started: true } : kickFailure("合成任务已在进行中");
1388
1439
  }
1389
1440
  /**
1390
1441
  * 抠像 + 合成。`startExtract` / `startRekey` / `startCompose` 都走这一条路径,
package/lib/riggen.js CHANGED
@@ -42,6 +42,7 @@ import { MESH_DEFAULT_DIVISIONS, MESH_MAX_DIVISIONS } from "./rigmesh.js";
42
42
  import { normalizePath } from "./rigpath.js";
43
43
  import { validateAnimationLoops, validateAtlas, validateDragonBones, validateDragonBonesTexture, validateSkeletonAtlasMatch, validateSpineWire } from "./rigvalidate.js";
44
44
  import { defaultSemanticsOf, mergeSemantics, validateSemantics, ROLE_NOUNS } from "./rigsemantics.js";
45
+ import { assetBasePath } from "./links.js";
45
46
  export const RIG_STAGES = [
46
47
  { key: "parts", label: "① 拆件", summary: "把角色拆成独立部件(头/躯干/四肢),逐件透明 PNG" },
47
48
  { key: "layout", label: "② 装配", summary: "把部件摆回参考姿态,出合成对比图供肉眼验收" },
@@ -615,7 +616,7 @@ function lossless(value) {
615
616
  return value;
616
617
  }
617
618
  export function rigSnapshot(job, origin = "") {
618
- const assetBase = `${origin}/dsh-game-material-master/rig-assets/${job.id}/`;
619
+ const assetBase = `${origin}${assetBasePath(`/dsh-game-material-master/rig-assets/${job.id}/`)}`;
619
620
  const url = (relative) => typeof relative === "string" && relative !== "" ? `${assetBase}${relative}` : undefined;
620
621
  const items = job.layout.items;
621
622
  const parts = job.parts.map((part) => {
@@ -1215,6 +1216,11 @@ export function disposeRig() {
1215
1216
  pollers.clear();
1216
1217
  running.clear();
1217
1218
  }
1219
+ /** 复位后台任务表(理由同 pipeline.activatePipeline:重载会让 disposed 永远停在 true)。 */
1220
+ export function activateRig() {
1221
+ disposed = false;
1222
+ running.clear();
1223
+ }
1218
1224
  export function listRigTasks(jobId) {
1219
1225
  return [...(running.get(jobId) ?? [])];
1220
1226
  }
package/lib/seqgen.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * 序列帧生成模块。
3
3
  *
4
- * 先用 MiniMax 生成一段视频(支持两种输入模式,平台规定二者互斥):
4
+ * 先生成一段视频(默认云端 MiniMax,设置里可切到本机 ComfyUI,见 videogen.ts)。
5
+ * MiniMax 支持两种输入模式(平台规定二者互斥):
5
6
  * - **首尾帧模式**:上传首帧(必填)/ 尾帧(选填)
6
7
  * - **多模态参考模式**:上传参考图 + 参考视频
7
8
  * 然后依次做:序列帧提取(张数可配)→ 绿幕抠像 → 横向合成,并可在界面里
@@ -21,7 +22,8 @@ import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
21
22
  import { basename, join, resolve, sep } from "node:path";
22
23
  import { randomUUID } from "node:crypto";
23
24
  import { loadConfig, sequenceJobsRoot } from "./config.js";
24
- import { downloadVideo, normalizeDuration, normalizeResolution, queryVideo, retrieveFile, submitVideo } from "./minimax.js";
25
+ import { normalizeDuration, normalizeResolution } from "./minimax.js";
26
+ import { assertVideoBackendReady, downloadVideoTask, queryVideoTask, submitVideoTask, videoFailureReason } from "./videogen.js";
25
27
  import { extractFrames, fileSize, mimeOf, toJpegDataUri } from "./media.js";
26
28
  import { composeSheet, keyGreen } from "./chroma.js";
27
29
  import { encodePng } from "./png.js";
@@ -185,6 +187,7 @@ function normalizeSequenceJob(raw) {
185
187
  video: {
186
188
  status: (raw?.video?.status ?? "empty"),
187
189
  taskId: typeof raw?.video?.taskId === "string" ? raw.video.taskId : undefined,
190
+ backend: raw?.video?.backend === "comfy" || raw?.video?.backend === "minimax" ? raw.video.backend : undefined,
188
191
  remoteStatus: typeof raw?.video?.remoteStatus === "string" ? raw.video.remoteStatus : undefined,
189
192
  file: typeof raw?.video?.file === "string" ? raw.video.file : undefined,
190
193
  error: typeof raw?.video?.error === "string" ? raw.video.error : undefined,
@@ -244,6 +247,11 @@ export function disposeSequence() {
244
247
  pollers.clear();
245
248
  jobsRunning.clear();
246
249
  }
250
+ /** 复位后台任务表(理由同 pipeline.activatePipeline:重载会让 disposed 永远停在 true)。 */
251
+ export function activateSequence() {
252
+ disposed = false;
253
+ jobsRunning.clear();
254
+ }
247
255
  export function listSequenceTasks(jobId) {
248
256
  return [...(jobsRunning.get(jobId) ?? [])];
249
257
  }
@@ -295,8 +303,7 @@ async function submitSequenceVideo(jobId) {
295
303
  if (job === undefined)
296
304
  throw new Error(`任务不存在:${jobId}`);
297
305
  const config = await loadConfig();
298
- if (config.minimaxApiKey.trim() === "")
299
- throw new Error("尚未配置 MiniMax API Key");
306
+ assertVideoBackendReady(config);
300
307
  // 模型是全局设置(设置 → 游戏素材大师 → 视频模型),任务只跟随、不覆盖:
301
308
  // 任务的模型快照一旦和当前网关/Key 对不上(例如官方 H3 + 优云智算网关),
302
309
  // 就会打出 cp.compshare.cn/v2/... 这种 404。这里以全局配置为准并回写任务。
@@ -333,11 +340,7 @@ async function submitSequenceVideo(jobId) {
333
340
  appendJobLog(job.log, "info", `提交视频任务(${job.mode === "frames" ? "首尾帧模式" : "参考模式"})`);
334
341
  await writeSequenceJob(job);
335
342
  try {
336
- const taskId = await submitVideo({
337
- baseUrl: config.minimaxBaseUrl,
338
- apiKey: config.minimaxApiKey,
339
- model,
340
- timeoutMs: config.minimaxTimeoutMs,
343
+ const submitted = await submitVideoTask(config, {
341
344
  prompt: built.prompt,
342
345
  firstFrameImage,
343
346
  lastFrameImage,
@@ -345,13 +348,22 @@ async function submitSequenceVideo(jobId) {
345
348
  referenceVideos,
346
349
  duration: job.settings.duration,
347
350
  resolution: job.settings.resolution,
348
- promptOptimizer: job.settings.promptOptimizer
351
+ promptOptimizer: job.settings.promptOptimizer,
352
+ model
349
353
  });
350
354
  const fresh = await readSequenceJob(jobId);
351
355
  if (fresh === undefined)
352
356
  return;
353
- fresh.video = { status: "running", taskId, remoteStatus: "已提交", updatedAt: Date.now() };
354
- appendJobLog(fresh.log, "info", `视频任务已提交(${taskId})`);
357
+ fresh.video = {
358
+ status: "running",
359
+ taskId: submitted.taskId,
360
+ backend: submitted.backend,
361
+ remoteStatus: "已提交",
362
+ updatedAt: Date.now()
363
+ };
364
+ appendJobLog(fresh.log, "info", `视频任务已提交(${submitted.taskId})`);
365
+ for (const note of submitted.notes)
366
+ appendJobLog(fresh.log, "info", note);
355
367
  await writeSequenceJob(fresh);
356
368
  ensureSequencePoller(jobId);
357
369
  }
@@ -413,19 +425,15 @@ export async function pollSequenceOnce(jobId) {
413
425
  return;
414
426
  }
415
427
  const config = await loadConfig();
416
- const request = {
417
- baseUrl: config.minimaxBaseUrl,
418
- apiKey: config.minimaxApiKey,
419
- model: job.settings.model || config.minimaxModel,
420
- timeoutMs: config.minimaxTimeoutMs
421
- };
428
+ const backend = job.video.backend ?? "minimax";
429
+ const model = job.settings.model || config.minimaxModel;
422
430
  try {
423
- const query = await queryVideo({ ...request, taskId });
431
+ const query = await queryVideoTask(config, backend, taskId, { model });
424
432
  if (query.status === "failed") {
425
433
  const fresh = await readSequenceJob(jobId);
426
434
  if (fresh === undefined)
427
435
  return;
428
- fresh.video = { ...fresh.video, status: "error", remoteStatus: query.remoteStatus, error: query.error ?? "MiniMax 报告任务失败", updatedAt: Date.now() };
436
+ fresh.video = { ...fresh.video, status: "error", remoteStatus: query.remoteStatus, error: videoFailureReason(backend, query.error), updatedAt: Date.now() };
429
437
  appendJobLog(fresh.log, "error", `视频生成失败:${fresh.video.error}`);
430
438
  await writeSequenceJob(fresh);
431
439
  stopSequencePoller(jobId);
@@ -439,10 +447,10 @@ export async function pollSequenceOnce(jobId) {
439
447
  await writeSequenceJob(fresh);
440
448
  return;
441
449
  }
442
- const url = query.videoUrl ?? (query.fileId !== undefined ? await retrieveFile({ ...request, fileId: query.fileId }) : undefined);
450
+ const url = query.url;
443
451
  if (url === undefined)
444
- throw new Error("任务已成功,但响应里既没有视频地址也没有 file_id");
445
- const bytes = await downloadVideo(url, config.minimaxTimeoutMs);
452
+ throw new Error("任务已成功,但查询结果里没有视频地址");
453
+ const bytes = await downloadVideoTask(config, backend, url);
446
454
  const relative = "videos/output.mp4";
447
455
  await writeFile(sequenceAssetPath(jobId, relative), bytes);
448
456
  const fresh = await readSequenceJob(jobId);