agentfootprint 7.9.0 → 7.11.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.
Files changed (44) hide show
  1. package/README.md +2 -2
  2. package/dist/core-flow/Graph.js +607 -0
  3. package/dist/core-flow/Graph.js.map +1 -0
  4. package/dist/core-flow/Workflow.js +210 -0
  5. package/dist/core-flow/Workflow.js.map +1 -0
  6. package/dist/esm/core-flow/Graph.d.ts +272 -0
  7. package/dist/esm/core-flow/Graph.js +601 -0
  8. package/dist/esm/core-flow/Graph.js.map +1 -0
  9. package/dist/esm/core-flow/Workflow.d.ts +146 -0
  10. package/dist/esm/core-flow/Workflow.js +205 -0
  11. package/dist/esm/core-flow/Workflow.js.map +1 -0
  12. package/dist/esm/index.d.ts +2 -0
  13. package/dist/esm/index.js +2 -0
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/patterns/LlmRouter.d.ts +221 -0
  16. package/dist/esm/patterns/LlmRouter.js +400 -0
  17. package/dist/esm/patterns/LlmRouter.js.map +1 -0
  18. package/dist/esm/patterns/LlmSwarm.d.ts +100 -0
  19. package/dist/esm/patterns/LlmSwarm.js +109 -0
  20. package/dist/esm/patterns/LlmSwarm.js.map +1 -0
  21. package/dist/esm/patterns/index.d.ts +2 -0
  22. package/dist/esm/patterns/index.js +2 -0
  23. package/dist/esm/patterns/index.js.map +1 -1
  24. package/dist/index.js +7 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/patterns/LlmRouter.js +406 -0
  27. package/dist/patterns/LlmRouter.js.map +1 -0
  28. package/dist/patterns/LlmSwarm.js +113 -0
  29. package/dist/patterns/LlmSwarm.js.map +1 -0
  30. package/dist/patterns/index.js +6 -1
  31. package/dist/patterns/index.js.map +1 -1
  32. package/dist/types/core-flow/Graph.d.ts +273 -0
  33. package/dist/types/core-flow/Graph.d.ts.map +1 -0
  34. package/dist/types/core-flow/Workflow.d.ts +147 -0
  35. package/dist/types/core-flow/Workflow.d.ts.map +1 -0
  36. package/dist/types/index.d.ts +2 -0
  37. package/dist/types/index.d.ts.map +1 -1
  38. package/dist/types/patterns/LlmRouter.d.ts +222 -0
  39. package/dist/types/patterns/LlmRouter.d.ts.map +1 -0
  40. package/dist/types/patterns/LlmSwarm.d.ts +101 -0
  41. package/dist/types/patterns/LlmSwarm.d.ts.map +1 -0
  42. package/dist/types/patterns/index.d.ts +2 -0
  43. package/dist/types/patterns/index.d.ts.map +1 -1
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -171,7 +171,7 @@ const pipeline = Sequence.create()
171
171
  await pipeline.run({ message: 'URGENT: refund dispute on order #4411' });
