@cuylabs/agent-core 0.6.0 → 0.8.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 (74) hide show
  1. package/README.md +5 -1
  2. package/dist/{builder-BKkipazh.d.ts → builder-UpOWQMW3.d.ts} +2 -2
  3. package/dist/{chunk-3C4VKG4P.js → chunk-4BDA7DQY.js} +273 -807
  4. package/dist/chunk-7VKQ4WPB.js +73 -0
  5. package/dist/chunk-BFM2YHNM.js +222 -0
  6. package/dist/chunk-CAA7FHIH.js +280 -0
  7. package/dist/chunk-KUVSERLJ.js +50 -0
  8. package/dist/chunk-N6HWIEEA.js +423 -0
  9. package/dist/chunk-N7P4PN3O.js +84 -0
  10. package/dist/{chunk-QWFMX226.js → chunk-RFEKJKTO.js} +252 -13
  11. package/dist/chunk-RZITT45F.js +202 -0
  12. package/dist/{chunk-X635CM2F.js → chunk-SQU2AJHO.js} +1 -1
  13. package/dist/chunk-VNQBHPCT.js +398 -0
  14. package/dist/{chunk-QAQADS4X.js → chunk-WWYYNWEW.js} +2 -1
  15. package/dist/{chunk-O2ZCFQL6.js → chunk-YSLSEQ6B.js} +105 -220
  16. package/dist/context/index.js +1 -1
  17. package/dist/errors/index.d.ts +11 -0
  18. package/dist/errors/index.js +16 -0
  19. package/dist/events-CE72w8W4.d.ts +149 -0
  20. package/dist/host/index.d.ts +45 -0
  21. package/dist/host/index.js +8 -0
  22. package/dist/{index-DZQJD_hp.d.ts → index-CWSchSql.d.ts} +42 -51
  23. package/dist/index.d.ts +98 -190
  24. package/dist/index.js +476 -939
  25. package/dist/inference/index.d.ts +62 -0
  26. package/dist/inference/index.js +27 -0
  27. package/dist/llm-error-D93FNNLY.d.ts +32 -0
  28. package/dist/middleware/index.d.ts +246 -5
  29. package/dist/middleware/index.js +7 -3
  30. package/dist/models/index.d.ts +226 -3
  31. package/dist/models/index.js +41 -3
  32. package/dist/presets/index.d.ts +53 -0
  33. package/dist/presets/index.js +28 -0
  34. package/dist/prompt/index.d.ts +12 -7
  35. package/dist/reasoning/index.d.ts +53 -8
  36. package/dist/reasoning/index.js +2 -7
  37. package/dist/{registry-CuRWWtcT.d.ts → registry-DwYqsQkX.d.ts} +1 -1
  38. package/dist/{runner-G1wxEgac.d.ts → runner-e2YRcUoX.d.ts} +82 -148
  39. package/dist/runtime/index.d.ts +44 -7
  40. package/dist/runtime/index.js +16 -5
  41. package/dist/safety/index.d.ts +38 -0
  42. package/dist/safety/index.js +12 -0
  43. package/dist/scope/index.d.ts +10 -0
  44. package/dist/scope/index.js +14 -0
  45. package/dist/{session-manager-Uawm2Le7.d.ts → session-manager-B_CWGTsl.d.ts} +1 -1
  46. package/dist/signal/index.d.ts +28 -0
  47. package/dist/signal/index.js +6 -0
  48. package/dist/skill/index.d.ts +8 -5
  49. package/dist/storage/index.d.ts +2 -2
  50. package/dist/sub-agent/index.d.ts +17 -8
  51. package/dist/tool/index.d.ts +9 -4
  52. package/dist/tool/index.js +4 -3
  53. package/dist/tool-BHbyUAy3.d.ts +150 -0
  54. package/dist/{tool-DYp6-cC3.d.ts → tool-DLXAR9Ce.d.ts} +5 -99
  55. package/dist/tracking/index.d.ts +3 -1
  56. package/dist/{tool-pFAnJc5Y.d.ts → types-BfNpU8NS.d.ts} +1 -150
  57. package/dist/types-BnpEOYV-.d.ts +50 -0
  58. package/dist/types-CHiPh8U2.d.ts +100 -0
  59. package/dist/types-CQL-SvTn.d.ts +29 -0
  60. package/dist/types-CWm-7rvB.d.ts +55 -0
  61. package/dist/types-KKDrdU9Y.d.ts +325 -0
  62. package/dist/{resolver-DOfZ-xuk.d.ts → types-QA4WhEfz.d.ts} +1 -117
  63. package/dist/types-QKHHQLLq.d.ts +336 -0
  64. package/dist/types-YuWV4ag7.d.ts +72 -0
  65. package/package.json +74 -8
  66. package/dist/capabilities/index.d.ts +0 -97
  67. package/dist/capabilities/index.js +0 -46
  68. package/dist/chunk-6TDTQJ4P.js +0 -116
  69. package/dist/chunk-FG4MD5MU.js +0 -54
  70. package/dist/config-D2xeGEHK.d.ts +0 -52
  71. package/dist/identifiers-BLUxFqV_.d.ts +0 -12
  72. package/dist/index-ipP3_ztp.d.ts +0 -198
  73. package/dist/network-D76DS5ot.d.ts +0 -5
  74. package/dist/types-BWo810L_.d.ts +0 -648
