@ai-sdk/amazon-bedrock 3.0.130 → 3.0.132
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 +13 -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 +156 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// src/bedrock-provider.ts
|
|
2
2
|
import {
|
|
3
3
|
generateId,
|
|
4
|
-
loadOptionalSetting,
|
|
4
|
+
loadOptionalSetting as loadOptionalSetting2,
|
|
5
5
|
loadSetting,
|
|
6
|
-
withoutTrailingSlash,
|
|
7
6
|
withUserAgentSuffix as withUserAgentSuffix2
|
|
8
7
|
} from "@ai-sdk/provider-utils";
|
|
9
8
|
|
|
10
9
|
// src/version.ts
|
|
11
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.132" : "0.0.0-test";
|
|
12
11
|
|
|
13
12
|
// src/bedrock-provider.ts
|
|
14
13
|
import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
@@ -17,7 +16,7 @@ import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
|
|
|
17
16
|
import { sanitizeJsonSchema } from "@ai-sdk/anthropic/internal";
|
|
18
17
|
import {
|
|
19
18
|
combineHeaders,
|
|
20
|
-
createJsonErrorResponseHandler,
|
|
19
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
21
20
|
createJsonResponseHandler,
|
|
22
21
|
parseProviderOptions as parseProviderOptions2,
|
|
23
22
|
postJsonToApi,
|
|
@@ -114,12 +113,26 @@ var bedrockProviderOptions = z.object({
|
|
|
114
113
|
serviceTier: z.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
115
114
|
});
|
|
116
115
|
|
|
116
|
+
// src/bedrock-anthropic-model-support.ts
|
|
117
|
+
function isAnthropicModel({
|
|
118
|
+
modelId,
|
|
119
|
+
modelFamily,
|
|
120
|
+
reasoningBudgetTokens
|
|
121
|
+
}) {
|
|
122
|
+
return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
|
|
123
|
+
}
|
|
124
|
+
|
|
117
125
|
// src/bedrock-error.ts
|
|
126
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
118
127
|
import { z as z2 } from "zod/v4";
|
|
119
128
|
var BedrockErrorSchema = z2.object({
|
|
120
129
|
message: z2.string(),
|
|
121
130
|
type: z2.string().nullish()
|
|
122
131
|
});
|
|
132
|
+
var bedrockFailedResponseHandler = createJsonErrorResponseHandler({
|
|
133
|
+
errorSchema: BedrockErrorSchema,
|
|
134
|
+
errorToMessage: (error) => error.type == null ? error.message : `${error.type}: ${error.message}`
|
|
135
|
+
});
|
|
123
136
|
|
|
124
137
|
// src/bedrock-event-stream-response-handler.ts
|
|
125
138
|
import { EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
@@ -232,6 +245,8 @@ async function prepareTools({
|
|
|
232
245
|
tools,
|
|
233
246
|
toolChoice,
|
|
234
247
|
modelId,
|
|
248
|
+
modelFamily,
|
|
249
|
+
reasoningBudgetTokens,
|
|
235
250
|
disableParallelToolUse
|
|
236
251
|
}) {
|
|
237
252
|
var _a;
|
|
@@ -264,14 +279,18 @@ async function prepareTools({
|
|
|
264
279
|
toolWarnings
|
|
265
280
|
};
|
|
266
281
|
}
|
|
267
|
-
const isAnthropicModel = modelId.includes("anthropic.");
|
|
268
282
|
const providerDefinedTools = supportedTools.filter(
|
|
269
283
|
(t) => t.type === "provider-defined"
|
|
270
284
|
);
|
|
285
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
286
|
+
modelId,
|
|
287
|
+
modelFamily,
|
|
288
|
+
reasoningBudgetTokens
|
|
289
|
+
});
|
|
271
290
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
272
291
|
let additionalTools = void 0;
|
|
273
292
|
const bedrockTools = [];
|
|
274
|
-
const usingAnthropicTools =
|
|
293
|
+
const usingAnthropicTools = isAnthropicModel2 && providerDefinedTools.length > 0;
|
|
275
294
|
if (usingAnthropicTools) {
|
|
276
295
|
if (functionTools.length > 0) {
|
|
277
296
|
toolWarnings.push({
|
|
@@ -331,7 +350,7 @@ async function prepareTools({
|
|
|
331
350
|
}
|
|
332
351
|
});
|
|
333
352
|
}
|
|
334
|
-
if (
|
|
353
|
+
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
335
354
|
additionalTools = {
|
|
336
355
|
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
337
356
|
type: "tool",
|
|
@@ -793,7 +812,7 @@ var BedrockChatLanguageModel = class {
|
|
|
793
812
|
toolChoice,
|
|
794
813
|
providerOptions
|
|
795
814
|
}) {
|
|
796
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
815
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
797
816
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
798
817
|
provider: "bedrock",
|
|
799
818
|
providerOptions,
|
|
@@ -845,12 +864,16 @@ var BedrockChatLanguageModel = class {
|
|
|
845
864
|
details: "Only text and json response formats are supported."
|
|
846
865
|
});
|
|
847
866
|
}
|
|
848
|
-
const
|
|
849
|
-
|
|
867
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
868
|
+
modelId: this.modelId,
|
|
869
|
+
modelFamily: this.config.modelFamily,
|
|
870
|
+
reasoningBudgetTokens: (_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens
|
|
871
|
+
});
|
|
872
|
+
const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
|
|
850
873
|
const isOpenAIModel = openAIModelId != null;
|
|
851
|
-
const isOpenAIGptOssModel = (
|
|
852
|
-
const isThinkingRequested = ((
|
|
853
|
-
const structuredOutputMode = (
|
|
874
|
+
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
875
|
+
const isThinkingRequested = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
876
|
+
const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
|
|
854
877
|
if (structuredOutputMode === "jsonTool") {
|
|
855
878
|
const additionalModelRequestFields = {
|
|
856
879
|
...bedrockOptions.additionalModelRequestFields
|
|
@@ -867,7 +890,8 @@ var BedrockChatLanguageModel = class {
|
|
|
867
890
|
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
868
891
|
}
|
|
869
892
|
}
|
|
870
|
-
const
|
|
893
|
+
const modelSupportsNativeStructuredOutput = this.config.modelFamily === "anthropic" || supportsNativeStructuredOutput(this.modelId) && isThinkingRequested;
|
|
894
|
+
const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
871
895
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
872
896
|
type: "function",
|
|
873
897
|
name: "json",
|
|
@@ -878,6 +902,8 @@ var BedrockChatLanguageModel = class {
|
|
|
878
902
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
879
903
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
880
904
|
modelId: this.modelId,
|
|
905
|
+
modelFamily: this.config.modelFamily,
|
|
906
|
+
reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
|
|
881
907
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
882
908
|
});
|
|
883
909
|
warnings.push(...toolWarnings);
|
|
@@ -888,17 +914,17 @@ var BedrockChatLanguageModel = class {
|
|
|
888
914
|
};
|
|
889
915
|
}
|
|
890
916
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
891
|
-
const existingBetas = (
|
|
917
|
+
const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
|
|
892
918
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
893
919
|
bedrockOptions.additionalModelRequestFields = {
|
|
894
920
|
...bedrockOptions.additionalModelRequestFields,
|
|
895
921
|
anthropic_beta: mergedBetas
|
|
896
922
|
};
|
|
897
923
|
}
|
|
898
|
-
const thinkingType = (
|
|
899
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
900
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
901
|
-
const isAnthropicThinkingEnabled =
|
|
924
|
+
const thinkingType = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.type;
|
|
925
|
+
const thinkingBudget = thinkingType === "enabled" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens : void 0;
|
|
926
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.display : void 0;
|
|
927
|
+
const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingRequested;
|
|
902
928
|
const inferenceConfig = {
|
|
903
929
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
904
930
|
...temperature != null && { temperature },
|
|
@@ -929,8 +955,8 @@ var BedrockChatLanguageModel = class {
|
|
|
929
955
|
}
|
|
930
956
|
};
|
|
931
957
|
}
|
|
932
|
-
} else if (!
|
|
933
|
-
if (((
|
|
958
|
+
} else if (!isAnthropicModel2) {
|
|
959
|
+
if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
|
|
934
960
|
warnings.push({
|
|
935
961
|
type: "unsupported-setting",
|
|
936
962
|
setting: "budgetTokens",
|
|
@@ -945,13 +971,13 @@ var BedrockChatLanguageModel = class {
|
|
|
945
971
|
});
|
|
946
972
|
}
|
|
947
973
|
}
|
|
948
|
-
const maxReasoningEffort = (
|
|
974
|
+
const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
|
|
949
975
|
if (maxReasoningEffort != null) {
|
|
950
|
-
if (
|
|
976
|
+
if (isAnthropicModel2) {
|
|
951
977
|
bedrockOptions.additionalModelRequestFields = {
|
|
952
978
|
...bedrockOptions.additionalModelRequestFields,
|
|
953
979
|
output_config: {
|
|
954
|
-
...(
|
|
980
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
|
|
955
981
|
effort: maxReasoningEffort
|
|
956
982
|
}
|
|
957
983
|
};
|
|
@@ -962,7 +988,7 @@ var BedrockChatLanguageModel = class {
|
|
|
962
988
|
} : {
|
|
963
989
|
...bedrockOptions.additionalModelRequestFields,
|
|
964
990
|
reasoning: {
|
|
965
|
-
...(
|
|
991
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
|
|
966
992
|
effort: maxReasoningEffort
|
|
967
993
|
}
|
|
968
994
|
};
|
|
@@ -970,7 +996,7 @@ var BedrockChatLanguageModel = class {
|
|
|
970
996
|
bedrockOptions.additionalModelRequestFields = {
|
|
971
997
|
...bedrockOptions.additionalModelRequestFields,
|
|
972
998
|
reasoningConfig: {
|
|
973
|
-
...((
|
|
999
|
+
...((_r = bedrockOptions.reasoningConfig) == null ? void 0 : _r.type) != null && {
|
|
974
1000
|
type: bedrockOptions.reasoningConfig.type
|
|
975
1001
|
},
|
|
976
1002
|
maxReasoningEffort
|
|
@@ -982,7 +1008,7 @@ var BedrockChatLanguageModel = class {
|
|
|
982
1008
|
bedrockOptions.additionalModelRequestFields = {
|
|
983
1009
|
...bedrockOptions.additionalModelRequestFields,
|
|
984
1010
|
output_config: {
|
|
985
|
-
...(
|
|
1011
|
+
...(_s = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _s.output_config,
|
|
986
1012
|
format: {
|
|
987
1013
|
type: "json_schema",
|
|
988
1014
|
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
@@ -1014,7 +1040,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1014
1040
|
details: "topK is not supported when thinking is enabled"
|
|
1015
1041
|
});
|
|
1016
1042
|
}
|
|
1017
|
-
const hasAnyTools = ((
|
|
1043
|
+
const hasAnyTools = ((_u = (_t = toolConfig.tools) == null ? void 0 : _t.length) != null ? _u : 0) > 0 || additionalTools;
|
|
1018
1044
|
let filteredPrompt = prompt;
|
|
1019
1045
|
if (!hasAnyTools) {
|
|
1020
1046
|
const hasToolContent = prompt.some(
|
|
@@ -1048,7 +1074,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1048
1074
|
structuredOutputMode: ____,
|
|
1049
1075
|
...filteredBedrockOptions
|
|
1050
1076
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1051
|
-
const additionalModelResponseFieldPaths =
|
|
1077
|
+
const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
|
|
1052
1078
|
return {
|
|
1053
1079
|
command: {
|
|
1054
1080
|
system,
|
|
@@ -1090,7 +1116,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1090
1116
|
url,
|
|
1091
1117
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1092
1118
|
body: args,
|
|
1093
|
-
failedResponseHandler:
|
|
1119
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
1094
1120
|
errorSchema: BedrockErrorSchema,
|
|
1095
1121
|
errorToMessage: (error) => {
|
|
1096
1122
|
var _a2;
|
|
@@ -1213,10 +1239,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1213
1239
|
url,
|
|
1214
1240
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1215
1241
|
body: args,
|
|
1216
|
-
failedResponseHandler:
|
|
1217
|
-
errorSchema: BedrockErrorSchema,
|
|
1218
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1219
|
-
}),
|
|
1242
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1220
1243
|
successfulResponseHandler: createBedrockEventStreamResponseHandler(BedrockStreamSchema),
|
|
1221
1244
|
abortSignal: options.abortSignal,
|
|
1222
1245
|
fetch: this.config.fetch
|
|
@@ -1663,7 +1686,6 @@ import {
|
|
|
1663
1686
|
} from "@ai-sdk/provider";
|
|
1664
1687
|
import {
|
|
1665
1688
|
combineHeaders as combineHeaders2,
|
|
1666
|
-
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
1667
1689
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1668
1690
|
parseProviderOptions as parseProviderOptions3,
|
|
1669
1691
|
postJsonToApi as postJsonToApi2,
|
|
@@ -1732,10 +1754,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1732
1754
|
combineHeaders2(await resolve2(this.config.headers), headers)
|
|
1733
1755
|
),
|
|
1734
1756
|
body: args,
|
|
1735
|
-
failedResponseHandler:
|
|
1736
|
-
errorSchema: BedrockErrorSchema,
|
|
1737
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1738
|
-
}),
|
|
1757
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1739
1758
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
1740
1759
|
BedrockEmbeddingResponseSchema
|
|
1741
1760
|
),
|
|
@@ -1756,7 +1775,6 @@ var BedrockEmbeddingResponseSchema = z6.object({
|
|
|
1756
1775
|
// src/bedrock-image-model.ts
|
|
1757
1776
|
import {
|
|
1758
1777
|
combineHeaders as combineHeaders3,
|
|
1759
|
-
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
1760
1778
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1761
1779
|
postJsonToApi as postJsonToApi3,
|
|
1762
1780
|
resolve as resolve3
|
|
@@ -1831,10 +1849,7 @@ var BedrockImageModel = class {
|
|
|
1831
1849
|
combineHeaders3(await resolve3(this.config.headers), headers)
|
|
1832
1850
|
),
|
|
1833
1851
|
body: args,
|
|
1834
|
-
failedResponseHandler:
|
|
1835
|
-
errorSchema: BedrockErrorSchema,
|
|
1836
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1837
|
-
}),
|
|
1852
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1838
1853
|
successfulResponseHandler: createJsonResponseHandler3(
|
|
1839
1854
|
bedrockImageResponseSchema
|
|
1840
1855
|
),
|
|
@@ -1944,9 +1959,47 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
|
1944
1959
|
};
|
|
1945
1960
|
}
|
|
1946
1961
|
|
|
1962
|
+
// src/resolve-bedrock-base-url.ts
|
|
1963
|
+
import {
|
|
1964
|
+
loadOptionalSetting,
|
|
1965
|
+
withoutTrailingSlash
|
|
1966
|
+
} from "@ai-sdk/provider-utils";
|
|
1967
|
+
var AWS_PARTITION_DNS_SUFFIXES = [
|
|
1968
|
+
{ regionPrefix: "cn-", dnsSuffix: "amazonaws.com.cn" },
|
|
1969
|
+
{ regionPrefix: "us-iso-", dnsSuffix: "c2s.ic.gov" },
|
|
1970
|
+
{ regionPrefix: "us-isob-", dnsSuffix: "sc2s.sgov.gov" },
|
|
1971
|
+
{ regionPrefix: "eu-isoe-", dnsSuffix: "cloud.adc-e.uk" },
|
|
1972
|
+
{ regionPrefix: "us-isof-", dnsSuffix: "csp.hci.ic.gov" },
|
|
1973
|
+
{ regionPrefix: "eusc-", dnsSuffix: "amazonaws.eu" }
|
|
1974
|
+
];
|
|
1975
|
+
function resolveBedrockBaseURL({
|
|
1976
|
+
baseURL,
|
|
1977
|
+
getRegion,
|
|
1978
|
+
service,
|
|
1979
|
+
serviceEndpointUrlEnvironmentVariableName
|
|
1980
|
+
}) {
|
|
1981
|
+
var _a, _b, _c, _d, _e;
|
|
1982
|
+
const resolvedBaseURL = (_a = baseURL != null ? baseURL : loadOptionalSetting({
|
|
1983
|
+
settingValue: void 0,
|
|
1984
|
+
environmentVariableName: serviceEndpointUrlEnvironmentVariableName
|
|
1985
|
+
})) != null ? _a : loadOptionalSetting({
|
|
1986
|
+
settingValue: void 0,
|
|
1987
|
+
environmentVariableName: "AWS_ENDPOINT_URL"
|
|
1988
|
+
});
|
|
1989
|
+
if (resolvedBaseURL != null) {
|
|
1990
|
+
return (_b = withoutTrailingSlash(resolvedBaseURL)) != null ? _b : resolvedBaseURL;
|
|
1991
|
+
}
|
|
1992
|
+
const region = getRegion();
|
|
1993
|
+
const dnsSuffix = (_d = (_c = AWS_PARTITION_DNS_SUFFIXES.find(
|
|
1994
|
+
({ regionPrefix }) => region.startsWith(regionPrefix)
|
|
1995
|
+
)) == null ? void 0 : _c.dnsSuffix) != null ? _d : "amazonaws.com";
|
|
1996
|
+
const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
|
|
1997
|
+
return (_e = withoutTrailingSlash(generatedBaseURL)) != null ? _e : generatedBaseURL;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
1947
2000
|
// src/bedrock-provider.ts
|
|
1948
2001
|
function createAmazonBedrock(options = {}) {
|
|
1949
|
-
const rawApiKey =
|
|
2002
|
+
const rawApiKey = loadOptionalSetting2({
|
|
1950
2003
|
settingValue: options.apiKey,
|
|
1951
2004
|
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
1952
2005
|
});
|
|
@@ -1986,7 +2039,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1986
2039
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1987
2040
|
description: "AWS secret access key"
|
|
1988
2041
|
}),
|
|
1989
|
-
sessionToken:
|
|
2042
|
+
sessionToken: loadOptionalSetting2({
|
|
1990
2043
|
settingValue: options.sessionToken,
|
|
1991
2044
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1992
2045
|
})
|
|
@@ -2012,35 +2065,36 @@ Original error: ${errorMessage}`
|
|
|
2012
2065
|
throw error;
|
|
2013
2066
|
}
|
|
2014
2067
|
}, options.fetch);
|
|
2015
|
-
const getBaseUrl = () => {
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
};
|
|
2068
|
+
const getBaseUrl = () => resolveBedrockBaseURL({
|
|
2069
|
+
baseURL: options.baseURL,
|
|
2070
|
+
getRegion: () => loadSetting({
|
|
2071
|
+
settingValue: options.region,
|
|
2072
|
+
settingName: "region",
|
|
2073
|
+
environmentVariableName: "AWS_REGION",
|
|
2074
|
+
description: "AWS region"
|
|
2075
|
+
}),
|
|
2076
|
+
service: "bedrock-runtime",
|
|
2077
|
+
serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_RUNTIME"
|
|
2078
|
+
});
|
|
2026
2079
|
const getHeaders = () => {
|
|
2027
2080
|
var _a;
|
|
2028
2081
|
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
2029
2082
|
return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
2030
2083
|
};
|
|
2031
|
-
const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
|
|
2084
|
+
const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
|
|
2032
2085
|
baseUrl: getBaseUrl,
|
|
2033
2086
|
headers: getHeaders,
|
|
2034
2087
|
fetch: fetchFunction,
|
|
2035
|
-
generateId
|
|
2088
|
+
generateId,
|
|
2089
|
+
modelFamily: settings.modelFamily
|
|
2036
2090
|
});
|
|
2037
|
-
const provider = function(modelId) {
|
|
2091
|
+
const provider = function(modelId, settings) {
|
|
2038
2092
|
if (new.target) {
|
|
2039
2093
|
throw new Error(
|
|
2040
2094
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
2041
2095
|
);
|
|
2042
2096
|
}
|
|
2043
|
-
return createChatModel(modelId);
|
|
2097
|
+
return createChatModel(modelId, settings);
|
|
2044
2098
|
};
|
|
2045
2099
|
const createEmbeddingModel = (modelId) => new BedrockEmbeddingModel(modelId, {
|
|
2046
2100
|
baseUrl: getBaseUrl,
|