@ai-sdk/amazon-bedrock 3.0.0-alpha.9 → 3.0.0-beta.10
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 +142 -0
- package/README.md +75 -0
- package/dist/index.d.mts +28 -27
- package/dist/index.d.ts +28 -27
- package/dist/index.js +379 -204
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +305 -134
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
|
30
30
|
|
|
31
31
|
// src/bedrock-chat-language-model.ts
|
|
32
32
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
33
|
-
var
|
|
33
|
+
var import_v43 = require("zod/v4");
|
|
34
34
|
|
|
35
35
|
// src/bedrock-api-types.ts
|
|
36
36
|
var BEDROCK_CACHE_POINT = {
|
|
@@ -48,27 +48,44 @@ var BEDROCK_STOP_REASONS = [
|
|
|
48
48
|
"tool-calls",
|
|
49
49
|
"tool_use"
|
|
50
50
|
];
|
|
51
|
+
var BEDROCK_IMAGE_MIME_TYPES = {
|
|
52
|
+
"image/jpeg": "jpeg",
|
|
53
|
+
"image/png": "png",
|
|
54
|
+
"image/gif": "gif",
|
|
55
|
+
"image/webp": "webp"
|
|
56
|
+
};
|
|
57
|
+
var BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
58
|
+
"application/pdf": "pdf",
|
|
59
|
+
"text/csv": "csv",
|
|
60
|
+
"application/msword": "doc",
|
|
61
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
62
|
+
"application/vnd.ms-excel": "xls",
|
|
63
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
64
|
+
"text/html": "html",
|
|
65
|
+
"text/plain": "txt",
|
|
66
|
+
"text/markdown": "md"
|
|
67
|
+
};
|
|
51
68
|
|
|
52
69
|
// src/bedrock-chat-options.ts
|
|
53
|
-
var
|
|
54
|
-
var bedrockProviderOptions =
|
|
70
|
+
var import_v4 = require("zod/v4");
|
|
71
|
+
var bedrockProviderOptions = import_v4.z.object({
|
|
55
72
|
/**
|
|
56
73
|
* Additional inference parameters that the model supports,
|
|
57
74
|
* beyond the base set of inference parameters that Converse
|
|
58
75
|
* supports in the inferenceConfig field
|
|
59
76
|
*/
|
|
60
|
-
additionalModelRequestFields:
|
|
61
|
-
reasoningConfig:
|
|
62
|
-
type:
|
|
63
|
-
budgetTokens:
|
|
77
|
+
additionalModelRequestFields: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
|
|
78
|
+
reasoningConfig: import_v4.z.object({
|
|
79
|
+
type: import_v4.z.union([import_v4.z.literal("enabled"), import_v4.z.literal("disabled")]).optional(),
|
|
80
|
+
budgetTokens: import_v4.z.number().optional()
|
|
64
81
|
}).optional()
|
|
65
82
|
});
|
|
66
83
|
|
|
67
84
|
// src/bedrock-error.ts
|
|
68
|
-
var
|
|
69
|
-
var BedrockErrorSchema =
|
|
70
|
-
message:
|
|
71
|
-
type:
|
|
85
|
+
var import_v42 = require("zod/v4");
|
|
86
|
+
var BedrockErrorSchema = import_v42.z.object({
|
|
87
|
+
message: import_v42.z.string(),
|
|
88
|
+
type: import_v42.z.string().nullish()
|
|
72
89
|
});
|
|
73
90
|
|
|
74
91
|
// src/bedrock-event-stream-response-handler.ts
|
|
@@ -144,14 +161,29 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
144
161
|
|
|
145
162
|
// src/bedrock-prepare-tools.ts
|
|
146
163
|
var import_provider2 = require("@ai-sdk/provider");
|
|
164
|
+
function promptContainsToolContent(prompt) {
|
|
165
|
+
return prompt.some((message) => {
|
|
166
|
+
if ("content" in message && Array.isArray(message.content)) {
|
|
167
|
+
return message.content.some(
|
|
168
|
+
(part) => part.type === "tool-call" || part.type === "tool-result"
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
147
174
|
function prepareTools({
|
|
148
175
|
tools,
|
|
149
|
-
toolChoice
|
|
176
|
+
toolChoice,
|
|
177
|
+
prompt
|
|
150
178
|
}) {
|
|
151
179
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
180
|
+
const hasToolContent = promptContainsToolContent(prompt);
|
|
152
181
|
if (tools == null) {
|
|
153
182
|
return {
|
|
154
|
-
toolConfig: {
|
|
183
|
+
toolConfig: {
|
|
184
|
+
tools: hasToolContent ? [] : void 0,
|
|
185
|
+
toolChoice: void 0
|
|
186
|
+
},
|
|
155
187
|
toolWarnings: []
|
|
156
188
|
};
|
|
157
189
|
}
|
|
@@ -166,7 +198,7 @@ function prepareTools({
|
|
|
166
198
|
name: tool.name,
|
|
167
199
|
description: tool.description,
|
|
168
200
|
inputSchema: {
|
|
169
|
-
json: tool.
|
|
201
|
+
json: tool.inputSchema
|
|
170
202
|
}
|
|
171
203
|
}
|
|
172
204
|
});
|
|
@@ -192,7 +224,10 @@ function prepareTools({
|
|
|
192
224
|
};
|
|
193
225
|
case "none":
|
|
194
226
|
return {
|
|
195
|
-
toolConfig: {
|
|
227
|
+
toolConfig: {
|
|
228
|
+
tools: hasToolContent ? [] : void 0,
|
|
229
|
+
toolChoice: void 0
|
|
230
|
+
},
|
|
196
231
|
toolWarnings
|
|
197
232
|
};
|
|
198
233
|
case "tool":
|
|
@@ -215,16 +250,16 @@ function prepareTools({
|
|
|
215
250
|
// src/convert-to-bedrock-chat-messages.ts
|
|
216
251
|
var import_provider3 = require("@ai-sdk/provider");
|
|
217
252
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
218
|
-
var generateFileId = (0, import_provider_utils2.createIdGenerator)({ prefix: "file", size: 16 });
|
|
219
253
|
function getCachePoint(providerMetadata) {
|
|
220
254
|
var _a;
|
|
221
255
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
222
256
|
}
|
|
223
257
|
async function convertToBedrockChatMessages(prompt) {
|
|
224
|
-
var _a, _b, _c, _d;
|
|
225
258
|
const blocks = groupIntoBlocks(prompt);
|
|
226
259
|
let system = [];
|
|
227
260
|
const messages = [];
|
|
261
|
+
let documentCounter = 0;
|
|
262
|
+
const generateDocumentName = () => `document-${++documentCounter}`;
|
|
228
263
|
for (let i = 0; i < blocks.length; i++) {
|
|
229
264
|
const block = blocks[i];
|
|
230
265
|
const isLastBlock = i === blocks.length - 1;
|
|
@@ -266,20 +301,23 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
266
301
|
});
|
|
267
302
|
}
|
|
268
303
|
if (part.mediaType.startsWith("image/")) {
|
|
269
|
-
const bedrockImageFormat = part.mediaType === "image/*" ? void 0 : (_b = (_a = part.mediaType) == null ? void 0 : _a.split("/")) == null ? void 0 : _b[1];
|
|
270
304
|
bedrockContent.push({
|
|
271
305
|
image: {
|
|
272
|
-
format:
|
|
306
|
+
format: getBedrockImageFormat(part.mediaType),
|
|
273
307
|
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
274
308
|
}
|
|
275
309
|
});
|
|
276
310
|
} else {
|
|
311
|
+
if (!part.mediaType) {
|
|
312
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
313
|
+
functionality: "file without mime type",
|
|
314
|
+
message: "File mime type is required in user message part content"
|
|
315
|
+
});
|
|
316
|
+
}
|
|
277
317
|
bedrockContent.push({
|
|
278
318
|
document: {
|
|
279
|
-
format: (
|
|
280
|
-
|
|
281
|
-
)) == null ? void 0 : _d[1],
|
|
282
|
-
name: generateFileId(),
|
|
319
|
+
format: getBedrockDocumentFormat(part.mediaType),
|
|
320
|
+
name: generateDocumentName(),
|
|
283
321
|
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
284
322
|
}
|
|
285
323
|
});
|
|
@@ -291,36 +329,46 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
291
329
|
break;
|
|
292
330
|
}
|
|
293
331
|
case "tool": {
|
|
294
|
-
for (
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const format = part2.mediaType.split("/")[1];
|
|
309
|
-
if (!isBedrockImageFormat(format)) {
|
|
310
|
-
throw new Error(
|
|
311
|
-
`Unsupported image format: ${format}`
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
image: {
|
|
316
|
-
format,
|
|
317
|
-
source: {
|
|
318
|
-
bytes: part2.data
|
|
332
|
+
for (const part of content) {
|
|
333
|
+
let toolResultContent;
|
|
334
|
+
const output = part.output;
|
|
335
|
+
switch (output.type) {
|
|
336
|
+
case "content": {
|
|
337
|
+
toolResultContent = output.value.map((contentPart) => {
|
|
338
|
+
switch (contentPart.type) {
|
|
339
|
+
case "text":
|
|
340
|
+
return { text: contentPart.text };
|
|
341
|
+
case "media":
|
|
342
|
+
if (!contentPart.mediaType.startsWith("image/")) {
|
|
343
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
344
|
+
functionality: `media type: ${contentPart.mediaType}`
|
|
345
|
+
});
|
|
319
346
|
}
|
|
320
|
-
|
|
321
|
-
|
|
347
|
+
const format = getBedrockImageFormat(
|
|
348
|
+
contentPart.mediaType
|
|
349
|
+
);
|
|
350
|
+
return {
|
|
351
|
+
image: {
|
|
352
|
+
format,
|
|
353
|
+
source: { bytes: contentPart.data }
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
break;
|
|
322
359
|
}
|
|
323
|
-
|
|
360
|
+
case "text":
|
|
361
|
+
case "error-text":
|
|
362
|
+
toolResultContent = [{ text: output.value }];
|
|
363
|
+
break;
|
|
364
|
+
case "json":
|
|
365
|
+
case "error-json":
|
|
366
|
+
default:
|
|
367
|
+
toolResultContent = [
|
|
368
|
+
{ text: JSON.stringify(output.value) }
|
|
369
|
+
];
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
324
372
|
bedrockContent.push({
|
|
325
373
|
toolResult: {
|
|
326
374
|
toolUseId: part.toolCallId,
|
|
@@ -409,7 +457,7 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
409
457
|
toolUse: {
|
|
410
458
|
toolUseId: part.toolCallId,
|
|
411
459
|
name: part.toolName,
|
|
412
|
-
input: part.
|
|
460
|
+
input: part.input
|
|
413
461
|
}
|
|
414
462
|
});
|
|
415
463
|
break;
|
|
@@ -431,8 +479,31 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
431
479
|
}
|
|
432
480
|
return { system, messages };
|
|
433
481
|
}
|
|
434
|
-
function
|
|
435
|
-
|
|
482
|
+
function getBedrockImageFormat(mimeType) {
|
|
483
|
+
if (!mimeType) {
|
|
484
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
485
|
+
functionality: "image without mime type",
|
|
486
|
+
message: "Image mime type is required in user message part content"
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
|
|
490
|
+
if (!format) {
|
|
491
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
492
|
+
functionality: `image mime type: ${mimeType}`,
|
|
493
|
+
message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
return format;
|
|
497
|
+
}
|
|
498
|
+
function getBedrockDocumentFormat(mimeType) {
|
|
499
|
+
const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
|
|
500
|
+
if (!format) {
|
|
501
|
+
throw new import_provider3.UnsupportedFunctionalityError({
|
|
502
|
+
functionality: `file mime type: ${mimeType}`,
|
|
503
|
+
message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
return format;
|
|
436
507
|
}
|
|
437
508
|
function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
|
|
438
509
|
return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
|
|
@@ -528,7 +599,7 @@ var BedrockChatLanguageModel = class {
|
|
|
528
599
|
toolChoice,
|
|
529
600
|
providerOptions
|
|
530
601
|
}) {
|
|
531
|
-
var _a, _b, _c, _d
|
|
602
|
+
var _a, _b, _c, _d;
|
|
532
603
|
const bedrockOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
533
604
|
provider: "bedrock",
|
|
534
605
|
providerOptions,
|
|
@@ -583,7 +654,7 @@ var BedrockChatLanguageModel = class {
|
|
|
583
654
|
}
|
|
584
655
|
bedrockOptions.additionalModelRequestFields = {
|
|
585
656
|
...bedrockOptions.additionalModelRequestFields,
|
|
586
|
-
|
|
657
|
+
thinking: {
|
|
587
658
|
type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
|
|
588
659
|
budget_tokens: thinkingBudget
|
|
589
660
|
}
|
|
@@ -605,7 +676,12 @@ var BedrockChatLanguageModel = class {
|
|
|
605
676
|
details: "topP is not supported when thinking is enabled"
|
|
606
677
|
});
|
|
607
678
|
}
|
|
608
|
-
const { toolConfig, toolWarnings } = prepareTools({
|
|
679
|
+
const { toolConfig, toolWarnings } = prepareTools({
|
|
680
|
+
tools,
|
|
681
|
+
toolChoice,
|
|
682
|
+
prompt
|
|
683
|
+
});
|
|
684
|
+
const { reasoningConfig: _, ...filteredBedrockOptions } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
609
685
|
return {
|
|
610
686
|
command: {
|
|
611
687
|
system,
|
|
@@ -614,8 +690,8 @@ var BedrockChatLanguageModel = class {
|
|
|
614
690
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
615
691
|
inferenceConfig
|
|
616
692
|
},
|
|
617
|
-
...
|
|
618
|
-
...
|
|
693
|
+
...filteredBedrockOptions,
|
|
694
|
+
...toolConfig.tools !== void 0 ? { toolConfig } : {}
|
|
619
695
|
},
|
|
620
696
|
warnings: [...warnings, ...toolWarnings]
|
|
621
697
|
};
|
|
@@ -678,10 +754,9 @@ var BedrockChatLanguageModel = class {
|
|
|
678
754
|
if (part.toolUse) {
|
|
679
755
|
content.push({
|
|
680
756
|
type: "tool-call",
|
|
681
|
-
toolCallType: "function",
|
|
682
757
|
toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
|
|
683
758
|
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
684
|
-
|
|
759
|
+
input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
|
|
685
760
|
});
|
|
686
761
|
}
|
|
687
762
|
}
|
|
@@ -739,7 +814,7 @@ var BedrockChatLanguageModel = class {
|
|
|
739
814
|
totalTokens: void 0
|
|
740
815
|
};
|
|
741
816
|
let providerMetadata = void 0;
|
|
742
|
-
const
|
|
817
|
+
const contentBlocks = {};
|
|
743
818
|
return {
|
|
744
819
|
stream: response.pipeThrough(
|
|
745
820
|
new TransformStream({
|
|
@@ -747,11 +822,14 @@ var BedrockChatLanguageModel = class {
|
|
|
747
822
|
controller.enqueue({ type: "stream-start", warnings });
|
|
748
823
|
},
|
|
749
824
|
transform(chunk, controller) {
|
|
750
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
825
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
751
826
|
function enqueueError(bedrockError) {
|
|
752
827
|
finishReason = "error";
|
|
753
828
|
controller.enqueue({ type: "error", error: bedrockError });
|
|
754
829
|
}
|
|
830
|
+
if (options.includeRawChunks) {
|
|
831
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
832
|
+
}
|
|
755
833
|
if (!chunk.success) {
|
|
756
834
|
enqueueError(chunk.error);
|
|
757
835
|
return;
|
|
@@ -800,78 +878,126 @@ var BedrockChatLanguageModel = class {
|
|
|
800
878
|
};
|
|
801
879
|
}
|
|
802
880
|
}
|
|
803
|
-
if (((_j = value.
|
|
881
|
+
if (((_j = value.contentBlockStart) == null ? void 0 : _j.contentBlockIndex) != null && !((_l = (_k = value.contentBlockStart) == null ? void 0 : _k.start) == null ? void 0 : _l.toolUse)) {
|
|
882
|
+
const blockIndex = value.contentBlockStart.contentBlockIndex;
|
|
883
|
+
contentBlocks[blockIndex] = { type: "text" };
|
|
804
884
|
controller.enqueue({
|
|
805
|
-
type: "text",
|
|
806
|
-
|
|
885
|
+
type: "text-start",
|
|
886
|
+
id: String(blockIndex)
|
|
807
887
|
});
|
|
808
888
|
}
|
|
809
|
-
if (((
|
|
889
|
+
if (((_m = value.contentBlockDelta) == null ? void 0 : _m.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
890
|
+
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
891
|
+
if (contentBlocks[blockIndex] == null) {
|
|
892
|
+
contentBlocks[blockIndex] = { type: "text" };
|
|
893
|
+
controller.enqueue({
|
|
894
|
+
type: "text-start",
|
|
895
|
+
id: String(blockIndex)
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
controller.enqueue({
|
|
899
|
+
type: "text-delta",
|
|
900
|
+
id: String(blockIndex),
|
|
901
|
+
delta: value.contentBlockDelta.delta.text
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
if (((_n = value.contentBlockStop) == null ? void 0 : _n.contentBlockIndex) != null) {
|
|
905
|
+
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
906
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
907
|
+
if (contentBlock != null) {
|
|
908
|
+
if (contentBlock.type === "reasoning") {
|
|
909
|
+
controller.enqueue({
|
|
910
|
+
type: "reasoning-end",
|
|
911
|
+
id: String(blockIndex)
|
|
912
|
+
});
|
|
913
|
+
} else if (contentBlock.type === "text") {
|
|
914
|
+
controller.enqueue({
|
|
915
|
+
type: "text-end",
|
|
916
|
+
id: String(blockIndex)
|
|
917
|
+
});
|
|
918
|
+
} else if (contentBlock.type === "tool-call") {
|
|
919
|
+
controller.enqueue({
|
|
920
|
+
type: "tool-input-end",
|
|
921
|
+
id: contentBlock.toolCallId
|
|
922
|
+
});
|
|
923
|
+
controller.enqueue({
|
|
924
|
+
type: "tool-call",
|
|
925
|
+
toolCallId: contentBlock.toolCallId,
|
|
926
|
+
toolName: contentBlock.toolName,
|
|
927
|
+
input: contentBlock.jsonText
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
delete contentBlocks[blockIndex];
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (((_o = value.contentBlockDelta) == null ? void 0 : _o.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
934
|
+
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
810
935
|
const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
|
|
811
936
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
937
|
+
if (contentBlocks[blockIndex] == null) {
|
|
938
|
+
contentBlocks[blockIndex] = { type: "reasoning" };
|
|
939
|
+
controller.enqueue({
|
|
940
|
+
type: "reasoning-start",
|
|
941
|
+
id: String(blockIndex)
|
|
942
|
+
});
|
|
943
|
+
}
|
|
812
944
|
controller.enqueue({
|
|
813
|
-
type: "reasoning",
|
|
814
|
-
|
|
945
|
+
type: "reasoning-delta",
|
|
946
|
+
id: String(blockIndex),
|
|
947
|
+
delta: reasoningContent.text
|
|
815
948
|
});
|
|
816
949
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
817
950
|
controller.enqueue({
|
|
818
|
-
type: "reasoning",
|
|
819
|
-
|
|
951
|
+
type: "reasoning-delta",
|
|
952
|
+
id: String(blockIndex),
|
|
953
|
+
delta: "",
|
|
820
954
|
providerMetadata: {
|
|
821
955
|
bedrock: {
|
|
822
956
|
signature: reasoningContent.signature
|
|
823
957
|
}
|
|
824
958
|
}
|
|
825
959
|
});
|
|
826
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
827
960
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
828
961
|
controller.enqueue({
|
|
829
|
-
type: "reasoning",
|
|
830
|
-
|
|
962
|
+
type: "reasoning-delta",
|
|
963
|
+
id: String(blockIndex),
|
|
964
|
+
delta: "",
|
|
831
965
|
providerMetadata: {
|
|
832
966
|
bedrock: {
|
|
833
967
|
redactedData: reasoningContent.data
|
|
834
968
|
}
|
|
835
969
|
}
|
|
836
970
|
});
|
|
837
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
838
971
|
}
|
|
839
972
|
}
|
|
840
973
|
const contentBlockStart = value.contentBlockStart;
|
|
841
|
-
if (((
|
|
974
|
+
if (((_p = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _p.toolUse) != null) {
|
|
842
975
|
const toolUse = contentBlockStart.start.toolUse;
|
|
843
|
-
|
|
976
|
+
const blockIndex = contentBlockStart.contentBlockIndex;
|
|
977
|
+
contentBlocks[blockIndex] = {
|
|
978
|
+
type: "tool-call",
|
|
844
979
|
toolCallId: toolUse.toolUseId,
|
|
845
980
|
toolName: toolUse.name,
|
|
846
981
|
jsonText: ""
|
|
847
982
|
};
|
|
848
|
-
}
|
|
849
|
-
const contentBlockDelta = value.contentBlockDelta;
|
|
850
|
-
if ((contentBlockDelta == null ? void 0 : contentBlockDelta.delta) && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
|
|
851
|
-
const contentBlock = toolCallContentBlocks[contentBlockDelta.contentBlockIndex];
|
|
852
|
-
const delta = (_m = contentBlockDelta.delta.toolUse.input) != null ? _m : "";
|
|
853
983
|
controller.enqueue({
|
|
854
|
-
type: "tool-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
toolName: contentBlock.toolName,
|
|
858
|
-
argsTextDelta: delta
|
|
984
|
+
type: "tool-input-start",
|
|
985
|
+
id: toolUse.toolUseId,
|
|
986
|
+
toolName: toolUse.name
|
|
859
987
|
});
|
|
860
|
-
contentBlock.jsonText += delta;
|
|
861
988
|
}
|
|
862
|
-
const
|
|
863
|
-
if (
|
|
864
|
-
const
|
|
865
|
-
const contentBlock =
|
|
866
|
-
if (contentBlock
|
|
989
|
+
const contentBlockDelta = value.contentBlockDelta;
|
|
990
|
+
if ((contentBlockDelta == null ? void 0 : contentBlockDelta.delta) && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
|
|
991
|
+
const blockIndex = contentBlockDelta.contentBlockIndex;
|
|
992
|
+
const contentBlock = contentBlocks[blockIndex];
|
|
993
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
994
|
+
const delta = (_q = contentBlockDelta.delta.toolUse.input) != null ? _q : "";
|
|
867
995
|
controller.enqueue({
|
|
868
|
-
type: "tool-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
toolName: contentBlock.toolName,
|
|
872
|
-
args: contentBlock.jsonText
|
|
996
|
+
type: "tool-input-delta",
|
|
997
|
+
id: contentBlock.toolCallId,
|
|
998
|
+
delta
|
|
873
999
|
});
|
|
874
|
-
|
|
1000
|
+
contentBlock.jsonText += delta;
|
|
875
1001
|
}
|
|
876
1002
|
}
|
|
877
1003
|
},
|
|
@@ -894,104 +1020,104 @@ var BedrockChatLanguageModel = class {
|
|
|
894
1020
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
895
1021
|
}
|
|
896
1022
|
};
|
|
897
|
-
var BedrockStopReasonSchema =
|
|
898
|
-
|
|
899
|
-
|
|
1023
|
+
var BedrockStopReasonSchema = import_v43.z.union([
|
|
1024
|
+
import_v43.z.enum(BEDROCK_STOP_REASONS),
|
|
1025
|
+
import_v43.z.string()
|
|
900
1026
|
]);
|
|
901
|
-
var BedrockToolUseSchema =
|
|
902
|
-
toolUseId:
|
|
903
|
-
name:
|
|
904
|
-
input:
|
|
1027
|
+
var BedrockToolUseSchema = import_v43.z.object({
|
|
1028
|
+
toolUseId: import_v43.z.string(),
|
|
1029
|
+
name: import_v43.z.string(),
|
|
1030
|
+
input: import_v43.z.unknown()
|
|
905
1031
|
});
|
|
906
|
-
var BedrockReasoningTextSchema =
|
|
907
|
-
signature:
|
|
908
|
-
text:
|
|
1032
|
+
var BedrockReasoningTextSchema = import_v43.z.object({
|
|
1033
|
+
signature: import_v43.z.string().nullish(),
|
|
1034
|
+
text: import_v43.z.string()
|
|
909
1035
|
});
|
|
910
|
-
var BedrockRedactedReasoningSchema =
|
|
911
|
-
data:
|
|
1036
|
+
var BedrockRedactedReasoningSchema = import_v43.z.object({
|
|
1037
|
+
data: import_v43.z.string()
|
|
912
1038
|
});
|
|
913
|
-
var BedrockResponseSchema =
|
|
914
|
-
metrics:
|
|
915
|
-
latencyMs:
|
|
1039
|
+
var BedrockResponseSchema = import_v43.z.object({
|
|
1040
|
+
metrics: import_v43.z.object({
|
|
1041
|
+
latencyMs: import_v43.z.number()
|
|
916
1042
|
}).nullish(),
|
|
917
|
-
output:
|
|
918
|
-
message:
|
|
919
|
-
content:
|
|
920
|
-
|
|
921
|
-
text:
|
|
1043
|
+
output: import_v43.z.object({
|
|
1044
|
+
message: import_v43.z.object({
|
|
1045
|
+
content: import_v43.z.array(
|
|
1046
|
+
import_v43.z.object({
|
|
1047
|
+
text: import_v43.z.string().nullish(),
|
|
922
1048
|
toolUse: BedrockToolUseSchema.nullish(),
|
|
923
|
-
reasoningContent:
|
|
924
|
-
|
|
1049
|
+
reasoningContent: import_v43.z.union([
|
|
1050
|
+
import_v43.z.object({
|
|
925
1051
|
reasoningText: BedrockReasoningTextSchema
|
|
926
1052
|
}),
|
|
927
|
-
|
|
1053
|
+
import_v43.z.object({
|
|
928
1054
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
929
1055
|
})
|
|
930
1056
|
]).nullish()
|
|
931
1057
|
})
|
|
932
1058
|
),
|
|
933
|
-
role:
|
|
1059
|
+
role: import_v43.z.string()
|
|
934
1060
|
})
|
|
935
1061
|
}),
|
|
936
1062
|
stopReason: BedrockStopReasonSchema,
|
|
937
|
-
trace:
|
|
938
|
-
usage:
|
|
939
|
-
inputTokens:
|
|
940
|
-
outputTokens:
|
|
941
|
-
totalTokens:
|
|
942
|
-
cacheReadInputTokens:
|
|
943
|
-
cacheWriteInputTokens:
|
|
1063
|
+
trace: import_v43.z.unknown().nullish(),
|
|
1064
|
+
usage: import_v43.z.object({
|
|
1065
|
+
inputTokens: import_v43.z.number(),
|
|
1066
|
+
outputTokens: import_v43.z.number(),
|
|
1067
|
+
totalTokens: import_v43.z.number(),
|
|
1068
|
+
cacheReadInputTokens: import_v43.z.number().nullish(),
|
|
1069
|
+
cacheWriteInputTokens: import_v43.z.number().nullish()
|
|
944
1070
|
})
|
|
945
1071
|
});
|
|
946
|
-
var BedrockStreamSchema =
|
|
947
|
-
contentBlockDelta:
|
|
948
|
-
contentBlockIndex:
|
|
949
|
-
delta:
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
reasoningContent:
|
|
1072
|
+
var BedrockStreamSchema = import_v43.z.object({
|
|
1073
|
+
contentBlockDelta: import_v43.z.object({
|
|
1074
|
+
contentBlockIndex: import_v43.z.number(),
|
|
1075
|
+
delta: import_v43.z.union([
|
|
1076
|
+
import_v43.z.object({ text: import_v43.z.string() }),
|
|
1077
|
+
import_v43.z.object({ toolUse: import_v43.z.object({ input: import_v43.z.string() }) }),
|
|
1078
|
+
import_v43.z.object({
|
|
1079
|
+
reasoningContent: import_v43.z.object({ text: import_v43.z.string() })
|
|
954
1080
|
}),
|
|
955
|
-
|
|
956
|
-
reasoningContent:
|
|
957
|
-
signature:
|
|
1081
|
+
import_v43.z.object({
|
|
1082
|
+
reasoningContent: import_v43.z.object({
|
|
1083
|
+
signature: import_v43.z.string()
|
|
958
1084
|
})
|
|
959
1085
|
}),
|
|
960
|
-
|
|
961
|
-
reasoningContent:
|
|
1086
|
+
import_v43.z.object({
|
|
1087
|
+
reasoningContent: import_v43.z.object({ data: import_v43.z.string() })
|
|
962
1088
|
})
|
|
963
1089
|
]).nullish()
|
|
964
1090
|
}).nullish(),
|
|
965
|
-
contentBlockStart:
|
|
966
|
-
contentBlockIndex:
|
|
967
|
-
start:
|
|
1091
|
+
contentBlockStart: import_v43.z.object({
|
|
1092
|
+
contentBlockIndex: import_v43.z.number(),
|
|
1093
|
+
start: import_v43.z.object({
|
|
968
1094
|
toolUse: BedrockToolUseSchema.nullish()
|
|
969
1095
|
}).nullish()
|
|
970
1096
|
}).nullish(),
|
|
971
|
-
contentBlockStop:
|
|
972
|
-
contentBlockIndex:
|
|
1097
|
+
contentBlockStop: import_v43.z.object({
|
|
1098
|
+
contentBlockIndex: import_v43.z.number()
|
|
973
1099
|
}).nullish(),
|
|
974
|
-
internalServerException:
|
|
975
|
-
messageStop:
|
|
976
|
-
additionalModelResponseFields:
|
|
1100
|
+
internalServerException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
1101
|
+
messageStop: import_v43.z.object({
|
|
1102
|
+
additionalModelResponseFields: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
977
1103
|
stopReason: BedrockStopReasonSchema
|
|
978
1104
|
}).nullish(),
|
|
979
|
-
metadata:
|
|
980
|
-
trace:
|
|
981
|
-
usage:
|
|
982
|
-
cacheReadInputTokens:
|
|
983
|
-
cacheWriteInputTokens:
|
|
984
|
-
inputTokens:
|
|
985
|
-
outputTokens:
|
|
1105
|
+
metadata: import_v43.z.object({
|
|
1106
|
+
trace: import_v43.z.unknown().nullish(),
|
|
1107
|
+
usage: import_v43.z.object({
|
|
1108
|
+
cacheReadInputTokens: import_v43.z.number().nullish(),
|
|
1109
|
+
cacheWriteInputTokens: import_v43.z.number().nullish(),
|
|
1110
|
+
inputTokens: import_v43.z.number(),
|
|
1111
|
+
outputTokens: import_v43.z.number()
|
|
986
1112
|
}).nullish()
|
|
987
1113
|
}).nullish(),
|
|
988
|
-
modelStreamErrorException:
|
|
989
|
-
throttlingException:
|
|
990
|
-
validationException:
|
|
1114
|
+
modelStreamErrorException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
1115
|
+
throttlingException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
|
|
1116
|
+
validationException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish()
|
|
991
1117
|
});
|
|
992
|
-
var bedrockReasoningMetadataSchema =
|
|
993
|
-
signature:
|
|
994
|
-
redactedData:
|
|
1118
|
+
var bedrockReasoningMetadataSchema = import_v43.z.object({
|
|
1119
|
+
signature: import_v43.z.string().optional(),
|
|
1120
|
+
redactedData: import_v43.z.string().optional()
|
|
995
1121
|
});
|
|
996
1122
|
|
|
997
1123
|
// src/bedrock-embedding-model.ts
|
|
@@ -999,22 +1125,22 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
999
1125
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1000
1126
|
|
|
1001
1127
|
// src/bedrock-embedding-options.ts
|
|
1002
|
-
var
|
|
1003
|
-
var bedrockEmbeddingProviderOptions =
|
|
1128
|
+
var import_v44 = require("zod/v4");
|
|
1129
|
+
var bedrockEmbeddingProviderOptions = import_v44.z.object({
|
|
1004
1130
|
/**
|
|
1005
1131
|
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
1006
1132
|
Only supported in amazon.titan-embed-text-v2:0.
|
|
1007
1133
|
*/
|
|
1008
|
-
dimensions:
|
|
1134
|
+
dimensions: import_v44.z.union([import_v44.z.literal(1024), import_v44.z.literal(512), import_v44.z.literal(256)]).optional(),
|
|
1009
1135
|
/**
|
|
1010
1136
|
Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
1011
1137
|
Only supported in amazon.titan-embed-text-v2:0.
|
|
1012
1138
|
*/
|
|
1013
|
-
normalize:
|
|
1139
|
+
normalize: import_v44.z.boolean().optional()
|
|
1014
1140
|
});
|
|
1015
1141
|
|
|
1016
1142
|
// src/bedrock-embedding-model.ts
|
|
1017
|
-
var
|
|
1143
|
+
var import_v45 = require("zod/v4");
|
|
1018
1144
|
var BedrockEmbeddingModel = class {
|
|
1019
1145
|
constructor(modelId, config) {
|
|
1020
1146
|
this.modelId = modelId;
|
|
@@ -1076,9 +1202,9 @@ var BedrockEmbeddingModel = class {
|
|
|
1076
1202
|
};
|
|
1077
1203
|
}
|
|
1078
1204
|
};
|
|
1079
|
-
var BedrockEmbeddingResponseSchema =
|
|
1080
|
-
embedding:
|
|
1081
|
-
inputTextTokenCount:
|
|
1205
|
+
var BedrockEmbeddingResponseSchema = import_v45.z.object({
|
|
1206
|
+
embedding: import_v45.z.array(import_v45.z.number()),
|
|
1207
|
+
inputTextTokenCount: import_v45.z.number()
|
|
1082
1208
|
});
|
|
1083
1209
|
|
|
1084
1210
|
// src/bedrock-image-model.ts
|
|
@@ -1090,7 +1216,7 @@ var modelMaxImagesPerCall = {
|
|
|
1090
1216
|
};
|
|
1091
1217
|
|
|
1092
1218
|
// src/bedrock-image-model.ts
|
|
1093
|
-
var
|
|
1219
|
+
var import_v46 = require("zod/v4");
|
|
1094
1220
|
var BedrockImageModel = class {
|
|
1095
1221
|
constructor(modelId, config) {
|
|
1096
1222
|
this.modelId = modelId;
|
|
@@ -1116,7 +1242,7 @@ var BedrockImageModel = class {
|
|
|
1116
1242
|
headers,
|
|
1117
1243
|
abortSignal
|
|
1118
1244
|
}) {
|
|
1119
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1245
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1120
1246
|
const warnings = [];
|
|
1121
1247
|
const [width, height] = size ? size.split("x").map(Number) : [];
|
|
1122
1248
|
const args = {
|
|
@@ -1125,6 +1251,9 @@ var BedrockImageModel = class {
|
|
|
1125
1251
|
text: prompt,
|
|
1126
1252
|
...((_a = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _a.negativeText) ? {
|
|
1127
1253
|
negativeText: providerOptions.bedrock.negativeText
|
|
1254
|
+
} : {},
|
|
1255
|
+
...((_b = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _b.style) ? {
|
|
1256
|
+
style: providerOptions.bedrock.style
|
|
1128
1257
|
} : {}
|
|
1129
1258
|
},
|
|
1130
1259
|
imageGenerationConfig: {
|
|
@@ -1132,8 +1261,8 @@ var BedrockImageModel = class {
|
|
|
1132
1261
|
...height ? { height } : {},
|
|
1133
1262
|
...seed ? { seed } : {},
|
|
1134
1263
|
...n ? { numberOfImages: n } : {},
|
|
1135
|
-
...((
|
|
1136
|
-
...((
|
|
1264
|
+
...((_c = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _c.quality) ? { quality: providerOptions.bedrock.quality } : {},
|
|
1265
|
+
...((_d = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _d.cfgScale) ? { cfgScale: providerOptions.bedrock.cfgScale } : {}
|
|
1137
1266
|
}
|
|
1138
1267
|
};
|
|
1139
1268
|
if (aspectRatio != void 0) {
|
|
@@ -1143,7 +1272,7 @@ var BedrockImageModel = class {
|
|
|
1143
1272
|
details: "This model does not support aspect ratio. Use `size` instead."
|
|
1144
1273
|
});
|
|
1145
1274
|
}
|
|
1146
|
-
const currentDate = (
|
|
1275
|
+
const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
|
|
1147
1276
|
const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
|
|
1148
1277
|
url: this.getUrl(this.modelId),
|
|
1149
1278
|
headers: await (0, import_provider_utils5.resolve)(
|
|
@@ -1171,8 +1300,8 @@ var BedrockImageModel = class {
|
|
|
1171
1300
|
};
|
|
1172
1301
|
}
|
|
1173
1302
|
};
|
|
1174
|
-
var bedrockImageResponseSchema =
|
|
1175
|
-
images:
|
|
1303
|
+
var bedrockImageResponseSchema = import_v46.z.object({
|
|
1304
|
+
images: import_v46.z.array(import_v46.z.string())
|
|
1176
1305
|
});
|
|
1177
1306
|
|
|
1178
1307
|
// src/headers-utils.ts
|
|
@@ -1243,10 +1372,28 @@ function prepareBodyString(body) {
|
|
|
1243
1372
|
return JSON.stringify(body);
|
|
1244
1373
|
}
|
|
1245
1374
|
}
|
|
1375
|
+
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
1376
|
+
return async (input, init) => {
|
|
1377
|
+
const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
|
|
1378
|
+
return fetch(input, {
|
|
1379
|
+
...init,
|
|
1380
|
+
headers: (0, import_provider_utils6.removeUndefinedEntries)(
|
|
1381
|
+
(0, import_provider_utils6.combineHeaders)(originalHeaders, {
|
|
1382
|
+
Authorization: `Bearer ${apiKey}`
|
|
1383
|
+
})
|
|
1384
|
+
)
|
|
1385
|
+
});
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1246
1388
|
|
|
1247
1389
|
// src/bedrock-provider.ts
|
|
1248
1390
|
function createAmazonBedrock(options = {}) {
|
|
1249
|
-
const
|
|
1391
|
+
const rawApiKey = (0, import_provider_utils7.loadOptionalSetting)({
|
|
1392
|
+
settingValue: options.apiKey,
|
|
1393
|
+
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
1394
|
+
});
|
|
1395
|
+
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
1396
|
+
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
1250
1397
|
const region = (0, import_provider_utils7.loadSetting)({
|
|
1251
1398
|
settingValue: options.region,
|
|
1252
1399
|
settingName: "region",
|
|
@@ -1254,30 +1401,58 @@ function createAmazonBedrock(options = {}) {
|
|
|
1254
1401
|
description: "AWS region"
|
|
1255
1402
|
});
|
|
1256
1403
|
if (options.credentialProvider) {
|
|
1404
|
+
try {
|
|
1405
|
+
return {
|
|
1406
|
+
...await options.credentialProvider(),
|
|
1407
|
+
region
|
|
1408
|
+
};
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1411
|
+
throw new Error(
|
|
1412
|
+
`AWS credential provider failed: ${errorMessage}. Please ensure your credential provider returns valid AWS credentials with accessKeyId and secretAccessKey properties.`
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
try {
|
|
1257
1417
|
return {
|
|
1258
|
-
|
|
1259
|
-
|
|
1418
|
+
region,
|
|
1419
|
+
accessKeyId: (0, import_provider_utils7.loadSetting)({
|
|
1420
|
+
settingValue: options.accessKeyId,
|
|
1421
|
+
settingName: "accessKeyId",
|
|
1422
|
+
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
1423
|
+
description: "AWS access key ID"
|
|
1424
|
+
}),
|
|
1425
|
+
secretAccessKey: (0, import_provider_utils7.loadSetting)({
|
|
1426
|
+
settingValue: options.secretAccessKey,
|
|
1427
|
+
settingName: "secretAccessKey",
|
|
1428
|
+
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1429
|
+
description: "AWS secret access key"
|
|
1430
|
+
}),
|
|
1431
|
+
sessionToken: (0, import_provider_utils7.loadOptionalSetting)({
|
|
1432
|
+
settingValue: options.sessionToken,
|
|
1433
|
+
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1434
|
+
})
|
|
1260
1435
|
};
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1438
|
+
if (errorMessage.includes("AWS_ACCESS_KEY_ID") || errorMessage.includes("accessKeyId")) {
|
|
1439
|
+
throw new Error(
|
|
1440
|
+
`AWS SigV4 authentication requires AWS credentials. Please provide either:
|
|
1441
|
+
1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
|
|
1442
|
+
2. Provide accessKeyId and secretAccessKey in options
|
|
1443
|
+
3. Use a credentialProvider function
|
|
1444
|
+
4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option
|
|
1445
|
+
Original error: ${errorMessage}`
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
if (errorMessage.includes("AWS_SECRET_ACCESS_KEY") || errorMessage.includes("secretAccessKey")) {
|
|
1449
|
+
throw new Error(
|
|
1450
|
+
`AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Please ensure both credentials are provided.
|
|
1451
|
+
Original error: ${errorMessage}`
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
throw error;
|
|
1261
1455
|
}
|
|
1262
|
-
return {
|
|
1263
|
-
region,
|
|
1264
|
-
accessKeyId: (0, import_provider_utils7.loadSetting)({
|
|
1265
|
-
settingValue: options.accessKeyId,
|
|
1266
|
-
settingName: "accessKeyId",
|
|
1267
|
-
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
1268
|
-
description: "AWS access key ID"
|
|
1269
|
-
}),
|
|
1270
|
-
secretAccessKey: (0, import_provider_utils7.loadSetting)({
|
|
1271
|
-
settingValue: options.secretAccessKey,
|
|
1272
|
-
settingName: "secretAccessKey",
|
|
1273
|
-
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1274
|
-
description: "AWS secret access key"
|
|
1275
|
-
}),
|
|
1276
|
-
sessionToken: (0, import_provider_utils7.loadOptionalSetting)({
|
|
1277
|
-
settingValue: options.sessionToken,
|
|
1278
|
-
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1279
|
-
})
|
|
1280
|
-
};
|
|
1281
1456
|
}, options.fetch);
|
|
1282
1457
|
const getBaseUrl = () => {
|
|
1283
1458
|
var _a, _b;
|
|
@@ -1295,7 +1470,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1295
1470
|
return new BedrockChatLanguageModel(modelId, {
|
|
1296
1471
|
baseUrl: getBaseUrl,
|
|
1297
1472
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1298
|
-
fetch:
|
|
1473
|
+
fetch: fetchFunction,
|
|
1299
1474
|
generateId: import_provider_utils7.generateId
|
|
1300
1475
|
});
|
|
1301
1476
|
};
|
|
@@ -1312,7 +1487,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1312
1487
|
return new BedrockEmbeddingModel(modelId, {
|
|
1313
1488
|
baseUrl: getBaseUrl,
|
|
1314
1489
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1315
|
-
fetch:
|
|
1490
|
+
fetch: fetchFunction
|
|
1316
1491
|
});
|
|
1317
1492
|
};
|
|
1318
1493
|
const createImageModel = (modelId) => {
|
|
@@ -1320,7 +1495,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1320
1495
|
return new BedrockImageModel(modelId, {
|
|
1321
1496
|
baseUrl: getBaseUrl,
|
|
1322
1497
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1323
|
-
fetch:
|
|
1498
|
+
fetch: fetchFunction
|
|
1324
1499
|
});
|
|
1325
1500
|
};
|
|
1326
1501
|
provider.languageModel = createChatModel;
|