@@ -0,0 +1,62 @@
1
+ import { ToolSet } from 'ai';
2
+ import { T as Tool } from '../tool-BHbyUAy3.js';
3
+ import { T as ToolHost } from '../types-CHiPh8U2.js';
4
+ import { M as MiddlewareRunner } from '../runner-e2YRcUoX.js';
5
+ export { S as StreamChunk } from '../runner-e2YRcUoX.js';
6
+ import { d as TurnTrackerContext } from '../tool-DLXAR9Ce.js';
7
+ import { T as ToolExecutionMode, I as InferenceStreamInput, A as AnyInferenceResult } from '../types-KKDrdU9Y.js';
8
+ export { a as AnyStreamResult, C as CustomStreamProvider, b as CustomStreamResult, D as DEFAULT_MAX_OUTPUT_TOKENS, c as InferenceCustomResult, d as InferenceStepInfo, e as InferenceStreamResult, L as LLMStreamInput, f as LLMStreamResult, O as OUTPUT_TOKEN_MAX, S as StepInfo } from '../types-KKDrdU9Y.js';
9
+ import 'zod';
10
+ import '@ai-sdk/provider-utils';
11
+ import '../events-CE72w8W4.js';
12
+ import '../messages-BYWGn8TY.js';
13
+ import '../types-BfNpU8NS.js';
14
+ import '../types-CQL-SvTn.js';
15
+ import '../types-CQaXbRsS.js';
16
+ import '../llm-error-D93FNNLY.js';
17
+
18
+ /**
19
+ * Build a Vercel AI SDK `ToolSet` from `Tool.Info` definitions.
20
+ */
21
+ declare function buildToolSet(options: {
22
+ tools: Record<string, Tool.Info>;
23
+ cwd: string;
24
+ sessionID: string;
25
+ messageID: string;
26
+ abort: AbortSignal;
27
+ turnTracker?: TurnTrackerContext;
28
+ host?: ToolHost;
29
+ middleware?: MiddlewareRunner;
30
+ executionMode?: ToolExecutionMode;
31
+ }): Promise<ToolSet>;
32
+
33
+ /**
34
+ * Create a model inference stream with optional retry support.
35
+ */
36
+ declare function stream(input: InferenceStreamInput): Promise<AnyInferenceResult>;
37
+ /**
38
+ * Create a stream without retry.
39
+ */
40
+ declare function streamOnce(input: InferenceStreamInput): Promise<AnyInferenceResult>;
41
+ /**
42
+ * Create a single-step stream.
43
+ */
44
+ declare function streamStep(input: InferenceStreamInput): Promise<AnyInferenceResult>;
45
+
46
+ declare const Inference: {
47
+ readonly buildToolSet: typeof buildToolSet;
48
+ readonly stream: typeof stream;
49
+ readonly streamOnce: typeof streamOnce;
50
+ readonly streamStep: typeof streamStep;
51
+ };
52
+ /**
53
+ * @deprecated Use `Inference`.
54
+ */
55
+ declare const LLM: {
56
+ readonly buildToolSet: typeof buildToolSet;
57
+ readonly stream: typeof stream;
58
+ readonly streamOnce: typeof streamOnce;
59
+ readonly streamStep: typeof streamStep;
60
+ };
61
+
62
+ export { AnyInferenceResult, Inference, InferenceStreamInput, LLM, ToolExecutionMode, buildToolSet, stream, streamOnce, streamStep };
@@ -0,0 +1,27 @@
1
+ import {
2
+ DEFAULT_MAX_OUTPUT_TOKENS,
3
+ Inference,
4
+ LLM,
5
+ OUTPUT_TOKEN_MAX,
6
+ buildToolSet,
7
+ stream,
8
+ streamOnce,
9
+ streamStep
10
+ } from "../chunk-N6HWIEEA.js";
11
+ import "../chunk-7VKQ4WPB.js";
12
+ import "../chunk-VEKUXUVF.js";
13
+ import "../chunk-SQU2AJHO.js";
14
+ import "../chunk-N7P4PN3O.js";
15
+ import "../chunk-RZITT45F.js";
16
+ import "../chunk-RFEKJKTO.js";
17
+ import "../chunk-DWYX7ASF.js";
18
+ export {
19
+ DEFAULT_MAX_OUTPUT_TOKENS,
20
+ Inference,
21
+ LLM,
22
+ OUTPUT_TOKEN_MAX,
23
+ buildToolSet,
24
+ stream,
25
+ streamOnce,
26
+ streamStep
27
+ };
@@ -0,0 +1,32 @@
1
+ type ErrorCategory = "rate_limit" | "overloaded" | "auth" | "invalid_request" | "context_overflow" | "content_filter" | "network" | "timeout" | "cancelled" | "unknown";
2
+ interface ResponseHeaders {
3
+ "retry-after"?: string;
4
+ "retry-after-ms"?: string;
5
+ "x-ratelimit-remaining"?: string;
6
+ "x-ratelimit-reset"?: string;
7
+ [key: string]: string | undefined;
8
+ }
9
+ interface LLMErrorOptions {
10
+ message: string;
11
+ category?: ErrorCategory;
12
+ status?: number;
13
+ headers?: ResponseHeaders;
14
+ cause?: Error;
15
+ provider?: string;
16
+ model?: string;
17
+ }
18
+
19
+ declare class LLMError extends Error {
20
+ readonly category: ErrorCategory;
21
+ readonly status?: number;
22
+ readonly headers?: ResponseHeaders;
23
+ readonly provider?: string;
24
+ readonly model?: string;
25
+ readonly isRetryable: boolean;
26
+ readonly retryDelayMs?: number;
27
+ constructor(options: LLMErrorOptions);
28
+ static from(error: unknown, context?: Partial<LLMErrorOptions>): LLMError;
29
+ get description(): string;
30
+ }
31
+
32
+ export { type ErrorCategory as E, LLMError as L, type ResponseHeaders as R, type LLMErrorOptions as a };
@@ -1,8 +1,249 @@
1
- export { h as AgentMiddleware, i as AgentModelHooks, B as BlockedModelCall, M as MiddlewareRunner, m as ModelCallContext, f as ModelCallInput, n as ModelCallOutput, T as ToolCallDecision } from '../runner-G1wxEgac.js';
2
- export { c as ApprovalMiddlewareConfig, O as OtelMiddlewareConfig, T as TelemetryConfig, e as TelemetryConfigResult, f as approvalMiddleware, g as createTelemetryConfig, o as otelMiddleware } from '../index-ipP3_ztp.js';
3
- import 'ai';
1
+ import { A as AgentMiddleware } from '../runner-e2YRcUoX.js';
2
+ export { f as AgentModelHooks, B as BlockedModelCall, M as MiddlewareRunner, h as ModelCallContext, e as ModelCallInput, i as ModelCallOutput, j as PluginCommand, k as PluginContext, l as PluginInit, T as ToolCallDecision } from '../runner-e2YRcUoX.js';
3
+ import { a as ApprovalConfig, R as RiskLevel } from '../types-CWm-7rvB.js';
4
+ import { TelemetrySettings } from 'ai';
5
+ import '@ai-sdk/provider-utils';
6
+ import '../events-CE72w8W4.js';
4
7
  import '../messages-BYWGn8TY.js';
