@ai-sdk/amazon-bedrock 3.0.0-beta.1 → 3.0.0-beta.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 +16 -0
- package/dist/index.d.mts +4 -27
- package/dist/index.d.ts +4 -27
- package/dist/index.js +140 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
postJsonToApi,
|
|
16
16
|
resolve
|
|
17
17
|
} from "@ai-sdk/provider-utils";
|
|
18
|
-
import { z as z3 } from "zod";
|
|
18
|
+
import { z as z3 } from "zod/v4";
|
|
19
19
|
|
|
20
20
|
// src/bedrock-api-types.ts
|
|
21
21
|
var BEDROCK_CACHE_POINT = {
|
|
@@ -33,16 +33,33 @@ var BEDROCK_STOP_REASONS = [
|
|
|
33
33
|
"tool-calls",
|
|
34
34
|
"tool_use"
|
|
35
35
|
];
|
|
36
|
+
var BEDROCK_IMAGE_MIME_TYPES = {
|
|
37
|
+
"image/jpeg": "jpeg",
|
|
38
|
+
"image/png": "png",
|
|
39
|
+
"image/gif": "gif",
|
|
40
|
+
"image/webp": "webp"
|
|
41
|
+
};
|
|
42
|
+
var BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
43
|
+
"application/pdf": "pdf",
|
|
44
|
+
"text/csv": "csv",
|
|
45
|
+
"application/msword": "doc",
|
|
46
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
47
|
+
"application/vnd.ms-excel": "xls",
|
|
48
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
49
|
+
"text/html": "html",
|
|
50
|
+
"text/plain": "txt",
|
|
51
|
+
"text/markdown": "md"
|
|
52
|
+
};
|
|
36
53
|
|
|
37
54
|
// src/bedrock-chat-options.ts
|
|
38
|
-
import { z } from "zod";
|
|
55
|
+
import { z } from "zod/v4";
|
|
39
56
|
var bedrockProviderOptions = z.object({
|
|
40
57
|
/**
|
|
41
58
|
* Additional inference parameters that the model supports,
|
|
42
59
|
* beyond the base set of inference parameters that Converse
|
|
43
60
|
* supports in the inferenceConfig field
|
|
44
61
|
*/
|
|
45
|
-
additionalModelRequestFields: z.record(z.any()).optional(),
|
|
62
|
+
additionalModelRequestFields: z.record(z.string(), z.any()).optional(),
|
|
46
63
|
reasoningConfig: z.object({
|
|
47
64
|
type: z.union([z.literal("enabled"), z.literal("disabled")]).optional(),
|
|
48
65
|
budgetTokens: z.number().optional()
|
|
@@ -50,7 +67,7 @@ var bedrockProviderOptions = z.object({
|
|
|
50
67
|
});
|
|
51
68
|
|
|
52
69
|
// src/bedrock-error.ts
|
|
53
|
-
import { z as z2 } from "zod";
|
|
70
|
+
import { z as z2 } from "zod/v4";
|
|
54
71
|
var BedrockErrorSchema = z2.object({
|
|
55
72
|
message: z2.string(),
|
|
56
73
|
type: z2.string().nullish()
|
|
@@ -213,7 +230,6 @@ function getCachePoint(providerMetadata) {
|
|
|
213
230
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
214
231
|
}
|
|
215
232
|
async function convertToBedrockChatMessages(prompt) {
|
|
216
|
-
var _a, _b, _c, _d;
|
|
217
233
|
const blocks = groupIntoBlocks(prompt);
|
|
218
234
|
let system = [];
|
|
219
235
|
const messages = [];
|
|
@@ -260,19 +276,22 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
260
276
|
});
|
|
261
277
|
}
|
|
262
278
|
if (part.mediaType.startsWith("image/")) {
|
|
263
|
-
const bedrockImageFormat = part.mediaType === "image/*" ? void 0 : (_b = (_a = part.mediaType) == null ? void 0 : _a.split("/")) == null ? void 0 : _b[1];
|
|
264
279
|
bedrockContent.push({
|
|
265
280
|
image: {
|
|
266
|
-
format:
|
|
281
|
+
format: getBedrockImageFormat(part.mediaType),
|
|
267
282
|
source: { bytes: convertToBase64(part.data) }
|
|
268
283
|
}
|
|
269
284
|
});
|
|
270
285
|
} else {
|
|
286
|
+
if (!part.mediaType) {
|
|
287
|
+
throw new UnsupportedFunctionalityError2({
|
|
288
|
+
functionality: "file without mime type",
|
|
289
|
+
message: "File mime type is required in user message part content"
|
|
290
|
+
});
|
|
291
|
+
}
|
|
271
292
|
bedrockContent.push({
|
|
272
293
|
document: {
|
|
273
|
-
format: (
|
|
274
|
-
"/"
|
|
275
|
-
)) == null ? void 0 : _d[1],
|
|
294
|
+
format: getBedrockDocumentFormat(part.mediaType),
|
|
276
295
|
name: generateDocumentName(),
|
|
277
296
|
source: { bytes: convertToBase64(part.data) }
|
|
278
297
|
}
|
|
@@ -300,12 +319,9 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
300
319
|
functionality: `media type: ${contentPart.mediaType}`
|
|
301
320
|
});
|
|
302
321
|
}
|
|
303
|
-
const format =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
functionality: `media type: ${contentPart.mediaType}`
|
|
307
|
-
});
|
|
308
|
-
}
|
|
322
|
+
const format = getBedrockImageFormat(
|
|
323
|
+
contentPart.mediaType
|
|
324
|
+
);
|
|
309
325
|
return {
|
|
310
326
|
image: {
|
|
311
327
|
format,
|
|
@@ -438,8 +454,31 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
438
454
|
}
|
|
439
455
|
return { system, messages };
|
|
440
456
|
}
|
|
441
|
-
function
|
|
442
|
-
|
|
457
|
+
function getBedrockImageFormat(mimeType) {
|
|
458
|
+
if (!mimeType) {
|
|
459
|
+
throw new UnsupportedFunctionalityError2({
|
|
460
|
+
functionality: "image without mime type",
|
|
461
|
+
message: "Image mime type is required in user message part content"
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
|
|
465
|
+
if (!format) {
|
|
466
|
+
throw new UnsupportedFunctionalityError2({
|
|
467
|
+
functionality: `image mime type: ${mimeType}`,
|
|
468
|
+
message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
return format;
|
|
472
|
+
}
|
|
473
|
+
function getBedrockDocumentFormat(mimeType) {
|
|
474
|
+
const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
|
|
475
|
+
if (!format) {
|
|
476
|
+
throw new UnsupportedFunctionalityError2({
|
|
477
|
+
functionality: `file mime type: ${mimeType}`,
|
|
478
|
+
message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
return format;
|
|
443
482
|
}
|
|
444
483
|
function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
|
|
445
484
|
return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
|
|
@@ -1028,9 +1067,9 @@ var BedrockStreamSchema = z3.object({
|
|
|
1028
1067
|
contentBlockStop: z3.object({
|
|
1029
1068
|
contentBlockIndex: z3.number()
|
|
1030
1069
|
}).nullish(),
|
|
1031
|
-
internalServerException: z3.record(z3.unknown()).nullish(),
|
|
1070
|
+
internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1032
1071
|
messageStop: z3.object({
|
|
1033
|
-
additionalModelResponseFields: z3.record(z3.unknown()).nullish(),
|
|
1072
|
+
additionalModelResponseFields: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1034
1073
|
stopReason: BedrockStopReasonSchema
|
|
1035
1074
|
}).nullish(),
|
|
1036
1075
|
metadata: z3.object({
|
|
@@ -1042,9 +1081,9 @@ var BedrockStreamSchema = z3.object({
|
|
|
1042
1081
|
outputTokens: z3.number()
|
|
1043
1082
|
}).nullish()
|
|
1044
1083
|
}).nullish(),
|
|
1045
|
-
modelStreamErrorException: z3.record(z3.unknown()).nullish(),
|
|
1046
|
-
throttlingException: z3.record(z3.unknown()).nullish(),
|
|
1047
|
-
validationException: z3.record(z3.unknown()).nullish()
|
|
1084
|
+
modelStreamErrorException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1085
|
+
throttlingException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1086
|
+
validationException: z3.record(z3.string(), z3.unknown()).nullish()
|
|
1048
1087
|
});
|
|
1049
1088
|
var bedrockReasoningMetadataSchema = z3.object({
|
|
1050
1089
|
signature: z3.string().optional(),
|
|
@@ -1065,7 +1104,7 @@ import {
|
|
|
1065
1104
|
} from "@ai-sdk/provider-utils";
|
|
1066
1105
|
|
|
1067
1106
|
// src/bedrock-embedding-options.ts
|
|
1068
|
-
import { z as z4 } from "zod";
|
|
1107
|
+
import { z as z4 } from "zod/v4";
|
|
1069
1108
|
var bedrockEmbeddingProviderOptions = z4.object({
|
|
1070
1109
|
/**
|
|
1071
1110
|
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
@@ -1080,7 +1119,7 @@ var bedrockEmbeddingProviderOptions = z4.object({
|
|
|
1080
1119
|
});
|
|
1081
1120
|
|
|
1082
1121
|
// src/bedrock-embedding-model.ts
|
|
1083
|
-
import { z as z5 } from "zod";
|
|
1122
|
+
import { z as z5 } from "zod/v4";
|
|
1084
1123
|
var BedrockEmbeddingModel = class {
|
|
1085
1124
|
constructor(modelId, config) {
|
|
1086
1125
|
this.modelId = modelId;
|
|
@@ -1162,7 +1201,7 @@ var modelMaxImagesPerCall = {
|
|
|
1162
1201
|
};
|
|
1163
1202
|
|
|
1164
1203
|
// src/bedrock-image-model.ts
|
|
1165
|
-
import { z as z6 } from "zod";
|
|
1204
|
+
import { z as z6 } from "zod/v4";
|
|
1166
1205
|
var BedrockImageModel = class {
|
|
1167
1206
|
constructor(modelId, config) {
|
|
1168
1207
|
this.modelId = modelId;
|