@tangle-network/agent-runtime 0.165.0 → 0.166.0
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/dist/{activation-DmUIq51m.js → activation-BkO0p4I1.js} +2 -2
- package/dist/{activation-DmUIq51m.js.map → activation-BkO0p4I1.js.map} +1 -1
- package/dist/agent.js +2 -2
- package/dist/{authoring-Cm122Duf.js → authoring-Bt17KOML.js} +2 -2
- package/dist/{authoring-Cm122Duf.js.map → authoring-Bt17KOML.js.map} +1 -1
- package/dist/durable.js +1 -1
- package/dist/graph-E0U0c2YP.js +2668 -0
- package/dist/graph-E0U0c2YP.js.map +1 -0
- package/dist/graph.d.ts +179 -15
- package/dist/graph.js +2 -1819
- package/dist/{improvement-cycle-BOd5DFeG.js → improvement-cycle-BAWOyeTA.js} +3 -3
- package/dist/{improvement-cycle-BOd5DFeG.js.map → improvement-cycle-BAWOyeTA.js.map} +1 -1
- package/dist/index.js +7 -7
- package/dist/intelligence.js +3 -3
- package/dist/kernel.js +6 -6
- package/dist/{knowledge-7_IfyD9R.js → knowledge-Bhhz6lvH.js} +3 -3
- package/dist/{knowledge-7_IfyD9R.js.map → knowledge-Bhhz6lvH.js.map} +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-Dx-5GZQK.js → loop-runner-bin-BQnpSn0h.js} +3 -3
- package/dist/{loop-runner-bin-Dx-5GZQK.js.map → loop-runner-bin-BQnpSn0h.js.map} +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.js +4 -4
- package/dist/{openai-tools-CDS7eSww.js → openai-tools-t6spVYKL.js} +2 -2
- package/dist/{openai-tools-CDS7eSww.js.map → openai-tools-t6spVYKL.js.map} +1 -1
- package/dist/{runtime-DESENUe1.js → runtime-BJoNta1Y.js} +6 -6
- package/dist/{runtime-DESENUe1.js.map → runtime-BJoNta1Y.js.map} +1 -1
- package/dist/{structural-rollout-DZGDg0yX.js → structural-rollout-B5E0mWCH.js} +2 -2
- package/dist/{structural-rollout-DZGDg0yX.js.map → structural-rollout-B5E0mWCH.js.map} +1 -1
- package/dist/{supervise-Da20R0PO.js → supervise-CnxqHx1P.js} +2 -2
- package/dist/{supervise-Da20R0PO.js.map → supervise-CnxqHx1P.js.map} +1 -1
- package/dist/{supervisor-DpIKMlPJ.js → supervisor-C8kgh8mf.js} +21 -2
- package/dist/{supervisor-DpIKMlPJ.js.map → supervisor-C8kgh8mf.js.map} +1 -1
- package/dist/testing.js +11 -11
- package/package.json +1 -1
- package/dist/graph-DGri_zJm.js +0 -532
- package/dist/graph-DGri_zJm.js.map +0 -1
- package/dist/graph.js.map +0 -1
package/dist/graph.js
CHANGED
|
@@ -1,1819 +1,2 @@
|
|
|
1
|
-
import { m as
|
|
2
|
-
|
|
3
|
-
import { t as addSpend } from "./util-D6ZEuBMi.js";
|
|
4
|
-
import { N as createBudgetPool, U as createExecutorRegistry, a as uncertainSpawnBudgets, i as sumMeasuredSpendFromEvents, l as runFinalizer, o as bestDelivered, p as createScope, r as maxSeqOf, s as collectDelivered } from "./supervisor-DpIKMlPJ.js";
|
|
5
|
-
import { i as workerFromBackend, s as supervisorAgent } from "./supervise-Da20R0PO.js";
|
|
6
|
-
import { t as GraphEdgeCapError } from "./graph-DGri_zJm.js";
|
|
7
|
-
//#region src/runtime/graph/condition.ts
|
|
8
|
-
/**
|
|
9
|
-
* The ONE predicate tree: every guard in a graph — an edge `guard`, a filter projection's
|
|
10
|
-
* predicate — is this shape, evaluated by this evaluator, so `contains`, ordering and equality can
|
|
11
|
-
* never mean two different things on two surfaces (adopted from ADC's `workflow-conditions`,
|
|
12
|
-
* agent-runtime#968). A declarative tree keeps an untrusted predicate incapable of code execution;
|
|
13
|
-
* the size and depth bounds keep a predicate authored once from burning CPU on every settle.
|
|
14
|
-
*
|
|
15
|
-
* No zod: the kernel's grain is a hand-written validator that throws `ValidationError` by name.
|
|
16
|
-
*/
|
|
17
|
-
/** The leaf comparison operators; `exists`/`truthy` are unary, the rest compare against `value`. */
|
|
18
|
-
const CONDITION_OPS = [
|
|
19
|
-
"eq",
|
|
20
|
-
"neq",
|
|
21
|
-
"gt",
|
|
22
|
-
"gte",
|
|
23
|
-
"lt",
|
|
24
|
-
"lte",
|
|
25
|
-
"in",
|
|
26
|
-
"contains",
|
|
27
|
-
"exists",
|
|
28
|
-
"truthy"
|
|
29
|
-
];
|
|
30
|
-
/** Operators that compare against `value`; `exists`/`truthy` are unary and must omit it. */
|
|
31
|
-
const OPS_NEEDING_VALUE = new Set(CONDITION_OPS.filter((op) => op !== "exists" && op !== "truthy"));
|
|
32
|
-
const MAX_PATH_LENGTH = 256;
|
|
33
|
-
const MAX_PATH_SEGMENTS = 16;
|
|
34
|
-
const PATH_SEGMENT = /^[A-Za-z_$][A-Za-z0-9_$-]*$/u;
|
|
35
|
-
/** Parse `a.b[0].c` into steps; refuse anything outside the bounded grammar. */
|
|
36
|
-
function parseConditionPath(path, context) {
|
|
37
|
-
if (typeof path !== "string" || path.length === 0 || path.length > MAX_PATH_LENGTH) throw new ValidationError(`${context}: path must be a non-empty string of at most ${MAX_PATH_LENGTH} chars`);
|
|
38
|
-
const steps = [];
|
|
39
|
-
for (const part of path.split(".")) {
|
|
40
|
-
const open = part.indexOf("[");
|
|
41
|
-
const head = open === -1 ? part : part.slice(0, open);
|
|
42
|
-
if (head.length > 0) {
|
|
43
|
-
if (!PATH_SEGMENT.test(head)) throw new ValidationError(`${context}: path segment ${JSON.stringify(head)} is not addressable`);
|
|
44
|
-
steps.push(head);
|
|
45
|
-
} else if (open !== 0 || steps.length === 0) throw new ValidationError(`${context}: path ${JSON.stringify(path)} has an empty segment`);
|
|
46
|
-
let rest = open === -1 ? "" : part.slice(open);
|
|
47
|
-
while (rest.length > 0) {
|
|
48
|
-
const match = /^\[(\d{1,6})\]/u.exec(rest);
|
|
49
|
-
if (!match) throw new ValidationError(`${context}: path index in ${JSON.stringify(part)} must be [N]`);
|
|
50
|
-
steps.push(Number(match[1]));
|
|
51
|
-
rest = rest.slice(match[0].length);
|
|
52
|
-
}
|
|
53
|
-
if (steps.length > MAX_PATH_SEGMENTS) throw new ValidationError(`${context}: path exceeds ${MAX_PATH_SEGMENTS} segments`);
|
|
54
|
-
}
|
|
55
|
-
if (steps.length === 0) throw new ValidationError(`${context}: path resolves no segment`);
|
|
56
|
-
return steps;
|
|
57
|
-
}
|
|
58
|
-
/** Walk a parsed path; any miss resolves `undefined`, never a throw — absence is an answer. */
|
|
59
|
-
function resolveConditionPath(context, steps) {
|
|
60
|
-
let current = context;
|
|
61
|
-
for (const step of steps) {
|
|
62
|
-
if (current === null || current === void 0) return void 0;
|
|
63
|
-
if (typeof step === "number") {
|
|
64
|
-
if (!Array.isArray(current)) return void 0;
|
|
65
|
-
current = current[step];
|
|
66
|
-
} else {
|
|
67
|
-
if (typeof current !== "object" || Array.isArray(current)) return void 0;
|
|
68
|
-
current = current[step];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return current;
|
|
72
|
-
}
|
|
73
|
-
function isLeaf(condition) {
|
|
74
|
-
return typeof condition.path === "string";
|
|
75
|
-
}
|
|
76
|
-
/** Validate shape, bounds, and per-leaf path/operator rules; returns the input for chaining. */
|
|
77
|
-
function validateCondition(raw, context) {
|
|
78
|
-
let nodes = 0;
|
|
79
|
-
const walk = (value, depth) => {
|
|
80
|
-
nodes += 1;
|
|
81
|
-
if (nodes > 40) throw new ValidationError(`${context}: condition exceeds 40 nodes`);
|
|
82
|
-
if (depth > 6) throw new ValidationError(`${context}: condition exceeds depth 6`);
|
|
83
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new ValidationError(`${context}: a condition must be an object`);
|
|
84
|
-
const record = value;
|
|
85
|
-
const combinators = [
|
|
86
|
-
"all",
|
|
87
|
-
"any",
|
|
88
|
-
"not"
|
|
89
|
-
].filter((key) => record[key] !== void 0);
|
|
90
|
-
if (combinators.length > 1) throw new ValidationError(`${context}: a condition carries ONE of all/any/not, got ${combinators.join("+")}`);
|
|
91
|
-
if (record.all !== void 0 || record.any !== void 0) {
|
|
92
|
-
const key = record.all !== void 0 ? "all" : "any";
|
|
93
|
-
const branch = record[key];
|
|
94
|
-
if (!Array.isArray(branch) || branch.length === 0) throw new ValidationError(`${context}: ${key} must be a non-empty array`);
|
|
95
|
-
for (const child of branch) walk(child, depth + 1);
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
if (record.not !== void 0) {
|
|
99
|
-
walk(record.not, depth + 1);
|
|
100
|
-
return value;
|
|
101
|
-
}
|
|
102
|
-
const op = record.op;
|
|
103
|
-
if (typeof record.path !== "string" || typeof op !== "string") throw new ValidationError(`${context}: a leaf needs { path, op }`);
|
|
104
|
-
if (!CONDITION_OPS.includes(op)) throw new ValidationError(`${context}: unknown op ${JSON.stringify(op)}; known: ${CONDITION_OPS.join(", ")}`);
|
|
105
|
-
parseConditionPath(record.path, context);
|
|
106
|
-
const needsValue = OPS_NEEDING_VALUE.has(op);
|
|
107
|
-
if (needsValue && !("value" in record)) throw new ValidationError(`${context}: op ${JSON.stringify(op)} requires a value`);
|
|
108
|
-
if (!needsValue && "value" in record) throw new ValidationError(`${context}: op ${JSON.stringify(op)} is unary — remove value`);
|
|
109
|
-
if (op === "in" && !Array.isArray(record.value)) throw new ValidationError(`${context}: op "in" takes an array value`);
|
|
110
|
-
return value;
|
|
111
|
-
};
|
|
112
|
-
return walk(raw, 1);
|
|
113
|
-
}
|
|
114
|
-
function canonicalEquals(a, b) {
|
|
115
|
-
if (Object.is(a, b)) return true;
|
|
116
|
-
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
117
|
-
try {
|
|
118
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
119
|
-
} catch {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function ordering(op, left, right) {
|
|
124
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
125
|
-
if (Number.isNaN(left) || Number.isNaN(right)) return false;
|
|
126
|
-
if (op === "gt") return left > right;
|
|
127
|
-
if (op === "gte") return left >= right;
|
|
128
|
-
if (op === "lt") return left < right;
|
|
129
|
-
return left <= right;
|
|
130
|
-
}
|
|
131
|
-
if (typeof left === "string" && typeof right === "string") {
|
|
132
|
-
if (op === "gt") return left > right;
|
|
133
|
-
if (op === "gte") return left >= right;
|
|
134
|
-
if (op === "lt") return left < right;
|
|
135
|
-
return left <= right;
|
|
136
|
-
}
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
/** Walk a validated condition over a context to a boolean. Never throws on data shape. */
|
|
140
|
-
function evaluateCondition(condition, context) {
|
|
141
|
-
if (isLeaf(condition)) {
|
|
142
|
-
const resolved = resolveConditionPath(context, parseConditionPath(condition.path, "evaluate"));
|
|
143
|
-
switch (condition.op) {
|
|
144
|
-
case "exists": return resolved !== void 0 && resolved !== null;
|
|
145
|
-
case "truthy": return Boolean(resolved);
|
|
146
|
-
case "eq": return canonicalEquals(resolved, condition.value);
|
|
147
|
-
case "neq": return !canonicalEquals(resolved, condition.value);
|
|
148
|
-
case "in": return Array.isArray(condition.value) ? condition.value.some((candidate) => canonicalEquals(resolved, candidate)) : false;
|
|
149
|
-
case "contains":
|
|
150
|
-
if (Array.isArray(resolved)) return resolved.some((element) => canonicalEquals(element, condition.value));
|
|
151
|
-
return typeof resolved === "string" && typeof condition.value === "string" ? resolved.includes(condition.value) : false;
|
|
152
|
-
default: return ordering(condition.op, resolved, condition.value);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if ("all" in condition) return condition.all.every((child) => evaluateCondition(child, context));
|
|
156
|
-
if ("any" in condition) return condition.any.some((child) => evaluateCondition(child, context));
|
|
157
|
-
return !evaluateCondition(condition.not, context);
|
|
158
|
-
}
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region src/runtime/graph/projection.ts
|
|
161
|
-
/**
|
|
162
|
-
* The ONE pure projection a `data` edge may carry (agent-runtime#971): the bounded,
|
|
163
|
-
* schema-preserving subset of ADC's collection helpers. Anything richer is a `script` NODE, so it
|
|
164
|
-
* is journaled (`inputRef` → `outRef`), typed, and visible. Exactly one operator per projection.
|
|
165
|
-
*/
|
|
166
|
-
const PROJECTION_KEYS = [
|
|
167
|
-
"path",
|
|
168
|
-
"pick",
|
|
169
|
-
"map",
|
|
170
|
-
"filter",
|
|
171
|
-
"first",
|
|
172
|
-
"last",
|
|
173
|
-
"count"
|
|
174
|
-
];
|
|
175
|
-
/** Validate a projection: exactly one known operator, its argument well-formed. */
|
|
176
|
-
function validateProjection(raw, context) {
|
|
177
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new ValidationError(`${context}: a projection must be an object`);
|
|
178
|
-
const record = raw;
|
|
179
|
-
const keys = PROJECTION_KEYS.filter((key) => record[key] !== void 0);
|
|
180
|
-
const unknown = Object.keys(record).filter((key) => !PROJECTION_KEYS.includes(key));
|
|
181
|
-
if (unknown.length > 0) throw new ValidationError(`${context}: unknown projection key(s) ${unknown.join(", ")}; known: ${PROJECTION_KEYS.join(", ")}`);
|
|
182
|
-
if (keys.length !== 1) throw new ValidationError(`${context}: a projection carries exactly ONE of ${PROJECTION_KEYS.join("/")}`);
|
|
183
|
-
const key = keys[0];
|
|
184
|
-
if (key === "path" || key === "map") parseConditionPath(record[key], context);
|
|
185
|
-
if (key === "pick") {
|
|
186
|
-
const fields = record.pick;
|
|
187
|
-
if (!Array.isArray(fields) || fields.length === 0 || fields.some((f) => typeof f !== "string")) throw new ValidationError(`${context}: pick must be a non-empty array of field names`);
|
|
188
|
-
}
|
|
189
|
-
if (key === "filter") validateCondition(record.filter, context);
|
|
190
|
-
if ((key === "first" || key === "last" || key === "count") && record[key] !== true) throw new ValidationError(`${context}: ${key} must be literally true`);
|
|
191
|
-
return raw;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Apply a validated projection to an admitted payload. Collection operators over a non-array
|
|
195
|
-
* refuse by name — a shape the author did not expect is a graph defect, not an empty result.
|
|
196
|
-
*/
|
|
197
|
-
function applyProjection(value, projection, context) {
|
|
198
|
-
if ("path" in projection) return resolveConditionPath(value, parseConditionPath(projection.path, context));
|
|
199
|
-
if ("pick" in projection) {
|
|
200
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new ValidationError(`${context}: pick needs an object payload`);
|
|
201
|
-
const record = value;
|
|
202
|
-
const out = {};
|
|
203
|
-
for (const field of projection.pick) if (field in record) out[field] = record[field];
|
|
204
|
-
return out;
|
|
205
|
-
}
|
|
206
|
-
const collection = value;
|
|
207
|
-
if (!Array.isArray(collection)) throw new ValidationError(`${context}: this projection needs an array payload`);
|
|
208
|
-
if ("map" in projection) {
|
|
209
|
-
const steps = parseConditionPath(projection.map, context);
|
|
210
|
-
return collection.map((element) => resolveConditionPath(element, steps));
|
|
211
|
-
}
|
|
212
|
-
if ("filter" in projection) return collection.filter((element) => evaluateCondition(projection.filter, element));
|
|
213
|
-
if ("first" in projection) return collection[0];
|
|
214
|
-
if ("last" in projection) return collection[collection.length - 1];
|
|
215
|
-
return collection.length;
|
|
216
|
-
}
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/runtime/graph/registry.ts
|
|
219
|
-
/**
|
|
220
|
-
* `Registry<T>` — the ONE name→thing shape for the graph engine.
|
|
221
|
-
*
|
|
222
|
-
* The kernel grew fourteen of these (agent-runtime#978) that differ in three properties:
|
|
223
|
-
* whether names can be listed, what a miss does, and whether the table is global. This one
|
|
224
|
-
* fixes all three — enumerable, a miss is refused BY NAME listing what is registered, and every
|
|
225
|
-
* registry is per-instance — and it is lifted from `AgentEnvironmentProviderRegistry`, the
|
|
226
|
-
* richest and best-tested of the fourteen, not invented.
|
|
227
|
-
*
|
|
228
|
-
* Entries are addressed by a versioned handle, `<id>/v<n>`, the same way the prompt registry
|
|
229
|
-
* addresses directives. A graph names a kind by handle; a host registers exact versions; a
|
|
230
|
-
* missing version is refused, never served by a newer one.
|
|
231
|
-
*/
|
|
232
|
-
/** `<id>/v<n>` — the only spelling a handle has on the wire, in a journal, or in an error. */
|
|
233
|
-
function formatRegistryHandle(handle) {
|
|
234
|
-
return `${handle.id}/v${handle.version}`;
|
|
235
|
-
}
|
|
236
|
-
/** Parse the wire spelling back. Refuses anything that is not exactly `<id>/v<n>`. */
|
|
237
|
-
function parseRegistryHandle(text, context) {
|
|
238
|
-
const match = /^([A-Za-z0-9][A-Za-z0-9._-]*)\/v(\d+)$/u.exec(text);
|
|
239
|
-
if (!match) throw new ValidationError(`${context}: ${JSON.stringify(text)} is not a registry handle; expected "<id>/v<n>"`);
|
|
240
|
-
const version = Number(match[2]);
|
|
241
|
-
if (!Number.isSafeInteger(version) || version < 1) throw new ValidationError(`${context}: handle version must be a positive integer`);
|
|
242
|
-
return {
|
|
243
|
-
id: match[1],
|
|
244
|
-
version
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Create a registry. Per-instance by construction: two engines in one process may hold
|
|
249
|
-
* different kind sets, a test is hermetic, and a run can print its own table. There is
|
|
250
|
-
* deliberately no module-level singleton — `builtinShapes` was the one mutable global in the
|
|
251
|
-
* kernel and it had zero tests.
|
|
252
|
-
*/
|
|
253
|
-
function createRegistry(label, seed = []) {
|
|
254
|
-
const table = /* @__PURE__ */ new Map();
|
|
255
|
-
const registry = {
|
|
256
|
-
register(entry, options = {}) {
|
|
257
|
-
if (typeof entry.id !== "string" || entry.id.length === 0) throw new ValidationError(`${label}: an entry must carry a non-empty id`);
|
|
258
|
-
if (!Number.isSafeInteger(entry.version) || entry.version < 1) throw new ValidationError(`${label}: ${JSON.stringify(entry.id)} must carry a positive integer version`);
|
|
259
|
-
const key = formatRegistryHandle(entry);
|
|
260
|
-
if (!options.replace && table.has(key)) throw new ValidationError(`${label}: ${JSON.stringify(key)} is already registered`);
|
|
261
|
-
table.set(key, entry);
|
|
262
|
-
},
|
|
263
|
-
has(handle) {
|
|
264
|
-
return table.has(formatRegistryHandle(handle));
|
|
265
|
-
},
|
|
266
|
-
get(handle) {
|
|
267
|
-
return table.get(formatRegistryHandle(handle));
|
|
268
|
-
},
|
|
269
|
-
require(handle, context = label) {
|
|
270
|
-
const key = formatRegistryHandle(handle);
|
|
271
|
-
const entry = table.get(key);
|
|
272
|
-
if (entry === void 0) {
|
|
273
|
-
const known = registry.names();
|
|
274
|
-
const suffix = known.length > 0 ? `; registered: ${known.join(", ")}` : "; nothing is registered";
|
|
275
|
-
throw new ValidationError(`${context}: ${JSON.stringify(key)} is not registered${suffix}`);
|
|
276
|
-
}
|
|
277
|
-
return entry;
|
|
278
|
-
},
|
|
279
|
-
names() {
|
|
280
|
-
return Array.from(table.keys()).sort();
|
|
281
|
-
},
|
|
282
|
-
entries() {
|
|
283
|
-
return registry.names().map((key) => table.get(key));
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
for (const entry of seed) registry.register(entry);
|
|
287
|
-
return registry;
|
|
288
|
-
}
|
|
289
|
-
//#endregion
|
|
290
|
-
//#region src/runtime/graph/definition.ts
|
|
291
|
-
/** Which gating-edge outcomes release a node (adopted from ADC, agent-runtime#968). */
|
|
292
|
-
const JOIN_RULES = [
|
|
293
|
-
"all",
|
|
294
|
-
"any",
|
|
295
|
-
"any_failed",
|
|
296
|
-
"all_done"
|
|
297
|
-
];
|
|
298
|
-
/** ADC-compatible visit backstop: nothing may be ENTERED more than this many times. */
|
|
299
|
-
const DEFAULT_MAX_NODE_VISITS = 25;
|
|
300
|
-
/** The hard ceiling an author's `maxVisits`/`maxNodeVisits` override may reach. */
|
|
301
|
-
const MAX_MAX_NODE_VISITS = 100;
|
|
302
|
-
/** Structural validation only — everything a registry is not needed for. */
|
|
303
|
-
function validateEngineGraphSpec(spec, context = "compileGraph") {
|
|
304
|
-
if (!Array.isArray(spec.nodes) || spec.nodes.length === 0) throw new ValidationError(`${context}: a graph needs at least one node`);
|
|
305
|
-
const ids = /* @__PURE__ */ new Set();
|
|
306
|
-
for (const node of spec.nodes) {
|
|
307
|
-
if (typeof node.id !== "string" || node.id.length === 0) throw new ValidationError(`${context}: every node needs a non-empty id`);
|
|
308
|
-
if (ids.has(node.id)) throw new ValidationError(`${context}: duplicate node id ${JSON.stringify(node.id)}`);
|
|
309
|
-
ids.add(node.id);
|
|
310
|
-
parseRegistryHandle(node.kind, `${context}: node ${node.id} kind`);
|
|
311
|
-
if (node.join !== void 0 && !JOIN_RULES.includes(node.join)) throw new ValidationError(`${context}: node ${node.id} join ${JSON.stringify(node.join)}; known: ${JOIN_RULES.join(", ")}`);
|
|
312
|
-
if (node.maxVisits !== void 0) {
|
|
313
|
-
if (!Number.isSafeInteger(node.maxVisits) || node.maxVisits < 1 || node.maxVisits > 100) throw new ValidationError(`${context}: node ${node.id} maxVisits must be an integer in [1, 100]`);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
if (!Array.isArray(spec.edges)) throw new ValidationError(`${context}: edges must be an array`);
|
|
317
|
-
for (const [index, edge] of spec.edges.entries()) {
|
|
318
|
-
const who = `${context}: edge[${index}]`;
|
|
319
|
-
if (edge.kind !== "delegates" && edge.kind !== "analyzes" && edge.kind !== "data") throw new ValidationError(`${who}: kind must be delegates | analyzes | data`);
|
|
320
|
-
for (const end of ["from", "to"]) {
|
|
321
|
-
const ref = edge[end];
|
|
322
|
-
if (typeof ref !== "object" || ref === null || typeof ref.node !== "string" || !ids.has(ref.node)) throw new ValidationError(`${who}: ${end}.node must name a node in this graph`);
|
|
323
|
-
}
|
|
324
|
-
if (edge.guard !== void 0) validateCondition(edge.guard, `${who} guard`);
|
|
325
|
-
if (edge.projection !== void 0) {
|
|
326
|
-
if (edge.kind !== "data") throw new ValidationError(`${who}: only a data edge carries a projection`);
|
|
327
|
-
validateProjection(edge.projection, `${who} projection`);
|
|
328
|
-
}
|
|
329
|
-
if (edge.maxTraversals !== void 0) {
|
|
330
|
-
if (!Number.isSafeInteger(edge.maxTraversals) || edge.maxTraversals < 1) throw new ValidationError(`${who}: maxTraversals must be a positive integer`);
|
|
331
|
-
}
|
|
332
|
-
if (edge.kind === "data" && edge.directive !== void 0) throw new ValidationError(`${who}: a data edge carries a port binding, never a directive`);
|
|
333
|
-
}
|
|
334
|
-
if (spec.root !== void 0 && !ids.has(spec.root)) throw new ValidationError(`${context}: root ${JSON.stringify(spec.root)} names no node`);
|
|
335
|
-
if (spec.maxNodeVisits !== void 0) {
|
|
336
|
-
if (!Number.isSafeInteger(spec.maxNodeVisits) || spec.maxNodeVisits < 1 || spec.maxNodeVisits > 100) throw new ValidationError(`${context}: maxNodeVisits must be an integer in [1, 100]`);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
//#endregion
|
|
340
|
-
//#region src/runtime/graph/compile.ts
|
|
341
|
-
/**
|
|
342
|
-
* Compile an authored graph against an engine's kind registry into the schedulable form. Every
|
|
343
|
-
* refusal here happens before any spend: an unknown kind, a port that does not exist, a `data`
|
|
344
|
-
* binding whose schemas cannot fit, a `delegates`/`data` edge into an oracle, a terminal with no
|
|
345
|
-
* completion check (agent-runtime#971, #973).
|
|
346
|
-
*/
|
|
347
|
-
/** A node's ports: its kind's declared outputs plus the two implicit ones every node has. */
|
|
348
|
-
const IMPLICIT_OUTPUT_PORTS = ["out", "trace"];
|
|
349
|
-
/** A node's ports: node-level declarations merged OVER its kind's (the node wins on a name). */
|
|
350
|
-
function nodePorts(kind, node) {
|
|
351
|
-
const merge = (declared, own) => {
|
|
352
|
-
if (own === void 0 || own.length === 0) return declared;
|
|
353
|
-
const names = new Set(own.map((port) => port.name));
|
|
354
|
-
return [...own, ...declared.filter((port) => !names.has(port.name))];
|
|
355
|
-
};
|
|
356
|
-
return {
|
|
357
|
-
inputs: merge(kind.inputs, node.ports?.inputs),
|
|
358
|
-
outputs: merge(kind.outputs, node.ports?.outputs)
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
function outputPort(ports, port) {
|
|
362
|
-
if (IMPLICIT_OUTPUT_PORTS.includes(port)) return {
|
|
363
|
-
name: port,
|
|
364
|
-
schema: {}
|
|
365
|
-
};
|
|
366
|
-
return ports.outputs.find((candidate) => candidate.name === port);
|
|
367
|
-
}
|
|
368
|
-
function inputPort(ports, port) {
|
|
369
|
-
return ports.inputs.find((candidate) => candidate.name === port);
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Bounded structural acceptance: does a value of `source`'s shape fit `target`? Schemas with no
|
|
373
|
-
* `type` accept anything; object targets require their `required` properties to be present and
|
|
374
|
-
* accepted when the source declares properties. Depth-bounded — this is a compile-time tripwire,
|
|
375
|
-
* not a full JSON Schema validator.
|
|
376
|
-
*/
|
|
377
|
-
function schemaAccepts(source, target, depth = 0) {
|
|
378
|
-
if (depth > 6) return true;
|
|
379
|
-
const sourceType = source.type;
|
|
380
|
-
const targetType = target.type;
|
|
381
|
-
if (targetType === void 0 || sourceType === void 0) return true;
|
|
382
|
-
const targets = Array.isArray(targetType) ? targetType : [targetType];
|
|
383
|
-
const sources = Array.isArray(sourceType) ? sourceType : [sourceType];
|
|
384
|
-
if (sources.filter((candidate) => targets.includes(candidate === "integer" ? "number" : candidate) || targets.includes(candidate)).length === 0) return false;
|
|
385
|
-
if (targets.includes("object") && sources.includes("object")) {
|
|
386
|
-
const required = Array.isArray(target.required) ? target.required : [];
|
|
387
|
-
const sourceProps = source.properties;
|
|
388
|
-
const targetProps = target.properties;
|
|
389
|
-
if (sourceProps !== void 0) for (const name of required) {
|
|
390
|
-
const sourceProp = sourceProps[name];
|
|
391
|
-
if (sourceProp === void 0) return false;
|
|
392
|
-
const targetProp = targetProps?.[name];
|
|
393
|
-
if (targetProp !== void 0 && !schemaAccepts(sourceProp, targetProp, depth + 1)) return false;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
if (targets.includes("array") && sources.includes("array")) {
|
|
397
|
-
const sourceItems = source.items;
|
|
398
|
-
const targetItems = target.items;
|
|
399
|
-
if (sourceItems !== void 0 && targetItems !== void 0) return schemaAccepts(sourceItems, targetItems, depth + 1);
|
|
400
|
-
}
|
|
401
|
-
return true;
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Lower an authored graph against an engine's kind registry into the schedulable form, refusing
|
|
405
|
-
* every structural defect before any spend.
|
|
406
|
-
*/
|
|
407
|
-
function compileGraph(engine, spec, context = "compileGraph") {
|
|
408
|
-
validateEngineGraphSpec(spec, context);
|
|
409
|
-
const kinds = /* @__PURE__ */ new Map();
|
|
410
|
-
const configs = /* @__PURE__ */ new Map();
|
|
411
|
-
for (const node of spec.nodes) {
|
|
412
|
-
const handle = parseRegistryHandle(node.kind, `${context}: node ${node.id}`);
|
|
413
|
-
const kind = engine.kinds.require(handle, `${context}: node ${node.id}`);
|
|
414
|
-
kinds.set(node.id, kind);
|
|
415
|
-
configs.set(node.id, kind.validateConfig(node.config ?? {}, `${context}: node ${node.id}`));
|
|
416
|
-
if (node.flags?.pure && kind.id !== "script") throw new ValidationError(`${context}: node ${node.id} sets pure, which only a script node may claim`);
|
|
417
|
-
}
|
|
418
|
-
const compiledEdges = [];
|
|
419
|
-
const inbound = /* @__PURE__ */ new Map();
|
|
420
|
-
const outbound = /* @__PURE__ */ new Map();
|
|
421
|
-
for (const [index, edge] of spec.edges.entries()) {
|
|
422
|
-
const who = `${context}: edge[${index}] ${edge.from.node}->${edge.to.node}`;
|
|
423
|
-
const fromKind = kinds.get(edge.from.node);
|
|
424
|
-
const toKind = kinds.get(edge.to.node);
|
|
425
|
-
if (!fromKind || !toKind) throw new ValidationError(`${who}: unresolved endpoint`);
|
|
426
|
-
const toNode = spec.nodes.find((node) => node.id === edge.to.node);
|
|
427
|
-
if (edge.kind !== "analyzes" && toNode?.flags?.oracle) throw new ValidationError(`${who}: a ${edge.kind} edge may not target oracle node ${edge.to.node}; use analyzes`);
|
|
428
|
-
const fromPort = edge.from.port ?? (edge.kind === "analyzes" ? "trace" : "out");
|
|
429
|
-
if (edge.kind === "analyzes" && fromPort !== "trace") throw new ValidationError(`${who}: an analyzes edge reads the trace port, got ${fromPort}`);
|
|
430
|
-
const fromPorts = nodePorts(fromKind, spec.nodes.find((node) => node.id === edge.from.node));
|
|
431
|
-
const toPorts = nodePorts(toKind, toNode);
|
|
432
|
-
const sourcePort = outputPort(fromPorts, fromPort);
|
|
433
|
-
if (!sourcePort) {
|
|
434
|
-
const known = [...IMPLICIT_OUTPUT_PORTS, ...fromPorts.outputs.map((port) => port.name)];
|
|
435
|
-
throw new ValidationError(`${who}: ${formatRegistryHandle(fromKind)} has no output port ${JSON.stringify(fromPort)}; known: ${known.join(", ")}`);
|
|
436
|
-
}
|
|
437
|
-
let toPort = edge.to.port ?? "";
|
|
438
|
-
if (edge.kind === "data") {
|
|
439
|
-
if (toPort === "") if (toPorts.inputs.length === 1) toPort = toPorts.inputs[0]?.name ?? "";
|
|
440
|
-
else throw new ValidationError(`${who}: a data edge needs to.port; ${formatRegistryHandle(toKind)} declares ${toPorts.inputs.length} inputs`);
|
|
441
|
-
const targetPort = inputPort(toPorts, toPort);
|
|
442
|
-
if (!targetPort) throw new ValidationError(`${who}: ${formatRegistryHandle(toKind)} has no input port ${JSON.stringify(toPort)}; known: ${toPorts.inputs.map((port) => port.name).join(", ") || "(none)"}`);
|
|
443
|
-
if (edge.projection === void 0 && !schemaAccepts(sourcePort.schema, targetPort.schema)) throw new ValidationError(`${who}: output ${fromPort} (${JSON.stringify(sourcePort.schema.type ?? "any")}) cannot fit input ${toPort} (${JSON.stringify(targetPort.schema.type ?? "any")})`);
|
|
444
|
-
}
|
|
445
|
-
const compiled = {
|
|
446
|
-
id: edge.id ?? `${edge.from.node}->${edge.to.node}#${index}`,
|
|
447
|
-
spec: edge,
|
|
448
|
-
fromPort,
|
|
449
|
-
toPort: toPort === "" ? "out" : toPort
|
|
450
|
-
};
|
|
451
|
-
compiledEdges.push(compiled);
|
|
452
|
-
outbound.set(edge.from.node, [...outbound.get(edge.from.node) ?? [], compiled]);
|
|
453
|
-
inbound.set(edge.to.node, [...inbound.get(edge.to.node) ?? [], compiled]);
|
|
454
|
-
}
|
|
455
|
-
const dupes = /* @__PURE__ */ new Set();
|
|
456
|
-
for (const edge of compiledEdges) {
|
|
457
|
-
if (dupes.has(edge.id)) throw new ValidationError(`${context}: duplicate edge id ${edge.id}`);
|
|
458
|
-
dupes.add(edge.id);
|
|
459
|
-
}
|
|
460
|
-
const entries = spec.nodes.filter((node) => (inbound.get(node.id) ?? []).length === 0);
|
|
461
|
-
if (entries.length === 0) throw new ValidationError(`${context}: no entry node — every node has an inbound edge`);
|
|
462
|
-
const root = spec.root ?? (entries.length === 1 ? entries[0]?.id ?? "" : (() => {
|
|
463
|
-
throw new ValidationError(`${context}: ${entries.length} entry nodes (${entries.map((node) => node.id).join(", ")}) — name spec.root`);
|
|
464
|
-
})());
|
|
465
|
-
const nodes = /* @__PURE__ */ new Map();
|
|
466
|
-
const terminals = [];
|
|
467
|
-
for (const node of spec.nodes) {
|
|
468
|
-
const kind = kinds.get(node.id);
|
|
469
|
-
if (!kind) throw new ValidationError(`${context}: unresolved node ${node.id}`);
|
|
470
|
-
const terminal = node.terminal ?? (outbound.get(node.id) ?? []).length === 0;
|
|
471
|
-
const deliverable = node.deliverable ?? (node.id === root ? spec.deliverable : void 0);
|
|
472
|
-
if (terminal) terminals.push(node.id);
|
|
473
|
-
nodes.set(node.id, {
|
|
474
|
-
id: node.id,
|
|
475
|
-
kind,
|
|
476
|
-
config: configs.get(node.id),
|
|
477
|
-
join: node.join ?? "all",
|
|
478
|
-
maxVisits: node.maxVisits ?? spec.maxNodeVisits ?? 25,
|
|
479
|
-
oracle: node.flags?.oracle ?? false,
|
|
480
|
-
pure: node.flags?.pure ?? false,
|
|
481
|
-
terminal,
|
|
482
|
-
...deliverable === void 0 ? {} : { deliverable },
|
|
483
|
-
inbound: inbound.get(node.id) ?? [],
|
|
484
|
-
outbound: outbound.get(node.id) ?? [],
|
|
485
|
-
spec: node
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
if (terminals.filter((id) => nodes.get(id)?.deliverable === void 0).length === terminals.length) throw new ValidationError(`${context}: no terminal declares a completion check (terminals: ${terminals.join(", ")}); give a node a deliverable or set spec.deliverable`);
|
|
489
|
-
return {
|
|
490
|
-
nodes,
|
|
491
|
-
edges: compiledEdges,
|
|
492
|
-
entries: entries.map((node) => node.id),
|
|
493
|
-
terminals,
|
|
494
|
-
root,
|
|
495
|
-
maxNodeVisits: spec.maxNodeVisits ?? 25
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
//#endregion
|
|
499
|
-
//#region src/runtime/graph/kind.ts
|
|
500
|
-
/** Validate a kind declaration at registration — so a malformed kind is refused by name once,
|
|
501
|
-
* not at the first node that uses it. */
|
|
502
|
-
function validateNodeKind(kind, context = "registerNodeKind") {
|
|
503
|
-
const who = `${context}: kind ${JSON.stringify(`${kind.id}/v${kind.version}`)}`;
|
|
504
|
-
if (typeof kind.id !== "string" || kind.id.length === 0) throw new ValidationError(`${context}: a kind must carry a non-empty id`);
|
|
505
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/u.test(kind.id)) throw new ValidationError(`${who}: id may contain only letters, digits, ".", "_" and "-"`);
|
|
506
|
-
if (!Number.isSafeInteger(kind.version) || kind.version < 1) throw new ValidationError(`${who}: version must be a positive integer`);
|
|
507
|
-
if (typeof kind.description !== "string" || kind.description.trim().length === 0) throw new ValidationError(`${who}: description is required`);
|
|
508
|
-
if (typeof kind.validateConfig !== "function") throw new ValidationError(`${who}: validateConfig must be a function`);
|
|
509
|
-
if (!isRecord(kind.configSchema)) throw new ValidationError(`${who}: configSchema must be a JSON Schema object`);
|
|
510
|
-
for (const [field, ports] of [["inputs", kind.inputs], ["outputs", kind.outputs]]) {
|
|
511
|
-
if (!Array.isArray(ports)) throw new ValidationError(`${who}: ${field} must be an array`);
|
|
512
|
-
const seen = /* @__PURE__ */ new Set();
|
|
513
|
-
for (const port of ports) {
|
|
514
|
-
if (!port || typeof port.name !== "string" || port.name.length === 0) throw new ValidationError(`${who}: every ${field} port needs a non-empty name`);
|
|
515
|
-
if (field === "outputs" && (port.name === "out" || port.name === "trace")) throw new ValidationError(`${who}: output port ${JSON.stringify(port.name)} is implicit on every node and cannot be declared`);
|
|
516
|
-
if (seen.has(port.name)) throw new ValidationError(`${who}: duplicate ${field} port ${JSON.stringify(port.name)}`);
|
|
517
|
-
seen.add(port.name);
|
|
518
|
-
if (!isRecord(port.schema)) throw new ValidationError(`${who}: ${field} port ${JSON.stringify(port.name)} needs a JSON Schema`);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (!Array.isArray(kind.effects) || kind.effects.some((e) => typeof e !== "string" || e.length === 0)) throw new ValidationError(`${who}: effects must be an array of non-empty names`);
|
|
522
|
-
if (new Set(kind.effects).size !== kind.effects.length) throw new ValidationError(`${who}: effects must not repeat a name`);
|
|
523
|
-
if (kind.onCrash !== "restart" && kind.onCrash !== "resume") throw new ValidationError(`${who}: onCrash must be "restart" or "resume"`);
|
|
524
|
-
if (kind.budget !== "metered" && kind.budget !== "exempt") throw new ValidationError(`${who}: budget must be "metered" or "exempt"`);
|
|
525
|
-
if (typeof kind.run !== "function") throw new ValidationError(`${who}: run must be a function`);
|
|
526
|
-
return kind;
|
|
527
|
-
}
|
|
528
|
-
/** The handle a graph writes to name this kind. */
|
|
529
|
-
function kindHandle(kind) {
|
|
530
|
-
return {
|
|
531
|
-
id: kind.id,
|
|
532
|
-
version: kind.version
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Narrow a host's effect table to exactly what one kind declared. Anything the kind did not
|
|
537
|
-
* declare is absent — `undefined` on read — so a kind cannot reach past its declaration, and the
|
|
538
|
-
* engine can list a graph's required effects before spending a token.
|
|
539
|
-
*/
|
|
540
|
-
function narrowEffects(declared, provided, context) {
|
|
541
|
-
const out = {};
|
|
542
|
-
const missing = [];
|
|
543
|
-
for (const name of declared) {
|
|
544
|
-
if (!(name in provided)) {
|
|
545
|
-
missing.push(name);
|
|
546
|
-
continue;
|
|
547
|
-
}
|
|
548
|
-
out[name] = provided[name];
|
|
549
|
-
}
|
|
550
|
-
if (missing.length > 0) throw new ValidationError(`${context}: host provides no effect for ${missing.map((m) => JSON.stringify(m)).join(", ")}; provided: ${Object.keys(provided).sort().join(", ") || "none"}`);
|
|
551
|
-
return Object.freeze(out);
|
|
552
|
-
}
|
|
553
|
-
function isRecord(value) {
|
|
554
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
555
|
-
}
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/runtime/graph/engine.ts
|
|
558
|
-
/**
|
|
559
|
-
* `createGraphEngine` — one engine instance: its kind registry (core kinds pre-registered, host
|
|
560
|
-
* kinds added by the caller), its effect table, and nothing global.
|
|
561
|
-
*
|
|
562
|
-
* The scheduler (#980), journal fold (#981) and the `runGraph` preset (#982) attach here; this
|
|
563
|
-
* file is the part that must exist first so a host can register kinds and a compiler can ask
|
|
564
|
-
* "which effects does this graph need" before a token is spent.
|
|
565
|
-
*/
|
|
566
|
-
/**
|
|
567
|
-
* Build one engine: a kind registry seeded with the core kinds plus the host's, and the host's
|
|
568
|
-
* effect values. Every kind is validated by name at construction, so a malformed host kind fails
|
|
569
|
-
* here, never at its first node.
|
|
570
|
-
*/
|
|
571
|
-
function createGraphEngine(options) {
|
|
572
|
-
const kinds = createRegistry("graph kinds");
|
|
573
|
-
for (const kind of options.coreKinds) kinds.register(validateNodeKind(kind, "createGraphEngine"));
|
|
574
|
-
for (const kind of options.kinds ?? []) kinds.register(validateNodeKind(kind, "createGraphEngine"));
|
|
575
|
-
const effects = Object.freeze({ ...options.effects ?? {} });
|
|
576
|
-
if (Object.keys(effects).some((name) => name.length === 0)) throw new ValidationError("createGraphEngine: an effect name must be non-empty");
|
|
577
|
-
const engine = {
|
|
578
|
-
kinds,
|
|
579
|
-
effects,
|
|
580
|
-
requiredEffects() {
|
|
581
|
-
const names = /* @__PURE__ */ new Set();
|
|
582
|
-
for (const kind of kinds.entries()) for (const name of kind.effects) names.add(name);
|
|
583
|
-
return Array.from(names).sort();
|
|
584
|
-
},
|
|
585
|
-
missingEffects() {
|
|
586
|
-
return engine.requiredEffects().filter((name) => !(name in effects));
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
return engine;
|
|
590
|
-
}
|
|
591
|
-
//#endregion
|
|
592
|
-
//#region src/runtime/graph/fold.ts
|
|
593
|
-
/**
|
|
594
|
-
* The fold (agent-runtime#974): scheduler state is a pure function of the journal, reconstructed
|
|
595
|
-
* by replaying events through the SAME reducer the live scheduler feeds — fold, never checkpoint.
|
|
596
|
-
* Kernel events (`spawned`, `settled`, `waiting`, `woken`) carry what the kernel owns; the engine's
|
|
597
|
-
* events (`node-inputs-resolved`, `edge-verdict`, `join-state`) carry what the scheduler decided,
|
|
598
|
-
* each journaled BEFORE its effect was visible. `edge` stays observability and is skipped here
|
|
599
|
-
* exactly as the kernel's own replay skips it.
|
|
600
|
-
*
|
|
601
|
-
* Events are consumed in APPEND order (the journal file's line order), not by `seq`: kernel and
|
|
602
|
-
* engine events carry independent ordinal counters, and append order is the one total order both
|
|
603
|
-
* share.
|
|
604
|
-
*/
|
|
605
|
-
/** The reducer's zero: every node unvisited, every edge pending, nothing suspended. */
|
|
606
|
-
function emptyFoldState(compiled) {
|
|
607
|
-
const nodes = /* @__PURE__ */ new Map();
|
|
608
|
-
for (const id of compiled.nodes.keys()) nodes.set(id, {
|
|
609
|
-
visits: 0,
|
|
610
|
-
blocked: false,
|
|
611
|
-
settles: []
|
|
612
|
-
});
|
|
613
|
-
const edges = /* @__PURE__ */ new Map();
|
|
614
|
-
for (const edge of compiled.edges) edges.set(edge.id, {
|
|
615
|
-
state: "pending",
|
|
616
|
-
consumedOnce: false,
|
|
617
|
-
traversals: 0,
|
|
618
|
-
judgedSourceSettles: 0,
|
|
619
|
-
capped: false
|
|
620
|
-
});
|
|
621
|
-
return {
|
|
622
|
-
nodes,
|
|
623
|
-
edges,
|
|
624
|
-
instances: /* @__PURE__ */ new Map(),
|
|
625
|
-
spawnedIds: /* @__PURE__ */ new Map(),
|
|
626
|
-
suspensions: /* @__PURE__ */ new Map(),
|
|
627
|
-
exhaustedEdges: /* @__PURE__ */ new Set()
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
function instanceOf(state, label) {
|
|
631
|
-
return state.instances.get(label);
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Apply ONE journal event. The live scheduler calls this right after each append; the restart path
|
|
635
|
-
* calls it over the loaded journal. Unknown kernel events are ignored — the engine folds only what
|
|
636
|
-
* it understands, exactly as the kernel's replay skips the engine's events.
|
|
637
|
-
*/
|
|
638
|
-
function applyGraphFoldEvent(state, ev, compiled) {
|
|
639
|
-
switch (ev.kind) {
|
|
640
|
-
case "node-inputs-resolved": {
|
|
641
|
-
const visit = Number(ev.instance.split("#").at(-1));
|
|
642
|
-
if (!Number.isSafeInteger(visit)) throw new ValidationError(`graph fold: instance ${ev.instance} carries no visit ordinal`);
|
|
643
|
-
state.instances.set(ev.instance, {
|
|
644
|
-
node: ev.node,
|
|
645
|
-
instance: ev.instance,
|
|
646
|
-
visit,
|
|
647
|
-
inputRef: ev.inputRef,
|
|
648
|
-
status: "released"
|
|
649
|
-
});
|
|
650
|
-
const node = state.nodes.get(ev.node);
|
|
651
|
-
if (node) node.visits = Math.max(node.visits, visit);
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
case "spawned": {
|
|
655
|
-
const instance = instanceOf(state, ev.label);
|
|
656
|
-
if (instance) {
|
|
657
|
-
instance.status = "live";
|
|
658
|
-
state.spawnedIds.set(ev.id, ev.label);
|
|
659
|
-
}
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
case "settled": {
|
|
663
|
-
const label = state.spawnedIds.get(ev.id);
|
|
664
|
-
const instance = label === void 0 ? void 0 : instanceOf(state, label);
|
|
665
|
-
if (!instance) return;
|
|
666
|
-
instance.status = ev.status;
|
|
667
|
-
const settle = {
|
|
668
|
-
node: instance.node,
|
|
669
|
-
visit: instance.visit,
|
|
670
|
-
status: ev.status,
|
|
671
|
-
...ev.outRef !== void 0 ? { outRef: ev.outRef } : {},
|
|
672
|
-
...ev.reason !== void 0 ? { reason: ev.reason } : {}
|
|
673
|
-
};
|
|
674
|
-
if (ev.trace?.status === "available") settle.traceRef = ev.trace.traceRef;
|
|
675
|
-
instance.settle = settle;
|
|
676
|
-
state.nodes.get(instance.node)?.settles.push(settle);
|
|
677
|
-
const node = compiled.nodes.get(instance.node);
|
|
678
|
-
for (const edge of node?.outbound ?? []) {
|
|
679
|
-
const folded = state.edges.get(edge.id);
|
|
680
|
-
if (folded?.consumedOnce && folded.state === "pending") {
|
|
681
|
-
folded.consumedOnce = false;
|
|
682
|
-
folded.judgedSourceSettles += 1;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
case "edge-verdict": {
|
|
688
|
-
const folded = state.edges.get(ev.edge);
|
|
689
|
-
if (!folded) return;
|
|
690
|
-
if (ev.capped) {
|
|
691
|
-
folded.capped = true;
|
|
692
|
-
state.exhaustedEdges.add(ev.edge);
|
|
693
|
-
const target = compiled.edges.find((edge) => edge.id === ev.edge)?.spec.to.node;
|
|
694
|
-
const compiledTarget = target === void 0 ? void 0 : compiled.nodes.get(target);
|
|
695
|
-
if (compiledTarget && (compiledTarget.join === "all" || compiledTarget.join === "all_done")) {
|
|
696
|
-
const node = state.nodes.get(target);
|
|
697
|
-
if (node) node.blocked = true;
|
|
698
|
-
}
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
folded.judgedSourceSettles += 1;
|
|
702
|
-
if (!ev.fired) {
|
|
703
|
-
folded.state = ev.sourceStatus === "done" ? "dead" : "failed";
|
|
704
|
-
folded.payloadRef = void 0;
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
folded.state = "satisfied";
|
|
708
|
-
folded.payloadRef = ev.inputRef;
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
case "join-state": {
|
|
712
|
-
for (const edgeId of ev.satisfiedBy) {
|
|
713
|
-
const folded = state.edges.get(edgeId);
|
|
714
|
-
if (!folded) continue;
|
|
715
|
-
folded.traversals += 1;
|
|
716
|
-
folded.state = "pending";
|
|
717
|
-
folded.payloadRef = void 0;
|
|
718
|
-
}
|
|
719
|
-
const target = compiled.nodes.get(ev.node);
|
|
720
|
-
for (const edge of target?.inbound ?? []) {
|
|
721
|
-
const folded = state.edges.get(edge.id);
|
|
722
|
-
if (!folded) continue;
|
|
723
|
-
if (ev.consumedPending.includes(edge.id)) folded.consumedOnce = true;
|
|
724
|
-
else if (folded.state !== "pending" && !ev.satisfiedBy.includes(edge.id)) {
|
|
725
|
-
folded.state = "pending";
|
|
726
|
-
folded.payloadRef = void 0;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
case "waiting": {
|
|
732
|
-
if (ev.spec.kind !== "token") return;
|
|
733
|
-
const instance = instanceOf(state, ev.label);
|
|
734
|
-
if (instance) {
|
|
735
|
-
instance.status = "suspended";
|
|
736
|
-
if (instance.settle !== void 0) {
|
|
737
|
-
const settles = state.nodes.get(instance.node)?.settles;
|
|
738
|
-
if (settles && settles.at(-1) === instance.settle) settles.pop();
|
|
739
|
-
instance.settle = void 0;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
state.suspensions.set(ev.spec.token, {
|
|
743
|
-
token: ev.spec.token,
|
|
744
|
-
node: instance?.node ?? ev.label.split("#")[0] ?? ev.label,
|
|
745
|
-
instance: ev.label,
|
|
746
|
-
onExpire: ev.spec.onExpire,
|
|
747
|
-
...ev.spec.expiresAtMs !== void 0 ? { expiresAtMs: ev.spec.expiresAtMs } : {},
|
|
748
|
-
...ev.spec.defaultRef !== void 0 ? { defaultRef: ev.spec.defaultRef } : {},
|
|
749
|
-
status: "pending"
|
|
750
|
-
});
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
case "woken": {
|
|
754
|
-
const token = ev.id.startsWith("graphwait:") ? ev.id.slice(10) : void 0;
|
|
755
|
-
const suspension = token === void 0 ? void 0 : state.suspensions.get(token);
|
|
756
|
-
if (!suspension) return;
|
|
757
|
-
const instance = instanceOf(state, suspension.instance);
|
|
758
|
-
if (ev.by === "expired") {
|
|
759
|
-
suspension.status = "expired";
|
|
760
|
-
if (instance) {
|
|
761
|
-
instance.status = "down";
|
|
762
|
-
const settle = {
|
|
763
|
-
node: suspension.node,
|
|
764
|
-
visit: instance.visit,
|
|
765
|
-
status: "down",
|
|
766
|
-
reason: "suspension expired"
|
|
767
|
-
};
|
|
768
|
-
instance.settle = settle;
|
|
769
|
-
state.nodes.get(suspension.node)?.settles.push(settle);
|
|
770
|
-
}
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
suspension.status = "woken";
|
|
774
|
-
if (instance) {
|
|
775
|
-
instance.status = "done";
|
|
776
|
-
const settle = {
|
|
777
|
-
node: suspension.node,
|
|
778
|
-
visit: instance.visit,
|
|
779
|
-
status: "done",
|
|
780
|
-
...ev.outRef !== void 0 ? { outRef: ev.outRef } : {}
|
|
781
|
-
};
|
|
782
|
-
instance.settle = settle;
|
|
783
|
-
state.nodes.get(suspension.node)?.settles.push(settle);
|
|
784
|
-
}
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
default: return;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
/** Fold a loaded journal (append order) into scheduler state. */
|
|
791
|
-
function foldGraphJournal(events, compiled) {
|
|
792
|
-
const state = emptyFoldState(compiled);
|
|
793
|
-
for (const ev of events) applyGraphFoldEvent(state, ev, compiled);
|
|
794
|
-
return state;
|
|
795
|
-
}
|
|
796
|
-
//#endregion
|
|
797
|
-
//#region src/runtime/graph/kinds.ts
|
|
798
|
-
/**
|
|
799
|
-
* One profile, one run: the kernel's leaf, exactly as `supervise()` derives it from `backend`.
|
|
800
|
-
* The model cannot decide this — it is what gets run.
|
|
801
|
-
*/
|
|
802
|
-
function agentKind(defaults) {
|
|
803
|
-
return {
|
|
804
|
-
id: "agent",
|
|
805
|
-
version: 1,
|
|
806
|
-
description: "One AgentProfile run as a leaf on a backend; the kernel derives the executor.",
|
|
807
|
-
validateConfig: (raw, context) => {
|
|
808
|
-
const config = asRecord(raw, `${context}: agent config`);
|
|
809
|
-
return {
|
|
810
|
-
...config.backend !== void 0 ? { backend: config.backend } : {},
|
|
811
|
-
...config.deliverable !== void 0 ? { deliverable: config.deliverable } : {}
|
|
812
|
-
};
|
|
813
|
-
},
|
|
814
|
-
configSchema: {
|
|
815
|
-
type: "object",
|
|
816
|
-
properties: {
|
|
817
|
-
backend: { type: "object" },
|
|
818
|
-
deliverable: { type: "object" }
|
|
819
|
-
},
|
|
820
|
-
additionalProperties: false
|
|
821
|
-
},
|
|
822
|
-
inputs: [],
|
|
823
|
-
outputs: [],
|
|
824
|
-
effects: [],
|
|
825
|
-
onCrash: "restart",
|
|
826
|
-
budget: "metered",
|
|
827
|
-
run: ({ config, profile, spawn }) => {
|
|
828
|
-
const backend = config.backend ?? defaults.backend;
|
|
829
|
-
if (!backend) throw new ValidationError(`agent kind: node ${JSON.stringify(profile.name)} has no backend — set config.backend or the engine default`);
|
|
830
|
-
return workerFromBackend(backend, config.deliverable ?? defaults.deliverable)(profile, spawn);
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* The thing that DECIDES: a nested `supervisorAgent` with the coordination verbs. Its children
|
|
836
|
-
* are its own tree — the graph sees one node in, one `Settled` out. A `subgraph` constrains what
|
|
837
|
-
* it may spawn; without one it is free-form under `profileSecurity` and `allowedModels`.
|
|
838
|
-
*/
|
|
839
|
-
function supervisorKind(deps) {
|
|
840
|
-
return {
|
|
841
|
-
id: "supervisor",
|
|
842
|
-
version: 1,
|
|
843
|
-
description: "A nested supervisor: spawns, observes, steers and awaits its own children with the coordination verbs.",
|
|
844
|
-
validateConfig: (raw, context) => {
|
|
845
|
-
const config = asRecord(raw, `${context}: supervisor config`);
|
|
846
|
-
return {
|
|
847
|
-
perWorker: asRecord(config.perWorker, `${context}: supervisor config.perWorker`),
|
|
848
|
-
...config.maxLiveWorkers !== void 0 ? { maxLiveWorkers: Number(config.maxLiveWorkers) } : {}
|
|
849
|
-
};
|
|
850
|
-
},
|
|
851
|
-
configSchema: {
|
|
852
|
-
type: "object",
|
|
853
|
-
properties: {
|
|
854
|
-
perWorker: { type: "object" },
|
|
855
|
-
maxLiveWorkers: { type: "integer" }
|
|
856
|
-
},
|
|
857
|
-
required: ["perWorker"],
|
|
858
|
-
additionalProperties: false
|
|
859
|
-
},
|
|
860
|
-
inputs: [],
|
|
861
|
-
outputs: [],
|
|
862
|
-
effects: [],
|
|
863
|
-
onCrash: "restart",
|
|
864
|
-
budget: "metered",
|
|
865
|
-
run: ({ config, profile }) => supervisorAgent(profile, {
|
|
866
|
-
blobs: deps.blobs,
|
|
867
|
-
makeWorkerAgent: deps.makeWorkerAgent,
|
|
868
|
-
perWorker: config.perWorker,
|
|
869
|
-
...config.maxLiveWorkers !== void 0 ? { maxLiveWorkers: config.maxLiveWorkers } : {},
|
|
870
|
-
...deps.router ? { router: deps.router } : {},
|
|
871
|
-
...deps.driveHarness ? { driveHarness: deps.driveHarness } : {}
|
|
872
|
-
})
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
/** The script kind's handle; it also names the kind in every script node's identity. */
|
|
876
|
-
const SCRIPT = {
|
|
877
|
-
id: "script",
|
|
878
|
-
version: 1
|
|
879
|
-
};
|
|
880
|
-
/**
|
|
881
|
-
* Caller code as a node. The one kind with no kernel primitive behind it: the kernel has no
|
|
882
|
-
* "data→data with no execution" concept (agent-runtime#970 fact-finding), so this is new. It is
|
|
883
|
-
* still a leaf `Agent` carrying an `Executor`, so the journal, the gate and the pool treat it like
|
|
884
|
-
* any other node.
|
|
885
|
-
*/
|
|
886
|
-
function scriptKind() {
|
|
887
|
-
return {
|
|
888
|
-
...SCRIPT,
|
|
889
|
-
description: "Run caller code over the resolved inputs; pure scripts are exempt and restorable.",
|
|
890
|
-
validateConfig: (raw, context) => {
|
|
891
|
-
const config = asRecord(raw, `${context}: script config`);
|
|
892
|
-
if (typeof config.body !== "function") throw new ValidationError(`${context}: script config.body must be a function`);
|
|
893
|
-
if (config.pure !== void 0 && typeof config.pure !== "boolean") throw new ValidationError(`${context}: script config.pure must be a boolean`);
|
|
894
|
-
if (config.pure === true && config.spent !== void 0) throw new ValidationError(`${context}: a pure script is budget-exempt and cannot report spent`);
|
|
895
|
-
return {
|
|
896
|
-
body: config.body,
|
|
897
|
-
...config.pure !== void 0 ? { pure: config.pure } : {},
|
|
898
|
-
...config.spent !== void 0 ? { spent: config.spent } : {}
|
|
899
|
-
};
|
|
900
|
-
},
|
|
901
|
-
configSchema: {
|
|
902
|
-
type: "object",
|
|
903
|
-
properties: {
|
|
904
|
-
pure: { type: "boolean" },
|
|
905
|
-
spent: { type: "object" }
|
|
906
|
-
},
|
|
907
|
-
additionalProperties: true
|
|
908
|
-
},
|
|
909
|
-
inputs: [],
|
|
910
|
-
outputs: [],
|
|
911
|
-
effects: [],
|
|
912
|
-
onCrash: "restart",
|
|
913
|
-
budget: "metered",
|
|
914
|
-
run: ({ config, profile, inputs }) => scriptAgent(profile, config, inputs, SCRIPT)
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
function scriptAgent(profile, config, inputs, kind) {
|
|
918
|
-
let artifact;
|
|
919
|
-
const spec = {
|
|
920
|
-
profile,
|
|
921
|
-
harness: null,
|
|
922
|
-
executor: {
|
|
923
|
-
runtime: "inline",
|
|
924
|
-
...config.pure ? { budgetExempt: true } : {},
|
|
925
|
-
async execute(_task, signal) {
|
|
926
|
-
const startedAt = Date.now();
|
|
927
|
-
const out = await config.body(inputs, signal);
|
|
928
|
-
const ms = Date.now() - startedAt;
|
|
929
|
-
const spent = config.pure ? {
|
|
930
|
-
iterations: 0,
|
|
931
|
-
tokens: {
|
|
932
|
-
input: 0,
|
|
933
|
-
output: 0
|
|
934
|
-
},
|
|
935
|
-
usd: 0,
|
|
936
|
-
ms
|
|
937
|
-
} : config.spent ?? {
|
|
938
|
-
iterations: 1,
|
|
939
|
-
tokens: {
|
|
940
|
-
input: 0,
|
|
941
|
-
output: 0,
|
|
942
|
-
tokensKnown: false
|
|
943
|
-
},
|
|
944
|
-
tokensKnown: false,
|
|
945
|
-
usd: 0,
|
|
946
|
-
usdKnown: false,
|
|
947
|
-
ms
|
|
948
|
-
};
|
|
949
|
-
artifact = {
|
|
950
|
-
outRef: contentAddress(out),
|
|
951
|
-
out,
|
|
952
|
-
spent
|
|
953
|
-
};
|
|
954
|
-
return artifact;
|
|
955
|
-
},
|
|
956
|
-
teardown: () => Promise.resolve({ destroyed: true }),
|
|
957
|
-
resultArtifact() {
|
|
958
|
-
if (!artifact) throw new ValidationError("script: resultArtifact() read before execute()");
|
|
959
|
-
return artifact;
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
execution: { correlation: { nodeKind: formatRegistryHandle(kind) } }
|
|
963
|
-
};
|
|
964
|
-
return {
|
|
965
|
-
name: profile.name ?? "script",
|
|
966
|
-
act: () => Promise.reject(new ValidationError("script: act() is not the execution path")),
|
|
967
|
-
executorSpec: spec
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* A node carrying its own graph: the constraint on what a supervisor may spawn at depth>1. Its
|
|
972
|
-
* executor is a nested engine run; that needs the scheduler (#980), so until then this kind is
|
|
973
|
-
* registered and REFUSES at run time by name rather than being absent — a graph that names it
|
|
974
|
-
* compiles, and the refusal says exactly what is missing.
|
|
975
|
-
*/
|
|
976
|
-
function subgraphKind() {
|
|
977
|
-
return {
|
|
978
|
-
id: "subgraph",
|
|
979
|
-
version: 1,
|
|
980
|
-
description: "A node that runs its own graph; constrains a supervisor at depth>1.",
|
|
981
|
-
validateConfig: (raw, context) => {
|
|
982
|
-
const config = asRecord(raw, `${context}: subgraph config`);
|
|
983
|
-
if (config.graph === void 0) throw new ValidationError(`${context}: subgraph config.graph is required`);
|
|
984
|
-
return { graph: config.graph };
|
|
985
|
-
},
|
|
986
|
-
configSchema: {
|
|
987
|
-
type: "object",
|
|
988
|
-
properties: { graph: { type: "object" } },
|
|
989
|
-
required: ["graph"]
|
|
990
|
-
},
|
|
991
|
-
inputs: [],
|
|
992
|
-
outputs: [],
|
|
993
|
-
effects: [],
|
|
994
|
-
onCrash: "restart",
|
|
995
|
-
budget: "metered",
|
|
996
|
-
run: ({ profile }) => {
|
|
997
|
-
throw new ValidationError(`subgraph kind: node ${JSON.stringify(profile.name)} cannot run yet — the scheduler that executes a nested graph lands in agent-runtime#980`);
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
function asRecord(value, context) {
|
|
1002
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new ValidationError(`${context} must be an object`);
|
|
1003
|
-
return value;
|
|
1004
|
-
}
|
|
1005
|
-
//#endregion
|
|
1006
|
-
//#region src/runtime/graph/scheduler.ts
|
|
1007
|
-
/**
|
|
1008
|
-
* The engine scheduler (agent-runtime#980, durable per #974/#976): run a compiled graph by hosting
|
|
1009
|
-
* every node instance on one kernel `Scope` — the pool, the journal, the blob store and
|
|
1010
|
-
* cancellation are the kernel's, never re-implemented. The scheduler owns only what a graph adds:
|
|
1011
|
-
* joins over guarded edges, traversal and visit caps, directive/payload delivery, suspensions,
|
|
1012
|
-
* terminals and the finalizer reduce.
|
|
1013
|
-
*
|
|
1014
|
-
* DURABILITY MODEL — fold, never checkpoint. Every scheduling decision is journaled BEFORE its
|
|
1015
|
-
* effect is visible (blob-then-journal where a ref is minted), then applied to in-memory state
|
|
1016
|
-
* through the SAME pure reducer (`applyGraphFoldEvent`) a restart replays the journal through.
|
|
1017
|
-
* Kill the process at any journal boundary and a restart with the same journal re-enters the exact
|
|
1018
|
-
* state: settled nodes restore from `outRef` and are never re-executed; a released-but-unspawned
|
|
1019
|
-
* instance re-enters from its pinned `inputRef`; an in-flight instance is in-doubt and re-enters
|
|
1020
|
-
* per its kind's `onCrash`.
|
|
1021
|
-
*
|
|
1022
|
-
* Engine `woken` ordinals live in a reserved high band (`ENGINE_WOKEN_SEQ_BASE`+) so they can
|
|
1023
|
-
* never collide with the kernel scope's cursor counter, which the kernel owns and advances
|
|
1024
|
-
* concurrently.
|
|
1025
|
-
*/
|
|
1026
|
-
/** Engine-appended `woken` ordinals start here — far above any kernel cursor counter. */
|
|
1027
|
-
const ENGINE_WOKEN_SEQ_BASE = 1e7;
|
|
1028
|
-
const SUSPEND_MARK = "__graphSuspension";
|
|
1029
|
-
/** What a kind's executor returns to park its node on a host wake (agent-runtime#976). */
|
|
1030
|
-
function suspended(options = {}) {
|
|
1031
|
-
const onExpire = options.onExpire ?? "wait";
|
|
1032
|
-
if (onExpire !== "wait" && options.expiresInMs === void 0) throw new ValidationError(`suspended: onExpire '${onExpire}' requires expiresInMs`);
|
|
1033
|
-
if (onExpire === "wait" && options.expiresInMs !== void 0) throw new ValidationError("suspended: onExpire 'wait' never expires — remove expiresInMs");
|
|
1034
|
-
if (onExpire === "default" && options.default === void 0) throw new ValidationError("suspended: onExpire 'default' requires a default payload");
|
|
1035
|
-
return {
|
|
1036
|
-
[SUSPEND_MARK]: true,
|
|
1037
|
-
onExpire,
|
|
1038
|
-
...options.expiresInMs !== void 0 ? { expiresInMs: options.expiresInMs } : {},
|
|
1039
|
-
...options.default !== void 0 ? { default: options.default } : {}
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
function isSuspensionRequest(value) {
|
|
1043
|
-
return typeof value === "object" && value !== null && value[SUSPEND_MARK] === true;
|
|
1044
|
-
}
|
|
1045
|
-
/** Admission for every value crossing an edge (#971): JSON round-trip, `undefined` stripped, a
|
|
1046
|
-
* non-representable value becomes a RECORD of that fact — a degraded record beats a vanished
|
|
1047
|
-
* edge. */
|
|
1048
|
-
function admitPayload(value) {
|
|
1049
|
-
if (value === void 0) return void 0;
|
|
1050
|
-
try {
|
|
1051
|
-
const text = JSON.stringify(value);
|
|
1052
|
-
if (text === void 0) return { nonCanonical: `payload of type ${typeof value}` };
|
|
1053
|
-
return JSON.parse(text);
|
|
1054
|
-
} catch (error) {
|
|
1055
|
-
return { nonCanonical: error instanceof Error ? error.message : String(error) };
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
/** Run a graph to its result: `createGraphRun` awaited — the one-call form for a run that needs
|
|
1059
|
-
* no live host wakes. */
|
|
1060
|
-
async function runEngineGraph(engine, spec, task, options) {
|
|
1061
|
-
return createGraphRun(engine, spec, task, options).done;
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Start (or resume) a graph run and return its handle: await `done` for the result; deliver host
|
|
1065
|
-
* wakes through `resume`/`expire` while it runs (#976).
|
|
1066
|
-
*/
|
|
1067
|
-
function createGraphRun(engine, spec, task, options) {
|
|
1068
|
-
const compiled = "nodes" in spec && spec.nodes instanceof Map ? spec : compileGraph(engine, spec);
|
|
1069
|
-
const wakes = [];
|
|
1070
|
-
let notifyWake;
|
|
1071
|
-
const handleState = { finished: false };
|
|
1072
|
-
const done = runGraphLoop(engine, compiled, task, options, wakes, () => notifyWake?.(), (fn) => {
|
|
1073
|
-
notifyWake = fn;
|
|
1074
|
-
}).finally(() => {
|
|
1075
|
-
handleState.finished = true;
|
|
1076
|
-
});
|
|
1077
|
-
const queue = (token, payload, expire) => {
|
|
1078
|
-
if (handleState.finished) return Promise.reject(new ValidationError(`graph resume: run completed; start a new run over the same journal to wake '${token}'`));
|
|
1079
|
-
return new Promise((settle, fail) => {
|
|
1080
|
-
wakes.push({
|
|
1081
|
-
token,
|
|
1082
|
-
payload,
|
|
1083
|
-
expire,
|
|
1084
|
-
settle,
|
|
1085
|
-
fail
|
|
1086
|
-
});
|
|
1087
|
-
notifyWake?.();
|
|
1088
|
-
});
|
|
1089
|
-
};
|
|
1090
|
-
return {
|
|
1091
|
-
done,
|
|
1092
|
-
resume: (token, payload) => queue(token, payload, false),
|
|
1093
|
-
expire: (token) => queue(token, void 0, true)
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
async function runGraphLoop(engine, compiled, task, options, wakes, _notify, onWakeSignal) {
|
|
1097
|
-
const context = "runEngineGraph";
|
|
1098
|
-
for (const node of compiled.nodes.values()) {
|
|
1099
|
-
const missing = node.kind.effects.filter((name) => !(name in engine.effects));
|
|
1100
|
-
if (missing.length > 0) throw new ValidationError(`${context}: node ${node.id} needs effect(s) ${missing.join(", ")} the host did not provide`);
|
|
1101
|
-
if (node.spec.budget === void 0 && options.perNode === void 0) throw new ValidationError(`${context}: node ${node.id} declares no budget and options.perNode is absent — the engine invents no split`);
|
|
1102
|
-
}
|
|
1103
|
-
for (const edge of compiled.edges) if (edge.spec.directive !== void 0 && options.prompts === void 0) throw new ValidationError(`${context}: edge ${edge.id} carries a directive but options.prompts is absent`);
|
|
1104
|
-
const now = options.now ?? Date.now;
|
|
1105
|
-
const journal = options.journal ?? new InMemorySpawnJournal();
|
|
1106
|
-
const blobs = options.blobs ?? new InMemoryResultBlobStore();
|
|
1107
|
-
const runId = options.runId ?? `graph:${contentAddress({ task }).slice(0, 18)}`;
|
|
1108
|
-
const prior = await journal.loadTree(runId);
|
|
1109
|
-
if (prior !== void 0 && options.resume !== true) throw new ValidationError(`${context}: runId '${runId}' already exists; pass resume: true to continue it or use a new runId`);
|
|
1110
|
-
const resuming = options.resume === true && prior !== void 0 && prior.length > 0;
|
|
1111
|
-
let runEpochMs = now();
|
|
1112
|
-
let rootBudget = options.budget;
|
|
1113
|
-
if (prior === void 0) await journal.beginTree(runId, new Date(runEpochMs).toISOString());
|
|
1114
|
-
if (!resuming) await journal.appendEvent(runId, {
|
|
1115
|
-
kind: "spawned",
|
|
1116
|
-
id: runId,
|
|
1117
|
-
label: "graph-root",
|
|
1118
|
-
budget: options.budget,
|
|
1119
|
-
runtime: "inline",
|
|
1120
|
-
seq: 0,
|
|
1121
|
-
at: new Date(runEpochMs).toISOString()
|
|
1122
|
-
});
|
|
1123
|
-
if (resuming) {
|
|
1124
|
-
const root = prior.find((ev) => ev.kind === "spawned" && ev.id === runId);
|
|
1125
|
-
if (root?.kind === "spawned") {
|
|
1126
|
-
runEpochMs = Date.parse(root.at);
|
|
1127
|
-
rootBudget = root.budget;
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
const elapsed = () => now() - runEpochMs;
|
|
1131
|
-
const pool = resuming ? createBudgetPool(rootBudget, elapsed, {
|
|
1132
|
-
committed: (() => {
|
|
1133
|
-
const measured = sumMeasuredSpendFromEvents(prior);
|
|
1134
|
-
return addSpend(measured.childWork, measured.driverInference);
|
|
1135
|
-
})(),
|
|
1136
|
-
uncertainReservations: uncertainSpawnBudgets(prior),
|
|
1137
|
-
...rootBudget.deadlineMs !== void 0 ? { absoluteDeadlineMs: runEpochMs + rootBudget.deadlineMs } : {}
|
|
1138
|
-
}) : createBudgetPool(rootBudget, elapsed);
|
|
1139
|
-
const abort = new AbortController();
|
|
1140
|
-
const onOuterAbort = () => abort.abort(options.signal?.reason);
|
|
1141
|
-
options.signal?.addEventListener("abort", onOuterAbort, { once: true });
|
|
1142
|
-
if (options.signal?.aborted) abort.abort(options.signal.reason);
|
|
1143
|
-
const scope = createScope({
|
|
1144
|
-
parentId: runId,
|
|
1145
|
-
root: runId,
|
|
1146
|
-
pool,
|
|
1147
|
-
journal,
|
|
1148
|
-
blobs,
|
|
1149
|
-
executors: createExecutorRegistry(),
|
|
1150
|
-
seams: {},
|
|
1151
|
-
depth: 0,
|
|
1152
|
-
signal: abort.signal,
|
|
1153
|
-
now,
|
|
1154
|
-
...resuming ? { resumeFrom: {
|
|
1155
|
-
settled: await replaySpawnTree(journal, blobs, runId),
|
|
1156
|
-
view: materializeTreeView(prior),
|
|
1157
|
-
maxSpawnOrdinal: maxSeqOf(prior, (ev) => ev.kind === "spawned"),
|
|
1158
|
-
maxCursorSeq: maxSeqOf(prior, closesCursorSlot),
|
|
1159
|
-
maxWaitOrdinal: maxSeqOf(prior, (ev) => ev.kind === "waiting"),
|
|
1160
|
-
waits: pendingWaits(prior),
|
|
1161
|
-
keys: /* @__PURE__ */ new Map(),
|
|
1162
|
-
priorSpend: sumMeasuredSpendFromEvents(prior)
|
|
1163
|
-
} } : {}
|
|
1164
|
-
});
|
|
1165
|
-
try {
|
|
1166
|
-
return await runToResult();
|
|
1167
|
-
} finally {
|
|
1168
|
-
options.signal?.removeEventListener("abort", onOuterAbort);
|
|
1169
|
-
abort.abort("run complete");
|
|
1170
|
-
}
|
|
1171
|
-
async function runToResult() {
|
|
1172
|
-
const state = emptyFoldState(compiled);
|
|
1173
|
-
if (resuming) for (const ev of prior) applyGraphFoldEvent(state, ev, compiled);
|
|
1174
|
-
let engineSeq = resuming ? maxEngineSeq(prior) + 1 : 0;
|
|
1175
|
-
let engineWokenSeq = ENGINE_WOKEN_SEQ_BASE + (resuming ? prior.filter((ev) => ev.kind === "woken" && ev.seq >= 1e7).length : 0);
|
|
1176
|
-
const appendAndApply = async (ev) => {
|
|
1177
|
-
await journal.appendEvent(runId, ev);
|
|
1178
|
-
applyGraphFoldEvent(state, ev, compiled);
|
|
1179
|
-
};
|
|
1180
|
-
const ledger = [];
|
|
1181
|
-
const liveHandles = /* @__PURE__ */ new Map();
|
|
1182
|
-
const waitingForBudget = [];
|
|
1183
|
-
const outCache = /* @__PURE__ */ new Map();
|
|
1184
|
-
let ledgerSeq = resuming ? prior.filter((ev) => ev.kind === "edge").length : 0;
|
|
1185
|
-
let liveCount = 0;
|
|
1186
|
-
let failure;
|
|
1187
|
-
const recordLedger = async (edge, traversal, outcome, reason) => {
|
|
1188
|
-
const spec = edge.spec;
|
|
1189
|
-
const entry = {
|
|
1190
|
-
edge: edge.id,
|
|
1191
|
-
kind: spec.kind,
|
|
1192
|
-
from: spec.from.node,
|
|
1193
|
-
to: spec.to.node,
|
|
1194
|
-
traversal,
|
|
1195
|
-
outcome,
|
|
1196
|
-
...spec.directive !== void 0 ? { directive: `${spec.directive.surface}/v${spec.directive.version}` } : {},
|
|
1197
|
-
...spec.kind === "data" ? { port: edge.toPort } : {},
|
|
1198
|
-
...reason !== void 0 ? { reason } : {}
|
|
1199
|
-
};
|
|
1200
|
-
ledger.push(entry);
|
|
1201
|
-
await journal.appendEvent(runId, {
|
|
1202
|
-
kind: "edge",
|
|
1203
|
-
id: `graph:${spec.to.node}`,
|
|
1204
|
-
edge: {
|
|
1205
|
-
kind: spec.kind,
|
|
1206
|
-
from: spec.from.node,
|
|
1207
|
-
to: spec.to.node,
|
|
1208
|
-
...entry.directive !== void 0 ? { directive: entry.directive } : {},
|
|
1209
|
-
...entry.port !== void 0 ? { port: entry.port } : {}
|
|
1210
|
-
},
|
|
1211
|
-
traversal,
|
|
1212
|
-
outcome: outcome === "delivered" ? "delivered" : outcome,
|
|
1213
|
-
bytes: 0,
|
|
1214
|
-
...reason !== void 0 ? { reason } : {},
|
|
1215
|
-
seq: ledgerSeq++,
|
|
1216
|
-
at: new Date(now()).toISOString()
|
|
1217
|
-
});
|
|
1218
|
-
};
|
|
1219
|
-
/** Spawn one released instance from its journaled envelope — the ONE entry path, used for a
|
|
1220
|
-
* fresh release, a budget-parked retry, and a restart re-entry alike. */
|
|
1221
|
-
const spawnInstance = async (instanceLabel) => {
|
|
1222
|
-
if (failure) return;
|
|
1223
|
-
const instance = state.instances.get(instanceLabel);
|
|
1224
|
-
const node = instance === void 0 ? void 0 : compiled.nodes.get(instance.node);
|
|
1225
|
-
if (!instance || !node || instance.inputRef === void 0) throw new ValidationError(`${context}: instance ${instanceLabel} has no journaled envelope`);
|
|
1226
|
-
const envelope = await blobs.get(instance.inputRef);
|
|
1227
|
-
if (envelope === void 0) throw new ValidationError(`${context}: envelope ${instance.inputRef} is not in the blob store`);
|
|
1228
|
-
const effects = narrowEffects(node.kind.effects, engine.effects, `${context}: node ${node.id}`);
|
|
1229
|
-
const agent = node.kind.run({
|
|
1230
|
-
config: node.config,
|
|
1231
|
-
profile: {
|
|
1232
|
-
name: node.id,
|
|
1233
|
-
...node.spec.profile ?? {}
|
|
1234
|
-
},
|
|
1235
|
-
inputs: envelope.inputs,
|
|
1236
|
-
effects
|
|
1237
|
-
});
|
|
1238
|
-
const budget = node.spec.budget ?? options.perNode;
|
|
1239
|
-
const spawned = scope.spawn(agent, envelope.task, {
|
|
1240
|
-
label: instanceLabel,
|
|
1241
|
-
budget
|
|
1242
|
-
});
|
|
1243
|
-
if (spawned.ok) {
|
|
1244
|
-
liveCount += 1;
|
|
1245
|
-
liveHandles.set(spawned.handle.id, instanceLabel);
|
|
1246
|
-
applyGraphFoldEvent(state, {
|
|
1247
|
-
kind: "spawned",
|
|
1248
|
-
id: spawned.handle.id,
|
|
1249
|
-
label: instanceLabel,
|
|
1250
|
-
budget,
|
|
1251
|
-
runtime: "inline",
|
|
1252
|
-
seq: 0,
|
|
1253
|
-
at: ""
|
|
1254
|
-
}, compiled);
|
|
1255
|
-
return;
|
|
1256
|
-
}
|
|
1257
|
-
if (spawned.reason === "budget-exhausted" || spawned.reason === "max-live-workers") {
|
|
1258
|
-
waitingForBudget.push(instanceLabel);
|
|
1259
|
-
return;
|
|
1260
|
-
}
|
|
1261
|
-
failure = {
|
|
1262
|
-
reason: "driver-failed",
|
|
1263
|
-
error: {
|
|
1264
|
-
name: "SpawnRefused",
|
|
1265
|
-
message: `node ${node.id}: ${spawned.reason}`
|
|
1266
|
-
}
|
|
1267
|
-
};
|
|
1268
|
-
abort.abort(`spawn refused: ${node.id}`);
|
|
1269
|
-
};
|
|
1270
|
-
/** Release a node: journal the wave (join-state + envelope) then spawn. */
|
|
1271
|
-
const release = async (nodeId, satisfiedBy, consumedPending) => {
|
|
1272
|
-
const node = compiled.nodes.get(nodeId);
|
|
1273
|
-
const folded = state.nodes.get(nodeId);
|
|
1274
|
-
if (!node || !folded) return;
|
|
1275
|
-
const visit = folded.visits + 1;
|
|
1276
|
-
if (visit > node.maxVisits) {
|
|
1277
|
-
failure = {
|
|
1278
|
-
reason: "cycle-budget-exceeded",
|
|
1279
|
-
error: {
|
|
1280
|
-
name: "GraphCycleBudget",
|
|
1281
|
-
message: `node ${nodeId} entered ${visit} times; maxVisits ${node.maxVisits}`
|
|
1282
|
-
}
|
|
1283
|
-
};
|
|
1284
|
-
abort.abort(`cycle-budget-exceeded: ${nodeId}`);
|
|
1285
|
-
return;
|
|
1286
|
-
}
|
|
1287
|
-
const instanceLabel = `${nodeId}#${visit}`;
|
|
1288
|
-
const inputs = {};
|
|
1289
|
-
const directives = [];
|
|
1290
|
-
const traces = [];
|
|
1291
|
-
for (const edge of satisfiedBy) {
|
|
1292
|
-
const foldedEdge = state.edges.get(edge.id);
|
|
1293
|
-
const spec = edge.spec;
|
|
1294
|
-
if (spec.kind === "data" && foldedEdge?.state === "satisfied") {
|
|
1295
|
-
let payload = foldedEdge.payloadRef === void 0 ? void 0 : outCache.get(foldedEdge.payloadRef);
|
|
1296
|
-
if (payload === void 0 && foldedEdge.payloadRef !== void 0) payload = admitPayload(await blobs.get(foldedEdge.payloadRef));
|
|
1297
|
-
let outcome = "delivered";
|
|
1298
|
-
let reason;
|
|
1299
|
-
if (spec.projection !== void 0) try {
|
|
1300
|
-
payload = admitPayload(applyProjection(payload, spec.projection, `edge ${edge.id}`));
|
|
1301
|
-
} catch (error) {
|
|
1302
|
-
outcome = "empty";
|
|
1303
|
-
reason = error instanceof Error ? error.message : String(error);
|
|
1304
|
-
payload = void 0;
|
|
1305
|
-
}
|
|
1306
|
-
if (payload === void 0 && outcome === "delivered") outcome = "empty";
|
|
1307
|
-
await recordLedger(edge, (foldedEdge?.traversals ?? 0) + 1, outcome, reason);
|
|
1308
|
-
if (payload !== void 0) inputs[edge.toPort] = payload;
|
|
1309
|
-
} else {
|
|
1310
|
-
if (spec.directive !== void 0 && options.prompts !== void 0) directives.push(options.prompts.resolve(spec.directive).text);
|
|
1311
|
-
if (spec.kind === "analyzes" && foldedEdge?.state === "satisfied") traces.push(`trace of ${spec.from.node}: ${foldedEdge.payloadRef ?? "(no traceRef)"}`);
|
|
1312
|
-
await recordLedger(edge, (foldedEdge?.traversals ?? 0) + 1, "delivered");
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
const nodeTask = [
|
|
1316
|
-
nodeId === compiled.root ? task : "",
|
|
1317
|
-
...directives,
|
|
1318
|
-
...traces
|
|
1319
|
-
].filter((part) => part.length > 0).join("\n\n");
|
|
1320
|
-
const envelope = {
|
|
1321
|
-
task: nodeTask.length > 0 ? nodeTask : task,
|
|
1322
|
-
inputs
|
|
1323
|
-
};
|
|
1324
|
-
const inputRef = contentAddress(envelope);
|
|
1325
|
-
await blobs.put(inputRef, envelope);
|
|
1326
|
-
const at = new Date(now()).toISOString();
|
|
1327
|
-
await appendAndApply({
|
|
1328
|
-
kind: "node-inputs-resolved",
|
|
1329
|
-
id: instanceLabel,
|
|
1330
|
-
node: nodeId,
|
|
1331
|
-
instance: instanceLabel,
|
|
1332
|
-
inputRef,
|
|
1333
|
-
seq: engineSeq++,
|
|
1334
|
-
at
|
|
1335
|
-
});
|
|
1336
|
-
await appendAndApply({
|
|
1337
|
-
kind: "join-state",
|
|
1338
|
-
id: instanceLabel,
|
|
1339
|
-
node: nodeId,
|
|
1340
|
-
rule: node.join,
|
|
1341
|
-
satisfiedBy: satisfiedBy.map((edge) => edge.id),
|
|
1342
|
-
consumedPending,
|
|
1343
|
-
instance: instanceLabel,
|
|
1344
|
-
seq: engineSeq++,
|
|
1345
|
-
at
|
|
1346
|
-
});
|
|
1347
|
-
await spawnInstance(instanceLabel);
|
|
1348
|
-
};
|
|
1349
|
-
/** Join evaluation per ADC's rules over the folded edge states. */
|
|
1350
|
-
const tryRelease = async (nodeId) => {
|
|
1351
|
-
const node = compiled.nodes.get(nodeId);
|
|
1352
|
-
const folded = state.nodes.get(nodeId);
|
|
1353
|
-
if (!node || !folded || folded.blocked || failure) return;
|
|
1354
|
-
const gating = node.inbound;
|
|
1355
|
-
if (gating.length === 0) return;
|
|
1356
|
-
const states = gating.map((edge) => ({
|
|
1357
|
-
edge,
|
|
1358
|
-
folded: state.edges.get(edge.id)
|
|
1359
|
-
}));
|
|
1360
|
-
const settled = states.filter((entry) => entry.folded && entry.folded.state !== "pending");
|
|
1361
|
-
const satisfied = states.filter((entry) => entry.folded?.state === "satisfied");
|
|
1362
|
-
const failed = states.filter((entry) => entry.folded?.state === "failed");
|
|
1363
|
-
const allSettled = settled.length === gating.length;
|
|
1364
|
-
let releaseNow = false;
|
|
1365
|
-
switch (node.join) {
|
|
1366
|
-
case "all":
|
|
1367
|
-
releaseNow = satisfied.length === gating.length && !states.some((entry) => entry.folded?.state === "dead" || entry.folded?.state === "failed");
|
|
1368
|
-
break;
|
|
1369
|
-
case "any":
|
|
1370
|
-
releaseNow = satisfied.length > 0;
|
|
1371
|
-
if (!releaseNow && allSettled) folded.blocked = true;
|
|
1372
|
-
break;
|
|
1373
|
-
case "any_failed":
|
|
1374
|
-
releaseNow = failed.length > 0;
|
|
1375
|
-
if (!releaseNow && allSettled) folded.blocked = true;
|
|
1376
|
-
break;
|
|
1377
|
-
case "all_done":
|
|
1378
|
-
releaseNow = allSettled;
|
|
1379
|
-
break;
|
|
1380
|
-
}
|
|
1381
|
-
if (!releaseNow) return;
|
|
1382
|
-
const consuming = node.join === "any" ? [satisfied[0]] : node.join === "any_failed" ? [failed[0]] : settled;
|
|
1383
|
-
for (const entry of consuming) {
|
|
1384
|
-
const cap = entry.edge.spec.maxTraversals;
|
|
1385
|
-
if (cap !== void 0 && (entry.folded?.traversals ?? 0) >= cap) {
|
|
1386
|
-
recordLedger(entry.edge, (entry.folded?.traversals ?? 0) + 1, "unpropagated", `traversal-cap-exhausted (max ${cap})`);
|
|
1387
|
-
await appendAndApply({
|
|
1388
|
-
kind: "edge-verdict",
|
|
1389
|
-
id: `graph:${nodeId}`,
|
|
1390
|
-
edge: entry.edge.id,
|
|
1391
|
-
fired: false,
|
|
1392
|
-
sourceStatus: "done",
|
|
1393
|
-
capped: true,
|
|
1394
|
-
seq: engineSeq++,
|
|
1395
|
-
at: new Date(now()).toISOString()
|
|
1396
|
-
});
|
|
1397
|
-
return;
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
const consumedPending = states.filter((entry) => entry.folded?.state === "pending" && hasLiveInstance(state, liveHandles, entry.edge.spec.from.node)).map((entry) => entry.edge.id);
|
|
1401
|
-
await release(nodeId, consuming.map((entry) => entry.edge), consumedPending);
|
|
1402
|
-
};
|
|
1403
|
-
/** Judge every outbound edge of a settle: journal the verdict, apply, then try the joins. */
|
|
1404
|
-
const propagate = async (instanceLabel, settle) => {
|
|
1405
|
-
const node = compiled.nodes.get(settle.node);
|
|
1406
|
-
if (!node) return;
|
|
1407
|
-
const succeeded = settle.status === "done" && settle.valid !== false;
|
|
1408
|
-
const sourceSettles = state.nodes.get(settle.node)?.settles.length ?? 0;
|
|
1409
|
-
for (const edge of node.outbound) {
|
|
1410
|
-
const folded = state.edges.get(edge.id);
|
|
1411
|
-
if (!folded) continue;
|
|
1412
|
-
if (folded.judgedSourceSettles >= sourceSettles) continue;
|
|
1413
|
-
let fired = false;
|
|
1414
|
-
let inputRef;
|
|
1415
|
-
if (succeeded) {
|
|
1416
|
-
const guardContext = {
|
|
1417
|
-
node: settle.node,
|
|
1418
|
-
out: settle.out,
|
|
1419
|
-
visits: state.nodes.get(settle.node)?.visits ?? 0,
|
|
1420
|
-
valid: settle.valid ?? true
|
|
1421
|
-
};
|
|
1422
|
-
fired = edge.spec.guard === void 0 || evaluateCondition(edge.spec.guard, guardContext);
|
|
1423
|
-
if (fired) inputRef = edge.spec.kind === "analyzes" ? settle.traceRef ?? void 0 : settle.outRef;
|
|
1424
|
-
}
|
|
1425
|
-
await appendAndApply({
|
|
1426
|
-
kind: "edge-verdict",
|
|
1427
|
-
id: instanceLabel,
|
|
1428
|
-
edge: edge.id,
|
|
1429
|
-
fired,
|
|
1430
|
-
sourceStatus: settle.status === "down" ? "down" : succeeded ? "done" : "invalid",
|
|
1431
|
-
...inputRef !== void 0 ? { inputRef } : {},
|
|
1432
|
-
seq: engineSeq++,
|
|
1433
|
-
at: new Date(now()).toISOString()
|
|
1434
|
-
});
|
|
1435
|
-
}
|
|
1436
|
-
for (const edge of node.outbound) await tryRelease(edge.spec.to.node);
|
|
1437
|
-
};
|
|
1438
|
-
const mintToken = (instanceLabel) => contentAddress({
|
|
1439
|
-
runId,
|
|
1440
|
-
instance: instanceLabel,
|
|
1441
|
-
kind: "graph-suspension"
|
|
1442
|
-
});
|
|
1443
|
-
const journalSuspension = async (instanceLabel, request) => {
|
|
1444
|
-
const token = mintToken(instanceLabel);
|
|
1445
|
-
let defaultRef;
|
|
1446
|
-
if (request.default !== void 0) {
|
|
1447
|
-
const admitted = admitPayload(request.default);
|
|
1448
|
-
defaultRef = contentAddress(admitted);
|
|
1449
|
-
await blobs.put(defaultRef, admitted);
|
|
1450
|
-
}
|
|
1451
|
-
await appendAndApply({
|
|
1452
|
-
kind: "waiting",
|
|
1453
|
-
id: `graphwait:${token}`,
|
|
1454
|
-
label: instanceLabel,
|
|
1455
|
-
spec: {
|
|
1456
|
-
kind: "token",
|
|
1457
|
-
token,
|
|
1458
|
-
onExpire: request.onExpire,
|
|
1459
|
-
...request.expiresInMs !== void 0 ? { expiresAtMs: now() + request.expiresInMs } : {},
|
|
1460
|
-
...defaultRef !== void 0 ? { defaultRef } : {}
|
|
1461
|
-
},
|
|
1462
|
-
armedAt: now(),
|
|
1463
|
-
seq: engineSeq++,
|
|
1464
|
-
at: new Date(now()).toISOString()
|
|
1465
|
-
});
|
|
1466
|
-
};
|
|
1467
|
-
const wake = async (suspension, by, outRef) => {
|
|
1468
|
-
await appendAndApply({
|
|
1469
|
-
kind: "woken",
|
|
1470
|
-
id: `graphwait:${suspension.token}`,
|
|
1471
|
-
by,
|
|
1472
|
-
...outRef !== void 0 ? { outRef } : {},
|
|
1473
|
-
seq: engineWokenSeq++,
|
|
1474
|
-
at: new Date(now()).toISOString()
|
|
1475
|
-
});
|
|
1476
|
-
const settle = state.instances.get(suspension.instance)?.settle;
|
|
1477
|
-
if (settle !== void 0) {
|
|
1478
|
-
const enriched = {
|
|
1479
|
-
...settle,
|
|
1480
|
-
...settle.outRef !== void 0 ? { out: admitPayload(await blobs.get(settle.outRef)) } : {}
|
|
1481
|
-
};
|
|
1482
|
-
if (enriched.outRef !== void 0 && enriched.out !== void 0) outCache.set(enriched.outRef, enriched.out);
|
|
1483
|
-
await propagate(suspension.instance, enriched);
|
|
1484
|
-
}
|
|
1485
|
-
};
|
|
1486
|
-
/** Expiries are engine-clocked: judged on every loop turn and before parking (#976). */
|
|
1487
|
-
const sweepExpiries = async () => {
|
|
1488
|
-
for (const suspension of [...state.suspensions.values()]) {
|
|
1489
|
-
if (suspension.status !== "pending") continue;
|
|
1490
|
-
if (suspension.expiresAtMs === void 0 || now() < suspension.expiresAtMs) continue;
|
|
1491
|
-
if (suspension.onExpire === "fail") await wake(suspension, "expired");
|
|
1492
|
-
else if (suspension.onExpire === "default") await wake(suspension, "fired", suspension.defaultRef);
|
|
1493
|
-
}
|
|
1494
|
-
};
|
|
1495
|
-
const processWakes = async () => {
|
|
1496
|
-
while (wakes.length > 0) {
|
|
1497
|
-
const request = wakes.shift();
|
|
1498
|
-
if (!request) break;
|
|
1499
|
-
try {
|
|
1500
|
-
const suspension = state.suspensions.get(request.token);
|
|
1501
|
-
if (!suspension) throw new ValidationError(`graph resume: unknown token '${request.token}'`);
|
|
1502
|
-
if (suspension.status !== "pending") throw new ValidationError(`graph resume: token '${request.token}' already woken`);
|
|
1503
|
-
if (request.expire) if (suspension.onExpire === "fail") await wake(suspension, "expired");
|
|
1504
|
-
else if (suspension.onExpire === "default") await wake(suspension, "fired", suspension.defaultRef);
|
|
1505
|
-
else await wake(suspension, "expired");
|
|
1506
|
-
else {
|
|
1507
|
-
const admitted = admitPayload(request.payload);
|
|
1508
|
-
const outRef = contentAddress(admitted);
|
|
1509
|
-
await blobs.put(outRef, admitted);
|
|
1510
|
-
outCache.set(outRef, admitted);
|
|
1511
|
-
await wake(suspension, "fired", outRef);
|
|
1512
|
-
}
|
|
1513
|
-
request.settle();
|
|
1514
|
-
} catch (error) {
|
|
1515
|
-
request.fail(error);
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
};
|
|
1519
|
-
const handleSettle = async (settled) => {
|
|
1520
|
-
const instanceLabel = liveHandles.get(settled.handle.id);
|
|
1521
|
-
if (instanceLabel === void 0) return;
|
|
1522
|
-
liveHandles.delete(settled.handle.id);
|
|
1523
|
-
liveCount -= 1;
|
|
1524
|
-
const instance = state.instances.get(instanceLabel);
|
|
1525
|
-
const node = instance === void 0 ? void 0 : compiled.nodes.get(instance.node);
|
|
1526
|
-
if (!instance || !node) return;
|
|
1527
|
-
if (settled.kind === "done" && isSuspensionRequest(settled.out)) {
|
|
1528
|
-
await journalSuspension(instanceLabel, settled.out);
|
|
1529
|
-
return;
|
|
1530
|
-
}
|
|
1531
|
-
applyGraphFoldEvent(state, {
|
|
1532
|
-
kind: "settled",
|
|
1533
|
-
id: settled.handle.id,
|
|
1534
|
-
status: settled.kind === "done" ? "done" : "down",
|
|
1535
|
-
...settled.kind === "done" ? { outRef: settled.outRef } : {},
|
|
1536
|
-
...settled.kind === "down" ? { reason: settled.reason } : {},
|
|
1537
|
-
...settled.kind === "done" && settled.trace?.status === "available" ? { trace: settled.trace } : {},
|
|
1538
|
-
spent: {
|
|
1539
|
-
iterations: 0,
|
|
1540
|
-
tokens: {
|
|
1541
|
-
input: 0,
|
|
1542
|
-
output: 0
|
|
1543
|
-
},
|
|
1544
|
-
usd: 0,
|
|
1545
|
-
ms: 0
|
|
1546
|
-
},
|
|
1547
|
-
seq: 0,
|
|
1548
|
-
at: ""
|
|
1549
|
-
}, compiled);
|
|
1550
|
-
const folded = state.instances.get(instanceLabel)?.settle;
|
|
1551
|
-
if (!folded) return;
|
|
1552
|
-
let enriched = folded;
|
|
1553
|
-
if (settled.kind === "done") {
|
|
1554
|
-
const admitted = admitPayload(settled.out);
|
|
1555
|
-
if (settled.outRef !== void 0) outCache.set(settled.outRef, admitted);
|
|
1556
|
-
let valid;
|
|
1557
|
-
if (node.deliverable !== void 0) try {
|
|
1558
|
-
valid = await node.deliverable.check(admitted);
|
|
1559
|
-
} catch {
|
|
1560
|
-
valid = false;
|
|
1561
|
-
}
|
|
1562
|
-
enriched = {
|
|
1563
|
-
...folded,
|
|
1564
|
-
out: admitted,
|
|
1565
|
-
...valid !== void 0 ? { valid } : {}
|
|
1566
|
-
};
|
|
1567
|
-
state.instances.get(instanceLabel).settle = enriched;
|
|
1568
|
-
const settles = state.nodes.get(instance.node)?.settles;
|
|
1569
|
-
if (settles) settles[settles.length - 1] = enriched;
|
|
1570
|
-
}
|
|
1571
|
-
if (instance.node === compiled.root && enriched.status === "done" && enriched.valid === true) {
|
|
1572
|
-
abort.abort("root delivered");
|
|
1573
|
-
return;
|
|
1574
|
-
}
|
|
1575
|
-
await propagate(instanceLabel, enriched);
|
|
1576
|
-
};
|
|
1577
|
-
const enterEntryNode = async (nodeId) => {
|
|
1578
|
-
const folded = state.nodes.get(nodeId);
|
|
1579
|
-
if (!folded) return;
|
|
1580
|
-
const visit = folded.visits + 1;
|
|
1581
|
-
const node = compiled.nodes.get(nodeId);
|
|
1582
|
-
if (!node) return;
|
|
1583
|
-
if (visit > node.maxVisits) return;
|
|
1584
|
-
const instanceLabel = `${nodeId}#${visit}`;
|
|
1585
|
-
const envelope = {
|
|
1586
|
-
task,
|
|
1587
|
-
inputs: {}
|
|
1588
|
-
};
|
|
1589
|
-
const inputRef = contentAddress(envelope);
|
|
1590
|
-
await blobs.put(inputRef, envelope);
|
|
1591
|
-
await appendAndApply({
|
|
1592
|
-
kind: "node-inputs-resolved",
|
|
1593
|
-
id: instanceLabel,
|
|
1594
|
-
node: nodeId,
|
|
1595
|
-
instance: instanceLabel,
|
|
1596
|
-
inputRef,
|
|
1597
|
-
seq: engineSeq++,
|
|
1598
|
-
at: new Date(now()).toISOString()
|
|
1599
|
-
});
|
|
1600
|
-
await spawnInstance(instanceLabel);
|
|
1601
|
-
};
|
|
1602
|
-
if (!resuming) for (const id of compiled.entries) await enterEntryNode(id);
|
|
1603
|
-
else {
|
|
1604
|
-
for (const instance of [...state.instances.values()]) if (instance.status === "released") await spawnInstance(instance.instance);
|
|
1605
|
-
else if (instance.status === "live") {
|
|
1606
|
-
const node = compiled.nodes.get(instance.node);
|
|
1607
|
-
const folded = state.nodes.get(instance.node);
|
|
1608
|
-
if (!node || !folded) continue;
|
|
1609
|
-
const visit = folded.visits + 1;
|
|
1610
|
-
if (visit > node.maxVisits) {
|
|
1611
|
-
failure = {
|
|
1612
|
-
reason: "cycle-budget-exceeded",
|
|
1613
|
-
error: {
|
|
1614
|
-
name: "GraphCycleBudget",
|
|
1615
|
-
message: `node ${instance.node} entered ${visit} times; maxVisits ${node.maxVisits}`
|
|
1616
|
-
}
|
|
1617
|
-
};
|
|
1618
|
-
break;
|
|
1619
|
-
}
|
|
1620
|
-
const restartLabel = `${instance.node}#${visit}`;
|
|
1621
|
-
instance.status = "down";
|
|
1622
|
-
const at = new Date(now()).toISOString();
|
|
1623
|
-
await journal.appendEvent(runId, {
|
|
1624
|
-
kind: "node-inputs-resolved",
|
|
1625
|
-
id: restartLabel,
|
|
1626
|
-
node: instance.node,
|
|
1627
|
-
instance: restartLabel,
|
|
1628
|
-
inputRef: instance.inputRef,
|
|
1629
|
-
seq: engineSeq++,
|
|
1630
|
-
at
|
|
1631
|
-
});
|
|
1632
|
-
applyGraphFoldEvent(state, {
|
|
1633
|
-
kind: "node-inputs-resolved",
|
|
1634
|
-
id: restartLabel,
|
|
1635
|
-
node: instance.node,
|
|
1636
|
-
instance: restartLabel,
|
|
1637
|
-
inputRef: instance.inputRef,
|
|
1638
|
-
seq: 0,
|
|
1639
|
-
at
|
|
1640
|
-
}, compiled);
|
|
1641
|
-
await spawnInstance(restartLabel);
|
|
1642
|
-
}
|
|
1643
|
-
for (const [nodeId, foldedNode] of state.nodes) {
|
|
1644
|
-
const latest = foldedNode.settles.at(-1);
|
|
1645
|
-
if (latest === void 0) continue;
|
|
1646
|
-
const instanceLabel = `${nodeId}#${latest.visit}`;
|
|
1647
|
-
let enriched = latest;
|
|
1648
|
-
if (latest.status === "done" && latest.outRef !== void 0) {
|
|
1649
|
-
const out = admitPayload(await blobs.get(latest.outRef));
|
|
1650
|
-
if (isSuspensionRequest(out)) {
|
|
1651
|
-
foldedNode.settles.pop();
|
|
1652
|
-
const instance = state.instances.get(instanceLabel);
|
|
1653
|
-
if (instance) instance.settle = void 0;
|
|
1654
|
-
await journalSuspension(instanceLabel, out);
|
|
1655
|
-
continue;
|
|
1656
|
-
}
|
|
1657
|
-
outCache.set(latest.outRef, out);
|
|
1658
|
-
const nodeSpec = compiled.nodes.get(nodeId);
|
|
1659
|
-
let valid;
|
|
1660
|
-
if (nodeSpec?.deliverable !== void 0) try {
|
|
1661
|
-
valid = await nodeSpec.deliverable.check(out);
|
|
1662
|
-
} catch {
|
|
1663
|
-
valid = false;
|
|
1664
|
-
}
|
|
1665
|
-
enriched = {
|
|
1666
|
-
...latest,
|
|
1667
|
-
out,
|
|
1668
|
-
...valid !== void 0 ? { valid } : {}
|
|
1669
|
-
};
|
|
1670
|
-
}
|
|
1671
|
-
await propagate(instanceLabel, enriched);
|
|
1672
|
-
}
|
|
1673
|
-
for (const id of compiled.entries) if ((state.nodes.get(id)?.visits ?? 0) === 0) await enterEntryNode(id);
|
|
1674
|
-
for (const id of compiled.nodes.keys()) await tryRelease(id);
|
|
1675
|
-
}
|
|
1676
|
-
const allTerminalsSettled = () => compiled.terminals.every((id) => (state.nodes.get(id)?.settles.length ?? 0) > 0);
|
|
1677
|
-
let wakeSignal = Promise.resolve();
|
|
1678
|
-
let armWake = () => {};
|
|
1679
|
-
const rearmWakeSignal = () => {
|
|
1680
|
-
wakeSignal = new Promise((fire) => {
|
|
1681
|
-
armWake = fire;
|
|
1682
|
-
});
|
|
1683
|
-
onWakeSignal(() => armWake());
|
|
1684
|
-
};
|
|
1685
|
-
rearmWakeSignal();
|
|
1686
|
-
let inFlightNext;
|
|
1687
|
-
while (!failure) {
|
|
1688
|
-
await sweepExpiries();
|
|
1689
|
-
if (wakes.length > 0) {
|
|
1690
|
-
await processWakes();
|
|
1691
|
-
continue;
|
|
1692
|
-
}
|
|
1693
|
-
if (allTerminalsSettled()) break;
|
|
1694
|
-
if (liveCount === 0) {
|
|
1695
|
-
const pendingSuspensions = [...state.suspensions.values()].filter((suspension) => suspension.status === "pending");
|
|
1696
|
-
if (pendingSuspensions.length > 0) {
|
|
1697
|
-
const nearest = Math.min(...pendingSuspensions.map((suspension) => suspension.expiresAtMs ?? Number.POSITIVE_INFINITY));
|
|
1698
|
-
if (Number.isFinite(nearest) && now() >= nearest) continue;
|
|
1699
|
-
if (options.waitForWakes) {
|
|
1700
|
-
rearmWakeSignal();
|
|
1701
|
-
await wakeSignal;
|
|
1702
|
-
continue;
|
|
1703
|
-
}
|
|
1704
|
-
const defaulting = pendingSuspensions.filter((suspension) => suspension.onExpire === "default");
|
|
1705
|
-
if (defaulting.length > 0) {
|
|
1706
|
-
for (const suspension of defaulting) await wake(suspension, "fired", suspension.defaultRef);
|
|
1707
|
-
continue;
|
|
1708
|
-
}
|
|
1709
|
-
break;
|
|
1710
|
-
}
|
|
1711
|
-
break;
|
|
1712
|
-
}
|
|
1713
|
-
inFlightNext ??= scope.next();
|
|
1714
|
-
const raced = await Promise.race([inFlightNext.then((settle) => ({ settle })), wakeSignal.then(() => "wake")]);
|
|
1715
|
-
if (raced === "wake") {
|
|
1716
|
-
rearmWakeSignal();
|
|
1717
|
-
continue;
|
|
1718
|
-
}
|
|
1719
|
-
inFlightNext = void 0;
|
|
1720
|
-
if (raced.settle === null) break;
|
|
1721
|
-
await handleSettle(raced.settle);
|
|
1722
|
-
for (const parked of waitingForBudget.splice(0)) await spawnInstance(parked);
|
|
1723
|
-
}
|
|
1724
|
-
abort.abort("graph loop complete");
|
|
1725
|
-
while (await (inFlightNext ?? scope.next()) !== null) inFlightNext = void 0;
|
|
1726
|
-
const rehydrate = async (settle) => {
|
|
1727
|
-
if (settle.out !== void 0 || settle.outRef === void 0) return settle;
|
|
1728
|
-
const out = outCache.get(settle.outRef) ?? admitPayload(await blobs.get(settle.outRef));
|
|
1729
|
-
const node = compiled.nodes.get(settle.node);
|
|
1730
|
-
let valid = settle.valid;
|
|
1731
|
-
if (valid === void 0 && node?.deliverable !== void 0 && settle.status === "done") try {
|
|
1732
|
-
valid = await node.deliverable.check(out);
|
|
1733
|
-
} catch {
|
|
1734
|
-
valid = false;
|
|
1735
|
-
}
|
|
1736
|
-
return {
|
|
1737
|
-
...settle,
|
|
1738
|
-
out,
|
|
1739
|
-
...valid !== void 0 ? { valid } : {}
|
|
1740
|
-
};
|
|
1741
|
-
};
|
|
1742
|
-
const settles = await Promise.all([...compiled.nodes.keys()].flatMap((id) => state.nodes.get(id)?.settles ?? []).map(rehydrate));
|
|
1743
|
-
const terminals = settles.filter((settle) => compiled.nodes.get(settle.node)?.terminal);
|
|
1744
|
-
const finish = (result) => {
|
|
1745
|
-
if (result.kind === "no-winner" && state.exhaustedEdges.size > 0) throw new GraphEdgeCapError(Object.freeze([...state.exhaustedEdges]), Object.freeze([...ledger]), result);
|
|
1746
|
-
return result;
|
|
1747
|
-
};
|
|
1748
|
-
if (failure) return finish({
|
|
1749
|
-
kind: "no-winner",
|
|
1750
|
-
reason: failure.reason,
|
|
1751
|
-
...failure.error ? { error: failure.error } : {},
|
|
1752
|
-
terminals,
|
|
1753
|
-
settles,
|
|
1754
|
-
ledger,
|
|
1755
|
-
unreachable: []
|
|
1756
|
-
});
|
|
1757
|
-
const pendingTokens = [...state.suspensions.values()].filter((suspension) => suspension.status === "pending").map((suspension) => suspension.token);
|
|
1758
|
-
if (pendingTokens.length > 0 && !allTerminalsSettled()) return {
|
|
1759
|
-
kind: "suspended",
|
|
1760
|
-
tokens: pendingTokens,
|
|
1761
|
-
terminals,
|
|
1762
|
-
settles,
|
|
1763
|
-
ledger
|
|
1764
|
-
};
|
|
1765
|
-
if (options.signal?.aborted) return finish({
|
|
1766
|
-
kind: "no-winner",
|
|
1767
|
-
reason: "aborted",
|
|
1768
|
-
terminals,
|
|
1769
|
-
settles,
|
|
1770
|
-
ledger,
|
|
1771
|
-
unreachable: []
|
|
1772
|
-
});
|
|
1773
|
-
const out = terminals.some((settle) => settle.status === "done" && settle.valid !== false) ? await runFinalizer(options.finalizer === void 0 || options.finalizer === "bestDelivered" ? bestDelivered : options.finalizer === "collectDelivered" ? collectDelivered : options.finalizer, {
|
|
1774
|
-
settled: terminals.map((settle) => ({
|
|
1775
|
-
id: settle.node,
|
|
1776
|
-
status: settle.status,
|
|
1777
|
-
valid: settle.status === "done" && settle.valid !== false,
|
|
1778
|
-
...settle.outRef !== void 0 ? { outRef: settle.outRef } : {}
|
|
1779
|
-
})),
|
|
1780
|
-
blobs,
|
|
1781
|
-
tree: scope.view,
|
|
1782
|
-
budget: scope.budget
|
|
1783
|
-
}) : void 0;
|
|
1784
|
-
if (out !== void 0) return {
|
|
1785
|
-
kind: "winner",
|
|
1786
|
-
out,
|
|
1787
|
-
terminals,
|
|
1788
|
-
settles,
|
|
1789
|
-
ledger
|
|
1790
|
-
};
|
|
1791
|
-
const unreachable = [...compiled.nodes.keys()].filter((id) => (state.nodes.get(id)?.settles.length ?? 0) === 0);
|
|
1792
|
-
return finish({
|
|
1793
|
-
kind: "no-winner",
|
|
1794
|
-
reason: compiled.terminals.some((id) => unreachable.includes(id)) ? unreachable.length === compiled.nodes.size ? "budget-exhausted" : "unreachable-terminal" : "all-children-down",
|
|
1795
|
-
terminals,
|
|
1796
|
-
settles,
|
|
1797
|
-
ledger,
|
|
1798
|
-
unreachable
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
function hasLiveInstance(state, liveHandles, node) {
|
|
1803
|
-
for (const label of liveHandles.values()) if (state.instances.get(label)?.node === node) return true;
|
|
1804
|
-
return false;
|
|
1805
|
-
}
|
|
1806
|
-
function maxEngineSeq(events) {
|
|
1807
|
-
let max = -1;
|
|
1808
|
-
for (const ev of events) {
|
|
1809
|
-
if (ev.kind === "node-inputs-resolved" || ev.kind === "edge-verdict" || ev.kind === "join-state") {
|
|
1810
|
-
if (ev.seq > max) max = ev.seq;
|
|
1811
|
-
}
|
|
1812
|
-
if (ev.kind === "waiting" && ev.spec.kind === "token" && ev.seq > max) max = ev.seq;
|
|
1813
|
-
}
|
|
1814
|
-
return max;
|
|
1815
|
-
}
|
|
1816
|
-
//#endregion
|
|
1817
|
-
export { CONDITION_OPS, DEFAULT_MAX_NODE_VISITS, ENGINE_WOKEN_SEQ_BASE, JOIN_RULES, MAX_MAX_NODE_VISITS, admitPayload, agentKind, applyGraphFoldEvent, applyProjection, compileGraph, createGraphEngine, createGraphRun, createRegistry, emptyFoldState, evaluateCondition, foldGraphJournal, formatRegistryHandle, kindHandle, narrowEffects, parseRegistryHandle, runEngineGraph, schemaAccepts, scriptKind, subgraphKind, supervisorKind, suspended, validateCondition, validateNodeKind, validateProjection };
|
|
1818
|
-
|
|
1819
|
-
//# sourceMappingURL=graph.js.map
|
|
1
|
+
import { A as supervisorKind, B as MAX_MAX_NODE_VISITS, C as applyGraphFoldEvent, D as agentKind, E as admitPayload, F as compileGraph, G as validateProjection, H as formatRegistryHandle, I as isEngineFired, J as validateCondition, K as CONDITION_OPS, L as schemaAccepts, M as kindHandle, N as narrowEffects, O as scriptKind, P as validateNodeKind, R as DEFAULT_MAX_NODE_VISITS, S as decideJoin, T as foldGraphJournal, U as parseRegistryHandle, V as createRegistry, W as applyProjection, _ as ENGINE_WOKEN_SEQ_BASE, a as RUN_GRAPH_KIND, b as materializeSettles, c as runGraphKind, d as runEngineGraph, f as isSuspensionRequest, g as tokenFromSuspensionNodeId, h as suspensionNodeId, j as createGraphEngine, k as subgraphKind, l as runGraphThroughEngine, m as suspended, o as graphFromRunGraph, p as mintSuspensionToken, q as evaluateCondition, s as runGraphEngine, u as createGraphRun, v as openGraphRun, w as emptyFoldState, x as createEdgeLedger, y as assembleGraphResult, z as JOIN_RULES } from "./graph-E0U0c2YP.js";
|
|
2
|
+
export { CONDITION_OPS, DEFAULT_MAX_NODE_VISITS, ENGINE_WOKEN_SEQ_BASE, JOIN_RULES, MAX_MAX_NODE_VISITS, RUN_GRAPH_KIND, admitPayload, agentKind, applyGraphFoldEvent, applyProjection, assembleGraphResult, compileGraph, createEdgeLedger, createGraphEngine, createGraphRun, createRegistry, decideJoin, emptyFoldState, evaluateCondition, foldGraphJournal, formatRegistryHandle, graphFromRunGraph, isEngineFired, isSuspensionRequest, kindHandle, materializeSettles, mintSuspensionToken, narrowEffects, openGraphRun, parseRegistryHandle, runEngineGraph, runGraphEngine, runGraphKind, runGraphThroughEngine, schemaAccepts, scriptKind, subgraphKind, supervisorKind, suspended, suspensionNodeId, tokenFromSuspensionNodeId, validateCondition, validateNodeKind, validateProjection };
|