@ai-sdk/anthropic 2.0.0-canary.5 → 2.0.0-canary.7
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 +32 -0
- package/dist/index.js +54 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -30
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +51 -38
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +43 -30
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 2.0.0-canary.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [26735b5]
|
|
8
|
+
- Updated dependencies [443d8ec]
|
|
9
|
+
- Updated dependencies [14c9410]
|
|
10
|
+
- Updated dependencies [d9c98f4]
|
|
11
|
+
- Updated dependencies [c4a2fec]
|
|
12
|
+
- Updated dependencies [0054544]
|
|
13
|
+
- Updated dependencies [9e9c809]
|
|
14
|
+
- Updated dependencies [32831c6]
|
|
15
|
+
- Updated dependencies [d0f9495]
|
|
16
|
+
- Updated dependencies [fd65bc6]
|
|
17
|
+
- Updated dependencies [393138b]
|
|
18
|
+
- Updated dependencies [7182d14]
|
|
19
|
+
- @ai-sdk/provider@2.0.0-canary.6
|
|
20
|
+
- @ai-sdk/provider-utils@3.0.0-canary.7
|
|
21
|
+
|
|
22
|
+
## 2.0.0-canary.6
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- f10304b: feat(tool-calling): don't require the user to have to pass parameters
|
|
27
|
+
- Updated dependencies [411e483]
|
|
28
|
+
- Updated dependencies [79457bd]
|
|
29
|
+
- Updated dependencies [ad80501]
|
|
30
|
+
- Updated dependencies [1766ede]
|
|
31
|
+
- Updated dependencies [f10304b]
|
|
32
|
+
- @ai-sdk/provider@2.0.0-canary.5
|
|
33
|
+
- @ai-sdk/provider-utils@3.0.0-canary.6
|
|
34
|
+
|
|
3
35
|
## 2.0.0-canary.5
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -27,11 +27,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
27
27
|
|
|
28
28
|
// src/anthropic-provider.ts
|
|
29
29
|
var import_provider4 = require("@ai-sdk/provider");
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/anthropic-messages-language-model.ts
|
|
33
33
|
var import_provider3 = require("@ai-sdk/provider");
|
|
34
|
-
var
|
|
34
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
35
35
|
var import_zod2 = require("zod");
|
|
36
36
|
|
|
37
37
|
// src/anthropic-error.ts
|
|
@@ -175,6 +175,7 @@ function prepareTools({
|
|
|
175
175
|
|
|
176
176
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
177
177
|
var import_provider2 = require("@ai-sdk/provider");
|
|
178
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
178
179
|
function convertToAnthropicMessagesPrompt({
|
|
179
180
|
prompt,
|
|
180
181
|
sendReasoning,
|
|
@@ -238,7 +239,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
238
239
|
} : {
|
|
239
240
|
type: "base64",
|
|
240
241
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
241
|
-
data: part.data
|
|
242
|
+
data: (0, import_provider_utils2.convertToBase64)(part.data)
|
|
242
243
|
},
|
|
243
244
|
cache_control: cacheControl
|
|
244
245
|
});
|
|
@@ -252,7 +253,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
252
253
|
} : {
|
|
253
254
|
type: "base64",
|
|
254
255
|
media_type: "application/pdf",
|
|
255
|
-
data: part.data
|
|
256
|
+
data: (0, import_provider_utils2.convertToBase64)(part.data)
|
|
256
257
|
},
|
|
257
258
|
cache_control: cacheControl
|
|
258
259
|
});
|
|
@@ -469,7 +470,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
469
470
|
}
|
|
470
471
|
async getArgs({
|
|
471
472
|
prompt,
|
|
472
|
-
|
|
473
|
+
maxOutputTokens = 4096,
|
|
473
474
|
// 4096: max model output tokens TODO update default in v5
|
|
474
475
|
temperature,
|
|
475
476
|
topP,
|
|
@@ -515,7 +516,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
515
516
|
sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
|
|
516
517
|
warnings
|
|
517
518
|
});
|
|
518
|
-
const anthropicOptions = (0,
|
|
519
|
+
const anthropicOptions = (0, import_provider_utils3.parseProviderOptions)({
|
|
519
520
|
provider: "anthropic",
|
|
520
521
|
providerOptions,
|
|
521
522
|
schema: anthropicProviderOptionsSchema
|
|
@@ -526,7 +527,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
526
527
|
// model id:
|
|
527
528
|
model: this.modelId,
|
|
528
529
|
// standardized settings:
|
|
529
|
-
max_tokens:
|
|
530
|
+
max_tokens: maxOutputTokens,
|
|
530
531
|
temperature,
|
|
531
532
|
top_k: topK,
|
|
532
533
|
top_p: topP,
|
|
@@ -569,7 +570,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
569
570
|
details: "topP is not supported when thinking is enabled"
|
|
570
571
|
});
|
|
571
572
|
}
|
|
572
|
-
baseArgs.max_tokens =
|
|
573
|
+
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
573
574
|
}
|
|
574
575
|
const {
|
|
575
576
|
tools: anthropicTools2,
|
|
@@ -591,8 +592,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
591
592
|
betas,
|
|
592
593
|
headers
|
|
593
594
|
}) {
|
|
594
|
-
return (0,
|
|
595
|
-
await (0,
|
|
595
|
+
return (0, import_provider_utils3.combineHeaders)(
|
|
596
|
+
await (0, import_provider_utils3.resolve)(this.config.headers),
|
|
596
597
|
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
|
|
597
598
|
headers
|
|
598
599
|
);
|
|
@@ -612,12 +613,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
612
613
|
responseHeaders,
|
|
613
614
|
value: response,
|
|
614
615
|
rawValue: rawResponse
|
|
615
|
-
} = await (0,
|
|
616
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
|
616
617
|
url: this.buildRequestUrl(false),
|
|
617
618
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
618
619
|
body: this.transformRequestBody(args),
|
|
619
620
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
620
|
-
successfulResponseHandler: (0,
|
|
621
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
621
622
|
anthropicMessagesResponseSchema
|
|
622
623
|
),
|
|
623
624
|
abortSignal: options.abortSignal,
|
|
@@ -636,6 +637,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
636
637
|
for (const content of response.content) {
|
|
637
638
|
if (content.type === "tool_use") {
|
|
638
639
|
toolCalls.push({
|
|
640
|
+
type: "tool-call",
|
|
639
641
|
toolCallType: "function",
|
|
640
642
|
toolCallId: content.id,
|
|
641
643
|
toolName: content.name,
|
|
@@ -644,26 +646,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
644
646
|
}
|
|
645
647
|
}
|
|
646
648
|
}
|
|
647
|
-
const reasoning =
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
649
|
+
const reasoning = [];
|
|
650
|
+
for (const content of response.content) {
|
|
651
|
+
if (content.type === "redacted_thinking") {
|
|
652
|
+
reasoning.push({
|
|
653
|
+
type: "reasoning",
|
|
654
|
+
reasoningType: "redacted",
|
|
655
|
+
data: content.data
|
|
656
|
+
});
|
|
657
|
+
} else if (content.type === "thinking") {
|
|
658
|
+
reasoning.push({
|
|
659
|
+
type: "reasoning",
|
|
660
|
+
reasoningType: "text",
|
|
661
|
+
text: content.thinking
|
|
662
|
+
});
|
|
663
|
+
reasoning.push({
|
|
664
|
+
type: "reasoning",
|
|
665
|
+
reasoningType: "signature",
|
|
666
|
+
signature: content.signature
|
|
667
|
+
});
|
|
657
668
|
}
|
|
658
|
-
|
|
669
|
+
}
|
|
659
670
|
return {
|
|
660
|
-
text,
|
|
671
|
+
text: text != null ? { type: "text", text } : void 0,
|
|
661
672
|
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
662
673
|
toolCalls,
|
|
663
674
|
finishReason: mapAnthropicStopReason(response.stop_reason),
|
|
664
675
|
usage: {
|
|
665
|
-
|
|
666
|
-
|
|
676
|
+
inputTokens: response.usage.input_tokens,
|
|
677
|
+
outputTokens: response.usage.output_tokens
|
|
667
678
|
},
|
|
668
679
|
request: { body: args },
|
|
669
680
|
response: {
|
|
@@ -684,22 +695,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
684
695
|
async doStream(options) {
|
|
685
696
|
const { args, warnings, betas } = await this.getArgs(options);
|
|
686
697
|
const body = { ...args, stream: true };
|
|
687
|
-
const { responseHeaders, value: response } = await (0,
|
|
698
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
688
699
|
url: this.buildRequestUrl(true),
|
|
689
700
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
690
701
|
body: this.transformRequestBody(body),
|
|
691
702
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
692
|
-
successfulResponseHandler: (0,
|
|
703
|
+
successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
|
|
693
704
|
anthropicMessagesChunkSchema
|
|
694
705
|
),
|
|
695
706
|
abortSignal: options.abortSignal,
|
|
696
707
|
fetch: this.config.fetch
|
|
697
708
|
});
|
|
698
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
699
709
|
let finishReason = "unknown";
|
|
700
710
|
const usage = {
|
|
701
|
-
|
|
702
|
-
|
|
711
|
+
inputTokens: void 0,
|
|
712
|
+
outputTokens: void 0
|
|
703
713
|
};
|
|
704
714
|
const toolCallContentBlocks = {};
|
|
705
715
|
let providerMetadata = void 0;
|
|
@@ -728,7 +738,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
728
738
|
}
|
|
729
739
|
case "redacted_thinking": {
|
|
730
740
|
controller.enqueue({
|
|
731
|
-
type: "
|
|
741
|
+
type: "reasoning",
|
|
742
|
+
reasoningType: "redacted",
|
|
732
743
|
data: value.content_block.data
|
|
733
744
|
});
|
|
734
745
|
return;
|
|
@@ -769,22 +780,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
769
780
|
switch (deltaType) {
|
|
770
781
|
case "text_delta": {
|
|
771
782
|
controller.enqueue({
|
|
772
|
-
type: "text
|
|
773
|
-
|
|
783
|
+
type: "text",
|
|
784
|
+
text: value.delta.text
|
|
774
785
|
});
|
|
775
786
|
return;
|
|
776
787
|
}
|
|
777
788
|
case "thinking_delta": {
|
|
778
789
|
controller.enqueue({
|
|
779
790
|
type: "reasoning",
|
|
780
|
-
|
|
791
|
+
reasoningType: "text",
|
|
792
|
+
text: value.delta.thinking
|
|
781
793
|
});
|
|
782
794
|
return;
|
|
783
795
|
}
|
|
784
796
|
case "signature_delta": {
|
|
785
797
|
if (blockType === "thinking") {
|
|
786
798
|
controller.enqueue({
|
|
787
|
-
type: "reasoning
|
|
799
|
+
type: "reasoning",
|
|
800
|
+
reasoningType: "signature",
|
|
788
801
|
signature: value.delta.signature
|
|
789
802
|
});
|
|
790
803
|
}
|
|
@@ -811,8 +824,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
811
824
|
}
|
|
812
825
|
}
|
|
813
826
|
case "message_start": {
|
|
814
|
-
usage.
|
|
815
|
-
usage.
|
|
827
|
+
usage.inputTokens = value.message.usage.input_tokens;
|
|
828
|
+
usage.outputTokens = value.message.usage.output_tokens;
|
|
816
829
|
providerMetadata = {
|
|
817
830
|
anthropic: {
|
|
818
831
|
cacheCreationInputTokens: (_a = value.message.usage.cache_creation_input_tokens) != null ? _a : null,
|
|
@@ -827,7 +840,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
827
840
|
return;
|
|
828
841
|
}
|
|
829
842
|
case "message_delta": {
|
|
830
|
-
usage.
|
|
843
|
+
usage.outputTokens = value.usage.output_tokens;
|
|
831
844
|
finishReason = mapAnthropicStopReason(value.delta.stop_reason);
|
|
832
845
|
return;
|
|
833
846
|
}
|
|
@@ -1132,10 +1145,10 @@ var anthropicTools = {
|
|
|
1132
1145
|
// src/anthropic-provider.ts
|
|
1133
1146
|
function createAnthropic(options = {}) {
|
|
1134
1147
|
var _a;
|
|
1135
|
-
const baseURL = (_a = (0,
|
|
1148
|
+
const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
|
|
1136
1149
|
const getHeaders = () => ({
|
|
1137
1150
|
"anthropic-version": "2023-06-01",
|
|
1138
|
-
"x-api-key": (0,
|
|
1151
|
+
"x-api-key": (0, import_provider_utils4.loadApiKey)({
|
|
1139
1152
|
apiKey: options.apiKey,
|
|
1140
1153
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
1141
1154
|
description: "Anthropic"
|