@ai-sdk/amazon-bedrock 3.0.120 → 3.0.125
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 +37 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.js +78 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "@ai-sdk/provider-utils";
|
|
9
9
|
|
|
10
10
|
// src/version.ts
|
|
11
|
-
var VERSION = true ? "3.0.
|
|
11
|
+
var VERSION = true ? "3.0.125" : "0.0.0-test";
|
|
12
12
|
|
|
13
13
|
// src/bedrock-provider.ts
|
|
14
14
|
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
@@ -223,7 +223,8 @@ import {
|
|
|
223
223
|
async function prepareTools({
|
|
224
224
|
tools,
|
|
225
225
|
toolChoice,
|
|
226
|
-
modelId
|
|
226
|
+
modelId,
|
|
227
|
+
disableParallelToolUse
|
|
227
228
|
}) {
|
|
228
229
|
var _a;
|
|
229
230
|
const toolWarnings = [];
|
|
@@ -277,7 +278,8 @@ async function prepareTools({
|
|
|
277
278
|
betas: anthropicBetas
|
|
278
279
|
} = await prepareAnthropicTools({
|
|
279
280
|
tools: providerDefinedTools,
|
|
280
|
-
toolChoice
|
|
281
|
+
toolChoice,
|
|
282
|
+
disableParallelToolUse
|
|
281
283
|
});
|
|
282
284
|
toolWarnings.push(...anthropicToolWarnings);
|
|
283
285
|
anthropicBetas.forEach((beta) => betas.add(beta));
|
|
@@ -321,8 +323,17 @@ async function prepareTools({
|
|
|
321
323
|
}
|
|
322
324
|
});
|
|
323
325
|
}
|
|
326
|
+
if (isAnthropicModel && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
327
|
+
additionalTools = {
|
|
328
|
+
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
329
|
+
type: "tool",
|
|
330
|
+
name: toolChoice.toolName,
|
|
331
|
+
disable_parallel_tool_use: true
|
|
332
|
+
} : { type: "auto", disable_parallel_tool_use: true }
|
|
333
|
+
};
|
|
334
|
+
}
|
|
324
335
|
let bedrockToolChoice = void 0;
|
|
325
|
-
if (!usingAnthropicTools && bedrockTools.length > 0 && toolChoice) {
|
|
336
|
+
if (!usingAnthropicTools && (additionalTools == null ? void 0 : additionalTools.tool_choice) == null && bedrockTools.length > 0 && toolChoice) {
|
|
326
337
|
const type = toolChoice.type;
|
|
327
338
|
switch (type) {
|
|
328
339
|
case "auto":
|
|
@@ -539,7 +550,12 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
539
550
|
bedrockContent.push(BEDROCK_CACHE_POINT);
|
|
540
551
|
}
|
|
541
552
|
}
|
|
542
|
-
messages.
|
|
553
|
+
const previousMessage = messages.at(-1);
|
|
554
|
+
if ((previousMessage == null ? void 0 : previousMessage.role) === "user") {
|
|
555
|
+
previousMessage.content.push(...bedrockContent);
|
|
556
|
+
} else {
|
|
557
|
+
messages.push({ role: "user", content: bedrockContent });
|
|
558
|
+
}
|
|
543
559
|
break;
|
|
544
560
|
}
|
|
545
561
|
case "assistant": {
|
|
@@ -629,7 +645,9 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
629
645
|
bedrockContent.push(BEDROCK_CACHE_POINT);
|
|
630
646
|
}
|
|
631
647
|
}
|
|
632
|
-
|
|
648
|
+
if (bedrockContent.length > 0) {
|
|
649
|
+
messages.push({ role: "assistant", content: bedrockContent });
|
|
650
|
+
}
|
|
633
651
|
break;
|
|
634
652
|
}
|
|
635
653
|
default: {
|
|
@@ -738,6 +756,9 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
738
756
|
}
|
|
739
757
|
|
|
740
758
|
// src/bedrock-chat-language-model.ts
|
|
759
|
+
var anthropicProviderOptions = z4.object({
|
|
760
|
+
disableParallelToolUse: z4.boolean().optional()
|
|
761
|
+
});
|
|
741
762
|
var BedrockChatLanguageModel = class {
|
|
742
763
|
constructor(modelId, config) {
|
|
743
764
|
this.modelId = modelId;
|
|
@@ -763,12 +784,17 @@ var BedrockChatLanguageModel = class {
|
|
|
763
784
|
toolChoice,
|
|
764
785
|
providerOptions
|
|
765
786
|
}) {
|
|
766
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
787
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
767
788
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
768
789
|
provider: "bedrock",
|
|
769
790
|
providerOptions,
|
|
770
791
|
schema: bedrockProviderOptions
|
|
771
792
|
})) != null ? _a : {};
|
|
793
|
+
const anthropicOptions = await parseProviderOptions2({
|
|
794
|
+
provider: "anthropic",
|
|
795
|
+
providerOptions,
|
|
796
|
+
schema: anthropicProviderOptions
|
|
797
|
+
});
|
|
772
798
|
const warnings = [];
|
|
773
799
|
if (frequencyPenalty != null) {
|
|
774
800
|
warnings.push({
|
|
@@ -811,7 +837,10 @@ var BedrockChatLanguageModel = class {
|
|
|
811
837
|
});
|
|
812
838
|
}
|
|
813
839
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
814
|
-
const
|
|
840
|
+
const openAIModelId = (_b = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _b[1];
|
|
841
|
+
const isOpenAIModel = openAIModelId != null;
|
|
842
|
+
const isOpenAIGptOssModel = (_c = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _c : false;
|
|
843
|
+
const isThinkingRequested = ((_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type) === "enabled" || ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "adaptive";
|
|
815
844
|
const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && isThinkingRequested && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
816
845
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
817
846
|
type: "function",
|
|
@@ -822,7 +851,8 @@ var BedrockChatLanguageModel = class {
|
|
|
822
851
|
const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools({
|
|
823
852
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
824
853
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
825
|
-
modelId: this.modelId
|
|
854
|
+
modelId: this.modelId,
|
|
855
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
826
856
|
});
|
|
827
857
|
warnings.push(...toolWarnings);
|
|
828
858
|
if (additionalTools) {
|
|
@@ -832,16 +862,16 @@ var BedrockChatLanguageModel = class {
|
|
|
832
862
|
};
|
|
833
863
|
}
|
|
834
864
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
835
|
-
const existingBetas = (
|
|
865
|
+
const existingBetas = (_f = bedrockOptions.anthropicBeta) != null ? _f : [];
|
|
836
866
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
837
867
|
bedrockOptions.additionalModelRequestFields = {
|
|
838
868
|
...bedrockOptions.additionalModelRequestFields,
|
|
839
869
|
anthropic_beta: mergedBetas
|
|
840
870
|
};
|
|
841
871
|
}
|
|
842
|
-
const thinkingType = (
|
|
843
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
844
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
872
|
+
const thinkingType = (_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.type;
|
|
873
|
+
const thinkingBudget = thinkingType === "enabled" ? (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.budgetTokens : void 0;
|
|
874
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.display : void 0;
|
|
845
875
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingRequested;
|
|
846
876
|
const inferenceConfig = {
|
|
847
877
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -874,7 +904,7 @@ var BedrockChatLanguageModel = class {
|
|
|
874
904
|
};
|
|
875
905
|
}
|
|
876
906
|
} else if (!isAnthropicModel) {
|
|
877
|
-
if (((
|
|
907
|
+
if (((_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.budgetTokens) != null) {
|
|
878
908
|
warnings.push({
|
|
879
909
|
type: "unsupported-setting",
|
|
880
910
|
setting: "budgetTokens",
|
|
@@ -889,30 +919,44 @@ var BedrockChatLanguageModel = class {
|
|
|
889
919
|
});
|
|
890
920
|
}
|
|
891
921
|
}
|
|
892
|
-
const maxReasoningEffort = (
|
|
893
|
-
if (maxReasoningEffort != null
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
922
|
+
const maxReasoningEffort = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.maxReasoningEffort;
|
|
923
|
+
if (maxReasoningEffort != null) {
|
|
924
|
+
if (isAnthropicModel) {
|
|
925
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
926
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
927
|
+
output_config: {
|
|
928
|
+
...(_l = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _l.output_config,
|
|
929
|
+
effort: maxReasoningEffort
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
} else if (isOpenAIModel) {
|
|
933
|
+
bedrockOptions.additionalModelRequestFields = isOpenAIGptOssModel ? {
|
|
934
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
935
|
+
reasoning_effort: maxReasoningEffort
|
|
936
|
+
} : {
|
|
937
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
938
|
+
reasoning: {
|
|
939
|
+
...(_m = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _m.reasoning,
|
|
940
|
+
effort: maxReasoningEffort
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
} else {
|
|
944
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
945
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
946
|
+
reasoningConfig: {
|
|
947
|
+
...((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.type) != null && {
|
|
948
|
+
type: bedrockOptions.reasoningConfig.type
|
|
949
|
+
},
|
|
950
|
+
maxReasoningEffort
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
}
|
|
910
954
|
}
|
|
911
955
|
if (useNativeStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
912
956
|
bedrockOptions.additionalModelRequestFields = {
|
|
913
957
|
...bedrockOptions.additionalModelRequestFields,
|
|
914
958
|
output_config: {
|
|
915
|
-
...(
|
|
959
|
+
...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
|
|
916
960
|
format: {
|
|
917
961
|
type: "json_schema",
|
|
918
962
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -944,7 +988,7 @@ var BedrockChatLanguageModel = class {
|
|
|
944
988
|
details: "topK is not supported when thinking is enabled"
|
|
945
989
|
});
|
|
946
990
|
}
|
|
947
|
-
const hasAnyTools = ((
|
|
991
|
+
const hasAnyTools = ((_q = (_p = toolConfig.tools) == null ? void 0 : _p.length) != null ? _q : 0) > 0 || additionalTools;
|
|
948
992
|
let filteredPrompt = prompt;
|
|
949
993
|
if (!hasAnyTools) {
|
|
950
994
|
const hasToolContent = prompt.some(
|