@cuylabs/agent-core 0.7.0 → 0.9.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 (79) hide show
  1. package/dist/{builder-BRvqCcIk.d.ts → builder-BgZ_j4Vs.d.ts} +3 -2
  2. package/dist/chunk-4QFNWPIF.js +202 -0
  3. package/dist/chunk-5ARZJWD2.js +259 -0
  4. package/dist/chunk-DXFBQMXP.js +53 -0
  5. package/dist/chunk-EKR6PKXU.js +180 -0
  6. package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
  7. package/dist/{chunk-IEFIQENH.js → chunk-H3FUYU52.js} +15 -7
  8. package/dist/chunk-I6PKJ7XQ.js +292 -0
  9. package/dist/chunk-IYWQOJMQ.js +102 -0
  10. package/dist/{chunk-3HNO5SVI.js → chunk-J4QDGZIA.js} +20 -4
  11. package/dist/{chunk-7MUFEN4K.js → chunk-JLXG2SH7.js} +349 -3
  12. package/dist/{chunk-CDTV2UYU.js → chunk-MAZ5DY5B.js} +64 -276
  13. package/dist/{chunk-P6YF7USR.js → chunk-MHKK374K.js} +12 -11
  14. package/dist/{chunk-VBWWUHWI.js → chunk-OFDKHNCX.js} +4 -1
  15. package/dist/{chunk-YUUJK53A.js → chunk-RKEW5WXI.js} +1 -1
  16. package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
  17. package/dist/{chunk-QGOGIP7T.js → chunk-UDCZ673N.js} +385 -233
  18. package/dist/{chunk-BDBZ3SLK.js → chunk-UHCJEM2E.js} +39 -2
  19. package/dist/chunk-WGZAPU6N.js +929 -0
  20. package/dist/{chunk-5K7AQVOU.js → chunk-WKHDSSXG.js} +130 -209
  21. package/dist/{chunk-BNSHUWCV.js → chunk-WWYYNWEW.js} +1 -1
  22. package/dist/context/index.js +1 -1
  23. package/dist/events-CE72w8W4.d.ts +149 -0
  24. package/dist/index-BCqEGzBj.d.ts +251 -0
  25. package/dist/{index-C33hlD6H.d.ts → index-DQuTZ8xL.d.ts} +319 -56
  26. package/dist/index.d.ts +42 -121
  27. package/dist/index.js +951 -848
  28. package/dist/inference/errors/index.d.ts +11 -0
  29. package/dist/inference/errors/index.js +16 -0
  30. package/dist/inference/index.d.ts +12 -8
  31. package/dist/inference/index.js +35 -7
  32. package/dist/llm-error-D93FNNLY.d.ts +32 -0
  33. package/dist/middleware/index.d.ts +246 -7
  34. package/dist/middleware/index.js +3 -1
  35. package/dist/models/index.d.ts +132 -9
  36. package/dist/models/index.js +48 -8
  37. package/dist/models/reasoning/index.d.ts +4 -0
  38. package/dist/{reasoning → models/reasoning}/index.js +2 -7
  39. package/dist/plugin/index.d.ts +414 -0
  40. package/dist/plugin/index.js +32 -0
  41. package/dist/presets/index.d.ts +53 -0
  42. package/dist/presets/index.js +30 -0
  43. package/dist/prompt/index.d.ts +11 -8
  44. package/dist/prompt/index.js +3 -2
  45. package/dist/{registry-BDLIHOQB.d.ts → registry-DwYqsQkX.d.ts} +1 -1
  46. package/dist/runner-CI-XeR16.d.ts +91 -0
  47. package/dist/runtime/index.d.ts +12 -8
  48. package/dist/runtime/index.js +8 -7
  49. package/dist/safety/index.d.ts +38 -0
  50. package/dist/safety/index.js +12 -0
  51. package/dist/scope/index.d.ts +2 -2
  52. package/dist/{session-manager-B_CWGTsl.d.ts → session-manager-KbYt2WUh.d.ts} +8 -0
  53. package/dist/signal/index.d.ts +28 -0
  54. package/dist/signal/index.js +6 -0
  55. package/dist/skill/index.d.ts +7 -6
  56. package/dist/skill/index.js +3 -3
  57. package/dist/storage/index.d.ts +2 -2
  58. package/dist/storage/index.js +1 -1
  59. package/dist/sub-agent/index.d.ts +16 -10
  60. package/dist/sub-agent/index.js +21 -4
  61. package/dist/tool/index.d.ts +22 -6
  62. package/dist/tool/index.js +3 -3
  63. package/dist/tool-CZWN3KbO.d.ts +141 -0
  64. package/dist/{tool-HUtkiVBx.d.ts → tool-DkhSCV2Y.d.ts} +2 -2
  65. package/dist/tracking/index.d.ts +2 -2
  66. package/dist/tracking/index.js +1 -1
  67. package/dist/{tool-Db1Ue-1U.d.ts → types-BfNpU8NS.d.ts} +1 -150
  68. package/dist/{types-FRpzzg_9.d.ts → types-BlOKk-Bb.d.ts} +10 -35
  69. package/dist/types-BlZwmnuW.d.ts +50 -0
  70. package/dist/{types-9jGQUjqW.d.ts → types-CQL-SvTn.d.ts} +1 -1
  71. package/dist/types-CWm-7rvB.d.ts +55 -0
  72. package/dist/{runner-DSKaEz3z.d.ts → types-DTSkxakL.d.ts} +7 -235
  73. package/dist/{types-CqDZTh4d.d.ts → types-DmDwi2zI.d.ts} +8 -4
  74. package/dist/types-YuWV4ag7.d.ts +72 -0
  75. package/package.json +67 -6
  76. package/dist/capability-resolver-CgRGsWVX.d.ts +0 -254
  77. package/dist/chunk-ZPMACVZK.js +0 -305
  78. package/dist/index-CfBGYrpd.d.ts +0 -317
  79. package/dist/reasoning/index.d.ts +0 -117
