@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.
package/dist/index.mjs CHANGED
@@ -161,17 +161,20 @@ function createBedrockEventStreamDecoder(body, processEvent) {
161
161
  if (buffer.length < totalLength) {
162
162
  break;
163
163
  }
164
- try {
165
- const subView = buffer.subarray(0, totalLength);
166
- const decoded = codec.decode(subView);
167
- buffer = buffer.slice(totalLength);
168
- const messageType = (_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value;
169
- const eventType = (_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value;
170
- const data = textDecoder.decode(decoded.body);
171
- await processEvent({ messageType, eventType, data }, controller);
172
- } catch (e) {
173
- break;
174
- }
164
+ const subView = buffer.subarray(0, totalLength);
165
+ const decoded = codec.decode(subView);
166
+ buffer = buffer.slice(totalLength);
167
+ const messageType = (_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value;
168
+ const eventType = (_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value;
169
+ const data = textDecoder.decode(decoded.body);
170
+ await processEvent({ messageType, eventType, data }, controller);
171
+ }
172
+ },
173
+ flush() {
174
+ if (buffer.length > 0) {
175
+ throw new Error(
176
+ `Incomplete Amazon Bedrock event-stream frame: ${buffer.length} buffered bytes remain at end of stream.`
177
+ );
175
178
  }
176
179
  }
177
180
  })
@@ -418,7 +421,8 @@ import {
418
421
  import { z as z3 } from "zod/v4";
419
422
  var bedrockReasoningMetadataSchema = z3.object({
420
423
  signature: z3.string().optional(),
421
- redactedData: z3.string().optional()
424
+ redactedData: z3.string().optional(),
425
+ redactedContent: z3.string().optional()
422
426
  });
423
427
 
424
428
  // src/normalize-tool-call-id.ts
@@ -732,6 +736,12 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
732
736
  }
733
737
  }
734
738
  });
739
+ } else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedContent) != null) {
740
+ bedrockContent.push({
741
+ reasoningContent: {
742
+ redactedContent: reasoningMetadata.redactedContent
743
+ }
744
+ });
735
745
  } else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
736
746
  bedrockContent.push({
737
747
  reasoningContent: {
@@ -1218,6 +1228,16 @@ var BedrockChatLanguageModel = class {
1218
1228
  }
1219
1229
  }
1220
1230
  });
1231
+ } else if ("redactedContent" in part.reasoningContent) {
1232
+ content.push({
1233
+ type: "reasoning",
1234
+ text: "",
1235
+ providerMetadata: {
1236
+ bedrock: {
1237
+ redactedContent: part.reasoningContent.redactedContent
1238
+ }
1239
+ }
1240
+ });
1221
1241
  }
1222
1242
  }
1223
1243
  if (part.toolUse) {
@@ -1331,7 +1351,7 @@ var BedrockChatLanguageModel = class {
1331
1351
  });
1332
1352
  },
1333
1353
  transform(chunk, controller) {
1334
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1354
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1335
1355
  function enqueueError(bedrockError) {
1336
1356
  finishReason = { unified: "error", raw: void 0 };
1337
1357
  controller.enqueue({ type: "error", error: bedrockError });
@@ -1435,9 +1455,15 @@ var BedrockChatLanguageModel = class {
1435
1455
  const contentBlock = contentBlocks[blockIndex];
1436
1456
  if (contentBlock != null) {
1437
1457
  if (contentBlock.type === "reasoning") {
1458
+ const redactedPayload = contentBlock.redactedContent != null ? { redactedContent: contentBlock.redactedContent } : null;
1438
1459
  controller.enqueue({
1439
1460
  type: "reasoning-end",
1440
- id: String(blockIndex)
1461
+ id: String(blockIndex),
1462
+ ...redactedPayload != null ? {
1463
+ providerMetadata: {
1464
+ bedrock: redactedPayload
1465
+ }
1466
+ } : {}
1441
1467
  });
1442
1468
  } else if (contentBlock.type === "text") {
1443
1469
  controller.enqueue({
@@ -1528,10 +1554,22 @@ var BedrockChatLanguageModel = class {
1528
1554
  }
1529
1555
  }
1530
1556
  });
1557
+ } else if ("redactedContent" in reasoningContent && reasoningContent.redactedContent) {
1558
+ if (contentBlocks[blockIndex] == null) {
1559
+ contentBlocks[blockIndex] = { type: "reasoning" };
1560
+ controller.enqueue({
1561
+ type: "reasoning-start",
1562
+ id: String(blockIndex)
1563
+ });
1564
+ }
1565
+ const contentBlock = contentBlocks[blockIndex];
1566
+ if (contentBlock.type === "reasoning") {
1567
+ contentBlock.redactedContent = ((_p = contentBlock.redactedContent) != null ? _p : "") + reasoningContent.redactedContent;
1568
+ }
1531
1569
  }
1532
1570
  }
1533
1571
  const contentBlockStart = value.contentBlockStart;
1534
- if (((_p = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _p.toolUse) != null) {
1572
+ if (((_q = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _q.toolUse) != null) {
1535
1573
  const toolUse = contentBlockStart.start.toolUse;
1536
1574
  const blockIndex = contentBlockStart.contentBlockIndex;
1537
1575
  const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
@@ -1559,7 +1597,7 @@ var BedrockChatLanguageModel = class {
1559
1597
  const blockIndex = contentBlockDelta.contentBlockIndex;
1560
1598
  const contentBlock = contentBlocks[blockIndex];
1561
1599
  if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
1562
- const delta = (_q = contentBlockDelta.delta.toolUse.input) != null ? _q : "";
1600
+ const delta = (_r = contentBlockDelta.delta.toolUse.input) != null ? _r : "";
1563
1601
  if (!contentBlock.isJsonResponseTool) {
1564
1602
  controller.enqueue({
1565
1603
  type: "tool-input-delta",
@@ -1697,6 +1735,13 @@ var BedrockResponseSchema = z4.object({
1697
1735
  }),
1698
1736
  z4.object({
1699
1737
  redactedReasoning: BedrockRedactedReasoningSchema
1738
+ }),
1739
+ // `redactedContent` is a member of the documented
1740
+ // ReasoningContentBlock union. OpenAI models on Bedrock
1741
+ // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1742
+ // reasoning in this shape.
1743
+ z4.object({
1744
+ redactedContent: z4.string()
1700
1745
  })
1701
1746
  ]).nullish()
1702
1747
  })
@@ -1734,6 +1779,12 @@ var BedrockStreamSchema = z4.object({
1734
1779
  }),
1735
1780
  z4.object({
1736
1781
  reasoningContent: z4.object({ data: z4.string() })
1782
+ }),
1783
+ // `redactedContent` is a member of the documented
1784
+ // ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
1785
+ // their encrypted reasoning in this shape.
1786
+ z4.object({
1787
+ reasoningContent: z4.object({ redactedContent: z4.string() })
1737
1788
  })
1738
1789
  ]).nullish()
1739
1790
  }).nullish(),
@@ -2193,7 +2244,7 @@ import {
2193
2244
  import { AwsV4Signer } from "aws4fetch";
2194
2245
 
2195
2246
  // src/version.ts
2196
- var VERSION = true ? "4.0.156" : "0.0.0-test";
2247
+ var VERSION = true ? "4.0.158" : "0.0.0-test";
2197
2248
 
2198
2249
  // src/bedrock-sigv4-fetch.ts
2199
2250
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {