@melite/estate-queue 0.0.0-stage → 0.1.4-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +557 -0
  2. package/lib/bakeParams.d.ts +17 -0
  3. package/lib/bakeParams.js +182 -0
  4. package/lib/bench.d.ts +24 -0
  5. package/lib/bench.js +121 -0
  6. package/lib/cardsArmError.d.ts +18 -0
  7. package/lib/cardsArmError.js +33 -0
  8. package/lib/cardsCompose.d.ts +41 -0
  9. package/lib/cardsCompose.js +247 -0
  10. package/lib/cardsDangling.d.ts +16 -0
  11. package/lib/cardsDangling.js +168 -0
  12. package/lib/cardsFacts.d.ts +74 -0
  13. package/lib/cardsFacts.js +64 -0
  14. package/lib/cardsLanes.d.ts +33 -0
  15. package/lib/cardsLanes.js +115 -0
  16. package/lib/cardsRegistry.d.ts +316 -0
  17. package/lib/cardsRegistry.js +1274 -0
  18. package/lib/cardsVariant.d.ts +28 -0
  19. package/lib/cardsVariant.js +190 -0
  20. package/lib/discloseRegistry.d.ts +94 -0
  21. package/lib/discloseRegistry.js +154 -0
  22. package/lib/filmLead.d.ts +4 -0
  23. package/lib/filmLead.js +17 -0
  24. package/lib/filmMemoryWarn.d.ts +27 -0
  25. package/lib/filmMemoryWarn.js +99 -0
  26. package/lib/flowsData.d.ts +179 -0
  27. package/lib/flowsData.js +547 -0
  28. package/lib/flowsFamilyCompose.d.ts +48 -0
  29. package/lib/flowsFamilyCompose.js +191 -0
  30. package/lib/flowsRegistryRows.d.ts +10 -0
  31. package/lib/flowsRegistryRows.js +378 -0
  32. package/lib/index.d.ts +50 -0
  33. package/lib/index.js +66 -0
  34. package/lib/ledgerTail.d.ts +20 -0
  35. package/lib/ledgerTail.js +123 -0
  36. package/lib/loadPlane.d.ts +93 -0
  37. package/lib/loadPlane.js +553 -0
  38. package/lib/loadRegistry.d.ts +22 -0
  39. package/lib/loadRegistry.js +55 -0
  40. package/lib/manageOps.d.ts +21 -0
  41. package/lib/manageOps.js +142 -0
  42. package/lib/managePlane.d.ts +120 -0
  43. package/lib/managePlane.js +1515 -0
  44. package/lib/manageProbe.d.ts +57 -0
  45. package/lib/manageProbe.js +154 -0
  46. package/lib/manageRegistry.d.ts +28 -0
  47. package/lib/manageRegistry.js +75 -0
  48. package/lib/managerRail.d.ts +33 -0
  49. package/lib/managerRail.js +91 -0
  50. package/lib/mediaKinds.d.ts +3 -0
  51. package/lib/mediaKinds.js +2 -0
  52. package/lib/queue.d.ts +9 -0
  53. package/lib/queue.js +76 -0
  54. package/lib/queueCore.d.ts +69 -0
  55. package/lib/queueCore.js +124 -0
  56. package/lib/queueLifecycle.d.ts +26 -0
  57. package/lib/queueLifecycle.js +65 -0
  58. package/lib/queueLock.d.ts +54 -0
  59. package/lib/queueLock.js +195 -0
  60. package/lib/queueResurrect.d.ts +59 -0
  61. package/lib/queueResurrect.js +249 -0
  62. package/lib/queueRetry.d.ts +36 -0
  63. package/lib/queueRetry.js +24 -0
  64. package/lib/queueSidecar.d.ts +145 -0
  65. package/lib/queueSidecar.js +182 -0
  66. package/lib/queueSubmit.d.ts +31 -0
  67. package/lib/queueSubmit.js +117 -0
  68. package/lib/queueSweep.d.ts +30 -0
  69. package/lib/queueSweep.js +121 -0
  70. package/lib/resurrect.d.ts +6 -0
  71. package/lib/resurrect.js +18 -0
  72. package/lib/rootsManifest.d.ts +11 -0
  73. package/lib/rootsManifest.js +11 -0
  74. package/lib/runStatus.d.ts +7 -0
  75. package/lib/runStatus.js +21 -0
  76. package/lib/runsChange.d.ts +53 -0
  77. package/lib/runsChange.js +63 -0
  78. package/lib/runsErrorCodes.d.ts +2 -0
  79. package/lib/runsErrorCodes.js +15 -0
  80. package/lib/runsExecute.d.ts +26 -0
  81. package/lib/runsExecute.js +356 -0
  82. package/lib/runsGates.d.ts +161 -0
  83. package/lib/runsGates.js +306 -0
  84. package/lib/runsList.d.ts +78 -0
  85. package/lib/runsList.js +580 -0
  86. package/lib/runsRefusalVoices.d.ts +9 -0
  87. package/lib/runsRefusalVoices.js +44 -0
  88. package/lib/runsRegistry.d.ts +253 -0
  89. package/lib/runsRegistry.js +1750 -0
  90. package/lib/runsSourceEcho.d.ts +54 -0
  91. package/lib/runsSourceEcho.js +275 -0
  92. package/lib/runsStart.d.ts +121 -0
  93. package/lib/runsStart.js +528 -0
  94. package/lib/runsTypes.d.ts +183 -0
  95. package/lib/runsTypes.js +282 -0
  96. package/lib/runsValidate.d.ts +5 -0
  97. package/lib/runsValidate.js +31 -0
  98. package/lib/runsValidateArms.d.ts +7 -0
  99. package/lib/runsValidateArms.js +285 -0
  100. package/lib/runsValidateInline.d.ts +6 -0
  101. package/lib/runsValidateInline.js +82 -0
  102. package/lib/runsValidateRefusals.d.ts +7 -0
  103. package/lib/runsValidateRefusals.js +18 -0
  104. package/lib/runsValidateServe.d.ts +15 -0
  105. package/lib/runsValidateServe.js +254 -0
  106. package/lib/runsValidateShared.d.ts +84 -0
  107. package/lib/runsValidateShared.js +88 -0
  108. package/lib/runsValidateStages.d.ts +25 -0
  109. package/lib/runsValidateStages.js +491 -0
  110. package/lib/runsValidateSweeps.d.ts +6 -0
  111. package/lib/runsValidateSweeps.js +143 -0
  112. package/lib/service.d.ts +45 -0
  113. package/lib/service.js +81 -0
  114. package/lib/skillFrontmatter.d.ts +11 -0
  115. package/lib/skillFrontmatter.js +46 -0
  116. package/lib/skillFs.d.ts +19 -0
  117. package/lib/skillFs.js +80 -0
  118. package/lib/skillPlane.d.ts +98 -0
  119. package/lib/skillPlane.js +263 -0
  120. package/lib/skillRegistry.d.ts +23 -0
  121. package/lib/skillRegistry.js +55 -0
  122. package/lib/skillRows.d.ts +126 -0
  123. package/lib/skillRows.js +466 -0
  124. package/lib/toolProjection.d.ts +30 -0
  125. package/lib/toolProjection.js +142 -0
  126. package/lib/vocab.d.ts +6 -0
  127. package/lib/vocab.js +18 -0
  128. package/package.json +47 -4
  129. package/README.md +0 -3
