@ai-sdk-tool/parser 2.1.5 → 2.1.7

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
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
33
  RJSON: () => robust_json_exports,
34
34
  createDynamicIfThenElseSchema: () => createDynamicIfThenElseSchema,
35
35
  createToolMiddleware: () => createToolMiddleware,
@@ -51,10 +51,10 @@ __export(index_exports, {
51
51
  logParsedSummary: () => logParsedSummary,
52
52
  logRawChunk: () => logRawChunk,
53
53
  morphXmlProtocol: () => morphXmlProtocol,
54
- originalToolsSchema: () => originalToolsSchema,
55
- xmlToolMiddleware: () => xmlToolMiddleware
54
+ morphXmlToolMiddleware: () => morphXmlToolMiddleware,
55
+ originalToolsSchema: () => originalToolsSchema
56
56
  });
57
- module.exports = __toCommonJS(index_exports);
57
+ module.exports = __toCommonJS(src_exports);
58
58
 
59
59
  // src/protocols/dummy-protocol.ts
60
60
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -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
  }
@@ -2029,21 +2068,26 @@ For each function call return a json object with function name and arguments wit
2029
2068
  </tool_call>`;
2030
2069
  }
2031
2070
  });
2032
- var xmlToolMiddleware = createToolMiddleware({
2071
+ var morphXmlToolMiddleware = createToolMiddleware({
2033
2072
  protocol: morphXmlProtocol,
2034
2073
  toolSystemPromptTemplate(tools) {
2035
2074
  return `You are a function calling AI model.
2036
- You are provided with function signatures within <tools></tools> XML tags.
2037
- You may call one or more functions to assist with the user query.
2038
- Don't make assumptions about what values to plug into functions.
2039
- Here are the available tools: <tools>${tools}</tools>
2040
- For a function call, return exactly one XML element whose tag name matches the tool's name, and nothing else.
2041
- When an argument is an array, write each item inside a single element on one line separated by commas (or provide a JSON-like list). When an argument is an object, provide a JSON-like value.
2042
- Examples:
2075
+
2076
+ Available functions are listed inside <tools></tools>.
2077
+ <tools>${tools}</tools>
2078
+
2079
+ # Rules
2080
+ - Use exactly one XML element whose tag name is the function name.
2081
+ - Put each parameter as a child element.
2082
+ - Values must follow the schema exactly (numbers, arrays, objects, enums \u2192 copy as-is).
2083
+ - Do not add or remove functions or parameters.
2084
+ - Each required parameter must appear once.
2085
+ - Output nothing before or after the function call.
2086
+
2087
+ # Example
2043
2088
  <get_weather>
2044
- <location>
2045
- San Francisco
2046
- </location>
2089
+ <location>New York</location>
2090
+ <unit>celsius</unit>
2047
2091
  </get_weather>`;
2048
2092
  }
2049
2093
  });
@@ -2070,7 +2114,7 @@ San Francisco
2070
2114
  logParsedSummary,
2071
2115
  logRawChunk,
2072
2116
  morphXmlProtocol,
2073
- originalToolsSchema,
2074
- xmlToolMiddleware
2117
+ morphXmlToolMiddleware,
2118
+ originalToolsSchema
2075
2119
  });
2076
2120
  //# sourceMappingURL=index.cjs.map