@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.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 !
|
|
115
|
+
return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
|
|
108
116
|
}
|
|
109
117
|
function supportsNativeStructuredOutput(modelId) {
|
|
110
|
-
return !
|
|
118
|
+
return !matchesModel(
|
|
119
|
+
modelId,
|
|
120
|
+
MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT
|
|
121
|
+
);
|
|
111
122
|
}
|
|
112
|
-
var
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
|
@@ -918,7 +932,8 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
918
932
|
|
|
919
933
|
// src/bedrock-chat-language-model.ts
|
|
920
934
|
var anthropicProviderOptions = z4.object({
|
|
921
|
-
disableParallelToolUse: z4.boolean().optional()
|
|
935
|
+
disableParallelToolUse: z4.boolean().optional(),
|
|
936
|
+
structuredOutputMode: z4.enum(["outputFormat", "jsonTool", "auto"]).optional()
|
|
922
937
|
});
|
|
923
938
|
var BedrockChatLanguageModel = class {
|
|
924
939
|
constructor(modelId, config) {
|
|
@@ -945,7 +960,7 @@ var BedrockChatLanguageModel = class {
|
|
|
945
960
|
toolChoice,
|
|
946
961
|
providerOptions
|
|
947
962
|
}) {
|
|
948
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
963
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
949
964
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
950
965
|
provider: "bedrock",
|
|
951
966
|
providerOptions,
|
|
@@ -1003,8 +1018,26 @@ var BedrockChatLanguageModel = class {
|
|
|
1003
1018
|
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
1004
1019
|
const isThinkingEnabled = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
1005
1020
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
1006
|
-
const
|
|
1007
|
-
|
|
1021
|
+
const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
|
|
1022
|
+
if (structuredOutputMode === "jsonTool") {
|
|
1023
|
+
const additionalModelRequestFields = {
|
|
1024
|
+
...bedrockOptions.additionalModelRequestFields
|
|
1025
|
+
};
|
|
1026
|
+
const outputConfig = additionalModelRequestFields.output_config;
|
|
1027
|
+
if (outputConfig != null && typeof outputConfig === "object" && !Array.isArray(outputConfig)) {
|
|
1028
|
+
const outputConfigWithoutFormat = { ...outputConfig };
|
|
1029
|
+
delete outputConfigWithoutFormat.format;
|
|
1030
|
+
if (Object.keys(outputConfigWithoutFormat).length > 0) {
|
|
1031
|
+
additionalModelRequestFields.output_config = outputConfigWithoutFormat;
|
|
1032
|
+
} else {
|
|
1033
|
+
delete additionalModelRequestFields.output_config;
|
|
1034
|
+
}
|
|
1035
|
+
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
|
|
1039
|
+
const useNativeStructuredOutput = isAnthropicModel && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
1040
|
+
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
1041
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1009
1042
|
type: "function",
|
|
1010
1043
|
name: "json",
|
|
@@ -1025,16 +1058,16 @@ var BedrockChatLanguageModel = class {
|
|
|
1025
1058
|
};
|
|
1026
1059
|
}
|
|
1027
1060
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
1028
|
-
const existingBetas = (
|
|
1061
|
+
const existingBetas = (_i = bedrockOptions.anthropicBeta) != null ? _i : [];
|
|
1029
1062
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1030
1063
|
bedrockOptions.additionalModelRequestFields = {
|
|
1031
1064
|
...bedrockOptions.additionalModelRequestFields,
|
|
1032
1065
|
anthropic_beta: mergedBetas
|
|
1033
1066
|
};
|
|
1034
1067
|
}
|
|
1035
|
-
const thinkingType = (
|
|
1036
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1037
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
1068
|
+
const thinkingType = (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.type;
|
|
1069
|
+
const thinkingBudget = thinkingType === "enabled" ? (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens : void 0;
|
|
1070
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.display : void 0;
|
|
1038
1071
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
1039
1072
|
const inferenceConfig = {
|
|
1040
1073
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -1067,7 +1100,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1067
1100
|
};
|
|
1068
1101
|
}
|
|
1069
1102
|
} else if (!isAnthropicModel) {
|
|
1070
|
-
if (((
|
|
1103
|
+
if (((_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.budgetTokens) != null) {
|
|
1071
1104
|
warnings.push({
|
|
1072
1105
|
type: "unsupported",
|
|
1073
1106
|
feature: "budgetTokens",
|
|
@@ -1082,13 +1115,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1082
1115
|
});
|
|
1083
1116
|
}
|
|
1084
1117
|
}
|
|
1085
|
-
const maxReasoningEffort = (
|
|
1118
|
+
const maxReasoningEffort = (_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.maxReasoningEffort;
|
|
1086
1119
|
if (maxReasoningEffort != null) {
|
|
1087
1120
|
if (isAnthropicModel) {
|
|
1088
1121
|
bedrockOptions.additionalModelRequestFields = {
|
|
1089
1122
|
...bedrockOptions.additionalModelRequestFields,
|
|
1090
1123
|
output_config: {
|
|
1091
|
-
...(
|
|
1124
|
+
...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
|
|
1092
1125
|
effort: maxReasoningEffort
|
|
1093
1126
|
}
|
|
1094
1127
|
};
|
|
@@ -1099,7 +1132,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1099
1132
|
} : {
|
|
1100
1133
|
...bedrockOptions.additionalModelRequestFields,
|
|
1101
1134
|
reasoning: {
|
|
1102
|
-
...(
|
|
1135
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.reasoning,
|
|
1103
1136
|
effort: maxReasoningEffort
|
|
1104
1137
|
}
|
|
1105
1138
|
};
|
|
@@ -1118,7 +1151,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1118
1151
|
bedrockOptions.additionalModelRequestFields = {
|
|
1119
1152
|
...bedrockOptions.additionalModelRequestFields,
|
|
1120
1153
|
output_config: {
|
|
1121
|
-
...(
|
|
1154
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
|
|
1122
1155
|
format: {
|
|
1123
1156
|
type: "json_schema",
|
|
1124
1157
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1150,7 +1183,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1150
1183
|
details: "topK is not supported when thinking is enabled"
|
|
1151
1184
|
});
|
|
1152
1185
|
}
|
|
1153
|
-
const hasAnyTools = ((
|
|
1186
|
+
const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
|
|
1154
1187
|
let filteredPrompt = prompt;
|
|
1155
1188
|
if (!hasAnyTools) {
|
|
1156
1189
|
const hasToolContent = prompt.some(
|
|
@@ -1192,6 +1225,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1192
1225
|
reasoningConfig: _,
|
|
1193
1226
|
additionalModelRequestFields: __,
|
|
1194
1227
|
serviceTier: ___,
|
|
1228
|
+
structuredOutputMode: ____,
|
|
1195
1229
|
...filteredBedrockOptions
|
|
1196
1230
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1197
1231
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -2320,7 +2354,7 @@ import {
|
|
|
2320
2354
|
import { AwsV4Signer } from "aws4fetch";
|
|
2321
2355
|
|
|
2322
2356
|
// src/version.ts
|
|
2323
|
-
var VERSION = true ? "4.0.
|
|
2357
|
+
var VERSION = true ? "4.0.168" : "0.0.0-test";
|
|
2324
2358
|
|
|
2325
2359
|
// src/bedrock-sigv4-fetch.ts
|
|
2326
2360
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|