@cuylabs/agent-core 0.5.0 → 0.7.0

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 (57) hide show
  1. package/README.md +85 -372
  2. package/dist/{builder-RcTZuYnO.d.ts → builder-BRvqCcIk.d.ts} +2 -2
  3. package/dist/{resolver-DOfZ-xuk.d.ts → capability-resolver-CgRGsWVX.d.ts} +1 -1
  4. package/dist/{chunk-IMGQOTU2.js → chunk-3HNO5SVI.js} +286 -690
  5. package/dist/chunk-5K7AQVOU.js +619 -0
  6. package/dist/{chunk-QAQADS4X.js → chunk-BNSHUWCV.js} +1 -0
  7. package/dist/{chunk-OTUGSCED.js → chunk-CDTV2UYU.js} +159 -1
  8. package/dist/chunk-IEFIQENH.js +73 -0
  9. package/dist/chunk-N7P4PN3O.js +84 -0
  10. package/dist/{chunk-QWFMX226.js → chunk-QGOGIP7T.js} +148 -15
  11. package/dist/chunk-VNQBHPCT.js +398 -0
  12. package/dist/{chunk-X635CM2F.js → chunk-ZPMACVZK.js} +1 -1
  13. package/dist/context/index.js +1 -1
  14. package/dist/host/index.d.ts +45 -0
  15. package/dist/host/index.js +8 -0
  16. package/dist/{index-p0kOsVsE.d.ts → index-C33hlD6H.d.ts} +12 -7
  17. package/dist/{index-tmhaADz5.d.ts → index-CfBGYrpd.d.ts} +121 -2
  18. package/dist/index.d.ts +107 -126
  19. package/dist/index.js +322 -597
  20. package/dist/inference/index.d.ts +59 -0
  21. package/dist/inference/index.js +25 -0
  22. package/dist/middleware/index.d.ts +8 -4
  23. package/dist/middleware/index.js +5 -3
  24. package/dist/models/index.d.ts +104 -2
  25. package/dist/models/index.js +40 -6
  26. package/dist/prompt/index.d.ts +10 -6
  27. package/dist/reasoning/index.d.ts +54 -8
  28. package/dist/reasoning/index.js +2 -3
  29. package/dist/{registry-CuRWWtcT.d.ts → registry-BDLIHOQB.d.ts} +1 -1
  30. package/dist/{runner-C7aMP_x3.d.ts → runner-DSKaEz3z.d.ts} +290 -7
  31. package/dist/runtime/index.d.ts +41 -7
  32. package/dist/runtime/index.js +15 -6
  33. package/dist/scope/index.d.ts +10 -0
  34. package/dist/scope/index.js +14 -0
  35. package/dist/{session-manager-Uawm2Le7.d.ts → session-manager-B_CWGTsl.d.ts} +1 -1
  36. package/dist/skill/index.d.ts +7 -5
  37. package/dist/storage/index.d.ts +2 -2
  38. package/dist/sub-agent/index.d.ts +12 -8
  39. package/dist/tool/index.d.ts +8 -4
  40. package/dist/tool/index.js +4 -3
  41. package/dist/{tool-pFAnJc5Y.d.ts → tool-Db1Ue-1U.d.ts} +1 -1
  42. package/dist/{tool-DYp6-cC3.d.ts → tool-HUtkiVBx.d.ts} +5 -99
  43. package/dist/tracking/index.d.ts +3 -1
  44. package/dist/types-9jGQUjqW.d.ts +29 -0
  45. package/dist/types-CHiPh8U2.d.ts +100 -0
  46. package/dist/types-CqDZTh4d.d.ts +335 -0
  47. package/dist/types-FRpzzg_9.d.ts +355 -0
  48. package/package.json +19 -8
  49. package/dist/capabilities/index.d.ts +0 -97
  50. package/dist/capabilities/index.js +0 -46
  51. package/dist/chunk-6TDTQJ4P.js +0 -116
  52. package/dist/chunk-DWYX7ASF.js +0 -26
  53. package/dist/chunk-FG4MD5MU.js +0 -54
  54. package/dist/config-D2xeGEHK.d.ts +0 -52
  55. package/dist/identifiers-BLUxFqV_.d.ts +0 -12
  56. package/dist/network-D76DS5ot.d.ts +0 -5
  57. package/dist/types-MM1JoX5T.d.ts +0 -810
