@ai-sdk/amazon-bedrock 4.0.49 → 4.0.51
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 +15 -0
- package/dist/anthropic/index.d.mts +1 -1
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +59 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -36
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +2 -2
- package/package.json +4 -4
- package/src/anthropic/bedrock-anthropic-options.ts +2 -2
- package/src/bedrock-chat-language-model.ts +56 -35
- package/src/bedrock-chat-options.ts +8 -2
package/dist/index.mjs
CHANGED
|
@@ -72,9 +72,13 @@ var bedrockProviderOptions = z.object({
|
|
|
72
72
|
*/
|
|
73
73
|
additionalModelRequestFields: z.record(z.string(), z.any()).optional(),
|
|
74
74
|
reasoningConfig: z.object({
|
|
75
|
-
type: z.union([
|
|
75
|
+
type: z.union([
|
|
76
|
+
z.literal("enabled"),
|
|
77
|
+
z.literal("disabled"),
|
|
78
|
+
z.literal("adaptive")
|
|
79
|
+
]).optional(),
|
|
76
80
|
budgetTokens: z.number().optional(),
|
|
77
|
-
maxReasoningEffort: z.enum(["low", "medium", "high"]).optional()
|
|
81
|
+
maxReasoningEffort: z.enum(["low", "medium", "high", "max"]).optional()
|
|
78
82
|
}).optional(),
|
|
79
83
|
/**
|
|
80
84
|
* Anthropic beta features to enable
|
|
@@ -767,7 +771,7 @@ var BedrockChatLanguageModel = class {
|
|
|
767
771
|
toolChoice,
|
|
768
772
|
providerOptions
|
|
769
773
|
}) {
|
|
770
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
774
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
771
775
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
772
776
|
provider: "bedrock",
|
|
773
777
|
providerOptions,
|
|
@@ -841,8 +845,9 @@ var BedrockChatLanguageModel = class {
|
|
|
841
845
|
};
|
|
842
846
|
}
|
|
843
847
|
const isAnthropicModel = this.modelId.includes("anthropic");
|
|
844
|
-
const
|
|
845
|
-
const
|
|
848
|
+
const thinkingType = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type;
|
|
849
|
+
const isThinkingRequested = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
850
|
+
const thinkingBudget = thinkingType === "enabled" ? (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.budgetTokens : void 0;
|
|
846
851
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingRequested;
|
|
847
852
|
const inferenceConfig = {
|
|
848
853
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -851,30 +856,55 @@ var BedrockChatLanguageModel = class {
|
|
|
851
856
|
...topK != null && { topK },
|
|
852
857
|
...stopSequences != null && { stopSequences }
|
|
853
858
|
};
|
|
854
|
-
if (isAnthropicThinkingEnabled
|
|
855
|
-
if (
|
|
856
|
-
inferenceConfig.maxTokens
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
bedrockOptions.additionalModelRequestFields = {
|
|
861
|
-
...bedrockOptions.additionalModelRequestFields,
|
|
862
|
-
thinking: {
|
|
863
|
-
type: (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type,
|
|
864
|
-
budget_tokens: thinkingBudget
|
|
859
|
+
if (isAnthropicThinkingEnabled) {
|
|
860
|
+
if (thinkingBudget != null) {
|
|
861
|
+
if (inferenceConfig.maxTokens != null) {
|
|
862
|
+
inferenceConfig.maxTokens += thinkingBudget;
|
|
863
|
+
} else {
|
|
864
|
+
inferenceConfig.maxTokens = thinkingBudget + 4096;
|
|
865
865
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
866
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
867
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
868
|
+
thinking: {
|
|
869
|
+
type: "enabled",
|
|
870
|
+
budget_tokens: thinkingBudget
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
} else if (thinkingType === "adaptive") {
|
|
874
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
875
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
876
|
+
thinking: {
|
|
877
|
+
type: "adaptive"
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
} else if (!isAnthropicModel) {
|
|
882
|
+
if (((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.budgetTokens) != null) {
|
|
883
|
+
warnings.push({
|
|
884
|
+
type: "unsupported",
|
|
885
|
+
feature: "budgetTokens",
|
|
886
|
+
details: "budgetTokens applies only to Anthropic models on Bedrock and will be ignored for this model."
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
if (thinkingType === "adaptive") {
|
|
890
|
+
warnings.push({
|
|
891
|
+
type: "unsupported",
|
|
892
|
+
feature: "adaptive thinking",
|
|
893
|
+
details: "adaptive thinking type applies only to Anthropic models on Bedrock."
|
|
894
|
+
});
|
|
895
|
+
}
|
|
873
896
|
}
|
|
874
897
|
const maxReasoningEffort = (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.maxReasoningEffort;
|
|
875
898
|
const isOpenAIModel = this.modelId.startsWith("openai.");
|
|
876
|
-
if (maxReasoningEffort != null
|
|
877
|
-
if (
|
|
899
|
+
if (maxReasoningEffort != null) {
|
|
900
|
+
if (isAnthropicModel) {
|
|
901
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
902
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
903
|
+
output_config: {
|
|
904
|
+
effort: maxReasoningEffort
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
} else if (isOpenAIModel) {
|
|
878
908
|
bedrockOptions.additionalModelRequestFields = {
|
|
879
909
|
...bedrockOptions.additionalModelRequestFields,
|
|
880
910
|
reasoning_effort: maxReasoningEffort
|
|
@@ -883,19 +913,12 @@ var BedrockChatLanguageModel = class {
|
|
|
883
913
|
bedrockOptions.additionalModelRequestFields = {
|
|
884
914
|
...bedrockOptions.additionalModelRequestFields,
|
|
885
915
|
reasoningConfig: {
|
|
886
|
-
...
|
|
887
|
-
|
|
888
|
-
},
|
|
916
|
+
...thinkingType != null && thinkingType !== "adaptive" && { type: thinkingType },
|
|
917
|
+
...thinkingBudget != null && { budgetTokens: thinkingBudget },
|
|
889
918
|
maxReasoningEffort
|
|
890
919
|
}
|
|
891
920
|
};
|
|
892
921
|
}
|
|
893
|
-
} else if (maxReasoningEffort != null && isAnthropicModel) {
|
|
894
|
-
warnings.push({
|
|
895
|
-
type: "unsupported",
|
|
896
|
-
feature: "maxReasoningEffort",
|
|
897
|
-
details: "maxReasoningEffort applies only to Amazon Nova models on Bedrock and will be ignored for this model."
|
|
898
|
-
});
|
|
899
922
|
}
|
|
900
923
|
if (isAnthropicThinkingEnabled && inferenceConfig.temperature != null) {
|
|
901
924
|
delete inferenceConfig.temperature;
|
|
@@ -921,7 +944,7 @@ var BedrockChatLanguageModel = class {
|
|
|
921
944
|
details: "topK is not supported when thinking is enabled"
|
|
922
945
|
});
|
|
923
946
|
}
|
|
924
|
-
const hasAnyTools = ((
|
|
947
|
+
const hasAnyTools = ((_h = (_g = toolConfig.tools) == null ? void 0 : _g.length) != null ? _h : 0) > 0 || additionalTools;
|
|
925
948
|
let filteredPrompt = prompt;
|
|
926
949
|
if (!hasAnyTools) {
|
|
927
950
|
const hasToolContent = prompt.some(
|
|
@@ -1895,7 +1918,7 @@ import {
|
|
|
1895
1918
|
import { AwsV4Signer } from "aws4fetch";
|
|
1896
1919
|
|
|
1897
1920
|
// src/version.ts
|
|
1898
|
-
var VERSION = true ? "4.0.
|
|
1921
|
+
var VERSION = true ? "4.0.51" : "0.0.0-test";
|
|
1899
1922
|
|
|
1900
1923
|
// src/bedrock-sigv4-fetch.ts
|
|
1901
1924
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|