@@ -3,7 +3,7 @@ import {
3
3
  clearCheckpoints,
4
4
  createCheckpointManager,
5
5
  createTurnTracker
6
- } from "../chunk-VBWWUHWI.js";
6
+ } from "../chunk-OFDKHNCX.js";
7
7
  import {
8
8
  extractFilePathsFromArgs,
9
9
  shouldCaptureBaseline,
@@ -1,6 +1,3 @@
1
- import { z } from 'zod';
2
- import { T as ToolMetadata, a as ToolReplayPolicy, b as ToolContext, F as FileOperationMeta, c as ToolResult } from './tool-HUtkiVBx.js';
3
-
4
1
  /**
5
2
  * Skill System Types
6
3
  *
@@ -270,150 +267,4 @@ interface SkillDiscoveryError {
270
267
  reason: string;
271
268
  }
272
269
 
273
- /**
274
- * Tool definition namespace for @cuylabs/agent-core
275
- *
276
- * Provides consistent tool creation via Tool.define.
277
- */
278
-
279
- /**
280
- * A schema type compatible with both Zod 3 and Zod 4.
281
- *
282
- * Uses structural typing so that schemas from either Zod version satisfy
283
- * the constraint. This avoids the problem where Zod 3's `ZodType` class
284
- * and Zod 4's `ZodType` class have incompatible internal shapes, causing
285
- * type errors when a library compiled against one version is consumed with
286
- * the other.
287
- *
288
- * Both Zod 3 and Zod 4 (classic API) schemas have `parse()` and `_output`.
289
- */
290
- interface CompatibleSchema<T = any> {
291
- /** Parse and validate input data. Present in both Zod 3 and Zod 4. */
292
- parse(data: unknown): T;
293
- /**
294
- * Type-level output marker used by both Zod versions:
295
- * - Zod 3: `readonly _output!: T` (definite assignment assertion)
296
- * - Zod 4 classic: `get _output(): T` (getter)
297
- */
298
- readonly _output: T;
299
- }
300
- /**
301
- * Infer the output type from a compatible schema.
302
- * Equivalent to `z.infer<T>` but works with both Zod 3 and Zod 4 schemas.
303
- */
304
- type InferSchemaOutput<T extends CompatibleSchema> = T["_output"];
305
- /**
306
- * Tool namespace - tool definition utilities
307
- */
308
- declare namespace Tool {
309
- /**
310
- * Tool info interface - the shape of a defined tool
311
- */
312
- interface Info<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
313
- /** Unique tool identifier */
314
- id: string;
315
- /** Recovery semantics for resume-capable runtimes. */
316
- replayPolicy?: ToolReplayPolicy;
317
- /** Initialize the tool (can be async for dynamic descriptions) */
318
- init: (ctx?: InitContext) => Promise<InitResult<TParams, TMeta>> | InitResult<TParams, TMeta>;
319
- }
320
- /**
321
- * Any tool info - for use in arrays and collections where generic types vary
322
- */
323
- type AnyInfo = Info<any, any>;
324
- /**
325
- * Context passed during tool initialization
326
- */
327
- interface InitContext {
328
- /** Working directory */
329
- cwd?: string;
330
- /** Agent name (if known) */
331
- agent?: string;
332
- }
333
- /**
334
- * Result of tool initialization
335
- */
336
- interface InitResult<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
337
- /** Tool description for the LLM */
338
- description: string;
339
- /** Zod schema for parameters */
340
- parameters: TParams;
341
- /** Execute the tool */
342
- execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
343
- /** Optional custom validation error formatter */
344
- formatValidationError?: (error: z.ZodError) => string;
345
- /**
346
- * File operation metadata for automatic turn tracking.
347
- * When set, the agent will automatically capture file baselines
348
- * before tool execution for undo/diff capabilities.
349
- *
350
- * @example
351
- * ```typescript
352
- * // For a write tool
353
- * fileOps: {
354
- * pathArgs: ['path'],
355
- * operationType: 'write'
356
- * }
357
- * ```
358
- */
359
- fileOps?: FileOperationMeta;
360
- /** Optional replay metadata for resume-capable runtimes. */
361
- replayPolicy?: ToolReplayPolicy;
362
- }
363
- /**
364
- * Result of tool execution
365
- */
366
- interface ExecuteResult<TMeta extends ToolMetadata = ToolMetadata> {
367
- /** Short title for display */
368
- title: string;
369
- /** Main output text */
370
- output: string;
371
- /** Metadata */
372
- metadata: TMeta;
373
- }
374
- interface DefineOptions {
375
- /** Static replay metadata exposed to higher-level runtimes. */
376
- replayPolicy?: ToolReplayPolicy;
377
- }
378
- /**
379
- * Define a tool with standard patterns
380
- *
381
- * @example
382
- * ```typescript
383
- * const myTool = Tool.define("my_tool", {
384
- * description: "Does something useful",
385
- * parameters: z.object({
386
- * input: z.string().describe("The input to process"),
387
- * }),
388
- * execute: async (params, ctx) => ({
389
- * title: "Processed",
390
- * output: `Result: ${params.input}`,
391
- * metadata: {},
392
- * }),
393
- * });
394
- * ```
395
- */
396
- function define<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, init: Info<TParams, TMeta>["init"] | Awaited<ReturnType<Info<TParams, TMeta>["init"]>>, options?: DefineOptions): Info<TParams, TMeta>;
397
- /**
398
- * Simple define for static tools (no async init)
399
- */
400
- function defineSimple<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, config: {
401
- description: string;
402
- parameters: TParams;
403
- execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
404
- replayPolicy?: ToolReplayPolicy;
405
- }): Info<TParams, TMeta>;
406
- }
407
- /**
408
- * Legacy helper - wraps to Tool.Info format
409
- *
410
- * @deprecated Use Tool.define instead
411
- */
412
- declare function defineTool<TParams extends CompatibleSchema>(definition: {
413
- id: string;
414
- description: string;
415
- parameters: TParams;
416
- execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ToolResult>;
417
- }): Tool.Info<TParams>;
418
-
419
- export { type CompatibleSchema as C, type InferSchemaOutput as I, type RemoteSkillEntry as R, type SkillDiscoveryResult as S, Tool as T, type SkillMetadata as a, type SkillContent as b, type SkillResource as c, type SkillConfig as d, type RemoteSkillIndex as e, type SkillDiscoveryError as f, type SkillResourceType as g, type SkillScope as h, type SkillSource as i, type SkillSourceType as j, defineTool as k };
270
+ export type { RemoteSkillEntry as R, SkillDiscoveryResult as S, SkillMetadata as a, SkillContent as b, SkillResource as c, SkillConfig as d, RemoteSkillIndex as e, SkillDiscoveryError as f, SkillResourceType as g, SkillScope as h, SkillSource as i, SkillSourceType as j };
@@ -1,9 +1,11 @@
1
1
  import { StreamTextResult, ToolSet, Output, LanguageModel, ModelMessage, TelemetrySettings } from 'ai';