@@ -1,101 +1,5 @@
1
- /**
2
- * ToolHost execution environment abstraction for agent tools.
3
- *
4
- * A ToolHost defines *where* tools execute: local machine, Docker container,
5
- * SSH remote, etc. Every host provides two surfaces:
6
- *
7
- * 1. **File system** — read, write, stat, list, check existence
8
- * 2. **Process execution** — spawn commands, kill processes
9
- *
10
- * Tools call `ctx.host.readFile()` / `ctx.host.exec()` instead of importing
11
- * `fs` and `child_process` directly. The host implementation handles the rest.
12
- *
13
- * @example
14
- * ```typescript
15
- * // Default: runs everything locally
16
- * const agent = createAgent({ host: localHost() });
17
- *
18
- * // Future: run tools inside a Docker container
19
- * const agent = createAgent({ host: dockerHost("my-container") });
20
- * ```
21
- */
22
- /** Options for spawning a process. */
23
- interface ExecOptions {
24
- /** Working directory for the command. */
25
- cwd?: string;
26
- /** Environment variables (merged with host defaults). */
27
- env?: Record<string, string | undefined>;
28
- /** Abort signal for cancellation. */
29
- signal?: AbortSignal;
30
- /** Timeout in milliseconds. 0 = no timeout. */
31
- timeout?: number;
32
- /** Callback for stdout data as it arrives. */
33
- onStdout?: (data: Buffer) => void;
34
- /** Callback for stderr data as it arrives. */
35
- onStderr?: (data: Buffer) => void;
36
- }
37
- /** Result of a process execution. */
38
- interface ExecResult {
39
- /** Combined stdout output. */
40
- stdout: string;
41
- /** Combined stderr output. */
42
- stderr: string;
43
- /** Exit code (null if killed by signal). */
44
- exitCode: number | null;
45
- /** Whether the process was killed due to timeout. */
46
- timedOut: boolean;
47
- }
48
- /** Minimal stat result — only the fields tools actually need. */
49
- interface FileStat {
50
- /** File size in bytes. */
51
- size: number;
52
- /** Last modification time. */
53
- mtime: Date;
54
- /** Whether this entry is a directory. */
55
- isDirectory: boolean;
56
- /** Whether this entry is a regular file. */
57
- isFile: boolean;
58
- }
59
- /** A directory entry returned by `readdir`. */
60
- interface DirEntry {
61
- /** Entry name (not full path). */
62
- name: string;
63
- /** Whether this entry is a directory. */
64
- isDirectory: boolean;
65
- /** Whether this entry is a regular file. */
66
- isFile: boolean;
67
- }
68
- /**
69
- * The execution environment for agent tools.
70
- *
71
- * Abstracts filesystem and process operations so tools work identically
72
- * whether running locally, in Docker, over SSH, or in any other environment.
73
- */
74
- interface ToolHost {
75
- /** Human-readable host identifier (e.g. "local", "docker:my-container"). */
76
- readonly name: string;
77
- /** Read a file as a UTF-8 string. Throws if the file doesn't exist. */
78
- readFile(path: string): Promise<string>;
79
- /** Read raw bytes from a file. Throws if the file doesn't exist. */
80
- readBytes(path: string, offset: number, length: number): Promise<Buffer>;
81
- /** Write a UTF-8 string to a file. Creates parent directories as needed. */
82
- writeFile(path: string, content: string): Promise<void>;
83
- /** Check if a path exists. Never throws. */
84
- exists(path: string): Promise<boolean>;
85
- /** Get file metadata. Throws if the path doesn't exist. */
86
- stat(path: string): Promise<FileStat>;
87
- /** List directory entries. Throws if the path is not a directory. */
88
- readdir(path: string): Promise<DirEntry[]>;
89
- /** Create directories recursively. No-op if they already exist. */
90
- mkdir(path: string): Promise<void>;
91
- /**
92
- * Execute a shell command.
93
- *
94
- * The host decides which shell to use (e.g. local host uses the user's
95
- * `$SHELL`, Docker host uses `docker exec`, SSH host uses remote shell).
96
- */
97
- exec(command: string, options?: ExecOptions): Promise<ExecResult>;
98
- }
1
+ import { T as ToolHost } from './types-CHiPh8U2.js';
2
+ import { b as ScopeSnapshot } from './types-9jGQUjqW.js';
99
3
 
