@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/CHANGELOG.md +8 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +47 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -27
- 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 +36 -0
- package/package.json +2 -2
- package/src/bedrock-anthropic-model-support.ts +19 -0
- package/src/bedrock-chat-language-model.ts +13 -7
- package/src/bedrock-chat-options.ts +10 -0
- package/src/bedrock-prepare-tools.ts +14 -2
- package/src/bedrock-provider.ts +22 -6
- package/src/index.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -110,6 +110,13 @@ var amazonBedrockLanguageModelOptions = z.object({
|
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
// src/bedrock-anthropic-model-support.ts
|
|
113
|
+
function isAnthropicModel({
|
|
114
|
+
modelId,
|
|
115
|
+
modelFamily,
|
|
116
|
+
reasoningBudgetTokens
|
|
117
|
+
}) {
|
|
118
|
+
return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
|
|
119
|
+
}
|
|
113
120
|
function supportsStrictTools(modelId) {
|
|
114
121
|
return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
|
|
115
122
|
}
|
|
@@ -253,6 +260,8 @@ async function prepareTools({
|
|
|
253
260
|
tools,
|
|
254
261
|
toolChoice,
|
|
255
262
|
modelId,
|
|
263
|
+
modelFamily,
|
|
264
|
+
reasoningBudgetTokens,
|
|
256
265
|
disableParallelToolUse
|
|
257
266
|
}) {
|
|
258
267
|
var _a;
|
|
@@ -285,12 +294,16 @@ async function prepareTools({
|
|
|
285
294
|
toolWarnings
|
|
286
295
|
};
|
|
287
296
|
}
|
|
288
|
-
const
|
|
297
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
298
|
+
modelId,
|
|
299
|
+
modelFamily,
|
|
300
|
+
reasoningBudgetTokens
|
|
301
|
+
});
|
|
289
302
|
const ProviderTools = supportedTools.filter((t) => t.type === "provider");
|
|
290
303
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
291
304
|
let additionalTools = void 0;
|
|
292
305
|
const bedrockTools = [];
|
|
293
|
-
const usingAnthropicTools =
|
|
306
|
+
const usingAnthropicTools = isAnthropicModel2 && ProviderTools.length > 0;
|
|
294
307
|
if (usingAnthropicTools) {
|
|
295
308
|
const {
|
|
296
309
|
toolChoice: preparedAnthropicToolChoice,
|
|
@@ -355,7 +368,7 @@ async function prepareTools({
|
|
|
355
368
|
}
|
|
356
369
|
});
|
|
357
370
|
}
|
|
358
|
-
if (
|
|
371
|
+
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
359
372
|
additionalTools = {
|
|
360
373
|
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
361
374
|
type: "tool",
|
|
@@ -962,7 +975,7 @@ var BedrockChatLanguageModel = class {
|
|
|
962
975
|
toolChoice,
|
|
963
976
|
providerOptions
|
|
964
977
|
}) {
|
|
965
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
978
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
966
979
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
967
980
|
provider: "bedrock",
|
|
968
981
|
providerOptions,
|
|
@@ -1014,7 +1027,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1014
1027
|
details: "Only text and json response formats are supported."
|
|
1015
1028
|
});
|
|
1016
1029
|
}
|
|
1017
|
-
const
|
|
1030
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
1031
|
+
modelId: this.modelId,
|
|
1032
|
+
modelFamily: this.config.modelFamily,
|
|
1033
|
+
reasoningBudgetTokens: (_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens
|
|
1034
|
+
});
|
|
1018
1035
|
const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
|
|
1019
1036
|
const isOpenAIModel = openAIModelId != null;
|
|
1020
1037
|
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
@@ -1037,9 +1054,9 @@ var BedrockChatLanguageModel = class {
|
|
|
1037
1054
|
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
1038
1055
|
}
|
|
1039
1056
|
}
|
|
1040
|
-
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
|
|
1041
|
-
const useNativeStructuredOutput =
|
|
1042
|
-
const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" &&
|
|
1057
|
+
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled || this.config.modelFamily === "anthropic");
|
|
1058
|
+
const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
1059
|
+
const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel2 && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
|
|
1043
1060
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1044
1061
|
type: "function",
|
|
1045
1062
|
name: "json",
|
|
@@ -1050,6 +1067,8 @@ var BedrockChatLanguageModel = class {
|
|
|
1050
1067
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
1051
1068
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
1052
1069
|
modelId: this.modelId,
|
|
1070
|
+
modelFamily: this.config.modelFamily,
|
|
1071
|
+
reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
|
|
1053
1072
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
1054
1073
|
});
|
|
1055
1074
|
warnings.push(...toolWarnings);
|
|
@@ -1060,17 +1079,17 @@ var BedrockChatLanguageModel = class {
|
|
|
1060
1079
|
};
|
|
1061
1080
|
}
|
|
1062
1081
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
1063
|
-
const existingBetas = (
|
|
1082
|
+
const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
|
|
1064
1083
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1065
1084
|
bedrockOptions.additionalModelRequestFields = {
|
|
1066
1085
|
...bedrockOptions.additionalModelRequestFields,
|
|
1067
1086
|
anthropic_beta: mergedBetas
|
|
1068
1087
|
};
|
|
1069
1088
|
}
|
|
1070
|
-
const thinkingType = (
|
|
1071
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1072
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
1073
|
-
const isAnthropicThinkingEnabled =
|
|
1089
|
+
const thinkingType = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.type;
|
|
1090
|
+
const thinkingBudget = thinkingType === "enabled" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens : void 0;
|
|
1091
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.display : void 0;
|
|
1092
|
+
const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingEnabled;
|
|
1074
1093
|
const inferenceConfig = {
|
|
1075
1094
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
1076
1095
|
...temperature != null && { temperature },
|
|
@@ -1101,8 +1120,8 @@ var BedrockChatLanguageModel = class {
|
|
|
1101
1120
|
}
|
|
1102
1121
|
};
|
|
1103
1122
|
}
|
|
1104
|
-
} else if (!
|
|
1105
|
-
if (((
|
|
1123
|
+
} else if (!isAnthropicModel2) {
|
|
1124
|
+
if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
|
|
1106
1125
|
warnings.push({
|
|
1107
1126
|
type: "unsupported",
|
|
1108
1127
|
feature: "budgetTokens",
|
|
@@ -1117,13 +1136,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1117
1136
|
});
|
|
1118
1137
|
}
|
|
1119
1138
|
}
|
|
1120
|
-
const maxReasoningEffort = (
|
|
1139
|
+
const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
|
|
1121
1140
|
if (maxReasoningEffort != null) {
|
|
1122
|
-
if (
|
|
1141
|
+
if (isAnthropicModel2) {
|
|
1123
1142
|
bedrockOptions.additionalModelRequestFields = {
|
|
1124
1143
|
...bedrockOptions.additionalModelRequestFields,
|
|
1125
1144
|
output_config: {
|
|
1126
|
-
...(
|
|
1145
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
|
|
1127
1146
|
effort: maxReasoningEffort
|
|
1128
1147
|
}
|
|
1129
1148
|
};
|
|
@@ -1134,7 +1153,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1134
1153
|
} : {
|
|
1135
1154
|
...bedrockOptions.additionalModelRequestFields,
|
|
1136
1155
|
reasoning: {
|
|
1137
|
-
...(
|
|
1156
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
|
|
1138
1157
|
effort: maxReasoningEffort
|
|
1139
1158
|
}
|
|
1140
1159
|
};
|
|
@@ -1153,7 +1172,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1153
1172
|
bedrockOptions.additionalModelRequestFields = {
|
|
1154
1173
|
...bedrockOptions.additionalModelRequestFields,
|
|
1155
1174
|
output_config: {
|
|
1156
|
-
...(
|
|
1175
|
+
...(_r = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _r.output_config,
|
|
1157
1176
|
format: {
|
|
1158
1177
|
type: "json_schema",
|
|
1159
1178
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1185,7 +1204,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1185
1204
|
details: "topK is not supported when thinking is enabled"
|
|
1186
1205
|
});
|
|
1187
1206
|
}
|
|
1188
|
-
const hasAnyTools = ((
|
|
1207
|
+
const hasAnyTools = ((_t = (_s = toolConfig.tools) == null ? void 0 : _s.length) != null ? _t : 0) > 0 || additionalTools;
|
|
1189
1208
|
let filteredPrompt = prompt;
|
|
1190
1209
|
if (!hasAnyTools) {
|
|
1191
1210
|
const hasToolContent = prompt.some(
|
|
@@ -1230,7 +1249,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1230
1249
|
structuredOutputMode: ____,
|
|
1231
1250
|
...filteredBedrockOptions
|
|
1232
1251
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1233
|
-
const additionalModelResponseFieldPaths =
|
|
1252
|
+
const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
|
|
1234
1253
|
return {
|
|
1235
1254
|
command: {
|
|
1236
1255
|
system,
|
|
@@ -2365,7 +2384,7 @@ import {
|
|
|
2365
2384
|
import { AwsV4Signer } from "aws4fetch";
|
|
2366
2385
|
|
|
2367
2386
|
// src/version.ts
|
|
2368
|
-
var VERSION = true ? "4.0.
|
|
2387
|
+
var VERSION = true ? "4.0.177" : "0.0.0-test";
|
|
2369
2388
|
|
|
2370
2389
|
// src/bedrock-sigv4-fetch.ts
|
|
2371
2390
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -2707,19 +2726,20 @@ Original error: ${errorMessage}`
|
|
|
2707
2726
|
service: "bedrock-agent-runtime",
|
|
2708
2727
|
serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME"
|
|
2709
2728
|
});
|
|
2710
|
-
const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
|
|
2729
|
+
const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
|
|
2711
2730
|
baseUrl: getBedrockRuntimeBaseUrl,
|
|
2712
2731
|
headers: getHeaders,
|
|
2713
2732
|
fetch: fetchFunction,
|
|
2714
|
-
generateId
|
|
2733
|
+
generateId,
|
|
2734
|
+
modelFamily: settings.modelFamily
|
|
2715
2735
|
});
|
|
2716
|
-
const provider = function(modelId) {
|
|
2736
|
+
const provider = function(modelId, settings) {
|
|
2717
2737
|
if (new.target) {
|
|
2718
2738
|
throw new Error(
|
|
2719
2739
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
2720
2740
|
);
|
|
2721
2741
|
}
|
|
2722
|
-
return createChatModel(modelId);
|
|
2742
|
+
return createChatModel(modelId, settings);
|
|
2723
2743
|
};
|
|
2724
2744
|
const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, {
|
|
2725
2745
|
baseUrl: getBedrockRuntimeBaseUrl,
|