@ai-sdk-tool/parser 3.3.1 → 3.3.2

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/community.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createToolMiddleware,
3
3
  xmlProtocol
4
- } from "./chunk-7E6UFDFQ.js";
5
- import "./chunk-EW3A6Y7O.js";
4
+ } from "./chunk-5WKXBBCU.js";
5
+ import "./chunk-ZDBNJWLY.js";
6
6
  import "./chunk-IX4FJELL.js";
7
7
  import "./chunk-OUGMLYAW.js";
8
8
 
package/dist/index.cjs CHANGED
@@ -908,6 +908,13 @@ function generateId() {
908
908
  return Math.random().toString(36).substring(2, 15);
909
909
  }
910
910
 
911
+ // src/core/utils/protocol-utils.ts
912
+ function addTextSegment(text, processedElements) {
913
+ if (text.trim()) {
914
+ processedElements.push({ type: "text", text });
915
+ }
916
+ }
917
+
911
918
  // src/core/utils/regex.ts
912
919
  function escapeRegExp(literal) {
913
920
  return literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -939,11 +946,6 @@ function processToolCallJson(toolCallJson, fullMatch, processedElements, options
939
946
  processedElements.push({ type: "text", text: fullMatch });
940
947
  }
941
948
  }
942
- function addTextSegment(text, processedElements) {
943
- if (text.trim()) {
944
- processedElements.push({ type: "text", text });
945
- }
946
- }
947
949
  function processMatchedToolCall(context) {
948
950
  const { match, text, currentIndex, processedElements, options } = context;
949
951
  const startIndex = match.index;
@@ -3703,12 +3705,9 @@ function getStringPropertyNames(schema) {
3703
3705
  }
3704
3706
  return names;
3705
3707
  }
3706
- function escapeRegExp2(s) {
3707
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3708
- }
3709
3708
  function dedupeSingleTag(xml, key) {
3710
3709
  var _a, _b;
3711
- const escaped = escapeRegExp2(key);
3710
+ const escaped = escapeRegExp(key);
3712
3711
  const re = new RegExp(`<${escaped}>([\\s\\S]*?)<\\/${escaped}>`, "g");
3713
3712
  const matches = Array.from(xml.matchAll(re));
3714
3713
  if (matches.length <= 1) {
@@ -3825,9 +3824,11 @@ function parse3(xml, schema, options = {}) {
3825
3824
  throw new RXMLParseError("Failed to parse XML with repair heuristics", error);
3826
3825
  }
3827
3826
 
3828
- // src/core/protocols/xml-protocol.ts
3827
+ // src/core/utils/regex-constants.ts
3829
3828
  var NAME_CHAR_RE2 = /[A-Za-z0-9_:-]/;
3830
3829
  var WHITESPACE_REGEX4 = /\s/;
3830
+
3831
+ // src/core/protocols/xml-protocol.ts
3831
3832
  function getToolSchema(tools, toolName) {
3832
3833
  var _a;
3833
3834
  return (_a = tools.find((t) => t.name === toolName)) == null ? void 0 : _a.inputSchema;
@@ -4535,8 +4536,6 @@ var xmlProtocol = (protocolOptions) => {
4535
4536
 
4536
4537
  // src/core/protocols/yaml-protocol.ts
4537
4538
  var import_yaml = __toESM(require("yaml"), 1);
4538
- var NAME_CHAR_RE3 = /[A-Za-z0-9_:-]/;
4539
- var WHITESPACE_REGEX5 = /\s/;
4540
4539
  var LEADING_WHITESPACE_RE = /^(\s*)/;
4541
4540
  function findClosingTagEnd(text, contentStart, toolName) {
4542
4541
  let pos = contentStart;
@@ -4553,11 +4552,11 @@ function findClosingTagEnd(text, contentStart, toolName) {
4553
4552
  break;
4554
4553
  }
4555
4554
  let p = ltIdx + 2;
4556
- while (p < gtIdx && WHITESPACE_REGEX5.test(text[p])) {
4555
+ while (p < gtIdx && WHITESPACE_REGEX4.test(text[p])) {
4557
4556
  p++;
4558
4557
  }
4559
4558
  const nameStart = p;
4560
- while (p < gtIdx && NAME_CHAR_RE3.test(text.charAt(p))) {
4559
+ while (p < gtIdx && NAME_CHAR_RE2.test(text.charAt(p))) {
4561
4560
  p++;
4562
4561
  }
4563
4562
  const name = text.slice(nameStart, p);
@@ -4573,11 +4572,11 @@ function findClosingTagEnd(text, contentStart, toolName) {
4573
4572
  pos = gtIdx === -1 ? text.length : gtIdx + 1;
4574
4573
  } else {
4575
4574
  let p = ltIdx + 1;
4576
- while (p < text.length && WHITESPACE_REGEX5.test(text[p])) {
4575
+ while (p < text.length && WHITESPACE_REGEX4.test(text[p])) {
4577
4576
  p++;
4578
4577
  }
4579
4578
  const nameStart = p;
4580
- while (p < text.length && NAME_CHAR_RE3.test(text.charAt(p))) {
4579
+ while (p < text.length && NAME_CHAR_RE2.test(text.charAt(p))) {
4581
4580
  p++;
4582
4581
  }
4583
4582
  const name = text.slice(nameStart, p);
@@ -4586,7 +4585,7 @@ function findClosingTagEnd(text, contentStart, toolName) {
4586
4585
  break;
4587
4586
  }
4588
4587
  let r = gtIdx - 1;
4589
- while (r >= nameStart && WHITESPACE_REGEX5.test(text[r])) {
4588
+ while (r >= nameStart && WHITESPACE_REGEX4.test(text[r])) {
4590
4589
  r--;
4591
4590
  }
4592
4591
  const selfClosing = text[r] === "/";
@@ -4704,22 +4703,14 @@ function parseYamlContent(yamlContent, options) {
4704
4703
  return null;
4705
4704
  }
4706
4705
  }
4707
- function appendTextPart(processedElements, textPart) {
4708
- if (textPart.trim()) {
4709
- processedElements.push({
4710
- type: "text",
4711
- text: textPart
4712
- });
4713
- }
4714
- }
4715
4706
  function processToolCallMatch(text, tc, currentIndex, processedElements, options) {
4716
4707
  var _a;
4717
4708
  if (tc.startIndex < currentIndex) {
4718
4709
  return currentIndex;
4719
4710
  }
4720
- appendTextPart(
4721
- processedElements,
4722
- text.substring(currentIndex, tc.startIndex)
4711
+ addTextSegment(
4712
+ text.substring(currentIndex, tc.startIndex),
4713
+ processedElements
4723
4714
  );
4724
4715
  const parsedArgs = parseYamlContent(tc.content, options);
4725
4716
  if (parsedArgs !== null) {
@@ -4837,7 +4828,7 @@ ${yamlContent}</${toolCall.toolName}>`;
4837
4828
  );
4838
4829
  }
4839
4830
  if (currentIndex < text.length) {
4840
- appendTextPart(processedElements, text.substring(currentIndex));
4831
+ addTextSegment(text.substring(currentIndex), processedElements);
4841
4832
  }
4842
4833
  return processedElements;
4843
4834
  },