@kevlns/art-workshop 0.2.1 → 0.3.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/AGENTS.md +24 -51
- package/README.md +31 -93
- package/art-workshop.mjs +69 -25
- package/docs/commands.md +913 -80
- package/docs/configuration.md +33 -139
- package/docs/core-guidance.md +7 -7
- package/docs/data-formats.md +14 -152
- package/docs/deployment.md +40 -0
- package/docs/model-architecture.md +52 -0
- package/docs/modes.md +15 -116
- package/docs/remote-models.md +42 -0
- package/docs/troubleshooting.md +30 -68
- package/lib/adapters/dashscope.mjs +234 -0
- package/lib/adapters/index.mjs +28 -0
- package/lib/agent.mjs +2 -2
- package/lib/analysis-worker.mjs +25 -0
- package/lib/analyze.mjs +8 -8
- package/lib/backends.mjs +350 -74
- package/lib/bl.mjs +3 -18
- package/lib/candidates.mjs +82 -0
- package/lib/comfyui.mjs +10 -8
- package/lib/contracts.d.ts +67 -0
- package/lib/deployment-worker.mjs +97 -0
- package/lib/deployment.mjs +72 -0
- package/lib/design.mjs +5 -5
- package/lib/dimensions.mjs +22 -0
- package/lib/edit.mjs +6 -3
- package/lib/environments.mjs +67 -0
- package/lib/execution/remote.mjs +156 -0
- package/lib/executor.mjs +10 -24
- package/lib/generate.mjs +9 -5
- package/lib/generation-policy.mjs +198 -0
- package/lib/images.mjs +10 -0
- package/lib/lifecycle.mjs +40 -0
- package/lib/migration.mjs +154 -0
- package/lib/model-catalog.mjs +288 -0
- package/lib/model-registry.mjs +234 -0
- package/lib/plan.mjs +98 -28
- package/lib/project.mjs +13 -4
- package/lib/providers.mjs +27 -22
- package/lib/refs.mjs +12 -16
- package/lib/runtime.mjs +6 -4
- package/lib/service.mjs +45 -4
- package/lib/settings.mjs +2 -4
- package/lib/style-lifecycle.mjs +72 -0
- package/lib/task-references.mjs +35 -0
- package/lib/task-worker.mjs +225 -50
- package/lib/tasks.mjs +440 -63
- package/lib/templates.mjs +69 -0
- package/lib/transport/cli.mjs +69 -0
- package/lib/transport/http.mjs +82 -0
- package/lib/vision.mjs +46 -0
- package/lib/workflows.mjs +10 -1
- package/lib/workspace.mjs +190 -0
- package/package.json +9 -3
- package/skills/art-workshop/SKILL.md +27 -54
- package/v-cli.plugin.json +1257 -143
- package/docs//351/227/256/351/242/230/346/212/245/345/221/212-2026-10-08.md +0 -29
package/lib/task-worker.mjs
CHANGED
|
@@ -1,58 +1,233 @@
|
|
|
1
|
-
import {existsSync,readdirSync,renameSync,
|
|
2
|
-
import {join} from
|
|
3
|
-
import {readJson,writeJson,hash} from
|
|
4
|
-
import {sha256File} from
|
|
5
|
-
import {validatePlan} from
|
|
6
|
-
import {externalPath} from
|
|
7
|
-
import {ensureService} from
|
|
8
|
-
import {generate,generationRequest} from
|
|
9
|
-
import {cancelPrompt} from
|
|
1
|
+
import { existsSync, readdirSync, renameSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { readJson, writeJson, hash } from "./shared.mjs";
|
|
4
|
+
import { sha256File } from "./bl.mjs";
|
|
5
|
+
import { validatePlan } from "./plan.mjs";
|
|
6
|
+
import { externalPath } from "./settings.mjs";
|
|
7
|
+
import { ensureService } from "./service.mjs";
|
|
8
|
+
import { generate, generationRequest } from "./providers.mjs";
|
|
9
|
+
import { cancelPrompt } from "./comfyui.mjs";
|
|
10
|
+
import { validateImage } from "./images.mjs";
|
|
10
11
|
|
|
11
|
-
const file=process.argv[2],
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const file = process.argv[2],
|
|
13
|
+
task = readJson(file);
|
|
14
|
+
const cancelled = () => {
|
|
15
|
+
const requested =
|
|
16
|
+
existsSync(file + ".cancel") ||
|
|
17
|
+
existsSync(join(task.root, "shutdown.json"));
|
|
18
|
+
if (
|
|
19
|
+
requested &&
|
|
20
|
+
!["succeeded", "failed", "cancelled", "unknown"].includes(task.status)
|
|
21
|
+
)
|
|
22
|
+
task.status = "cancelling";
|
|
23
|
+
return requested;
|
|
24
|
+
};
|
|
25
|
+
const persist = () => {
|
|
26
|
+
task.heartbeat = new Date().toISOString();
|
|
27
|
+
writeJson(file, task);
|
|
28
|
+
};
|
|
29
|
+
task.workerPid = process.pid;
|
|
30
|
+
task.status = "running";
|
|
31
|
+
persist();
|
|
32
|
+
const heartbeat = setInterval(persist, 1000);
|
|
33
|
+
let manifest, manifestPath;
|
|
34
|
+
function saveManifest() {
|
|
35
|
+
if (!manifest) return;
|
|
36
|
+
manifest.summary = {
|
|
37
|
+
expected: task.items.length,
|
|
38
|
+
completed: manifest.items.filter((x) => x.status !== "running").length,
|
|
39
|
+
ok: manifest.items.filter((x) => x.ok).length,
|
|
40
|
+
failed: manifest.items.filter((x) => x.status === "failed").length,
|
|
41
|
+
cancelled: manifest.items.filter((x) => x.status === "cancelled").length,
|
|
42
|
+
};
|
|
43
|
+
writeJson(manifestPath, manifest);
|
|
44
|
+
}
|
|
18
45
|
try {
|
|
19
|
-
validatePlan(task.plan);
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
validatePlan(task.plan);
|
|
47
|
+
externalPath(task.outputRoot, "输出目录");
|
|
48
|
+
for (const ref of task.resumeOnly ? [] : task.plan.refs)
|
|
49
|
+
if (sha256File(externalPath(ref.path)) !== ref.hash)
|
|
50
|
+
throw new Error("原图/参考图已变化:" + ref.path);
|
|
51
|
+
const runDir = join(task.outputRoot, task.plan.job + "-" + task.taskId);
|
|
52
|
+
manifestPath = join(runDir, "manifest.json");
|
|
53
|
+
task.manifestPath = manifestPath;
|
|
54
|
+
manifest = task.resumeOnly
|
|
55
|
+
? readJson(manifestPath)
|
|
56
|
+
: {
|
|
57
|
+
schema: "art-workshop/run",
|
|
58
|
+
runId: task.taskId,
|
|
59
|
+
taskId: task.taskId,
|
|
60
|
+
plan: task.plan,
|
|
61
|
+
planHash: task.plan.planHash,
|
|
62
|
+
provider: task.plan.backend?.provider ?? "bailian",
|
|
63
|
+
startedAt: new Date().toISOString(),
|
|
64
|
+
items: [],
|
|
65
|
+
};
|
|
66
|
+
if (
|
|
67
|
+
manifest.taskId !== task.taskId ||
|
|
68
|
+
manifest.planHash !== task.plan.planHash
|
|
69
|
+
)
|
|
70
|
+
throw new Error("原批次结果身份不匹配");
|
|
71
|
+
if (task.resumeOnly) manifest.finishedAt = null;
|
|
72
|
+
saveManifest();
|
|
73
|
+
persist();
|
|
74
|
+
const backend = task.plan.backend;
|
|
75
|
+
if (backend?.provider === "comfyui")
|
|
76
|
+
task.endpoint = await ensureService(backend, task.root, { cancelled });
|
|
77
|
+
for (const item of task.items) {
|
|
78
|
+
if (cancelled()) break;
|
|
79
|
+
if (
|
|
80
|
+
task.resumeOnly &&
|
|
81
|
+
!["accepted", "completed"].includes(
|
|
82
|
+
task.remoteExecutions?.[item.inputHash]?.state,
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
continue;
|
|
86
|
+
if (
|
|
87
|
+
task.resumeOnly &&
|
|
88
|
+
manifest.items.some((row) => row.inputHash === item.inputHash && row.ok)
|
|
89
|
+
)
|
|
90
|
+
continue;
|
|
91
|
+
task.currentItem = { itemId: item.itemId, variantId: item.variantId };
|
|
92
|
+
persist();
|
|
93
|
+
const record = {
|
|
94
|
+
...structuredClone(item),
|
|
95
|
+
ok: false,
|
|
96
|
+
status: "running",
|
|
97
|
+
files: [],
|
|
98
|
+
urls: [],
|
|
99
|
+
outputHashes: {},
|
|
100
|
+
};
|
|
101
|
+
const previousIndex = manifest.items.findIndex(
|
|
102
|
+
(row) => row.inputHash === item.inputHash,
|
|
103
|
+
);
|
|
104
|
+
if (previousIndex >= 0) manifest.items[previousIndex] = record;
|
|
105
|
+
else manifest.items.push(record);
|
|
106
|
+
saveManifest();
|
|
32
107
|
try {
|
|
33
|
-
const before=new Set(readdirSync(runDir));
|
|
34
|
-
const request=generationRequest(task.plan,item);
|
|
35
|
-
record.request=request;
|
|
36
|
-
|
|
37
|
-
|
|
108
|
+
const before = new Set(readdirSync(runDir));
|
|
109
|
+
const request = generationRequest(task.plan, item);
|
|
110
|
+
record.request = request;
|
|
111
|
+
saveManifest();
|
|
112
|
+
const result = await generate(task.plan, item, {
|
|
113
|
+
endpoint: task.endpoint,
|
|
114
|
+
root: task.root,
|
|
115
|
+
outputDir: runDir,
|
|
116
|
+
prefix: `${item.itemId}--${item.variantId}`,
|
|
117
|
+
cancelled,
|
|
118
|
+
receipt: task.remoteExecutions?.[item.inputHash],
|
|
119
|
+
onReceipt: (receipt) => {
|
|
120
|
+
task.remoteExecutions ??= {};
|
|
121
|
+
task.remoteExecutions[item.inputHash] = receipt;
|
|
122
|
+
record.remote = receipt;
|
|
123
|
+
const pending = Object.values(task.remoteExecutions).some((value) =>
|
|
124
|
+
["dispatching", "accepted"].includes(value.state),
|
|
125
|
+
);
|
|
126
|
+
task.unsettled = pending;
|
|
127
|
+
if (!pending) task.remoteCancellation = null;
|
|
128
|
+
persist();
|
|
129
|
+
saveManifest();
|
|
130
|
+
},
|
|
131
|
+
onPrompt: (promptId) => {
|
|
132
|
+
task.promptId = promptId;
|
|
133
|
+
persist();
|
|
134
|
+
},
|
|
135
|
+
onRemoteCancel: () => {
|
|
136
|
+
task.remoteCancellation =
|
|
137
|
+
"client-stopped; upstream execution cannot be confirmed";
|
|
138
|
+
task.unsettled = true;
|
|
139
|
+
persist();
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
if (result.files) record.files = result.files;
|
|
38
143
|
else {
|
|
39
|
-
record.urls=result.urls??[];
|
|
40
|
-
const fresh=readdirSync(runDir)
|
|
41
|
-
|
|
144
|
+
record.urls = result.urls ?? [];
|
|
145
|
+
const fresh = readdirSync(runDir)
|
|
146
|
+
.filter((f) => !before.has(f) && /\.(png|jpe?g|webp)$/i.test(f))
|
|
147
|
+
.sort();
|
|
148
|
+
for (const [index, source] of fresh.entries()) {
|
|
149
|
+
const target = `${item.itemId}--${item.variantId}${index ? "--" + (index + 1) : ""}${source.slice(source.lastIndexOf("."))}`;
|
|
150
|
+
if (source !== target) {
|
|
151
|
+
if (existsSync(join(runDir, target))) throw new Error("产物已存在");
|
|
152
|
+
renameSync(join(runDir, source), join(runDir, target));
|
|
153
|
+
}
|
|
154
|
+
record.files.push(target);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (
|
|
158
|
+
record.files.length !== (item.execution ?? task.plan.execution).perValue
|
|
159
|
+
)
|
|
160
|
+
throw new Error("生成数量与计划不符");
|
|
161
|
+
const expected = (item.execution ?? task.plan.execution).size
|
|
162
|
+
.split("*")
|
|
163
|
+
.map(Number);
|
|
164
|
+
for (const image of record.files) {
|
|
165
|
+
const path = join(runDir, image),
|
|
166
|
+
info = await validateImage(readFileSync(path));
|
|
167
|
+
if (info.width !== expected[0] || info.height !== expected[1])
|
|
168
|
+
throw new Error("生成图片尺寸与冻结计划不符");
|
|
169
|
+
record.outputHashes[image] = sha256File(path);
|
|
170
|
+
}
|
|
171
|
+
record.ok = true;
|
|
172
|
+
record.status = "generated";
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (backend?.provider === "comfyui" && task.promptId)
|
|
175
|
+
try {
|
|
176
|
+
await cancelPrompt(task.endpoint, task.promptId);
|
|
177
|
+
task.promptId = null;
|
|
178
|
+
} catch (stopError) {
|
|
179
|
+
error.unsettled = true;
|
|
180
|
+
error.message += ";无法确认后端停止:" + stopError.message;
|
|
181
|
+
}
|
|
182
|
+
if (error.unsettled) task.unsettled = true;
|
|
183
|
+
record.status = cancelled() && !error.unsettled ? "cancelled" : "failed";
|
|
184
|
+
record.error = error.message;
|
|
185
|
+
if (record.status === "failed") {
|
|
186
|
+
task.error = error.message;
|
|
187
|
+
if (error.diagnostic) {
|
|
188
|
+
record.diagnostic = error.diagnostic;
|
|
189
|
+
task.diagnostic = error.diagnostic;
|
|
190
|
+
}
|
|
42
191
|
}
|
|
43
|
-
if(record.files.length!==(item.execution??task.plan.execution).perValue)throw new Error('生成数量与计划不符');
|
|
44
|
-
for(const image of record.files)record.outputHashes[image]=sha256File(join(runDir,image));
|
|
45
|
-
record.ok=true;record.status='generated';
|
|
46
|
-
}catch(error){
|
|
47
|
-
if(backend?.provider==='comfyui'&&task.promptId)try{await cancelPrompt(task.endpoint,task.promptId);task.promptId=null;}catch(stopError){error.unsettled=true;error.message+=';无法确认后端停止:'+stopError.message;}
|
|
48
|
-
if(error.unsettled)task.unsettled=true;
|
|
49
|
-
record.status=cancelled()&&!error.unsettled?'cancelled':'failed';record.error=error.message;
|
|
50
|
-
if(record.status==='failed'){task.error=error.message;if(error.diagnostic){record.diagnostic=error.diagnostic;task.diagnostic=error.diagnostic;}}
|
|
51
192
|
}
|
|
52
193
|
saveManifest();
|
|
194
|
+
if (task.unsettled) break;
|
|
195
|
+
}
|
|
196
|
+
if (cancelled() || task.unsettled)
|
|
197
|
+
for (const item of task.items)
|
|
198
|
+
if (!manifest.items.some((x) => x.inputHash === item.inputHash))
|
|
199
|
+
manifest.items.push({
|
|
200
|
+
...structuredClone(item),
|
|
201
|
+
ok: false,
|
|
202
|
+
status: "cancelled",
|
|
203
|
+
files: [],
|
|
204
|
+
urls: [],
|
|
205
|
+
outputHashes: {},
|
|
206
|
+
error: "任务已取消,未执行",
|
|
207
|
+
});
|
|
208
|
+
manifest.finishedAt = new Date().toISOString();
|
|
209
|
+
saveManifest();
|
|
210
|
+
task.status = cancelled()
|
|
211
|
+
? "cancelled"
|
|
212
|
+
: manifest.summary.failed
|
|
213
|
+
? "failed"
|
|
214
|
+
: manifest.summary.cancelled
|
|
215
|
+
? "cancelled"
|
|
216
|
+
: "succeeded";
|
|
217
|
+
} catch (error) {
|
|
218
|
+
task.status = cancelled() ? "cancelled" : "failed";
|
|
219
|
+
task.error = error.message;
|
|
220
|
+
if (error.diagnostic) task.diagnostic = error.diagnostic;
|
|
221
|
+
if (manifest) {
|
|
222
|
+
manifest.error = error.message;
|
|
223
|
+
manifest.diagnostic = error.diagnostic;
|
|
224
|
+
manifest.finishedAt = new Date().toISOString();
|
|
225
|
+
saveManifest();
|
|
53
226
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
task.
|
|
57
|
-
|
|
58
|
-
|
|
227
|
+
} finally {
|
|
228
|
+
clearInterval(heartbeat);
|
|
229
|
+
task.stopConfirmed =
|
|
230
|
+
!task.unsettled && !task.promptId && !task.remoteCancellation;
|
|
231
|
+
task.finishedAt = new Date().toISOString();
|
|
232
|
+
persist();
|
|
233
|
+
}
|