@ai-sdk/amazon-bedrock 4.0.163 → 4.0.165
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/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +80 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -37
- package/dist/index.mjs.map +1 -1
- package/dist/mantle/index.js +1 -1
- package/dist/mantle/index.mjs +1 -1
- package/package.json +4 -4
- package/src/bedrock-chat-language-model.ts +11 -0
- package/src/bedrock-prepare-tools.ts +30 -1
- package/src/convert-to-bedrock-chat-messages.ts +65 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 4.0.165
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- da1ce8f: Forward the Anthropic option for disabling parallel tool use through Amazon Bedrock without sending conflicting tool choice fields.
|
|
8
|
+
- Updated dependencies [426c9b3]
|
|
9
|
+
- Updated dependencies [34d045d]
|
|
10
|
+
- @ai-sdk/openai@3.0.104
|
|
11
|
+
|
|
12
|
+
## 4.0.164
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- d69e9a1: Omit assistant messages that become empty after unsupported reasoning content is removed.
|
|
17
|
+
- Updated dependencies [9a521b9]
|
|
18
|
+
- @ai-sdk/openai@3.0.103
|
|
19
|
+
- @ai-sdk/provider-utils@4.0.49
|
|
20
|
+
- @ai-sdk/anthropic@3.0.114
|
|
21
|
+
|
|
3
22
|
## 4.0.163
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/anthropic/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
|
35
35
|
var import_aws4fetch = require("aws4fetch");
|
|
36
36
|
|
|
37
37
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "4.0.
|
|
38
|
+
var VERSION = true ? "4.0.165" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/anthropic/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { AwsV4Signer } from "aws4fetch";
|
|
25
25
|
|
|
26
26
|
// src/version.ts
|
|
27
|
-
var VERSION = true ? "4.0.
|
|
27
|
+
var VERSION = true ? "4.0.165" : "0.0.0-test";
|
|
28
28
|
|
|
29
29
|
// src/bedrock-sigv4-fetch.ts
|
|
30
30
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/index.js
CHANGED
|
@@ -241,7 +241,8 @@ var import_internal = require("@ai-sdk/anthropic/internal");
|
|
|
241
241
|
async function prepareTools({
|
|
242
242
|
tools,
|
|
243
243
|
toolChoice,
|
|
244
|
-
modelId
|
|
244
|
+
modelId,
|
|
245
|
+
disableParallelToolUse
|
|
245
246
|
}) {
|
|
246
247
|
var _a;
|
|
247
248
|
const toolWarnings = [];
|
|
@@ -287,6 +288,7 @@ async function prepareTools({
|
|
|
287
288
|
} = await (0, import_internal.prepareTools)({
|
|
288
289
|
tools: ProviderTools,
|
|
289
290
|
toolChoice,
|
|
291
|
+
disableParallelToolUse,
|
|
290
292
|
supportsStructuredOutput: false,
|
|
291
293
|
supportsStrictTools: false
|
|
292
294
|
});
|
|
@@ -342,8 +344,17 @@ async function prepareTools({
|
|
|
342
344
|
}
|
|
343
345
|
});
|
|
344
346
|
}
|
|
347
|
+
if (isAnthropicModel && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
348
|
+
additionalTools = {
|
|
349
|
+
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
350
|
+
type: "tool",
|
|
351
|
+
name: toolChoice.toolName,
|
|
352
|
+
disable_parallel_tool_use: true
|
|
353
|
+
} : { type: "auto", disable_parallel_tool_use: true }
|
|
354
|
+
};
|
|
355
|
+
}
|
|
345
356
|
let bedrockToolChoice = void 0;
|
|
346
|
-
if (!usingAnthropicTools && bedrockTools.length > 0 && toolChoice) {
|
|
357
|
+
if (!usingAnthropicTools && (additionalTools == null ? void 0 : additionalTools.tool_choice) == null && bedrockTools.length > 0 && toolChoice) {
|
|
347
358
|
const type = toolChoice.type;
|
|
348
359
|
switch (type) {
|
|
349
360
|
case "auto":
|
|
@@ -688,7 +699,12 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
688
699
|
}
|
|
689
700
|
pushCachePoint(bedrockContent, providerOptions);
|
|
690
701
|
}
|
|
691
|
-
messages.
|
|
702
|
+
const previousMessage = messages.at(-1);
|
|
703
|
+
if ((previousMessage == null ? void 0 : previousMessage.role) === "user") {
|
|
704
|
+
previousMessage.content.push(...bedrockContent);
|
|
705
|
+
} else {
|
|
706
|
+
messages.push({ role: "user", content: bedrockContent });
|
|
707
|
+
}
|
|
692
708
|
break;
|
|
693
709
|
}
|
|
694
710
|
case "assistant": {
|
|
@@ -697,15 +713,56 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
697
713
|
const message = block.messages[j];
|
|
698
714
|
const isLastMessage = j === block.messages.length - 1;
|
|
699
715
|
const { content } = message;
|
|
700
|
-
const
|
|
701
|
-
(part) =>
|
|
716
|
+
const convertedReasoningContent = await Promise.all(
|
|
717
|
+
content.map(async (part) => {
|
|
718
|
+
if (part.type !== "reasoning") {
|
|
719
|
+
return void 0;
|
|
720
|
+
}
|
|
721
|
+
const metadata = await (0, import_provider_utils3.parseProviderOptions)({
|
|
722
|
+
provider: "bedrock",
|
|
723
|
+
providerOptions: part.providerOptions,
|
|
724
|
+
schema: bedrockReasoningMetadataSchema
|
|
725
|
+
});
|
|
726
|
+
if ((metadata == null ? void 0 : metadata.signature) != null) {
|
|
727
|
+
return {
|
|
728
|
+
reasoningContent: {
|
|
729
|
+
reasoningText: {
|
|
730
|
+
// do not trim reasoning text when a signature is present:
|
|
731
|
+
// the signature validates the exact original bytes
|
|
732
|
+
text: part.text,
|
|
733
|
+
signature: metadata.signature
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
if ((metadata == null ? void 0 : metadata.redactedContent) != null) {
|
|
739
|
+
return {
|
|
740
|
+
reasoningContent: {
|
|
741
|
+
redactedContent: metadata.redactedContent
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
if ((metadata == null ? void 0 : metadata.redactedData) != null) {
|
|
746
|
+
return {
|
|
747
|
+
reasoningContent: {
|
|
748
|
+
redactedReasoning: {
|
|
749
|
+
data: metadata.redactedData
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
return void 0;
|
|
755
|
+
})
|
|
756
|
+
);
|
|
757
|
+
const hasReplayableReasoningBlocks = convertedReasoningContent.some(
|
|
758
|
+
(part) => part != null
|
|
702
759
|
);
|
|
703
760
|
for (let k = 0; k < content.length; k++) {
|
|
704
761
|
const part = content[k];
|
|
705
762
|
const isLastContentPart = k === content.length - 1;
|
|
706
763
|
switch (part.type) {
|
|
707
764
|
case "text": {
|
|
708
|
-
if (!part.text.trim() && !
|
|
765
|
+
if (!part.text.trim() && !hasReplayableReasoningBlocks) {
|
|
709
766
|
break;
|
|
710
767
|
}
|
|
711
768
|
bedrockContent.push({
|
|
@@ -724,34 +781,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
724
781
|
break;
|
|
725
782
|
}
|
|
726
783
|
case "reasoning": {
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
schema: bedrockReasoningMetadataSchema
|
|
731
|
-
});
|
|
732
|
-
if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
|
|
733
|
-
bedrockContent.push({
|
|
734
|
-
reasoningContent: {
|
|
735
|
-
reasoningText: {
|
|
736
|
-
text: part.text,
|
|
737
|
-
signature: reasoningMetadata.signature
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedContent) != null) {
|
|
742
|
-
bedrockContent.push({
|
|
743
|
-
reasoningContent: {
|
|
744
|
-
redactedContent: reasoningMetadata.redactedContent
|
|
745
|
-
}
|
|
746
|
-
});
|
|
747
|
-
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
748
|
-
bedrockContent.push({
|
|
749
|
-
reasoningContent: {
|
|
750
|
-
redactedReasoning: {
|
|
751
|
-
data: reasoningMetadata.redactedData
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
});
|
|
784
|
+
const convertedPart = convertedReasoningContent[k];
|
|
785
|
+
if (convertedPart != null) {
|
|
786
|
+
bedrockContent.push(convertedPart);
|
|
755
787
|
}
|
|
756
788
|
break;
|
|
757
789
|
}
|
|
@@ -770,7 +802,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
770
802
|
}
|
|
771
803
|
pushCachePoint(bedrockContent, message.providerOptions);
|
|
772
804
|
}
|
|
773
|
-
|
|
805
|
+
if (bedrockContent.length > 0) {
|
|
806
|
+
messages.push({ role: "assistant", content: bedrockContent });
|
|
807
|
+
}
|
|
774
808
|
break;
|
|
775
809
|
}
|
|
776
810
|
default: {
|
|
@@ -879,6 +913,9 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
879
913
|
}
|
|
880
914
|
|
|
881
915
|
// src/bedrock-chat-language-model.ts
|
|
916
|
+
var anthropicProviderOptions = import_v44.z.object({
|
|
917
|
+
disableParallelToolUse: import_v44.z.boolean().optional()
|
|
918
|
+
});
|
|
882
919
|
var BedrockChatLanguageModel = class {
|
|
883
920
|
constructor(modelId, config) {
|
|
884
921
|
this.modelId = modelId;
|
|
@@ -910,6 +947,11 @@ var BedrockChatLanguageModel = class {
|
|
|
910
947
|
providerOptions,
|
|
911
948
|
schema: amazonBedrockLanguageModelOptions
|
|
912
949
|
})) != null ? _a : {};
|
|
950
|
+
const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
951
|
+
provider: "anthropic",
|
|
952
|
+
providerOptions,
|
|
953
|
+
schema: anthropicProviderOptions
|
|
954
|
+
});
|
|
913
955
|
const warnings = [];
|
|
914
956
|
if (frequencyPenalty != null) {
|
|
915
957
|
warnings.push({
|
|
@@ -968,7 +1010,8 @@ var BedrockChatLanguageModel = class {
|
|
|
968
1010
|
const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools({
|
|
969
1011
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
970
1012
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
971
|
-
modelId: this.modelId
|
|
1013
|
+
modelId: this.modelId,
|
|
1014
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
972
1015
|
});
|
|
973
1016
|
warnings.push(...toolWarnings);
|
|
974
1017
|
if (additionalTools) {
|
|
@@ -2243,7 +2286,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
2243
2286
|
var import_aws4fetch = require("aws4fetch");
|
|
2244
2287
|
|
|
2245
2288
|
// src/version.ts
|
|
2246
|
-
var VERSION = true ? "4.0.
|
|
2289
|
+
var VERSION = true ? "4.0.165" : "0.0.0-test";
|
|
2247
2290
|
|
|
2248
2291
|
// src/bedrock-sigv4-fetch.ts
|
|
2249
2292
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|