@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.js
CHANGED
|
@@ -27,17 +27,17 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/bedrock-provider.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.132" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/bedrock-provider.ts
|
|
36
36
|
var import_internal3 = require("@ai-sdk/anthropic/internal");
|
|
37
37
|
|
|
38
38
|
// src/bedrock-chat-language-model.ts
|
|
39
39
|
var import_internal2 = require("@ai-sdk/anthropic/internal");
|
|
40
|
-
var
|
|
40
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
41
41
|
var import_v44 = require("zod/v4");
|
|
42
42
|
|
|
43
43
|
// src/bedrock-api-types.ts
|
|
@@ -129,16 +129,30 @@ var bedrockProviderOptions = import_v4.z.object({
|
|
|
129
129
|
serviceTier: import_v4.z.enum(["reserved", "priority", "default", "flex"]).optional()
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
+
// src/bedrock-anthropic-model-support.ts
|
|
133
|
+
function isAnthropicModel({
|
|
134
|
+
modelId,
|
|
135
|
+
modelFamily,
|
|
136
|
+
reasoningBudgetTokens
|
|
137
|
+
}) {
|
|
138
|
+
return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
|
|
139
|
+
}
|
|
140
|
+
|
|
132
141
|
// src/bedrock-error.ts
|
|
142
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
133
143
|
var import_v42 = require("zod/v4");
|
|
134
144
|
var BedrockErrorSchema = import_v42.z.object({
|
|
135
145
|
message: import_v42.z.string(),
|
|
136
146
|
type: import_v42.z.string().nullish()
|
|
137
147
|
});
|
|
148
|
+
var bedrockFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
|
149
|
+
errorSchema: BedrockErrorSchema,
|
|
150
|
+
errorToMessage: (error) => error.type == null ? error.message : `${error.type}: ${error.message}`
|
|
151
|
+
});
|
|
138
152
|
|
|
139
153
|
// src/bedrock-event-stream-response-handler.ts
|
|
140
154
|
var import_provider = require("@ai-sdk/provider");
|
|
141
|
-
var
|
|
155
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
142
156
|
|
|
143
157
|
// src/bedrock-event-stream-decoder.ts
|
|
144
158
|
var import_eventstream_codec = require("@smithy/eventstream-codec");
|
|
@@ -190,7 +204,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
|
|
|
190
204
|
|
|
191
205
|
// src/bedrock-event-stream-response-handler.ts
|
|
192
206
|
var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
193
|
-
const responseHeaders = (0,
|
|
207
|
+
const responseHeaders = (0, import_provider_utils2.extractResponseHeaders)(response);
|
|
194
208
|
if (response.body == null) {
|
|
195
209
|
throw new import_provider.EmptyResponseBodyError({});
|
|
196
210
|
}
|
|
@@ -203,7 +217,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
203
217
|
if (payloadType == null) {
|
|
204
218
|
return;
|
|
205
219
|
}
|
|
206
|
-
const parsedDataResult = await (0,
|
|
220
|
+
const parsedDataResult = await (0, import_provider_utils2.safeParseJSON)({ text: event.data });
|
|
207
221
|
if (!parsedDataResult.success) {
|
|
208
222
|
controller.enqueue(parsedDataResult);
|
|
209
223
|
return;
|
|
@@ -212,7 +226,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
212
226
|
const wrappedData = {
|
|
213
227
|
[payloadType]: parsedDataResult.value
|
|
214
228
|
};
|
|
215
|
-
const validatedWrappedData = await (0,
|
|
229
|
+
const validatedWrappedData = await (0, import_provider_utils2.safeValidateTypes)({
|
|
216
230
|
value: wrappedData,
|
|
217
231
|
schema: chunkSchema
|
|
218
232
|
});
|
|
@@ -232,12 +246,14 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
232
246
|
|
|
233
247
|
// src/bedrock-prepare-tools.ts
|
|
234
248
|
var import_provider2 = require("@ai-sdk/provider");
|
|
235
|
-
var
|
|
249
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
236
250
|
var import_internal = require("@ai-sdk/anthropic/internal");
|
|
237
251
|
async function prepareTools({
|
|
238
252
|
tools,
|
|
239
253
|
toolChoice,
|
|
240
254
|
modelId,
|
|
255
|
+
modelFamily,
|
|
256
|
+
reasoningBudgetTokens,
|
|
241
257
|
disableParallelToolUse
|
|
242
258
|
}) {
|
|
243
259
|
var _a;
|
|
@@ -270,14 +286,18 @@ async function prepareTools({
|
|
|
270
286
|
toolWarnings
|
|
271
287
|
};
|
|
272
288
|
}
|
|
273
|
-
const isAnthropicModel = modelId.includes("anthropic.");
|
|
274
289
|
const providerDefinedTools = supportedTools.filter(
|
|
275
290
|
(t) => t.type === "provider-defined"
|
|
276
291
|
);
|
|
292
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
293
|
+
modelId,
|
|
294
|
+
modelFamily,
|
|
295
|
+
reasoningBudgetTokens
|
|
296
|
+
});
|
|
277
297
|
const functionTools = supportedTools.filter((t) => t.type === "function");
|
|
278
298
|
let additionalTools = void 0;
|
|
279
299
|
const bedrockTools = [];
|
|
280
|
-
const usingAnthropicTools =
|
|
300
|
+
const usingAnthropicTools = isAnthropicModel2 && providerDefinedTools.length > 0;
|
|
281
301
|
if (usingAnthropicTools) {
|
|
282
302
|
if (functionTools.length > 0) {
|
|
283
303
|
toolWarnings.push({
|
|
@@ -313,7 +333,7 @@ async function prepareTools({
|
|
|
313
333
|
toolSpec: {
|
|
314
334
|
name: tool.name,
|
|
315
335
|
inputSchema: {
|
|
316
|
-
json: (0,
|
|
336
|
+
json: (0, import_provider_utils3.asSchema)(fullToolDefinition.inputSchema).jsonSchema
|
|
317
337
|
}
|
|
318
338
|
}
|
|
319
339
|
});
|
|
@@ -337,7 +357,7 @@ async function prepareTools({
|
|
|
337
357
|
}
|
|
338
358
|
});
|
|
339
359
|
}
|
|
340
|
-
if (
|
|
360
|
+
if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
|
|
341
361
|
additionalTools = {
|
|
342
362
|
tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
|
|
343
363
|
type: "tool",
|
|
@@ -382,7 +402,7 @@ async function prepareTools({
|
|
|
382
402
|
|
|
383
403
|
// src/convert-to-bedrock-chat-messages.ts
|
|
384
404
|
var import_provider3 = require("@ai-sdk/provider");
|
|
385
|
-
var
|
|
405
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
386
406
|
|
|
387
407
|
// src/bedrock-reasoning-metadata.ts
|
|
388
408
|
var import_v43 = require("zod/v4");
|
|
@@ -399,7 +419,7 @@ function getCachePoint(providerMetadata) {
|
|
|
399
419
|
}
|
|
400
420
|
async function shouldEnableCitations(providerMetadata) {
|
|
401
421
|
var _a, _b;
|
|
402
|
-
const bedrockOptions = await (0,
|
|
422
|
+
const bedrockOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
403
423
|
provider: "bedrock",
|
|
404
424
|
providerOptions: providerMetadata,
|
|
405
425
|
schema: bedrockFilePartProviderOptions
|
|
@@ -473,7 +493,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
473
493
|
bedrockContent.push({
|
|
474
494
|
image: {
|
|
475
495
|
format: getBedrockImageFormat(part.mediaType),
|
|
476
|
-
source: { bytes: (0,
|
|
496
|
+
source: { bytes: (0, import_provider_utils4.convertToBase64)(part.data) }
|
|
477
497
|
}
|
|
478
498
|
});
|
|
479
499
|
} else {
|
|
@@ -490,7 +510,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
490
510
|
document: {
|
|
491
511
|
format: getBedrockDocumentFormat(part.mediaType),
|
|
492
512
|
name: (_a = part.filename) != null ? _a : generateDocumentName(),
|
|
493
|
-
source: { bytes: (0,
|
|
513
|
+
source: { bytes: (0, import_provider_utils4.convertToBase64)(part.data) },
|
|
494
514
|
...enableCitations && {
|
|
495
515
|
citations: { enabled: true }
|
|
496
516
|
}
|
|
@@ -600,7 +620,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
600
620
|
break;
|
|
601
621
|
}
|
|
602
622
|
case "reasoning": {
|
|
603
|
-
const reasoningMetadata = await (0,
|
|
623
|
+
const reasoningMetadata = await (0, import_provider_utils4.parseProviderOptions)({
|
|
604
624
|
provider: "bedrock",
|
|
605
625
|
providerOptions: part.providerOptions,
|
|
606
626
|
schema: bedrockReasoningMetadataSchema
|
|
@@ -797,13 +817,13 @@ var BedrockChatLanguageModel = class {
|
|
|
797
817
|
toolChoice,
|
|
798
818
|
providerOptions
|
|
799
819
|
}) {
|
|
800
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
801
|
-
const bedrockOptions = (_a = await (0,
|
|
820
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
821
|
+
const bedrockOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
|
|
802
822
|
provider: "bedrock",
|
|
803
823
|
providerOptions,
|
|
804
824
|
schema: bedrockProviderOptions
|
|
805
825
|
})) != null ? _a : {};
|
|
806
|
-
const anthropicOptions = await (0,
|
|
826
|
+
const anthropicOptions = await (0, import_provider_utils5.parseProviderOptions)({
|
|
807
827
|
provider: "anthropic",
|
|
808
828
|
providerOptions,
|
|
809
829
|
schema: anthropicProviderOptions
|
|
@@ -849,12 +869,16 @@ var BedrockChatLanguageModel = class {
|
|
|
849
869
|
details: "Only text and json response formats are supported."
|
|
850
870
|
});
|
|
851
871
|
}
|
|
852
|
-
const
|
|
853
|
-
|
|
872
|
+
const isAnthropicModel2 = isAnthropicModel({
|
|
873
|
+
modelId: this.modelId,
|
|
874
|
+
modelFamily: this.config.modelFamily,
|
|
875
|
+
reasoningBudgetTokens: (_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens
|
|
876
|
+
});
|
|
877
|
+
const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
|
|
854
878
|
const isOpenAIModel = openAIModelId != null;
|
|
855
|
-
const isOpenAIGptOssModel = (
|
|
856
|
-
const isThinkingRequested = ((
|
|
857
|
-
const structuredOutputMode = (
|
|
879
|
+
const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
|
|
880
|
+
const isThinkingRequested = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
|
|
881
|
+
const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
|
|
858
882
|
if (structuredOutputMode === "jsonTool") {
|
|
859
883
|
const additionalModelRequestFields = {
|
|
860
884
|
...bedrockOptions.additionalModelRequestFields
|
|
@@ -871,7 +895,8 @@ var BedrockChatLanguageModel = class {
|
|
|
871
895
|
bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
|
|
872
896
|
}
|
|
873
897
|
}
|
|
874
|
-
const
|
|
898
|
+
const modelSupportsNativeStructuredOutput = this.config.modelFamily === "anthropic" || supportsNativeStructuredOutput(this.modelId) && isThinkingRequested;
|
|
899
|
+
const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
|
|
875
900
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput ? {
|
|
876
901
|
type: "function",
|
|
877
902
|
name: "json",
|
|
@@ -882,6 +907,8 @@ var BedrockChatLanguageModel = class {
|
|
|
882
907
|
tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
|
|
883
908
|
toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
|
|
884
909
|
modelId: this.modelId,
|
|
910
|
+
modelFamily: this.config.modelFamily,
|
|
911
|
+
reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
|
|
885
912
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
886
913
|
});
|
|
887
914
|
warnings.push(...toolWarnings);
|
|
@@ -892,17 +919,17 @@ var BedrockChatLanguageModel = class {
|
|
|
892
919
|
};
|
|
893
920
|
}
|
|
894
921
|
if (betas.size > 0 || bedrockOptions.anthropicBeta) {
|
|
895
|
-
const existingBetas = (
|
|
922
|
+
const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
|
|
896
923
|
const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
|
|
897
924
|
bedrockOptions.additionalModelRequestFields = {
|
|
898
925
|
...bedrockOptions.additionalModelRequestFields,
|
|
899
926
|
anthropic_beta: mergedBetas
|
|
900
927
|
};
|
|
901
928
|
}
|
|
902
|
-
const thinkingType = (
|
|
903
|
-
const thinkingBudget = thinkingType === "enabled" ? (
|
|
904
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
905
|
-
const isAnthropicThinkingEnabled =
|
|
929
|
+
const thinkingType = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.type;
|
|
930
|
+
const thinkingBudget = thinkingType === "enabled" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens : void 0;
|
|
931
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.display : void 0;
|
|
932
|
+
const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingRequested;
|
|
906
933
|
const inferenceConfig = {
|
|
907
934
|
...maxOutputTokens != null && { maxTokens: maxOutputTokens },
|
|
908
935
|
...temperature != null && { temperature },
|
|
@@ -933,8 +960,8 @@ var BedrockChatLanguageModel = class {
|
|
|
933
960
|
}
|
|
934
961
|
};
|
|
935
962
|
}
|
|
936
|
-
} else if (!
|
|
937
|
-
if (((
|
|
963
|
+
} else if (!isAnthropicModel2) {
|
|
964
|
+
if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
|
|
938
965
|
warnings.push({
|
|
939
966
|
type: "unsupported-setting",
|
|
940
967
|
setting: "budgetTokens",
|
|
@@ -949,13 +976,13 @@ var BedrockChatLanguageModel = class {
|
|
|
949
976
|
});
|
|
950
977
|
}
|
|
951
978
|
}
|
|
952
|
-
const maxReasoningEffort = (
|
|
979
|
+
const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
|
|
953
980
|
if (maxReasoningEffort != null) {
|
|
954
|
-
if (
|
|
981
|
+
if (isAnthropicModel2) {
|
|
955
982
|
bedrockOptions.additionalModelRequestFields = {
|
|
956
983
|
...bedrockOptions.additionalModelRequestFields,
|
|
957
984
|
output_config: {
|
|
958
|
-
...(
|
|
985
|
+
...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
|
|
959
986
|
effort: maxReasoningEffort
|
|
960
987
|
}
|
|
961
988
|
};
|
|
@@ -966,7 +993,7 @@ var BedrockChatLanguageModel = class {
|
|
|
966
993
|
} : {
|
|
967
994
|
...bedrockOptions.additionalModelRequestFields,
|
|
968
995
|
reasoning: {
|
|
969
|
-
...(
|
|
996
|
+
...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
|
|
970
997
|
effort: maxReasoningEffort
|
|
971
998
|
}
|
|
972
999
|
};
|
|
@@ -974,7 +1001,7 @@ var BedrockChatLanguageModel = class {
|
|
|
974
1001
|
bedrockOptions.additionalModelRequestFields = {
|
|
975
1002
|
...bedrockOptions.additionalModelRequestFields,
|
|
976
1003
|
reasoningConfig: {
|
|
977
|
-
...((
|
|
1004
|
+
...((_r = bedrockOptions.reasoningConfig) == null ? void 0 : _r.type) != null && {
|
|
978
1005
|
type: bedrockOptions.reasoningConfig.type
|
|
979
1006
|
},
|
|
980
1007
|
maxReasoningEffort
|
|
@@ -986,7 +1013,7 @@ var BedrockChatLanguageModel = class {
|
|
|
986
1013
|
bedrockOptions.additionalModelRequestFields = {
|
|
987
1014
|
...bedrockOptions.additionalModelRequestFields,
|
|
988
1015
|
output_config: {
|
|
989
|
-
...(
|
|
1016
|
+
...(_s = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _s.output_config,
|
|
990
1017
|
format: {
|
|
991
1018
|
type: "json_schema",
|
|
992
1019
|
schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
|
|
@@ -1018,7 +1045,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1018
1045
|
details: "topK is not supported when thinking is enabled"
|
|
1019
1046
|
});
|
|
1020
1047
|
}
|
|
1021
|
-
const hasAnyTools = ((
|
|
1048
|
+
const hasAnyTools = ((_u = (_t = toolConfig.tools) == null ? void 0 : _t.length) != null ? _u : 0) > 0 || additionalTools;
|
|
1022
1049
|
let filteredPrompt = prompt;
|
|
1023
1050
|
if (!hasAnyTools) {
|
|
1024
1051
|
const hasToolContent = prompt.some(
|
|
@@ -1052,7 +1079,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1052
1079
|
structuredOutputMode: ____,
|
|
1053
1080
|
...filteredBedrockOptions
|
|
1054
1081
|
} = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
1055
|
-
const additionalModelResponseFieldPaths =
|
|
1082
|
+
const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
|
|
1056
1083
|
return {
|
|
1057
1084
|
command: {
|
|
1058
1085
|
system,
|
|
@@ -1080,7 +1107,7 @@ var BedrockChatLanguageModel = class {
|
|
|
1080
1107
|
async getHeaders({
|
|
1081
1108
|
headers
|
|
1082
1109
|
}) {
|
|
1083
|
-
return (0,
|
|
1110
|
+
return (0, import_provider_utils5.combineHeaders)(await (0, import_provider_utils5.resolve)(this.config.headers), headers);
|
|
1084
1111
|
}
|
|
1085
1112
|
async doGenerate(options) {
|
|
1086
1113
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
@@ -1090,18 +1117,18 @@ var BedrockChatLanguageModel = class {
|
|
|
1090
1117
|
usesJsonResponseTool
|
|
1091
1118
|
} = await this.getArgs(options);
|
|
1092
1119
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
1093
|
-
const { value: response, responseHeaders } = await (0,
|
|
1120
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
|
|
1094
1121
|
url,
|
|
1095
1122
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1096
1123
|
body: args,
|
|
1097
|
-
failedResponseHandler: (0,
|
|
1124
|
+
failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
|
|
1098
1125
|
errorSchema: BedrockErrorSchema,
|
|
1099
1126
|
errorToMessage: (error) => {
|
|
1100
1127
|
var _a2;
|
|
1101
1128
|
return `${(_a2 = error.message) != null ? _a2 : "Unknown error"}`;
|
|
1102
1129
|
}
|
|
1103
1130
|
}),
|
|
1104
|
-
successfulResponseHandler: (0,
|
|
1131
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
1105
1132
|
BedrockResponseSchema
|
|
1106
1133
|
),
|
|
1107
1134
|
abortSignal: options.abortSignal,
|
|
@@ -1213,14 +1240,11 @@ var BedrockChatLanguageModel = class {
|
|
|
1213
1240
|
usesJsonResponseTool
|
|
1214
1241
|
} = await this.getArgs(options);
|
|
1215
1242
|
const url = `${this.getUrl(this.modelId)}/converse-stream`;
|
|
1216
|
-
const { value: response, responseHeaders } = await (0,
|
|
1243
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
|
|
1217
1244
|
url,
|
|
1218
1245
|
headers: await this.getHeaders({ headers: options.headers }),
|
|
1219
1246
|
body: args,
|
|
1220
|
-
failedResponseHandler:
|
|
1221
|
-
errorSchema: BedrockErrorSchema,
|
|
1222
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1223
|
-
}),
|
|
1247
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1224
1248
|
successfulResponseHandler: createBedrockEventStreamResponseHandler(BedrockStreamSchema),
|
|
1225
1249
|
abortSignal: options.abortSignal,
|
|
1226
1250
|
fetch: this.config.fetch
|
|
@@ -1663,7 +1687,7 @@ var BedrockStreamSchema = import_v44.z.object({
|
|
|
1663
1687
|
|
|
1664
1688
|
// src/bedrock-embedding-model.ts
|
|
1665
1689
|
var import_provider4 = require("@ai-sdk/provider");
|
|
1666
|
-
var
|
|
1690
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1667
1691
|
|
|
1668
1692
|
// src/bedrock-embedding-options.ts
|
|
1669
1693
|
var import_v45 = require("zod/v4");
|
|
@@ -1710,7 +1734,7 @@ var BedrockEmbeddingModel = class {
|
|
|
1710
1734
|
values
|
|
1711
1735
|
});
|
|
1712
1736
|
}
|
|
1713
|
-
const bedrockOptions = (_a = await (0,
|
|
1737
|
+
const bedrockOptions = (_a = await (0, import_provider_utils6.parseProviderOptions)({
|
|
1714
1738
|
provider: "bedrock",
|
|
1715
1739
|
providerOptions,
|
|
1716
1740
|
schema: bedrockEmbeddingProviderOptions
|
|
@@ -1721,17 +1745,14 @@ var BedrockEmbeddingModel = class {
|
|
|
1721
1745
|
normalize: bedrockOptions.normalize
|
|
1722
1746
|
};
|
|
1723
1747
|
const url = this.getUrl(this.modelId);
|
|
1724
|
-
const { value: response } = await (0,
|
|
1748
|
+
const { value: response } = await (0, import_provider_utils6.postJsonToApi)({
|
|
1725
1749
|
url,
|
|
1726
|
-
headers: await (0,
|
|
1727
|
-
(0,
|
|
1750
|
+
headers: await (0, import_provider_utils6.resolve)(
|
|
1751
|
+
(0, import_provider_utils6.combineHeaders)(await (0, import_provider_utils6.resolve)(this.config.headers), headers)
|
|
1728
1752
|
),
|
|
1729
1753
|
body: args,
|
|
1730
|
-
failedResponseHandler:
|
|
1731
|
-
|
|
1732
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1733
|
-
}),
|
|
1734
|
-
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
1754
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1755
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
1735
1756
|
BedrockEmbeddingResponseSchema
|
|
1736
1757
|
),
|
|
1737
1758
|
fetch: this.config.fetch,
|
|
@@ -1749,7 +1770,7 @@ var BedrockEmbeddingResponseSchema = import_v46.z.object({
|
|
|
1749
1770
|
});
|
|
1750
1771
|
|
|
1751
1772
|
// src/bedrock-image-model.ts
|
|
1752
|
-
var
|
|
1773
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1753
1774
|
|
|
1754
1775
|
// src/bedrock-image-settings.ts
|
|
1755
1776
|
var modelMaxImagesPerCall = {
|
|
@@ -1814,17 +1835,14 @@ var BedrockImageModel = class {
|
|
|
1814
1835
|
});
|
|
1815
1836
|
}
|
|
1816
1837
|
const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
|
|
1817
|
-
const { value: response, responseHeaders } = await (0,
|
|
1838
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils7.postJsonToApi)({
|
|
1818
1839
|
url: this.getUrl(this.modelId),
|
|
1819
|
-
headers: await (0,
|
|
1820
|
-
(0,
|
|
1840
|
+
headers: await (0, import_provider_utils7.resolve)(
|
|
1841
|
+
(0, import_provider_utils7.combineHeaders)(await (0, import_provider_utils7.resolve)(this.config.headers), headers)
|
|
1821
1842
|
),
|
|
1822
1843
|
body: args,
|
|
1823
|
-
failedResponseHandler:
|
|
1824
|
-
|
|
1825
|
-
errorToMessage: (error) => `${error.type}: ${error.message}`
|
|
1826
|
-
}),
|
|
1827
|
-
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
1844
|
+
failedResponseHandler: bedrockFailedResponseHandler,
|
|
1845
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
|
1828
1846
|
bedrockImageResponseSchema
|
|
1829
1847
|
),
|
|
1830
1848
|
abortSignal,
|
|
@@ -1846,20 +1864,20 @@ var bedrockImageResponseSchema = import_v47.z.object({
|
|
|
1846
1864
|
});
|
|
1847
1865
|
|
|
1848
1866
|
// src/bedrock-sigv4-fetch.ts
|
|
1849
|
-
var
|
|
1867
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1850
1868
|
var import_aws4fetch = require("aws4fetch");
|
|
1851
1869
|
function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
1852
1870
|
return async (input, init) => {
|
|
1853
1871
|
var _a, _b;
|
|
1854
1872
|
const request = input instanceof Request ? input : void 0;
|
|
1855
|
-
const originalHeaders = (0,
|
|
1856
|
-
(0,
|
|
1857
|
-
(0,
|
|
1873
|
+
const originalHeaders = (0, import_provider_utils8.combineHeaders)(
|
|
1874
|
+
(0, import_provider_utils8.normalizeHeaders)(request == null ? void 0 : request.headers),
|
|
1875
|
+
(0, import_provider_utils8.normalizeHeaders)(init == null ? void 0 : init.headers)
|
|
1858
1876
|
);
|
|
1859
|
-
const headersWithUserAgent = (0,
|
|
1877
|
+
const headersWithUserAgent = (0, import_provider_utils8.withUserAgentSuffix)(
|
|
1860
1878
|
originalHeaders,
|
|
1861
1879
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1862
|
-
(0,
|
|
1880
|
+
(0, import_provider_utils8.getRuntimeEnvironmentUserAgent)()
|
|
1863
1881
|
);
|
|
1864
1882
|
let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
|
|
1865
1883
|
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
@@ -1890,8 +1908,8 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
|
|
|
1890
1908
|
service: "bedrock"
|
|
1891
1909
|
});
|
|
1892
1910
|
const signingResult = await signer.sign();
|
|
1893
|
-
const signedHeaders = (0,
|
|
1894
|
-
const combinedHeaders = (0,
|
|
1911
|
+
const signedHeaders = (0, import_provider_utils8.normalizeHeaders)(signingResult.headers);
|
|
1912
|
+
const combinedHeaders = (0, import_provider_utils8.combineHeaders)(headersWithUserAgent, signedHeaders);
|
|
1895
1913
|
return fetch(input, {
|
|
1896
1914
|
...init,
|
|
1897
1915
|
body,
|
|
@@ -1912,13 +1930,13 @@ function prepareBodyString(body) {
|
|
|
1912
1930
|
}
|
|
1913
1931
|
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
1914
1932
|
return async (input, init) => {
|
|
1915
|
-
const originalHeaders = (0,
|
|
1916
|
-
const headersWithUserAgent = (0,
|
|
1933
|
+
const originalHeaders = (0, import_provider_utils8.normalizeHeaders)(init == null ? void 0 : init.headers);
|
|
1934
|
+
const headersWithUserAgent = (0, import_provider_utils8.withUserAgentSuffix)(
|
|
1917
1935
|
originalHeaders,
|
|
1918
1936
|
`ai-sdk/amazon-bedrock/${VERSION}`,
|
|
1919
|
-
(0,
|
|
1937
|
+
(0, import_provider_utils8.getRuntimeEnvironmentUserAgent)()
|
|
1920
1938
|
);
|
|
1921
|
-
const finalHeaders = (0,
|
|
1939
|
+
const finalHeaders = (0, import_provider_utils8.combineHeaders)(headersWithUserAgent, {
|
|
1922
1940
|
Authorization: `Bearer ${apiKey}`
|
|
1923
1941
|
});
|
|
1924
1942
|
return fetch(input, {
|
|
@@ -1928,15 +1946,50 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
|
1928
1946
|
};
|
|
1929
1947
|
}
|
|
1930
1948
|
|
|
1949
|
+
// src/resolve-bedrock-base-url.ts
|
|
1950
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1951
|
+
var AWS_PARTITION_DNS_SUFFIXES = [
|
|
1952
|
+
{ regionPrefix: "cn-", dnsSuffix: "amazonaws.com.cn" },
|
|
1953
|
+
{ regionPrefix: "us-iso-", dnsSuffix: "c2s.ic.gov" },
|
|
1954
|
+
{ regionPrefix: "us-isob-", dnsSuffix: "sc2s.sgov.gov" },
|
|
1955
|
+
{ regionPrefix: "eu-isoe-", dnsSuffix: "cloud.adc-e.uk" },
|
|
1956
|
+
{ regionPrefix: "us-isof-", dnsSuffix: "csp.hci.ic.gov" },
|
|
1957
|
+
{ regionPrefix: "eusc-", dnsSuffix: "amazonaws.eu" }
|
|
1958
|
+
];
|
|
1959
|
+
function resolveBedrockBaseURL({
|
|
1960
|
+
baseURL,
|
|
1961
|
+
getRegion,
|
|
1962
|
+
service,
|
|
1963
|
+
serviceEndpointUrlEnvironmentVariableName
|
|
1964
|
+
}) {
|
|
1965
|
+
var _a, _b, _c, _d, _e;
|
|
1966
|
+
const resolvedBaseURL = (_a = baseURL != null ? baseURL : (0, import_provider_utils9.loadOptionalSetting)({
|
|
1967
|
+
settingValue: void 0,
|
|
1968
|
+
environmentVariableName: serviceEndpointUrlEnvironmentVariableName
|
|
1969
|
+
})) != null ? _a : (0, import_provider_utils9.loadOptionalSetting)({
|
|
1970
|
+
settingValue: void 0,
|
|
1971
|
+
environmentVariableName: "AWS_ENDPOINT_URL"
|
|
1972
|
+
});
|
|
1973
|
+
if (resolvedBaseURL != null) {
|
|
1974
|
+
return (_b = (0, import_provider_utils9.withoutTrailingSlash)(resolvedBaseURL)) != null ? _b : resolvedBaseURL;
|
|
1975
|
+
}
|
|
1976
|
+
const region = getRegion();
|
|
1977
|
+
const dnsSuffix = (_d = (_c = AWS_PARTITION_DNS_SUFFIXES.find(
|
|
1978
|
+
({ regionPrefix }) => region.startsWith(regionPrefix)
|
|
1979
|
+
)) == null ? void 0 : _c.dnsSuffix) != null ? _d : "amazonaws.com";
|
|
1980
|
+
const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
|
|
1981
|
+
return (_e = (0, import_provider_utils9.withoutTrailingSlash)(generatedBaseURL)) != null ? _e : generatedBaseURL;
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1931
1984
|
// src/bedrock-provider.ts
|
|
1932
1985
|
function createAmazonBedrock(options = {}) {
|
|
1933
|
-
const rawApiKey = (0,
|
|
1986
|
+
const rawApiKey = (0, import_provider_utils10.loadOptionalSetting)({
|
|
1934
1987
|
settingValue: options.apiKey,
|
|
1935
1988
|
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
1936
1989
|
});
|
|
1937
1990
|
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
1938
1991
|
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
1939
|
-
const region = (0,
|
|
1992
|
+
const region = (0, import_provider_utils10.loadSetting)({
|
|
1940
1993
|
settingValue: options.region,
|
|
1941
1994
|
settingName: "region",
|
|
1942
1995
|
environmentVariableName: "AWS_REGION",
|
|
@@ -1958,19 +2011,19 @@ function createAmazonBedrock(options = {}) {
|
|
|
1958
2011
|
try {
|
|
1959
2012
|
return {
|
|
1960
2013
|
region,
|
|
1961
|
-
accessKeyId: (0,
|
|
2014
|
+
accessKeyId: (0, import_provider_utils10.loadSetting)({
|
|
1962
2015
|
settingValue: options.accessKeyId,
|
|
1963
2016
|
settingName: "accessKeyId",
|
|
1964
2017
|
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
1965
2018
|
description: "AWS access key ID"
|
|
1966
2019
|
}),
|
|
1967
|
-
secretAccessKey: (0,
|
|
2020
|
+
secretAccessKey: (0, import_provider_utils10.loadSetting)({
|
|
1968
2021
|
settingValue: options.secretAccessKey,
|
|
1969
2022
|
settingName: "secretAccessKey",
|
|
1970
2023
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1971
2024
|
description: "AWS secret access key"
|
|
1972
2025
|
}),
|
|
1973
|
-
sessionToken: (0,
|
|
2026
|
+
sessionToken: (0, import_provider_utils10.loadOptionalSetting)({
|
|
1974
2027
|
settingValue: options.sessionToken,
|
|
1975
2028
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1976
2029
|
})
|
|
@@ -1996,35 +2049,36 @@ Original error: ${errorMessage}`
|
|
|
1996
2049
|
throw error;
|
|
1997
2050
|
}
|
|
1998
2051
|
}, options.fetch);
|
|
1999
|
-
const getBaseUrl = () => {
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
};
|
|
2052
|
+
const getBaseUrl = () => resolveBedrockBaseURL({
|
|
2053
|
+
baseURL: options.baseURL,
|
|
2054
|
+
getRegion: () => (0, import_provider_utils10.loadSetting)({
|
|
2055
|
+
settingValue: options.region,
|
|
2056
|
+
settingName: "region",
|
|
2057
|
+
environmentVariableName: "AWS_REGION",
|
|
2058
|
+
description: "AWS region"
|
|
2059
|
+
}),
|
|
2060
|
+
service: "bedrock-runtime",
|
|
2061
|
+
serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_RUNTIME"
|
|
2062
|
+
});
|
|
2010
2063
|
const getHeaders = () => {
|
|
2011
2064
|
var _a;
|
|
2012
2065
|
const baseHeaders = (_a = options.headers) != null ? _a : {};
|
|
2013
|
-
return (0,
|
|
2066
|
+
return (0, import_provider_utils10.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
|
|
2014
2067
|
};
|
|
2015
|
-
const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
|
|
2068
|
+
const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
|
|
2016
2069
|
baseUrl: getBaseUrl,
|
|
2017
2070
|
headers: getHeaders,
|
|
2018
2071
|
fetch: fetchFunction,
|
|
2019
|
-
generateId:
|
|
2072
|
+
generateId: import_provider_utils10.generateId,
|
|
2073
|
+
modelFamily: settings.modelFamily
|
|
2020
2074
|
});
|
|
2021
|
-
const provider = function(modelId) {
|
|
2075
|
+
const provider = function(modelId, settings) {
|
|
2022
2076
|
if (new.target) {
|
|
2023
2077
|
throw new Error(
|
|
2024
2078
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
2025
2079
|
);
|
|
2026
2080
|
}
|
|
2027
|
-
return createChatModel(modelId);
|
|
2081
|
+
return createChatModel(modelId, settings);
|
|
2028
2082
|
};
|
|
2029
2083
|
const createEmbeddingModel = (modelId) => new BedrockEmbeddingModel(modelId, {
|
|
2030
2084
|
baseUrl: getBaseUrl,
|