@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/CHANGELOG.md +14 -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 +61 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -24
- 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 +2 -2
- package/src/bedrock-anthropic-model-support.ts +17 -7
- package/src/bedrock-chat-language-model.ts +49 -5
- 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
|
|
@@ -913,8 +927,12 @@ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
|
|
|
913
927
|
}
|
|
914
928
|
|
|
915
929
|
// src/bedrock-chat-language-model.ts
|
|
930
|
+
function isJsonResponseToolName(name) {
|
|
931
|
+
return name === "json" || name === "json<|channel|>commentary";
|
|
932
|
+
}
|
|
916
933
|
var anthropicProviderOptions = import_v44.z.object({
|
|
917
|
-
disableParallelToolUse: import_v44.z.boolean().optional()
|
|
934
|
+
disableParallelToolUse: import_v44.z.boolean().optional(),
|
|
935
|
+
structuredOutputMode: import_v44.z.enum(["outputFormat", "jsonTool", "auto"]).optional()
|
|
918
936
|
});
|
|
919
937
|
var BedrockChatLanguageModel = class {
|
|
920
938
|
constructor(modelId, config) {
|
|
@@ -941,7 +959,7 @@ var BedrockChatLanguageModel = class {
|
|
|
941
959
|
toolChoice,
|
|
942
960
|
providerOptions
|
|
943
961
|
}) {
|
|
944
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
962
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
945
963
|
const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
946
964
|
provider: "bedrock",
|
|
947
965
|
providerOptions,
|
|
@@ -999,8 +1017,26 @@ var BedrockChatLanguageModel = class {
|
|
|
999
1017
|
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
1000
1018
|
const isThinkingEnabled = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
1001
1019
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } = (0, import_internal2.getModelCapabilities)(this.modelId);
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1020
|
+
const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
|
|
1021
|
+
if (structuredOutputMode === "jsonTool") {
|
|
1022
|
+
const additionalModelRequestFields = {
|
|
1023
|
+
...bedrockOptions.additionalModelRequestFields
|
|
1024
|
+
};
|
|
1025
|
+
const outputConfig = additionalModelRequestFields.output_config;
|
|
1026
|
+
if (outputConfig != null && typeof outputConfig === "object" && !Array.isArray(outputConfig)) {
|
|
1027
|
+
const outputConfigWithoutFormat = { ...outputConfig };
|
|
1028
|
+
delete outputConfigWithoutFormat.format;
|
|
1029
|
+
if (Object.keys(outputConfigWithoutFormat).length > 0) {
|
|
1030
|
+
additionalModelRequestFields.output_config = outputConfigWithoutFormat;
|
|
1031
|
+
} else {
|
|
1032
|
+
delete additionalModelRequestFields.output_config;
|
|
1033
|
+
}
|
|
1034
|
+
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
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;
|
|
1004
1040
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1005
1041
|
type: "function",
|
|
1006
1042
|
name: "json",
|
|
@@ -1021,16 +1057,16 @@ var BedrockChatLanguageModel = class {
|
|
|
1021
1057
|
};
|
|
1022
1058
|
}
|
|
1023
1059
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
1024
|
-
const existingBetas = (
|
|
1060
|
+
const existingBetas = (_i = bedrockOptions.anthropicBeta) != null ? _i : [];
|
|
1025
1061
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1026
1062
|
bedrockOptions.additionalModelRequestFields = {
|
|
1027
1063
|
...bedrockOptions.additionalModelRequestFields,
|
|
1028
1064
|
anthropic_beta: mergedBetas
|
|
1029
1065
|
};
|
|
1030
1066
|
}
|
|
1031
|
-
const thinkingType = (
|
|
1032
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1033
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
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;
|
|
1034
1070
|
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
1035
1071
|
const inferenceConfig = {
|
|
1036
1072
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
@@ -1063,7 +1099,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1063
1099
|
};
|
|
1064
1100
|
}
|
|
1065
1101
|
} else if (!isAnthropicModel) {
|
|
1066
|
-
if (((
|
|
1102
|
+
if (((_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.budgetTokens) != null) {
|
|
1067
1103
|
warnings.push({
|
|
1068
1104
|
type: "unsupported",
|
|
1069
1105
|
feature: "budgetTokens",
|
|
@@ -1078,13 +1114,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1078
1114
|
});
|
|
1079
1115
|
}
|
|
1080
1116
|
}
|
|
1081
|
-
const maxReasoningEffort = (
|
|
1117
|
+
const maxReasoningEffort = (_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.maxReasoningEffort;
|
|
1082
1118
|
if (maxReasoningEffort != null) {
|
|
1083
1119
|
if (isAnthropicModel) {
|
|
1084
1120
|
bedrockOptions.additionalModelRequestFields = {
|
|
1085
1121
|
...bedrockOptions.additionalModelRequestFields,
|
|
1086
1122
|
output_config: {
|
|
1087
|
-
...(
|
|
1123
|
+
...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
|
|
1088
1124
|
effort: maxReasoningEffort
|
|
1089
1125
|
}
|
|
1090
1126
|
};
|
|
@@ -1095,7 +1131,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1095
1131
|
} : {
|
|
1096
1132
|
...bedrockOptions.additionalModelRequestFields,
|
|
1097
1133
|
reasoning: {
|
|
1098
|
-
...(
|
|
1134
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.reasoning,
|
|
1099
1135
|
effort: maxReasoningEffort
|
|
1100
1136
|
}
|
|
1101
1137
|
};
|
|
@@ -1114,7 +1150,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1114
1150
|
bedrockOptions.additionalModelRequestFields = {
|
|
1115
1151
|
...bedrockOptions.additionalModelRequestFields,
|
|
1116
1152
|
output_config: {
|
|
1117
|
-
...(
|
|
1153
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
|
|
1118
1154
|
format: {
|
|
1119
1155
|
type: "json_schema",
|
|
1120
1156
|
schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
|
|
@@ -1146,7 +1182,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1146
1182
|
details: "topK is not supported when thinking is enabled"
|
|
1147
1183
|
});
|
|
1148
1184
|
}
|
|
1149
|
-
const hasAnyTools = ((
|
|
1185
|
+
const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
|
|
1150
1186
|
let filteredPrompt = prompt;
|
|
1151
1187
|
if (!hasAnyTools) {
|
|
1152
1188
|
const hasToolContent = prompt.some(
|
|
@@ -1188,6 +1224,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1188
1224
|
reasoningConfig: _,
|
|
1189
1225
|
additionalModelRequestFields: __,
|
|
1190
1226
|
serviceTier: ___,
|
|
1227
|
+
structuredOutputMode: ____,
|
|
1191
1228
|
...filteredBedrockOptions
|
|
1192
1229
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1193
1230
|
const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
|
|
@@ -1294,7 +1331,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1294
1331
|
}
|
|
1295
1332
|
}
|
|
1296
1333
|
if (part.toolUse) {
|
|
1297
|
-
const isJsonResponseTool = usesJsonResponseTool && part.toolUse.name
|
|
1334
|
+
const isJsonResponseTool = usesJsonResponseTool && isJsonResponseToolName(part.toolUse.name);
|
|
1298
1335
|
if (isJsonResponseTool) {
|
|
1299
1336
|
isJsonResponseFromTool = true;
|
|
1300
1337
|
content.push({
|
|
@@ -1629,7 +1666,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1629
1666
|
if (((_q = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _q.toolUse) != null) {
|
|
1630
1667
|
const toolUse = contentBlockStart.start.toolUse;
|
|
1631
1668
|
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
1632
|
-
const isJsonResponseTool = usesJsonResponseTool && toolUse.name
|
|
1669
|
+
const isJsonResponseTool = usesJsonResponseTool && isJsonResponseToolName(toolUse.name);
|
|
1633
1670
|
const normalizedToolCallId = normalizeToolCallId(
|
|
1634
1671
|
toolUse.toolUseId,
|
|
1635
1672
|
isMistral
|
|
@@ -2295,7 +2332,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
2295
2332
|
var import_aws4fetch = require("aws4fetch");
|
|
2296
2333
|
|
|
2297
2334
|
// src/version.ts
|
|
2298
|
-
var VERSION = true ? "4.0.
|
|
2335
|
+
var VERSION = true ? "4.0.169" : "0.0.0-test";
|
|
2299
2336
|
|
|
2300
2337
|
// src/bedrock-sigv4-fetch.ts
|
|
2301
2338
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|