2
- import { T as Tool } from './tool-Db1Ue-1U.js';
2
+ import { T as Tool } from './tool-CZWN3KbO.js';
3
3
  import { T as ToolHost } from './types-CHiPh8U2.js';
4
- import { S as StreamChunk, d as StreamProvider, M as MiddlewareRunner, e as ModelCallInput } from './runner-DSKaEz3z.js';
4
+ import { M as MiddlewareRunner } from './runner-CI-XeR16.js';
5
+ import { S as StreamChunk, f as StreamProvider, M as ModelCallInput } from './types-DTSkxakL.js';
5
6
  import { R as ReasoningLevel } from './types-CQaXbRsS.js';
6
- import { d as TurnTrackerContext } from './tool-HUtkiVBx.js';
7
+ import { d as TurnTrackerContext } from './tool-DkhSCV2Y.js';
8
+ import { L as LLMError } from './llm-error-D93FNNLY.js';
7
9
 
8
10
  /**
9
11
  * Intervention Controller for @cuylabs/agent-core
@@ -97,6 +99,8 @@ declare class InterventionController {
97
99
  * @internal Called by the LLM stream's `prepareStep` hook
98
100
  */
99
101
  drainImmediate(): PendingIntervention[];
102
+ /** Adopt existing immediate interventions without changing their IDs. */
103
+ adoptImmediate(items: PendingIntervention[]): void;
100
104
  /** Whether there are pending immediate interventions */
