@melite/estate-queue 0.1.4-alpha → 0.2.0-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 (106) hide show
  1. package/LICENSE +561 -457
  2. package/README.md +55 -0
  3. package/lib/bench.d.ts +19 -11
  4. package/lib/bench.js +47 -57
  5. package/lib/cardsArmError.d.ts +94 -2
  6. package/lib/cardsArmError.js +34 -4
  7. package/lib/cardsCompose.d.ts +13 -1
  8. package/lib/cardsCompose.js +151 -67
  9. package/lib/cardsDangling.d.ts +2 -2
  10. package/lib/cardsDangling.js +82 -37
  11. package/lib/cardsFacts.d.ts +32 -3
  12. package/lib/cardsFacts.js +39 -1
  13. package/lib/cardsLanes.d.ts +62 -4
  14. package/lib/cardsLanes.js +407 -20
  15. package/lib/cardsLanesCopy.d.ts +21 -0
  16. package/lib/cardsLanesCopy.js +22 -0
  17. package/lib/cardsRegistry.d.ts +195 -10
  18. package/lib/cardsRegistry.js +959 -67
  19. package/lib/cardsVariant.d.ts +22 -8
  20. package/lib/cardsVariant.js +243 -52
  21. package/lib/discloseRegistry.d.ts +42 -11
  22. package/lib/discloseRegistry.js +163 -23
  23. package/lib/filmLead.js +5 -3
  24. package/lib/flowsData.d.ts +68 -13
  25. package/lib/flowsData.js +236 -107
  26. package/lib/flowsFamilyCompose.d.ts +5 -8
  27. package/lib/flowsFamilyCompose.js +25 -14
  28. package/lib/flowsParamsOverlay.d.ts +55 -0
  29. package/lib/flowsParamsOverlay.js +197 -0
  30. package/lib/flowsRegistryRows.d.ts +4 -1
  31. package/lib/flowsRegistryRows.js +325 -25
  32. package/lib/index.d.ts +1 -3
  33. package/lib/index.js +20 -5
  34. package/lib/lifecycleLatch.d.ts +16 -0
  35. package/lib/lifecycleLatch.js +42 -0
  36. package/lib/loadPlane.d.ts +3 -2
  37. package/lib/loadPlane.js +34 -8
  38. package/lib/loadRegistry.js +1 -1
  39. package/lib/manageOps.d.ts +8 -2
  40. package/lib/manageOps.js +28 -7
  41. package/lib/managePlane.d.ts +42 -1
  42. package/lib/managePlane.js +911 -101
  43. package/lib/managePreflight.d.ts +26 -0
  44. package/lib/managePreflight.js +179 -0
  45. package/lib/manageProbe.d.ts +15 -7
  46. package/lib/manageProbe.js +79 -8
  47. package/lib/manageRegistry.d.ts +42 -4
  48. package/lib/manageRegistry.js +45 -7
  49. package/lib/mediaKinds.d.ts +1 -1
  50. package/lib/mediaKinds.js +1 -1
  51. package/lib/queue.js +14 -10
  52. package/lib/queueCore.d.ts +21 -5
  53. package/lib/queueCore.js +22 -5
  54. package/lib/queueLifecycle.d.ts +0 -24
  55. package/lib/queueLifecycle.js +9 -63
  56. package/lib/queueLock.d.ts +8 -2
  57. package/lib/queueLock.js +9 -6
  58. package/lib/queueResurrect.d.ts +7 -2
  59. package/lib/queueResurrect.js +25 -6
  60. package/lib/queueSidecar.d.ts +114 -1
  61. package/lib/queueSidecar.js +178 -7
  62. package/lib/queueSubmit.d.ts +124 -10
  63. package/lib/queueSubmit.js +251 -48
  64. package/lib/queueSweep.js +13 -2
  65. package/lib/runsChange.d.ts +8 -0
  66. package/lib/runsChange.js +21 -5
  67. package/lib/runsErrorCodes.d.ts +1 -1
  68. package/lib/runsErrorCodes.js +35 -0
  69. package/lib/runsExecute.d.ts +26 -0
  70. package/lib/runsExecute.js +184 -6
  71. package/lib/runsGates.d.ts +5 -1
  72. package/lib/runsGates.js +10 -5
  73. package/lib/runsList.d.ts +43 -3
  74. package/lib/runsList.js +172 -58
  75. package/lib/runsRefusalVoices.js +101 -0
  76. package/lib/runsRegistry.d.ts +188 -12
  77. package/lib/runsRegistry.js +1233 -179
  78. package/lib/runsSourceEcho.d.ts +27 -0
  79. package/lib/runsSourceEcho.js +84 -18
  80. package/lib/runsStart.d.ts +80 -17
  81. package/lib/runsStart.js +303 -49
  82. package/lib/runsTypes.d.ts +62 -2
  83. package/lib/runsTypes.js +30 -6
  84. package/lib/runsValidateArms.js +61 -7
  85. package/lib/runsValidateServe.d.ts +2 -2
  86. package/lib/runsValidateServe.js +46 -14
  87. package/lib/runsValidateShared.d.ts +10 -1
  88. package/lib/runsValidateShared.js +14 -0
  89. package/lib/runsValidateStages.d.ts +10 -3
  90. package/lib/runsValidateStages.js +44 -12
  91. package/lib/runtimeProvision.d.ts +119 -0
  92. package/lib/runtimeProvision.js +243 -0
  93. package/lib/service.d.ts +24 -6
  94. package/lib/service.js +19 -11
  95. package/lib/skillFs.d.ts +9 -4
  96. package/lib/skillFs.js +12 -14
  97. package/lib/skillPlane.d.ts +3 -2
  98. package/lib/skillPlane.js +12 -6
  99. package/lib/skillRegistry.js +1 -1
  100. package/lib/skillRows.d.ts +4 -3
  101. package/lib/skillRows.js +21 -14
  102. package/lib/toolProjection.d.ts +1 -1
  103. package/lib/toolProjection.js +1 -1
  104. package/package.json +18 -17
  105. package/lib/runStatus.d.ts +0 -7
  106. package/lib/runStatus.js +0 -21
