@ai-sdk/amazon-bedrock 5.0.37 → 5.0.39

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.
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "5.0.37" : "0.0.0-test";
38
+ var VERSION = true ? "5.0.39" : "0.0.0-test";
39
39
 
40
40
  // src/amazon-bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -23,7 +23,7 @@ import {
23
23
  import { AwsV4Signer } from "aws4fetch";
24
24
 
25
25
  // src/version.ts
26
- var VERSION = true ? "5.0.37" : "0.0.0-test";
26
+ var VERSION = true ? "5.0.39" : "0.0.0-test";
27
27
 
28
28
  // src/amazon-bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -508,6 +508,11 @@ console.log(amazonResult.reasoningText); // reasoning text
508
508
  console.log(amazonResult.text); // text response
509
509
  ```
510
510
 
511
+ For Anthropic models, Bedrock's `maxTokens` limit includes both thinking and
512
+ final text. The provider therefore adds `budgetTokens` to `maxOutputTokens`
513
+ when setting `maxTokens`. When `maxOutputTokens` is omitted, the provider adds
514
+ `budgetTokens` to the default of `4096`.
515
+
511
516
  See [AI SDK UI: Chatbot](/docs/ai-sdk-ui/chatbot#reasoning) for more details
512
517
  on how to integrate reasoning into your chatbot.
513
518
 
@@ -1593,6 +1598,11 @@ console.log(reasoning); // reasoning details including redacted reasoning
1593
1598
  console.log(text); // text response
1594
1599
  ```
1595
1600
 
