@melite/estate-queue 0.0.0-stage → 0.1.5-pre-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/README.md +54 -2
- package/lib/bakeParams.d.ts +17 -0
- package/lib/bakeParams.js +182 -0
- package/lib/bench.d.ts +32 -0
- package/lib/bench.js +111 -0
- package/lib/cardsArmError.d.ts +61 -0
- package/lib/cardsArmError.js +57 -0
- package/lib/cardsCompose.d.ts +53 -0
- package/lib/cardsCompose.js +295 -0
- package/lib/cardsDangling.d.ts +16 -0
- package/lib/cardsDangling.js +213 -0
- package/lib/cardsFacts.d.ts +87 -0
- package/lib/cardsFacts.js +78 -0
- package/lib/cardsLanes.d.ts +43 -0
- package/lib/cardsLanes.js +178 -0
- package/lib/cardsRegistry.d.ts +404 -0
- package/lib/cardsRegistry.js +1543 -0
- package/lib/cardsVariant.d.ts +37 -0
- package/lib/cardsVariant.js +243 -0
- package/lib/discloseRegistry.d.ts +95 -0
- package/lib/discloseRegistry.js +156 -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 +234 -0
- package/lib/flowsData.js +673 -0
- package/lib/flowsFamilyCompose.d.ts +45 -0
- package/lib/flowsFamilyCompose.js +191 -0
- package/lib/flowsParamsOverlay.d.ts +55 -0
- package/lib/flowsParamsOverlay.js +197 -0
- package/lib/flowsRegistryRows.d.ts +12 -0
- package/lib/flowsRegistryRows.js +520 -0
- package/lib/index.d.ts +47 -0
- package/lib/index.js +75 -0
- package/lib/ledgerTail.d.ts +20 -0
- package/lib/ledgerTail.js +123 -0
- package/lib/lifecycleLatch.d.ts +16 -0
- package/lib/lifecycleLatch.js +42 -0
- package/lib/loadPlane.d.ts +94 -0
- package/lib/loadPlane.js +570 -0
- package/lib/loadRegistry.d.ts +22 -0
- package/lib/loadRegistry.js +55 -0
- package/lib/manageOps.d.ts +27 -0
- package/lib/manageOps.js +162 -0
- package/lib/managePlane.d.ts +151 -0
- package/lib/managePlane.js +1790 -0
- package/lib/manageProbe.d.ts +48 -0
- package/lib/manageProbe.js +165 -0
- package/lib/manageRegistry.d.ts +66 -0
- package/lib/manageRegistry.js +113 -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 +80 -0
- package/lib/queueCore.d.ts +72 -0
- package/lib/queueCore.js +128 -0
- package/lib/queueLifecycle.d.ts +2 -0
- package/lib/queueLifecycle.js +11 -0
- package/lib/queueLock.d.ts +60 -0
- package/lib/queueLock.js +198 -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 +149 -0
- package/lib/queueSidecar.js +183 -0
- package/lib/queueSubmit.d.ts +82 -0
- package/lib/queueSubmit.js +191 -0
- package/lib/queueSweep.d.ts +30 -0
- package/lib/queueSweep.js +132 -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/runsChange.d.ts +61 -0
- package/lib/runsChange.js +79 -0
- package/lib/runsErrorCodes.d.ts +2 -0
- package/lib/runsErrorCodes.js +48 -0
- package/lib/runsExecute.d.ts +52 -0
- package/lib/runsExecute.js +494 -0
- package/lib/runsGates.d.ts +161 -0
- package/lib/runsGates.js +307 -0
- package/lib/runsList.d.ts +78 -0
- package/lib/runsList.js +574 -0
- package/lib/runsRefusalVoices.d.ts +9 -0
- package/lib/runsRefusalVoices.js +96 -0
- package/lib/runsRegistry.d.ts +351 -0
- package/lib/runsRegistry.js +2394 -0
- package/lib/runsSourceEcho.d.ts +81 -0
- package/lib/runsSourceEcho.js +341 -0
- package/lib/runsStart.d.ts +163 -0
- package/lib/runsStart.js +667 -0
- package/lib/runsTypes.d.ts +218 -0
- package/lib/runsTypes.js +289 -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 +339 -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 +276 -0
- package/lib/runsValidateShared.d.ts +84 -0
- package/lib/runsValidateShared.js +88 -0
- package/lib/runsValidateStages.d.ts +32 -0
- package/lib/runsValidateStages.js +511 -0
- package/lib/runsValidateSweeps.d.ts +6 -0
- package/lib/runsValidateSweeps.js +143 -0
- package/lib/service.d.ts +63 -0
- package/lib/service.js +89 -0
- package/lib/skillFrontmatter.d.ts +11 -0
- package/lib/skillFrontmatter.js +46 -0
- package/lib/skillFs.d.ts +24 -0
- package/lib/skillFs.js +78 -0
- package/lib/skillPlane.d.ts +99 -0
- package/lib/skillPlane.js +269 -0
- package/lib/skillRegistry.d.ts +23 -0
- package/lib/skillRegistry.js +55 -0
- package/lib/skillRows.d.ts +127 -0
- package/lib/skillRows.js +468 -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 +48 -4
|
@@ -0,0 +1,48 @@
|
|
|
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(stateRoots: readonly string[]): 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
|
+
export declare function engineQueueView(mctx: ManageCtx): Promise<{
|
|
28
|
+
running: number;
|
|
29
|
+
pending: number;
|
|
30
|
+
} | null>;
|
|
31
|
+
interface EndpointView {
|
|
32
|
+
reachable: boolean;
|
|
33
|
+
url?: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
comfyui_version?: unknown;
|
|
36
|
+
devices?: Array<{
|
|
37
|
+
name: string;
|
|
38
|
+
vram_total: unknown;
|
|
39
|
+
vram_free: unknown;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
export declare function probeEndpoint(mctx: ManageCtx): Promise<EndpointView>;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=manageProbe.d.ts.map
|
|
@@ -0,0 +1,165 @@
|
|
|
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(stateRoots) {
|
|
29
|
+
const out = [];
|
|
30
|
+
for (const dir of sweepOutputRoots(stateRoots)) {
|
|
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
|
+
/** The caller's abort is never a probe answer (audits N-S2/S4):
|
|
101
|
+
* rethrow the abort reason so the fold arms below stay reserved for
|
|
102
|
+
* genuine probe failures — a cancelled caller must cancel, not
|
|
103
|
+
* degrade. Both probes in this file share the arm. */
|
|
104
|
+
function rethrowIfCallerAborted(signal) {
|
|
105
|
+
if (signal?.aborted !== true)
|
|
106
|
+
return;
|
|
107
|
+
const reason = signal.reason;
|
|
108
|
+
throw reason instanceof Error ? reason : new DOMException("The operation was aborted", "AbortError");
|
|
109
|
+
}
|
|
110
|
+
export async function engineQueueView(mctx) {
|
|
111
|
+
const cfg = mctx.endpoint();
|
|
112
|
+
const url = typeof cfg["url"] === "string" ? cfg["url"].replace(/\/+$/, "") : "";
|
|
113
|
+
if (url === "")
|
|
114
|
+
return null;
|
|
115
|
+
const dl = deadline(mctx.signal, 5000, "MANAGE_PROBE");
|
|
116
|
+
try {
|
|
117
|
+
const r = await fetch(url + "/queue", { signal: dl.signal });
|
|
118
|
+
const q = (await r.json());
|
|
119
|
+
const running = q["queue_running"];
|
|
120
|
+
const pending = q["queue_pending"];
|
|
121
|
+
if (!Array.isArray(running) || !Array.isArray(pending))
|
|
122
|
+
return null;
|
|
123
|
+
return { running: running.length, pending: pending.length };
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
// a caller abort rides (N-S2) — only genuine probe failures
|
|
127
|
+
// fold to "no corroboration"
|
|
128
|
+
rethrowIfCallerAborted(mctx.signal);
|
|
129
|
+
void e;
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
dl[Symbol.dispose]();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
export async function probeEndpoint(mctx) {
|
|
141
|
+
const cfg = mctx.endpoint();
|
|
142
|
+
const url = typeof cfg["url"] === "string" ? cfg["url"].replace(/\/+$/, "") : "";
|
|
143
|
+
if (url === "")
|
|
144
|
+
return { reachable: false, reason: "no url in endpoint config" };
|
|
145
|
+
const dl = deadline(mctx.signal, 5000, "MANAGE_PROBE");
|
|
146
|
+
try {
|
|
147
|
+
const r = await fetch(url + "/system_stats", { signal: dl.signal });
|
|
148
|
+
const stats = (await r.json());
|
|
149
|
+
const sysinfo = (stats["system"] ?? {});
|
|
150
|
+
const devices = (stats["devices"] ?? []).slice(0, 4).map((d) => ({
|
|
151
|
+
name: typeof d["name"] === "string" ? d["name"] : "?",
|
|
152
|
+
vram_total: d["vram_total"],
|
|
153
|
+
vram_free: d["vram_free"],
|
|
154
|
+
}));
|
|
155
|
+
return { reachable: true, url, comfyui_version: sysinfo["comfyui_version"], devices };
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
rethrowIfCallerAborted(mctx.signal);
|
|
159
|
+
return { reachable: false, url, reason: String(e).slice(0, 120) };
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
dl[Symbol.dispose]();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=manageProbe.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
4
|
+
import type { ManageEnvelope } from "./managePlane.js";
|
|
5
|
+
declare module "@deepseek-ai/dsh-typert-protocol" {
|
|
6
|
+
interface RemoteErrorDetailsMap {
|
|
7
|
+
/** A refused manage envelope — the details CARRY the envelope
|
|
8
|
+
* (action/status/data) so the tool surfaces WHY. */
|
|
9
|
+
"manage/refused": {
|
|
10
|
+
readonly action?: string;
|
|
11
|
+
readonly status?: number;
|
|
12
|
+
readonly code?: string;
|
|
13
|
+
readonly data?: unknown;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export interface ManageConfig {
|
|
22
|
+
/** The estate deployment's systemd unit (systemctl/journalctl). */
|
|
23
|
+
comfyUnit?: string;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
autoProvision?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** The validator twin of {@link ManageConfig}. */
|
|
33
|
+
export declare const ManageConfig: Schema<Schemastery.ObjectS<NoInfer<{
|
|
34
|
+
comfyUnit: Schema<string, string, "defined">;
|
|
35
|
+
autoProvision: Schema<boolean, boolean, "defined">;
|
|
36
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
37
|
+
comfyUnit: Schema<string, string, "defined">;
|
|
38
|
+
autoProvision: Schema<boolean, boolean, "defined">;
|
|
39
|
+
}>>, "plain">;
|
|
40
|
+
export declare class ManageGatewayService extends Service {
|
|
41
|
+
static inject: string[];
|
|
42
|
+
/** The estate deployment's systemd unit (config-pinned). */
|
|
43
|
+
readonly comfyUnit: string;
|
|
44
|
+
/** The lane's provisioning posture (config-pinned). */
|
|
45
|
+
readonly autoProvision: boolean;
|
|
46
|
+
constructor(ctx: Context, config?: ManageConfig);
|
|
47
|
+
/** The one entry: the tools' /v1/manage lane. */
|
|
48
|
+
act(doc: unknown, signal: AbortSignal): Promise<ManageEnvelope>;
|
|
49
|
+
}
|
|
50
|
+
/** The manage row: gates on the timer seat (the rail's timeouts)
|
|
51
|
+
* and the queue seat (the state roots manifest act() walks —
|
|
52
|
+
* the af-close4 inject cure). Provisioning is not a gate: the
|
|
53
|
+
* plane reads it through the optional ctx.get accessor. */
|
|
54
|
+
export declare const manageProvider: {
|
|
55
|
+
name: string;
|
|
56
|
+
inject: readonly ["timer", "queue"];
|
|
57
|
+
Config: Schema<Schemastery.ObjectS<NoInfer<{
|
|
58
|
+
comfyUnit: Schema<string, string, "defined">;
|
|
59
|
+
autoProvision: Schema<boolean, boolean, "defined">;
|
|
60
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
61
|
+
comfyUnit: Schema<string, string, "defined">;
|
|
62
|
+
autoProvision: Schema<boolean, boolean, "defined">;
|
|
63
|
+
}>>, "plain">;
|
|
64
|
+
apply(ctx: Context, config?: ManageConfig): void;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=manageRegistry.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
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 Schema from "@deepseek-ai/schemastery";
|
|
16
|
+
import { loadEndpointConfig, resolveRepoRoot, modelsService } from "@melite/comfyui-cordis";
|
|
17
|
+
import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
|
|
18
|
+
import { dispatchManage } from "./managePlane.js";
|
|
19
|
+
/** The validator twin of {@link ManageConfig}. */
|
|
20
|
+
export const ManageConfig = Schema.object({
|
|
21
|
+
comfyUnit: Schema.string().default("melite-comfyui.service"),
|
|
22
|
+
autoProvision: Schema.boolean().default(false),
|
|
23
|
+
});
|
|
24
|
+
export class ManageGatewayService extends Service {
|
|
25
|
+
|
|
26
|
+
// ctx.queue.stateRoots unconditionally — with "queue" absent from
|
|
27
|
+
// this list the cordis proxy refused EVERY arm with `cannot get
|
|
28
|
+
// property "queue" without inject` (the runs registry declares
|
|
29
|
+
// the same seat and worked on the very same mount). Provisioning
|
|
30
|
+
// stays OFF the list: act() reads it through the optional
|
|
31
|
+
// ctx.get(name, false) accessor (the NO CAST note below), never
|
|
32
|
+
// a proxy property read — a lane without the provisioning seat
|
|
33
|
+
// keeps the plane (the model doors degrade, the rail arms work).
|
|
34
|
+
static inject = ["timer", "queue"];
|
|
35
|
+
/** The estate deployment's systemd unit (config-pinned). */
|
|
36
|
+
comfyUnit;
|
|
37
|
+
/** The lane's provisioning posture (config-pinned). */
|
|
38
|
+
autoProvision;
|
|
39
|
+
constructor(ctx, config = {}) {
|
|
40
|
+
super(ctx, "manage");
|
|
41
|
+
this.comfyUnit = config.comfyUnit ?? "melite-comfyui.service";
|
|
42
|
+
this.autoProvision = config.autoProvision ?? false;
|
|
43
|
+
}
|
|
44
|
+
/** The one entry: the tools' /v1/manage lane. */
|
|
45
|
+
async act(doc, signal) {
|
|
46
|
+
signal.throwIfAborted();
|
|
47
|
+
const mctx = {
|
|
48
|
+
repoRoot: resolveRepoRoot(),
|
|
49
|
+
stateRoots: this.ctx.queue.stateRoots,
|
|
50
|
+
comfyUnit: this.comfyUnit,
|
|
51
|
+
autoProvision: this.autoProvision,
|
|
52
|
+
endpoint: () => loadEndpointConfig(),
|
|
53
|
+
models: modelsService(),
|
|
54
|
+
|
|
55
|
+
// so. The old `as ProvisioningServiceDefinition` asserted a seat
|
|
56
|
+
// that a lane may simply not mount, and every downstream
|
|
57
|
+
// dereference became a TypeError at call time instead of a
|
|
58
|
+
// declared absence. The plane gates it once (provisioningOf /
|
|
59
|
+
// provisioningOrAbsent).
|
|
60
|
+
provisioning: this.ctx.get("provisioning", false),
|
|
61
|
+
// THE WEIGHT-LANDING RE-ARM (the cards-plane batch): model
|
|
62
|
+
// landings re-arm the card registry's presence cache — the same
|
|
63
|
+
// structural-optional read as provisioning, never a gate (a lane
|
|
64
|
+
// without the registry has no presence face).
|
|
65
|
+
...(this.ctx.get("cardRegistry", false) !== undefined
|
|
66
|
+
? {
|
|
67
|
+
rearmWeights: () => {
|
|
68
|
+
this.ctx.get("cardRegistry", false).rearmWeights();
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
: {}),
|
|
72
|
+
// TWO-CORDIS TOPOLOGY: the timer plugin's Context augmentation
|
|
73
|
+
// lands on ITS cordis copy (structural, never instanceof
|
|
74
|
+
// across copies — the documented law); the seat reads the
|
|
75
|
+
// timer through the structural shape.
|
|
76
|
+
timeout: (callback, delay) => this.ctx.timeout(callback, delay),
|
|
77
|
+
signal,
|
|
78
|
+
};
|
|
79
|
+
const [status, envelope] = await dispatchManage(doc, mctx, signal);
|
|
80
|
+
if (envelope.ok)
|
|
81
|
+
return envelope;
|
|
82
|
+
// A refusal IS the answer's shape: carry the envelope in the
|
|
83
|
+
// RemoteError — the lane surfaces it as the tool's value.
|
|
84
|
+
throw new RemoteError("manage/refused", envelope.detail, {
|
|
85
|
+
action: envelope.action,
|
|
86
|
+
status,
|
|
87
|
+
code: envelope.code,
|
|
88
|
+
data: envelope.data,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** The manage row: gates on the timer seat (the rail's timeouts)
|
|
93
|
+
* and the queue seat (the state roots manifest act() walks —
|
|
94
|
+
* the af-close4 inject cure). Provisioning is not a gate: the
|
|
95
|
+
* plane reads it through the optional ctx.get accessor. */
|
|
96
|
+
export const manageProvider = {
|
|
97
|
+
name: "estate-manage",
|
|
98
|
+
inject: ["timer", "queue"],
|
|
99
|
+
Config: ManageConfig,
|
|
100
|
+
apply(ctx, config = {}) {
|
|
101
|
+
new ManageGatewayService(ctx, config);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// typecheck). The adapter package that CONSUMES the seat declares it
|
|
106
|
+
// on Context — structurally, by its own header's rule: a compiled
|
|
107
|
+
// package may not import these source-run sources into its emit
|
|
108
|
+
// graph, so the contract travels with the caller, and the class that
|
|
109
|
+
// mounts the seat satisfies it structurally. Declaring it here as
|
|
110
|
+
// well (the rename left this twin behind, its comment still naming
|
|
111
|
+
// the pre-rename class) is TS2717 the moment one program composes
|
|
112
|
+
// both sides — which no program did until the walls did.
|
|
113
|
+
//# 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,80 @@
|
|
|
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 (every TERMINAL
|
|
25
|
+
// status — completed, failed, AND stopped (audit F-S11) — past
|
|
26
|
+
// 500, oldest created_at first; queued/running never touched),
|
|
27
|
+
// the worker outliving failures (RESILIENCE LAW).
|
|
28
|
+
|
|
29
|
+
// policy helpers (queueRetry.ts shouldRetry/noteStageRetry,
|
|
30
|
+
// queueCore.ts settleRun, RETRIES_MAX) are ported + spec-pinned
|
|
31
|
+
// but the worker has NO retry loop — runOne settles a failed
|
|
32
|
+
// run terminal, once. `timeout_s` (the R3.3 budget source) is
|
|
33
|
+
// refused on card stages (flowsRegistryRows.ts), so the core
|
|
34
|
+
// reads no budget today. Wire the loop or delete the policy —
|
|
35
|
+
// never quote it as live.
|
|
36
|
+
// - persistence/journal shapes: LEDGER_PATH output/_ledger.jsonl +
|
|
37
|
+
// the append-only line close-per-line that never throws,
|
|
38
|
+
// atomic tmp+rename indent-2 writes, the sidecar document key
|
|
39
|
+
// order + the capped JSON error (20000) when set, _request.json
|
|
40
|
+
// verbatim, boot_resurrect FIFO-by-created_at + CARD-BIRTH
|
|
41
|
+
// orphan skip, boot_sweep + the read-time sweep texts.
|
|
42
|
+
// - the rebuild-from-record value rules (STRICT: arrays ride,
|
|
43
|
+
// non-arrays skip; missing/empty graphs resurrect rowless;
|
|
44
|
+
// NodeRow mistypes orphan; created_at garbage coerces to 0;
|
|
45
|
+
// _request.json needs only to parse).
|
|
46
|
+
// - live-serve normalization: files keep parsed values in memory.
|
|
47
|
+
// - the queue snapshot key order (queued/running/active/
|
|
48
|
+
// queued_ids) + queue_position (index or 0).
|
|
49
|
+
//
|
|
50
|
+
// WHAT STAYS ENGINE-OWNED (documented gaps, never silent):
|
|
51
|
+
// - engine execution (compose/transport) + the merged/per-stage
|
|
52
|
+
// dispatch: the worker loop here takes an injected execute()
|
|
53
|
+
// (the worker-vs-execute split).
|
|
54
|
+
// - cost_preview / recent / metrics rings (R4.3): observability,
|
|
55
|
+
// not queue discipline — a later stroke.
|
|
56
|
+
// - the WS bus (publish/subscribe frames): WS ports absolute last
|
|
57
|
+
// per the ladder P6; the terminal-frame SHAPE is pinned here as
|
|
58
|
+
// data (terminalFrame) so the bus port inherits it.
|
|
59
|
+
//
|
|
60
|
+
// SERIAL-GPU LAW: one active run per process (the active guard) and
|
|
61
|
+
// one writer process per state root (the lock file). The lock holds
|
|
62
|
+
// for the process lifetime (released pid-checked on clean shutdown);
|
|
63
|
+
// the worker is the only popper (single-writer under one loop).
|
|
64
|
+
//
|
|
65
|
+
// Erasable-syntax TS only (node --experimental-strip-types): no
|
|
66
|
+
// enums, import type for types, .ts specifiers for relative imports.
|
|
67
|
+
|
|
68
|
+
// the sibling helper modules below — pure move, zero logic changes.
|
|
69
|
+
// This barrel keeps the public surface byte-identical: PUBLIC API
|
|
70
|
+
// NEVER MOVES — every symbol stays importable from this barrel,
|
|
71
|
+
// source plane queue.ts / emitted queue.js).
|
|
72
|
+
export * from "./queueLock.js";
|
|
73
|
+
export * from "./queueSubmit.js";
|
|
74
|
+
export * from "./queueLifecycle.js";
|
|
75
|
+
export * from "./queueCore.js";
|
|
76
|
+
export * from "./queueRetry.js";
|
|
77
|
+
export * from "./queueSidecar.js";
|
|
78
|
+
export * from "./queueSweep.js";
|
|
79
|
+
export * from "./queueResurrect.js";
|
|
80
|
+
//# sourceMappingURL=queue.js.map
|