@ai-sdk/amazon-bedrock 5.0.58 → 5.0.60

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.58" : "0.0.0-test";
38
+ var VERSION = true ? "5.0.60" : "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.58" : "0.0.0-test";
26
+ var VERSION = true ? "5.0.60" : "0.0.0-test";
27
27
 
28
28
  // src/amazon-bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "5.0.58",
3
+ "version": "5.0.60",
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.39",
48
- "@ai-sdk/openai": "4.0.43",
47
+ "@ai-sdk/anthropic": "4.0.40",
48
+ "@ai-sdk/openai": "4.0.45",
49
49
  "@ai-sdk/provider": "4.0.7",
50
- "@ai-sdk/provider-utils": "5.0.27"
50
+ "@ai-sdk/provider-utils": "5.0.28"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "22.19.19",
@@ -258,6 +258,12 @@ export interface AmazonBedrockRedactedReasoningContentBlock {
258
258
  };
259
259
  }
260
260
 
261
+ export interface AmazonBedrockRedactedContentBlock {
262
+ reasoningContent: {
263
+ redactedContent: string;
264
+ };
265
+ }
266
+
261
267
  export type AmazonBedrockContentBlock =
262
268
  | AmazonBedrockDocumentBlock
263
269
  | AmazonBedrockGuardrailConverseContentBlock
@@ -268,4 +274,5 @@ export type AmazonBedrockContentBlock =
268
274
  | AmazonBedrockToolUseBlock
269
275
  | AmazonBedrockReasoningContentBlock
270
276
  | AmazonBedrockRedactedReasoningContentBlock
277
+ | AmazonBedrockRedactedContentBlock
271
278
  | AmazonBedrockCachePoint;
@@ -573,6 +573,18 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
573
573
  bedrock: redactedPayload,
574
574
  },
575
575
  });
576
+ } else if ('redactedContent' in part.reasoningContent) {
577
+ const redactedPayload: AmazonBedrockReasoningMetadata = {
578
+ redactedContent: part.reasoningContent.redactedContent,
579
+ };
580
+ content.push({
581
+ type: 'reasoning',
582
+ text: '',
583
+ providerMetadata: {
584
+ amazonBedrock: redactedPayload,
585
+ bedrock: redactedPayload,
586
+ },
587
+ });
576
588
  }
577
589
  }
578
590
 
@@ -591,7 +603,7 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
591
603
  } else {
592
604
  const isMistral = isMistralModel(this.modelId);
593
605
  const rawToolCallId =
594
- part.toolUse?.toolUseId ?? this.config.generateId();
606
+ part.toolUse?.toolUseId || this.config.generateId();
595
607
  content.push({
596
608
  type: 'tool-call' as const,
597
609
  toolCallId: normalizeToolCallId(rawToolCallId, isMistral),
@@ -720,7 +732,8 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
720
732
  jsonText: string;
721
733
  isJsonResponseTool?: boolean;
722
734
  }
723
- | { type: 'text' | 'reasoning' }
735
+ | { type: 'text' }
736
+ | { type: 'reasoning'; redactedContent?: string }
724
737
  > = {};
725
738
 
726
739
  return {
@@ -770,6 +783,10 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
770
783
  enqueueError(value.modelStreamErrorException);
771
784
  return;
772
785
  }
786
+ if (value.serviceUnavailableException) {
787
+ enqueueError(value.serviceUnavailableException);
788
+ return;
789
+ }
773
790
  if (value.throttlingException) {
774
791
  enqueueError(value.throttlingException);
775
792
  return;
@@ -891,9 +908,21 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
891
908
 
892
909
  if (contentBlock != null) {
893
910
  if (contentBlock.type === 'reasoning') {
911
+ const redactedPayload: AmazonBedrockReasoningMetadata | null =
912
+ contentBlock.redactedContent != null
913
+ ? { redactedContent: contentBlock.redactedContent }
914
+ : null;
894
915
  controller.enqueue({
895
916
  type: 'reasoning-end',
896
917
  id: String(blockIndex),
918
+ ...(redactedPayload != null
919
+ ? {
920
+ providerMetadata: {
921
+ amazonBedrock: redactedPayload,
922
+ bedrock: redactedPayload,
923
+ },
924
+ }
925
+ : {}),
897
926
  });
898
927
  } else if (contentBlock.type === 'text') {
899
928
  controller.enqueue({
@@ -1008,6 +1037,27 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
1008
1037
  },
1009
1038
  });
1010
1039
  }
1040
+ } else if (
1041
+ 'redactedContent' in reasoningContent &&
1042
+ reasoningContent.redactedContent
1043
+ ) {
1044
+ if (contentBlocks[blockIndex] == null) {
1045
+ contentBlocks[blockIndex] = { type: 'reasoning' };
1046
+ controller.enqueue({
1047
+ type: 'reasoning-start',
1048
+ id: String(blockIndex),
1049
+ });
1050
+ }
1051
+
1052
+ const contentBlock = contentBlocks[blockIndex];
1053
+ if (contentBlock.type === 'reasoning') {
1054
+ // accumulate and attach once via reasoning-end: the merged
1055
+ // provider metadata of a reasoning part is last-write-wins,
1056
+ // so per-delta metadata would drop earlier chunks
1057
+ contentBlock.redactedContent =
1058
+ (contentBlock.redactedContent ?? '') +
1059
+ reasoningContent.redactedContent;
1060
+ }
1011
1061
  }
1012
1062
  }
1013
1063
 
@@ -1216,6 +1266,13 @@ const AmazonBedrockResponseSchema = z.object({
1216
1266
  z.object({
1217
1267
  redactedReasoning: AmazonBedrockRedactedReasoningSchema,
1218
1268
  }),
1269
+ // `redactedContent` is a member of the documented
1270
+ // ReasoningContentBlock union. OpenAI models on Bedrock
1271
+ // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1272
+ // reasoning in this shape.
1273
+ z.object({
1274
+ redactedContent: z.string(),
1275
+ }),
1219
1276
  ])
1220
1277
  .nullish(),
1221
1278
  }),
