@nylorun/harness 0.22.1-beta → 0.23.1-beta

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 (55) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/HOST_CONTRACT.md +26 -23
  3. package/README.md +5 -30
  4. package/dist/api/executors.d.ts +5 -4
  5. package/dist/api/harness.d.ts +0 -10
  6. package/dist/api/harness.js +1 -52
  7. package/dist/api/host.d.ts +2 -8
  8. package/dist/api/host.js +3 -15
  9. package/dist/api/run.d.ts +0 -11
  10. package/dist/api/run.js +1 -11
  11. package/dist/compatibility.d.ts +4 -12
  12. package/dist/compatibility.js +3 -11
  13. package/dist/definition/agent-definition.d.ts +0 -3
  14. package/dist/definition/agent-definition.js +0 -2
  15. package/dist/flow/checkpoint.d.ts +16 -0
  16. package/dist/flow/checkpoint.js +6 -2
  17. package/dist/flow/context.d.ts +19 -10
  18. package/dist/flow/context.js +36 -20
  19. package/dist/flow/engine.d.ts +25 -7
  20. package/dist/flow/engine.js +304 -38
  21. package/dist/flow/index.d.ts +3 -5
  22. package/dist/flow/index.js +3 -5
  23. package/dist/flow/paths.d.ts +1 -8
  24. package/dist/flow/paths.js +1 -12
  25. package/dist/flow/tool.d.ts +14 -0
  26. package/dist/flow/tool.js +67 -0
  27. package/dist/flow/types.d.ts +30 -3
  28. package/dist/flow/types.js +14 -1
  29. package/dist/loop/run.js +5 -134
  30. package/dist/loop/state.js +2 -22
  31. package/dist/loop/step/run.d.ts +1 -10
  32. package/dist/loop/step/run.js +2 -101
  33. package/dist/loop/step/runtime.d.ts +0 -17
  34. package/dist/run/durable.d.ts +7 -11
  35. package/dist/run/durable.js +14 -33
  36. package/dist/run/index.d.ts +3 -4
  37. package/dist/run/index.js +1 -2
  38. package/dist/types/execution.d.ts +5 -18
  39. package/package.json +2 -2
  40. package/dist/flow/chain.d.ts +0 -8
  41. package/dist/flow/chain.js +0 -27
  42. package/dist/flow/loop.d.ts +0 -35
  43. package/dist/flow/loop.js +0 -238
  44. package/dist/flow/map.d.ts +0 -7
  45. package/dist/flow/map.js +0 -64
  46. package/dist/flow/node.d.ts +0 -31
  47. package/dist/flow/node.js +0 -113
  48. package/dist/flow/parallel.d.ts +0 -7
  49. package/dist/flow/parallel.js +0 -47
  50. package/dist/flow/switch.d.ts +0 -8
  51. package/dist/flow/switch.js +0 -35
  52. package/dist/flow/v2.d.ts +0 -12
  53. package/dist/flow/v2.js +0 -370
  54. package/dist/loop/step/hooks.d.ts +0 -56
  55. package/dist/loop/step/hooks.js +0 -191
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/harness",
3
- "version": "0.22.1-beta",
3
+ "version": "0.23.1-beta",
4
4
  "description": "Nylorun's TypeScript agent execution engine. See github.com/nylorun/agents.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -81,7 +81,7 @@
81
81
  "zod": "^4.6.5"
82
82
  },
