@ai-sdk/amazon-bedrock 4.0.175 → 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 +16 -0
- package/dist/anthropic/index.d.mts +3 -1
- package/dist/anthropic/index.d.ts +3 -1
- package/dist/anthropic/index.js +59 -24
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +53 -16
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +112 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -53
- 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 +43 -0
- package/package.json +3 -3
- package/src/anthropic/bedrock-anthropic-provider.ts +13 -7
- 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 +44 -18
- package/src/index.ts +1 -0
- package/src/resolve-bedrock-base-url.ts +51 -0
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
3
3
|
import {
|
|
4
4
|
generateId,
|
|
5
|
-
loadOptionalSetting,
|
|
5
|
+
loadOptionalSetting as loadOptionalSetting2,
|
|
6
6
|
loadSetting,
|
|
7
|
-
withoutTrailingSlash,
|
|
8
7
|
withUserAgentSuffix as withUserAgentSuffix2
|
|
9
8
|
} from "@ai-sdk/provider-utils";
|
|
10
9
|
|
|
@@ -111,6 +110,13 @@ var amazonBedrockLanguageModelOptions = z.object({
|
|
|
111
110
|
});
|
|
112
111
|
|
|
113
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
|
+
}
|
|
114
120
|
function supportsStrictTools(modelId) {
|
|
115
121
|
return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
|
|
116
122
|
}
|
|
@@ -254,6 +260,8 @@ async function prepareTools({
|
|
|
254
260
|
tools,
|
|
255
261
|
toolChoice,
|
|
256
262
|
modelId,
|
|
263
|
+
modelFamily,
|
|
264
|
+
reasoningBudgetTokens,
|
|
257
265
|
disableParallelToolUse
|
|
258
266
|
}) {
|
|
259
267
|
var _a;
|
|
@@ -286,12 +294,16 @@ async function prepareTools({
|
|
|
286
294
|
toolWarnings
|
|
287
295
|
};
|
|
288
296
|
}
|
|
289
|
-
const
|
|
297
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
298
|
+
modelId,
|
|
299
|
+
modelFamily,
|
|
300
|
+
reasoningBudgetTokens
|
|
301
|
+
});
|
|
290
302
|
const ProviderTools = supportedTools.filter((t) => t.type === "provider");
|
|
291
303
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
292
304
|
let additionalTools = void 0;
|
|
293
305
|
const bedrockTools = [];
|
|
294
|
-
const usingAnthropicTools =
|
|
306
|
+
const usingAnthropicTools = isAnthropicModel2 && ProviderTools.length > 0;
|
|
295
307
|
if (usingAnthropicTools) {
|
|
296
308
|
const {
|
|
297
309
|
toolChoice: preparedAnthropicToolChoice,
|
|
@@ -356,7 +368,7 @@ async function prepareTools({
|
|
|
356
368
|
}
|
|
357
369
|
});
|
|
358
370
|
}
|
|
359
|
-
if (
|
|
371
|
+
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
360
372
|
additionalTools = {
|
|
361
373
|
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
362
374
|
type: "tool",
|
|
@@ -963,7 +975,7 @@ var BedrockChatLanguageModel = class {
|
|
|
963
975
|
toolChoice,
|
|
964
976
|
providerOptions
|
|
965
977
|
}) {
|
|
966
|
-
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;
|
|
967
979
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
968
980
|
provider: "bedrock",
|
|
969
981
|
providerOptions,
|
|
@@ -1015,7 +1027,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1015
1027
|
details: "Only text and json response formats are supported."
|
|
1016
1028
|
});
|
|
1017
1029
|
}
|
|
1018
|
-
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
|
+
});
|
|
1019
1035
|
const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
|
|
1020
1036
|
const isOpenAIModel = openAIModelId != null;
|
|
1021
1037
|
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
@@ -1038,9 +1054,9 @@ var BedrockChatLanguageModel = class {
|
|
|
1038
1054
|
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
1039
1055
|
}
|
|
1040
1056
|
}
|
|
1041
|
-
const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
|
|
1042
|
-
const useNativeStructuredOutput =
|
|
1043
|
-
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;
|
|
1044
1060
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1045
1061
|
type: "function",
|
|
1046
1062
|
name: "json",
|
|
@@ -1051,6 +1067,8 @@ var BedrockChatLanguageModel = class {
|
|
|
1051
1067
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
1052
1068
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
1053
1069
|
modelId: this.modelId,
|
|
1070
|
+
modelFamily: this.config.modelFamily,
|
|
1071
|
+
reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
|
|
1054
1072
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
1055
1073
|
});
|
|
1056
1074
|
warnings.push(...toolWarnings);
|
|
@@ -1061,17 +1079,17 @@ var BedrockChatLanguageModel = class {
|
|
|
1061
1079
|
};
|
|
1062
1080
|
}
|
|
1063
1081
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
1064
|
-
const existingBetas = (
|
|
1082
|
+
const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
|
|
1065
1083
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
1066
1084
|
bedrockOptions.additionalModelRequestFields = {
|
|
1067
1085
|
...bedrockOptions.additionalModelRequestFields,
|
|
1068
1086
|
anthropic_beta: mergedBetas
|
|
1069
1087
|
};
|
|
1070
1088
|
}
|
|
1071
|
-
const thinkingType = (
|
|
1072
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
1073
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
1074
|
-
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;
|
|
1075
1093
|
const inferenceConfig = {
|
|
1076
1094
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
1077
1095
|
...temperature != null && { temperature },
|
|
@@ -1102,8 +1120,8 @@ var BedrockChatLanguageModel = class {
|
|
|
1102
1120
|
}
|
|
1103
1121
|
};
|
|
1104
1122
|
}
|
|
1105
|
-
} else if (!
|
|
1106
|
-
if (((
|
|
1123
|
+
} else if (!isAnthropicModel2) {
|
|
1124
|
+
if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
|
|
1107
1125
|
warnings.push({
|
|
1108
1126
|
type: "unsupported",
|
|
1109
1127
|
feature: "budgetTokens",
|
|
@@ -1118,13 +1136,13 @@ var BedrockChatLanguageModel = class {
|
|
|
1118
1136
|
});
|
|
1119
1137
|
}
|
|
1120
1138
|
}
|
|
1121
|
-
const maxReasoningEffort = (
|
|
1139
|
+
const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
|
|
1122
1140
|
if (maxReasoningEffort != null) {
|
|
1123
|
-
if (
|
|
1141
|
+
if (isAnthropicModel2) {
|
|
1124
1142
|
bedrockOptions.additionalModelRequestFields = {
|
|
1125
1143
|
...bedrockOptions.additionalModelRequestFields,
|
|
1126
1144
|
output_config: {
|
|
1127
|
-
...(
|
|
1145
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
|
|
1128
1146
|
effort: maxReasoningEffort
|
|
1129
1147
|
}
|
|
1130
1148
|
};
|
|
@@ -1135,7 +1153,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1135
1153
|
} : {
|
|
1136
1154
|
...bedrockOptions.additionalModelRequestFields,
|
|
1137
1155
|
reasoning: {
|
|
1138
|
-
...(
|
|
1156
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
|
|
1139
1157
|
effort: maxReasoningEffort
|
|
1140
1158
|
}
|
|
1141
1159
|
};
|
|
@@ -1154,7 +1172,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1154
1172
|
bedrockOptions.additionalModelRequestFields = {
|
|
1155
1173
|
...bedrockOptions.additionalModelRequestFields,
|
|
1156
1174
|
output_config: {
|
|
1157
|
-
...(
|
|
1175
|
+
...(_r = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _r.output_config,
|
|
1158
1176
|
format: {
|
|
1159
1177
|
type: "json_schema",
|
|
1160
1178
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1186,7 +1204,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1186
1204
|
details: "topK is not supported when thinking is enabled"
|
|
1187
1205
|
});
|
|
1188
1206
|
}
|
|
1189
|
-
const hasAnyTools = ((
|
|
1207
|
+
const hasAnyTools = ((_t = (_s = toolConfig.tools) == null ? void 0 : _s.length) != null ? _t : 0) > 0 || additionalTools;
|
|
1190
1208
|
let filteredPrompt = prompt;
|
|
1191
1209
|
if (!hasAnyTools) {
|
|
1192
1210
|
const hasToolContent = prompt.some(
|
|
@@ -1231,7 +1249,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1231
1249
|
structuredOutputMode: ____,
|
|
1232
1250
|
...filteredBedrockOptions
|
|
1233
1251
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1234
|
-
const additionalModelResponseFieldPaths =
|
|
1252
|
+
const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
|
|
1235
1253
|
return {
|
|
1236
1254
|
command: {
|
|
1237
1255
|
system,
|
|
@@ -2366,7 +2384,7 @@ import {
|
|
|
2366
2384
|
import { AwsV4Signer } from "aws4fetch";
|
|
2367
2385
|
|
|
2368
2386
|
// src/version.ts
|
|
2369
|
-
var VERSION = true ? "4.0.
|
|
2387
|
+
var VERSION = true ? "4.0.177" : "0.0.0-test";
|
|
2370
2388
|
|
|
2371
2389
|
// src/bedrock-sigv4-fetch.ts
|
|
2372
2390
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -2575,9 +2593,47 @@ var BedrockRerankingModel = class {
|
|
|
2575
2593
|
}
|
|
2576
2594
|
};
|
|
2577
2595
|
|
|
2596
|
+
// src/resolve-bedrock-base-url.ts
|
|
2597
|
+
import {
|
|
2598
|
+
loadOptionalSetting,
|
|
2599
|
+
withoutTrailingSlash
|
|
2600
|
+
} from "@ai-sdk/provider-utils";
|
|
2601
|
+
var AWS_PARTITION_DNS_SUFFIXES = [
|
|
2602
|
+
{ regionPrefix: "cn-", dnsSuffix: "amazonaws.com.cn" },
|
|
2603
|
+
{ regionPrefix: "us-iso-", dnsSuffix: "c2s.ic.gov" },
|
|
2604
|
+
{ regionPrefix: "us-isob-", dnsSuffix: "sc2s.sgov.gov" },
|
|
2605
|
+
{ regionPrefix: "eu-isoe-", dnsSuffix: "cloud.adc-e.uk" },
|
|
2606
|
+
{ regionPrefix: "us-isof-", dnsSuffix: "csp.hci.ic.gov" },
|
|
2607
|
+
{ regionPrefix: "eusc-", dnsSuffix: "amazonaws.eu" }
|
|
2608
|
+
];
|
|
2609
|
+
function resolveBedrockBaseURL({
|
|
2610
|
+
baseURL,
|
|
2611
|
+
getRegion,
|
|
2612
|
+
service,
|
|
2613
|
+
serviceEndpointUrlEnvironmentVariableName
|
|
2614
|
+
}) {
|
|
2615
|
+
var _a, _b, _c, _d, _e;
|
|
2616
|
+
const resolvedBaseURL = (_a = baseURL != null ? baseURL : loadOptionalSetting({
|
|
2617
|
+
settingValue: void 0,
|
|
2618
|
+
environmentVariableName: serviceEndpointUrlEnvironmentVariableName
|
|
2619
|
+
})) != null ? _a : loadOptionalSetting({
|
|
2620
|
+
settingValue: void 0,
|
|
2621
|
+
environmentVariableName: "AWS_ENDPOINT_URL"
|
|
2622
|
+
});
|
|
2623
|
+
if (resolvedBaseURL != null) {
|
|
2624
|
+
return (_b = withoutTrailingSlash(resolvedBaseURL)) != null ? _b : resolvedBaseURL;
|
|
2625
|
+
}
|
|
2626
|
+
const region = getRegion();
|
|
2627
|
+
const dnsSuffix = (_d = (_c = AWS_PARTITION_DNS_SUFFIXES.find(
|
|
2628
|
+
({ regionPrefix }) => region.startsWith(regionPrefix)
|
|
2629
|
+
)) == null ? void 0 : _c.dnsSuffix) != null ? _d : "amazonaws.com";
|
|
2630
|
+
const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
|
|
2631
|
+
return (_e = withoutTrailingSlash(generatedBaseURL)) != null ? _e : generatedBaseURL;
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2578
2634
|
// src/bedrock-provider.ts
|
|
2579
2635
|
function createAmazonBedrock(options = {}) {
|
|
2580
|
-
const rawApiKey =
|
|
2636
|
+
const rawApiKey = loadOptionalSetting2({
|
|
2581
2637
|
settingValue: options.apiKey,
|
|
2582
2638
|
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
2583
2639
|
});
|
|
@@ -2617,7 +2673,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
2617
2673
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
2618
2674
|
description: "AWS secret access key"
|
|
2619
2675
|
}),
|
|
2620
|
-
sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken :
|
|
2676
|
+
sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken : loadOptionalSetting2({
|
|
2621
2677
|
settingValue: options.sessionToken,
|
|
2622
2678
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
2623
2679
|
})
|
|
@@ -2648,41 +2704,42 @@ Original error: ${errorMessage}`
|
|
|
2648
2704
|
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
2649
2705
|
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
2650
2706
|
};
|
|
2651
|
-
const getBedrockRuntimeBaseUrl = () => {
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
};
|
|
2662
|
-
const getBedrockAgentRuntimeBaseUrl = () => {
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
};
|
|
2673
|
-
const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
|
|
2707
|
+
const getBedrockRuntimeBaseUrl = () => resolveBedrockBaseURL({
|
|
2708
|
+
baseURL: options.baseURL,
|
|
2709
|
+
getRegion: () => loadSetting({
|
|
2710
|
+
settingValue: options.region,
|
|
2711
|
+
settingName: "region",
|
|
2712
|
+
environmentVariableName: "AWS_REGION",
|
|
2713
|
+
description: "AWS region"
|
|
2714
|
+
}),
|
|
2715
|
+
service: "bedrock-runtime",
|
|
2716
|
+
serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_RUNTIME"
|
|
2717
|
+
});
|
|
2718
|
+
const getBedrockAgentRuntimeBaseUrl = () => resolveBedrockBaseURL({
|
|
2719
|
+
baseURL: options.baseURL,
|
|
2720
|
+
getRegion: () => loadSetting({
|
|
2721
|
+
settingValue: options.region,
|
|
2722
|
+
settingName: "region",
|
|
2723
|
+
environmentVariableName: "AWS_REGION",
|
|
2724
|
+
description: "AWS region"
|
|
2725
|
+
}),
|
|
2726
|
+
service: "bedrock-agent-runtime",
|
|
2727
|
+
serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME"
|
|
2728
|
+
});
|
|
2729
|
+
const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
|
|
2674
2730
|
baseUrl: getBedrockRuntimeBaseUrl,
|
|
2675
2731
|
headers: getHeaders,
|
|
2676
2732
|
fetch: fetchFunction,
|
|
2677
|
-
generateId
|
|
2733
|
+
generateId,
|
|
2734
|
+
modelFamily: settings.modelFamily
|
|
2678
2735
|
});
|
|
2679
|
-
const provider = function(modelId) {
|
|
2736
|
+
const provider = function(modelId, settings) {
|
|
2680
2737
|
if (new.target) {
|
|
2681
2738
|
throw new Error(
|
|
2682
2739
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
2683
2740
|
);
|
|
2684
2741
|
}
|
|
2685
|
-
return createChatModel(modelId);
|
|
2742
|
+
return createChatModel(modelId, settings);
|
|
2686
2743
|
};
|
|
2687
2744
|
const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, {
|
|
2688
2745
|
baseUrl: getBedrockRuntimeBaseUrl,
|