172
172
  ```
173
173
 
174
- The fourth primitive is `Loop` — `Loop.repeat(agent).until(guard).times(5)`, with a mandatory budget guard. And the named patterns from the research literature ship pre-composed from the same four: `selfConsistency` · `reflection` · `debate` · `mapReduce` · `tot` · `swarm`. Because every composition is a flowchart, the structure you wrote is the structure you see in the UI — and the trace spans the whole pipeline, not one agent at a time. [Designing systems of agents ↓](#-build--design-your-agent-or-system-of-agents)
174
+ The fourth primitive is `Loop` — `Loop.repeat(agent).until(guard).times(5)`, with a mandatory budget guard. And the named patterns from the research literature ship pre-composed from the same four: `selfConsistency` · `reflection` · `debate` · `mapReduce` · `tot` · `swarm` · `llmSwarm` (a swarm whose hand-offs an LLM decides). Because every composition is a flowchart, the structure you wrote is the structure you see in the UI — and the trace spans the whole pipeline, not one agent at a time. [Designing systems of agents ↓](#-build--design-your-agent-or-system-of-agents)
175
175
 
176
176
  ---
177
177
 
@@ -753,7 +753,7 @@ The flowchart, recorders, and tests don't change between dev and prod.
753
753
 
754
754
  **Core**
755
755
  - 2 primitives — `LLMCall`, `Agent` (the ReAct loop)
756
- - 4 control flows — `Sequence`, `Parallel`, `Conditional`, `Loop`
756
+ - 4 control flows — `Sequence`, `Parallel`, `Conditional`, `Loop` (plus `workflow()`, the same sequence with every hand-off type-checked by the compiler, and `graph()`, a fixed DAG whose independent nodes run concurrently)
757
757
  - 1 Injection primitive — `defineSkill` / `defineSteering` / `defineInstruction` / `defineFact`
758
758
  - 1 reliability gate — `.reliability({ preCheck, postDecide, providers, circuitBreaker, fallback })`
759
759
  - 1 tool dispatch primitive — `ToolProvider` (sync OR async) — `staticTools` · `gatedTools` · `skillScopedTools` · or a custom `ToolProvider` that discovers over hubs / MCP / per-tenant catalogs
@@ -0,0 +1,607 @@
1
+ "use strict";
2
+ /**
3
+ * graph() — a FIXED DAG of runners, levelized at build time.
4
+ *
5
+ * WHY this exists: `Sequence` and `workflow()` run steps in a line, and
6
+ * `Parallel` fans out ONCE and merges. Real pipelines are neither: an
7
+ * intake step feeds two independent lookups, and a writer waits for both.
8
+ * Expressing that with the existing compositions means nesting a Parallel
9
+ * inside a Sequence and threading values through by hand — and on this
10
+ * codebase that hand-off silently loses structured data (see "The trap"
11
+ * below). `graph()` states the shape once, as nodes and edges, and lets
12
+ * the engine work out what can run at the same time.
13
+ *
14
+ * What it gives you:
15
+ * - **Concurrency you did not have to schedule.** Kahn levelization at
16
+ * BUILD time groups nodes with no dependency between them; every node
17
+ * in a level runs at the same time.
18
+ * - **A shape checked before it runs.** A cycle, an edge pointing at a
19
+ * node that does not exist, or a duplicate id is refused at BUILD
20
+ * time, naming the offender. You cannot construct a broken graph.
21
+ * - **No silent merges.** A node with two or more parents MUST declare
22
+ * a `join` — a silent merge is a wrong merge, so the build refuses
23
+ * and names the node.
24
+ * - **Values, not text.** An edge's payload is the producer's OUTPUT
25
+ * handed to the consumer, unchanged. There is no shared mutable scope
26
+ * between nodes: a node reads exactly what its parents produced.
27
+ *
28
+ * Pattern: Adapter over footprintjs's subflow mounts — a level with
29
+ * several nodes becomes stacked `addSubFlowChart` calls (a fork,
30
+ * run concurrently); a level with one node is mounted
31
+ * sequentially (`addSubFlowChartNext`, which resumes cleanly
32
+ * across a pause). One join stage between levels.
33
+ * Role: core-flow/ layer, alongside Sequence/Parallel/Conditional/
34
+ * Loop/Workflow. Pure control flow — no LLM dependency.
35
+ * Emits: agentfootprint.composition.enter / exit, reported as kind
36
+ * `'Sequence'`. See "Why kind 'Sequence'" below.
37
+ *
38
+ * ## The trap this was built around (verified against footprintjs, not docs)
39
+ *
40
+ * The obvious sketch — `graph = Sequence(Parallel(level0), Parallel(level1), …)`
41
+ * — does NOT work on this codebase, for two independent reasons:
42
+ *
43
+ * 1. `Sequence`'s step contract is `{ message: string } -> string`, and
44
+ * its step `outputMapper` coerces a non-string step output to `''`.
45
+ * `workflow()` (v7.10.0) exists precisely because of this.
46
+ * 2. `Parallel` has the SAME limit one layer down: its branch type is
47
+ * `Runner<{ message: string }, string>` and its branch `outputMapper`
48
+ * coerces a non-string branch output to `''` (`Parallel.ts`, the
49
+ * `typeof sfOutput === 'string' ? sfOutput : ''` mapper). So a
50
+ * Parallel level cannot carry a structured value either.
51
+ *
52
+ * So `graph()` is built on the pass-through model `workflow()` established
53
+ * — its own composition, its own mappers, the same recorder wiring and the
54
+ * same `composition.enter` / `exit` events — rather than on top of
55
+ * Sequence/Parallel.
56
+ *
57
+ * ## Why kind 'Sequence'
58
+ *
59
+ * `CompositionKind` is a CLOSED public union (`'Sequence' | 'Parallel' |
60
+ * 'Conditional' | 'Loop'`). Widening it would break exhaustive switches in
61
+ * consumer code for no behavioural gain — the same call v7.10.0 made for
62
+ * `workflow()`. A graph's LEVELS are a sequence (level 0, then level 1, …),
63
+ * so `'Sequence'` is the honest member of that union: this composition runs
64
+ * its levels in order. The fan-out WITHIN a level is visible in the chart
65
+ * itself (a fork node per level), which is where a renderer reads it from.
66
+ *
67
+ * ## Honest limits (all verified against the engine, pinned in tests)
68
+ *
69
+ * 1. Only PLAIN DATA crosses a node boundary — the same limit
70
+ * `workflow()` documents. A value with a prototype (Date, Map, class
71
+ * instance) arrives as `{}`; `undefined` fields are dropped.
72
+ * 2. A node must RETURN its output: the value handed to its children is
73
+ * the node chart's traversal result.
74
+ * 3. A node that THROWS is always reported as
75
+ * `graph '<id>': node '<node>' failed: <reason>`, but it reaches that
76
+ * sentence by two different routes. In a CONCURRENT level footprintjs
77
+ * runs children under `Promise.allSettled`, so a failed child is
78
+ * simply ABSENT from the results and the level join turns that
79
+ * absence into the error. In a SEQUENTIAL (single-node) level the
80
+ * error rejects the run raw, and `rethrowWithNodeAttribution` renames
81
+ * it. Consumers see one shape either way.
82
+ * 4. A node that PAUSES surfaces as a pause — the engine halts the
83
+ * traversal before the level's join runs, so `run()` returns a
84
+ * `RunnerPauseOutcome`. `resume()` then carries on through the REST
85
+ * of the graph only when the paused node was ALONE in its level (a
86
+ * sequential mount). Resuming into a fork child completes that child
87
+ * and stops: the remaining levels do not run. Give a node that asks a
88
+ * human a level of its own. Both halves are pinned in tests.
89
+ *
90
+ * @example a diamond: A feeds B and C, D waits for both
91
+ * ```ts
92
+ * const pipeline = graph({
93
+ * nodes: [
94
+ * { id: 'intake', runner: intake },
95
+ * { id: 'orders', runner: lookupOrders },
96
+ * { id: 'billing', runner: lookupBilling },
97
+ * {
98
+ * id: 'reply',
99
+ * runner: writeReply,
100
+ * // Two parents ⇒ a join is REQUIRED. `upstream` is keyed by node id.
101
+ * join: (upstream) => ({
102
+ * orders: upstream.orders as OrderInfo,
103
+ * billing: upstream.billing as BillingInfo,
104
+ * }),
105
+ * },
106
+ * ],
107
+ * edges: [
108
+ * { from: 'intake', to: 'orders' },
109
+ * { from: 'intake', to: 'billing' },
110
+ * { from: 'orders', to: 'reply' },
111
+ * { from: 'billing', to: 'reply' },
112
+ * ],
113
+ * });
114
+ *
115
+ * const out = await pipeline.run({ message: 'where is my refund?' });
116
+ * // out = { intake: …, orders: …, billing: …, reply: … } — keyed by node id
117
+ * ```
118
+ */
119
+ Object.defineProperty(exports, "__esModule", { value: true });
120
+ exports.graph = exports.Graph = exports.levelize = void 0;
121
+ const footprintjs_1 = require("footprintjs");
122
+ const RunnerBase_js_1 = require("../core/RunnerBase.js");
123
+ const AgentRecorder_js_1 = require("../recorders/core/AgentRecorder.js");
124
+ const CompositionRecorder_js_1 = require("../recorders/core/CompositionRecorder.js");
125
+ const ContextRecorder_js_1 = require("../recorders/core/ContextRecorder.js");
126
+ const StreamRecorder_js_1 = require("../recorders/core/StreamRecorder.js");
127
+ const typedEmit_js_1 = require("../recorders/core/typedEmit.js");
128
+ /**
129
+ * The one sentence every node failure is reported with, whatever mount the
130
+ * level used. A graph has two mount paths — a fork for concurrent levels, a
131
+ * sequential mount for single-node ones — and footprintjs surfaces failures
132
+ * differently through each (a fork child's error is swallowed into absence;
133
+ * a sequential child's rejects the run raw). Consumers should not have to
134
+ * know which one they got, so both are reported like this.
135
+ */
136
+ function nodeFailureMessage(graphId, nodeId, reason) {
137
+ return `graph '${graphId}': node '${nodeId}' failed: ${reason}`;
138
+ }
139
+ // ─── Build-time validation + levelization ────────────────────────────
140
+ /**
141
+ * Kahn levelization: group nodes so that everything in level N depends
142
+ * only on levels < N. Nodes within a level are independent BY
143
+ * CONSTRUCTION, which is exactly the licence to run them concurrently.
144
+ *
145
+ * Declaration order is preserved inside each level so a graph's chart —
146
+ * and therefore its trace — is deterministic.
147
+ *
148
+ * Throws (naming the offender) on: an unknown edge endpoint, a duplicate
149
+ * node id, a cycle, or a fan-in > 1 with no `join`.
150
+ */
151
+ function levelize(nodes, edges) {
152
+ if (nodes.length === 0) {
153
+ throw new Error('graph: needs at least one node');
154
+ }
155
+ const byId = new Map();
156
+ for (const node of nodes) {
157
+ if (byId.has(node.id)) {
158
+ throw new Error(`graph: duplicate node id '${node.id}' — every node id must be unique (it is the results key).`);
159
+ }
160
+ byId.set(node.id, node);
161
+ }
162
+ const parents = new Map();
163
+ const children = new Map();
164
+ for (const node of nodes) {
165
+ parents.set(node.id, []);
166
+ children.set(node.id, []);
167
+ }
168
+ for (const edge of edges) {
169
+ if (!byId.has(edge.from)) {
170
+ throw new Error(`graph: edge '${edge.from}' -> '${edge.to}' references unknown node '${edge.from}'.`);
171
+ }
172
+ if (!byId.has(edge.to)) {
173
+ throw new Error(`graph: edge '${edge.from}' -> '${edge.to}' references unknown node '${edge.to}'.`);
174
+ }
175
+ parents.get(edge.to)?.push(edge.from);
176
+ children.get(edge.from)?.push(edge.to);
177
+ }
178
+ // Fan-in > 1 demands an explicit join. Checked BEFORE the cycle walk so
179
+ // the more actionable error wins on a graph that has both problems.
180
+ for (const node of nodes) {
181
+ const up = parents.get(node.id) ?? [];
182
+ if (up.length > 1 && node.join === undefined) {
183
+ throw new Error(`graph: node '${node.id}' has ${up.length} parents (${up.join(', ')}) but no join — ` +
184
+ 'a silent merge is a wrong merge. Give the node a join(upstream) that returns its input; ' +
185
+ 'upstream is keyed by parent node id.');
186
+ }
187
+ }
188
+ // Kahn: repeatedly take every node whose parents have all been placed.
189
+ const remainingParents = new Map();
190
+ for (const node of nodes)
191
+ remainingParents.set(node.id, (parents.get(node.id) ?? []).length);
192
+ const levels = [];
193
+ let frontier = nodes.filter((n) => remainingParents.get(n.id) === 0);
194
+ let placed = 0;
195
+ while (frontier.length > 0) {
196
+ levels.push(frontier);
197
+ placed += frontier.length;
198
+ const next = [];
199
+ for (const node of frontier) {
200
+ for (const childId of children.get(node.id) ?? []) {
201
+ const left = (remainingParents.get(childId) ?? 0) - 1;
202
+ remainingParents.set(childId, left);
203
+ if (left === 0) {
204
+ const child = byId.get(childId);
205
+ if (child !== undefined)
206
+ next.push(child);
207
+ }
208
+ }
209
+ }
210
+ // Restore declaration order — `next` is built in parent-visit order.
211
+ frontier = nodes.filter((n) => next.includes(n));
212
+ }
213
+ if (placed < nodes.length) {
214
+ const stuck = new Set(nodes.filter((n) => (remainingParents.get(n.id) ?? 0) > 0).map((n) => n.id));
215
+ throw new Error(`graph: cycle detected — edge '${findBackEdge(stuck, edges)}' closes a loop. A graph must be acyclic.`);
216
+ }
217
+ return levels;
218
+ }
219
+ exports.levelize = levelize;
220
+ /**
221
+ * Name ONE edge that closes a cycle, so the error can point at something
222
+ * the author can delete. Depth-first over the nodes Kahn could not place;
223
+ * the first edge back onto the current stack is the one reported.
224
+ */
225
+ function findBackEdge(stuck, edges) {
226
+ const out = new Map();
227
+ for (const edge of edges) {
228
+ if (stuck.has(edge.from) && stuck.has(edge.to)) {
229
+ const list = out.get(edge.from) ?? [];
230
+ list.push(edge.to);
231
+ out.set(edge.from, list);
232
+ }
233
+ }
234
+ const onStack = new Set();
235
+ const done = new Set();
236
+ let found;
237
+ const walk = (id) => {
238
+ if (found !== undefined)
239
+ return;
240
+ onStack.add(id);
241
+ for (const next of out.get(id) ?? []) {
242
+ if (found !== undefined)
243
+ return;
244
+ if (onStack.has(next)) {
245
+ found = `${id}' -> '${next}`;
246
+ return;
247
+ }
248
+ if (!done.has(next))
249
+ walk(next);
250
+ }
251
+ onStack.delete(id);
252
+ done.add(id);
253
+ };
254
+ for (const id of stuck) {
255
+ if (!done.has(id))
256
+ walk(id);
257
+ if (found !== undefined)
258
+ break;
259
+ }
260
+ // Every unplaced node is on a cycle, so a back edge always exists; the
261
+ // fallback keeps the error useful rather than throwing inside a thrower.
262
+ return found ?? [...stuck].join("' -> '");
263
+ }
264
+ /**
265
+ * Hand a producer's value to a consumer as its input args.
266
+ *
267
+ * `string` → `{ message }` (the house convention every LLM runner here
268
+ * speaks, identical to `workflow()`'s hand-off rule). Plain object →
269
+ * itself. Anything else is a broken hand-off and says so, naming both
270
+ * ends — the alternative is an empty input inside the consumer with
271
+ * nothing pointing back here.
272
+ */
273
+ function toNodeArgs(value, nodeId, source) {
274
+ if (typeof value === 'string')
275
+ return { message: value };
276
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
277
+ return { ...value };
278
+ }
279
+ const got = value === null ? 'null' : Array.isArray(value) ? 'an array' : typeof value;
280
+ throw new Error(`graph: ${source} handed node '${nodeId}' ${got}, but a node needs an object ` +
281
+ '(or a string, which arrives as { message }). Make each node return its output.');
282
+ }
283
+ // ─── The composition ─────────────────────────────────────────────────
284
+ /**
285
+ * A fixed DAG of runners. Build one with {@link graph}.
286
+ */
287
+ class Graph extends RunnerBase_js_1.RunnerBase {
288
+ name;
289
+ id;
290
+ nodes;
291
+ levels;
292
+ parentsOf;
293
+ opts;
294
+ currentRunContext = {
295
+ runStartMs: 0,
296
+ runId: 'pending',
297
+ compositionPath: [],
298
+ };
299
+ /**
300
+ * Per-node first-error records for the current run. footprintjs's
301
+ * `SubflowExecutor` swallows a subflow error into the parent's debug
302
+ * bag and skips the `outputMapper`, so the message never reaches parent
303
+ * scope on its own. An internal recorder captures it here; the level
304
+ * join reads it to name what actually went wrong. Mirrors Parallel's
305
+ * `branchErrors`, epoch-guarded for the same reason.
306
+ */
307
+ nodeErrors = new Map();
308
+ /** Monotonic run token — see Parallel's `runEpoch`. */
309
+ runEpoch = 0;
310
+ constructor(opts) {
311
+ super();
312
+ this.opts = opts;
313
+ this.name = opts.name ?? 'Graph';
314
+ this.id = opts.id ?? 'graph';
315
+ this.nodes = opts.nodes;
316
+ // Levelization VALIDATES — a broken graph throws here, at construction.
317
+ this.levels = levelize(opts.nodes, opts.edges);
318
+ const parents = new Map();
319
+ for (const node of opts.nodes)
320
+ parents.set(node.id, []);
321
+ for (const edge of opts.edges)
322
+ parents.get(edge.to)?.push(edge.from);
323
+ this.parentsOf = parents;
324
+ // Eager chart construction — see `RunnerBase.initChart` JSDoc.
325
+ this.initChart(() => this.buildChart());
326
+ }
327
+ /** How the graph was levelized — level 0 first. Stable post-construction. */
328
+ getLevels() {
329
+ return this.levels.map((level) => level.map((n) => n.id));
330
+ }
331
+ async run(input, options) {
332
+ const executor = this.createExecutor();
333
+ this.lastExecutor = executor;
334
+ let result;
335
+ try {
336
+ result = await executor.run({ input: { ...input }, ...(options ?? {}) });
337
+ }
338
+ catch (err) {
339
+ this.rethrowWithNodeAttribution(err);
340
+ }
341
+ return this.finalizeResult(executor, result);
342
+ }
343
+ async resume(checkpoint, input, options) {
344
+ this.emitPauseResume(checkpoint, input);
345
+ const executor = this.createExecutor();
346
+ this.lastExecutor = executor;
347
+ let result;
348
+ try {
349
+ result = await executor.resume(checkpoint, input, options);
350
+ }
351
+ catch (err) {
352
+ this.rethrowWithNodeAttribution(err);
353
+ }
354
+ return this.finalizeResult(executor, result);
355
+ }
356
+ /**
357
+ * Give a RAW rejection the same node-naming shape the level join
358
+ * produces.
359
+ *
360
+ * A node in a SEQUENTIAL (single-node) level rejects the run with its
361
+ * own error — the level join never runs, so nothing has attributed it to
362
+ * a node yet. The error recorder did see it, so correlate (by identity
363
+ * first, then bare message) and rename. Anything that does not correlate
364
+ * — including the join's own already-attributed error — is rethrown
365
+ * untouched.
366
+ */
367
+ rethrowWithNodeAttribution(err) {
368
+ const message = err instanceof Error ? err.message : String(err);
369
+ for (const [nodeId, record] of this.nodeErrors) {
370
+ if (record.raw === err || record.message === message) {
371
+ throw new Error(nodeFailureMessage(this.id, nodeId, record.message), { cause: err });
372
+ }
373
+ }
374
+ throw err;
375
+ }
376
+ createExecutor() {
377
+ this.currentRunContext = {
378
+ runStartMs: Date.now(),
379
+ runId: (0, RunnerBase_js_1.makeRunId)(),
380
+ compositionPath: [`Graph:${this.id}`],
381
+ };
382
+ this.runEpoch += 1;
383
+ this.nodeErrors.clear();
384
+ const executor = new footprintjs_1.FlowChartExecutor(this.getSpec());
385
+ const dispatcher = this.getDispatcher();
386
+ const getRunCtx = () => this.currentRunContext;
387
+ executor.attachCombinedRecorder(new ContextRecorder_js_1.ContextRecorder({ dispatcher, getRunContext: getRunCtx }));
388
+ executor.attachCombinedRecorder((0, StreamRecorder_js_1.streamRecorder)({ dispatcher, getRunContext: getRunCtx }));
389
+ executor.attachCombinedRecorder((0, AgentRecorder_js_1.agentRecorder)({ dispatcher, getRunContext: getRunCtx }));
390
+ executor.attachCombinedRecorder((0, CompositionRecorder_js_1.compositionRecorder)({ dispatcher, getRunContext: getRunCtx }));
391
+ executor.attachCombinedRecorder(this.makeNodeErrorRecorder(this.runEpoch));
392
+ for (const r of this.attachedRecorders)
393
+ executor.attachCombinedRecorder(r);
394
+ return executor;
395
+ }
396
+ /**
397
+ * Capture the first error per node. The node id is the first segment of
398
+ * the engine-prefixed `stageId` (`orders/call-llm` → node `orders`) —
399
+ * the same correlation Parallel uses, and the only one that survives a
400
+ * node mounting subflows of its own.
401
+ */
402
+ makeNodeErrorRecorder(epoch) {
403
+ const nodeIds = new Set(this.nodes.map((n) => n.id));
404
+ return {
405
+ id: 'graph-node-errors',
406
+ onError: (event) => {
407
+ if (epoch !== this.runEpoch)
408
+ return; // straggler from a dead run
409
+ if (!(0, footprintjs_1.isFlowEvent)(event))
410
+ return;
411
+ const stageId = event.traversalContext?.stageId ?? '';
412
+ const slash = stageId.indexOf('/');
413
+ const nodeId = slash >= 0 ? stageId.slice(0, slash) : undefined;
414
+ if (nodeId === undefined || !nodeIds.has(nodeId))
415
+ return;
416
+ if (this.nodeErrors.has(nodeId))
417
+ return;
418
+ const structured = event.structuredError;
419
+ const message = structured?.message ??
420
+ (event.message.startsWith('Error: ')
421
+ ? event.message.slice('Error: '.length)
422
+ : event.message);
423
+ this.nodeErrors.set(nodeId, { message, raw: structured?.raw });
424
+ },
425
+ };
426
+ }
427
+ finalizeResult(executor, result) {
428
+ const paused = this.detectPause(executor, result);
429
+ if (paused)
430
+ return paused;
431
+ if (result instanceof Error)
432
+ throw result;
433
+ return (result ?? {});
434
+ }
435
+ buildChart() {
436
+ const compositionId = this.id;
437
+ const compositionName = this.name;
438
+ const nodeCount = this.nodes.length;
439
+ const levels = this.levels;
440
+ const nodeErrors = this.nodeErrors;
441
+ const seed = (scope) => {
442
+ // The graph's own input is what every ROOT node receives.
443
+ scope.graphInput = scope.$getArgs();
444
+ scope.results = {};
445
+ (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.composition.enter', {
446
+ kind: 'Sequence',
447
+ id: compositionId,
448
+ name: compositionName,
449
+ childCount: nodeCount,
450
+ });
451
+ };
452
+ // Root description prefix `Sequence:` is the taxonomy marker every
453
+ // consumer (Lens, FlowchartRecorder.mapTopologyToSteps) already reads.
454
+ let builder = (0, footprintjs_1.flowChart)('Seed', seed, 'seed', {
455
+ ...(this.opts.structureRecorders !== undefined && {
456
+ structureRecorders: [...this.opts.structureRecorders],
457
+ }),
458
+ description: `Sequence: ${nodeCount}-node DAG in ${levels.length} level(s)`,
459
+ });
460
+ levels.forEach((level, levelIndex) => {
461
+ // A level with SEVERAL nodes is mounted on the SAME builder cursor —
462
+ // stacked `addSubFlowChart` calls produce a fork node, which
463
+ // footprintjs's ChildrenExecutor runs concurrently. That is the whole
464
+ // reason to levelize.
465
+ //
466
+ // A level with ONE node is mounted SEQUENTIALLY instead
467
+ // (`addSubFlowChartNext`). There is nothing to run it alongside, and
468
+ // the sequential mount is strictly better across a pause: resuming
469
+ // into a fork child completes THAT child and stops, whereas a
470
+ // sequential mount resumes and carries on through the rest of the
471
+ // graph. Verified against footprintjs; see the class JSDoc's
472
+ // "Honest limits".
473
+ const concurrent = level.length > 1;
474
+ for (const node of level) {
475
+ const mount = concurrent
476
+ ? builder.addSubFlowChart.bind(builder)
477
+ : builder.addSubFlowChartNext.bind(builder);
478
+ builder = mount(node.id, node.runner.getSpec(), node.name ?? node.id, {
479
+ // A THROW from an inputMapper (a broken hand-off, or a join that
480
+ // rejects what it got) is caught by footprintjs's SubflowExecutor
481
+ // and turned into a plain "this subflow did not run" — the reason
482
+ // never reaches parent scope. Record it first, so the level join
483
+ // can name what actually happened instead of 'unknown error'.
484
+ inputMapper: (parent) => {
485
+ try {
486
+ return this.inputForNode(node, parent);
487
+ }
488
+ catch (err) {
489
+ if (!nodeErrors.has(node.id)) {
490
+ nodeErrors.set(node.id, {
491
+ message: err instanceof Error ? err.message : String(err),
492
+ raw: err,
493
+ });
494
+ }
495
+ throw err;
496
+ }
497
+ },
498
+ // Untouched: whatever the node's chart returned is what its
499
+ // children (and the caller) receive. No string coercion — this
500
+ // is exactly what Sequence and Parallel cannot do.
501
+ outputMapper: (sfOutput) => ({ results: { [node.id]: sfOutput } }),
502
+ });
503
+ }
504
+ // The join stage does two jobs: it ADVANCES the builder cursor (so
505
+ // the next level forks from here instead of joining this level's
506
+ // fork), and it turns a failed node's ABSENCE into a loud error.
507
+ builder = builder.addFunction(`Level ${levelIndex} join`, (scope) => {
508
+ // Read through `$getValue`, never `scope.results`: values merged
509
+ // into parent state by a subflow outputMapper are present in
510
+ // shared state but do NOT enumerate through TypedScope's nested
511
+ // property proxy. Verified against footprintjs — the property
512
+ // read returns `{}` while `$getValue` returns the real record.
513
+ const results = scope.$getValue('results') ?? {};
514
+ const missing = level.map((n) => n.id).filter((id) => !(id in results));
515
+ if (missing.length > 0) {
516
+ (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.composition.exit', {
517
+ kind: 'Sequence',
518
+ id: compositionId,
519
+ name: compositionName,
520
+ status: 'err',
521
+ durationMs: Date.now() - this.currentRunContext.runStartMs,
522
+ });
523
+ const reasonFor = (id) => nodeErrors.get(id)?.message ?? 'unknown error';
524
+ const firstMissing = missing[0] ?? '';
525
+ if (missing.length === 1) {
526
+ throw new Error(nodeFailureMessage(compositionId, firstMissing, reasonFor(firstMissing)));
527
+ }
528
+ const details = missing.map((id) => ` ${id}: ${reasonFor(id)}`).join('\n');
529
+ throw new Error(`graph '${compositionId}': ${missing.length} nodes failed in level ${levelIndex}:\n${details}`);
530
+ }
531
+ return undefined;
532
+ }, `level-${levelIndex}-join`, `Graph level ${levelIndex} join`);
533
+ });
534
+ builder = builder.addFunction('Finalize', (scope) => {
535
+ (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.composition.exit', {
536
+ kind: 'Sequence',
537
+ id: compositionId,
538
+ name: compositionName,
539
+ status: 'ok',
540
+ durationMs: Date.now() - this.currentRunContext.runStartMs,
541
+ });
542
+ // `$getValue` for the same reason as the level join.
543
+ return scope.$getValue('results') ?? {};
544
+ }, 'finalize', 'Graph finalize');
545
+ return builder.build();
546
+ }
547
+ /**
548
+ * What one node receives. Roots get the graph's own input; a single
549
+ * parent is passed through; 2+ parents go through the node's `join`
550
+ * (which the build already guaranteed exists).
551
+ *
552
+ * `parent` here is the RAW parent state the engine hands an
553
+ * `inputMapper` — not a TypedScope — so structured upstream values read
554
+ * back intact.
555
+ */
556
+ inputForNode(node, parent) {
557
+ const results = parent.results ?? {};
558
+ const upstreamIds = this.parentsOf.get(node.id) ?? [];
559
+ if (upstreamIds.length === 0) {
560
+ return { ...(parent.graphInput ?? {}) };
561
+ }
562
+ if (node.join !== undefined) {
563
+ const upstream = {};
564
+ for (const id of upstreamIds)
565
+ upstream[id] = results[id];
566
+ return toNodeArgs(node.join(upstream), node.id, `join of node '${node.id}'`);
567
+ }
568
+ const only = upstreamIds[0] ?? '';
569
+ return toNodeArgs(results[only], node.id, `node '${only}'`);
570
+ }
571
+ }
572
+ exports.Graph = Graph;
573
+ // ─── The factory ─────────────────────────────────────────────────────
574
+ /**
575
+ * Build a fixed DAG of runners. Independent nodes run concurrently; the
576
+ * result is every node's output, keyed by node id.
577
+ *
578
+ * The shape is checked at BUILD time — a cycle, an edge pointing at an
579
+ * unknown node, a duplicate id, or a 2+-parent node with no `join` throws
580
+ * here, naming the offender, rather than misbehaving mid-run.
581
+ *
582
+ * @example a fan-out with a merge
583
+ * ```ts
584
+ * const pipeline = graph({
585
+ * nodes: [
586
+ * { id: 'plan', runner: planner },
587
+ * { id: 'search', runner: searcher },
588
+ * { id: 'recall', runner: memory },
589
+ * { id: 'answer', runner: writer, join: (u) => ({ ...u }) },
590
+ * ],
591
+ * edges: [
592
+ * { from: 'plan', to: 'search' },
593
+ * { from: 'plan', to: 'recall' },
594
+ * { from: 'search', to: 'answer' },
595
+ * { from: 'recall', to: 'answer' },
596
+ * ],
597
+ * });
598
+ *
599
+ * const out = await pipeline.run({ message: 'what changed last week?' });
600
+ * console.log(out.answer);
601
+ * ```
602
+ */
603
+ function graph(opts) {
604
+ return new Graph(opts);
605
+ }
606
+ exports.graph = graph;
607
+ //# sourceMappingURL=Graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../src/core-flow/Graph.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;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