@ai-sdk/anthropic 4.0.42 → 4.0.44
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 +19 -0
- package/dist/index.js +79 -83
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +61 -10
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +17 -8
- package/package.json +2 -2
- package/src/anthropic-api.ts +4 -0
- package/src/anthropic-language-model.ts +61 -5
- package/src/anthropic-messages-batch.ts +22 -88
- package/src/skills/anthropic-skills.ts +12 -1
package/dist/internal/index.js
CHANGED
|
@@ -107,9 +107,11 @@ import {
|
|
|
107
107
|
combineHeaders as combineHeaders2,
|
|
108
108
|
createEventSourceResponseHandler,
|
|
109
109
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
110
|
+
createProviderStreamError,
|
|
110
111
|
createToolNameMapping,
|
|
111
112
|
generateId,
|
|
112
113
|
isCustomReasoning,
|
|
114
|
+
isProviderStreamError,
|
|
113
115
|
mapReasoningToProviderBudget,
|
|
114
116
|
mapReasoningToProviderEffort,
|
|
115
117
|
parseProviderOptions as parseProviderOptions2,
|
|
@@ -826,7 +828,11 @@ var anthropicChunkSchema = lazySchema3(
|
|
|
826
828
|
type: z3.literal("error"),
|
|
827
829
|
error: z3.object({
|
|
828
830
|
type: z3.string(),
|
|
829
|
-
message: z3.string()
|
|
831
|
+
message: z3.string(),
|
|
832
|
+
code: z3.union([z3.string(), z3.number()]).nullish(),
|
|
833
|
+
statusCode: z3.number().nullish(),
|
|
834
|
+
isRetryable: z3.boolean().nullish(),
|
|
835
|
+
data: z3.unknown().nullish()
|
|
830
836
|
})
|
|
831
837
|
}),
|
|
832
838
|
z3.object({
|
|
@@ -3573,6 +3579,41 @@ function formatConstraintValue(value) {
|
|
|
3573
3579
|
}
|
|
3574
3580
|
|
|
3575
3581
|
// src/anthropic-language-model.ts
|
|
3582
|
+
function createAnthropicStreamError(error) {
|
|
3583
|
+
var _a, _b, _c;
|
|
3584
|
+
const inferredMetadata = getAnthropicStreamErrorMetadata(error.type);
|
|
3585
|
+
return createProviderStreamError({
|
|
3586
|
+
message: error.message,
|
|
3587
|
+
type: error.type,
|
|
3588
|
+
code: (_a = error.code) != null ? _a : void 0,
|
|
3589
|
+
statusCode: (_b = error.statusCode) != null ? _b : inferredMetadata.statusCode,
|
|
3590
|
+
isRetryable: (_c = error.isRetryable) != null ? _c : inferredMetadata.isRetryable,
|
|
3591
|
+
data: "data" in error ? error.data : error
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3594
|
+
function getAnthropicStreamErrorMetadata(type) {
|
|
3595
|
+
switch (type) {
|
|
3596
|
+
case "api_error":
|
|
3597
|
+
return { statusCode: 500, isRetryable: true };
|
|
3598
|
+
case "overloaded_error":
|
|
3599
|
+
return { statusCode: 529, isRetryable: true };
|
|
3600
|
+
case "rate_limit_error":
|
|
3601
|
+
return { statusCode: 429, isRetryable: true };
|
|
3602
|
+
case "request_too_large":
|
|
3603
|
+
return { statusCode: 413, isRetryable: false };
|
|
3604
|
+
case "authentication_error":
|
|
3605
|
+
return { statusCode: 401, isRetryable: false };
|
|
3606
|
+
case "permission_error":
|
|
3607
|
+
return { statusCode: 403, isRetryable: false };
|
|
3608
|
+
case "not_found_error":
|
|
3609
|
+
return { statusCode: 404, isRetryable: false };
|
|
3610
|
+
case "billing_error":
|
|
3611
|
+
case "invalid_request_error":
|
|
3612
|
+
return { statusCode: 400, isRetryable: false };
|
|
3613
|
+
default:
|
|
3614
|
+
return {};
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3576
3617
|
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
3577
3618
|
var _a;
|
|
3578
3619
|
if (citation.type === "web_search_result_location") {
|
|
@@ -4699,7 +4740,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4699
4740
|
}
|
|
4700
4741
|
async doStream(options) {
|
|
4701
4742
|
"use step";
|
|
4702
|
-
var _a, _b;
|
|
4743
|
+
var _a, _b, _c, _d;
|
|
4703
4744
|
const {
|
|
4704
4745
|
args: body,
|
|
4705
4746
|
warnings,
|
|
@@ -4760,7 +4801,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4760
4801
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4761
4802
|
},
|
|
4762
4803
|
transform(chunk, controller) {
|
|
4763
|
-
var _a2, _b2,
|
|
4804
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
4764
4805
|
if (hasInvalidMessageSequence) {
|
|
4765
4806
|
return;
|
|
4766
4807
|
}
|
|
@@ -5053,7 +5094,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5053
5094
|
stdout: part.content.stdout,
|
|
5054
5095
|
stderr: part.content.stderr,
|
|
5055
5096
|
return_code: part.content.return_code,
|
|
5056
|
-
content: (
|
|
5097
|
+
content: (_c2 = part.content.content) != null ? _c2 : []
|
|
5057
5098
|
}
|
|
5058
5099
|
});
|
|
5059
5100
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -5066,7 +5107,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5066
5107
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
5067
5108
|
stderr: part.content.stderr,
|
|
5068
5109
|
return_code: part.content.return_code,
|
|
5069
|
-
content: (
|
|
5110
|
+
content: (_d2 = part.content.content) != null ? _d2 : []
|
|
5070
5111
|
}
|
|
5071
5112
|
});
|
|
5072
5113
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -5560,7 +5601,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5560
5601
|
return;
|
|
5561
5602
|
}
|
|
5562
5603
|
case "error": {
|
|
5563
|
-
controller.enqueue({
|
|
5604
|
+
controller.enqueue({
|
|
5605
|
+
type: "error",
|
|
5606
|
+
error: createAnthropicStreamError(value.error)
|
|
5607
|
+
});
|
|
5564
5608
|
return;
|
|
5565
5609
|
}
|
|
5566
5610
|
default: {
|
|
@@ -5581,14 +5625,17 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5581
5625
|
}
|
|
5582
5626
|
if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
|
|
5583
5627
|
const error = result.value.error;
|
|
5628
|
+
if (!isProviderStreamError(error)) {
|
|
5629
|
+
throw new Error("Expected a normalized Anthropic stream error");
|
|
5630
|
+
}
|
|
5584
5631
|
throw new APICallError({
|
|
5585
5632
|
message: error.message,
|
|
5586
5633
|
url,
|
|
5587
5634
|
requestBodyValues: body,
|
|
5588
|
-
statusCode: error.
|
|
5635
|
+
statusCode: (_c = error.statusCode) != null ? _c : 500,
|
|
5589
5636
|
responseHeaders,
|
|
5590
|
-
responseBody: JSON.stringify(error),
|
|
5591
|
-
isRetryable: error.
|
|
5637
|
+
responseBody: JSON.stringify(error.data),
|
|
5638
|
+
isRetryable: (_d = error.isRetryable) != null ? _d : false
|
|
5592
5639
|
});
|
|
5593
5640
|
}
|
|
5594
5641
|
} finally {
|
|
@@ -6469,6 +6516,10 @@ var anthropicSkillVersionResponseSchema = lazySchema24(
|
|
|
6469
6516
|
);
|
|
6470
6517
|
|
|
6471
6518
|
// src/skills/anthropic-skills.ts
|
|
6519
|
+
function encodePathSegment(value) {
|
|
6520
|
+
const encodedValue = encodeURIComponent(value);
|
|
6521
|
+
return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
|
|
6522
|
+
}
|
|
6472
6523
|
var AnthropicSkills = class {
|
|
6473
6524
|
constructor(config) {
|
|
6474
6525
|
this.config = config;
|
|
@@ -6488,7 +6539,7 @@ var AnthropicSkills = class {
|
|
|
6488
6539
|
headers
|
|
6489
6540
|
}) {
|
|
6490
6541
|
const { value: versionResponse } = await getFromApi({
|
|
6491
|
-
url: `${this.config.baseURL}/skills/${skillId}/versions/${version}`,
|
|
6542
|
+
url: `${this.config.baseURL}/skills/${encodePathSegment(skillId)}/versions/${encodePathSegment(version)}`,
|
|
6492
6543
|
validateUrl: false,
|
|
6493
6544
|
headers,
|
|
6494
6545
|
failedResponseHandler: anthropicFailedResponseHandler,
|