@@ -0,0 +1,249 @@
1
+ import { parseSidecar } from "./queueSidecar.js";
2
+ // queueResurrect.ts — resurrection planning + strict JSON reads
3
+ // (boot tolerance for on-disk records; lenient arms deleted
4
+
5
+ //
6
+ // Erasable-syntax TS only (node --experimental-strip-types): no
7
+ // enums, import type for types, .ts specifiers for relative imports.
8
+ import { readFileSync, readdirSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ /** input_from refs for a NodeRow: arrays ride element-wise;
11
+ * falsy rides []; anything else is the raise road (the caller
12
+ * orphans the record). */
13
+ export function refList(value) {
14
+ const src = value ? value : [];
15
+ if (Array.isArray(src))
16
+ return [...src];
17
+ return null;
18
+ }
19
+ /** entries for the row maps: plain objects ride their entries;
20
+ * falsy rides {}; anything else is the raise road. */
21
+ export function recordEntries(value) {
22
+ const src = value ? value : {};
23
+ if (typeof src === "object" && src !== null && !Array.isArray(src)) {
24
+ return Object.entries(src);
25
+ }
26
+ return null;
27
+ }
28
+ /** One graph row usable: id/type are non-empty strings;
29
+ * input_from rides refList with every ref a non-blank string;
30
+ * input_names/outputs ride recordEntries with string values;
31
+ * duplicate node ids refuse. seen carries the gate across rows. */
32
+ export function nodeRowUsable(row, seen) {
33
+ if (typeof row !== "object" || row === null || Array.isArray(row)) {
34
+ return false;
35
+ }
36
+ const rec = row;
37
+ const id = rec["id"];
38
+ const type = rec["type"];
39
+ if (typeof id !== "string" || id === "")
40
+ return false;
41
+ if (typeof type !== "string" || type === "")
42
+ return false;
43
+ if (seen.has(id))
44
+ return false;
45
+ const refs = refList(rec["input_from"]);
46
+ if (refs === null)
47
+ return false;
48
+ for (const ref of refs) {
49
+ if (typeof ref !== "string" || ref.trim() === "")
50
+ return false;
51
+ }
52
+ for (const key of ["input_names", "outputs"]) {
53
+ const entries = recordEntries(rec[key]);
54
+ if (entries === null)
55
+ return false;
56
+ for (const entry of entries) {
57
+ if (typeof entry[1] !== "string")
58
+ return false;
59
+ }
60
+ }
61
+ if (recordEntries(rec["params"]) === null)
62
+ return false;
63
+ seen.add(id);
64
+ return true;
65
+ }
66
+ /** The durable graph check (doc.get("graph") or [] 2324): falsy
67
+ * (missing/None/False/0/"") rides the empty FlowGraph — zero nodes
68
+ * construct fine, so the record resurrects; a truthy non-list dies
69
+ * iterating (strings/dicts/numbers orphan); every row must be
70
+ * NodeRow-usable (extra keys ignored, mistypes orphan). */
71
+ export function graphRowsUsable(graph) {
72
+ const rows = graph ? graph : [];
73
+ if (!Array.isArray(rows))
74
+ return false;
75
+ const seen = new Set();
76
+ for (const row of rows) {
77
+ if (!nodeRowUsable(row, seen))
78
+ return false;
79
+ }
80
+ return true;
81
+ }
82
+ /** list coerce for stages/skipped: arrays ride; falsy rides [];
83
+ * anything else throws (the raise road: plan + build agree on the
84
+ * skip, never throw out). */
85
+ export function sidecarList(value) {
86
+ const src = value ? value : [];
87
+ if (Array.isArray(src))
88
+ return [...src];
89
+ throw new Error("unlistable sidecar value");
90
+ }
91
+ /** artifact names: the sidecar list filtered to non-empty strings. */
92
+ export function artifactStrings(value) {
93
+ return sidecarList(value)
94
+ .filter((a) => typeof a === "string" && a !== "")
95
+ .map((a) => a);
96
+ }
97
+ /** created_at coerce: finite numbers ride; numeric strings parse;
98
+ * everything else rides 0 and never throws (boot order for
99
+ * records without a usable timestamp). */
100
+ export function coerceCreatedAt(value) {
101
+ if (typeof value === "number") {
102
+ return Number.isFinite(value) ? value : 0;
103
+ }
104
+ if (typeof value === "string") {
105
+ const s = value.trim();
106
+ if (s === "")
107
+ return 0;
108
+ if (/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(s)) {
109
+ return Number(s);
110
+ }
111
+ return 0;
112
+ }
113
+ return 0;
114
+ }
115
+
116
+
117
+
118
+
119
+
120
+ export function durableRecordUsable(sidecarText, requestText, draftExists) {
121
+ let doc = null;
122
+ try {
123
+ // THE SIDECAR'S READ CONTRACT (parseSidecar): this reader decides
124
+ // whether a run may be RESURRECTED from its sidecar, so a doc
125
+ // whose stages are not addressable rows must answer false — the
126
+ // resurrect law's own precondition, not a downstream find().
127
+ // the parse JUDGES the shape and returns the row VERBATIM
128
+ doc = parseSidecar(JSON.parse(sidecarText))?.request ?? null;
129
+ }
130
+ catch {
131
+ return false;
132
+ }
133
+ if (doc === null) {
134
+ return false;
135
+ }
136
+ const rec = doc;
137
+ const draftId = rec["draft_id"];
138
+ if (typeof draftId !== "string" || draftId === "" || !draftExists) {
139
+ return false;
140
+ }
141
+ // _request.json needs only to PARSE (no validation — a list/
142
+ // str/num request rebuilds fine. A later lookup crash lands at
143
+ // worker/serve time, never at resurrect — an object-only check
144
+ // here would orphan records resurrect saves).
145
+ try {
146
+ JSON.parse(requestText);
147
+ }
148
+ catch {
149
+ return false;
150
+ }
151
+ if (!graphRowsUsable(rec["graph"]))
152
+ return false;
153
+ // stages/skipped/artifacts listifiability: the list check
154
+ // sits OUTSIDE the rebuild try (a non-array skips the
155
+ // record at boot). The predicate agrees with the replay road
156
+ // (the service's bootReconcile re-reads through the start door)
157
+ // so plan order never admits a row the replay cannot carry.
158
+ try {
159
+ sidecarList(rec["stages"]);
160
+ sidecarList(rec["skipped_stages"]);
161
+ artifactStrings(rec["artifacts"]);
162
+ }
163
+ catch {
164
+ return false;
165
+ }
166
+ return true;
167
+ }
168
+ /** Plan the resurrect (fs reads + order; the caller appends +
169
+ * ledgers, or use bootResurrect below for the whole seam). */
170
+ export function planResurrect(stateRoot, readSidecar = (runId) => {
171
+ try {
172
+ return readFileSync(join(stateRoot, "output", runId, "_flow.json"), "utf8");
173
+ }
174
+ catch {
175
+ return null;
176
+ }
177
+ }, readRequest = (runId) => {
178
+ try {
179
+ return readFileSync(join(stateRoot, "output", runId, "_request.json"), "utf8");
180
+ }
181
+ catch {
182
+ return null;
183
+ }
184
+ }, draftExists = () => {
185
+
186
+ // legacy drafts/<id>.json probe is dead — the drafts domain
187
+ // owns existence now. Callers pass their domain probe (the
188
+ // queue lane fails loud, never silently drops to no drafts).
189
+ throw new Error("[gateway-ts] planResurrect needs the caller's draftExists probe (drafts domain)");
190
+ }) {
191
+ const outRoot = join(stateRoot, "output");
192
+ let names;
193
+ try {
194
+ names = readdirSync(outRoot);
195
+ }
196
+ catch {
197
+ return { order: [], orphans: [] };
198
+ }
199
+ const candidates = [];
200
+ const orphans = [];
201
+ for (const name of names.sort()) {
202
+ if (!name.startsWith("run-"))
203
+ continue;
204
+ const text = readSidecar(name);
205
+ if (text === null)
206
+ continue;
207
+ let doc = null;
208
+ try {
209
+ doc = JSON.parse(text);
210
+ }
211
+ catch {
212
+
213
+ // row — it belongs in orphans (the operator's reconcile
214
+ // road), never dropped from both order and orphans. The old
215
+ // bare continue made the run invisible to resurrection.
216
+ orphans.push(name);
217
+ continue;
218
+ }
219
+ if (typeof doc !== "object" || doc === null || Array.isArray(doc)) {
220
+ orphans.push(name);
221
+ continue;
222
+ }
223
+ const rec = doc;
224
+ if (rec["status"] !== "queued")
225
+ continue;
226
+ const createdNum = coerceCreatedAt(rec["created_at"]);
227
+ const draftId = rec["draft_id"];
228
+ const req = readRequest(name);
229
+ const usable = req !== null &&
230
+ durableRecordUsable(text, req, typeof draftId === "string" && draftId !== ""
231
+ ? draftExists(draftId)
232
+ : false);
233
+ if (!usable) {
234
+ orphans.push(name);
235
+ continue;
236
+ }
237
+ // The durable/file brand door: the dir name IS the run id,
238
+ // admitted only past the run- prefix, the sidecar parse and the
239
+ // usable-request check above (the dsh-brand convention: the
240
+ // cast lives at the validating boundary, never at consumers).
241
+ candidates.push({ created: createdNum, runId: name });
242
+ }
243
+ candidates.sort((a, b) => a.created - b.created);
244
+ return { order: candidates.map((c) => c.runId), orphans };
245
+ }
246
+ /** One rebuilt queued run — RETIRED (stroke 83): the hollow
247
+ * requeue road is deleted; the service's bootReconcile REPLAYS _request.json
248
+ * through the start door so revived rows carry REAL params. */
249
+ //# sourceMappingURL=queueResurrect.js.map
@@ -0,0 +1,36 @@
1
+ export interface RetryAsk {
2
+ readonly attempt: number;
3
+ readonly maxExtra: number;
4
+ readonly stopSet: boolean;
5
+ }
6
+ export interface RetryNote {
7
+ /** The stage-row stamp (retries_used + retry_last_error). */
8
+ readonly stagePatch: {
9
+ retries_used: number;
10
+ retry_last_error: string;
11
+ };
12
+ /** The durable row: ledger("run.stage_retry", ...). */
13
+ readonly ledgerEvent: string;
14
+ readonly ledgerData: {
15
+ run_id: string;
16
+ stage: string;
17
+ attempt: number;
18
+ error: string;
19
+ };
20
+ /** The live row: publish(run_id, stage/…/retry). Key order . */
21
+ readonly busFrame: {
22
+ type: string;
23
+ stage: string;
24
+ index: number;
25
+ retry: number;
26
+ };
27
+ }
28
+ /** Continue-or-raise: a failed attempt re-runs while
29
+ * attempts remain AND no stop landed; a deliberate STOP never
30
+ * retries (both the exception arm 1754 and the error-dict arm
31
+ * 1775-1778 gate on the stop flag). */
32
+ export declare function shouldRetry(ask: RetryAsk): boolean;
33
+ /** One documented retry: sidecar row + events bus +
34
+ * ledger — never a silent re-run. */
35
+ export declare function noteStageRetry(runId: string, stageId: string, stageIndex: number, attempt: number, why: string): RetryNote;
36
+ //# sourceMappingURL=queueRetry.d.ts.map
@@ -0,0 +1,24 @@
1
+
2
+ // pure move, zero logic changes — the queue.ts barrel re-exports
3
+ // every symbol, so the public surface is byte-identical).
4
+ //
5
+ // Erasable-syntax TS only (node --experimental-strip-types): no
6
+ // enums, import type for types, .ts specifiers for relative imports.
7
+ /** Continue-or-raise: a failed attempt re-runs while
8
+ * attempts remain AND no stop landed; a deliberate STOP never
9
+ * retries (both the exception arm 1754 and the error-dict arm
10
+ * 1775-1778 gate on the stop flag). */
11
+ export function shouldRetry(ask) {
12
+ return ask.attempt < ask.maxExtra && !ask.stopSet;
13
+ }
14
+ /** One documented retry: sidecar row + events bus +
15
+ * ledger — never a silent re-run. */
16
+ export function noteStageRetry(runId, stageId, stageIndex, attempt, why) {
17
+ return {
18
+ stagePatch: { retries_used: attempt, retry_last_error: why },
19
+ ledgerEvent: "run.stage_retry",
20
+ ledgerData: { run_id: runId, stage: stageId, attempt, error: why },
21
+ busFrame: { type: "stage", stage: stageId, index: stageIndex, retry: attempt },
22
+ };
23
+ }
24
+ //# sourceMappingURL=queueRetry.js.map
@@ -0,0 +1,145 @@
1
+ export interface GraphRow {
2
+ readonly id: string;
3
+ readonly type: string;
4
+ readonly input_from: readonly string[];
5
+ readonly input_names: Record<string, unknown>;
6
+ readonly outputs: Record<string, unknown>;
7
+ readonly params: Record<string, unknown>;
8
+ }
9
+ export interface SidecarStage {
10
+ readonly id: string;
11
+ readonly name: string;
12
+ readonly index: number;
13
+ readonly status: string;
14
+ readonly engine?: string;
15
+ readonly url?: string;
16
+ readonly gallery?: Array<{
17
+ name: string;
18
+ }>;
19
+ readonly result_outputs?: Record<string, unknown>;
20
+ readonly error?: string;
21
+ readonly merged?: boolean;
22
+ readonly outputs: Record<string, unknown>;
23
+ readonly expected: Record<string, unknown>;
24
+ }
25
+ export declare function sidecarStageOf(stage: {
26
+ readonly id: string;
27
+ readonly name: string;
28
+ readonly index: number;
29
+ readonly status: string;
30
+ readonly engine?: string;
31
+ readonly outputs?: Record<string, unknown>;
32
+ readonly expected?: Record<string, unknown>;
33
+ readonly [key: string]: unknown;
34
+ }): SidecarStage;
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ export declare function variantOfBodies(bodies: unknown[]): string | undefined;
47
+ /** The sidecar document: KEY ORDER as (run_id, status, error,
48
+ * stages, skipped_stages, artifacts, created_at, test, draft_id,
49
+ * pipeline, graph). error rides the JSON error capped at 20000 chars when
50
+ * set (a JSON-quoted string — the writer quirk, mirrored, never
51
+ * "fixed"), else "". */
52
+ export declare function sidecarDoc(args: {
53
+ runId: string;
54
+ status: string;
55
+ error: string;
56
+ stages: SidecarStage[];
57
+ skippedStages: string[];
58
+ artifacts: string[];
59
+ createdAt: number;
60
+ testFlag: boolean;
61
+ draftId: string;
62
+ pipeline: string;
63
+ graph: GraphRow[];
64
+ /** THE SNAPSHOT KEYS (strokes 45/45d, carried stroke 48): the exact
65
+ * card + bench that ran. Absent when unstamped (inline runs)
66
+ * the pinned prefix above never shifts. */
67
+ cardSnapshot?: unknown;
68
+ benchSnapshot?: unknown;
69
+ /** F-6(b) ADMISSION WARNINGS (the film lane's VRAM-pressure
70
+ * warn): the status row spells it `warnings` too — one spelling
71
+ * on disk and on the wire. Absent when none were stamped. */
72
+ warnings?: string[];
73
+
74
+
75
+
76
+
77
+
78
+ composeEcho?: {
79
+ seam: string;
80
+ calls: number;
81
+ benchRev: number | null;
82
+ };
83
+
84
+
85
+
86
+
87
+ sourceEcho?: {
88
+ refs: Array<{
89
+ url: string;
90
+ file: string;
91
+ }>;
92
+ };
93
+ /** THE EXPORT NAME (023's self-critique #4/#6): the voice_name
94
+ * the design/export lane minted. The status row spells it
95
+ * `export_name` too. Absent on non-export runs. */
96
+ exportName?: string;
97
+
98
+
99
+
100
+
101
+ exportPath?: string;
102
+
103
+
104
+
105
+
106
+ variant?: string;
107
+
108
+
109
+
110
+ loudness?: {
111
+ loudness_lufs: number;
112
+ peak_db: number;
113
+ };
114
+ voiceFreshness?: {
115
+ reused_existing: boolean;
116
+ voice_file: string;
117
+ };
118
+ }): Record<string, unknown>;
119
+ /** The door name the run started with (_pipeline_of 2111-2119:
120
+ * exactly one of flow | flow_inline | model — the sidecar's
121
+ * `pipeline` and the queued ledger row share this one truth). */
122
+ export declare function pipelineOf(request: {
123
+ flow?: unknown;
124
+ model?: unknown;
125
+ flow_inline?: unknown;
126
+ }): string;
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+ export declare function parseSidecar(raw: unknown): {
141
+ stages: Array<Record<string, unknown>>;
142
+ pipeline: string;
143
+ request: Record<string, unknown>;
144
+ } | null;
145
+ //# sourceMappingURL=queueSidecar.d.ts.map
@@ -0,0 +1,182 @@
1
+
2
+ // pure move, zero logic changes — the queue.ts barrel re-exports
3
+ // every symbol, so the public surface is byte-identical).
4
+ //
5
+ // Erasable-syntax TS only (node --experimental-strip-types): no
6
+ // enums, import type for types, .ts specifiers for relative imports.
7
+ export function sidecarStageOf(stage) {
8
+ const out = {
9
+ id: stage.id,
10
+ name: stage.name,
11
+ index: stage.index,
12
+ status: stage.status,
13
+ outputs: stage.outputs ?? {},
14
+ expected: stage.expected ?? {},
15
+ };
16
+ if (typeof stage.engine === 'string')
17
+ out.engine = stage.engine;
18
+ if (typeof stage.url === 'string')
19
+ out.url = stage.url;
20
+ if (Array.isArray(stage.gallery)) {
21
+ const gallery = stage.gallery.filter((entry) => typeof entry === 'object' && entry !== null && !Array.isArray(entry)
22
+ && typeof entry.name === 'string'
23
+ && entry.name !== '');
24
+ if (gallery.length > 0)
25
+ out.gallery = gallery;
26
+ }
27
+ if (typeof stage.result_outputs === 'object' && stage.result_outputs !== null && !Array.isArray(stage.result_outputs)) {
28
+ out.result_outputs = stage.result_outputs;
29
+ }
30
+ if (typeof stage.error === 'string')
31
+ out.error = stage.error;
32
+ if (stage.merged === true)
33
+ out.merged = true;
34
+ return out;
35
+ }
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ export function variantOfBodies(bodies) {
48
+ for (const p of bodies) {
49
+ if (p === null || typeof p !== "object" || Array.isArray(p))
50
+ continue;
51
+ const v = p["variant"];
52
+ if (typeof v === "string" && v.trim() !== "")
53
+ return v.trim();
54
+ }
55
+ return undefined;
56
+ }
57
+ /** The sidecar document: KEY ORDER as (run_id, status, error,
58
+ * stages, skipped_stages, artifacts, created_at, test, draft_id,
59
+ * pipeline, graph). error rides the JSON error capped at 20000 chars when
60
+ * set (a JSON-quoted string — the writer quirk, mirrored, never
61
+ * "fixed"), else "". */
62
+ export function sidecarDoc(args) {
63
+ return {
64
+ // IDENTITY KEYS FIRST (stroke 82): buildRunCard and the listRuns
65
+ // scan slice(0, 8191) the sidecar — with stages/error/graph in
66
+ // the prefix, any bulky payload pushed created_at/draft_id/
67
+ // pipeline past the window and the row listed as a zombie
68
+ // (empty pipeline, draft cleared, created 0). The scalars ride
69
+ // ahead of every payload; a big error or graph can only
70
+ // truncate what follows it.
71
+ run_id: args.runId,
72
+ status: args.status,
73
+ created_at: args.createdAt,
74
+ test: args.testFlag,
75
+ draft_id: args.draftId,
76
+ pipeline: args.pipeline,
77
+ // THE STAGE-ID DIGEST (commission 015, §6 finding 6): the ids of
78
+ // the stages THIS run composed, CSV-compact, riding with the
79
+ // identity scalars AHEAD of every payload — the list row's
80
+ // 8191-byte window cannot reach the stages array, but it always
81
+ // reaches this. Derived from the very stages the doc stores, so
82
+ // digest and array can never disagree; every writer (queued,
83
+ // settled, resurrect) shares this one seat.
84
+ stage_ids: args.stages.map((s) => s.id).filter((id) => id !== "").join(","),
85
+ ...(args.exportName !== undefined && args.exportName !== "" ? { export_name: args.exportName } : {}),
86
+ ...(args.exportPath !== undefined && args.exportPath !== "" ? { export_path: args.exportPath } : {}),
87
+ ...(args.variant !== undefined && args.variant !== "" ? { variant: args.variant } : {}),
88
+ ...(args.loudness !== undefined ? { loudness: args.loudness } : {}),
89
+ ...(args.voiceFreshness !== undefined ? { voice_freshness: args.voiceFreshness } : {}),
90
+ error: args.error !== "" ? JSON.stringify(args.error).slice(0, 20000) : "",
91
+ stages: args.stages,
92
+ skipped_stages: [...args.skippedStages],
93
+ artifacts: [...args.artifacts],
94
+ graph: args.graph,
95
+ ...(args.cardSnapshot !== undefined ? { card_snapshot: args.cardSnapshot } : {}),
96
+ ...(args.benchSnapshot !== undefined ? { bench_snapshot: args.benchSnapshot } : {}),
97
+ ...(args.warnings !== undefined && args.warnings.length > 0 ? { warnings: [...args.warnings] } : {}),
98
+ ...(args.composeEcho !== undefined ? { compose_echo: args.composeEcho } : {}),
99
+ ...(args.sourceEcho !== undefined ? { source_echo: args.sourceEcho } : {}),
100
+ };
101
+ }
102
+ /** The door name the run started with (_pipeline_of 2111-2119:
103
+ * exactly one of flow | flow_inline | model — the sidecar's
104
+ * `pipeline` and the queued ledger row share this one truth). */
105
+ export function pipelineOf(request) {
106
+ if (typeof request.flow === "string" && request.flow !== "") {
107
+ return request.flow;
108
+ }
109
+ if (typeof request.model === "string" && request.model !== "") {
110
+ return request.model;
111
+ }
112
+ const inline = request.flow_inline;
113
+ if (typeof inline === "object" &&
114
+ inline !== null &&
115
+ typeof inline.id === "string") {
116
+ return inline.id;
117
+ }
118
+ return "";
119
+ }
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ export function parseSidecar(raw) {
134
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
135
+ return null;
136
+ const doc = raw;
137
+ // the STAGES: an array of records, each with a STRING id (the one
138
+ // field every reader keys on) — a row without one cannot be found
139
+ // by id and is refused rather than silently invisible
140
+ const rawStages = doc["stages"];
141
+ const stages = [];
142
+ if (rawStages !== undefined && rawStages !== null) {
143
+ if (!Array.isArray(rawStages))
144
+ return null;
145
+ for (const s of rawStages) {
146
+ if (s === null || typeof s !== "object" || Array.isArray(s))
147
+ return null;
148
+ const row = s;
149
+ if (typeof row["id"] !== "string" || row["id"] === "")
150
+ return null;
151
+ stages.push(row);
152
+ }
153
+ }
154
+ // the REQUEST: a record when present — and it is what `request`
155
+ // returns (the check was dead theater: it validated the key, then
156
+
157
+ const rawRequest = doc["request"];
158
+ if (rawRequest !== undefined && rawRequest !== null) {
159
+ if (typeof rawRequest !== "object" || Array.isArray(rawRequest))
160
+ return null;
161
+ }
162
+ // CONTENT typing (strictness fix 7): `pipeline` and `status` are
163
+ // strings when PRESENT. Absent keys stay legal — the file-era
164
+ // convention (found-ness matters; absent pipeline is "" to the
165
+ // list reader). A present-but-non-string value is corruption the
166
+ // old parse silently retyped: `pipeline: 42` became "" and served.
167
+ if (doc["pipeline"] !== undefined && typeof doc["pipeline"] !== "string")
168
+ return null;
169
+ if (doc["status"] !== undefined && typeof doc["status"] !== "string")
170
+ return null;
171
+ return {
172
+ // the CALLER's own row, fields intact (this judges the shape; it
173
+ // never rebuilds a sidecar — a settle carries the old row's own
174
+ // faces forward, and a rebuild would drop them)
175
+ stages: Array.isArray(rawStages) ? rawStages : [],
176
+ pipeline: typeof doc["pipeline"] === "string" ? doc["pipeline"] : "",
177
+ request: rawRequest !== undefined && rawRequest !== null
178
+ ? rawRequest
179
+ : doc,
180
+ };
181
+ }
182
+ //# sourceMappingURL=queueSidecar.js.map
@@ -0,0 +1,31 @@
1
+ export interface QueueRefusal {
2
+ readonly status: number;
3
+ readonly payload: Record<string, unknown>;
4
+ }
5
+ export declare function refusal(status: number, error: string, code: string, loc?: string, expected?: string, got?: string): QueueRefusal;
6
+ /** Draft id rule (draftIdOk in @melite/estate-drafts, re-exported below): <=96 chars of [A-Za-z0-9_-]. */
7
+ /** This core re-checks nothing: it BUILDS the refusal for a caller-computed verdict (the check is one regex, owned by the drafts package so envelope validation is whole). */
8
+ /** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see validateSubmitEnvelope. */
9
+
10
+
11
+
12
+
13
+
14
+
15
+ export { draftIdOk } from "@melite/estate-drafts";
16
+ export { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS, } from "./vocab.js";
17
+ /** The strict-body gate (_strict_body 248-276). */
18
+ export declare function strictBodyCheck(body: Record<string, unknown>): QueueRefusal | null;
19
+ /** Door-selection order (resolve_request 302: flow/flow_inline/
20
+ * model fixed order — ambiguity lists in DOOR order, not sorted). */
21
+ export declare const SUBMIT_DOORS: readonly string[];
22
+ /** The whole pre-registration chain in order: non-object body
23
+ * (bad_envelope/body) -> non-bool test (bad_envelope/test) ->
24
+ * draft required (draft_required) -> malformed (draft_malformed)
25
+ * -> unknown doc (draft_unknown) -> strict knobs/carry ->
26
+ * ambiguity (verbatim) -> no-door. draftExists is the caller's
27
+ * `drafts/<id>.json is_file` probe (existence is I/O — the core
28
+ * owns the TEXT, the door owns the fs). Returns null when the
29
+ * envelope may proceed to graph resolution. */
30
+ export declare function validateSubmitEnvelope(doc: unknown, draftExists: (draftId: string) => boolean): QueueRefusal | null;
31
+ //# sourceMappingURL=queueSubmit.d.ts.map