@ai-sdk/amazon-bedrock 3.0.54 → 3.0.56

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/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.54" : "0.0.0-test";
11
+ var VERSION = true ? "3.0.56" : "0.0.0-test";
12
12
 
13
13
  // src/bedrock-provider.ts
14
14
  import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
@@ -82,7 +82,11 @@ var bedrockProviderOptions = z.object({
82
82
  reasoningConfig: z.object({
83
83
  type: z.union([z.literal("enabled"), z.literal("disabled")]).optional(),
84
84
  budgetTokens: z.number().optional()
85
- }).optional()
85
+ }).optional(),
86
+ /**
87
+ * Anthropic beta features to enable
88
+ */
89
+ anthropicBeta: z.array(z.string()).optional()
86
90
  });
87
91
 
88
92
  // src/bedrock-error.ts
@@ -181,6 +185,7 @@ async function prepareTools({
181
185
  toolChoice,
182
186
  modelId
183
187
  }) {
188
+ var _a;
184
189
  const toolWarnings = [];
185
190
  const betas = /* @__PURE__ */ new Set();
186
191
  if (tools == null || tools.length === 0) {
@@ -269,7 +274,7 @@ async function prepareTools({
269
274
  bedrockTools.push({
270
275
  toolSpec: {
271
276
  name: tool.name,
272
- description: tool.description,
277
+ ...((_a = tool.description) == null ? void 0 : _a.trim()) !== "" ? { description: tool.description } : {},
273
278
  inputSchema: {
274
279
  json: tool.inputSchema
275
280
  }
@@ -683,7 +688,7 @@ var BedrockChatLanguageModel = class {
683
688
  toolChoice,
684
689
  providerOptions
685
690
  }) {
686
- var _a, _b, _c, _d, _e, _f;
691
+ var _a, _b, _c, _d, _e, _f, _g;
687
692
  const bedrockOptions = (_a = await parseProviderOptions2({
688
693
  provider: "bedrock",
689
694
  providerOptions,
@@ -708,6 +713,21 @@ var BedrockChatLanguageModel = class {
708
713
  setting: "seed"
709
714
  });
710
715
  }
716
+ if (temperature != null && temperature > 1) {
717
+ warnings.push({
718
+ type: "unsupported-setting",
719
+ setting: "temperature",
720
+ details: `${temperature} exceeds bedrock maximum of 1.0. clamped to 1.0`
721
+ });
722
+ temperature = 1;
723
+ } else if (temperature != null && temperature < 0) {
724
+ warnings.push({
725
+ type: "unsupported-setting",
726
+ setting: "temperature",
727
+ details: `${temperature} is below bedrock minimum of 0. clamped to 0`
728
+ });
729
+ temperature = 0;
730
+ }
711
731
  if (responseFormat != null && responseFormat.type !== "text" && responseFormat.type !== "json") {
712
732
  warnings.push({
713
733
  type: "unsupported-setting",
@@ -741,8 +761,16 @@ var BedrockChatLanguageModel = class {
741
761
  ...additionalTools
742
762
  };
743
763
  }
744
- const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
745
- const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
764
+ if (betas.size > 0 || bedrockOptions.anthropicBeta) {
765
+ const existingBetas = (_b = bedrockOptions.anthropicBeta) != null ? _b : [];
766
+ const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
767
+ bedrockOptions.additionalModelRequestFields = {
768
+ ...bedrockOptions.additionalModelRequestFields,
769
+ anthropic_beta: mergedBetas
770
+ };
771
+ }
772
+ const isThinking = ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "enabled";
773
+ const thinkingBudget = (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.budgetTokens;
746
774
  const inferenceConfig = {
747
775
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
748
776
  ...temperature != null && { temperature },
@@ -759,7 +787,7 @@ var BedrockChatLanguageModel = class {
759
787
  bedrockOptions.additionalModelRequestFields = {
760
788
  ...bedrockOptions.additionalModelRequestFields,
761
789
  thinking: {
762
- type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
790
+ type: (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type,
763
791
  budget_tokens: thinkingBudget
764
792
  }
765
793
  };
@@ -788,7 +816,7 @@ var BedrockChatLanguageModel = class {
788
816
  details: "topK is not supported when thinking is enabled"
789
817
  });
790
818
  }
791
- const hasAnyTools = ((_f = (_e = toolConfig.tools) == null ? void 0 : _e.length) != null ? _f : 0) > 0 || additionalTools;
819
+ const hasAnyTools = ((_g = (_f = toolConfig.tools) == null ? void 0 : _f.length) != null ? _g : 0) > 0 || additionalTools;
792
820
  let filteredPrompt = prompt;
793
821
  if (!hasAnyTools) {
794
822
  const hasToolContent = prompt.some(
@@ -837,27 +865,21 @@ var BedrockChatLanguageModel = class {
837
865
  };
838
866
  }
839
867
  async getHeaders({
840
- betas,
841
868
  headers
842
869
  }) {
843
- return combineHeaders(
844
- await resolve(this.config.headers),
845
- betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
846
- headers
847
- );
870
+ return combineHeaders(await resolve(this.config.headers), headers);
848
871
  }
849
872
  async doGenerate(options) {
850
873
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
851
874
  const {
852
875
  command: args,
853
876
  warnings,
854
- usesJsonResponseTool,
855
- betas
877
+ usesJsonResponseTool
856
878
  } = await this.getArgs(options);
857
879
  const url = `${this.getUrl(this.modelId)}/converse`;
858
880
  const { value: response, responseHeaders } = await postJsonToApi({
859
881
  url,
860
- headers: await this.getHeaders({ betas, headers: options.headers }),
882
+ headers: await this.getHeaders({ headers: options.headers }),
861
883
  body: args,
862
884
  failedResponseHandler: createJsonErrorResponseHandler({
863
885
  errorSchema: BedrockErrorSchema,
@@ -954,13 +976,12 @@ var BedrockChatLanguageModel = class {
954
976
  const {
955
977
  command: args,
956
978
  warnings,
957
- usesJsonResponseTool,
958
- betas
979
+ usesJsonResponseTool
959
980
  } = await this.getArgs(options);
960
981
  const url = `${this.getUrl(this.modelId)}/converse-stream`;
961
982
  const { value: response, responseHeaders } = await postJsonToApi({
962
983
  url,
963
- headers: await this.getHeaders({ betas, headers: options.headers }),
984
+ headers: await this.getHeaders({ headers: options.headers }),
964
985
  body: args,
965
986
  failedResponseHandler: createJsonErrorResponseHandler({
966
987
  errorSchema: BedrockErrorSchema,