@ai-sdk/amazon-bedrock 4.0.167 → 4.0.168
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/CHANGELOG.md +6 -0
- package/dist/anthropic/index.js +14 -8
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +14 -8
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +56 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -22
- package/dist/index.mjs.map +1 -1
- package/dist/mantle/index.js +1 -1
- package/dist/mantle/index.mjs +1 -1
- package/docs/08-amazon-bedrock.mdx +45 -0
- package/package.json +1 -1
- package/src/bedrock-anthropic-model-support.ts +17 -7
- package/src/bedrock-chat-language-model.ts +43 -3
- package/src/bedrock-chat-options.ts +8 -0
package/dist/index.js
CHANGED
|
@@ -81,6 +81,14 @@ var bedrockFilePartProviderOptions = import_v4.z.object({
|
|
|
81
81
|
}).optional()
|
|
82
82
|
});
|
|
83
83
|
var amazonBedrockLanguageModelOptions = import_v4.z.object({
|
|
84
|
+
/**
|
|
85
|
+
* Determines how structured outputs are generated for Anthropic models.
|
|
86
|
+
*
|
|
87
|
+
* - `outputFormat`: Use the native `output_config.format` parameter.
|
|
88
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format.
|
|
89
|
+
* - `auto`: Use `outputFormat` when supported, otherwise use `jsonTool` (default).
|
|
90
|
+
*/
|
|
91
|
+
structuredOutputMode: import_v4.z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
84
92
|
/**
|
|
85
93
|
* Additional inference parameters that the model supports,
|
|
86
94
|
* beyond the base set of inference parameters that Converse
|
|
@@ -115,22 +123,28 @@ var amazonBedrockLanguageModelOptions = import_v4.z.object({
|
|
|
115
123
|
|
|
116
124
|
// src/bedrock-anthropic-model-support.ts
|
|
117
125
|
function supportsStrictTools(modelId) {
|
|
118
|
-
return !
|
|
126
|
+
return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
|
|
119
127
|
}
|
|
120
128
|
function supportsNativeStructuredOutput(modelId) {
|
|
121
|
-
return !
|
|
129
|
+
return !matchesModel(
|
|
130
|
+
modelId,
|
|
131
|
+
MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT
|
|
132
|
+
);
|
|
122
133
|
}
|
|
123
|
-
var
|
|
134
|
+
var MODELS_WITHOUT_STRICT_TOOL_SUPPORT = [
|
|
124
135
|
"claude-opus-4-7",
|
|
125
136
|
"claude-opus-4-8",
|
|
126
137
|
"claude-opus-5",
|
|
127
138
|
"claude-fable-5",
|
|
128
139
|
"claude-sonnet-5"
|
|
129
140
|
];
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
141
|
+
var MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT = [
|
|
142
|
+
...MODELS_WITHOUT_STRICT_TOOL_SUPPORT,
|
|
143
|
+
"claude-sonnet-4-6",
|
|
144
|
+
"claude-haiku-4-5"
|
|
145
|
+
];
|
|
146
|
+
function matchesModel(modelId, models) {
|
|
147
|
+
return models.some((model) => modelId.includes(model));
|
|
134
148
|
}
|
|
135
149
|
|
|
136
150
|
// src/bedrock-error.ts
|
|
@@ -914,7 +928,8 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
914
928
|
|
|
915
929
|
// src/bedrock-chat-language-model.ts
|
|
916
930
|
var anthropicProviderOptions = import_v44.z.object({
|
|
917
|
-
disableParallelToolUse: import_v44.z.boolean().optional()
|
|
931
|
+
disableParallelToolUse: import_v44.z.boolean().optional(),
|
|
932
|
+
structuredOutputMode: import_v44.z.enum(["outputFormat", "jsonTool", "auto"]).optional()
|
|
918
933
|
});
|
|
919
934
|
var BedrockChatLanguageModel = class {
|
|
920
935
|
constructor(modelId, config) {
|
|
@@ -941,7 +956,7 @@ var BedrockChatLanguageModel = class {
|
|
|
941
956
|
toolChoice,
|
|
942
957
|
providerOptions
|
|
943
958
|
}) {
|
|
944
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
959
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
945
960
|
const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
946
961
|
provider: "bedrock",
|
|
947
962
|
providerOptions,
|
|
@@ -999,8 +1014,26 @@ var BedrockChatLanguageModel = class {
|
|
|
999
1014
|
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
1000
1015
|
const isThinkingEnabled = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
1001
1016
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } = (0, import_internal2.getModelCapabilities)(this.modelId);
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1017
|
+
const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
|
|
1018
|
+
if (structuredOutputMode === "jsonTool") {
|
|
1019
|
+
const additionalModelRequestFields = {
|
|
1020
|
+
...bedrockOptions.additionalModelRequestFields
|
|
1021
|
+
};
|
|
1022
|
+
const outputConfig = additionalModelRequestFields.output_config;
|
|
1023
|
+
if (outputConfig != null && typeof outputConfig === "object" && !Array.isArray(outputConfig)) {
|
|
1024
|
+
const outputConfigWithoutFormat = { ...outputConfig };
|
|
1025
|
+
delete outputConfigWithoutFormat.format;
|
|
1026
|
+
if (Object.keys(outputConfigWithoutFormat).length > 0) {
|
|
1027
|
+
additionalModelRequestFields.output_config = outputConfigWithoutFormat;
|
|
1028
|
+
} else {
|
|
1029
|
+
delete additionalModelRequestFields.output_config;
|
|
1030
|
+
}
|
|
1031
|
+
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
|
|
1035
|
+
const useNativeStructuredOutput = isAnthropicModel && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
1036
|
+
const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
|
|
1004
1037
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1005
1038
|
type: "function",
|
|
1006
1039
|
name: "json",
|
|
@@ -1021,16 +1054,16 @@ var BedrockChatLanguageModel = class {
|
|
|
1021
1054
|
};
|
|
1022
1055
|
}
|
|
1023
1056
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
1024
|
-
const existingBetas = (
|
|
1057
|
+
const existingBetas = (_i = bedrockOptions.anthropicBeta) != null ? _i : [];
|
|
1025
1058
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1026
1059
|
bedrockOptions.additionalModelRequestFields = {
|
|
1027
1060
|
...bedrockOptions.additionalModelRequestFields,
|
|
1028
1061
|
anthropic_beta: mergedBetas
|
|
1029
1062
|
};
|
|
1030
1063
|
}
|
|
1031
|
-
const thinkingType = (
|
|
1032
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1033
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
1064
|
+
const thinkingType = (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.type;
|
|
1065
|
+
const thinkingBudget = thinkingType === "enabled" ? (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens : void 0;
|
|
1066
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.display : void 0;
|
|
1034
1067
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
1035
1068
|
const inferenceConfig = {
|
|
1036
1069
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -1063,7 +1096,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1063
1096
|
};
|
|
1064
1097
|
}
|
|
1065
1098
|
} else if (!isAnthropicModel) {
|
|
1066
|
-
if (((
|
|
1099
|
+
if (((_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.budgetTokens) != null) {
|
|
1067
1100
|
warnings.push({
|
|
1068
1101
|
type: "unsupported",
|
|
1069
1102
|
feature: "budgetTokens",
|
|
@@ -1078,13 +1111,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1078
1111
|
});
|
|
1079
1112
|
}
|
|
1080
1113
|
}
|
|
1081
|
-
const maxReasoningEffort = (
|
|
1114
|
+
const maxReasoningEffort = (_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.maxReasoningEffort;
|
|
1082
1115
|
if (maxReasoningEffort != null) {
|
|
1083
1116
|
if (isAnthropicModel) {
|
|
1084
1117
|
bedrockOptions.additionalModelRequestFields = {
|
|
1085
1118
|
...bedrockOptions.additionalModelRequestFields,
|
|
1086
1119
|
output_config: {
|
|
1087
|
-
...(
|
|
1120
|
+
...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
|
|
1088
1121
|
effort: maxReasoningEffort
|
|
1089
1122
|
}
|
|
1090
1123
|
};
|
|
@@ -1095,7 +1128,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1095
1128
|
} : {
|
|
1096
1129
|
...bedrockOptions.additionalModelRequestFields,
|
|
1097
1130
|
reasoning: {
|
|
1098
|
-
...(
|
|
1131
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.reasoning,
|
|
1099
1132
|
effort: maxReasoningEffort
|
|
1100
1133
|
}
|
|
1101
1134
|
};
|
|
@@ -1114,7 +1147,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1114
1147
|
bedrockOptions.additionalModelRequestFields = {
|
|
1115
1148
|
...bedrockOptions.additionalModelRequestFields,
|
|
1116
1149
|
output_config: {
|
|
1117
|
-
...(
|
|
1150
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
|
|
1118
1151
|
format: {
|
|
1119
1152
|
type: "json_schema",
|
|
1120
1153
|
schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
|
|
@@ -1146,7 +1179,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1146
1179
|
details: "topK is not supported when thinking is enabled"
|
|
1147
1180
|
});
|
|
1148
1181
|
}
|
|
1149
|
-
const hasAnyTools = ((
|
|
1182
|
+
const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
|
|
1150
1183
|
let filteredPrompt = prompt;
|
|
1151
1184
|
if (!hasAnyTools) {
|
|
1152
1185
|
const hasToolContent = prompt.some(
|
|
@@ -1188,6 +1221,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1188
1221
|
reasoningConfig: _,
|
|
1189
1222
|
additionalModelRequestFields: __,
|
|
1190
1223
|
serviceTier: ___,
|
|
1224
|
+
structuredOutputMode: ____,
|
|
1191
1225
|
...filteredBedrockOptions
|
|
1192
1226
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1193
1227
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -2295,7 +2329,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
2295
2329
|
var import_aws4fetch = require("aws4fetch");
|
|
2296
2330
|
|
|
2297
2331
|
// src/version.ts
|
|
2298
|
-
var VERSION = true ? "4.0.
|
|
2332
|
+
var VERSION = true ? "4.0.168" : "0.0.0-test";
|
|
2299
2333
|
|
|
2300
2334
|
// src/bedrock-sigv4-fetch.ts
|
|
2301
2335
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|