@nylorun/core 0.13.0-beta → 0.16.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/dist/compatibility.d.ts +68 -25
  3. package/dist/compatibility.js +67 -27
  4. package/dist/contracts.d.ts +325 -959
  5. package/dist/contracts.js +281 -516
  6. package/dist/define.d.ts +13 -10
  7. package/dist/define.js +7 -4
  8. package/dist/definition/assemble.d.ts +0 -3
  9. package/dist/definition/assemble.js +13 -19
  10. package/dist/definition/bind-agent.js +0 -2
  11. package/dist/definition/bind-tool.js +0 -1
  12. package/dist/definition/bound.d.ts +3 -10
  13. package/dist/definition/builder.d.ts +19 -55
  14. package/dist/definition/builder.js +19 -130
  15. package/dist/definition/capability.d.ts +3 -15
  16. package/dist/definition/capability.js +3 -25
  17. package/dist/definition/code-tools.d.ts +22 -0
  18. package/dist/definition/code-tools.js +46 -0
  19. package/dist/definition/declaration.d.ts +0 -3
  20. package/dist/definition/declaration.js +8 -11
  21. package/dist/definition/delegate.d.ts +7 -7
  22. package/dist/definition/flow/compile.d.ts +4 -5
  23. package/dist/definition/flow/compile.js +120 -72
  24. package/dist/definition/flow/from.d.ts +2 -2
  25. package/dist/definition/flow/from.js +14 -33
  26. package/dist/definition/flow/index.d.ts +2 -2
  27. package/dist/definition/flow/index.js +2 -2
  28. package/dist/definition/flow/paths.d.ts +32 -17
  29. package/dist/definition/flow/paths.js +35 -14
  30. package/dist/definition/flow/spec.d.ts +6 -9
  31. package/dist/definition/flow/spec.js +49 -31
  32. package/dist/definition/flow/types.d.ts +40 -116
  33. package/dist/definition/from.js +36 -41
  34. package/dist/definition/helpers.d.ts +1 -1
  35. package/dist/definition/helpers.js +1 -1
  36. package/dist/definition/http-tool.d.ts +66 -0
  37. package/dist/definition/http-tool.js +131 -0
  38. package/dist/definition/implementations.d.ts +0 -3
  39. package/dist/definition/manifest.js +5 -4
  40. package/dist/definition/mcp.d.ts +4 -2
  41. package/dist/definition/mcp.js +14 -18
  42. package/dist/definition/removed.d.ts +10 -0
  43. package/dist/definition/removed.js +26 -0
  44. package/dist/definition/sandbox-capability.d.ts +2 -0
  45. package/dist/definition/sandbox-capability.js +11 -1
  46. package/dist/definition/schema.js +0 -3
  47. package/dist/definition/skill-tools.d.ts +16 -2
  48. package/dist/definition/skill-tools.js +38 -31
  49. package/dist/definition/variant.d.ts +1 -1
  50. package/dist/definition/variant.js +3 -14
  51. package/dist/definition/workflow/diagnostics.d.ts +1 -7
  52. package/dist/definition/workflow/diagnostics.js +1 -24
  53. package/dist/definition/workflow/index.d.ts +3 -17
  54. package/dist/definition/workflow/index.js +2 -9
  55. package/dist/definition/workflow/runnable.d.ts +2 -34
  56. package/dist/definition/workflow/runnable.js +8 -142
  57. package/dist/definition/workflow/types.d.ts +1 -10
  58. package/dist/harness-api/messages.d.ts +24 -27
  59. package/dist/harness-api/messages.js +1 -1
  60. package/dist/harness-api/schema.d.ts +0 -16
  61. package/dist/harness-api/schema.js +5 -12
  62. package/dist/index.d.ts +1 -1
  63. package/dist/types/manifest.d.ts +41 -14
  64. package/dist/types/middleware.d.ts +11 -16
  65. package/dist/types/observe.d.ts +0 -6
  66. package/dist/types/tool.d.ts +0 -6
  67. package/dist/types/workflow.d.ts +54 -110
  68. package/dist/utils/definition-files.d.ts +31 -0
  69. package/dist/utils/definition-files.js +84 -0
  70. package/package.json +1 -1
  71. package/dist/definition/hooks.d.ts +0 -19
  72. package/dist/definition/hooks.js +0 -67
  73. package/dist/definition/workflow/build.d.ts +0 -28
  74. package/dist/definition/workflow/build.js +0 -40
  75. package/dist/definition/workflow/chain.d.ts +0 -49
  76. package/dist/definition/workflow/chain.js +0 -40
  77. package/dist/definition/workflow/loop.d.ts +0 -54
  78. package/dist/definition/workflow/loop.js +0 -100
  79. package/dist/definition/workflow/map.d.ts +0 -17
  80. package/dist/definition/workflow/map.js +0 -45
  81. package/dist/definition/workflow/parallel.d.ts +0 -19
  82. package/dist/definition/workflow/parallel.js +0 -36
  83. package/dist/definition/workflow/patch.d.ts +0 -11
  84. package/dist/definition/workflow/patch.js +0 -45
  85. package/dist/definition/workflow/slot.d.ts +0 -23
  86. package/dist/definition/workflow/slot.js +0 -16
  87. package/dist/definition/workflow/switch.d.ts +0 -26
  88. package/dist/definition/workflow/switch.js +0 -64
  89. package/dist/types/dynamics.d.ts +0 -101
  90. package/dist/types/dynamics.js +0 -1
