@ai-sdk/amazon-bedrock 4.0.176 → 4.0.177

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.js CHANGED
@@ -122,6 +122,13 @@ var amazonBedrockLanguageModelOptions = import_v4.z.object({
122
122
  });
123
123
 
124
124
  // src/bedrock-anthropic-model-support.ts
125
+ function isAnthropicModel({
126
+ modelId,
127
+ modelFamily,
128
+ reasoningBudgetTokens
129
+ }) {
130
+ return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
131
+ }
125
132
  function supportsStrictTools(modelId) {
126
133
  return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
127
134
  }
@@ -256,6 +263,8 @@ async function prepareTools({
256
263
  tools,
257
264
  toolChoice,
258
265
  modelId,
266
+ modelFamily,
267
+ reasoningBudgetTokens,
259
268
  disableParallelToolUse
260
269
  }) {
261
270
  var _a;
@@ -288,12 +297,16 @@ async function prepareTools({
288
297
  toolWarnings
289
298
  };
290
299
  }
291
- const isAnthropicModel = modelId.includes("anthropic.");
300
+ const isAnthropicModel2 = isAnthropicModel({
301
+ modelId,
302
+ modelFamily,
303
+ reasoningBudgetTokens
304
+ });
292
305
  const ProviderTools = supportedTools.filter((t) => t.type === "provider");
293
306
  const functionTools = supportedTools.filter((t) => t.type === "function");
294
307
  let additionalTools = void 0;
295
308
  const bedrockTools = [];
296
- const usingAnthropicTools = isAnthropicModel && ProviderTools.length > 0;
309
+ const usingAnthropicTools = isAnthropicModel2 && ProviderTools.length > 0;
297
310
  if (usingAnthropicTools) {
298
311
  const {
299
312
  toolChoice: preparedAnthropicToolChoice,
@@ -358,7 +371,7 @@ async function prepareTools({
358
371
  }
359
372
  });
360
373
  }
361
- if (isAnthropicModel && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
374
+ if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
362
375
  additionalTools = {
363
376
  tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
364
377
  type: "tool",
@@ -959,7 +972,7 @@ var BedrockChatLanguageModel = class {
959
972
  toolChoice,
960
973
  providerOptions
961
974
  }) {
962
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
975
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
963
976
  const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
964
977
  provider: "bedrock",
965
978
  providerOptions,
@@ -1011,7 +1024,11 @@ var BedrockChatLanguageModel = class {
1011
1024
  details: "Only text and json response formats are supported."
1012
1025
  });
1013
1026
  }
1014
- const isAnthropicModel = this.modelId.includes("anthropic") || this.modelId.includes(":application-inference-profile/") && ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens) != null;
1027
+ const isAnthropicModel2 = isAnthropicModel({
1028
+ modelId: this.modelId,
1029
+ modelFamily: this.config.modelFamily,
1030
+ reasoningBudgetTokens: (_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens
1031
+ });
1015
1032
  const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
1016
1033
  const isOpenAIModel = openAIModelId != null;
1017
1034
  const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
@@ -1034,9 +1051,9 @@ var BedrockChatLanguageModel = class {
1034
1051
  bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
1035
1052
  }
1036
1053
  }
1037
- const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
1038
- const useNativeStructuredOutput = isAnthropicModel && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
1039
- const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
1054
+ const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled || this.config.modelFamily === "anthropic");
1055
+ const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
1056
+ const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel2 && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
1040
1057
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
1041
1058
  type: "function",
1042
1059
  name: "json",
@@ -1047,6 +1064,8 @@ var BedrockChatLanguageModel = class {
1047
1064
  tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
1048
1065
  toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
1049
1066
  modelId: this.modelId,
1067
+ modelFamily: this.config.modelFamily,
1068
+ reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
1050
1069
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
1051
1070
  });
1052
1071
  warnings.push(...toolWarnings);
@@ -1057,17 +1076,17 @@ var BedrockChatLanguageModel = class {
1057
1076
  };
1058
1077
  }
1059
1078
  if (betas.size > 0 || bedrockOptions.anthropicBeta) {
1060
- const existingBetas = (_i = bedrockOptions.anthropicBeta) != null ? _i : [];
1079
+ const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
1061
1080
  const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
1062
1081
  bedrockOptions.additionalModelRequestFields = {
1063
1082
  ...bedrockOptions.additionalModelRequestFields,
1064
1083
  anthropic_beta: mergedBetas
1065
1084
  };
1066
1085
  }
