@ai-sdk/amazon-bedrock 4.0.49 → 4.0.50

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 4.0.50
4
+
5
+ ### Patch Changes
6
+
7
+ - 632ab10: feat(amazon-bedrock): add support for new Anthropic adaptive thinking and reasoning effort including max
8
+
3
9
  ## 4.0.49
4
10
 
5
11
  ### Patch Changes
@@ -9,7 +9,7 @@ interface BedrockCredentials {
9
9
  sessionToken?: string;
10
10
  }
11
11
 
12
- type BedrockAnthropicModelId = 'anthropic.claude-opus-4-6-v1:0' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-6-v1:0' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
12
+ type BedrockAnthropicModelId = 'anthropic.claude-opus-4-6-v1' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-6-v1' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
13
13
 
14
14
  interface BedrockAnthropicProvider extends ProviderV3 {
15
15
  /**
@@ -9,7 +9,7 @@ interface BedrockCredentials {
9
9
  sessionToken?: string;
10
10
  }
11
11
 
12
- type BedrockAnthropicModelId = 'anthropic.claude-opus-4-6-v1:0' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-6-v1:0' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
12
+ type BedrockAnthropicModelId = 'anthropic.claude-opus-4-6-v1' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-6-v1' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
13
13
 
14
14
  interface BedrockAnthropicProvider extends ProviderV3 {
15
15
  /**
@@ -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.49" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.50" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
@@ -24,7 +24,7 @@ import {
24
24
  import { AwsV4Signer } from "aws4fetch";
25
25
 
26
26
  // src/version.ts
27
- var VERSION = true ? "4.0.49" : "0.0.0-test";
27
+ var VERSION = true ? "4.0.50" : "0.0.0-test";
28
28
 
29
29
  // src/bedrock-sigv4-fetch.ts
30
30
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
package/dist/index.d.mts CHANGED
@@ -8,12 +8,13 @@ type BedrockChatModelId = 'amazon.titan-tg1-large' | 'amazon.titan-text-express-
8
8
  declare const bedrockProviderOptions: z.ZodObject<{
9
9
  additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
10
10
  reasoningConfig: z.ZodOptional<z.ZodObject<{
11
- type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
11
+ type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">, z.ZodLiteral<"adaptive">]>>;
12
12
  budgetTokens: z.ZodOptional<z.ZodNumber>;
13
13
  maxReasoningEffort: z.ZodOptional<z.ZodEnum<{
14
14
  low: "low";
15
15
  medium: "medium";
16
16
  high: "high";
17
+ max: "max";
17
18
  }>>;
18
19
  }, z.core.$strip>>;
19
20
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
package/dist/index.d.ts CHANGED
@@ -8,12 +8,13 @@ type BedrockChatModelId = 'amazon.titan-tg1-large' | 'amazon.titan-text-express-
8
8
  declare const bedrockProviderOptions: z.ZodObject<{
9
9
  additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
10
10
  reasoningConfig: z.ZodOptional<z.ZodObject<{
11
- type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>>;
11
+ type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">, z.ZodLiteral<"adaptive">]>>;
12
12
  budgetTokens: z.ZodOptional<z.ZodNumber>;
13
13
  maxReasoningEffort: z.ZodOptional<z.ZodEnum<{
14
14
  low: "low";
15
15
  medium: "medium";
16
16
  high: "high";
17
+ max: "max";
17
18
  }>>;
18
19
  }, z.core.$strip>>;
19
20
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
package/dist/index.js CHANGED
@@ -87,9 +87,13 @@ var bedrockProviderOptions = import_v4.z.object({
87
87
  */
88
88
  additionalModelRequestFields: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
89
89
  reasoningConfig: import_v4.z.object({
90
- type: import_v4.z.union([import_v4.z.literal("enabled"), import_v4.z.literal("disabled")]).optional(),
90
+ type: import_v4.z.union([
91
+ import_v4.z.literal("enabled"),
92
+ import_v4.z.literal("disabled"),
93
+ import_v4.z.literal("adaptive")
94
+ ]).optional(),
91
95
  budgetTokens: import_v4.z.number().optional(),
92
- maxReasoningEffort: import_v4.z.enum(["low", "medium", "high"]).optional()
96
+ maxReasoningEffort: import_v4.z.enum(["low", "medium", "high", "max"]).optional()
93
97
  }).optional(),
94
98
  /**
95
99
  * Anthropic beta features to enable
@@ -771,7 +775,7 @@ var BedrockChatLanguageModel = class {
771
775
  toolChoice,
772
776
  providerOptions
773
777
  }) {
774
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
778
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
775
779
  const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
776
780
  provider: "bedrock",
777
781
  providerOptions,
@@ -845,8 +849,9 @@ var BedrockChatLanguageModel = class {
845
849
  };
846
850
  }
847
851
  const isAnthropicModel = this.modelId.includes("anthropic");
848
- const isThinkingRequested = ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "enabled";
849
- const thinkingBudget = (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.budgetTokens;
852
+ const thinkingType = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type;
853
+ const isThinkingRequested = thinkingType === "enabled" || thinkingType === "adaptive";
854
+ const thinkingBudget = thinkingType === "enabled" ? (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.budgetTokens : void 0;
850
855
  const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingRequested;
851
856
  const inferenceConfig = {
852
857
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
@@ -855,30 +860,56 @@ var BedrockChatLanguageModel = class {
855
860
  ...topK != null && { topK },
856
861
  ...stopSequences != null && { stopSequences }
857
862
  };
858
- if (isAnthropicThinkingEnabled && thinkingBudget != null) {
859
- if (inferenceConfig.maxTokens != null) {
860
- inferenceConfig.maxTokens += thinkingBudget;
861
- } else {
862
- inferenceConfig.maxTokens = thinkingBudget + 4096;
863
- }
864
- bedrockOptions.additionalModelRequestFields = {
865
- ...bedrockOptions.additionalModelRequestFields,
866
- thinking: {
867
- type: (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type,
868
- budget_tokens: thinkingBudget
863
+ if (isAnthropicThinkingEnabled) {
864
+ if (thinkingBudget != null) {
865
+ if (inferenceConfig.maxTokens != null) {
866
+ inferenceConfig.maxTokens += thinkingBudget;
867
+ } else {
868
+ inferenceConfig.maxTokens = thinkingBudget + 4096;
869
869
  }
870
- };
871
- } else if (!isAnthropicModel && thinkingBudget != null) {
872
- warnings.push({
873
- type: "unsupported",
874
- feature: "budgetTokens",
875
- details: "budgetTokens applies only to Anthropic models on Bedrock and will be ignored for this model."
876
- });
870
+ bedrockOptions.additionalModelRequestFields = {
871
+ ...bedrockOptions.additionalModelRequestFields,
872
+ thinking: {
873
+ type: "enabled",
874
+ budget_tokens: thinkingBudget
875
+ }
876
+ };
877
+ } else if (thinkingType === "adaptive") {
878
+ bedrockOptions.additionalModelRequestFields = {
879
+ ...bedrockOptions.additionalModelRequestFields,
880
+ thinking: {
881
+ type: "adaptive"
882
+ }
883
+ };
884
+ }
885
+ } else if (!isAnthropicModel) {
886
+ if (((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.budgetTokens) != null) {
887
+ warnings.push({
888
+ type: "unsupported",
889
+ feature: "budgetTokens",
890
+ details: "budgetTokens applies only to Anthropic models on Bedrock and will be ignored for this model."
891
+ });
892
+ }
893
+ if (thinkingType === "adaptive") {
894
+ warnings.push({
895
+ type: "unsupported",
896
+ feature: "adaptive thinking",
897
+ details: "adaptive thinking type applies only to Anthropic models on Bedrock."
898
+ });
899
+ }
877
900
  }
878
901
  const maxReasoningEffort = (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.maxReasoningEffort;
879
902
  const isOpenAIModel = this.modelId.startsWith("openai.");
880
- if (maxReasoningEffort != null && !isAnthropicModel) {
881
- if (isOpenAIModel) {
903
+ if (maxReasoningEffort != null) {
904
+ if (isAnthropicModel) {
905
+ const existingBetas = (_h = (_g = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _g.anthropic_beta) != null ? _h : [];
906
+ bedrockOptions.additionalModelRequestFields = {
907
+ ...bedrockOptions.additionalModelRequestFields,
908
+ output_config: {
909
+ effort: maxReasoningEffort
910
+ }
911
+ };
912
+ } else if (isOpenAIModel) {
882
913
  bedrockOptions.additionalModelRequestFields = {
883
914
  ...bedrockOptions.additionalModelRequestFields,
884
915
  reasoning_effort: maxReasoningEffort
@@ -887,19 +918,12 @@ var BedrockChatLanguageModel = class {
887
918
  bedrockOptions.additionalModelRequestFields = {
888
919
  ...bedrockOptions.additionalModelRequestFields,
889
920
  reasoningConfig: {
890
- ...((_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.type) != null && {
891
- type: bedrockOptions.reasoningConfig.type
892
- },
921
+ ...thinkingType != null && thinkingType !== "adaptive" && { type: thinkingType },
922
+ ...thinkingBudget != null && { budgetTokens: thinkingBudget },
893
923
  maxReasoningEffort
894
924
  }
895
925
  };
896
926
  }
897
- } else if (maxReasoningEffort != null && isAnthropicModel) {
898
- warnings.push({
899
- type: "unsupported",
900
- feature: "maxReasoningEffort",
901
- details: "maxReasoningEffort applies only to Amazon Nova models on Bedrock and will be ignored for this model."
902
- });
903
927
  }
904
928
  if (isAnthropicThinkingEnabled && inferenceConfig.temperature != null) {
905
929
  delete inferenceConfig.temperature;
@@ -925,7 +949,7 @@ var BedrockChatLanguageModel = class {
925
949
  details: "topK is not supported when thinking is enabled"
926
950
  });
927
951
  }
928
- const hasAnyTools = ((_i = (_h = toolConfig.tools) == null ? void 0 : _h.length) != null ? _i : 0) > 0 || additionalTools;
952
+ const hasAnyTools = ((_j = (_i = toolConfig.tools) == null ? void 0 : _i.length) != null ? _j : 0) > 0 || additionalTools;
929
953
  let filteredPrompt = prompt;
930
954
  if (!hasAnyTools) {
931
955
  const hasToolContent = prompt.some(
@@ -1878,7 +1902,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1878
1902
  var import_aws4fetch = require("aws4fetch");
1879
1903
 
1880
1904
  // src/version.ts
1881
- var VERSION = true ? "4.0.49" : "0.0.0-test";
1905
+ var VERSION = true ? "4.0.50" : "0.0.0-test";
1882
1906
 
1883
1907
  // src/bedrock-sigv4-fetch.ts
1884
1908
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {