@ai-sdk/amazon-bedrock 3.0.0-canary.1 → 3.0.0-canary.3
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 +21 -0
- package/dist/index.js +50 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -103
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a166433]
|
|
8
|
+
- Updated dependencies [abf9a79]
|
|
9
|
+
- Updated dependencies [9f95b35]
|
|
10
|
+
- Updated dependencies [0a87932]
|
|
11
|
+
- Updated dependencies [6dc848c]
|
|
12
|
+
- @ai-sdk/provider-utils@3.0.0-canary.3
|
|
13
|
+
- @ai-sdk/provider@2.0.0-canary.2
|
|
14
|
+
|
|
15
|
+
## 3.0.0-canary.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [c57e248]
|
|
20
|
+
- Updated dependencies [33f4a6a]
|
|
21
|
+
- @ai-sdk/provider@2.0.0-canary.1
|
|
22
|
+
- @ai-sdk/provider-utils@3.0.0-canary.2
|
|
23
|
+
|
|
3
24
|
## 3.0.0-canary.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -130,9 +130,11 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
130
130
|
|
|
131
131
|
// src/bedrock-prepare-tools.ts
|
|
132
132
|
var import_provider2 = require("@ai-sdk/provider");
|
|
133
|
-
function prepareTools(
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
function prepareTools({
|
|
134
|
+
tools,
|
|
135
|
+
toolChoice
|
|
136
|
+
}) {
|
|
137
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
136
138
|
if (tools == null) {
|
|
137
139
|
return {
|
|
138
140
|
toolConfig: { tools: void 0, toolChoice: void 0 },
|
|
@@ -156,7 +158,6 @@ function prepareTools(mode) {
|
|
|
156
158
|
});
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
|
-
const toolChoice = mode.toolChoice;
|
|
160
161
|
if (toolChoice == null) {
|
|
161
162
|
return {
|
|
162
163
|
toolConfig: { tools: bedrockTools, toolChoice: void 0 },
|
|
@@ -191,7 +192,7 @@ function prepareTools(mode) {
|
|
|
191
192
|
default: {
|
|
192
193
|
const _exhaustiveCheck = type;
|
|
193
194
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
194
|
-
functionality: `
|
|
195
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
195
196
|
});
|
|
196
197
|
}
|
|
197
198
|
}
|
|
@@ -206,7 +207,7 @@ function getCachePoint(providerMetadata) {
|
|
|
206
207
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
207
208
|
}
|
|
208
209
|
function convertToBedrockChatMessages(prompt) {
|
|
209
|
-
var _a, _b, _c, _d
|
|
210
|
+
var _a, _b, _c, _d;
|
|
210
211
|
const blocks = groupIntoBlocks(prompt);
|
|
211
212
|
let system = [];
|
|
212
213
|
const messages = [];
|
|
@@ -223,7 +224,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
223
224
|
}
|
|
224
225
|
for (const message of block.messages) {
|
|
225
226
|
system.push({ text: message.content });
|
|
226
|
-
if (getCachePoint(message.
|
|
227
|
+
if (getCachePoint(message.providerOptions)) {
|
|
227
228
|
system.push(BEDROCK_CACHE_POINT);
|
|
228
229
|
}
|
|
229
230
|
}
|
|
@@ -232,7 +233,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
232
233
|
case "user": {
|
|
233
234
|
const bedrockContent = [];
|
|
234
235
|
for (const message of block.messages) {
|
|
235
|
-
const { role, content,
|
|
236
|
+
const { role, content, providerOptions } = message;
|
|
236
237
|
switch (role) {
|
|
237
238
|
case "user": {
|
|
238
239
|
for (let j = 0; j < content.length; j++) {
|
|
@@ -244,43 +245,33 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
244
245
|
});
|
|
245
246
|
break;
|
|
246
247
|
}
|
|
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
248
|
case "file": {
|
|
268
249
|
if (part.data instanceof URL) {
|
|
269
250
|
throw new import_provider3.UnsupportedFunctionalityError({
|
|
270
|
-
functionality: "File
|
|
251
|
+
functionality: "File URL data"
|
|
271
252
|
});
|
|
272
253
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
source: {
|
|
280
|
-
bytes: part.data
|
|
254
|
+
if (part.mediaType.startsWith("image/")) {
|
|
255
|
+
const bedrockImageFormat = part.mediaType === "image/*" ? void 0 : (_b = (_a = part.mediaType) == null ? void 0 : _a.split("/")) == null ? void 0 : _b[1];
|
|
256
|
+
bedrockContent.push({
|
|
257
|
+
image: {
|
|
258
|
+
format: bedrockImageFormat,
|
|
259
|
+
source: { bytes: part.data }
|
|
281
260
|
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
261
|
+
});
|
|
262
|
+
} else {
|
|
263
|
+
bedrockContent.push({
|
|
264
|
+
document: {
|
|
265
|
+
format: (_d = (_c = part.mediaType) == null ? void 0 : _c.split(
|
|
266
|
+
"/"
|
|
267
|
+
)) == null ? void 0 : _d[1],
|
|
268
|
+
name: generateFileId(),
|
|
269
|
+
source: {
|
|
270
|
+
bytes: part.data
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
284
275
|
break;
|
|
285
276
|
}
|
|
286
277
|
}
|
|
@@ -297,12 +288,12 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
297
288
|
text: part2.text
|
|
298
289
|
};
|
|
299
290
|
case "image":
|
|
300
|
-
if (!part2.
|
|
291
|
+
if (!part2.mediaType) {
|
|
301
292
|
throw new Error(
|
|
302
293
|
"Image mime type is required in tool result part content"
|
|
303
294
|
);
|
|
304
295
|
}
|
|
305
|
-
const format = part2.
|
|
296
|
+
const format = part2.mediaType.split("/")[1];
|
|
306
297
|
if (!isBedrockImageFormat(format)) {
|
|
307
298
|
throw new Error(
|
|
308
299
|
`Unsupported image format: ${format}`
|
|
@@ -332,7 +323,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
332
323
|
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
333
324
|
}
|
|
334
325
|
}
|
|
335
|
-
if (getCachePoint(
|
|
326
|
+
if (getCachePoint(providerOptions)) {
|
|
336
327
|
bedrockContent.push(BEDROCK_CACHE_POINT);
|
|
337
328
|
}
|
|
338
329
|
}
|
|
@@ -406,7 +397,7 @@ function convertToBedrockChatMessages(prompt) {
|
|
|
406
397
|
}
|
|
407
398
|
}
|
|
408
399
|
}
|
|
409
|
-
if (getCachePoint(message.
|
|
400
|
+
if (getCachePoint(message.providerOptions)) {
|
|
410
401
|
bedrockContent.push(BEDROCK_CACHE_POINT);
|
|
411
402
|
}
|
|
412
403
|
}
|
|
@@ -504,7 +495,6 @@ var BedrockChatLanguageModel = class {
|
|
|
504
495
|
this.supportsImageUrls = false;
|
|
505
496
|
}
|
|
506
497
|
getArgs({
|
|
507
|
-
mode,
|
|
508
498
|
prompt,
|
|
509
499
|
maxTokens,
|
|
510
500
|
temperature,
|
|
@@ -515,10 +505,11 @@ var BedrockChatLanguageModel = class {
|
|
|
515
505
|
stopSequences,
|
|
516
506
|
responseFormat,
|
|
517
507
|
seed,
|
|
518
|
-
|
|
508
|
+
tools,
|
|
509
|
+
toolChoice,
|
|
510
|
+
providerOptions
|
|
519
511
|
}) {
|
|
520
512
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
521
|
-
const type = mode.type;
|
|
522
513
|
const warnings = [];
|
|
523
514
|
if (frequencyPenalty != null) {
|
|
524
515
|
warnings.push({
|
|
@@ -553,7 +544,7 @@ var BedrockChatLanguageModel = class {
|
|
|
553
544
|
}
|
|
554
545
|
const { system, messages } = convertToBedrockChatMessages(prompt);
|
|
555
546
|
const reasoningConfigOptions = BedrockReasoningConfigOptionsSchema.safeParse(
|
|
556
|
-
(_a =
|
|
547
|
+
(_a = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _a.reasoning_config
|
|
557
548
|
);
|
|
558
549
|
if (!reasoningConfigOptions.success) {
|
|
559
550
|
throw new import_provider4.InvalidArgumentError({
|
|
@@ -600,58 +591,20 @@ var BedrockChatLanguageModel = class {
|
|
|
600
591
|
details: "topP is not supported when thinking is enabled"
|
|
601
592
|
});
|
|
602
593
|
}
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
594
|
+
const { toolConfig, toolWarnings } = prepareTools({ tools, toolChoice });
|
|
595
|
+
return {
|
|
596
|
+
command: {
|
|
597
|
+
system,
|
|
598
|
+
messages,
|
|
599
|
+
additionalModelRequestFields: this.settings.additionalModelRequestFields,
|
|
600
|
+
...Object.keys(inferenceConfig).length > 0 && {
|
|
601
|
+
inferenceConfig
|
|
602
|
+
},
|
|
603
|
+
...providerOptions == null ? void 0 : providerOptions.bedrock,
|
|
604
|
+
...((_g = toolConfig.tools) == null ? void 0 : _g.length) ? { toolConfig } : {}
|
|
608
605
|
},
|
|
609
|
-
|
|
610
|
-
...providerMetadata == null ? void 0 : providerMetadata.bedrock
|
|
606
|
+
warnings: [...warnings, ...toolWarnings]
|
|
611
607
|
};
|
|
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
608
|
}
|
|
656
609
|
async doGenerate(options) {
|
|
657
610
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|