@@ -1,6 +1,7 @@
1
1
  import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
2
2
  import { RUNS_ERROR_CODES } from "./runsErrorCodes.js";
3
- import { getRegistryFlow, expandRegistryFlow, registryFlowToInline, registryInitialsError } from "./flowsData.js";
3
+ import { expandRegistryFlow, registryFlowToInline, registryInitialsError } from "./flowsData.js";
4
+ import { applyFlowParamsOverride, overlayDecls } from "./flowsParamsOverlay.js";
4
5
  import { composeFamilyStages, liveFamilySeat } from "./flowsFamilyCompose.js";
5
6
  import { resolveRepoRoot } from "@melite/comfyui-cordis";
6
7
  import { inlineArm, strictBody } from "./runsValidate.js";
@@ -45,11 +46,34 @@ export async function validate(doc, signal, ctx) {
45
46
  // The RAW value, named — the start arm's voice verbatim.
46
47
  "flow id " + JSON.stringify(raw) + " is not a legal identifier", { loc: "flow" });
47
48
  }
48
- const decl = getRegistryFlow(name);
49
+ const flowsSeat = ctx.get("meliteFlows");
50
+ const decl = flowsSeat.get(name);
49
51
  if (decl === undefined) {
50
52
  throw new RemoteError("runs/invalid-request", "no flow named " + name + " in the registry", { loc: "flow" });
51
53
  }
52
- const expanded = expandRegistryFlow(decl);
54
+ // THE EXPANSION FOLD (round-21 flows audit F4): the start
55
+ // door's twin — expansion's authoring throws ride the
56
+ // invalid-request voice here too, never 500-class.
57
+ let expanded;
58
+ try {
59
+ expanded = expandRegistryFlow(decl, flowsSeat);
60
+ }
61
+ catch (e) {
62
+ throw new RemoteError("runs/invalid-request", e instanceof Error ? e.message : String(e), { loc: "stages" });
63
+ }
64
+ // THE PARAMS DOOR RIDES VALIDATE (round-21 flows audit F1),
65
+ // AT THE START DOOR'S SEAM (round-23 family-compose audit Q1,
66
+ // unifyOverlayPoint): the start arm overlays the EXPANDED
67
+ // rows before its initials gate and family-compose
68
+ // (runsRegistry 1518→1533→1588) — this arm now rides the same
69
+ // point on the same rows, so a body tripping more than one
70
+ // gate gets the same first refusal from both doors, never
71
+ // params-voice here and stages-voice at start (or the
72
+ // reverse).
73
+ const overrideRaw = body["params"];
74
+ if (overrideRaw !== undefined) {
75
+ applyFlowParamsOverride(name, expanded.stages, overrideRaw, overlayDecls(ctx.cardRegistry), String(body["model"] ?? ""));
76
+ }
53
77
  // The same compile-time gate at validate (REBUILD-21).
