@ai-sdk/amazon-bedrock 4.0.67 → 4.0.68

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
@@ -766,7 +766,7 @@ var BedrockChatLanguageModel = class {
766
766
  toolChoice,
767
767
  providerOptions
768
768
  }) {
769
- var _a, _b, _c, _d, _e, _f, _g, _h;
769
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
770
770
  const bedrockOptions = (_a = await parseProviderOptions2({
771
771
  provider: "bedrock",
772
772
  providerOptions,
@@ -813,7 +813,10 @@ var BedrockChatLanguageModel = class {
813
813
  details: "Only text and json response formats are supported."
814
814
  });
815
815
  }
816
- const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
816
+ const isAnthropicModel = this.modelId.includes("anthropic");
817
+ const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
818
+ const useNativeStructuredOutput = isAnthropicModel && isThinkingEnabled && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
819
+ const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
817
820
  type: "function",
818
821
  name: "json",
819
822
  description: "Respond with a JSON object.",
@@ -832,18 +835,16 @@ var BedrockChatLanguageModel = class {
832
835
  };
833
836
  }
834
837
  if (betas.size > 0 || bedrockOptions.anthropicBeta) {
835
- const existingBetas = (_b = bedrockOptions.anthropicBeta) != null ? _b : [];
838
+ const existingBetas = (_d = bedrockOptions.anthropicBeta) != null ? _d : [];
836
839
  const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
837
840
  bedrockOptions.additionalModelRequestFields = {
838
841
  ...bedrockOptions.additionalModelRequestFields,
839
842
  anthropic_beta: mergedBetas
840
843
  };
841
844
  }
842
- const isAnthropicModel = this.modelId.includes("anthropic");
843
- const thinkingType = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type;
844
- const isThinkingRequested = thinkingType === "enabled" || thinkingType === "adaptive";
845
- const thinkingBudget = thinkingType === "enabled" ? (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.budgetTokens : void 0;
846
- const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingRequested;
845
+ const thinkingType = (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type;
846
+ const thinkingBudget = thinkingType === "enabled" ? (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.budgetTokens : void 0;
847
+ const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
847
848
  const inferenceConfig = {
848
849
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
849
850
  ...temperature != null && { temperature },
@@ -874,7 +875,7 @@ var BedrockChatLanguageModel = class {
874
875
  };
875
876
  }
876
877
  } else if (!isAnthropicModel) {
877
- if (((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.budgetTokens) != null) {
878
+ if (((_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.budgetTokens) != null) {
878
879
  warnings.push({
879
880
  type: "unsupported",
880
881
  feature: "budgetTokens",
@@ -889,13 +890,14 @@ var BedrockChatLanguageModel = class {
889
890
  });
890
891
  }
891
892
  }
892
- const maxReasoningEffort = (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.maxReasoningEffort;
893
+ const maxReasoningEffort = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.maxReasoningEffort;
893
894
  const isOpenAIModel = this.modelId.startsWith("openai.");
894
895
  if (maxReasoningEffort != null) {
895
896
  if (isAnthropicModel) {
896
897
  bedrockOptions.additionalModelRequestFields = {
897
898
  ...bedrockOptions.additionalModelRequestFields,
898
899
  output_config: {
900
+ ...(_i = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _i.output_config,
899
901
  effort: maxReasoningEffort
900
902
  }
901
903
  };
@@ -915,6 +917,18 @@ var BedrockChatLanguageModel = class {
915
917
  };
916
918
  }
917
919
  }
920
+ if (useNativeStructuredOutput) {
921
+ bedrockOptions.additionalModelRequestFields = {
922
+ ...bedrockOptions.additionalModelRequestFields,
923
+ output_config: {
924
+ ...(_j = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _j.output_config,
925
+ format: {
926
+ type: "json_schema",
927
+ schema: responseFormat.schema
928
+ }
929
+ }
930
+ };
931
+ }
918
932
  if (isAnthropicThinkingEnabled && inferenceConfig.temperature != null) {
919
933
  delete inferenceConfig.temperature;
920
934
  warnings.push({
@@ -939,7 +953,7 @@ var BedrockChatLanguageModel = class {
939
953
  details: "topK is not supported when thinking is enabled"
940
954
  });
941
955
  }
942
- const hasAnyTools = ((_h = (_g = toolConfig.tools) == null ? void 0 : _g.length) != null ? _h : 0) > 0 || additionalTools;
956
+ const hasAnyTools = ((_l = (_k = toolConfig.tools) == null ? void 0 : _k.length) != null ? _l : 0) > 0 || additionalTools;
943
957
  let filteredPrompt = prompt;
944
958
  if (!hasAnyTools) {
945
959
  const hasToolContent = prompt.some(
@@ -1951,7 +1965,7 @@ import {
1951
1965
  import { AwsV4Signer } from "aws4fetch";
1952
1966
 
1953
1967
  // src/version.ts
1954
- var VERSION = true ? "4.0.67" : "0.0.0-test";
1968
+ var VERSION = true ? "4.0.68" : "0.0.0-test";
1955
1969
 
1956
1970
  // src/bedrock-sigv4-fetch.ts
1957
1971
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {