@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.
@@ -269,7 +269,7 @@ function extractObjectParts(obj) {
269
269
  let textContent;
270
270
  for (const [key, value] of Object.entries(obj)) {
271
271
  if (key.startsWith("@")) {
272
- attributes[key.substring(1)] = value;
272
+ attributes[key.slice(1)] = value;
273
273
  } else if (key === "#text" || key === "_text") {
274
274
  textContent = String(value);
275
275
  } else if (key === "_attributes") {
@@ -1828,7 +1828,7 @@ var XMLTokenizer = class {
1828
1828
  handleClosingTag(tagName, children) {
1829
1829
  const closeStart = this.pos + 2;
1830
1830
  this.pos = this.xmlString.indexOf(">", this.pos);
1831
- const closeTag = this.xmlString.substring(closeStart, this.pos);
1831
+ const closeTag = this.xmlString.slice(closeStart, this.pos);
1832
1832
  if (tagName && closeTag.trim() !== tagName) {
1833
1833
  const { line, column } = getLineColumn(this.xmlString, this.pos);
1834
1834
  throw new RXMLParseError(
@@ -2074,7 +2074,7 @@ var XMLTokenizer = class {
2074
2074
  handleSpecialContent(children) {
2075
2075
  if (this.xmlString.charCodeAt(this.pos + 2) === CharCodes.MINUS) {
2076
2076
  this.handleComment(children);
2077
- } 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") {
2077
+ } 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") {
2078
2078
  this.handleCData(children);
2079
2079
  } else {
2080
2080
  this.handleDoctype(children);
@@ -2092,7 +2092,7 @@ var XMLTokenizer = class {
2092
2092
  this.pos = this.xmlString.length;
2093
2093
  }
2094
2094
  if (this.options.keepComments) {
2095
- children.push(this.xmlString.substring(startCommentPos, this.pos + 1));
2095
+ children.push(this.xmlString.slice(startCommentPos, this.pos + 1));
2096
2096
  }
2097
2097
  this.pos += 1;
2098
2098
  }
@@ -2102,10 +2102,10 @@ var XMLTokenizer = class {
2102
2102
  handleCData(children) {
2103
2103
  const cdataEndIndex = this.xmlString.indexOf("]]>", this.pos);
2104
2104
  if (cdataEndIndex === -1) {
2105
- children.push(this.xmlString.substr(this.pos + 9));
2105
+ children.push(this.xmlString.slice(this.pos + 9));
2106
2106
  this.pos = this.xmlString.length;
2107
2107
  } else {
2108
- children.push(this.xmlString.substring(this.pos + 9, cdataEndIndex));
2108
+ children.push(this.xmlString.slice(this.pos + 9, cdataEndIndex));
2109
2109
  this.pos = cdataEndIndex + 3;
2110
2110
  }
2111
2111
  }
@@ -2124,7 +2124,7 @@ var XMLTokenizer = class {
2124
2124
  }
2125
2125
  this.pos += 1;
2126
2126
  }
2127
- children.push(this.xmlString.substring(startDoctype, this.pos));
2127
+ children.push(this.xmlString.slice(startDoctype, this.pos));
2128
2128
  this.pos += 1;
2129
2129
  }
2130
2130
  /**
@@ -3593,7 +3593,7 @@ function makeLexer(tokenSpecs) {
3593
3593
  const matched = findToken();
3594
3594
  if (!matched) {
3595
3595
  const err = new SyntaxError(
3596
- `Unexpected character: ${remainingContents[0]}; input: ${remainingContents.substr(
3596
+ `Unexpected character: ${remainingContents[0]}; input: ${remainingContents.slice(
3597
3597
  0,
3598
3598
  100
3599
3599
  )}`
@@ -4678,7 +4678,7 @@ function processMatchedToolCall(context) {
4678
4678
  const startIndex = match.index;
4679
4679
  const toolCallJson = match[1];
4680
4680
  if (startIndex > currentIndex) {
4681
- const textSegment = text.substring(currentIndex, startIndex);
4681
+ const textSegment = text.slice(currentIndex, startIndex);
4682
4682
  addTextSegment(textSegment, processedElements);
4683
4683
  }
4684
4684
  if (toolCallJson) {
@@ -5251,7 +5251,7 @@ var hermesProtocol = ({
5251
5251
  match = toolCallRegex.exec(text);
5252
5252
  }
5253
5253
  if (currentIndex < text.length) {
5254
- const remainingText = text.substring(currentIndex);
5254
+ const remainingText = text.slice(currentIndex);
5255
5255
  addTextSegment(remainingText, processedElements);
5256
5256
  }
5257
5257
  return processedElements;
@@ -5433,9 +5433,9 @@ function processToolCallInBuffer(params) {
5433
5433
  }
5434
5434
  const endIdx = endMatch.index;
5435
5435
  const endPos = endIdx + endMatch[0].length;
5436
- const content = buffer.substring(0, endIdx);
5436
+ const content = buffer.slice(0, endIdx);
5437
5437
  emitToolInputProgress2(controller, currentToolCall, content);
5438
- const remainder = buffer.substring(endPos);
5438
+ const remainder = buffer.slice(endPos);
5439
5439
  setBuffer(remainder);
5440
5440
  handleStreamingToolCallEnd2({
5441
5441
  toolContent: content,
@@ -5490,9 +5490,9 @@ function processNoToolCallInBuffer(params) {
5490
5490
  shouldContinue: false
5491
5491
  };
5492
5492
  }
5493
- flushText(controller, buffer.substring(0, earliestStartTagIndex));
5493
+ flushText(controller, buffer.slice(0, earliestStartTagIndex));
5494
5494
  if (selfClosing) {
5495
- const newBuffer2 = buffer.substring(earliestStartTagIndex + tagLength);
5495
+ const newBuffer2 = buffer.slice(earliestStartTagIndex + tagLength);
5496
5496
  setBuffer(newBuffer2);
5497
5497
  const currentToolCall = emitToolInputStart(controller, earliestToolName);
5498
5498
  handleStreamingToolCallEnd2({
@@ -5512,7 +5512,7 @@ function processNoToolCallInBuffer(params) {
5512
5512
  };
5513
5513
  }
5514
5514
  const startTag = `<${earliestToolName}>`;
5515
- const newBuffer = buffer.substring(earliestStartTagIndex + startTag.length);
5515
+ const newBuffer = buffer.slice(earliestStartTagIndex + startTag.length);
5516
5516
  setBuffer(newBuffer);
5517
5517
  return {
5518
5518
  buffer: newBuffer,
@@ -5593,10 +5593,7 @@ function processToolCall(params) {
5593
5593
  input: JSON.stringify(parsed)
5594
5594
  });
5595
5595
  } catch (error) {
5596
- const originalCallText = text.substring(
5597
- toolCall.startIndex,
5598
- toolCall.endIndex
5599
- );
5596
+ const originalCallText = text.slice(toolCall.startIndex, toolCall.endIndex);
5600
5597
  (_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(
5601
5598
  options,
5602
5599
  `Could not process XML tool call: ${toolCall.toolName}`,
@@ -6166,7 +6163,7 @@ function pushSelfClosingToolCall(toolCalls, toolName, text, tagStart, tagLength)
6166
6163
  startIndex: tagStart,
6167
6164
  endIndex,
6168
6165
  content: "",
6169
- segment: text.substring(tagStart, endIndex)
6166
+ segment: text.slice(tagStart, endIndex)
6170
6167
  });
6171
6168
  return endIndex;
6172
6169
  }
@@ -6176,7 +6173,7 @@ function appendOpenToolCallIfComplete(toolCalls, text, toolName, tagStart, start
6176
6173
  if (fullTagEnd === -1 || fullTagEnd <= contentStart) {
6177
6174
  return contentStart;
6178
6175
  }
6179
- const segment = text.substring(tagStart, fullTagEnd);
6176
+ const segment = text.slice(tagStart, fullTagEnd);
6180
6177
  const closeTagStart = findLastCloseTagStart(segment, toolName);
6181
6178
  const inner = closeTagStart === -1 ? segment.slice(startTag.length) : segment.slice(startTag.length, closeTagStart);
6182
6179
  toolCalls.push({
@@ -6460,7 +6457,7 @@ var morphXmlProtocol = (protocolOptions) => {
6460
6457
  if (tc.startIndex > currentIndex) {
6461
6458
  processedElements.push({
6462
6459
  type: "text",
6463
- text: parseText.substring(currentIndex, tc.startIndex)
6460
+ text: parseText.slice(currentIndex, tc.startIndex)
6464
6461
  });
6465
6462
  }
6466
6463
  processToolCall({
@@ -6476,7 +6473,7 @@ var morphXmlProtocol = (protocolOptions) => {
6476
6473
  if (currentIndex < parseText.length) {
6477
6474
  processedElements.push({
6478
6475
  type: "text",
6479
- text: parseText.substring(currentIndex)
6476
+ text: parseText.slice(currentIndex)
6480
6477
  });
6481
6478
  }
6482
6479
  return processedElements;
@@ -8881,7 +8878,7 @@ function collectToolCallsForName(text, toolName) {
8881
8878
  if (fullTagEnd !== -1 && fullTagEnd > contentStart) {
8882
8879
  const endTag = `</${toolName}>`;
8883
8880
  const endTagStart = fullTagEnd - endTag.length;
8884
- const content = text.substring(contentStart, endTagStart);
8881
+ const content = text.slice(contentStart, endTagStart);
8885
8882
  toolCalls.push({
8886
8883
  toolName,
8887
8884
  startIndex: tagStart,
@@ -8951,13 +8948,10 @@ function processToolCallMatch(text, tc, currentIndex, processedElements, options
8951
8948
  if (tc.startIndex < currentIndex) {
8952
8949
  return currentIndex;
8953
8950
  }
8954
- addTextSegment(
8955
- text.substring(currentIndex, tc.startIndex),
8956
- processedElements
8957
- );
8951
+ addTextSegment(text.slice(currentIndex, tc.startIndex), processedElements);
8958
8952
  const parsedArgs = parseYamlContent(tc.content, options);
8959
8953
  if (parsedArgs === null) {
8960
- const originalText = text.substring(tc.startIndex, tc.endIndex);
8954
+ const originalText = text.slice(tc.startIndex, tc.endIndex);
8961
8955
  (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse YAML tool call", {
8962
8956
  toolCall: originalText
8963
8957
  });
@@ -9045,7 +9039,7 @@ ${yamlContent}</${toolCall.toolName}>`;
9045
9039
  );
9046
9040
  }
9047
9041
  if (currentIndex < parseText.length) {
9048
- addTextSegment(parseText.substring(currentIndex), processedElements);
9042
+ addTextSegment(parseText.slice(currentIndex), processedElements);
9049
9043
  }
9050
9044
  return processedElements;
9051
9045
  },
@@ -9184,9 +9178,9 @@ ${yamlContent}</${toolCall.toolName}>`;
9184
9178
  emitToolInputProgress2(controller, buffer);
9185
9179
  return false;
9186
9180
  }
9187
- const content = buffer.substring(0, endIdx);
9181
+ const content = buffer.slice(0, endIdx);
9188
9182
  emitToolInputProgress2(controller, content);
9189
- buffer = buffer.substring(endIdx + endTag.length);
9183
+ buffer = buffer.slice(endIdx + endTag.length);
9190
9184
  processToolCallEnd(
9191
9185
  controller,
9192
9186
  content,
@@ -9207,11 +9201,11 @@ ${yamlContent}</${toolCall.toolName}>`;
9207
9201
  };
9208
9202
  const handleNewToolTag = (controller, tagIndex, tagName, selfClosing, tagLength) => {
9209
9203
  if (tagIndex > 0) {
9210
- flushText(controller, buffer.substring(0, tagIndex));
9204
+ flushText(controller, buffer.slice(0, tagIndex));
9211
9205
  }
9212
9206
  flushText(controller);
9213
9207
  if (selfClosing) {
9214
- buffer = buffer.substring(tagIndex + tagLength);
9208
+ buffer = buffer.slice(tagIndex + tagLength);
9215
9209
  const toolCallId = generateToolCallId();
9216
9210
  currentToolCall = {
9217
9211
  name: tagName,
@@ -9227,7 +9221,7 @@ ${yamlContent}</${toolCall.toolName}>`;
9227
9221
  currentToolCall = null;
9228
9222
  } else {
9229
9223
  const startTag = `<${tagName}>`;
9230
- buffer = buffer.substring(tagIndex + startTag.length);
9224
+ buffer = buffer.slice(tagIndex + startTag.length);
9231
9225
  currentToolCall = {
9232
9226
  name: tagName,
9233
9227
  toolCallId: generateToolCallId(),