@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.
- package/dist/{builder-BRvqCcIk.d.ts → builder-BgZ_j4Vs.d.ts} +3 -2
- package/dist/chunk-4QFNWPIF.js +202 -0
- package/dist/chunk-5ARZJWD2.js +259 -0
- package/dist/chunk-DXFBQMXP.js +53 -0
- package/dist/chunk-EKR6PKXU.js +180 -0
- package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
- package/dist/{chunk-IEFIQENH.js → chunk-H3FUYU52.js} +15 -7
- package/dist/chunk-I6PKJ7XQ.js +292 -0
- package/dist/chunk-IYWQOJMQ.js +102 -0
- package/dist/{chunk-3HNO5SVI.js → chunk-J4QDGZIA.js} +20 -4
- package/dist/{chunk-7MUFEN4K.js → chunk-JLXG2SH7.js} +349 -3
- package/dist/{chunk-CDTV2UYU.js → chunk-MAZ5DY5B.js} +64 -276
- package/dist/{chunk-P6YF7USR.js → chunk-MHKK374K.js} +12 -11
- package/dist/{chunk-VBWWUHWI.js → chunk-OFDKHNCX.js} +4 -1
- package/dist/{chunk-YUUJK53A.js → chunk-RKEW5WXI.js} +1 -1
- package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
- package/dist/{chunk-QGOGIP7T.js → chunk-UDCZ673N.js} +385 -233
- package/dist/{chunk-BDBZ3SLK.js → chunk-UHCJEM2E.js} +39 -2
- package/dist/chunk-WGZAPU6N.js +929 -0
- package/dist/{chunk-5K7AQVOU.js → chunk-WKHDSSXG.js} +130 -209
- package/dist/{chunk-BNSHUWCV.js → chunk-WWYYNWEW.js} +1 -1
- package/dist/context/index.js +1 -1
- package/dist/events-CE72w8W4.d.ts +149 -0
- package/dist/index-BCqEGzBj.d.ts +251 -0
- package/dist/{index-C33hlD6H.d.ts → index-DQuTZ8xL.d.ts} +319 -56
- package/dist/index.d.ts +42 -121
- package/dist/index.js +951 -848
- package/dist/inference/errors/index.d.ts +11 -0
- package/dist/inference/errors/index.js +16 -0
- package/dist/inference/index.d.ts +12 -8
- package/dist/inference/index.js +35 -7
- package/dist/llm-error-D93FNNLY.d.ts +32 -0
- package/dist/middleware/index.d.ts +246 -7
- package/dist/middleware/index.js +3 -1
- package/dist/models/index.d.ts +132 -9
- package/dist/models/index.js +48 -8
- package/dist/models/reasoning/index.d.ts +4 -0
- package/dist/{reasoning → models/reasoning}/index.js +2 -7
- package/dist/plugin/index.d.ts +414 -0
- package/dist/plugin/index.js +32 -0
- package/dist/presets/index.d.ts +53 -0
- package/dist/presets/index.js +30 -0
- package/dist/prompt/index.d.ts +11 -8
- package/dist/prompt/index.js +3 -2
- package/dist/{registry-BDLIHOQB.d.ts → registry-DwYqsQkX.d.ts} +1 -1
- package/dist/runner-CI-XeR16.d.ts +91 -0
- package/dist/runtime/index.d.ts +12 -8
- package/dist/runtime/index.js +8 -7
- package/dist/safety/index.d.ts +38 -0
- package/dist/safety/index.js +12 -0
- package/dist/scope/index.d.ts +2 -2
- package/dist/{session-manager-B_CWGTsl.d.ts → session-manager-KbYt2WUh.d.ts} +8 -0
- package/dist/signal/index.d.ts +28 -0
- package/dist/signal/index.js +6 -0
- package/dist/skill/index.d.ts +7 -6
- package/dist/skill/index.js +3 -3
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/sub-agent/index.d.ts +16 -10
- package/dist/sub-agent/index.js +21 -4
- package/dist/tool/index.d.ts +22 -6
- package/dist/tool/index.js +3 -3
- package/dist/tool-CZWN3KbO.d.ts +141 -0
- package/dist/{tool-HUtkiVBx.d.ts → tool-DkhSCV2Y.d.ts} +2 -2
- package/dist/tracking/index.d.ts +2 -2
- package/dist/tracking/index.js +1 -1
- package/dist/{tool-Db1Ue-1U.d.ts → types-BfNpU8NS.d.ts} +1 -150
- package/dist/{types-FRpzzg_9.d.ts → types-BlOKk-Bb.d.ts} +10 -35
- package/dist/types-BlZwmnuW.d.ts +50 -0
- package/dist/{types-9jGQUjqW.d.ts → types-CQL-SvTn.d.ts} +1 -1
- package/dist/types-CWm-7rvB.d.ts +55 -0
- package/dist/{runner-DSKaEz3z.d.ts → types-DTSkxakL.d.ts} +7 -235
- package/dist/{types-CqDZTh4d.d.ts → types-DmDwi2zI.d.ts} +8 -4
- package/dist/types-YuWV4ag7.d.ts +72 -0
- package/package.json +67 -6
- package/dist/capability-resolver-CgRGsWVX.d.ts +0 -254
- package/dist/chunk-ZPMACVZK.js +0 -305
- package/dist/index-CfBGYrpd.d.ts +0 -317
- package/dist/reasoning/index.d.ts +0 -117
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { E as ErrorCategory, R as ResponseHeaders } from '../../llm-error-D93FNNLY.js';
|
|
2
|
+
export { L as LLMError, a as LLMErrorOptions } from '../../llm-error-D93FNNLY.js';
|
|
3
|
+
|
|
4
|
+
declare function isRetryableCategory(category: ErrorCategory): boolean;
|
|
5
|
+
declare function parseRetryDelay(headers: ResponseHeaders): number | undefined;
|
|
6
|
+
|
|
7
|
+
declare function isRetryable(error: unknown): boolean;
|
|
8
|
+
declare function getRetryDelay(error: unknown): number | undefined;
|
|
9
|
+
declare function getErrorCategory(error: unknown): ErrorCategory;
|
|
10
|
+
|
|
11
|
+
export { ErrorCategory, ResponseHeaders, getErrorCategory, getRetryDelay, isRetryable, isRetryableCategory, parseRetryDelay };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LLMError,
|
|
3
|
+
getErrorCategory,
|
|
4
|
+
getRetryDelay,
|
|
5
|
+
isRetryable,
|
|
6
|
+
isRetryableCategory,
|
|
7
|
+
parseRetryDelay
|
|
8
|
+
} from "../../chunk-4QFNWPIF.js";
|
|
9
|
+
export {
|
|
10
|
+
LLMError,
|
|
11
|
+
getErrorCategory,
|
|
12
|
+
getRetryDelay,
|
|
13
|
+
isRetryable,
|
|
14
|
+
isRetryableCategory,
|
|
15
|
+
parseRetryDelay
|
|
16
|
+
};
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { ToolSet } from 'ai';
|
|
2
|
-
import { T as Tool } from '../tool-
|
|
2
|
+
import { T as Tool } from '../tool-CZWN3KbO.js';
|
|
3
3
|
import { T as ToolHost } from '../types-CHiPh8U2.js';
|
|
4
|
-
import { M as MiddlewareRunner } from '../runner-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
export {
|
|
4
|
+
import { M as MiddlewareRunner } from '../runner-CI-XeR16.js';
|
|
5
|
+
import { d as TurnTrackerContext } from '../tool-DkhSCV2Y.js';
|
|
6
|
+
import { T as ToolExecutionMode, I as InferenceStreamInput, A as AnyInferenceResult } from '../types-BlOKk-Bb.js';
|
|
7
|
+
export { a as AnyStreamResult, C as CustomStreamProvider, b as CustomStreamResult, D as DEFAULT_MAX_OUTPUT_TOKENS, c as DEFAULT_RETRY_CONFIG, d as InferenceCustomResult, e as InferenceStepInfo, f as InferenceStreamResult, L as LLMStreamInput, g as LLMStreamResult, O as OUTPUT_TOKEN_MAX, R as RetryConfig, h as RetryHandlerOptions, i as RetryState, S as StepInfo, j as calculateDelay, k as createRetryHandler, l as createRetryState, s as shouldRetry, m as sleep, w as withRetry } from '../types-BlOKk-Bb.js';
|
|
8
|
+
export { E as ErrorCategory, L as LLMError, a as LLMErrorOptions, R as ResponseHeaders } from '../llm-error-D93FNNLY.js';
|
|
9
|
+
export { getErrorCategory, getRetryDelay, isRetryable, isRetryableCategory, parseRetryDelay } from './errors/index.js';
|
|
10
|
+
export { S as StreamChunk } from '../types-DTSkxakL.js';
|
|
9
11
|
import 'zod';
|
|
10
|
-
import '
|
|
12
|
+
import '../events-CE72w8W4.js';
|
|
11
13
|
import '../messages-BYWGn8TY.js';
|
|
12
|
-
import '../types-
|
|
14
|
+
import '../types-CQL-SvTn.js';
|
|
13
15
|
import '../types-CQaXbRsS.js';
|
|
16
|
+
import '@ai-sdk/provider-utils';
|
|
17
|
+
import '../types-BfNpU8NS.js';
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* Build a Vercel AI SDK `ToolSet` from `Tool.Info` definitions.
|
package/dist/inference/index.js
CHANGED
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
3
|
+
DEFAULT_RETRY_CONFIG,
|
|
3
4
|
Inference,
|
|
4
5
|
LLM,
|
|
5
6
|
OUTPUT_TOKEN_MAX,
|
|
6
7
|
buildToolSet,
|
|
8
|
+
calculateDelay,
|
|
9
|
+
createRetryHandler,
|
|
10
|
+
createRetryState,
|
|
11
|
+
shouldRetry,
|
|
12
|
+
sleep,
|
|
7
13
|
stream,
|
|
8
14
|
streamOnce,
|
|
9
|
-
streamStep
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-N7P4PN3O.js";
|
|
15
|
+
streamStep,
|
|
16
|
+
withRetry
|
|
17
|
+
} from "../chunk-WKHDSSXG.js";
|
|
18
|
+
import "../chunk-H3FUYU52.js";
|
|
14
19
|
import "../chunk-VEKUXUVF.js";
|
|
15
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
LLMError,
|
|
22
|
+
getErrorCategory,
|
|
23
|
+
getRetryDelay,
|
|
24
|
+
isRetryable,
|
|
25
|
+
isRetryableCategory,
|
|
26
|
+
parseRetryDelay
|
|
27
|
+
} from "../chunk-4QFNWPIF.js";
|
|
28
|
+
import "../chunk-N7P4PN3O.js";
|
|
29
|
+
import "../chunk-UDCZ673N.js";
|
|
30
|
+
import "../chunk-I6PKJ7XQ.js";
|
|
16
31
|
export {
|
|
17
32
|
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
33
|
+
DEFAULT_RETRY_CONFIG,
|
|
18
34
|
Inference,
|
|
19
35
|
LLM,
|
|
36
|
+
LLMError,
|
|
20
37
|
OUTPUT_TOKEN_MAX,
|
|
21
38
|
buildToolSet,
|
|
39
|
+
calculateDelay,
|
|
40
|
+
createRetryHandler,
|
|
41
|
+
createRetryState,
|
|
42
|
+
getErrorCategory,
|
|
43
|
+
getRetryDelay,
|
|
44
|
+
isRetryable,
|
|
45
|
+
isRetryableCategory,
|
|
46
|
+
parseRetryDelay,
|
|
47
|
+
shouldRetry,
|
|
48
|
+
sleep,
|
|
22
49
|
stream,
|
|
23
50
|
streamOnce,
|
|
24
|
-
streamStep
|
|
51
|
+
streamStep,
|
|
52
|
+
withRetry
|
|
25
53
|
};
|
|
@@ -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,11 +1,250 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
1
|
+
import { A as AgentMiddleware } from '../types-DTSkxakL.js';
|
|
2
|
+
export { g as AgentModelHooks, B as BlockedModelCall, a as ModelCallContext, M as ModelCallInput, b as ModelCallOutput, T as ToolCallDecision } from '../types-DTSkxakL.js';
|
|
3
|
+
export { M as MiddlewareRunner } from '../runner-CI-XeR16.js';
|
|
4
|
+
import { a as ApprovalConfig, R as RiskLevel } from '../types-CWm-7rvB.js';
|
|
5
|
+
import { TelemetrySettings } from 'ai';
|
|
4
6
|
import '@ai-sdk/provider-utils';
|
|
7
|
+
import '../events-CE72w8W4.js';
|
|
5
8
|
import '../messages-BYWGn8TY.js';
|
|
6
|
-
import '../
|
|
7
|
-
import '
|
|
8
|
-
import '../tool-
|
|
9
|
+
import '../types-BfNpU8NS.js';
|
|
10
|
+
import '../types-CQL-SvTn.js';
|
|
11
|
+
import '../tool-DkhSCV2Y.js';
|
|
9
12
|
import '../types-CHiPh8U2.js';
|
|
10
|
-
import '../
|
|
13
|
+
import '../tool-CZWN3KbO.js';
|
|
14
|
+
import 'zod';
|
|
11
15
|
import '../types-CQaXbRsS.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Approval Middleware
|
|
19
|
+
*
|
|
20
|
+
* Wraps the existing approval system as an AgentMiddleware.
|
|
21
|
+
* This is how approval finally gets wired into the tool execution
|
|
22
|
+
* pipeline — no more dead code.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { createAgent, approvalMiddleware } from "@cuylabs/agent-core";
|
|
27
|
+
*
|
|
28
|
+
* const agent = createAgent({
|
|
29
|
+
* model: anthropic("claude-sonnet-4-20250514"),
|
|
30
|
+
* tools: [read, write, bash],
|
|
31
|
+
* middleware: [
|
|
32
|
+
* approvalMiddleware({
|
|
33
|
+
* rules: [
|
|
34
|
+
* { pattern: "src/*", tool: "read_file", action: "allow" },
|
|
35
|
+
* ],
|
|
36
|
+
* onRequest: async (req) => {
|
|
37
|
+
* // Prompt user in your UI
|
|
38
|
+
* return await askUser(req);
|
|
39
|
+
* },
|
|
40
|
+
* }),
|
|
41
|
+
* ],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Configuration for the approval middleware.
|
|
48
|
+
*
|
|
49
|
+
* Extends the existing ApprovalConfig with middleware-specific options.
|
|
50
|
+
*/
|
|
51
|
+
interface ApprovalMiddlewareConfig extends ApprovalConfig {
|
|
52
|
+
/**
|
|
53
|
+
* Custom risk classification for tools.
|
|
54
|
+
*
|
|
55
|
+
* Overrides the built-in risk map. Tools not listed here
|
|
56
|
+
* fall back to the default classification.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* customRisks: {
|
|
61
|
+
* "my_deploy_tool": "dangerous",
|
|
62
|
+
* "my_lint_tool": "safe",
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
customRisks?: Record<string, RiskLevel>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create an approval middleware from an ApprovalConfig.
|
|
70
|
+
*
|
|
71
|
+
* This bridges the existing `createApprovalHandler` into the middleware
|
|
72
|
+
* system. The `beforeToolCall` hook checks rules, classifies risk,
|
|
73
|
+
* and calls the approval handler when needed.
|
|
74
|
+
*
|
|
75
|
+
* @param config - Approval configuration (rules, handler, timeout, etc.)
|
|
76
|
+
* @returns An AgentMiddleware that gates tool execution
|
|
77
|
+
*/
|
|
78
|
+
declare function approvalMiddleware(config?: ApprovalMiddlewareConfig): AgentMiddleware;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Configuration for the OpenTelemetry middleware.
|
|
82
|
+
*/
|
|
83
|
+
interface OtelMiddlewareConfig {
|
|
84
|
+
/**
|
|
85
|
+
* Whether to record tool call arguments as span attributes.
|
|
86
|
+
* Defaults to `true`.
|
|
87
|
+
*/
|
|
88
|
+
recordInputs?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Whether to record tool results as span attributes.
|
|
91
|
+
* Defaults to `true`.
|
|
92
|
+
*/
|
|
93
|
+
recordOutputs?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Agent name — used in the root span name and attributes.
|
|
96
|
+
* Falls back to `"agent"`.
|
|
97
|
+
*/
|
|
98
|
+
agentName?: string;
|
|
99
|
+
/** Agent description — recorded as `gen_ai.agent.description`. */
|
|
100
|
+
agentDescription?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Whether to emit `execute_tool` spans for tool calls.
|
|
103
|
+
* Defaults to `true`.
|
|
104
|
+
*/
|
|
105
|
+
emitToolSpans?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* TTL in milliseconds for orphaned spans.
|
|
108
|
+
* Defaults to 5 minutes.
|
|
109
|
+
*/
|
|
110
|
+
spanTimeoutMs?: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Configuration for `createTelemetryConfig()`.
|
|
114
|
+
*/
|
|
115
|
+
interface TelemetryConfig {
|
|
116
|
+
/** Agent name — used in span names and `gen_ai.agent.name`. */
|
|
117
|
+
agentName: string;
|
|
118
|
+
/** Agent description — recorded as `gen_ai.agent.description`. */
|
|
119
|
+
agentDescription?: string;
|
|
120
|
+
/** Record tool arguments and LLM prompts in spans. Defaults to `true`. */
|
|
121
|
+
recordInputs?: boolean;
|
|
122
|
+
/** Record tool results and LLM responses in spans. Defaults to `true`. */
|
|
123
|
+
recordOutputs?: boolean;
|
|
124
|
+
/** Emit `execute_tool` spans from our middleware. Defaults to `true`. */
|
|
125
|
+
emitToolSpans?: boolean;
|
|
126
|
+
/** TTL in ms for orphaned spans. Defaults to 5 minutes. */
|
|
127
|
+
spanTimeoutMs?: number;
|
|
128
|
+
/**
|
|
129
|
+
* An OTel `SpanProcessor` to auto-create and register a `NodeTracerProvider`.
|
|
130
|
+
*/
|
|
131
|
+
spanProcessor?: unknown;
|
|
132
|
+
/**
|
|
133
|
+
* OTel service name for the `NodeTracerProvider` resource.
|
|
134
|
+
* Defaults to `agentName`.
|
|
135
|
+
*/
|
|
136
|
+
serviceName?: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Result of `createTelemetryConfig()`.
|
|
140
|
+
*/
|
|
141
|
+
interface TelemetryConfigResult {
|
|
142
|
+
/** Agent-core middleware. */
|
|
143
|
+
middleware: AgentMiddleware;
|
|
144
|
+
/** AI SDK telemetry settings. */
|
|
145
|
+
telemetry: TelemetrySettings;
|
|
146
|
+
/**
|
|
147
|
+
* Flush and shut down the auto-created tracer provider.
|
|
148
|
+
* No-op when no provider was auto-created.
|
|
149
|
+
*/
|
|
150
|
+
shutdown: () => Promise<void>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare function otelMiddleware(config?: OtelMiddlewareConfig): AgentMiddleware;
|
|
154
|
+
|
|
155
|
+
declare function createTelemetryConfig(config: TelemetryConfig): TelemetryConfigResult;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Prompt Cache Middleware — Type definitions.
|
|
159
|
+
*
|
|
160
|
+
* The middleware auto-detects the model provider and applies the right
|
|
161
|
+
* caching strategy. Currently supports Anthropic's `cache_control`
|
|
162
|
+
* with ephemeral breakpoints. Other providers pass through unchanged
|
|
163
|
+
* until their caching strategy is implemented.
|
|
164
|
+
*/
|
|
165
|
+
/**
|
|
166
|
+
* Supported cache TTL values.
|
|
167
|
+
*
|
|
168
|
+
* - `"5m"` — 5-minute cache (default, ~90% input cost reduction on Anthropic)
|
|
169
|
+
* - `"1h"` — 1-hour cache (higher write cost, longer retention)
|
|
170
|
+
*/
|
|
171
|
+
type CacheTTL = "5m" | "1h";
|
|
172
|
+
/**
|
|
173
|
+
* Configuration for the prompt cache middleware.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // Auto-detect provider, 5-minute TTL
|
|
178
|
+
* promptCacheMiddleware()
|
|
179
|
+
*
|
|
180
|
+
* // Custom TTL
|
|
181
|
+
* promptCacheMiddleware({ ttl: "1h" })
|
|
182
|
+
*
|
|
183
|
+
* // Custom breakpoint strategy (Anthropic)
|
|
184
|
+
* promptCacheMiddleware({ messageBreakpoints: 2 })
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
interface PromptCacheConfig {
|
|
188
|
+
/**
|
|
189
|
+
* Cache TTL. Defaults to `"5m"`.
|
|
190
|
+
*
|
|
191
|
+
* - `"5m"` — 5 minutes.
|
|
192
|
+
* - `"1h"` — 1 hour.
|
|
193
|
+
*/
|
|
194
|
+
ttl?: CacheTTL;
|
|
195
|
+
/**
|
|
196
|
+
* Number of cache breakpoints to place on conversation messages.
|
|
197
|
+
*
|
|
198
|
+
* For Anthropic: max 4 breakpoints total (system always gets 1).
|
|
199
|
+
* This controls additional breakpoints on conversation messages.
|
|
200
|
+
*
|
|
201
|
+
* Defaults to `1` (system + 1 message boundary = 2 breakpoints).
|
|
202
|
+
* Set to `0` to only cache the system prompt.
|
|
203
|
+
*/
|
|
204
|
+
messageBreakpoints?: number;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Prompt Cache Middleware — provider-dispatched prompt caching.
|
|
209
|
+
*
|
|
210
|
+
* Auto-detects the model provider and applies the right caching strategy:
|
|
211
|
+
*
|
|
212
|
+
* - **Anthropic**: Sets `cache_control: { type: "ephemeral" }` breakpoints
|
|
213
|
+
* on system prompt and stable conversation messages. Up to 4 breakpoints.
|
|
214
|
+
*
|
|
215
|
+
* - **Other providers**: Pass through unchanged (strategies can be added).
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* import { promptCacheMiddleware } from "@cuylabs/agent-core/middleware";
|
|
220
|
+
*
|
|
221
|
+
* const agent = createAgent({
|
|
222
|
+
* model: anthropic("claude-sonnet-4-20250514"),
|
|
223
|
+
* middleware: [promptCacheMiddleware()],
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Create a prompt cache middleware that auto-detects the model provider
|
|
230
|
+
* and applies the right caching strategy.
|
|
231
|
+
*
|
|
232
|
+
* Currently supported:
|
|
233
|
+
* - **Anthropic** — `cache_control` breakpoints on system + messages
|
|
234
|
+
*
|
|
235
|
+
* Unsupported providers pass through unchanged.
|
|
236
|
+
*
|
|
237
|
+
* @param config - Optional TTL and breakpoint settings
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* // Works with any supported provider — auto-detects
|
|
242
|
+
* const agent = createAgent({
|
|
243
|
+
* model: anthropic("claude-sonnet-4-20250514"),
|
|
244
|
+
* middleware: [promptCacheMiddleware()],
|
|
245
|
+
* });
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
declare function promptCacheMiddleware(config?: PromptCacheConfig): AgentMiddleware;
|
|
249
|
+
|
|
250
|
+
export { AgentMiddleware, type ApprovalMiddlewareConfig, type CacheTTL, type OtelMiddlewareConfig, type PromptCacheConfig, type TelemetryConfig, type TelemetryConfigResult, approvalMiddleware, createTelemetryConfig, otelMiddleware, promptCacheMiddleware };
|
package/dist/middleware/index.js
CHANGED
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
createTelemetryConfig,
|
|
5
5
|
otelMiddleware,
|
|
6
6
|
promptCacheMiddleware
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-MAZ5DY5B.js";
|
|
8
|
+
import "../chunk-5ARZJWD2.js";
|
|
9
|
+
import "../chunk-I6PKJ7XQ.js";
|
|
8
10
|
export {
|
|
9
11
|
MiddlewareRunner,
|
|
10
12
|
approvalMiddleware,
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { LanguageModel } from 'ai';
|
|
2
|
-
import { C as CapabilitySource, S as SourcePriority,
|
|
3
|
-
export { D as DEFAULT_RESOLVER_OPTIONS, I as InputModality,
|
|
2
|
+
import { C as CapabilitySource, S as SourcePriority, b as SourceResult, P as ProviderCompatibility, R as ResolverOptions, a as ModelEntry, M as ModelCapabilities } from '../index-BCqEGzBj.js';
|
|
3
|
+
export { D as DEFAULT_RESOLVER_OPTIONS, I as InputModality, O as OutputModality, c as buildAnthropicOptions, d as buildBedrockOptions, e as buildGoogleOptions, f as buildGroqOptions, g as buildOpenAIOptions, h as buildOpenRouterOptions, i as buildReasoningOptions, j as buildReasoningOptionsSync, k as buildXAIOptions, l as getProviderOptionsKey, m as getReasoningConfig, n as getReasoningConfigSync, s as supportsReasoning, o as supportsReasoningSync } from '../index-BCqEGzBj.js';
|
|
4
|
+
export { E as EXTENDED_LEVELS, F as FIXED_LEVELS, a as ReasoningConfig, R as ReasoningLevel, S as STANDARD_LEVELS, s as shouldIncludeReasoningSummary } from '../types-CQaXbRsS.js';
|
|
5
|
+
import '@ai-sdk/provider-utils';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Extract a model ID string from a LanguageModel instance.
|
|
@@ -10,8 +12,21 @@ declare function getModelId(model: LanguageModel): string;
|
|
|
10
12
|
* Extract a provider identifier from a LanguageModel instance.
|
|
11
13
|
*/
|
|
12
14
|
declare function getProviderId(model: LanguageModel): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Extract model ID from a LanguageModel.
|
|
17
|
+
*
|
|
18
|
+
* Canonical helper — use this instead of `getModelId` in consumer code.
|
|
19
|
+
*/
|
|
20
|
+
declare const extractModelId: (model: LanguageModel) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Extract provider from a LanguageModel.
|
|
23
|
+
*
|
|
24
|
+
* Tries the model's `.provider` property first, then falls back
|
|
25
|
+
* to pattern-matching the model ID via `inferProvider`.
|
|
26
|
+
*/
|
|
27
|
+
declare function extractProvider(model: LanguageModel): string | undefined;
|
|
13
28
|
|
|
14
|
-
type AdapterKind = "openai" | "anthropic" | "google" | "openai-compatible";
|
|
29
|
+
type AdapterKind = "openai" | "anthropic" | "google" | "openai-compatible" | "openrouter" | "azure" | "bedrock" | "vertex" | "xai" | "mistral" | "groq";
|
|
15
30
|
type AdapterSettings = {
|
|
16
31
|
apiKey?: string;
|
|
17
32
|
baseUrl?: string;
|
|
@@ -33,11 +48,6 @@ type Directory = {
|
|
|
33
48
|
entries?: Record<string, ModelSpec>;
|
|
34
49
|
};
|
|
35
50
|
type Resolver = (key: string) => Promise<LanguageModel>;
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated Use `Resolver` (async) instead. Kept for backwards compatibility
|
|
38
|
-
* with custom `build` functions that return synchronously.
|
|
39
|
-
*/
|
|
40
|
-
type SyncResolver = (key: string) => LanguageModel;
|
|
41
51
|
declare function createResolver(directory: Directory): Resolver;
|
|
42
52
|
|
|
43
53
|
/**
|
|
@@ -47,6 +57,13 @@ declare function createResolver(directory: Directory): Resolver;
|
|
|
47
57
|
* This is the fallback layer — always works offline.
|
|
48
58
|
*/
|
|
49
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Infer context window size (in tokens) from a model ID.
|
|
62
|
+
*
|
|
63
|
+
* Uses local pattern matching — no network calls, always fast.
|
|
64
|
+
* Returns `undefined` if the model isn't recognized.
|
|
65
|
+
*/
|
|
66
|
+
declare function inferContextWindow(modelId: string): number | undefined;
|
|
50
67
|
/**
|
|
51
68
|
* Infer provider from model ID
|
|
52
69
|
*/
|
|
@@ -106,6 +123,13 @@ declare class CacheCapabilitySource implements CapabilitySource {
|
|
|
106
123
|
isAvailable(): Promise<boolean>;
|
|
107
124
|
}
|
|
108
125
|
|
|
126
|
+
interface NetworkStatus {
|
|
127
|
+
online: boolean;
|
|
128
|
+
lastSuccess?: number;
|
|
129
|
+
lastError?: string;
|
|
130
|
+
failureCount: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
109
133
|
declare function getNetworkStatus(): NetworkStatus;
|
|
110
134
|
|
|
111
135
|
declare class RemoteCapabilityFetcher {
|
|
@@ -132,4 +156,103 @@ declare class RemoteCapabilitySource implements CapabilitySource {
|
|
|
132
156
|
refresh(): Promise<void>;
|
|
133
157
|
}
|
|
134
158
|
|
|
135
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Model Capability Resolver for @cuylabs/agent-core
|
|
161
|
+
*
|
|
162
|
+
* Main orchestrator that combines multiple capability sources:
|
|
163
|
+
* 1. User overrides (highest priority)
|
|
164
|
+
* 2. Local cache (fast, persisted)
|
|
165
|
+
* 3. Pattern matching (always available)
|
|
166
|
+
* 4. Remote API (optional, network-dependent)
|
|
167
|
+
*
|
|
168
|
+
* Designed for the Vercel AI SDK v6 ecosystem.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Resolution result with source information
|
|
173
|
+
*/
|
|
174
|
+
interface ResolutionResult {
|
|
175
|
+
/** The resolved model entry */
|
|
176
|
+
entry: ModelEntry;
|
|
177
|
+
/** Which source provided the primary result */
|
|
178
|
+
source: SourcePriority;
|
|
179
|
+
/** Whether this is a confident match */
|
|
180
|
+
confident: boolean;
|
|
181
|
+
/** Resolution timing in ms */
|
|
182
|
+
resolveTimeMs: number;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Model Capability Resolver
|
|
186
|
+
*
|
|
187
|
+
* Provides a unified API for querying model capabilities with
|
|
188
|
+
* automatic fallback through multiple sources.
|
|
189
|
+
*/
|
|
190
|
+
declare class ModelCapabilityResolver {
|
|
191
|
+
private options;
|
|
192
|
+
private cache;
|
|
193
|
+
private sources;
|
|
194
|
+
private initialized;
|
|
195
|
+
private initPromise;
|
|
196
|
+
constructor(options?: Partial<ResolverOptions>);
|
|
197
|
+
/**
|
|
198
|
+
* Initialize the resolver (load cache, optionally fetch remote)
|
|
199
|
+
*/
|
|
200
|
+
initialize(): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Resolve capabilities for a model
|
|
203
|
+
*/
|
|
204
|
+
resolve(model: LanguageModel): Promise<ResolutionResult>;
|
|
205
|
+
/**
|
|
206
|
+
* Quick check if a model supports reasoning
|
|
207
|
+
* Uses cache/patterns only for speed
|
|
208
|
+
*/
|
|
209
|
+
supportsReasoning(model: LanguageModel): Promise<boolean>;
|
|
210
|
+
/**
|
|
211
|
+
* Get capabilities for a model
|
|
212
|
+
*/
|
|
213
|
+
getCapabilities(model: LanguageModel): Promise<ModelCapabilities>;
|
|
214
|
+
/**
|
|
215
|
+
* Get provider compatibility settings
|
|
216
|
+
*/
|
|
217
|
+
getCompatibility(model: LanguageModel): Promise<ProviderCompatibility | undefined>;
|
|
218
|
+
/**
|
|
219
|
+
* Force refresh from remote API
|
|
220
|
+
*/
|
|
221
|
+
refreshRemote(): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Get current network status
|
|
224
|
+
*/
|
|
225
|
+
getNetworkStatus(): NetworkStatus;
|
|
226
|
+
/**
|
|
227
|
+
* Get resolver statistics
|
|
228
|
+
*/
|
|
229
|
+
getStats(): {
|
|
230
|
+
cacheSize: number;
|
|
231
|
+
cacheLoaded: boolean;
|
|
232
|
+
remoteFetchEnabled: boolean;
|
|
233
|
+
networkOnline: boolean;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Clear all cached data
|
|
237
|
+
*/
|
|
238
|
+
clearCache(): Promise<void>;
|
|
239
|
+
/**
|
|
240
|
+
* List all available models
|
|
241
|
+
* Fetches from remote if cache is empty and remote is enabled
|
|
242
|
+
*/
|
|
243
|
+
listModels(): Promise<ModelEntry[]>;
|
|
244
|
+
/**
|
|
245
|
+
* List all available models grouped by provider
|
|
246
|
+
*/
|
|
247
|
+
listModelsByProvider(): Promise<Record<string, ModelEntry[]>>;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get the default resolver instance
|
|
251
|
+
*/
|
|
252
|
+
declare function getDefaultResolver(): ModelCapabilityResolver;
|
|
253
|
+
/**
|
|
254
|
+
* Configure the default resolver with custom options
|
|
255
|
+
*/
|
|
256
|
+
declare function configureResolver(options: Partial<ResolverOptions>): void;
|
|
257
|
+
|
|
258
|
+
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, applyCapabilityOverride, configureResolver, createResolver, extractModelId, extractProvider, findCapabilityOverride, getDefaultResolver, getModelId, getNetworkStatus, getProviderCompatibility, getProviderId, inferContextWindow, inferProvider, likelySupportsReasoning };
|