@ai-sdk/amazon-bedrock 4.0.161 → 4.0.163

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
@@ -908,7 +908,7 @@ var BedrockChatLanguageModel = class {
908
908
  toolChoice,
909
909
  providerOptions
910
910
  }) {
911
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
911
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
912
912
  const bedrockOptions = (_a = await parseProviderOptions2({
913
913
  provider: "bedrock",
914
914
  providerOptions,
@@ -956,7 +956,10 @@ var BedrockChatLanguageModel = class {
956
956
  });
957
957
  }
958
958
  const isAnthropicModel = this.modelId.includes("anthropic");
959
- const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
959
+ const openAIModelId = (_b = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _b[1];
960
+ const isOpenAIModel = openAIModelId != null;
961
+ const isOpenAIGptOssModel = (_c = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _c : false;
962
+ const isThinkingEnabled = ((_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type) === "enabled" || ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "adaptive";
960
963
  const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
961
964
  const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
962
965
  const useJsonInstructionForStructuredOutput = isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
@@ -979,16 +982,16 @@ var BedrockChatLanguageModel = class {
979
982
  };
980
983
  }
981
984
  if (betas.size > 0 || bedrockOptions.anthropicBeta) {
982
- const existingBetas = (_d = bedrockOptions.anthropicBeta) != null ? _d : [];
985
+ const existingBetas = (_f = bedrockOptions.anthropicBeta) != null ? _f : [];
983
986
  const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
984
987
  bedrockOptions.additionalModelRequestFields = {
985
988
  ...bedrockOptions.additionalModelRequestFields,
986
989
  anthropic_beta: mergedBetas
987
990
  };
988
991
  }
989
- const thinkingType = (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type;
990
- const thinkingBudget = thinkingType === "enabled" ? (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.budgetTokens : void 0;
991
- const thinkingDisplay = thinkingType === "adaptive" ? (_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.display : void 0;
992
+ const thinkingType = (_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.type;
993
+ const thinkingBudget = thinkingType === "enabled" ? (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.budgetTokens : void 0;
994
+ const thinkingDisplay = thinkingType === "adaptive" ? (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.display : void 0;
992
995
  const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
993
996
  const inferenceConfig = {
994
997
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
@@ -1021,7 +1024,7 @@ var BedrockChatLanguageModel = class {
1021
1024
  };
1022
1025
  }
1023
1026
  } else if (!isAnthropicModel) {
1024
- if (((_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.budgetTokens) != null) {
1027
+ if (((_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.budgetTokens) != null) {
1025
1028
  warnings.push({
1026
1029
  type: "unsupported",
1027
1030
  feature: "budgetTokens",
@@ -1036,21 +1039,26 @@ var BedrockChatLanguageModel = class {
1036
1039
  });
1037
1040
  }
1038
1041
  }
1039
- const maxReasoningEffort = (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.maxReasoningEffort;
1040
- const isOpenAIModel = this.modelId.startsWith("openai.");
1042
+ const maxReasoningEffort = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.maxReasoningEffort;
1041
1043
  if (maxReasoningEffort != null) {
1042
1044
  if (isAnthropicModel) {
1043
1045
  bedrockOptions.additionalModelRequestFields = {
1044
1046
  ...bedrockOptions.additionalModelRequestFields,
1045
1047
  output_config: {
1046
- ...(_j = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _j.output_config,
1048
+ ...(_l = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _l.output_config,
1047
1049
  effort: maxReasoningEffort
1048
1050
  }
1049
1051
  };
1050
1052
  } else if (isOpenAIModel) {
1051
- bedrockOptions.additionalModelRequestFields = {
1053
+ bedrockOptions.additionalModelRequestFields = isOpenAIGptOssModel ? {
1052
1054
  ...bedrockOptions.additionalModelRequestFields,
1053
1055
  reasoning_effort: maxReasoningEffort
1056
+ } : {
1057
+ ...bedrockOptions.additionalModelRequestFields,
1058
+ reasoning: {
1059
+ ...(_m = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _m.reasoning,
1060
+ effort: maxReasoningEffort
1061
+ }
1054
1062
  };
1055
1063
  } else {
1056
1064
  bedrockOptions.additionalModelRequestFields = {
@@ -1067,7 +1075,7 @@ var BedrockChatLanguageModel = class {
1067
1075
  bedrockOptions.additionalModelRequestFields = {
1068
1076
  ...bedrockOptions.additionalModelRequestFields,
1069
1077
  output_config: {
1070
- ...(_k = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _k.output_config,
1078
+ ...(_n = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _n.output_config,
1071
1079
  format: {
1072
1080
  type: "json_schema",
1073
1081
  schema: sanitizeJsonSchema(responseFormat.schema)
@@ -1099,7 +1107,7 @@ var BedrockChatLanguageModel = class {
1099
1107
  details: "topK is not supported when thinking is enabled"
1100
1108
  });
1101
1109
  }
1102
- const hasAnyTools = ((_m = (_l = toolConfig.tools) == null ? void 0 : _l.length) != null ? _m : 0) > 0 || additionalTools;
1110
+ const hasAnyTools = ((_p = (_o = toolConfig.tools) == null ? void 0 : _o.length) != null ? _p : 0) > 0 || additionalTools;
1103
1111
  let filteredPrompt = prompt;
1104
1112
  if (!hasAnyTools) {
1105
1113
  const hasToolContent = prompt.some(
@@ -1729,6 +1737,10 @@ var BedrockReasoningTextSchema = z4.object({
1729
1737
  var BedrockRedactedReasoningSchema = z4.object({
1730
1738
  data: z4.string()
1731
1739
  });
1740
+ var AmazonBedrockCacheDetailSchema = z4.object({
1741
+ inputTokens: z4.number(),
1742
+ ttl: z4.string()
1743
+ }).catchall(z4.json());
1732
1744
  var BedrockResponseSchema = z4.object({
1733
1745
  metrics: z4.object({
1734
1746
  latencyMs: z4.number()
@@ -1770,8 +1782,8 @@ var BedrockResponseSchema = z4.object({
1770
1782
  totalTokens: z4.number(),
1771
1783
  cacheReadInputTokens: z4.number().nullish(),
1772
1784
  cacheWriteInputTokens: z4.number().nullish(),
1773
- cacheDetails: z4.array(z4.object({ inputTokens: z4.number(), ttl: z4.string() })).nullish()
1774
- })
1785
+ cacheDetails: z4.array(AmazonBedrockCacheDetailSchema).nullish()
1786
+ }).catchall(z4.json())
1775
1787
  });
1776
1788
  var BedrockStreamSchema = z4.object({
1777
1789
  contentBlockDelta: z4.object({
@@ -1819,10 +1831,11 @@ var BedrockStreamSchema = z4.object({
1819
1831
  usage: z4.object({
1820
1832
  cacheReadInputTokens: z4.number().nullish(),
1821
1833
  cacheWriteInputTokens: z4.number().nullish(),
1822
- cacheDetails: z4.array(z4.object({ inputTokens: z4.number(), ttl: z4.string() })).nullish(),
1834
+ cacheDetails: z4.array(AmazonBedrockCacheDetailSchema).nullish(),
1823
1835
  inputTokens: z4.number(),
1824
- outputTokens: z4.number()
1825
- }).nullish()
1836
+ outputTokens: z4.number(),
1837
+ totalTokens: z4.number().optional()
1838
+ }).catchall(z4.json()).nullish()
1826
1839
  }).nullish(),
1827
1840
  modelStreamErrorException: z4.record(z4.string(), z4.unknown()).nullish(),
1828
1841
  serviceUnavailableException: z4.record(z4.string(), z4.unknown()).nullish(),
@@ -2255,7 +2268,7 @@ import {
2255
2268
  import { AwsV4Signer } from "aws4fetch";
2256
2269
 
2257
2270
  // src/version.ts
2258
- var VERSION = true ? "4.0.161" : "0.0.0-test";
2271
+ var VERSION = true ? "4.0.163" : "0.0.0-test";
2259
2272
 
2260
2273
  // src/bedrock-sigv4-fetch.ts
2261
2274
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {