@ai-sdk/anthropic 3.0.97 → 3.0.99
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 +57 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -14
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +10 -1
- package/dist/internal/index.d.ts +10 -1
- package/dist/internal/index.js +60 -15
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +58 -14
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/anthropic-messages-api.ts +1 -0
- package/src/anthropic-messages-language-model.ts +59 -5
- package/src/convert-to-anthropic-messages-prompt.ts +5 -2
- package/src/internal/index.ts +1 -0
|
@@ -1034,4 +1034,13 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
|
|
|
1034
1034
|
betas: Set<string>;
|
|
1035
1035
|
}>;
|
|
1036
1036
|
|
|
1037
|
-
|
|
1037
|
+
/**
|
|
1038
|
+
* Removes JSON Schema keywords that Anthropic rejects in
|
|
1039
|
+
* `output_config.format.schema`.
|
|
1040
|
+
*
|
|
1041
|
+
* The full original schema is still used by AI SDK result validation. This
|
|
1042
|
+
* only relaxes the schema sent to Anthropic's constrained decoder.
|
|
1043
|
+
*/
|
|
1044
|
+
declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
|
|
1045
|
+
|
|
1046
|
+
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, prepareTools, sanitizeJsonSchema };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1034,4 +1034,13 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
|
|
|
1034
1034
|
betas: Set<string>;
|
|
1035
1035
|
}>;
|
|
1036
1036
|
|
|
1037
|
-
|
|
1037
|
+
/**
|
|
1038
|
+
* Removes JSON Schema keywords that Anthropic rejects in
|
|
1039
|
+
* `output_config.format.schema`.
|
|
1040
|
+
*
|
|
1041
|
+
* The full original schema is still used by AI SDK result validation. This
|
|
1042
|
+
* only relaxes the schema sent to Anthropic's constrained decoder.
|
|
1043
|
+
*/
|
|
1044
|
+
declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
|
|
1045
|
+
|
|
1046
|
+
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, prepareTools, sanitizeJsonSchema };
|
package/dist/internal/index.js
CHANGED
|
@@ -22,7 +22,8 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AnthropicMessagesLanguageModel: () => AnthropicMessagesLanguageModel,
|
|
24
24
|
anthropicTools: () => anthropicTools,
|
|
25
|
-
prepareTools: () => prepareTools
|
|
25
|
+
prepareTools: () => prepareTools,
|
|
26
|
+
sanitizeJsonSchema: () => sanitizeJsonSchema
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(index_exports);
|
|
28
29
|
|
|
@@ -2522,6 +2523,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2522
2523
|
// in pre-filled assistant responses
|
|
2523
2524
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
2524
2525
|
),
|
|
2526
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
2527
|
+
citations: textMetadata.citations
|
|
2528
|
+
},
|
|
2525
2529
|
cache_control: cacheControl
|
|
2526
2530
|
});
|
|
2527
2531
|
}
|
|
@@ -3422,6 +3426,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3422
3426
|
description: "Respond with a JSON object.",
|
|
3423
3427
|
inputSchema: responseFormat.schema
|
|
3424
3428
|
} : void 0;
|
|
3429
|
+
if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
|
|
3430
|
+
warnings.push({
|
|
3431
|
+
type: "unsupported",
|
|
3432
|
+
feature: "providerOptions.anthropic.disableParallelToolUse",
|
|
3433
|
+
details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3425
3436
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
3426
3437
|
const cacheControlValidator = new CacheControlValidator();
|
|
3427
3438
|
const toolNameMapping = (0, import_provider_utils15.createToolNameMapping)({
|
|
@@ -3789,7 +3800,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3789
3800
|
});
|
|
3790
3801
|
}
|
|
3791
3802
|
async doGenerate(options) {
|
|
3792
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3803
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3793
3804
|
const {
|
|
3794
3805
|
args,
|
|
3795
3806
|
warnings,
|
|
@@ -3832,7 +3843,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3832
3843
|
switch (part.type) {
|
|
3833
3844
|
case "text": {
|
|
3834
3845
|
if (!usesJsonResponseTool) {
|
|
3835
|
-
|
|
3846
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
3847
|
+
(citation) => citation.type === "web_search_result_location"
|
|
3848
|
+
);
|
|
3849
|
+
content.push({
|
|
3850
|
+
type: "text",
|
|
3851
|
+
text: part.text,
|
|
3852
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
3853
|
+
providerMetadata: {
|
|
3854
|
+
anthropic: {
|
|
3855
|
+
citations: webSearchCitations
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3859
|
+
});
|
|
3836
3860
|
if (part.citations) {
|
|
3837
3861
|
for (const citation of part.citations) {
|
|
3838
3862
|
const source = createCitationSource(
|
|
@@ -3996,7 +4020,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3996
4020
|
case "web_fetch_tool_result": {
|
|
3997
4021
|
if (part.content.type === "web_fetch_result") {
|
|
3998
4022
|
citationDocuments.push({
|
|
3999
|
-
title: (
|
|
4023
|
+
title: (_b = part.content.content.title) != null ? _b : part.content.url,
|
|
4000
4024
|
mediaType: part.content.content.source.media_type
|
|
4001
4025
|
});
|
|
4002
4026
|
content.push({
|
|
@@ -4059,7 +4083,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4059
4083
|
title: result.title,
|
|
4060
4084
|
providerMetadata: {
|
|
4061
4085
|
anthropic: {
|
|
4062
|
-
pageAge: (
|
|
4086
|
+
pageAge: (_c = result.page_age) != null ? _c : null
|
|
4063
4087
|
}
|
|
4064
4088
|
}
|
|
4065
4089
|
});
|
|
@@ -4090,7 +4114,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4090
4114
|
stdout: part.content.stdout,
|
|
4091
4115
|
stderr: part.content.stderr,
|
|
4092
4116
|
return_code: part.content.return_code,
|
|
4093
|
-
content: (
|
|
4117
|
+
content: (_d = part.content.content) != null ? _d : []
|
|
4094
4118
|
}
|
|
4095
4119
|
});
|
|
4096
4120
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -4103,7 +4127,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4103
4127
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
4104
4128
|
stderr: part.content.stderr,
|
|
4105
4129
|
return_code: part.content.return_code,
|
|
4106
|
-
content: (
|
|
4130
|
+
content: (_e = part.content.content) != null ? _e : []
|
|
4107
4131
|
}
|
|
4108
4132
|
});
|
|
4109
4133
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -4225,13 +4249,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4225
4249
|
finishReason: response.stop_reason,
|
|
4226
4250
|
isJsonResponseFromTool
|
|
4227
4251
|
}),
|
|
4228
|
-
raw: (
|
|
4252
|
+
raw: (_f = response.stop_reason) != null ? _f : void 0
|
|
4229
4253
|
},
|
|
4230
4254
|
usage: convertAnthropicMessagesUsage({ usage: response.usage }),
|
|
4231
4255
|
request: { body: args },
|
|
4232
4256
|
response: {
|
|
4233
|
-
id: (
|
|
4234
|
-
modelId: (
|
|
4257
|
+
id: (_g = response.id) != null ? _g : void 0,
|
|
4258
|
+
modelId: (_h = response.model) != null ? _h : void 0,
|
|
4235
4259
|
headers: responseHeaders,
|
|
4236
4260
|
body: rawResponse
|
|
4237
4261
|
},
|
|
@@ -4368,7 +4392,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4368
4392
|
if (usesJsonResponseTool) {
|
|
4369
4393
|
return;
|
|
4370
4394
|
}
|
|
4371
|
-
contentBlocks[value.index] = {
|
|
4395
|
+
contentBlocks[value.index] = {
|
|
4396
|
+
type: "text",
|
|
4397
|
+
citations: []
|
|
4398
|
+
};
|
|
4372
4399
|
controller.enqueue({
|
|
4373
4400
|
type: "text-start",
|
|
4374
4401
|
id: String(value.index)
|
|
@@ -4397,7 +4424,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4397
4424
|
return;
|
|
4398
4425
|
}
|
|
4399
4426
|
case "compaction": {
|
|
4400
|
-
contentBlocks[value.index] = {
|
|
4427
|
+
contentBlocks[value.index] = {
|
|
4428
|
+
type: "text",
|
|
4429
|
+
citations: []
|
|
4430
|
+
};
|
|
4401
4431
|
controller.enqueue({
|
|
4402
4432
|
type: "text-start",
|
|
4403
4433
|
id: String(value.index),
|
|
@@ -4413,7 +4443,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4413
4443
|
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
4414
4444
|
if (isJsonResponseTool) {
|
|
4415
4445
|
isJsonResponseFromTool = true;
|
|
4416
|
-
contentBlocks[value.index] = {
|
|
4446
|
+
contentBlocks[value.index] = {
|
|
4447
|
+
type: "text",
|
|
4448
|
+
citations: []
|
|
4449
|
+
};
|
|
4417
4450
|
controller.enqueue({
|
|
4418
4451
|
type: "text-start",
|
|
4419
4452
|
id: String(value.index)
|
|
@@ -4786,7 +4819,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4786
4819
|
case "text": {
|
|
4787
4820
|
controller.enqueue({
|
|
4788
4821
|
type: "text-end",
|
|
4789
|
-
id: String(value.index)
|
|
4822
|
+
id: String(value.index),
|
|
4823
|
+
...contentBlock.citations.length > 0 && {
|
|
4824
|
+
providerMetadata: {
|
|
4825
|
+
anthropic: {
|
|
4826
|
+
citations: contentBlock.citations
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4790
4830
|
});
|
|
4791
4831
|
break;
|
|
4792
4832
|
}
|
|
@@ -4925,6 +4965,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4925
4965
|
}
|
|
4926
4966
|
case "citations_delta": {
|
|
4927
4967
|
const citation = value.delta.citation;
|
|
4968
|
+
const contentBlock = contentBlocks[value.index];
|
|
4969
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
4970
|
+
contentBlock.citations.push(citation);
|
|
4971
|
+
}
|
|
4928
4972
|
const source = createCitationSource(
|
|
4929
4973
|
citation,
|
|
4930
4974
|
citationDocuments,
|
|
@@ -5779,6 +5823,7 @@ var anthropicTools = {
|
|
|
5779
5823
|
0 && (module.exports = {
|
|
5780
5824
|
AnthropicMessagesLanguageModel,
|
|
5781
5825
|
anthropicTools,
|
|
5782
|
-
prepareTools
|
|
5826
|
+
prepareTools,
|
|
5827
|
+
sanitizeJsonSchema
|
|
5783
5828
|
});
|
|
5784
5829
|
//# sourceMappingURL=index.js.map
|