@ai-sdk/amazon-bedrock 3.0.0-canary.1 → 3.0.0-canary.11
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 +112 -0
- package/dist/index.d.mts +39 -26
- package/dist/index.d.ts +39 -26
- package/dist/index.js +317 -305
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +322 -310
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -9
package/dist/index.js
CHANGED
|
@@ -29,9 +29,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
29
29
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/bedrock-chat-language-model.ts
|
|
32
|
-
var import_provider4 = require("@ai-sdk/provider");
|
|
33
32
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
34
|
-
var
|
|
33
|
+
var import_zod3 = require("zod");
|
|
35
34
|
|
|
36
35
|
// src/bedrock-api-types.ts
|
|
37
36
|
var BEDROCK_CACHE_POINT = {
|
|
@@ -50,11 +49,26 @@ var BEDROCK_STOP_REASONS = [
|
|
|
50
49
|
"tool_use"
|
|
51
50
|
];
|
|
52
51
|
|
|
53
|
-
// src/bedrock-
|
|
52
|
+
// src/bedrock-chat-options.ts
|
|
54
53
|
var import_zod = require("zod");
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
var bedrockProviderOptions = import_zod.z.object({
|
|
55
|
+
/**
|
|
56
|
+
* Additional inference parameters that the model supports,
|
|
57
|
+
* beyond the base set of inference parameters that Converse
|
|
58
|
+
* supports in the inferenceConfig field
|
|
59
|
+
*/
|
|
60
|
+
additionalModelRequestFields: import_zod.z.record(import_zod.z.any()).optional(),
|
|
61
|
+
reasoningConfig: import_zod.z.object({
|
|
62
|
+
type: import_zod.z.union([import_zod.z.literal("enabled"), import_zod.z.literal("disabled")]).nullish(),
|
|
63
|
+
budgetTokens: import_zod.z.number().nullish()
|
|
64
|
+
}).nullish()
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// src/bedrock-error.ts
|
|
68
|
+
var import_zod2 = require("zod");
|
|
69
|
+
var BedrockErrorSchema = import_zod2.z.object({
|
|
70
|
+
message: import_zod2.z.string(),
|
|
71
|
+
type: import_zod2.z.string().nullish()
|
|
58
72
|
});
|
|
59
73
|
|
|
60
74
|
// src/bedrock-event-stream-response-handler.ts
|
|
@@ -74,7 +88,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
74
88
|
responseHeaders,
|
|
75
89
|
value: response.body.pipeThrough(
|
|
76
90
|
new TransformStream({
|
|
77
|
-
transform(chunk, controller) {
|
|
91
|
+
async transform(chunk, controller) {
|
|
78
92
|
var _a, _b;
|
|
79
93
|
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
80
94
|
newBuffer.set(buffer);
|
|
@@ -95,7 +109,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
95
109
|
buffer = buffer.slice(totalLength);
|
|
96
110
|
if (((_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value) === "event") {
|
|
97
111
|
const data = textDecoder.decode(decoded.body);
|
|
98
|
-
const parsedDataResult = (0, import_provider_utils.safeParseJSON)({ text: data });
|
|
112
|
+
const parsedDataResult = await (0, import_provider_utils.safeParseJSON)({ text: data });
|
|
99
113
|
if (!parsedDataResult.success) {
|
|
100
114
|
controller.enqueue(parsedDataResult);
|
|
101
115
|
break;
|
|
@@ -104,7 +118,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
104
118
|
let wrappedData = {
|
|
105
119
|
[(_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value]: parsedDataResult.value
|
|
106
120
|
};
|
|
107
|
-
const validatedWrappedData = (0, import_provider_utils.safeValidateTypes)({
|
|
121
|
+
const validatedWrappedData = await (0, import_provider_utils.safeValidateTypes)({
|
|
108
122
|
value: wrappedData,
|
|
109
123
|
schema: chunkSchema
|
|
110
124
|
});
|
|
@@ -130,9 +144,11 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
130
144
|
|
|
131
145
|
// src/bedrock-prepare-tools.ts
|
|
132
146
|
var import_provider2 = require("@ai-sdk/provider");
|
|
133
|
-
function prepareTools(
|
|
134
|
-
|
|
135
|
-
|
|
147
|
+
function prepareTools({
|
|
148
|
+
tools,
|
|
149
|
+
toolChoice
|
|
150
|
+
}) {
|
|
151
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
136
152
|
if (tools == null) {
|
|
137
153
|
return {
|
|
138
154
|
toolConfig: { tools: void 0, toolChoice: void 0 },
|
|
@@ -156,7 +172,6 @@ function prepareTools(mode) {
|
|
|
156
172
|
});
|
|
157
173
|
}
|
|
158
174
|
}
|
|
159
|
-
const toolChoice = mode.toolChoice;
|
|
160
175
|
if (toolChoice == null) {
|
|
161
176
|
return {
|
|
162
177
|
toolConfig: { tools: bedrockTools, toolChoice: void 0 },
|
|
@@ -191,7 +206,7 @@ function prepareTools(mode) {
|
|
|
191
206
|
default: {
|
|
192
207
|
const _exhaustiveCheck = type;
|
|
193
208
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
194
|
-
functionality: `
|
|
209
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
195
210
|
});
|
|
196
211
|
}
|
|
197
212
|
}
|
|
@@ -205,8 +220,8 @@ function getCachePoint(providerMetadata) {
|
|
|
205
220
|
var _a;
|
|
206
221
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
207
222
|
}
|
|
208
|
-
function convertToBedrockChatMessages(prompt) {
|
|
209
|
-
var _a, _b, _c, _d
|
|
223
|
+
async function convertToBedrockChatMessages(prompt) {
|
|
224
|
+
var _a, _b, _c, _d;
|
|
210
225
|
const blocks = groupIntoBlocks(prompt);
|
|
211
226
|
let system = [];
|
|
212
227
|
const messages = [];
|
|
@@ -223,7 +238,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
223
238
|
}
|
|
224
239
|
for (const message of block.messages) {
|
|
225
240
|
system.push({ text: message.content });
|
|
226
|
-
if (getCachePoint(message.
|
|
241
|
+
if (getCachePoint(message.providerOptions)) {
|
|
227
242
|
system.push(BEDROCK_CACHE_POINT);
|
|
228
243
|
}
|
|
229
244
|
}
|
|
@@ -232,7 +247,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
232
247
|
case "user": {
|
|
233
248
|
const bedrockContent = [];
|
|
234
249
|
for (const message of block.messages) {
|
|
235
|
-
const { role, content,
|
|
250
|
+
const { role, content, providerOptions } = message;
|
|
236
251
|
switch (role) {
|
|
237
252
|
case "user": {
|
|
238
253
|
for (let j = 0; j < content.length; j++) {
|
|
@@ -244,43 +259,31 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
244
259
|
});
|
|
245
260
|
break;
|
|
246
261
|
}
|
|
247
|
-
case "image": {
|
|
248
|
-
if (part.image instanceof URL) {
|
|
249
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
250
|
-
functionality: "Image URLs in user messages"
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
bedrockContent.push({
|
|
254
|
-
image: {
|
|
255
|
-
format: (_b = (_a = part.mimeType) == null ? void 0 : _a.split(
|
|
256
|
-
"/"
|
|
257
|
-
)) == null ? void 0 : _b[1],
|
|
258
|
-
source: {
|
|
259
|
-
bytes: (0, import_provider_utils2.convertUint8ArrayToBase64)(
|
|
260
|
-
(_c = part.image) != null ? _c : part.image
|
|
261
|
-
)
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
262
|
case "file": {
|
|
268
263
|
if (part.data instanceof URL) {
|
|
269
264
|
throw new import_provider3.UnsupportedFunctionalityError({
|
|
270
|
-
functionality: "File
|
|
265
|
+
functionality: "File URL data"
|
|
271
266
|
});
|
|
272
267
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
source: {
|
|
280
|
-
bytes: part.data
|
|
268
|
+
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
|
+
bedrockContent.push({
|
|
271
|
+
image: {
|
|
272
|
+
format: bedrockImageFormat,
|
|
273
|
+
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
281
274
|
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
bedrockContent.push({
|
|
278
|
+
document: {
|
|
279
|
+
format: (_d = (_c = part.mediaType) == null ? void 0 : _c.split(
|
|
280
|
+
"/"
|
|
281
|
+
)) == null ? void 0 : _d[1],
|
|
282
|
+
name: generateFileId(),
|
|
283
|
+
source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
284
287
|
break;
|
|
285
288
|
}
|
|
286
289
|
}
|
|
@@ -297,12 +300,12 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
297
300
|
text: part2.text
|
|
298
301
|
};
|
|
299
302
|
case "image":
|
|
300
|
-
if (!part2.
|
|
303
|
+
if (!part2.mediaType) {
|
|
301
304
|
throw new Error(
|
|
302
305
|
"Image mime type is required in tool result part content"
|
|
303
306
|
);
|
|
304
307
|
}
|
|
305
|
-
const format = part2.
|
|
308
|
+
const format = part2.mediaType.split("/")[1];
|
|
306
309
|
if (!isBedrockImageFormat(format)) {
|
|
307
310
|
throw new Error(
|
|
308
311
|
`Unsupported image format: ${format}`
|
|
@@ -332,7 +335,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
332
335
|
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
333
336
|
}
|
|
334
337
|
}
|
|
335
|
-
if (getCachePoint(
|
|
338
|
+
if (getCachePoint(providerOptions)) {
|
|
336
339
|
bedrockContent.push(BEDROCK_CACHE_POINT);
|
|
337
340
|
}
|
|
338
341
|
}
|
|
@@ -366,32 +369,39 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
366
369
|
break;
|
|
367
370
|
}
|
|
368
371
|
case "reasoning": {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
// because Bedrock does not allow trailing whitespace
|
|
374
|
-
// in pre-filled assistant responses
|
|
375
|
-
text: trimIfLast(
|
|
376
|
-
isLastBlock,
|
|
377
|
-
isLastMessage,
|
|
378
|
-
isLastContentPart,
|
|
379
|
-
part.text
|
|
380
|
-
),
|
|
381
|
-
signature: part.signature
|
|
382
|
-
}
|
|
383
|
-
}
|
|
372
|
+
const reasoningMetadata = await (0, import_provider_utils2.parseProviderOptions)({
|
|
373
|
+
provider: "bedrock",
|
|
374
|
+
providerOptions: part.providerOptions,
|
|
375
|
+
schema: bedrockReasoningMetadataSchema
|
|
384
376
|
});
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
377
|
+
if (reasoningMetadata != null) {
|
|
378
|
+
if (reasoningMetadata.signature != null) {
|
|
379
|
+
bedrockContent.push({
|
|
380
|
+
reasoningContent: {
|
|
381
|
+
reasoningText: {
|
|
382
|
+
// trim the last text part if it's the last message in the block
|
|
383
|
+
// because Bedrock does not allow trailing whitespace
|
|
384
|
+
// in pre-filled assistant responses
|
|
385
|
+
text: trimIfLast(
|
|
386
|
+
isLastBlock,
|
|
387
|
+
isLastMessage,
|
|
388
|
+
isLastContentPart,
|
|
389
|
+
part.text
|
|
390
|
+
),
|
|
391
|
+
signature: reasoningMetadata.signature
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
} else if (reasoningMetadata.redactedData != null) {
|
|
396
|
+
bedrockContent.push({
|
|
397
|
+
reasoningContent: {
|
|
398
|
+
redactedReasoning: {
|
|
399
|
+
data: reasoningMetadata.redactedData
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
});
|
|
393
403
|
}
|
|
394
|
-
}
|
|
404
|
+
}
|
|
395
405
|
break;
|
|
396
406
|
}
|
|
397
407
|
case "tool-call": {
|
|
@@ -406,7 +416,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
406
416
|
}
|
|
407
417
|
}
|
|
408
418
|
}
|
|
409
|
-
if (getCachePoint(message.
|
|
419
|
+
if (getCachePoint(message.providerOptions)) {
|
|
410
420
|
bedrockContent.push(BEDROCK_CACHE_POINT);
|
|
411
421
|
}
|
|
412
422
|
}
|
|
@@ -494,19 +504,15 @@ function mapBedrockFinishReason(finishReason) {
|
|
|
494
504
|
|
|
495
505
|
// src/bedrock-chat-language-model.ts
|
|
496
506
|
var BedrockChatLanguageModel = class {
|
|
497
|
-
constructor(modelId,
|
|
507
|
+
constructor(modelId, config) {
|
|
498
508
|
this.modelId = modelId;
|
|
499
|
-
this.settings = settings;
|
|
500
509
|
this.config = config;
|
|
501
510
|
this.specificationVersion = "v2";
|
|
502
511
|
this.provider = "amazon-bedrock";
|
|
503
|
-
this.defaultObjectGenerationMode = "tool";
|
|
504
|
-
this.supportsImageUrls = false;
|
|
505
512
|
}
|
|
506
|
-
getArgs({
|
|
507
|
-
mode,
|
|
513
|
+
async getArgs({
|
|
508
514
|
prompt,
|
|
509
|
-
|
|
515
|
+
maxOutputTokens,
|
|
510
516
|
temperature,
|
|
511
517
|
topP,
|
|
512
518
|
topK,
|
|
@@ -515,10 +521,16 @@ var BedrockChatLanguageModel = class {
|
|
|
515
521
|
stopSequences,
|
|
516
522
|
responseFormat,
|
|
517
523
|
seed,
|
|
518
|
-
|
|
524
|
+
tools,
|
|
525
|
+
toolChoice,
|
|
526
|
+
providerOptions
|
|
519
527
|
}) {
|
|
520
|
-
var _a, _b, _c, _d, _e
|
|
521
|
-
const
|
|
528
|
+
var _a, _b, _c, _d, _e;
|
|
529
|
+
const bedrockOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
530
|
+
provider: "bedrock",
|
|
531
|
+
providerOptions,
|
|
532
|
+
schema: bedrockProviderOptions
|
|
533
|
+
})) != null ? _a : {};
|
|
522
534
|
const warnings = [];
|
|
523
535
|
if (frequencyPenalty != null) {
|
|
524
536
|
warnings.push({
|
|
@@ -551,35 +563,25 @@ var BedrockChatLanguageModel = class {
|
|
|
551
563
|
details: "JSON response format is not supported."
|
|
552
564
|
});
|
|
553
565
|
}
|
|
554
|
-
const { system, messages } = convertToBedrockChatMessages(prompt);
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
);
|
|
558
|
-
if (!reasoningConfigOptions.success) {
|
|
559
|
-
throw new import_provider4.InvalidArgumentError({
|
|
560
|
-
argument: "providerOptions.bedrock.reasoning_config",
|
|
561
|
-
message: "invalid reasoning configuration options",
|
|
562
|
-
cause: reasoningConfigOptions.error
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
const isThinking = ((_b = reasoningConfigOptions.data) == null ? void 0 : _b.type) === "enabled";
|
|
566
|
-
const thinkingBudget = (_e = (_c = reasoningConfigOptions.data) == null ? void 0 : _c.budgetTokens) != null ? _e : (_d = reasoningConfigOptions.data) == null ? void 0 : _d.budget_tokens;
|
|
566
|
+
const { system, messages } = await convertToBedrockChatMessages(prompt);
|
|
567
|
+
const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
|
|
568
|
+
const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
|
|
567
569
|
const inferenceConfig = {
|
|
568
|
-
...
|
|
570
|
+
...maxOutputTokens != null && { maxOutputTokens },
|
|
569
571
|
...temperature != null && { temperature },
|
|
570
572
|
...topP != null && { topP },
|
|
571
573
|
...stopSequences != null && { stopSequences }
|
|
572
574
|
};
|
|
573
575
|
if (isThinking && thinkingBudget != null) {
|
|
574
|
-
if (inferenceConfig.
|
|
575
|
-
inferenceConfig.
|
|
576
|
+
if (inferenceConfig.maxOutputTokens != null) {
|
|
577
|
+
inferenceConfig.maxOutputTokens += thinkingBudget;
|
|
576
578
|
} else {
|
|
577
|
-
inferenceConfig.
|
|
579
|
+
inferenceConfig.maxOutputTokens = thinkingBudget + 4096;
|
|
578
580
|
}
|
|
579
|
-
|
|
580
|
-
...
|
|
581
|
-
|
|
582
|
-
type: (
|
|
581
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
582
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
583
|
+
reasoningConfig: {
|
|
584
|
+
type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
|
|
583
585
|
budget_tokens: thinkingBudget
|
|
584
586
|
}
|
|
585
587
|
};
|
|
@@ -600,62 +602,29 @@ var BedrockChatLanguageModel = class {
|
|
|
600
602
|
details: "topP is not supported when thinking is enabled"
|
|
601
603
|
});
|
|
602
604
|
}
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
605
|
+
const { toolConfig, toolWarnings } = prepareTools({ tools, toolChoice });
|
|
606
|
+
return {
|
|
607
|
+
command: {
|
|
608
|
+
system,
|
|
609
|
+
messages,
|
|
610
|
+
additionalModelRequestFields: bedrockOptions.additionalModelRequestFields,
|
|
611
|
+
...Object.keys(inferenceConfig).length > 0 && {
|
|
612
|
+
inferenceConfig
|
|
613
|
+
},
|
|
614
|
+
...providerOptions == null ? void 0 : providerOptions.bedrock,
|
|
615
|
+
...((_e = toolConfig.tools) == null ? void 0 : _e.length) ? { toolConfig } : {}
|
|
608
616
|
},
|
|
609
|
-
|
|
610
|
-
|
|
617
|
+
warnings: [...warnings, ...toolWarnings]
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
async getSupportedUrls() {
|
|
621
|
+
return {
|
|
622
|
+
// no supported urls for bedrock
|
|
611
623
|
};
|
|
612
|
-
switch (type) {
|
|
613
|
-
case "regular": {
|
|
614
|
-
const { toolConfig, toolWarnings } = prepareTools(mode);
|
|
615
|
-
return {
|
|
616
|
-
command: {
|
|
617
|
-
...baseArgs,
|
|
618
|
-
...((_g = toolConfig.tools) == null ? void 0 : _g.length) ? { toolConfig } : {}
|
|
619
|
-
},
|
|
620
|
-
warnings: [...warnings, ...toolWarnings]
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
case "object-json": {
|
|
624
|
-
throw new import_provider4.UnsupportedFunctionalityError({
|
|
625
|
-
functionality: "json-mode object generation"
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
case "object-tool": {
|
|
629
|
-
return {
|
|
630
|
-
command: {
|
|
631
|
-
...baseArgs,
|
|
632
|
-
toolConfig: {
|
|
633
|
-
tools: [
|
|
634
|
-
{
|
|
635
|
-
toolSpec: {
|
|
636
|
-
name: mode.tool.name,
|
|
637
|
-
description: mode.tool.description,
|
|
638
|
-
inputSchema: {
|
|
639
|
-
json: mode.tool.parameters
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
],
|
|
644
|
-
toolChoice: { tool: { name: mode.tool.name } }
|
|
645
|
-
}
|
|
646
|
-
},
|
|
647
|
-
warnings
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
default: {
|
|
651
|
-
const _exhaustiveCheck = type;
|
|
652
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
624
|
}
|
|
656
625
|
async doGenerate(options) {
|
|
657
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
658
|
-
const { command: args, warnings } = this.getArgs(options);
|
|
626
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
627
|
+
const { command: args, warnings } = await this.getArgs(options);
|
|
659
628
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
660
629
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
|
661
630
|
url,
|
|
@@ -677,67 +646,77 @@ var BedrockChatLanguageModel = class {
|
|
|
677
646
|
abortSignal: options.abortSignal,
|
|
678
647
|
fetch: this.config.fetch
|
|
679
648
|
});
|
|
680
|
-
const
|
|
649
|
+
const content = [];
|
|
650
|
+
for (const part of response.output.message.content) {
|
|
651
|
+
if (part.text) {
|
|
652
|
+
content.push({ type: "text", text: part.text });
|
|
653
|
+
}
|
|
654
|
+
if (part.reasoningContent) {
|
|
655
|
+
if ("reasoningText" in part.reasoningContent) {
|
|
656
|
+
const reasoning = {
|
|
657
|
+
type: "reasoning",
|
|
658
|
+
text: part.reasoningContent.reasoningText.text
|
|
659
|
+
};
|
|
660
|
+
if (part.reasoningContent.reasoningText.signature) {
|
|
661
|
+
reasoning.providerMetadata = {
|
|
662
|
+
bedrock: {
|
|
663
|
+
signature: part.reasoningContent.reasoningText.signature
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
content.push(reasoning);
|
|
668
|
+
} else if ("redactedReasoning" in part.reasoningContent) {
|
|
669
|
+
content.push({
|
|
670
|
+
type: "reasoning",
|
|
671
|
+
text: "",
|
|
672
|
+
providerMetadata: {
|
|
673
|
+
bedrock: {
|
|
674
|
+
redactedData: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (part.toolUse) {
|
|
681
|
+
content.push({
|
|
682
|
+
type: "tool-call",
|
|
683
|
+
toolCallType: "function",
|
|
684
|
+
toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
|
|
685
|
+
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
686
|
+
args: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
}
|
|
681
690
|
const providerMetadata = response.trace || response.usage ? {
|
|
682
691
|
bedrock: {
|
|
683
692
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
684
693
|
...response.usage && {
|
|
685
694
|
usage: {
|
|
686
|
-
cacheReadInputTokens: (
|
|
687
|
-
cacheWriteInputTokens: (
|
|
695
|
+
cacheReadInputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.cacheReadInputTokens) != null ? _i : Number.NaN,
|
|
696
|
+
cacheWriteInputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null ? _k : Number.NaN
|
|
688
697
|
}
|
|
689
698
|
}
|
|
690
699
|
}
|
|
691
700
|
} : void 0;
|
|
692
|
-
const reasoning = response.output.message.content.filter((content) => content.reasoningContent).map((content) => {
|
|
693
|
-
var _a2;
|
|
694
|
-
if (content.reasoningContent && "reasoningText" in content.reasoningContent) {
|
|
695
|
-
return {
|
|
696
|
-
type: "text",
|
|
697
|
-
text: content.reasoningContent.reasoningText.text,
|
|
698
|
-
...content.reasoningContent.reasoningText.signature && {
|
|
699
|
-
signature: content.reasoningContent.reasoningText.signature
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
} else if (content.reasoningContent && "redactedReasoning" in content.reasoningContent) {
|
|
703
|
-
return {
|
|
704
|
-
type: "redacted",
|
|
705
|
-
data: (_a2 = content.reasoningContent.redactedReasoning.data) != null ? _a2 : ""
|
|
706
|
-
};
|
|
707
|
-
} else {
|
|
708
|
-
return void 0;
|
|
709
|
-
}
|
|
710
|
-
}).filter((item) => item !== void 0);
|
|
711
701
|
return {
|
|
712
|
-
|
|
713
|
-
var _a2;
|
|
714
|
-
return (_a2 = part.text) != null ? _a2 : "";
|
|
715
|
-
}).join("")) != null ? _h : void 0,
|
|
716
|
-
toolCalls: (_l = (_k = (_j = (_i = response.output) == null ? void 0 : _i.message) == null ? void 0 : _j.content) == null ? void 0 : _k.filter((part) => !!part.toolUse)) == null ? void 0 : _l.map((part) => {
|
|
717
|
-
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
718
|
-
return {
|
|
719
|
-
toolCallType: "function",
|
|
720
|
-
toolCallId: (_b2 = (_a2 = part.toolUse) == null ? void 0 : _a2.toolUseId) != null ? _b2 : this.config.generateId(),
|
|
721
|
-
toolName: (_d2 = (_c2 = part.toolUse) == null ? void 0 : _c2.name) != null ? _d2 : `tool-${this.config.generateId()}`,
|
|
722
|
-
args: JSON.stringify((_f2 = (_e2 = part.toolUse) == null ? void 0 : _e2.input) != null ? _f2 : "")
|
|
723
|
-
};
|
|
724
|
-
}),
|
|
702
|
+
content,
|
|
725
703
|
finishReason: mapBedrockFinishReason(
|
|
726
704
|
response.stopReason
|
|
727
705
|
),
|
|
728
706
|
usage: {
|
|
729
|
-
|
|
730
|
-
|
|
707
|
+
inputTokens: (_l = response.usage) == null ? void 0 : _l.inputTokens,
|
|
708
|
+
outputTokens: (_m = response.usage) == null ? void 0 : _m.outputTokens
|
|
709
|
+
},
|
|
710
|
+
response: {
|
|
711
|
+
// TODO add id, timestamp, etc
|
|
712
|
+
headers: responseHeaders
|
|
731
713
|
},
|
|
732
|
-
rawCall: { rawPrompt, rawSettings },
|
|
733
|
-
rawResponse: { headers: responseHeaders },
|
|
734
714
|
warnings,
|
|
735
|
-
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
736
715
|
...providerMetadata && { providerMetadata }
|
|
737
716
|
};
|
|
738
717
|
}
|
|
739
718
|
async doStream(options) {
|
|
740
|
-
const { command: args, warnings } = this.getArgs(options);
|
|
719
|
+
const { command: args, warnings } = await this.getArgs(options);
|
|
741
720
|
const url = `${this.getUrl(this.modelId)}/converse-stream`;
|
|
742
721
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
|
743
722
|
url,
|
|
@@ -754,17 +733,19 @@ var BedrockChatLanguageModel = class {
|
|
|
754
733
|
abortSignal: options.abortSignal,
|
|
755
734
|
fetch: this.config.fetch
|
|
756
735
|
});
|
|
757
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
758
736
|
let finishReason = "unknown";
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
737
|
+
const usage = {
|
|
738
|
+
inputTokens: void 0,
|
|
739
|
+
outputTokens: void 0
|
|
762
740
|
};
|
|
763
741
|
let providerMetadata = void 0;
|
|
764
742
|
const toolCallContentBlocks = {};
|
|
765
743
|
return {
|
|
766
744
|
stream: response.pipeThrough(
|
|
767
745
|
new TransformStream({
|
|
746
|
+
start(controller) {
|
|
747
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
748
|
+
},
|
|
768
749
|
transform(chunk, controller) {
|
|
769
750
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
770
751
|
function enqueueError(bedrockError) {
|
|
@@ -798,10 +779,8 @@ var BedrockChatLanguageModel = class {
|
|
|
798
779
|
);
|
|
799
780
|
}
|
|
800
781
|
if (value.metadata) {
|
|
801
|
-
usage =
|
|
802
|
-
|
|
803
|
-
completionTokens: (_d = (_c = value.metadata.usage) == null ? void 0 : _c.outputTokens) != null ? _d : Number.NaN
|
|
804
|
-
};
|
|
782
|
+
usage.inputTokens = (_b = (_a = value.metadata.usage) == null ? void 0 : _a.inputTokens) != null ? _b : usage.inputTokens;
|
|
783
|
+
usage.outputTokens = (_d = (_c = value.metadata.usage) == null ? void 0 : _c.outputTokens) != null ? _d : usage.outputTokens;
|
|
805
784
|
const cacheUsage = ((_e = value.metadata.usage) == null ? void 0 : _e.cacheReadInputTokens) != null || ((_f = value.metadata.usage) == null ? void 0 : _f.cacheWriteInputTokens) != null ? {
|
|
806
785
|
usage: {
|
|
807
786
|
cacheReadInputTokens: (_h = (_g = value.metadata.usage) == null ? void 0 : _g.cacheReadInputTokens) != null ? _h : Number.NaN,
|
|
@@ -822,8 +801,8 @@ var BedrockChatLanguageModel = class {
|
|
|
822
801
|
}
|
|
823
802
|
if (((_k = value.contentBlockDelta) == null ? void 0 : _k.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
|
|
824
803
|
controller.enqueue({
|
|
825
|
-
type: "text
|
|
826
|
-
|
|
804
|
+
type: "text",
|
|
805
|
+
text: value.contentBlockDelta.delta.text
|
|
827
806
|
});
|
|
828
807
|
}
|
|
829
808
|
if (((_l = value.contentBlockDelta) == null ? void 0 : _l.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
|
|
@@ -831,18 +810,30 @@ var BedrockChatLanguageModel = class {
|
|
|
831
810
|
if ("text" in reasoningContent && reasoningContent.text) {
|
|
832
811
|
controller.enqueue({
|
|
833
812
|
type: "reasoning",
|
|
834
|
-
|
|
813
|
+
text: reasoningContent.text
|
|
835
814
|
});
|
|
836
815
|
} else if ("signature" in reasoningContent && reasoningContent.signature) {
|
|
837
816
|
controller.enqueue({
|
|
838
|
-
type: "reasoning
|
|
839
|
-
|
|
817
|
+
type: "reasoning",
|
|
818
|
+
text: "",
|
|
819
|
+
providerMetadata: {
|
|
820
|
+
bedrock: {
|
|
821
|
+
signature: reasoningContent.signature
|
|
822
|
+
}
|
|
823
|
+
}
|
|
840
824
|
});
|
|
825
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
841
826
|
} else if ("data" in reasoningContent && reasoningContent.data) {
|
|
842
827
|
controller.enqueue({
|
|
843
|
-
type: "
|
|
844
|
-
|
|
828
|
+
type: "reasoning",
|
|
829
|
+
text: "",
|
|
830
|
+
providerMetadata: {
|
|
831
|
+
bedrock: {
|
|
832
|
+
redactedData: reasoningContent.data
|
|
833
|
+
}
|
|
834
|
+
}
|
|
845
835
|
});
|
|
836
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
846
837
|
}
|
|
847
838
|
}
|
|
848
839
|
const contentBlockStart = value.contentBlockStart;
|
|
@@ -893,9 +884,8 @@ var BedrockChatLanguageModel = class {
|
|
|
893
884
|
}
|
|
894
885
|
})
|
|
895
886
|
),
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
warnings
|
|
887
|
+
// TODO request?
|
|
888
|
+
response: { headers: responseHeaders }
|
|
899
889
|
};
|
|
900
890
|
}
|
|
901
891
|
getUrl(modelId) {
|
|
@@ -903,116 +893,131 @@ var BedrockChatLanguageModel = class {
|
|
|
903
893
|
return `${this.config.baseUrl()}/model/${encodedModelId}`;
|
|
904
894
|
}
|
|
905
895
|
};
|
|
906
|
-
var
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
budgetTokens: import_zod2.z.number().nullish()
|
|
910
|
-
}).nullish();
|
|
911
|
-
var BedrockStopReasonSchema = import_zod2.z.union([
|
|
912
|
-
import_zod2.z.enum(BEDROCK_STOP_REASONS),
|
|
913
|
-
import_zod2.z.string()
|
|
896
|
+
var BedrockStopReasonSchema = import_zod3.z.union([
|
|
897
|
+
import_zod3.z.enum(BEDROCK_STOP_REASONS),
|
|
898
|
+
import_zod3.z.string()
|
|
914
899
|
]);
|
|
915
|
-
var BedrockToolUseSchema =
|
|
916
|
-
toolUseId:
|
|
917
|
-
name:
|
|
918
|
-
input:
|
|
900
|
+
var BedrockToolUseSchema = import_zod3.z.object({
|
|
901
|
+
toolUseId: import_zod3.z.string(),
|
|
902
|
+
name: import_zod3.z.string(),
|
|
903
|
+
input: import_zod3.z.unknown()
|
|
919
904
|
});
|
|
920
|
-
var BedrockReasoningTextSchema =
|
|
921
|
-
signature:
|
|
922
|
-
text:
|
|
905
|
+
var BedrockReasoningTextSchema = import_zod3.z.object({
|
|
906
|
+
signature: import_zod3.z.string().nullish(),
|
|
907
|
+
text: import_zod3.z.string()
|
|
923
908
|
});
|
|
924
|
-
var BedrockRedactedReasoningSchema =
|
|
925
|
-
data:
|
|
909
|
+
var BedrockRedactedReasoningSchema = import_zod3.z.object({
|
|
910
|
+
data: import_zod3.z.string()
|
|
926
911
|
});
|
|
927
|
-
var BedrockResponseSchema =
|
|
928
|
-
metrics:
|
|
929
|
-
latencyMs:
|
|
912
|
+
var BedrockResponseSchema = import_zod3.z.object({
|
|
913
|
+
metrics: import_zod3.z.object({
|
|
914
|
+
latencyMs: import_zod3.z.number()
|
|
930
915
|
}).nullish(),
|
|
931
|
-
output:
|
|
932
|
-
message:
|
|
933
|
-
content:
|
|
934
|
-
|
|
935
|
-
text:
|
|
916
|
+
output: import_zod3.z.object({
|
|
917
|
+
message: import_zod3.z.object({
|
|
918
|
+
content: import_zod3.z.array(
|
|
919
|
+
import_zod3.z.object({
|
|
920
|
+
text: import_zod3.z.string().nullish(),
|
|
936
921
|
toolUse: BedrockToolUseSchema.nullish(),
|
|
937
|
-
reasoningContent:
|
|
938
|
-
|
|
922
|
+
reasoningContent: import_zod3.z.union([
|
|
923
|
+
import_zod3.z.object({
|
|
939
924
|
reasoningText: BedrockReasoningTextSchema
|
|
940
925
|
}),
|
|
941
|
-
|
|
926
|
+
import_zod3.z.object({
|
|
942
927
|
redactedReasoning: BedrockRedactedReasoningSchema
|
|
943
928
|
})
|
|
944
929
|
]).nullish()
|
|
945
930
|
})
|
|
946
931
|
),
|
|
947
|
-
role:
|
|
932
|
+
role: import_zod3.z.string()
|
|
948
933
|
})
|
|
949
934
|
}),
|
|
950
935
|
stopReason: BedrockStopReasonSchema,
|
|
951
|
-
trace:
|
|
952
|
-
usage:
|
|
953
|
-
inputTokens:
|
|
954
|
-
outputTokens:
|
|
955
|
-
totalTokens:
|
|
956
|
-
cacheReadInputTokens:
|
|
957
|
-
cacheWriteInputTokens:
|
|
936
|
+
trace: import_zod3.z.unknown().nullish(),
|
|
937
|
+
usage: import_zod3.z.object({
|
|
938
|
+
inputTokens: import_zod3.z.number(),
|
|
939
|
+
outputTokens: import_zod3.z.number(),
|
|
940
|
+
totalTokens: import_zod3.z.number(),
|
|
941
|
+
cacheReadInputTokens: import_zod3.z.number().nullish(),
|
|
942
|
+
cacheWriteInputTokens: import_zod3.z.number().nullish()
|
|
958
943
|
})
|
|
959
944
|
});
|
|
960
|
-
var BedrockStreamSchema =
|
|
961
|
-
contentBlockDelta:
|
|
962
|
-
contentBlockIndex:
|
|
963
|
-
delta:
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
reasoningContent:
|
|
945
|
+
var BedrockStreamSchema = import_zod3.z.object({
|
|
946
|
+
contentBlockDelta: import_zod3.z.object({
|
|
947
|
+
contentBlockIndex: import_zod3.z.number(),
|
|
948
|
+
delta: import_zod3.z.union([
|
|
949
|
+
import_zod3.z.object({ text: import_zod3.z.string() }),
|
|
950
|
+
import_zod3.z.object({ toolUse: import_zod3.z.object({ input: import_zod3.z.string() }) }),
|
|
951
|
+
import_zod3.z.object({
|
|
952
|
+
reasoningContent: import_zod3.z.object({ text: import_zod3.z.string() })
|
|
968
953
|
}),
|
|
969
|
-
|
|
970
|
-
reasoningContent:
|
|
971
|
-
signature:
|
|
954
|
+
import_zod3.z.object({
|
|
955
|
+
reasoningContent: import_zod3.z.object({
|
|
956
|
+
signature: import_zod3.z.string()
|
|
972
957
|
})
|
|
973
958
|
}),
|
|
974
|
-
|
|
975
|
-
reasoningContent:
|
|
959
|
+
import_zod3.z.object({
|
|
960
|
+
reasoningContent: import_zod3.z.object({ data: import_zod3.z.string() })
|
|
976
961
|
})
|
|
977
962
|
]).nullish()
|
|
978
963
|
}).nullish(),
|
|
979
|
-
contentBlockStart:
|
|
980
|
-
contentBlockIndex:
|
|
981
|
-
start:
|
|
964
|
+
contentBlockStart: import_zod3.z.object({
|
|
965
|
+
contentBlockIndex: import_zod3.z.number(),
|
|
966
|
+
start: import_zod3.z.object({
|
|
982
967
|
toolUse: BedrockToolUseSchema.nullish()
|
|
983
968
|
}).nullish()
|
|
984
969
|
}).nullish(),
|
|
985
|
-
contentBlockStop:
|
|
986
|
-
contentBlockIndex:
|
|
970
|
+
contentBlockStop: import_zod3.z.object({
|
|
971
|
+
contentBlockIndex: import_zod3.z.number()
|
|
987
972
|
}).nullish(),
|
|
988
|
-
internalServerException:
|
|
989
|
-
messageStop:
|
|
990
|
-
additionalModelResponseFields:
|
|
973
|
+
internalServerException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
974
|
+
messageStop: import_zod3.z.object({
|
|
975
|
+
additionalModelResponseFields: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
991
976
|
stopReason: BedrockStopReasonSchema
|
|
992
977
|
}).nullish(),
|
|
993
|
-
metadata:
|
|
994
|
-
trace:
|
|
995
|
-
usage:
|
|
996
|
-
cacheReadInputTokens:
|
|
997
|
-
cacheWriteInputTokens:
|
|
998
|
-
inputTokens:
|
|
999
|
-
outputTokens:
|
|
978
|
+
metadata: import_zod3.z.object({
|
|
979
|
+
trace: import_zod3.z.unknown().nullish(),
|
|
980
|
+
usage: import_zod3.z.object({
|
|
981
|
+
cacheReadInputTokens: import_zod3.z.number().nullish(),
|
|
982
|
+
cacheWriteInputTokens: import_zod3.z.number().nullish(),
|
|
983
|
+
inputTokens: import_zod3.z.number(),
|
|
984
|
+
outputTokens: import_zod3.z.number()
|
|
1000
985
|
}).nullish()
|
|
1001
986
|
}).nullish(),
|
|
1002
|
-
modelStreamErrorException:
|
|
1003
|
-
throttlingException:
|
|
1004
|
-
validationException:
|
|
987
|
+
modelStreamErrorException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
988
|
+
throttlingException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
|
|
989
|
+
validationException: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
990
|
+
});
|
|
991
|
+
var bedrockReasoningMetadataSchema = import_zod3.z.object({
|
|
992
|
+
signature: import_zod3.z.string().optional(),
|
|
993
|
+
redactedData: import_zod3.z.string().optional()
|
|
1005
994
|
});
|
|
1006
995
|
|
|
1007
996
|
// src/bedrock-embedding-model.ts
|
|
1008
997
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1009
|
-
|
|
998
|
+
|
|
999
|
+
// src/bedrock-embedding-options.ts
|
|
1000
|
+
var import_zod4 = require("zod");
|
|
1001
|
+
var bedrockEmbeddingProviderOptions = import_zod4.z.object({
|
|
1002
|
+
/**
|
|
1003
|
+
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
1004
|
+
Only supported in amazon.titan-embed-text-v2:0.
|
|
1005
|
+
*/
|
|
1006
|
+
dimensions: import_zod4.z.union([import_zod4.z.literal(1024), import_zod4.z.literal(512), import_zod4.z.literal(256)]).optional(),
|
|
1007
|
+
/**
|
|
1008
|
+
Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
1009
|
+
Only supported in amazon.titan-embed-text-v2:0.
|
|
1010
|
+
*/
|
|
1011
|
+
normalize: import_zod4.z.boolean().optional()
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
// src/bedrock-embedding-model.ts
|
|
1015
|
+
var import_zod5 = require("zod");
|
|
1010
1016
|
var BedrockEmbeddingModel = class {
|
|
1011
|
-
constructor(modelId,
|
|
1017
|
+
constructor(modelId, config) {
|
|
1012
1018
|
this.modelId = modelId;
|
|
1013
|
-
this.settings = settings;
|
|
1014
1019
|
this.config = config;
|
|
1015
|
-
this.specificationVersion = "
|
|
1020
|
+
this.specificationVersion = "v2";
|
|
1016
1021
|
this.provider = "amazon-bedrock";
|
|
1017
1022
|
this.maxEmbeddingsPerCall = void 0;
|
|
1018
1023
|
this.supportsParallelCalls = true;
|
|
@@ -1024,13 +1029,20 @@ var BedrockEmbeddingModel = class {
|
|
|
1024
1029
|
async doEmbed({
|
|
1025
1030
|
values,
|
|
1026
1031
|
headers,
|
|
1027
|
-
abortSignal
|
|
1032
|
+
abortSignal,
|
|
1033
|
+
providerOptions
|
|
1028
1034
|
}) {
|
|
1035
|
+
var _a;
|
|
1036
|
+
const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
1037
|
+
provider: "bedrock",
|
|
1038
|
+
providerOptions,
|
|
1039
|
+
schema: bedrockEmbeddingProviderOptions
|
|
1040
|
+
})) != null ? _a : {};
|
|
1029
1041
|
const embedSingleText = async (inputText) => {
|
|
1030
1042
|
const args = {
|
|
1031
1043
|
inputText,
|
|
1032
|
-
dimensions:
|
|
1033
|
-
normalize:
|
|
1044
|
+
dimensions: bedrockOptions.dimensions,
|
|
1045
|
+
normalize: bedrockOptions.normalize
|
|
1034
1046
|
};
|
|
1035
1047
|
const url = this.getUrl(this.modelId);
|
|
1036
1048
|
const { value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
@@ -1065,9 +1077,9 @@ var BedrockEmbeddingModel = class {
|
|
|
1065
1077
|
);
|
|
1066
1078
|
}
|
|
1067
1079
|
};
|
|
1068
|
-
var BedrockEmbeddingResponseSchema =
|
|
1069
|
-
embedding:
|
|
1070
|
-
inputTextTokenCount:
|
|
1080
|
+
var BedrockEmbeddingResponseSchema = import_zod5.z.object({
|
|
1081
|
+
embedding: import_zod5.z.array(import_zod5.z.number()),
|
|
1082
|
+
inputTextTokenCount: import_zod5.z.number()
|
|
1071
1083
|
});
|
|
1072
1084
|
|
|
1073
1085
|
// src/bedrock-image-model.ts
|
|
@@ -1079,7 +1091,7 @@ var modelMaxImagesPerCall = {
|
|
|
1079
1091
|
};
|
|
1080
1092
|
|
|
1081
1093
|
// src/bedrock-image-model.ts
|
|
1082
|
-
var
|
|
1094
|
+
var import_zod6 = require("zod");
|
|
1083
1095
|
var BedrockImageModel = class {
|
|
1084
1096
|
constructor(modelId, settings, config) {
|
|
1085
1097
|
this.modelId = modelId;
|
|
@@ -1161,8 +1173,8 @@ var BedrockImageModel = class {
|
|
|
1161
1173
|
};
|
|
1162
1174
|
}
|
|
1163
1175
|
};
|
|
1164
|
-
var bedrockImageResponseSchema =
|
|
1165
|
-
images:
|
|
1176
|
+
var bedrockImageResponseSchema = import_zod6.z.object({
|
|
1177
|
+
images: import_zod6.z.array(import_zod6.z.string())
|
|
1166
1178
|
});
|
|
1167
1179
|
|
|
1168
1180
|
// src/headers-utils.ts
|
|
@@ -1284,26 +1296,26 @@ function createAmazonBedrock(options = {}) {
|
|
|
1284
1296
|
})}.amazonaws.com`
|
|
1285
1297
|
)) != null ? _b : `https://bedrock-runtime.us-east-1.amazonaws.com`;
|
|
1286
1298
|
};
|
|
1287
|
-
const createChatModel = (modelId
|
|
1299
|
+
const createChatModel = (modelId) => {
|
|
1288
1300
|
var _a;
|
|
1289
|
-
return new BedrockChatLanguageModel(modelId,
|
|
1301
|
+
return new BedrockChatLanguageModel(modelId, {
|
|
1290
1302
|
baseUrl: getBaseUrl,
|
|
1291
1303
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1292
1304
|
fetch: sigv4Fetch,
|
|
1293
1305
|
generateId: import_provider_utils7.generateId
|
|
1294
1306
|
});
|
|
1295
1307
|
};
|
|
1296
|
-
const provider = function(modelId
|
|
1308
|
+
const provider = function(modelId) {
|
|
1297
1309
|
if (new.target) {
|
|
1298
1310
|
throw new Error(
|
|
1299
1311
|
"The Amazon Bedrock model function cannot be called with the new keyword."
|
|
1300
1312
|
);
|
|
1301
1313
|
}
|
|
1302
|
-
return createChatModel(modelId
|
|
1314
|
+
return createChatModel(modelId);
|
|
1303
1315
|
};
|
|
1304
|
-
const createEmbeddingModel = (modelId
|
|
1316
|
+
const createEmbeddingModel = (modelId) => {
|
|
1305
1317
|
var _a;
|
|
1306
|
-
return new BedrockEmbeddingModel(modelId,
|
|
1318
|
+
return new BedrockEmbeddingModel(modelId, {
|
|
1307
1319
|
baseUrl: getBaseUrl,
|
|
1308
1320
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1309
1321
|
fetch: sigv4Fetch
|