@ai-sdk/amazon-bedrock 4.0.176 → 4.0.178
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 +16 -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 +132 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -48
- 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 +18 -12
- package/src/bedrock-chat-options.ts +10 -0
- package/src/bedrock-embedding-model.ts +2 -6
- package/src/bedrock-error.ts +7 -0
- package/src/bedrock-image-model.ts +2 -6
- package/src/bedrock-prepare-tools.ts +14 -2
- package/src/bedrock-provider.ts +22 -6
- package/src/index.ts +1 -0
- package/src/reranking/bedrock-reranking-model.ts +2 -6
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
// src/bedrock-chat-language-model.ts
|
|
11
11
|
import {
|
|
12
12
|
combineHeaders,
|
|
13
|
-
createJsonErrorResponseHandler,
|
|
13
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
14
14
|
createJsonResponseHandler,
|
|
15
15
|
injectJsonInstructionIntoMessages,
|
|
16
16
|
parseProviderOptions as parseProviderOptions2,
|
|
@@ -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
|
}
|
|
@@ -136,11 +143,16 @@ function matchesModel(modelId, models) {
|
|
|
136
143
|
}
|
|
137
144
|
|
|
138
145
|
// src/bedrock-error.ts
|
|
146
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
139
147
|
import { z as z2 } from "zod/v4";
|
|
140
148
|
var BedrockErrorSchema = z2.object({
|
|
141
149
|
message: z2.string(),
|
|
142
150
|
type: z2.string().nullish()
|
|
143
151
|
});
|
|
152
|
+
var bedrockFailedResponseHandler = createJsonErrorResponseHandler({
|
|
153
|
+
errorSchema: BedrockErrorSchema,
|
|
154
|
+
errorToMessage: (error) => error.type == null ? error.message : `${error.type}: ${error.message}`
|
|
155
|
+
});
|
|
144
156
|
|
|
145
157
|
// src/bedrock-event-stream-response-handler.ts
|
|
146
158
|
import { EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
@@ -253,6 +265,8 @@ async function prepareTools({
|
|
|
253
265
|
tools,
|
|
254
266
|
toolChoice,
|
|
255
267
|
modelId,
|
|
268
|
+
modelFamily,
|
|
269
|
+
reasoningBudgetTokens,
|
|
256
270
|
disableParallelToolUse
|
|
257
271
|
}) {
|
|
258
272
|
var _a;
|
|
@@ -285,12 +299,16 @@ async function prepareTools({
|
|
|
285
299
|
toolWarnings
|
|
286
300
|
};
|
|
287
301
|
}
|
|
288
|
-
const
|
|
302
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
303
|
+
modelId,
|
|
304
|
+
modelFamily,
|
|
305
|
+
reasoningBudgetTokens
|
|
306
|
+
});
|
|
289
307
|
const ProviderTools = supportedTools.filter((t) => t.type === "provider");
|
|
290
308
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
291
309
|
let additionalTools = void 0;
|
|
292
310
|
const bedrockTools = [];
|
|
293
|
-
const usingAnthropicTools =
|
|
311
|
+
const usingAnthropicTools = isAnthropicModel2 && ProviderTools.length > 0;
|
|
294
312
|
if (usingAnthropicTools) {
|
|
295
313
|
const {
|
|
296
314
|
toolChoice: preparedAnthropicToolChoice,
|
|
@@ -355,7 +373,7 @@ async function prepareTools({
|
|
|
355
373
|
}
|
|
356
374
|
});
|
|
357
375
|
}
|
|
358
|
-
if (
|
|
376
|
+
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
359
377
|
additionalTools = {
|
|
360
378
|
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
361
379
|
type: "tool",
|
|
@@ -962,7 +980,7 @@ var BedrockChatLanguageModel = class {
|
|
|
962
980
|
toolChoice,
|
|
963
981
|
providerOptions
|
|
964
982
|
}) {
|
|
965
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
983
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
966
984
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
967
985
|
provider: "bedrock",
|
|
968
986
|
providerOptions,
|
|
@@ -1014,7 +1032,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1014
1032
|
details: "Only text and json response formats are supported."
|
|
1015
1033
|
});
|
|
1016
1034
|
}
|
|
1017
|
-
const
|
|
1035
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
1036
|
+
modelId: this.modelId,
|
|
1037
|
+
modelFamily: this.config.modelFamily,
|
|
1038
|
+
reasoningBudgetTokens: (_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens
|
|
1039
|
+
});
|
|
1018
1040
|
const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
|
|
1019
1041
|
const isOpenAIModel = openAIModelId != null;
|
|
1020
1042
|
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
@@ -1037,9 +1059,9 @@ var BedrockChatLanguageModel = class {
|
|
|
1037
1059
|
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
1038
1060
|
}
|
|
1039
1061
|
}
|
|
1040
|
-
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
|
|
1041
|
-
const useNativeStructuredOutput =
|
|
1042
|
-
const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" &&
|
|
1062
|
+
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled || this.config.modelFamily === "anthropic");
|
|
1063
|
+
const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
1064
|
+
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
1065
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1044
1066
|
type: "function",
|
|
1045
1067
|
name: "json",
|
|
@@ -1050,6 +1072,8 @@ var BedrockChatLanguageModel = class {
|
|
|
1050
1072
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
1051
1073
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
1052
1074
|
modelId: this.modelId,
|
|
1075
|
+
modelFamily: this.config.modelFamily,
|
|
1076
|
+
reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
|
|
1053
1077
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
1054
1078
|
});
|
|
1055
1079
|
warnings.push(...toolWarnings);
|
|
@@ -1060,17 +1084,17 @@ var BedrockChatLanguageModel = class {
|
|
|
1060
1084
|
};
|
|
1061
1085
|
}
|
|
1062
1086
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
1063
|
-
const existingBetas = (
|
|
1087
|
+
const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
|
|
1064
1088
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1065
1089
|
bedrockOptions.additionalModelRequestFields = {
|
|
1066
1090
|
...bedrockOptions.additionalModelRequestFields,
|
|
1067
1091
|
anthropic_beta: mergedBetas
|
|
1068
1092
|
};
|
|
1069
1093
|
}
|
|
1070
|
-
const thinkingType = (
|
|
1071
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1072
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
1073
|
-
const isAnthropicThinkingEnabled =
|
|
1094
|
+
const thinkingType = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.type;
|
|
1095
|
+
const thinkingBudget = thinkingType === "enabled" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens : void 0;
|
|
1096
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.display : void 0;
|
|
1097
|
+
const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingEnabled;
|
|
1074
1098
|
const inferenceConfig = {
|
|
1075
1099
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
1076
1100
|
...temperature != null && { temperature },
|
|
@@ -1101,8 +1125,8 @@ var BedrockChatLanguageModel = class {
|
|
|
1101
1125
|
}
|
|
1102
1126
|
};
|
|
1103
1127
|
}
|
|
1104
|
-
} else if (!
|
|
1105
|
-
if (((
|
|
1128
|
+
} else if (!isAnthropicModel2) {
|
|
1129
|
+
if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
|
|
1106
1130
|
warnings.push({
|
|
1107
1131
|
type: "unsupported",
|
|
1108
1132
|
feature: "budgetTokens",
|
|
@@ -1117,13 +1141,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1117
1141
|
});
|
|
1118
1142
|
}
|
|
1119
1143
|
}
|
|
1120
|
-
const maxReasoningEffort = (
|
|
1144
|
+
const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
|
|
1121
1145
|
if (maxReasoningEffort != null) {
|
|
1122
|
-
if (
|
|
1146
|
+
if (isAnthropicModel2) {
|
|
1123
1147
|
bedrockOptions.additionalModelRequestFields = {
|
|
1124
1148
|
...bedrockOptions.additionalModelRequestFields,
|
|
1125
1149
|
output_config: {
|
|
1126
|
-
...(
|
|
1150
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
|
|
1127
1151
|
effort: maxReasoningEffort
|
|
1128
1152
|
}
|
|
1129
1153
|
};
|
|
@@ -1134,7 +1158,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1134
1158
|
} : {
|
|
1135
1159
|
...bedrockOptions.additionalModelRequestFields,
|
|
1136
1160
|
reasoning: {
|
|
1137
|
-
...(
|
|
1161
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
|
|
1138
1162
|
effort: maxReasoningEffort
|
|
1139
1163
|
}
|
|
1140
1164
|
};
|
|
@@ -1153,7 +1177,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1153
1177
|
bedrockOptions.additionalModelRequestFields = {
|
|
1154
1178
|
...bedrockOptions.additionalModelRequestFields,
|
|
1155
1179
|
output_config: {
|
|
1156
|
-
...(
|
|
1180
|
+
...(_r = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _r.output_config,
|
|
1157
1181
|
format: {
|
|
1158
1182
|
type: "json_schema",
|
|
1159
1183
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1185,7 +1209,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1185
1209
|
details: "topK is not supported when thinking is enabled"
|
|
1186
1210
|
});
|
|
1187
1211
|
}
|
|
1188
|
-
const hasAnyTools = ((
|
|
1212
|
+
const hasAnyTools = ((_t = (_s = toolConfig.tools) == null ? void 0 : _s.length) != null ? _t : 0) > 0 || additionalTools;
|
|
1189
1213
|
let filteredPrompt = prompt;
|
|
1190
1214
|
if (!hasAnyTools) {
|
|
1191
1215
|
const hasToolContent = prompt.some(
|
|
@@ -1230,7 +1254,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1230
1254
|
structuredOutputMode: ____,
|
|
1231
1255
|
...filteredBedrockOptions
|
|
1232
1256
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1233
|
-
const additionalModelResponseFieldPaths =
|
|
1257
|
+
const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
|
|
1234
1258
|
return {
|
|
1235
1259
|
command: {
|
|
1236
1260
|
system,
|
|
@@ -1274,7 +1298,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1274
1298
|
url,
|
|
1275
1299
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1276
1300
|
body: args,
|
|
1277
|
-
failedResponseHandler:
|
|
1301
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
1278
1302
|
errorSchema: BedrockErrorSchema,
|
|
1279
1303
|
errorToMessage: (error) => {
|
|
1280
1304
|
var _a2;
|
|
@@ -1414,10 +1438,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1414
1438
|
url,
|
|
1415
1439
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1416
1440
|
body: args,
|
|
1417
|
-
failedResponseHandler:
|
|
1418
|
-
errorSchema: BedrockErrorSchema,
|
|
1419
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1420
|
-
}),
|
|
1441
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1421
1442
|
successfulResponseHandler: createBedrockEventStreamResponseHandler(BedrockStreamSchema),
|
|
1422
1443
|
abortSignal: options.abortSignal,
|
|
1423
1444
|
fetch: this.config.fetch
|
|
@@ -1940,7 +1961,6 @@ import {
|
|
|
1940
1961
|
} from "@ai-sdk/provider";
|
|
1941
1962
|
import {
|
|
1942
1963
|
combineHeaders as combineHeaders2,
|
|
1943
|
-
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
1944
1964
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1945
1965
|
parseProviderOptions as parseProviderOptions3,
|
|
1946
1966
|
postJsonToApi as postJsonToApi2,
|
|
@@ -2070,10 +2090,7 @@ var BedrockEmbeddingModel = class {
|
|
|
2070
2090
|
combineHeaders2(await resolve2(this.config.headers), headers)
|
|
2071
2091
|
),
|
|
2072
2092
|
body: args,
|
|
2073
|
-
failedResponseHandler:
|
|
2074
|
-
errorSchema: BedrockErrorSchema,
|
|
2075
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
2076
|
-
}),
|
|
2093
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
2077
2094
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
2078
2095
|
BedrockEmbeddingResponseSchema
|
|
2079
2096
|
),
|
|
@@ -2145,7 +2162,6 @@ var BedrockEmbeddingResponseSchema = z6.union([
|
|
|
2145
2162
|
import {
|
|
2146
2163
|
combineHeaders as combineHeaders3,
|
|
2147
2164
|
convertUint8ArrayToBase64,
|
|
2148
|
-
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
2149
2165
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
2150
2166
|
postJsonToApi as postJsonToApi3,
|
|
2151
2167
|
resolve as resolve3
|
|
@@ -2299,10 +2315,7 @@ var BedrockImageModel = class {
|
|
|
2299
2315
|
combineHeaders3(await resolve3(this.config.headers), headers)
|
|
2300
2316
|
),
|
|
2301
2317
|
body: args,
|
|
2302
|
-
failedResponseHandler:
|
|
2303
|
-
errorSchema: BedrockErrorSchema,
|
|
2304
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
2305
|
-
}),
|
|
2318
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
2306
2319
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
2307
2320
|
bedrockImageResponseSchema
|
|
2308
2321
|
),
|
|
@@ -2365,7 +2378,7 @@ import {
|
|
|
2365
2378
|
import { AwsV4Signer } from "aws4fetch";
|
|
2366
2379
|
|
|
2367
2380
|
// src/version.ts
|
|
2368
|
-
var VERSION = true ? "4.0.
|
|
2381
|
+
var VERSION = true ? "4.0.178" : "0.0.0-test";
|
|
2369
2382
|
|
|
2370
2383
|
// src/bedrock-sigv4-fetch.ts
|
|
2371
2384
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -2453,7 +2466,6 @@ function createApiKeyFetchFunction(apiKey, fetch) {
|
|
|
2453
2466
|
// src/reranking/bedrock-reranking-model.ts
|
|
2454
2467
|
import {
|
|
2455
2468
|
combineHeaders as combineHeaders5,
|
|
2456
|
-
createJsonErrorResponseHandler as createJsonErrorResponseHandler4,
|
|
2457
2469
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2458
2470
|
parseProviderOptions as parseProviderOptions4,
|
|
2459
2471
|
postJsonToApi as postJsonToApi4,
|
|
@@ -2554,10 +2566,7 @@ var BedrockRerankingModel = class {
|
|
|
2554
2566
|
}
|
|
2555
2567
|
}))
|
|
2556
2568
|
},
|
|
2557
|
-
failedResponseHandler:
|
|
2558
|
-
errorSchema: BedrockErrorSchema,
|
|
2559
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
2560
|
-
}),
|
|
2569
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
2561
2570
|
successfulResponseHandler: createJsonResponseHandler4(
|
|
2562
2571
|
bedrockRerankingResponseSchema
|
|
2563
2572
|
),
|
|
@@ -2707,19 +2716,20 @@ Original error: ${errorMessage}`
|
|
|
2707
2716
|
service: "bedrock-agent-runtime",
|
|
2708
2717
|
serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME"
|
|
2709
2718
|
});
|
|
2710
|
-
const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
|
|
2719
|
+
const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
|
|
2711
2720
|
baseUrl: getBedrockRuntimeBaseUrl,
|
|
2712
2721
|
headers: getHeaders,
|
|
2713
2722
|
fetch: fetchFunction,
|
|
2714
|
-
generateId
|
|
2723
|
+
generateId,
|
|
2724
|
+
modelFamily: settings.modelFamily
|
|
2715
2725
|
});
|
|
2716
|
-
const provider = function(modelId) {
|
|
2726
|
+
const provider = function(modelId, settings) {
|
|
2717
2727
|
if (new.target) {
|
|
2718
2728
|
throw new Error(
|
|
2719
2729
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
2720
2730
|
);
|
|
2721
2731
|
}
|
|
2722
|
-
return createChatModel(modelId);
|
|
2732
|
+
return createChatModel(modelId, settings);
|
|
2723
2733
|
};
|
|
2724
2734
|
const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, {
|
|
2725
2735
|
baseUrl: getBedrockRuntimeBaseUrl,
|