@kevlns/art-workshop 0.5.2 → 0.6.1

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 (53) hide show
  1. package/README.md +13 -11
  2. package/art-workshop.mjs +50 -10
  3. package/docs/channels.md +49 -0
  4. package/docs/commands.md +2158 -91
  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 +33 -2
  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 +2 -2
  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 +3 -3
  24. package/lib/style-lifecycle.mjs +7 -73
  25. package/lib/style-report.mjs +1 -1
  26. package/lib/style-samples.mjs +94 -0
  27. package/lib/task-contract.mjs +2 -1
  28. package/lib/templates.mjs +1 -1
  29. package/lib/video/PROVENANCE.json +63 -0
  30. package/lib/video/atomic.mjs +32 -0
  31. package/lib/video/channel.mjs +70 -0
  32. package/lib/video/contract-local-media.mjs +42 -0
  33. package/lib/video/contract-story.mjs +213 -0
  34. package/lib/video/contract-video.mjs +117 -0
  35. package/lib/video/contracts.mjs +3 -0
  36. package/lib/video/h3.mjs +232 -0
  37. package/lib/video/local-runtime.mjs +20 -0
  38. package/lib/video/media.mjs +223 -0
  39. package/lib/video/models.mjs +336 -0
  40. package/lib/video/path.mjs +18 -0
  41. package/lib/video/process.mjs +15 -0
  42. package/lib/video/resource.mjs +15 -0
  43. package/lib/video/service.mjs +731 -0
  44. package/lib/video/workflow.mjs +571 -0
  45. package/lib/video.mjs +12 -0
  46. package/lib/workspace.mjs +35 -21
  47. package/package.json +8 -3
  48. package/rules/core-guidance.json +1 -1
  49. package/skills/art-workshop/SKILL.md +4 -2
  50. package/skills/art-workshop/references/project.md +18 -9
  51. package/skills/art-workshop/references/style-discussion.md +8 -6
  52. package/skills/art-workshop/references/video.md +13 -0
  53. package/v-cli.plugin.json +4380 -276