54
78
  const badInitial = registryInitialsError(expanded, body, {
55
79
  repoRoot: resolveRepoRoot(),
@@ -78,6 +102,13 @@ export async function validate(doc, signal, ctx) {
78
102
  catch (e) {
79
103
  throw new RemoteError("runs/invalid-request", e instanceof Error ? e.message : String(e), { loc: "stages" });
80
104
  }
105
+ // The overlay rode AFTER this compose until the round-23
106
+ // family-compose audit (Q1) — start overlays first, so the
107
+ // composed rows are already the overlaid truth when the door
108
+ // compiles them; card stages pass through composeFamilyStages
109
+ // by reference, family stages admit nothing (their card is
110
+ // ""), so the pre-compose overlay is neither lost nor
111
+ // reordered.
81
112
  const inlineDoc = registryFlowToInline(composedFlow);
82
113
  const rest = { ...body };
83
114
  delete rest["flow"];
@@ -90,7 +121,16 @@ export async function validate(doc, signal, ctx) {
90
121
  // LOUD miswire ("no CardRegistryService for cardGate") — the
91
122
 
92
123
  // could run but never validate.
93
- const answer = inlineArm(liveDoc, ctx.cardRegistry);
124
+
125
+ // engines seat's registered ids — the same source the run
126
+ // door's inline compiler judges. A seat-less boot (pure walls,
127
+ // fixtures) passes undefined and the ENGINE_TABLE shape keeps
128
+ // the pre-seam verdict.
129
+ const enginesSeat = ctx.get("engines");
130
+ const knownEngines = enginesSeat !== undefined && typeof enginesSeat.ids === "function"
131
+ ? enginesSeat.ids()
132
+ : undefined;
133
+ const answer = inlineArm(liveDoc, ctx.cardRegistry, knownEngines);
94
134
  if (answer.status === 200) {
95
135
  // THE ONE-ADMISSION LAW (commission 018's sharpest
96
136
 
@@ -170,10 +210,20 @@ async function composeCardStagesAtValidate(liveDoc, svc) {
170
210
  }
171
211
  for (const st of cardStages) {
172
212
  const params = st["params"];
213
+
214
+ // the run compose lanes mid three ways (params.model, the
215
+ // row's service key, the card fallback — runsRegistry's
216
+ // ROUTING-KEY STAMP). This walk spelled it TWO ways (no
217
+ // service read), so a service-bearing row validated as its
218
+ // card compose and ran as its service compose — two seats,
219
+ // one row, two verdicts. One law now: the same three-way
220
+ // spelling, the same stamp (an explicit service key rides as
221
+ // body.model so the board law judges the value that lanes).
222
+ const service = typeof st["service"] === "string" && st["service"] !== "" ? st["service"] : undefined;
173
223
  // a non-string model row (the door's card gate only demands
174
224
  // presence) composes against the CARD name — the arm is live
175
225
  const mid = typeof params["model"] === "string"
176
- ? params["model"] : String(st["card"]);
226
+ ? params["model"] : String(service ?? st["card"]);
177
227
  // A MODEL-LESS CARD STAGE (stroke 3: the registry's rig hop)
178
228
  // rides with NO model key at all: an injected one would hit
179
229
  // the board check ("model 'rig' is not offered by card 'rig'",
@@ -183,7 +233,7 @@ async function composeCardStagesAtValidate(liveDoc, svc) {
183
233
  // compose names the family through the card's own selector
184
234
  // (the rig card's mode knob).
185
235
  const body = params["model"] === undefined
186
- ? { ...params }
236
+ ? (service !== undefined ? { ...params, model: service } : { ...params })
187
237
  : { ...params, model: mid };
188
238
  try {
189
239
  await svc.phase1Card(body, mid);
@@ -258,11 +308,15 @@ export async function modelValidateArm(body, ctx) {
258
308
  const params = prep.params;
259
309
  // IN-PROCESS COMPOSE: the SAME registry compose pipeline the
260
310
  // start arm rides composes for validate (one plane, both arms).
311
+ // ONE-FACTS-READ (round-22 compose audit Q3b): the door's one
312
+ // facts read rides the whole arm — the internal prepare and the
313
+
314
+ // second strict read beside a degraded first.
261
315
  const refused =
262
316
  // the body's OWN model address rides: the params are overlaid (the
263
317
  // model key is consumed), so the arm must not lose the address the
264
318
  // board check and the variant selection both judge
265
- await svc.composeValidateCard(prep.card, prep.fam, params, mid, body);
319
+ await svc.composeValidateCard(prep.card, prep.fam, params, mid, body, facts);
266
320
  if (refused !== null) {
267
321
  return {
268
322
  status: 400,
@@ -10,6 +10,6 @@ export declare function compileFlow(flow: Flow, body: Record<string, unknown>, c
10
10
  skipped: string[];
11
11
  };
12
12
  export declare function costPreview(engineTypes: string[]): Record<string, unknown>;
13
- export declare function inlineArm(full: unknown, cards?: CardRegistryLike | null): FlowsValidateAnswer;
14
- export declare function serveSubject(subject: unknown, fullRec: Record<string, unknown>, cards?: CardRegistryLike | null): FlowsValidateAnswer;
13
+ export declare function inlineArm(full: unknown, cards?: CardRegistryLike | null, knownEngines?: readonly string[]): FlowsValidateAnswer;
14
+ export declare function serveSubject(subject: unknown, fullRec: Record<string, unknown>, cards?: CardRegistryLike | null, knownEngines?: readonly string[]): FlowsValidateAnswer;
15
15
  //# sourceMappingURL=runsValidateServe.d.ts.map
@@ -1,8 +1,7 @@
1
1
  // runsValidateServe.ts — the shared compile-serve tail split from
2
2
  // runsValidate.ts (pure move, zero logic changes): branch prune, to_graph,
3
3
  // the $channel gate, cost preview, and the inline/named serve arms.
4
- import { engineIdOk } from "@melite/engine-contract";
5
- import { ENGINE_TABLE, FlowError } from "./runsValidateShared.js";
4
+ import { FlowError, engineDefaultOutput } from "./runsValidateShared.js";
6
5
  import { edgeRef } from "./runsValidateInline.js";
7
6
  import { flowFromBody, kindsOk, wiresResolve } from "./runsValidateStages.js";
8
7
  import { batchRows, sweepWorkflows } from "./runsValidateSweeps.js";
@@ -81,14 +80,25 @@ export function toGraph(flow) {
81
80
  outputs.push({ ...o });
82
81
  }
83
82
  else {
84
- // validateEngines already refused unknown engines and the
85
- // table carries a default for every known one — the
86
- // try/except-unknown shape of to_graph collapses to the table.
87
- // validateEngines refused unknown engines upstream — the hit is proven.
88
- const row = st.engine.startsWith("mcp:") && engineIdOk(st.engine)
89
- ? { plugin: "mcp-client", def: "image" }
90
- : ENGINE_TABLE[st.engine];
91
- outputs.push({ name: "default", kind: row.def });
83
+ // THE SHARED DEFAULT READ (P7 latent): validateEngines refused
84
+ // unknown engines upstream, so this hit is proven — but the
85
+ // rule (mcp leg + table) is still read here, not retyped, so
86
+ // the day the table grows this seat cannot disagree. The
87
+ // undefined leg is the defense-in-depth voice for a guarantee
88
+ // missed, in the lattice's own words.
89
+ const def = engineDefaultOutput(st.engine);
90
+ if (def === undefined) {
91
+ throw new FlowError("flow " +
92
+ JSON.stringify(flow.id) +
93
+ " stage " +
94
+ JSON.stringify(st.id) +
95
+ ": engine " +
96
+ JSON.stringify(st.engine) +
97
+ " — no engine plugin for type " +
98
+ JSON.stringify(st.engine) +
99
+ " (no engine plugin declares it)");
100
+ }
101
+ outputs.push({ name: "default", kind: def });
92
102
  }
93
103
  return {
94
104
  id: st.id,
@@ -167,22 +177,22 @@ export function costPreview(engineTypes) {
167
177
  stages: engineTypes.map((et) => ({ engine: et, median_s: null, samples: 0 })),
168
178
  };
169
179
  }
170
- export function inlineArm(full, cards) {
180
+ export function inlineArm(full, cards, knownEngines) {
171
181
  const fullRec = typeof full === "object" && full !== null && !Array.isArray(full)
172
182
  ? full
173
183
  : {};
174
184
  const hasInline = typeof full === "object" && full !== null && !Array.isArray(full) && "flow_inline" in fullRec;
175
185
  const envelope = hasInline ? fullRec["flow_inline"] : undefined;
176
186
  const subject = envelope !== undefined && envelope !== null ? envelope : full;
177
- return serveSubject(subject, fullRec, cards);
187
+ return serveSubject(subject, fullRec, cards, knownEngines);
178
188
  }
179
189
  // ── the shared compile-serve tail (flowFromBody -> compile ->
180
190
  // pin sweep -> the 200 shape; the inline arm and the named arm
181
191
  // both ride it — one validator, never two) ──────────────────────
182
- export function serveSubject(subject, fullRec, cards) {
192
+ export function serveSubject(subject, fullRec, cards, knownEngines) {
183
193
  let flow;
184
194
  try {
185
- flow = flowFromBody(subject, cards);
195
+ flow = flowFromBody(subject, cards, knownEngines);
186
196
  }
187
197
  catch (e) {
188
198
  if (e instanceof FlowError) {
@@ -198,6 +208,28 @@ export function serveSubject(subject, fullRec, cards) {
198
208
  }
199
209
  throw e;
200
210
  }
211
+
212
+ // inline compiler refuses skip_when outright ("unported on this
213
+
214
+ // to answer the SAME doc 200 with a skipped receipt: one half
215
+ // said the branch folds, the other said the branch is unported.
216
+ // One law, both doors: the run door's refusal voice is the truth,
217
+ // so validate refuses before the prune arm can serve its 200.
218
+ const skipIds = flow.stages
219
+ .filter((st) => st.skipWhen !== null)
220
+ .map((st) => st.id);
221
+ if (skipIds.length > 0) {
222
+ return {
223
+ status: 400,
224
+ payload: {
225
+ error: "flow_inline stage " +
226
+ JSON.stringify(skipIds[0]) +
227
+ ": skip_when is unported on this gateway",
228
+ code: "preview_scope",
229
+ loc: "stages",
230
+ },
231
+ };
232
+ }
201
233
  let compiled;
202
234
  try {
203
235
  compiled = compileFlow(flow, fullRec, cards);
@@ -1,4 +1,4 @@
1
- import type { CardDefinition } from "@melite/comfyui-cordis";
1
+ import type { CardDefinition } from '@melite/comfyui-card-kit/card-definition';
2
2
  /** The door's answer (status folds away at the remote seam; the
3
3
  * payload rides verbatim). */
4
4
  export interface FlowsValidateAnswer {
@@ -16,6 +16,15 @@ export declare const ENGINE_TABLE: Record<string, {
16
16
  plugin: string;
17
17
  def: string;
18
18
  }>;
19
+ /** THE ENGINE TABLE'S DEFAULT READ (P7 latent): the lattice's own
20
+ * rule, owned once — mcp:<server> grammar ids read the mcp-client
21
+ * row ("image"), table rows read their def, anything else reads
22
+ * undefined (unknown: no fill — the caller's door refuses, never
23
+ * guesses). Both doors derive from this one read (validate's
24
+ * lattice below, start's empty-outputs fill): a future grammar id
25
+ * absent from the table makes BOTH refuse instead of splitting
26
+ * validate-refuses/start-accepts. */
27
+ export declare function engineDefaultOutput(engine: string): string | undefined;
19
28
  export declare const KIND_VOCAB: readonly string[];
20
29
  export declare const SKIP_VOCAB: readonly string[];
21
30
  export declare const INLINE_TOP_SORTED: readonly string[];
@@ -2,6 +2,7 @@
2
2
  // zero logic changes): closed vocabularies, flow-domain types, FlowError,
3
3
  // and the card-registry face.
4
4
  import { WIRE_STAGE_KEYS } from "@melite/contracts/benchStage";
5
+ import { engineIdOk } from "@melite/engine-contract";
5
6
  import { INLINE_TOP_KEYS } from "./runsGates.js";
6
7
  // ENGINE_TABLE: engine_type -> {plugin_id, default_output kind}.
7
8
 
@@ -24,6 +25,19 @@ export const ENGINE_TABLE = {
24
25
  // run dir).
25
26
  agent: { plugin: "agent", def: "text" },
26
27
  };
28
+ /** THE ENGINE TABLE'S DEFAULT READ (P7 latent): the lattice's own
29
+ * rule, owned once — mcp:<server> grammar ids read the mcp-client
30
+ * row ("image"), table rows read their def, anything else reads
31
+ * undefined (unknown: no fill — the caller's door refuses, never
32
+ * guesses). Both doors derive from this one read (validate's
33
+ * lattice below, start's empty-outputs fill): a future grammar id
34
+ * absent from the table makes BOTH refuse instead of splitting
35
+ * validate-refuses/start-accepts. */
36
+ export function engineDefaultOutput(engine) {
37
+ if (engine.startsWith("mcp:") && engineIdOk(engine))
38
+ return "image";
39
+ return ENGINE_TABLE[engine]?.def;
40
+ }
27
41
  // ── closed vocabularies (Kind / SkipWhen order) ──────
28
42
  export const KIND_VOCAB = [
29
43
  "text",
@@ -1,4 +1,4 @@
1
- import type { CardDefinition } from "@melite/comfyui-cordis";
1
+ import type { CardDefinition } from '@melite/comfyui-card-kit/card-definition';
2
2
  import type { CardRegistryLike, Flow, FlowStageRow } from "./runsValidateShared.js";
3
3
  export type { FlowStageRow };
4
4
  export declare function strictBody(body: Record<string, unknown>): void;
@@ -20,6 +20,13 @@ export declare function cardGate(flowId: string, st: FlowStageRow, cards?: CardR
20
20
 
21
21
  export declare function coerceSnapshotBody(def: CardDefinition | undefined, body: Record<string, unknown>): Record<string, unknown>;
22
22
  export declare function kindsOk(flowId: string, stages: FlowStageRow[], engineDefaults: Record<string, string | null>, cards?: CardRegistryLike | null): void;
23
- export declare function validateEngines(flow: Flow, cards?: CardRegistryLike | null): Flow;
24
- export declare function flowFromBody(body: unknown, cards?: CardRegistryLike | null): Flow;
23
+ export declare function validateEngines(flow: Flow, cards?: CardRegistryLike | null,
24
+
25
+
26
+
27
+
28
+
29
+
30
+ knownEngines?: readonly string[]): Flow;
31
+ export declare function flowFromBody(body: unknown, cards?: CardRegistryLike | null, knownEngines?: readonly string[]): Flow;
25
32
  //# sourceMappingURL=runsValidateStages.d.ts.map
@@ -2,10 +2,10 @@
2
2
  // runsValidate.ts (pure move, zero logic changes): strict-body admission,
3
3
  // stage rows, wires, the card gate, kinds, engines, flow_from_body.
4
4
  import { coerceWireArrays, coerceWireNumbers, unwrapItemArrays } from '@melite/comfyui-card-kit';
5
- import { engineIdOk } from "@melite/engine-contract";
6
5
  import { checkStrictBody } from "./runsGates.js";
7
- import { ENGINE_TABLE, FLOW_ID_RE, INLINE_TOP_SORTED, STAGE_KEYS_SORTED, FlowError, needCardRegistry, } from "./runsValidateShared.js";
6
+ import { FLOW_ID_RE, INLINE_TOP_SORTED, STAGE_KEYS_SORTED, FlowError, engineDefaultOutput, needCardRegistry, } from "./runsValidateShared.js";
8
7
  import { edgeRef, inlineEdge, inlineKind, inlineSkip } from "./runsValidateInline.js";
8
+ import { KIND_VOCAB } from "./runsValidateShared.js";
9
9
  import { coerceRecord, minLengthRefusal } from "./runsValidateRefusals.js";
10
10
  // ── strict body ──────
11
11
  // Key split owned by the admission gate; the FlowError prose stays here.
@@ -333,10 +333,23 @@ export function kindsOk(flowId, stages, engineDefaults, cards) {
333
333
  const onlyExpected = [...expectedNames].filter((k) => !inputNames.has(k)).sort();
334
334
  if (onlyInput.length > 0 || onlyExpected.length > 0) {
335
335
  const bits = [];
336
- if (onlyInput.length > 0)
336
+ if (onlyInput.length > 0) {
337
337
  bits.push("wired but untyped: " + JSON.stringify(onlyInput));
338
+ }
338
339
  if (onlyExpected.length > 0)
339
340
  bits.push("typed but unwired: " + JSON.stringify(onlyExpected));
341
+
342
+ // met this refusal three times, guessed kinds blindly, and
343
+ // abandoned wiring — the voice named the mismatch but never
344
+ // the legal vocabulary, the fix's shape, or where the card's
345
+ // own kinds live). One refusal must carry the whole cure.
346
+ const first = onlyInput[0];
347
+ const teach = first === undefined
348
+ ? ""
349
+ : " — state the wire's kind with expected {" +
350
+ JSON.stringify(first) + ": \"image\"} on the stage (the closed Kind vocabulary is " +
351
+ JSON.stringify([...KIND_VOCAB]) +
352
+ "; a card whose ports declare the slot types itself — load its schema first)";
340
353
  throw new FlowError("flow " +
341
354
  JSON.stringify(flowId) +
342
355
  " stage " +
@@ -344,7 +357,8 @@ export function kindsOk(flowId, stages, engineDefaults, cards) {
344
357
  ": inputs/expected mismatch (" +
345
358
  bits.join("; ") +
346
359
  ") — every input needs an expected Kind, every expected " +
347
- "Kind needs an input");
360
+ "Kind needs an input" +
361
+ teach);
348
362
  }
349
363
  const resolved = new Map();
350
364
  for (const o of st.outputs)
@@ -432,13 +446,31 @@ export function kindsOk(flowId, stages, engineDefaults, cards) {
432
446
  // bus — here the wall-pinned ENGINE_TABLE (existence + DEFAULT_OUTPUT);
433
447
  // then the FULL kind pass. Unknown-engine text mirrors
434
448
  // plugins.load_engine verbatim.
435
- export function validateEngines(flow, cards) {
449
+ export function validateEngines(flow, cards,
450
+
451
+
452
+
453
+
454
+
455
+
456
+ knownEngines) {
436
457
  const engineDefaults = {};
437
458
  for (const st of flow.stages) {
438
- const row = st.engine.startsWith("mcp:") && engineIdOk(st.engine)
439
- ? { plugin: "mcp-client", def: "image" }
440
- : ENGINE_TABLE[st.engine];
441
- if (row === undefined) {
459
+ if (knownEngines !== undefined && !knownEngines.includes(st.engine)) {
460
+ throw new FlowError("flow " +
461
+ JSON.stringify(flow.id) +
462
+ " stage " +
463
+ JSON.stringify(st.id) +
464
+ " names engine " +
465
+ JSON.stringify(st.engine) +
466
+ " — this gateway serves registered engines only (" +
467
+ (knownEngines.length === 0
468
+ ? "none registered"
469
+ : knownEngines.slice().sort().join(", ")) +
470
+ ")");
471
+ }
472
+ const def = engineDefaultOutput(st.engine);
473
+ if (def === undefined) {
442
474
  throw new FlowError("flow " +
443
475
  JSON.stringify(flow.id) +
444
476
  " stage " +
@@ -449,13 +481,13 @@ export function validateEngines(flow, cards) {
449
481
  JSON.stringify(st.engine) +
450
482
  " (no engine plugin declares it)");
451
483
  }
452
- engineDefaults[st.engine] = row.def;
484
+ engineDefaults[st.engine] = def;
453
485
  }
454
486
  kindsOk(flow.id, flow.stages, engineDefaults, cards);
455
487
  return flow;
456
488
  }
457
489
  // flowFromBody: JSON body -> validated Flow.
458
- export function flowFromBody(body, cards) {
490
+ export function flowFromBody(body, cards, knownEngines) {
459
491
  if (typeof body !== "object" || body === null || Array.isArray(body)) {
460
492
  throw new FlowError("flow body must be a JSON object");
461
493
  }
@@ -486,6 +518,6 @@ export function flowFromBody(body, cards) {
486
518
  wiresResolve(flowId, rows);
487
519
  kindsOk(flowId, rows, {}, cards);
488
520
  const flow = { id: flowId, description: String(rec["description"] ?? ""), stages: rows };
489
- return validateEngines(flow, cards);
521
+ return validateEngines(flow, cards, knownEngines);
490
522
  }
491
523
  //# sourceMappingURL=runsValidateStages.js.map
@@ -0,0 +1,119 @@
1
+ import type { DeclaredRuntime } from "@melite/comfyui-card-kit/model-contract";
2
+ export type RuntimeSentinels = Pick<DeclaredRuntime, "name" | "env" | "rel" | "sentinel" | "command">;
3
+ /** One sentinel's safe join: a sentinel escaping its home (.. or
4
+ * empty) is a declaration bug — false, never a filesystem escape. */
5
+ export declare function sentinelHit(home: string, sentinel: string): boolean;
6
+ /** Every sentinel stands under `home` (through a symlink when the
7
+ * home is one — existsSync follows links). */
8
+ export declare function runtimeHealthy(home: string, sentinels: readonly string[]): boolean;
9
+ /** The engine's own walk-up, mirrored (nodes_anny.py:885-935): the
10
+ * first ancestor of the output dir holding the rel dir decides — a
11
+ * chipped first hit is the miss, never a cue to walk on. Walk-up
12
+ * only: the caller owns the env leg, so this never re-checks it. */
13
+ export declare function resolveRuntimeHome(outputDir: string, rt: Pick<DeclaredRuntime, "rel" | "sentinel">): string | null;
14
+ /** THE DECLARED ENGINE ROOT (E2-2 Piece A): where the live engine
15
+ * lives on this box, stated in the endpoint machine statement
16
+ * (`engine_root`). Additive key, unknown to every other reader. */
17
+ export declare function engineRootOf(): string | null;
18
+ /** The engine's output dir: the endpoint's output_dir when stated
19
+ * (absolute as-is, relative resolved under the declared engine
20
+ * root — the managed "data/temp" spelling), else the ComfyUI
21
+ * default (<root>/output). The walk-up only moves UP, so
22
+ * starting deep is safe. */
23
+ export declare function engineOutputDir(root: string): string;
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ export declare function lanesEnvFileOf(): string | null;
36
+ export interface LanesEnvValue {
37
+ readonly value: string;
38
+ readonly present: boolean;
39
+ }
40
+ /** Parse ONE key out of a systemd EnvironmentFile spelling: KEY=VALUE
41
+ * lines; blank lines and `#`/`;` comments (indented or not) are
42
+ * skipped; inline `#` text stays part of the value (systemd does not
43
+ * strip trailing comments in this mode, so neither do we — a quoted
44
+ * or commented value surfaces verbatim in the named-source answer
45
+ * and fails its sentinels loudly, never silently). ORDER: LAST-WINS —
46
+ * a later assignment overrides an earlier one, matching systemd's
47
+ * EnvironmentFile read order (later settings override earlier
48
+ * settings) and shell source semantics. The walls pin this with a
49
+ * first-dead/last-healthy fixture. */
50
+ export declare function lanesEnvValue(file: string, key: string, read: (path: string) => string): LanesEnvValue;
51
+ /** The ONE env view both consumers read: the lanes.env value
52
+ * overlays the process env for exactly rt.env (the file is what the
53
+ * next lane start arms, so a fresh edit wins over a stale process
54
+ * copy). `source` says which side spoke, so the verb's answer can
55
+ * name it. */
56
+ export type RuntimeEnvSource = "process" | "lanes.env" | "absent";
57
+ export declare function runtimeEnvView(envKey: string, env?: Record<string, string | undefined>): {
58
+ value: string;
59
+ source: RuntimeEnvSource;
60
+ };
61
+ /** The fs-ish seam the decision runs over — the real node half rides
62
+ * {@link nodeRuntimeFs}; the walls inject tmp-fixture halves. */
63
+ export interface RuntimeFs {
64
+ exists(path: string): boolean;
65
+ isSymlink(path: string): boolean;
66
+ readlink(path: string): string | null;
67
+ mkdir(path: string): void;
68
+ symlink(target: string, path: string): void;
69
+ }
70
+ export declare const nodeRuntimeFs: RuntimeFs;
71
+ /** How the runtime was answered present — the verb's receipt names
72
+ * it, and the managed-engine arm (walk-up) proves the verb never
73
+ * double-seats. */
74
+ export type RuntimePresentSource = "env" | "lanes.env" | "walk-up" | "target";
75
+ export type RuntimeProvisionDecision = {
76
+ kind: "already-present";
77
+ home: string;
78
+ source: RuntimePresentSource;
79
+ } | {
80
+ kind: "linkable";
81
+ seed: string;
82
+ target: string;
83
+ } | {
84
+ kind: "refused";
85
+ reason: "no-engine-root" | "broken-seed" | "target-blocked" | "env-invalid";
86
+ detail: string;
87
+ };
88
+ export interface RuntimeProvisionDeps {
89
+ /** The endpoint's declared engine root (null = the estate cannot
90
+ * see that tree). */
91
+ engineRoot: string | null;
92
+ /** The walk-up start (the engine's own output dir) — only read
93
+ * when engineRoot is non-null. */
94
+ walkStart: string;
95
+ /** The ONE env view (runtimeEnvView) — the value AND the side it
96
+ * came from, so an invalid override is named with its origin. */
97
+ env: {
98
+ value: string;
99
+ source: RuntimeEnvSource;
100
+ };
101
+ /** The repo's healthy seed home: join(repoRoot, "data", "runtime",
102
+ * rt.name). */
103
+ repoSeedHome: string;
104
+ fs: RuntimeFs;
105
+ }
106
+ /** THE DECISION CORE (pure). Order is the law:
107
+ * 1. a stated env override (process or lanes.env) — valid counts as
108
+ * present (source env / lanes.env), invalid refuses naming it
109
+ * (the press gate refuses the same run: gate+verb agreement);
110
+ * 2. no engine root refuses (the estate cannot see that tree);
111
+ * 3. the walk-up from the engine's output — a hit is present
112
+ * (the managed-engine arm: the verb never double-seats);
113
+ * 4. an existing healthy target (real dir or live symlink) is
114
+ * present; a real CHIPPED or foreign one refuses target-blocked
115
+ * — never clobbered;
116
+ * 5. a healthy seed with an absent target is linkable; a chipped
117
+ * seed refuses broken-seed voicing the DECL's provision command. */
118
+ export declare function resolveRuntimeProvision(rt: RuntimeSentinels, deps: RuntimeProvisionDeps): RuntimeProvisionDecision;
119
+ //# sourceMappingURL=runtimeProvision.d.ts.map