@kevlns/art-workshop 0.5.2 → 0.6.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.
Files changed (52) hide show
  1. package/README.md +13 -11
  2. package/art-workshop.mjs +50 -5
  3. package/docs/channels.md +49 -0
  4. package/docs/commands.md +2259 -22
  5. package/docs/configuration.md +8 -0
  6. package/docs/core-guidance.md +12 -4
  7. package/docs/data-formats.md +10 -6
  8. package/docs/local-models/qwen-image-2.1.json +1 -1
  9. package/docs/modes.md +12 -6
  10. package/docs/release-0.6.0.md +9 -0
  11. package/lib/analysis-worker.mjs +9 -5
  12. package/lib/backends.mjs +2 -0
  13. package/lib/candidates.mjs +2 -1
  14. package/lib/channel-operation.mjs +84 -0
  15. package/lib/core.mjs +29 -0
  16. package/lib/edit.mjs +5 -3
  17. package/lib/generate.mjs +5 -3
  18. package/lib/generation-policy.mjs +1 -1
  19. package/lib/object-format.mjs +1 -1
  20. package/lib/prompt-structure.mjs +3 -3
  21. package/lib/service.mjs +21 -0
  22. package/lib/style-bundle.mjs +19 -6
  23. package/lib/style-contract.mjs +1 -1
  24. package/lib/style-lifecycle.mjs +8 -9
  25. package/lib/style-samples.mjs +92 -0
  26. package/lib/task-contract.mjs +2 -1
  27. package/lib/templates.mjs +1 -1
  28. package/lib/video/PROVENANCE.json +63 -0
  29. package/lib/video/atomic.mjs +32 -0
  30. package/lib/video/channel.mjs +70 -0
  31. package/lib/video/contract-local-media.mjs +42 -0
  32. package/lib/video/contract-story.mjs +213 -0
  33. package/lib/video/contract-video.mjs +117 -0
  34. package/lib/video/contracts.mjs +3 -0
  35. package/lib/video/h3.mjs +232 -0
  36. package/lib/video/local-runtime.mjs +20 -0
  37. package/lib/video/media.mjs +223 -0
  38. package/lib/video/models.mjs +336 -0
  39. package/lib/video/path.mjs +18 -0
  40. package/lib/video/process.mjs +15 -0
  41. package/lib/video/resource.mjs +15 -0
  42. package/lib/video/service.mjs +731 -0
  43. package/lib/video/workflow.mjs +571 -0
  44. package/lib/video.mjs +12 -0
  45. package/lib/workspace.mjs +34 -21
  46. package/package.json +8 -3
  47. package/rules/core-guidance.json +1 -1
  48. package/skills/art-workshop/SKILL.md +4 -2
  49. package/skills/art-workshop/references/project.md +19 -9
  50. package/skills/art-workshop/references/style-discussion.md +7 -3
  51. package/skills/art-workshop/references/video.md +13 -0
  52. package/v-cli.plugin.json +4594 -101
