@ai-sdk/amazon-bedrock 4.0.156 → 4.0.158

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 ? "4.0.156" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.158" : "0.0.0-test";
39
39
 
40
40
  // src/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 ? "4.0.156" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.158" : "0.0.0-test";
27
27
 
28
28
  // src/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": "4.0.156",
3
+ "version": "4.0.158",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -213,6 +213,12 @@ export interface BedrockRedactedReasoningContentBlock {
213
213
  };
214
214
  }
215
215
 
216
+ export interface BedrockRedactedContentBlock {
217
+ reasoningContent: {
218
+ redactedContent: string;
219
+ };
220
+ }
221
+
216
222
  export type BedrockContentBlock =
217
223
  | BedrockDocumentBlock
218
224
  | BedrockGuardrailConverseContentBlock
@@ -222,4 +228,5 @@ export type BedrockContentBlock =
222
228
  | BedrockToolUseBlock
223
229
  | BedrockReasoningContentBlock
224
230
  | BedrockRedactedReasoningContentBlock
231
+ | BedrockRedactedContentBlock
225
232
  | BedrockCachePoint;
@@ -528,6 +528,16 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
528
528
  } satisfies BedrockReasoningMetadata,
529
529
  },
530
530
  });
531
+ } else if ('redactedContent' in part.reasoningContent) {
532
+ content.push({
533
+ type: 'reasoning',
534
+ text: '',
535
+ providerMetadata: {
536
+ bedrock: {
537
+ redactedContent: part.reasoningContent.redactedContent,
538
+ } satisfies BedrockReasoningMetadata,
539
+ },
540
+ });
531
541
  }
532
542
  }
533
543
 
@@ -669,7 +679,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
669
679
  jsonText: string;
670
680
  isJsonResponseTool?: boolean;
671
681
  }
672
- | { type: 'text' | 'reasoning' }
682
+ | { type: 'text' }
683
+ | { type: 'reasoning'; redactedContent?: string }
673
684
  > = {};
674
685
 
675
686
  return {
@@ -838,9 +849,20 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
838
849
 
839
850
  if (contentBlock != null) {
840
851
  if (contentBlock.type === 'reasoning') {
852
+ const redactedPayload: BedrockReasoningMetadata | null =
853
+ contentBlock.redactedContent != null
854
+ ? { redactedContent: contentBlock.redactedContent }
855
+ : null;
841
856
  controller.enqueue({
842
857
  type: 'reasoning-end',
843
858
  id: String(blockIndex),
859
+ ...(redactedPayload != null
860
+ ? {
861
+ providerMetadata: {
862
+ bedrock: redactedPayload,
863
+ },
864
+ }
865
+ : {}),
844
866
  });
845
867
  } else if (contentBlock.type === 'text') {
846
868
  controller.enqueue({
@@ -947,6 +969,27 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
947
969
  } satisfies BedrockReasoningMetadata,
948
970
  },
949
971
  });
972
+ } else if (
973
+ 'redactedContent' in reasoningContent &&
974
+ reasoningContent.redactedContent
975
+ ) {
976
+ if (contentBlocks[blockIndex] == null) {
977
+ contentBlocks[blockIndex] = { type: 'reasoning' };
978
+ controller.enqueue({
979
+ type: 'reasoning-start',
980
+ id: String(blockIndex),
981
+ });
982
+ }
983
+
984
+ const contentBlock = contentBlocks[blockIndex];
985
+ if (contentBlock.type === 'reasoning') {
986
+ // accumulate and attach once via reasoning-end: the merged
987
+ // provider metadata of a reasoning part is last-write-wins,
988
+ // so per-delta metadata would drop earlier chunks
989
+ contentBlock.redactedContent =
990
+ (contentBlock.redactedContent ?? '') +
991
+ reasoningContent.redactedContent;
992
+ }
950
993
  }
951
994
  }
952
995
 
@@ -1160,6 +1203,13 @@ const BedrockResponseSchema = z.object({
1160
1203
  z.object({
1161
1204
  redactedReasoning: BedrockRedactedReasoningSchema,
1162
1205
  }),
1206
+ // `redactedContent` is a member of the documented
1207
+ // ReasoningContentBlock union. OpenAI models on Bedrock
1208
+ // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1209
+ // reasoning in this shape.
1210
+ z.object({
1211
+ redactedContent: z.string(),
1212
+ }),
1163
1213
  ])
1164
1214
  .nullish(),
1165
1215
  }),
@@ -1206,6 +1256,12 @@ const BedrockStreamSchema = z.object({
1206
1256
  z.object({
1207
1257
  reasoningContent: z.object({ data: z.string() }),
1208
1258
  }),
1259
+ // `redactedContent` is a member of the documented
1260
+ // ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
1261
+ // their encrypted reasoning in this shape.
1262
+ z.object({
1263
+ reasoningContent: z.object({ redactedContent: z.string() }),
1264
+ }),
1209
1265
  ])
1210
1266
  .nullish(),
1211
1267
  })
@@ -37,21 +37,23 @@ export function createBedrockEventStreamDecoder<T>(
37
37
  break;
38
38
  }
39
39
 
40
- try {
41
- const subView = buffer.subarray(0, totalLength);
42
- const decoded = codec.decode(subView);
40
+ const subView = buffer.subarray(0, totalLength);
41
+ const decoded = codec.decode(subView);
43
42
 
44
- buffer = buffer.slice(totalLength);
43
+ buffer = buffer.slice(totalLength);
45
44
 
46
- const messageType = decoded.headers[':message-type']
47
- ?.value as string;
48
- const eventType = decoded.headers[':event-type']?.value as string;
49
- const data = textDecoder.decode(decoded.body);
45
+ const messageType = decoded.headers[':message-type']?.value as string;
46
+ const eventType = decoded.headers[':event-type']?.value as string;
47
+ const data = textDecoder.decode(decoded.body);
50
48
 
51
- await processEvent({ messageType, eventType, data }, controller);
52
- } catch {
53
- break;
54
- }
49
+ await processEvent({ messageType, eventType, data }, controller);
50
+ }
51
+ },
52
+ flush() {
53
+ if (buffer.length > 0) {
54
+ throw new Error(
55
+ `Incomplete Amazon Bedrock event-stream frame: ${buffer.length} buffered bytes remain at end of stream.`,
56
+ );
55
57
  }
56
58
  },
57
59
  }),
@@ -3,6 +3,7 @@ import { z } from 'zod/v4';
3
3
  export const bedrockReasoningMetadataSchema = 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 BedrockReasoningMetadata = z.infer<
@@ -395,6 +395,12 @@ export async function convertToBedrockChatMessages(
395
395
  },
396
396
  },
397
397
  });
398
+ } else if (reasoningMetadata?.redactedContent != null) {
399
+ bedrockContent.push({
400
+ reasoningContent: {
401
+ redactedContent: reasoningMetadata.redactedContent,
402
+ },
403
+ });
398
404
  } else if (reasoningMetadata?.redactedData != null) {
399
405
  bedrockContent.push({
400
406
  reasoningContent: {