@nylorun/core 0.12.0-beta → 0.15.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 +159 -0
  2. package/dist/compatibility.d.ts +84 -50
  3. package/dist/compatibility.js +84 -67
  4. package/dist/contracts.d.ts +462 -1196
  5. package/dist/contracts.js +403 -681
  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,100 +0,0 @@
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
- });
50
- let verifyField;
51
- if (isVerifyFn(verify)) {
52
- verifyField = { fn: true };
53
- acc.nodes[id] = { kind: "verify", fn: verify };
54
- }
55
- else {
56
- const verifyChild = isSlot(verify)
57
- ? resolveChild(verify)
58
- : resolveChild(verify);
59
- const agentEntry = Object.values(verifyChild.agents)[0];
60
- if (!agentEntry) {
61
- fail([
62
- diagnostic("loop.invalid-verify", "Loop.verify must be a verify function or a verifier agent"),
63
- ]);
64
- }
65
- assertVerifierAgent({
66
- id: agentEntry.manifest.id,
67
- getBinding: () => agentEntry,
68
- });
69
- // Keys follow the harness path for the verifier, `<loop>/<part>` (workflows.md §6).
70
- mergeChild(acc, {
71
- agents: verifyChild.agents,
72
- nodes: remapNodeKeys(verifyChild.nodes, verifyChild.id, `${id}/${verifyChild.id}`),
73
- });
74
- const node = verifyChild.node;
75
- if (!("agent" in node) && !("slot" in node)) {
76
- fail([
77
- diagnostic("loop.invalid-verify", "Loop.verify must be a verify function or a verifier agent"),
78
- ]);
79
- }
80
- verifyField = node;
81
- }
82
- acc.nodes[`${id}/decide`] = {
83
- kind: "fn",
84
- fn: decide,
85
- };
86
- return finishWorkflow({
87
- id,
88
- root: {
89
- loop: {
90
- id,
91
- run: runResolved.node,
92
- verify: verifyField,
93
- decide: { fn: true },
94
- },
95
- },
96
- acc,
97
- inputSchema: options.inputSchema,
98
- outputSchema: options.outputSchema,
99
- });
100
- }
@@ -1,17 +0,0 @@
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>[]>;
@@ -1,45 +0,0 @@
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
- });
26
- acc.nodes[`${id}/over`] = {
27
- kind: "fn",
28
- fn: over,
29
- };
30
- // Preserve each child's id for path construction (map.md §3.2).
31
- void runnableId(each);
32
- return finishWorkflow({
33
- id,
34
- root: {
35
- map: {
36
- id,
37
- over: { fn: true },
38
- each: resolved.node,
39
- },
40
- },
41
- acc,
42
- inputSchema: options.inputSchema,
43
- outputSchema: options.outputSchema,
44
- });
45
- }
@@ -1,19 +0,0 @@
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>>;
@@ -1,36 +0,0 @@
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
- });
27
- branchNodes[name] = resolved.node;
28
- }
29
- return finishWorkflow({
30
- id,
31
- root: { parallel: { id, branches: branchNodes } },
32
- acc,
33
- inputSchema: options.inputSchema,
34
- outputSchema: options.outputSchema,
35
- });
36
- }
@@ -1,11 +0,0 @@
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;
@@ -1,45 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
1
- import type { JsonValue } from "../../types/shared.js";
2
- import type { WorkflowRunnable } from "./runnable.js";
3
- /**
4
- * Arguments for a slot `input` reshape function (workflows.md §4).
5
- * `results` comes from the nearest enclosing Chain; `index` only in Map `each`.
6
- */
7
- export type SlotInputArgs<Value = JsonValue, Input = JsonValue, Results extends Readonly<Record<string, JsonValue>> = Readonly<Record<string, JsonValue>>> = {
8
- readonly value: Value;
9
- readonly input: Input;
10
- readonly results: Results;
11
- readonly index?: number;
12
- };
13
- /**
14
- * Plain-object rename/reshape wrapper. There is no helper constructor —
15
- * write `{ run, id?, input? }` (workflows.md §4, decision 5).
16
- */
17
- export type Slot<Run extends WorkflowRunnable = WorkflowRunnable, Value = JsonValue, Input = JsonValue, Results extends Readonly<Record<string, JsonValue>> = Readonly<Record<string, JsonValue>>> = {
18
- readonly run: Run;
19
- readonly id?: string;
20
- readonly input?: (args: SlotInputArgs<Value, Input, Results>) => JsonValue;
21
- };
22
- export type ChildRef<Run extends WorkflowRunnable = WorkflowRunnable> = Run | Slot<Run>;
23
- export declare function isSlot(value: unknown): value is Slot;
@@ -1,16 +0,0 @@
1
- export function isSlot(value) {
2
- if (!value || typeof value !== "object")
3
- return false;
4
- if (!("run" in value))
5
- return false;
6
- // Agents / workflows expose manifest + getBinding; tools expose name + execute/run.
7
- if ("manifest" in value || "getBinding" in value)
8
- return false;
9
- if ("name" in value &&
10
- (typeof value.execute === "function" ||
11
- typeof value.run === "function" ||
12
- "inputSchema" in value ||
13
- "input" in value))
14
- return false;
15
- return true;
16
- }
@@ -1,26 +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 } from "./slot.js";
5
- import type { BuiltWorkflow, OutputOf } from "./types.js";
6
- export type SwitchCases = Readonly<Record<string, ChildRef>>;
7
- export type SwitchOn<In, Cases extends SwitchCases, HasDefault extends boolean> = HasDefault extends true ? (input: In) => string : (input: In) => Extract<keyof Cases, string>;
8
- export type SwitchOutput<Cases extends SwitchCases, Default extends ChildRef | undefined> = OutputOf<Cases[keyof Cases]> | (Default extends ChildRef ? OutputOf<Default> : never);
9
- export interface SwitchOptions<Cases extends SwitchCases = SwitchCases, In = JsonValue, Default extends ChildRef | undefined = undefined> {
10
- readonly id: string;
11
- readonly on: SwitchOn<In, Cases, Default extends ChildRef ? true : false>;
12
- readonly cases: Cases;
13
- readonly default?: Default;
14
- readonly inputSchema?: ToolSchemaSource;
15
- readonly outputSchema?: ToolSchemaSource;
16
- }
17
- /**
18
- * Pick exactly one case by a pure `on` key (switch.md).
19
- * `default` is reserved and cannot be a case key.
20
- */
21
- export declare function Switch<const Cases extends SwitchCases, In = JsonValue, Default extends ChildRef | undefined = undefined>(options: SwitchOptions<Cases, In, Default> & {
22
- readonly cases: Cases;
23
- readonly default?: Default;
24
- }): BuiltWorkflow<In, SwitchOutput<Cases, Default>>;
25
- /** @deprecated Prefer Switch — kept for documentation symmetry with decision tables. */
26
- export type SwitchRunnable = WorkflowRunnable;
@@ -1,64 +0,0 @@
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
- * Pick exactly one case by a pure `on` key (switch.md).
6
- * `default` is reserved and cannot be a case key.
7
- */
8
- export function Switch(options) {
9
- const { id, on, cases } = options;
10
- if (!id)
11
- fail([diagnostic("switch.missing-id", "Switch requires id")]);
12
- assertValidPathPart(id, "Switch id");
13
- if (typeof on !== "function")
14
- fail([diagnostic("switch.missing-on", "Switch requires on")]);
15
- if (!cases || Object.keys(cases).length === 0)
16
- fail([diagnostic("switch.empty-cases", "Switch cases must have at least one entry")]);
17
- const caseKeys = Object.keys(cases);
18
- for (const key of caseKeys) {
19
- if (key === "default")
20
- fail([
21
- diagnostic("switch.reserved-default", "default is reserved and cannot be a case key"),
22
- ]);
23
- assertValidPathPart(key, "Switch case key");
24
- }
25
- const acc = emptyAccumulator();
26
- const caseNodes = {};
27
- for (const key of caseKeys) {
28
- const resolved = resolveChild(cases[key]);
29
- const casePath = `${id}/${key}`;
30
- mergeChild(acc, {
31
- agents: resolved.agents,
32
- nodes: remapNodeKeys(resolved.nodes, resolved.id, casePath),
33
- });
34
- caseNodes[key] = resolved.node;
35
- }
36
- let defaultNode;
37
- if (options.default !== undefined) {
38
- const resolved = resolveChild(options.default);
39
- const defaultPath = `${id}/default`;
40
- mergeChild(acc, {
41
- agents: resolved.agents,
42
- nodes: remapNodeKeys(resolved.nodes, resolved.id, defaultPath),
43
- });
44
- defaultNode = resolved.node;
45
- }
46
- acc.nodes[`${id}/on`] = {
47
- kind: "fn",
48
- fn: on,
49
- };
50
- return finishWorkflow({
51
- id,
52
- root: {
53
- switch: {
54
- id,
55
- on: { fn: true },
56
- cases: caseNodes,
57
- ...(defaultNode === undefined ? {} : { default: defaultNode }),
58
- },
59
- },
60
- acc,
61
- inputSchema: options.inputSchema,
62
- outputSchema: options.outputSchema,
63
- });
64
- }
@@ -1,101 +0,0 @@
1
- import type { JsonValue } from "./shared.js";
2
- import type { PromptItem } from "./model.js";
3
- import type { MessageInput } from "./transcript.js";
4
- /** Closed-world patch applied before a model call. No `model` — Runtime owns resolution. */
5
- export type Patch = {
6
- /** Switch capabilities declared in the manifest. */
7
- readonly capabilities?: Readonly<Record<string, boolean>>;
8
- /** Switch tools by name. */
9
- readonly tools?: Readonly<Record<string, boolean>>;
10
- /** Extra instructions for the model calls this patch covers. */
11
- readonly instructions?: readonly string[];
12
- /** Write session state keys (merged into durable session state). */
13
- readonly state?: Readonly<Record<string, JsonValue>>;
14
- /** Refuse the model call; message returned to the host. */
15
- readonly block?: string;
16
- /**
17
- * Capability-level shorthand: toggle only this capability.
18
- * Normalized to `capabilities: { [id]: active }` at bind time.
19
- */
20
- readonly active?: boolean;
21
- };
22
- /** Decision applied after a model response, before tools/text take effect. */
23
- export type Decision = {
24
- readonly text?: string;
25
- readonly deny?: readonly {
26
- readonly id: string;
27
- readonly reason: string;
28
- }[];
29
- readonly approve?: readonly {
30
- readonly id: string;
31
- readonly prompt: string;
32
- }[];
33
- readonly retry?: string;
34
- readonly block?: string;
35
- };
36
- /** Decision applied to a turn's final answer before it is returned. */
37
- export type TurnDecision = {
38
- /** Replace the final text. Plain-text agents only. */
39
- readonly text?: string;
40
- /** Replace the final structured output. Agents with an output schema only. */
41
- readonly output?: JsonValue;
42
- /** Ask the model to answer again; the feedback is added as a message. */
43
- readonly retry?: string;
44
- readonly block?: string;
45
- };
46
- /** When a hook runs: once per turn, or on every model call (step). */
47
- export type HookScope = "turn" | "step";
48
- export type HookAt = "before" | "after";
49
- /** A registered hook point as published in the manifest. */
50
- export type HookManifest = {
51
- readonly at: HookAt;
52
- readonly scope: HookScope;
53
- };
54
- export type HookState = Readonly<Record<string, JsonValue>>;
55
- export type HookToolCall = {
56
- readonly id: string;
57
- readonly name: string;
58
- readonly args: JsonValue;
59
- };
60
- export type BeforeTurnArgs<Info = unknown> = {
61
- /** The user input that started this turn. */
62
- readonly input?: MessageInput | string;
63
- readonly info?: Info;
64
- readonly state: HookState;
65
- readonly messages: readonly PromptItem[];
66
- };
67
- export type BeforeStepArgs<Info = unknown> = BeforeTurnArgs<Info> & {
68
- /** Zero-based model call index within the turn. */
69
- readonly step: number;
70
- };
71
- export type AfterStepArgs<Info = unknown> = {
72
- readonly text?: string;
73
- readonly toolCalls: readonly HookToolCall[];
74
- readonly info?: Info;
75
- readonly state: HookState;
76
- readonly step: number;
77
- /** Retries already requested by `after("step")` hooks in this turn. */
78
- readonly attempt: number;
79
- };
80
- export type AfterTurnArgs<Info = unknown> = {
81
- /** Final text, for plain-text agents. */
82
- readonly text?: string;
83
- /** Final output: the text, or the structured value when an output schema is set. */
84
- readonly output: JsonValue;
85
- readonly info?: Info;
86
- readonly state: HookState;
87
- /** Retries already requested by `after("turn")` hooks in this turn. */
88
- readonly attempt: number;
89
- };
90
- type Awaitable<T> = T | Promise<T>;
91
- export type BeforeHook<S extends HookScope, Info = unknown> = (args: S extends "turn" ? BeforeTurnArgs<Info> : BeforeStepArgs<Info>) => Awaitable<Patch>;
92
- export type AfterHook<S extends HookScope, Info = unknown> = S extends "step" ? (args: AfterStepArgs<Info>) => Awaitable<Decision> : (args: AfterTurnArgs<Info>) => Awaitable<TurnDecision>;
93
- export type BeforeHooks<Info = unknown> = {
94
- readonly turn?: BeforeHook<"turn", Info>;
95
- readonly step?: BeforeHook<"step", Info>;
96
- };
97
- export type AfterHooks<Info = unknown> = {
98
- readonly step?: AfterHook<"step", Info>;
99
- readonly turn?: AfterHook<"turn", Info>;
100
- };
101
- export {};
@@ -1 +0,0 @@
1
- export {};