@ai-sdk-tool/parser 2.1.5 → 2.1.6

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.cjs CHANGED
@@ -1416,7 +1416,7 @@ async function wrapGenerate({
1416
1416
  doGenerate,
1417
1417
  params
1418
1418
  }) {
1419
- var _a, _b, _c, _d;
1419
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1420
1420
  if (isToolChoiceActive(params)) {
1421
1421
  const result2 = await doGenerate();
1422
1422
  let parsed2 = {};
@@ -1449,7 +1449,16 @@ async function wrapGenerate({
1449
1449
  };
1450
1450
  const debugLevelToolChoice = getDebugLevel();
1451
1451
  const originText = first && first.type === "text" ? first.text : "";
1452
- if (debugLevelToolChoice === "parse") {
1452
+ const dbg2 = (_d = (_c = params.providerOptions) == null ? void 0 : _c.toolCallMiddleware) == null ? void 0 : _d.debugSummary;
1453
+ if (dbg2) {
1454
+ dbg2.originalText = originText;
1455
+ try {
1456
+ dbg2.toolCalls = JSON.stringify([
1457
+ { toolName: toolCall.toolName, input: toolCall.input }
1458
+ ]);
1459
+ } catch (e) {
1460
+ }
1461
+ } else if (debugLevelToolChoice === "parse") {
1453
1462
  logParsedSummary({ toolCalls: [toolCall], originalText: originText });
1454
1463
  }
1455
1464
  return {
@@ -1458,7 +1467,7 @@ async function wrapGenerate({
1458
1467
  };
1459
1468
  }
1460
1469
  const tools = originalToolsSchema.decode(
1461
- (_d = (_c = params.providerOptions) == null ? void 0 : _c.toolCallMiddleware) == null ? void 0 : _d.originalTools
1470
+ (_f = (_e = params.providerOptions) == null ? void 0 : _e.toolCallMiddleware) == null ? void 0 : _f.originalTools
1462
1471
  );
1463
1472
  const result = await doGenerate();
1464
1473
  if (result.content.length === 0) {
@@ -1489,15 +1498,27 @@ async function wrapGenerate({
1489
1498
  if (debugLevel === "stream") {
1490
1499
  newContent.forEach((part) => logParsedChunk(part));
1491
1500
  }
1492
- if (debugLevel === "parse") {
1493
- const allText = result.content.filter(
1494
- (c) => c.type === "text"
1495
- ).map((c) => c.text).join("\n\n");
1496
- const segments = protocol.extractToolCallSegments ? protocol.extractToolCallSegments({ text: allText, tools }) : [];
1497
- const originalText = segments.join("\n\n");
1498
- const toolCalls = newContent.filter(
1499
- (p) => p.type === "tool-call"
1500
- );
1501
+ const allText = result.content.filter(
1502
+ (c) => c.type === "text"
1503
+ ).map((c) => c.text).join("\n\n");
1504
+ const segments = protocol.extractToolCallSegments ? protocol.extractToolCallSegments({ text: allText, tools }) : [];
1505
+ const originalText = segments.join("\n\n");
1506
+ const toolCalls = newContent.filter(
1507
+ (p) => p.type === "tool-call"
1508
+ );
1509
+ const dbg = (_h = (_g = params.providerOptions) == null ? void 0 : _g.toolCallMiddleware) == null ? void 0 : _h.debugSummary;
1510
+ if (dbg) {
1511
+ dbg.originalText = originalText;
1512
+ try {
1513
+ dbg.toolCalls = JSON.stringify(
1514
+ toolCalls.map((tc) => ({
1515
+ toolName: tc.toolName,
1516
+ input: tc.input
1517
+ }))
1518
+ );
1519
+ } catch (e) {
1520
+ }
1521
+ } else if (debugLevel === "parse") {
1501
1522
  logParsedSummary({ toolCalls, originalText });
1502
1523
  }
1503
1524
  return {
@@ -1619,6 +1640,7 @@ async function wrapStream({
1619
1640
  transform: /* @__PURE__ */ (() => {
1620
1641
  const parsedToolCalls = [];
1621
1642
  return (part, controller) => {
1643
+ var _a2, _b2;
1622
1644
  if (part.type === "tool-call") {
1623
1645
  parsedToolCalls.push(part);
1624
1646
  }
@@ -1629,10 +1651,27 @@ async function wrapStream({
1629
1651
  tools
1630
1652
  }) : [];
1631
1653
  const origin = segments.join("\n\n");
1632
- logParsedSummary({
1633
- toolCalls: parsedToolCalls,
1634
- originalText: origin
1635
- });
1654
+ const dbg = (_b2 = (_a2 = params.providerOptions) == null ? void 0 : _a2.toolCallMiddleware) == null ? void 0 : _b2.debugSummary;
1655
+ if (dbg) {
1656
+ dbg.originalText = origin;
1657
+ try {
1658
+ const toolCallParts = parsedToolCalls.filter(
1659
+ (p) => p.type === "tool-call"
1660
+ );
1661
+ dbg.toolCalls = JSON.stringify(
1662
+ toolCallParts.map((tc) => ({
1663
+ toolName: tc.toolName,
1664
+ input: tc.input
1665
+ }))
1666
+ );
1667
+ } catch (e) {
1668
+ }
1669
+ } else {
1670
+ logParsedSummary({
1671
+ toolCalls: parsedToolCalls,
1672
+ originalText: origin
1673
+ });
1674
+ }
1636
1675
  } catch (e) {
1637
1676
  }
1638
1677
  }