@@ -0,0 +1,213 @@
1
+ import {
2
+ defaultVideoConfig,
3
+ validateVideo,
4
+ videoOutput
5
+ } from "./contract-video.mjs";
6
+ const emptyVideoScript = (model) => {
7
+ const config = defaultVideoConfig(model);
8
+ return {
9
+ brief: "",
10
+ modelId: config.modelId,
11
+ mode: config.mode,
12
+ parameters: config.parameters,
13
+ inputs: [],
14
+ shots: []
15
+ };
16
+ };
17
+ const cutTransition = () => ({
18
+ type: "cut",
19
+ duration: 0,
20
+ note: ""
21
+ });
22
+ function durationConfig(model, config, seconds) {
23
+ if (!Number.isFinite(seconds) || seconds <= 0)
24
+ throw new Error("镜头时长必须为正数");
25
+ if (seconds * Number(config.parameters.fps) < 1)
26
+ throw new Error("镜头时长至少为一帧");
27
+ const field = model.fields.duration;
28
+ if (!field) throw new Error("当前模型未声明时长参数");
29
+ const step = field.step ?? (field.type === "integer" ? 1 : 1e-3);
30
+ const values = field.enum ? field.enum.filter((n) => typeof n === "number").sort((a, b) => a - b) : [
31
+ Math.ceil((Math.max(seconds, field.minimum ?? step) - 1e-8) / step) * step
32
+ ];
33
+ for (const raw of values) {
34
+ const n = Number(raw.toFixed(8));
35
+ if (n < (field.minimum ?? 0) || n > (field.maximum ?? Infinity)) continue;
36
+ const next = {
37
+ ...config,
38
+ parameters: { ...config.parameters, duration: n }
39
+ };
40
+ try {
41
+ if (videoOutput(next, model).duration + 1e-6 >= seconds) return next;
42
+ } catch {
43
+ }
44
+ }
45
+ throw new Error("时长超出模型范围或帧数网格;请在自然动作边界拆分镜头");
46
+ }
47
+ function planVideoScript(script, model) {
48
+ const errors = [], segments = [];
49
+ if (!model || script.modelId !== model.id)
50
+ return { segments, errors: ["请选择生成模型"], duration: 0 };
51
+ if (!script.shots.length)
52
+ return { segments, errors: ["请先编写镜头剧本"], duration: 0 };
53
+ const base = {
54
+ ...defaultVideoConfig(model),
55
+ modelId: model.id,
56
+ mode: script.mode,
57
+ parameters: {
58
+ ...defaultVideoConfig(model).parameters,
59
+ ...script.parameters
60
+ },
61
+ prompt: "",
62
+ inputs: []
63
+ };
64
+ const groups = [];
65
+ for (const shot of script.shots) {
66
+ if (!shot.prompt.trim()) errors.push(`${shot.name}:请填写画面与动作`);
67
+ try {
68
+ durationConfig(model, base, shot.duration);
69
+ } catch (e) {
70
+ errors.push(`${shot.name}:${e.message}`);
71
+ }
72
+ const last = groups.at(-1), previous = last?.at(-1);
73
+ let combine = !!last && !shot.newClip && previous?.transition.type !== "dissolve" && (shot.mode ?? script.mode) === (previous?.mode ?? script.mode) && !shot.inputs.some((i) => i.kind === "first") && !previous?.inputs.some((i) => i.kind === "last");
74
+ if (combine)
75
+ try {
76
+ durationConfig(
77
+ model,
78
+ base,
79
+ last.reduce((n, s) => n + s.duration, 0) + shot.duration
80
+ );
81
+ } catch {
82
+ combine = false;
83
+ }
84
+ if (combine) last.push(shot);
85
+ else groups.push([shot]);
86
+ }
87
+ groups.forEach((shots, index) => {
88
+ const duration = shots.reduce((n, s) => n + s.duration, 0);
89
+ const dependency = index > 0 && groups[index - 1].at(-1).transition.type === "continue";
90
+ const inputs = script.inputs.filter(
91
+ (i) => i.kind === "reference" || i.kind === "first" && index === 0 || i.kind === "last" && index === groups.length - 1
92
+ ).map((i) => ({ ...i }));
93
+ let offset = 0;
94
+ for (const shot of shots) {
95
+ for (const input of shot.inputs)
96
+ inputs.push({
97
+ ...input,
98
+ ...input.kind === "middle" ? {
99
+ frame: (input.frame ?? 0) + Math.round(offset * Number(base.parameters.fps))
100
+ } : {}
101
+ });
102
+ offset += shot.duration;
103
+ }
104
+ const unique = inputs.filter(
105
+ (i, n) => i.kind !== "reference" || inputs.findIndex(
106
+ (x) => x.kind === i.kind && x.assetId === i.assetId
107
+ ) === n
108
+ );
109
+ if (dependency && unique.some((i) => i.kind === "first"))
110
+ errors.push(`${shots[0].name}:前段尾帧与指定首帧冲突`);
111
+ const preferred = shots[0].mode ?? script.mode;
112
+ const mode = [preferred, ...Object.keys(model.modes)].find(
113
+ (key) => {
114
+ const m = model.modes[key];
115
+ return m && (!dependency || m.first) && (!m.requireBoundary || dependency || unique.some((i) => i.kind === "first" || i.kind === "last")) && (key !== "reference" || unique.some((i) => i.kind === "reference")) && unique.every((i) => m[i.kind === "reference" ? "references" : i.kind]);
116
+ }
117
+ );
118
+ if (!mode)
119
+ errors.push(
120
+ `${shots[0].name}:模型没有同时支持这些素材及衔接约束的工作方式,请调整引用或切镜`
121
+ );
122
+ let config = {
123
+ ...base,
124
+ mode: mode ?? preferred,
125
+ inputs: unique,
126
+ prompt: shots.map(
127
+ (s, n) => `${shots.length > 1 ? `镜头${n + 1}:` : ""}${s.prompt}${s.transition.note ? `
128
+ 衔接设计:${s.transition.note}` : ""}`
129
+ ).join("\n\n")
130
+ };
131
+ try {
132
+ config = durationConfig(model, config, duration);
133
+ const checking = dependency ? {
134
+ ...config,
135
+ inputs: [
136
+ ...config.inputs,
137
+ { kind: "first", assetId: "pending-tail" }
138
+ ]
139
+ } : config;
140
+ for (const error of validateVideo(checking, model))
141
+ errors.push(`${shots[0].name}:${error}`);
142
+ segments.push({
143
+ id: shots.map((s) => s.id).join("."),
144
+ shotIds: shots.map((s) => s.id),
145
+ name: shots.length === 1 ? shots[0].name : `${shots[0].name} — ${shots.at(-1).name}`,
146
+ config,
147
+ duration,
148
+ generatedDuration: videoOutput(config, model).duration,
149
+ dependency,
150
+ transition: { ...shots.at(-1).transition }
151
+ });
152
+ } catch (e) {
153
+ errors.push(`${shots[0].name}:${e.message}`);
154
+ }
155
+ });
156
+ for (let i = 0; i < segments.length - 1; i++) {
157
+ const t = segments[i].transition;
158
+ if (t.type === "dissolve" && (t.duration <= 0 || t.duration >= Math.min(segments[i].duration, segments[i + 1].duration)))
159
+ errors.push(`${segments[i].name}:叠化时长应小于相邻两段时长`);
160
+ }
161
+ return {
162
+ segments,
163
+ errors: [...new Set(errors)],
164
+ duration: segments.reduce(
165
+ (n, s, i) => n + s.duration - (i < segments.length - 1 && s.transition.type === "dissolve" ? s.transition.duration : 0),
166
+ 0
167
+ )
168
+ };
169
+ }
170
+ function videoDependencyErrors(task, operationId) {
171
+ const op = task.operations.find((o) => o.id === operationId), dep = op?.dependency;
172
+ const errors = [];
173
+ if (op?.refinementId) {
174
+ const refinement = task.refinements?.find((r) => r.id === op.refinementId);
175
+ let source = op, index = refinement?.operationIds.indexOf(source.id) ?? -1;
176
+ const visited = /* @__PURE__ */ new Set();
177
+ while (index < 0 && source.derivedFrom && !visited.has(source.id)) {
178
+ visited.add(source.id);
179
+ const previous = task.operations.find((o) => o.id === source.derivedFrom);
180
+ if (!previous) break;
181
+ source = previous;
182
+ index = refinement?.operationIds.indexOf(source.id) ?? -1;
183
+ }
184
+ if (!refinement || index < 0) errors.push("精修操作不属于当前精修安排");
185
+ else {
186
+ if (index === 0 && !op.config.inputs.some(
187
+ (i) => i.kind === "first" && i.assetId === refinement.firstAssetId
188
+ ))
189
+ errors.push("精修首帧必须保留原选区边界");
190
+ if (index === refinement.operationIds.length - 1 && !op.config.inputs.some(
191
+ (i) => i.kind === "last" && i.assetId === refinement.lastAssetId
192
+ ))
193
+ errors.push("精修尾帧必须保留原选区边界");
194
+ }
195
+ }
196
+ if (!dep) return errors;
197
+ const accepted = task.operations.find(
198
+ (o) => o.id === dep.operationId
199
+ )?.accepted;
200
+ if (!accepted) return [...errors, "等待前段生成并采纳尾帧"];
201
+ if (dep.runId !== accepted.runId || dep.assetId !== accepted.tailAssetId || !op.config.inputs.some(
202
+ (i) => i.kind === "first" && i.assetId === dep.assetId
203
+ ))
204
+ errors.push("前段已变化,请重新绑定采纳的尾帧");
205
+ return errors;
206
+ }
207
+ export {
208
+ cutTransition,
209
+ durationConfig,
210
+ emptyVideoScript,
211
+ planVideoScript,
212
+ videoDependencyErrors
213
+ };
@@ -0,0 +1,117 @@
1
+ const videoModeLabels = {
2
+ text: "纯文本创作",
3
+ boundary: "固定首/尾帧",
4
+ reference: "参考素材创作"
5
+ };
6
+ const videoBusy = (op) => ["dispatching", "running", "unknown"].includes(op.runs.at(-1)?.status ?? "");
7
+ const videoComplete = (op) => op.runs.at(-1)?.status === "succeeded";
8
+ function defaultVideoConfig(model) {
9
+ return {
10
+ modelId: model?.id ?? "",
11
+ mode: Object.keys(model?.modes ?? { text: {} })[0],
12
+ prompt: "",
13
+ parameters: Object.fromEntries(
14
+ Object.entries(model?.fields ?? {}).map(([key, field]) => [
15
+ key,
16
+ field.default
17
+ ])
18
+ ),
19
+ inputs: []
20
+ };
21
+ }
22
+ function videoOutput(config, model) {
23
+ const fps = Number(config.parameters.fps), duration = Number(config.parameters.duration);
24
+ const { multiple, offset, maximum } = model.frames;
25
+ if (!Number.isFinite(fps) || fps <= 0 || !Number.isFinite(duration) || duration <= 0 || !Number.isInteger(multiple) || multiple < 1)
26
+ throw new Error("时长或帧率无效");
27
+ const frames = Math.max(
28
+ offset,
29
+ Math.ceil((Math.round(fps * duration) - offset) / multiple) * multiple + offset
30
+ );
31
+ if (!Number.isSafeInteger(frames) || frames < 1 || frames > maximum)
32
+ throw new Error("总帧数超出模型范围");
33
+ return {
34
+ fps,
35
+ frames,
36
+ duration: frames / fps,
37
+ width: Number(config.parameters.width),
38
+ height: Number(config.parameters.height)
39
+ };
40
+ }
41
+ function validateVideo(config, model) {
42
+ const errors = [];
43
+ if (config.modelId !== model.id) errors.push("模型身份不匹配");
44
+ if (!config.prompt.trim()) errors.push("请填写本次内容");
45
+ const mode = model.modes[config.mode];
46
+ if (!mode) errors.push("模型不支持此工作方式");
47
+ for (const key of Object.keys(config.parameters))
48
+ if (!model.fields[key]) errors.push(`不支持的参数:${key}`);
49
+ for (const [key, field] of Object.entries(model.fields)) {
50
+ const value = config.parameters[key];
51
+ const numeric = field.type === "number" || field.type === "integer";
52
+ if (typeof value !== (numeric ? "number" : field.type) || numeric && (!Number.isFinite(value) || field.type === "integer" && !Number.isSafeInteger(value))) {
53
+ errors.push(`${field.label}类型无效`);
54
+ continue;
55
+ }
56
+ if (field.enum && !field.enum.includes(value))
57
+ errors.push(`${field.label}不在允许值中`);
58
+ if (numeric) {
59
+ const n = value;
60
+ if (field.minimum !== void 0 && n < field.minimum || field.maximum !== void 0 && n > field.maximum)
61
+ errors.push(`${field.label}超出范围`);
62
+ if (field.step && Math.abs(n / field.step - Math.round(n / field.step)) > 1e-6)
63
+ errors.push(`${field.label}步长无效`);
64
+ }
65
+ }
66
+ try {
67
+ const output = videoOutput(config, model);
68
+ if (!Number.isInteger(output.width) || !Number.isInteger(output.height) || output.width <= 0 || output.height <= 0 || output.width * output.height > model.maximumPixels)
69
+ errors.push("分辨率超出模型范围");
70
+ const occupied = /* @__PURE__ */ new Set();
71
+ for (const input of config.inputs) {
72
+ if (!mode?.[input.kind === "reference" ? "references" : input.kind])
73
+ errors.push("当前工作方式不支持已引入的约束");
74
+ if (input.kind === "middle" && (!Number.isInteger(input.frame) || input.frame <= 0 || input.frame >= output.frames - 1))
75
+ errors.push("中间帧位置超出范围");
76
+ const key = input.kind === "reference" ? `reference:${input.assetId}` : input.kind === "middle" ? `middle:${input.frame}` : input.kind;
77
+ if (occupied.has(key)) errors.push("同一位置不能重复引入画面");
78
+ occupied.add(key);
79
+ }
80
+ } catch (e) {
81
+ errors.push(e.message);
82
+ }
83
+ if (mode?.requireBoundary && !config.inputs.some((i) => i.kind === "first" || i.kind === "last"))
84
+ errors.push("至少引入首帧或尾帧");
85
+ if (mode?.references && !config.inputs.some((i) => i.kind === "reference"))
86
+ errors.push("请添加参考素材");
87
+ return [...new Set(errors)];
88
+ }
89
+ function timelinePosition(value, unit, fps, frames) {
90
+ let n;
91
+ if (unit === "frame") {
92
+ if (!/^F?\d+$/i.test(value.trim())) throw new Error("请输入整数帧号");
93
+ n = Number(value.trim().replace(/^F/i, ""));
94
+ } else {
95
+ const raw = value.trim().replace(/(?:s|秒)$/i, "");
96
+ if (!/^(?:\d+:){0,2}\d+(?:\.\d+)?$/.test(raw))
97
+ throw new Error("请输入秒数或时分秒");
98
+ const parts = raw.split(":").map(Number);
99
+ if (parts.length > 1 && parts.slice(1).some((x) => x >= 60))
100
+ throw new Error("时分秒格式无效");
101
+ const seconds = parts.reduce((total, part) => total * 60 + part, 0);
102
+ if (seconds > frames / fps + 5e-4) throw new Error("时间超出范围");
103
+ n = Math.min(frames - 1, Math.round(seconds * fps));
104
+ }
105
+ if (!Number.isSafeInteger(n) || n < 0 || n >= frames)
106
+ throw new Error("位置超出范围");
107
+ return n;
108
+ }
109
+ export {
110
+ defaultVideoConfig,
111
+ timelinePosition,
112
+ validateVideo,
113
+ videoBusy,
114
+ videoComplete,
115
+ videoModeLabels,
116
+ videoOutput
117
+ };
@@ -0,0 +1,3 @@
1
+ export * from './contract-video.mjs';
2
+ export * from './contract-story.mjs';
3
+ export * from './contract-local-media.mjs';
@@ -0,0 +1,232 @@
1
+ import { localMediaModels } from "./contracts.mjs";
2
+ function h3Preset() {
3
+ const graph = {
4
+ "1": {
5
+ class_type: "UNETLoader",
6
+ inputs: {
7
+ unet_name: localMediaModels.video[0].split("/").at(-1),
8
+ weight_dtype: "default"
9
+ }
10
+ },
11
+ "2": {
12
+ class_type: "CLIPLoader",
13
+ inputs: {
14
+ clip_name: localMediaModels.video[2].split("/").at(-1),
15
+ type: "minimax",
16
+ device: "default"
17
+ }
18
+ },
19
+ "3": {
20
+ class_type: "VAELoader",
21
+ inputs: { vae_name: localMediaModels.video[3].split("/").at(-1) }
22
+ },
23
+ "4": {
24
+ class_type: "VAELoader",
25
+ inputs: { vae_name: localMediaModels.video[4].split("/").at(-1) }
26
+ },
27
+ "5": {
28
+ class_type: "MiniMaxH3ImageToVideo",
29
+ inputs: {
30
+ clip: ["2", 0],
31
+ vae: ["3", 0],
32
+ prompt: "$prompt",
33
+ width: "$width",
34
+ height: "$height",
35
+ length: "$frames"
36
+ }
37
+ },
38
+ "6": {
39
+ class_type: "BasicGuider",
40
+ inputs: { model: ["1", 0], conditioning: ["5", 0] }
41
+ },
42
+ "7": { class_type: "KSamplerSelect", inputs: { sampler_name: "$sampler" } },
43
+ "8": {
44
+ class_type: "BasicScheduler",
45
+ inputs: {
46
+ model: ["1", 0],
47
+ scheduler: "$scheduler",
48
+ steps: "$steps",
49
+ denoise: 1
50
+ }
51
+ },
52
+ "9": { class_type: "RandomNoise", inputs: { noise_seed: "$seed" } },
53
+ "10": {
54
+ class_type: "SamplerCustomAdvanced",
55
+ inputs: {
56
+ noise: ["9", 0],
57
+ guider: ["6", 0],
58
+ sampler: ["7", 0],
59
+ sigmas: ["8", 0],
60
+ latent_image: ["5", 1]
61
+ }
62
+ },
63
+ "11": {
64
+ class_type: "VAEDecode",
65
+ inputs: { samples: ["10", 0], vae: ["3", 0] }
66
+ },
67
+ "12": {
68
+ class_type: "VAEDecodeAudio",
69
+ inputs: { samples: ["10", 0], vae: ["4", 0] }
70
+ },
71
+ "13": {
72
+ class_type: "CreateVideo",
73
+ inputs: {
74
+ images: ["11", 0],
75
+ audio: ["12", 0],
76
+ fps: "$fps",
77
+ bit_depth: 8,
78
+ color_space: "sRGB"
79
+ }
80
+ },
81
+ "14": {
82
+ class_type: "SaveVideo",
83
+ inputs: {
84
+ video: ["13", 0],
85
+ filename_prefix: "vant/video",
86
+ format: "mp4",
87
+ "format.codec": "h264"
88
+ }
89
+ }
90
+ };
91
+ const requiredModels = [
92
+ { node: "1", input: "unet_name", value: graph["1"].inputs.unet_name },
93
+ { node: "2", input: "clip_name", value: graph["2"].inputs.clip_name },
94
+ { node: "3", input: "vae_name", value: graph["3"].inputs.vae_name },
95
+ { node: "4", input: "vae_name", value: graph["4"].inputs.vae_name }
96
+ ];
97
+ const reference = structuredClone(graph);
98
+ reference["1"].inputs.unet_name = localMediaModels.video[1].split("/").at(-1);
99
+ reference["5"] = {
100
+ class_type: "MiniMaxH3ReferenceToVideo",
101
+ inputs: {
102
+ clip: ["2", 0],
103
+ vae: ["3", 0],
104
+ audio_vae: ["4", 0],
105
+ prompt: "$prompt",
106
+ width: "$width",
107
+ height: "$height",
108
+ length: "$frames",
109
+ ref_image_size: "match"
110
+ }
111
+ };
112
+ return {
113
+ models: [
114
+ {
115
+ id: "minimax-h3",
116
+ name: "MiniMax H3 · 本地 ComfyUI",
117
+ adapter: "comfyui",
118
+ fields: {
119
+ duration: {
120
+ label: "期望时长 / 秒",
121
+ type: "number",
122
+ default: 8,
123
+ minimum: 0.2,
124
+ maximum: 30,
125
+ step: 0.01
126
+ },
127
+ fps: { label: "帧率", type: "integer", default: 24, enum: [24] },
128
+ width: {
129
+ label: "宽度",
130
+ type: "integer",
131
+ default: 864,
132
+ enum: [768, 864, 1024],
133
+ step: 32
134
+ },
135
+ height: {
136
+ label: "高度",
137
+ type: "integer",
138
+ default: 480,
139
+ enum: [480, 512, 576],
140
+ step: 32
141
+ },
142
+ seed: {
143
+ label: "随机种子",
144
+ type: "integer",
145
+ default: 1,
146
+ minimum: 0,
147
+ maximum: Number.MAX_SAFE_INTEGER,
148
+ step: 1
149
+ },
150
+ steps: {
151
+ label: "采样步数",
152
+ type: "integer",
153
+ default: 20,
154
+ minimum: 1,
155
+ maximum: 60,
156
+ step: 1
157
+ },
158
+ sampler: {
159
+ label: "采样器",
160
+ type: "string",
161
+ default: "res_multistep",
162
+ enum: ["res_multistep"]
163
+ },
164
+ scheduler: {
165
+ label: "调度器",
166
+ type: "string",
167
+ default: "simple",
168
+ enum: ["simple"]
169
+ }
170
+ },
171
+ modes: {
172
+ text: {
173
+ first: false,
174
+ last: false,
175
+ middle: true,
176
+ references: false,
177
+ template: "h3-fl2va"
178
+ },
179
+ boundary: {
180
+ first: true,
181
+ last: true,
182
+ middle: true,
183
+ references: false,
184
+ requireBoundary: true,
185
+ template: "h3-fl2va"
186
+ },
187
+ reference: {
188
+ first: false,
189
+ last: false,
190
+ middle: false,
191
+ references: true,
192
+ template: "h3-ref2va"
193
+ }
194
+ },
195
+ frames: { multiple: 17, offset: 5, maximum: 736 },
196
+ maximumPixels: 589824
197
+ }
198
+ ],
199
+ templates: {
200
+ "h3-fl2va": {
201
+ graph,
202
+ requiredModels,
203
+ imageBindings: {
204
+ first: { node: "5", input: "first_frame" },
205
+ last: { node: "5", input: "last_frame" }
206
+ },
207
+ guides: {
208
+ conditioning: ["5", 0],
209
+ latent: ["5", 1],
210
+ vae: ["3", 0],
211
+ targets: [{ node: "6", input: "conditioning" }]
212
+ }
213
+ },
214
+ "h3-ref2va": {
215
+ referencePrompt: "minimax-tags",
216
+ graph: reference,
217
+ requiredModels: requiredModels.map(
218
+ (r) => r.node === "1" ? { ...r, value: String(reference["1"].inputs.unet_name) } : r
219
+ ),
220
+ imageBindings: {
221
+ references: Array.from({ length: 9 }, (_, n) => ({
222
+ node: "5",
223
+ input: `ref_images.ref_image_${n}`
224
+ }))
225
+ }
226
+ }
227
+ }
228
+ };
229
+ }
230
+ export {
231
+ h3Preset
232
+ };
@@ -0,0 +1,20 @@
1
+ import {stat} from 'node:fs/promises';
2
+ import {join,isAbsolute,resolve,relative} from 'node:path';
3
+ import {pathToFileURL} from 'node:url';
4
+ import {createHash} from 'node:crypto';
5
+ import {isDeepStrictEqual} from 'node:util';
6
+ import {canonicalVideoRoot} from './path.mjs';
7
+ export const assertLocalEndpoint=value=>{const u=new URL(value);if(u.protocol!=='http:'||!['127.0.0.1','localhost','[::1]'].includes(u.hostname)||u.pathname!=='/'||u.username||u.password||u.search||u.hash)throw new Error('视频服务仅支持已配置的本机 HTTP 根地址');return u};
8
+ const exists=path=>stat(path).then(value=>value.isFile()&&value.size>0,()=>false);
9
+ export class LocalVideoRuntime{
10
+ constructor({root,instanceId,sdkRoot,fetcher=fetch}={}){this.root=root?canonicalVideoRoot(root):root;this.prefix=`dsh-vant-video-${createHash('sha256').update(this.root||'').digest('hex').slice(0,16)}-`;this.instanceId=instanceId?.startsWith(this.prefix)?instanceId:this.prefix+(instanceId||'reader');this.sdkRoot=sdkRoot||null;this.fetcher=fetcher;this.liveCache=new Map();}
11
+ async sdk(){const service=await import(this.sdkRoot?pathToFileURL(join(this.sdkRoot,'@kevlns/art-workshop/lib/service.mjs')).href:new URL('../service.mjs',import.meta.url).href).catch(()=>null);if(!service?.ensureService||!service.closeService||!service.rememberedService||!service.processIdentity)throw new Error('受管本地视频运行时 SDK 不可用;请安装兼容的 art-workshop');return service}
12
+ async reachable(config,signal){const url=assertLocalEndpoint(config.localEndpoint),key=url.href,cached=this.liveCache.get(key);if(!signal&&cached&&cached.until>Date.now())return cached.promise;const entry={until:Infinity,promise:null};entry.promise=(async()=>{try{const response=await this.fetcher(new URL('system_stats',url),{signal:signal?AbortSignal.any([signal,AbortSignal.timeout(3000)]):AbortSignal.timeout(3000)});return response.ok}catch{return false}finally{entry.until=Date.now()+2000}})();this.liveCache.set(key,entry);return entry.promise}
13
+ async python(root){for(const file of ['python_embeded/python.exe','.venv/Scripts/python.exe','.venv/bin/python'])if(await exists(join(root,file)))return join(root,file)}
14
+ async fileIssues(config){const root=config.localInstallRoot;if(!root||!isAbsolute(root))return ['ComfyUI 未运行;如需受管启动,请配置本地环境绝对目录'];const errors=[];if(!await this.python(root))errors.push('环境中缺少 Python');if(!await exists(join(root,'ComfyUI/main.py')))errors.push('环境中缺少 ComfyUI/main.py');const folders={UNETLoader:'diffusion_models',CLIPLoader:'text_encoders',VAELoader:'vae'};for(const model of config.models)for(const mode of Object.values(model.modes)){const template=config.templates[mode.template];if(!template){errors.push('缺少工作流 '+mode.template);continue}if(model.id==='minimax-h3'&&!await exists(join(root,'ComfyUI/comfy_extras/nodes_minimax_h3.py')))errors.push('缺少 MiniMax H3 原生节点');for(const item of template.requiredModels){const folder=folders[template.graph[item.node]?.class_type];if(!folder){errors.push('无法核对模型加载节点 '+item.node);continue}const base=resolve(root,'ComfyUI/models',folder),target=resolve(base,item.value),delta=relative(base,target);if(isAbsolute(delta)||delta.startsWith('..')||!await exists(target))errors.push('缺少模型 '+item.value)}}try{await this.sdk()}catch(error){errors.push(error.message)}return [...new Set(errors)]}
15
+ async inspect(config){assertLocalEndpoint(config.localEndpoint);if(await this.reachable(config))return [];return this.fileIssues(config)}
16
+ backend(config,python){return {id:'vant-local-video',workflow:'vant-video',template:{},bindings:{},endpoints:[config.localEndpoint],launch:{executable:python,cwd:config.localInstallRoot,args:['-s','ComfyUI/main.py','--disable-dynamic-vram','--lowvram','--disable-auto-launch','--listen','127.0.0.1','--port',new URL(config.localEndpoint).port||'80'],startupTimeoutSeconds:120}}}
17
+ async ensure(config,signal){signal.throwIfAborted();assertLocalEndpoint(config.localEndpoint);if(await this.reachable(config,signal))return;const errors=await this.fileIssues(config);if(errors.length)throw new Error(errors.join(';'));const sdk=await this.sdk();const previous=process.env.VANT_SERVICE_INSTANCE;process.env.VANT_SERVICE_INSTANCE=this.instanceId;try{await sdk.ensureService(this.backend(config,await this.python(config.localInstallRoot)),config.localInstallRoot,{cancelled:()=>signal.aborted})}finally{if(previous===undefined)delete process.env.VANT_SERVICE_INSTANCE;else process.env.VANT_SERVICE_INSTANCE=previous}this.liveCache.delete(new URL(config.localEndpoint).href);signal.throwIfAborted()}
18
+ async status(config){const running=await this.reachable(config),startupIssues=await this.fileIssues(config);let record=null,sdkAvailable=false;try{const sdk=await this.sdk();sdkAvailable=true;record=sdk.rememberedService(config.localInstallRoot,config.localEndpoint)}catch{}const owned=!!(record?.owned&&record.owner?.instanceId?.startsWith(this.prefix));return {mode:config.localInstallRoot?'managed-local':'external-existing',running,endpoint:config.localEndpoint,autoStartConfigured:!!config.localInstallRoot,autoStart:!!config.localInstallRoot&&!startupIssues.length,sdkAvailable,ownedByProject:owned,origin:owned?'managed-sdk':running?'external':'unavailable',startupIssues,issues:running?[]:startupIssues}}
19
+ async stop(config){const sdk=await this.sdk(),record=sdk.rememberedService(config.localInstallRoot,config.localEndpoint);if(!record?.owned||!record.owner?.instanceId?.startsWith(this.prefix)||!record.identity)throw new Error('当前服务不是此项目的受管服务,不会停止外部进程');const identity=await sdk.processIdentity(record.identity.pid);if(!isDeepStrictEqual(identity,record.identity))throw new Error('受管视频服务进程身份已变化,不会停止');if(typeof sdk.closeOwnedService!=='function')throw Object.assign(new Error('受管 SDK 缺少所有者绑定的安全关闭能力,不能关闭服务'),{code:'video-runtime-stop-unavailable'});const expected=structuredClone({owner:record.owner,identity:record.identity});try{return await sdk.closeOwnedService(config.localInstallRoot,config.localEndpoint,this.backend(config,await this.python(config.localInstallRoot)),expected)}catch(error){throw Object.assign(error,{unknown:true})}}
20
+ }