@melite/estate-queue 0.0.0-stage → 0.1.5-pre-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +557 -0
- package/README.md +54 -2
- package/lib/bakeParams.d.ts +17 -0
- package/lib/bakeParams.js +182 -0
- package/lib/bench.d.ts +32 -0
- package/lib/bench.js +111 -0
- package/lib/cardsArmError.d.ts +61 -0
- package/lib/cardsArmError.js +57 -0
- package/lib/cardsCompose.d.ts +53 -0
- package/lib/cardsCompose.js +295 -0
- package/lib/cardsDangling.d.ts +16 -0
- package/lib/cardsDangling.js +213 -0
- package/lib/cardsFacts.d.ts +87 -0
- package/lib/cardsFacts.js +78 -0
- package/lib/cardsLanes.d.ts +43 -0
- package/lib/cardsLanes.js +178 -0
- package/lib/cardsRegistry.d.ts +404 -0
- package/lib/cardsRegistry.js +1543 -0
- package/lib/cardsVariant.d.ts +37 -0
- package/lib/cardsVariant.js +243 -0
- package/lib/discloseRegistry.d.ts +95 -0
- package/lib/discloseRegistry.js +156 -0
- package/lib/filmLead.d.ts +4 -0
- package/lib/filmLead.js +17 -0
- package/lib/filmMemoryWarn.d.ts +27 -0
- package/lib/filmMemoryWarn.js +99 -0
- package/lib/flowsData.d.ts +234 -0
- package/lib/flowsData.js +673 -0
- package/lib/flowsFamilyCompose.d.ts +45 -0
- package/lib/flowsFamilyCompose.js +191 -0
- package/lib/flowsParamsOverlay.d.ts +55 -0
- package/lib/flowsParamsOverlay.js +197 -0
- package/lib/flowsRegistryRows.d.ts +12 -0
- package/lib/flowsRegistryRows.js +520 -0
- package/lib/index.d.ts +47 -0
- package/lib/index.js +75 -0
- package/lib/ledgerTail.d.ts +20 -0
- package/lib/ledgerTail.js +123 -0
- package/lib/lifecycleLatch.d.ts +16 -0
- package/lib/lifecycleLatch.js +42 -0
- package/lib/loadPlane.d.ts +94 -0
- package/lib/loadPlane.js +570 -0
- package/lib/loadRegistry.d.ts +22 -0
- package/lib/loadRegistry.js +55 -0
- package/lib/manageOps.d.ts +27 -0
- package/lib/manageOps.js +162 -0
- package/lib/managePlane.d.ts +151 -0
- package/lib/managePlane.js +1790 -0
- package/lib/manageProbe.d.ts +48 -0
- package/lib/manageProbe.js +165 -0
- package/lib/manageRegistry.d.ts +66 -0
- package/lib/manageRegistry.js +113 -0
- package/lib/managerRail.d.ts +33 -0
- package/lib/managerRail.js +91 -0
- package/lib/mediaKinds.d.ts +3 -0
- package/lib/mediaKinds.js +2 -0
- package/lib/queue.d.ts +9 -0
- package/lib/queue.js +80 -0
- package/lib/queueCore.d.ts +72 -0
- package/lib/queueCore.js +128 -0
- package/lib/queueLifecycle.d.ts +2 -0
- package/lib/queueLifecycle.js +11 -0
- package/lib/queueLock.d.ts +60 -0
- package/lib/queueLock.js +198 -0
- package/lib/queueResurrect.d.ts +59 -0
- package/lib/queueResurrect.js +249 -0
- package/lib/queueRetry.d.ts +36 -0
- package/lib/queueRetry.js +24 -0
- package/lib/queueSidecar.d.ts +149 -0
- package/lib/queueSidecar.js +183 -0
- package/lib/queueSubmit.d.ts +82 -0
- package/lib/queueSubmit.js +191 -0
- package/lib/queueSweep.d.ts +30 -0
- package/lib/queueSweep.js +132 -0
- package/lib/resurrect.d.ts +6 -0
- package/lib/resurrect.js +18 -0
- package/lib/rootsManifest.d.ts +11 -0
- package/lib/rootsManifest.js +11 -0
- package/lib/runsChange.d.ts +61 -0
- package/lib/runsChange.js +79 -0
- package/lib/runsErrorCodes.d.ts +2 -0
- package/lib/runsErrorCodes.js +48 -0
- package/lib/runsExecute.d.ts +52 -0
- package/lib/runsExecute.js +494 -0
- package/lib/runsGates.d.ts +161 -0
- package/lib/runsGates.js +307 -0
- package/lib/runsList.d.ts +78 -0
- package/lib/runsList.js +574 -0
- package/lib/runsRefusalVoices.d.ts +9 -0
- package/lib/runsRefusalVoices.js +96 -0
- package/lib/runsRegistry.d.ts +351 -0
- package/lib/runsRegistry.js +2394 -0
- package/lib/runsSourceEcho.d.ts +81 -0
- package/lib/runsSourceEcho.js +341 -0
- package/lib/runsStart.d.ts +163 -0
- package/lib/runsStart.js +667 -0
- package/lib/runsTypes.d.ts +218 -0
- package/lib/runsTypes.js +289 -0
- package/lib/runsValidate.d.ts +5 -0
- package/lib/runsValidate.js +31 -0
- package/lib/runsValidateArms.d.ts +7 -0
- package/lib/runsValidateArms.js +339 -0
- package/lib/runsValidateInline.d.ts +6 -0
- package/lib/runsValidateInline.js +82 -0
- package/lib/runsValidateRefusals.d.ts +7 -0
- package/lib/runsValidateRefusals.js +18 -0
- package/lib/runsValidateServe.d.ts +15 -0
- package/lib/runsValidateServe.js +276 -0
- package/lib/runsValidateShared.d.ts +84 -0
- package/lib/runsValidateShared.js +88 -0
- package/lib/runsValidateStages.d.ts +32 -0
- package/lib/runsValidateStages.js +511 -0
- package/lib/runsValidateSweeps.d.ts +6 -0
- package/lib/runsValidateSweeps.js +143 -0
- package/lib/service.d.ts +63 -0
- package/lib/service.js +89 -0
- package/lib/skillFrontmatter.d.ts +11 -0
- package/lib/skillFrontmatter.js +46 -0
- package/lib/skillFs.d.ts +24 -0
- package/lib/skillFs.js +78 -0
- package/lib/skillPlane.d.ts +99 -0
- package/lib/skillPlane.js +269 -0
- package/lib/skillRegistry.d.ts +23 -0
- package/lib/skillRegistry.js +55 -0
- package/lib/skillRows.d.ts +127 -0
- package/lib/skillRows.js +468 -0
- package/lib/toolProjection.d.ts +30 -0
- package/lib/toolProjection.js +142 -0
- package/lib/vocab.d.ts +6 -0
- package/lib/vocab.js +18 -0
- package/package.json +48 -4
package/lib/flowsData.js
ADDED
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
// flowsData.ts — the TS flow-authoring plane, RE-HOMED (REBUILD-13,
|
|
2
|
+
|
|
3
|
+
// gateway package (doors/flowsRegistry.ts, killed with the gateway
|
|
4
|
+
// app — KILL commit 40b57f94) live HERE as data, beside their
|
|
5
|
+
// serving owners (the runs registry {flow:} arms). Port verbatim:
|
|
6
|
+
// the eight declarations, the live from_flow expansion, and the
|
|
7
|
+
// inline shim (registryFlowToInline) — validate and start resolve
|
|
8
|
+
// stages LIVE through expandRegistryFlow, no snapshot drift.
|
|
9
|
+
//
|
|
10
|
+
// THE COMPILE-TIME INITIAL GATE (REBUILD-21, the deferral closed):
|
|
11
|
+
// registryInitialsError + checkFileInitial + InitialsRoots port
|
|
12
|
+
// verbatim (photo/glb file-initial checks + bake_params via the
|
|
13
|
+
// re-homed belt); the runs registry's {flow:} arms run it BEFORE
|
|
14
|
+
// any run registers — start can never queue what validate refuses.
|
|
15
|
+
//
|
|
16
|
+
// QUEUE LANE LAW unchanged: no legacy (no flow.py read — existence
|
|
17
|
+
// rides this registry), no fallbacks, no hardcodes.
|
|
18
|
+
//
|
|
19
|
+
// Erasable-syntax TS only (node --experimental-strip-types).
|
|
20
|
+
import { isFile } from "./skillFs.js";
|
|
21
|
+
import { CARD_PLANE_ENGINE, LEGACY_RUN_MEDIA_PREFIX, RUN_MEDIA_PREFIX } from "@melite/contracts/benchStage";
|
|
22
|
+
import { join, resolve } from "node:path";
|
|
23
|
+
import { mediaVocab } from "./mediaKinds.js";
|
|
24
|
+
import { validateBakeParams } from "./bakeParams.js";
|
|
25
|
+
// ── shared builders ─────────────────────────────────────────────
|
|
26
|
+
export function initial(key) {
|
|
27
|
+
return { initial: key };
|
|
28
|
+
}
|
|
29
|
+
export function fromStage(stage, output) {
|
|
30
|
+
return { stage, output };
|
|
31
|
+
}
|
|
32
|
+
export function plainStage(row) {
|
|
33
|
+
return {
|
|
34
|
+
id: row.id,
|
|
35
|
+
engine: row.engine,
|
|
36
|
+
card: row.card ?? "",
|
|
37
|
+
family: row.family ?? "",
|
|
38
|
+
action: row.action ?? "",
|
|
39
|
+
description: row.description,
|
|
40
|
+
inputs: row.inputs,
|
|
41
|
+
expected: row.expected ?? {},
|
|
42
|
+
outputs: row.outputs ?? {},
|
|
43
|
+
cardIo: row.cardIo ?? {},
|
|
44
|
+
params: row.params,
|
|
45
|
+
skipWhen: row.skipWhen ?? null,
|
|
46
|
+
fromFlow: null,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function linkedStage(flow, stage, id, inputs) {
|
|
50
|
+
return {
|
|
51
|
+
id,
|
|
52
|
+
engine: "",
|
|
53
|
+
card: "",
|
|
54
|
+
family: "",
|
|
55
|
+
action: "",
|
|
56
|
+
description: "",
|
|
57
|
+
inputs,
|
|
58
|
+
expected: {},
|
|
59
|
+
outputs: {},
|
|
60
|
+
cardIo: {},
|
|
61
|
+
params: {},
|
|
62
|
+
skipWhen: null,
|
|
63
|
+
fromFlow: { flow, stage },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The craft loop (stroke 55, plan §2.3): ONE engine stage on
|
|
68
|
+
* 'craft' — act (a nested engine command) → capture (run-dir
|
|
69
|
+
* artifacts) → critique (the image-capable route, the capture
|
|
70
|
+
* attached) → decide (done | refine-with-next-command), bounded
|
|
71
|
+
* by max_iterations (default unlimited, hard cap 1000). The
|
|
72
|
+
* operator's card sketch verbatim: model dropdown, inputs
|
|
73
|
+
* (generic), prompt for the agent, optional max iterations. The
|
|
74
|
+
* stage params carry those four fields at DRIVE time (the agent
|
|
75
|
+
* composes them into the start doc; the registry row is the
|
|
76
|
+
* template + the agent leaf). */
|
|
77
|
+
/** The agent spawner (stroke 61, plan §5): ONE engine stage on
|
|
78
|
+
* 'agent' — a general tool-calling loop with the task as its brief
|
|
79
|
+
* (packages/engines/agent). The operator's card sketch verbatim:
|
|
80
|
+
* MCPs (blender, unity, custom), skills (dreamshot…), max turns
|
|
81
|
+
* (default unlimited), inputs (the plus-box list). The stage
|
|
82
|
+
* params carry those fields at DRIVE time; the registry row is
|
|
83
|
+
* the template + the agent leaf. */
|
|
84
|
+
import { BODY_TO_SOMAX, ANNY_HMR_ESTIMATOR, ANNY_PARAMS, AUDIO_NATIVE_TTS, CHARACTER_FACTORY, FIT_SEAT, IMAGE_UPSCALE, MUSIC_NATIVE, CRAFT_LOOP, OBJECT_FORGE, } from "./flowsRegistryRows.js";
|
|
85
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
86
|
+
const REGISTRY = {
|
|
87
|
+
"craft-loop": CRAFT_LOOP,
|
|
88
|
+
"anny-hmr-estimator": ANNY_HMR_ESTIMATOR,
|
|
89
|
+
"body-to-somax": BODY_TO_SOMAX,
|
|
90
|
+
"character-factory": CHARACTER_FACTORY,
|
|
91
|
+
"anny-params": ANNY_PARAMS,
|
|
92
|
+
"audio-native-tts": AUDIO_NATIVE_TTS,
|
|
93
|
+
"fit-seat": FIT_SEAT,
|
|
94
|
+
"image-upscale": IMAGE_UPSCALE,
|
|
95
|
+
"music-native": MUSIC_NATIVE,
|
|
96
|
+
"object-forge": OBJECT_FORGE,
|
|
97
|
+
};
|
|
98
|
+
/** A pure read-only seat over the boot seed (REGISTRY verbatim, no
|
|
99
|
+
* registration surface): the door for callers with no host fiber —
|
|
100
|
+
* pure rigs and the walls. Service-owning callers read the live
|
|
101
|
+
* seat instead (ctx.get("meliteFlows")).
|
|
102
|
+
* @returns the seeded FlowsSeat. */
|
|
103
|
+
export function seedFlowsSeat() {
|
|
104
|
+
const rows = new Map(Object.entries(REGISTRY));
|
|
105
|
+
return {
|
|
106
|
+
get: (name) => rows.get(name),
|
|
107
|
+
names: () => [...rows.keys()].sort(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** The live flow registry seat (J4 cure: the table is instance
|
|
111
|
+
* state, never a module global). */
|
|
112
|
+
export class FlowsSeatService extends Service {
|
|
113
|
+
static inject = [];
|
|
114
|
+
// TS-private, not #private: cordis ctx.get returns a proxy, and
|
|
115
|
+
// private-class-field reads die through it ("whose class did not
|
|
116
|
+
// declare it"). The models seat rides public fields the same way.
|
|
117
|
+
flows = new Map();
|
|
118
|
+
constructor(ctx) {
|
|
119
|
+
super(ctx, "meliteFlows");
|
|
120
|
+
// THE SEED ROWS ARE FIBER-OWNED (the models precedent:
|
|
121
|
+
// ctx.effect(() => ctx.models.registerFamily(DECL))): every row
|
|
122
|
+
// registers through the same interlocks as a live drop-in —
|
|
123
|
+
// disposing this service's fiber removes them.
|
|
124
|
+
for (const flow of Object.values(REGISTRY)) {
|
|
125
|
+
ctx.effect(() => this.register(flow));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** The raw (unexpanded) declaration, or undefined for unknown
|
|
129
|
+
* names. */
|
|
130
|
+
get(name) {
|
|
131
|
+
return this.flows.get(name);
|
|
132
|
+
}
|
|
133
|
+
/** All registered flow names, sorted. */
|
|
134
|
+
names() {
|
|
135
|
+
return [...this.flows.keys()].sort();
|
|
136
|
+
}
|
|
137
|
+
/** Register one flow into the live seat. LOUD: a duplicate id
|
|
138
|
+
* refuses (one owner per flow id — the same interlock as cards
|
|
139
|
+
* and model families); the stage and validator interlocks ride
|
|
140
|
+
* verbatim. Returns the disposer; call it (or dispose the
|
|
141
|
+
* ctx.effect that owns it) and the flow is gone from every
|
|
142
|
+
* read.
|
|
143
|
+
* @param flow - the declaration to seat.
|
|
144
|
+
* @returns the disposer removing exactly this row. */
|
|
145
|
+
register(flow) {
|
|
146
|
+
if (this.flows.has(flow.id)) {
|
|
147
|
+
throw new Error(`flow '${flow.id}' registered twice — one owner per flow id (the interlock)`);
|
|
148
|
+
}
|
|
149
|
+
if (!Array.isArray(flow.stages) || flow.stages.length === 0) {
|
|
150
|
+
throw new Error(`flow '${String(flow.id)}' has no stages — a flow is a pipeline, an empty one is authoring noise`);
|
|
151
|
+
}
|
|
152
|
+
// THE SEAM'S TWO HALVES MUST AGREE (registration, not first
|
|
153
|
+
// use): a required initial the flow does not also VALIDATE gets
|
|
154
|
+
// no shape check, and the extractor — which walks
|
|
155
|
+
// initialValidators — never lifts it, so the value would reach
|
|
156
|
+
// the merge unlinked and die there as an unresolvable token.
|
|
157
|
+
// Refuse the row at its one registration instead of at the
|
|
158
|
+
// door, sixty seconds later.
|
|
159
|
+
for (const key of flow.requiredInitials ?? []) {
|
|
160
|
+
if (flow.initialValidators[key] === undefined) {
|
|
161
|
+
throw new Error(`flow '${String(flow.id)}' requires initial '${key}' but declares no validator for it — ` +
|
|
162
|
+
"a required initial needs its kind (the gate shapes it; the extractor lifts it)");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// THE WIRED-INITIALS INTERLOCK (flows F3 — registration, not
|
|
166
|
+
// first use): every stage input edge naming an initial needs
|
|
167
|
+
// its validator too — the gate walks initialValidators only,
|
|
168
|
+
// and the extractor lifts declared keys only, so a
|
|
169
|
+
// wired-but-unvalidated initial would reach the merge unlinked
|
|
170
|
+
// and die there as an unresolvable token. Link stages carry
|
|
171
|
+
// their own winning inputs, so no target resolution is needed:
|
|
172
|
+
// the link's own edges are judged here. Refuse the row at its
|
|
173
|
+
// one registration instead of at the door, sixty seconds later.
|
|
174
|
+
for (const st of flow.stages) {
|
|
175
|
+
for (const edge of Object.values(st.inputs)) {
|
|
176
|
+
|
|
177
|
+
// concurrent session's F3 hunk, still WIP: the edge values
|
|
178
|
+
// are untyped here, so the initial lifts through a guarded
|
|
179
|
+
// unknown (their spec pins string initials only).
|
|
180
|
+
// Validators are keyed by name — only a string initial can
|
|
181
|
+
// name one, and the gate judges exactly what the refusal
|
|
182
|
+
// prints.
|
|
183
|
+
if (typeof edge !== "object" || edge === null)
|
|
184
|
+
continue;
|
|
185
|
+
if (!("initial" in edge))
|
|
186
|
+
continue;
|
|
187
|
+
const initial = edge.initial;
|
|
188
|
+
if (typeof initial !== "string")
|
|
189
|
+
continue;
|
|
190
|
+
if (flow.initialValidators[initial] === undefined) {
|
|
191
|
+
throw new Error(`flow '${String(flow.id)}' stage '${st.id}' wires initial '${initial}' but declares no validator for it — ` +
|
|
192
|
+
"a wired initial needs its kind (the gate shapes it; the extractor lifts it)");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// THE DRY-RUN (audit J-S1 — the gate was near-no-op): each
|
|
197
|
+
// stage's own composition shape is judged HERE, at the row's
|
|
198
|
+
// one registration, with the same gate expansion judges — a
|
|
199
|
+
// mis-shaped row dies at boot/live-add with its name, never at
|
|
200
|
+
// first compile. Cross-row wiring (from_flow targets) stays
|
|
201
|
+
// compile-time law: a link may name a flow that registers
|
|
202
|
+
// LATER, and demanding it now would break the boot order.
|
|
203
|
+
for (const st of flow.stages) {
|
|
204
|
+
if (st.fromFlow === null)
|
|
205
|
+
refuseRawWorkflowShape(flow.id, st);
|
|
206
|
+
}
|
|
207
|
+
this.flows.set(flow.id, flow);
|
|
208
|
+
return () => {
|
|
209
|
+
// only OUR row dies — a later registration under the same id
|
|
210
|
+
// (impossible today, the interlock above) would not be
|
|
211
|
+
// reverted
|
|
212
|
+
if (this.flows.get(flow.id) === flow)
|
|
213
|
+
this.flows.delete(flow.id);
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** Resolve every fromFlow row against its source flow (Stage.from_flow
|
|
218
|
+
* verbatim: the source row's engine/card/description/expected/
|
|
219
|
+
* outputs/card_io/params ride; the link's id + inputs win). Throws
|
|
220
|
+
* LOUD on a dangling link (authoring bug — never a silent row). */
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
export function refuseRawWorkflowShape(flowId, st) {
|
|
236
|
+
if (st.family !== "" && st.action === "") {
|
|
237
|
+
throw new Error("[flows_registry] flow " + flowId + " stage " + st.id +
|
|
238
|
+
" declares family " + st.family + " with no action — the family plane needs both (refused at expansion)");
|
|
239
|
+
}
|
|
240
|
+
if (st.card === "" && st.family === "" && st.action === "") {
|
|
241
|
+
if (st.engine !== CARD_PLANE_ENGINE)
|
|
242
|
+
return; // engine-verb stage — legal
|
|
243
|
+
throw new Error("[flows_registry] flow " + flowId + " stage " + st.id +
|
|
244
|
+
" names neither card nor family+action on engine " + st.engine +
|
|
245
|
+
" — the raw-workflow authoring shape is retired (refused at expansion, never served)");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
function detachStage(st) {
|
|
263
|
+
return {
|
|
264
|
+
...st,
|
|
265
|
+
params: structuredClone(st.params),
|
|
266
|
+
inputs: structuredClone(st.inputs),
|
|
267
|
+
expected: structuredClone(st.expected),
|
|
268
|
+
outputs: structuredClone(st.outputs),
|
|
269
|
+
cardIo: structuredClone(st.cardIo),
|
|
270
|
+
skipWhen: structuredClone(st.skipWhen),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
export function expandRegistryFlow(flow, seat) {
|
|
274
|
+
const stages = flow.stages.map((st) => {
|
|
275
|
+
if (st.fromFlow === null) {
|
|
276
|
+
refuseRawWorkflowShape(flow.id, st);
|
|
277
|
+
return detachStage(st);
|
|
278
|
+
}
|
|
279
|
+
const link = st.fromFlow;
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// flow registered live could never be a from_flow TARGET — the
|
|
283
|
+
// seat was write-only for expansion, and no wall could see it
|
|
284
|
+
// (the seed flow the walls clone has no links). A drop-in that
|
|
285
|
+
// registers a flow another flow links to is exactly the
|
|
286
|
+
// composition the door exists for. The seat rides the caller's
|
|
287
|
+
// param (J4): expansion reads the LIVE table, never a module
|
|
288
|
+
// global.
|
|
289
|
+
const src = seat.get(link.flow);
|
|
290
|
+
if (src === undefined) {
|
|
291
|
+
throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
|
|
292
|
+
" links unknown flow " + link.flow);
|
|
293
|
+
}
|
|
294
|
+
const base = src.stages.find((s) => s.id === link.stage);
|
|
295
|
+
if (base === undefined) {
|
|
296
|
+
throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
|
|
297
|
+
" links unknown stage " + link.flow + "/" +
|
|
298
|
+
link.stage);
|
|
299
|
+
}
|
|
300
|
+
if (base.fromFlow !== null) {
|
|
301
|
+
throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
|
|
302
|
+
" links a linked stage (single-hop only): " +
|
|
303
|
+
link.flow + "/" + link.stage);
|
|
304
|
+
}
|
|
305
|
+
return detachStage({ ...base, id: st.id, inputs: st.inputs });
|
|
306
|
+
});
|
|
307
|
+
return { ...flow, stages };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
export function inlineStagesNameCards(doc) {
|
|
314
|
+
const rows = doc["stages"];
|
|
315
|
+
if (!Array.isArray(rows))
|
|
316
|
+
return false;
|
|
317
|
+
return rows.some((r) => typeof r === "object" && r !== null &&
|
|
318
|
+
typeof r["card"] === "string" &&
|
|
319
|
+
r["card"] !== "");
|
|
320
|
+
}
|
|
321
|
+
/** The registry flow as a flow_from_body-shaped inline doc (the
|
|
322
|
+
* validate compile + start shim both ride the EXISTING inline
|
|
323
|
+
* pipelines — no second validator). Card rows ride card/card_io;
|
|
324
|
+
* skip_when rides verbatim. */
|
|
325
|
+
export function registryFlowToInline(flow) {
|
|
326
|
+
return {
|
|
327
|
+
id: flow.id,
|
|
328
|
+
description: flow.description,
|
|
329
|
+
stages: flow.stages.map((st) => {
|
|
330
|
+
const inputs = {};
|
|
331
|
+
for (const [name, edge] of Object.entries(st.inputs)) {
|
|
332
|
+
if ("initial" in edge)
|
|
333
|
+
inputs[name] = { initial: edge.initial };
|
|
334
|
+
else {
|
|
335
|
+
inputs[name] = {
|
|
336
|
+
stage: edge.stage,
|
|
337
|
+
output: edge.output,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const row = {
|
|
342
|
+
id: st.id,
|
|
343
|
+
engine: st.engine,
|
|
344
|
+
description: st.description,
|
|
345
|
+
inputs,
|
|
346
|
+
outputs: { ...st.outputs },
|
|
347
|
+
expected: { ...st.expected },
|
|
348
|
+
params: st.params,
|
|
349
|
+
};
|
|
350
|
+
if (st.card !== "")
|
|
351
|
+
row["card"] = st.card;
|
|
352
|
+
if (Object.keys(st.cardIo).length > 0)
|
|
353
|
+
row["card_io"] = { ...st.cardIo };
|
|
354
|
+
if (st.skipWhen !== null) {
|
|
355
|
+
row["skip_when"] = {
|
|
356
|
+
initial: st.skipWhen.initial,
|
|
357
|
+
when: st.skipWhen.when,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
return row;
|
|
361
|
+
}),
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/** Check one photo/glb initial value. Null = passes. */
|
|
365
|
+
function checkFileInitial(key, kind, value, roots) {
|
|
366
|
+
let ref;
|
|
367
|
+
if (typeof value === "string")
|
|
368
|
+
ref = value;
|
|
369
|
+
else if (typeof value === "object" && value !== null && !Array.isArray(value) &&
|
|
370
|
+
typeof value["path"] === "string") {
|
|
371
|
+
ref = value["path"];
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
return ("initial " + JSON.stringify(key) + " must be a file path string or " +
|
|
375
|
+
"{path: ...} (got " + (typeof value) + ")");
|
|
376
|
+
}
|
|
377
|
+
const raw = ref.trim();
|
|
378
|
+
if (raw.startsWith("data:") || raw.startsWith("blob:")) {
|
|
379
|
+
return ("initial " + JSON.stringify(key) +
|
|
380
|
+
" is browser-local (nothing to stage) — upload the file first: " +
|
|
381
|
+
"POST /v1/uploads, then pass its staged path");
|
|
382
|
+
}
|
|
383
|
+
// (split never yields [] — [0] is always a string here)
|
|
384
|
+
const dot = raw.split(/[?#]/)[0].lastIndexOf(".");
|
|
385
|
+
const ext = dot >= 0
|
|
386
|
+
? raw.split(/[?#]/)[0].slice(dot + 1).toLowerCase()
|
|
387
|
+
: "";
|
|
388
|
+
// The vocab is TYPED DATA now (mediaKinds.ts, REBUILD-7) — no
|
|
389
|
+
// repo-anchored kindsPath read survives the re-home.
|
|
390
|
+
const kinds = mediaVocab();
|
|
391
|
+
const allowed = kind === "photo" ? kinds.image : kinds.model;
|
|
392
|
+
if (!allowed.includes(ext)) {
|
|
393
|
+
return ("initial " + JSON.stringify(key) + " is not a stageable " +
|
|
394
|
+
(kind === "photo" ? "image" : "mesh") + " (got extension " +
|
|
395
|
+
JSON.stringify(ext) + ")");
|
|
396
|
+
}
|
|
397
|
+
if (raw.includes("..")) {
|
|
398
|
+
return "initial " + JSON.stringify(key) + " refuses traversal";
|
|
399
|
+
}
|
|
400
|
+
const runPrefixRef = runMediaPrefixRef(raw);
|
|
401
|
+
if (runPrefixRef !== "" && !runMediaRefWellformed(raw, runPrefixRef)) {
|
|
402
|
+
return ("initial " + JSON.stringify(key) +
|
|
403
|
+
" is a malformed artifact URL (want " + RUN_MEDIA_PREFIX + "/<run_id>/<file>)");
|
|
404
|
+
}
|
|
405
|
+
const cands = initialFileCandidates(raw, roots);
|
|
406
|
+
for (const cand of cands) {
|
|
407
|
+
if (isFile(cand))
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
return "initial " + JSON.stringify(key) + " is not on disk (" + raw + ")";
|
|
411
|
+
}
|
|
412
|
+
/** The run-media prefix `raw` carries — the live /melite-media/runs/
|
|
413
|
+
* or the legacy /v1/assets/runs/ spelling, else "" (the same pair
|
|
414
|
+
* the media route mounts and the bench heals, benchStage.ts). */
|
|
415
|
+
function runMediaPrefixRef(raw) {
|
|
416
|
+
const ASSET_RUNS_PREFIX = LEGACY_RUN_MEDIA_PREFIX + "/";
|
|
417
|
+
const MEDIA_RUNS_PREFIX = RUN_MEDIA_PREFIX + "/";
|
|
418
|
+
return raw.startsWith(MEDIA_RUNS_PREFIX)
|
|
419
|
+
? MEDIA_RUNS_PREFIX
|
|
420
|
+
: raw.startsWith(ASSET_RUNS_PREFIX) ? ASSET_RUNS_PREFIX : "";
|
|
421
|
+
}
|
|
422
|
+
/** A run-media ref names <run_id>/<file> — one slash beyond the
|
|
423
|
+
* prefix, no trailing slash, no empty segments. */
|
|
424
|
+
function runMediaRefWellformed(raw, runPrefix) {
|
|
425
|
+
const rel = raw.slice(runPrefix.length);
|
|
426
|
+
return !(rel === "" || rel.endsWith("/") || !rel.includes("/"));
|
|
427
|
+
}
|
|
428
|
+
/** The on-disk candidate paths one gate-blessed file initial may
|
|
429
|
+
* live at — the press gate's SAME trees, extracted so the
|
|
430
|
+
* claim-time re-probe (runsRegistry pump) judges by the identical
|
|
431
|
+
* set instead of re-spelling it. Contract: `raw` already passed
|
|
432
|
+
* checkFileInitial's shape gates (data:/blob:, extension vocab,
|
|
433
|
+
* traversal, malformed run-prefix URL) — this builds candidates
|
|
434
|
+
* only; a raw outside those gates gets a list that misses, which
|
|
435
|
+
* is the honest answer for a value the gate would have refused.
|
|
436
|
+
* @param raw the trimmed path reference ({path: …} unwrapped)
|
|
437
|
+
* @param roots the same roots manifest the press gate rode
|
|
438
|
+
* @returns the candidate paths, in the press gate's order */
|
|
439
|
+
export function initialFileCandidates(raw, roots) {
|
|
440
|
+
const cands = [];
|
|
441
|
+
|
|
442
|
+
// ever): the live /melite-media/runs/ and the legacy
|
|
443
|
+
// /v1/assets/runs/ that stored benches, archives and run rows
|
|
444
|
+
// still name. The media route serves both, so a chained input
|
|
445
|
+
// resolves whichever spelling it carries.
|
|
446
|
+
const runPrefix = runMediaPrefixRef(raw);
|
|
447
|
+
if (runPrefix !== "") {
|
|
448
|
+
const rel = raw.slice(runPrefix.length);
|
|
449
|
+
for (const root of [
|
|
450
|
+
join(roots.stateRoot, "output"),
|
|
451
|
+
join(roots.stateRoot, "test-output"),
|
|
452
|
+
join(roots.repoRoot, "data", "runs", "output"),
|
|
453
|
+
join(roots.repoRoot, "data", "runs", "test-output"),
|
|
454
|
+
]) {
|
|
455
|
+
cands.push(join(root, rel));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
else if (raw.startsWith("/")) {
|
|
459
|
+
cands.push(raw);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
cands.push(resolve(roots.repoRoot, raw));
|
|
463
|
+
cands.push(resolve(process.cwd(), raw));
|
|
464
|
+
}
|
|
465
|
+
return cands;
|
|
466
|
+
}
|
|
467
|
+
/** The compile-time gate over a registry flow's initial_validators:
|
|
468
|
+
* the first refusal text, or null when every PRESENT initial
|
|
469
|
+
* passes (absent initials ride — the $channel/branch arms own
|
|
470
|
+
* them). Runs BEFORE any run registers, on both doors. */
|
|
471
|
+
export function registryInitialsError(flow, body, roots) {
|
|
472
|
+
for (const [key, kind] of Object.entries(flow.initialValidators)) {
|
|
473
|
+
const value = body[key];
|
|
474
|
+
if (value === undefined || value === null)
|
|
475
|
+
continue;
|
|
476
|
+
if (kind === "bake_params") {
|
|
477
|
+
const s = typeof value === "string"
|
|
478
|
+
? value
|
|
479
|
+
: JSON.stringify(value);
|
|
480
|
+
if (s === undefined) {
|
|
481
|
+
return ("initial " + JSON.stringify(key) +
|
|
482
|
+
" must be a params_json string or object (got " +
|
|
483
|
+
(typeof value) + ")");
|
|
484
|
+
}
|
|
485
|
+
const err = validateBakeParams(s);
|
|
486
|
+
if (err !== null) {
|
|
487
|
+
return "initial " + JSON.stringify(key) + " refuses the preset dialect: " + err;
|
|
488
|
+
}
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
// A TEXT initial is a bare name, not a file: a bone, a rig slot.
|
|
492
|
+
// The engine's own gate is on emptiness; the door's is on shape,
|
|
493
|
+
// so a path can never arrive where a name belongs.
|
|
494
|
+
if (kind === "text") {
|
|
495
|
+
const text = typeof value === "string" ? value : "";
|
|
496
|
+
if (text.trim() === "") {
|
|
497
|
+
return "initial " + JSON.stringify(key) + " must be a non-empty name";
|
|
498
|
+
}
|
|
499
|
+
if (text.includes("..") || text.includes("/") || text.includes("\\")) {
|
|
500
|
+
return "initial " + JSON.stringify(key) +
|
|
501
|
+
" is a bare name (no path separators, no traversal)";
|
|
502
|
+
}
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
const err = checkFileInitial(key, kind, value, roots);
|
|
506
|
+
if (err !== null)
|
|
507
|
+
return err;
|
|
508
|
+
}
|
|
509
|
+
// A REQUIRED INITIAL refuses here, before a run registers (an
|
|
510
|
+
// optional one rides absent — the $channel/branch arms own it), and
|
|
511
|
+
// AFTER the present-value checks so a request carrying a bad value
|
|
512
|
+
// hears about THAT value first. The fit verb's bone is the case: the
|
|
513
|
+
// vendor's row gate refuses an empty one, so a request that omits it
|
|
514
|
+
// must learn that at the door, not sixty seconds into a render.
|
|
515
|
+
for (const key of flow.requiredInitials ?? []) {
|
|
516
|
+
const value = body[key];
|
|
517
|
+
if (value === undefined || value === null || value === "") {
|
|
518
|
+
return "initial " + JSON.stringify(key) +
|
|
519
|
+
" is REQUIRED by the " + JSON.stringify(flow.id) + " flow — " +
|
|
520
|
+
"this verb cannot run without it (name it in the request; the " +
|
|
521
|
+
"door refuses here rather than the engine refusing later)";
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
/** The initial VALUE one gate-blessed body entry carries, in the
|
|
527
|
+
* string form the engine merge links a $spell against: file
|
|
528
|
+
* initials give their path ({path: …} unwraps — the two spellings
|
|
529
|
+
* the gate blesses), bake_params gives its params_json string
|
|
530
|
+
* (objects stringify — the dialect the belt validates). Null
|
|
531
|
+
* refuses a shape the gate would have refused, so a mangled
|
|
532
|
+
* durable body fails loud at the door instead of shipping an
|
|
533
|
+
* "[object Object]" literal to the engine.
|
|
534
|
+
* @param key the initial's declared name, for the refusal voice
|
|
535
|
+
* @param kind the declared validator kind
|
|
536
|
+
* @param value the raw body entry
|
|
537
|
+
* @returns the normalized string, or null when the shape is neither */
|
|
538
|
+
export function normalizedInitialValue(key, kind, value) {
|
|
539
|
+
// A TEXT initial is a BARE NAME: nothing unwraps it and nothing
|
|
540
|
+
// path-shaped reaches it, so the {path: …} arm below never runs
|
|
541
|
+
|
|
542
|
+
// name, reachable only because every call site runs the gate
|
|
543
|
+
// first — this arm makes the extractor honest on its own.)
|
|
544
|
+
if (kind === "text")
|
|
545
|
+
return typeof value === "string" ? value : null;
|
|
546
|
+
if (typeof value === "string")
|
|
547
|
+
return value;
|
|
548
|
+
if (kind === "bake_params") {
|
|
549
|
+
// JSON.stringify(undefined) is undefined — the null-ish check
|
|
550
|
+
// in the caller skips absent entries before this arm.
|
|
551
|
+
const s = JSON.stringify(value);
|
|
552
|
+
return s === undefined ? null : s;
|
|
553
|
+
}
|
|
554
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value) &&
|
|
555
|
+
typeof value["path"] === "string") {
|
|
556
|
+
return value["path"];
|
|
557
|
+
}
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
/** The request initials a body carries for a flow's declared
|
|
561
|
+
* validators, normalized per {@link normalizedInitialValue}:
|
|
562
|
+
* declared keys, present values only; absent stays absent (the
|
|
563
|
+
* $channel/branch arms own those). First refusal text, or null
|
|
564
|
+
* when every present value normalizes. Both start doors (the
|
|
565
|
+
* flow arm and the flow_inline replay arm, which recovers the
|
|
566
|
+
* declaration from the inline doc's registry id) call this —
|
|
567
|
+
* the replayed durable body re-extracts the same values the
|
|
568
|
+
* original start extracted, so a queued run that reboots mid-
|
|
569
|
+
* queue keeps its $spells linkable at the engine merge.
|
|
570
|
+
* @param flow the declaration whose initialValidators own the keys
|
|
571
|
+
* @param body the request body
|
|
572
|
+
* @returns the normalized initials record, or a refusal string */
|
|
573
|
+
export function extractRequestInitials(flow, body) {
|
|
574
|
+
const initials = {};
|
|
575
|
+
for (const [key, kind] of Object.entries(flow.initialValidators)) {
|
|
576
|
+
const value = body[key];
|
|
577
|
+
if (value === undefined || value === null)
|
|
578
|
+
continue;
|
|
579
|
+
const normalized = normalizedInitialValue(key, kind, value);
|
|
580
|
+
if (normalized === null) {
|
|
581
|
+
return {
|
|
582
|
+
refusal: "initial " + JSON.stringify(key) +
|
|
583
|
+
(kind === "bake_params"
|
|
584
|
+
? " must be a params_json string or object (got " +
|
|
585
|
+
(typeof value) + ")"
|
|
586
|
+
: kind === "text"
|
|
587
|
+
? " must be a bare name (got " + (typeof value) + ")"
|
|
588
|
+
: " must be a file path string or {path: ...} (got " +
|
|
589
|
+
(typeof value) + ")"),
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
initials[key] = normalized;
|
|
593
|
+
}
|
|
594
|
+
return { initials };
|
|
595
|
+
}
|
|
596
|
+
// ── the skill-body render (REBUILD-16; the tail beyond the
|
|
597
|
+
// REBUILD-13 cut) ──
|
|
598
|
+
function edgeText(edge, flow, seat) {
|
|
599
|
+
// A REQUIRED INITIAL SAYS SO (the door refuses a request without
|
|
600
|
+
// it; the served body is where a caller learns that before they
|
|
601
|
+
// try). The flow's own requiredInitials list is the one truth.
|
|
602
|
+
if ("initial" in edge) {
|
|
603
|
+
return "initial '" + edge.initial + "'" +
|
|
604
|
+
((flow.requiredInitials ?? []).includes(edge.initial) ? " (REQUIRED)" : "");
|
|
605
|
+
}
|
|
606
|
+
const src = edge.stage + "." + edge.output;
|
|
607
|
+
let kind = "";
|
|
608
|
+
for (const st of flow.stages) {
|
|
609
|
+
const base = st.fromFlow !== null ? resolveLink(st, seat) : st;
|
|
610
|
+
if (base.id === edge.stage) {
|
|
611
|
+
kind = base.outputs[edge.output] ?? base.cardIo[edge.output] ?? "";
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return "stage " + src + (kind !== "" ? " (" + kind + ")" : "");
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
function resolveLink(st, seat) {
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
if (st.fromFlow === null) {
|
|
629
|
+
throw new Error("resolveLink: stage '" + st.id + "' carries no fromFlow link (caller guard missing)");
|
|
630
|
+
}
|
|
631
|
+
const link = st.fromFlow;
|
|
632
|
+
// the LIVE SEAT, same law as expandRegistryFlow above
|
|
633
|
+
const src = seat.get(link.flow);
|
|
634
|
+
if (src === undefined) {
|
|
635
|
+
throw new Error("registry: stage '" + st.id + "' links from unknown flow '" + link.flow +
|
|
636
|
+
"' (known flows: " + seat.names().join(", ") + ")");
|
|
637
|
+
}
|
|
638
|
+
const base = src.stages.find((s) => s.id === link.stage);
|
|
639
|
+
if (base === undefined) {
|
|
640
|
+
throw new Error("registry: stage '" + st.id + "' links from unknown stage '" + link.flow + "/" + link.stage +
|
|
641
|
+
"' (known stages: " + src.stages.map((s) => s.id).sort().join(", ") + ")");
|
|
642
|
+
}
|
|
643
|
+
return base;
|
|
644
|
+
}
|
|
645
|
+
/** Render one registry flow as its skill-body text. */
|
|
646
|
+
export function registrySkillBody(flow, seat) {
|
|
647
|
+
const lines = ["# flow " + flow.id, "", flow.description, "", "## stages"];
|
|
648
|
+
for (const st of flow.stages) {
|
|
649
|
+
const base = st.fromFlow !== null ? resolveLink(st, seat) : st;
|
|
650
|
+
let head = "- " + st.id + " (";
|
|
651
|
+
head += st.fromFlow !== null
|
|
652
|
+
? "from " + st.fromFlow.flow + "/" + st.fromFlow.stage
|
|
653
|
+
: base.engine + (base.card !== "" ? ", card " + base.card : "");
|
|
654
|
+
head += ")";
|
|
655
|
+
if (base.description !== "")
|
|
656
|
+
head += ": " + base.description;
|
|
657
|
+
lines.push(head);
|
|
658
|
+
for (const [name, edge] of Object.entries(st.inputs)) {
|
|
659
|
+
lines.push(" input " + name + ": " + edgeText(edge, flow, seat));
|
|
660
|
+
}
|
|
661
|
+
for (const [name, kind] of Object.entries(base.outputs)) {
|
|
662
|
+
lines.push(" output " + name + ": " + kind);
|
|
663
|
+
}
|
|
664
|
+
for (const [name, kind] of Object.entries(base.cardIo)) {
|
|
665
|
+
lines.push(" card_io " + name + ": " + kind);
|
|
666
|
+
}
|
|
667
|
+
if (st.skipWhen !== null) {
|
|
668
|
+
lines.push(" skip when initial '" + st.skipWhen.initial + "' is " + st.skipWhen.when);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return lines.join("\n") + "\n";
|
|
672
|
+
}
|
|
673
|
+
//# sourceMappingURL=flowsData.js.map
|