@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/dist/index.mjs
CHANGED
|
@@ -239,7 +239,8 @@ import {
|
|
|
239
239
|
async function prepareTools({
|
|
240
240
|
tools,
|
|
241
241
|
toolChoice,
|
|
242
|
-
modelId
|
|
242
|
+
modelId,
|
|
243
|
+
disableParallelToolUse
|
|
243
244
|
}) {
|
|
244
245
|
var _a;
|
|
245
246
|
const toolWarnings = [];
|
|
@@ -285,6 +286,7 @@ async function prepareTools({
|
|
|
285
286
|
} = await prepareAnthropicTools({
|
|
286
287
|
tools: ProviderTools,
|
|
287
288
|
toolChoice,
|
|
289
|
+
disableParallelToolUse,
|
|
288
290
|
supportsStructuredOutput: false,
|
|
289
291
|
supportsStrictTools: false
|
|
290
292
|
});
|
|
@@ -340,8 +342,17 @@ async function prepareTools({
|
|
|
340
342
|
}
|
|
341
343
|
});
|
|
342
344
|
}
|
|
345
|
+
if (isAnthropicModel && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
346
|
+
additionalTools = {
|
|
347
|
+
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
348
|
+
type: "tool",
|
|
349
|
+
name: toolChoice.toolName,
|
|
350
|
+
disable_parallel_tool_use: true
|
|
351
|
+
} : { type: "auto", disable_parallel_tool_use: true }
|
|
352
|
+
};
|
|
353
|
+
}
|
|
343
354
|
let bedrockToolChoice = void 0;
|
|
344
|
-
if (!usingAnthropicTools && bedrockTools.length > 0 && toolChoice) {
|
|
355
|
+
if (!usingAnthropicTools && (additionalTools == null ? void 0 : additionalTools.tool_choice) == null && bedrockTools.length > 0 && toolChoice) {
|
|
345
356
|
const type = toolChoice.type;
|
|
346
357
|
switch (type) {
|
|
347
358
|
case "auto":
|
|
@@ -692,7 +703,12 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
692
703
|
}
|
|
693
704
|
pushCachePoint(bedrockContent, providerOptions);
|
|
694
705
|
}
|
|
695
|
-
messages.
|
|
706
|
+
const previousMessage = messages.at(-1);
|
|
707
|
+
if ((previousMessage == null ? void 0 : previousMessage.role) === "user") {
|
|
708
|
+
previousMessage.content.push(...bedrockContent);
|
|
709
|
+
} else {
|
|
710
|
+
messages.push({ role: "user", content: bedrockContent });
|
|
711
|
+
}
|
|
696
712
|
break;
|
|
697
713
|
}
|
|
698
714
|
case "assistant": {
|
|
@@ -701,15 +717,56 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
701
717
|
const message = block.messages[j];
|
|
702
718
|
const isLastMessage = j === block.messages.length - 1;
|
|
703
719
|
const { content } = message;
|
|
704
|
-
const
|
|
705
|
-
(part) =>
|
|
720
|
+
const convertedReasoningContent = await Promise.all(
|
|
721
|
+
content.map(async (part) => {
|
|
722
|
+
if (part.type !== "reasoning") {
|
|
723
|
+
return void 0;
|
|
724
|
+
}
|
|
725
|
+
const metadata = await parseProviderOptions({
|
|
726
|
+
provider: "bedrock",
|
|
727
|
+
providerOptions: part.providerOptions,
|
|
728
|
+
schema: bedrockReasoningMetadataSchema
|
|
729
|
+
});
|
|
730
|
+
if ((metadata == null ? void 0 : metadata.signature) != null) {
|
|
731
|
+
return {
|
|
732
|
+
reasoningContent: {
|
|
733
|
+
reasoningText: {
|
|
734
|
+
// do not trim reasoning text when a signature is present:
|
|
735
|
+
// the signature validates the exact original bytes
|
|
736
|
+
text: part.text,
|
|
737
|
+
signature: metadata.signature
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
if ((metadata == null ? void 0 : metadata.redactedContent) != null) {
|
|
743
|
+
return {
|
|
744
|
+
reasoningContent: {
|
|
745
|
+
redactedContent: metadata.redactedContent
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
if ((metadata == null ? void 0 : metadata.redactedData) != null) {
|
|
750
|
+
return {
|
|
751
|
+
reasoningContent: {
|
|
752
|
+
redactedReasoning: {
|
|
753
|
+
data: metadata.redactedData
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
return void 0;
|
|
759
|
+
})
|
|
760
|
+
);
|
|
761
|
+
const hasReplayableReasoningBlocks = convertedReasoningContent.some(
|
|
762
|
+
(part) => part != null
|
|
706
763
|
);
|
|
707
764
|
for (let k = 0; k < content.length; k++) {
|
|
708
765
|
const part = content[k];
|
|
709
766
|
const isLastContentPart = k === content.length - 1;
|
|
710
767
|
switch (part.type) {
|
|
711
768
|
case "text": {
|
|
712
|
-
if (!part.text.trim() && !
|
|
769
|
+
if (!part.text.trim() && !hasReplayableReasoningBlocks) {
|
|
713
770
|
break;
|
|
714
771
|
}
|
|
715
772
|
bedrockContent.push({
|
|
@@ -728,34 +785,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
728
785
|
break;
|
|
729
786
|
}
|
|
730
787
|
case "reasoning": {
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
schema: bedrockReasoningMetadataSchema
|
|
735
|
-
});
|
|
736
|
-
if ((reasoningMetadata == null ? void 0 : reasoningMetadata.signature) != null) {
|
|
737
|
-
bedrockContent.push({
|
|
738
|
-
reasoningContent: {
|
|
739
|
-
reasoningText: {
|
|
740
|
-
text: part.text,
|
|
741
|
-
signature: reasoningMetadata.signature
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedContent) != null) {
|
|
746
|
-
bedrockContent.push({
|
|
747
|
-
reasoningContent: {
|
|
748
|
-
redactedContent: reasoningMetadata.redactedContent
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
} else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
|
|
752
|
-
bedrockContent.push({
|
|
753
|
-
reasoningContent: {
|
|
754
|
-
redactedReasoning: {
|
|
755
|
-
data: reasoningMetadata.redactedData
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
});
|
|
788
|
+
const convertedPart = convertedReasoningContent[k];
|
|
789
|
+
if (convertedPart != null) {
|
|
790
|
+
bedrockContent.push(convertedPart);
|
|
759
791
|
}
|
|
760
792
|
break;
|
|
761
793
|
}
|
|
@@ -774,7 +806,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
|
|
|
774
806
|
}
|
|
775
807
|
pushCachePoint(bedrockContent, message.providerOptions);
|
|
776
808
|
}
|
|
777
|
-
|
|
809
|
+
if (bedrockContent.length > 0) {
|
|
810
|
+
messages.push({ role: "assistant", content: bedrockContent });
|
|
811
|
+
}
|
|
778
812
|
break;
|
|
779
813
|
}
|
|
780
814
|
default: {
|
|
@@ -883,6 +917,9 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
883
917
|
}
|
|
884
918
|
|
|
885
919
|
// src/bedrock-chat-language-model.ts
|
|
920
|
+
var anthropicProviderOptions = z4.object({
|
|
921
|
+
disableParallelToolUse: z4.boolean().optional()
|
|
922
|
+
});
|
|
886
923
|
var BedrockChatLanguageModel = class {
|
|
887
924
|
constructor(modelId, config) {
|
|
888
925
|
this.modelId = modelId;
|
|
@@ -914,6 +951,11 @@ var BedrockChatLanguageModel = class {
|
|
|
914
951
|
providerOptions,
|
|
915
952
|
schema: amazonBedrockLanguageModelOptions
|
|
916
953
|
})) != null ? _a : {};
|
|
954
|
+
const anthropicOptions = await parseProviderOptions2({
|
|
955
|
+
provider: "anthropic",
|
|
956
|
+
providerOptions,
|
|
957
|
+
schema: anthropicProviderOptions
|
|
958
|
+
});
|
|
917
959
|
const warnings = [];
|
|
918
960
|
if (frequencyPenalty != null) {
|
|
919
961
|
warnings.push({
|
|
@@ -972,7 +1014,8 @@ var BedrockChatLanguageModel = class {
|
|
|
972
1014
|
const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools({
|
|
973
1015
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
974
1016
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
975
|
-
modelId: this.modelId
|
|
1017
|
+
modelId: this.modelId,
|
|
1018
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
976
1019
|
});
|
|
977
1020
|
warnings.push(...toolWarnings);
|
|
978
1021
|
if (additionalTools) {
|
|
@@ -2268,7 +2311,7 @@ import {
|
|
|
2268
2311
|
import { AwsV4Signer } from "aws4fetch";
|
|
2269
2312
|
|
|
2270
2313
|
// src/version.ts
|
|
2271
|
-
var VERSION = true ? "4.0.
|
|
2314
|
+
var VERSION = true ? "4.0.165" : "0.0.0-test";
|
|
2272
2315
|
|
|
2273
2316
|
// src/bedrock-sigv4-fetch.ts
|
|
2274
2317
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|