@ai-sdk/amazon-bedrock 4.0.167 → 4.0.169

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
@@ -70,6 +70,14 @@ var bedrockFilePartProviderOptions = z.object({
70
70
  }).optional()
71
71
  });
72
72
  var amazonBedrockLanguageModelOptions = z.object({
73
+ /**
74
+ * Determines how structured outputs are generated for Anthropic models.
75
+ *
76
+ * - `outputFormat`: Use the native `output_config.format` parameter.
77
+ * - `jsonTool`: Use a special 'json' tool to specify the structured output format.
78
+ * - `auto`: Use `outputFormat` when supported, otherwise use `jsonTool` (default).
79
+ */
80
+ structuredOutputMode: z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
73
81
  /**
74
82
  * Additional inference parameters that the model supports,
75
83
  * beyond the base set of inference parameters that Converse
@@ -104,22 +112,28 @@ var amazonBedrockLanguageModelOptions = z.object({
104
112
 
105
113
  // src/bedrock-anthropic-model-support.ts
106
114
  function supportsStrictTools(modelId) {
107
- return !rejectsNewerSchemaFields(modelId);
115
+ return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
108
116
  }
109
117
  function supportsNativeStructuredOutput(modelId) {
110
- return !rejectsNewerSchemaFields(modelId);
118
+ return !matchesModel(
119
+ modelId,
120
+ MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT
121
+ );
111
122
  }
112
- var MODELS_REJECTING_NEWER_SCHEMA_FIELDS = [
123
+ var MODELS_WITHOUT_STRICT_TOOL_SUPPORT = [
113
124
  "claude-opus-4-7",
114
125
  "claude-opus-4-8",
115
126
  "claude-opus-5",
116
127
  "claude-fable-5",
117
128
  "claude-sonnet-5"
118
129
  ];
119
- function rejectsNewerSchemaFields(modelId) {
120
- return MODELS_REJECTING_NEWER_SCHEMA_FIELDS.some(
121
- (model) => modelId.includes(model)
122
- );
130
+ var MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT = [
131
+ ...MODELS_WITHOUT_STRICT_TOOL_SUPPORT,
132
+ "claude-sonnet-4-6",
133
+ "claude-haiku-4-5"
134
+ ];
135
+ function matchesModel(modelId, models) {
136
+ return models.some((model) => modelId.includes(model));
123
137
  }
124
138
 
125
139
  // src/bedrock-error.ts
@@ -917,8 +931,12 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
917
931
  }
918
932
 
919
933
  // src/bedrock-chat-language-model.ts
934
+ function isJsonResponseToolName(name) {
935
+ return name === "json" || name === "json<|channel|>commentary";
936
+ }
920
937
  var anthropicProviderOptions = z4.object({
921
- disableParallelToolUse: z4.boolean().optional()
938
+ disableParallelToolUse: z4.boolean().optional(),
939
+ structuredOutputMode: z4.enum(["outputFormat", "jsonTool", "auto"]).optional()
922
940
  });
923
941
  var BedrockChatLanguageModel = class {
924
942
  constructor(modelId, config) {
@@ -945,7 +963,7 @@ var BedrockChatLanguageModel = class {
945
963
  toolChoice,
946
964
  providerOptions
947
965
  }) {
948
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
966
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
949
967
  const bedrockOptions = (_a = await parseProviderOptions2({
950
968
  provider: "bedrock",
951
969
  providerOptions,
@@ -1003,8 +1021,26 @@ var BedrockChatLanguageModel = class {
1003
1021
  const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
1004
1022
  const isThinkingEnabled = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
1005
1023
  const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
1006
- const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
1007
- const useJsonInstructionForStructuredOutput = isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
1024
+ const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
1025
+ if (structuredOutputMode === "jsonTool") {
1026
+ const additionalModelRequestFields = {
1027
+ ...bedrockOptions.additionalModelRequestFields
1028
+ };
1029
+ const outputConfig = additionalModelRequestFields.output_config;
1030
+ if (outputConfig != null && typeof outputConfig === "object" && !Array.isArray(outputConfig)) {
1031
+ const outputConfigWithoutFormat = { ...outputConfig };
1032
+ delete outputConfigWithoutFormat.format;
1033
+ if (Object.keys(outputConfigWithoutFormat).length > 0) {
1034
+ additionalModelRequestFields.output_config = outputConfigWithoutFormat;
1035
+ } else {
1036
+ delete additionalModelRequestFields.output_config;
1037
+ }
1038
+ bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
1039
+ }
1040
+ }
1041
+ const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
1042
+ const useNativeStructuredOutput = isAnthropicModel && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
1043
+ const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
1008
1044
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
1009
1045
  type: "function",
1010
1046
  name: "json",
@@ -1025,16 +1061,16 @@ var BedrockChatLanguageModel = class {
1025
1061
  };
1026
1062
  }
1027
1063
  if (betas.size > 0 || bedrockOptions.anthropicBeta) {
1028
- const existingBetas = (_g = bedrockOptions.anthropicBeta) != null ? _g : [];
1064
+ const existingBetas = (_i = bedrockOptions.anthropicBeta) != null ? _i : [];
1029
1065
  const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
1030
1066
  bedrockOptions.additionalModelRequestFields = {
1031
1067
  ...bedrockOptions.additionalModelRequestFields,
1032
1068
  anthropic_beta: mergedBetas
1033
1069
  };
1034
1070
  }
1035
- const thinkingType = (_h = bedrockOptions.reasoningConfig) == null ? void 0 : _h.type;
1036
- const thinkingBudget = thinkingType === "enabled" ? (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens : void 0;
1037
- const thinkingDisplay = thinkingType === "adaptive" ? (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.display : void 0;
1071
+ const thinkingType = (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.type;
1072
+ const thinkingBudget = thinkingType === "enabled" ? (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens : void 0;
1073
+ const thinkingDisplay = thinkingType === "adaptive" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.display : void 0;
1038
1074
  const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
1039
1075
  const inferenceConfig = {
1040
1076
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
@@ -1067,7 +1103,7 @@ var BedrockChatLanguageModel = class {
1067
1103
  };
1068
1104
  }
1069
1105
  } else if (!isAnthropicModel) {
1070
- if (((_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens) != null) {
1106
+ if (((_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.budgetTokens) != null) {
1071
1107
  warnings.push({
1072
1108
  type: "unsupported",
1073
1109
  feature: "budgetTokens",
@@ -1082,13 +1118,13 @@ var BedrockChatLanguageModel = class {
1082
1118
  });
1083
1119
  }
1084
1120
  }
1085
- const maxReasoningEffort = (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.maxReasoningEffort;
1121
+ const maxReasoningEffort = (_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.maxReasoningEffort;
1086
1122
  if (maxReasoningEffort != null) {
1087
1123
  if (isAnthropicModel) {
1088
1124
  bedrockOptions.additionalModelRequestFields = {
1089
1125
  ...bedrockOptions.additionalModelRequestFields,
1090
1126
  output_config: {
1091
- ...(_m = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _m.output_config,
1127
+ ...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
1092
1128
  effort: maxReasoningEffort
1093
1129
  }
1094
1130
  };
@@ -1099,7 +1135,7 @@ var BedrockChatLanguageModel = class {
1099
1135
  } : {
1100
1136
  ...bedrockOptions.additionalModelRequestFields,
1101
1137
  reasoning: {
1102
- ...(_n = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _n.reasoning,
1138
+ ...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.reasoning,
1103
1139
  effort: maxReasoningEffort
1104
1140
  }
1105
1141
  };
@@ -1118,7 +1154,7 @@ var BedrockChatLanguageModel = class {
1118
1154
  bedrockOptions.additionalModelRequestFields = {
1119
1155
  ...bedrockOptions.additionalModelRequestFields,
1120
1156
  output_config: {
1121
- ...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
1157
+ ...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
1122
1158
  format: {
1123
1159
  type: "json_schema",
1124
1160
  schema: sanitizeJsonSchema(responseFormat.schema)
@@ -1150,7 +1186,7 @@ var BedrockChatLanguageModel = class {
1150
1186
  details: "topK is not supported when thinking is enabled"
1151
1187
  });
1152
1188
  }
1153
- const hasAnyTools = ((_q = (_p = toolConfig.tools) == null ? void 0 : _p.length) != null ? _q : 0) > 0 || additionalTools;
1189
+ const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
1154
1190
  let filteredPrompt = prompt;
1155
1191
  if (!hasAnyTools) {
1156
1192
  const hasToolContent = prompt.some(
@@ -1192,6 +1228,7 @@ var BedrockChatLanguageModel = class {
1192
1228
  reasoningConfig: _,
1193
1229
  additionalModelRequestFields: __,
1194
1230
  serviceTier: ___,
1231
+ structuredOutputMode: ____,
1195
1232
  ...filteredBedrockOptions
1196
1233
  } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
1197
1234
  const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
@@ -1298,7 +1335,7 @@ var BedrockChatLanguageModel = class {
1298
1335
  }
1299
1336
  }
1300
1337
  if (part.toolUse) {
1301
- const isJsonResponseTool = usesJsonResponseTool && part.toolUse.name === "json";
1338
+ const isJsonResponseTool = usesJsonResponseTool && isJsonResponseToolName(part.toolUse.name);
1302
1339
  if (isJsonResponseTool) {
1303
1340
  isJsonResponseFromTool = true;
1304
1341
  content.push({
@@ -1633,7 +1670,7 @@ var BedrockChatLanguageModel = class {
1633
1670
  if (((_q = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _q.toolUse) != null) {
1634
1671
  const toolUse = contentBlockStart.start.toolUse;
1635
1672
  const blockIndex = contentBlockStart.contentBlockIndex;
1636
- const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
1673
+ const isJsonResponseTool = usesJsonResponseTool && isJsonResponseToolName(toolUse.name);
1637
1674
  const normalizedToolCallId = normalizeToolCallId(
1638
1675
  toolUse.toolUseId,
1639
1676
  isMistral
@@ -2320,7 +2357,7 @@ import {
2320
2357
  import { AwsV4Signer } from "aws4fetch";
2321
2358
 
2322
2359
  // src/version.ts
2323
- var VERSION = true ? "4.0.167" : "0.0.0-test";
2360
+ var VERSION = true ? "4.0.169" : "0.0.0-test";
2324
2361
 
2325
2362
  // src/bedrock-sigv4-fetch.ts
2326
2363
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {