tryharness 0.7.71 → 0.7.73
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/README.md +13 -8
- package/assets/opencode-plugin.js +70 -3
- package/cli.mjs +27 -12
- package/lib/asks.mjs +4 -0
- package/lib/boardCommands.mjs +9 -1
- package/lib/boardProtocol.json +23 -19
- package/lib/bridge.mjs +2 -0
- package/lib/capabilityCheck.mjs +86 -0
- package/lib/computerAddress.mjs +6 -14
- package/lib/coordinator.mjs +259 -30
- package/lib/daemon.mjs +164 -133
- package/lib/dispatchContract.json +1 -31
- package/lib/dispatchTools.js +8 -39
- package/lib/dispatches.mjs +27 -285
- package/lib/goalCommands.mjs +21 -38
- package/lib/herdr.mjs +159 -0
- package/lib/hookDialects.mjs +36 -2
- package/lib/jobAnswers.mjs +3 -0
- package/lib/kanban.mjs +256 -0
- package/lib/live.mjs +25 -3
- package/lib/localAgentAsk.mjs +20 -29
- package/lib/machineRoutes.mjs +1 -5
- package/lib/machineRuns.mjs +42 -22
- package/lib/manager.mjs +254 -0
- package/lib/mcp-stdio.mjs +58 -39
- package/lib/moves.mjs +365 -0
- package/lib/nudge.mjs +13 -3
- package/lib/ownMachines.mjs +122 -12
- package/lib/places.mjs +29 -2
- package/lib/plans.mjs +7 -1
- package/lib/projectSettings.mjs +11 -1
- package/lib/projects.mjs +20 -4
- package/lib/runAuthority.mjs +104 -35
- package/lib/runBrief.mjs +14 -1
- package/lib/runWorker.mjs +48 -24
- package/lib/runner.mjs +184 -75
- package/lib/selfUpdate.mjs +41 -0
- package/lib/serverWords.mjs +11 -11
- package/lib/sessionControl.mjs +68 -3
- package/lib/steerHook.mjs +124 -0
- package/lib/steerQueue.mjs +176 -0
- package/lib/store.mjs +34 -34
- package/lib/subagentSteering.mjs +363 -0
- package/lib/subagents.mjs +138 -29
- package/lib/swarm.mjs +16 -3
- package/lib/taskCommands.mjs +36 -71
- package/lib/threadActions.mjs +13 -3
- package/lib/threadAuthority.mjs +21 -14
- package/lib/threadBriefs.mjs +9 -3
- package/lib/threadRuns.mjs +35 -8
- package/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/release.json +54 -49
- package/lib/comfyExecution.mjs +0 -545
- package/lib/promptDecider.mjs +0 -471
- package/lib/promptFlow.mjs +0 -562
- package/lib/promptScopes.mjs +0 -670
package/lib/comfyExecution.mjs
DELETED
|
@@ -1,545 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import http from "node:http";
|
|
3
|
-
import { WebSocket } from "ws";
|
|
4
|
-
|
|
5
|
-
const digest = (value) =>
|
|
6
|
-
createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
7
|
-
const day = () => {
|
|
8
|
-
const value = new Date();
|
|
9
|
-
value.setHours(0, 0, 0, 0);
|
|
10
|
-
return value.toISOString();
|
|
11
|
-
};
|
|
12
|
-
const key = (ref) => `comfy-execution:${ref}`;
|
|
13
|
-
const exact = (value, names) =>
|
|
14
|
-
value &&
|
|
15
|
-
typeof value === "object" &&
|
|
16
|
-
Object.keys(value).length === names.length &&
|
|
17
|
-
names.every((name) => Object.hasOwn(value, name));
|
|
18
|
-
const MAX_IMAGE = 5 * 1024 * 1024;
|
|
19
|
-
// A numeric loopback service is reached directly, independent of proxy settings.
|
|
20
|
-
const localRequest = (origin, route, options = {}) =>
|
|
21
|
-
new Promise((resolve, reject) => {
|
|
22
|
-
const outgoing = http.request(
|
|
23
|
-
origin + route,
|
|
24
|
-
{
|
|
25
|
-
method: options.method ?? "GET",
|
|
26
|
-
headers: options.headers,
|
|
27
|
-
agent: false,
|
|
28
|
-
},
|
|
29
|
-
(body) =>
|
|
30
|
-
resolve({
|
|
31
|
-
body,
|
|
32
|
-
status: body.statusCode,
|
|
33
|
-
ok: body.statusCode >= 200 && body.statusCode < 300,
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
outgoing.on("error", reject);
|
|
37
|
-
outgoing.end(options.body);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
/** A registered local GPU operation, never a model-supplied URL or workflow.
|
|
41
|
-
* The worker owns its policy, submit intent and physical execution receipt.
|
|
42
|
-
*/
|
|
43
|
-
export function createComfyExecution({
|
|
44
|
-
store,
|
|
45
|
-
configuration,
|
|
46
|
-
machine,
|
|
47
|
-
publish,
|
|
48
|
-
}) {
|
|
49
|
-
const active = new Map();
|
|
50
|
-
const observerRecovery = new Set();
|
|
51
|
-
let closing = false;
|
|
52
|
-
const reconciling = new Map();
|
|
53
|
-
const read = (ref) => JSON.parse(store.meta(key(ref)) || "null");
|
|
54
|
-
const save = (job) => store.meta(key(job.operation_ref), JSON.stringify(job));
|
|
55
|
-
const policy = () => {
|
|
56
|
-
const config = configuration();
|
|
57
|
-
if (
|
|
58
|
-
config?.enabled !== true ||
|
|
59
|
-
!Number.isInteger(config.dailyRenderLimit) ||
|
|
60
|
-
config.dailyRenderLimit < 1
|
|
61
|
-
)
|
|
62
|
-
throw new Error("ComfyUI execution is not enabled on this computer");
|
|
63
|
-
const origin = new URL(config.origin);
|
|
64
|
-
if (
|
|
65
|
-
origin.protocol !== "http:" ||
|
|
66
|
-
!["127.0.0.1", "[::1]"].includes(origin.hostname) ||
|
|
67
|
-
origin.username ||
|
|
68
|
-
origin.password ||
|
|
69
|
-
origin.pathname !== "/" ||
|
|
70
|
-
origin.search ||
|
|
71
|
-
origin.hash
|
|
72
|
-
)
|
|
73
|
-
throw new Error(
|
|
74
|
-
"ComfyUI must be registered at a numeric loopback origin"
|
|
75
|
-
);
|
|
76
|
-
return {
|
|
77
|
-
origin: origin.origin,
|
|
78
|
-
limit: config.dailyRenderLimit,
|
|
79
|
-
checkpoint: config.checkpoint ?? null,
|
|
80
|
-
revision: digest(config),
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
const request = async (route, { allowError = false, ...options } = {}) => {
|
|
84
|
-
const current = policy();
|
|
85
|
-
const response = await localRequest(current.origin, route, options);
|
|
86
|
-
if (!response.ok && !allowError)
|
|
87
|
-
throw Object.assign(
|
|
88
|
-
new Error(`ComfyUI returned HTTP ${response.status}`),
|
|
89
|
-
{ http_status: response.status }
|
|
90
|
-
);
|
|
91
|
-
return response;
|
|
92
|
-
};
|
|
93
|
-
const text = async (response) => {
|
|
94
|
-
const chunks = [];
|
|
95
|
-
let size = 0;
|
|
96
|
-
for await (const chunk of response.body) {
|
|
97
|
-
size += chunk.length;
|
|
98
|
-
if (size > 1024 * 1024)
|
|
99
|
-
throw new Error("The ComfyUI control reply is too large");
|
|
100
|
-
chunks.push(chunk);
|
|
101
|
-
}
|
|
102
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
103
|
-
};
|
|
104
|
-
const json = async (route) => JSON.parse(await text(await request(route)));
|
|
105
|
-
const cancelAtProvider = async (job) => {
|
|
106
|
-
let fresh = read(job.operation_ref);
|
|
107
|
-
if (!fresh.prompt_id) {
|
|
108
|
-
const response = await localRequest(job.origin, "/queue");
|
|
109
|
-
const queue = JSON.parse(await text(response));
|
|
110
|
-
const item = [
|
|
111
|
-
...(queue.queue_pending ?? []),
|
|
112
|
-
...(queue.queue_running ?? []),
|
|
113
|
-
].find(
|
|
114
|
-
(entry) => entry?.[3]?.harness_operation_ref === job.operation_ref
|
|
115
|
-
);
|
|
116
|
-
if (!item) return fresh;
|
|
117
|
-
fresh = { ...read(job.operation_ref), prompt_id: item[1] };
|
|
118
|
-
save(fresh);
|
|
119
|
-
}
|
|
120
|
-
// The provider ignores running ids here; never interrupt another workflow.
|
|
121
|
-
const response = await localRequest(job.origin, "/queue", {
|
|
122
|
-
method: "POST",
|
|
123
|
-
headers: { "content-type": "application/json" },
|
|
124
|
-
body: JSON.stringify({ delete: [fresh.prompt_id] }),
|
|
125
|
-
});
|
|
126
|
-
await text(response);
|
|
127
|
-
if (!response.ok)
|
|
128
|
-
throw new Error("ComfyUI did not confirm queued cancellation");
|
|
129
|
-
return fresh;
|
|
130
|
-
};
|
|
131
|
-
const catalog = async () => {
|
|
132
|
-
try {
|
|
133
|
-
const current = policy();
|
|
134
|
-
const info = await json("/object_info/CheckpointLoaderSimple");
|
|
135
|
-
const models =
|
|
136
|
-
info.CheckpointLoaderSimple?.input?.required?.ckpt_name?.[0];
|
|
137
|
-
const checkpoint =
|
|
138
|
-
current.checkpoint ??
|
|
139
|
-
(Array.isArray(models) ? [...models].sort()[0] : null);
|
|
140
|
-
if (typeof checkpoint !== "string" || !models?.includes(checkpoint))
|
|
141
|
-
throw new Error("No registered checkpoint is available");
|
|
142
|
-
return {
|
|
143
|
-
ok: true,
|
|
144
|
-
capability_ref: "capability:comfy-image@1",
|
|
145
|
-
policy_ref: `comfy:${current.revision}`,
|
|
146
|
-
checkpoint,
|
|
147
|
-
computer: machine().id,
|
|
148
|
-
label: machine().label,
|
|
149
|
-
};
|
|
150
|
-
} catch (error) {
|
|
151
|
-
return { ok: false, error: error.message };
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const result = (job) => {
|
|
155
|
-
const { image: _image, published_state: _published, ...receipt } = job;
|
|
156
|
-
return receipt;
|
|
157
|
-
};
|
|
158
|
-
const tell = async (job) => {
|
|
159
|
-
const answer = await publish(result(job)).catch(() => null);
|
|
160
|
-
const fresh = read(job.operation_ref);
|
|
161
|
-
if (answer?.ok && !answer.queued && fresh?.state === job.state)
|
|
162
|
-
save({ ...fresh, published_state: job.state });
|
|
163
|
-
};
|
|
164
|
-
const finish = async (job) => {
|
|
165
|
-
if (job.policy_ref !== `comfy:${policy().revision}` || job.cancelled)
|
|
166
|
-
throw new Error("The worker permission changed");
|
|
167
|
-
const history = await json(`/history/${encodeURIComponent(job.prompt_id)}`);
|
|
168
|
-
const entry = history[job.prompt_id];
|
|
169
|
-
if (!entry) return job;
|
|
170
|
-
if (entry.prompt?.[3]?.harness_operation_ref !== job.operation_ref)
|
|
171
|
-
throw new Error("ComfyUI history does not bind this operation");
|
|
172
|
-
if (entry.status?.status_str === "error") {
|
|
173
|
-
const failed = {
|
|
174
|
-
...job,
|
|
175
|
-
state: "failed",
|
|
176
|
-
error: "ComfyUI execution failed",
|
|
177
|
-
};
|
|
178
|
-
save(failed);
|
|
179
|
-
active.get(job.operation_ref)?.close();
|
|
180
|
-
await tell(failed);
|
|
181
|
-
return failed;
|
|
182
|
-
}
|
|
183
|
-
if (!entry.status?.completed) return job;
|
|
184
|
-
const image = entry.outputs?.["9"]?.images?.[0];
|
|
185
|
-
if (
|
|
186
|
-
!image ||
|
|
187
|
-
image.type !== "output" ||
|
|
188
|
-
!/^[\w.-]+\.png$/.test(image.filename) ||
|
|
189
|
-
typeof image.subfolder !== "string" ||
|
|
190
|
-
image.subfolder.split(/[\\/]/).some((part) => part.startsWith("."))
|
|
191
|
-
)
|
|
192
|
-
throw new Error("The workflow returned an unsupported image reference");
|
|
193
|
-
const query = new URLSearchParams({
|
|
194
|
-
filename: image.filename,
|
|
195
|
-
subfolder: image.subfolder,
|
|
196
|
-
type: "output",
|
|
197
|
-
});
|
|
198
|
-
const response = await request(`/view?${query}`);
|
|
199
|
-
const chunks = [];
|
|
200
|
-
let size = 0;
|
|
201
|
-
for await (const chunk of response.body) {
|
|
202
|
-
size += chunk.length;
|
|
203
|
-
if (size > MAX_IMAGE) {
|
|
204
|
-
response.body.destroy();
|
|
205
|
-
throw new Error("Image exceeds the artifact limit");
|
|
206
|
-
}
|
|
207
|
-
chunks.push(chunk);
|
|
208
|
-
}
|
|
209
|
-
const bytes = Buffer.concat(chunks);
|
|
210
|
-
if (
|
|
211
|
-
!bytes
|
|
212
|
-
.subarray(0, 8)
|
|
213
|
-
.equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
|
|
214
|
-
)
|
|
215
|
-
throw new Error("The returned artifact is not a PNG");
|
|
216
|
-
const next = {
|
|
217
|
-
...job,
|
|
218
|
-
state: "done",
|
|
219
|
-
image: bytes.toString("base64"),
|
|
220
|
-
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
221
|
-
bytes: bytes.length,
|
|
222
|
-
mime: "image/png",
|
|
223
|
-
name: image.filename,
|
|
224
|
-
};
|
|
225
|
-
if (
|
|
226
|
-
read(job.operation_ref).cancelled ||
|
|
227
|
-
job.policy_ref !== `comfy:${policy().revision}`
|
|
228
|
-
)
|
|
229
|
-
throw new Error("Execution authority changed before delivery");
|
|
230
|
-
save(next);
|
|
231
|
-
active.get(job.operation_ref)?.close();
|
|
232
|
-
await tell(next);
|
|
233
|
-
return next;
|
|
234
|
-
};
|
|
235
|
-
const reconcileOnce = async (job) => {
|
|
236
|
-
job = read(job.operation_ref);
|
|
237
|
-
if (["done", "failed", "cancelled"].includes(job.state)) return job;
|
|
238
|
-
if (job.policy_ref !== `comfy:${policy().revision}`)
|
|
239
|
-
return {
|
|
240
|
-
...job,
|
|
241
|
-
state: "unknown",
|
|
242
|
-
error: "The worker permission changed",
|
|
243
|
-
};
|
|
244
|
-
if (!job.prompt_id) {
|
|
245
|
-
const history = await json("/history");
|
|
246
|
-
const queue = await json("/queue");
|
|
247
|
-
const candidate = [
|
|
248
|
-
...Object.values(history).map((x) => x.prompt),
|
|
249
|
-
...(queue.queue_running ?? []),
|
|
250
|
-
...(queue.queue_pending ?? []),
|
|
251
|
-
].find((x) => x?.[3]?.harness_operation_ref === job.operation_ref);
|
|
252
|
-
if (!candidate) return job;
|
|
253
|
-
job = { ...job, prompt_id: candidate[1], state: "running" };
|
|
254
|
-
save(job);
|
|
255
|
-
}
|
|
256
|
-
return finish(job);
|
|
257
|
-
};
|
|
258
|
-
const reconcile = (job) => {
|
|
259
|
-
if (reconciling.has(job.operation_ref))
|
|
260
|
-
return reconciling.get(job.operation_ref);
|
|
261
|
-
const work = reconcileOnce(job).finally(() =>
|
|
262
|
-
reconciling.delete(job.operation_ref)
|
|
263
|
-
);
|
|
264
|
-
reconciling.set(job.operation_ref, work);
|
|
265
|
-
return work;
|
|
266
|
-
};
|
|
267
|
-
const watch = (job, socket) => {
|
|
268
|
-
socket.on("message", () => {
|
|
269
|
-
void reconcile(read(job.operation_ref)).catch(() => {});
|
|
270
|
-
});
|
|
271
|
-
socket.on("error", () => {});
|
|
272
|
-
socket.on("close", () => {
|
|
273
|
-
if (active.get(job.operation_ref) !== socket) return;
|
|
274
|
-
active.delete(job.operation_ref);
|
|
275
|
-
const fresh = read(job.operation_ref);
|
|
276
|
-
if (fresh?.state === "submitting") {
|
|
277
|
-
save({
|
|
278
|
-
...fresh,
|
|
279
|
-
state: "unknown",
|
|
280
|
-
error: "The ComfyUI connection closed before submit was confirmed",
|
|
281
|
-
});
|
|
282
|
-
void tell(read(job.operation_ref));
|
|
283
|
-
}
|
|
284
|
-
if (
|
|
285
|
-
!closing &&
|
|
286
|
-
!["done", "failed", "cancelled"].includes(fresh?.state) &&
|
|
287
|
-
!observerRecovery.has(job.operation_ref)
|
|
288
|
-
) {
|
|
289
|
-
// One event-driven observer replacement, with no new submit or deadline.
|
|
290
|
-
// A failed replacement leaves the original attempt for reconciliation.
|
|
291
|
-
observerRecovery.add(job.operation_ref);
|
|
292
|
-
try {
|
|
293
|
-
observe(read(job.operation_ref));
|
|
294
|
-
} catch {}
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
|
-
const observe = (job) => {
|
|
299
|
-
if (
|
|
300
|
-
closing ||
|
|
301
|
-
active.has(job.operation_ref) ||
|
|
302
|
-
["done", "failed", "cancelled"].includes(job.state)
|
|
303
|
-
)
|
|
304
|
-
return;
|
|
305
|
-
if (job.policy_ref !== `comfy:${policy().revision}`) return;
|
|
306
|
-
const socket = new WebSocket(
|
|
307
|
-
job.origin.replace("http:", "ws:") +
|
|
308
|
-
`/ws?clientId=${encodeURIComponent(job.operation_ref)}`
|
|
309
|
-
);
|
|
310
|
-
active.set(job.operation_ref, socket);
|
|
311
|
-
watch(job, socket);
|
|
312
|
-
socket.once(
|
|
313
|
-
"open",
|
|
314
|
-
() => void reconcile(read(job.operation_ref)).catch(() => {})
|
|
315
|
-
);
|
|
316
|
-
};
|
|
317
|
-
const submit = async (call, from) => {
|
|
318
|
-
if (
|
|
319
|
-
!exact(call, [
|
|
320
|
-
"operation",
|
|
321
|
-
"operation_ref",
|
|
322
|
-
"prompt",
|
|
323
|
-
"policy_ref",
|
|
324
|
-
"computer",
|
|
325
|
-
"owner_epoch",
|
|
326
|
-
]) ||
|
|
327
|
-
call.operation !== "submit" ||
|
|
328
|
-
!/^render:[a-f0-9-]{36}$/.test(call.operation_ref) ||
|
|
329
|
-
typeof call.prompt !== "string" ||
|
|
330
|
-
!call.prompt.trim() ||
|
|
331
|
-
call.prompt.length > 16000 ||
|
|
332
|
-
call.owner_epoch !== 1 ||
|
|
333
|
-
call.computer !== machine().id
|
|
334
|
-
)
|
|
335
|
-
return { ok: false, code: "execution_schema" };
|
|
336
|
-
const previous = read(call.operation_ref);
|
|
337
|
-
if (previous)
|
|
338
|
-
return previous.from === from &&
|
|
339
|
-
previous.prompt === call.prompt &&
|
|
340
|
-
previous.policy_ref === call.policy_ref
|
|
341
|
-
? { ok: true, execution: result(await reconcile(previous)) }
|
|
342
|
-
: { ok: false, code: "execution_conflict" };
|
|
343
|
-
const offered = await catalog();
|
|
344
|
-
if (!offered.ok || offered.policy_ref !== call.policy_ref)
|
|
345
|
-
return { ok: false, code: "capability_changed" };
|
|
346
|
-
const current = policy();
|
|
347
|
-
const quotaKey = `comfy-quota:${day()}`;
|
|
348
|
-
const count = Number(store.meta(quotaKey) || 0);
|
|
349
|
-
if (count >= current.limit) return { ok: false, code: "render_budget" };
|
|
350
|
-
const job = {
|
|
351
|
-
...call,
|
|
352
|
-
from,
|
|
353
|
-
state: "submitting",
|
|
354
|
-
computer_label: machine().label,
|
|
355
|
-
attempt_ref: `attempt:${randomUUID()}`,
|
|
356
|
-
checkpoint: offered.checkpoint,
|
|
357
|
-
origin: current.origin,
|
|
358
|
-
};
|
|
359
|
-
store.dispatchTransaction(() => {
|
|
360
|
-
if (
|
|
361
|
-
read(call.operation_ref) ||
|
|
362
|
-
Number(store.meta(quotaKey) || 0) !== count ||
|
|
363
|
-
policy().revision !== current.revision
|
|
364
|
-
)
|
|
365
|
-
throw new Error("Execution authority changed");
|
|
366
|
-
save(job);
|
|
367
|
-
store.meta(quotaKey, String(count + 1));
|
|
368
|
-
const refs = JSON.parse(store.meta("comfy-executions") || "[]");
|
|
369
|
-
store.meta(
|
|
370
|
-
"comfy-executions",
|
|
371
|
-
JSON.stringify([...refs, job.operation_ref])
|
|
372
|
-
);
|
|
373
|
-
});
|
|
374
|
-
// Start progress before submit, so completion cannot race past the observer.
|
|
375
|
-
const socket = new WebSocket(
|
|
376
|
-
current.origin.replace("http:", "ws:") +
|
|
377
|
-
`/ws?clientId=${encodeURIComponent(call.operation_ref)}`
|
|
378
|
-
);
|
|
379
|
-
active.set(job.operation_ref, socket);
|
|
380
|
-
watch(job, socket);
|
|
381
|
-
socket.once("open", () => {
|
|
382
|
-
void (async () => {
|
|
383
|
-
try {
|
|
384
|
-
if (policy().revision !== current.revision)
|
|
385
|
-
throw new Error("Execution authority changed");
|
|
386
|
-
if (read(job.operation_ref).cancelled) return;
|
|
387
|
-
const workflow = {
|
|
388
|
-
1: {
|
|
389
|
-
class_type: "CheckpointLoaderSimple",
|
|
390
|
-
inputs: { ckpt_name: offered.checkpoint },
|
|
391
|
-
},
|
|
392
|
-
2: {
|
|
393
|
-
class_type: "CLIPTextEncode",
|
|
394
|
-
inputs: { text: call.prompt, clip: ["1", 1] },
|
|
395
|
-
},
|
|
396
|
-
3: {
|
|
397
|
-
class_type: "CLIPTextEncode",
|
|
398
|
-
inputs: { text: "", clip: ["1", 1] },
|
|
399
|
-
},
|
|
400
|
-
4: {
|
|
401
|
-
class_type: "EmptyLatentImage",
|
|
402
|
-
inputs: { width: 512, height: 512, batch_size: 1 },
|
|
403
|
-
},
|
|
404
|
-
5: {
|
|
405
|
-
class_type: "KSampler",
|
|
406
|
-
inputs: {
|
|
407
|
-
model: ["1", 0],
|
|
408
|
-
positive: ["2", 0],
|
|
409
|
-
negative: ["3", 0],
|
|
410
|
-
latent_image: ["4", 0],
|
|
411
|
-
seed: 0,
|
|
412
|
-
steps: 20,
|
|
413
|
-
cfg: 7,
|
|
414
|
-
sampler_name: "euler",
|
|
415
|
-
scheduler: "normal",
|
|
416
|
-
denoise: 1,
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
8: {
|
|
420
|
-
class_type: "VAEDecode",
|
|
421
|
-
inputs: { samples: ["5", 0], vae: ["1", 2] },
|
|
422
|
-
},
|
|
423
|
-
9: {
|
|
424
|
-
class_type: "SaveImage",
|
|
425
|
-
inputs: {
|
|
426
|
-
images: ["8", 0],
|
|
427
|
-
filename_prefix: `harness_${call.operation_ref.slice(7)}`,
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
};
|
|
431
|
-
const response = await request("/prompt", {
|
|
432
|
-
allowError: true,
|
|
433
|
-
method: "POST",
|
|
434
|
-
headers: { "content-type": "application/json" },
|
|
435
|
-
body: JSON.stringify({
|
|
436
|
-
client_id: call.operation_ref,
|
|
437
|
-
prompt: workflow,
|
|
438
|
-
extra_data: { harness_operation_ref: call.operation_ref },
|
|
439
|
-
}),
|
|
440
|
-
});
|
|
441
|
-
const raw = await text(response);
|
|
442
|
-
store.meta(
|
|
443
|
-
`comfy-response:${job.operation_ref}`,
|
|
444
|
-
JSON.stringify({ http_status: response.status, body: raw })
|
|
445
|
-
);
|
|
446
|
-
if (!response.ok)
|
|
447
|
-
throw Object.assign(
|
|
448
|
-
new Error(`ComfyUI returned HTTP ${response.status}`),
|
|
449
|
-
{ http_status: response.status }
|
|
450
|
-
);
|
|
451
|
-
const reply = JSON.parse(raw);
|
|
452
|
-
if (
|
|
453
|
-
reply.error ||
|
|
454
|
-
(reply.node_errors &&
|
|
455
|
-
Object.keys(reply.node_errors).length &&
|
|
456
|
-
!reply.prompt_id)
|
|
457
|
-
) {
|
|
458
|
-
const failed = {
|
|
459
|
-
...read(job.operation_ref),
|
|
460
|
-
state: "failed",
|
|
461
|
-
error: "ComfyUI rejected the prepared workflow",
|
|
462
|
-
};
|
|
463
|
-
save(failed);
|
|
464
|
-
socket.close();
|
|
465
|
-
await tell(failed);
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
if (typeof reply.prompt_id !== "string")
|
|
469
|
-
throw new Error("ComfyUI did not return an execution identity");
|
|
470
|
-
const fresh = read(job.operation_ref);
|
|
471
|
-
if (fresh.cancelled) {
|
|
472
|
-
save({ ...fresh, prompt_id: reply.prompt_id });
|
|
473
|
-
await cancelAtProvider(read(job.operation_ref));
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (fresh.state !== "done")
|
|
477
|
-
save({ ...fresh, state: "running", prompt_id: reply.prompt_id });
|
|
478
|
-
await reconcile(read(job.operation_ref));
|
|
479
|
-
} catch (error) {
|
|
480
|
-
const fresh = read(job.operation_ref);
|
|
481
|
-
if (fresh.state === "cancelled") {
|
|
482
|
-
await cancelAtProvider(fresh).catch(() => {});
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
if (fresh.state === "done") return;
|
|
486
|
-
const unknown = {
|
|
487
|
-
...read(job.operation_ref),
|
|
488
|
-
state: error.http_status === 400 ? "failed" : "unknown",
|
|
489
|
-
error: error.message,
|
|
490
|
-
};
|
|
491
|
-
save(unknown);
|
|
492
|
-
await tell(unknown);
|
|
493
|
-
// Read receipts after an ambiguous submit; never POST it again.
|
|
494
|
-
if (unknown.state === "unknown")
|
|
495
|
-
await reconcile(unknown).catch(() => {});
|
|
496
|
-
}
|
|
497
|
-
})();
|
|
498
|
-
});
|
|
499
|
-
return { ok: true, execution: result(job) };
|
|
500
|
-
};
|
|
501
|
-
const answer = async (call, from) => {
|
|
502
|
-
try {
|
|
503
|
-
if (call?.operation === "catalog") return catalog();
|
|
504
|
-
if (call?.operation === "submit") return submit(call, from);
|
|
505
|
-
const job = read(call?.operation_ref);
|
|
506
|
-
if (!job || job.from !== from)
|
|
507
|
-
return { ok: false, code: "execution_missing" };
|
|
508
|
-
if (call.operation === "cancel") {
|
|
509
|
-
const next = { ...job, cancelled: true, state: "cancelled" };
|
|
510
|
-
save(next);
|
|
511
|
-
active.get(job.operation_ref)?.close();
|
|
512
|
-
// Delete only this operation's queued item. Never interrupt another running workflow.
|
|
513
|
-
return { ok: true, execution: result(await cancelAtProvider(next)) };
|
|
514
|
-
}
|
|
515
|
-
if (call.operation === "status")
|
|
516
|
-
return { ok: true, execution: result(await reconcile(job)) };
|
|
517
|
-
if (call.operation === "image" && job.state === "done")
|
|
518
|
-
return { ok: true, data: job.image, sha256: job.sha256 };
|
|
519
|
-
return { ok: false, code: "execution_operation" };
|
|
520
|
-
} catch (error) {
|
|
521
|
-
return { ok: false, code: "execution_unavailable", error: error.message };
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
return {
|
|
525
|
-
answer,
|
|
526
|
-
resume: async () => {
|
|
527
|
-
for (const ref of JSON.parse(store.meta("comfy-executions") || "[]")) {
|
|
528
|
-
const job = read(ref);
|
|
529
|
-
if (!job || ["cancelled", "failed"].includes(job.state)) continue;
|
|
530
|
-
try {
|
|
531
|
-
const next = await reconcile(job);
|
|
532
|
-
if (next.state === "done") {
|
|
533
|
-
if (next.published_state !== "done") await tell(next);
|
|
534
|
-
continue;
|
|
535
|
-
}
|
|
536
|
-
observe(next);
|
|
537
|
-
} catch {}
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
close: () => {
|
|
541
|
-
closing = true;
|
|
542
|
-
for (const socket of active.values()) socket.close();
|
|
543
|
-
},
|
|
544
|
-
};
|
|
545
|
-
}
|