@nylorun/core 0.7.0-beta → 0.9.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 (61) hide show
  1. package/CHANGELOG.md +249 -0
  2. package/dist/compatibility.d.ts +42 -4
  3. package/dist/compatibility.js +65 -3
  4. package/dist/contracts.d.ts +2165 -328
  5. package/dist/contracts.js +1246 -100
  6. package/dist/define.d.ts +13 -5
  7. package/dist/define.js +7 -2
  8. package/dist/definition/assemble.js +16 -14
  9. package/dist/definition/bind-tool.js +1 -0
  10. package/dist/definition/bound.d.ts +2 -0
  11. package/dist/definition/builder.d.ts +116 -16
  12. package/dist/definition/builder.js +330 -53
  13. package/dist/definition/capability.d.ts +55 -0
  14. package/dist/definition/capability.js +104 -0
  15. package/dist/definition/declaration.js +6 -2
  16. package/dist/definition/delegate.d.ts +25 -4
  17. package/dist/definition/delegate.js +34 -6
  18. package/dist/definition/flow/compile.d.ts +23 -0
  19. package/dist/definition/flow/compile.js +274 -0
  20. package/dist/definition/flow/from.d.ts +11 -0
  21. package/dist/definition/flow/from.js +78 -0
  22. package/dist/definition/flow/index.d.ts +11 -0
  23. package/dist/definition/flow/index.js +11 -0
  24. package/dist/definition/flow/paths.d.ts +60 -0
  25. package/dist/definition/flow/paths.js +90 -0
  26. package/dist/definition/flow/spec.d.ts +66 -0
  27. package/dist/definition/flow/spec.js +130 -0
  28. package/dist/definition/flow/types.d.ts +157 -0
  29. package/dist/definition/flow/types.js +1 -0
  30. package/dist/definition/from.js +5 -1
  31. package/dist/definition/helpers.d.ts +1 -16
  32. package/dist/definition/helpers.js +1 -30
  33. package/dist/definition/mcp.d.ts +37 -0
  34. package/dist/definition/mcp.js +81 -0
  35. package/dist/definition/model-failure.d.ts +4 -0
  36. package/dist/definition/model-failure.js +22 -0
  37. package/dist/definition/sandbox-capability.d.ts +12 -0
  38. package/dist/definition/sandbox-capability.js +33 -0
  39. package/dist/definition/schema.js +3 -0
  40. package/dist/definition/workflow/build.d.ts +3 -13
  41. package/dist/definition/workflow/build.js +3 -25
  42. package/dist/definition/workflow/chain.js +0 -1
  43. package/dist/definition/workflow/loop.js +2 -4
  44. package/dist/definition/workflow/map.js +0 -1
  45. package/dist/definition/workflow/parallel.js +0 -1
  46. package/dist/definition/workflow/runnable.d.ts +13 -5
  47. package/dist/definition/workflow/runnable.js +11 -41
  48. package/dist/definition/workflow/switch.js +0 -2
  49. package/dist/errors.d.ts +3 -1
  50. package/dist/types/manifest.d.ts +4 -2
  51. package/dist/types/middleware.d.ts +1 -3
  52. package/dist/types/model.d.ts +32 -1
  53. package/dist/types/observe.d.ts +7 -1
  54. package/dist/types/tool.d.ts +6 -0
  55. package/dist/types/transcript.d.ts +14 -1
  56. package/dist/types/workflow.d.ts +72 -3
  57. package/dist/utils/deprecate.d.ts +3 -0
  58. package/dist/utils/deprecate.js +25 -0
  59. package/dist/utils/sandbox.d.ts +0 -4
  60. package/dist/utils/sandbox.js +0 -16
  61. package/package.json +1 -1
package/dist/define.d.ts CHANGED
@@ -3,21 +3,29 @@ export type { AgentOptions } from "./definition/builder.js";
3
3
  export { HarnessError, isHarnessError } from "./errors.js";
4
4
  export type { HarnessErrorCode, HarnessErrorDetails, HarnessErrorOptions, } from "./errors.js";
5
5
  export type { AgentTool, BuiltAgent } from "./types/agent.js";
6
- export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
6
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
7
7
  export type { Delegate } from "./definition/delegate.js";
