@ai-sdk/anthropic 3.0.0-beta.93 → 3.0.0-beta.95
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 +17 -0
- package/dist/index.js +63 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -52
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +3 -3
- package/dist/internal/index.d.ts +3 -3
- package/dist/internal/index.js +62 -51
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +62 -51
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ 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.95" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -51,29 +51,6 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
51
51
|
errorToMessage: (data) => data.error.message
|
|
52
52
|
});
|
|
53
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
|
-
|
|
77
54
|
// src/anthropic-messages-api.ts
|
|
78
55
|
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
79
56
|
import { z as z2 } from "zod/v4";
|
|
@@ -1343,6 +1320,29 @@ async function prepareTools({
|
|
|
1343
1320
|
}
|
|
1344
1321
|
}
|
|
1345
1322
|
|
|
1323
|
+
// src/convert-anthropic-messages-usage.ts
|
|
1324
|
+
function convertAnthropicMessagesUsage(usage) {
|
|
1325
|
+
var _a, _b;
|
|
1326
|
+
const inputTokens = usage.input_tokens;
|
|
1327
|
+
const outputTokens = usage.output_tokens;
|
|
1328
|
+
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
1329
|
+
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
1330
|
+
return {
|
|
1331
|
+
inputTokens: {
|
|
1332
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
1333
|
+
noCache: inputTokens,
|
|
1334
|
+
cacheRead: cacheReadTokens,
|
|
1335
|
+
cacheWrite: cacheCreationTokens
|
|
1336
|
+
},
|
|
1337
|
+
outputTokens: {
|
|
1338
|
+
total: outputTokens,
|
|
1339
|
+
text: void 0,
|
|
1340
|
+
reasoning: void 0
|
|
1341
|
+
},
|
|
1342
|
+
raw: usage
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
1346
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
1347
1347
|
import {
|
|
1348
1348
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -2299,11 +2299,10 @@ function mapAnthropicStopReason({
|
|
|
2299
2299
|
case "tool_use":
|
|
2300
2300
|
return isJsonResponseFromTool ? "stop" : "tool-calls";
|
|
2301
2301
|
case "max_tokens":
|
|
2302
|
-
return "length";
|
|
2303
2302
|
case "model_context_window_exceeded":
|
|
2304
2303
|
return "length";
|
|
2305
2304
|
default:
|
|
2306
|
-
return "
|
|
2305
|
+
return "other";
|
|
2307
2306
|
}
|
|
2308
2307
|
}
|
|
2309
2308
|
|
|
@@ -2719,7 +2718,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2719
2718
|
});
|
|
2720
2719
|
}
|
|
2721
2720
|
async doGenerate(options) {
|
|
2722
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2721
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2723
2722
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2724
2723
|
...options,
|
|
2725
2724
|
stream: false,
|
|
@@ -3028,15 +3027,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3028
3027
|
}
|
|
3029
3028
|
return {
|
|
3030
3029
|
content,
|
|
3031
|
-
finishReason:
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3030
|
+
finishReason: {
|
|
3031
|
+
unified: mapAnthropicStopReason({
|
|
3032
|
+
finishReason: response.stop_reason,
|
|
3033
|
+
isJsonResponseFromTool
|
|
3034
|
+
}),
|
|
3035
|
+
raw: (_c = response.stop_reason) != null ? _c : void 0
|
|
3036
|
+
},
|
|
3035
3037
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
3036
3038
|
request: { body: args },
|
|
3037
3039
|
response: {
|
|
3038
|
-
id: (
|
|
3039
|
-
modelId: (
|
|
3040
|
+
id: (_d = response.id) != null ? _d : void 0,
|
|
3041
|
+
modelId: (_e = response.model) != null ? _e : void 0,
|
|
3040
3042
|
headers: responseHeaders,
|
|
3041
3043
|
body: rawResponse
|
|
3042
3044
|
},
|
|
@@ -3044,20 +3046,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3044
3046
|
providerMetadata: {
|
|
3045
3047
|
anthropic: {
|
|
3046
3048
|
usage: response.usage,
|
|
3047
|
-
cacheCreationInputTokens: (
|
|
3048
|
-
stopSequence: (
|
|
3049
|
+
cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
|
|
3050
|
+
stopSequence: (_g = response.stop_sequence) != null ? _g : null,
|
|
3049
3051
|
container: response.container ? {
|
|
3050
3052
|
expiresAt: response.container.expires_at,
|
|
3051
3053
|
id: response.container.id,
|
|
3052
|
-
skills: (
|
|
3054
|
+
skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
|
|
3053
3055
|
type: skill.type,
|
|
3054
3056
|
skillId: skill.skill_id,
|
|
3055
3057
|
version: skill.version
|
|
3056
|
-
}))) != null ?
|
|
3058
|
+
}))) != null ? _i : null
|
|
3057
3059
|
} : null,
|
|
3058
|
-
contextManagement: (
|
|
3060
|
+
contextManagement: (_j = mapAnthropicResponseContextManagement(
|
|
3059
3061
|
response.context_management
|
|
3060
|
-
)) != null ?
|
|
3062
|
+
)) != null ? _j : null
|
|
3061
3063
|
}
|
|
3062
3064
|
}
|
|
3063
3065
|
};
|
|
@@ -3088,7 +3090,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3088
3090
|
abortSignal: options.abortSignal,
|
|
3089
3091
|
fetch: this.config.fetch
|
|
3090
3092
|
});
|
|
3091
|
-
let finishReason =
|
|
3093
|
+
let finishReason = {
|
|
3094
|
+
unified: "other",
|
|
3095
|
+
raw: void 0
|
|
3096
|
+
};
|
|
3092
3097
|
const usage = {
|
|
3093
3098
|
input_tokens: 0,
|
|
3094
3099
|
output_tokens: 0,
|
|
@@ -3111,7 +3116,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3111
3116
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3112
3117
|
},
|
|
3113
3118
|
transform(chunk, controller) {
|
|
3114
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3119
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3115
3120
|
if (options.includeRawChunks) {
|
|
3116
3121
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3117
3122
|
}
|
|
@@ -3594,10 +3599,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3594
3599
|
};
|
|
3595
3600
|
}
|
|
3596
3601
|
if (value.message.stop_reason != null) {
|
|
3597
|
-
finishReason =
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3602
|
+
finishReason = {
|
|
3603
|
+
unified: mapAnthropicStopReason({
|
|
3604
|
+
finishReason: value.message.stop_reason,
|
|
3605
|
+
isJsonResponseFromTool
|
|
3606
|
+
}),
|
|
3607
|
+
raw: value.message.stop_reason
|
|
3608
|
+
};
|
|
3601
3609
|
}
|
|
3602
3610
|
controller.enqueue({
|
|
3603
3611
|
type: "response-metadata",
|
|
@@ -3648,19 +3656,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3648
3656
|
}
|
|
3649
3657
|
case "message_delta": {
|
|
3650
3658
|
usage.output_tokens = value.usage.output_tokens;
|
|
3651
|
-
finishReason =
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3659
|
+
finishReason = {
|
|
3660
|
+
unified: mapAnthropicStopReason({
|
|
3661
|
+
finishReason: value.delta.stop_reason,
|
|
3662
|
+
isJsonResponseFromTool
|
|
3663
|
+
}),
|
|
3664
|
+
raw: (_i = value.delta.stop_reason) != null ? _i : void 0
|
|
3665
|
+
};
|
|
3666
|
+
stopSequence = (_j = value.delta.stop_sequence) != null ? _j : null;
|
|
3656
3667
|
container = value.delta.container != null ? {
|
|
3657
3668
|
expiresAt: value.delta.container.expires_at,
|
|
3658
3669
|
id: value.delta.container.id,
|
|
3659
|
-
skills: (
|
|
3670
|
+
skills: (_l = (_k = value.delta.container.skills) == null ? void 0 : _k.map((skill) => ({
|
|
3660
3671
|
type: skill.type,
|
|
3661
3672
|
skillId: skill.skill_id,
|
|
3662
3673
|
version: skill.version
|
|
3663
|
-
}))) != null ?
|
|
3674
|
+
}))) != null ? _l : null
|
|
3664
3675
|
} : null;
|
|
3665
3676
|
if (value.delta.context_management) {
|
|
3666
3677
|
contextManagement = mapAnthropicResponseContextManagement(
|