@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.
Files changed (131) hide show
  1. package/LICENSE +557 -0
  2. package/README.md +54 -2
  3. package/lib/bakeParams.d.ts +17 -0
  4. package/lib/bakeParams.js +182 -0
  5. package/lib/bench.d.ts +32 -0
  6. package/lib/bench.js +111 -0
  7. package/lib/cardsArmError.d.ts +61 -0
  8. package/lib/cardsArmError.js +57 -0
  9. package/lib/cardsCompose.d.ts +53 -0
  10. package/lib/cardsCompose.js +295 -0
  11. package/lib/cardsDangling.d.ts +16 -0
  12. package/lib/cardsDangling.js +213 -0
  13. package/lib/cardsFacts.d.ts +87 -0
  14. package/lib/cardsFacts.js +78 -0
  15. package/lib/cardsLanes.d.ts +43 -0
  16. package/lib/cardsLanes.js +178 -0
  17. package/lib/cardsRegistry.d.ts +404 -0
  18. package/lib/cardsRegistry.js +1543 -0
  19. package/lib/cardsVariant.d.ts +37 -0
  20. package/lib/cardsVariant.js +243 -0
  21. package/lib/discloseRegistry.d.ts +95 -0
  22. package/lib/discloseRegistry.js +156 -0
  23. package/lib/filmLead.d.ts +4 -0
  24. package/lib/filmLead.js +17 -0
  25. package/lib/filmMemoryWarn.d.ts +27 -0
  26. package/lib/filmMemoryWarn.js +99 -0
  27. package/lib/flowsData.d.ts +234 -0
  28. package/lib/flowsData.js +673 -0
  29. package/lib/flowsFamilyCompose.d.ts +45 -0
  30. package/lib/flowsFamilyCompose.js +191 -0
  31. package/lib/flowsParamsOverlay.d.ts +55 -0
  32. package/lib/flowsParamsOverlay.js +197 -0
  33. package/lib/flowsRegistryRows.d.ts +12 -0
  34. package/lib/flowsRegistryRows.js +520 -0
  35. package/lib/index.d.ts +47 -0
  36. package/lib/index.js +75 -0
  37. package/lib/ledgerTail.d.ts +20 -0
  38. package/lib/ledgerTail.js +123 -0
  39. package/lib/lifecycleLatch.d.ts +16 -0
  40. package/lib/lifecycleLatch.js +42 -0
  41. package/lib/loadPlane.d.ts +94 -0
  42. package/lib/loadPlane.js +570 -0
  43. package/lib/loadRegistry.d.ts +22 -0
  44. package/lib/loadRegistry.js +55 -0
  45. package/lib/manageOps.d.ts +27 -0
  46. package/lib/manageOps.js +162 -0
  47. package/lib/managePlane.d.ts +151 -0
  48. package/lib/managePlane.js +1790 -0
  49. package/lib/manageProbe.d.ts +48 -0
  50. package/lib/manageProbe.js +165 -0
  51. package/lib/manageRegistry.d.ts +66 -0
  52. package/lib/manageRegistry.js +113 -0
  53. package/lib/managerRail.d.ts +33 -0
  54. package/lib/managerRail.js +91 -0
  55. package/lib/mediaKinds.d.ts +3 -0
  56. package/lib/mediaKinds.js +2 -0
  57. package/lib/queue.d.ts +9 -0
  58. package/lib/queue.js +80 -0
  59. package/lib/queueCore.d.ts +72 -0
  60. package/lib/queueCore.js +128 -0
  61. package/lib/queueLifecycle.d.ts +2 -0
  62. package/lib/queueLifecycle.js +11 -0
  63. package/lib/queueLock.d.ts +60 -0
  64. package/lib/queueLock.js +198 -0
  65. package/lib/queueResurrect.d.ts +59 -0
  66. package/lib/queueResurrect.js +249 -0
  67. package/lib/queueRetry.d.ts +36 -0
  68. package/lib/queueRetry.js +24 -0
  69. package/lib/queueSidecar.d.ts +149 -0
  70. package/lib/queueSidecar.js +183 -0
  71. package/lib/queueSubmit.d.ts +82 -0
  72. package/lib/queueSubmit.js +191 -0
  73. package/lib/queueSweep.d.ts +30 -0
  74. package/lib/queueSweep.js +132 -0
  75. package/lib/resurrect.d.ts +6 -0
  76. package/lib/resurrect.js +18 -0
  77. package/lib/rootsManifest.d.ts +11 -0
  78. package/lib/rootsManifest.js +11 -0
  79. package/lib/runsChange.d.ts +61 -0
  80. package/lib/runsChange.js +79 -0
  81. package/lib/runsErrorCodes.d.ts +2 -0
  82. package/lib/runsErrorCodes.js +48 -0
  83. package/lib/runsExecute.d.ts +52 -0
  84. package/lib/runsExecute.js +494 -0
  85. package/lib/runsGates.d.ts +161 -0
  86. package/lib/runsGates.js +307 -0
  87. package/lib/runsList.d.ts +78 -0
  88. package/lib/runsList.js +574 -0
  89. package/lib/runsRefusalVoices.d.ts +9 -0
  90. package/lib/runsRefusalVoices.js +96 -0
  91. package/lib/runsRegistry.d.ts +351 -0
  92. package/lib/runsRegistry.js +2394 -0
  93. package/lib/runsSourceEcho.d.ts +81 -0
  94. package/lib/runsSourceEcho.js +341 -0
  95. package/lib/runsStart.d.ts +163 -0
  96. package/lib/runsStart.js +667 -0
  97. package/lib/runsTypes.d.ts +218 -0
  98. package/lib/runsTypes.js +289 -0
  99. package/lib/runsValidate.d.ts +5 -0
  100. package/lib/runsValidate.js +31 -0
  101. package/lib/runsValidateArms.d.ts +7 -0
  102. package/lib/runsValidateArms.js +339 -0
  103. package/lib/runsValidateInline.d.ts +6 -0
  104. package/lib/runsValidateInline.js +82 -0
  105. package/lib/runsValidateRefusals.d.ts +7 -0
  106. package/lib/runsValidateRefusals.js +18 -0
  107. package/lib/runsValidateServe.d.ts +15 -0
  108. package/lib/runsValidateServe.js +276 -0
  109. package/lib/runsValidateShared.d.ts +84 -0
  110. package/lib/runsValidateShared.js +88 -0
  111. package/lib/runsValidateStages.d.ts +32 -0
  112. package/lib/runsValidateStages.js +511 -0
  113. package/lib/runsValidateSweeps.d.ts +6 -0
  114. package/lib/runsValidateSweeps.js +143 -0
  115. package/lib/service.d.ts +63 -0
  116. package/lib/service.js +89 -0
  117. package/lib/skillFrontmatter.d.ts +11 -0
  118. package/lib/skillFrontmatter.js +46 -0
  119. package/lib/skillFs.d.ts +24 -0
  120. package/lib/skillFs.js +78 -0
  121. package/lib/skillPlane.d.ts +99 -0
  122. package/lib/skillPlane.js +269 -0
  123. package/lib/skillRegistry.d.ts +23 -0
  124. package/lib/skillRegistry.js +55 -0
  125. package/lib/skillRows.d.ts +127 -0
  126. package/lib/skillRows.js +468 -0
  127. package/lib/toolProjection.d.ts +30 -0
  128. package/lib/toolProjection.js +142 -0
  129. package/lib/vocab.d.ts +6 -0
  130. package/lib/vocab.js +18 -0
  131. package/package.json +48 -4
