@chances-ai/engine 30.0.0 → 31.0.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/ai/adapters/ai-sdk-stream.d.ts +13 -1
- package/dist/ai/adapters/ai-sdk-stream.d.ts.map +1 -1
- package/dist/ai/adapters/ai-sdk-stream.js +140 -39
- package/dist/ai/adapters/ai-sdk-stream.js.map +1 -1
- package/dist/ai/adapters/ai-sdk.d.ts +8 -0
- package/dist/ai/adapters/ai-sdk.d.ts.map +1 -1
- package/dist/ai/adapters/ai-sdk.js +39 -1
- package/dist/ai/adapters/ai-sdk.js.map +1 -1
- package/dist/ai/adapters/mock.d.ts.map +1 -1
- package/dist/ai/adapters/mock.js +6 -2
- package/dist/ai/adapters/mock.js.map +1 -1
- package/dist/ai/adapters/native-anthropic.d.ts +51 -0
- package/dist/ai/adapters/native-anthropic.d.ts.map +1 -0
- package/dist/ai/adapters/native-anthropic.js +179 -0
- package/dist/ai/adapters/native-anthropic.js.map +1 -0
- package/dist/ai/adapters/openai-compatible.d.ts +17 -1
- package/dist/ai/adapters/openai-compatible.d.ts.map +1 -1
- package/dist/ai/adapters/openai-compatible.js +105 -1
- package/dist/ai/adapters/openai-compatible.js.map +1 -1
- package/dist/ai/compat.d.ts +30 -0
- package/dist/ai/compat.d.ts.map +1 -0
- package/dist/ai/compat.js +93 -0
- package/dist/ai/compat.js.map +1 -0
- package/dist/ai/cost.d.ts +9 -0
- package/dist/ai/cost.d.ts.map +1 -1
- package/dist/ai/cost.js +15 -2
- package/dist/ai/cost.js.map +1 -1
- package/dist/ai/index.d.ts +6 -2
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -1
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/known-models.d.ts +20 -6
- package/dist/ai/known-models.d.ts.map +1 -1
- package/dist/ai/known-models.generated.d.ts +3 -0
- package/dist/ai/known-models.generated.d.ts.map +1 -0
- package/dist/ai/known-models.generated.js +518 -0
- package/dist/ai/known-models.generated.js.map +1 -0
- package/dist/ai/known-models.js +29 -128
- package/dist/ai/known-models.js.map +1 -1
- package/dist/ai/provider-table.d.ts +36 -0
- package/dist/ai/provider-table.d.ts.map +1 -0
- package/dist/ai/provider-table.js +80 -0
- package/dist/ai/provider-table.js.map +1 -0
- package/dist/ai/retry.d.ts +74 -3
- package/dist/ai/retry.d.ts.map +1 -1
- package/dist/ai/retry.js +246 -6
- package/dist/ai/retry.js.map +1 -1
- package/dist/ai/router.d.ts +12 -0
- package/dist/ai/router.d.ts.map +1 -1
- package/dist/ai/router.js +19 -0
- package/dist/ai/router.js.map +1 -1
- package/dist/ai/sampling.d.ts +37 -0
- package/dist/ai/sampling.d.ts.map +1 -0
- package/dist/ai/sampling.js +34 -0
- package/dist/ai/sampling.js.map +1 -0
- package/dist/ai/setup.d.ts.map +1 -1
- package/dist/ai/setup.js +27 -3
- package/dist/ai/setup.js.map +1 -1
- package/dist/ai/summarizer.d.ts.map +1 -1
- package/dist/ai/summarizer.js +6 -1
- package/dist/ai/summarizer.js.map +1 -1
- package/dist/ai/think-filter.d.ts +30 -0
- package/dist/ai/think-filter.d.ts.map +1 -0
- package/dist/ai/think-filter.js +193 -0
- package/dist/ai/think-filter.js.map +1 -0
- package/dist/ai/thinking.d.ts +77 -0
- package/dist/ai/thinking.d.ts.map +1 -0
- package/dist/ai/thinking.js +174 -0
- package/dist/ai/thinking.js.map +1 -0
- package/dist/ai/types.d.ts +134 -7
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/core/compaction/compactor.d.ts.map +1 -1
- package/dist/core/compaction/compactor.js +44 -6
- package/dist/core/compaction/compactor.js.map +1 -1
- package/dist/core/engine.d.ts +16 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +122 -18
- package/dist/core/engine.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -15,5 +15,17 @@ import type { ChatRequest, ProviderEvent } from "../types.js";
|
|
|
15
15
|
* streaming-error redaction path without depending on the real `ai`
|
|
16
16
|
* package's internals. Production callers omit it and pay one `import("ai")`.
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
/** (7.10 §3.5) Adapter-computed extras threaded into `streamText`. */
|
|
19
|
+
export interface AiSdkStreamOptions {
|
|
20
|
+
/** Provider-specific options (reasoning/thinking) spread into `streamText`. */
|
|
21
|
+
providerOptions?: Record<string, unknown>;
|
|
22
|
+
/** When set (anthropic), the cache_control marker placed on the LAST user
|
|
23
|
+
* message's last content part — caches the whole prefix (system + tools +
|
|
24
|
+
* history) before it. `ttl` rides through to the provider. */
|
|
25
|
+
cacheControl?: {
|
|
26
|
+
type: "ephemeral";
|
|
27
|
+
ttl?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare function streamFromAiSdk(model: unknown, req: ChatRequest, signal: AbortSignal, loadAi?: () => Promise<unknown>, opts?: AiSdkStreamOptions): AsyncIterable<ProviderEvent>;
|
|
19
31
|
//# sourceMappingURL=ai-sdk-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-stream.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAwB,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-sdk-stream.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAwB,aAAa,EAAE,MAAM,aAAa,CAAC;AA4DpF;;;;;;;;;;;;;;;GAeG;AACH,sEAAsE;AACtE,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C;;mEAE+D;IAC/D,YAAY,CAAC,EAAE;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,wBAAuB,eAAe,CACpC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,WAAW,EACnB,MAAM,GAAE,MAAM,OAAO,CAAC,OAAO,CAAsB,EACnD,IAAI,GAAE,kBAAuB,GAC5B,aAAa,CAAC,aAAa,CAAC,CAwK9B"}
|
|
@@ -14,23 +14,7 @@ function toJsonArgs(x) {
|
|
|
14
14
|
return {};
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
* Streams a chat request through any Vercel AI SDK language model. Both
|
|
19
|
-
* {@link AiSdkAdapter} (native @ai-sdk/* providers) and
|
|
20
|
-
* {@link OpenAICompatibleAdapter} (createOpenAICompatible-backed providers)
|
|
21
|
-
* call into this so the normalization → ProviderEvent mapping lives in one
|
|
22
|
-
* place.
|
|
23
|
-
*
|
|
24
|
-
* `model` is typed as `unknown` because the AI SDK module is dynamic-imported
|
|
25
|
-
* and we don't pin its type surface here; callers pass through whatever
|
|
26
|
-
* `streamText({ model })` accepts at their installed version.
|
|
27
|
-
*
|
|
28
|
-
* `loadAi` is a test-only seam — the adapters thread their own
|
|
29
|
-
* `__loadSdkModuleForTest` through it so an end-to-end test can drive the
|
|
30
|
-
* streaming-error redaction path without depending on the real `ai`
|
|
31
|
-
* package's internals. Production callers omit it and pay one `import("ai")`.
|
|
32
|
-
*/
|
|
33
|
-
export async function* streamFromAiSdk(model, req, signal, loadAi = () => import("ai")) {
|
|
17
|
+
export async function* streamFromAiSdk(model, req, signal, loadAi = () => import("ai"), opts = {}) {
|
|
34
18
|
const ai = (await loadAi().catch(() => null));
|
|
35
19
|
const streamText = ai?.streamText;
|
|
36
20
|
const jsonSchema = ai?.jsonSchema;
|
|
@@ -47,31 +31,109 @@ export async function* streamFromAiSdk(model, req, signal, loadAi = () => import
|
|
|
47
31
|
t.name,
|
|
48
32
|
{ description: t.description, parameters: jsonSchema(t.parameters) },
|
|
49
33
|
]));
|
|
34
|
+
// (7.10 §3.5) Cache the conversation prefix by marking the LAST user message's
|
|
35
|
+
// last content part (anthropic caches everything before the marker). The W6
|
|
36
|
+
// native client does the full 3-anchor placement; this single anchor captures
|
|
37
|
+
// the bulk of the savings on the AI-SDK path.
|
|
38
|
+
let lastUserIdx = -1;
|
|
39
|
+
for (let i = req.messages.length - 1; i >= 0; i--) {
|
|
40
|
+
if (req.messages[i].role === "user") {
|
|
41
|
+
lastUserIdx = i;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const messages = req.messages.map((m, i) => toCoreMessage(m, i === lastUserIdx ? opts.cacheControl : undefined));
|
|
46
|
+
// (7.10 §3.5) Sampling. Skip temperature/topP when reasoning is on — reasoning
|
|
47
|
+
// models (anthropic extended thinking, openai o-series) reject them; maxTokens
|
|
48
|
+
// is always honored.
|
|
49
|
+
const s = req.sampling;
|
|
50
|
+
const reasoningOn = req.reasoning !== undefined;
|
|
51
|
+
const sampling = {};
|
|
52
|
+
if (s?.maxTokens !== undefined)
|
|
53
|
+
sampling.maxTokens = s.maxTokens;
|
|
54
|
+
if (!reasoningOn && s?.temperature !== undefined)
|
|
55
|
+
sampling.temperature = s.temperature;
|
|
56
|
+
if (!reasoningOn && s?.topP !== undefined)
|
|
57
|
+
sampling.topP = s.topP;
|
|
58
|
+
// (7.10 TS re-review) Honor `sampling.timeoutMs` as a whole-request deadline:
|
|
59
|
+
// combine the caller's abort signal with a timeout signal. When the deadline
|
|
60
|
+
// (not the caller) fires we relabel the error "timed out" so the retry
|
|
61
|
+
// classifier treats it as a retryable network error rather than a mystery.
|
|
62
|
+
const timeoutMs = req.sampling?.timeoutMs;
|
|
63
|
+
const deadline = timeoutMs !== undefined ? AbortSignal.timeout(timeoutMs) : undefined;
|
|
64
|
+
const abortSignal = deadline ? AbortSignal.any([signal, deadline]) : signal;
|
|
65
|
+
const errorMessage = (err) => deadline?.aborted && !signal.aborted
|
|
66
|
+
? `provider stream timed out after ${timeoutMs}ms`
|
|
67
|
+
: err instanceof Error
|
|
68
|
+
? err.message
|
|
69
|
+
: String(err);
|
|
50
70
|
let result;
|
|
51
71
|
try {
|
|
52
72
|
result = streamText({
|
|
53
73
|
model,
|
|
54
74
|
system: req.system,
|
|
55
|
-
messages
|
|
75
|
+
messages,
|
|
56
76
|
tools,
|
|
57
|
-
abortSignal
|
|
77
|
+
abortSignal,
|
|
78
|
+
...sampling,
|
|
79
|
+
...(opts.providerOptions ? { providerOptions: opts.providerOptions } : {}),
|
|
58
80
|
});
|
|
59
81
|
}
|
|
60
82
|
catch (err) {
|
|
61
|
-
yield { type: "error", message:
|
|
83
|
+
yield { type: "error", message: errorMessage(err) };
|
|
62
84
|
return;
|
|
63
85
|
}
|
|
64
86
|
// (7.7 §7) The provider's finish reason, captured from the `finish` part and
|
|
65
87
|
// surfaced on the terminal `done` event so the engine can detect a length-stop
|
|
66
88
|
// overflow (Xiaomi MiMo: `finishReason: "length"` with zero output tokens).
|
|
67
89
|
let finishReason;
|
|
90
|
+
// (7.10) Thinking-block lifecycle. AI SDK v4 streams reasoning as
|
|
91
|
+
// `reasoning`/`reasoning-signature`/`redacted-reasoning` parts BEFORE the
|
|
92
|
+
// answer text; we open a block on the first one and close it (carrying the
|
|
93
|
+
// captured signature) when the first non-reasoning part arrives.
|
|
94
|
+
let inThinking = false;
|
|
95
|
+
let thinkingSig;
|
|
96
|
+
let thinkingRedacted = false;
|
|
97
|
+
function* endThinking() {
|
|
98
|
+
if (inThinking) {
|
|
99
|
+
yield { type: "thinking-end", signature: thinkingSig, redacted: thinkingRedacted || undefined };
|
|
100
|
+
inThinking = false;
|
|
101
|
+
thinkingSig = undefined;
|
|
102
|
+
thinkingRedacted = false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
68
105
|
try {
|
|
69
106
|
for await (const part of result.fullStream) {
|
|
70
107
|
switch (part.type) {
|
|
108
|
+
case "reasoning": {
|
|
109
|
+
if (!inThinking) {
|
|
110
|
+
inThinking = true;
|
|
111
|
+
yield { type: "thinking-start" };
|
|
112
|
+
}
|
|
113
|
+
yield { type: "thinking-delta", text: part.textDelta ?? part.text ?? "" };
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case "reasoning-signature":
|
|
117
|
+
// Captured now; emitted on thinking-end so the block carries it.
|
|
118
|
+
if (part.signature)
|
|
119
|
+
thinkingSig = part.signature;
|
|
120
|
+
break;
|
|
121
|
+
case "redacted-reasoning":
|
|
122
|
+
if (!inThinking) {
|
|
123
|
+
inThinking = true;
|
|
124
|
+
yield { type: "thinking-start" };
|
|
125
|
+
}
|
|
126
|
+
// The opaque payload travels as the signature; mark the block redacted.
|
|
127
|
+
thinkingRedacted = true;
|
|
128
|
+
if (part.data)
|
|
129
|
+
thinkingSig = part.data;
|
|
130
|
+
break;
|
|
71
131
|
case "text-delta":
|
|
132
|
+
yield* endThinking();
|
|
72
133
|
yield { type: "text-delta", text: part.text ?? part.textDelta ?? "" };
|
|
73
134
|
break;
|
|
74
135
|
case "tool-call":
|
|
136
|
+
yield* endThinking();
|
|
75
137
|
yield {
|
|
76
138
|
type: "tool-call",
|
|
77
139
|
call: {
|
|
@@ -82,14 +144,24 @@ export async function* streamFromAiSdk(model, req, signal, loadAi = () => import
|
|
|
82
144
|
};
|
|
83
145
|
break;
|
|
84
146
|
case "finish": {
|
|
147
|
+
yield* endThinking();
|
|
85
148
|
const u = part.usage ?? {};
|
|
86
149
|
finishReason = typeof part.finishReason === "string" ? part.finishReason : undefined;
|
|
150
|
+
// (7.10) Map the SDK's flat counts into the 4-bucket Usage. The SDK
|
|
151
|
+
// reports cache hits in `cachedInputTokens` and folds them INTO
|
|
152
|
+
// `inputTokens`; we split them OUT so the buckets stay mutually
|
|
153
|
+
// exclusive (cacheRead bills at its own cheaper rate). cacheRead is
|
|
154
|
+
// clamped to the reported prompt total so an over-reporting SDK can't
|
|
155
|
+
// inflate totalTokens / the `input + cacheRead` overflow check beyond
|
|
156
|
+
// the real prompt size (codex W2 R2-M1). cacheWrite is 0 here — the
|
|
157
|
+
// AI SDK doesn't separate cache creation (the W6 native client does).
|
|
158
|
+
const rawInput = u.inputTokens ?? u.promptTokens ?? 0;
|
|
159
|
+
const output = u.outputTokens ?? u.completionTokens ?? 0;
|
|
160
|
+
const cacheRead = Math.min(Math.max(0, u.cachedInputTokens ?? 0), rawInput);
|
|
161
|
+
const input = rawInput - cacheRead;
|
|
87
162
|
yield {
|
|
88
163
|
type: "usage",
|
|
89
|
-
usage: {
|
|
90
|
-
inputTokens: u.inputTokens ?? u.promptTokens ?? 0,
|
|
91
|
-
outputTokens: u.outputTokens ?? u.completionTokens ?? 0,
|
|
92
|
-
},
|
|
164
|
+
usage: { input, output, cacheRead, cacheWrite: 0, totalTokens: input + output + cacheRead },
|
|
93
165
|
};
|
|
94
166
|
break;
|
|
95
167
|
}
|
|
@@ -100,12 +172,18 @@ export async function* streamFromAiSdk(model, req, signal, loadAi = () => import
|
|
|
100
172
|
}
|
|
101
173
|
}
|
|
102
174
|
catch (err) {
|
|
103
|
-
yield { type: "error", message:
|
|
175
|
+
yield { type: "error", message: errorMessage(err) };
|
|
104
176
|
return;
|
|
105
177
|
}
|
|
178
|
+
// Safety: close an open thinking block if the provider ended without a `finish`.
|
|
179
|
+
yield* endThinking();
|
|
106
180
|
yield { type: "done", finishReason };
|
|
107
181
|
}
|
|
108
|
-
|
|
182
|
+
/** (7.10) The anthropic cache marker as AI-SDK content-part providerOptions. */
|
|
183
|
+
function cacheMeta(cacheControl) {
|
|
184
|
+
return cacheControl ? { providerOptions: { anthropic: { cacheControl } } } : {};
|
|
185
|
+
}
|
|
186
|
+
function toCoreMessage(m, cacheControl) {
|
|
109
187
|
if (m.role === "tool") {
|
|
110
188
|
return {
|
|
111
189
|
role: "tool",
|
|
@@ -120,9 +198,25 @@ function toCoreMessage(m) {
|
|
|
120
198
|
if (m.role === "assistant") {
|
|
121
199
|
return {
|
|
122
200
|
role: "assistant",
|
|
123
|
-
content: m.content.map((c) =>
|
|
124
|
-
|
|
125
|
-
|
|
201
|
+
content: m.content.map((c) => {
|
|
202
|
+
if (c.type === "tool-call") {
|
|
203
|
+
return { type: "tool-call", toolCallId: c.callId, toolName: c.name, args: c.args };
|
|
204
|
+
}
|
|
205
|
+
// (7.10) Replay a stored thinking block for reasoning continuity. A real
|
|
206
|
+
// signature → reasoning part; redacted → redacted-reasoning; an empty
|
|
207
|
+
// signature can't be replayed as reasoning (the API rejects it), so it
|
|
208
|
+
// degrades to text (the conservative default; the W6 native client
|
|
209
|
+
// honors per-model allowEmptySignature via thinkingBlockToProvider).
|
|
210
|
+
if (c.type === "thinking") {
|
|
211
|
+
if (c.redacted)
|
|
212
|
+
return { type: "redacted-reasoning", data: c.signature ?? "" };
|
|
213
|
+
if (c.signature && c.signature.trim().length > 0) {
|
|
214
|
+
return { type: "reasoning", text: c.text, signature: c.signature };
|
|
215
|
+
}
|
|
216
|
+
return { type: "text", text: c.text };
|
|
217
|
+
}
|
|
218
|
+
return { type: "text", text: c.type === "text" ? c.text : "" };
|
|
219
|
+
}),
|
|
126
220
|
};
|
|
127
221
|
}
|
|
128
222
|
// user (or system). (7.9) When the message carries image parts, emit the AI
|
|
@@ -130,16 +224,23 @@ function toCoreMessage(m) {
|
|
|
130
224
|
// the plain-string form so existing text-only messages are byte-identical.
|
|
131
225
|
const hasImage = m.content.some((c) => c.type === "image");
|
|
132
226
|
if (m.role === "user" && hasImage) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
227
|
+
const parts = m.content
|
|
228
|
+
.filter((c) => c.type === "text" || c.type === "image")
|
|
229
|
+
.map((c) => c.type === "image"
|
|
230
|
+
? // `mediaType` (AI SDK v5) + `mimeType` (older) for cross-version safety.
|
|
231
|
+
{ type: "image", image: c.data, mediaType: c.mimeType, mimeType: c.mimeType }
|
|
232
|
+
: { type: "text", text: c.type === "text" ? c.text : "" });
|
|
233
|
+
// Mark the LAST part for caching (caches the prefix up to here).
|
|
234
|
+
if (cacheControl && parts.length > 0)
|
|
235
|
+
parts[parts.length - 1] = { ...parts[parts.length - 1], ...cacheMeta(cacheControl) };
|
|
236
|
+
return { role: "user", content: parts };
|
|
237
|
+
}
|
|
238
|
+
const text = m.content.map((c) => (c.type === "text" ? c.text : "")).join("");
|
|
239
|
+
// (7.10 §3.5) A cached user turn must use the array content form so the marker
|
|
240
|
+
// can ride a content part (a plain string can't carry providerOptions).
|
|
241
|
+
if (cacheControl && m.role === "user") {
|
|
242
|
+
return { role: "user", content: [{ type: "text", text, ...cacheMeta(cacheControl) }] };
|
|
142
243
|
}
|
|
143
|
-
return { role: m.role, content:
|
|
244
|
+
return { role: m.role, content: text };
|
|
144
245
|
}
|
|
145
246
|
//# sourceMappingURL=ai-sdk-stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-stream.js","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-sdk-stream.js","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,qBAAqB,CAAC;AA+C/D;;;;uEAIuE;AACvE,SAAS,UAAU,CAAC,CAAU;IAC5B,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAc,CAAC;IACpD,CAAC;IAAC,MAAM,CAA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wEAAwE;IACxE,IAAI,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACtC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;IACzF,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -40,6 +40,14 @@ export declare class AiSdkAdapter implements ProviderAdapter {
|
|
|
40
40
|
constructor(opts: AiSdkAdapterOptions);
|
|
41
41
|
listModels(): ModelDescriptor[];
|
|
42
42
|
stream(req: ChatRequest, signal: AbortSignal): AsyncIterable<ProviderEvent>;
|
|
43
|
+
/** (7.10 §3.5) The anthropic cache marker for this request (undefined for
|
|
44
|
+
* non-anthropic providers or `cacheRetention:"none"`). `long` upgrades to a
|
|
45
|
+
* 1h ttl only when the model's compat allows it. */
|
|
46
|
+
private anthropicCache;
|
|
47
|
+
/** (7.10 §3.4) Translate the requested reasoning effort to the provider's
|
|
48
|
+
* native `providerOptions` for the AI SDK. The engine has already clamped the
|
|
49
|
+
* effort to the model's supported range. */
|
|
50
|
+
private reasoningOptions;
|
|
43
51
|
private createModel;
|
|
44
52
|
}
|
|
45
53
|
/** Replaces every occurrence of `apiKey` in `message` with `[REDACTED]`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,eAAe,EACf,aAAa,EACd,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,E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OpenAIReasoningEffort, } from "../thinking.js";
|
|
1
3
|
import { streamFromAiSdk } from "./ai-sdk-stream.js";
|
|
2
4
|
/** Maps native AI-SDK providers to the npm package each one needs. Exported
|
|
3
5
|
* so the diagnostic in {@link AiSdkAdapter.createModel} and tests share one
|
|
@@ -58,7 +60,43 @@ export class AiSdkAdapter {
|
|
|
58
60
|
const loadAi = this.opts.__loadSdkModuleForTest
|
|
59
61
|
? () => this.opts.__loadSdkModuleForTest("ai")
|
|
60
62
|
: undefined;
|
|
61
|
-
|
|
63
|
+
const opts = {
|
|
64
|
+
providerOptions: this.reasoningOptions(req.reasoning),
|
|
65
|
+
cacheControl: this.anthropicCache(req),
|
|
66
|
+
};
|
|
67
|
+
yield* redactStream(streamFromAiSdk(model, req, signal, loadAi, opts), this.opts.apiKey);
|
|
68
|
+
}
|
|
69
|
+
/** (7.10 §3.5) The anthropic cache marker for this request (undefined for
|
|
70
|
+
* non-anthropic providers or `cacheRetention:"none"`). `long` upgrades to a
|
|
71
|
+
* 1h ttl only when the model's compat allows it. */
|
|
72
|
+
anthropicCache(req) {
|
|
73
|
+
if (this.opts.provider !== "anthropic" || req.cacheRetention === "none")
|
|
74
|
+
return undefined;
|
|
75
|
+
const compat = detectCompat("anthropic-messages", {
|
|
76
|
+
provider: "anthropic",
|
|
77
|
+
modelId: req.model,
|
|
78
|
+
});
|
|
79
|
+
const ttl = req.cacheRetention === "long" && compat.supportsLongCacheRetention ? "1h" : undefined;
|
|
80
|
+
return { type: "ephemeral", ...(ttl ? { ttl } : {}) };
|
|
81
|
+
}
|
|
82
|
+
/** (7.10 §3.4) Translate the requested reasoning effort to the provider's
|
|
83
|
+
* native `providerOptions` for the AI SDK. The engine has already clamped the
|
|
84
|
+
* effort to the model's supported range. */
|
|
85
|
+
reasoningOptions(reasoning) {
|
|
86
|
+
if (!reasoning)
|
|
87
|
+
return undefined;
|
|
88
|
+
switch (this.opts.provider) {
|
|
89
|
+
case "anthropic":
|
|
90
|
+
return { anthropic: { thinking: { type: "enabled", budgetTokens: effortToThinkingBudget(reasoning) } } };
|
|
91
|
+
case "openai":
|
|
92
|
+
return { openai: { reasoningEffort: mapEffortToOpenAIReasoningEffort(reasoning) } };
|
|
93
|
+
case "google":
|
|
94
|
+
return {
|
|
95
|
+
google: {
|
|
96
|
+
thinkingConfig: { thinkingBudget: effortToGoogleThinkingBudget(reasoning), includeThoughts: true },
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
62
100
|
}
|
|
63
101
|
async createModel(modelId) {
|
|
64
102
|
const pkg = AI_SDK_PACKAGES[this.opts.provider];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../../../src/ai/adapters/ai-sdk.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,gCAAgC,GACjC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,eAAe,EAA2B,MAAM,oBAAoB,CAAC;AAI9E;;;yBAGyB;AACzB,MAAM,CAAC,MAAM,eAAe,GAAkC;IAC5D,SAAS,EAAE,mBAAmB;IAC9B,MAAM,EAAE,gBAAgB;IACxB,MAAM,EAAE,gBAAgB;CACzB,CAAC;AAaF,wDAAwD;AACxD,MAAM,aAAa,GAAmD;IACpE,SAAS,EAAE,iBAAiB;IAC5B,MAAM,EAAE,cAAc;IACtB,MAAM,EAAE,0BAA0B;CACnC,CAAC;AAmBF;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,YAAY;IAGM;IAFpB,EAAE,CAAS;IAEpB,YAA6B,IAAyB;QAAzB,SAAI,GAAJ,IAAI,CAAqB;QACpD,IAAI,CAAC,EAAE,GAAG,IAAI,CAA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AAC,OAAO,CAAC,CAAC;IACxD,CAAC;CAEF;AAED;;;;;2BAK2B;AAC3B,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE,MAAc;IACpD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IACjD,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAClD,CAAC;AAED;;2EAE2E;AAC3E,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,CACjC,MAAoC,EACpC,MAAc;IAEd,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;QAC9B,IAAI,EAAE,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACxB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;QAC/D,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/mock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EAEX,eAAe,EACf,eAAe,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/mock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EAEX,eAAe,EACf,eAAe,EACf,aAAa,EAEd,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,qBAAa,WAAY,YAAW,eAAe;IACjD,QAAQ,CAAC,EAAE,UAAU;IAErB,UAAU,IAAI,eAAe,EAAE;IAexB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,GAAG,aAAa,CAAC,aAAa,CAAC;CAwBpF"}
|
package/dist/ai/adapters/mock.js
CHANGED
|
@@ -28,7 +28,7 @@ export class MockAdapter {
|
|
|
28
28
|
const readMatch = /^\s*read\s+(\S+)/i.exec(text);
|
|
29
29
|
if (readMatch && !alreadyHasToolResult && req.tools.some((t) => t.name === "read")) {
|
|
30
30
|
yield { type: "tool-call", call: { callId: createId("call"), name: "read", args: { path: readMatch[1] } } };
|
|
31
|
-
yield { type: "usage", usage:
|
|
31
|
+
yield { type: "usage", usage: usageOf(estimate(text), 4) };
|
|
32
32
|
yield { type: "done" };
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -38,10 +38,14 @@ export class MockAdapter {
|
|
|
38
38
|
for (const chunk of reply.match(/.{1,12}/g) ?? [reply]) {
|
|
39
39
|
yield { type: "text-delta", text: chunk };
|
|
40
40
|
}
|
|
41
|
-
yield { type: "usage", usage:
|
|
41
|
+
yield { type: "usage", usage: usageOf(estimate(text), estimate(reply)) };
|
|
42
42
|
yield { type: "done" };
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
/** (7.10) The mock has no prompt cache — emit a zeroed 4-bucket Usage. */
|
|
46
|
+
function usageOf(input, output) {
|
|
47
|
+
return { input, output, cacheRead: 0, cacheWrite: 0, totalTokens: input + output };
|
|
48
|
+
}
|
|
45
49
|
function textOf(content) {
|
|
46
50
|
return content
|
|
47
51
|
.filter((c) => c.type === "text")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../../src/ai/adapters/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../../src/ai/adapters/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAU/C;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACb,EAAE,GAAG,MAAM,CAAC;IAErB,UA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AC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ChatRequest, ModelDescriptor, ProviderAdapter, ProviderEvent } from "../types.js";
|
|
2
|
+
export interface NativeAnthropicAdapterOptions {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
models: ModelDescriptor[];
|
|
5
|
+
/** Optional override base URL (Bedrock/Vertex relays, proxies). */
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* (7.10 W6) `api="anthropic-messages"` adapter. Prefers the hand-rolled native
|
|
10
|
+
* client (chances-natives `anthropic` feature) which gives us cache_control
|
|
11
|
+
* 3-anchor placement, byte-faithful thinking signatures, and structured
|
|
12
|
+
* status/Retry-After the AI-SDK hides; falls back to `@ai-sdk/anthropic` when no
|
|
13
|
+
* native client is loaded (the per-fn JS-fallback invariant — the live path
|
|
14
|
+
* works today regardless of the addon build).
|
|
15
|
+
*
|
|
16
|
+
* Both paths emit the SAME `ProviderEvent` sequence (the native parser is the
|
|
17
|
+
* golden-equivalence target), so the engine is oblivious to which ran.
|
|
18
|
+
*/
|
|
19
|
+
export declare class NativeAnthropicAdapter implements ProviderAdapter {
|
|
20
|
+
private readonly opts;
|
|
21
|
+
readonly id = "anthropic";
|
|
22
|
+
private readonly fallback;
|
|
23
|
+
constructor(opts: NativeAnthropicAdapterOptions);
|
|
24
|
+
listModels(): ModelDescriptor[];
|
|
25
|
+
stream(req: ChatRequest, signal: AbortSignal): AsyncIterable<ProviderEvent>;
|
|
26
|
+
/** Bridge the native callback stream to an async iterable. The Rust worker
|
|
27
|
+
* pushes ProviderEvent JSON on a libuv-thread callback; we queue + hand them
|
|
28
|
+
* out in order, ending on the terminal `done`/`error` or on abort. */
|
|
29
|
+
private streamNative;
|
|
30
|
+
private parseEvent;
|
|
31
|
+
private buildNativeRequest;
|
|
32
|
+
private buildNativeOptions;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* (7.10 W6) The JSON the Rust `build_request_body` consumes. Pure + exported so
|
|
36
|
+
* the request shaping is unit-tested without a native build. effort→budget lives
|
|
37
|
+
* ONCE (here, via `thinking.ts`); the cache compat flags come from the model.
|
|
38
|
+
* Reasoning and sampling are mutually exclusive on anthropic — when a thinking
|
|
39
|
+
* budget is present the Rust builder drops temperature/top_p, so we omit them.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildNativeAnthropicRequest(req: ChatRequest, models: ModelDescriptor[]): Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* (7.10 W6) Map a raw native event object to a {@link ProviderEvent}. Pure +
|
|
44
|
+
* exported for unit tests. The native `error` event carries `status` +
|
|
45
|
+
* `retryAfter` (raw header); we normalize the Retry-After (incl. an HTTP-date)
|
|
46
|
+
* to seconds and fold it into the message so the engine's classifier
|
|
47
|
+
* (`classifyProviderError`) classifies by the HTTP code AND honors the
|
|
48
|
+
* server-directed delay — the precise path the AI-SDK hides.
|
|
49
|
+
*/
|
|
50
|
+
export declare function normalizeNativeError(e: Record<string, unknown>): ProviderEvent;
|
|
51
|
+
//# sourceMappingURL=native-anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-anthropic.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/native-anthropic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,WAAW,EACX,eAAe,EACf,eAAe,EACf,aAAa,EACd,MAAM,aAAa,CAAC;AAMrB,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAIhD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,QAAQ,CAAC,EAAE,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAEX,IAAI,EAAE,6BAA6B;IAQhE,UAAU,IAAI,eAAe,EAAE;IAIxB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC,aAAa,CAAC;IASlF;;2EAEuE;YACxD,YAAY;IA+C3B,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,kBAAkB;CAuB3B;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,eAAe,EAAE,GACxB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0BzB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAW9E"}
|