@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
@@ -1,305 +0,0 @@
1
- import {
2
- extractModelId,
3
- extractProvider,
4
- getDefaultResolver,
5
- likelySupportsReasoning
6
- } from "./chunk-QGOGIP7T.js";
7
-
8
- // src/reasoning/types.ts
9
- var STANDARD_LEVELS = ["off", "low", "medium", "high"];
10
- var EXTENDED_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
11
- var FIXED_LEVELS = ["medium"];
12
- function shouldIncludeReasoningSummary() {
13
- if (typeof process !== "undefined" && process.env) {
14
- return process.env.CODE_AGENT_DISABLE_REASONING_SUMMARY !== "true";
15
- }
16
- return true;
17
- }
18
-
19
- // src/reasoning/providers.ts
20
- function buildOpenAIOptions(level, compat) {
21
- if (level === "off") return void 0;
22
- const options = {};
23
- if (compat?.supportsReasoningEffort !== false) {
24
- options.reasoningEffort = level;
25
- }
26
- if (shouldIncludeReasoningSummary()) {
27
- options.reasoningSummary = "auto";
28
- }
29
- return options;
30
- }
31
- var ANTHROPIC_BUDGETS = {
32
- off: 0,
33
- minimal: 2e3,
34
- low: 4e3,
35
- medium: 8e3,
36
- high: 16e3,
37
- xhigh: 31999
38
- };
39
- function buildAnthropicOptions(level) {
40
- if (level === "off") return void 0;
41
- return {
42
- thinking: {
43
- type: "enabled",
44
- budgetTokens: ANTHROPIC_BUDGETS[level]
45
- }
46
- };
47
- }
48
- var GOOGLE_BUDGETS = {
49
- off: 0,
50
- minimal: 2e3,
51
- low: 4e3,
52
- medium: 8e3,
53
- high: 16e3,
54
- xhigh: 24576
55
- };
56
- function buildGoogleOptions(level, modelId) {
57
- if (level === "off") return void 0;
58
- if (modelId?.includes("gemini-3") || modelId?.includes("gemini-4")) {
59
- return {
60
- thinkingConfig: {
61
- includeThoughts: true,
62
- thinkingLevel: level === "high" || level === "xhigh" ? "high" : "low"
63
- }
64
- };
65
- }
66
- return {
67
- thinkingConfig: {
68
- includeThoughts: true,
69
- thinkingBudget: GOOGLE_BUDGETS[level]
70
- }
71
- };
72
- }
73
- function buildXAIOptions(level) {
74
- if (level === "off") return void 0;
75
- return { reasoningEffort: level };
76
- }
77
- function buildGroqOptions(level) {
78
- if (level === "off") return void 0;
79
- return {
80
- includeThoughts: true,
81
- thinkingLevel: level === "high" || level === "xhigh" ? "high" : "low"
82
- };
83
- }
84
- var BEDROCK_ANTHROPIC_BUDGETS = {
85
- off: 0,
86
- minimal: 2e3,
87
- low: 4e3,
88
- medium: 8e3,
89
- high: 16e3,
90
- xhigh: 31999
91
- };
92
- function buildBedrockOptions(level, modelId) {
93
- if (level === "off") return void 0;
94
- if (modelId?.includes("anthropic") || modelId?.includes("claude")) {
95
- return {
96
- reasoningConfig: {
97
- type: "enabled",
98
- budgetTokens: BEDROCK_ANTHROPIC_BUDGETS[level]
99
- }
100
- };
101
- }
102
- return {
103
- reasoningConfig: {
104
- type: "enabled",
105
- maxReasoningEffort: level
106
- }
107
- };
108
- }
109
- function buildOpenRouterOptions(level) {
110
- if (level === "off") return void 0;
111
- return {
112
- reasoning: { effort: level }
113
- };
114
- }
115
- var PROVIDER_KEY_MAP = {
116
- "openai.chat": "openai",
117
- "openai.responses": "openai",
118
- "anthropic.messages": "anthropic",
119
- "google.generative-ai": "google",
120
- "bedrock": "bedrock",
121
- "azure": "azure",
122
- "xai": "xai",
123
- "deepinfra": "deepinfra",
124
- "togetherai": "togetherai",
125
- "groq": "groq",
126
- "mistral": "mistral"
127
- };
128
- function getProviderOptionsKey(provider) {
129
- return PROVIDER_KEY_MAP[provider] || provider.split(".")[0] || "unknown";
130
- }
131
-
132
- // src/reasoning/config.ts
133
- async function getReasoningConfig(model) {
134
- const resolver = getDefaultResolver();
135
- const result = await resolver.resolve(model);
136
- const { capabilities, compatibility } = result.entry;
137
- const provider = extractProvider(model);
138
- const modelId = extractModelId(model).toLowerCase();
139
- if (!capabilities.reasoning) {
140
- return {
141
- supportsReasoning: false,
142
- availableLevels: ["off"],
143
- getProviderOptions: () => void 0
144
- };
145
- }
146
- if (provider?.includes("openai") || modelId.includes("gpt") || modelId.match(/^o[134]/)) {
147
- if (modelId === "o1-mini") {
148
- return {
149
- supportsReasoning: true,
150
- availableLevels: FIXED_LEVELS,
151
- getProviderOptions: () => void 0
152
- };
153
- }
154
- const isAdvanced = modelId.includes("gpt-5") || modelId.includes("o3") || modelId.includes("o4");
155
- return {
156
- supportsReasoning: true,
157
- availableLevels: isAdvanced ? EXTENDED_LEVELS : STANDARD_LEVELS,
158
- getProviderOptions: (level) => buildOpenAIOptions(level, compatibility)
159
- };
160
- }
161
- if (provider?.includes("anthropic") || modelId.includes("claude")) {
162
- return {
163
- supportsReasoning: true,
164
- availableLevels: ["off", "low", "medium", "high"],
165
- getProviderOptions: buildAnthropicOptions
166
- };
167
- }
168
- if (provider?.includes("google") || modelId.includes("gemini")) {
169
- return {
170
- supportsReasoning: true,
171
- availableLevels: STANDARD_LEVELS,
172
- getProviderOptions: (level) => buildGoogleOptions(level, modelId)
173
- };
174
- }
175
- if (provider?.includes("xai") || modelId.includes("grok")) {
176
- return {
177
- supportsReasoning: true,
178
- availableLevels: STANDARD_LEVELS,
179
- getProviderOptions: buildXAIOptions
180
- };
181
- }
182
- if (provider?.includes("bedrock")) {
183
- return {
184
- supportsReasoning: true,
185
- availableLevels: STANDARD_LEVELS,
186
- getProviderOptions: (level) => buildBedrockOptions(level, modelId)
187
- };
188
- }
189
- if (provider?.includes("groq")) {
190
- return {
191
- supportsReasoning: true,
192
- availableLevels: ["off", "low", "high"],
193
- getProviderOptions: buildGroqOptions
194
- };
195
- }
196
- if (provider?.includes("openrouter")) {
197
- return {
198
- supportsReasoning: true,
199
- availableLevels: STANDARD_LEVELS,
200
- getProviderOptions: buildOpenRouterOptions
201
- };
202
- }
203
- if (modelId.includes("r1") || modelId.includes("deepseek")) {
204
- return {
205
- supportsReasoning: true,
206
- availableLevels: FIXED_LEVELS,
207
- getProviderOptions: () => void 0
208
- };
209
- }
210
- return {
211
- supportsReasoning: true,
212
- availableLevels: STANDARD_LEVELS,
213
- getProviderOptions: (level) => buildOpenAIOptions(level, compatibility)
214
- };
215
- }
216
- function getReasoningConfigSync(model) {
217
- const modelId = extractModelId(model).toLowerCase();
218
- const provider = extractProvider(model) || "";
219
- const supportsReasoning2 = modelId.match(/^o[134]/) !== null || modelId.includes("gpt-5") || modelId.includes("r1") || modelId.includes("thinking") || modelId.includes("reasoning") || modelId.includes("grok") && modelId.includes("mini");
220
- if (!supportsReasoning2) {
221
- return {
222
- supportsReasoning: false,
223
- availableLevels: ["off"],
224
- getProviderOptions: () => void 0
225
- };
226
- }
227
- const isOpenAI = provider.includes("openai") || !!modelId.match(/^o[134]/) || modelId.includes("gpt");
228
- const isAnthropic = provider.includes("anthropic") || modelId.includes("claude");
229
- const isGoogle = provider.includes("google") || modelId.includes("gemini");
230
- const isXAI = provider.includes("xai") || modelId.includes("grok");
231
- const isBedrock = provider.includes("bedrock");
232
- const isGroq = provider.includes("groq");
233
- const isOpenRouter = provider.includes("openrouter");
234
- return {
235
- supportsReasoning: true,
236
- availableLevels: STANDARD_LEVELS,
237
- getProviderOptions: (level) => {
238
- if (level === "off") return void 0;
239
- if (isOpenAI) {
240
- const opts = { reasoningEffort: level };
241
- if (shouldIncludeReasoningSummary()) opts.reasoningSummary = "auto";
242
- return opts;
243
- }
244
- if (isAnthropic) return buildAnthropicOptions(level);
245
- if (isGoogle) return buildGoogleOptions(level, modelId);
246
- if (isXAI) return buildXAIOptions(level);
247
- if (isBedrock) return buildBedrockOptions(level, modelId);
248
- if (isGroq) return buildGroqOptions(level);
249
- if (isOpenRouter) return buildOpenRouterOptions(level);
250
- const defaultOpts = { reasoningEffort: level };
251
- if (shouldIncludeReasoningSummary()) defaultOpts.reasoningSummary = "auto";
252
- return defaultOpts;
253
- }
254
- };
255
- }
256
- async function buildReasoningOptions(model, level) {
257
- if (level === "off") return void 0;
258
- const config = await getReasoningConfig(model);
259
- if (!config.supportsReasoning) return void 0;
260
- const effectiveLevel = config.availableLevels.includes(level) ? level : config.availableLevels[config.availableLevels.length - 1];
261
- const options = config.getProviderOptions(effectiveLevel);
262
- if (!options) return void 0;
263
- const provider = extractProvider(model) || "";
264
- const providerKey = getProviderOptionsKey(provider);
265
- return { [providerKey]: options };
266
- }
267
- function buildReasoningOptionsSync(model, level) {
268
- if (level === "off") return void 0;
269
- const config = getReasoningConfigSync(model);
270
- if (!config.supportsReasoning) return void 0;
271
- const effectiveLevel = config.availableLevels.includes(level) ? level : config.availableLevels[config.availableLevels.length - 1];
272
- const options = config.getProviderOptions(effectiveLevel);
273
- if (!options) return void 0;
274
- const provider = extractProvider(model) || "";
275
- const providerKey = getProviderOptionsKey(provider);
276
- return { [providerKey]: options };
277
- }
278
- async function supportsReasoning(model) {
279
- const resolver = getDefaultResolver();
280
- return resolver.supportsReasoning(model);
281
- }
282
- function supportsReasoningSync(model) {
283
- return likelySupportsReasoning(extractModelId(model));
284
- }
285
-
286
- export {
287
- STANDARD_LEVELS,
288
- EXTENDED_LEVELS,
289
- FIXED_LEVELS,
290
- shouldIncludeReasoningSummary,
291
- buildOpenAIOptions,
292
- buildAnthropicOptions,
293
- buildGoogleOptions,
294
- buildXAIOptions,
295
- buildGroqOptions,
296
- buildBedrockOptions,
297
- buildOpenRouterOptions,
298
- getProviderOptionsKey,
299
- getReasoningConfig,
300
- getReasoningConfigSync,
301
- buildReasoningOptions,
302
- buildReasoningOptionsSync,
303
- supportsReasoning,
304
- supportsReasoningSync
305
- };
@@ -1,317 +0,0 @@
1
- import { h as AgentMiddleware } from './runner-DSKaEz3z.js';
2
- import { TelemetrySettings } from 'ai';
3
-
4
- /**
5
- * Risk level for operations.
6
- */
7
- type RiskLevel = "safe" | "moderate" | "dangerous";
8
- /**
9
- * User response to an approval request.
10
- */
11
- type ApprovalAction = "allow" | "deny" | "remember";
12
- /**
13
- * Approval request sent to the UI/handler.
14
- */
15
- interface ApprovalRequest {
16
- /** Unique request ID */
17
- id: string;
18
- /** Session ID */
19
- sessionId: string;
20
- /** Tool name */
21
- tool: string;
22
- /** Tool arguments */
23
- args: unknown;
24
- /** Human-readable description */
25
- description: string;
26
- /** Risk level */
27
- risk: RiskLevel;
28
- /** Patterns that would be remembered if "remember" is chosen */
29
- patterns: string[];
30
- /** Timestamp */
31
- timestamp: number;
32
- }
33
- /**
34
- * Rule for auto-approving/denying operations.
35
- */
36
- interface ApprovalRule {
37
- /** Pattern to match (glob-style) */
38
- pattern: string;
39
- /** Tool to match (`*` for all) */
40
- tool: string;
41
- /** Action to take */
42
- action: "allow" | "deny";
43
- }
44
- /**
45
- * Configuration for the approval handler.
46
- */
47
- interface ApprovalConfig {
48
- /** Default action when no rule matches (default: "ask") */
49
- defaultAction?: "allow" | "deny" | "ask";
50
- /** Pre-configured rules */
51
- rules?: ApprovalRule[];
52
- /** Handler for approval requests */
53
- onRequest?: (request: ApprovalRequest) => Promise<ApprovalAction>;
54
- /** Timeout for approval requests in ms (default: 5 minutes) */
55
- timeout?: number;
56
- }
57
-
58
- /**
59
- * Approval Middleware
60
- *
61
- * Wraps the existing approval system as an AgentMiddleware.
62
- * This is how approval finally gets wired into the tool execution
63
- * pipeline — no more dead code.
64
- *
65
- * @example
66
- * ```typescript
67
- * import { createAgent, approvalMiddleware } from "@cuylabs/agent-core";
68
- *
69
- * const agent = createAgent({
70
- * model: anthropic("claude-sonnet-4-20250514"),
71
- * tools: [read, write, bash],
72
- * middleware: [
73
- * approvalMiddleware({
74
- * rules: [
75
- * { pattern: "src/*", tool: "read_file", action: "allow" },
76
- * ],
77
- * onRequest: async (req) => {
78
- * // Prompt user in your UI
79
- * return await askUser(req);
80
- * },
81
- * }),
82
- * ],
83
- * });
84
- * ```
85
- */
86
-
87
- /**
88
- * Configuration for the approval middleware.
89
- *
90
- * Extends the existing ApprovalConfig with middleware-specific options.
91
- */
92
- interface ApprovalMiddlewareConfig extends ApprovalConfig {
93
- /**
94
- * Custom risk classification for tools.
95
- *
96
- * Overrides the built-in risk map. Tools not listed here
97
- * fall back to the default classification.
98
- *
99
- * @example
100
- * ```typescript
101
- * customRisks: {
102
- * "my_deploy_tool": "dangerous",
103
- * "my_lint_tool": "safe",
104
- * }
105
- * ```
106
- */
107
- customRisks?: Record<string, RiskLevel>;
108
- }
109
- /**
110
- * Create an approval middleware from an ApprovalConfig.
111
- *
112
- * This bridges the existing `createApprovalHandler` into the middleware
113
- * system. The `beforeToolCall` hook checks rules, classifies risk,
114
- * and calls the approval handler when needed.
115
- *
116
- * @param config - Approval configuration (rules, handler, timeout, etc.)
117
- * @returns An AgentMiddleware that gates tool execution
118
- */
119
- declare function approvalMiddleware(config?: ApprovalMiddlewareConfig): AgentMiddleware;
120
-
121
- /**
122
- * Configuration for the OpenTelemetry middleware.
123
- */
124
- interface OtelMiddlewareConfig {
125
- /**
126
- * Whether to record tool call arguments as span attributes.
127
- * Defaults to `true`.
128
- */
129
- recordInputs?: boolean;
130
- /**
131
- * Whether to record tool results as span attributes.
132
- * Defaults to `true`.
133
- */
134
- recordOutputs?: boolean;
135
- /**
136
- * Agent name — used in the root span name and attributes.
137
- * Falls back to `"agent"`.
138
- */
139
- agentName?: string;
140
- /** Agent description — recorded as `gen_ai.agent.description`. */
141
- agentDescription?: string;
142
- /**
143
- * Whether to emit `execute_tool` spans for tool calls.
144
- * Defaults to `true`.
145
- */
146
- emitToolSpans?: boolean;
147
- /**
148
- * TTL in milliseconds for orphaned spans.
149
- * Defaults to 5 minutes.
150
- */
151
- spanTimeoutMs?: number;
152
- }
153
- /**
154
- * Configuration for `createTelemetryConfig()`.
155
- */
156
- interface TelemetryConfig {
157
- /** Agent name — used in span names and `gen_ai.agent.name`. */
158
- agentName: string;
159
- /** Agent description — recorded as `gen_ai.agent.description`. */
160
- agentDescription?: string;
161
- /** Record tool arguments and LLM prompts in spans. Defaults to `true`. */
162
- recordInputs?: boolean;
163
- /** Record tool results and LLM responses in spans. Defaults to `true`. */
164
- recordOutputs?: boolean;
165
- /** Emit `execute_tool` spans from our middleware. Defaults to `true`. */
166
- emitToolSpans?: boolean;
167
- /** TTL in ms for orphaned spans. Defaults to 5 minutes. */
168
- spanTimeoutMs?: number;
169
- /**
170
- * An OTel `SpanProcessor` to auto-create and register a `NodeTracerProvider`.
171
- */
172
- spanProcessor?: unknown;
173
- /**
174
- * OTel service name for the `NodeTracerProvider` resource.
175
- * Defaults to `agentName`.
176
- */
177
- serviceName?: string;
178
- }
179
- /**
180
- * Result of `createTelemetryConfig()`.
181
- */
182
- interface TelemetryConfigResult {
183
- /** Agent-core middleware. */
184
- middleware: AgentMiddleware;
185
- /** AI SDK telemetry settings. */
186
- telemetry: TelemetrySettings;
187
- /**
188
- * Flush and shut down the auto-created tracer provider.
189
- * No-op when no provider was auto-created.
190
- */
191
- shutdown: () => Promise<void>;
192
- }
193
-
194
- declare function otelMiddleware(config?: OtelMiddlewareConfig): AgentMiddleware;
195
-
196
- declare function createTelemetryConfig(config: TelemetryConfig): TelemetryConfigResult;
197
-
198
- /**
199
- * Prompt Cache Middleware — Type definitions.
200
- *
201
- * Defines the configuration for provider-specific prompt caching.
202
- * Currently supports Anthropic's `cache_control` with ephemeral breakpoints.
203
- */
204
- /**
205
- * Supported cache TTL values for Anthropic prompt caching.
206
- *
207
- * - `"5m"` — 5-minute cache (default, ~90% input cost reduction)
208
- * - `"1h"` — 1-hour cache (higher write cost, but longer retention)
209
- */
210
- type CacheTTL = "5m" | "1h";
211
- /**
212
- * Configuration for the prompt cache middleware.
213
- *
214
- * @example
215
- * ```typescript
216
- * // Default — auto-detect Anthropic, 5-minute TTL
217
- * promptCacheMiddleware()
218
- *
219
- * // Custom TTL
220
- * promptCacheMiddleware({ ttl: "1h" })
221
- *
222
- * // Custom breakpoint strategy
223
- * promptCacheMiddleware({
224
- * messageBreakpoints: 2, // cache system + 2 message boundaries
225
- * })
226
- * ```
227
- */
228
- interface PromptCacheConfig {
229
- /**
230
- * Cache TTL. Defaults to `"5m"` (Anthropic's default).
231
- *
232
- * - `"5m"` — 5 minutes. 1.25× write, 0.1× read.
233
- * - `"1h"` — 1 hour. Higher write cost, longer retention.
234
- */
235
- ttl?: CacheTTL;
236
- /**
237
- * Number of cache breakpoints to place on conversation messages.
238
- *
239
- * Anthropic allows up to 4 breakpoints total. The system prompt always
240
- * gets one. This controls how many additional breakpoints are placed
241
- * on conversation messages (counting from the end of stable content).
242
- *
243
- * Defaults to `1` (system + 1 message boundary = 2 breakpoints).
244
- *
245
- * Set to `0` to only cache the system prompt.
246
- */
247
- messageBreakpoints?: number;
248
- }
249
-
250
- /**
251
- * Prompt Cache Middleware — Anthropic prompt caching via `model.input`.
252
- *
253
- * Reduces input token costs by marking stable content (system prompt,
254
- * older conversation messages) with Anthropic `cache_control` breakpoints.
255
- *
256
- * How it works:
257
- *
258
- * 1. The middleware runs before each `streamText()` call via `model.input`
259
- * 2. It detects if the model is Anthropic (via provider string or model ID)
260
- * 3. For Anthropic models, it sets `cache_control: { type: "ephemeral" }`
261
- * on the system prompt and on stable conversation messages
262
- * 4. The AI SDK's Anthropic provider translates these into API-level
263
- * `cache_control` fields that Anthropic uses for prefix caching
264
- *
265
- * Cost impact:
266
- * - First call per cache region: 1.25× write cost (25% premium)
267
- * - Subsequent calls hitting cache: 0.1× read cost (90% savings)
268
- * - Cache TTL: 5 minutes (default) or 1 hour
269
- * - Net savings on multi-turn conversations: ~75%
270
- *
271
- * Anthropic limits: max 4 cache breakpoints per request.
272
- * This middleware uses 1 for system + up to `messageBreakpoints` for messages.
273
- *
274
- * @example
275
- * ```typescript
276
- * import { promptCacheMiddleware } from "@cuylabs/agent-core/middleware";
277
- *
278
- * const agent = createAgent({
279
- * model: anthropic("claude-sonnet-4-20250514"),
280
- * middleware: [promptCacheMiddleware()],
281
- * });
282
- * ```
283
- */
284
-
285
- /**
286
- * Create a prompt cache middleware for Anthropic models.
287
- *
288
- * Automatically detects Anthropic models and adds `cache_control`
289
- * breakpoints to the system prompt and stable conversation messages.
290
- * Non-Anthropic models are passed through unchanged.
291
- *
292
- * @param config - Optional configuration (TTL, breakpoint count)
293
- * @returns An `AgentMiddleware` that enables Anthropic prompt caching
294
- *
295
- * @example
296
- * ```typescript
297
- * import { anthropic } from "@ai-sdk/anthropic";
298
- * import { createAgent } from "@cuylabs/agent-core";
299
- * import { promptCacheMiddleware } from "@cuylabs/agent-core/middleware";
300
- *
301
- * const agent = createAgent({
302
- * model: anthropic("claude-sonnet-4-20250514"),
303
- * middleware: [promptCacheMiddleware()],
304
- * });
305
- *
306
- * // With custom config
307
- * const agent2 = createAgent({
308
- * model: anthropic("claude-sonnet-4-20250514"),
309
- * middleware: [
310
- * promptCacheMiddleware({ ttl: "1h", messageBreakpoints: 2 }),
311
- * ],
312
- * });
313
- * ```
314
- */
315
- declare function promptCacheMiddleware(config?: PromptCacheConfig): AgentMiddleware;
316
-
317
- export { type ApprovalConfig as A, type CacheTTL as C, type OtelMiddlewareConfig as O, type PromptCacheConfig as P, type RiskLevel as R, type TelemetryConfig as T, type ApprovalRule as a, type ApprovalAction as b, type ApprovalMiddlewareConfig as c, type ApprovalRequest as d, type TelemetryConfigResult as e, approvalMiddleware as f, createTelemetryConfig as g, otelMiddleware as o, promptCacheMiddleware as p };