@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/runsStart.js
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import { CARD_PLANE_ENGINE } from "@melite/contracts/benchStage";
|
|
2
|
+
// runsStart.ts — the start arm's pure chain, re-homed VERBATIM from
|
|
3
|
+
// the dead flowsRun door (REBUILD-6): the flow_inline structural
|
|
4
|
+
// compile (frozen texts over the admission verdicts in
|
|
5
|
+
// ./runsGates.ts) and the registration tail (mint + dir + the rich
|
|
6
|
+
// run row). Refusals keep the door's byte-pinned prose as tagged
|
|
7
|
+
// unions — the remote maps them to the protocol's ONE RemoteError.
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
// a scope two strokes out of date and now contradicted its own body):
|
|
11
|
+
// this module is the start arm's chain for EVERY run shape the runs
|
|
12
|
+
// service registers — {model:} card runs, {flow:} registry runs,
|
|
13
|
+
// {flow_inline:} inline runs, and MULTI-STAGE bench rows. The
|
|
14
|
+
// refusals that remain are the ones listed at their own arms: the
|
|
15
|
+
// compile gates (an unknown node, an undeclared input, a dead wire,
|
|
16
|
+
// a self-wire) and the initial gate (a missing FromStage initial).
|
|
17
|
+
import { mkdirSync } from "node:fs";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { engineIdOk } from "@melite/engine-contract";
|
|
20
|
+
import { FLOW_INLINE_TOP_VOICE, INLINE_TOP_KEYS, STAGE_KEYS, checkFlowInlineTop, checkFlowStage, } from "./runsGates.js";
|
|
21
|
+
import { appendLedger, outRootFor, refusal, sidecarDoc, sidecarStageOf, variantOfBodies, writeJsonAtomic } from "./queue.js";
|
|
22
|
+
import { rootsManifest } from "./rootsManifest.js";
|
|
23
|
+
import { saveBenchSnapshotStages } from "@melite/contracts/benchSnapshot";
|
|
24
|
+
import { collectSourceRefs, resolveSourceRefs } from "./runsSourceEcho.js";
|
|
25
|
+
/** flow_inline structural compile — door-verbatim (structure via
|
|
26
|
+
* the admission verdicts, voice here; the engine policy +
|
|
27
|
+
* default-fills below are value-domain, not type structure).
|
|
28
|
+
*
|
|
29
|
+
* THE ENGINE GATE (stroke 53, the engine-generics seam): the
|
|
30
|
+
* engine id must be GRAMMATICAL (the card plane's engine or 'mcp:<server>',
|
|
31
|
+
* engine-contract's engineIdOk) AND known to the caller. The
|
|
32
|
+
* caller passes the live registry ids (the 'engines' seat when
|
|
33
|
+
* mounted); the default (CARD_PLANE_ENGINE) keeps every seat-less boot
|
|
34
|
+
* (fixtures, walls) on the pre-seam voice. */
|
|
35
|
+
export function compileFlowInline(inline, knownEngines = [CARD_PLANE_ENGINE]) {
|
|
36
|
+
const top = checkFlowInlineTop(inline);
|
|
37
|
+
if (top.kind === "not-object" || top.kind === "bad-stages") {
|
|
38
|
+
return refusal(400, FLOW_INLINE_TOP_VOICE[top.kind], "invalid_request");
|
|
39
|
+
}
|
|
40
|
+
if (top.kind === "unknown-keys") {
|
|
41
|
+
return refusal(400, "flow body carries unknown keys " +
|
|
42
|
+
JSON.stringify(top.dead) +
|
|
43
|
+
" — allowed: " +
|
|
44
|
+
JSON.stringify([...INLINE_TOP_KEYS].sort()), "invalid_request");
|
|
45
|
+
}
|
|
46
|
+
if (top.kind === "missing-id-stages") {
|
|
47
|
+
return refusal(400, "flow body needs at least id and stages — got keys " +
|
|
48
|
+
JSON.stringify(top.keys), "invalid_request");
|
|
49
|
+
}
|
|
50
|
+
const rec = top.rec;
|
|
51
|
+
const stages = [];
|
|
52
|
+
const rows = rec["stages"];
|
|
53
|
+
for (let i = 0; i < rows.length; i++) {
|
|
54
|
+
const checked = checkFlowStage(rows[i]);
|
|
55
|
+
if (checked.kind === "not-object") {
|
|
56
|
+
return refusal(400, "stage[" + i + "] must be an object", "invalid_request");
|
|
57
|
+
}
|
|
58
|
+
if (checked.kind === "unknown-fields") {
|
|
59
|
+
const st = checked.st;
|
|
60
|
+
return refusal(400, "stage[" +
|
|
61
|
+
i +
|
|
62
|
+
"] " +
|
|
63
|
+
JSON.stringify(String(st["id"] ?? "<no id>")) +
|
|
64
|
+
": body carries unknown field(s) " +
|
|
65
|
+
JSON.stringify(checked.extras) +
|
|
66
|
+
" — the schema declares " +
|
|
67
|
+
JSON.stringify([...STAGE_KEYS].sort()) +
|
|
68
|
+
" (extra=forbid at the door)", "invalid_request");
|
|
69
|
+
}
|
|
70
|
+
if (checked.kind === "bad-id") {
|
|
71
|
+
const sid = String(checked.st["id"] ?? "");
|
|
72
|
+
return refusal(400, "stage id " + JSON.stringify(sid) + " is not a legal identifier", "invalid_request");
|
|
73
|
+
}
|
|
74
|
+
const st = checked.st;
|
|
75
|
+
// (the bad-id gate above refuses id-less stages — the id is a
|
|
76
|
+
// string here.)
|
|
77
|
+
const sid = st["id"];
|
|
78
|
+
const engine = String(st["engine"] ?? "");
|
|
79
|
+
if (engine === "") {
|
|
80
|
+
return refusal(400, "stage " + JSON.stringify(sid) + ": no engine named", "invalid_request");
|
|
81
|
+
}
|
|
82
|
+
if (engine !== CARD_PLANE_ENGINE) {
|
|
83
|
+
// Grammar first (drift in the id itself), then membership
|
|
84
|
+
// (an id the gateway cannot serve). Both refuse with the
|
|
85
|
+
// engine named — never a silent skip. The seat-less default
|
|
86
|
+
// (the card plane's engine) keeps the pre-seam refusal for foreign ids.
|
|
87
|
+
if (!engineIdOk(engine)) {
|
|
88
|
+
return refusal(400, "flow_inline stage " +
|
|
89
|
+
JSON.stringify(sid) +
|
|
90
|
+
" names engine " +
|
|
91
|
+
JSON.stringify(engine) +
|
|
92
|
+
" — engine ids are '" + CARD_PLANE_ENGINE + "' or 'mcp:<server>' ([A-Za-z0-9_-]{1,32})", "invalid_request");
|
|
93
|
+
}
|
|
94
|
+
if (!knownEngines.includes(engine)) {
|
|
95
|
+
return refusal(400, "flow_inline stage " +
|
|
96
|
+
JSON.stringify(sid) +
|
|
97
|
+
" names engine " +
|
|
98
|
+
JSON.stringify(engine) +
|
|
99
|
+
" — this gateway serves registered engines only (" +
|
|
100
|
+
(knownEngines.length === 0
|
|
101
|
+
? "none registered"
|
|
102
|
+
: knownEngines.slice().sort().join(", ")) +
|
|
103
|
+
")", "preview_scope");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// No branch pruning on this gateway: skip_when is unported.
|
|
107
|
+
if (st["skip_when"] !== undefined && st["skip_when"] !== null) {
|
|
108
|
+
return refusal(400, "flow_inline stage " +
|
|
109
|
+
JSON.stringify(sid) +
|
|
110
|
+
": skip_when is unported on this gateway", "preview_scope");
|
|
111
|
+
}
|
|
112
|
+
// (the undefined guard above fired — the ?? below is dead.)
|
|
113
|
+
if (st["card"] !== undefined && String(st["card"]) !== "") {
|
|
114
|
+
return refusal(400, "flow_inline stage " +
|
|
115
|
+
JSON.stringify(sid) +
|
|
116
|
+
": card= stages are unported on this gateway", "preview_scope");
|
|
117
|
+
}
|
|
118
|
+
// A MALFORMED CONTAINER IS REFUSED, NOT COERCED (the coverage
|
|
119
|
+
// audit's HIGH finding, proven independently by two auditors).
|
|
120
|
+
|
|
121
|
+
// absent: the run registered "clean", the operator saw a
|
|
122
|
+
// completed run with its wiring silently gone, and
|
|
123
|
+
// runs-start.spec.ts ASSERTED that silence. The bench door
|
|
124
|
+
// refuses the same shapes (bench/bad-wire) — two seats, one
|
|
125
|
+
// shape, opposite judgments. The bench is right: a container that
|
|
126
|
+
// cannot be read is not an absent container.
|
|
127
|
+
for (const key of ["params", "inputs", "outputs", "expected"]) {
|
|
128
|
+
const raw = st[key];
|
|
129
|
+
if (raw === undefined)
|
|
130
|
+
continue;
|
|
131
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
132
|
+
return refusal(400, "flow_inline stage " + JSON.stringify(sid) + ": " + key +
|
|
133
|
+
" must be an object (got " +
|
|
134
|
+
(raw === null ? "null" : Array.isArray(raw) ? "array" : typeof raw) +
|
|
135
|
+
"); a shape that cannot be read is refused here, not dropped — a dropped " +
|
|
136
|
+
key + " makes the run register without it", "invalid_request");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// AND A MALFORMED BINDING inside a well-formed container, for the
|
|
140
|
+
// same reason: `{stage: "up"}` with no output channel is a wire
|
|
141
|
+
// that resolves to nothing, and dropping it is indistinguishable
|
|
142
|
+
// from never having wired it.
|
|
143
|
+
const rawInputs = st["inputs"];
|
|
144
|
+
for (const [name, ref] of Object.entries(rawInputs ?? {})) {
|
|
145
|
+
const rr = ref;
|
|
146
|
+
const shaped = typeof rr === "object" && rr !== null && !Array.isArray(rr);
|
|
147
|
+
if (shaped && (typeof rr["stage"] === "string" && typeof rr["output"] === "string"))
|
|
148
|
+
continue;
|
|
149
|
+
if (shaped && typeof rr["initial"] === "string")
|
|
150
|
+
continue;
|
|
151
|
+
return refusal(400, "flow_inline stage " + JSON.stringify(sid) + ": input " + JSON.stringify(name) +
|
|
152
|
+
" is neither {stage, output} nor {initial} (got " + JSON.stringify(ref) +
|
|
153
|
+
") — a wire that cannot be read is refused here, not dropped", "invalid_request");
|
|
154
|
+
}
|
|
155
|
+
const params = typeof st["params"] === "object" && st["params"] !== null && !Array.isArray(st["params"])
|
|
156
|
+
? st["params"]
|
|
157
|
+
: {};
|
|
158
|
+
const outputs = typeof st["outputs"] === "object" && st["outputs"] !== null && !Array.isArray(st["outputs"])
|
|
159
|
+
? st["outputs"]
|
|
160
|
+
: { default: "image" }; // the engine DEFAULT_OUTPUT fill
|
|
161
|
+
const expected = typeof st["expected"] === "object" && st["expected"] !== null && !Array.isArray(st["expected"])
|
|
162
|
+
? st["expected"]
|
|
163
|
+
: {};
|
|
164
|
+
const outputNodes = typeof params["output_nodes"] === "object" &&
|
|
165
|
+
params["output_nodes"] !== null &&
|
|
166
|
+
!Array.isArray(params["output_nodes"])
|
|
167
|
+
? params["output_nodes"]
|
|
168
|
+
: {};
|
|
169
|
+
const inputNames = {};
|
|
170
|
+
const inputs = st["inputs"];
|
|
171
|
+
if (typeof inputs === "object" && inputs !== null && !Array.isArray(inputs)) {
|
|
172
|
+
for (const [name, ref] of Object.entries(inputs)) {
|
|
173
|
+
const rr = ref;
|
|
174
|
+
if (typeof rr === "object" && rr !== null && !Array.isArray(rr) &&
|
|
175
|
+
typeof rr["stage"] === "string" && typeof rr["output"] === "string") {
|
|
176
|
+
inputNames[name] = String(rr["stage"]) + "." + String(rr["output"]);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// the binding wall above already refused every entry that
|
|
180
|
+
// is neither {stage, output} nor {initial} — reaching the
|
|
181
|
+
// else means the {initial} shape, no re-test needed
|
|
182
|
+
inputNames[name] = "__initial__." + String(rr["initial"]);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// $spell in params resolves against EXACTLY this inputNames map
|
|
188
|
+
// at the merge (rewriteSpells) — a spell naming no wired input
|
|
189
|
+
|
|
190
|
+
// $image1'. THE DOOR COVERS WHAT THE RUN WILL DO: refuse here,
|
|
191
|
+
// in the door's voice, naming the spell and the fix.
|
|
192
|
+
const ghosts = [];
|
|
193
|
+
const sweep = (v) => {
|
|
194
|
+
if (typeof v === "string") {
|
|
195
|
+
if (v.startsWith("$") && !(v.slice(1) in inputNames))
|
|
196
|
+
ghosts.push(v);
|
|
197
|
+
}
|
|
198
|
+
else if (Array.isArray(v)) {
|
|
199
|
+
for (const x of v)
|
|
200
|
+
sweep(x);
|
|
201
|
+
}
|
|
202
|
+
else if (typeof v === "object" && v !== null) {
|
|
203
|
+
for (const x of Object.values(v))
|
|
204
|
+
sweep(x);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
sweep(params);
|
|
208
|
+
if (ghosts.length > 0) {
|
|
209
|
+
return refusal(400, "flow_inline stage " +
|
|
210
|
+
JSON.stringify(sid) +
|
|
211
|
+
": params carry " +
|
|
212
|
+
JSON.stringify([...new Set(ghosts)].sort()) +
|
|
213
|
+
" but the stage wires no input of that name — the merge would refuse it at run time ('$name' must name a FromStage-wired input or a request initial; name it or wire it)", "invalid_request");
|
|
214
|
+
}
|
|
215
|
+
stages.push({ id: sid, engine, params, outputs, expected, outputNodes, inputNames });
|
|
216
|
+
}
|
|
217
|
+
return { stages };
|
|
218
|
+
}
|
|
219
|
+
/** The door-selection gate: exactly one of flow / flow_inline /
|
|
220
|
+
* model, in DOOR order for the ambiguity text (resolve_request
|
|
221
|
+
* 302). Returns the selected door key, or the refusal. */
|
|
222
|
+
export function selectSubmitDoor(body) {
|
|
223
|
+
const doors = ["flow", "flow_inline", "model"].filter((k) => k in body);
|
|
224
|
+
if (doors.length > 1) {
|
|
225
|
+
return refusal(400, "ambiguous request: names " +
|
|
226
|
+
JSON.stringify(doors) +
|
|
227
|
+
" — provide exactly one of flow, flow_inline, model", "invalid_request");
|
|
228
|
+
}
|
|
229
|
+
if (doors.length === 0) {
|
|
230
|
+
return refusal(400, "no flow selected: provide flow, flow_inline or model", "invalid_request");
|
|
231
|
+
}
|
|
232
|
+
return { door: doors[0] };
|
|
233
|
+
}
|
|
234
|
+
/** The envelope refusal texts (door-verbatim, for the remote's
|
|
235
|
+
* envelope walk). Kept as a table — one voice each, like the
|
|
236
|
+
* admission gate's static tables. */
|
|
237
|
+
export function envelopeRefusal(kind, doc, detail) {
|
|
238
|
+
switch (kind) {
|
|
239
|
+
case "not-object":
|
|
240
|
+
return refusal(400, "request body must be a JSON object", "bad_envelope", "body", "object", Array.isArray(doc) ? "array" : typeof doc);
|
|
241
|
+
case "bad-test":
|
|
242
|
+
return refusal(400, "test flag must be a boolean (got " +
|
|
243
|
+
(typeof detail?.testFlag) +
|
|
244
|
+
" " +
|
|
245
|
+
JSON.stringify(detail?.testFlag) +
|
|
246
|
+
")", "bad_envelope", "test", "boolean", (typeof detail?.testFlag));
|
|
247
|
+
case "missing-draft":
|
|
248
|
+
return refusal(400, "draft_id is required — every run is born from an " +
|
|
249
|
+
"action card (CARD BIRTH LAW); compose the card first: " +
|
|
250
|
+
"POST /v1/flows/drafts, then start with its draft_id", "draft_required", "draft_id", "doc-backed draft id", "absent");
|
|
251
|
+
case "malformed-draft":
|
|
252
|
+
return refusal(400, "draft_id malformed (96 char cap, [A-Za-z0-9_-] only): " +
|
|
253
|
+
JSON.stringify(detail?.draftId ?? ""), "draft_malformed", "draft_id", "[A-Za-z0-9_-]{1,96}", (detail?.draftId ?? "").slice(0, 60));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/** The unknown-draft refusal (door-verbatim; the probe rides the
|
|
257
|
+
* caller's drafts domain — the remote hops the ctx seat). */
|
|
258
|
+
export function unknownDraftRefusal(draftId) {
|
|
259
|
+
return refusal(400, "unknown draft_id " +
|
|
260
|
+
JSON.stringify(draftId) +
|
|
261
|
+
" — no card doc at drafts/" +
|
|
262
|
+
draftId +
|
|
263
|
+
".json; compose the card first: POST /v1/flows/drafts", "draft_unknown", "draft_id", "existing card doc", draftId.slice(0, 60));
|
|
264
|
+
}
|
|
265
|
+
/** The registration tail (door-verbatim): mint the id, route the
|
|
266
|
+
* out root on the test flag, build the rich run row. The caller
|
|
267
|
+
* (the remote) enqueues it on the queue core + kicks the pump.
|
|
268
|
+
* Returns the row and its queue position. */
|
|
269
|
+
export async function registerCompiledRun(args) {
|
|
270
|
+
const { compiled, testFlag, draftId, stateRoot, enqueue, door } = args;
|
|
271
|
+
// THE ONE RUN ID (see the type above): the caller's. There is no
|
|
272
|
+
// second producer here, and there cannot be one without failing the
|
|
273
|
+
// compiler.
|
|
274
|
+
const runId = door.runId;
|
|
275
|
+
|
|
276
|
+
// compiled stage's params are swept for source pointers BEFORE the
|
|
277
|
+
// run dir exists — a dead source refuses here with its URL named,
|
|
278
|
+
// never mid-render, and nothing registers. The roots are the
|
|
279
|
+
// manifest (own root first — the media server's own walk); tails
|
|
280
|
+
// fall through to the lane cwd, the stager's own order. The run's
|
|
281
|
+
// own id is exempt (the compose writes its future output path
|
|
282
|
+
// into the graph — a forward reference, not a source).
|
|
283
|
+
const roots = rootsManifest(stateRoot);
|
|
284
|
+
let sources;
|
|
285
|
+
try {
|
|
286
|
+
sources = resolveSourceRefs(collectSourceRefs(compiled.stages.map((s) => s.params)), roots, process.cwd(), runId);
|
|
287
|
+
}
|
|
288
|
+
catch (e) {
|
|
289
|
+
return refusal(400, e.message, "invalid_request", "params");
|
|
290
|
+
}
|
|
291
|
+
const dir = join(outRootFor(stateRoot, testFlag), runId);
|
|
292
|
+
mkdirSync(dir, { recursive: true });
|
|
293
|
+
|
|
294
|
+
// compiled stage rides the run row — one GraphRow + one RunStageRow +
|
|
295
|
+
// one params/outputNodes slot each, input_names carrying the
|
|
296
|
+
// cross-stage wiring the merged walk consumes. The single-stage
|
|
297
|
+
// shape is the N=1 case of this SAME loop (byte-identical row for
|
|
298
|
+
// the one-stage docs the gateway served before).
|
|
299
|
+
const createdAt = Date.now() / 1000;
|
|
300
|
+
const graphRows = compiled.stages.map((st) => ({
|
|
301
|
+
id: st.id,
|
|
302
|
+
type: st.engine,
|
|
303
|
+
input_from: [],
|
|
304
|
+
input_names: { ...st.inputNames },
|
|
305
|
+
outputs: { ...st.outputs },
|
|
306
|
+
params: { ...st.params },
|
|
307
|
+
}));
|
|
308
|
+
const run = {
|
|
309
|
+
runId,
|
|
310
|
+
status: "queued",
|
|
311
|
+
stages: compiled.stages.map((st, i) => ({
|
|
312
|
+
id: st.id,
|
|
313
|
+
name: st.id,
|
|
314
|
+
index: i,
|
|
315
|
+
status: "pending",
|
|
316
|
+
engine: st.engine,
|
|
317
|
+
outputs: { ...st.outputs },
|
|
318
|
+
expected: { ...st.expected },
|
|
319
|
+
})),
|
|
320
|
+
skippedStages: [],
|
|
321
|
+
artifacts: [],
|
|
322
|
+
error: "",
|
|
323
|
+
draftId,
|
|
324
|
+
dir,
|
|
325
|
+
testFlag,
|
|
326
|
+
stopFlag: false,
|
|
327
|
+
params: compiled.stages.map((st) => ({ ...st.params })),
|
|
328
|
+
createdAt,
|
|
329
|
+
pipeline: "flow_inline",
|
|
330
|
+
graphRows,
|
|
331
|
+
outputNodes: compiled.stages.map((st) => ({ ...st.outputNodes })),
|
|
332
|
+
initials: { ...door.initials },
|
|
333
|
+
};
|
|
334
|
+
run.inputNames = Object.fromEntries(compiled.stages.map((st) => [st.id, { ...st.inputNames }]));
|
|
335
|
+
if (args.warnings !== undefined && args.warnings.length > 0) {
|
|
336
|
+
run.warnings = [...args.warnings];
|
|
337
|
+
}
|
|
338
|
+
// THE DOOR IS REQUIRED (the run id is read from it above) — the
|
|
339
|
+
// door-undefined guards and the `?.`/`??` vestiges of the old
|
|
340
|
+
// optional door were dead legs, pruned with the door law. (The
|
|
341
|
+
// re-audit caught three survivors this comment once overclaimed
|
|
342
|
+
// as gone — the benchDoc gate, the benchRec read, and the
|
|
343
|
+
|
|
344
|
+
run.pipeline = door.pipeline;
|
|
345
|
+
if (door.cardId !== undefined)
|
|
346
|
+
run.cardId = door.cardId;
|
|
347
|
+
// THE CARD SNAPSHOT LAW (stroke 45, the operator's wand complaint):
|
|
348
|
+
// _flow.json's stage faces are HOLLOW (ids/status only) — the card
|
|
349
|
+
// + params that actually ran were recorded nowhere, so "restore the
|
|
350
|
+
// workflow that made this image" could only re-read the MUTABLE
|
|
351
|
+
// bench draft and serve whatever it holds NOW. The card arm knows
|
|
352
|
+
// the exact card + body here; they ride the sidecar verbatim. The
|
|
353
|
+
// wand reconstructs from THIS, never from the living bench.
|
|
354
|
+
// THE SNAPSHOT IS NOT THE CARD ARM'S PRIVILEGE (the adversarial
|
|
355
|
+
|
|
356
|
+
// `cardId !== undefined`, which a BENCH-COMPOSED run never sets —
|
|
357
|
+
// so Run ALL registered a run with no snapshot at all, and the
|
|
358
|
+
// wand's "restore the workflow that made this" fell back to the
|
|
359
|
+
// LIVE bench draft, which is exactly the staleness this law was
|
|
360
|
+
// built to kill. The card identity and the bench identity are
|
|
361
|
+
// separate facts and each rides when it exists.
|
|
362
|
+
if (door.cardId !== undefined) {
|
|
363
|
+
run.cardSnapshot = {
|
|
364
|
+
card: door.cardId,
|
|
365
|
+
params: door.requestBody,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
if (door.benchDoc !== undefined) {
|
|
369
|
+
const benchStages = Array.isArray(door.benchDoc["stages"])
|
|
370
|
+
? door.benchDoc["stages"]
|
|
371
|
+
: undefined;
|
|
372
|
+
if (benchStages !== undefined && benchStages.length > 0) {
|
|
373
|
+
|
|
374
|
+
// finding): card-mode runs MINT their bench (the CARD BIRTH
|
|
375
|
+
// law wants a doc-backed draft) while a studio user HAND-
|
|
376
|
+
// COMPOSES one through melite_construct — and the snapshot
|
|
377
|
+
// alone could not tell them apart. The bench's OWN log head
|
|
378
|
+
// can: its author + kind say who wrote the bench the run was
|
|
379
|
+
// born from, verbatim from the domain row (never a synthesized
|
|
380
|
+
// label, never a guess — absent log, the key rides undefined
|
|
381
|
+
// and the snapshot says only what was provably read).
|
|
382
|
+
const benchLog = door.benchDoc?.["log"];
|
|
383
|
+
const head = Array.isArray(benchLog) && benchLog.length > 0 &&
|
|
384
|
+
typeof benchLog[0] === "object" && benchLog[0] !== null &&
|
|
385
|
+
!Array.isArray(benchLog[0])
|
|
386
|
+
? { ...benchLog[0] }
|
|
387
|
+
: undefined;
|
|
388
|
+
|
|
389
|
+
// "the saving should 100% be a schemamaster contract, that
|
|
390
|
+
// way we know 100% if it will load again"): the writer stamps
|
|
391
|
+
// bench_snapshot THROUGH the shared contract in
|
|
392
|
+
// @melite/contracts/benchSnapshot, never raw — run memory and
|
|
393
|
+
// the era's self-naming model strip AT SAVE, provenance rides
|
|
394
|
+
// 'restored' (the admission repair law's coordinate), and a
|
|
395
|
+
// row that cannot load is DROPPED with a warning on the
|
|
396
|
+
// sidecar (visible loss, never persisted-unloadable). The
|
|
397
|
+
// guarantee is exact: everything saved under the contract
|
|
398
|
+
// parses on the load side.
|
|
399
|
+
const contracted = saveBenchSnapshotStages(benchStages);
|
|
400
|
+
if (contracted.warnings.length > 0) {
|
|
401
|
+
run.warnings = [
|
|
402
|
+
...(run.warnings ?? []),
|
|
403
|
+
...contracted.warnings.map((w) => `bench snapshot: ${w}`),
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
if (contracted.stages.length > 0) {
|
|
407
|
+
run.benchSnapshot = {
|
|
408
|
+
stages: contracted.stages,
|
|
409
|
+
intent: typeof door.benchDoc?.["intent"] === "string"
|
|
410
|
+
? door.benchDoc?.["intent"]
|
|
411
|
+
: "",
|
|
412
|
+
...(head !== undefined ? { bench_head: head } : {}),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
// R3 durable queue (submit 1317-1351): the request rides
|
|
418
|
+
// _request.json, the compiled document rides _flow.json,
|
|
419
|
+
// and run.queued in the ledger is what a restart reconciles
|
|
420
|
+
// against. The card door passes its body — coerced through the
|
|
421
|
+
// snapshot-coercion law at the door (declared numerics restored,
|
|
422
|
+
// BRIEF14 finding #2: the sidecar proves type integrity, the
|
|
423
|
+
// seam/structure evidence rides unchanged); the inline door passes
|
|
424
|
+
// the envelope's flow_inline doc below (same writes, same order).
|
|
425
|
+
const requestBody = door.requestBody;
|
|
426
|
+
|
|
427
|
+
// operator pressed carried, the engine received cut, and the run
|
|
428
|
+
// left NO voice saying which — the film was 15 minutes of the
|
|
429
|
+
// wrong seam and the post-mortem could only infer). Computed BEFORE
|
|
430
|
+
// the durable writes, stamped ON them: the run record + the console
|
|
431
|
+
// + the ledger row name the doc revision the compose read and the
|
|
432
|
+
// seam values the engine actually received. "What did ComfyUI get?"
|
|
433
|
+
// is one grep away, forever, on every run — the read-side half of
|
|
434
|
+
// the law (the write-side half is the client's run gate: the engine
|
|
435
|
+
// never composes from a doc the press has not confirmed).
|
|
436
|
+
const bodyRec = requestBody;
|
|
437
|
+
const echoCalls = Array.isArray(bodyRec?.["calls"])
|
|
438
|
+
? bodyRec["calls"]
|
|
439
|
+
: [];
|
|
440
|
+
const benchRec = door.benchDoc;
|
|
441
|
+
const benchRev = typeof benchRec?.bench?.rev === "number" ? benchRec.bench.rev : null;
|
|
442
|
+
if (echoCalls.length > 0) {
|
|
443
|
+
const seam = echoCalls
|
|
444
|
+
.map((c) => (typeof c["transition"] === "string" ? c["transition"] : "carry"))
|
|
445
|
+
.join(",");
|
|
446
|
+
run.composeEcho = { seam, calls: echoCalls.length, benchRev };
|
|
447
|
+
console.log(`[compose] run=${runId} draft=${draftId} calls=${echoCalls.length} seam=${seam} bench_rev=${benchRev ?? "?"}`);
|
|
448
|
+
}
|
|
449
|
+
// THE SOURCE ECHO STAMP (the same law, source-side): the resolved
|
|
450
|
+
// files ride the record, the console, and the ledger row — "what
|
|
451
|
+
// created this run" is one grep away, forever. Sourceless runs
|
|
452
|
+
// stamp nothing.
|
|
453
|
+
if (sources.length > 0) {
|
|
454
|
+
run.sourceEcho = { refs: sources.map((s) => ({ url: s.url, file: s.file })) };
|
|
455
|
+
console.log(`[sources] run=${runId} draft=${draftId} refs=${sources.length} ${sources.map((s) => s.url).join(",")}`);
|
|
456
|
+
}
|
|
457
|
+
// THE VARIANT STAMP (commission 033's self-critique #5,
|
|
458
|
+
|
|
459
|
+
// customvoice) names itself at BIRTH — the 033 ledger read
|
|
460
|
+
// pipeline qwen3-tts-voicedesign on both a design run and a
|
|
461
|
+
// performing run, indistinguishable. run.params first, the exact
|
|
462
|
+
// submitted body (card snapshot / request body) as fallback —
|
|
463
|
+
// the export-name stamp's 024 lesson. Variant-less runs stamp
|
|
464
|
+
// nothing (the lift returns undefined; absent, never guessed).
|
|
465
|
+
const regVariant = variantOfBodies([...run.params, door.requestBody]);
|
|
466
|
+
if (regVariant !== undefined) {
|
|
467
|
+
run.variant = regVariant;
|
|
468
|
+
console.log(`[variant] run=${runId} draft=${draftId} variant=${regVariant}`);
|
|
469
|
+
}
|
|
470
|
+
await writeJsonAtomic(join(dir, "_request.json"), requestBody);
|
|
471
|
+
await writeJsonAtomic(join(dir, "_flow.json"), sidecarDocFor(run));
|
|
472
|
+
if (echoCalls.length > 0) {
|
|
473
|
+
appendLedger(stateRoot, "run.queued", {
|
|
474
|
+
run_id: runId,
|
|
475
|
+
draft_id: draftId,
|
|
476
|
+
pipeline: run.pipeline,
|
|
477
|
+
...(regVariant !== undefined ? { variant: regVariant } : {}),
|
|
478
|
+
seam: run.composeEcho?.seam,
|
|
479
|
+
calls: echoCalls.length,
|
|
480
|
+
bench_rev: benchRev,
|
|
481
|
+
sources: sources.length,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
appendLedger(stateRoot, "run.queued", {
|
|
486
|
+
run_id: runId,
|
|
487
|
+
draft_id: draftId,
|
|
488
|
+
pipeline: run.pipeline,
|
|
489
|
+
...(regVariant !== undefined ? { variant: regVariant } : {}),
|
|
490
|
+
sources: sources.length,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
const queuePosition = enqueue(run);
|
|
494
|
+
return { run, queuePosition };
|
|
495
|
+
}
|
|
496
|
+
/** The queued sidecar doc for a registered run (the queue.ts
|
|
497
|
+
* sidecarDoc over the row's live stage faces — the same writer
|
|
498
|
+
* the settle path rides). */
|
|
499
|
+
function sidecarDocFor(run) {
|
|
500
|
+
return sidecarDoc({
|
|
501
|
+
runId: run.runId,
|
|
502
|
+
status: "queued",
|
|
503
|
+
error: "",
|
|
504
|
+
stages: run.stages.map((s) => sidecarStageOf(s)),
|
|
505
|
+
skippedStages: [],
|
|
506
|
+
artifacts: [],
|
|
507
|
+
createdAt: run.createdAt,
|
|
508
|
+
testFlag: run.testFlag,
|
|
509
|
+
draftId: run.draftId,
|
|
510
|
+
pipeline: run.pipeline,
|
|
511
|
+
graph: run.graphRows,
|
|
512
|
+
cardSnapshot: run.cardSnapshot,
|
|
513
|
+
benchSnapshot: run.benchSnapshot,
|
|
514
|
+
// F-6(b): admission warnings ride the queued sidecar (disk
|
|
515
|
+
// rows carry them after a reload).
|
|
516
|
+
warnings: run.warnings,
|
|
517
|
+
// THE COMPOSE ECHO: what the engine received rides the queued
|
|
518
|
+
// sidecar too (the wand/restore reads disk, not memory).
|
|
519
|
+
composeEcho: run.composeEcho,
|
|
520
|
+
// THE SOURCE ECHO: the files that created the run ride the
|
|
521
|
+
// queued sidecar too.
|
|
522
|
+
sourceEcho: run.sourceEcho,
|
|
523
|
+
// THE VARIANT: the lane rides the queued sidecar too (the
|
|
524
|
+
// wand/restore reads disk, not memory).
|
|
525
|
+
variant: run.variant,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
//# sourceMappingURL=runsStart.js.map
|