@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
package/lib/manageOps.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// manageOps.ts — the manage plane's rails (extracted from
|
|
2
|
+
// managePlane.ts, the god-file cut): the vendor manager rail +
|
|
3
|
+
// refusals folding, estate model downloads, and the systemd
|
|
4
|
+
// lifecycle verbs.
|
|
5
|
+
import { execFile } from "node:child_process";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { activeRuns } from "./manageProbe.js";
|
|
8
|
+
import { ManagerApiError, managerBase, managerGet } from "./managerRail.js";
|
|
9
|
+
import { Refused } from "./managePlane.js";
|
|
10
|
+
const execFileAsync = promisify(execFile);
|
|
11
|
+
// ── the manager rail (vendor HTTP — see manager-api.ts) ────────────
|
|
12
|
+
export function base(ctx) {
|
|
13
|
+
return managerBase(ctx);
|
|
14
|
+
}
|
|
15
|
+
/** Map a manager refusal to the estate envelope (the vendor's own
|
|
16
|
+
* security texts ride verbatim — this door never reinterprets a
|
|
17
|
+
* security answer). */
|
|
18
|
+
export function mapManagerRefused(e, action) {
|
|
19
|
+
if (e.status === 503)
|
|
20
|
+
return new Refused(503, e.text, undefined);
|
|
21
|
+
if (e.status === 403) {
|
|
22
|
+
return new Refused(403, "manager refused " + action + " (security_level or the loopback listen flag): " + e.text.slice(0, 200));
|
|
23
|
+
}
|
|
24
|
+
if (e.status === 404)
|
|
25
|
+
return new Refused(404, "manager has no such target: " + e.text.slice(0, 200));
|
|
26
|
+
if (e.status === 504)
|
|
27
|
+
return new Refused(504, "manager request timed out: " + e.text.slice(0, 200));
|
|
28
|
+
return new Refused(502, "manager api error " + e.status + ": " + e.text.slice(0, 200));
|
|
29
|
+
}
|
|
30
|
+
/** Map a rail failure to its refusal: the rail throws ManagerApiError
|
|
31
|
+
* by contract (refusals verbatim, transports as the 503 template),
|
|
32
|
+
* so the fallthrough only guards the type, never a live error. */
|
|
33
|
+
export function mapRail(e, action) {
|
|
34
|
+
if (e instanceof ManagerApiError)
|
|
35
|
+
return mapManagerRefused(e, action);
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
export function railMs(req) {
|
|
41
|
+
return Math.min(Math.max(req.timeout_seconds, 1), 850) * 1000;
|
|
42
|
+
}
|
|
43
|
+
/** Poll the vendor's task queue until drained (install arms: the
|
|
44
|
+
* vendor returns 202-semantics — queue accepted — and processes
|
|
45
|
+
* asynchronously; the poll bounds the AI door's wait). */
|
|
46
|
+
function abortReason(signal) {
|
|
47
|
+
return signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted", "AbortError");
|
|
48
|
+
}
|
|
49
|
+
export async function awaitQueueDrained(ctx, req) {
|
|
50
|
+
const deadline = Date.now() + railMs(req);
|
|
51
|
+
for (;;) {
|
|
52
|
+
if (ctx.signal?.aborted === true)
|
|
53
|
+
throw abortReason(ctx.signal);
|
|
54
|
+
if (Date.now() >= deadline)
|
|
55
|
+
return { timed_out: true };
|
|
56
|
+
let st;
|
|
57
|
+
try {
|
|
58
|
+
st = await managerGet(base(ctx), "/manager/queue/status", {
|
|
59
|
+
ctx, timeoutMs: Math.min(10_000, Math.max(1, deadline - Date.now())),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (Date.now() >= deadline)
|
|
64
|
+
return { timed_out: true };
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
const processing = st["is_processing"] === true;
|
|
68
|
+
const pending = Number(st["in_progress_count"] ?? 0) + Number(st["total_count"] ?? 0) - Number(st["done_count"] ?? 0);
|
|
69
|
+
if (!processing && pending <= 0)
|
|
70
|
+
return st;
|
|
71
|
+
if (Date.now() >= deadline)
|
|
72
|
+
return { ...st, timed_out: true };
|
|
73
|
+
await waitForQueuePoll(ctx);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function waitForQueuePoll(ctx) {
|
|
77
|
+
const signal = ctx.signal;
|
|
78
|
+
if (signal?.aborted === true)
|
|
79
|
+
return Promise.reject(abortReason(signal));
|
|
80
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
81
|
+
// The seat IS the timer (ManageCtx.timeout, the conformance
|
|
82
|
+
// stroke's no-bare-setTimeout guarantee): the poll waits on
|
|
83
|
+
// ctx.timeout and races the door's signal. No settled-flag dance
|
|
84
|
+
// -- a promise settles once, so the guard the wrapper carried
|
|
85
|
+
// was unreachable; the post-registration re-check closes the
|
|
86
|
+
// race where the signal aborts between the check above and the
|
|
87
|
+
// listener landing.
|
|
88
|
+
const dispose = ctx.timeout(() => {
|
|
89
|
+
signal?.removeEventListener('abort', onAbort);
|
|
90
|
+
resolvePromise();
|
|
91
|
+
}, 1000);
|
|
92
|
+
const onAbort = () => {
|
|
93
|
+
dispose();
|
|
94
|
+
rejectPromise(abortReason(signal));
|
|
95
|
+
};
|
|
96
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
97
|
+
if (signal?.aborted === true)
|
|
98
|
+
onAbort();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/** BYO guard: estate-orchestration legs (systemd, workspace reads)
|
|
102
|
+
* never touch a user-owned ComfyUI. */
|
|
103
|
+
export function estateOnly(req, cfg) {
|
|
104
|
+
if (cfg["provision"] === "managed")
|
|
105
|
+
return;
|
|
106
|
+
throw new Refused(409, "byo endpoint: " + req.action + " orchestrates the estate engine — the estate never touches a user-owned ComfyUI");
|
|
107
|
+
}
|
|
108
|
+
// ── systemd orchestration (estate deployment — TS-native) ──────────
|
|
109
|
+
|
|
110
|
+
// frozen before any plugin loads; it is now the manage provider's
|
|
111
|
+
// config field, resolved per mount.
|
|
112
|
+
/** Run systemctl for the estate's engine unit.
|
|
113
|
+
* @param req - the manage request (envelope rows).
|
|
114
|
+
* @param verb - the systemctl verb to run.
|
|
115
|
+
* @param unit - the estate deployment's systemd unit (config-pinned).
|
|
116
|
+
* @param signal - aborts the child and maps to the abort reason.
|
|
117
|
+
* @returns [status, envelope] as the manage lane's answer.
|
|
118
|
+
*/
|
|
119
|
+
export async function systemctl(req, verb, unit, signal) {
|
|
120
|
+
try {
|
|
121
|
+
await execFileAsync("systemctl", ["--user", verb, unit], {
|
|
122
|
+
timeout: 30 * 1000,
|
|
123
|
+
encoding: "utf8",
|
|
124
|
+
signal,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (signal?.aborted === true)
|
|
129
|
+
throw abortReason(signal);
|
|
130
|
+
const value = error;
|
|
131
|
+
const why = String(value.stderr ?? value.message).trim().slice(0, 200);
|
|
132
|
+
return [500, { action: req.action, ok: false, detail: "systemctl " + verb + " " + unit + " failed: " + why }];
|
|
133
|
+
}
|
|
134
|
+
return [200, {
|
|
135
|
+
action: req.action,
|
|
136
|
+
ok: true,
|
|
137
|
+
detail: verb + " issued for " + unit,
|
|
138
|
+
next_action: verb === "stop" ? "launch" : "status",
|
|
139
|
+
data: { next_action: verb === "stop" ? "launch" : "status" },
|
|
140
|
+
}];
|
|
141
|
+
}
|
|
142
|
+
export function guardLifecycle(req, ctx) {
|
|
143
|
+
if (req.force)
|
|
144
|
+
return;
|
|
145
|
+
const active = activeRuns(ctx.stateRoots);
|
|
146
|
+
if (active.length > 0) {
|
|
147
|
+
throw new Refused(409, "refused: " + active.length + " active run(s) (" + active.slice(0, 4).join(", ") +
|
|
148
|
+
") — stop them first (the stop door) or pass force=true");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// locks — a teardown during an in-flight fetch unloaded VRAM under
|
|
152
|
+
// a landing fetch or failed it mid-stream. The seat's sync census
|
|
153
|
+
// (locks plus pre-lock mints) joins the refusal: a seat without the
|
|
154
|
+
// probe reads as idle (the optional-seat posture). Synchronous by
|
|
155
|
+
// law — the guard never awaits.
|
|
156
|
+
const inflight = ctx.provisioning?.inflightAcquires?.() ?? [];
|
|
157
|
+
if (inflight.length > 0) {
|
|
158
|
+
throw new Refused(409, "refused: " + inflight.length + " in-flight acquisition(s) (" + inflight.slice(0, 4).join(", ") +
|
|
159
|
+
") — wait for the fetch to land (poll acquire_weight) or pass force=true", { state: "conflict", next_action: "status" });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=manageOps.js.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ModelsService } from "@melite/comfyui-cordis";
|
|
2
|
+
import type { ProvisioningServiceDefinition } from "@melite/estate-provisioning";
|
|
3
|
+
export declare const ACTIONS: readonly ["status", "endpoint_set", "logs", "search_models", "list_extensions", "snapshot_list", "install_extension", "install_extension_url", "download_model", "provision_model", "acquire_weight", "restart", "stop", "launch", "update", "switch_version", "free", "snapshot_save", "snapshot_restore", "lora_list", "lora_install"];
|
|
4
|
+
export type ManageAction = (typeof ACTIONS)[number];
|
|
5
|
+
export declare const LIFECYCLE_GUARDED: ReadonlySet<ManageAction>;
|
|
6
|
+
export interface ManageEnvelope {
|
|
7
|
+
action: string;
|
|
8
|
+
ok: boolean;
|
|
9
|
+
detail: string;
|
|
10
|
+
data?: unknown;
|
|
11
|
+
status?: number;
|
|
12
|
+
code?: string;
|
|
13
|
+
state?: string;
|
|
14
|
+
next_action?: string;
|
|
15
|
+
operation_id?: string;
|
|
16
|
+
operations?: unknown[];
|
|
17
|
+
items?: unknown[];
|
|
18
|
+
rows?: unknown[];
|
|
19
|
+
requested?: string[];
|
|
20
|
+
succeeded?: string[];
|
|
21
|
+
missed?: string[];
|
|
22
|
+
misses?: string[];
|
|
23
|
+
partial?: boolean;
|
|
24
|
+
restart_required?: boolean;
|
|
25
|
+
retry_after_ms?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ManageCtx {
|
|
28
|
+
/** File-anchored repo root (routing, catalog, runs scan anchor). */
|
|
29
|
+
repoRoot: string;
|
|
30
|
+
/** The §23 cross-roots manifest (own state root first, then the
|
|
31
|
+
* stateRoots config extras): the runs-probe rows (restart
|
|
32
|
+
* guard, status) walk these trees — one law from the queue
|
|
33
|
+
* seat, never the retired env seam (J12). */
|
|
34
|
+
stateRoots: readonly string[];
|
|
35
|
+
/** The estate deployment's systemd unit (V7 cure: the manage
|
|
36
|
+
* provider's config field — systemctl/journalctl/status rows all
|
|
37
|
+
* read this one value, never an import-time env capture). */
|
|
38
|
+
comfyUnit: string;
|
|
39
|
+
/** The lane's provisioning posture (the manage provider's config
|
|
40
|
+
* field): true tells the deck the DECLARED arms run without the
|
|
41
|
+
* operator confirm — the raw-URL arms stay operator-gated in the
|
|
42
|
+
* deck's own gate regardless of this value. */
|
|
43
|
+
autoProvision: boolean;
|
|
44
|
+
/** The endpoint config, re-read per call (fresh — never cached
|
|
45
|
+
* between calls): carries the engine url the manager rail rides.
|
|
46
|
+
* The bridges door passes loadEndpointConfig itself. */
|
|
47
|
+
endpoint: () => Record<string, unknown>;
|
|
48
|
+
/** The models catalog (stroke 4a: injected by the bridges door
|
|
49
|
+
* from the engine-model-catalog provider row — required, never
|
|
50
|
+
* optional: a door without its catalog is a miswire, and the
|
|
51
|
+
* type error at the construction site is the loudest refusal). */
|
|
52
|
+
models: ModelsService;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
provisioning?: ProvisioningServiceDefinition;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
timeout: (callback: () => void, delay: number) => () => void;
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
objectInfo?: () => Promise<unknown>;
|
|
84
|
+
/** THE WEIGHT-LANDING RE-ARM (the cards-plane batch): called after
|
|
85
|
+
* a model lands under a living process (provision_model,
|
|
86
|
+
* download_model, an acquire_weight poll observing a terminal
|
|
87
|
+
* state) so the card registry's presence cache re-derives on its
|
|
88
|
+
* next read. Optional: a lane without the estate card registry
|
|
89
|
+
* has no presence face to re-arm. */
|
|
90
|
+
rearmWeights?: () => void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
export declare function provisioningOf(ctx: ManageCtx): ProvisioningServiceDefinition;
|
|
106
|
+
export declare function provisioningOrAbsent(ctx: ManageCtx): ProvisioningServiceDefinition | undefined;
|
|
107
|
+
export interface Req {
|
|
108
|
+
action: ManageAction;
|
|
109
|
+
nodes: string[];
|
|
110
|
+
url: string;
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
ref: string;
|
|
116
|
+
relative_path: string;
|
|
117
|
+
filename: string;
|
|
118
|
+
wait: boolean | null;
|
|
119
|
+
timeout_seconds: number;
|
|
120
|
+
model: string;
|
|
121
|
+
variant: string;
|
|
122
|
+
quant: string;
|
|
123
|
+
tail: number;
|
|
124
|
+
query: string;
|
|
125
|
+
version: string;
|
|
126
|
+
target: string;
|
|
127
|
+
extra_args: string[];
|
|
128
|
+
force: boolean;
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
operator_confirmed: boolean;
|
|
133
|
+
snapshot: string;
|
|
134
|
+
path: string;
|
|
135
|
+
data: string;
|
|
136
|
+
families: string[];
|
|
137
|
+
/** THE ACQUIRE-WEIGHT POLL KEY (F9 run-press acquisition): the
|
|
138
|
+
* tracker's poll carries ONLY this — the start carries the model
|
|
139
|
+
* (plus the missing file for display, via filename) and returns
|
|
140
|
+
* this id at once. */
|
|
141
|
+
operation_id: string;
|
|
142
|
+
}
|
|
143
|
+
export declare class Refused extends Error {
|
|
144
|
+
data?: unknown;
|
|
145
|
+
constructor(code: number, message: string, data?: unknown);
|
|
146
|
+
code: number;
|
|
147
|
+
}
|
|
148
|
+
export declare const badRequest: (m: string) => Refused;
|
|
149
|
+
export declare function parseReq(doc: unknown): Req;
|
|
150
|
+
export declare function dispatchManage(doc: unknown, ctx: ManageCtx, signal?: AbortSignal): Promise<[number, ManageEnvelope]>;
|
|
151
|
+
//# sourceMappingURL=managePlane.d.ts.map
|