83
83
  "dependencies": {
84
- "@nylorun/core": "0.13.0-beta"
84
+ "@nylorun/core": "0.16.0-beta"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "zod": "^4.6.5"
@@ -1,8 +0,0 @@
1
- import type { JsonValue } from "@nylorun/core/define";
2
- import type { WorkflowChainNode } from "@nylorun/core";
3
- import type { FlowContext } from "./context.js";
4
- /**
5
- * Chain: steps in order; step 1 gets chain input; later steps get prior output
6
- * unless a slot `input` reshapes. `results` is lexical for the nearest enclosing Chain.
7
- */
8
- export declare function runChain(ctx: FlowContext, chain: WorkflowChainNode["chain"], path: string, input: JsonValue): Promise<JsonValue>;
@@ -1,27 +0,0 @@
1
- import { joinPath } from "./paths.js";
2
- import { runNode, unwrapSlot } from "./node.js";
3
- /**
4
- * Chain: steps in order; step 1 gets chain input; later steps get prior output
5
- * unless a slot `input` reshapes. `results` is lexical for the nearest enclosing Chain.
6
- */
7
- export async function runChain(ctx, chain, path, input) {
8
- const results = {};
9
- const chainInput = input;
10
- ctx.resultsStack.push(results);
11
- try {
12
- let current = input;
13
- for (const step of chain.steps) {
14
- const { part } = unwrapSlot(step);
15
- const stepPath = joinPath(path, part);
16
- const output = await runNode(ctx, step, stepPath, current, {
17
- ownerInput: chainInput,
18
- });
19
- results[part] = output;
20
- current = output;
21
- }
22
- return current;
23
- }
24
- finally {
25
- ctx.resultsStack.pop();
26
- }
27
- }
@@ -1,35 +0,0 @@
1
- import type { AgentManifest, JsonValue, WorkflowManifest } from "@nylorun/core/define";
2
- import type { WorkflowLoopNode } from "@nylorun/core";
3
- import type { DurableHost } from "../run/durable.js";
4
- import type { FlowCheckpoint } from "./checkpoint.js";
5
- import { type FlowContext } from "./context.js";
6
- import { type FlowOperatorLimits } from "./limits.js";
7
- import { type FlowDurableResult } from "./types.js";
8
- export type { FlowDurableResult, FlowRunResult } from "./types.js";
9
- /** Host may wrap agent-effect outcomes so the Loop learns the turn's manifest. */
10
- export declare const AGENT_TURN_MARKER: "__nylorunAgentTurn";
11
- export type AgentTurnValue = {
12
- readonly [AGENT_TURN_MARKER]: 1;
13
- readonly output: JsonValue;
14
- readonly agent: AgentManifest;
15
- };
16
- export declare function agentTurnValue(output: JsonValue, agent: AgentManifest): AgentTurnValue;
17
- export declare function readAgentTurn(value: unknown): {
18
- output: JsonValue;
19
- agent?: AgentManifest;
20
- };
21
- /**
22
- * Interpret a root Loop node. Returns effects only; the host journals outcomes.
23
- */
24
- export declare function runLoop(options: {
25
- readonly manifest: WorkflowManifest;
26
- readonly checkpoint: FlowCheckpoint;
27
- readonly host: DurableHost;
28
- readonly signal?: AbortSignal;
29
- readonly limits?: Partial<FlowOperatorLimits> | null;
30
- }): Promise<FlowDurableResult>;
31
- /**
32
- * Nested or root Loop body: run → verify → decide until `{ output }` or stop.
33
- * Agent turn pinning / decide patches (`decision.agent`) are L5.
34
- */
35
- export declare function runLoopNode(ctx: FlowContext, loop: WorkflowLoopNode["loop"], path: string, input: JsonValue): Promise<JsonValue>;
package/dist/flow/loop.js DELETED
@@ -1,238 +0,0 @@
1
- import { HarnessError, isVariantOf } from "@nylorun/core/define";
2
- import { HostSuspension } from "../loop/host-suspension.js";
3
- import { createFlowContext, failureOf, settleInFlight } from "./context.js";
4
- import { assertLoopIteration } from "./limits.js";
5
- import { joinPath, nodeKeyOf } from "./paths.js";
6
- import { runNode, unwrapSlot } from "./node.js";
7
- import { FlowNodeError } from "./types.js";
8
- /** Host may wrap agent-effect outcomes so the Loop learns the turn's manifest. */
9
- export const AGENT_TURN_MARKER = "__nylorunAgentTurn";
10
- export function agentTurnValue(output, agent) {
11
- return { [AGENT_TURN_MARKER]: 1, output, agent };
12
- }
13
- export function readAgentTurn(value) {
14
- if (value &&
15
- typeof value === "object" &&
16
- !Array.isArray(value) &&
17
- value[AGENT_TURN_MARKER] === 1 &&
18
- "output" in value &&
19
- "agent" in value) {
20
- return {
21
- output: value.output,
22
- agent: value.agent,
23
- };
24
- }
25
- return { output: value };
26
- }
27
- function invalidAgent(path, message) {
28
- throw new FlowNodeError({ code: "loop.invalid-agent", message, path });
29
- }
30
- /**
31
- * Interpret a root Loop node. Returns effects only; the host journals outcomes.
32
- */
33
- export async function runLoop(options) {
34
- const { manifest, checkpoint, host } = options;
35
- if (manifest.workflowSchemaVersion !== 1)
36
- throw new HarnessError("execution.invalid-state", "runLoop expects a workflow manifest v1");
37
- const root = manifest.root;
38
- if (!("loop" in root))
39
- throw new HarnessError("execution.invalid-state", "runLoop expects a loop root");
40
- const ctx = createFlowContext({
41
- manifest,
42
- checkpoint,
43
- host,
44
- signal: options.signal,
45
- limits: options.limits,
46
- });
47
- try {
48
- if (options.signal?.aborted)
49
- return { status: "cancelled", checkpoint, result: { status: "cancelled" } };
50
- const output = await runLoopNode(ctx, root.loop, root.loop.id, checkpoint.input);
51
- return {
52
- status: "completed",
53
- checkpoint,
54
- result: { status: "completed", output },
55
- };
56
- }
57
- catch (error) {
58
- await settleInFlight(ctx);
59
- if (error instanceof HostSuspension) {
60
- return {
61
- status: [...ctx.pending.values()].includes("uncertain") ? "uncertain" : "waiting",
62
- checkpoint,
63
- effectIds: [...ctx.pending.keys()],
64
- };
65
- }
66
- if (error instanceof FlowNodeError && error.failure.code === "cancelled")
67
- return { status: "cancelled", checkpoint, result: { status: "cancelled" } };
68
- const failure = failureOf(error, root.loop.id);
69
- return {
70
- status: "failed",
71
- checkpoint,
72
- result: { status: "failed", error: failure },
73
- ...(ctx.cancelEffectIds.size > 0 ? { cancelEffectIds: [...ctx.cancelEffectIds] } : {}),
74
- };
75
- }
76
- }
77
- /**
78
- * Nested or root Loop body: run → verify → decide until `{ output }` or stop.
79
- * Agent turn pinning / decide patches (`decision.agent`) are L5.
80
- */
81
- export async function runLoopNode(ctx, loop, path, input) {
82
- let iteration = 1;
83
- let currentInput = input;
84
- const history = [];
85
- const loopInput = input;
86
- const runIsAgent = "agent" in loop.run;
87
- // Session pin (first turn's manifest) and the patch carried within this run.
88
- let pinnedAgent;
89
- let currentAgent;
90
- for (;;) {
91
- if (ctx.signal?.aborted)
92
- throw new FlowNodeError({ code: "cancelled", message: "cancelled", path });
93
- // Operator ceiling before starting this iteration (WF-L3 / LOOP-A8).
94
- assertLoopIteration(iteration, ctx.limits, path);
95
- ctx.iterations = [...ctx.iterations, iteration];
96
- const iterations = ctx.iterationsString();
97
- try {
98
- let runOutput;
99
- if (runIsAgent) {
100
- const agentId = loop.run.agent;
101
- const agentPath = runPath(path, loop.run);
102
- const rawAgent = await ctx.effect("agent", {
103
- agentId,
104
- input: currentInput,
105
- path: agentPath,
106
- ...(currentAgent ? { manifest: currentAgent } : {}),
107
- }, { path: agentPath, key: nodeKeyOf(agentPath), iterations }, { loopPath: path, n: iteration });
108
- const turned = readAgentTurn(rawAgent);
109
- runOutput = turned.output;
110
- if (turned.agent) {
111
- // First turn establishes the session pin; later turns may be variants.
112
- pinnedAgent ??= turned.agent;
113
- currentAgent = turned.agent;
114
- }
115
- }
116
- else {
117
- runOutput = await runNode(ctx, loop.run, runPath(path, loop.run), currentInput, {
118
- ownerInput: loopInput,
119
- });
120
- }
121
- const verdict = await runVerify(ctx, loop.verify, path, {
122
- input: loopInput,
123
- output: runOutput,
124
- iteration,
125
- });
126
- let decision;
127
- try {
128
- decision = (await ctx.effect("fn", {
129
- output: runOutput,
130
- verdict,
131
- iteration,
132
- input: loopInput,
133
- history,
134
- ...(currentAgent ? { agent: currentAgent } : {}),
135
- }, { path, key: `${nodeKeyOf(path)}/decide`, iterations }, { loopPath: path, n: iteration, role: "decide" }));
136
- }
137
- catch (error) {
138
- if (error instanceof FlowNodeError && error.failure.code === "fn.failed") {
139
- throw new FlowNodeError({
140
- code: "loop.stopped",
141
- message: error.failure.message,
142
- path,
143
- });
144
- }
145
- if (error instanceof Error &&
146
- !(error instanceof HostSuspension) &&
147
- !(error instanceof FlowNodeError)) {
148
- throw new FlowNodeError({
149
- code: "loop.stopped",
150
- message: error.message,
151
- path,
152
- });
153
- }
154
- throw error;
155
- }
156
- if ("output" in decision && !("input" in decision))
157
- return decision.output;
158
- if (!("input" in decision))
159
- throw new HarnessError("execution.invalid-state", "Decide returned neither input nor output");
160
- const next = decision;
161
- if (next.agent !== undefined) {
162
- if (!runIsAgent) {
163
- invalidAgent(path, "Decide returned agent but Loop.run is not an agent");
164
- }
165
- if (pinnedAgent && !isVariantOf(next.agent, pinnedAgent)) {
166
- invalidAgent(path, "Decide returned a manifest that is not a variant of the pinned agent");
167
- }
168
- currentAgent = next.agent;
169
- }
170
- history.push({ iteration, output: runOutput, verdict });
171
- currentInput = next.input;
172
- iteration += 1;
173
- }
174
- finally {
175
- ctx.iterations.pop();
176
- }
177
- }
178
- }
179
- function runPath(loopPath, run) {
180
- const { part } = unwrapSlot(run);
181
- return joinPath(loopPath, part);
182
- }
183
- async function runVerify(ctx, verify, loopPath, args) {
184
- const iterations = ctx.iterationsString();
185
- if ("fn" in verify) {
186
- try {
187
- return (await ctx.effect("verify", args, { path: loopPath, key: nodeKeyOf(loopPath), iterations }, { loopPath, n: args.iteration }));
188
- }
189
- catch (error) {
190
- if (error instanceof FlowNodeError) {
191
- if (error.failure.code === "loop.verify-failed")
192
- throw error;
193
- throw new FlowNodeError({
194
- code: "loop.verify-failed",
195
- message: error.failure.message,
196
- path: loopPath,
197
- });
198
- }
199
- throw error;
200
- }
201
- }
202
- // Verifier agent (or slot wrapping one): input is { task, response, iteration }.
203
- const judgePayload = {
204
- task: args.input,
205
- response: args.output,
206
- iteration: args.iteration,
207
- };
208
- try {
209
- if ("slot" in verify) {
210
- const { part } = unwrapSlot(verify);
211
- const verifyPath = joinPath(loopPath, part);
212
- const value = await runNode(ctx, verify, verifyPath, judgePayload);
213
- return value;
214
- }
215
- if ("agent" in verify) {
216
- const verifyPath = joinPath(loopPath, verify.agent);
217
- const value = await ctx.effect("agent", { agentId: verify.agent, input: judgePayload, path: verifyPath }, { path: verifyPath, key: nodeKeyOf(verifyPath), iterations }, { loopPath, n: args.iteration, role: "verify-agent" });
218
- return value;
219
- }
220
- }
221
- catch (error) {
222
- if (error instanceof HostSuspension)
223
- throw error;
224
- if (error instanceof FlowNodeError) {
225
- throw new FlowNodeError({
226
- code: "loop.verify-failed",
227
- message: error.failure.message,
228
- path: loopPath,
229
- });
230
- }
231
- throw new FlowNodeError({
232
- code: "loop.verify-failed",
233
- message: error instanceof Error ? error.message : String(error),
234
- path: loopPath,
235
- });
236
- }
237
- throw new HarnessError("execution.invalid-state", "Unsupported Loop.verify node");
238
- }
@@ -1,7 +0,0 @@
1
- import type { JsonValue } from "@nylorun/core/define";
2
- import type { WorkflowMapNode } from "@nylorun/core";
3
- import type { FlowContext } from "./context.js";
4
- /**
5
- * Map: journal `over`, run each item concurrently at `<map>[i]/<each id>`; fail-fast.
6
- */
7
- export declare function runMap(ctx: FlowContext, node: WorkflowMapNode["map"], path: string, input: JsonValue): Promise<JsonValue>;
package/dist/flow/map.js DELETED
@@ -1,64 +0,0 @@
1
- import { HostSuspension } from "../loop/host-suspension.js";
2
- import { failureOf, markFailFastCancels } from "./context.js";
3
- import { assertMapItemCount } from "./limits.js";
4
- import { FlowNodeError } from "./types.js";
5
- import { mapItemPath, nodeKeyOf } from "./paths.js";
6
- import { runNode, unwrapSlot } from "./node.js";
7
- /**
8
- * Map: journal `over`, run each item concurrently at `<map>[i]/<each id>`; fail-fast.
9
- */
10
- export async function runMap(ctx, node, path, input) {
11
- const over = await ctx.effect("fn", input, { path, key: `${nodeKeyOf(path)}/over` }, { role: "map-over" });
12
- if (!Array.isArray(over)) {
13
- throw new FlowNodeError({
14
- code: "map.not-a-list",
15
- message: "Map.over did not return an array",
16
- path,
17
- });
18
- }
19
- const items = over;
20
- // Operator ceiling before any item starts (WF-L2 / MAP-E2).
21
- assertMapItemCount(items.length, ctx.limits, path);
22
- // Runtime emits map.items { path, count } after over is journaled.
23
- if (items.length === 0)
24
- return [];
25
- const { part: eachPart } = unwrapSlot(node.each);
26
- const outputs = new Array(items.length);
27
- const suspensions = [];
28
- const failures = [];
29
- await Promise.all(items.map(async (item, index) => {
30
- const itemPath = mapItemPath(path, index, eachPart);
31
- try {
32
- const eachNode = node.each;
33
- if ("slot" in eachNode && eachNode.slot.input) {
34
- outputs[index] = await runNode(ctx, eachNode, itemPath, item, {
35
- map: { item, mapInput: input, index },
36
- });
37
- }
38
- else {
39
- outputs[index] = await runNode(ctx, eachNode, itemPath, item);
40
- }
41
- }
42
- catch (error) {
43
- if (error instanceof HostSuspension) {
44
- suspensions.push(error);
45
- return;
46
- }
47
- failures.push(error instanceof FlowNodeError ? error : new FlowNodeError(failureOf(error, itemPath)));
48
- }
49
- }));
50
- if (failures.length > 0) {
51
- markFailFastCancels(ctx);
52
- failures.sort((a, b) => indexFromPath(a.failure.path) - indexFromPath(b.failure.path));
53
- throw failures[0];
54
- }
55
- if (suspensions.length > 0)
56
- throw suspensions[0];
57
- return outputs;
58
- }
59
- function indexFromPath(path) {
60
- if (!path)
61
- return Number.MAX_SAFE_INTEGER;
62
- const match = path.match(/\[(\d+)\]/);
63
- return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
64
- }
@@ -1,31 +0,0 @@
1
- import type { JsonValue } from "@nylorun/core/define";
2
- import type { WorkflowNode } from "@nylorun/core";
3
- import type { FlowContext } from "./context.js";
4
- import { joinPath, mapItemPath, nodeKeyOf } from "./paths.js";
5
- /** Path part / id for a node among its siblings. */
6
- export declare function nodePart(node: WorkflowNode): string;
7
- export type SlotUnwrap = {
8
- readonly run: WorkflowNode;
9
- readonly inputFn: boolean;
10
- readonly part: string;
11
- };
12
- export declare function unwrapSlot(node: WorkflowNode): SlotUnwrap;
13
- export type RunNodeOptions = {
14
- /**
15
- * Input of the primitive that owns the slot (`workflows.md` §4).
16
- * Defaults to `input` (the value the child would receive without a reshape).
17
- */
18
- readonly ownerInput?: JsonValue;
19
- /** Map item: slot `input` receives `{ value: item, input: mapInput, results, index }`. */
20
- readonly map?: {
21
- readonly item: JsonValue;
22
- readonly mapInput: JsonValue;
23
- readonly index: number;
24
- };
25
- };
26
- /**
27
- * Run any workflow node at `path` with `input`.
28
- * Slots: optional `fn` reshape, then the wrapped runnable.
29
- */
30
- export declare function runNode(ctx: FlowContext, node: WorkflowNode, path: string, input: JsonValue, options?: RunNodeOptions): Promise<JsonValue>;
31
- export { joinPath, mapItemPath, nodeKeyOf };
package/dist/flow/node.js DELETED
@@ -1,113 +0,0 @@
1
- import { HarnessError } from "@nylorun/core/define";
2
- import { joinPath, mapItemPath, nodeKeyOf } from "./paths.js";
3
- import { runChain } from "./chain.js";
4
- import { runSwitch } from "./switch.js";
5
- import { runParallel } from "./parallel.js";
6
- import { runMap } from "./map.js";
7
- import { readAgentTurn, runLoopNode } from "./loop.js";
8
- import { FlowNodeError } from "./types.js";
9
- /** Path part / id for a node among its siblings. */
10
- export function nodePart(node) {
11
- if ("agent" in node)
12
- return node.agent;
13
- if ("tool" in node)
14
- return node.tool.name;
15
- if ("chain" in node)
16
- return node.chain.id;
17
- if ("switch" in node)
18
- return node.switch.id;
19
- if ("parallel" in node)
20
- return node.parallel.id;
21
- if ("map" in node)
22
- return node.map.id;
23
- if ("loop" in node)
24
- return node.loop.id;
25
- if ("slot" in node)
26
- return node.slot.id ?? nodePart(node.slot.run);
27
- throw new HarnessError("execution.invalid-state", "Unknown workflow node kind");
28
- }
29
- export function unwrapSlot(node) {
30
- if ("slot" in node) {
31
- return {
32
- run: node.slot.run,
33
- inputFn: !!node.slot.input,
34
- part: node.slot.id ?? nodePart(node.slot.run),
35
- };
36
- }
37
- return { run: node, inputFn: false, part: nodePart(node) };
38
- }
39
- /**
40
- * Run any workflow node at `path` with `input`.
41
- * Slots: optional `fn` reshape, then the wrapped runnable.
42
- */
43
- export async function runNode(ctx, node, path, input, options = {}) {
44
- if ("slot" in node) {
45
- let childInput = input;
46
- if (node.slot.input) {
47
- const results = ctx.nearestResults();
48
- const fnArgs = options.map
49
- ? {
50
- value: options.map.item,
51
- input: options.map.mapInput,
52
- results,
53
- index: options.map.index,
54
- }
55
- : {
56
- value: input,
57
- input: options.ownerInput ?? input,
58
- results,
59
- };
60
- childInput = (await ctx.effect("fn", fnArgs, { path, key: `${nodeKeyOf(path)}/input`, role: "slot-input" }, { role: "slot-input" }));
61
- }
62
- return runRunnable(ctx, node.slot.run, path, childInput);
63
- }
64
- return runRunnable(ctx, node, path, input);
65
- }
66
- async function runRunnable(ctx, node, path, input) {
67
- if ("slot" in node)
68
- return runNode(ctx, node, path, input);
69
- if ("agent" in node)
70
- return runAgent(ctx, node.agent, path, input);
71
- if ("tool" in node)
72
- return runTool(ctx, node.tool.name, path, input);
73
- if ("chain" in node)
74
- return runChain(ctx, node.chain, path, input);
75
- if ("switch" in node)
76
- return runSwitch(ctx, node.switch, path, input);
77
- if ("parallel" in node)
78
- return runParallel(ctx, node.parallel, path, input);
79
- if ("map" in node)
80
- return runMap(ctx, node.map, path, input);
81
- if ("loop" in node)
82
- return runLoopNode(ctx, node.loop, path, input);
83
- throw new HarnessError("execution.invalid-state", "Unknown workflow node kind");
84
- }
85
- async function runAgent(ctx, agentId, path, input) {
86
- // The host marks a linked agent's output with its turn manifest for Loops; a step
87
- // passes on the output only.
88
- return readAgentTurn(await ctx.effect("agent", { agentId, input, path }, { path, key: nodeKeyOf(path) })).output;
89
- }
90
- async function runTool(ctx, name, path, input) {
91
- const value = await ctx.effect("tool", input, { path, key: nodeKeyOf(path) }, { toolName: name });
92
- return toolNodeOutput(value, path);
93
- }
94
- /**
95
- * The Action endpoint settles a tool node like any tool: `{ kind: "completed", output }` or
96
- * `{ kind: "denied", reason }`. The flow passes on the output only. Failed values are
97
- * already raised by `ctx.effect`.
98
- */
99
- function toolNodeOutput(value, path) {
100
- if (!value || typeof value !== "object" || Array.isArray(value))
101
- return value;
102
- const outcome = value;
103
- if (outcome.kind === "completed" && "output" in outcome)
104
- return outcome.output ?? null;
105
- if (outcome.kind === "denied")
106
- throw new FlowNodeError({
107
- code: "tool.denied",
108
- message: typeof outcome.reason === "string" ? outcome.reason : "Tool call denied",
109
- path,
110
- });
111
- return value;
112
- }
113
- export { joinPath, mapItemPath, nodeKeyOf };
@@ -1,7 +0,0 @@
1
- import type { JsonValue } from "@nylorun/core/define";
2
- import type { WorkflowParallelNode } from "@nylorun/core";
3
- import type { FlowContext } from "./context.js";
4
- /**
5
- * Parallel: all branches ready at once; output object in declaration order; fail-fast.
6
- */
7
- export declare function runParallel(ctx: FlowContext, node: WorkflowParallelNode["parallel"], path: string, input: JsonValue): Promise<JsonValue>;
@@ -1,47 +0,0 @@
1
- import { HostSuspension } from "../loop/host-suspension.js";
2
- import { failureOf, markFailFastCancels } from "./context.js";
3
- import { FlowNodeError } from "./types.js";
4
- import { joinPath } from "./paths.js";
5
- import { runNode } from "./node.js";
6
- /**
7
- * Parallel: all branches ready at once; output object in declaration order; fail-fast.
8
- */
9
- export async function runParallel(ctx, node, path, input) {
10
- const names = Object.keys(node.branches);
11
- const outputs = {};
12
- const suspensions = [];
13
- const failures = [];
14
- await Promise.all(names.map(async (name) => {
15
- const branch = node.branches[name];
16
- const branchPath = joinPath(path, name);
17
- try {
18
- outputs[name] = await runNode(ctx, branch, branchPath, input);
19
- }
20
- catch (error) {
21
- if (error instanceof HostSuspension) {
22
- suspensions.push(error);
23
- return;
24
- }
25
- failures.push(error instanceof FlowNodeError ? error : new FlowNodeError(failureOf(error, branchPath)));
26
- }
27
- }));
28
- if (failures.length > 0) {
29
- markFailFastCancels(ctx);
30
- // First failure in declaration order wins when several settle together.
31
- const ordered = failures.sort((a, b) => {
32
- const ai = names.findIndex((n) => (a.failure.path ?? "").includes(`/${n}`) || a.failure.path?.endsWith(n));
33
- const bi = names.findIndex((n) => (b.failure.path ?? "").includes(`/${n}`) || b.failure.path?.endsWith(n));
34
- return (ai === -1 ? names.length : ai) - (bi === -1 ? names.length : bi);
35
- });
36
- throw ordered[0];
37
- }
38
- if (suspensions.length > 0) {
39
- // Re-throw one suspension; pending map already holds every branch effect id.
40
- throw suspensions[0];
41
- }
42
- // Declaration order.
43
- const result = {};
44
- for (const name of names)
45
- result[name] = outputs[name];
46
- return result;
47
- }
@@ -1,8 +0,0 @@
1
- import type { JsonValue } from "@nylorun/core/define";
2
- import type { WorkflowSwitchNode } from "@nylorun/core";
3
- import type { FlowContext } from "./context.js";
4
- /**
5
- * Switch: `fn` effect for `on`, select case or fail `switch.no-match`, run chosen case.
6
- * The key is journaled so replay always takes the same case.
7
- */
8
- export declare function runSwitch(ctx: FlowContext, node: WorkflowSwitchNode["switch"], path: string, input: JsonValue): Promise<JsonValue>;
@@ -1,35 +0,0 @@
1
- import { FlowNodeError } from "./types.js";
2
- import { joinPath, nodeKeyOf } from "./paths.js";
3
- import { runNode } from "./node.js";
4
- /**
5
- * Switch: `fn` effect for `on`, select case or fail `switch.no-match`, run chosen case.
6
- * The key is journaled so replay always takes the same case.
7
- */
8
- export async function runSwitch(ctx, node, path, input) {
9
- const key = await ctx.effect("fn", input, { path, key: `${nodeKeyOf(path)}/on` }, { role: "switch-on" });
10
- if (typeof key !== "string") {
11
- throw new FlowNodeError({
12
- code: "fn.failed",
13
- message: `Switch.on must return a string, got ${typeof key}`,
14
- path,
15
- });
16
- }
17
- let caseNode = node.cases[key];
18
- let casePart = key;
19
- if (!caseNode) {
20
- if (node.default) {
21
- caseNode = node.default;
22
- casePart = "default";
23
- }
24
- else {
25
- throw new FlowNodeError({
26
- code: "switch.no-match",
27
- message: `No Switch case matched key ${JSON.stringify(key)}`,
28
- path,
29
- });
30
- }
31
- }
32
- // Selection is implied by the journaled `on` result; Runtime emits switch.selected.
33
- const casePath = joinPath(path, casePart);
34
- return runNode(ctx, caseNode, casePath, input);
35
- }
package/dist/flow/v2.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { type WorkflowManifestV2 } from "@nylorun/core/define";
2
- import type { DurableHost } from "../run/durable.js";
3
- import type { FlowCheckpoint } from "./checkpoint.js";
4
- import { type FlowOperatorLimits } from "./limits.js";
5
- import { type FlowDurableResult } from "./types.js";
6
- export declare function runFlowV2(options: {
7
- manifest: WorkflowManifestV2;
8
- checkpoint: FlowCheckpoint;
9
- host: DurableHost;
10
- signal?: AbortSignal;
11
- limits?: Partial<FlowOperatorLimits> | null;
12
- }): Promise<FlowDurableResult>;