@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.d.cts CHANGED
@@ -283,6 +283,10 @@ declare function extractOnErrorOption(providerOptions?: unknown): {
283
283
 
284
284
  type ToolCallMiddlewareProviderOptions = {
285
285
  toolCallMiddleware?: {
286
+ debugSummary?: {
287
+ originalText?: string;
288
+ toolCalls?: string;
289
+ };
286
290
  toolChoice?: {
287
291
  type: string;
288
292
  };
package/dist/index.d.ts CHANGED
@@ -283,6 +283,10 @@ declare function extractOnErrorOption(providerOptions?: unknown): {
283
283
 
284
284
  type ToolCallMiddlewareProviderOptions = {
285
285
  toolCallMiddleware?: {
286
+ debugSummary?: {
287
+ originalText?: string;
288
+ toolCalls?: string;
289
+ };
286
290
  toolChoice?: {
287
291
  type: string;
288
292
  };
package/dist/index.js CHANGED
@@ -1364,7 +1364,7 @@ async function wrapGenerate({
1364
1364
  doGenerate,
1365
1365
  params
1366
1366
  }) {
1367
- var _a, _b, _c, _d;
1367
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1368
1368
  if (isToolChoiceActive(params)) {
1369
1369
  const result2 = await doGenerate();
1370
1370
  let parsed2 = {};
@@ -1397,7 +1397,16 @@ async function wrapGenerate({
1397
1397
  };
1398
1398
  const debugLevelToolChoice = getDebugLevel();
1399
1399
  const originText = first && first.type === "text" ? first.text : "";
1400
- if (debugLevelToolChoice === "parse") {
1400
+ const dbg2 = (_d = (_c = params.providerOptions) == null ? void 0 : _c.toolCallMiddleware) == null ? void 0 : _d.debugSummary;
1401
+ if (dbg2) {
1402
+ dbg2.originalText = originText;
1403
+ try {
1404
+ dbg2.toolCalls = JSON.stringify([
1405
+ { toolName: toolCall.toolName, input: toolCall.input }
1406
+ ]);
1407
+ } catch (e) {
1408
+ }
1409
+ } else if (debugLevelToolChoice === "parse") {
1401
1410
  logParsedSummary({ toolCalls: [toolCall], originalText: originText });
1402
1411
  }
1403
1412
  return {
@@ -1406,7 +1415,7 @@ async function wrapGenerate({
1406
1415
  };
1407
1416
  }
1408
1417
  const tools = originalToolsSchema.decode(
1409
- (_d = (_c = params.providerOptions) == null ? void 0 : _c.toolCallMiddleware) == null ? void 0 : _d.originalTools
1418
+ (_f = (_e = params.providerOptions) == null ? void 0 : _e.toolCallMiddleware) == null ? void 0 : _f.originalTools
1410
1419
  );
1411
1420
  const result = await doGenerate();
1412
1421
  if (result.content.length === 0) {
@@ -1437,15 +1446,27 @@ async function wrapGenerate({
1437
1446
  if (debugLevel === "stream") {
1438
1447
  newContent.forEach((part) => logParsedChunk(part));
1439
1448
  }
1440
- if (debugLevel === "parse") {
1441
- const allText = result.content.filter(
1442
- (c) => c.type === "text"
1443
- ).map((c) => c.text).join("\n\n");
1444
- const segments = protocol.extractToolCallSegments ? protocol.extractToolCallSegments({ text: allText, tools }) : [];
1445
- const originalText = segments.join("\n\n");
1446
- const toolCalls = newContent.filter(
1447
- (p) => p.type === "tool-call"
1448
- );
1449
+ const allText = result.content.filter(
1450
+ (c) => c.type === "text"
1451
+ ).map((c) => c.text).join("\n\n");
1452
+ const segments = protocol.extractToolCallSegments ? protocol.extractToolCallSegments({ text: allText, tools }) : [];
1453
+ const originalText = segments.join("\n\n");
1454
+ const toolCalls = newContent.filter(
1455
+ (p) => p.type === "tool-call"
1456
+ );
1457
+ const dbg = (_h = (_g = params.providerOptions) == null ? void 0 : _g.toolCallMiddleware) == null ? void 0 : _h.debugSummary;
1458
+ if (dbg) {
1459
+ dbg.originalText = originalText;
1460
+ try {
1461
+ dbg.toolCalls = JSON.stringify(
1462
+ toolCalls.map((tc) => ({
1463
+ toolName: tc.toolName,
1464
+ input: tc.input
1465
+ }))
1466
+ );
1467
+ } catch (e) {
1468
+ }
1469
+ } else if (debugLevel === "parse") {
1449
1470
  logParsedSummary({ toolCalls, originalText });
1450
1471
  }
1451
1472
  return {
@@ -1567,6 +1588,7 @@ async function wrapStream({
1567
1588
  transform: /* @__PURE__ */ (() => {
1568
1589
  const parsedToolCalls = [];
1569
1590
  return (part, controller) => {
1591
+ var _a2, _b2;
1570
1592
  if (part.type === "tool-call") {
1571
1593
  parsedToolCalls.push(part);
1572
1594
  }
@@ -1577,10 +1599,27 @@ async function wrapStream({
1577
1599
  tools
1578
1600
  }) : [];
1579
1601
  const origin = segments.join("\n\n");
1580
- logParsedSummary({
1581
- toolCalls: parsedToolCalls,
1582
- originalText: origin
1583
- });
1602
+ const dbg = (_b2 = (_a2 = params.providerOptions) == null ? void 0 : _a2.toolCallMiddleware) == null ? void 0 : _b2.debugSummary;
1603
+ if (dbg) {
1604
+ dbg.originalText = origin;
1605
+ try {
1606
+ const toolCallParts = parsedToolCalls.filter(
1607
+ (p) => p.type === "tool-call"
1608
+ );
1609
+ dbg.toolCalls = JSON.stringify(
1610
+ toolCallParts.map((tc) => ({
1611
+ toolName: tc.toolName,
1612
+ input: tc.input
1613
+ }))
1614
+ );
1615
+ } catch (e) {
1616
+ }
1617
+ } else {
1618
+ logParsedSummary({
1619
+ toolCalls: parsedToolCalls,
1620
+ originalText: origin
1621
+ });
1622
+ }
1584
1623
  } catch (e) {
1585
1624
  }
1586
1625
  }