@@ -1,7 +1,7 @@
1
1
  import type { AgentBinding } from "../definition/binding.js";
2
2
  import type { BoundToolDefinition } from "../definition/bound.js";
3
3
  import type { JsonObject, JsonValue } from "./shared.js";
4
- import type { AgentManifest, SandboxManifest } from "./manifest.js";
4
+ import type { AgentManifest, HttpToolTarget, SandboxManifest } from "./manifest.js";
5
5
  /** Loop verify outcome: pass, or fail with required feedback. */
6
6
  export type Verdict = {
7
7
  readonly pass: true;
@@ -11,130 +11,85 @@ export type Verdict = {
11
11
  readonly feedback: string;
12
12
  readonly data?: JsonValue;
13
13
  };
14
- /** Local function marker in a workflow manifest (code never crosses the wire). */
15
- export interface WorkflowFnRef {
16
- readonly fn: true;
14
+ /**
15
+ * Workflow manifest v3 (flow agents). A flow is data: no node names developer code. Each
16
+ * stage gets the previous stage's output, and the first stage gets the flow's input.
17
+ *
18
+ * Every node may carry `id`. For an agent or tool it replaces the leaf's path part; for a
19
+ * control node it is the stage key.
20
+ */
21
+ export interface WorkflowNodeOptions {
22
+ readonly id?: string;
17
23
  }
18
- /** Agent leaf: referenced by definition id. */
19
- export interface WorkflowAgentNode {
24
+ /** Agent leaf, or a nested flow agent: a key of the enclosing manifest's `agents`. */
25
+ export interface WorkflowAgentNode extends WorkflowNodeOptions {
20
26
  readonly agent: string;
21
27
  }
22
- /** Tool leaf: name and schemas only; implementation stays in the binding. */
23
- export interface WorkflowToolNode {
28
+ /**
29
+ * Tool leaf: name and schemas. With `http` it is an HTTP stage, one request the Runtime makes
30
+ * through its Tool Gate as for an agent's HTTP tool. Without, it runs your code: the Runtime
31
+ * refuses it at save, and only the local engine (`@nylorun/harness/run`) runs its `run`.
32
+ */
33
+ export interface WorkflowToolNode extends WorkflowNodeOptions {
24
34
  readonly tool: {
25
35
  readonly name: string;
26
36
  readonly description?: string;
27
37
  readonly inputSchema?: JsonObject;
28
38
  readonly outputSchema?: JsonObject;
39
+ readonly http?: HttpToolTarget;
29
40
  };
30
41
  }
31
- export interface WorkflowChainNode {
32
- readonly chain: {
33
- readonly id: string;
34
- readonly steps: readonly WorkflowNode[];
35
- };
42
+ export interface WorkflowChainNode extends WorkflowNodeOptions {
43
+ readonly chain: readonly WorkflowNode[];
36
44
  }
37
- export interface WorkflowSwitchNode {
45
+ /**
46
+ * Picks a case from the previous output: a string is the case name, and so is an object's
47
+ * `route` field. The chosen case gets the whole output; `default` catches the rest.
48
+ */
49
+ export interface WorkflowSwitchNode extends WorkflowNodeOptions {
38
50
  readonly switch: {
39
- readonly id: string;
40
- readonly on: WorkflowFnRef;
41
51
  readonly cases: Readonly<Record<string, WorkflowNode>>;
42
52
  readonly default?: WorkflowNode;
43
53
  };
44
54
  }
45
- export interface WorkflowParallelNode {
46
- readonly parallel: {
47
- readonly id: string;
48
- readonly branches: Readonly<Record<string, WorkflowNode>>;
49
- };
55
+ /** Every branch gets the same input; the output is keyed by branch. */
56
+ export interface WorkflowParallelNode extends WorkflowNodeOptions {
57
+ readonly parallel: Readonly<Record<string, WorkflowNode>>;
50
58
  }
51
- export interface WorkflowMapNode {
59
+ /** Runs `each` once per item of its input: an array, or an object's `items` array. */
60
+ export interface WorkflowMapNode extends WorkflowNodeOptions {
52
61
  readonly map: {
53
- readonly id: string;
54
- readonly over: WorkflowFnRef;
55
62
  readonly each: WorkflowNode;
56
63
  };
57
64
  }
58
- export interface WorkflowLoopNode {
59
- readonly loop: {
60
- readonly id: string;
61
- readonly run: WorkflowNode;
62
- readonly verify: WorkflowFnRef | WorkflowAgentNode | WorkflowSlotNode;
63
- readonly decide: WorkflowFnRef;
64
- };
65
- }
66
- /** Rename and/or reshape a child: `{ slot: { id?, input?, run } }`. */
67
- export interface WorkflowSlotNode {
68
- readonly slot: {
69
- readonly id?: string;
70
- readonly input?: WorkflowFnRef;
71
- readonly run: WorkflowNode;
72
- };
73
- }
74
- export type WorkflowNode = WorkflowAgentNode | WorkflowToolNode | WorkflowChainNode | WorkflowSwitchNode | WorkflowParallelNode | WorkflowMapNode | WorkflowLoopNode | WorkflowSlotNode;
75
- /** Workflow manifest v1: control nodes carry ids, and agents are resolved from the registry. */
76
- export interface WorkflowManifestV1 {
77
- readonly kind: "workflow";
78
- readonly workflowSchemaVersion: 1;
79
- readonly id: string;
80
- readonly root: WorkflowNode;
81
- readonly sandbox?: SandboxManifest;
82
- }
83
65
  /**
84
- * Fields every v2 node may carry. `id` names the stage: for an agent or tool it
85
- * replaces the leaf's path part, for a control node it is the stage key and the
86
- * `results` key. `input` marks a function that reshapes what the node receives.
66
+ * An HTTP verifier: the Runtime POSTs `{ input, output, iteration }` to it through its Tool Gate
67
+ * and reads a verdict from the answer. Its stage key is its position (`@0.verify`).
87
68
  */
88
- export interface WorkflowNodeOptionsV2 {
89
- readonly id?: string;
90
- readonly input?: WorkflowFnRef;
91
- }
92
- /** Agent leaf, or a nested flow agent: a key of the enclosing manifest's `agents`. */
93
- export interface WorkflowAgentNodeV2 extends WorkflowNodeOptionsV2 {
94
- readonly agent: string;
95
- }
96
- export interface WorkflowToolNodeV2 extends WorkflowNodeOptionsV2 {
97
- readonly tool: WorkflowToolNode["tool"];
98
- }
99
- export interface WorkflowChainNodeV2 extends WorkflowNodeOptionsV2 {
100
- readonly chain: readonly WorkflowNodeV2[];
101
- }
102
- export interface WorkflowSwitchNodeV2 extends WorkflowNodeOptionsV2 {
103
- readonly switch: {
104
- readonly on: WorkflowFnRef;
105
- readonly cases: Readonly<Record<string, WorkflowNodeV2>>;
106
- readonly default?: WorkflowNodeV2;
107
- };
108
- }
109
- export interface WorkflowParallelNodeV2 extends WorkflowNodeOptionsV2 {
110
- readonly parallel: Readonly<Record<string, WorkflowNodeV2>>;
111
- }
112
- /** Runs `each` once per item of its input, which must be an array. */
113
- export interface WorkflowMapNodeV2 extends WorkflowNodeOptionsV2 {
114
- readonly map: {
115
- readonly each: WorkflowNodeV2;
116
- };
69
+ export interface WorkflowHttpVerify {
70
+ readonly http: HttpToolTarget;
117
71
  }
72
+ /** What judges a Loop attempt: a verifier agent, or an HTTP verifier. */
73
+ export type WorkflowLoopVerify = WorkflowAgentNode | WorkflowHttpVerify;
118
74
  /**
119
- * Runs `run`, judges it with `verify`, then retries or stops. Without `decide`, a pass
120
- * returns the output and a fail retries with the feedback, up to `max` attempts.
75
+ * Runs `run`, judges it with `verify`, then stops on a pass or retries with the verdict's
76
+ * feedback, up to `max` attempts.
121
77
  */
122
- export interface WorkflowLoopNodeV2 extends WorkflowNodeOptionsV2 {
78
+ export interface WorkflowLoopNode extends WorkflowNodeOptions {
123
79
  readonly loop: {
124
- readonly run: WorkflowNodeV2;
125
- readonly verify: WorkflowFnRef | WorkflowAgentNodeV2;
126
- readonly max?: number;
127
- readonly decide?: WorkflowFnRef;
80
+ readonly run: WorkflowNode;
81
+ readonly verify: WorkflowLoopVerify;
82
+ readonly max: number;
128
83
  };
129
84
  }
130
- export type WorkflowNodeV2 = WorkflowAgentNodeV2 | WorkflowToolNodeV2 | WorkflowChainNodeV2 | WorkflowSwitchNodeV2 | WorkflowParallelNodeV2 | WorkflowMapNodeV2 | WorkflowLoopNodeV2;
85
+ export type WorkflowNode = WorkflowAgentNode | WorkflowToolNode | WorkflowChainNode | WorkflowSwitchNode | WorkflowParallelNode | WorkflowMapNode | WorkflowLoopNode;
131
86
  /**
132
- * Workflow manifest v2: a flow agent. Its leaf agents are embedded in `agents`, so one
87
+ * Workflow manifest v3: a flow agent. Its leaf agents are embedded in `agents`, so one
133
88
  * manifest hash covers the whole agent, and session paths come from the leaves.
134
89
  */
135
- export interface WorkflowManifestV2 {
90
+ export interface WorkflowManifest {
136
91
  readonly kind: "workflow";
137
- readonly workflowSchemaVersion: 2;
92
+ readonly workflowSchemaVersion: 3;
138
93
  readonly id: string;
139
94
  readonly name?: string;
140
95
  readonly description?: string;
@@ -143,33 +98,22 @@ export interface WorkflowManifestV2 {
143
98
  readonly outputSchema?: JsonObject;
144
99
  /** The sandbox every leaf that declares one shares. */
145
100
  readonly sandbox?: SandboxManifest;
146
- readonly root: WorkflowNodeV2;
147
- /** Every agent the flow runs, by id: ReAct agents (v4) and nested flow agents (v2). */
148
- readonly agents: Readonly<Record<string, AgentManifest | WorkflowManifestV2>>;
101
+ readonly root: WorkflowNode;
102
+ /** Every agent the flow runs, by id: ReAct agents (v5) and nested flow agents (v3). */
103
+ readonly agents: Readonly<Record<string, AgentManifest | WorkflowManifest>>;
149
104
  }
150
- /** Wire document for a workflow definition. Missing `kind` is never a workflow. */
151
- export type WorkflowManifest = WorkflowManifestV1 | WorkflowManifestV2;
152
- /**
153
- * Local implementation for a node key: a tool node, a pure `fn`, or a Loop `verify` function.
154
- * Functions are never serialized.
155
- */
105
+ /** Local implementation for a tool node key. Never serialized. */
156
106
  export type WorkflowNodeImplementation = {
157
107
  readonly kind: "tool";
158
108
  readonly tool: BoundToolDefinition;
159
- } | {
160
- readonly kind: "fn";
161
- readonly fn: (...args: never[]) => unknown;
162
- } | {
163
- readonly kind: "verify";
164
- readonly fn: (...args: never[]) => unknown;
165
109
  };
166
110
  /**
167
- * Built-workflow binding: manifest plus node-key → implementation, and referenced agent bindings.
168
- * Not a wire format; `toJSON()` stays manifest-only.
111
+ * Built-workflow binding: manifest plus tool node key → implementation, and embedded agent
112
+ * bindings. Not a wire format; `toJSON()` stays manifest-only.
169
113
  */
170
114
  export interface WorkflowBinding {
171
115
  readonly manifest: WorkflowManifest;
172
- /** Node key (path without Map indices) → local code. */
116
+ /** Tool node key (path without Map indices) → local code. */
173
117
  readonly nodes: Readonly<Record<string, WorkflowNodeImplementation>>;
174
118
  readonly agents: Readonly<Record<string, AgentBinding>>;
175
119
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Definition files (track R2 M4): the files a definition names by content hash, uploaded once
3
+ * with `PUT /v1/files/sha256:<hex>` and held by the Runtime. Today they are the files of a
4
+ * skill's folder (`SkillManifest.files`). Shared by the SDK, the wire schema and the Runtime.
5
+ */
6
+ /** The largest definition file the Runtime stores. */
7
+ export declare const DEFINITION_FILE_MAX_BYTES: number;
8
+ /** The most files one skill may have. */
9
+ export declare const SKILL_FILES_MAX = 500;
10
+ /** The longest path of a file in a skill's folder. */
11
+ export declare const SKILL_FILE_PATH_MAX = 512;
12
+ /** The file every skill has: its frontmatter and instructions. */
13
+ export declare const SKILL_ENTRY = "SKILL.md";
14
+ /** Where a session's sandbox holds each skill's files, read-only: `/skills/<name>/`. */
15
+ export declare const SKILLS_MOUNT = "/skills";
16
+ /** `sha256:<hex>`, the way a manifest names a definition file. */
17
+ export declare function isDefinitionFileHash(value: unknown): value is string;
18
+ /** Why `path` cannot name a file in a skill's folder, or undefined when it can. */
19
+ export declare function skillFilePathIssue(path: string): string | undefined;
20
+ /** Why `files` is not a skill's file map, or undefined when it is. */
21
+ export declare function skillFilesIssue(files: unknown): string | undefined;
22
+ /**
23
+ * Every definition file a definition document names: its agents' skill files, those of the
24
+ * agents it uses as tools, and those of a flow's agents, as `sha256:<hex>`.
25
+ */
26
+ export declare function definitionFilesOf(document: unknown, into?: Set<string>): Set<string>;
27
+ /**
28
+ * A `SKILL.md`'s instructions: the text after its YAML frontmatter (`---` lines), without the
29
+ * blank line that follows it. Text without frontmatter is returned whole.
30
+ */
31
+ export declare function skillInstructions(text: string): string;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Definition files (track R2 M4): the files a definition names by content hash, uploaded once
3
+ * with `PUT /v1/files/sha256:<hex>` and held by the Runtime. Today they are the files of a
4
+ * skill's folder (`SkillManifest.files`). Shared by the SDK, the wire schema and the Runtime.
5
+ */
6
+ /** The largest definition file the Runtime stores. */
7
+ export const DEFINITION_FILE_MAX_BYTES = 10 * 1024 * 1024;
8
+ /** The most files one skill may have. */
9
+ export const SKILL_FILES_MAX = 500;
10
+ /** The longest path of a file in a skill's folder. */
11
+ export const SKILL_FILE_PATH_MAX = 512;
12
+ /** The file every skill has: its frontmatter and instructions. */
13
+ export const SKILL_ENTRY = "SKILL.md";
14
+ /** Where a session's sandbox holds each skill's files, read-only: `/skills/<name>/`. */
15
+ export const SKILLS_MOUNT = "/skills";
16
+ const FILE_HASH = /^sha256:[0-9a-f]{64}$/;
17
+ /** `sha256:<hex>`, the way a manifest names a definition file. */
18
+ export function isDefinitionFileHash(value) {
19
+ return typeof value === "string" && FILE_HASH.test(value);
20
+ }
21
+ /** Why `path` cannot name a file in a skill's folder, or undefined when it can. */
22
+ export function skillFilePathIssue(path) {
23
+ if (path.length === 0 || path.length > SKILL_FILE_PATH_MAX)
24
+ return `must be 1 to ${SKILL_FILE_PATH_MAX} characters`;
25
+ if (path.includes("\\"))
26
+ return "must use / as its separator, not \\";
27
+ if (path.startsWith("/"))
28
+ return "must be relative to the skill's folder";
29
+ if (/[\u0000-\u001f]/.test(path))
30
+ return "must not contain control characters";
31
+ for (const segment of path.split("/"))
32
+ if (segment === "" || segment === "." || segment === "..")
33
+ return "must not have empty, . or .. segments";
34
+ return undefined;
35
+ }
36
+ /** Why `files` is not a skill's file map, or undefined when it is. */
37
+ export function skillFilesIssue(files) {
38
+ if (!files || typeof files !== "object" || Array.isArray(files))
39
+ return `files must map each path in the skill's folder to sha256:<hex>`;
40
+ const entries = Object.entries(files);
41
+ if (entries.length > SKILL_FILES_MAX)
42
+ return `has ${entries.length} files; a skill may have at most ${SKILL_FILES_MAX}`;
43
+ if (!(SKILL_ENTRY in files))
44
+ return `files must include ${SKILL_ENTRY}`;
45
+ for (const [path, hash] of entries) {
46
+ const issue = skillFilePathIssue(path);
47
+ if (issue)
48
+ return `file path ${JSON.stringify(path.slice(0, 80))} ${issue}`;
49
+ if (!isDefinitionFileHash(hash))
50
+ return `file ${JSON.stringify(path)} must name its content as sha256:<64 lowercase hex>`;
51
+ }
52
+ return undefined;
53
+ }
54
+ /**
55
+ * Every definition file a definition document names: its agents' skill files, those of the
56
+ * agents it uses as tools, and those of a flow's agents, as `sha256:<hex>`.
57
+ */
58
+ export function definitionFilesOf(document, into = new Set()) {
59
+ if (!document || typeof document !== "object")
60
+ return into;
61
+ const value = document;
62
+ if (value.kind === "workflow") {
63
+ for (const agent of Object.values(value.agents ?? {}))
64
+ definitionFilesOf(agent, into);
65
+ return into;
66
+ }
67
+ for (const capability of value.capabilities ?? []) {
68
+ for (const skill of Object.values(capability.skills ?? {}))
69
+ for (const hash of Object.values(skill?.files ?? {}))
70
+ if (isDefinitionFileHash(hash))
71
+ into.add(hash);
72
+ for (const tool of capability.tools ?? [])
73
+ definitionFilesOf(tool.agent, into);
74
+ }
75
+ return into;
76
+ }
77
+ /**
78
+ * A `SKILL.md`'s instructions: the text after its YAML frontmatter (`---` lines), without the
79
+ * blank line that follows it. Text without frontmatter is returned whole.
80
+ */
81
+ export function skillInstructions(text) {
82
+ const match = /^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(text);
83
+ return match ? text.slice(match[0].length).replace(/^\r?\n/, "") : text;
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.13.0-beta",
3
+ "version": "0.16.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",
@@ -1,19 +0,0 @@
1
- import type { AfterHooks, BeforeHooks, HookAt, HookManifest, HookScope } from "../types/dynamics.js";
2
- import type { Implementations } from "./implementations.js";
3
- /** Every hook point, in the order the loop reaches them and the manifest lists them. */
4
- export declare const HOOK_POINTS: readonly HookManifest[];
5
- /** Canonical manifest list for a capability's hooks, or undefined when it has none. */
6
- export declare function hooksFrom(before: BeforeHooks<any> | undefined, after: AfterHooks<any> | undefined): readonly HookManifest[] | undefined;
7
- export declare function hasHook(hooks: readonly HookManifest[] | undefined, at: HookAt, scope: HookScope): boolean;
8
- /** Why a manifest `hooks` value is invalid, or undefined when it is valid. */
9
- export declare function hookListIssue(value: unknown): string | undefined;
10
- /**
11
- * Run one hook point for the listed capabilities, concurrently.
12
- * Never throws: a missing or failing hook blocks with its message, so a
13
- * re-delivered hook cannot fail the same way forever.
14
- */
15
- export declare function runHookPoint(implementations: Implementations<any>, hook: {
16
- readonly at: HookAt;
17
- readonly scope: HookScope;
18
- readonly capabilityIds: readonly string[];
19
- }, args: unknown): Promise<Readonly<Record<string, unknown>>>;
@@ -1,67 +0,0 @@
1
- /** Every hook point, in the order the loop reaches them and the manifest lists them. */
2
- export const HOOK_POINTS = Object.freeze([
3
- Object.freeze({ at: "before", scope: "turn" }),
4
- Object.freeze({ at: "before", scope: "step" }),
5
- Object.freeze({ at: "after", scope: "step" }),
6
- Object.freeze({ at: "after", scope: "turn" }),
7
- ]);
8
- const pointIndex = (point) => HOOK_POINTS.findIndex((item) => item.at === point.at && item.scope === point.scope);
9
- /** Canonical manifest list for a capability's hooks, or undefined when it has none. */
10
- export function hooksFrom(before, after) {
11
- const hooks = HOOK_POINTS.filter((point) => typeof (point.at === "before" ? before : after)?.[point.scope] ===
12
- "function");
13
- return hooks.length ? Object.freeze(hooks) : undefined;
14
- }
15
- export function hasHook(hooks, at, scope) {
16
- return hooks?.some((hook) => hook.at === at && hook.scope === scope) ?? false;
17
- }
18
- /** Why a manifest `hooks` value is invalid, or undefined when it is valid. */
19
- export function hookListIssue(value) {
20
- if (!Array.isArray(value))
21
- return "hooks must be an array";
22
- if (value.length === 0)
23
- return "hooks must be omitted when empty";
24
- let previous = -1;
25
- for (const item of value) {
26
- if (item === null ||
27
- typeof item !== "object" ||
28
- Object.keys(item).some((key) => key !== "at" && key !== "scope"))
29
- return "each hook must be { at, scope }";
30
- const index = pointIndex(item);
31
- if (index < 0)
32
- return `unknown hook point '${String(item.at)} ${String(item.scope)}'`;
33
- if (index === previous)
34
- return `duplicate hook '${item.at} ${item.scope}'`;
35
- if (index < previous)
36
- return "hooks must be listed as before turn, before step, after step, after turn";
37
- previous = index;
38
- }
39
- return undefined;
40
- }
41
- /**
42
- * Run one hook point for the listed capabilities, concurrently.
43
- * Never throws: a missing or failing hook blocks with its message, so a
44
- * re-delivered hook cannot fail the same way forever.
45
- */
46
- export async function runHookPoint(implementations, hook, args) {
47
- const entries = await Promise.all(hook.capabilityIds.map(async (id) => {
48
- const fn = implementations[id]?.[hook.at]?.[hook.scope];
49
- if (typeof fn !== "function")
50
- return [
51
- id,
52
- {
53
- block: `Missing ${hook.at}("${hook.scope}") implementation for capability '${id}'`,
54
- },
55
- ];
56
- try {
57
- return [id, (await fn(args)) ?? {}];
58
- }
59
- catch (error) {
60
- return [
61
- id,
62
- { block: error instanceof Error ? error.message : String(error) },
63
- ];
64
- }
65
- }));
66
- return Object.freeze(Object.fromEntries(entries));
67
- }
@@ -1,28 +0,0 @@
1
- import type { AgentBinding } from "../binding.js";
2
- import type { BuildDiagnostic, JsonValue } from "../../types/shared.js";
3
- import type { WorkflowNode, WorkflowNodeImplementation } from "../../types/workflow.js";
4
- import type { ToolSchemaSource } from "../../types/tool.js";
5
- import type { BuiltWorkflow } from "./types.js";
6
- export type BuildAccumulator = {
7
- readonly agents: Record<string, AgentBinding>;
8
- readonly nodes: Record<string, WorkflowNodeImplementation>;
9
- };
10
- export declare function emptyAccumulator(): BuildAccumulator;
11
- export declare function mergeChild(acc: BuildAccumulator, child: {
12
- readonly agents: Record<string, AgentBinding>;
13
- readonly nodes: Record<string, WorkflowNodeImplementation>;
14
- }): void;
15
- export type FinishOptions<In = JsonValue, Out = JsonValue> = {
16
- readonly id: string;
17
- readonly root: WorkflowNode;
18
- readonly acc: BuildAccumulator;
19
- readonly inputSchema?: ToolSchemaSource;
20
- readonly outputSchema?: ToolSchemaSource;
21
- /** Extra diagnostics collected by the primitive. */
22
- readonly diagnostics?: readonly BuildDiagnostic[];
23
- };
24
- /**
25
- * Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON. A workflow
26
- * declares no sandbox: the session it runs in is opened with one (Sandboxes v3).
27
- */
28
- export declare function finishWorkflow<In = JsonValue, Out = JsonValue>(options: FinishOptions<In, Out>): BuiltWorkflow<In, Out>;
@@ -1,40 +0,0 @@
1
- import { diagnostic, fail } from "./diagnostics.js";
2
- export function emptyAccumulator() {
3
- return { agents: {}, nodes: {} };
4
- }
5
- export function mergeChild(acc, child) {
6
- Object.assign(acc.agents, child.agents);
7
- Object.assign(acc.nodes, child.nodes);
8
- }
9
- /**
10
- * Assemble a BuiltWorkflow: non-enumerable getBinding, manifest-only toJSON. A workflow
11
- * declares no sandbox: the session it runs in is opened with one (Sandboxes v3).
12
- */
13
- export function finishWorkflow(options) {
14
- const diagnostics = [...(options.diagnostics ?? [])];
15
- if (diagnostics.length)
16
- fail(diagnostics);
17
- const manifest = {
18
- kind: "workflow",
19
- workflowSchemaVersion: 1,
20
- id: options.id,
21
- root: options.root,
22
- };
23
- const binding = Object.freeze({
24
- manifest,
25
- nodes: Object.freeze({ ...options.acc.nodes }),
26
- agents: Object.freeze({ ...options.acc.agents }),
27
- });
28
- const built = {
29
- id: options.id,
30
- manifest,
31
- toJSON: () => manifest,
32
- ...(options.inputSchema === undefined ? {} : { inputSchema: options.inputSchema }),
33
- ...(options.outputSchema === undefined ? {} : { outputSchema: options.outputSchema }),
34
- };
35
- Object.defineProperty(built, "getBinding", {
36
- value: () => binding,
37
- enumerable: false,
38
- });
39
- return built;
40
- }
@@ -1,49 +0,0 @@
1
- import type { JsonValue } from "../../types/shared.js";
2
- import type { ToolSchemaSource } from "../../types/tool.js";
3
- import { type WorkflowRunnable } from "./runnable.js";
4
- import type { ChildRef, Slot, SlotInputArgs } from "./slot.js";
5
- import type { BuiltWorkflow, OutputOf } from "./types.js";
6
- export type ChainStep = ChildRef;
7
- type StepId<S> = S extends Slot<infer R, any, any, any> ? S extends {
8
- readonly id: infer I extends string;
9
- } ? I : RunnableId<R> : RunnableId<S>;
10
- type RunnableId<R> = R extends {
11
- readonly id: infer I extends string;
12
- } ? I : R extends {
13
- readonly name: infer N extends string;
14
- } ? N : string;
15
- type StepOutput<S> = S extends Slot<infer R, any, any, any> ? OutputOf<R> : OutputOf<S>;
16
- /** Results object available to step K (earlier step outputs only). */
17
- export type ResultsBefore<Steps extends readonly ChainStep[], K extends number> = {
18
- readonly [I in keyof Steps as I extends `${infer N extends number}` ? N extends K ? never : `${N}` extends `${infer M extends number}` ? M extends number ? M extends K ? never : Compare<M, K> extends true ? StepId<Steps[M] & ChainStep> : never : never : never : never]: StepOutput<Steps[I & keyof Steps] & ChainStep>;
19
- };
20
- /** `true` when A < B (both number literals). Simplified: use a recursive counter for small tuples. */
21
- type Compare<A extends number, B extends number> = A extends B ? false : LessThan<[...TupleOf<A>], [...TupleOf<B>]>;
22
- type TupleOf<N extends number, Acc extends unknown[] = []> = Acc["length"] extends N ? Acc : TupleOf<N, [...Acc, unknown]>;
23
- type LessThan<A extends unknown[], B extends unknown[]> = A["length"] extends B["length"] ? false : A extends [...B, ...unknown[]] ? false : B extends [...A, ...unknown[]] ? true : false;
24
- /** Typed results accumulating through a steps tuple. */
25
- export type ChainResults<Steps extends readonly ChainStep[]> = {
26
- readonly [I in keyof Steps as StepId<Steps[I & keyof Steps] & ChainStep>]: StepOutput<Steps[I & keyof Steps] & ChainStep>;
27
- };
28
- export type LastOutput<Steps extends readonly ChainStep[]> = Steps extends readonly [
29
- ...infer _Rest,
30
- infer Last
31
- ] ? StepOutput<Last & ChainStep> : JsonValue;
32
- export interface ChainOptions<Steps extends readonly [ChainStep, ...ChainStep[]] = readonly [ChainStep, ...ChainStep[]], In = JsonValue, Out = LastOutput<Steps>> {
33
- readonly id: string;
34
- readonly steps: Steps;
35
- readonly inputSchema?: ToolSchemaSource;
36
- readonly outputSchema?: ToolSchemaSource;
37
- }
38
- /**
39
- * Run steps in order. Each step's output is the next step's input unless a slot
40
- * reshapes it. `results` exposes earlier step outputs to later slots (chain.md).
41
- */
42
- export declare function Chain<const Steps extends readonly [ChainStep, ...ChainStep[]], In = JsonValue>(options: ChainOptions<Steps, In>): BuiltWorkflow<In, LastOutput<Steps>>;
43
- /** Helper type: a slot whose `input` may only read known earlier result keys. */
44
- export type ChainSlot<Run extends WorkflowRunnable, PrevResults extends Readonly<Record<string, JsonValue>>, Value = JsonValue, Input = JsonValue> = {
45
- readonly run: Run;
46
- readonly id?: string;
47
- readonly input?: (args: SlotInputArgs<Value, Input, PrevResults>) => JsonValue;
48
- };
49
- export {};
@@ -1,40 +0,0 @@
1
- import { assertValidPathPart, diagnostic, fail, siblingUniquenessDiagnostics, } from "./diagnostics.js";
2
- import { emptyAccumulator, finishWorkflow, mergeChild } from "./build.js";
3
- import { remapNodeKeys, resolveChild, runnableId, } from "./runnable.js";
4
- import { isSlot } from "./slot.js";
5
- /**
6
- * Run steps in order. Each step's output is the next step's input unless a slot
7
- * reshapes it. `results` exposes earlier step outputs to later slots (chain.md).
8
- */
9
- export function Chain(options) {
10
- const { id, steps } = options;
11
- if (!id)
12
- fail([diagnostic("chain.missing-id", "Chain requires id")]);
13
- assertValidPathPart(id, "Chain id");
14
- if (!steps || steps.length === 0)
15
- fail([diagnostic("chain.empty-steps", "Chain steps must be non-empty")]);
16
- const ids = steps.map((step) => runnableId(step));
17
- const dupes = siblingUniquenessDiagnostics(ids, "Chain step");
18
- if (dupes.length)
19
- fail(dupes);
20
- const acc = emptyAccumulator();
21
- const stepNodes = [];
22
- for (let i = 0; i < steps.length; i++) {
23
- const step = steps[i];
24
- const resolved = resolveChild(step);
25
- assertValidPathPart(resolved.id, "Chain step id");
26
- const stepPath = `${id}/${resolved.id}`;
27
- mergeChild(acc, {
28
- agents: resolved.agents,
29
- nodes: remapNodeKeys(resolved.nodes, resolved.id, stepPath),
30
- });
31
- stepNodes.push(resolved.node);
32
- }
33
- return finishWorkflow({
34
- id,
35
- root: { chain: { id, steps: stepNodes } },
36
- acc,
37
- inputSchema: options.inputSchema,
38
- outputSchema: options.outputSchema,
39
- });
40
- }
@@ -1,54 +0,0 @@
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>;