8
8
  export { capability, middleware, model, tool } from "./definition/helpers.js";
9
+ export { SANDBOX_CAPABILITY_ID, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
10
+ export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
11
+ export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
12
+ export type { CapabilityIdentity, CapabilityOptions } from "./definition/capability.js";
13
+ export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, forEachFlowNode, functionKey, indexSuffix, isLeafNode, isWorkflowManifestV2, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
14
+ export type { FlowAgentBuilder, Flow, Named, StageArgs, NestedStageArgs, FlowOut, LoopChoice, LoopDecideArgs as FlowLoopDecideArgs, LoopVerifyFn as FlowLoopVerifyFn, FlowFunctionRole, FlowNodeVisit, FlowImplementations, } from "./definition/flow/index.js";
15
+ export type { McpCapability, McpOptions, McpServerSpec } from "./definition/mcp.js";
9
16
  export { ToolError, isToolError } from "./definition/tool-error.js";
10
17
  export { defineSchema } from "./definition/schema.js";
11
18
  export { hashManifest } from "./utils/hash.js";
19
+ export { MODEL_FAILURE_CODES, isModelFailureOutcome } from "./definition/model-failure.js";
12
20
  export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
13
- export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
21
+ export { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
14
22
  export type { SandboxToolName } from "./utils/sandbox.js";
15
23
  export type { Implementations } from "./definition/implementations.js";
16
24
  export type { AgentManifest, CapabilityManifest, McpServerManifest, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
17
25
  export type { CapabilityDeclaration, CapabilityInput, CapabilityItems, MiddlewareContributions, SkillRecord, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
18
26
  export type { Patch, Decision, TurnDecision, HookAt, HookScope, HookManifest, HookState, HookToolCall, BeforeHook, AfterHook, BeforeHooks, AfterHooks, BeforeTurnArgs, BeforeStepArgs, AfterStepArgs, AfterTurnArgs, } from "./types/dynamics.js";
19
27
  export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
20
- export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
28
+ export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelFailureCode, ModelFailureOutcome, ModelProducer, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
21
29
  export type { BuildDiagnostic, ContextItem, DeferredOutcome, JsonObject, JsonPrimitive, JsonValue, Tripwire, } from "./types/shared.js";
22
30
  export type { ObserveEvent, ObserveModelConfigurationSnapshot, ObserveModelRequested, ObserveSealedCall, ObserveToolSnapshot, Observer, } from "./types/observe.js";
23
31
  export type { InputEvent, MessageInput, InteractionReply, TranscriptEntry, UserContentPart, } from "./types/transcript.js";
@@ -28,7 +36,7 @@ export type { AgentBinding } from "./definition/binding.js";
28
36
  export { Loop, Chain, Switch, Parallel, Map, VerdictSchema, isVerdict, withInstructions, withoutTools, WorkflowBuildError, isSlot, isBuiltWorkflow, } from "./definition/workflow/index.js";
29
37
  export type { BuiltWorkflow, OutputOf, InputOf, LoopOptions, LoopRunnable, LoopVerify, LoopVerifyFn, LoopDecideFn, LoopVerifyArgs, LoopDecideArgs, LoopDecision, ChainOptions, ChainStep, ChainResults, ChainSlot, SwitchOptions, SwitchCases, ParallelOptions, ParallelBranches, MapOptions, MapOver, Slot, SlotInputArgs, WorkflowRunnable, } from "./definition/workflow/index.js";
30
38
  export { isVariantOf } from "./definition/variant.js";
31
- export type { Verdict, WorkflowBinding, WorkflowManifest } from "./types/workflow.js";
39
+ export type { Verdict, WorkflowBinding, WorkflowManifest, WorkflowManifestV1, WorkflowManifestV2, WorkflowNodeV2, } from "./types/workflow.js";
32
40
  export type { BoundMiddleware, BoundToolDefinition, } from "./definition/bound.js";
33
41
  export { bindTool } from "./definition/bind-tool.js";
34
42
  export { bindOutputContract } from "./definition/output-contract.js";
@@ -39,4 +47,4 @@ export { schemaFromJSON } from "./definition/schema-json.js";
39
47
  export { normalizeSchema } from "./definition/schema.js";
40
48
  export * from "./utils/immutable.js";
41
49
  export * from "./utils/canonical.js";
42
- export type { TranscriptToolsEntry } from "./types/transcript.js";
50
+ export type { TranscriptToolsEntry, TranscriptCompactionEntry } from "./types/transcript.js";
package/dist/define.js CHANGED
@@ -1,12 +1,17 @@
1
1
  export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./definition/builder.js";
2
2
  export { HarnessError, isHarnessError } from "./errors.js";
3
- export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
3
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
4
4
  export { capability, middleware, model, tool } from "./definition/helpers.js";
5
+ export { SANDBOX_CAPABILITY_ID, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
6
+ export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
7
+ export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
8
+ export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, forEachFlowNode, functionKey, indexSuffix, isLeafNode, isWorkflowManifestV2, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
5
9
  export { ToolError, isToolError } from "./definition/tool-error.js";
6
10
  export { defineSchema } from "./definition/schema.js";
7
11
  export { hashManifest } from "./utils/hash.js";
12
+ export { MODEL_FAILURE_CODES, isModelFailureOutcome } from "./definition/model-failure.js";
8
13
  export { createSandboxTools, SANDBOX_INSTRUCTIONS, } from "./definition/sandbox-tools.js";
9
- export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
14
+ export { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, SANDBOX_WORKSPACE, isSandboxHostPattern, isSandboxToolName, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
10
15
  export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
11
16
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
12
17
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
@@ -2,7 +2,7 @@ import { bindAgent } from "./bind-agent.js";
2
2
  import { createManifest } from "./manifest.js";
3
3
  import { createSkillTools } from "./skill-tools.js";
4
4
  import { DELEGATE_NAME_PATTERN, delegateOf, delegatesOf } from "./delegate.js";
5
- import { canonical } from "../utils/canonical.js";
5
+ import { SANDBOX_CAPABILITY_ID } from "./sandbox-capability.js";
6
6
  const diagnostic = (code, message, extra = {}) => Object.freeze({ code, message, ...extra });
7
7
  export function assembleAgent(middleware, identity, dynamics = new Map()) {
8
8
  const diagnostics = [];
@@ -67,14 +67,12 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
67
67
  for (const entry of item.tools ?? []) {
68
68
  const owner = toolOwners.get(entry.name);
69
69
  if (owner !== undefined && owner !== item.id)
70
- diagnostics.push(diagnostic("tool.duplicate-name", `Tool '${entry.name}' is declared by capabilities '${owner}' and '${item.id}'` +
71
- (owner === "sandbox" || item.id === "sandbox"
72
- ? "; sandbox() provides built-in bash, read, write, edit, grep and glob tools, so rename yours"
73
- : "")));
70
+ diagnostics.push(diagnostic("tool.duplicate-name", `Tool '${entry.name}' is declared by capabilities '${owner}' and '${item.id}'`));
74
71
  else
75
72
  toolOwners.set(entry.name, item.id);
76
73
  }
77
74
  diagnostics.push(...delegationDiagnostics(skilled.items));
75
+ diagnostics.push(...sandboxDiagnostics(skilled.items));
78
76
  if (diagnostics.length)
79
77
  return Object.freeze({
80
78
  ok: false,
@@ -96,10 +94,6 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
96
94
  /** v1 delegation is one level deep and non-interactive; anything else fails the build by name. */
97
95
  function delegationDiagnostics(items) {
98
96
  const found = [];
99
- const sandboxes = new Set();
100
- for (const item of items)
101
- if (item.sandbox)
102
- sandboxes.add(canonical(item.sandbox));
103
97
  for (const item of items)
104
98
  for (const tool of item.tools ?? []) {
105
99
  const delegate = delegateOf(tool);
@@ -111,20 +105,28 @@ function delegationDiagnostics(items) {
111
105
  found.push(diagnostic("delegation.invalid-name", `Agent '${child.id}' is used as a tool, so its id must be 1-64 letters, digits, '_' or '-'`, extra));
112
106
  if (!child.description?.trim())
113
107
  found.push(diagnostic("delegation.description-required", `Agent '${child.id}' is used as a tool by capability '${item.id}' and needs a description: the parent's model reads it to decide when to delegate`, extra));
108
+ // A flow agent runs in its own linked session; its agents may delegate in turn.
109
+ if (child.kind === "workflow")
110
+ continue;
114
111
  const nested = delegatesOf(child)[0];
115
112
  if (nested)
116
113
  found.push(diagnostic("delegation.nested", `'${child.id}' delegates to '${nested.manifest.id}'; nested delegation is not supported yet`, extra));
117
114
  for (const childTool of delegate.agent?.getBinding().tools ?? [])
118
115
  if (childTool.approval)
119
116
  found.push(diagnostic("delegation.approval-unsupported", `'${childTool.name}' in '${child.id}' needs approval; agents used as tools can't ask for it yet, so keep it on the parent`, extra));
120
- for (const capability of child.capabilities)
121
- if (capability.sandbox)
122
- sandboxes.add(canonical(capability.sandbox));
123
117
  }
124
- if (sandboxes.size > 1)
125
- found.push(diagnostic("sandbox.mismatch", "An agent and the agents it uses as tools share one sandbox, so every sandbox they declare must be identical"));
126
118
  return found;
127
119
  }
120
+ /**
121
+ * Definitions declare no sandbox: a session gets one when it is opened (Sandboxes v3). A
122
+ * capability that still carries `sandbox` fails the build instead of being silently dropped.
123
+ * The Runtime's own capability (`nylorun.sandbox`, in a session's pinned manifest) is exempt.
124
+ */
125
+ function sandboxDiagnostics(items) {
126
+ return items
127
+ .filter((item) => item.sandbox !== undefined && item.id !== SANDBOX_CAPABILITY_ID)
128
+ .map((item) => diagnostic("sandbox.in-definition", `Capability '${item.id}' declares a sandbox. Agents no longer declare one: open the session with it instead, createSession({ sandbox: { image, network: { allow }, resources } }), or set the Tenant's default sandbox.`));
129
+ }
128
130
  const SKILL_TOOL_NAMES = new Set(["load_skill", "read_skill_resource"]);
129
131
  function attachSkillTools(items) {
130
132
  const skills = new Map();
@@ -22,6 +22,7 @@ export function bindTool(item, owner) {
22
22
  execute: prepared.execute.bind(prepared),
23
23
  ...(prepared.approval === undefined ? {} : { approval: prepared.approval }),
24
24
  ...(prepared.effects === undefined ? {} : { effects: prepared.effects }),
25
+ ...(prepared.background === undefined ? {} : { background: prepared.background }),
25
26
  owner: Object.freeze({ ...owner }),
26
27
  ...(delegate === undefined ? {} : { delegate }),
27
28
  });
@@ -11,6 +11,8 @@ export interface BoundToolDefinition<Info = unknown> extends Omit<ToolDefinition
11
11
  readonly execute: (args: unknown, context: ToolExecutionContext<Info>) => Promise<ToolRunResult>;
12
12
  readonly approval?: ToolApproval<ToolInputSchema>;
13
13
  readonly effects?: ToolEffects;
14
+ /** Runs in the background when an Action endpoint serves it (`ToolDefinition.background`). */
15
+ readonly background?: boolean;
14
16
  readonly owner: ToolOwner;
15
17
  readonly source: ToolDefinition<any, any, any>;
16
18
  /** Set when this tool is an agent used as a tool; the engine runs it. */
@@ -4,30 +4,48 @@ import type { BuildDiagnostic, JsonObject } from "../types/shared.js";
4
4
  import { HarnessError } from "../errors.js";
5
5
  import type { ToolDefinition, ToolSchemaSource, SchemaOutput } from "../types/tool.js";
6
6
  import type { AgentTool, BuiltAgent } from "../types/agent.js";
7
- import type { AgentManifest } from "../types/manifest.js";
7
+ import type { AgentManifest, McpServerManifest } from "../types/manifest.js";
8
+ import type { WorkflowBinding, WorkflowManifest } from "../types/workflow.js";
8
9
  import type { AfterHook, BeforeHook, HookScope } from "../types/dynamics.js";
9
10
  import type { Implementations } from "./implementations.js";
10
11
  import { type CapabilityDynamics } from "./assemble.js";
12
+ import { type McpServerSpec } from "./mcp.js";
13
+ import { type FlowImplementations } from "./flow/from.js";
14
+ import { type BuiltWorkflow } from "./workflow/types.js";
15
+ import { type FlowStage } from "./flow/spec.js";
16
+ import type { AddResult, BranchesOut, CaseKey, CasesOut, FlowAgentBuilder, FlowOut, IdOf, LoopChoice, LoopDecideArgs, LoopVerifyFn, Named, StageArgs } from "./flow/types.js";
11
17
  export interface AgentOptions<Schema extends ToolSchemaSource | undefined = undefined> {
18
+ /** @deprecated Use `.output(schema)`. */
12
19
  readonly outputSchema?: Schema;
13
20
  readonly id: string;
14
21
  readonly name?: string;
15
22
  readonly description?: string;
16
23
  readonly metadata?: JsonObject;
24
+ /** @deprecated Use `.instructions(...)`. */
17
25
  readonly instructions?: string | readonly string[];
18
- /** Top-level tools (H2), and agents used as tools. Composed as capability id `"agent"`. */
26
+ /** @deprecated Use `.tools(...)` and `.subagents(...)`. */
19
27
  readonly tools?: readonly (ToolDefinition<any, any, any> | AgentTool)[];
20
28
  }
29
+ type Body = "none" | "react" | "flow";
21
30
  interface BuilderSnapshot {
22
31
  readonly id: string;
23
32
  readonly name?: string;
24
33
  readonly description?: string;
25
34
  readonly metadata?: JsonObject;
26
35
  readonly outputSchema?: ToolSchemaSource;
36
+ readonly inputSchema?: ToolSchemaSource;
27
37
  readonly entries: readonly BoundMiddleware[];
28
38
  readonly dynamics: ReadonlyMap<string, CapabilityDynamics>;
29
39
  /** Builder-level problems, reported with the assembly diagnostics. */
30
40
  readonly diagnostics?: readonly BuildDiagnostic[];
41
+ readonly body: Body;
42
+ /** Raw items of the `"agent"` capability, so later calls can add to it. */
43
+ readonly agentPart?: {
44
+ readonly instructions?: readonly string[];
45
+ readonly tools?: readonly (ToolDefinition<any, any, any> | AgentTool)[];
46
+ };
47
+ readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
48
+ readonly stages: readonly FlowStage[];
31
49
  }
32
50
  export declare class AgentBuildError extends HarnessError {
33
51
  readonly diagnostics: readonly BuildDiagnostic[];
@@ -36,39 +54,121 @@ export declare class AgentBuildError extends HarnessError {
36
54
  export declare class AgentLifecycleError extends HarnessError {
37
55
  constructor(message: string);
38
56
  }
39
- export declare function Agent<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined>(options: AgentOptions<Schema>): AgentBuilder<Info, Schema>;
57
+ export declare function Agent<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined, const Id extends string = string>(options: AgentOptions<Schema> & {
58
+ readonly id: Id;
59
+ }): AgentBuilder<Info, Schema, Id>;
40
60
  export declare namespace Agent {
61
+ /** Rebuild a flow agent from its workflow manifest v2 and the code its stage keys name. */
62
+ function from(json: import("../types/workflow.js").WorkflowManifestV2, implementations?: FlowImplementations): BuiltWorkflow;
63
+ /** Rebuild an agent from its manifest and the code its capabilities name. */
41
64
  function from<Info = unknown>(json: AgentManifest | import("../types/shared.js").JsonObject, implementations: Implementations<Info>): BuiltAgent<Info>;
42
65
  }
43
66
  declare const SNAPSHOT: unique symbol;
44
- export declare class AgentBuilder<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined> {
67
+ type SchemaOut<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : never;
68
+ type ReactOutput<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : string;
69
+ type StartFlow<Info, Schema, Id extends string, Cur, Results> = FlowAgentBuilder<Info, any, Cur, Results, SchemaOut<Schema>, Id>;
70
+ export declare class AgentBuilder<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined, Id extends string = string> {
45
71
  #private;
72
+ /** Phantom carriers for flow typing (never set at runtime). */
73
+ readonly __output?: ReactOutput<Schema>;
74
+ readonly __id?: Id;
46
75
  getBinding(): import("./binding.js").AgentBinding;
47
76
  constructor(options: AgentOptions<Schema>);
48
77
  /** @internal */
49
78
  constructor(snapshot: BuilderSnapshot, brand: typeof SNAPSHOT);
50
- static create<Info, Schema extends ToolSchemaSource | undefined>(options: AgentOptions<Schema>): AgentBuilder<Info, Schema>;
51
- private static withSnapshot;
79
+ static create<Info, Schema extends ToolSchemaSource | undefined, Id extends string = string>(options: AgentOptions<Schema>): AgentBuilder<Info, Schema, Id>;
80
+ /** @internal True for an agent whose body is a flow. */
81
+ static isFlowAgent(value: unknown): boolean;
82
+ /** A new builder of the same class (subclasses survive chaining). */
83
+ protected spawn(snapshot: BuilderSnapshot): this;
52
84
  /** Compose-time identity — available before `.build()`. */
53
- get id(): string;
85
+ get id(): Id;
54
86
  get name(): string | undefined;
55
87
  get manifest(): AgentManifest;
88
+ /** A flow agent's input and output schemas (local; not on the v1 wire). */
89
+ get inputSchema(): ToolSchemaSource | undefined;
90
+ get outputSchema(): ToolSchemaSource | undefined;
56
91
  toJSON(): AgentManifest;
57
- use(middleware: StepMiddleware<Info>): AgentBuilder<Info, Schema>;
58
- use(id: string, middleware: StepMiddleware<Info>): AgentBuilder<Info, Schema>;
59
- use(declaration: CapabilityInput<Info>): AgentBuilder<Info, Schema>;
92
+ /** Add instructions. Repeated calls add more. */
93
+ instructions(...text: readonly string[]): this;
94
+ /** Add tools. Repeated calls add more. Agents belong in `.subagents()`. */
95
+ tools(...tools: readonly (ToolDefinition<any, any, any> | AgentTool)[]): this;
96
+ /** Add agents the model may delegate a self-contained task to. */
97
+ subagents(...agents: readonly AgentTool[]): this;
98
+ /** Declare MCP servers. A server's `name` defaults to its key; calls merge. */
99
+ mcp(servers: Readonly<Record<string, McpServerSpec>>): this;
100
+ /** Attach a reusable bundle made with `capability({ id })`. */
101
+ capability(bundle: CapabilityInput<Info> | {
102
+ toDeclaration(): CapabilityInput<Info>;
103
+ }): this;
104
+ /** Run `fn` before each turn. */
105
+ beforeTurn(fn: BeforeHook<"turn", Info>): this;
106
+ /** Run `fn` before every model call. */
107
+ beforeModel(fn: BeforeHook<"step", Info>): this;
108
+ /** Run `fn` after every model call. */
109
+ afterModel(fn: AfterHook<"step", Info>): this;
110
+ /** Run `fn` after the turn's final answer. */
111
+ afterTurn(fn: AfterHook<"turn", Info>): this;
112
+ /** The structured output. Set once. */
113
+ output<S extends ToolSchemaSource>(schema: S): AgentBuilder<Info, S, Id>;
114
+ /** @deprecated Use `.capability()`, `.mcp()`, `.skills()` or `.plugin()`. */
115
+ use(middleware: StepMiddleware<Info>): this;
116
+ /** @deprecated Use `.capability()`, `.mcp()`, `.skills()` or `.plugin()`. */
117
+ use(id: string, middleware: StepMiddleware<Info>): this;
118
+ /** @deprecated Use `.capability()`, `.mcp()`, `.skills()` or `.plugin()`. */
119
+ use(declaration: CapabilityInput<Info>): this;
60
120
  /**
121
+ * @deprecated Use `.beforeTurn()` or `.beforeModel()`.
61
122
  * Run `fn` before each turn (`"turn"`) or before every model call (`"step"`).
62
- * The returned Patch applies to the whole turn or to that one model call.
63
123
  */
64
- before<S extends HookScope>(scope: S, fn: BeforeHook<S, Info>): AgentBuilder<Info, Schema>;
124
+ before<S extends HookScope>(scope: S, fn: BeforeHook<S, Info>): this;
65
125
  /**
126
+ * @deprecated Use `.afterModel()` or `.afterTurn()`.
66
127
  * Run `fn` after every model call (`"step"`) or after the turn's final answer (`"turn"`).
67
128
  */
68
- after<S extends HookScope>(scope: S, fn: AfterHook<S, Info>): AgentBuilder<Info, Schema>;
69
- private addAgentHook;
70
- /** Optional no-op: returns the assembled agent facade. */
71
- build(): BuiltAgent<Info, Schema extends ToolSchemaSource ? SchemaOutput<Schema> : string>;
129
+ after<S extends HookScope>(scope: S, fn: AfterHook<S, Info>): this;
130
+ /** The flow agent's input. Set once. */
131
+ input<S extends ToolSchemaSource>(schema: S): FlowAgentBuilder<Info, SchemaOutput<S>, SchemaOutput<S>, {}, SchemaOut<Schema>, Id>;
132
+ step<C, const StepId extends string = IdOf<C>>(child: C, options?: {
133
+ readonly id?: StepId;
134
+ readonly input?: (args: StageArgs<any, {}, any>) => unknown;
135
+ }): StartFlow<Info, Schema, Id, FlowOut<C>, AddResult<{}, StepId, FlowOut<C>>>;
136
+ switch<const Cases extends Readonly<Record<string, unknown>>, T, const StageId extends string = string>(cases: Cases, options: {
137
+ readonly input: (args: StageArgs<any, {}, any>) => T;
138
+ readonly on: (args: StageArgs<T, {}, any>) => CaseKey<Cases>;
139
+ readonly id?: StageId;
140
+ }): StartFlow<Info, Schema, Id, CasesOut<Cases>, AddResult<{}, StageId, CasesOut<Cases>>>;
141
+ switch<const Cases extends Readonly<Record<string, unknown>>, const StageId extends string = string>(cases: Cases, options: {
142
+ readonly on: (args: StageArgs<any, {}, any>) => CaseKey<Cases>;
143
+ readonly id?: StageId;
144
+ }): StartFlow<Info, Schema, Id, CasesOut<Cases>, AddResult<{}, StageId, CasesOut<Cases>>>;
145
+ parallel<const Branches extends Readonly<Record<string, unknown>>, const StageId extends string = string>(branches: Branches, options?: {
146
+ readonly id?: StageId;
147
+ readonly input?: (args: StageArgs<any, {}, any>) => unknown;
148
+ }): StartFlow<Info, Schema, Id, BranchesOut<Branches>, AddResult<{}, StageId, BranchesOut<Branches>>>;
149
+ map<E, const StageId extends string = string>(each: E, options?: {
150
+ readonly id?: StageId;
151
+ readonly input?: (args: StageArgs<any, {}, any>) => readonly unknown[];
152
+ }): StartFlow<Info, Schema, Id, FlowOut<E>[], AddResult<{}, StageId, FlowOut<E>[]>>;
153
+ loop<B, const StageId extends string = string>(body: B, options: {
154
+ readonly verify: LoopVerifyFn<any, FlowOut<B>> | object;
155
+ readonly max?: number;
156
+ readonly decide?: (args: LoopDecideArgs<any, FlowOut<B>>) => LoopChoice<FlowOut<B>>;
157
+ readonly id?: StageId;
158
+ readonly input?: (args: StageArgs<any, {}, any>) => unknown;
159
+ }): StartFlow<Info, Schema, Id, FlowOut<B>, AddResult<{}, StageId, FlowOut<B>>>;
160
+ /** Give this agent a new step id where there is no options object. */
161
+ withId(id: string): Named<this>;
162
+ /** Optional no-op: returns the assembled agent facade (a workflow for flow agents). */
163
+ build(): BuiltAgent<Info, ReactOutput<Schema>>;
72
164
  private ensure;
165
+ /** Record which body a method belongs to; mixing bodies is a build error. */
166
+ private bodyFor;
167
+ private addStage;
168
+ private withAgentItems;
169
+ private addDeclaration;
170
+ private appendCompiled;
171
+ private addAgentHook;
73
172
  }
74
173
  export type { Implementations };
174
+ export type { WorkflowBinding, WorkflowManifest };