1601
+ Anthropic's `max_tokens` limit includes both thinking and final text. To reserve
1602
+ room for both, the provider adds `budgetTokens` to `maxOutputTokens` when
1603
+ setting `max_tokens`. For known models, the combined value is capped at the
1604
+ model's maximum output token limit.
1605
+
1596
1606
  See [AI SDK UI: Chatbot](/docs/ai-sdk-ui/chatbot#reasoning) for more details
1597
1607
  on how to integrate reasoning into your chatbot.
1598
1608
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "5.0.37",
3
+ "version": "5.0.39",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -44,10 +44,10 @@
44
44
  "@smithy/eventstream-codec": "^4.3.3",
45
45
  "@smithy/util-utf8": "^4.3.3",
46
46
  "aws4fetch": "^1.0.20",
47
- "@ai-sdk/anthropic": "4.0.25",
48
- "@ai-sdk/openai": "4.0.25",
47
+ "@ai-sdk/anthropic": "4.0.26",
48
+ "@ai-sdk/openai": "4.0.26",
49
49
  "@ai-sdk/provider": "4.0.4",
50
- "@ai-sdk/provider-utils": "5.0.16"
50
+ "@ai-sdk/provider-utils": "5.0.17"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "22.19.19",
@@ -150,6 +150,26 @@ export type AmazonBedrockDocumentFormat =
150
150
  AmazonBedrockDocumentFormats[keyof AmazonBedrockDocumentFormats];
151
151
  export type AmazonBedrockDocumentMimeType = keyof AmazonBedrockDocumentFormats;
152
152
 
153
+ /**
154
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_VideoBlock.html
155
+ */
156
+ export const BEDROCK_VIDEO_MIME_TYPES = {
157
+ 'video/x-matroska': 'mkv',
158
+ 'video/quicktime': 'mov',
159
+ 'video/mp4': 'mp4',
160
+ 'video/webm': 'webm',
161
+ 'video/x-flv': 'flv',
162
+ 'video/mpeg': 'mpeg',
163
+ 'video/mpg': 'mpg',
164
+ 'video/wmv': 'wmv',
165
+ 'video/x-ms-wmv': 'wmv',
166
+ 'video/3gpp': 'three_gp',
167
+ } as const;
168
+ type AmazonBedrockVideoFormats = typeof BEDROCK_VIDEO_MIME_TYPES;
169
+ export type AmazonBedrockVideoFormat =
170
+ AmazonBedrockVideoFormats[keyof AmazonBedrockVideoFormats];
171
+ export type AmazonBedrockVideoMimeType = keyof AmazonBedrockVideoFormats;
172
+
153
173
  export interface AmazonBedrockDocumentBlock {
154
174
  document: {
155
175
  format: AmazonBedrockDocumentFormat;
@@ -182,6 +202,21 @@ export interface AmazonBedrockImageBlock {
182
202
  };
183
203
  }
184
204
 
205
+ export interface AmazonBedrockVideoBlock {
206
+ video: {
207
+ format: AmazonBedrockVideoFormat;
208
+ source:
209
+ | {
210
+ bytes: string;
211
+ }
212
+ | {
213
+ s3Location: {
214
+ uri: string;
215
+ };
216
+ };
217
+ };
218
+ }
219
+
185
220
  export interface AmazonBedrockToolResultBlock {
186
221
  toolResult: {
187
222
  toolUseId: string;
@@ -189,6 +224,7 @@ export interface AmazonBedrockToolResultBlock {
189
224
  | AmazonBedrockTextBlock
190
225
  | AmazonBedrockImageBlock
191
226
  | AmazonBedrockDocumentBlock
227
+ | AmazonBedrockVideoBlock
192
228
  >;
193
229
  };
194
230
  }
@@ -226,6 +262,7 @@ export type AmazonBedrockContentBlock =
226
262
  | AmazonBedrockDocumentBlock
227
263
  | AmazonBedrockGuardrailConverseContentBlock
228
264
  | AmazonBedrockImageBlock
265
+ | AmazonBedrockVideoBlock
229
266
  | AmazonBedrockTextBlock
230
267
  | AmazonBedrockToolResultBlock
231
268
  | AmazonBedrockToolUseBlock
@@ -486,6 +486,7 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
486
486
 
487
487
  readonly supportedUrls: Record<string, RegExp[]> = {
488
488
  'image/*': [/^s3:\/\//],
489
+ 'video/*': [/^s3:\/\//],
489
490
  };
490
491
 
491
492
  private async getHeaders({
@@ -18,6 +18,7 @@ import {
18
18
  import {
19
19
  BEDROCK_DOCUMENT_MIME_TYPES,
20
20
  BEDROCK_IMAGE_MIME_TYPES,
21
+ BEDROCK_VIDEO_MIME_TYPES,
21
22
  type AmazonBedrockAssistantMessage,
22
23
  type AmazonBedrockCachePoint,
23
24
  type AmazonBedrockDocumentFormat,
@@ -28,6 +29,9 @@ import {
28
29
  type AmazonBedrockMessages,
29
30
  type AmazonBedrockSystemMessages,
30
31
  type AmazonBedrockUserMessage,
32
+ type AmazonBedrockVideoBlock,
33
+ type AmazonBedrockVideoFormat,
34
+ type AmazonBedrockVideoMimeType,
31
35
  } from './amazon-bedrock-api-types';
32
36
  import { amazonBedrockFilePartProviderOptions } from './amazon-bedrock-chat-language-model-options';
33
37
  import { amazonBedrockReasoningMetadataSchema } from './amazon-bedrock-reasoning-metadata';
@@ -64,13 +68,15 @@ function sanitizeToolName(toolName: string): string {
64
68
  return toolName.replace(/[^a-zA-Z0-9_-]/g, '') || '_';
65
69
  }
66
70
 
67
- function getAmazonBedrockImageSource({
71
+ function getAmazonBedrockMediaSource({
68
72
  data,
69
73
  functionality,
70
74
  }: {
71
75
  data: Extract<LanguageModelV4FilePart['data'], { type: 'data' | 'url' }>;
72
76
  functionality: string;
73
- }): AmazonBedrockImageBlock['image']['source'] {
77
+ }):
78
+ | AmazonBedrockImageBlock['image']['source']
79
+ | AmazonBedrockVideoBlock['video']['source'] {
74
80
  switch (data.type) {
75
81
  case 'data':
76
82
  return { bytes: convertToBase64(data.data) };
@@ -178,21 +184,39 @@ export async function convertToAmazonBedrockChatMessages(
178
184
 
179
185
  const fullMediaType = resolveFullMediaType({ part });
180
186
 
181
- if (getTopLevelMediaType(fullMediaType) !== 'image') {
182
- throw new UnsupportedFunctionalityError({
183
- functionality: 'File URL data',
184
- });
185
- }
186
-
187
- amazonBedrockContent.push({
188
- image: {
189
- format: getAmazonBedrockImageFormat(fullMediaType),
190
- source: getAmazonBedrockImageSource({
191
- data: part.data,
187
+ switch (getTopLevelMediaType(fullMediaType)) {
188
+ case 'image': {
189
+ amazonBedrockContent.push({
190
+ image: {
191
+ format:
192
+ getAmazonBedrockImageFormat(fullMediaType),
193
+ source: getAmazonBedrockMediaSource({
194
+ data: part.data,
195
+ functionality: 'File URL data',
196
+ }),
197
+ },
198
+ });
199
+ break;
200
+ }
201
+ case 'video': {
202
+ amazonBedrockContent.push({
203
+ video: {
204
+ format:
205
+ getAmazonBedrockVideoFormat(fullMediaType),
206
+ source: getAmazonBedrockMediaSource({
207
+ data: part.data,
208
+ functionality: 'File URL data',
209
+ }),
210
+ },
211
+ });
212
+ break;
213
+ }
214
+ default: {
215
+ throw new UnsupportedFunctionalityError({
192
216
  functionality: 'File URL data',
193
- }),
194
- },
195
- });
217
+ });
218
+ }
219
+ }
196
220
  break;
197
221
  }
198
222
  case 'text': {
@@ -225,37 +249,54 @@ export async function convertToAmazonBedrockChatMessages(
225
249
  case 'data': {
226
250
  const fullMediaType = resolveFullMediaType({ part });
227
251
 
228
- if (getTopLevelMediaType(fullMediaType) === 'image') {
229
- amazonBedrockContent.push({
230
- image: {
231
- format:
232
- getAmazonBedrockImageFormat(fullMediaType),
233
- source: getAmazonBedrockImageSource({
234
- data: part.data,
235
- functionality: 'File URL data',
236
- }),
237
- },
238
- });
239
- } else {
240
- const enableCitations = await shouldEnableCitations(
241
- part.providerOptions,
242
- );
243
-
244
- amazonBedrockContent.push({
245
- document: {
246
- format:
247
- getAmazonBedrockDocumentFormat(fullMediaType),
248
- name: part.filename
249
- ? stripFileExtension(part.filename)
250
- : generateDocumentName(),
251
- source: {
252
- bytes: convertToBase64(part.data.data),
252
+ switch (getTopLevelMediaType(fullMediaType)) {
253
+ case 'image': {
254
+ amazonBedrockContent.push({
255
+ image: {
256
+ format:
257
+ getAmazonBedrockImageFormat(fullMediaType),
258
+ source: getAmazonBedrockMediaSource({
259
+ data: part.data,
260
+ functionality: 'File URL data',
261
+ }),
253
262
  },
254
- ...(enableCitations && {
255
- citations: { enabled: true },
256
- }),
257
- },
258
- });
263
+ });
264
+ break;
265
+ }
266
+ case 'video': {
267
+ amazonBedrockContent.push({
268
+ video: {
269
+ format:
270
+ getAmazonBedrockVideoFormat(fullMediaType),
271
+ source: getAmazonBedrockMediaSource({
272
+ data: part.data,
273
+ functionality: 'File URL data',
274
+ }),
275
+ },
276
+ });
277
+ break;
278
+ }
279
+ default: {
280
+ const enableCitations = await shouldEnableCitations(
281
+ part.providerOptions,
282
+ );
283
+
284
+ amazonBedrockContent.push({
285
+ document: {
286
+ format:
287
+ getAmazonBedrockDocumentFormat(fullMediaType),
288
+ name: part.filename
289
+ ? stripFileExtension(part.filename)
290
+ : generateDocumentName(),
291
+ source: {
292
+ bytes: convertToBase64(part.data.data),
293
+ },
294
+ ...(enableCitations && {
295
+ citations: { enabled: true },
296
+ }),
297
+ },
298
+ });
299
+ }
259
300
  }
260
301
  break;
261
302
  }
@@ -300,51 +341,68 @@ export async function convertToAmazonBedrockChatMessages(
300
341
  part: contentPart,
301
342
  });
302
343
 
303
- if (
304
- getTopLevelMediaType(fullMediaType) !== 'image'
305
- ) {
306
- if (contentPart.data.type !== 'data') {
307
- throw new UnsupportedFunctionalityError({
308
- functionality: `tool result file data of type "${contentPart.data.type}"`,
309
- });
344
+ switch (getTopLevelMediaType(fullMediaType)) {
345
+ case 'image': {
346
+ return {
347
+ image: {
348
+ format:
349
+ getAmazonBedrockImageFormat(
350
+ fullMediaType,
351
+ ),
352
+ source: getAmazonBedrockMediaSource({
353
+ data: contentPart.data,
354
+ functionality: `tool result file data of type "${contentPart.data.type}"`,
355
+ }),
356
+ },
357
+ };
310
358
  }
311
-
312
- const enableCitations =
313
- await shouldEnableCitations(
314
- contentPart.providerOptions,
315
- );
316
-
317
- return {
318
- document: {
319
- format:
320
- getAmazonBedrockDocumentFormat(
321
- fullMediaType,
322
- ),
323
- name: contentPart.filename
324
- ? stripFileExtension(contentPart.filename)
325
- : generateDocumentName(),
326
- source: {
327
- bytes: convertToBase64(
328
- contentPart.data.data,
329
- ),
359
+ case 'video': {
360
+ return {
361
+ video: {
362
+ format:
363
+ getAmazonBedrockVideoFormat(
364
+ fullMediaType,
365
+ ),
366
+ source: getAmazonBedrockMediaSource({
367
+ data: contentPart.data,
368
+ functionality: `tool result file data of type "${contentPart.data.type}"`,
369
+ }),
330
370
  },
331
- ...(enableCitations && {
332
- citations: { enabled: true },
333
- }),
334
- },
335
- };
371
+ };
372
+ }
373
+ default: {
374
+ if (contentPart.data.type !== 'data') {
375
+ throw new UnsupportedFunctionalityError({
376
+ functionality: `tool result file data of type "${contentPart.data.type}"`,
377
+ });
378
+ }
379
+
380
+ const enableCitations =
381
+ await shouldEnableCitations(
382
+ contentPart.providerOptions,
383
+ );
384
+
385
+ return {
386
+ document: {
387
+ format:
388
+ getAmazonBedrockDocumentFormat(
389
+ fullMediaType,
390
+ ),
391
+ name: contentPart.filename
392
+ ? stripFileExtension(contentPart.filename)
393
+ : generateDocumentName(),
394
+ source: {
395
+ bytes: convertToBase64(
396
+ contentPart.data.data,
397
+ ),
398
+ },
399
+ ...(enableCitations && {
400
+ citations: { enabled: true },
401
+ }),
402
+ },
403
+ };
404
+ }
336
405
  }
337
-
338
- return {
339
- image: {
340
- format:
341
- getAmazonBedrockImageFormat(fullMediaType),
342
- source: getAmazonBedrockImageSource({
343
- data: contentPart.data,
344
- functionality: `tool result file data of type "${contentPart.data.type}"`,
345
- }),
346
- },
347
- };
348
406
  }
349
407
  default: {
350
408
  throw new UnsupportedFunctionalityError({
@@ -546,6 +604,21 @@ function getAmazonBedrockDocumentFormat(
546
604
  return format;
547
605
  }
548
606
 
607
+ function getAmazonBedrockVideoFormat(
608
+ mimeType: string,
609
+ ): AmazonBedrockVideoFormat {
610
+ const format =
611
+ BEDROCK_VIDEO_MIME_TYPES[mimeType as AmazonBedrockVideoMimeType];
612
+ if (!format) {
613
+ throw new UnsupportedFunctionalityError({
614
+ functionality: `video mime type: ${mimeType}`,
615
+ message: `Unsupported video mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_VIDEO_MIME_TYPES).join(', ')}`,
616
+ });
617
+ }
618
+
619
+ return format;
620
+ }
621
+
549
622
  function trimIfLast(
550
623
  isLastBlock: boolean,
551
624
  isLastMessage: boolean,