@ai-sdk/amazon-bedrock 5.0.58 → 5.0.59

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,16 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 5.0.59
4
+
5
+ ### Patch Changes
6
+
7
+ - e6087c9: fix: handle empty string tool call IDs
8
+ - aabc617: fix (provider/amazon-bedrock): support `reasoningContent.redactedContent` from the Converse API and replay it on subsequent turns
9
+ - Updated dependencies [e6087c9]
10
+ - @ai-sdk/provider-utils@5.0.28
11
+ - @ai-sdk/openai@4.0.44
12
+ - @ai-sdk/anthropic@4.0.40
13
+
3
14
  ## 5.0.58
4
15
 
5
16
  ### Patch Changes
@@ -24,7 +24,7 @@ import {
24
24
  import { AwsV4Signer } from "aws4fetch";
25
25
 
26
26
  // src/version.ts
27
- var VERSION = true ? "5.0.58" : "0.0.0-test";
27
+ var VERSION = true ? "5.0.59" : "0.0.0-test";
28
28
 
29
29
  // src/amazon-bedrock-sigv4-fetch.ts
30
30
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/dist/index.js CHANGED
@@ -430,7 +430,8 @@ import {
430
430
  import { z as z3 } from "zod/v4";
431
431
  var amazonBedrockReasoningMetadataSchema = z3.object({
432
432
  signature: z3.string().optional(),
433
- redactedData: z3.string().optional()
433
+ redactedData: z3.string().optional(),
434
+ redactedContent: z3.string().optional()
434
435
  });
435
436
 
436
437
  // src/normalize-tool-call-id.ts
@@ -835,6 +836,12 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
835
836
  }
836
837
  }
837
838
  });
839
+ } else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedContent) != null) {
840
+ amazonBedrockContent.push({
841
+ reasoningContent: {
842
+ redactedContent: reasoningMetadata.redactedContent
843
+ }
844
+ });
838
845
  } else if ((reasoningMetadata == null ? void 0 : reasoningMetadata.redactedData) != null) {
839
846
  amazonBedrockContent.push({
840
847
  reasoningContent: {
@@ -1293,7 +1300,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1293
1300
  );
1294
1301
  }
1295
1302
  async doGenerate(options) {
1296
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1303
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1297
1304
  const {
1298
1305
  command: args,
1299
1306
  warnings,
@@ -1356,6 +1363,18 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1356
1363
  bedrock: redactedPayload
1357
1364
  }
1358
1365
  });
1366
+ } else if ("redactedContent" in part.reasoningContent) {
1367
+ const redactedPayload = {
1368
+ redactedContent: part.reasoningContent.redactedContent
1369
+ };
1370
+ content.push({
1371
+ type: "reasoning",
1372
+ text: "",
1373
+ providerMetadata: {
1374
+ amazonBedrock: redactedPayload,
1375
+ bedrock: redactedPayload
1376
+ }
1377
+ });
1359
1378
  }
1360
1379
  }
1361
1380
  if (part.toolUse) {
@@ -1368,17 +1387,17 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1368
1387
  });
1369
1388
  } else {
1370
1389
  const isMistral = isMistralModel(this.modelId);
1371
- const rawToolCallId = (_d = (_c = part.toolUse) == null ? void 0 : _c.toolUseId) != null ? _d : this.config.generateId();
1390
+ const rawToolCallId = ((_c = part.toolUse) == null ? void 0 : _c.toolUseId) || this.config.generateId();
1372
1391
  content.push({
1373
1392
  type: "tool-call",
1374
1393
  toolCallId: normalizeToolCallId(rawToolCallId, isMistral),
1375
- toolName: (_f = (_e = part.toolUse) == null ? void 0 : _e.name) != null ? _f : `tool-${this.config.generateId()}`,
1376
- input: JSON.stringify((_h = (_g = part.toolUse) == null ? void 0 : _g.input) != null ? _h : {})
1394
+ toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
1395
+ input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : {})
1377
1396
  });
1378
1397
  }
1379
1398
  }
1380
1399
  }
