@ai-sdk-tool/parser 4.1.7 → 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.
@@ -5,10 +5,10 @@ import {
5
5
  parse as parse2,
6
6
  stringify,
7
7
  unescapeXml
8
- } from "./chunk-IATDQDRY.js";
8
+ } from "./chunk-TLZV6QE3.js";
9
9
  import {
10
10
  parse
11
- } from "./chunk-A3DLFT2S.js";
11
+ } from "./chunk-KLP3RUJ2.js";
12
12
  import {
13
13
  coerceBySchema,
14
14
  getSchemaType,
@@ -515,7 +515,7 @@ function processMatchedToolCall(context) {
515
515
  const startIndex = match.index;
516
516
  const toolCallJson = match[1];
517
517
  if (startIndex > currentIndex) {
518
- const textSegment = text.substring(currentIndex, startIndex);
518
+ const textSegment = text.slice(currentIndex, startIndex);
519
519
  addTextSegment(textSegment, processedElements);
520
520
  }
521
521
  if (toolCallJson) {
@@ -1088,7 +1088,7 @@ var hermesProtocol = ({
1088
1088
  match = toolCallRegex.exec(text);
1089
1089
  }
1090
1090
  if (currentIndex < text.length) {
1091
- const remainingText = text.substring(currentIndex);
1091
+ const remainingText = text.slice(currentIndex);
1092
1092
  addTextSegment(remainingText, processedElements);
1093
1093
  }
1094
1094
  return processedElements;
@@ -1270,9 +1270,9 @@ function processToolCallInBuffer(params) {
1270
1270
  }
1271
1271
  const endIdx = endMatch.index;
1272
1272
  const endPos = endIdx + endMatch[0].length;
1273
- const content = buffer.substring(0, endIdx);
1273
+ const content = buffer.slice(0, endIdx);
1274
1274
  emitToolInputProgress2(controller, currentToolCall, content);
1275
- const remainder = buffer.substring(endPos);
1275
+ const remainder = buffer.slice(endPos);
1276
1276
  setBuffer(remainder);
1277
1277
  handleStreamingToolCallEnd2({
1278
1278
  toolContent: content,
@@ -1327,9 +1327,9 @@ function processNoToolCallInBuffer(params) {
1327
1327
  shouldContinue: false
1328
1328
  };
1329
1329
  }
1330
- flushText(controller, buffer.substring(0, earliestStartTagIndex));
1330
+ flushText(controller, buffer.slice(0, earliestStartTagIndex));
1331
1331
  if (selfClosing) {
1332
- const newBuffer2 = buffer.substring(earliestStartTagIndex + tagLength);
1332
+ const newBuffer2 = buffer.slice(earliestStartTagIndex + tagLength);
1333
1333
  setBuffer(newBuffer2);
1334
1334
  const currentToolCall = emitToolInputStart(controller, earliestToolName);
1335
1335
  handleStreamingToolCallEnd2({
@@ -1349,7 +1349,7 @@ function processNoToolCallInBuffer(params) {
1349
1349
  };
1350
1350
  }
1351
1351
  const startTag = `<${earliestToolName}>`;
1352
- const newBuffer = buffer.substring(earliestStartTagIndex + startTag.length);
1352
+ const newBuffer = buffer.slice(earliestStartTagIndex + startTag.length);
1353
1353
  setBuffer(newBuffer);
1354
1354
  return {
1355
1355
  buffer: newBuffer,
@@ -1430,10 +1430,7 @@ function processToolCall(params) {
1430
1430
  input: JSON.stringify(parsed)
1431
1431
  });
1432
1432
  } catch (error) {
1433
- const originalCallText = text.substring(
1434
- toolCall.startIndex,
1435
- toolCall.endIndex
1436
- );
1433
+ const originalCallText = text.slice(toolCall.startIndex, toolCall.endIndex);
1437
1434
  (_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(
1438
1435
  options,
1439
1436
  `Could not process XML tool call: ${toolCall.toolName}`,
@@ -2003,7 +2000,7 @@ function pushSelfClosingToolCall(toolCalls, toolName, text, tagStart, tagLength)
2003
2000
  startIndex: tagStart,
2004
2001
  endIndex,
2005
2002
  content: "",
2006
- segment: text.substring(tagStart, endIndex)
2003
+ segment: text.slice(tagStart, endIndex)
2007
2004
  });
2008
2005
  return endIndex;
2009
2006
  }
@@ -2013,7 +2010,7 @@ function appendOpenToolCallIfComplete(toolCalls, text, toolName, tagStart, start
2013
2010
  if (fullTagEnd === -1 || fullTagEnd <= contentStart) {
2014
2011
  return contentStart;
2015
2012
  }
2016
- const segment = text.substring(tagStart, fullTagEnd);
2013
+ const segment = text.slice(tagStart, fullTagEnd);
2017
2014
  const closeTagStart = findLastCloseTagStart(segment, toolName);
2018
2015
  const inner = closeTagStart === -1 ? segment.slice(startTag.length) : segment.slice(startTag.length, closeTagStart);
2019
2016
  toolCalls.push({
@@ -2297,7 +2294,7 @@ var morphXmlProtocol = (protocolOptions) => {
2297
2294
  if (tc.startIndex > currentIndex) {
2298
2295
  processedElements.push({
2299
2296
  type: "text",
2300
- text: parseText.substring(currentIndex, tc.startIndex)
2297
+ text: parseText.slice(currentIndex, tc.startIndex)
2301
2298
  });
2302
2299
  }
2303
2300
  processToolCall({
@@ -2313,7 +2310,7 @@ var morphXmlProtocol = (protocolOptions) => {
2313
2310
  if (currentIndex < parseText.length) {
2314
2311
  processedElements.push({
2315
2312
  type: "text",
2316
- text: parseText.substring(currentIndex)
2313
+ text: parseText.slice(currentIndex)
2317
2314
  });
2318
2315
  }
2319
2316
  return processedElements;
@@ -4719,7 +4716,7 @@ function collectToolCallsForName(text, toolName) {
4719
4716
  if (fullTagEnd !== -1 && fullTagEnd > contentStart) {
4720
4717
  const endTag = `</${toolName}>`;
4721
4718
  const endTagStart = fullTagEnd - endTag.length;
4722
- const content = text.substring(contentStart, endTagStart);
4719
+ const content = text.slice(contentStart, endTagStart);
4723
4720
  toolCalls.push({
4724
4721
  toolName,
4725
4722
  startIndex: tagStart,
@@ -4789,13 +4786,10 @@ function processToolCallMatch(text, tc, currentIndex, processedElements, options
4789
4786
  if (tc.startIndex < currentIndex) {
4790
4787
  return currentIndex;
4791
4788
  }
4792
- addTextSegment(
4793
- text.substring(currentIndex, tc.startIndex),
4794
- processedElements
4795
- );
4789
+ addTextSegment(text.slice(currentIndex, tc.startIndex), processedElements);
4796
4790
  const parsedArgs = parseYamlContent(tc.content, options);
4797
4791
  if (parsedArgs === null) {
4798
- const originalText = text.substring(tc.startIndex, tc.endIndex);
4792
+ const originalText = text.slice(tc.startIndex, tc.endIndex);
4799
4793
  (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse YAML tool call", {
4800
4794
  toolCall: originalText
4801
4795
  });
@@ -4883,7 +4877,7 @@ ${yamlContent}</${toolCall.toolName}>`;
4883
4877
  );
4884
4878
  }
4885
4879
  if (currentIndex < parseText.length) {
4886
- addTextSegment(parseText.substring(currentIndex), processedElements);
4880
+ addTextSegment(parseText.slice(currentIndex), processedElements);
4887
4881
  }
4888
4882
  return processedElements;
4889
4883
  },
@@ -5022,9 +5016,9 @@ ${yamlContent}</${toolCall.toolName}>`;
5022
5016
  emitToolInputProgress2(controller, buffer);
5023
5017
  return false;
5024
5018
  }
5025
- const content = buffer.substring(0, endIdx);
5019
+ const content = buffer.slice(0, endIdx);
5026
5020
  emitToolInputProgress2(controller, content);
5027
- buffer = buffer.substring(endIdx + endTag.length);
5021
+ buffer = buffer.slice(endIdx + endTag.length);
5028
5022
  processToolCallEnd(
5029
5023
  controller,
5030
5024
  content,
@@ -5045,11 +5039,11 @@ ${yamlContent}</${toolCall.toolName}>`;
5045
5039
  };
5046
5040
  const handleNewToolTag = (controller, tagIndex, tagName, selfClosing, tagLength) => {
5047
5041
  if (tagIndex > 0) {
5048
- flushText(controller, buffer.substring(0, tagIndex));
5042
+ flushText(controller, buffer.slice(0, tagIndex));
5049
5043
  }
5050
5044
  flushText(controller);
5051
5045
  if (selfClosing) {
5052
- buffer = buffer.substring(tagIndex + tagLength);
5046
+ buffer = buffer.slice(tagIndex + tagLength);
5053
5047
  const toolCallId = generateToolCallId();
5054
5048
  currentToolCall = {
5055
5049
  name: tagName,
@@ -5065,7 +5059,7 @@ ${yamlContent}</${toolCall.toolName}>`;
5065
5059
  currentToolCall = null;
5066
5060
  } else {
5067
5061
  const startTag = `<${tagName}>`;
5068
- buffer = buffer.substring(tagIndex + startTag.length);
5062
+ buffer = buffer.slice(tagIndex + startTag.length);
5069
5063
  currentToolCall = {
5070
5064
  name: tagName,
5071
5065
  toolCallId: generateToolCallId(),
@@ -7333,4 +7327,4 @@ export {
7333
7327
  morphXmlToolMiddleware,
7334
7328
  yamlXmlToolMiddleware
7335
7329
  };
7336
- //# sourceMappingURL=chunk-7EDEAFRX.js.map
7330
+ //# sourceMappingURL=chunk-AELRIRO2.js.map