@nylorun/core 0.3.0-beta → 0.5.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 +32 -0
- package/dist/compatibility.d.ts +48 -1
- package/dist/compatibility.js +192 -1
- package/dist/contracts.d.ts +562 -19
- package/dist/contracts.js +442 -29
- package/dist/define.d.ts +9 -3
- package/dist/define.js +3 -0
- package/dist/definition/assemble.js +35 -0
- package/dist/definition/bind-tool.js +3 -0
- package/dist/definition/bound.d.ts +3 -0
- package/dist/definition/builder.d.ts +5 -5
- package/dist/definition/declaration.d.ts +2 -2
- package/dist/definition/declaration.js +13 -1
- package/dist/definition/delegate.d.ts +35 -0
- package/dist/definition/delegate.js +72 -0
- package/dist/definition/from.js +15 -2
- package/dist/definition/helpers.d.ts +1 -1
- package/dist/definition/helpers.js +8 -1
- package/dist/definition/manifest.js +3 -0
- package/dist/definition/variant.d.ts +7 -0
- package/dist/definition/variant.js +87 -0
- package/dist/definition/workflow/build.d.ts +38 -0
- package/dist/definition/workflow/build.js +62 -0
- package/dist/definition/workflow/chain.d.ts +49 -0
- package/dist/definition/workflow/chain.js +41 -0
- package/dist/definition/workflow/diagnostics.d.ts +14 -0
- package/dist/definition/workflow/diagnostics.js +38 -0
- package/dist/definition/workflow/index.d.ts +18 -0
- package/dist/definition/workflow/index.js +10 -0
- package/dist/definition/workflow/loop.d.ts +54 -0
- package/dist/definition/workflow/loop.js +102 -0
- package/dist/definition/workflow/map.d.ts +17 -0
- package/dist/definition/workflow/map.js +46 -0
- package/dist/definition/workflow/parallel.d.ts +19 -0
- package/dist/definition/workflow/parallel.js +37 -0
- package/dist/definition/workflow/patch.d.ts +11 -0
- package/dist/definition/workflow/patch.js +45 -0
- package/dist/definition/workflow/runnable.d.ts +40 -0
- package/dist/definition/workflow/runnable.js +251 -0
- package/dist/definition/workflow/slot.d.ts +23 -0
- package/dist/definition/workflow/slot.js +16 -0
- package/dist/definition/workflow/switch.d.ts +26 -0
- package/dist/definition/workflow/switch.js +66 -0
- package/dist/definition/workflow/types.d.ts +25 -0
- package/dist/definition/workflow/types.js +7 -0
- package/dist/definition/workflow/verdict.d.ts +20 -0
- package/dist/definition/workflow/verdict.js +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/types/agent.d.ts +5 -0
- package/dist/types/manifest.d.ts +5 -0
- package/dist/types/middleware.d.ts +5 -0
- package/dist/types/observe.d.ts +87 -1
- package/dist/types/tool.d.ts +11 -0
- package/dist/types/workflow.d.ts +106 -0
- package/dist/types/workflow.js +1 -0
- package/dist/utils/hash.d.ts +3 -2
- package/dist/utils/hash.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Thrown when a workflow primitive fails its build-time checks. */
|
|
2
|
+
export class WorkflowBuildError extends Error {
|
|
3
|
+
diagnostics;
|
|
4
|
+
constructor(diagnostics) {
|
|
5
|
+
super(diagnostics.map((item) => item.message).join("; ") || "Workflow build failed");
|
|
6
|
+
this.diagnostics = diagnostics;
|
|
7
|
+
this.name = "WorkflowBuildError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function diagnostic(code, message, extra = {}) {
|
|
11
|
+
return Object.freeze({ code, message, ...extra });
|
|
12
|
+
}
|
|
13
|
+
export function fail(diagnostics) {
|
|
14
|
+
throw new WorkflowBuildError(Object.freeze([...diagnostics]));
|
|
15
|
+
}
|
|
16
|
+
export function failOne(code, message, extra) {
|
|
17
|
+
fail([diagnostic(code, message, extra)]);
|
|
18
|
+
}
|
|
19
|
+
/** Path parts: non-empty, with no `/`, `[` or `]`. */
|
|
20
|
+
export function isValidPathPart(part) {
|
|
21
|
+
return part.length > 0 && !/[\/\[\]]/.test(part);
|
|
22
|
+
}
|
|
23
|
+
export function assertValidPathPart(part, label) {
|
|
24
|
+
if (!isValidPathPart(part))
|
|
25
|
+
failOne("workflow.invalid-path-part", `${label} '${part}' must be a non-empty path part with no '/', '[' or ']'`);
|
|
26
|
+
}
|
|
27
|
+
/** Record duplicate sibling path parts; returns diagnostics (does not throw). */
|
|
28
|
+
export function siblingUniquenessDiagnostics(parts, label) {
|
|
29
|
+
const seen = new Map();
|
|
30
|
+
const found = [];
|
|
31
|
+
for (const part of parts) {
|
|
32
|
+
const count = (seen.get(part) ?? 0) + 1;
|
|
33
|
+
seen.set(part, count);
|
|
34
|
+
if (count === 2)
|
|
35
|
+
found.push(diagnostic("workflow.duplicate-sibling", `Duplicate ${label} id '${part}'; path parts must be unique among siblings`, { details: { id: part } }));
|
|
36
|
+
}
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { Loop } from "./loop.js";
|
|
2
|
+
export type { LoopOptions, LoopRunnable, LoopVerify, LoopVerifyFn, LoopDecideFn, LoopVerifyArgs, LoopDecideArgs, LoopDecision, } from "./loop.js";
|
|
3
|
+
export { Chain } from "./chain.js";
|
|
4
|
+
export type { ChainOptions, ChainStep, ChainResults, ChainSlot, LastOutput, } from "./chain.js";
|
|
5
|
+
export { Switch } from "./switch.js";
|
|
6
|
+
export type { SwitchOptions, SwitchCases, SwitchOn, SwitchOutput, } from "./switch.js";
|
|
7
|
+
export { Parallel } from "./parallel.js";
|
|
8
|
+
export type { ParallelOptions, ParallelBranches, ParallelOutput } from "./parallel.js";
|
|
9
|
+
export { Map } from "./map.js";
|
|
10
|
+
export type { MapOptions, MapOver } from "./map.js";
|
|
11
|
+
export { isSlot } from "./slot.js";
|
|
12
|
+
export type { Slot, SlotInputArgs, ChildRef } from "./slot.js";
|
|
13
|
+
export { Verdict, VerdictSchema, isVerdict } from "./verdict.js";
|
|
14
|
+
export { withInstructions, withoutTools } from "./patch.js";
|
|
15
|
+
export { WorkflowBuildError, isValidPathPart } from "./diagnostics.js";
|
|
16
|
+
export { isBuiltWorkflow } from "./types.js";
|
|
17
|
+
export type { BuiltWorkflow, OutputOf, InputOf } from "./types.js";
|
|
18
|
+
export type { WorkflowRunnable } from "./runnable.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { Loop } from "./loop.js";
|
|
2
|
+
export { Chain } from "./chain.js";
|
|
3
|
+
export { Switch } from "./switch.js";
|
|
4
|
+
export { Parallel } from "./parallel.js";
|
|
5
|
+
export { Map } from "./map.js";
|
|
6
|
+
export { isSlot } from "./slot.js";
|
|
7
|
+
export { Verdict, VerdictSchema, isVerdict } from "./verdict.js";
|
|
8
|
+
export { withInstructions, withoutTools } from "./patch.js";
|
|
9
|
+
export { WorkflowBuildError, isValidPathPart } from "./diagnostics.js";
|
|
10
|
+
export { isBuiltWorkflow } from "./types.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AgentTool, BuiltAgent } from "../../types/agent.js";
|
|
2
|
+
import type { JsonValue } from "../../types/shared.js";
|
|
3
|
+
import type { Verdict } from "../../types/workflow.js";
|
|
4
|
+
import type { ToolSchemaSource } from "../../types/tool.js";
|
|
5
|
+
import { type WorkflowRunnable } from "./runnable.js";
|
|
6
|
+
import { type ChildRef, type Slot } from "./slot.js";
|
|
7
|
+
import type { BuiltWorkflow } from "./types.js";
|
|
8
|
+
/** Arguments passed to a Loop verify function. */
|
|
9
|
+
export type LoopVerifyArgs = {
|
|
10
|
+
readonly input: JsonValue;
|
|
11
|
+
readonly output: JsonValue;
|
|
12
|
+
readonly iteration: number;
|
|
13
|
+
};
|
|
14
|
+
/** Arguments passed to a Loop decide function. */
|
|
15
|
+
export type LoopDecideArgs = {
|
|
16
|
+
readonly agent?: import("../../types/manifest.js").AgentManifest;
|
|
17
|
+
readonly output: JsonValue;
|
|
18
|
+
readonly verdict: Verdict;
|
|
19
|
+
readonly iteration: number;
|
|
20
|
+
readonly input: JsonValue;
|
|
21
|
+
readonly history: readonly {
|
|
22
|
+
readonly iteration: number;
|
|
23
|
+
readonly output: JsonValue;
|
|
24
|
+
readonly verdict: Verdict;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
export type LoopDecision = {
|
|
28
|
+
readonly input: JsonValue;
|
|
29
|
+
readonly agent?: import("../../types/manifest.js").AgentManifest;
|
|
30
|
+
} | {
|
|
31
|
+
readonly output: JsonValue;
|
|
32
|
+
};
|
|
33
|
+
export type LoopVerifyFn = (args: LoopVerifyArgs, ctx?: unknown) => Verdict | Promise<Verdict>;
|
|
34
|
+
export type LoopDecideFn = (args: LoopDecideArgs) => LoopDecision;
|
|
35
|
+
/** @deprecated Prefer WorkflowRunnable — tracer alias. */
|
|
36
|
+
export type LoopRunnable = WorkflowRunnable;
|
|
37
|
+
export type LoopVerify = LoopVerifyFn | BuiltAgent | AgentTool | {
|
|
38
|
+
build(): BuiltAgent;
|
|
39
|
+
} | Slot<BuiltAgent | AgentTool | {
|
|
40
|
+
build(): BuiltAgent;
|
|
41
|
+
}>;
|
|
42
|
+
export interface LoopOptions<In = JsonValue, Out = JsonValue> {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly run: ChildRef;
|
|
45
|
+
readonly verify: LoopVerify;
|
|
46
|
+
readonly decide: LoopDecideFn;
|
|
47
|
+
readonly inputSchema?: ToolSchemaSource;
|
|
48
|
+
readonly outputSchema?: ToolSchemaSource;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build a Loop workflow: run → verify → decide, repeating until decide returns output.
|
|
52
|
+
* `run` accepts any runnable or slot; `verify` is a function or verifier agent (loops.md).
|
|
53
|
+
*/
|
|
54
|
+
export declare function Loop<In = JsonValue, Out = JsonValue>(options: LoopOptions<In, Out>): BuiltWorkflow<In, Out>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { normalizeSchema } from "../schema.js";
|
|
2
|
+
import { assertValidPathPart, diagnostic, fail, } from "./diagnostics.js";
|
|
3
|
+
import { emptyAccumulator, finishWorkflow, mergeChild } from "./build.js";
|
|
4
|
+
import { remapNodeKeys, resolveChild, } from "./runnable.js";
|
|
5
|
+
import { isSlot } from "./slot.js";
|
|
6
|
+
function isVerifyFn(value) {
|
|
7
|
+
return typeof value === "function";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Build-time check: a verifier agent's outputSchema must accept Verdict (loops.md §5).
|
|
11
|
+
*/
|
|
12
|
+
function assertVerifierAgent(agent) {
|
|
13
|
+
const schema = agent.getBinding().outputSchema;
|
|
14
|
+
if (!schema) {
|
|
15
|
+
fail([
|
|
16
|
+
diagnostic("loop.verify-schema", `Verifier agent '${agent.id}' must declare an outputSchema that extends Verdict`),
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
const normalized = normalizeSchema(schema, "output");
|
|
20
|
+
const pass = normalized.validate({ pass: true });
|
|
21
|
+
const failVerdict = normalized.validate({ pass: false, feedback: "x" });
|
|
22
|
+
if (!pass.ok || !failVerdict.ok) {
|
|
23
|
+
fail([
|
|
24
|
+
diagnostic("loop.verify-schema", `Verifier agent '${agent.id}' outputSchema must accept Verdict ({ pass: true } | { pass: false, feedback })`),
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build a Loop workflow: run → verify → decide, repeating until decide returns output.
|
|
30
|
+
* `run` accepts any runnable or slot; `verify` is a function or verifier agent (loops.md).
|
|
31
|
+
*/
|
|
32
|
+
export function Loop(options) {
|
|
33
|
+
const { id, verify, decide } = options;
|
|
34
|
+
if (!id)
|
|
35
|
+
fail([diagnostic("loop.missing-id", "Loop requires id")]);
|
|
36
|
+
assertValidPathPart(id, "Loop id");
|
|
37
|
+
if (!options.run)
|
|
38
|
+
fail([diagnostic("loop.missing-run", "Loop requires run")]);
|
|
39
|
+
if (!verify)
|
|
40
|
+
fail([diagnostic("loop.missing-verify", "Loop requires verify")]);
|
|
41
|
+
if (!decide || typeof decide !== "function")
|
|
42
|
+
fail([diagnostic("loop.missing-decide", "Loop requires decide")]);
|
|
43
|
+
const acc = emptyAccumulator();
|
|
44
|
+
const runResolved = resolveChild(options.run);
|
|
45
|
+
const runPath = `${id}/${runResolved.id}`;
|
|
46
|
+
mergeChild(acc, {
|
|
47
|
+
agents: runResolved.agents,
|
|
48
|
+
nodes: remapNodeKeys(runResolved.nodes, runResolved.id, runPath),
|
|
49
|
+
sandboxSpecs: runResolved.sandboxSpecs,
|
|
50
|
+
});
|
|
51
|
+
let verifyField;
|
|
52
|
+
if (isVerifyFn(verify)) {
|
|
53
|
+
verifyField = { fn: true };
|
|
54
|
+
acc.nodes[id] = { kind: "verify", fn: verify };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const verifyChild = isSlot(verify)
|
|
58
|
+
? resolveChild(verify)
|
|
59
|
+
: resolveChild(verify);
|
|
60
|
+
const agentEntry = Object.values(verifyChild.agents)[0];
|
|
61
|
+
if (!agentEntry) {
|
|
62
|
+
fail([
|
|
63
|
+
diagnostic("loop.invalid-verify", "Loop.verify must be a verify function or a verifier agent"),
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
assertVerifierAgent({
|
|
67
|
+
id: agentEntry.manifest.id,
|
|
68
|
+
getBinding: () => agentEntry,
|
|
69
|
+
});
|
|
70
|
+
// Verifier agent sessions are derived separately; local fn keys (slot input) sit under verify.
|
|
71
|
+
mergeChild(acc, {
|
|
72
|
+
agents: verifyChild.agents,
|
|
73
|
+
nodes: remapNodeKeys(verifyChild.nodes, verifyChild.id, `${id}/verify`),
|
|
74
|
+
sandboxSpecs: verifyChild.sandboxSpecs,
|
|
75
|
+
});
|
|
76
|
+
const node = verifyChild.node;
|
|
77
|
+
if (!("agent" in node) && !("slot" in node)) {
|
|
78
|
+
fail([
|
|
79
|
+
diagnostic("loop.invalid-verify", "Loop.verify must be a verify function or a verifier agent"),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
verifyField = node;
|
|
83
|
+
}
|
|
84
|
+
acc.nodes[`${id}/decide`] = {
|
|
85
|
+
kind: "fn",
|
|
86
|
+
fn: decide,
|
|
87
|
+
};
|
|
88
|
+
return finishWorkflow({
|
|
89
|
+
id,
|
|
90
|
+
root: {
|
|
91
|
+
loop: {
|
|
92
|
+
id,
|
|
93
|
+
run: runResolved.node,
|
|
94
|
+
verify: verifyField,
|
|
95
|
+
decide: { fn: true },
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
acc,
|
|
99
|
+
inputSchema: options.inputSchema,
|
|
100
|
+
outputSchema: options.outputSchema,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JsonValue } from "../../types/shared.js";
|
|
2
|
+
import type { ToolSchemaSource } from "../../types/tool.js";
|
|
3
|
+
import type { ChildRef } from "./slot.js";
|
|
4
|
+
import type { BuiltWorkflow, OutputOf } from "./types.js";
|
|
5
|
+
export type MapOver<In, Item> = (input: In) => readonly Item[];
|
|
6
|
+
export interface MapOptions<Each extends ChildRef = ChildRef, In = JsonValue, Item = JsonValue> {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly over: MapOver<In, Item>;
|
|
9
|
+
readonly each: Each;
|
|
10
|
+
readonly inputSchema?: ToolSchemaSource;
|
|
11
|
+
readonly outputSchema?: ToolSchemaSource;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Run `each` once per item from pure `over(input)` (map.md).
|
|
15
|
+
* Output is an array of each item's output, in item order. Empty list → [].
|
|
16
|
+
*/
|
|
17
|
+
export declare function Map<Each extends ChildRef, In = JsonValue, Item = JsonValue>(options: MapOptions<Each, In, Item>): BuiltWorkflow<In, OutputOf<Each>[]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { assertValidPathPart, diagnostic, fail, } from "./diagnostics.js";
|
|
2
|
+
import { emptyAccumulator, finishWorkflow, mergeChild } from "./build.js";
|
|
3
|
+
import { remapNodeKeys, resolveChild, runnableId } from "./runnable.js";
|
|
4
|
+
/**
|
|
5
|
+
* Run `each` once per item from pure `over(input)` (map.md).
|
|
6
|
+
* Output is an array of each item's output, in item order. Empty list → [].
|
|
7
|
+
*/
|
|
8
|
+
export function Map(options) {
|
|
9
|
+
const { id, over, each } = options;
|
|
10
|
+
if (!id)
|
|
11
|
+
fail([diagnostic("map.missing-id", "Map requires id")]);
|
|
12
|
+
assertValidPathPart(id, "Map id");
|
|
13
|
+
if (typeof over !== "function")
|
|
14
|
+
fail([diagnostic("map.missing-over", "Map requires over")]);
|
|
15
|
+
if (each === undefined || each === null)
|
|
16
|
+
fail([diagnostic("map.missing-each", "Map requires each")]);
|
|
17
|
+
const resolved = resolveChild(each);
|
|
18
|
+
assertValidPathPart(resolved.id, "Map each id");
|
|
19
|
+
const acc = emptyAccumulator();
|
|
20
|
+
// Node key drops Map indices: implement/code, not implement[i]/code.
|
|
21
|
+
const eachPath = `${id}/${resolved.id}`;
|
|
22
|
+
mergeChild(acc, {
|
|
23
|
+
agents: resolved.agents,
|
|
24
|
+
nodes: remapNodeKeys(resolved.nodes, resolved.id, eachPath),
|
|
25
|
+
sandboxSpecs: resolved.sandboxSpecs,
|
|
26
|
+
});
|
|
27
|
+
acc.nodes[`${id}/over`] = {
|
|
28
|
+
kind: "fn",
|
|
29
|
+
fn: over,
|
|
30
|
+
};
|
|
31
|
+
// Preserve each child's id for path construction (map.md §3.2).
|
|
32
|
+
void runnableId(each);
|
|
33
|
+
return finishWorkflow({
|
|
34
|
+
id,
|
|
35
|
+
root: {
|
|
36
|
+
map: {
|
|
37
|
+
id,
|
|
38
|
+
over: { fn: true },
|
|
39
|
+
each: resolved.node,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
acc,
|
|
43
|
+
inputSchema: options.inputSchema,
|
|
44
|
+
outputSchema: options.outputSchema,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JsonValue } from "../../types/shared.js";
|
|
2
|
+
import type { ToolSchemaSource } from "../../types/tool.js";
|
|
3
|
+
import type { ChildRef } from "./slot.js";
|
|
4
|
+
import type { BuiltWorkflow, OutputOf } from "./types.js";
|
|
5
|
+
export type ParallelBranches = Readonly<Record<string, ChildRef>>;
|
|
6
|
+
export type ParallelOutput<Branches extends ParallelBranches> = {
|
|
7
|
+
readonly [K in keyof Branches]: OutputOf<Branches[K]>;
|
|
8
|
+
};
|
|
9
|
+
export interface ParallelOptions<Branches extends ParallelBranches = ParallelBranches, In = JsonValue> {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly branches: Branches;
|
|
12
|
+
readonly inputSchema?: ToolSchemaSource;
|
|
13
|
+
readonly outputSchema?: ToolSchemaSource;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Run a fixed set of named branches concurrently on the same input (parallel.md).
|
|
17
|
+
* Output is an object keyed by branch name in declaration order.
|
|
18
|
+
*/
|
|
19
|
+
export declare function Parallel<const Branches extends ParallelBranches, In = JsonValue>(options: ParallelOptions<Branches, In>): BuiltWorkflow<In, ParallelOutput<Branches>>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { assertValidPathPart, diagnostic, fail, } from "./diagnostics.js";
|
|
2
|
+
import { emptyAccumulator, finishWorkflow, mergeChild } from "./build.js";
|
|
3
|
+
import { remapNodeKeys, resolveChild } from "./runnable.js";
|
|
4
|
+
/**
|
|
5
|
+
* Run a fixed set of named branches concurrently on the same input (parallel.md).
|
|
6
|
+
* Output is an object keyed by branch name in declaration order.
|
|
7
|
+
*/
|
|
8
|
+
export function Parallel(options) {
|
|
9
|
+
const { id, branches } = options;
|
|
10
|
+
if (!id)
|
|
11
|
+
fail([diagnostic("parallel.missing-id", "Parallel requires id")]);
|
|
12
|
+
assertValidPathPart(id, "Parallel id");
|
|
13
|
+
if (!branches || Object.keys(branches).length === 0)
|
|
14
|
+
fail([
|
|
15
|
+
diagnostic("parallel.empty-branches", "Parallel branches must have at least one entry"),
|
|
16
|
+
]);
|
|
17
|
+
const acc = emptyAccumulator();
|
|
18
|
+
const branchNodes = {};
|
|
19
|
+
for (const name of Object.keys(branches)) {
|
|
20
|
+
assertValidPathPart(name, "Parallel branch name");
|
|
21
|
+
const resolved = resolveChild(branches[name]);
|
|
22
|
+
const branchPath = `${id}/${name}`;
|
|
23
|
+
mergeChild(acc, {
|
|
24
|
+
agents: resolved.agents,
|
|
25
|
+
nodes: remapNodeKeys(resolved.nodes, resolved.id, branchPath),
|
|
26
|
+
sandboxSpecs: resolved.sandboxSpecs,
|
|
27
|
+
});
|
|
28
|
+
branchNodes[name] = resolved.node;
|
|
29
|
+
}
|
|
30
|
+
return finishWorkflow({
|
|
31
|
+
id,
|
|
32
|
+
root: { parallel: { id, branches: branchNodes } },
|
|
33
|
+
acc,
|
|
34
|
+
inputSchema: options.inputSchema,
|
|
35
|
+
outputSchema: options.outputSchema,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AgentManifest } from "../../types/manifest.js";
|
|
2
|
+
/**
|
|
3
|
+
* Append instruction text to the agent's primary capability (loops.md §3.3).
|
|
4
|
+
* Pure: returns a new manifest; never mutates.
|
|
5
|
+
*/
|
|
6
|
+
export declare function withInstructions(manifest: AgentManifest, text: string): AgentManifest;
|
|
7
|
+
/**
|
|
8
|
+
* Remove named tools from every capability (loops.md §3.3). Pure.
|
|
9
|
+
* Tools may be removed, not added — matches Loop variant rules.
|
|
10
|
+
*/
|
|
11
|
+
export declare function withoutTools(manifest: AgentManifest, names: readonly string[]): AgentManifest;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { deepFreeze } from "../../utils/immutable.js";
|
|
2
|
+
function primaryCapabilityIndex(manifest) {
|
|
3
|
+
const agentIdx = manifest.capabilities.findIndex((c) => c.id === "agent");
|
|
4
|
+
return agentIdx >= 0 ? agentIdx : 0;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Append instruction text to the agent's primary capability (loops.md §3.3).
|
|
8
|
+
* Pure: returns a new manifest; never mutates.
|
|
9
|
+
*/
|
|
10
|
+
export function withInstructions(manifest, text) {
|
|
11
|
+
if (typeof text !== "string" || text.length === 0)
|
|
12
|
+
throw new TypeError("withInstructions requires a non-empty string");
|
|
13
|
+
if (manifest.capabilities.length === 0)
|
|
14
|
+
throw new TypeError("withInstructions requires a manifest with at least one capability");
|
|
15
|
+
const index = primaryCapabilityIndex(manifest);
|
|
16
|
+
const capabilities = manifest.capabilities.map((cap, i) => {
|
|
17
|
+
if (i !== index)
|
|
18
|
+
return cap;
|
|
19
|
+
return {
|
|
20
|
+
...cap,
|
|
21
|
+
instructions: Object.freeze([...(cap.instructions ?? []), text]),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
return deepFreeze({ ...manifest, capabilities });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Remove named tools from every capability (loops.md §3.3). Pure.
|
|
28
|
+
* Tools may be removed, not added — matches Loop variant rules.
|
|
29
|
+
*/
|
|
30
|
+
export function withoutTools(manifest, names) {
|
|
31
|
+
const remove = new Set(names);
|
|
32
|
+
const capabilities = manifest.capabilities.map((cap) => {
|
|
33
|
+
if (!cap.tools?.length)
|
|
34
|
+
return cap;
|
|
35
|
+
const tools = cap.tools.filter((tool) => !remove.has(tool.name));
|
|
36
|
+
if (tools.length === cap.tools.length)
|
|
37
|
+
return cap;
|
|
38
|
+
if (tools.length === 0) {
|
|
39
|
+
const { tools: _dropped, ...rest } = cap;
|
|
40
|
+
return rest;
|
|
41
|
+
}
|
|
42
|
+
return { ...cap, tools: Object.freeze(tools) };
|
|
43
|
+
});
|
|
44
|
+
return deepFreeze({ ...manifest, capabilities });
|
|
45
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AgentTool, BuiltAgent } from "../../types/agent.js";
|
|
2
|
+
import type { JsonObject } from "../../types/shared.js";
|
|
3
|
+
import type { ToolDefinition } from "../../types/tool.js";
|
|
4
|
+
import type { WorkflowNode } from "../../types/workflow.js";
|
|
5
|
+
import type { AgentBinding } from "../binding.js";
|
|
6
|
+
import type { BoundToolDefinition } from "../bound.js";
|
|
7
|
+
import { type BuiltWorkflow } from "./types.js";
|
|
8
|
+
import { type ChildRef } from "./slot.js";
|
|
9
|
+
/** Anything a primitive accepts as a child (or a slot wrapping one). */
|
|
10
|
+
export type WorkflowRunnable = BuiltAgent | AgentTool | {
|
|
11
|
+
build(): BuiltAgent;
|
|
12
|
+
} | ToolDefinition<any, any, any> | BuiltWorkflow;
|
|
13
|
+
export type ResolvedChild = {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly node: WorkflowNode;
|
|
16
|
+
readonly agents: Record<string, AgentBinding>;
|
|
17
|
+
/** Nested workflow implementations, keyed relative to the child root id. */
|
|
18
|
+
readonly nodes: Record<string, import("../../types/workflow.js").WorkflowNodeImplementation>;
|
|
19
|
+
readonly tool?: BoundToolDefinition;
|
|
20
|
+
readonly sandboxSpecs: readonly JsonObject[];
|
|
21
|
+
readonly isReshapingSlot: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** Collect sandbox specs declared on an agent (and its delegates, one level). */
|
|
24
|
+
export declare function sandboxSpecsOf(agent: BuiltAgent | AgentTool): JsonObject[];
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a runnable or slot into a manifest node plus local bindings.
|
|
27
|
+
* When the slot has `input`, the node is wrapped as `{ slot: { id?, input, run } }`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveChild(child: ChildRef, defaultRename?: string): ResolvedChild;
|
|
30
|
+
/**
|
|
31
|
+
* Rewrite node keys that are rooted at `fromRoot` so they sit at `toPath`.
|
|
32
|
+
* Used when nesting a child under a parent path (workflows.md §6).
|
|
33
|
+
*
|
|
34
|
+
* Example: Loop nodes `{ code, code/decide }` nested at `ship/code` become
|
|
35
|
+
* `{ ship/code, ship/code/decide }`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function remapNodeKeys(nodes: Record<string, import("../../types/workflow.js").WorkflowNodeImplementation>, fromRoot: string, toPath: string): Record<string, import("../../types/workflow.js").WorkflowNodeImplementation>;
|
|
38
|
+
/** @deprecated Prefer remapNodeKeys — kept for call-site clarity during migration. */
|
|
39
|
+
export declare function prefixNodeKeys(nodes: Record<string, import("../../types/workflow.js").WorkflowNodeImplementation>, parentPath: string): Record<string, import("../../types/workflow.js").WorkflowNodeImplementation>;
|
|
40
|
+
export declare function runnableId(child: ChildRef): string;
|