1067
- const thinkingType = (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.type;
1068
- const thinkingBudget = thinkingType === "enabled" ? (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens : void 0;
1069
- const thinkingDisplay = thinkingType === "adaptive" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.display : void 0;
1070
- const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
1086
+ const thinkingType = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.type;
1087
+ const thinkingBudget = thinkingType === "enabled" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens : void 0;
1088
+ const thinkingDisplay = thinkingType === "adaptive" ? (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.display : void 0;
1089
+ const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingEnabled;
1071
1090
  const inferenceConfig = {
1072
1091
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
1073
1092
  ...temperature != null && { temperature },
@@ -1098,8 +1117,8 @@ var BedrockChatLanguageModel = class {
1098
1117
  }
1099
1118
  };
1100
1119
  }
1101
- } else if (!isAnthropicModel) {
1102
- if (((_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.budgetTokens) != null) {
1120
+ } else if (!isAnthropicModel2) {
1121
+ if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
1103
1122
  warnings.push({
1104
1123
  type: "unsupported",
1105
1124
  feature: "budgetTokens",
@@ -1114,13 +1133,13 @@ var BedrockChatLanguageModel = class {
1114
1133
  });
1115
1134
  }
1116
1135
  }
1117
- const maxReasoningEffort = (_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.maxReasoningEffort;
1136
+ const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
1118
1137
  if (maxReasoningEffort != null) {
1119
- if (isAnthropicModel) {
1138
+ if (isAnthropicModel2) {
1120
1139
  bedrockOptions.additionalModelRequestFields = {
1121
1140
  ...bedrockOptions.additionalModelRequestFields,
1122
1141
  output_config: {
1123
- ...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
1142
+ ...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
1124
1143
  effort: maxReasoningEffort
1125
1144
  }
1126
1145
  };
@@ -1131,7 +1150,7 @@ var BedrockChatLanguageModel = class {
1131
1150
  } : {
1132
1151
  ...bedrockOptions.additionalModelRequestFields,
1133
1152
  reasoning: {
1134
- ...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.reasoning,
1153
+ ...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
1135
1154
  effort: maxReasoningEffort
1136
1155
  }
1137
1156
  };
@@ -1150,7 +1169,7 @@ var BedrockChatLanguageModel = class {
1150
1169
  bedrockOptions.additionalModelRequestFields = {
1151
1170
  ...bedrockOptions.additionalModelRequestFields,
1152
1171
  output_config: {
1153
- ...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
1172
+ ...(_r = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _r.output_config,
1154
1173
  format: {
1155
1174
  type: "json_schema",
1156
1175
  schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
@@ -1182,7 +1201,7 @@ var BedrockChatLanguageModel = class {
1182
1201
  details: "topK is not supported when thinking is enabled"
1183
1202
  });
1184
1203
  }
1185
- const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
1204
+ const hasAnyTools = ((_t = (_s = toolConfig.tools) == null ? void 0 : _s.length) != null ? _t : 0) > 0 || additionalTools;
1186
1205
  let filteredPrompt = prompt;
1187
1206
  if (!hasAnyTools) {
1188
1207
  const hasToolContent = prompt.some(
@@ -1227,7 +1246,7 @@ var BedrockChatLanguageModel = class {
1227
1246
  structuredOutputMode: ____,
1228
1247
  ...filteredBedrockOptions
1229
1248
  } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
1230
- const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
1249
+ const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
1231
1250
  return {
1232
1251
  command: {
1233
1252
  system,
@@ -2341,7 +2360,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
2341
2360
  var import_aws4fetch = require("aws4fetch");
2342
2361
 
2343
2362
  // src/version.ts
2344
- var VERSION = true ? "4.0.176" : "0.0.0-test";
2363
+ var VERSION = true ? "4.0.177" : "0.0.0-test";
2345
2364
 
2346
2365
  // src/bedrock-sigv4-fetch.ts
2347
2366
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -2673,19 +2692,20 @@ Original error: ${errorMessage}`
2673
2692
  service: "bedrock-agent-runtime",
2674
2693
  serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME"
2675
2694
  });
2676
- const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
2695
+ const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
2677
2696
  baseUrl: getBedrockRuntimeBaseUrl,
2678
2697
  headers: getHeaders,
2679
2698
  fetch: fetchFunction,
2680
- generateId: import_provider_utils12.generateId
2699
+ generateId: import_provider_utils12.generateId,
2700
+ modelFamily: settings.modelFamily
2681
2701
  });
2682
- const provider = function(modelId) {
2702
+ const provider = function(modelId, settings) {
2683
2703
  if (new.target) {
2684
2704
  throw new Error(
2685
2705
  "The Amazon Bedrock model function cannot be called with the new keyword."
2686
2706
  );
2687
2707
  }
2688
- return createChatModel(modelId);
2708
+ return createChatModel(modelId, settings);
2689
2709
  };
2690
2710
  const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, {
2691
2711
  baseUrl: getBedrockRuntimeBaseUrl,