@ai-sdk/anthropic 3.0.0-beta.77 → 3.0.0-beta.79
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/CHANGELOG.md +15 -0
- package/dist/index.js +61 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -37
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +60 -34
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +61 -36
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -11,12 +11,11 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.0-beta.
|
|
14
|
+
var VERSION = true ? "3.0.0-beta.79" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
18
|
-
APICallError
|
|
19
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
18
|
+
APICallError
|
|
20
19
|
} from "@ai-sdk/provider";
|
|
21
20
|
import {
|
|
22
21
|
combineHeaders,
|
|
@@ -52,6 +51,29 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
52
51
|
errorToMessage: (data) => data.error.message
|
|
53
52
|
});
|
|
54
53
|
|
|
54
|
+
// src/convert-anthropic-messages-usage.ts
|
|
55
|
+
function convertAnthropicMessagesUsage(usage) {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const inputTokens = usage.input_tokens;
|
|
58
|
+
const outputTokens = usage.output_tokens;
|
|
59
|
+
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
60
|
+
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
61
|
+
return {
|
|
62
|
+
inputTokens: {
|
|
63
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
64
|
+
noCache: inputTokens,
|
|
65
|
+
cacheRead: cacheReadTokens,
|
|
66
|
+
cacheWrite: cacheCreationTokens
|
|
67
|
+
},
|
|
68
|
+
outputTokens: {
|
|
69
|
+
total: outputTokens,
|
|
70
|
+
text: void 0,
|
|
71
|
+
reasoning: void 0
|
|
72
|
+
},
|
|
73
|
+
raw: usage
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
55
77
|
// src/anthropic-messages-api.ts
|
|
56
78
|
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
57
79
|
import { z as z2 } from "zod/v4";
|
|
@@ -2259,7 +2281,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2259
2281
|
toolNameMapping
|
|
2260
2282
|
});
|
|
2261
2283
|
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
2262
|
-
|
|
2284
|
+
let thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
|
|
2263
2285
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
2264
2286
|
const baseArgs = {
|
|
2265
2287
|
// model id:
|
|
@@ -2351,9 +2373,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2351
2373
|
};
|
|
2352
2374
|
if (isThinking) {
|
|
2353
2375
|
if (thinkingBudget == null) {
|
|
2354
|
-
|
|
2355
|
-
|
|
2376
|
+
warnings.push({
|
|
2377
|
+
type: "compatibility",
|
|
2378
|
+
feature: "extended thinking",
|
|
2379
|
+
details: "thinking budget is required when thinking is enabled. using default budget of 1024 tokens."
|
|
2356
2380
|
});
|
|
2381
|
+
baseArgs.thinking = {
|
|
2382
|
+
type: "enabled",
|
|
2383
|
+
budget_tokens: 1024
|
|
2384
|
+
};
|
|
2385
|
+
thinkingBudget = 1024;
|
|
2357
2386
|
}
|
|
2358
2387
|
if (baseArgs.temperature != null) {
|
|
2359
2388
|
baseArgs.temperature = void 0;
|
|
@@ -2379,7 +2408,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2379
2408
|
details: "topP is not supported when thinking is enabled"
|
|
2380
2409
|
});
|
|
2381
2410
|
}
|
|
2382
|
-
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
2411
|
+
baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
|
|
2383
2412
|
}
|
|
2384
2413
|
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
2385
2414
|
if (maxOutputTokens != null) {
|
|
@@ -2508,7 +2537,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2508
2537
|
});
|
|
2509
2538
|
}
|
|
2510
2539
|
async doGenerate(options) {
|
|
2511
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
2540
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2512
2541
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2513
2542
|
...options,
|
|
2514
2543
|
stream: false,
|
|
@@ -2807,16 +2836,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2807
2836
|
finishReason: response.stop_reason,
|
|
2808
2837
|
isJsonResponseFromTool
|
|
2809
2838
|
}),
|
|
2810
|
-
usage:
|
|
2811
|
-
inputTokens: response.usage.input_tokens,
|
|
2812
|
-
outputTokens: response.usage.output_tokens,
|
|
2813
|
-
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2814
|
-
cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
|
|
2815
|
-
},
|
|
2839
|
+
usage: convertAnthropicMessagesUsage(response.usage),
|
|
2816
2840
|
request: { body: args },
|
|
2817
2841
|
response: {
|
|
2818
|
-
id: (
|
|
2819
|
-
modelId: (
|
|
2842
|
+
id: (_b = response.id) != null ? _b : void 0,
|
|
2843
|
+
modelId: (_c = response.model) != null ? _c : void 0,
|
|
2820
2844
|
headers: responseHeaders,
|
|
2821
2845
|
body: rawResponse
|
|
2822
2846
|
},
|
|
@@ -2824,20 +2848,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2824
2848
|
providerMetadata: {
|
|
2825
2849
|
anthropic: {
|
|
2826
2850
|
usage: response.usage,
|
|
2827
|
-
cacheCreationInputTokens: (
|
|
2828
|
-
stopSequence: (
|
|
2851
|
+
cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null,
|
|
2852
|
+
stopSequence: (_e = response.stop_sequence) != null ? _e : null,
|
|
2829
2853
|
container: response.container ? {
|
|
2830
2854
|
expiresAt: response.container.expires_at,
|
|
2831
2855
|
id: response.container.id,
|
|
2832
|
-
skills: (
|
|
2856
|
+
skills: (_g = (_f = response.container.skills) == null ? void 0 : _f.map((skill) => ({
|
|
2833
2857
|
type: skill.type,
|
|
2834
2858
|
skillId: skill.skill_id,
|
|
2835
2859
|
version: skill.version
|
|
2836
|
-
}))) != null ?
|
|
2860
|
+
}))) != null ? _g : null
|
|
2837
2861
|
} : null,
|
|
2838
|
-
contextManagement: (
|
|
2862
|
+
contextManagement: (_h = mapAnthropicResponseContextManagement(
|
|
2839
2863
|
response.context_management
|
|
2840
|
-
)) != null ?
|
|
2864
|
+
)) != null ? _h : null
|
|
2841
2865
|
}
|
|
2842
2866
|
}
|
|
2843
2867
|
};
|
|
@@ -2870,9 +2894,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2870
2894
|
});
|
|
2871
2895
|
let finishReason = "unknown";
|
|
2872
2896
|
const usage = {
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2897
|
+
input_tokens: 0,
|
|
2898
|
+
output_tokens: 0,
|
|
2899
|
+
cache_creation_input_tokens: 0,
|
|
2900
|
+
cache_read_input_tokens: 0
|
|
2876
2901
|
};
|
|
2877
2902
|
const contentBlocks = {};
|
|
2878
2903
|
const mcpToolCalls = {};
|
|
@@ -2890,7 +2915,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2890
2915
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2891
2916
|
},
|
|
2892
2917
|
transform(chunk, controller) {
|
|
2893
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i
|
|
2918
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
2894
2919
|
if (options.includeRawChunks) {
|
|
2895
2920
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2896
2921
|
}
|
|
@@ -3329,35 +3354,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3329
3354
|
}
|
|
3330
3355
|
}
|
|
3331
3356
|
case "message_start": {
|
|
3332
|
-
usage.
|
|
3333
|
-
usage.
|
|
3357
|
+
usage.input_tokens = value.message.usage.input_tokens;
|
|
3358
|
+
usage.cache_read_input_tokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : 0;
|
|
3359
|
+
usage.cache_creation_input_tokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : 0;
|
|
3334
3360
|
rawUsage = {
|
|
3335
3361
|
...value.message.usage
|
|
3336
3362
|
};
|
|
3337
|
-
cacheCreationInputTokens = (
|
|
3363
|
+
cacheCreationInputTokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
|
|
3338
3364
|
controller.enqueue({
|
|
3339
3365
|
type: "response-metadata",
|
|
3340
|
-
id: (
|
|
3341
|
-
modelId: (
|
|
3366
|
+
id: (_e = value.message.id) != null ? _e : void 0,
|
|
3367
|
+
modelId: (_f = value.message.model) != null ? _f : void 0
|
|
3342
3368
|
});
|
|
3343
3369
|
return;
|
|
3344
3370
|
}
|
|
3345
3371
|
case "message_delta": {
|
|
3346
|
-
usage.
|
|
3347
|
-
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
3372
|
+
usage.output_tokens = value.usage.output_tokens;
|
|
3348
3373
|
finishReason = mapAnthropicStopReason({
|
|
3349
3374
|
finishReason: value.delta.stop_reason,
|
|
3350
3375
|
isJsonResponseFromTool
|
|
3351
3376
|
});
|
|
3352
|
-
stopSequence = (
|
|
3377
|
+
stopSequence = (_g = value.delta.stop_sequence) != null ? _g : null;
|
|
3353
3378
|
container = value.delta.container != null ? {
|
|
3354
3379
|
expiresAt: value.delta.container.expires_at,
|
|
3355
3380
|
id: value.delta.container.id,
|
|
3356
|
-
skills: (
|
|
3381
|
+
skills: (_i = (_h = value.delta.container.skills) == null ? void 0 : _h.map((skill) => ({
|
|
3357
3382
|
type: skill.type,
|
|
3358
3383
|
skillId: skill.skill_id,
|
|
3359
3384
|
version: skill.version
|
|
3360
|
-
}))) != null ?
|
|
3385
|
+
}))) != null ? _i : null
|
|
3361
3386
|
} : null;
|
|
3362
3387
|
if (value.delta.context_management) {
|
|
3363
3388
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -3374,7 +3399,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3374
3399
|
controller.enqueue({
|
|
3375
3400
|
type: "finish",
|
|
3376
3401
|
finishReason,
|
|
3377
|
-
usage,
|
|
3402
|
+
usage: convertAnthropicMessagesUsage(usage),
|
|
3378
3403
|
providerMetadata: {
|
|
3379
3404
|
anthropic: {
|
|
3380
3405
|
usage: rawUsage != null ? rawUsage : null,
|