@nylorun/harness 0.22.0-beta → 0.23.0-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.
- package/CHANGELOG.md +96 -0
- package/HOST_CONTRACT.md +18 -21
- package/README.md +5 -30
- package/dist/api/executors.d.ts +5 -4
- package/dist/api/harness.d.ts +0 -10
- package/dist/api/harness.js +1 -52
- package/dist/api/host.d.ts +2 -8
- package/dist/api/host.js +3 -15
- package/dist/api/run.d.ts +0 -11
- package/dist/api/run.js +1 -11
- package/dist/compatibility.d.ts +4 -12
- package/dist/compatibility.js +3 -11
- package/dist/definition/agent-definition.d.ts +0 -3
- package/dist/definition/agent-definition.js +0 -2
- package/dist/flow/checkpoint.d.ts +16 -0
- package/dist/flow/checkpoint.js +6 -2
- package/dist/flow/context.d.ts +19 -10
- package/dist/flow/context.js +36 -20
- package/dist/flow/engine.d.ts +25 -7
- package/dist/flow/engine.js +304 -38
- package/dist/flow/index.d.ts +3 -5
- package/dist/flow/index.js +3 -5
- package/dist/flow/paths.d.ts +1 -8
- package/dist/flow/paths.js +1 -12
- package/dist/flow/tool.d.ts +14 -0
- package/dist/flow/tool.js +67 -0
- package/dist/flow/types.d.ts +30 -3
- package/dist/flow/types.js +14 -1
- package/dist/loop/run.js +5 -134
- package/dist/loop/state.js +2 -22
- package/dist/loop/step/run.d.ts +1 -10
- package/dist/loop/step/run.js +2 -101
- package/dist/loop/step/runtime.d.ts +0 -17
- package/dist/run/durable.d.ts +7 -11
- package/dist/run/durable.js +14 -33
- package/dist/run/index.d.ts +3 -4
- package/dist/run/index.js +1 -2
- package/dist/types/execution.d.ts +5 -18
- package/package.json +2 -2
- package/dist/flow/chain.d.ts +0 -8
- package/dist/flow/chain.js +0 -27
- package/dist/flow/loop.d.ts +0 -35
- package/dist/flow/loop.js +0 -238
- package/dist/flow/map.d.ts +0 -7
- package/dist/flow/map.js +0 -64
- package/dist/flow/node.d.ts +0 -31
- package/dist/flow/node.js +0 -113
- package/dist/flow/parallel.d.ts +0 -7
- package/dist/flow/parallel.js +0 -47
- package/dist/flow/switch.d.ts +0 -8
- package/dist/flow/switch.js +0 -35
- package/dist/flow/v2.d.ts +0 -12
- package/dist/flow/v2.js +0 -370
- package/dist/loop/step/hooks.d.ts +0 -56
- package/dist/loop/step/hooks.js +0 -191
package/dist/compatibility.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
export { checkCompatibility } from "./definition/compatibility.js";
|
|
2
2
|
export declare const CHECKPOINT_VERSION = 1;
|
|
3
|
-
export declare const ENGINE_VERSION = "hosted-
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export declare const FLOW_ENGINE_VERSION = "flow-2";
|
|
9
|
-
export declare const FLOW_ENGINE_VERSION_V1 = "flow-1";
|
|
10
|
-
export type FlowEngineVersion = typeof FLOW_ENGINE_VERSION | typeof FLOW_ENGINE_VERSION_V1;
|
|
11
|
-
/** The engine a workflow manifest runs on. */
|
|
12
|
-
export declare function flowEngineVersionOf(manifest: {
|
|
13
|
-
readonly workflowSchemaVersion: number;
|
|
14
|
-
}): FlowEngineVersion;
|
|
3
|
+
export declare const ENGINE_VERSION = "hosted-4";
|
|
4
|
+
/** Flow engine version pinned on workflow checkpoints: workflow manifest v3 runs on `flow-3`. */
|
|
5
|
+
export declare const FLOW_ENGINE_VERSION = "flow-3";
|
|
6
|
+
export type FlowEngineVersion = typeof FLOW_ENGINE_VERSION;
|
package/dist/compatibility.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
export { checkCompatibility } from "./definition/compatibility.js";
|
|
2
2
|
export const CHECKPOINT_VERSION = 1;
|
|
3
|
-
export const ENGINE_VERSION = "hosted-
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
* `flow-2`; v1 manifests keep running on `flow-1`, so in-flight v1 runs finish as they began.
|
|
7
|
-
*/
|
|
8
|
-
export const FLOW_ENGINE_VERSION = "flow-2";
|
|
9
|
-
export const FLOW_ENGINE_VERSION_V1 = "flow-1";
|
|
10
|
-
/** The engine a workflow manifest runs on. */
|
|
11
|
-
export function flowEngineVersionOf(manifest) {
|
|
12
|
-
return manifest.workflowSchemaVersion === 2 ? FLOW_ENGINE_VERSION : FLOW_ENGINE_VERSION_V1;
|
|
13
|
-
}
|
|
3
|
+
export const ENGINE_VERSION = "hosted-4";
|
|
4
|
+
/** Flow engine version pinned on workflow checkpoints: workflow manifest v3 runs on `flow-3`. */
|
|
5
|
+
export const FLOW_ENGINE_VERSION = "flow-3";
|
|
@@ -3,7 +3,6 @@ import type { ToolRegistry } from "./registry.js";
|
|
|
3
3
|
import type { TurnOutputContract } from "@nylorun/core/define";
|
|
4
4
|
import type { AgentManifest } from "@nylorun/core/define";
|
|
5
5
|
import type { Implementations } from "@nylorun/core/define";
|
|
6
|
-
import { type HookRunner } from "../loop/step/hooks.js";
|
|
7
6
|
export interface AgentDefinition {
|
|
8
7
|
readonly id: string;
|
|
9
8
|
readonly middleware: readonly BoundMiddleware[];
|
|
@@ -12,8 +11,6 @@ export interface AgentDefinition {
|
|
|
12
11
|
readonly manifest: AgentManifest;
|
|
13
12
|
readonly hash: string;
|
|
14
13
|
readonly implementations: Implementations;
|
|
15
|
-
/** Runs one hook point. In-process by default; the durable host journals it as one effect. */
|
|
16
|
-
readonly runHooks: HookRunner;
|
|
17
14
|
}
|
|
18
15
|
export type { Implementations };
|
|
19
16
|
import type { AgentBinding } from "@nylorun/core/define";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { localHookRunner } from "../loop/step/hooks.js";
|
|
2
1
|
import { bindingFromAgent, bindOutputContract } from "@nylorun/core/define";
|
|
3
2
|
import { ToolRegistry as Registry } from "./registry.js";
|
|
4
3
|
import { hashManifest } from "@nylorun/core/compatibility";
|
|
@@ -12,7 +11,6 @@ export function definitionFromBinding(binding) {
|
|
|
12
11
|
hash: hashManifest(binding.manifest),
|
|
13
12
|
middleware: binding.declarations,
|
|
14
13
|
implementations: binding.implementations,
|
|
15
|
-
runHooks: localHookRunner(binding.implementations),
|
|
16
14
|
registry: new Registry(binding.declarations, binding.tools),
|
|
17
15
|
...(binding.outputSchema ? { output: bindOutputContract(binding.outputSchema) } : {}),
|
|
18
16
|
});
|
|
@@ -11,7 +11,21 @@ export interface FlowCheckpoint {
|
|
|
11
11
|
/** Increment for each human/event continuation, not for an action result. */
|
|
12
12
|
readonly segment: number;
|
|
13
13
|
readonly input: JsonValue;
|
|
14
|
+
/**
|
|
15
|
+
* Answers to the flow's own interactions (a tool node's `ctx.approve` / `ctx.ask`), by
|
|
16
|
+
* interaction id. A flow resumes in the same segment, so its journaled effects replay; the
|
|
17
|
+
* tool that asked runs again as a new effect with its answer.
|
|
18
|
+
*/
|
|
19
|
+
readonly resumes?: Readonly<Record<string, FlowResume>>;
|
|
14
20
|
}
|
|
21
|
+
/** The answer to one flow interaction (`approve` or `respond`). */
|
|
22
|
+
export type FlowResume = {
|
|
23
|
+
readonly kind: "approval";
|
|
24
|
+
readonly approved: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "response";
|
|
27
|
+
readonly value: JsonValue;
|
|
28
|
+
};
|
|
15
29
|
export declare function createFlowCheckpoint(input: {
|
|
16
30
|
manifest: WorkflowManifest;
|
|
17
31
|
sessionId: string;
|
|
@@ -19,3 +33,5 @@ export declare function createFlowCheckpoint(input: {
|
|
|
19
33
|
input: JsonValue;
|
|
20
34
|
segment?: number;
|
|
21
35
|
}): FlowCheckpoint;
|
|
36
|
+
/** `checkpoint` with the answer to interaction `interactionId`. */
|
|
37
|
+
export declare function resumeFlowCheckpoint(checkpoint: FlowCheckpoint, interactionId: string, answer: FlowResume): FlowCheckpoint;
|
package/dist/flow/checkpoint.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { WorkflowManifestSchema } from "@nylorun/core/contracts";
|
|
2
2
|
import { hashManifest } from "@nylorun/core/define";
|
|
3
|
-
import { CHECKPOINT_VERSION,
|
|
3
|
+
import { CHECKPOINT_VERSION, FLOW_ENGINE_VERSION, } from "../compatibility.js";
|
|
4
4
|
export function createFlowCheckpoint(input) {
|
|
5
5
|
WorkflowManifestSchema.parse(input.manifest);
|
|
6
6
|
return {
|
|
7
7
|
version: CHECKPOINT_VERSION,
|
|
8
|
-
engineVersion:
|
|
8
|
+
engineVersion: FLOW_ENGINE_VERSION,
|
|
9
9
|
manifestHash: hashManifest(input.manifest),
|
|
10
10
|
sessionId: input.sessionId,
|
|
11
11
|
turnId: input.turnId,
|
|
@@ -13,3 +13,7 @@ export function createFlowCheckpoint(input) {
|
|
|
13
13
|
input: input.input,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
/** `checkpoint` with the answer to interaction `interactionId`. */
|
|
17
|
+
export function resumeFlowCheckpoint(checkpoint, interactionId, answer) {
|
|
18
|
+
return { ...checkpoint, resumes: { ...checkpoint.resumes, [interactionId]: answer } };
|
|
19
|
+
}
|
package/dist/flow/context.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WorkflowManifest } from "@nylorun/core/define";
|
|
2
2
|
import type { DurableHost } from "../run/durable.js";
|
|
3
3
|
import type { FlowCheckpoint } from "./checkpoint.js";
|
|
4
4
|
import { type FlowOperatorLimits } from "./limits.js";
|
|
5
|
-
import { type FlowFailure } from "./types.js";
|
|
6
|
-
export type FlowEffectKind = "agent" | "tool"
|
|
5
|
+
import { FlowPause, type FlowDurableResult, type FlowFailure, type FlowInteraction } from "./types.js";
|
|
6
|
+
export type FlowEffectKind = "agent" | "tool";
|
|
7
7
|
export type FlowContext = {
|
|
8
8
|
readonly manifest: WorkflowManifest;
|
|
9
9
|
readonly checkpoint: FlowCheckpoint;
|
|
@@ -12,21 +12,25 @@ export type FlowContext = {
|
|
|
12
12
|
/** Operator ceilings (Map items / Loop iterations). */
|
|
13
13
|
readonly limits: FlowOperatorLimits;
|
|
14
14
|
readonly pending: Map<string, "pending" | "uncertain">;
|
|
15
|
+
/** Interactions tool nodes wait on, by interaction id. */
|
|
16
|
+
readonly interactions: Map<string, FlowInteraction>;
|
|
15
17
|
readonly inFlight: Set<Promise<unknown>>;
|
|
16
|
-
/** Nearest enclosing Chain `results`, outermost first. */
|
|
17
|
-
readonly resultsStack: Array<Record<string, JsonValue>>;
|
|
18
|
-
/** Enclosing Loop iteration numbers, outermost first. */
|
|
19
|
-
iterations: number[];
|
|
20
18
|
/** Effect ids the engine wants cancelled after fail-fast. */
|
|
21
19
|
readonly cancelEffectIds: Set<string>;
|
|
22
20
|
effect(kind: FlowEffectKind, input: unknown, identity: {
|
|
23
21
|
path: string;
|
|
24
22
|
key: string;
|
|
25
|
-
iterations
|
|
23
|
+
iterations: string;
|
|
26
24
|
role?: string;
|
|
27
25
|
}, context?: Record<string, unknown>): Promise<unknown>;
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
/** The id `effect` gives an effect of `kind` at `identity`. */
|
|
27
|
+
effectIdOf(kind: FlowEffectKind, identity: {
|
|
28
|
+
path: string;
|
|
29
|
+
iterations: string;
|
|
30
|
+
role?: string;
|
|
31
|
+
}): string;
|
|
32
|
+
/** Records an interaction a tool node waits on; throw what it returns. */
|
|
33
|
+
pause(interaction: FlowInteraction): FlowPause;
|
|
30
34
|
};
|
|
31
35
|
export declare function createFlowContext(options: {
|
|
32
36
|
readonly manifest: WorkflowManifest;
|
|
@@ -35,6 +39,11 @@ export declare function createFlowContext(options: {
|
|
|
35
39
|
readonly signal?: AbortSignal;
|
|
36
40
|
readonly limits?: Partial<FlowOperatorLimits> | null;
|
|
37
41
|
}): FlowContext;
|
|
42
|
+
/**
|
|
43
|
+
* The result of a flow that unwound on a suspension: waiting (or uncertain) while any effect is
|
|
44
|
+
* pending, otherwise paused on the interactions its tool nodes wait on.
|
|
45
|
+
*/
|
|
46
|
+
export declare function suspendedResult(ctx: FlowContext): FlowDurableResult;
|
|
38
47
|
export declare function markFailFastCancels(ctx: FlowContext): void;
|
|
39
48
|
export declare function settleInFlight(ctx: FlowContext): Promise<void>;
|
|
40
49
|
export declare function failureOf(error: unknown, fallbackPath?: string): FlowFailure;
|
package/dist/flow/context.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { HostSuspension } from "../loop/host-suspension.js";
|
|
2
2
|
import { resolveOperatorLimits } from "./limits.js";
|
|
3
|
-
import { flowEffectId,
|
|
4
|
-
import { failedValueOf, FlowNodeError } from "./types.js";
|
|
3
|
+
import { flowEffectId, nodeKeyOf } from "./paths.js";
|
|
4
|
+
import { failedValueOf, FlowNodeError, FlowPause, } from "./types.js";
|
|
5
5
|
export function createFlowContext(options) {
|
|
6
6
|
const pending = new Map();
|
|
7
|
+
const interactions = new Map();
|
|
7
8
|
const inFlight = new Set();
|
|
8
9
|
const cancelEffectIds = new Set();
|
|
9
|
-
const resultsStack = [];
|
|
10
10
|
const ctx = {
|
|
11
11
|
manifest: options.manifest,
|
|
12
12
|
checkpoint: options.checkpoint,
|
|
@@ -14,29 +14,29 @@ export function createFlowContext(options) {
|
|
|
14
14
|
signal: options.signal,
|
|
15
15
|
limits: resolveOperatorLimits(options.limits),
|
|
16
16
|
pending,
|
|
17
|
+
interactions,
|
|
17
18
|
inFlight,
|
|
18
|
-
resultsStack,
|
|
19
|
-
iterations: [],
|
|
20
19
|
cancelEffectIds,
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
},
|
|
24
|
-
iterationsString() {
|
|
25
|
-
return iterationsOf(ctx.iterations);
|
|
26
|
-
},
|
|
27
|
-
async effect(kind, input, identity, context = {}) {
|
|
28
|
-
if (options.signal?.aborted)
|
|
29
|
-
throw new FlowNodeError({ code: "cancelled", message: "cancelled" });
|
|
30
|
-
const iterations = identity.iterations ?? ctx.iterationsString();
|
|
31
|
-
const key = identity.key || nodeKeyOf(identity.path);
|
|
32
|
-
const effectId = flowEffectId({
|
|
20
|
+
effectIdOf(kind, identity) {
|
|
21
|
+
return flowEffectId({
|
|
33
22
|
turnId: options.checkpoint.turnId,
|
|
34
23
|
segment: options.checkpoint.segment,
|
|
35
24
|
path: identity.path,
|
|
36
25
|
kind,
|
|
37
|
-
iterations,
|
|
26
|
+
iterations: identity.iterations,
|
|
38
27
|
...(identity.role === undefined ? {} : { role: identity.role }),
|
|
39
28
|
});
|
|
29
|
+
},
|
|
30
|
+
pause(interaction) {
|
|
31
|
+
interactions.set(interaction.interaction.id, interaction);
|
|
32
|
+
return new FlowPause(interaction);
|
|
33
|
+
},
|
|
34
|
+
async effect(kind, input, identity, context = {}) {
|
|
35
|
+
if (options.signal?.aborted)
|
|
36
|
+
throw new FlowNodeError({ code: "cancelled", message: "cancelled" });
|
|
37
|
+
const { iterations } = identity;
|
|
38
|
+
const key = identity.key || nodeKeyOf(identity.path);
|
|
39
|
+
const effectId = ctx.effectIdOf(kind, identity);
|
|
40
40
|
if (cancelEffectIds.has(effectId))
|
|
41
41
|
throw new FlowNodeError({
|
|
42
42
|
code: "cancelled",
|
|
@@ -81,6 +81,22 @@ export function createFlowContext(options) {
|
|
|
81
81
|
};
|
|
82
82
|
return ctx;
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* The result of a flow that unwound on a suspension: waiting (or uncertain) while any effect is
|
|
86
|
+
* pending, otherwise paused on the interactions its tool nodes wait on.
|
|
87
|
+
*/
|
|
88
|
+
export function suspendedResult(ctx) {
|
|
89
|
+
const { checkpoint } = ctx;
|
|
90
|
+
if (ctx.pending.size === 0 && ctx.interactions.size > 0) {
|
|
91
|
+
const pending = [...ctx.interactions.values()];
|
|
92
|
+
return { status: "paused", checkpoint, result: { status: "paused", pending } };
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
status: [...ctx.pending.values()].includes("uncertain") ? "uncertain" : "waiting",
|
|
96
|
+
checkpoint,
|
|
97
|
+
effectIds: [...ctx.pending.keys()],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
84
100
|
export function markFailFastCancels(ctx) {
|
|
85
101
|
for (const effectId of ctx.pending.keys())
|
|
86
102
|
ctx.cancelEffectIds.add(effectId);
|
|
@@ -96,6 +112,6 @@ export function failureOf(error, fallbackPath) {
|
|
|
96
112
|
};
|
|
97
113
|
}
|
|
98
114
|
if (error instanceof Error && error.message)
|
|
99
|
-
return { code: "
|
|
100
|
-
return { code: "
|
|
115
|
+
return { code: "flow.failed", message: error.message, path: fallbackPath };
|
|
116
|
+
return { code: "flow.failed", message: String(error), path: fallbackPath };
|
|
101
117
|
}
|
package/dist/flow/engine.d.ts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flow engine for workflow manifest v3 (`flow-3`). A flow is data: every value a stage sees
|
|
3
|
+
* comes from the flow's input and the outputs of the agents and tools before it. Returns
|
|
4
|
+
* effects only (SD-I1).
|
|
5
|
+
*
|
|
6
|
+
* - The first stage gets the flow's input; every later stage gets the previous output.
|
|
7
|
+
* - A Switch reads the previous output: a string is the case name, and so is an object's
|
|
8
|
+
* `route` field. The chosen case gets the whole output.
|
|
9
|
+
* - A Map runs over the previous output when it is an array, or over its `items` array.
|
|
10
|
+
* - A Parallel gives every branch the same input; its output is keyed by branch.
|
|
11
|
+
* - A Loop runs its body, asks its verifier for a verdict, and stops on a pass or retries with
|
|
12
|
+
* the feedback, up to `max` attempts. The body keeps its session. A verifier agent gets
|
|
13
|
+
* `{ task, response, iteration }`; an HTTP verifier `{ input, output, iteration }`. A body
|
|
14
|
+
* that starts with an HTTP stage, which takes an object, is retried with the Loop's input.
|
|
15
|
+
* - An HTTP stage (a tool node with `http`) checks its input against its input schema, then
|
|
16
|
+
* runs as a `tool` effect the host makes through its Tool Gate. A failed request fails the
|
|
17
|
+
* stage with its code (`http.status`, `http.timeout`, `tool.invalid-output`, …).
|
|
18
|
+
* - Agent and tool sessions are named by leaf paths: the leaf's id, `[i]` per Map item,
|
|
19
|
+
* under nested flow agents' ids. Control stages add nothing.
|
|
20
|
+
* - Leaf agents come from the manifest's embedded `agents`; nested flow agents run inline
|
|
21
|
+
* with their own input. An agent effect carries its flow agent's input as `flowInput`
|
|
22
|
+
* when the stage's own input differs, so the host can show the agent the original request.
|
|
23
|
+
*/
|
|
24
|
+
import { type WorkflowManifest } from "@nylorun/core/define";
|
|
2
25
|
import type { DurableHost } from "../run/durable.js";
|
|
3
26
|
import type { FlowCheckpoint } from "./checkpoint.js";
|
|
4
|
-
import type
|
|
27
|
+
import { type FlowOperatorLimits } from "./limits.js";
|
|
5
28
|
import { type FlowDurableResult } from "./types.js";
|
|
6
|
-
/**
|
|
7
|
-
* Deterministic flow interpreter for workflow manifests. v2 manifests run on the
|
|
8
|
-
* `flow-2` engine (`./v2.ts`); v1 manifests on `flow-1`, one module per primitive.
|
|
9
|
-
* Returns effects only (SD-I1).
|
|
10
|
-
*/
|
|
11
29
|
export declare function runFlowDurable(options: {
|
|
12
30
|
manifest: WorkflowManifest;
|
|
13
31
|
checkpoint: FlowCheckpoint;
|