operon-agents-core 0.1.0-alpha.30 → 0.1.0-alpha.31

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 (93) hide show
  1. package/dist/agent/agent.d.ts +19 -5
  2. package/dist/agent/context-report.d.ts +8 -5
  3. package/dist/agent/context-report.js +36 -6
  4. package/dist/agent/errors.d.ts +22 -0
  5. package/dist/agent/errors.js +39 -0
  6. package/dist/agent/handoff.js +1 -1
  7. package/dist/agent/index.d.ts +3 -2
  8. package/dist/agent/index.js +1 -1
  9. package/dist/agent/pause.js +0 -5
  10. package/dist/agent/run-support.d.ts +2 -2
  11. package/dist/agent/runner.d.ts +37 -20
  12. package/dist/agent/runner.js +106 -42
  13. package/dist/agent/session.d.ts +16 -7
  14. package/dist/agent/session.js +33 -19
  15. package/dist/agent/subagent-tools.js +2 -2
  16. package/dist/agent/workflow/tool.js +1 -1
  17. package/dist/capabilities/background/tools.js +3 -3
  18. package/dist/capabilities/compaction/index.js +2 -2
  19. package/dist/capabilities/compaction/tokens.js +2 -0
  20. package/dist/capabilities/goal/tools.js +3 -3
  21. package/dist/capabilities/plan/tools.js +2 -2
  22. package/dist/capabilities/skills/flow-provider.js +1 -1
  23. package/dist/capabilities/skills/skill-tool.js +1 -1
  24. package/dist/capabilities/task/tools.js +4 -4
  25. package/dist/capabilities/todo/tools.js +1 -1
  26. package/dist/config/index.d.ts +4 -0
  27. package/dist/config/index.js +2 -0
  28. package/dist/config/merge.js +17 -0
  29. package/dist/config/schema.d.ts +97 -0
  30. package/dist/config/schema.js +47 -0
  31. package/dist/config/session-config.d.ts +338 -0
  32. package/dist/config/session-config.js +208 -0
  33. package/dist/events/events.d.ts +7 -2
  34. package/dist/events/projection.d.ts +8 -0
  35. package/dist/events/projection.js +12 -2
  36. package/dist/events/publisher.js +3 -0
  37. package/dist/internal.d.ts +3 -1
  38. package/dist/internal.js +4 -1
  39. package/dist/loop/context.d.ts +12 -0
  40. package/dist/loop/context.js +38 -0
  41. package/dist/loop/index.d.ts +1 -1
  42. package/dist/loop/run-turn.d.ts +2 -4
  43. package/dist/loop/run-turn.js +7 -7
  44. package/dist/loop/steer.d.ts +27 -4
  45. package/dist/loop/steer.js +74 -6
  46. package/dist/loop/tool-call.d.ts +0 -3
  47. package/dist/loop/tool-call.js +0 -2
  48. package/dist/loop/turn-step.d.ts +1 -3
  49. package/dist/loop/turn-step.js +7 -1
  50. package/dist/loop/types.d.ts +2 -0
  51. package/dist/permission/auto-approver/decision-auto-approver.js +2 -1
  52. package/dist/permission/auto-approver/llm-auto-approver.js +6 -5
  53. package/dist/permission/types.d.ts +6 -0
  54. package/dist/store/checkpointing-store.d.ts +2 -0
  55. package/dist/store/checkpointing-store.js +4 -0
  56. package/dist/store/index.d.ts +1 -1
  57. package/dist/store/index.js +1 -1
  58. package/dist/store/lock.d.ts +1 -1
  59. package/dist/store/lock.js +2 -2
  60. package/dist/store/store.d.ts +3 -0
  61. package/dist/store/store.js +3 -0
  62. package/dist/telemetry/index.d.ts +1 -1
  63. package/dist/telemetry/index.js +1 -1
  64. package/dist/tool/builtin/ask-user-question.js +1 -1
  65. package/dist/tool/builtin/bash.js +4 -3
  66. package/dist/tool/builtin/edit.js +11 -69
  67. package/dist/tool/builtin/glob.js +1 -1
  68. package/dist/tool/builtin/grep.js +1 -1
  69. package/dist/tool/builtin/read.js +16 -76
  70. package/dist/tool/builtin/write.js +13 -99
  71. package/dist/tool/define.d.ts +25 -34
  72. package/dist/tool/define.js +8 -26
  73. package/dist/tool/environment-base.d.ts +4 -20
  74. package/dist/tool/environment-base.js +0 -34
  75. package/dist/tool/environment-local.d.ts +2 -4
  76. package/dist/tool/environment-local.js +2 -13
  77. package/dist/tool/environment-null.d.ts +1 -1
  78. package/dist/tool/environment-null.js +1 -1
  79. package/dist/tool/environment-ssh.d.ts +1 -1
  80. package/dist/tool/environment-ssh.js +1 -1
  81. package/dist/tool/environment.d.ts +12 -56
  82. package/dist/tool/index.d.ts +5 -5
  83. package/dist/tool/index.js +4 -4
  84. package/dist/tool/search/search-tool.js +2 -2
  85. package/dist/tool/support/environment-ops.d.ts +21 -21
  86. package/dist/tool/support/environment-ops.js +8 -41
  87. package/dist/tool/types.d.ts +0 -8
  88. package/dist/tool/web/fetch-url.js +1 -1
  89. package/dist/tool/web/web-search.js +1 -1
  90. package/dist/tool/workspace-spec.js +3 -2
  91. package/package.json +1 -1
  92. package/dist/tool/file-freshness.d.ts +0 -95
  93. package/dist/tool/file-freshness.js +0 -76