101
105
  get hasPending(): boolean;
102
106
  /** Number of pending immediate interventions */
@@ -118,6 +122,8 @@ declare class InterventionController {
118
122
  * The internal queue is cleared atomically.
119
123
  */
120
124
  drainDeferred(): PendingIntervention[];
125
+ /** Adopt existing deferred interventions without changing their IDs. */
126
+ adoptDeferred(items: PendingIntervention[]): void;
121
127
  /** Whether there are deferred messages */
122
128
  get hasDeferred(): boolean;
123
129
  /** Number of deferred messages */
@@ -128,37 +134,6 @@ declare class InterventionController {
128
134
  resetCallbacks(): void;
129
135
  }
130
136
 
131
- type ErrorCategory = "rate_limit" | "overloaded" | "auth" | "invalid_request" | "context_overflow" | "content_filter" | "network" | "timeout" | "cancelled" | "unknown";
132
- interface ResponseHeaders {
133
- "retry-after"?: string;
134
- "retry-after-ms"?: string;
135
- "x-ratelimit-remaining"?: string;
136
- "x-ratelimit-reset"?: string;
137
- [key: string]: string | undefined;
138
- }
139
- interface LLMErrorOptions {
140
- message: string;
141
- category?: ErrorCategory;
142
- status?: number;
143
- headers?: ResponseHeaders;
144
- cause?: Error;
145
- provider?: string;
146
- model?: string;
147
- }
148
-
149
- declare class LLMError extends Error {
150
- readonly category: ErrorCategory;
151
- readonly status?: number;
152
- readonly headers?: ResponseHeaders;
153
- readonly provider?: string;
154
- readonly model?: string;
155
- readonly isRetryable: boolean;
156
- readonly retryDelayMs?: number;
157
- constructor(options: LLMErrorOptions);
158
- static from(error: unknown, context?: Partial<LLMErrorOptions>): LLMError;
159
- get description(): string;
160
- }
161
-
162
137
  /**
163
138
  * Retry logic with exponential backoff for @cuylabs/agent-core
164
139
  *
@@ -352,4 +327,4 @@ type LLMStreamInput = InferenceStreamInput;
352
327
  */
353
328
  type StepInfo = InferenceStepInfo;
354
329
 
355
- export { type AnyInferenceResult as A, type CustomStreamProvider as C, DEFAULT_MAX_OUTPUT_TOKENS as D, type ErrorCategory as E, type InferenceStreamInput as I, type LLMStreamInput as L, OUTPUT_TOKEN_MAX as O, type PendingIntervention as P, type ResponseHeaders as R, type StepInfo as S, type ToolExecutionMode as T, type AnyStreamResult as a, type CustomStreamResult as b, type InferenceCustomResult as c, type InferenceStepInfo as d, type InferenceStreamResult as e, type LLMStreamResult as f, InterventionController as g, DEFAULT_RETRY_CONFIG as h, LLMError as i, type LLMErrorOptions as j, type OnInterventionApplied as k, type RetryConfig as l, type RetryHandlerOptions as m, type RetryState as n, calculateDelay as o, createRetryHandler as p, createRetryState as q, sleep as r, shouldRetry as s, withRetry as w };
330
+ export { type AnyInferenceResult as A, type CustomStreamProvider as C, DEFAULT_MAX_OUTPUT_TOKENS as D, type InferenceStreamInput as I, type LLMStreamInput as L, OUTPUT_TOKEN_MAX as O, type PendingIntervention as P, type RetryConfig as R, type StepInfo as S, type ToolExecutionMode as T, type AnyStreamResult as a, type CustomStreamResult as b, DEFAULT_RETRY_CONFIG as c, type InferenceCustomResult as d, type InferenceStepInfo as e, type InferenceStreamResult as f, type LLMStreamResult as g, type RetryHandlerOptions as h, type RetryState as i, calculateDelay as j, createRetryHandler as k, createRetryState as l, sleep as m, InterventionController as n, type OnInterventionApplied as o, shouldRetry as s, withRetry as w };
@@ -0,0 +1,50 @@
1
+ import { LanguageModel } from 'ai';
2
+ import { R as ReasoningLevel } from './types-CQaXbRsS.js';
3
+ import { T as Tool } from './tool-CZWN3KbO.js';
4
+
5
+ /**
6
+ * Agent preset - a reusable configuration profile.
7
+ */
8
+ interface Preset {
9
+ /** Unique identifier for this preset */
10
+ name: string;
11
+ /** Human-readable description */
12
+ description: string;
13
+ /**
14
+ * Tool allow patterns (glob-like).
15
+ * If provided, only tools matching these patterns are candidates.
16
+ */
17
+ allowTools?: string[];
18
+ /**
19
+ * Tool deny patterns (glob-like).
20
+ * Deny patterns apply only after allow matching, so explicit allows win.
21
+ */
22
+ denyTools?: string[];
23
+ /**
24
+ * Override system prompt.
25
+ * Use `{basePrompt}` to include the parent's system prompt.
26
+ */
27
+ systemPrompt?: string;
28
+ /** Override temperature (0-1). */
29
+ temperature?: number;
30
+ /** Override max steps. */
31
+ maxSteps?: number;
32
+ /** Override reasoning level. */
33
+ reasoningLevel?: ReasoningLevel;
34
+ /** Override model. */
35
+ model?: LanguageModel;
36
+ }
37
+ /**
38
+ * Result of applying a preset - ready for `fork()`.
39
+ */
40
+ interface AppliedPreset {
41
+ name: string;
42
+ systemPrompt?: string;
43
+ tools?: Tool.AnyInfo[];
44
+ temperature?: number;
45
+ maxSteps?: number;
46
+ reasoningLevel?: ReasoningLevel;
47
+ model?: LanguageModel;
48
+ }
49
+
50
+ export type { AppliedPreset as A, Preset as P };
@@ -26,4 +26,4 @@ interface ScopeOptions {
26
26
  attributes?: ScopeAttributes;
27
27
  }
28
28
 
29
- export type { ScopeOptions as S, Scope as a, ScopeSnapshot as b, ScopeAttributeValue as c, ScopeAttributes as d, ScopeKind as e };
29
+ export type { ScopeSnapshot as S, Scope as a, ScopeAttributeValue as b, ScopeAttributes as c, ScopeKind as d, ScopeOptions as e };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Risk level for operations.
3
+ */
4
+ type RiskLevel = "safe" | "moderate" | "dangerous";
5
+ /**
6
+ * User response to an approval request.
7
+ */
8
+ type ApprovalAction = "allow" | "deny" | "remember";
9
+ /**
10
+ * Approval request sent to the UI/handler.
11
+ */
12
+ interface ApprovalRequest {
13
+ /** Unique request ID */
14
+ id: string;
15
+ /** Session ID */
16
+ sessionId: string;
17
+ /** Tool name */
18
+ tool: string;
19
+ /** Tool arguments */
20
+ args: unknown;
21
+ /** Human-readable description */
22
+ description: string;
23
+ /** Risk level */
24
+ risk: RiskLevel;
25
+ /** Patterns that would be remembered if "remember" is chosen */
26
+ patterns: string[];
27
+ /** Timestamp */
28
+ timestamp: number;
29
+ }
30
+ /**
31
+ * Rule for auto-approving/denying operations.
32
+ */
33
+ interface ApprovalRule {
34
+ /** Pattern to match (glob-style) */
35
+ pattern: string;
36
+ /** Tool to match (`*` for all) */
37
+ tool: string;
38
+ /** Action to take */
39
+ action: "allow" | "deny";
40
+ }
41
+ /**
42
+ * Configuration for the approval handler.
43
+ */
44
+ interface ApprovalConfig {
45
+ /** Default action when no rule matches (default: "ask") */
46
+ defaultAction?: "allow" | "deny" | "ask";
47
+ /** Pre-configured rules */
48
+ rules?: ApprovalRule[];
49
+ /** Handler for approval requests */
50
+ onRequest?: (request: ApprovalRequest) => Promise<ApprovalAction>;
51
+ /** Timeout for approval requests in ms (default: 5 minutes) */
52
+ timeout?: number;
53
+ }
54
+
55
+ export type { ApprovalAction as A, RiskLevel as R, ApprovalConfig as a, ApprovalRequest as b, ApprovalRule as c };
@@ -1,10 +1,11 @@
1
- import * as ai from 'ai';
2
1
  import { LanguageModel, ModelMessage, TelemetrySettings, SystemModelMessage } from 'ai';
3
2
  import { ProviderOptions } from '@ai-sdk/provider-utils';
4
- import { T as TokenUsage, M as Message } from './messages-BYWGn8TY.js';
5
- import { d as SkillConfig, T as Tool } from './tool-Db1Ue-1U.js';
6
- import { b as ScopeSnapshot } from './types-9jGQUjqW.js';
7
- import { b as ToolContext } from './tool-HUtkiVBx.js';
3
+ import { A as AgentEvent } from './events-CE72w8W4.js';
4
+ import { d as SkillConfig } from './types-BfNpU8NS.js';
5
+ import { T as TokenUsage } from './messages-BYWGn8TY.js';
6
+ import { S as ScopeSnapshot } from './types-CQL-SvTn.js';
7
+ import { T as ToolContext } from './tool-DkhSCV2Y.js';
8
+ import { T as Tool } from './tool-CZWN3KbO.js';
8
9
  import { R as ReasoningLevel } from './types-CQaXbRsS.js';
9
10
 
10
11
  /**
@@ -173,151 +174,6 @@ interface EnhancedTools extends Array<unknown> {
173
174
  __customStreamModels?: string[];
174
175
  }
175
176
 
176
- /** Agent status for UI display */
177
- type AgentStatus = "idle" | "processing" | "thinking" | "reasoning" | "calling-tool" | "waiting-approval" | "error";
178
- /** Approval request for UI */
179
- interface ApprovalEvent {
180
- id: string;
181
- tool: string;
182
- args: unknown;
183
- description: string;
184
- risk: "safe" | "moderate" | "dangerous";
185
- }
186
- /** Neutral turn-commit boundaries for runtime/durability integrations */
187
- type AgentTurnBoundaryKind = "input-commit-start" | "input-commit-finish" | "intervention-commit-start" | "intervention-commit-finish" | "step-commit-start" | "step-commit-finish" | "output-commit-start" | "output-commit-finish";
188
- /**
189
- * Events emitted during agent execution
190
- *
191
- * These events are designed for UI consumption:
192
- * - status: Overall agent state for status indicators
193
- * - approval-request: User confirmation needed
194
- * - progress: Step counts for progress bars
195
- */
196
- type AgentEvent = {
197
- type: "status";
198
- status: AgentStatus;
199
- } | {
200
- type: "approval-request";
201
- request: ApprovalEvent;
202
- } | {
203
- type: "approval-resolved";
204
- id: string;
205
- action: "allow" | "deny" | "remember";
206
- } | {
207
- type: "step-start";
208
- step: number;
209
- maxSteps: number;
210
- } | {
211
- type: "step-finish";
212
- step: number;
213
- usage?: TokenUsage;
214
- finishReason?: string;
215
- } | {
216
- type: "turn-boundary";
217
- boundary: AgentTurnBoundaryKind;
218
- step?: number;
219
- messageRole?: Message["role"];
220
- pendingToolCallCount?: number;
221
- } | {
222
- type: "message";
223
- message: Message;
224
- } | {
225
- type: "text-start";
226
- } | {
227
- type: "text-delta";
228
- text: string;
229
- } | {
230
- type: "text-end";
231
- } | {
232
- type: "reasoning-start";
233
- id: string;
234
- } | {
235
- type: "reasoning-delta";
236
- id: string;
237
- text: string;
238
- } | {
239
- type: "reasoning-end";
240
- id: string;
241
- } | {
242
- type: "tool-start";
243
- toolName: string;
244
- toolCallId: string;
245
- input: unknown;
246
- } | {
247
- type: "tool-result";
248
- toolName: string;
249
- toolCallId: string;
250
- result: unknown;
251
- } | {
252
- type: "tool-error";
253
- toolName: string;
254
- toolCallId: string;
255
- error: string;
256
- } | {
257
- type: "computer-call";
258
- callId: string;
259
- action: unknown;
260
- pendingSafetyChecks?: unknown[];
261
- } | {
262
- type: "computer-result";
263
- callId: string;
264
- result: unknown;
265
- } | {
266
- type: "intervention-applied";
267
- id: string;
268
- message: string;
269
- } | {
270
- type: "doom-loop";
271
- toolName: string;
272
- repeatCount: number;
273
- } | {
274
- type: "context-overflow";
275
- inputTokens: number;
276
- limit: number;
277
- } | {
278
- type: "turn-summary";
279
- turnId: string;
280
- files: Array<{
281
- path: string;
282
- type: "created" | "modified" | "deleted" | "unchanged";
283
- additions: number;
284
- deletions: number;
285
- }>;
286
- additions: number;
287
- deletions: number;
288
- } | {
289
- type: "retry";
290
- attempt: number;
291
- delayMs: number;
292
- error: Error;
293
- } | {
294
- type: "error";
295
- error: Error;
296
- } | {
297
- type: "complete";
298
- usage?: TokenUsage;
299
- output?: string;
300
- };
301
- /**
302
- * Step-processing result - what happens after reducing one streamed step
303
- */
304
- type StepProcessingResult = "continue" | "stop" | "compact";
305
- /**
306
- * @deprecated Use `StepProcessingResult`.
307
- */
308
- type ProcessorResult = StepProcessingResult;
309
- /**
310
- * Stream input for model inference
311
- */
312
- interface StreamInput {
313
- sessionID: string;
314
- model: ai.LanguageModel;
315
- system: string[];
316
- messages: ai.ModelMessage[];
317
- abort: AbortSignal;
318
- tools: Record<string, unknown>;
319
- }
320
-
321
177
  /**
322
178
  * Prompt Pipeline Types
323
179
  *
@@ -792,88 +648,4 @@ interface AgentMiddleware {
792
648
  getOtelContext?(sessionId: string): unknown;
793
649
  }
794
650
 
795
- /**
796
- * Middleware Runner
797
- *
798
- * Executes middleware hooks in the correct order with proper
799
- * error handling and short-circuit semantics.
800
- *
801
- * This is the internal engine — consumers never see it.
802
- * They interact with middleware through AgentConfig.middleware.
803
- */
804
-
805
- /**
806
- * Middleware runner — holds an ordered list of middleware and
807
- * exposes methods to run each hook type with correct semantics.
808
- *
809
- * Immutable after construction. Fork creates a new runner
810
- * (with inherited + additional middleware).
811
- */
812
- declare class MiddlewareRunner {
813
- private readonly stack;
814
- constructor(middleware?: AgentMiddleware[]);
815
- /** Number of registered middleware */
816
- get count(): number;
817
- /** Whether any middleware is registered */
818
- get hasMiddleware(): boolean;
819
- /** Get the middleware list (for fork inheritance) */
820
- getMiddleware(): readonly AgentMiddleware[];
821
- runModelInput(input: ModelCallInput, ctx: ModelCallContext): Promise<ModelCallInput | BlockedModelCall>;
822
- runModelChunk(chunk: StreamChunk, ctx: ModelCallContext): Promise<StreamChunk | undefined>;
823
- runModelOutput(output: ModelCallOutput, ctx: ModelCallContext): Promise<ModelCallOutput>;
824
- /**
825
- * Run all `beforeToolCall` hooks in order.
826
- *
827
- * Returns `{ action: "allow" }` if all middleware allow (or have no hook).
828
- * Returns `{ action: "deny", reason }` on first denial — remaining
829
- * middleware are skipped.
830
- */
831
- runBeforeToolCall(tool: string, args: unknown, ctx: ToolContext): Promise<ToolCallDecision>;
832
- /**
833
- * Run all `afterToolCall` hooks in reverse order.
834
- *
835
- * Each hook receives the result from the previous hook (or the
836
- * original tool result for the first hook). Errors are caught
837
- * and logged — the original result passes through.
838
- */
839
- runAfterToolCall(tool: string, args: unknown, result: Tool.ExecuteResult, ctx: ToolContext): Promise<Tool.ExecuteResult>;
840
- /**
841
- * Collect prompt sections from all middleware.
842
- *
843
- * Returns a flat array of sections. Each middleware can return a single
844
- * section, an array of sections, or undefined/empty.
845
- */
846
- collectPromptSections(ctx: PromptBuildContext): PromptSection[];
847
- /**
848
- * Broadcast an event to all middleware observers.
849
- *
850
- * Non-blocking — errors are caught and logged. This never
851
- * slows down the streaming pipeline.
852
- */
853
- emitEvent(event: AgentEvent): void;
854
- /**
855
- * Get the OTel context for a session from the telemetry middleware.
856
- * Returns undefined if no telemetry middleware is registered.
857
- */
858
- getOtelContext(sessionId: string): unknown | undefined;
859
- /**
860
- * Run all `onChatStart` hooks in order.
861
- *
862
- * Errors are caught and logged — a broken logger should not
863
- * prevent the chat from starting.
864
- */
865
- runChatStart(sessionId: string, message: string): Promise<void>;
866
- /**
867
- * Run all `onChatEnd` hooks in order.
868
- *
869
- * Always called, even when the stream errored. Errors in handlers
870
- * are caught and logged.
871
- */
872
- runChatEnd(sessionId: string, result: {
873
- usage?: TokenUsage;
874
- error?: Error;
875
- output?: string;
876
- }): Promise<void>;
877
- }
878
-
879
- export { type AgentEvent as A, type BlockedModelCall as B, type EnhancedTools as E, type InstructionFile as I, MiddlewareRunner as M, type PromptConfig as P, type StreamChunk as S, type ToolCallDecision as T, type PromptBuildContext as a, type PromptSection as b, type ModelFamily as c, type StreamProvider as d, type ModelCallInput as e, type StepProcessingResult as f, type AgentTurnBoundaryKind as g, type AgentMiddleware as h, type AgentModelHooks as i, type AgentStatus as j, type ApprovalEvent as k, type EnvironmentInfo as l, type ModelCallContext as m, type ModelCallOutput as n, type ProcessorResult as o, type StreamInput as p, type StreamProviderConfig as q, type StreamProviderFactory as r, type StreamProviderInput as s, type StreamProviderResult as t };
651
+ export type { AgentMiddleware as A, BlockedModelCall as B, EnhancedTools as E, InstructionFile as I, ModelCallInput as M, PromptBuildContext as P, StreamChunk as S, ToolCallDecision as T, ModelCallContext as a, ModelCallOutput as b, PromptSection as c, PromptConfig as d, ModelFamily as e, StreamProvider as f, AgentModelHooks as g, EnvironmentInfo as h, StreamProviderConfig as i, StreamProviderFactory as j, StreamProviderInput as k, StreamProviderResult as l };
@@ -1,11 +1,13 @@
1
1
  import { LanguageModel, TelemetrySettings, ModelMessage, ToolSet } from 'ai';
2
- import { T as Tool } from './tool-Db1Ue-1U.js';
2
+ import { T as Tool } from './tool-CZWN3KbO.js';
3
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';
4
+ import { M as MiddlewareRunner } from './runner-CI-XeR16.js';
5
+ import { n as InterventionController, T as ToolExecutionMode, I as InferenceStreamInput } from './types-BlOKk-Bb.js';
6
6
  import { R as ReasoningLevel } from './types-CQaXbRsS.js';
7
- import { N as NormalizedToolReplayPolicy, d as TurnTrackerContext } from './tool-HUtkiVBx.js';
7
+ import { N as NormalizedToolReplayPolicy, d as TurnTrackerContext } from './tool-DkhSCV2Y.js';
8
8
  import { T as TokenUsage, M as Message } from './messages-BYWGn8TY.js';
9
+ import { f as StreamProvider } from './types-DTSkxakL.js';
10
+ import { S as StepProcessingResult, A as AgentEvent, b as AgentTurnBoundaryKind } from './events-CE72w8W4.js';
9
11
 
10
12
  /**
11
13
  * Doom-loop handling contracts for repeated tool invocations.
@@ -40,6 +42,8 @@ interface StepProcessingOptions {
40
42
  sessionID?: string;
41
43
  /** Abort signal */
42
44
  abort: AbortSignal;
45
+ /** Normalize provider/runtime errors before emitting them as events */
46
+ normalizeError?: (error: unknown) => Error;
43
47
  /** Event callback */
44
48
  onEvent: (event: AgentEvent) => void | Promise<void>;
45
49
  /** Doom loop threshold (default: 3) */