@@ -1262,6 +1319,12 @@ const AmazonBedrockStreamSchema = z.object({
1262
1319
  z.object({
1263
1320
  reasoningContent: z.object({ data: z.string() }),
1264
1321
  }),
1322
+ // `redactedContent` is a member of the documented
1323
+ // ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
1324
+ // their encrypted reasoning in this shape.
1325
+ z.object({
1326
+ reasoningContent: z.object({ redactedContent: z.string() }),
1327
+ }),
1265
1328
  ])
1266
1329
  .nullish(),
1267
1330
  })
@@ -1308,6 +1371,7 @@ const AmazonBedrockStreamSchema = z.object({
1308
1371
  })
1309
1372
  .nullish(),
1310
1373
  modelStreamErrorException: z.record(z.string(), z.unknown()).nullish(),
1374
+ serviceUnavailableException: z.record(z.string(), z.unknown()).nullish(),
1311
1375
  throttlingException: z.record(z.string(), z.unknown()).nullish(),
1312
1376
  validationException: z.record(z.string(), z.unknown()).nullish(),
1313
1377
  });
@@ -3,7 +3,8 @@ import { toUtf8, fromUtf8 } from '@smithy/util-utf8';
3
3
 
4
4
  export interface DecodedEvent {
5
5
  messageType: string;
6
- eventType: string;
6
+ eventType?: string;
7
+ exceptionType?: string;
7
8
  data: string;
8
9
  }
9
10
 
@@ -43,10 +44,18 @@ export function createAmazonBedrockEventStreamDecoder<T>(
43
44
  buffer = buffer.slice(totalLength);
44
45
 
45
46
  const messageType = decoded.headers[':message-type']?.value as string;
46
- const eventType = decoded.headers[':event-type']?.value as string;
47
+ const eventType = decoded.headers[':event-type']?.value as
48
+ | string
49
+ | undefined;
50
+ const exceptionType = decoded.headers[':exception-type']?.value as
51
+ | string
52
+ | undefined;
47
53
  const data = textDecoder.decode(decoded.body);
48
54
 
49
- await processEvent({ messageType, eventType, data }, controller);
55
+ await processEvent(
56
+ { messageType, eventType, exceptionType, data },
57
+ controller,
58
+ );
50
59
  }
51
60
  },
52
61
  flush() {
@@ -25,31 +25,40 @@ export const createAmazonBedrockEventStreamResponseHandler =
25
25
  value: createAmazonBedrockEventStreamDecoder<ParseResult<T>>(
26
26
  response.body,
27
27
  async (event, controller) => {
28
- if (event.messageType === 'event') {
29
- const parsedDataResult = await safeParseJSON({ text: event.data });
30
- if (!parsedDataResult.success) {
31
- controller.enqueue(parsedDataResult);
32
- return;
33
- }
28
+ const payloadType =
29
+ event.messageType === 'event'
30
+ ? event.eventType
31
+ : event.messageType === 'exception'
32
+ ? event.exceptionType
33
+ : undefined;
34
34
 
35
- delete (parsedDataResult.value as any).p;
36
- const wrappedData = {
37
- [event.eventType]: parsedDataResult.value,
38
- };
35
+ if (payloadType == null) {
36
+ return;
37
+ }
38
+
39
+ const parsedDataResult = await safeParseJSON({ text: event.data });
40
+ if (!parsedDataResult.success) {
41
+ controller.enqueue(parsedDataResult);
42
+ return;
43
+ }
44
+
45
+ delete (parsedDataResult.value as any).p;
46
+ const wrappedData = {
47
+ [payloadType]: parsedDataResult.value,
48
+ };
39
49
 
40
- const validatedWrappedData = await safeValidateTypes<T>({
41
- value: wrappedData,
42
- schema: chunkSchema,
50
+ const validatedWrappedData = await safeValidateTypes<T>({
51
+ value: wrappedData,
52
+ schema: chunkSchema,
53
+ });
54
+ if (!validatedWrappedData.success) {
55
+ controller.enqueue(validatedWrappedData);
56
+ } else {
57
+ controller.enqueue({
58
+ success: true,
59
+ value: validatedWrappedData.value,
60
+ rawValue: wrappedData,
43
61
  });
44
- if (!validatedWrappedData.success) {
45
- controller.enqueue(validatedWrappedData);
46
- } else {
47
- controller.enqueue({
48
- success: true,
49
- value: validatedWrappedData.value,
50
- rawValue: wrappedData,
51
- });
52
- }
53
62
  }
54
63
  },
55
64
  ),
@@ -3,6 +3,7 @@ import { z } from 'zod/v4';
3
3
  export const amazonBedrockReasoningMetadataSchema = z.object({
4
4
  signature: z.string().optional(),
5
5
  redactedData: z.string().optional(),
6
+ redactedContent: z.string().optional(),
6
7
  });
7
8
 
8
9
  export type AmazonBedrockReasoningMetadata = z.infer<
@@ -520,6 +520,12 @@ export async function convertToAmazonBedrockChatMessages(
520
520
  },
521
521
  },
522
522
  });
523
+ } else if (reasoningMetadata?.redactedContent != null) {
524
+ amazonBedrockContent.push({
525
+ reasoningContent: {
526
+ redactedContent: reasoningMetadata.redactedContent,
527
+ },
528
+ });
523
529
  } else if (reasoningMetadata?.redactedData != null) {
524
530
  amazonBedrockContent.push({
525
531
  reasoningContent: {