@@ -21,7 +21,14 @@ export interface AgentGuardrails<TContext = unknown> {
21
21
  readonly toolInput?: readonly ToolInputGuardrail<TContext>[];
22
22
  readonly toolOutput?: readonly ToolOutputGuardrail<TContext>[];
23
23
  }
24
- export interface AgentConfig<TContext = unknown> {
24
+ /**
25
+ * What `outputType` needs from a schema: a `parse` that returns the value or throws. A zod schema
26
+ * satisfies it, and is how `RunResult.outputParsed` gets its type.
27
+ */
28
+ export interface OutputSchema<TOutput = unknown> {
29
+ parse(value: unknown): TOutput;
30
+ }
31
+ export interface AgentConfig<TContext = unknown, TOutput = unknown> {
25
32
  readonly name: string;
26
33
  readonly instructions?: string | ((ctx: AgentRunContext<TContext>) => string | Promise<string>);
27
34
  readonly handoffDescription?: string;
@@ -35,7 +42,7 @@ export interface AgentConfig<TContext = unknown> {
35
42
  readonly handoffs?: readonly Handoff<TContext>[];
36
43
  readonly subagents?: readonly Agent<TContext>[];
37
44
  readonly guardrails?: AgentGuardrails<TContext>;
38
- readonly outputType?: unknown;
45
+ readonly outputType?: OutputSchema<TOutput>;
39
46
  readonly maxStepsPerTurn?: number;
40
47
  /**
41
48
  * Capability/MCP tools are discovered on demand through SearchTool; only loaded ones are
@@ -46,7 +53,7 @@ export interface AgentConfig<TContext = unknown> {
46
53
  */
47
54
  readonly deferTools?: boolean;
48
55
  }
49
- export declare class Agent<TContext = unknown> {
56
+ export declare class Agent<TContext = unknown, TOutput = unknown> {
50
57
  readonly name: string;
51
58
  readonly instructions?: AgentConfig<TContext>["instructions"];
52
59
  readonly handoffDescription?: string;
@@ -56,11 +63,18 @@ export declare class Agent<TContext = unknown> {
56
63
  readonly handoffs: readonly Handoff<TContext>[];
57
64
  readonly subagents: readonly Agent<TContext>[];
58
65
  readonly guardrails: AgentGuardrails<TContext>;
59
- readonly outputType?: unknown;
66
+ readonly outputType?: OutputSchema<TOutput>;
60
67
  readonly maxStepsPerTurn?: number;
61
68
  readonly deferTools?: boolean;
62
- constructor(config: AgentConfig<TContext>);
69
+ constructor(config: AgentConfig<TContext, TOutput>);
63
70
  resolveInstructions(ctx: AgentRunContext<TContext>): Promise<string | undefined>;
64
71
  }
72
+ /**
73
+ * Build an agent. `outputType` types `RunResult.outputParsed` — unless the agent has handoffs:
74
+ * another agent may then give the final answer, under its own schema, so the output is `unknown`.
75
+ */
76
+ export declare function defineAgent<TContext = unknown, TOutput = unknown>(config: AgentConfig<TContext, TOutput> & {
77
+ readonly handoffs?: undefined | readonly [];
78
+ }): Agent<TContext, TOutput>;
65
79
  export declare function defineAgent<TContext = unknown>(config: AgentConfig<TContext>): Agent<TContext>;
66
80
  //# sourceMappingURL=agent.d.ts.map
@@ -4,14 +4,14 @@
4
4
  * turn-boundary injections (skills catalog, todo/task mirrors, …), the compaction reserve,
5
5
  * and the free remainder.
6
6
  *
7
- * The numbers are ESTIMATES (same char/4 heuristic the compaction strategy uses), computed
8
- * from exactly the `{ system, tools, messages }` the Runner is about to send — so the buckets
9
- * sum to the real request, not a separate re-derivation.
7
+ * Total occupancy comes from the provider's last measured request when available. Category
8
+ * weights are estimates of `{ system, tools, messages }`, normalised to that measured total.
9
+ * Before any usage is available (or after history replacement), the total is estimated too.
10
10
  */
11
11
  import type { ChatModel } from "../llm/define-model.ts";
12
12
  import type { Message } from "../protocol/index.ts";
13
13
  import type { Tool } from "../tool/types.ts";
14
- /** One additive slice of the context window: its token estimate and share of the whole window. */
14
+ /** Estimated attribution of occupancy; normalised to the provider total when available. */
15
15
  export interface ContextSlice {
16
16
  readonly tokens: number;
17
17
  /** Percent of the full context window, 0..100. */
@@ -26,8 +26,9 @@ export interface ContextBreakdown {
26
26
  /** The active model's full context window (tokens). */
27
27
  readonly contextWindow: number;
28
28
  readonly model: string;
29
- /** systemPrompt + tools + messages + injections (everything actually sent this turn). */
29
+ /** Last measured input occupancy; falls back to an estimate until provider usage is available. */
30
30
  readonly used: number;
31
+ readonly usageSource: "provider" | "estimate";
31
32
  readonly usedPercent: number;
32
33
  readonly systemPrompt: ContextSlice;
33
34
  /** Built-in / handoff / spawn tool schemas. */
@@ -55,6 +56,8 @@ export interface ComputeContextBreakdownInput {
55
56
  /** Compaction reserve (`CompactionService.reservedContextTokens`), or 0 if absent. */
56
57
  readonly compactBufferTokens: number;
57
58
  readonly capturedAt: number;
59
+ /** Exact input tokens, including cached input, from the latest provider response. */
60
+ readonly observedInputTokens?: number;
58
61
  }
59
62
  export declare function computeContextBreakdown(input: ComputeContextBreakdownInput): ContextBreakdown;
60
63
  //# sourceMappingURL=context-report.d.ts.map
@@ -27,18 +27,48 @@ export function computeContextBreakdown(input) {
27
27
  }
28
28
  injections.sort((a, b) => b.tokens - a.tokens);
29
29
  const conversationTokens = Math.max(0, messagesTotal - injectionsTotal);
30
- const used = systemTokens + builtinTools + mcpTools + messagesTotal;
30
+ const estimatedUsed = systemTokens + builtinTools + mcpTools + messagesTotal;
31
+ const observed = input.observedInputTokens;
32
+ const measured = observed !== undefined && Number.isFinite(observed) && observed > 0;
33
+ const used = measured ? observed : estimatedUsed;
34
+ // Allocate rounded estimates cumulatively so every category adds up to the measured total.
35
+ // These remain attribution estimates, not provider-supplied per-category token counts.
36
+ let estimatedSoFar = 0;
37
+ let allocated = 0;
38
+ const attributed = (tokens) => {
39
+ if (!measured || estimatedUsed === 0)
40
+ return slice(tokens);
41
+ estimatedSoFar += tokens;
42
+ const next = Math.round(estimatedSoFar / estimatedUsed * used);
43
+ const result = slice(Math.max(0, next - allocated));
44
+ allocated = next;
45
+ return result;
46
+ };
47
+ const systemSlice = attributed(systemTokens);
48
+ const builtinSlice = attributed(builtinTools);
49
+ const mcpSlice = attributed(mcpTools);
50
+ // Stale injection estimates must not create extra occupancy.
51
+ let injectionRemaining = messagesTotal;
52
+ const attributedInjections = injections.map((item) => {
53
+ const tokens = Math.min(item.tokens, injectionRemaining);
54
+ injectionRemaining -= tokens;
55
+ return { id: item.id, ...attributed(tokens) };
56
+ });
57
+ const messagesSlice = measured && estimatedUsed === 0
58
+ ? slice(used)
59
+ : attributed(measured ? injectionRemaining : conversationTokens);
31
60
  const free = Math.max(0, window - used - input.compactBufferTokens);
32
61
  return {
33
62
  contextWindow: window,
34
63
  model: input.model.id,
35
64
  used,
65
+ usageSource: measured ? "provider" : "estimate",
36
66
  usedPercent: pct(used),
37
- systemPrompt: slice(systemTokens),
38
- toolsBuiltin: slice(builtinTools),
39
- toolsMcp: slice(mcpTools),
40
- messages: slice(conversationTokens),
41
- injections,
67
+ systemPrompt: systemSlice,
68
+ toolsBuiltin: builtinSlice,
69
+ toolsMcp: mcpSlice,
70
+ messages: messagesSlice,
71
+ injections: measured ? attributedInjections : injections,
42
72
  compactBuffer: slice(input.compactBufferTokens),
43
73
  free: slice(free),
44
74
  capturedAt: input.capturedAt,
@@ -0,0 +1,22 @@
1
+ /** The session is closed: nothing can be sent to it or run on it. */
2
+ export declare class SessionClosedError extends Error {
3
+ readonly sessionId: string;
4
+ constructor(sessionId: string);
5
+ }
6
+ /** The session is waiting for an answer to an interrupted run, and nothing else can go in first. */
7
+ export declare class SessionInterruptedError extends Error {
8
+ readonly sessionId: string;
9
+ constructor(sessionId: string);
10
+ }
11
+ /** An answer was given, but the session has no interrupted run to apply it to. */
12
+ export declare class SessionNotInterruptedError extends Error {
13
+ readonly sessionId: string;
14
+ constructor(sessionId: string);
15
+ }
16
+ /** No frame is running at the address a message was sent to. */
17
+ export declare class SteerTargetNotFoundError extends Error {
18
+ readonly sessionId: string;
19
+ readonly address: string;
20
+ constructor(sessionId: string, address: string);
21
+ }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,39 @@
1
+ /** The session is closed: nothing can be sent to it or run on it. */
2
+ export class SessionClosedError extends Error {
3
+ sessionId;
4
+ constructor(sessionId) {
5
+ super(`session "${sessionId}" is closed`);
6
+ this.name = "SessionClosedError";
7
+ this.sessionId = sessionId;
8
+ }
9
+ }
10
+ /** The session is waiting for an answer to an interrupted run, and nothing else can go in first. */
11
+ export class SessionInterruptedError extends Error {
12
+ sessionId;
13
+ constructor(sessionId) {
14
+ super(`session "${sessionId}" has an interrupted run. Respond to it or resolve it before sending anything else.`);
15
+ this.name = "SessionInterruptedError";
16
+ this.sessionId = sessionId;
17
+ }
18
+ }
19
+ /** An answer was given, but the session has no interrupted run to apply it to. */
20
+ export class SessionNotInterruptedError extends Error {
21
+ sessionId;
22
+ constructor(sessionId) {
23
+ super(`No interrupted run to respond to on session "${sessionId}" (no persisted interruption state).`);
24
+ this.name = "SessionNotInterruptedError";
25
+ this.sessionId = sessionId;
26
+ }
27
+ }
28
+ /** No frame is running at the address a message was sent to. */
29
+ export class SteerTargetNotFoundError extends Error {
30
+ sessionId;
31
+ address;
32
+ constructor(sessionId, address) {
33
+ super(`no frame is running at "${address}" in session "${sessionId}"`);
34
+ this.name = "SteerTargetNotFoundError";
35
+ this.sessionId = sessionId;
36
+ this.address = address;
37
+ }
38
+ }
39
+ //# sourceMappingURL=errors.js.map
@@ -52,7 +52,7 @@ export class Handoff {
52
52
  return defineTool({
53
53
  name: toolName,
54
54
  description: this.toolDescription,
55
- params,
55
+ parameters: params,
56
56
  resolve: (args) => ({
57
57
  approvalRule: toolName,
58
58
  accesses: ToolAccesses.none(),
@@ -1,4 +1,6 @@
1
1
  export { Agent, defineAgent } from "./agent.ts";
2
+ export { SessionClosedError, SessionInterruptedError, SessionNotInterruptedError, SteerTargetNotFoundError } from "./errors.ts";
3
+ export type { OutputSchema } from "./agent.ts";
2
4
  export type { AgentConfig, AgentGuardrails, AgentRunContext } from "./agent.ts";
3
5
  export { Handoff, handoff, getTransferMessage, toFunctionToolName } from "./handoff.ts";
4
6
  export type { HandoffOptions, HandoffInputData, HandoffInputFilter } from "./handoff.ts";
@@ -20,7 +22,6 @@ export type { WorktreeHandle } from "./worktree.ts";
20
22
  export { computeContextBreakdown } from "./context-report.ts";
21
23
  export type { ContextBreakdown, ContextSlice, ContextInjectionSlice, ComputeContextBreakdownInput, } from "./context-report.ts";
22
24
  export { Runner } from "./runner.ts";
23
- export type { AgentInput, ResumeInput, RunInterruption, RunnerConfig, RunOptions, RunResult, RunStatus, } from "./runner.ts";
25
+ export type { AgentInput, CompletedRunResult, FailedRunResult, GuardrailBlockedRunResult, InterruptedRunResult, ResumeInput, RunError, RunnerConfig, RunOptions, RunResult, RunStatus, StoppedRunResult, } from "./runner.ts";
24
26
  export * from "./workflow/index.ts";
25
- export { closeOrphanedTurns, recoverOrphanedTurns } from "./lifecycle-recovery.ts";
26
27
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,5 @@
1
1
  export { Agent, defineAgent } from "./agent.js";
2
+ export { SessionClosedError, SessionInterruptedError, SessionNotInterruptedError, SteerTargetNotFoundError } from "./errors.js";
2
3
  export { Handoff, handoff, getTransferMessage, toFunctionToolName } from "./handoff.js";
3
4
  export { GuardrailTripwireError, isGuardrailTripwireError, runInputGuardrails, runOutputGuardrails, toolGuardrail, toolInputGuardrailHook, toolOutputGuardrailHook, } from "./guardrail.js";
4
5
  export { composeLoopHooks } from "./compose-hooks.js";
@@ -16,5 +17,4 @@ export { Runner } from "./runner.js";
16
17
  // Workflow engine (the deterministic subagent-orchestration runtime) + its manager
17
18
  // and snapshot/journal layers, exposed so upper layers can integrate programmatically.
18
19
  export * from "./workflow/index.js";
19
- export { closeOrphanedTurns, recoverOrphanedTurns } from "./lifecycle-recovery.js";
20
20
  //# sourceMappingURL=index.js.map
@@ -30,11 +30,6 @@ export async function pauseRun(active, context, pending, suspensions, state, tur
30
30
  // Snapshot — RunResult.messages must not alias the live context array (see Engine.finish).
31
31
  messages: [...messages],
32
32
  usage: state.usage,
33
- interruption: {
34
- id: interruption.interruptionId,
35
- revision: interruption.revision,
36
- pending: publicPending,
37
- },
38
33
  interruptions: publicPending,
39
34
  };
40
35
  return attachInterruptionState(result, interruption);
@@ -10,7 +10,7 @@ import type { ModelSettings, ThinkingLevel } from "../llm/model.ts";
10
10
  import type { AgentEventBody, EventSink } from "../events/index.ts";
11
11
  import type { ConversationContext, HistoryChangeListener } from "../loop/context.ts";
12
12
  import type { Agent, AgentRunContext } from "./agent.ts";
13
- import type { DeriveOptions, RunState, RunStatus } from "./runner.ts";
13
+ import type { DeriveOptions, RunState } from "./runner.ts";
14
14
  import type { TurnStopReason } from "../loop/types.ts";
15
15
  /**
16
16
  * This frame's flat directory id — what peers address it by.
@@ -65,7 +65,7 @@ export declare function deriveChild<TContext>(parent: RunState<TContext>, opts:
65
65
  export declare function injectAtTurnBoundary<TContext>(state: RunState<TContext>, context: ConversationContext): Map<string, number>;
66
66
  export declare function lastAssistant(messages: readonly Message[]): AssistantMessage | undefined;
67
67
  export declare function finalText(messages: readonly Message[]): string;
68
- export declare function mapTerminalStatus(stop: TurnStopReason): RunStatus;
68
+ export declare function mapTerminalStatus(stop: TurnStopReason): "completed" | "aborted" | "error";
69
69
  export interface ParsedOutput {
70
70
  /** The parsed value; absent when the schema rejected the text (see `error`). */
71
71
  readonly value?: unknown;
@@ -69,11 +69,6 @@ export type AgentInput = string | Message[];
69
69
  * not one the model produced.
70
70
  */
71
71
  export type RunStatus = "completed" | "interrupted" | "max_turns" | "aborted" | "error" | "guardrail_blocked" | "skipped";
72
- export interface RunInterruption {
73
- readonly id: string;
74
- readonly revision: number;
75
- readonly pending: readonly PendingRunInterrupt[];
76
- }
77
72
  /** Which guardrail aborted a `guardrail_blocked` run — the batteries-included facade (Harness)
78
73
  * synthesizes this instead of throwing; the low-level `Runner.run` still throws (OpenAI parity). */
79
74
  export interface RunGuardrailBlock {
@@ -81,28 +76,46 @@ export interface RunGuardrailBlock {
81
76
  readonly guardrail: string;
82
77
  readonly agent?: string;
83
78
  }
84
- export interface RunResult {
85
- readonly status: RunStatus;
79
+ /** Why a run ended with `status: "error"`. */
80
+ export interface RunError {
81
+ readonly message: string;
82
+ }
83
+ interface RunResultBase {
86
84
  /** Agent that owns the conversation after this run and should receive the next prompt. */
87
85
  readonly finalAgent: string;
88
86
  /** Root conversation shard owned by `finalAgent`. */
89
87
  readonly activeAddress: string;
90
88
  readonly output: string;
91
- readonly outputParsed?: unknown;
89
+ readonly messages: Message[];
90
+ readonly usage: Usage;
91
+ }
92
+ export interface CompletedRunResult<TOutput = unknown> extends RunResultBase {
93
+ readonly status: "completed";
94
+ readonly outputParsed?: TOutput;
92
95
  /** Set when the agent's `outputType` schema rejected the final text — `outputParsed` is
93
96
  * then absent. Distinguishes a parse failure from "no outputType configured" (both leave
94
97
  * `outputParsed` undefined) and carries the schema's rejection reason. */
95
98
  readonly outputParseError?: string;
96
- readonly messages: Message[];
97
- readonly usage: Usage;
98
- readonly interruption?: RunInterruption;
99
- /** OpenAI-parity alias for `interruption.pending`: the approvals and tool input requests
100
- * awaiting an answer when `status === "interrupted"`. Feed the answers back through
101
- * `Runner.resume`. */
102
- readonly interruptions?: readonly PendingRunInterrupt[];
103
- /** Set only when `status === "guardrail_blocked"`. */
104
- readonly guardrail?: RunGuardrailBlock;
105
99
  }
100
+ export interface InterruptedRunResult extends RunResultBase {
101
+ readonly status: "interrupted";
102
+ /** The approvals and tool input requests awaiting an answer, flattened across every paused
103
+ * frame. Feed the answers back through `Runner.resume`. */
104
+ readonly interruptions: readonly PendingRunInterrupt[];
105
+ }
106
+ export interface GuardrailBlockedRunResult extends RunResultBase {
107
+ readonly status: "guardrail_blocked";
108
+ readonly guardrail: RunGuardrailBlock;
109
+ }
110
+ export interface FailedRunResult extends RunResultBase {
111
+ readonly status: "error";
112
+ readonly error: RunError;
113
+ }
114
+ export interface StoppedRunResult extends RunResultBase {
115
+ readonly status: "max_turns" | "aborted" | "skipped";
116
+ }
117
+ /** How a run ended. Discriminated on `status`: narrow it to reach what that outcome carries. */
118
+ export type RunResult<TOutput = unknown> = CompletedRunResult<TOutput> | InterruptedRunResult | GuardrailBlockedRunResult | FailedRunResult | StoppedRunResult;
106
119
  /** Input to `Runner.resume` — the paused run's control tree plus the caller's answers. */
107
120
  export interface ResumeInput {
108
121
  /** Persisted interruption state. Re-read it from the store before resuming (e.g. after a
@@ -217,7 +230,8 @@ export declare class Runner<TContext = unknown> {
217
230
  private readonly config;
218
231
  private readonly engine;
219
232
  constructor(config?: RunnerConfig<TContext>);
220
- run(agent: Agent<TContext>, input: AgentInput, opts?: RunOptions<TContext>): Promise<RunResult>;
233
+ run<TOutput = unknown>(agent: Agent<TContext, TOutput>, input: AgentInput, opts?: RunOptions<TContext>): Promise<RunResult<TOutput>>;
234
+ private runUntyped;
221
235
  /**
222
236
  * Hold the session lease for the duration of `fn`, when a lock is configured.
223
237
  *
@@ -228,10 +242,12 @@ export declare class Runner<TContext = unknown> {
228
242
  * names one is opening a fresh id nobody else can hold, so it skips the lease entirely.
229
243
  */
230
244
  private withLease;
231
- runStream(agent: Agent<TContext>, input: AgentInput, opts?: RunOptions<TContext>): RunHandle<RunResult>;
245
+ runStream<TOutput = unknown>(agent: Agent<TContext, TOutput>, input: AgentInput, opts?: RunOptions<TContext>): RunHandle<RunResult<TOutput>>;
246
+ private runStreamUntyped;
232
247
  /** Continue an interrupted run. Mirrors `run(agent, input, opts)`: the second argument is
233
248
  * the resume input (paused control tree + answers) instead of a fresh prompt. */
234
- resume(rootAgent: Agent<TContext>, input: ResumeInput, opts?: RunOptions<TContext>): Promise<RunResult>;
249
+ resume<TOutput = unknown>(rootAgent: Agent<TContext, TOutput>, input: ResumeInput, opts?: RunOptions<TContext>): Promise<RunResult<TOutput>>;
250
+ private resumeUntyped;
235
251
  /** Reuse the caller's session, or open one for this run. `owned` means we created it and the
236
252
  * caller of this method must close it. */
237
253
  private acquireSession;
@@ -254,4 +270,5 @@ export declare class Runner<TContext = unknown> {
254
270
  private beginRun;
255
271
  private reportDiagnostics;
256
272
  }
273
+ export {};
257
274
  //# sourceMappingURL=runner.d.ts.map