@ai-sdk/amazon-bedrock 3.0.0-beta.2 → 3.0.0-beta.4

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 3.0.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - a10bf62: Fixes "Extra inputs are not permitted" error when using reasoning with Bedrock
8
+
9
+ ## 3.0.0-beta.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 3593385: fix(bedrock): resolve mime-types of document and images
14
+
3
15
  ## 3.0.0-beta.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -48,6 +48,23 @@ 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
70
  var import_v4 = require("zod/v4");
@@ -220,7 +237,6 @@ function getCachePoint(providerMetadata) {
220
237
  return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
221
238
  }
222
239
  async function convertToBedrockChatMessages(prompt) {
223
- var _a, _b, _c, _d;
224
240
  const blocks = groupIntoBlocks(prompt);
225
241
  let system = [];
226
242
  const messages = [];
@@ -267,19 +283,22 @@ async function convertToBedrockChatMessages(prompt) {
267
283
  });
268
284
  }
269
285
  if (part.mediaType.startsWith("image/")) {
270
- const bedrockImageFormat = part.mediaType === "image/*" ? void 0 : (_b = (_a = part.mediaType) == null ? void 0 : _a.split("/")) == null ? void 0 : _b[1];
271
286
  bedrockContent.push({
272
287
  image: {
273
- format: bedrockImageFormat,
288
+ format: getBedrockImageFormat(part.mediaType),
274
289
  source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
275
290
  }
276
291
  });
277
292
  } else {
293
+ if (!part.mediaType) {
294
+ throw new import_provider3.UnsupportedFunctionalityError({
295
+ functionality: "file without mime type",
296
+ message: "File mime type is required in user message part content"
297
+ });
298
+ }
278
299
  bedrockContent.push({
279
300
  document: {
280
- format: (_d = (_c = part.mediaType) == null ? void 0 : _c.split(
281
- "/"
282
- )) == null ? void 0 : _d[1],
301
+ format: getBedrockDocumentFormat(part.mediaType),
283
302
  name: generateDocumentName(),
284
303
  source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
285
304
  }
@@ -307,12 +326,9 @@ async function convertToBedrockChatMessages(prompt) {
307
326
  functionality: `media type: ${contentPart.mediaType}`
308
327
  });
309
328
  }
310
- const format = contentPart.mediaType.split("/")[1];
311
- if (!isBedrockImageFormat(format)) {
312
- throw new import_provider3.UnsupportedFunctionalityError({
313
- functionality: `media type: ${contentPart.mediaType}`
314
- });
315
- }
329
+ const format = getBedrockImageFormat(
330
+ contentPart.mediaType
331
+ );
316
332
  return {
317
333
  image: {
318
334
  format,
@@ -445,8 +461,31 @@ async function convertToBedrockChatMessages(prompt) {
445
461
  }
446
462
  return { system, messages };
447
463
  }
448
- function isBedrockImageFormat(format) {
449
- return ["jpeg", "png", "gif"].includes(format);
464
+ function getBedrockImageFormat(mimeType) {
465
+ if (!mimeType) {
466
+ throw new import_provider3.UnsupportedFunctionalityError({
467
+ functionality: "image without mime type",
468
+ message: "Image mime type is required in user message part content"
469
+ });
470
+ }
471
+ const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
472
+ if (!format) {
473
+ throw new import_provider3.UnsupportedFunctionalityError({
474
+ functionality: `image mime type: ${mimeType}`,
475
+ message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
476
+ });
477
+ }
478
+ return format;
479
+ }
480
+ function getBedrockDocumentFormat(mimeType) {
481
+ const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
482
+ if (!format) {
483
+ throw new import_provider3.UnsupportedFunctionalityError({
484
+ functionality: `file mime type: ${mimeType}`,
485
+ message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
486
+ });
487
+ }
488
+ return format;
450
489
  }
451
490
  function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
452
491
  return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
@@ -597,7 +636,7 @@ var BedrockChatLanguageModel = class {
597
636
  }
598
637
  bedrockOptions.additionalModelRequestFields = {
599
638
  ...bedrockOptions.additionalModelRequestFields,
600
- reasoningConfig: {
639
+ thinking: {
601
640
  type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
602
641
  budget_tokens: thinkingBudget
603
642
  }
@@ -620,6 +659,7 @@ var BedrockChatLanguageModel = class {
620
659
  });
621
660
  }
622
661
  const { toolConfig, toolWarnings } = prepareTools({ tools, toolChoice });
662
+ const { reasoningConfig: _, ...filteredBedrockOptions } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
623
663
  return {
624
664
  command: {
625
665
  system,
@@ -628,7 +668,7 @@ var BedrockChatLanguageModel = class {
628
668
  ...Object.keys(inferenceConfig).length > 0 && {
629
669
  inferenceConfig
630
670
  },
631
- ...providerOptions == null ? void 0 : providerOptions.bedrock,
671
+ ...filteredBedrockOptions,
632
672
  ...((_e = toolConfig.tools) == null ? void 0 : _e.length) ? { toolConfig } : {}
633
673
  },
634
674
  warnings: [...warnings, ...toolWarnings]