5
- import '../tool-pFAnJc5Y.js';
8
+ import '../types-BfNpU8NS.js';
9
+ import '../types-CQL-SvTn.js';
10
+ import '../tool-DLXAR9Ce.js';
11
+ import '../types-CHiPh8U2.js';
12
+ import '../tool-BHbyUAy3.js';
6
13
  import 'zod';
7
- import '../tool-DYp6-cC3.js';
8
14
  import '../types-CQaXbRsS.js';
15
+
16
+ /**
17
+ * Approval Middleware
18
+ *
19
+ * Wraps the existing approval system as an AgentMiddleware.
20
+ * This is how approval finally gets wired into the tool execution
21
+ * pipeline — no more dead code.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * import { createAgent, approvalMiddleware } from "@cuylabs/agent-core";
26
+ *
27
+ * const agent = createAgent({
28
+ * model: anthropic("claude-sonnet-4-20250514"),
29
+ * tools: [read, write, bash],
30
+ * middleware: [
31
+ * approvalMiddleware({
32
+ * rules: [
33
+ * { pattern: "src/*", tool: "read_file", action: "allow" },
34
+ * ],
35
+ * onRequest: async (req) => {
36
+ * // Prompt user in your UI
37
+ * return await askUser(req);
38
+ * },
39
+ * }),
40
+ * ],
41
+ * });
42
+ * ```
43
+ */
44
+
45
+ /**
46
+ * Configuration for the approval middleware.
47
+ *
48
+ * Extends the existing ApprovalConfig with middleware-specific options.
49
+ */
50
+ interface ApprovalMiddlewareConfig extends ApprovalConfig {
51
+ /**
52
+ * Custom risk classification for tools.
53
+ *
54
+ * Overrides the built-in risk map. Tools not listed here
55
+ * fall back to the default classification.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * customRisks: {
60
+ * "my_deploy_tool": "dangerous",
61
+ * "my_lint_tool": "safe",
62
+ * }
63
+ * ```
64
+ */
65
+ customRisks?: Record<string, RiskLevel>;
66
+ }
67
+ /**
68
+ * Create an approval middleware from an ApprovalConfig.
69
+ *
70
+ * This bridges the existing `createApprovalHandler` into the middleware
71
+ * system. The `beforeToolCall` hook checks rules, classifies risk,
72
+ * and calls the approval handler when needed.
73
+ *
74
+ * @param config - Approval configuration (rules, handler, timeout, etc.)
75
+ * @returns An AgentMiddleware that gates tool execution
76
+ */
77
+ declare function approvalMiddleware(config?: ApprovalMiddlewareConfig): AgentMiddleware;
78
+
79
+ /**
80
+ * Configuration for the OpenTelemetry middleware.
81
+ */
82
+ interface OtelMiddlewareConfig {
83
+ /**
84
+ * Whether to record tool call arguments as span attributes.
85
+ * Defaults to `true`.
86
+ */
87
+ recordInputs?: boolean;
88
+ /**
89
+ * Whether to record tool results as span attributes.
90
+ * Defaults to `true`.
91
+ */
92
+ recordOutputs?: boolean;
93
+ /**
94
+ * Agent name — used in the root span name and attributes.
95
+ * Falls back to `"agent"`.
96
+ */
97
+ agentName?: string;
98
+ /** Agent description — recorded as `gen_ai.agent.description`. */
99
+ agentDescription?: string;
100
+ /**
101
+ * Whether to emit `execute_tool` spans for tool calls.
102
+ * Defaults to `true`.
103
+ */
104
+ emitToolSpans?: boolean;
105
+ /**
106
+ * TTL in milliseconds for orphaned spans.
107
+ * Defaults to 5 minutes.
108
+ */
109
+ spanTimeoutMs?: number;
110
+ }
111
+ /**
112
+ * Configuration for `createTelemetryConfig()`.
113
+ */
114
+ interface TelemetryConfig {
115
+ /** Agent name — used in span names and `gen_ai.agent.name`. */
116
+ agentName: string;
117
+ /** Agent description — recorded as `gen_ai.agent.description`. */
118
+ agentDescription?: string;
119
+ /** Record tool arguments and LLM prompts in spans. Defaults to `true`. */
120
+ recordInputs?: boolean;
121
+ /** Record tool results and LLM responses in spans. Defaults to `true`. */
122
+ recordOutputs?: boolean;
123
+ /** Emit `execute_tool` spans from our middleware. Defaults to `true`. */
124
+ emitToolSpans?: boolean;
125
+ /** TTL in ms for orphaned spans. Defaults to 5 minutes. */
126
+ spanTimeoutMs?: number;
127
+ /**
128
+ * An OTel `SpanProcessor` to auto-create and register a `NodeTracerProvider`.
129
+ */
130
+ spanProcessor?: unknown;
131
+ /**
132
+ * OTel service name for the `NodeTracerProvider` resource.
133
+ * Defaults to `agentName`.
134
+ */
135
+ serviceName?: string;
136
+ }
137
+ /**
138
+ * Result of `createTelemetryConfig()`.
139
+ */
140
+ interface TelemetryConfigResult {
141
+ /** Agent-core middleware. */
142
+ middleware: AgentMiddleware;
143
+ /** AI SDK telemetry settings. */
144
+ telemetry: TelemetrySettings;
145
+ /**
146
+ * Flush and shut down the auto-created tracer provider.
147
+ * No-op when no provider was auto-created.
148
+ */
149
+ shutdown: () => Promise<void>;
150
+ }
151
+
152
+ declare function otelMiddleware(config?: OtelMiddlewareConfig): AgentMiddleware;
153
+
154
+ declare function createTelemetryConfig(config: TelemetryConfig): TelemetryConfigResult;
155
+
156
+ /**
157
+ * Prompt Cache Middleware — Type definitions.
158
+ *
159
+ * The middleware auto-detects the model provider and applies the right
160
+ * caching strategy. Currently supports Anthropic's `cache_control`
161
+ * with ephemeral breakpoints. Other providers pass through unchanged
162
+ * until their caching strategy is implemented.
163
+ */
164
+ /**
165
+ * Supported cache TTL values.
166
+ *
167
+ * - `"5m"` — 5-minute cache (default, ~90% input cost reduction on Anthropic)
168
+ * - `"1h"` — 1-hour cache (higher write cost, longer retention)
169
+ */
170
+ type CacheTTL = "5m" | "1h";
171
+ /**
172
+ * Configuration for the prompt cache middleware.
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * // Auto-detect provider, 5-minute TTL
177
+ * promptCacheMiddleware()
178
+ *
179
+ * // Custom TTL
180
+ * promptCacheMiddleware({ ttl: "1h" })
181
+ *
182
+ * // Custom breakpoint strategy (Anthropic)
183
+ * promptCacheMiddleware({ messageBreakpoints: 2 })
184
+ * ```
185
+ */
186
+ interface PromptCacheConfig {
187
+ /**
188
+ * Cache TTL. Defaults to `"5m"`.
189
+ *
190
+ * - `"5m"` — 5 minutes.
191
+ * - `"1h"` — 1 hour.
192
+ */
193
+ ttl?: CacheTTL;
194
+ /**
195
+ * Number of cache breakpoints to place on conversation messages.
196
+ *
197
+ * For Anthropic: max 4 breakpoints total (system always gets 1).
198
+ * This controls additional breakpoints on conversation messages.
199
+ *
200
+ * Defaults to `1` (system + 1 message boundary = 2 breakpoints).
201
+ * Set to `0` to only cache the system prompt.
202
+ */
203
+ messageBreakpoints?: number;
204
+ }
205
+
206
+ /**
207
+ * Prompt Cache Middleware — provider-dispatched prompt caching.
208
+ *
209
+ * Auto-detects the model provider and applies the right caching strategy:
210
+ *
211
+ * - **Anthropic**: Sets `cache_control: { type: "ephemeral" }` breakpoints
212
+ * on system prompt and stable conversation messages. Up to 4 breakpoints.
213
+ *
214
+ * - **Other providers**: Pass through unchanged (strategies can be added).
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * import { promptCacheMiddleware } from "@cuylabs/agent-core/middleware";
219
+ *
220
+ * const agent = createAgent({
221
+ * model: anthropic("claude-sonnet-4-20250514"),
222
+ * middleware: [promptCacheMiddleware()],
223
+ * });
224
+ * ```
225
+ */
226
+
227
+ /**
228
+ * Create a prompt cache middleware that auto-detects the model provider
229
+ * and applies the right caching strategy.
230
+ *
231
+ * Currently supported:
232
+ * - **Anthropic** — `cache_control` breakpoints on system + messages
233
+ *
234
+ * Unsupported providers pass through unchanged.
235
+ *
236
+ * @param config - Optional TTL and breakpoint settings
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // Works with any supported provider — auto-detects
241
+ * const agent = createAgent({
242
+ * model: anthropic("claude-sonnet-4-20250514"),
243
+ * middleware: [promptCacheMiddleware()],
244
+ * });
245
+ * ```
246
+ */
247
+ declare function promptCacheMiddleware(config?: PromptCacheConfig): AgentMiddleware;
248
+
249
+ export { AgentMiddleware, type ApprovalMiddlewareConfig, type CacheTTL, type OtelMiddlewareConfig, type PromptCacheConfig, type TelemetryConfig, type TelemetryConfigResult, approvalMiddleware, createTelemetryConfig, otelMiddleware, promptCacheMiddleware };
@@ -2,11 +2,15 @@ import {
2
2
  MiddlewareRunner,
3
3
  approvalMiddleware,
4
4
  createTelemetryConfig,
5
- otelMiddleware
6
- } from "../chunk-O2ZCFQL6.js";
5
+ otelMiddleware,
6
+ promptCacheMiddleware
7
+ } from "../chunk-YSLSEQ6B.js";
8
+ import "../chunk-BFM2YHNM.js";
9
+ import "../chunk-DWYX7ASF.js";
7
10
  export {
8
11
  MiddlewareRunner,
9
12
  approvalMiddleware,
10
13
  createTelemetryConfig,
11
- otelMiddleware
14
+ otelMiddleware,
15
+ promptCacheMiddleware
12
16
  };
