@melite/estate-queue 0.0.0-stage → 0.1.4-alpha
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/LICENSE +557 -0
- package/lib/bakeParams.d.ts +17 -0
- package/lib/bakeParams.js +182 -0
- package/lib/bench.d.ts +24 -0
- package/lib/bench.js +121 -0
- package/lib/cardsArmError.d.ts +18 -0
- package/lib/cardsArmError.js +33 -0
- package/lib/cardsCompose.d.ts +41 -0
- package/lib/cardsCompose.js +247 -0
- package/lib/cardsDangling.d.ts +16 -0
- package/lib/cardsDangling.js +168 -0
- package/lib/cardsFacts.d.ts +74 -0
- package/lib/cardsFacts.js +64 -0
- package/lib/cardsLanes.d.ts +33 -0
- package/lib/cardsLanes.js +115 -0
- package/lib/cardsRegistry.d.ts +316 -0
- package/lib/cardsRegistry.js +1274 -0
- package/lib/cardsVariant.d.ts +28 -0
- package/lib/cardsVariant.js +190 -0
- package/lib/discloseRegistry.d.ts +94 -0
- package/lib/discloseRegistry.js +154 -0
- package/lib/filmLead.d.ts +4 -0
- package/lib/filmLead.js +17 -0
- package/lib/filmMemoryWarn.d.ts +27 -0
- package/lib/filmMemoryWarn.js +99 -0
- package/lib/flowsData.d.ts +179 -0
- package/lib/flowsData.js +547 -0
- package/lib/flowsFamilyCompose.d.ts +48 -0
- package/lib/flowsFamilyCompose.js +191 -0
- package/lib/flowsRegistryRows.d.ts +10 -0
- package/lib/flowsRegistryRows.js +378 -0
- package/lib/index.d.ts +50 -0
- package/lib/index.js +66 -0
- package/lib/ledgerTail.d.ts +20 -0
- package/lib/ledgerTail.js +123 -0
- package/lib/loadPlane.d.ts +93 -0
- package/lib/loadPlane.js +553 -0
- package/lib/loadRegistry.d.ts +22 -0
- package/lib/loadRegistry.js +55 -0
- package/lib/manageOps.d.ts +21 -0
- package/lib/manageOps.js +142 -0
- package/lib/managePlane.d.ts +120 -0
- package/lib/managePlane.js +1515 -0
- package/lib/manageProbe.d.ts +57 -0
- package/lib/manageProbe.js +154 -0
- package/lib/manageRegistry.d.ts +28 -0
- package/lib/manageRegistry.js +75 -0
- package/lib/managerRail.d.ts +33 -0
- package/lib/managerRail.js +91 -0
- package/lib/mediaKinds.d.ts +3 -0
- package/lib/mediaKinds.js +2 -0
- package/lib/queue.d.ts +9 -0
- package/lib/queue.js +76 -0
- package/lib/queueCore.d.ts +69 -0
- package/lib/queueCore.js +124 -0
- package/lib/queueLifecycle.d.ts +26 -0
- package/lib/queueLifecycle.js +65 -0
- package/lib/queueLock.d.ts +54 -0
- package/lib/queueLock.js +195 -0
- package/lib/queueResurrect.d.ts +59 -0
- package/lib/queueResurrect.js +249 -0
- package/lib/queueRetry.d.ts +36 -0
- package/lib/queueRetry.js +24 -0
- package/lib/queueSidecar.d.ts +145 -0
- package/lib/queueSidecar.js +182 -0
- package/lib/queueSubmit.d.ts +31 -0
- package/lib/queueSubmit.js +117 -0
- package/lib/queueSweep.d.ts +30 -0
- package/lib/queueSweep.js +121 -0
- package/lib/resurrect.d.ts +6 -0
- package/lib/resurrect.js +18 -0
- package/lib/rootsManifest.d.ts +11 -0
- package/lib/rootsManifest.js +11 -0
- package/lib/runStatus.d.ts +7 -0
- package/lib/runStatus.js +21 -0
- package/lib/runsChange.d.ts +53 -0
- package/lib/runsChange.js +63 -0
- package/lib/runsErrorCodes.d.ts +2 -0
- package/lib/runsErrorCodes.js +15 -0
- package/lib/runsExecute.d.ts +26 -0
- package/lib/runsExecute.js +356 -0
- package/lib/runsGates.d.ts +161 -0
- package/lib/runsGates.js +306 -0
- package/lib/runsList.d.ts +78 -0
- package/lib/runsList.js +580 -0
- package/lib/runsRefusalVoices.d.ts +9 -0
- package/lib/runsRefusalVoices.js +44 -0
- package/lib/runsRegistry.d.ts +253 -0
- package/lib/runsRegistry.js +1750 -0
- package/lib/runsSourceEcho.d.ts +54 -0
- package/lib/runsSourceEcho.js +275 -0
- package/lib/runsStart.d.ts +121 -0
- package/lib/runsStart.js +528 -0
- package/lib/runsTypes.d.ts +183 -0
- package/lib/runsTypes.js +282 -0
- package/lib/runsValidate.d.ts +5 -0
- package/lib/runsValidate.js +31 -0
- package/lib/runsValidateArms.d.ts +7 -0
- package/lib/runsValidateArms.js +285 -0
- package/lib/runsValidateInline.d.ts +6 -0
- package/lib/runsValidateInline.js +82 -0
- package/lib/runsValidateRefusals.d.ts +7 -0
- package/lib/runsValidateRefusals.js +18 -0
- package/lib/runsValidateServe.d.ts +15 -0
- package/lib/runsValidateServe.js +254 -0
- package/lib/runsValidateShared.d.ts +84 -0
- package/lib/runsValidateShared.js +88 -0
- package/lib/runsValidateStages.d.ts +25 -0
- package/lib/runsValidateStages.js +491 -0
- package/lib/runsValidateSweeps.d.ts +6 -0
- package/lib/runsValidateSweeps.js +143 -0
- package/lib/service.d.ts +45 -0
- package/lib/service.js +81 -0
- package/lib/skillFrontmatter.d.ts +11 -0
- package/lib/skillFrontmatter.js +46 -0
- package/lib/skillFs.d.ts +19 -0
- package/lib/skillFs.js +80 -0
- package/lib/skillPlane.d.ts +98 -0
- package/lib/skillPlane.js +263 -0
- package/lib/skillRegistry.d.ts +23 -0
- package/lib/skillRegistry.js +55 -0
- package/lib/skillRows.d.ts +126 -0
- package/lib/skillRows.js +466 -0
- package/lib/toolProjection.d.ts +30 -0
- package/lib/toolProjection.js +142 -0
- package/lib/vocab.d.ts +6 -0
- package/lib/vocab.js +18 -0
- package/package.json +47 -4
- package/README.md +0 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ManageCtx } from "./managePlane.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export declare function activeRuns(): string[];
|
|
21
|
+
/** The manager's live security view (READ ONLY — the manager reads
|
|
22
|
+
* config.ini once at ComfyUI startup, so a call-time write would be
|
|
23
|
+
* a lie until restart; provision owns the pin). v3.38 layout:
|
|
24
|
+
* user/__manager/config.ini (system-user-api ComfyUI), legacy
|
|
25
|
+
* user/default/ComfyUI-Manager/config.ini otherwise. */
|
|
26
|
+
export declare function managerSecurity(repoRoot: string): string;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export declare function engineQueueView(mctx: ManageCtx): Promise<{
|
|
37
|
+
running: number;
|
|
38
|
+
pending: number;
|
|
39
|
+
} | null>;
|
|
40
|
+
interface EndpointView {
|
|
41
|
+
reachable: boolean;
|
|
42
|
+
url?: string;
|
|
43
|
+
reason?: string;
|
|
44
|
+
comfyui_version?: unknown;
|
|
45
|
+
devices?: Array<{
|
|
46
|
+
name: string;
|
|
47
|
+
vram_total: unknown;
|
|
48
|
+
vram_free: unknown;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export declare function probeEndpoint(mctx: ManageCtx): Promise<EndpointView>;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=manageProbe.d.ts.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// manageProbe.ts — the manage plane's estate probes (extracted
|
|
2
|
+
// from managePlane.ts, the god-file cut): the TS-native status
|
|
3
|
+
// walk, the active-runs census, and the manager security probe.
|
|
4
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { sweepOutputRoots } from "./cardsDangling.js";
|
|
7
|
+
import { deadline } from "@deepseek-ai/dsh-timeout";
|
|
8
|
+
// ── runs / security / probe (TS-native) ────────────────────────────
|
|
9
|
+
const STATUS_RE = /"status"\s*:\s*"([a-z]+)"/;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export function activeRuns() {
|
|
29
|
+
const out = [];
|
|
30
|
+
for (const dir of sweepOutputRoots()) {
|
|
31
|
+
let names;
|
|
32
|
+
try {
|
|
33
|
+
names = readdirSync(dir);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
if (e.code === "ENOENT")
|
|
37
|
+
continue; // root not created yet — normal
|
|
38
|
+
out.push("(unreadable root: " + dir + " " + (e.code ?? "?") + ")");
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
for (const name of names) {
|
|
42
|
+
if (!name.startsWith("run-"))
|
|
43
|
+
continue;
|
|
44
|
+
let buf;
|
|
45
|
+
try {
|
|
46
|
+
buf = readFileSync(join(dir, name, "_flow.json"), "utf-8").slice(0, 8191);
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
const code = e.code ?? "?";
|
|
50
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
51
|
+
continue; // no state file — nothing to protect
|
|
52
|
+
out.push(name + " (state unreadable: " + code + ")"); // unknown ⇒ active (fail-closed)
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const m = STATUS_RE.exec(buf);
|
|
56
|
+
// 'stopping' is LIVE (the registry's own set, runsRegistry's
|
|
57
|
+
// teardown + live-age laws): a stop was REQUESTED, the run is
|
|
58
|
+
// still writing — restart teardown must protect it like any
|
|
59
|
+
|
|
60
|
+
if (m && (m[1] === "running" || m[1] === "queued" || m[1] === "stopping"))
|
|
61
|
+
out.push(name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return [...new Set(out)].sort();
|
|
65
|
+
}
|
|
66
|
+
/** The manager's live security view (READ ONLY — the manager reads
|
|
67
|
+
* config.ini once at ComfyUI startup, so a call-time write would be
|
|
68
|
+
* a lie until restart; provision owns the pin). v3.38 layout:
|
|
69
|
+
* user/__manager/config.ini (system-user-api ComfyUI), legacy
|
|
70
|
+
* user/default/ComfyUI-Manager/config.ini otherwise. */
|
|
71
|
+
export function managerSecurity(repoRoot) {
|
|
72
|
+
const runtime = join(repoRoot, "data", "runtime", "comfyui");
|
|
73
|
+
const cands = [
|
|
74
|
+
join(runtime, "user", "__manager", "config.ini"),
|
|
75
|
+
join(runtime, "user", "default", "ComfyUI-Manager", "config.ini"),
|
|
76
|
+
];
|
|
77
|
+
for (const ini of cands) {
|
|
78
|
+
let text;
|
|
79
|
+
try {
|
|
80
|
+
text = readFileSync(ini, "utf-8");
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const level = /^\s*security_level\s*=\s*(\S+)/m.exec(text);
|
|
86
|
+
const gitUrl = /^\s*allow_git_url_install\s*=\s*true/m.test(text);
|
|
87
|
+
return "security_level=" + (level ? level[1] : "normal (default)") + (gitUrl ? " +git_url" : "") + " [" + ini + "]";
|
|
88
|
+
}
|
|
89
|
+
return "unpinned (no manager config on disk — provision sync)";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export async function engineQueueView(mctx) {
|
|
101
|
+
const cfg = mctx.endpoint();
|
|
102
|
+
const url = typeof cfg["url"] === "string" ? cfg["url"].replace(/\/+$/, "") : "";
|
|
103
|
+
if (url === "")
|
|
104
|
+
return null;
|
|
105
|
+
const dl = deadline(mctx.signal, 5000, "MANAGE_PROBE");
|
|
106
|
+
try {
|
|
107
|
+
const r = await fetch(url + "/queue", { signal: dl.signal });
|
|
108
|
+
const q = (await r.json());
|
|
109
|
+
const running = q["queue_running"];
|
|
110
|
+
const pending = q["queue_pending"];
|
|
111
|
+
if (!Array.isArray(running) || !Array.isArray(pending))
|
|
112
|
+
return null;
|
|
113
|
+
return { running: running.length, pending: pending.length };
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
dl[Symbol.dispose]();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
export async function probeEndpoint(mctx) {
|
|
127
|
+
const cfg = mctx.endpoint();
|
|
128
|
+
const url = typeof cfg["url"] === "string" ? cfg["url"].replace(/\/+$/, "") : "";
|
|
129
|
+
if (url === "")
|
|
130
|
+
return { reachable: false, reason: "no url in endpoint config" };
|
|
131
|
+
const dl = deadline(mctx.signal, 5000, "MANAGE_PROBE");
|
|
132
|
+
try {
|
|
133
|
+
const r = await fetch(url + "/system_stats", { signal: dl.signal });
|
|
134
|
+
const stats = (await r.json());
|
|
135
|
+
const sysinfo = (stats["system"] ?? {});
|
|
136
|
+
const devices = (stats["devices"] ?? []).slice(0, 4).map((d) => ({
|
|
137
|
+
name: typeof d["name"] === "string" ? d["name"] : "?",
|
|
138
|
+
vram_total: d["vram_total"],
|
|
139
|
+
vram_free: d["vram_free"],
|
|
140
|
+
}));
|
|
141
|
+
return { reachable: true, url, comfyui_version: sysinfo["comfyui_version"], devices };
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
if (mctx.signal?.aborted === true) {
|
|
145
|
+
const reason = mctx.signal.reason;
|
|
146
|
+
throw reason instanceof Error ? reason : new DOMException("The operation was aborted", "AbortError");
|
|
147
|
+
}
|
|
148
|
+
return { reachable: false, url, reason: String(e).slice(0, 120) };
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
dl[Symbol.dispose]();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=manageProbe.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { ManageEnvelope } from "./managePlane.js";
|
|
4
|
+
declare module "@deepseek-ai/dsh-typert-protocol" {
|
|
5
|
+
interface RemoteErrorDetailsMap {
|
|
6
|
+
/** A refused manage envelope — the details CARRY the envelope
|
|
7
|
+
* (action/status/data) so the tool surfaces WHY. */
|
|
8
|
+
"manage/refused": {
|
|
9
|
+
readonly action?: string;
|
|
10
|
+
readonly status?: number;
|
|
11
|
+
readonly code?: string;
|
|
12
|
+
readonly data?: unknown;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare class ManageGatewayService extends Service {
|
|
17
|
+
static inject: string[];
|
|
18
|
+
constructor(ctx: Context);
|
|
19
|
+
/** The one entry: the tools' /v1/manage lane. */
|
|
20
|
+
act(doc: unknown, signal: AbortSignal): Promise<ManageEnvelope>;
|
|
21
|
+
}
|
|
22
|
+
/** The manage row: gates on the timer seat (the rail's timeouts). */
|
|
23
|
+
export declare const manageProvider: {
|
|
24
|
+
name: string;
|
|
25
|
+
inject: readonly ["timer"];
|
|
26
|
+
apply(ctx: Context): void;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=manageRegistry.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
// the pure plane (managePlane.ts) answers through a Service; the
|
|
3
|
+
// ctx assembles from the estate's own seats — the endpoint config
|
|
4
|
+
// re-read per call (loadEndpointConfig), the models catalog
|
|
5
|
+
// (modelsService — the engine singleton, no seat), the timer seat
|
|
6
|
+
// (ctx.timeout — cordis-plugin-timer, never a bare setTimeout).
|
|
7
|
+
//
|
|
8
|
+
// The seat's contract: act(doc) returns the ENVELOPE
|
|
9
|
+
// ({action, ok, detail, data}) on ok; a refused envelope THROWS a
|
|
10
|
+
// RemoteError carrying the envelope (code manage/refused) — the
|
|
11
|
+
// tools' lane surface reads it as the value, so the model sees WHY.
|
|
12
|
+
//
|
|
13
|
+
// Erasable-syntax TS only (node --experimental-strip-types).
|
|
14
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
15
|
+
import { loadEndpointConfig, resolveRepoRoot, modelsService } from "@melite/comfyui-cordis";
|
|
16
|
+
import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
|
|
17
|
+
import { dispatchManage } from "./managePlane.js";
|
|
18
|
+
// ROLE (cookbook adding-a-package role table): Gateway: adapts the external comfy-manager API to the local manage lane. Key "manage" unchanged.
|
|
19
|
+
export class ManageGatewayService extends Service {
|
|
20
|
+
static inject = ["timer", "provisioning"];
|
|
21
|
+
constructor(ctx) {
|
|
22
|
+
super(ctx, "manage");
|
|
23
|
+
}
|
|
24
|
+
/** The one entry: the tools' /v1/manage lane. */
|
|
25
|
+
async act(doc, signal) {
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
const mctx = {
|
|
28
|
+
repoRoot: resolveRepoRoot(),
|
|
29
|
+
endpoint: () => loadEndpointConfig(),
|
|
30
|
+
models: modelsService(),
|
|
31
|
+
|
|
32
|
+
// so. The old `as ProvisioningServiceDefinition` asserted a seat
|
|
33
|
+
// that a lane may simply not mount, and every downstream
|
|
34
|
+
// dereference became a TypeError at call time instead of a
|
|
35
|
+
// declared absence. The plane gates it once (provisioningOf /
|
|
36
|
+
// provisioningOrAbsent).
|
|
37
|
+
provisioning: this.ctx.get("provisioning", false),
|
|
38
|
+
// TWO-CORDIS TOPOLOGY: the timer plugin's Context augmentation
|
|
39
|
+
// lands on ITS cordis copy (structural, never instanceof
|
|
40
|
+
// across copies — the documented law); the seat reads the
|
|
41
|
+
// timer through the structural shape.
|
|
42
|
+
timeout: (callback, delay) => this.ctx.timeout(callback, delay),
|
|
43
|
+
signal,
|
|
44
|
+
};
|
|
45
|
+
const [status, envelope] = await dispatchManage(doc, mctx, signal);
|
|
46
|
+
if (envelope.ok)
|
|
47
|
+
return envelope;
|
|
48
|
+
// A refusal IS the answer's shape: carry the envelope in the
|
|
49
|
+
// RemoteError — the lane surfaces it as the tool's value.
|
|
50
|
+
throw new RemoteError("manage/refused", envelope.detail, {
|
|
51
|
+
action: envelope.action,
|
|
52
|
+
status,
|
|
53
|
+
code: envelope.code,
|
|
54
|
+
data: envelope.data,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The manage row: gates on the timer seat (the rail's timeouts). */
|
|
59
|
+
export const manageProvider = {
|
|
60
|
+
name: "estate-manage",
|
|
61
|
+
inject: ["timer"],
|
|
62
|
+
apply(ctx) {
|
|
63
|
+
new ManageGatewayService(ctx);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// typecheck). The adapter package that CONSUMES the seat declares it
|
|
68
|
+
// on Context — structurally, by its own header's rule: a compiled
|
|
69
|
+
// package may not import these source-run sources into its emit
|
|
70
|
+
// graph, so the contract travels with the caller, and the class that
|
|
71
|
+
// mounts the seat satisfies it structurally. Declaring it here as
|
|
72
|
+
// well (the rename left this twin behind, its comment still naming
|
|
73
|
+
// the pre-rename class) is TS2717 the moment one program composes
|
|
74
|
+
// both sides — which no program did until the walls did.
|
|
75
|
+
//# sourceMappingURL=manageRegistry.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ManageCtx } from "./managePlane.js";
|
|
2
|
+
/** Thrown on any non-2xx manager answer or transport failure. The
|
|
3
|
+
* handler maps status → the estate envelope (403 security, 404
|
|
4
|
+
* unknown pack, 503 plane-unavailable). */
|
|
5
|
+
export declare class ManagerApiError extends Error {
|
|
6
|
+
status: number;
|
|
7
|
+
text: string;
|
|
8
|
+
constructor(status: number, text: string);
|
|
9
|
+
}
|
|
10
|
+
/** The manager base URL — ComfyUI's own endpoint (the endpoint
|
|
11
|
+
* config's url). Empty string means "no endpoint pinned" (the
|
|
12
|
+
* sandbox default): every rail call then refuses 503 with the
|
|
13
|
+
* plane-unavailable template. */
|
|
14
|
+
export declare function managerBase(ctx: ManageCtx): string;
|
|
15
|
+
/** Plane-unavailable template — the ONE refusal every handler
|
|
16
|
+
* raises when the manager cannot be reached (engine down, manager
|
|
17
|
+
* custom node missing, or ComfyUI started without the loopback
|
|
18
|
+
* listen). Provision sync vendors the node; the estate service
|
|
19
|
+
* pins the flag. */
|
|
20
|
+
export declare function planeUnavailable(base: string, cause: string): ManagerApiError;
|
|
21
|
+
export interface CallOpts {
|
|
22
|
+
method: "GET" | "POST";
|
|
23
|
+
body?: unknown;
|
|
24
|
+
timeoutMs: number;
|
|
25
|
+
ctx: ManageCtx;
|
|
26
|
+
}
|
|
27
|
+
/** GET a manager route (JSON expected). */
|
|
28
|
+
export declare function managerGet(base: string, path: string, opts: Omit<CallOpts, "method" | "body">): Promise<unknown>;
|
|
29
|
+
/** POST a manager route. The vendor's content-type gate
|
|
30
|
+
* (_reject_simple_form_content_type) demands proper JSON posts —
|
|
31
|
+
* this always sends application/json. */
|
|
32
|
+
export declare function managerPost(base: string, path: string, body: unknown, opts: Omit<CallOpts, "method">): Promise<unknown>;
|
|
33
|
+
//# sourceMappingURL=managerRail.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { deadline, timeoutOf } from "@deepseek-ai/dsh-timeout";
|
|
2
|
+
/** Thrown on any non-2xx manager answer or transport failure. The
|
|
3
|
+
* handler maps status → the estate envelope (403 security, 404
|
|
4
|
+
* unknown pack, 503 plane-unavailable). */
|
|
5
|
+
export class ManagerApiError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
text;
|
|
8
|
+
constructor(status, text) {
|
|
9
|
+
super("manager api " + status + ": " + text.slice(0, 200));
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.text = text;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The manager base URL — ComfyUI's own endpoint (the endpoint
|
|
15
|
+
* config's url). Empty string means "no endpoint pinned" (the
|
|
16
|
+
* sandbox default): every rail call then refuses 503 with the
|
|
17
|
+
* plane-unavailable template. */
|
|
18
|
+
export function managerBase(ctx) {
|
|
19
|
+
const cfg = ctx.endpoint();
|
|
20
|
+
const url = typeof cfg["url"] === "string" ? cfg["url"].replace(/\/+$/, "") : "";
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
/** Plane-unavailable template — the ONE refusal every handler
|
|
24
|
+
* raises when the manager cannot be reached (engine down, manager
|
|
25
|
+
* custom node missing, or ComfyUI started without the loopback
|
|
26
|
+
* listen). Provision sync vendors the node; the estate service
|
|
27
|
+
* pins the flag. */
|
|
28
|
+
export function planeUnavailable(base, cause) {
|
|
29
|
+
return new ManagerApiError(503, "management plane unavailable: ComfyUI-Manager not reachable at " +
|
|
30
|
+
(base !== "" ? base : "<no endpoint url>") +
|
|
31
|
+
" (" + cause + ") — provision sync vendors the built-in manager and the estate starts ComfyUI with --listen 127.0.0.1 (the manager's security predicate reads it at startup)");
|
|
32
|
+
}
|
|
33
|
+
/** One manager call. JSON both ways; the response body parses as
|
|
34
|
+
* JSON when it can (the vendor mixes json_response and plain text
|
|
35
|
+
* answers — 200s are json on every route we ride, refusal bodies
|
|
36
|
+
* may be either; parse defensively). */
|
|
37
|
+
async function call(base, path, opts) {
|
|
38
|
+
// The fuse is dsh-timeout's deadline (AbortSignal.any + a TimeoutReason
|
|
39
|
+
// the classification below reads back); the 504/abort voices are ours.
|
|
40
|
+
const dl = deadline(opts.ctx.signal, opts.timeoutMs, "MANAGER_API");
|
|
41
|
+
try {
|
|
42
|
+
const r = await fetch(base + path, {
|
|
43
|
+
method: opts.method,
|
|
44
|
+
headers: opts.body !== undefined ? { "content-type": "application/json" } : undefined,
|
|
45
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
46
|
+
signal: dl.signal,
|
|
47
|
+
});
|
|
48
|
+
const text = await r.text();
|
|
49
|
+
if (opts.ctx.signal?.aborted === true) {
|
|
50
|
+
throw new DOMException("The operation was aborted", "AbortError");
|
|
51
|
+
}
|
|
52
|
+
if (timeoutOf(dl.signal, "MANAGER_API"))
|
|
53
|
+
throw new ManagerApiError(504, "manager request timed out");
|
|
54
|
+
if (!(r.status >= 200 && r.status < 300)) {
|
|
55
|
+
throw new ManagerApiError(r.status, text);
|
|
56
|
+
}
|
|
57
|
+
if (text === "")
|
|
58
|
+
return null;
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(text);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return text;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
if (opts.ctx.signal?.aborted === true) {
|
|
68
|
+
const reason = opts.ctx.signal.reason;
|
|
69
|
+
throw reason instanceof Error ? reason : new DOMException("The operation was aborted", "AbortError");
|
|
70
|
+
}
|
|
71
|
+
if (timeoutOf(dl.signal, "MANAGER_API"))
|
|
72
|
+
throw new ManagerApiError(504, "manager request timed out");
|
|
73
|
+
if (e instanceof ManagerApiError)
|
|
74
|
+
throw e;
|
|
75
|
+
throw planeUnavailable(base, e instanceof Error ? e.message : String(e));
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
dl[Symbol.dispose]();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** GET a manager route (JSON expected). */
|
|
82
|
+
export function managerGet(base, path, opts) {
|
|
83
|
+
return call(base, path, { ...opts, method: "GET" });
|
|
84
|
+
}
|
|
85
|
+
/** POST a manager route. The vendor's content-type gate
|
|
86
|
+
* (_reject_simple_form_content_type) demands proper JSON posts —
|
|
87
|
+
* this always sends application/json. */
|
|
88
|
+
export function managerPost(base, path, body, opts) {
|
|
89
|
+
return call(base, path, { ...opts, method: "POST", body });
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=managerRail.js.map
|
package/lib/queue.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./queueLock.js";
|
|
2
|
+
export * from "./queueSubmit.js";
|
|
3
|
+
export * from "./queueLifecycle.js";
|
|
4
|
+
export * from "./queueCore.js";
|
|
5
|
+
export * from "./queueRetry.js";
|
|
6
|
+
export * from "./queueSidecar.js";
|
|
7
|
+
export * from "./queueSweep.js";
|
|
8
|
+
export * from "./queueResurrect.js";
|
|
9
|
+
//# sourceMappingURL=queue.d.ts.map
|
package/lib/queue.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// queue.ts — P5 queue-core port (the serial-GPU state machine).
|
|
2
|
+
//
|
|
3
|
+
|
|
4
|
+
// Status: landed:
|
|
5
|
+
|
|
6
|
+
// the dead-pid steal ledgered server.lock_stolen, the pid-0
|
|
7
|
+
// probe, the REFUSING line main() prints before any boot
|
|
8
|
+
// side effect.
|
|
9
|
+
// - enqueue/dequeue ordering: order append + the worker's
|
|
10
|
+
// head-pop under the serial guard. PRIORITIES: none — append +
|
|
11
|
+
// head-pop is the whole discipline. A `priority` body key is
|
|
12
|
+
// ignored (FIFO) — this core takes no priority anywhere; a
|
|
13
|
+
// priority-carrying body lands FIFO.
|
|
14
|
+
// - the submit pre-registration refusal chain (submit +
|
|
15
|
+
// strict-body + resolve-request doors): envelope order body ->
|
|
16
|
+
// test -> draft required/malformed/unknown -> strict
|
|
17
|
+
// knobs/carry -> door ambiguity/exclusivity, every text
|
|
18
|
+
// byte-identical (the R4.2 envelope: error verbatim + code +
|
|
19
|
+
// loc/expected/got only when set).
|
|
20
|
+
// - stop/resume/reproduce refusals byte-identical.
|
|
21
|
+
// - the worker's portable policy: 50 ms poll + serial-active
|
|
22
|
+
// guard, the terminal mapping (stopped iff the stop flag is set
|
|
23
|
+
// else completed/failed, "<Type>: <msg>" error), the terminal
|
|
24
|
+
// broadcast frame, the settled-row eviction (completed/failed
|
|
25
|
+
// past 500, oldest created_at first, queued/running/stopped
|
|
26
|
+
// never touched), the worker outliving failures (RESILIENCE
|
|
27
|
+
// LAW).
|
|
28
|
+
// - R3.3 retry rows: max_extra from the node row (retries
|
|
29
|
+
// 0..5), budget from timeout_s (the run budget), stop NEVER
|
|
30
|
+
// retries, every retry ledgered run.stage_retry + stamped
|
|
31
|
+
// retries_used/retry_last_error. Range 0..5 enforced where the
|
|
32
|
+
// row is built — the core reads it.
|
|
33
|
+
// - persistence/journal shapes: LEDGER_PATH output/_ledger.jsonl +
|
|
34
|
+
// the append-only line close-per-line that never throws,
|
|
35
|
+
// atomic tmp+rename indent-2 writes, the sidecar document key
|
|
36
|
+
// order + the capped JSON error (20000) when set, _request.json
|
|
37
|
+
// verbatim, boot_resurrect FIFO-by-created_at + CARD-BIRTH
|
|
38
|
+
// orphan skip, boot_sweep + the read-time sweep texts.
|
|
39
|
+
// - the rebuild-from-record value rules (STRICT: arrays ride,
|
|
40
|
+
// non-arrays skip; missing/empty graphs resurrect rowless;
|
|
41
|
+
// NodeRow mistypes orphan; created_at garbage coerces to 0;
|
|
42
|
+
// _request.json needs only to parse).
|
|
43
|
+
// - live-serve normalization: files keep parsed values in memory.
|
|
44
|
+
// - the queue snapshot key order (queued/running/active/
|
|
45
|
+
// queued_ids) + queue_position (index or 0).
|
|
46
|
+
//
|
|
47
|
+
// WHAT STAYS ENGINE-OWNED (documented gaps, never silent):
|
|
48
|
+
// - engine execution (compose/transport) + the merged/per-stage
|
|
49
|
+
// dispatch: the worker loop here takes an injected execute()
|
|
50
|
+
// (the worker-vs-execute split).
|
|
51
|
+
// - cost_preview / recent / metrics rings (R4.3): observability,
|
|
52
|
+
// not queue discipline — a later stroke.
|
|
53
|
+
// - the WS bus (publish/subscribe frames): WS ports absolute last
|
|
54
|
+
// per the ladder P6; the terminal-frame SHAPE is pinned here as
|
|
55
|
+
// data (terminalFrame) so the bus port inherits it.
|
|
56
|
+
//
|
|
57
|
+
// SERIAL-GPU LAW: one active run per process (the active guard) and
|
|
58
|
+
// one writer process per state root (the lock file). The lock holds
|
|
59
|
+
// for the process lifetime (released pid-checked on clean shutdown);
|
|
60
|
+
// the worker is the only popper (single-writer under one loop).
|
|
61
|
+
//
|
|
62
|
+
// Erasable-syntax TS only (node --experimental-strip-types): no
|
|
63
|
+
// enums, import type for types, .ts specifiers for relative imports.
|
|
64
|
+
|
|
65
|
+
// the sibling helper modules below — pure move, zero logic changes.
|
|
66
|
+
// This barrel keeps the public surface byte-identical: PUBLIC API
|
|
67
|
+
// NEVER MOVES — every symbol stays importable from "./queue.ts").
|
|
68
|
+
export * from "./queueLock.js";
|
|
69
|
+
export * from "./queueSubmit.js";
|
|
70
|
+
export * from "./queueLifecycle.js";
|
|
71
|
+
export * from "./queueCore.js";
|
|
72
|
+
export * from "./queueRetry.js";
|
|
73
|
+
export * from "./queueSidecar.js";
|
|
74
|
+
export * from "./queueSweep.js";
|
|
75
|
+
export * from "./queueResurrect.js";
|
|
76
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Branded } from "@deepseek-ai/dsh-brand";
|
|
2
|
+
import type { LifecycleState } from "./queueLifecycle.js";
|
|
3
|
+
/** The run id: run-<12hex>-<8hex>, opaque as it crosses wire, queue
|
|
4
|
+
* and file (branded at its two producers — the mint below and the
|
|
5
|
+
* resurrect fs door — per the dsh-brand convention). */
|
|
6
|
+
export type RunId = Branded<"RunId">;
|
|
7
|
+
export interface QueueRunRow {
|
|
8
|
+
runId: RunId;
|
|
9
|
+
status: LifecycleState;
|
|
10
|
+
/** Terminal failure text ("<Type>: <msg>") — "" until failed. */
|
|
11
|
+
error: string;
|
|
12
|
+
createdAt: number;
|
|
13
|
+
draftId: string;
|
|
14
|
+
testFlag: boolean;
|
|
15
|
+
stopFlag: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** The serial-GPU registry: runs + submission-order list + the one
|
|
18
|
+
* active run. The worker is the only popper (single-writer under
|
|
19
|
+
* one loop); submission order is append order (strict FIFO — no
|
|
20
|
+
* priority lane exists, see the header). */
|
|
21
|
+
export declare class QueueCore {
|
|
22
|
+
readonly runs: Map<string, QueueRunRow>;
|
|
23
|
+
readonly order: string[];
|
|
24
|
+
activeId: string | null;
|
|
25
|
+
readonly bootAt: number;
|
|
26
|
+
/** Registration tail (submit 1341-1342): the run row joins the
|
|
27
|
+
* registry, its id appends the order list. Returns the queue
|
|
28
|
+
* position (append index). */
|
|
29
|
+
enqueue(run: QueueRunRow): number;
|
|
30
|
+
/** The worker's claim (worker 1356-1360): while active is set the
|
|
31
|
+
* next pop BLOCKS (one GPU run machine-wide); else the head
|
|
32
|
+
* leaves the order list and becomes active. Null = idle. A ghost
|
|
33
|
+
* id at the head (row swept mid-queue — resurrect, bootSweep) is
|
|
34
|
+
* SKIPPED, not treated as idle: returning null on a consumed
|
|
35
|
+
* ghost made the pump read a NON-empty queue as idle and strand
|
|
36
|
+
* every run behind the ghost until a later kick (audit R8,
|
|
37
|
+
* stroke 82). */
|
|
38
|
+
tryDequeue(): QueueRunRow | null;
|
|
39
|
+
/** Release the active claim (worker finally: active null). */
|
|
40
|
+
releaseActive(): void;
|
|
41
|
+
/** Terminal mapping (worker 1366-1371): stopped iff the stop flag
|
|
42
|
+
* is set, else completed on success / failed on exception with
|
|
43
|
+
* the "<Type>: <msg>" error. Returns the settled status. */
|
|
44
|
+
settleRun(run: QueueRunRow, failureText: string | null): LifecycleState;
|
|
45
|
+
/** queue_position (status door 2973-2975): order index, else 0
|
|
46
|
+
* (active/finished runs read 0). */
|
|
47
|
+
queuePosition(runId: string): number;
|
|
48
|
+
/** The queue snapshot (_h_queue 2893-2900): key order . */
|
|
49
|
+
snapshot(): {
|
|
50
|
+
queued: number;
|
|
51
|
+
running: number;
|
|
52
|
+
active: string;
|
|
53
|
+
queued_ids: string[];
|
|
54
|
+
};
|
|
55
|
+
/** Settled-row eviction (_evict_settled 1137-1151): settled ==
|
|
56
|
+
* completed|failed ONLY (stopped rows stay — a deliberate stop
|
|
57
|
+
* is a live receipt, not garbage); past 500 the oldest
|
|
58
|
+
* created_at leaves first. Returns evicted ids. */
|
|
59
|
+
evictSettled(): string[];
|
|
60
|
+
}
|
|
61
|
+
/** run-<12hex>-<8hex> ids (submit 1267: uuid4 hex + time-ms low 32).
|
|
62
|
+
* The mint is one of the brand's two producers; the return cast is
|
|
63
|
+
* the construction door. */
|
|
64
|
+
export declare function newRunId(): RunId;
|
|
65
|
+
/** The terminal broadcast frame (worker 1413-1414): every
|
|
66
|
+
* subscriber gets the final status exactly once. Shape pinned
|
|
67
|
+
* here so the P6 bus port inherits it. */
|
|
68
|
+
export declare function terminalFrame(status: LifecycleState): Record<string, string>;
|
|
69
|
+
//# sourceMappingURL=queueCore.d.ts.map
|