@@ -0,0 +1,571 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { join } from "node:path";
3
+ import { rm } from "node:fs/promises";
4
+ import { z } from "zod";
5
+ import {
6
+ cutTransition,
7
+ defaultVideoConfig,
8
+ durationConfig,
9
+ planVideoScript,
10
+ videoBusy,
11
+ videoComplete,
12
+ videoDependencyErrors
13
+ } from "./contracts.mjs";
14
+ import { projectPath } from "./path.mjs";
15
+ import { VideoMedia } from "./media.mjs";
16
+ const id = z.string().regex(/^[a-zA-Z0-9_-]{1,100}$/);
17
+ const title = z.string().trim().min(1).max(160);
18
+ const storyInputSchema = z.object({
19
+ assetId: id,
20
+ kind: z.enum(["first", "last", "middle", "reference"]),
21
+ frame: z.number().int().nonnegative().optional(),
22
+ role: z.enum(["subject", "style", "motion", "camera"]).optional()
23
+ }).strict();
24
+ const transition = z.object({
25
+ type: z.enum(["cut", "continue", "dissolve"]),
26
+ duration: z.number().finite().min(0).max(30).default(0),
27
+ note: z.string().max(4e3).default("")
28
+ }).strict();
29
+ const scriptSchema = z.object({
30
+ brief: z.string().max(2e4),
31
+ modelId: z.string().max(100),
32
+ mode: z.enum(["text", "boundary", "reference"]),
33
+ parameters: z.record(
34
+ z.string(),
35
+ z.union([z.string(), z.number().finite(), z.boolean()])
36
+ ),
37
+ inputs: z.array(storyInputSchema).max(128),
38
+ shots: z.array(
39
+ z.object({
40
+ id,
41
+ name: title,
42
+ prompt: z.string().max(2e4),
43
+ duration: z.number().positive().max(7200),
44
+ newClip: z.boolean().default(false),
45
+ mode: z.enum(["text", "boundary", "reference"]).optional(),
46
+ inputs: z.array(storyInputSchema).max(32).default([]),
47
+ transition: transition.default(cutTransition())
48
+ }).strict()
49
+ ).max(128)
50
+ }).strict();
51
+ const workflowActions = [
52
+ "script.read",
53
+ "script.update",
54
+ "script.plan",
55
+ "script.apply",
56
+ "operation.accept",
57
+ "operation.bind",
58
+ "film.compose",
59
+ "film.refine",
60
+ "film.preview",
61
+ "film.adopt",
62
+ "film.undo",
63
+ "media.status"
64
+ ];
65
+ function conflict() {
66
+ return Object.assign(new Error("任务已变化,请重新读取后再操作"), {
67
+ status: 409
68
+ });
69
+ }
70
+ function taskIn(state, taskId) {
71
+ const task = state.tasks.find((t) => t.id === id.parse(taskId));
72
+ if (!task) throw new Error("视频任务不存在");
73
+ return task;
74
+ }
75
+ function operationIn(task, operationId) {
76
+ const op = task.operations.find((o) => o.id === id.parse(operationId));
77
+ if (!op) throw new Error("视频操作不存在");
78
+ return op;
79
+ }
80
+ function writable(task, revision) {
81
+ if (task.archived) throw new Error("任务已归档");
82
+ if (task.revision !== revision) throw conflict();
83
+ }
84
+ function touch(task, op) {
85
+ task.revision++;
86
+ task.updatedAt = Date.now();
87
+ if (op) {
88
+ op.revision++;
89
+ op.updatedAt = task.updatedAt;
90
+ }
91
+ }
92
+ function newOperation(name, config) {
93
+ return {
94
+ id: randomUUID(),
95
+ name,
96
+ revision: 1,
97
+ config,
98
+ runs: [],
99
+ createdAt: Date.now(),
100
+ updatedAt: Date.now()
101
+ };
102
+ }
103
+ function bindTail(task, op) {
104
+ if (!op.dependency) return;
105
+ if (videoBusy(op) || videoComplete(op))
106
+ throw new Error("已运行操作不能改绑,请派生新操作");
107
+ const accepted = operationIn(task, op.dependency.operationId).accepted;
108
+ if (!accepted) throw new Error("请先采纳前段视频");
109
+ op.config.inputs = [
110
+ ...op.config.inputs.filter((i) => i.kind !== "first"),
111
+ { kind: "first", assetId: accepted.tailAssetId }
112
+ ];
113
+ op.dependency = {
114
+ ...op.dependency,
115
+ runId: accepted.runId,
116
+ assetId: accepted.tailAssetId
117
+ };
118
+ touch(task, op);
119
+ }
120
+ class VideoWorkflow {
121
+ constructor(host) {
122
+ this.host = host;
123
+ this.media = new VideoMedia(() => host.models.get(), host.signal);
124
+ }
125
+ host;
126
+ media;
127
+ async filename(w, file) {
128
+ return projectPath(w.root, join(await this.host.root(w), file));
129
+ }
130
+ async acceptedMedia(w, task, op) {
131
+ return op.accepted?.output ? { path: await this.filename(w, op.accepted.output) } : this.host.media(w, task.id, op.id, op.accepted.runId);
132
+ }
133
+ async filmMedia(w, taskId, filmId) {
134
+ const task = await this.host.get(w, taskId), film = task.films?.find((f) => f.id === id.parse(filmId));
135
+ if (!film) throw new Error("成片版本不存在");
136
+ return {
137
+ path: await this.filename(w, film.output),
138
+ name: `${task.name.replace(/[<>:"/\\|?*\x00-\x1f]/g, "_")}.mp4`
139
+ };
140
+ }
141
+ async execute(w, action, input) {
142
+ if (action === "media.status") return this.media.status();
143
+ if (action === "script.read") return this.host.get(w, input.taskId);
144
+ if (action === "script.plan") {
145
+ const task = await this.host.get(w, input.taskId), script = input.script ? scriptSchema.parse(input.script) : task.script;
146
+ if (!script)
147
+ return { segments: [], errors: ["请先保存剧本"], duration: 0 };
148
+ const model = (await this.host.models.catalog()).find(
149
+ (m) => m.id === script.modelId
150
+ );
151
+ return { ...planVideoScript(script, model), model };
152
+ }
153
+ if (action === "script.update") {
154
+ const script = scriptSchema.parse(input.script);
155
+ if (new Set(script.shots.map((s) => s.id)).size !== script.shots.length)
156
+ throw new Error("镜头 ID 重复");
157
+ if (script.inputs.some((i) => i.kind === "middle"))
158
+ throw new Error("中间帧请绑定到具体镜头");
159
+ return this.host.transaction(w, (state) => {
160
+ const task = taskIn(state, input.taskId);
161
+ writable(task, input.revision);
162
+ for (const i of [
163
+ ...script.inputs,
164
+ ...script.shots.flatMap((s) => s.inputs)
165
+ ])
166
+ if (!state.assets.some((a) => a.id === i.assetId))
167
+ throw new Error("引用素材不存在");
168
+ task.script = { ...script, revision: (task.script?.revision ?? 0) + 1 };
169
+ touch(task);
170
+ return task;
171
+ });
172
+ }
173
+ if (action === "script.apply") return this.apply(w, input);
174
+ if (action === "operation.accept") return this.accept(w, input);
175
+ if (action === "operation.bind")
176
+ return this.host.transaction(w, (state) => {
177
+ const task = taskIn(state, input.taskId), op = operationIn(task, input.operationId);
178
+ if (task.archived || op.revision !== input.revision) throw conflict();
179
+ bindTail(task, op);
180
+ return task;
181
+ });
182
+ if (action === "film.compose") return this.compose(w, input);
183
+ if (action === "film.refine") return this.refine(w, input);
184
+ if (action === "film.preview") return this.preview(w, input);
185
+ if (action === "film.adopt" || action === "film.undo")
186
+ return this.host.transaction(w, (state) => {
187
+ const task = taskIn(state, input.taskId);
188
+ writable(task, input.revision);
189
+ if (action === "film.undo") {
190
+ const current = task.films?.find((f) => f.id === task.currentFilmId);
191
+ if (!current?.parentId) throw new Error("没有可恢复的前一版本");
192
+ task.currentFilmId = current.parentId;
193
+ } else {
194
+ const film = task.films?.find((f) => f.id === id.parse(input.filmId));
195
+ if (!film?.refinementId || film.parentId !== task.currentFilmId)
196
+ throw new Error("候选基于其他成片版本,请重新选择当前版本精修");
197
+ task.currentFilmId = film.id;
198
+ }
199
+ touch(task);
200
+ return task;
201
+ });
202
+ throw new Error("未知视频工作流动作");
203
+ }
204
+ async apply(w, input) {
205
+ const catalog = await this.host.models.catalog();
206
+ return this.host.transaction(w, (state) => {
207
+ const task = taskIn(state, input.taskId);
208
+ writable(task, input.revision);
209
+ if (!task.script) throw new Error("请先保存剧本");
210
+ const model = catalog.find((m) => m.id === task.script.modelId), result = planVideoScript(task.script, model);
211
+ if (result.errors.length) throw new Error(result.errors.join(";"));
212
+ const planId = randomUUID();
213
+ for (let index = 0; index < result.segments.length; index++) {
214
+ const seg = result.segments[index], old = task.plan?.segments.find((s) => s.id === seg.id), prior = old && task.operations.find((o) => o.id === old.operationId);
215
+ const previous = index ? result.segments[index - 1].operationId : void 0;
216
+ const config = structuredClone(seg.config);
217
+ const before = prior ? structuredClone(prior.config) : void 0;
218
+ if (before && prior?.dependency)
219
+ before.inputs = before.inputs.filter(
220
+ (i) => !(i.kind === "first" && i.assetId === prior.dependency.assetId)
221
+ );
222
+ const reusable = prior && JSON.stringify(before) === JSON.stringify(config) && prior.editDuration === seg.duration && (!seg.dependency ? !prior.dependency : prior.dependency?.operationId === previous);
223
+ const op = reusable ? prior : newOperation(seg.name.slice(0, 160), config);
224
+ if (!reusable) {
225
+ op.scriptSegmentId = seg.id;
226
+ op.editDuration = seg.duration;
227
+ if (prior) op.derivedFrom = prior.id;
228
+ if (seg.dependency) {
229
+ op.dependency = { operationId: previous };
230
+ if (task.operations.find((o) => o.id === previous)?.accepted)
231
+ bindTail(task, op);
232
+ }
233
+ task.operations.push(op);
234
+ }
235
+ seg.operationId = op.id;
236
+ }
237
+ task.plan = {
238
+ id: planId,
239
+ scriptRevision: task.script.revision,
240
+ model: structuredClone(model),
241
+ segments: result.segments,
242
+ duration: result.duration
243
+ };
244
+ touch(task);
245
+ return task;
246
+ });
247
+ }
248
+ async accept(w, input) {
249
+ const snapshot = await this.host.get(w, input.taskId), op = operationIn(snapshot, input.operationId), run = op.runs.find((r) => r.id === id.parse(input.runId));
250
+ if (op.accepted?.runId === run?.id && run) return snapshot;
251
+ if (!run || run.status !== "succeeded")
252
+ throw new Error("只能采纳已成功生成的视频");
253
+ if (snapshot.archived || op.revision !== input.revision) throw conflict();
254
+ const errors = videoDependencyErrors(snapshot, op.id);
255
+ if (errors.length) throw new Error(errors.join(";"));
256
+ const source = await this.host.media(w, snapshot.id, op.id, run.id), info = await this.media.probe(source.path), duration = op.editDuration ?? info.duration;
257
+ if (duration > info.duration + 1 / info.fps)
258
+ throw new Error("生成结果短于计划时长,请重新生成或调整剧本");
259
+ const output = `accepted-${randomUUID()}.mp4`, normalized = await this.filename(w, output);
260
+ await this.media.render(
261
+ [
262
+ {
263
+ path: source.path,
264
+ start: 0,
265
+ duration,
266
+ sourceDuration: info.duration
267
+ }
268
+ ],
269
+ normalized,
270
+ info
271
+ );
272
+ try {
273
+ const bytes = await this.media.frame(
274
+ normalized,
275
+ Math.max(0, duration - 1 / info.fps),
276
+ await this.host.root(w)
277
+ );
278
+ const asset = await this.host.putAsset(
279
+ w,
280
+ `${op.name} · 采纳尾帧`.slice(0, 160),
281
+ bytes,
282
+ "capture",
283
+ { taskId: snapshot.id, operationId: op.id, runId: run.id }
284
+ );
285
+ return await this.host.transaction(w, (state) => {
286
+ const task = taskIn(state, snapshot.id), current = operationIn(task, op.id);
287
+ if (task.archived || current.revision !== input.revision)
288
+ throw conflict();
289
+ const changed = videoDependencyErrors(task, current.id);
290
+ if (changed.length) throw new Error(changed.join(";"));
291
+ current.accepted = {
292
+ runId: run.id,
293
+ tailAssetId: asset.id,
294
+ duration,
295
+ fps: info.fps,
296
+ output
297
+ };
298
+ touch(task, current);
299
+ let replaces = false;
300
+ if (current.scriptSegmentId) {
301
+ const seg = task.plan?.segments.find(
302
+ (s) => s.id === current.scriptSegmentId
303
+ );
304
+ if (seg && current.derivedFrom === seg.operationId) {
305
+ seg.operationId = current.id;
306
+ replaces = true;
307
+ }
308
+ }
309
+ if (current.refinementId) {
310
+ const refinement = task.refinements?.find(
311
+ (r) => r.id === current.refinementId
312
+ );
313
+ if (refinement?.operationIds.includes(current.derivedFrom ?? "")) {
314
+ refinement.operationIds = refinement.operationIds.map(
315
+ (id2) => id2 === current.derivedFrom ? current.id : id2
316
+ );
317
+ replaces = true;
318
+ }
319
+ }
320
+ if (replaces)
321
+ for (const dependent of task.operations.filter(
322
+ (o) => o.dependency?.operationId === current.derivedFrom
323
+ )) {
324
+ dependent.dependency.operationId = current.id;
325
+ touch(task, dependent);
326
+ }
327
+ for (const dependent of task.operations.filter(
328
+ (o) => o.dependency?.operationId === current.id && !videoBusy(o) && !videoComplete(o)
329
+ )) {
330
+ const first = dependent.config.inputs.find((i) => i.kind === "first");
331
+ if (!first || first.assetId === dependent.dependency?.assetId)
332
+ bindTail(task, dependent);
333
+ }
334
+ return task;
335
+ });
336
+ } catch (error) {
337
+ await rm(normalized, { force: true });
338
+ throw error;
339
+ }
340
+ }
341
+ async saveFilm(w, snapshot, film) {
342
+ try {
343
+ return await this.host.transaction(w, (state) => {
344
+ const task = taskIn(state, snapshot.id);
345
+ writable(task, snapshot.revision);
346
+ (task.films ??= []).push(film);
347
+ if (!film.refinementId) task.currentFilmId = film.id;
348
+ touch(task);
349
+ return task;
350
+ });
351
+ } catch (e) {
352
+ await rm(await this.filename(w, film.output), { force: true });
353
+ throw e;
354
+ }
355
+ }
356
+ async compose(w, input) {
357
+ const task = await this.host.get(w, input.taskId), requestId = id.parse(input.requestId);
358
+ if (task.films?.some((f) => f.requestId === requestId)) return task;
359
+ writable(task, input.revision);
360
+ if (!task.plan?.segments.length) throw new Error("请先应用剧本到视频操作");
361
+ if (task.plan.scriptRevision !== task.script?.revision)
362
+ throw new Error("剧本有新修改,请先重新应用生成安排");
363
+ const clips = [], parts = [];
364
+ for (const seg of task.plan.segments) {
365
+ const op = operationIn(task, seg.operationId), accepted = op.accepted;
366
+ if (!accepted) throw new Error(`请先采纳 ${op.name}`);
367
+ const errors = videoDependencyErrors(task, op.id);
368
+ if (errors.length) throw new Error(`${op.name}:${errors.join(";")}`);
369
+ const source = await this.acceptedMedia(w, task, op);
370
+ clips.push({
371
+ operationId: op.id,
372
+ runId: accepted.runId,
373
+ start: 0,
374
+ duration: seg.duration,
375
+ transition: seg.transition
376
+ });
377
+ parts.push({
378
+ path: source.path,
379
+ start: 0,
380
+ duration: seg.duration,
381
+ transition: seg.transition
382
+ });
383
+ }
384
+ const first = await this.media.probe(parts[0].path), filmId = randomUUID(), output = `film-${filmId}.mp4`;
385
+ const info = await this.media.render(
386
+ parts,
387
+ await this.filename(w, output),
388
+ first
389
+ );
390
+ return this.saveFilm(w, task, {
391
+ id: filmId,
392
+ requestId,
393
+ output,
394
+ ...info,
395
+ clips,
396
+ createdAt: Date.now(),
397
+ parentId: task.currentFilmId
398
+ });
399
+ }
400
+ async refine(w, input) {
401
+ const request = z.object({
402
+ taskId: id,
403
+ revision: z.number().int().positive(),
404
+ requestId: id,
405
+ filmId: id,
406
+ start: z.number().finite().nonnegative(),
407
+ end: z.number().finite().positive(),
408
+ modelId: z.string(),
409
+ prompt: z.string().trim().min(1).max(2e4),
410
+ keepAudio: z.boolean().default(true),
411
+ parameters: z.record(
412
+ z.string(),
413
+ z.union([z.string(), z.number().finite(), z.boolean()])
414
+ ).optional(),
415
+ sections: z.array(
416
+ z.object({
417
+ duration: z.number().positive(),
418
+ prompt: z.string().min(1).max(2e4)
419
+ }).strict()
420
+ ).min(1).max(32).optional()
421
+ }).strict().parse(input);
422
+ const task = await this.host.get(w, request.taskId);
423
+ if (task.refinements?.some((r) => r.requestId === request.requestId))
424
+ return task;
425
+ writable(task, request.revision);
426
+ const film = task.films?.find((f) => f.id === request.filmId);
427
+ if (!film || film.id !== task.currentFilmId)
428
+ throw new Error("请选择当前成片版本");
429
+ if (request.end <= request.start || request.end > film.duration)
430
+ throw new Error("精修选区超出成片范围");
431
+ const start = Math.round(request.start * film.fps) / film.fps, end = Math.round(request.end * film.fps) / film.fps;
432
+ if (end - start < 1 / film.fps) throw new Error("精修范围至少为一帧");
433
+ const model = (await this.host.models.catalog()).find(
434
+ (m) => m.id === request.modelId
435
+ );
436
+ if (!model) throw new Error("请选择精修生成模型");
437
+ const mode = Object.keys(model.modes).find((m) => model.modes[m]?.first && model.modes[m]?.last);
438
+ if (!mode) throw new Error("当前模型不支持同时固定首尾帧,请更换模型");
439
+ const sections = request.sections ?? [
440
+ { duration: end - start, prompt: request.prompt }
441
+ ];
442
+ if (Math.abs(sections.reduce((n, s) => n + s.duration, 0) - (end - start)) > 1 / film.fps / 2)
443
+ throw new Error("精修分段总时长应等于选区时长");
444
+ const configs = sections.map(
445
+ (s) => durationConfig(
446
+ model,
447
+ {
448
+ ...defaultVideoConfig(model),
449
+ mode,
450
+ parameters: {
451
+ ...defaultVideoConfig(model).parameters,
452
+ ...request.parameters
453
+ },
454
+ prompt: s.prompt
455
+ },
456
+ s.duration
457
+ )
458
+ );
459
+ const source = await this.filmMedia(w, task.id, film.id), root = await this.host.root(w);
460
+ const first = await this.host.putAsset(
461
+ w,
462
+ "精修首帧",
463
+ await this.media.frame(source.path, start, root),
464
+ "capture",
465
+ { filmId: film.id, time: String(start) }
466
+ );
467
+ const last = await this.host.putAsset(
468
+ w,
469
+ "精修尾帧",
470
+ await this.media.frame(
471
+ source.path,
472
+ Math.min(film.duration - 1 / film.fps, end - 1 / film.fps),
473
+ root
474
+ ),
475
+ "capture",
476
+ { filmId: film.id, time: String(end - 1 / film.fps) }
477
+ );
478
+ return this.host.transaction(w, (state) => {
479
+ const current = taskIn(state, task.id);
480
+ writable(current, request.revision);
481
+ const refinementId = randomUUID();
482
+ let previous;
483
+ const ops = configs.map((config, i) => {
484
+ config.inputs = [];
485
+ if (i === 0) config.inputs.push({ kind: "first", assetId: first.id });
486
+ if (i === configs.length - 1)
487
+ config.inputs.push({ kind: "last", assetId: last.id });
488
+ const op = newOperation(
489
+ `精修 ${start.toFixed(2)}–${end.toFixed(2)} · ${i + 1}`,
490
+ config
491
+ );
492
+ op.refinementId = refinementId;
493
+ op.editDuration = sections[i].duration;
494
+ if (previous) op.dependency = { operationId: previous };
495
+ previous = op.id;
496
+ return op;
497
+ });
498
+ current.operations.push(...ops);
499
+ (current.refinements ??= []).push({
500
+ id: refinementId,
501
+ requestId: request.requestId,
502
+ filmId: film.id,
503
+ start,
504
+ end,
505
+ keepAudio: request.keepAudio,
506
+ operationIds: ops.map((o) => o.id),
507
+ firstAssetId: first.id,
508
+ lastAssetId: last.id
509
+ });
510
+ touch(current);
511
+ return current;
512
+ });
513
+ }
514
+ async preview(w, input) {
515
+ const task = await this.host.get(w, input.taskId), requestId = id.parse(input.requestId);
516
+ if (task.films?.some((f) => f.requestId === requestId)) return task;
517
+ writable(task, input.revision);
518
+ const refinement = task.refinements?.find(
519
+ (r) => r.id === id.parse(input.refinementId)
520
+ );
521
+ if (!refinement || refinement.filmId !== task.currentFilmId)
522
+ throw new Error("精修来源已变化,请基于当前成片重新选择");
523
+ const film = task.films.find((f) => f.id === refinement.filmId), source = await this.filmMedia(w, task.id, film.id), parts = [];
524
+ const clips = [];
525
+ if (refinement.start > 0)
526
+ parts.push({ path: source.path, start: 0, duration: refinement.start });
527
+ for (const opId of refinement.operationIds) {
528
+ const op = operationIn(task, opId);
529
+ if (!op.accepted) throw new Error(`请先采纳 ${op.name}`);
530
+ const errors = videoDependencyErrors(task, op.id);
531
+ if (errors.length) throw new Error(errors.join(";"));
532
+ const media = await this.acceptedMedia(w, task, op), duration = op.editDuration;
533
+ parts.push({ path: media.path, start: 0, duration });
534
+ clips.push({
535
+ operationId: op.id,
536
+ runId: op.accepted.runId,
537
+ start: 0,
538
+ duration,
539
+ transition: cutTransition()
540
+ });
541
+ }
542
+ if (refinement.end < film.duration - 1e-6)
543
+ parts.push({
544
+ path: source.path,
545
+ start: refinement.end,
546
+ duration: film.duration - refinement.end
547
+ });
548
+ const filmId = randomUUID(), output = `film-${filmId}.mp4`, info = await this.media.render(
549
+ parts,
550
+ await this.filename(w, output),
551
+ film,
552
+ refinement.keepAudio ? source.path : void 0
553
+ );
554
+ return this.saveFilm(w, task, {
555
+ id: filmId,
556
+ requestId,
557
+ output,
558
+ ...info,
559
+ clips,
560
+ createdAt: Date.now(),
561
+ parentId: film.id,
562
+ refinementId: refinement.id
563
+ });
564
+ }
565
+ }
566
+ export {
567
+ VideoWorkflow,
568
+ scriptSchema,
569
+ storyInputSchema,
570
+ workflowActions
571
+ };
package/lib/video.mjs ADDED
@@ -0,0 +1,12 @@
1
+ export {createVideoChannel,actions,readActions,settingsRevision,stateFile,isVideoUploadBase64,VIDEO_SETTINGS_SNAPSHOT_VERSION} from './video/channel.mjs';
2
+ export {withResource,assertVideoRuntime} from './video/resource.mjs';
3
+ export {atomicJson,replaceFile} from './video/atomic.mjs';
4
+ export {execute as executeProcess} from './video/process.mjs';
5
+ export {projectPath} from './video/path.mjs';
6
+ export {VideoService,configSchema,videoActions} from './video/service.mjs';
7
+ export {VideoModels,videoSettingsSchema,compileVideo,validateVideoSettings} from './video/models.mjs';
8
+ export {VideoMedia} from './video/media.mjs';
9
+ export {VideoWorkflow,workflowActions,scriptSchema} from './video/workflow.mjs';
10
+ export {LocalVideoRuntime,assertLocalEndpoint} from './video/local-runtime.mjs';
11
+ export {h3Preset} from './video/h3.mjs';
12
+ export * from './video/contracts.mjs';