@ai-sdk-tool/parser 4.1.8 → 4.1.9

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
@@ -7,13 +7,13 @@ import {
7
7
  safeStringifyInputExample,
8
8
  toSafeXmlTagName,
9
9
  uiTarsXmlProtocol
10
- } from "./chunk-7EDEAFRX.js";
10
+ } from "./chunk-AELRIRO2.js";
11
11
  import {
12
12
  escapeXmlMinimalAttr,
13
13
  escapeXmlMinimalText,
14
14
  stringify
15
- } from "./chunk-IATDQDRY.js";
16
- import "./chunk-A3DLFT2S.js";
15
+ } from "./chunk-TLZV6QE3.js";
16
+ import "./chunk-KLP3RUJ2.js";
17
17
  import "./chunk-GMTE7BY5.js";
18
18
 
19
19
  // src/community/sijawara.ts
package/dist/index.cjs CHANGED
@@ -124,7 +124,7 @@ function makeLexer(tokenSpecs) {
124
124
  const matched = findToken();
125
125
  if (!matched) {
126
126
  const err = new SyntaxError(
127
- `Unexpected character: ${remainingContents[0]}; input: ${remainingContents.substr(
127
+ `Unexpected character: ${remainingContents[0]}; input: ${remainingContents.slice(
128
128
  0,
129
129
  100
130
130
  )}`
@@ -2007,7 +2007,7 @@ function processMatchedToolCall(context) {
2007
2007
  const startIndex = match.index;
2008
2008
  const toolCallJson = match[1];
2009
2009
  if (startIndex > currentIndex) {
2010
- const textSegment = text.substring(currentIndex, startIndex);
2010
+ const textSegment = text.slice(currentIndex, startIndex);
2011
2011
  addTextSegment(textSegment, processedElements);
2012
2012
  }
2013
2013
  if (toolCallJson) {
@@ -2580,7 +2580,7 @@ var hermesProtocol = ({
2580
2580
  match = toolCallRegex.exec(text);
2581
2581
  }
2582
2582
  if (currentIndex < text.length) {
2583
- const remainingText = text.substring(currentIndex);
2583
+ const remainingText = text.slice(currentIndex);
2584
2584
  addTextSegment(remainingText, processedElements);
2585
2585
  }
2586
2586
  return processedElements;
@@ -2873,7 +2873,7 @@ function extractObjectParts(obj) {
2873
2873
  let textContent;
2874
2874
  for (const [key, value] of Object.entries(obj)) {
2875
2875
  if (key.startsWith("@")) {
2876
- attributes[key.substring(1)] = value;
2876
+ attributes[key.slice(1)] = value;
2877
2877
  } else if (key === "#text" || key === "_text") {
2878
2878
  textContent = String(value);
2879
2879
  } else if (key === "_attributes") {
@@ -3667,7 +3667,7 @@ var XMLTokenizer = class {
3667
3667
  handleClosingTag(tagName, children) {
3668
3668
  const closeStart = this.pos + 2;
3669
3669
  this.pos = this.xmlString.indexOf(">", this.pos);
3670
- const closeTag = this.xmlString.substring(closeStart, this.pos);
3670
+ const closeTag = this.xmlString.slice(closeStart, this.pos);
3671
3671
  if (tagName && closeTag.trim() !== tagName) {
3672
3672
  const { line, column } = getLineColumn(this.xmlString, this.pos);
3673
3673
  throw new RXMLParseError(
@@ -3913,7 +3913,7 @@ var XMLTokenizer = class {
3913
3913
  handleSpecialContent(children) {
3914
3914
  if (this.xmlString.charCodeAt(this.pos + 2) === CharCodes.MINUS) {
3915
3915
  this.handleComment(children);
3916
- } else if (this.xmlString.charCodeAt(this.pos + 2) === CharCodes.OPEN_CORNER_BRACKET && this.xmlString.charCodeAt(this.pos + 8) === CharCodes.OPEN_CORNER_BRACKET && this.xmlString.substr(this.pos + 3, 5).toLowerCase() === "cdata") {
3916
+ } else if (this.xmlString.charCodeAt(this.pos + 2) === CharCodes.OPEN_CORNER_BRACKET && this.xmlString.charCodeAt(this.pos + 8) === CharCodes.OPEN_CORNER_BRACKET && this.xmlString.slice(this.pos + 3, this.pos + 8).toLowerCase() === "cdata") {
3917
3917
  this.handleCData(children);
3918
3918
  } else {
3919
3919
  this.handleDoctype(children);
@@ -3931,7 +3931,7 @@ var XMLTokenizer = class {
3931
3931
  this.pos = this.xmlString.length;
3932
3932
  }
3933
3933
  if (this.options.keepComments) {
3934
- children.push(this.xmlString.substring(startCommentPos, this.pos + 1));
3934
+ children.push(this.xmlString.slice(startCommentPos, this.pos + 1));
3935
3935
  }
3936
3936
  this.pos += 1;
3937
3937
  }
@@ -3941,10 +3941,10 @@ var XMLTokenizer = class {
3941
3941
  handleCData(children) {
3942
3942
  const cdataEndIndex = this.xmlString.indexOf("]]>", this.pos);
3943
3943
  if (cdataEndIndex === -1) {
3944
- children.push(this.xmlString.substr(this.pos + 9));
3944
+ children.push(this.xmlString.slice(this.pos + 9));
3945
3945
  this.pos = this.xmlString.length;
3946
3946
  } else {
3947
- children.push(this.xmlString.substring(this.pos + 9, cdataEndIndex));
3947
+ children.push(this.xmlString.slice(this.pos + 9, cdataEndIndex));
3948
3948
  this.pos = cdataEndIndex + 3;
3949
3949
  }
3950
3950
  }
@@ -3963,7 +3963,7 @@ var XMLTokenizer = class {
3963
3963
  }
3964
3964
  this.pos += 1;
3965
3965
  }
3966
- children.push(this.xmlString.substring(startDoctype, this.pos));
3966
+ children.push(this.xmlString.slice(startDoctype, this.pos));
3967
3967
  this.pos += 1;
3968
3968
  }
3969
3969
  /**
@@ -4964,9 +4964,9 @@ function processToolCallInBuffer(params) {
4964
4964
  }
4965
4965
  const endIdx = endMatch.index;
4966
4966
  const endPos = endIdx + endMatch[0].length;
4967
- const content = buffer.substring(0, endIdx);
4967
+ const content = buffer.slice(0, endIdx);
4968
4968
  emitToolInputProgress2(controller, currentToolCall, content);
4969
- const remainder = buffer.substring(endPos);
4969
+ const remainder = buffer.slice(endPos);
4970
4970
  setBuffer(remainder);
4971
4971
  handleStreamingToolCallEnd2({
4972
4972
  toolContent: content,
@@ -5021,9 +5021,9 @@ function processNoToolCallInBuffer(params) {
5021
5021
  shouldContinue: false
5022
5022
  };
5023
5023
  }
5024
- flushText(controller, buffer.substring(0, earliestStartTagIndex));
5024
+ flushText(controller, buffer.slice(0, earliestStartTagIndex));
5025
5025
  if (selfClosing) {
5026
- const newBuffer2 = buffer.substring(earliestStartTagIndex + tagLength);
5026
+ const newBuffer2 = buffer.slice(earliestStartTagIndex + tagLength);
5027
5027
  setBuffer(newBuffer2);
5028
5028
  const currentToolCall = emitToolInputStart(controller, earliestToolName);
5029
5029
  handleStreamingToolCallEnd2({
@@ -5043,7 +5043,7 @@ function processNoToolCallInBuffer(params) {
5043
5043
  };
5044
5044
  }
5045
5045
  const startTag = `<${earliestToolName}>`;
5046
- const newBuffer = buffer.substring(earliestStartTagIndex + startTag.length);
5046
+ const newBuffer = buffer.slice(earliestStartTagIndex + startTag.length);
5047
5047
  setBuffer(newBuffer);
5048
5048
  return {
5049
5049
  buffer: newBuffer,
@@ -5124,10 +5124,7 @@ function processToolCall(params) {
5124
5124
  input: JSON.stringify(parsed)
5125
5125
  });
5126
5126
  } catch (error) {
5127
- const originalCallText = text.substring(
5128
- toolCall.startIndex,
5129
- toolCall.endIndex
5130
- );
5127
+ const originalCallText = text.slice(toolCall.startIndex, toolCall.endIndex);
5131
5128
  (_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(
5132
5129
  options,
5133
5130
  `Could not process XML tool call: ${toolCall.toolName}`,
@@ -5697,7 +5694,7 @@ function pushSelfClosingToolCall(toolCalls, toolName, text, tagStart, tagLength)
5697
5694
  startIndex: tagStart,
5698
5695
  endIndex,
5699
5696
  content: "",
5700
- segment: text.substring(tagStart, endIndex)
5697
+ segment: text.slice(tagStart, endIndex)
5701
5698
  });
5702
5699
  return endIndex;
5703
5700
  }
@@ -5707,7 +5704,7 @@ function appendOpenToolCallIfComplete(toolCalls, text, toolName, tagStart, start
5707
5704
  if (fullTagEnd === -1 || fullTagEnd <= contentStart) {
5708
5705
  return contentStart;
5709
5706
  }
5710
- const segment = text.substring(tagStart, fullTagEnd);
5707
+ const segment = text.slice(tagStart, fullTagEnd);
5711
5708
  const closeTagStart = findLastCloseTagStart(segment, toolName);
5712
5709
  const inner = closeTagStart === -1 ? segment.slice(startTag.length) : segment.slice(startTag.length, closeTagStart);
5713
5710
  toolCalls.push({
@@ -5991,7 +5988,7 @@ var morphXmlProtocol = (protocolOptions) => {
5991
5988
  if (tc.startIndex > currentIndex) {
5992
5989
  processedElements.push({
5993
5990
  type: "text",
5994
- text: parseText.substring(currentIndex, tc.startIndex)
5991
+ text: parseText.slice(currentIndex, tc.startIndex)
5995
5992
  });
5996
5993
  }
5997
5994
  processToolCall({
@@ -6007,7 +6004,7 @@ var morphXmlProtocol = (protocolOptions) => {
6007
6004
  if (currentIndex < parseText.length) {
6008
6005
  processedElements.push({
6009
6006
  type: "text",
6010
- text: parseText.substring(currentIndex)
6007
+ text: parseText.slice(currentIndex)
6011
6008
  });
6012
6009
  }
6013
6010
  return processedElements;
@@ -8413,7 +8410,7 @@ function collectToolCallsForName(text, toolName) {
8413
8410
  if (fullTagEnd !== -1 && fullTagEnd > contentStart) {
8414
8411
  const endTag = `</${toolName}>`;
8415
8412
  const endTagStart = fullTagEnd - endTag.length;
8416
- const content = text.substring(contentStart, endTagStart);
8413
+ const content = text.slice(contentStart, endTagStart);
8417
8414
  toolCalls.push({
8418
8415
  toolName,
8419
8416
  startIndex: tagStart,
@@ -8483,13 +8480,10 @@ function processToolCallMatch(text, tc, currentIndex, processedElements, options
8483
8480
  if (tc.startIndex < currentIndex) {
8484
8481
  return currentIndex;
8485
8482
  }
8486
- addTextSegment(
8487
- text.substring(currentIndex, tc.startIndex),
8488
- processedElements
8489
- );
8483
+ addTextSegment(text.slice(currentIndex, tc.startIndex), processedElements);
8490
8484
  const parsedArgs = parseYamlContent(tc.content, options);
8491
8485
  if (parsedArgs === null) {
8492
- const originalText = text.substring(tc.startIndex, tc.endIndex);
8486
+ const originalText = text.slice(tc.startIndex, tc.endIndex);
8493
8487
  (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse YAML tool call", {
8494
8488
  toolCall: originalText
8495
8489
  });
@@ -8577,7 +8571,7 @@ ${yamlContent}</${toolCall.toolName}>`;
8577
8571
  );
8578
8572
  }
8579
8573
  if (currentIndex < parseText.length) {
8580
- addTextSegment(parseText.substring(currentIndex), processedElements);
8574
+ addTextSegment(parseText.slice(currentIndex), processedElements);
8581
8575
  }
8582
8576
  return processedElements;
8583
8577
  },
