@cuylabs/agent-core 0.6.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 +5 -1
  2. package/dist/{builder-BKkipazh.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-3C4VKG4P.js → chunk-3HNO5SVI.js} +273 -807
  5. package/dist/chunk-5K7AQVOU.js +619 -0
  6. package/dist/{chunk-QAQADS4X.js → chunk-BNSHUWCV.js} +1 -0
  7. package/dist/{chunk-O2ZCFQL6.js → chunk-CDTV2UYU.js} +86 -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-DZQJD_hp.d.ts → index-C33hlD6H.d.ts} +12 -7
  17. package/dist/{index-ipP3_ztp.d.ts → index-CfBGYrpd.d.ts} +121 -2
  18. package/dist/index.d.ts +107 -126
  19. package/dist/index.js +321 -601
  20. package/dist/inference/index.d.ts +59 -0
  21. package/dist/inference/index.js +25 -0
  22. package/dist/middleware/index.d.ts +7 -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 +9 -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-G1wxEgac.d.ts → runner-DSKaEz3z.d.ts} +35 -8
  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 +7 -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-BWo810L_.d.ts +0 -648
@@ -1,648 +0,0 @@
1
- import { StreamTextResult, ToolSet, Output, LanguageModel, ModelMessage, TelemetrySettings } from 'ai';
2
- import { T as Tool } from './tool-pFAnJc5Y.js';
3
- import { d as ToolHost, e as TurnTrackerContext, N as NormalizedToolReplayPolicy } from './tool-DYp6-cC3.js';
4
- import { d as ProcessorResult, A as AgentEvent, S as StreamChunk, e as StreamProvider, M as MiddlewareRunner, f as ModelCallInput, g as AgentTurnBoundaryKind } from './runner-G1wxEgac.js';
5
- import { R as ReasoningLevel } from './types-CQaXbRsS.js';
6
- import { T as TokenUsage, M as Message } from './messages-BYWGn8TY.js';
7
-
8
- /**
9
- * Doom-loop handling contracts for repeated tool invocations.
10
- */
11
- /**
12
- * Response from a doom-loop handler.
13
- */
14
- type DoomLoopAction = "allow" | "deny" | "remember";
15
- /**
16
- * Doom-loop detection request.
17
- */
18
- interface DoomLoopRequest {
19
- /** The tool being called repeatedly */
20
- tool: string;
21
- /** How many times it has been called with the same input */
22
- repeatCount: number;
23
- /** The repeated input */
24
- input: unknown;
25
- /** Session ID */
26
- sessionId: string;
27
- }
28
- /**
29
- * Handler for doom-loop situations.
30
- */
31
- type DoomLoopHandler = (request: DoomLoopRequest) => Promise<DoomLoopAction>;
32
-
33
- /**
34
- * Intervention Controller for @cuylabs/agent-core
35
- *
36
- * Manages mid-turn message injection into running agent turns.
37
- * Uses Vercel AI SDK v6's `prepareStep` hook for zero-overhead
38
- * integration at step boundaries (between LLM calls in a multi-step turn).
39
- *
40
- * Instead of polling a queue after each tool execution, this leverages
41
- * the SDK's native step lifecycle. The
42
- * `prepareStep` callback fires before every LLM call, giving us a
43
- * natural injection point with no custom loop machinery.
44
- *
45
- * Two injection modes:
46
- * - **Immediate**: `intervene(msg)` — injected at the next step boundary
47
- * - **Deferred**: `queueNext(msg)` — held until the turn completes
48
- */
49
- /** A queued intervention message waiting to be applied */
50
- interface PendingIntervention {
51
- /** Unique identifier for tracking */
52
- readonly id: string;
53
- /** The user message to inject */
54
- readonly message: string;
55
- /** When the intervention was created */
56
- readonly createdAt: Date;
57
- }
58
- /**
59
- * Callback fired when an intervention is applied to a step.
60
- *
61
- * The agent uses this to push `intervention-applied` events into
62
- * the streaming event queue so they reach the consumer in the
63
- * correct order relative to other events.
64
- */
65
- type OnInterventionApplied = (intervention: PendingIntervention) => void;
66
- /**
67
- * Manages mid-turn message injection for agents.
68
- *
69
- * This is the core primitive that connects user redirection intent
70
- * to the AI SDK's multi-step loop. The flow:
71
- *
72
- * 1. Consumer calls `agent.intervene("focus on auth.ts")` from any async context
73
- * 2. The message is queued as a `PendingIntervention`
74
- * 3. At the next step boundary, `prepareStep` drains the queue
75
- * 4. The message is appended to the LLM's input messages
76
- * 5. The LLM responds to the redirect naturally
77
- *
78
- * Thread safety: All operations are synchronous and run on the
79
- * same event loop. No locks needed — Node.js guarantees ordering.
80
- *
81
- * @example
82
- * ```typescript
83
- * const ctrl = new InterventionController();
84
- *
85
- * // Queue an intervention (from a UI handler, WebSocket, etc.)
86
- * const id = ctrl.intervene("stop refactoring, fix the failing test first");
87
- *
88
- * // Later, in prepareStep:
89
- * const pending = ctrl.drainImmediate();
90
- * // → [{ id, message: "stop refactoring...", createdAt }]
91
- * ```
92
- */
93
- declare class InterventionController {
94
- /** Immediate interventions — applied at the next step boundary */
95
- private immediate;
96
- /** Deferred messages — held until the turn completes */
97
- private deferred;
98
- /**
99
- * Callback fired when an intervention is wired into a step.
100
- * Set by the Agent before starting a chat turn, cleared after.
101
- */
102
- onApplied?: OnInterventionApplied;
103
- /**
104
- * Inject a message at the next LLM step boundary.
105
- *
106
- * The message is appended as a user message to the conversation
107
- * before the next LLM call in the current multi-step turn. The
108
- * LLM will see it and can adjust its behavior accordingly.
109
- *
110
- * Safe to call from any async context while `chat()` is running.
111
- * If called when no turn is active, the message will be picked up
112
- * by the first step of the next `chat()` call.
113
- *
114
- * @param message - The user message to inject
115
- * @returns Intervention ID for tracking
116
- */
117
- intervene(message: string): string;
118
- /**
119
- * Drain and return all pending immediate interventions.
120
- * The internal queue is cleared atomically.
121
- *
122
- * @internal Called by the LLM stream's `prepareStep` hook
123
- */
124
- drainImmediate(): PendingIntervention[];
125
- /** Whether there are pending immediate interventions */
126
- get hasPending(): boolean;
127
- /** Number of pending immediate interventions */
128
- get pendingCount(): number;
129
- /**
130
- * Queue a message for after the current turn completes.
131
- *
132
- * Unlike `intervene()`, this does **not** inject mid-turn. The
133
- * message is held and available via `drainDeferred()` after
134
- * `chat()` finishes. The consumer decides whether to send it
135
- * as a new turn.
136
- *
137
- * @param message - The message to queue
138
- * @returns Intervention ID for tracking
139
- */
140
- queueNext(message: string): string;
141
- /**
142
- * Drain and return all deferred messages.
143
- * The internal queue is cleared atomically.
144
- */
145
- drainDeferred(): PendingIntervention[];
146
- /** Whether there are deferred messages */
147
- get hasDeferred(): boolean;
148
- /** Number of deferred messages */
149
- get deferredCount(): number;
150
- /** Clear all queues (immediate + deferred) */
151
- clear(): void;
152
- /** Reset the controller for a new turn (clears onApplied, keeps queues) */
153
- resetCallbacks(): void;
154
- }
155
-
156
- /**
157
- * Options for processing a streamed model result.
158
- */
159
- interface ProcessorOptions {
160
- /** Session ID (optional - for tracking purposes) */
161
- sessionID?: string;
162
- /** Abort signal */
163
- abort: AbortSignal;
164
- /** Event callback */
165
- onEvent: (event: AgentEvent) => void | Promise<void>;
166
- /** Doom loop threshold (default: 3) */
167
- doomLoopThreshold?: number;
168
- /** Enforce doom loop (throw error vs warn) when no handler is provided */
169
- enforceDoomLoop?: boolean;
170
- /**
171
- * Handler for doom loop detection.
172
- * Allows user choice: allow, deny, or remember.
173
- */
174
- onDoomLoop?: DoomLoopHandler;
175
- /** Tools that are "remembered" (allowed without asking) */
176
- rememberedDoomLoopTools?: Set<string>;
177
- /** Token limit for context overflow detection */
178
- contextTokenLimit?: number;
179
- /** Callback for context overflow */
180
- onContextOverflow?: (tokens: number, limit: number) => void | Promise<void>;
181
- /** Current step number */
182
- currentStep?: number;
183
- /** Max steps */
184
- maxSteps?: number;
185
- }
186
- /**
187
- * Result of stream processing.
188
- */
189
- interface ProcessorOutput {
190
- /** Processing result */
191
- result: ProcessorResult;
192
- /** Accumulated text */
193
- text: string;
194
- /** Tool results */
195
- toolResults: Array<{
196
- toolName: string;
197
- toolCallId: string;
198
- result: unknown;
199
- }>;
200
- /** Final usage */
201
- usage?: TokenUsage;
202
- /** Finish reason reported by the most recent completed step */
203
- finishReason?: string;
204
- /** Error if any */
205
- error?: Error;
206
- }
207
-
208
- type ErrorCategory = "rate_limit" | "overloaded" | "auth" | "invalid_request" | "context_overflow" | "content_filter" | "network" | "timeout" | "cancelled" | "unknown";
209
- interface ResponseHeaders {
210
- "retry-after"?: string;
211
- "retry-after-ms"?: string;
212
- "x-ratelimit-remaining"?: string;
213
- "x-ratelimit-reset"?: string;
214
- [key: string]: string | undefined;
215
- }
216
- interface LLMErrorOptions {
217
- message: string;
218
- category?: ErrorCategory;
219
- status?: number;
220
- headers?: ResponseHeaders;
221
- cause?: Error;
222
- provider?: string;
223
- model?: string;
224
- }
225
-
226
- declare class LLMError extends Error {
227
- readonly category: ErrorCategory;
228
- readonly status?: number;
229
- readonly headers?: ResponseHeaders;
230
- readonly provider?: string;
231
- readonly model?: string;
232
- readonly isRetryable: boolean;
233
- readonly retryDelayMs?: number;
234
- constructor(options: LLMErrorOptions);
235
- static from(error: unknown, context?: Partial<LLMErrorOptions>): LLMError;
236
- get description(): string;
237
- }
238
-
239
- /**
240
- * Retry logic with exponential backoff for @cuylabs/agent-core
241
- *
242
- * Provides configurable retry behavior with header-aware delays,
243
- * exponential backoff, and abort signal support.
244
- */
245
-
246
- /**
247
- * Retry configuration
248
- */
249
- interface RetryConfig {
250
- /** Maximum number of retry attempts (default: 3) */
251
- maxAttempts?: number;
252
- /** Initial delay in ms (default: 2000) */
253
- initialDelayMs?: number;
254
- /** Backoff multiplier (default: 2) */
255
- backoffFactor?: number;
256
- /** Maximum delay without headers in ms (default: 30000) */
257
- maxDelayMs?: number;
258
- /** Whether to jitter delays (default: true) */
259
- jitter?: boolean;
260
- /** Callback when retrying */
261
- onRetry?: (attempt: number, delayMs: number, error: LLMError) => void;
262
- }
263
- /**
264
- * Default retry configuration
265
- */
266
- declare const DEFAULT_RETRY_CONFIG: Required<Omit<RetryConfig, "onRetry">>;
267
- /**
268
- * Tracks retry state across attempts
269
- */
270
- interface RetryState {
271
- /** Current attempt number (1-indexed) */
272
- attempt: number;
273
- /** Total errors encountered */
274
- errors: LLMError[];
275
- /** Whether more retries are available */
276
- canRetry: boolean;
277
- /** Delay until next retry (if applicable) */
278
- nextDelayMs?: number;
279
- }
280
- /**
281
- * Creates initial retry state
282
- */
283
- declare function createRetryState(): RetryState;
284
- /**
285
- * Calculate delay for a retry attempt
286
- */
287
- declare function calculateDelay(attempt: number, error: LLMError | undefined, config: Required<Omit<RetryConfig, "onRetry">>): number;
288
- /**
289
- * Sleep for a duration, respecting abort signal
290
- */
291
- declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
292
- /**
293
- * Execute a function with retry logic
294
- */
295
- declare function withRetry<T>(fn: (attempt: number) => Promise<T>, config?: RetryConfig, signal?: AbortSignal): Promise<T>;
296
- /**
297
- * Options for retry handler
298
- */
299
- interface RetryHandlerOptions extends RetryConfig {
300
- /** Abort signal */
301
- signal?: AbortSignal;
302
- }
303
- /**
304
- * Creates a retry handler that wraps stream creation
305
- */
306
- declare function createRetryHandler(options?: RetryHandlerOptions): <T>(createStream: (attempt: number) => Promise<T>) => Promise<T>;
307
- /**
308
- * Checks if more retries should be attempted
309
- */
310
- declare function shouldRetry(error: unknown, attempt: number, maxAttempts?: number): boolean;
311
-
312
- /** Stream result type - uses default Output for text streaming. */
313
- type LLMStreamResult = StreamTextResult<ToolSet, Output.Output<string, string, never>>;
314
-
315
- /**
316
- * Custom stream result type - compatible shape from external providers.
317
- */
318
- type CustomStreamResult = {
319
- fullStream: AsyncIterable<StreamChunk>;
320
- text: Promise<string>;
321
- usage: Promise<{
322
- inputTokens: number;
323
- outputTokens: number;
324
- totalTokens: number;
325
- }>;
326
- finishReason: Promise<string>;
327
- };
328
- /** Union type for stream results - either AI SDK or custom. */
329
- type AnyStreamResult = LLMStreamResult | CustomStreamResult;
330
- /** Default max output tokens. */
331
- declare const OUTPUT_TOKEN_MAX = 32000;
332
- /**
333
- * @deprecated Use StreamProvider from types instead.
334
- */
335
- type CustomStreamProvider = StreamProvider;
336
- /** Control whether AI SDK tool definitions auto-execute or only expose calls. */
337
- type ToolExecutionMode = "auto" | "plan";
338
- /**
339
- * Input for LLM stream creation.
340
- */
341
- interface LLMStreamInput {
342
- /** Session ID */
343
- sessionID: string;
344
- /** Step number within the current turn */
345
- step?: number;
346
- /** Model to use */
347
- model: LanguageModel;
348
- /** System prompt parts */
349
- system: string[];
350
- /** Messages to send */
351
- messages: ModelMessage[];
352
- /** Abort signal */
353
- abort: AbortSignal;
354
- /** Tools to use */
355
- tools: Record<string, Tool.Info>;
356
- /** Whether tools should auto-execute or only be surfaced as tool calls. */
357
- toolExecutionMode?: ToolExecutionMode;
358
- /** Working directory */
359
- cwd: string;
360
- /** Execution environment for tools */
361
- host?: ToolHost;
362
- /** Temperature */
363
- temperature?: number;
364
- /** Top-p */
365
- topP?: number;
366
- /** Max output tokens */
367
- maxOutputTokens?: number;
368
- /** Max steps (tool iterations) */
369
- maxSteps?: number;
370
- /** Reasoning level for extended-thinking models */
371
- reasoningLevel?: ReasoningLevel;
372
- /** Retry configuration */
373
- retry?: RetryConfig;
374
- /** Callback for step completion */
375
- onStepFinish?: (step: StepInfo) => void | Promise<void>;
376
- /** Custom stream provider */
377
- customStreamProvider?: StreamProvider;
378
- /** Turn tracker for automatic file baseline capture */
379
- turnTracker?: TurnTrackerContext;
380
- /** Pre-built MCP tools */
381
- mcpTools?: ToolSet;
382
- /** Intervention controller for mid-turn message injection */
383
- intervention?: InterventionController;
384
- /** Middleware runner for lifecycle hooks */
385
- middleware?: MiddlewareRunner;
386
- /** AI SDK telemetry settings */
387
- telemetry?: TelemetrySettings;
388
- /** Internal snapshot of the resolved model request after middleware input hooks. */
389
- activeModelCall?: ModelCallInput;
390
- }
391
- /**
392
- * Step information surfaced to callers.
393
- */
394
- interface StepInfo {
395
- toolResults?: Array<{
396
- toolName: string;
397
- toolCallId: string;
398
- output: unknown;
399
- }>;
400
- usage?: {
401
- inputTokens?: number;
402
- outputTokens?: number;
403
- totalTokens?: number;
404
- };
405
- finishReason?: string;
406
- }
407
-
408
- interface AgentTurnEngineOptions {
409
- sessionId: string;
410
- startedAt: string;
411
- getToolReplayPolicy?: (toolName: string) => NormalizedToolReplayPolicy | undefined;
412
- }
413
- interface AgentTurnBoundaryMetadata {
414
- step?: number;
415
- messageRole?: Message["role"];
416
- pendingToolCallCount?: number;
417
- }
418
- interface AgentTurnStepCommitToolCall {
419
- toolCallId: string;
420
- toolName: string;
421
- args: unknown;
422
- replayPolicy?: NormalizedToolReplayPolicy;
423
- }
424
- interface AgentTurnStepCommitToolResult {
425
- toolCallId: string;
426
- toolName: string;
427
- result: unknown;
428
- replayPolicy?: NormalizedToolReplayPolicy;
429
- }
430
- interface AgentTurnStepCommitSnapshot {
431
- toolCalls: AgentTurnStepCommitToolCall[];
432
- toolResults: AgentTurnStepCommitToolResult[];
433
- }
434
- interface CreateAgentTurnStepCommitBatchOptions {
435
- assistantMessageId?: string;
436
- toolMessageIds?: Record<string, string>;
437
- createdAt?: Date;
438
- }
439
- interface AgentTurnCommitBatch {
440
- startBoundary: AgentEvent & {
441
- type: "turn-boundary";
442
- };
443
- finishBoundary: AgentEvent & {
444
- type: "turn-boundary";
445
- };
446
- messages: Message[];
447
- }
448
- interface AgentTurnOutputCommitOptions {
449
- text: string;
450
- usage?: TokenUsage;
451
- createdAt?: Date;
452
- id?: string;
453
- }
454
- type AgentTurnBoundaryEvent = AgentEvent & {
455
- type: "turn-boundary";
456
- };
457
-
458
- type AgentTurnPhase = "initializing" | "committing-input" | "running-model" | "running-tools" | "committing-step" | "committing-output" | "completed" | "failed";
459
- interface AgentTurnBoundarySnapshot {
460
- kind: AgentTurnBoundaryKind;
461
- createdAt: string;
462
- step?: number;
463
- messageRole?: "system" | "user" | "assistant" | "tool";
464
- pendingToolCallCount?: number;
465
- }
466
- interface AgentTurnActiveToolCall {
467
- toolCallId: string;
468
- toolName: string;
469
- input: unknown;
470
- startedAt: string;
471
- replayPolicy?: NormalizedToolReplayPolicy;
472
- }
473
- interface AgentTurnResolvedToolCall {
474
- toolCallId: string;
475
- toolName: string;
476
- outcome: "result" | "error";
477
- value: unknown;
478
- resolvedAt: string;
479
- replayPolicy?: NormalizedToolReplayPolicy;
480
- }
481
- /**
482
- * Neutral state model for a single in-flight agent turn.
483
- *
484
- * This is intentionally infrastructure-agnostic. Runtime adapters can persist
485
- * or inspect it without coupling `agent-core` to Dapr, queues, or workflow
486
- * engines. The current shape is suitable for durable tracking and forms the
487
- * basis for future workflow-level resume support.
488
- */
489
- interface AgentTurnState {
490
- sessionId: string;
491
- phase: AgentTurnPhase;
492
- step: number;
493
- maxSteps?: number;
494
- response: string;
495
- usage: TokenUsage;
496
- eventCount: number;
497
- activeToolCalls: AgentTurnActiveToolCall[];
498
- resolvedToolCalls: AgentTurnResolvedToolCall[];
499
- lastFinishReason?: string;
500
- lastBoundary?: AgentTurnBoundarySnapshot;
501
- lastEvent?: AgentEvent;
502
- error?: string;
503
- startedAt: string;
504
- updatedAt: string;
505
- }
506
- interface CreateAgentTurnStateOptions {
507
- sessionId: string;
508
- startedAt: string;
509
- }
510
- interface AgentTurnStateAdvanceOptions {
511
- toolReplayPolicy?: NormalizedToolReplayPolicy;
512
- }
513
- /**
514
- * Create the initial neutral state for a single agent turn.
515
- */
516
- declare function createAgentTurnState(options: CreateAgentTurnStateOptions): AgentTurnState;
517
- /**
518
- * Advance neutral turn state from a streamed `AgentEvent`.
519
- *
520
- * This reducer deliberately models coarse but deterministic boundaries:
521
- * step start, tool activity, step finish, completion, and failure. Runtime
522
- * adapters can persist the resulting state now, and future resume-capable
523
- * engines can build on the same state transitions.
524
- */
525
- declare function advanceAgentTurnState(state: AgentTurnState, event: AgentEvent, updatedAt: string, options?: AgentTurnStateAdvanceOptions): AgentTurnState;
526
- /**
527
- * Mark the turn as failed when execution aborts without a terminal `error`
528
- * event. This covers exceptions thrown by the stream itself or runtime
529
- * wrappers around the loop.
530
- */
531
- declare function failAgentTurnState(state: AgentTurnState, error: Error, updatedAt: string): AgentTurnState;
532
-
533
- /**
534
- * Neutral internal turn engine for one in-flight agent turn.
535
- */
536
- declare class AgentTurnEngine {
537
- private turnState;
538
- private readonly pendingToolCalls;
539
- private readonly pendingToolResults;
540
- private readonly getToolReplayPolicy?;
541
- constructor(options: AgentTurnEngineOptions);
542
- getState(): AgentTurnState;
543
- hasPendingToolCalls(): boolean;
544
- createStepCommitSnapshot(): AgentTurnStepCommitSnapshot | undefined;
545
- recordEvent(event: AgentEvent, updatedAt: string): AgentTurnState;
546
- createBoundaryEvent(boundary: AgentTurnBoundaryKind, metadata?: AgentTurnBoundaryMetadata): AgentTurnBoundaryEvent;
547
- createInputCommit(options: {
548
- content: string;
549
- system?: string;
550
- createdAt?: Date;
551
- id?: string;
552
- }): AgentTurnCommitBatch;
553
- createInterventionCommit(options: {
554
- id: string;
555
- content: string;
556
- createdAt?: Date;
557
- }): AgentTurnCommitBatch;
558
- consumeStepCommit(step: number): AgentTurnCommitBatch | undefined;
559
- createOutputCommit(options: AgentTurnOutputCommitOptions): AgentTurnCommitBatch | undefined;
560
- }
561
- declare function createAgentTurnEngine(options: AgentTurnEngineOptions): AgentTurnEngine;
562
-
563
- interface AgentTurnCommitOptions {
564
- emitMessages?: boolean;
565
- }
566
- type AgentTurnCommitApplier = (batch: AgentTurnCommitBatch, options?: AgentTurnCommitOptions) => AsyncGenerator<AgentEvent>;
567
- interface AgentTurnStepRuntimeConfig {
568
- model: LanguageModel;
569
- cwd: string;
570
- temperature?: number;
571
- topP?: number;
572
- maxOutputTokens?: number;
573
- maxSteps: number;
574
- doomLoopThreshold?: number;
575
- enforceDoomLoop?: boolean;
576
- onDoomLoop?: DoomLoopHandler;
577
- contextWindow?: number;
578
- streamProvider?: StreamProvider;
579
- telemetry?: TelemetrySettings;
580
- }
581
- interface PrepareModelStepOptions {
582
- sessionId: string;
583
- step: number;
584
- systemPrompts: string[];
585
- messages: Message[];
586
- toModelMessages: (messages: Message[]) => ModelMessage[];
587
- abort: AbortSignal;
588
- tools: Record<string, Tool.Info>;
589
- mcpTools?: ToolSet;
590
- config: AgentTurnStepRuntimeConfig;
591
- host?: ToolHost;
592
- turnTracker?: TurnTrackerContext;
593
- intervention?: InterventionController;
594
- middleware?: MiddlewareRunner;
595
- reasoningLevel?: ReasoningLevel;
596
- toolExecutionMode?: ToolExecutionMode;
597
- }
598
- interface PreparedAgentModelStep {
599
- step: number;
600
- messages: Message[];
601
- modelMessages: ModelMessage[];
602
- llmInput: LLMStreamInput;
603
- processor: {
604
- maxSteps: number;
605
- doomLoopThreshold?: number;
606
- enforceDoomLoop?: boolean;
607
- onDoomLoop?: DoomLoopHandler;
608
- contextTokenLimit?: number;
609
- };
610
- }
611
- interface RunModelStepOptions {
612
- preparedStep: PreparedAgentModelStep;
613
- turnEngine: AgentTurnEngine;
614
- applyCommitBatch: AgentTurnCommitApplier;
615
- rememberedDoomLoopTools?: Set<string>;
616
- }
617
- interface CommitStepOptions {
618
- step: number;
619
- finishReason?: string;
620
- turnEngine: AgentTurnEngine;
621
- applyCommitBatch: AgentTurnCommitApplier;
622
- }
623
- interface CommitOutputOptions {
624
- text: string;
625
- usage?: ProcessorOutput["usage"];
626
- turnEngine: AgentTurnEngine;
627
- applyCommitBatch: AgentTurnCommitApplier;
628
- }
629
- interface RunToolBatchOptions {
630
- sessionId: string;
631
- snapshot: AgentTurnStepCommitSnapshot;
632
- tools: Record<string, Tool.Info>;
633
- cwd: string;
634
- abort: AbortSignal;
635
- host?: ToolHost;
636
- turnTracker?: TurnTrackerContext;
637
- middleware?: MiddlewareRunner;
638
- turnState?: AgentTurnState;
639
- }
640
- interface RunToolBatchResult {
641
- snapshot: AgentTurnStepCommitSnapshot;
642
- turnState?: AgentTurnState;
643
- events: Array<Extract<AgentEvent, {
644
- type: "tool-result" | "tool-error";
645
- }>>;
646
- }
647
-
648
- export { createRetryHandler as $, type AnyStreamResult as A, type LLMErrorOptions as B, type CommitOutputOptions as C, DEFAULT_RETRY_CONFIG as D, type ErrorCategory as E, type LLMStreamResult as F, type OnInterventionApplied as G, type PendingIntervention as H, InterventionController as I, type PrepareModelStepOptions as J, type PreparedAgentModelStep as K, type LLMStreamInput as L, type RetryConfig as M, type RetryHandlerOptions as N, OUTPUT_TOKEN_MAX as O, type ProcessorOptions as P, type RetryState as Q, type ResponseHeaders as R, type RunModelStepOptions as S, type ToolExecutionMode as T, type RunToolBatchOptions as U, type RunToolBatchResult as V, type StepInfo as W, advanceAgentTurnState as X, calculateDelay as Y, createAgentTurnEngine as Z, createAgentTurnState as _, type ProcessorOutput as a, createRetryState as a0, failAgentTurnState as a1, shouldRetry as a2, sleep as a3, withRetry as a4, type AgentTurnActiveToolCall as b, type AgentTurnBoundaryMetadata as c, type AgentTurnBoundarySnapshot as d, type AgentTurnCommitApplier as e, type AgentTurnCommitBatch as f, type AgentTurnCommitOptions as g, AgentTurnEngine as h, type AgentTurnEngineOptions as i, type AgentTurnPhase as j, type AgentTurnResolvedToolCall as k, type AgentTurnState as l, type AgentTurnStateAdvanceOptions as m, type AgentTurnStepCommitSnapshot as n, type AgentTurnStepCommitToolCall as o, type AgentTurnStepCommitToolResult as p, type AgentTurnStepRuntimeConfig as q, type CommitStepOptions as r, type CreateAgentTurnStateOptions as s, type CreateAgentTurnStepCommitBatchOptions as t, type CustomStreamProvider as u, type CustomStreamResult as v, type DoomLoopAction as w, type DoomLoopHandler as x, type DoomLoopRequest as y, LLMError as z };