@ai-sdk/anthropic 4.0.15 → 4.0.17
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 +18 -0
- package/dist/index.js +57 -14
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +10 -1
- package/dist/internal/index.js +58 -14
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +2 -2
- package/package.json +2 -2
- package/src/anthropic-api.ts +1 -0
- package/src/anthropic-language-model.ts +59 -5
- package/src/convert-to-anthropic-prompt.ts +5 -2
- package/src/internal/index.ts +1 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -1122,6 +1122,15 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
|
|
|
1122
1122
|
betas: Set<string>;
|
|
1123
1123
|
}>;
|
|
1124
1124
|
|
|
1125
|
+
/**
|
|
1126
|
+
* Removes JSON Schema keywords that Anthropic rejects in
|
|
1127
|
+
* `output_config.format.schema`.
|
|
1128
|
+
*
|
|
1129
|
+
* The full original schema is still used by AI SDK result validation. This
|
|
1130
|
+
* only relaxes the schema sent to Anthropic's constrained decoder.
|
|
1131
|
+
*/
|
|
1132
|
+
declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
|
|
1133
|
+
|
|
1125
1134
|
interface AnthropicSkillsConfig {
|
|
1126
1135
|
provider: string;
|
|
1127
1136
|
baseURL: string;
|
|
@@ -1138,4 +1147,4 @@ declare class AnthropicSkills implements SkillsV4 {
|
|
|
1138
1147
|
uploadSkill(params: Parameters<SkillsV4['uploadSkill']>[0]): Promise<Awaited<ReturnType<SkillsV4['uploadSkill']>>>;
|
|
1139
1148
|
}
|
|
1140
1149
|
|
|
1141
|
-
export { AnthropicFiles, AnthropicLanguageModel, AnthropicLanguageModel as AnthropicMessagesLanguageModel, type AnthropicModelId as AnthropicMessagesModelId, type AnthropicModelId, AnthropicSkills, anthropicTools, getModelCapabilities, prepareTools };
|
|
1150
|
+
export { AnthropicFiles, AnthropicLanguageModel, AnthropicLanguageModel as AnthropicMessagesLanguageModel, type AnthropicModelId as AnthropicMessagesModelId, type AnthropicModelId, AnthropicSkills, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema };
|
package/dist/internal/index.js
CHANGED
|
@@ -2733,6 +2733,9 @@ async function convertToAnthropicPrompt({
|
|
|
2733
2733
|
// in pre-filled assistant responses
|
|
2734
2734
|
isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
|
|
2735
2735
|
),
|
|
2736
|
+
...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
|
|
2737
|
+
citations: textMetadata.citations
|
|
2738
|
+
},
|
|
2736
2739
|
cache_control: cacheControl
|
|
2737
2740
|
});
|
|
2738
2741
|
}
|
|
@@ -3648,6 +3651,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3648
3651
|
description: "Respond with a JSON object.",
|
|
3649
3652
|
inputSchema: responseFormat.schema
|
|
3650
3653
|
} : void 0;
|
|
3654
|
+
if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
|
|
3655
|
+
warnings.push({
|
|
3656
|
+
type: "unsupported",
|
|
3657
|
+
feature: "providerOptions.anthropic.disableParallelToolUse",
|
|
3658
|
+
details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
|
|
3659
|
+
});
|
|
3660
|
+
}
|
|
3651
3661
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
3652
3662
|
const cacheControlValidator = new CacheControlValidator();
|
|
3653
3663
|
const toolNameMapping = createToolNameMapping({
|
|
@@ -4035,7 +4045,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4035
4045
|
});
|
|
4036
4046
|
}
|
|
4037
4047
|
async doGenerate(options) {
|
|
4038
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
4048
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4039
4049
|
const {
|
|
4040
4050
|
args,
|
|
4041
4051
|
warnings,
|
|
@@ -4078,7 +4088,20 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4078
4088
|
switch (part.type) {
|
|
4079
4089
|
case "text": {
|
|
4080
4090
|
if (!usesJsonResponseTool) {
|
|
4081
|
-
|
|
4091
|
+
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
4092
|
+
(citation) => citation.type === "web_search_result_location"
|
|
4093
|
+
);
|
|
4094
|
+
content.push({
|
|
4095
|
+
type: "text",
|
|
4096
|
+
text: part.text,
|
|
4097
|
+
...webSearchCitations != null && webSearchCitations.length > 0 && {
|
|
4098
|
+
providerMetadata: {
|
|
4099
|
+
anthropic: {
|
|
4100
|
+
citations: webSearchCitations
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
});
|
|
4082
4105
|
if (part.citations) {
|
|
4083
4106
|
for (const citation of part.citations) {
|
|
4084
4107
|
const source = createCitationSource(
|
|
@@ -4242,7 +4265,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4242
4265
|
case "web_fetch_tool_result": {
|
|
4243
4266
|
if (part.content.type === "web_fetch_result") {
|
|
4244
4267
|
citationDocuments.push({
|
|
4245
|
-
title: (
|
|
4268
|
+
title: (_b = part.content.content.title) != null ? _b : part.content.url,
|
|
4246
4269
|
mediaType: part.content.content.source.media_type
|
|
4247
4270
|
});
|
|
4248
4271
|
content.push({
|
|
@@ -4305,7 +4328,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4305
4328
|
title: result.title,
|
|
4306
4329
|
providerMetadata: {
|
|
4307
4330
|
anthropic: {
|
|
4308
|
-
pageAge: (
|
|
4331
|
+
pageAge: (_c = result.page_age) != null ? _c : null
|
|
4309
4332
|
}
|
|
4310
4333
|
}
|
|
4311
4334
|
});
|
|
@@ -4336,7 +4359,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4336
4359
|
stdout: part.content.stdout,
|
|
4337
4360
|
stderr: part.content.stderr,
|
|
4338
4361
|
return_code: part.content.return_code,
|
|
4339
|
-
content: (
|
|
4362
|
+
content: (_d = part.content.content) != null ? _d : []
|
|
4340
4363
|
}
|
|
4341
4364
|
});
|
|
4342
4365
|
} else if (part.content.type === "encrypted_code_execution_result") {
|
|
@@ -4349,7 +4372,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4349
4372
|
encrypted_stdout: part.content.encrypted_stdout,
|
|
4350
4373
|
stderr: part.content.stderr,
|
|
4351
4374
|
return_code: part.content.return_code,
|
|
4352
|
-
content: (
|
|
4375
|
+
content: (_e = part.content.content) != null ? _e : []
|
|
4353
4376
|
}
|
|
4354
4377
|
});
|
|
4355
4378
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -4471,13 +4494,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4471
4494
|
finishReason: response.stop_reason,
|
|
4472
4495
|
isJsonResponseFromTool
|
|
4473
4496
|
}),
|
|
4474
|
-
raw: (
|
|
4497
|
+
raw: (_f = response.stop_reason) != null ? _f : void 0
|
|
4475
4498
|
},
|
|
4476
4499
|
usage: convertAnthropicUsage({ usage: response.usage }),
|
|
4477
4500
|
request: { body: args },
|
|
4478
4501
|
response: {
|
|
4479
|
-
id: (
|
|
4480
|
-
modelId: (
|
|
4502
|
+
id: (_g = response.id) != null ? _g : void 0,
|
|
4503
|
+
modelId: (_h = response.model) != null ? _h : void 0,
|
|
4481
4504
|
headers: responseHeaders,
|
|
4482
4505
|
body: rawResponse
|
|
4483
4506
|
},
|
|
@@ -4611,7 +4634,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4611
4634
|
if (usesJsonResponseTool) {
|
|
4612
4635
|
return;
|
|
4613
4636
|
}
|
|
4614
|
-
contentBlocks[value.index] = {
|
|
4637
|
+
contentBlocks[value.index] = {
|
|
4638
|
+
type: "text",
|
|
4639
|
+
citations: []
|
|
4640
|
+
};
|
|
4615
4641
|
controller.enqueue({
|
|
4616
4642
|
type: "text-start",
|
|
4617
4643
|
id: String(value.index)
|
|
@@ -4640,7 +4666,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4640
4666
|
return;
|
|
4641
4667
|
}
|
|
4642
4668
|
case "compaction": {
|
|
4643
|
-
contentBlocks[value.index] = {
|
|
4669
|
+
contentBlocks[value.index] = {
|
|
4670
|
+
type: "text",
|
|
4671
|
+
citations: []
|
|
4672
|
+
};
|
|
4644
4673
|
controller.enqueue({
|
|
4645
4674
|
type: "text-start",
|
|
4646
4675
|
id: String(value.index),
|
|
@@ -4656,7 +4685,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4656
4685
|
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
4657
4686
|
if (isJsonResponseTool) {
|
|
4658
4687
|
isJsonResponseFromTool = true;
|
|
4659
|
-
contentBlocks[value.index] = {
|
|
4688
|
+
contentBlocks[value.index] = {
|
|
4689
|
+
type: "text",
|
|
4690
|
+
citations: []
|
|
4691
|
+
};
|
|
4660
4692
|
controller.enqueue({
|
|
4661
4693
|
type: "text-start",
|
|
4662
4694
|
id: String(value.index)
|
|
@@ -5029,7 +5061,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5029
5061
|
case "text": {
|
|
5030
5062
|
controller.enqueue({
|
|
5031
5063
|
type: "text-end",
|
|
5032
|
-
id: String(value.index)
|
|
5064
|
+
id: String(value.index),
|
|
5065
|
+
...contentBlock.citations.length > 0 && {
|
|
5066
|
+
providerMetadata: {
|
|
5067
|
+
anthropic: {
|
|
5068
|
+
citations: contentBlock.citations
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
}
|
|
5033
5072
|
});
|
|
5034
5073
|
break;
|
|
5035
5074
|
}
|
|
@@ -5168,6 +5207,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5168
5207
|
}
|
|
5169
5208
|
case "citations_delta": {
|
|
5170
5209
|
const citation = value.delta.citation;
|
|
5210
|
+
const contentBlock = contentBlocks[value.index];
|
|
5211
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
|
|
5212
|
+
contentBlock.citations.push(citation);
|
|
5213
|
+
}
|
|
5171
5214
|
const source = createCitationSource(
|
|
5172
5215
|
citation,
|
|
5173
5216
|
citationDocuments,
|
|
@@ -6288,6 +6331,7 @@ export {
|
|
|
6288
6331
|
AnthropicSkills,
|
|
6289
6332
|
anthropicTools,
|
|
6290
6333
|
getModelCapabilities,
|
|
6291
|
-
prepareTools
|
|
6334
|
+
prepareTools,
|
|
6335
|
+
sanitizeJsonSchema
|
|
6292
6336
|
};
|
|
6293
6337
|
//# sourceMappingURL=index.js.map
|