@@ -8716,9 +8710,9 @@ ${yamlContent}</${toolCall.toolName}>`;
8716
8710
  emitToolInputProgress2(controller, buffer);
8717
8711
  return false;
8718
8712
  }
8719
- const content = buffer.substring(0, endIdx);
8713
+ const content = buffer.slice(0, endIdx);
8720
8714
  emitToolInputProgress2(controller, content);
8721
- buffer = buffer.substring(endIdx + endTag.length);
8715
+ buffer = buffer.slice(endIdx + endTag.length);
8722
8716
  processToolCallEnd(
8723
8717
  controller,
8724
8718
  content,
@@ -8739,11 +8733,11 @@ ${yamlContent}</${toolCall.toolName}>`;
8739
8733
  };
8740
8734
  const handleNewToolTag = (controller, tagIndex, tagName, selfClosing, tagLength) => {
8741
8735
  if (tagIndex > 0) {
8742
- flushText(controller, buffer.substring(0, tagIndex));
8736
+ flushText(controller, buffer.slice(0, tagIndex));
8743
8737
  }
8744
8738
  flushText(controller);
8745
8739
  if (selfClosing) {
8746
- buffer = buffer.substring(tagIndex + tagLength);
8740
+ buffer = buffer.slice(tagIndex + tagLength);
8747
8741
  const toolCallId = generateToolCallId();
8748
8742
  currentToolCall = {
8749
8743
  name: tagName,
@@ -8759,7 +8753,7 @@ ${yamlContent}</${toolCall.toolName}>`;
8759
8753
  currentToolCall = null;
8760
8754
  } else {
8761
8755
  const startTag = `<${tagName}>`;
8762
- buffer = buffer.substring(tagIndex + startTag.length);
8756
+ buffer = buffer.slice(tagIndex + startTag.length);
8763
8757
  currentToolCall = {
8764
8758
  name: tagName,
8765
8759
  toolCallId: generateToolCallId(),