100
4
  /**
101
5
  * Tool-related types for @cuylabs/agent-core
@@ -128,6 +32,8 @@ interface ToolContext {
128
32
  messageID: string;
129
33
  /** Agent name */
130
34
  agent: string;
35
+ /** Active execution scope snapshot for this tool call. */
36
+ scope?: ScopeSnapshot;
131
37
  /**
132
38
  * Execution environment for file and process operations.
133
39
  *
@@ -236,4 +142,4 @@ interface ToolMetadata {
236
142
  [key: string]: unknown;
237
143
  }
238
144
 
239
- export type { DirEntry as D, ExecOptions as E, FileOperationMeta as F, NormalizedToolReplayPolicy as N, ToolMetadata as T, ToolReplayPolicy as a, ToolContext as b, ToolResult as c, ToolHost as d, TurnTrackerContext as e, ExecResult as f, FileStat as g, ToolReplayMode as h, ToolSideEffectLevel as i };
145
+ export type { FileOperationMeta as F, NormalizedToolReplayPolicy as N, ToolMetadata as T, ToolReplayPolicy as a, ToolContext as b, ToolResult as c, TurnTrackerContext as d, ToolReplayMode as e, ToolSideEffectLevel as f };
@@ -1,6 +1,8 @@
1
1
  import { T as TurnChangeTracker } from '../tracker-DClqYqTj.js';
2
2
  export { F as FileBaseline, a as TurnFileChange, b as TurnSummary, c as TurnTrackerConfig, U as UndoResult, d as createTurnTracker } from '../tracker-DClqYqTj.js';
3
- import { F as FileOperationMeta } from '../tool-DYp6-cC3.js';
3
+ import { F as FileOperationMeta } from '../tool-HUtkiVBx.js';
4
+ import '../types-CHiPh8U2.js';
5
+ import '../types-9jGQUjqW.js';
4
6
 
5
7
  /**
6
8
  * Checkpoint system contracts for @cuylabs/agent-core.
@@ -0,0 +1,29 @@
1
+ type ScopeKind = "task" | "turn" | "model" | "tool" | "commit" | "sub-agent" | "activity";
2
+ type ScopeAttributeValue = string | number | boolean | null;
3
+ type ScopeAttributes = Record<string, ScopeAttributeValue | undefined>;
4
+ interface Scope {
5
+ id: string;
6
+ rootId: string;
7
+ kind: ScopeKind;
8
+ name: string;
9
+ parentId?: string;
10
+ depth: number;
11
+ startedAt: string;
12
+ sessionId?: string;
13
+ taskId?: string;
14
+ step?: number;
15
+ attributes: ScopeAttributes;
16
+ }
17
+ type ScopeSnapshot = Scope;
18
+ interface ScopeOptions {
19
+ id?: string;
20
+ kind: ScopeKind;
21
+ name: string;
22
+ parent?: ScopeSnapshot | null;
23
+ sessionId?: string;
24
+ taskId?: string;
25
+ step?: number;
26
+ attributes?: ScopeAttributes;
27
+ }
28
+
29
+ export type { ScopeOptions as S, Scope as a, ScopeSnapshot as b, ScopeAttributeValue as c, ScopeAttributes as d, ScopeKind as e };
@@ -0,0 +1,100 @@
1
+ /**
2
+ * ToolHost — execution environment abstraction for agent tools.
3
+ *
4
+ * A ToolHost defines *where* tools execute: local machine, Docker container,
5
+ * SSH remote, etc. Every host provides two surfaces:
6
+ *
7
+ * 1. **File system** — read, write, stat, list, check existence
8
+ * 2. **Process execution** — spawn commands, kill processes
9
+ *
10
+ * Tools call `ctx.host.readFile()` / `ctx.host.exec()` instead of importing
11
+ * `fs` and `child_process` directly. The host implementation handles the rest.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Default: runs everything locally
16
+ * const agent = createAgent({ host: localHost() });
17
+ *
18
+ * // Future: run tools inside a Docker container
19
+ * const agent = createAgent({ host: dockerHost("my-container") });
20
+ * ```
21
+ */
22
+ /** Options for spawning a process. */
23
+ interface ExecOptions {
24
+ /** Working directory for the command. */
25
+ cwd?: string;
26
+ /** Environment variables (merged with host defaults). */
27
+ env?: Record<string, string | undefined>;
28
+ /** Abort signal for cancellation. */
29
+ signal?: AbortSignal;
30
+ /** Timeout in milliseconds. 0 = no timeout. */
31
+ timeout?: number;
32
+ /** Callback for stdout data as it arrives. */
33
+ onStdout?: (data: Buffer) => void;
34
+ /** Callback for stderr data as it arrives. */
35
+ onStderr?: (data: Buffer) => void;
36
+ }
37
+ /** Result of a process execution. */
38
+ interface ExecResult {
39
+ /** Combined stdout output. */
40
+ stdout: string;
41
+ /** Combined stderr output. */
42
+ stderr: string;
43
+ /** Exit code (null if killed by signal). */
44
+ exitCode: number | null;
45
+ /** Whether the process was killed due to timeout. */
46
+ timedOut: boolean;
47
+ }
48
+ /** Minimal stat result — only the fields tools actually need. */
49
+ interface FileStat {
50
+ /** File size in bytes. */
51
+ size: number;
52
+ /** Last modification time. */
53
+ mtime: Date;
54
+ /** Whether this entry is a directory. */
55
+ isDirectory: boolean;
56
+ /** Whether this entry is a regular file. */
57
+ isFile: boolean;
58
+ }
59
+ /** A directory entry returned by `readdir`. */
60
+ interface DirEntry {
61
+ /** Entry name (not full path). */
62
+ name: string;
63
+ /** Whether this entry is a directory. */
64
+ isDirectory: boolean;
65
+ /** Whether this entry is a regular file. */
66
+ isFile: boolean;
67
+ }
68
+ /**
69
+ * The execution environment for agent tools.
70
+ *
71
+ * Abstracts filesystem and process operations so tools work identically
72
+ * whether running locally, in Docker, over SSH, or in any other environment.
73
+ */
74
+ interface ToolHost {
75
+ /** Human-readable host identifier (e.g. "local", "docker:my-container"). */
76
+ readonly name: string;
77
+ /** Read a file as a UTF-8 string. Throws if the file doesn't exist. */
78
+ readFile(path: string): Promise<string>;
79
+ /** Read raw bytes from a file. Throws if the file doesn't exist. */
80
+ readBytes(path: string, offset: number, length: number): Promise<Buffer>;
81
+ /** Write a UTF-8 string to a file. Creates parent directories as needed. */
82
+ writeFile(path: string, content: string): Promise<void>;
83
+ /** Check if a path exists. Never throws. */
84
+ exists(path: string): Promise<boolean>;
85
+ /** Get file metadata. Throws if the path doesn't exist. */
86
+ stat(path: string): Promise<FileStat>;
87
+ /** List directory entries. Throws if the path is not a directory. */
88
+ readdir(path: string): Promise<DirEntry[]>;
89
+ /** Create directories recursively. No-op if they already exist. */
90
+ mkdir(path: string): Promise<void>;
91
+ /**
92
+ * Execute a shell command.
93
+ *
94
+ * The host decides which shell to use (e.g. local host uses the user's
95
+ * `$SHELL`, Docker host uses `docker exec`, SSH host uses remote shell).
96
+ */
97
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
98
+ }
99
+
100
+ export type { DirEntry as D, ExecOptions as E, FileStat as F, ToolHost as T, ExecResult as a };
@@ -0,0 +1,335 @@
1
+ import { LanguageModel, TelemetrySettings, ModelMessage, ToolSet } from 'ai';
2
+ import { T as Tool } from './tool-Db1Ue-1U.js';
3
+ import { T as ToolHost } from './types-CHiPh8U2.js';
4
+ import { f as StepProcessingResult, A as AgentEvent, g as AgentTurnBoundaryKind, d as StreamProvider, M as MiddlewareRunner } from './runner-DSKaEz3z.js';
5
+ import { g as InterventionController, T as ToolExecutionMode, I as InferenceStreamInput } from './types-FRpzzg_9.js';
6
+ import { R as ReasoningLevel } from './types-CQaXbRsS.js';
7
+ import { N as NormalizedToolReplayPolicy, d as TurnTrackerContext } from './tool-HUtkiVBx.js';
8
+ import { T as TokenUsage, M as Message } from './messages-BYWGn8TY.js';
9
+
10
+ /**
11
+ * Doom-loop handling contracts for repeated tool invocations.
12
+ */
13
+ /**
14
+ * Response from a doom-loop handler.
15
+ */
16
+ type DoomLoopAction = "allow" | "deny" | "remember";
17
+ /**
18
+ * Doom-loop detection request.
19
+ */
20
+ interface DoomLoopRequest {
21
+ /** The tool being called repeatedly */
22
+ tool: string;
23
+ /** How many times it has been called with the same input */
24
+ repeatCount: number;
25
+ /** The repeated input */
26
+ input: unknown;
27
+ /** Session ID */
28
+ sessionId: string;
29
+ }
30
+ /**
31
+ * Handler for doom-loop situations.
32
+ */
33
+ type DoomLoopHandler = (request: DoomLoopRequest) => Promise<DoomLoopAction>;
34
+
35
+ /**
36
+ * Options for processing a streamed model result.
37
+ */
38
+ interface StepProcessingOptions {
39
+ /** Session ID (optional - for tracking purposes) */
40
+ sessionID?: string;
41
+ /** Abort signal */
42
+ abort: AbortSignal;
43
+ /** Event callback */
44
+ onEvent: (event: AgentEvent) => void | Promise<void>;
45
+ /** Doom loop threshold (default: 3) */
46
+ doomLoopThreshold?: number;
47
+ /** Enforce doom loop (throw error vs warn) when no handler is provided */
48
+ enforceDoomLoop?: boolean;
49
+ /**
50
+ * Handler for doom loop detection.
51
+ * Allows user choice: allow, deny, or remember.
52
+ */
53
+ onDoomLoop?: DoomLoopHandler;
54
+ /** Tools that are "remembered" (allowed without asking) */
55
+ rememberedDoomLoopTools?: Set<string>;
56
+ /** Token limit for context overflow detection */
57
+ contextTokenLimit?: number;
58
+ /** Callback for context overflow */
59
+ onContextOverflow?: (tokens: number, limit: number) => void | Promise<void>;
60
+ /** Current step number */
61
+ currentStep?: number;
62
+ /** Max steps */
63
+ maxSteps?: number;
64
+ }
65
+ /**
66
+ * Result of stream processing.
67
+ */
68
+ interface StepProcessingOutput {
69
+ /** Processing result */
70
+ result: StepProcessingResult;
71
+ /** Accumulated text */
72
+ text: string;
73
+ /** Tool results */
74
+ toolResults: Array<{
75
+ toolName: string;
76
+ toolCallId: string;
77
+ result: unknown;
78
+ }>;
79
+ /** Final usage */
80
+ usage?: TokenUsage;
81
+ /** Finish reason reported by the most recent completed step */
82
+ finishReason?: string;
83
+ /** Error if any */
84
+ error?: Error;
85
+ }
86
+ /**
87
+ * @deprecated Use `StepProcessingOptions`.
88
+ */
89
+ type ProcessorOptions = StepProcessingOptions;
90
+ /**
91
+ * @deprecated Use `StepProcessingOutput`.
92
+ */
93
+ type ProcessorOutput = StepProcessingOutput;
94
+
95
+ interface AgentTurnEngineOptions {
96
+ sessionId: string;
97
+ startedAt: string;
98
+ getToolReplayPolicy?: (toolName: string) => NormalizedToolReplayPolicy | undefined;
99
+ }
100
+ interface AgentTurnBoundaryMetadata {
101
+ step?: number;
102
+ messageRole?: Message["role"];
103
+ pendingToolCallCount?: number;
104
+ }
105
+ interface AgentTurnStepCommitToolCall {
106
+ toolCallId: string;
107
+ toolName: string;
108
+ args: unknown;
109
+ replayPolicy?: NormalizedToolReplayPolicy;
110
+ }
111
+ interface AgentTurnStepCommitToolResult {
112
+ toolCallId: string;
113
+ toolName: string;
114
+ result: unknown;
115
+ replayPolicy?: NormalizedToolReplayPolicy;
116
+ }
117
+ interface AgentTurnStepCommitSnapshot {
118
+ toolCalls: AgentTurnStepCommitToolCall[];
119
+ toolResults: AgentTurnStepCommitToolResult[];
120
+ }
121
+ interface CreateAgentTurnStepCommitBatchOptions {
122
+ assistantMessageId?: string;
123
+ toolMessageIds?: Record<string, string>;
124
+ createdAt?: Date;
125
+ }
126
+ interface AgentTurnCommitBatch {
127
+ startBoundary: AgentEvent & {
128
+ type: "turn-boundary";
129
+ };
130
+ finishBoundary: AgentEvent & {
131
+ type: "turn-boundary";
132
+ };
133
+ messages: Message[];
134
+ }
135
+ interface AgentTurnOutputCommitOptions {
136
+ text: string;
137
+ usage?: TokenUsage;
138
+ createdAt?: Date;
139
+ id?: string;
140
+ }
141
+ type AgentTurnBoundaryEvent = AgentEvent & {
142
+ type: "turn-boundary";
143
+ };
144
+
145
+ type AgentTurnPhase = "initializing" | "committing-input" | "running-model" | "running-tools" | "committing-step" | "committing-output" | "completed" | "failed";
146
+ interface AgentTurnBoundarySnapshot {
147
+ kind: AgentTurnBoundaryKind;
148
+ createdAt: string;
149
+ step?: number;
150
+ messageRole?: "system" | "user" | "assistant" | "tool";
151
+ pendingToolCallCount?: number;
152
+ }
153
+ interface AgentTurnActiveToolCall {
154
+ toolCallId: string;
155
+ toolName: string;
156
+ input: unknown;
157
+ startedAt: string;
158
+ replayPolicy?: NormalizedToolReplayPolicy;
159
+ }
160
+ interface AgentTurnResolvedToolCall {
161
+ toolCallId: string;
162
+ toolName: string;
163
+ outcome: "result" | "error";
164
+ value: unknown;
165
+ resolvedAt: string;
166
+ replayPolicy?: NormalizedToolReplayPolicy;
167
+ }
168
+ /**
169
+ * Neutral state model for a single in-flight agent turn.
170
+ *
171
+ * This is intentionally infrastructure-agnostic. Runtime adapters can persist
172
+ * or inspect it without coupling `agent-core` to Dapr, queues, or workflow
173
+ * engines. The current shape is suitable for durable tracking and forms the
174
+ * basis for future workflow-level resume support.
175
+ */
176
+ interface AgentTurnState {
177
+ sessionId: string;
178
+ phase: AgentTurnPhase;
179
+ step: number;
180
+ maxSteps?: number;
181
+ response: string;
182
+ usage: TokenUsage;
183
+ eventCount: number;
184
+ activeToolCalls: AgentTurnActiveToolCall[];
185
+ resolvedToolCalls: AgentTurnResolvedToolCall[];
186
+ lastFinishReason?: string;
187
+ lastBoundary?: AgentTurnBoundarySnapshot;
188
+ lastEvent?: AgentEvent;
189
+ error?: string;
190
+ startedAt: string;
191
+ updatedAt: string;
192
+ }
193
+ interface CreateAgentTurnStateOptions {
194
+ sessionId: string;
195
+ startedAt: string;
196
+ }
197
+ interface AgentTurnStateAdvanceOptions {
198
+ toolReplayPolicy?: NormalizedToolReplayPolicy;
199
+ }
200
+ /**
201
+ * Create the initial neutral state for a single agent turn.
202
+ */
203
+ declare function createAgentTurnState(options: CreateAgentTurnStateOptions): AgentTurnState;
204
+ /**
205
+ * Advance neutral turn state from a streamed `AgentEvent`.
206
+ *
207
+ * This reducer deliberately models coarse but deterministic boundaries:
208
+ * step start, tool activity, step finish, completion, and failure. Runtime
209
+ * adapters can persist the resulting state now, and future resume-capable
210
+ * engines can build on the same state transitions.
211
+ */
212
+ declare function advanceAgentTurnState(state: AgentTurnState, event: AgentEvent, updatedAt: string, options?: AgentTurnStateAdvanceOptions): AgentTurnState;
213
+ /**
214
+ * Mark the turn as failed when execution aborts without a terminal `error`
215
+ * event. This covers exceptions thrown by the stream itself or runtime
216
+ * wrappers around the loop.
217
+ */
218
+ declare function failAgentTurnState(state: AgentTurnState, error: Error, updatedAt: string): AgentTurnState;
219
+
220
+ /**
221
+ * Neutral internal turn engine for one in-flight agent turn.
222
+ */
223
+ declare class AgentTurnEngine {
224
+ private turnState;
225
+ private readonly pendingToolCalls;
226
+ private readonly pendingToolResults;
227
+ private readonly getToolReplayPolicy?;
228
+ constructor(options: AgentTurnEngineOptions);
229
+ getState(): AgentTurnState;
230
+ hasPendingToolCalls(): boolean;
231
+ createStepCommitSnapshot(): AgentTurnStepCommitSnapshot | undefined;
232
+ recordEvent(event: AgentEvent, updatedAt: string): AgentTurnState;
233
+ createBoundaryEvent(boundary: AgentTurnBoundaryKind, metadata?: AgentTurnBoundaryMetadata): AgentTurnBoundaryEvent;
234
+ createInputCommit(options: {
235
+ content: string;
236
+ system?: string;
237
+ createdAt?: Date;
238
+ id?: string;
239
+ }): AgentTurnCommitBatch;
240
+ createInterventionCommit(options: {
241
+ id: string;
242
+ content: string;
243
+ createdAt?: Date;
244
+ }): AgentTurnCommitBatch;
245
+ consumeStepCommit(step: number): AgentTurnCommitBatch | undefined;
246
+ createOutputCommit(options: AgentTurnOutputCommitOptions): AgentTurnCommitBatch | undefined;
247
+ }
248
+ declare function createAgentTurnEngine(options: AgentTurnEngineOptions): AgentTurnEngine;
249
+
250
+ interface AgentTurnCommitOptions {
251
+ emitMessages?: boolean;
252
+ }
253
+ type AgentTurnCommitApplier = (batch: AgentTurnCommitBatch, options?: AgentTurnCommitOptions) => AsyncGenerator<AgentEvent>;
254
+ interface AgentTurnStepRuntimeConfig {
255
+ model: LanguageModel;
256
+ cwd: string;
257
+ temperature?: number;
258
+ topP?: number;
259
+ maxOutputTokens?: number;
260
+ maxSteps: number;
261
+ doomLoopThreshold?: number;
262
+ enforceDoomLoop?: boolean;
263
+ onDoomLoop?: DoomLoopHandler;
264
+ contextWindow?: number;
265
+ streamProvider?: StreamProvider;
266
+ telemetry?: TelemetrySettings;
267
+ }
268
+ interface PrepareModelStepOptions {
269
+ sessionId: string;
270
+ step: number;
271
+ systemPrompts: string[];
272
+ messages: Message[];
273
+ toModelMessages: (messages: Message[]) => ModelMessage[];
274
+ abort: AbortSignal;
275
+ tools: Record<string, Tool.Info>;
276
+ mcpTools?: ToolSet;
277
+ config: AgentTurnStepRuntimeConfig;
278
+ host?: ToolHost;
279
+ turnTracker?: TurnTrackerContext;
280
+ intervention?: InterventionController;
281
+ middleware?: MiddlewareRunner;
282
+ reasoningLevel?: ReasoningLevel;
283
+ toolExecutionMode?: ToolExecutionMode;
284
+ }
285
+ interface PreparedAgentModelStep {
286
+ step: number;
287
+ messages: Message[];
288
+ modelMessages: ModelMessage[];
289
+ inferenceInput: InferenceStreamInput;
290
+ stepProcessing: {
291
+ maxSteps: number;
292
+ doomLoopThreshold?: number;
293
+ enforceDoomLoop?: boolean;
294
+ onDoomLoop?: DoomLoopHandler;
295
+ contextTokenLimit?: number;
296
+ };
297
+ }
298
+ interface RunModelStepOptions {
299
+ preparedStep: PreparedAgentModelStep;
300
+ turnEngine: AgentTurnEngine;
301
+ applyCommitBatch: AgentTurnCommitApplier;
302
+ rememberedDoomLoopTools?: Set<string>;
303
+ }
304
+ interface CommitStepOptions {
305
+ step: number;
306
+ finishReason?: string;
307
+ turnEngine: AgentTurnEngine;
308
+ applyCommitBatch: AgentTurnCommitApplier;
309
+ }
310
+ interface CommitOutputOptions {
311
+ text: string;
312
+ usage?: StepProcessingOutput["usage"];
313
+ turnEngine: AgentTurnEngine;
314
+ applyCommitBatch: AgentTurnCommitApplier;
315
+ }
316
+ interface RunToolBatchOptions {
317
+ sessionId: string;
318
+ snapshot: AgentTurnStepCommitSnapshot;
319
+ tools: Record<string, Tool.Info>;
320
+ cwd: string;
321
+ abort: AbortSignal;
322
+ host?: ToolHost;
323
+ turnTracker?: TurnTrackerContext;
324
+ middleware?: MiddlewareRunner;
325
+ turnState?: AgentTurnState;
326
+ }
327
+ interface RunToolBatchResult {
328
+ snapshot: AgentTurnStepCommitSnapshot;
329
+ turnState?: AgentTurnState;
330
+ events: Array<Extract<AgentEvent, {
331
+ type: "tool-result" | "tool-error";
332
+ }>>;
333
+ }
334
+
335
+ export { type AgentTurnActiveToolCall as A, advanceAgentTurnState as B, type CommitOutputOptions as C, type DoomLoopAction as D, createAgentTurnEngine as E, createAgentTurnState as F, failAgentTurnState as G, type PrepareModelStepOptions as P, type RunModelStepOptions as R, type StepProcessingOptions as S, type AgentTurnBoundaryMetadata as a, type AgentTurnBoundarySnapshot as b, type AgentTurnCommitApplier as c, type AgentTurnCommitBatch as d, type AgentTurnCommitOptions as e, AgentTurnEngine as f, type AgentTurnEngineOptions as g, type AgentTurnPhase as h, type AgentTurnResolvedToolCall as i, type AgentTurnState as j, type AgentTurnStateAdvanceOptions as k, type AgentTurnStepCommitSnapshot as l, type AgentTurnStepCommitToolCall as m, type AgentTurnStepCommitToolResult as n, type AgentTurnStepRuntimeConfig as o, type CommitStepOptions as p, type CreateAgentTurnStateOptions as q, type CreateAgentTurnStepCommitBatchOptions as r, type DoomLoopHandler as s, type DoomLoopRequest as t, type PreparedAgentModelStep as u, type ProcessorOptions as v, type ProcessorOutput as w, type RunToolBatchOptions as x, type RunToolBatchResult as y, type StepProcessingOutput as z };