@@ -0,0 +1,45 @@
1
+ import type { RegistryFlow } from "./flowsData.js";
2
+ /** The families seat's read shape (structural — the models
3
+ * service's allDecls() rows, action arrays intact). */
4
+ export type FamilyDeclRow = {
5
+ readonly id: string;
6
+ };
7
+ export type FamilyModelsSeat = {
8
+ allDecls(): readonly FamilyDeclRow[];
9
+ };
10
+ /** How the family seat answered, which is three different facts:
11
+ * `seated` (the table holds families), `bare` (the owner is mounted
12
+ * and the table holds none — a lane that mounted the catalog
13
+ * provider without the family plugins), and `absent` (no seat at
14
+ * all: an unmounted context whose singleton never booted). The
15
+ * refusal must name which one it is — a family that is merely
16
+ * unregistered is a different defect from a lane with no table.
17
+ * A flow with NO family stage never reads this. */
18
+ export type FamilySeatState = "seated" | "bare" | "absent";
19
+ /** The live family declarations, and how the seat answered. A flow
20
+ * WITH a family stage refuses LOUD on an unanswering seat inside
21
+ * composeOne, in the seat's own voice.
22
+ * @param modelsSeat the context's models service when mounted
23
+ * (the injectable read); the booted singleton otherwise
24
+ * @returns the declarations (empty on an unanswering seat) and the
25
+ * state that produced them */
26
+ export declare function liveFamilySeat(modelsSeat?: FamilyModelsSeat | null): {
27
+ readonly decls: readonly FamilyDeclRow[];
28
+ readonly state: FamilySeatState;
29
+ };
30
+ /** Compose every family-action stage of an expanded flow into its
31
+ * workflow envelope. Flows with no family stage pass through
32
+ * byte-identical (zero lookups, zero overhead).
33
+ * @param flow the EXPANDED registry flow (fromFlow links resolved)
34
+ * @param decls the families seat's declarations (allDecls())
35
+ * @param seatState how the seat answered, so a refusal names the
36
+ * condition it found (see {@link liveFamilySeat}) — REQUIRED, no
37
+ * default (round-23 audit Q4): a caller that assumes "seated" on an
38
+ * unbooted lane gets the unregistered-family voice for an
39
+ * environment fact, the exact collapse the seat-voice law forbids
40
+ * @returns the flow with every family stage composed
41
+ * @throws when the seat cannot answer, a family is unregistered, an
42
+ * action undeclared, a param unadmitted, or a hand-written output
43
+ * contradicts the action's declaration */
44
+ export declare function composeFamilyStages(flow: RegistryFlow, decls: readonly FamilyDeclRow[], seatState: FamilySeatState): RegistryFlow;
45
+ //# sourceMappingURL=flowsFamilyCompose.d.ts.map
@@ -0,0 +1,191 @@
1
+ // flowsFamilyCompose.ts — the family-action stage interpreter (the
2
+ // atom vocabulary, stroke 4 — the flow plane's estimator half). A
3
+ // registry stage that names a FAMILY plus one of its declared
4
+ // actions composes HERE, at expansion time: the flow row owns
5
+ // routing only, the family's DECL owns the nodes — the same
6
+ // hierarchy a card stage rides (the card dispatches
7
+ // ACTION_BINDINGS; the flow dispatches family+action directly, no
8
+ // card face — the SubActionMod law: a verb's knobs never join any
9
+ // card schema; they ride the family's own action declaration).
10
+ //
11
+ // WIRE PARITY: the composed stage lands as the exact envelope a
12
+ // raw `workflow:` stage landed — params.workflow carries the
13
+ // serialized graph, $-refs ride verbatim (the inline compile and
14
+ // the merged worker own their resolution, exactly as for raw
15
+ // graphs), outputs derive from the ACTION's declared outputs (the
16
+ // derivation law: the row never hand-mirrors what the declaration
17
+ // already owns; a contradicting hand-write refuses LOUD).
18
+ import { declaredAction, instantiateAction } from "@melite/comfyui-card-kit";
19
+ import { GraphBuilder } from "@melite/comfyui-card-kit/graph";
20
+ import { modelsService } from "@melite/comfyui-cordis";
21
+ /** The live family declarations, and how the seat answered. A flow
22
+ * WITH a family stage refuses LOUD on an unanswering seat inside
23
+ * composeOne, in the seat's own voice.
24
+ * @param modelsSeat the context's models service when mounted
25
+ * (the injectable read); the booted singleton otherwise
26
+ * @returns the declarations (empty on an unanswering seat) and the
27
+ * state that produced them */
28
+ export function liveFamilySeat(modelsSeat) {
29
+ if (modelsSeat !== undefined && modelsSeat !== null) {
30
+ const decls = modelsSeat.allDecls();
31
+ return { decls, state: decls.length === 0 ? "bare" : "seated" };
32
+ }
33
+ try {
34
+ const decls = modelsService().allDecls();
35
+ return { decls, state: decls.length === 0 ? "bare" : "seated" };
36
+ }
37
+ catch {
38
+ return { decls: [], state: "absent" };
39
+ }
40
+ }
41
+ /** One family stage's resolved form: the workflow envelope plus the
42
+ * derived outputs. The row itself = not a family stage (passthrough;
43
+ * round-23 audit Q3 — the return is non-nullable, the early return
44
+ * hands back the row). */
45
+ function composeOne(flowId, st, decls, seatState) {
46
+ if (st.family === "")
47
+ return st;
48
+ // Either/or is the row contract (flowsData's RegistryStage): a
49
+ // stage naming BOTH would compose a graph the card gate then
50
+ // judges — refuse the contradiction at admission.
51
+ if (st.card !== "") {
52
+ throw new Error("flow '" + flowId + "' stage '" + st.id + "' names card '" + st.card +
53
+ "' AND family '" + st.family + "' — a stage routes through one plane, never both");
54
+ }
55
+ const decl = decls.find((d) => d.id === st.family);
56
+ if (decl === undefined) {
57
+ const registered = decls.map((d) => d.id).sort().join(", ") || "none";
58
+ const where = "flow '" + flowId + "' stage '" + st.id + "' naming family '" + st.family + "'";
59
+ // THE SEAT'S OWN VOICE PER CONDITION. An absent seat and a bare
60
+ // mount are environment facts and each has its own repair; only
61
+ // the third — a seated table without this family — is a
62
+ // registration fact. Collapsing all three into "no such family"
63
+ // named a typo where the lane had no table to ask.
64
+ if (seatState === "absent") {
65
+ throw new Error("[models] no ModelsService for " + where +
66
+ " — doors inject 'models' and pass ctx.models " +
67
+ "(the manifest's engine-model-catalog row provides at boot)");
68
+ }
69
+ if (seatState === "bare") {
70
+ throw new Error(where + " — the models seat is mounted with ZERO families " +
71
+ "(registered: none): this lane mounted the bare catalog " +
72
+ "provider without the families row, so no family can resolve");
73
+ }
74
+ throw new Error("flow '" + flowId + "' stage '" + st.id + "' names family '" + st.family +
75
+ "' — no such family in the models seat (registered: " + registered + ")");
76
+ }
77
+ let action;
78
+ try {
79
+ action = declaredAction(decl, st.action);
80
+ }
81
+ catch (e) {
82
+ // The kit's voice is card-plane ("the card's binding refused at
83
+ // boarding"); re-voice for the flow door, keeping its declared
84
+ // list in the parenthetical. (declaredAction throws Error only —
85
+ // the String arm is the never-fired defensive half.)
86
+ throw new Error("flow '" + flowId + "' stage '" + st.id + "' names action '" + st.action +
87
+ "' the family '" + st.family + "' does not declare (" +
88
+ (e instanceof Error ? e.message : /* v8 ignore next */ String(e)) + ")");
89
+ }
90
+ // LANE-INDEPENDENCE (the admission under the derivation): a flow
91
+ // row composes against the model-less facts shape, so the action
92
+ // must read nothing off a lane — a lane-bound action named by a
93
+ // flow would compose a WRONG graph silently (its facts door
94
+ // degrades or blames lane_inputs it never receives).
95
+ if (action.laneIndependent !== true) {
96
+ throw new Error("flow '" + flowId + "' stage '" + st.id + "' names action '" + st.family +
97
+ "." + st.action + "' — the action is lane-bound (its facts door reads a " +
98
+ "resolved model row); only lane-independent actions compose from a flow row");
99
+ }
100
+ // THE ADMISSION CONTRACT (the lowest level, one voice): every
101
+ // params key must be a declared action param — the same class of
102
+ // refusal the card plane speaks ("unknown param(s) on the
103
+ // image-gen card: out_dir"), fired BEFORE any node composes.
104
+ const declared = new Set(action.params.map((p) => p.name));
105
+ const unknown = Object.keys(st.params).filter((k) => !declared.has(k));
106
+ if (unknown.length > 0) {
107
+ throw new Error("unknown param(s) on the " + st.family + "." + st.action + " action: " +
108
+ unknown.sort().join(", "));
109
+ }
110
+ // THE DERIVATION LAW (roadmap §12, the family half): outputs
111
+ // derive from the action's own declaration; a hand-write that
112
+ // contradicts it refuses LOUD — never two spellings of one truth.
113
+ const derived = {};
114
+ for (const o of action.outputs)
115
+ derived[o.name] = o.kind;
116
+ for (const [name, kind] of Object.entries(st.outputs)) {
117
+ if (derived[name] !== kind) {
118
+ throw new Error("flow '" + flowId + "' stage '" + st.id + "' hand-writes output '" + name +
119
+ "' as '" + kind + "' but the " + st.family + "." + st.action +
120
+ " action declares '" + String(derived[name]) + "' — the row routes, the declaration owns the truth");
121
+ }
122
+ }
123
+ // The family's facts row for the interpreter: the estimator-class
124
+ // actions declare vacuous doors (no checkpoint, no encoder), so
125
+ // the weightless row IS the honest shape — the same field set the
126
+ // engine's own model-less compose arm passes (service.ts:941;
127
+ // round-23 audit Q5 repinned the cite) — same keys, deliberate
128
+ // value differences: id carries the family here and '' there,
129
+ // card is '' here where the engine arm carries the card id — and
130
+ // the action's facts parser is the gate, refusing nothing
131
+ // here by design.
132
+ const g = new GraphBuilder();
133
+ const handle = instantiateAction(action, st.params, {
134
+ id: st.family,
135
+ card: "",
136
+ family: st.family,
137
+ defaults: {},
138
+ lane_inputs: {},
139
+ variants: [],
140
+ variant_groups: [],
141
+ outputs: [],
142
+ mods: [],
143
+ }, g, "");
144
+ // THE PRODUCER IS THE ACTION'S OWN HANDLE (the multi-save law).
145
+ // The merge resolves a stage's channels to producer nodes two ways:
146
+ // a declared output_nodes row, or — failing that — a single Save
147
+ // node, which refuses outright when the graph saves more than once.
148
+ // An action that writes several artifacts (the turnaround sheet, the
149
+ // albedo/normal/sidecar trio) hit that refusal every time, because
150
+ // the composition declared no producer at all. The handle build()
151
+ // returns IS the producer for the action's FIRST declared output,
152
+ // named by the action's own declaration — never guessed from node
153
+ // order. The declared path wins in the merge, so single-save
154
+ // actions keep their behavior: they also declare, and declaration
155
+ // won there too.
156
+ const producer = {};
157
+ const firstOutput = action.outputs[0];
158
+ if (firstOutput !== undefined) {
159
+ producer[firstOutput.name] = handle.nodeId;
160
+ }
161
+ return {
162
+ ...st,
163
+ family: "",
164
+ action: "",
165
+ outputs: derived,
166
+ params: { workflow: g.toJSON(), output_nodes: producer },
167
+ };
168
+ }
169
+ /** Compose every family-action stage of an expanded flow into its
170
+ * workflow envelope. Flows with no family stage pass through
171
+ * byte-identical (zero lookups, zero overhead).
172
+ * @param flow the EXPANDED registry flow (fromFlow links resolved)
173
+ * @param decls the families seat's declarations (allDecls())
174
+ * @param seatState how the seat answered, so a refusal names the
175
+ * condition it found (see {@link liveFamilySeat}) — REQUIRED, no
176
+ * default (round-23 audit Q4): a caller that assumes "seated" on an
177
+ * unbooted lane gets the unregistered-family voice for an
178
+ * environment fact, the exact collapse the seat-voice law forbids
179
+ * @returns the flow with every family stage composed
180
+ * @throws when the seat cannot answer, a family is unregistered, an
181
+ * action undeclared, a param unadmitted, or a hand-written output
182
+ * contradicts the action's declaration */
183
+ export function composeFamilyStages(flow, decls, seatState) {
184
+ if (!flow.stages.some((st) => st.family !== ""))
185
+ return flow;
186
+ return {
187
+ ...flow,
188
+ stages: flow.stages.map((st) => composeOne(flow.id, st, decls, seatState)),
189
+ };
190
+ }
191
+ //# sourceMappingURL=flowsFamilyCompose.js.map
@@ -0,0 +1,55 @@
1
+ import type { CardRegistryService } from "./cardsRegistry.js";
2
+ /**
3
+ * The overlay's mod-fold scoping decision (round-22 compose audit
4
+ * Q3a): which family scopes the absorbed mod surface for a stage's
5
+ * card. The request's model seat wins outright; with no seat, the
6
+ * card's sole boarded family scopes it; a multi-family card with no
7
+ * seat stays unscoped ("" — the union, compose's own selector to
8
+ * refuse). Pure so the walls can pin the routing; the route→atom map
9
+ * itself rides the engine-fiber fold (`owningAtom`, never booted in
10
+ * the test fiber).
11
+ *
12
+ * @param boarded the card decl's boarded families
13
+ * @param fam the request's family seat ("" when none)
14
+ * @returns the scoping family, "" for unscoped
15
+ */
16
+ export declare function overlayAtomFor(boarded: readonly string[], fam: string): string;
17
+ /**
18
+ * The decls read both doors ride (round-22 compose audit Q5b,
19
+ * FLOW-DOOR-DEGRADE-OR-MAP): the registry's cardDecls() is a STRICT
20
+ * read — a missing model-facts.json throws raw (a 500 past the flow
21
+ * doors, where the {model:} door degrades by policy), because both
22
+ * overlay call sites sat outside any RemoteError mapping. The read
23
+ * rides this one mapping so both doors voice the same
24
+ * runs/invalid-request naming the missing file — never a raw
25
+ * escape, never two voices.
26
+ *
27
+ * @param cardRegistry the context's card registry seat
28
+ * @returns the declared rows, as cardDecls() serves them
29
+ * @throws runs/invalid-request (loc "params") when the strict read throws
30
+ */
31
+ export declare function overlayDecls(cardRegistry: Pick<CardRegistryService, "cardDecls">): ReturnType<CardRegistryService["cardDecls"]>;
32
+ /** THE FLOW PARAMS OVERLAY — the one law both doors ride (round-21
33
+ * flows audit F1): the request's `params` overlays the expansion's
34
+ * fresh rows. A primitive value targets the single stage whose card
35
+ * admits the key (zero: unknown-key refusal; several: ambiguous —
36
+ * the operator names the stage); an object value targets one stage
37
+ * by id, every key admitted by that stage's card. Admission reads
38
+ * the SHARED surface (knobs ∪ absorbed mod fields ∪ admits — audit
39
+ * J-E2), and every refusal is runs/invalid-request BEFORE either
40
+ * door proceeds: validate answering green while start refused 400
41
+ * was the F1 divergence. Mutates the rows in place (the expansion's
42
+ * own containers — flowsData's TEMPLATE DETACH keeps the registry's
43
+ * rows shared and untouched); the stage list is copied, never the
44
+ * rows.
45
+ *
46
+ * @param flowName the flow id, named in every refusal
47
+ * @param stages the expansion's stage rows (mutated in place)
48
+ * @param overrideRaw the request body's raw `params` value
49
+ * @param decls the card registry's declared rows (the admission read)
50
+ * @param fam the request's family seat (`body.model`, "" when the
51
+ * request names none) — scopes the absorbed mod surface to the
52
+ * owning atom, the same fold compose and variant judge with
53
+ */
54
+ export declare function applyFlowParamsOverride(flowName: string, stages: ReadonlyArray<unknown>, overrideRaw: unknown, decls: ReturnType<CardRegistryService["cardDecls"]>, fam: string): void;
55
+ //# sourceMappingURL=flowsParamsOverlay.d.ts.map
@@ -0,0 +1,197 @@
1
+ // flowsParamsOverlay.ts — the flow params overlay, the one law both
2
+ // doors ride (cut out of runsRegistry so the validate door can ride
3
+ // it without a runsRegistry cycle; round-21 flows audit F1).
4
+ import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
5
+ import { owningAtom, theService } from "@melite/comfyui-cordis";
6
+ import { cardAdmits } from "./cardsCompose.js";
7
+ /**
8
+ * The overlay's mod-fold scoping decision (round-22 compose audit
9
+ * Q3a): which family scopes the absorbed mod surface for a stage's
10
+ * card. The request's model seat wins outright; with no seat, the
11
+ * card's sole boarded family scopes it; a multi-family card with no
12
+ * seat stays unscoped ("" — the union, compose's own selector to
13
+ * refuse). Pure so the walls can pin the routing; the route→atom map
14
+ * itself rides the engine-fiber fold (`owningAtom`, never booted in
15
+ * the test fiber).
16
+ *
17
+ * @param boarded the card decl's boarded families
18
+ * @param fam the request's family seat ("" when none)
19
+ * @returns the scoping family, "" for unscoped
20
+ */
21
+ export function overlayAtomFor(boarded, fam) {
22
+ if (fam !== "")
23
+ return fam;
24
+ return boarded.length === 1 ? boarded[0] : "";
25
+ }
26
+ /**
27
+ * The decls read both doors ride (round-22 compose audit Q5b,
28
+ * FLOW-DOOR-DEGRADE-OR-MAP): the registry's cardDecls() is a STRICT
29
+ * read — a missing model-facts.json throws raw (a 500 past the flow
30
+ * doors, where the {model:} door degrades by policy), because both
31
+ * overlay call sites sat outside any RemoteError mapping. The read
32
+ * rides this one mapping so both doors voice the same
33
+ * runs/invalid-request naming the missing file — never a raw
34
+ * escape, never two voices.
35
+ *
36
+ * @param cardRegistry the context's card registry seat
37
+ * @returns the declared rows, as cardDecls() serves them
38
+ * @throws runs/invalid-request (loc "params") when the strict read throws
39
+ */
40
+ export function overlayDecls(cardRegistry) {
41
+ try {
42
+ return cardRegistry.cardDecls();
43
+ }
44
+ catch (e) {
45
+ throw new RemoteError("runs/invalid-request", "flow params overlay cannot read the card declarations — " +
46
+ (e instanceof Error ? e.message : String(e)), { loc: "params" });
47
+ }
48
+ }
49
+ /** THE FLOW PARAMS OVERLAY — the one law both doors ride (round-21
50
+ * flows audit F1): the request's `params` overlays the expansion's
51
+ * fresh rows. A primitive value targets the single stage whose card
52
+ * admits the key (zero: unknown-key refusal; several: ambiguous —
53
+ * the operator names the stage); an object value targets one stage
54
+ * by id, every key admitted by that stage's card. Admission reads
55
+ * the SHARED surface (knobs ∪ absorbed mod fields ∪ admits — audit
56
+ * J-E2), and every refusal is runs/invalid-request BEFORE either
57
+ * door proceeds: validate answering green while start refused 400
58
+ * was the F1 divergence. Mutates the rows in place (the expansion's
59
+ * own containers — flowsData's TEMPLATE DETACH keeps the registry's
60
+ * rows shared and untouched); the stage list is copied, never the
61
+ * rows.
62
+ *
63
+ * @param flowName the flow id, named in every refusal
64
+ * @param stages the expansion's stage rows (mutated in place)
65
+ * @param overrideRaw the request body's raw `params` value
66
+ * @param decls the card registry's declared rows (the admission read)
67
+ * @param fam the request's family seat (`body.model`, "" when the
68
+ * request names none) — scopes the absorbed mod surface to the
69
+ * owning atom, the same fold compose and variant judge with
70
+ */
71
+ export function applyFlowParamsOverride(flowName, stages, overrideRaw, decls, fam) {
72
+ if (typeof overrideRaw !== "object" || overrideRaw === null || Array.isArray(overrideRaw)) {
73
+ throw new RemoteError("runs/invalid-request", "flow params must be an object ({key: value} or {stage_id: {key: value}}), got " +
74
+ JSON.stringify(overrideRaw), { loc: "params" });
75
+ }
76
+ const override = overrideRaw;
77
+ const stageRows = [...stages];
78
+ const paramsOf = (row) => {
79
+ if (typeof row["params"] !== "object" || row["params"] === null || Array.isArray(row["params"])) {
80
+ row["params"] = {};
81
+ }
82
+ return row["params"];
83
+ };
84
+ // THE SHARED ADMISSION SURFACE (audit J-E2): the override door
85
+ // judges with the SAME predicate compose's admission gate judges
86
+ // with — knobs ∪ absorbed mod fields ∪ admits (wildcard rows
87
+ // included), the mod fold scoped to the row's owning atom
88
+ // (OVERLAY-ATOM-FOLD, round-22 compose audit Q3a: an unfiltered
89
+ // fold admitted a family A mod key on a run at family B — the
90
+ // overlay greened what compose refuses, two refusals for one body).
91
+ // The atom resolves from the request's model seat, falling back to
92
+ // the card's sole boarded family; a multi-family card with no seat
93
+ // keeps the union (compose resolves its own selector there, and the
94
+ // door cannot know it — the residual over-admission is compose's
95
+ // own to refuse, at the same 400 class).
96
+ const modNamesOf = (card) => {
97
+ const names = new Set();
98
+ try {
99
+ // The routing is pure (the walls pin it); the route→atom map
100
+ // rides the booted models service — "" stays unscoped.
101
+ const scoped = overlayAtomFor(decls[card]?.boarded ?? [], fam);
102
+ const envelopeAtom = scoped === "" ? "" : owningAtom(scoped);
103
+ for (const a of theService().cardModFields(card)) {
104
+ if (envelopeAtom !== "" && !a.families.includes(envelopeAtom))
105
+ continue;
106
+ for (const n of Object.keys(a.fields.dict ?? {}))
107
+ names.add(n);
108
+ }
109
+ }
110
+ catch (modFoldError) {
111
+ // modFoldError: card defs not booted in this fiber — the
112
+ // mod surface is empty here; the knobs+admits rows still
113
+ // gate (the door can only over-admit into compose's own
114
+ // refusal, never under-admit what compose takes).
115
+ }
116
+ return names;
117
+ };
118
+ const admitsParam = (row, key) => {
119
+ const card = typeof row["card"] === "string" ? row["card"] : "";
120
+ return cardAdmits(decls[card], modNamesOf(card), key);
121
+ };
122
+ // THE FAMILY ROWS TAKE NO PARAMS (round-23 audit Q2): a family
123
+ // stage carries card "" (the either/or row contract), so no decl
124
+ // admits anything for it and the generic voice indicted a card ""
125
+ // the request never spelled. The verb's own params are not
126
+ // per-press tunable (every live family flow declares tool: null),
127
+ // so the honest answer is a named refusal, not a dead admission
128
+ // path.
129
+ const familyRows = stageRows.filter((r) => r["card"] === "" &&
130
+ typeof r["family"] === "string" && r["family"] !== "");
131
+ const familyTag = () => familyRows
132
+ .map((r) => JSON.stringify(r["id"]) + " (" + JSON.stringify(r["family"]) + "." + JSON.stringify(r["action"] ?? "") + ")")
133
+ .join(", ");
134
+ // the refusal message names the SHARED surface (knobs ride it
135
+ // since J-E2 — the admits row alone would understate it)
136
+ const admitOf = (row) => {
137
+ const card = typeof row["card"] === "string" ? row["card"] : "";
138
+ const decl = decls[card];
139
+ return [
140
+ ...new Set([
141
+ ...(decl?.schemaNames ?? []),
142
+ ...modNamesOf(card),
143
+ ...(decl?.admits ?? []),
144
+ ]),
145
+ ];
146
+ };
147
+ for (const [key, value] of Object.entries(override)) {
148
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
149
+ // THE STAGE-TARGETED SHAPE: the key names a stage, the
150
+ // object rides that stage's params verbatim-overlaid.
151
+ const target = stageRows.find((r) => r["id"] === key);
152
+ if (target === undefined) {
153
+ throw new RemoteError("runs/invalid-request", "flow params stage " + JSON.stringify(key) +
154
+ " names no stage of flow " + flowName +
155
+ " (stages: " + stageRows.map((r) => JSON.stringify(r["id"])).join(", ") + ")", { loc: "params" });
156
+ }
157
+ if (target["card"] === "" &&
158
+ typeof target["family"] === "string" && target["family"] !== "") {
159
+ throw new RemoteError("runs/invalid-request", "stage " + JSON.stringify(key) + " of flow " + flowName +
160
+ " is a family stage (" + JSON.stringify(target["family"]) + "." +
161
+ JSON.stringify(target["action"] ?? "") + ") — family stages take " +
162
+ "initials, not params; drop the key", { loc: "params" });
163
+ }
164
+ const admits = admitOf(target);
165
+ for (const [pk, pv] of Object.entries(value)) {
166
+ if (!admitsParam(target, pk)) {
167
+ throw new RemoteError("runs/invalid-request", "card " + JSON.stringify(target["card"]) +
168
+ " does not admit param " + JSON.stringify(pk) +
169
+ " (admitted: " + JSON.stringify(admits) + ")", { loc: "params" });
170
+ }
171
+ paramsOf(target)[pk] = pv;
172
+ }
173
+ continue;
174
+ }
175
+ // THE FLAT SHAPE: exactly one admitting stage, or refuse.
176
+ const targets = stageRows.filter((r) => admitsParam(r, key));
177
+ if (targets.length === 0) {
178
+ if (familyRows.length > 0) {
179
+ throw new RemoteError("runs/invalid-request", "no stage of flow " + flowName + " admits param " + JSON.stringify(key) +
180
+ " — its family stage" + (familyRows.length > 1 ? "s" : "") + " " + familyTag() +
181
+ " take" + (familyRows.length > 1 ? "" : "s") + " initials, not params", { loc: "params" });
182
+ }
183
+ throw new RemoteError("runs/invalid-request", "no stage of flow " + flowName + " admits param " + JSON.stringify(key) +
184
+ " — a flat params value needs exactly one admitting stage; " +
185
+ "target a stage with {stage_id: {" + key + ": …}} or drop the key", { loc: "params" });
186
+ }
187
+ if (targets.length > 1) {
188
+ throw new RemoteError("runs/invalid-request", "param " + JSON.stringify(key) + " is admitted by " + targets.length +
189
+ " stages of flow " + flowName + " (" +
190
+ targets.map((r) => JSON.stringify(r["id"])).join(", ") +
191
+ ") — ambiguous; target one stage with {stage_id: {" + key + ": …}}", { loc: "params" });
192
+ }
193
+ const row = targets[0];
194
+ paramsOf(row)[key] = value;
195
+ }
196
+ }
197
+ //# sourceMappingURL=flowsParamsOverlay.js.map
@@ -0,0 +1,12 @@
1
+ import type { RegistryFlow } from "./flowsData.js";
2
+ export declare const ANNY_HMR_ESTIMATOR: RegistryFlow;
3
+ export declare const ANNY_PARAMS: RegistryFlow;
4
+ export declare const AUDIO_NATIVE_TTS: RegistryFlow;
5
+ export declare const BODY_TO_SOMAX: RegistryFlow;
6
+ export declare const FIT_SEAT: RegistryFlow;
7
+ export declare const IMAGE_UPSCALE: RegistryFlow;
8
+ export declare const MUSIC_NATIVE: RegistryFlow;
9
+ export declare const CRAFT_LOOP: RegistryFlow;
10
+ export declare const CHARACTER_FACTORY: RegistryFlow;
11
+ export declare const OBJECT_FORGE: RegistryFlow;
12
+ //# sourceMappingURL=flowsRegistryRows.d.ts.map