1381
- const stopSequence = (_k = (_j = (_i = response.additionalModelResponseFields) == null ? void 0 : _i.delta) == null ? void 0 : _j.stop_sequence) != null ? _k : null;
1400
+ const stopSequence = (_j = (_i = (_h = response.additionalModelResponseFields) == null ? void 0 : _h.delta) == null ? void 0 : _i.stop_sequence) != null ? _j : null;
1382
1401
  const providerMetadataPayload = response.trace || response.usage || response.performanceConfig || response.serviceTier || isJsonResponseFromTool || stopSequence ? {
1383
1402
  ...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
1384
1403
  ...response.performanceConfig && {
@@ -1387,7 +1406,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1387
1406
  ...response.serviceTier && {
1388
1407
  serviceTier: response.serviceTier
1389
1408
  },
1390
- ...(((_l = response.usage) == null ? void 0 : _l.cacheWriteInputTokens) != null || ((_m = response.usage) == null ? void 0 : _m.cacheDetails) != null) && {
1409
+ ...(((_k = response.usage) == null ? void 0 : _k.cacheWriteInputTokens) != null || ((_l = response.usage) == null ? void 0 : _l.cacheDetails) != null) && {
1391
1410
  usage: {
1392
1411
  ...response.usage.cacheWriteInputTokens != null && {
1393
1412
  cacheWriteInputTokens: response.usage.cacheWriteInputTokens
@@ -1411,11 +1430,11 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1411
1430
  response.stopReason,
1412
1431
  isJsonResponseFromTool
1413
1432
  ),
1414
- raw: (_n = response.stopReason) != null ? _n : void 0
1433
+ raw: (_m = response.stopReason) != null ? _m : void 0
1415
1434
  },
1416
1435
  usage: convertAmazonBedrockUsage(response.usage),
1417
1436
  response: {
1418
- id: (_o = responseHeaders == null ? void 0 : responseHeaders["x-amzn-requestid"]) != null ? _o : void 0,
1437
+ id: (_n = responseHeaders == null ? void 0 : responseHeaders["x-amzn-requestid"]) != null ? _n : void 0,
1419
1438
  timestamp: (responseHeaders == null ? void 0 : responseHeaders["date"]) != null ? new Date(responseHeaders["date"]) : void 0,
1420
1439
  modelId: this.modelId,
1421
1440
  headers: responseHeaders
@@ -1473,7 +1492,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1473
1492
  });
1474
1493
  },
1475
1494
  transform(chunk, controller) {
1476
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1495
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1477
1496
  function enqueueError(amazonBedrockError) {
1478
1497
  finishReason = { unified: "error", raw: void 0 };
1479
1498
  controller.enqueue({ type: "error", error: amazonBedrockError });
@@ -1579,9 +1598,16 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1579
1598
  const contentBlock = contentBlocks[blockIndex];
1580
1599
  if (contentBlock != null) {
1581
1600
  if (contentBlock.type === "reasoning") {
1601
+ const redactedPayload = contentBlock.redactedContent != null ? { redactedContent: contentBlock.redactedContent } : null;
1582
1602
  controller.enqueue({
1583
1603
  type: "reasoning-end",
1584
- id: String(blockIndex)
1604
+ id: String(blockIndex),
1605
+ ...redactedPayload != null ? {
1606
+ providerMetadata: {
1607
+ amazonBedrock: redactedPayload,
1608
+ bedrock: redactedPayload
1609
+ }
1610
+ } : {}
1585
1611
  });
1586
1612
  } else if (contentBlock.type === "text") {
1587
1613
  controller.enqueue({
@@ -1680,10 +1706,22 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1680
1706
  }
1681
1707
  });
1682
1708
  }
1709
+ } else if ("redactedContent" in reasoningContent && reasoningContent.redactedContent) {
1710
+ if (contentBlocks[blockIndex] == null) {
1711
+ contentBlocks[blockIndex] = { type: "reasoning" };
1712
+ controller.enqueue({
1713
+ type: "reasoning-start",
1714
+ id: String(blockIndex)
1715
+ });
1716
+ }
1717
+ const contentBlock = contentBlocks[blockIndex];
1718
+ if (contentBlock.type === "reasoning") {
1719
+ contentBlock.redactedContent = ((_p = contentBlock.redactedContent) != null ? _p : "") + reasoningContent.redactedContent;
1720
+ }
1683
1721
  }
1684
1722
  }
1685
1723
  const contentBlockStart = value.contentBlockStart;
1686
- if (((_p = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _p.toolUse) != null) {
1724
+ if (((_q = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _q.toolUse) != null) {
1687
1725
  const toolUse = contentBlockStart.start.toolUse;
1688
1726
  const blockIndex = contentBlockStart.contentBlockIndex;
1689
1727
  const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
@@ -1711,7 +1749,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
1711
1749
  const blockIndex = contentBlockDelta.contentBlockIndex;
1712
1750
  const contentBlock = contentBlocks[blockIndex];
1713
1751
  if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
1714
- const delta = (_q = contentBlockDelta.delta.toolUse.input) != null ? _q : "";
1752
+ const delta = (_r = contentBlockDelta.delta.toolUse.input) != null ? _r : "";
1715
1753
  if (!contentBlock.isJsonResponseTool) {
1716
1754
  controller.enqueue({
1717
1755
  type: "tool-input-delta",
@@ -1844,6 +1882,13 @@ var AmazonBedrockResponseSchema = z4.object({
1844
1882
  }),
1845
1883
  z4.object({
1846
1884
  redactedReasoning: AmazonBedrockRedactedReasoningSchema
1885
+ }),
1886
+ // `redactedContent` is a member of the documented
1887
+ // ReasoningContentBlock union. OpenAI models on Bedrock
1888
+ // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1889
+ // reasoning in this shape.
1890
+ z4.object({
1891
+ redactedContent: z4.string()
1847
1892
  })
1848
1893
  ]).nullish()
1849
1894
  })
@@ -1881,6 +1926,12 @@ var AmazonBedrockStreamSchema = z4.object({
1881
1926
  }),
1882
1927
  z4.object({
1883
1928
  reasoningContent: z4.object({ data: z4.string() })
1929
+ }),
1930
+ // `redactedContent` is a member of the documented
1931
+ // ReasoningContentBlockDelta union. OpenAI models on Bedrock stream
1932
+ // their encrypted reasoning in this shape.
1933
+ z4.object({
1934
+ reasoningContent: z4.object({ redactedContent: z4.string() })
1884
1935
  })
1885
1936
  ]).nullish()
1886
1937
  }).nullish(),
@@ -2486,7 +2537,7 @@ import {
2486
2537
  import { AwsV4Signer } from "aws4fetch";
2487
2538
 
2488
2539
  // src/version.ts
2489
- var VERSION = true ? "5.0.58" : "0.0.0-test";
2540
+ var VERSION = true ? "5.0.59" : "0.0.0-test";
2490
2541
 
2491
2542
  // src/amazon-bedrock-sigv4-fetch.ts
2492
2543
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {