@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
package/lib/manageOps.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
export const COMFY_UNIT = process.env["MELITE_COMFYUI_UNIT"] ?? "melite-comfyui.service";
|
|
110
|
+
export async function systemctl(req, verb, signal) {
|
|
111
|
+
try {
|
|
112
|
+
await execFileAsync("systemctl", ["--user", verb, COMFY_UNIT], {
|
|
113
|
+
timeout: 30 * 1000,
|
|
114
|
+
encoding: "utf8",
|
|
115
|
+
signal,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (signal?.aborted === true)
|
|
120
|
+
throw abortReason(signal);
|
|
121
|
+
const value = error;
|
|
122
|
+
const why = String(value.stderr ?? value.message).trim().slice(0, 200);
|
|
123
|
+
return [500, { action: req.action, ok: false, detail: "systemctl " + verb + " " + COMFY_UNIT + " failed: " + why }];
|
|
124
|
+
}
|
|
125
|
+
return [200, {
|
|
126
|
+
action: req.action,
|
|
127
|
+
ok: true,
|
|
128
|
+
detail: verb + " issued for " + COMFY_UNIT,
|
|
129
|
+
next_action: verb === "stop" ? "launch" : "status",
|
|
130
|
+
data: { next_action: verb === "stop" ? "launch" : "status" },
|
|
131
|
+
}];
|
|
132
|
+
}
|
|
133
|
+
export function guardLifecycle(req, ctx) {
|
|
134
|
+
if (req.force)
|
|
135
|
+
return;
|
|
136
|
+
const active = activeRuns();
|
|
137
|
+
if (active.length > 0) {
|
|
138
|
+
throw new Refused(409, "refused: " + active.length + " active run(s) (" + active.slice(0, 4).join(", ") +
|
|
139
|
+
") — stop them first (the stop door) or pass force=true");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=manageOps.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
}
|
|
26
|
+
export interface ManageCtx {
|
|
27
|
+
/** File-anchored repo root (routing, catalog, runs scan anchor). */
|
|
28
|
+
repoRoot: string;
|
|
29
|
+
/** The endpoint config, re-read per call (fresh — never cached
|
|
30
|
+
* between calls): carries the engine url the manager rail rides.
|
|
31
|
+
* The bridges door passes loadEndpointConfig itself. */
|
|
32
|
+
endpoint: () => Record<string, unknown>;
|
|
33
|
+
/** The models catalog (stroke 4a: injected by the bridges door
|
|
34
|
+
* from the engine-model-catalog provider row — required, never
|
|
35
|
+
* optional: a door without its catalog is a miswire, and the
|
|
36
|
+
* type error at the construction site is the loudest refusal). */
|
|
37
|
+
models: ModelsService;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
provisioning?: ProvisioningServiceDefinition;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
timeout: (callback: () => void, delay: number) => () => void;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
objectInfo?: () => Promise<unknown>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export declare function provisioningOf(ctx: ManageCtx): ProvisioningServiceDefinition;
|
|
84
|
+
export declare function provisioningOrAbsent(ctx: ManageCtx): ProvisioningServiceDefinition | undefined;
|
|
85
|
+
export interface Req {
|
|
86
|
+
action: ManageAction;
|
|
87
|
+
nodes: string[];
|
|
88
|
+
url: string;
|
|
89
|
+
relative_path: string;
|
|
90
|
+
filename: string;
|
|
91
|
+
wait: boolean | null;
|
|
92
|
+
timeout_seconds: number;
|
|
93
|
+
model: string;
|
|
94
|
+
variant: string;
|
|
95
|
+
quant: string;
|
|
96
|
+
tail: number;
|
|
97
|
+
query: string;
|
|
98
|
+
version: string;
|
|
99
|
+
target: string;
|
|
100
|
+
extra_args: string[];
|
|
101
|
+
force: boolean;
|
|
102
|
+
snapshot: string;
|
|
103
|
+
path: string;
|
|
104
|
+
data: string;
|
|
105
|
+
families: string[];
|
|
106
|
+
/** THE ACQUIRE-WEIGHT POLL KEY (F9 run-press acquisition): the
|
|
107
|
+
* tracker's poll carries ONLY this — the start carries the model
|
|
108
|
+
* (plus the missing file for display, via filename) and returns
|
|
109
|
+
* this id at once. */
|
|
110
|
+
operation_id: string;
|
|
111
|
+
}
|
|
112
|
+
export declare class Refused extends Error {
|
|
113
|
+
data?: unknown;
|
|
114
|
+
constructor(code: number, message: string, data?: unknown);
|
|
115
|
+
code: number;
|
|
116
|
+
}
|
|
117
|
+
export declare const badRequest: (m: string) => Refused;
|
|
118
|
+
export declare function parseReq(doc: unknown): Req;
|
|
119
|
+
export declare function dispatchManage(doc: unknown, ctx: ManageCtx, signal?: AbortSignal): Promise<[number, ManageEnvelope]>;
|
|
120
|
+
//# sourceMappingURL=managePlane.d.ts.map
|