@@ -1,7 +1,17 @@
1
- export { g as getModelId, a as getProviderId } from '../identifiers-BLUxFqV_.js';
2
1
  import { LanguageModel } from 'ai';
2
+ import { C as CapabilitySource, S as SourcePriority, b as SourceResult, P as ProviderCompatibility, R as ResolverOptions, a as ModelEntry, M as ModelCapabilities } from '../types-QA4WhEfz.js';
3
+ export { D as DEFAULT_RESOLVER_OPTIONS, I as InputModality, O as OutputModality } from '../types-QA4WhEfz.js';
3
4
 
4
- type AdapterKind = "openai" | "anthropic" | "google" | "openai-compatible";
5
+ /**
6
+ * Extract a model ID string from a LanguageModel instance.
7
+ */
8
+ declare function getModelId(model: LanguageModel): string;
9
+ /**
10
+ * Extract a provider identifier from a LanguageModel instance.
11
+ */
12
+ declare function getProviderId(model: LanguageModel): string | undefined;
13
+
14
+ type AdapterKind = "openai" | "anthropic" | "google" | "openai-compatible" | "openrouter" | "azure" | "bedrock" | "vertex" | "xai" | "mistral" | "groq";
5
15
  type AdapterSettings = {
6
16
  apiKey?: string;
7
17
  baseUrl?: string;
@@ -30,4 +40,217 @@ type Resolver = (key: string) => Promise<LanguageModel>;
30
40
  type SyncResolver = (key: string) => LanguageModel;
31
41
  declare function createResolver(directory: Directory): Resolver;
32
42
 
33
- export { type AdapterSettings, type Directory, type EngineSpec, type ModelSpec, type Resolver, type SyncResolver, createResolver };
43
+ /**
44
+ * Profile-Based Capability Detection for @cuylabs/agent-core
45
+ *
46
+ * Static pattern matching for model capabilities when no external data is available.
47
+ * This is the fallback layer — always works offline.
48
+ */
49
+
50
+ /**
51
+ * Infer context window size (in tokens) from a model ID.
52
+ *
53
+ * Uses local pattern matching — no network calls, always fast.
54
+ * Returns `undefined` if the model isn't recognized.
55
+ */
56
+ declare function inferContextWindow(modelId: string): number | undefined;
57
+ /**
58
+ * Infer provider from model ID
59
+ */
60
+ declare function inferProvider(modelId: string): string | undefined;
61
+ /**
62
+ * Pattern-based capability source
63
+ * Always available, uses heuristics to detect capabilities
64
+ */
65
+ declare class PatternCapabilitySource implements CapabilitySource {
66
+ readonly priority = SourcePriority.PatternMatch;
67
+ readonly name = "Pattern Matching";
68
+ lookup(modelId: string, providerHint?: string): Promise<SourceResult>;
69
+ isAvailable(): Promise<boolean>;
70
+ }
71
+ /**
72
+ * Quick check if a model ID likely supports reasoning
73
+ */
74
+ declare function likelySupportsReasoning(modelId: string): boolean;
75
+ /**
76
+ * Get provider compatibility for a model
77
+ */
78
+ declare function getProviderCompatibility(modelId: string, provider?: string): ProviderCompatibility | undefined;
79
+
80
+ type CapabilityOverrides = ResolverOptions["modelOverrides"];
81
+ type OverrideLookup = {
82
+ override?: Partial<ModelCapabilities>;
83
+ matchedKey?: string;
84
+ };
85
+ declare function findCapabilityOverride(overrides: CapabilityOverrides, modelId: string, provider?: string): OverrideLookup;
86
+ declare function applyCapabilityOverride(entry: ModelEntry, override?: Partial<ModelCapabilities>): ModelEntry;
87
+
88
+ declare class CapabilityCache {
89
+ private adapter;
90
+ private memoryCache;
91
+ private ttlMs;
92
+ private loaded;
93
+ constructor(options?: Partial<ResolverOptions>);
94
+ private load;
95
+ get(modelId: string, provider?: string): Promise<ModelEntry | undefined>;
96
+ set(entry: ModelEntry): Promise<void>;
97
+ setMany(entries: ModelEntry[]): Promise<void>;
98
+ persist(): Promise<void>;
99
+ clear(): Promise<void>;
100
+ stats(): {
101
+ size: number;
102
+ loaded: boolean;
103
+ };
104
+ getAll(): Promise<ModelEntry[]>;
105
+ getAllByProvider(): Promise<Record<string, ModelEntry[]>>;
106
+ }
107
+ declare class CacheCapabilitySource implements CapabilitySource {
108
+ private cache;
109
+ readonly priority = SourcePriority.LocalCache;
110
+ readonly name = "Local Cache";
111
+ constructor(cache: CapabilityCache);
112
+ lookup(modelId: string, provider?: string): Promise<SourceResult>;
113
+ isAvailable(): Promise<boolean>;
114
+ }
115
+
116
+ interface NetworkStatus {
117
+ online: boolean;
118
+ lastSuccess?: number;
119
+ lastError?: string;
120
+ failureCount: number;
121
+ }
122
+
123
+ declare function getNetworkStatus(): NetworkStatus;
124
+
125
+ declare class RemoteCapabilityFetcher {
126
+ private apiUrl;
127
+ private timeoutMs;
128
+ private cache;
129
+ private lastFetchTime;
130
+ private minFetchInterval;
131
+ constructor(cache: CapabilityCache, options?: Partial<ResolverOptions>);
132
+ fetchAll(): Promise<ModelEntry[]>;
133
+ ping(): Promise<boolean>;
134
+ }
135
+
136
+ declare class RemoteCapabilitySource implements CapabilitySource {
137
+ readonly priority = SourcePriority.RemoteAPI;
138
+ readonly name = "Remote API (models.dev)";
139
+ private fetcher;
140
+ private cache;
141
+ private fetchPromise;
142
+ private enabled;
143
+ constructor(cache: CapabilityCache, options?: Partial<ResolverOptions>);
144
+ lookup(modelId: string, provider?: string): Promise<SourceResult>;
145
+ isAvailable(): Promise<boolean>;
146
+ refresh(): Promise<void>;
147
+ }
148
+
149
+ /**
150
+ * Model Capability Resolver for @cuylabs/agent-core
151
+ *
152
+ * Main orchestrator that combines multiple capability sources:
153
+ * 1. User overrides (highest priority)
154
+ * 2. Local cache (fast, persisted)
155
+ * 3. Pattern matching (always available)
156
+ * 4. Remote API (optional, network-dependent)
157
+ *
158
+ * Designed for the Vercel AI SDK v6 ecosystem.
159
+ */
160
+
161
+ /**
162
+ * Extract model ID from LanguageModel
163
+ */
164
+ declare function extractModelId(model: LanguageModel): string;
165
+ /**
166
+ * Extract provider from LanguageModel
167
+ */
168
+ declare function extractProvider(model: LanguageModel): string | undefined;
169
+ /**
170
+ * Resolution result with source information
171
+ */
172
+ interface ResolutionResult {
173
+ /** The resolved model entry */
174
+ entry: ModelEntry;
175
+ /** Which source provided the primary result */
176
+ source: SourcePriority;
177
+ /** Whether this is a confident match */
178
+ confident: boolean;
179
+ /** Resolution timing in ms */
180
+ resolveTimeMs: number;
181
+ }
182
+ /**
183
+ * Model Capability Resolver
184
+ *
185
+ * Provides a unified API for querying model capabilities with
186
+ * automatic fallback through multiple sources.
187
+ */
188
+ declare class ModelCapabilityResolver {
189
+ private options;
190
+ private cache;
191
+ private sources;
192
+ private initialized;
193
+ private initPromise;
194
+ constructor(options?: Partial<ResolverOptions>);
195
+ /**
196
+ * Initialize the resolver (load cache, optionally fetch remote)
197
+ */
198
+ initialize(): Promise<void>;
199
+ /**
200
+ * Resolve capabilities for a model
201
+ */
202
+ resolve(model: LanguageModel): Promise<ResolutionResult>;
203
+ /**
204
+ * Quick check if a model supports reasoning
205
+ * Uses cache/patterns only for speed
206
+ */
207
+ supportsReasoning(model: LanguageModel): Promise<boolean>;
208
+ /**
209
+ * Get capabilities for a model
210
+ */
211
+ getCapabilities(model: LanguageModel): Promise<ModelCapabilities>;
212
+ /**
213
+ * Get provider compatibility settings
214
+ */
215
+ getCompatibility(model: LanguageModel): Promise<ProviderCompatibility | undefined>;
216
+ /**
217
+ * Force refresh from remote API
218
+ */
219
+ refreshRemote(): Promise<void>;
220
+ /**
221
+ * Get current network status
222
+ */
223
+ getNetworkStatus(): NetworkStatus;
224
+ /**
225
+ * Get resolver statistics
226
+ */
227
+ getStats(): {
228
+ cacheSize: number;
229
+ cacheLoaded: boolean;
230
+ remoteFetchEnabled: boolean;
231
+ networkOnline: boolean;
232
+ };
233
+ /**
234
+ * Clear all cached data
235
+ */
236
+ clearCache(): Promise<void>;
237
+ /**
238
+ * List all available models
239
+ * Fetches from remote if cache is empty and remote is enabled
240
+ */
241
+ listModels(): Promise<ModelEntry[]>;
242
+ /**
243
+ * List all available models grouped by provider
244
+ */
245
+ listModelsByProvider(): Promise<Record<string, ModelEntry[]>>;
246
+ }
247
+ /**
248
+ * Get the default resolver instance
249
+ */
250
+ declare function getDefaultResolver(): ModelCapabilityResolver;
251
+ /**
252
+ * Configure the default resolver with custom options
253
+ */
254
+ declare function configureResolver(options: Partial<ResolverOptions>): void;
255
+
256
+ export { type AdapterSettings, CacheCapabilitySource, CapabilityCache, type CapabilityOverrides, CapabilitySource, type Directory, type EngineSpec, ModelCapabilities, ModelCapabilityResolver, ModelEntry, type ModelSpec, type NetworkStatus, PatternCapabilitySource, ProviderCompatibility, RemoteCapabilityFetcher, RemoteCapabilitySource, type ResolutionResult, type Resolver, ResolverOptions, SourcePriority, SourceResult, type SyncResolver, applyCapabilityOverride, configureResolver, createResolver, extractModelId, extractProvider, findCapabilityOverride, getDefaultResolver, getModelId, getNetworkStatus, getProviderCompatibility, getProviderId, inferContextWindow, inferProvider, likelySupportsReasoning };
@@ -1,12 +1,50 @@
1
1
  import {
2
- createResolver
3
- } from "../chunk-6TDTQJ4P.js";
2
+ CacheCapabilitySource,
3
+ CapabilityCache,
4
+ DEFAULT_RESOLVER_OPTIONS,
5
+ ModelCapabilityResolver,
6
+ PatternCapabilitySource,
7
+ RemoteCapabilityFetcher,
8
+ RemoteCapabilitySource,
9
+ SourcePriority,
10
+ applyCapabilityOverride,
11
+ configureResolver,
12
+ createResolver,
13
+ extractModelId,
14
+ extractProvider,
15
+ findCapabilityOverride,
16
+ getDefaultResolver,
17
+ getNetworkStatus,
18
+ getProviderCompatibility,
19
+ inferContextWindow,
20
+ inferProvider,
21
+ likelySupportsReasoning
22
+ } from "../chunk-RFEKJKTO.js";
4
23
  import {
5
24
  getModelId,
6
25
  getProviderId
7
26
  } from "../chunk-DWYX7ASF.js";
8
27
  export {
28
+ CacheCapabilitySource,
29
+ CapabilityCache,
30
+ DEFAULT_RESOLVER_OPTIONS,
31
+ ModelCapabilityResolver,
32
+ PatternCapabilitySource,
33
+ RemoteCapabilityFetcher,
34
+ RemoteCapabilitySource,
35
+ SourcePriority,
36
+ applyCapabilityOverride,
37
+ configureResolver,
9
38
  createResolver,
39
+ extractModelId,
40
+ extractProvider,
41
+ findCapabilityOverride,
42
+ getDefaultResolver,
10
43
  getModelId,
11
- getProviderId
44
+ getNetworkStatus,
45
+ getProviderCompatibility,
46
+ getProviderId,
47
+ inferContextWindow,
48
+ inferProvider,
49
+ likelySupportsReasoning
12
50
  };