@ai-sdk-tool/parser 4.1.6 → 4.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/community.js CHANGED
@@ -7,13 +7,13 @@ import {
7
7
  safeStringifyInputExample,
8
8
  toSafeXmlTagName,
9
9
  uiTarsXmlProtocol
10
- } from "./chunk-ZIOUCBCX.js";
10
+ } from "./chunk-7EDEAFRX.js";
11
11
  import {
12
12
  escapeXmlMinimalAttr,
13
13
  escapeXmlMinimalText,
14
14
  stringify
15
- } from "./chunk-D4YULTAO.js";
16
- import "./chunk-QBZNMO5C.js";
15
+ } from "./chunk-IATDQDRY.js";
16
+ import "./chunk-A3DLFT2S.js";
17
17
  import "./chunk-GMTE7BY5.js";
18
18
 
19
19
  // src/community/sijawara.ts
package/dist/index.cjs CHANGED
@@ -323,7 +323,7 @@ function popToken(tokens, state) {
323
323
  const token = tokens[state.pos];
324
324
  state.pos += 1;
325
325
  if (!token) {
326
- const lastLine = tokens.length !== 0 ? (_b = (_a = tokens.at(-1)) == null ? void 0 : _a.line) != null ? _b : 1 : 1;
326
+ const lastLine = tokens.length === 0 ? 1 : (_b = (_a = tokens.at(-1)) == null ? void 0 : _a.line) != null ? _b : 1;
327
327
  return { type: "eof", match: "", value: void 0, line: lastLine };
328
328
  }
329
329
  return token;
@@ -4002,7 +4002,7 @@ function getTopLevelStringProps(s) {
4002
4002
  function restorePlaceholderString(val, placeholderMap) {
4003
4003
  if (val.startsWith("__RXML_PLACEHOLDER_")) {
4004
4004
  const orig = placeholderMap.get(val);
4005
- return orig !== void 0 ? orig : val;
4005
+ return orig === void 0 ? val : orig;
4006
4006
  }
4007
4007
  return val;
4008
4008
  }
@@ -8488,19 +8488,19 @@ function processToolCallMatch(text, tc, currentIndex, processedElements, options
8488
8488
  processedElements
8489
8489
  );
8490
8490
  const parsedArgs = parseYamlContent(tc.content, options);
8491
- if (parsedArgs !== null) {
8491
+ if (parsedArgs === null) {
8492
+ const originalText = text.substring(tc.startIndex, tc.endIndex);
8493
+ (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse YAML tool call", {
8494
+ toolCall: originalText
8495
+ });
8496
+ processedElements.push({ type: "text", text: originalText });
8497
+ } else {
8492
8498
  processedElements.push({
8493
8499
  type: "tool-call",
8494
8500
  toolCallId: generateToolCallId(),
8495
8501
  toolName: tc.toolName,
8496
8502
  input: JSON.stringify(parsedArgs)
8497
8503
  });
8498
- } else {
8499
- const originalText = text.substring(tc.startIndex, tc.endIndex);
8500
- (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse YAML tool call", {
8501
- toolCall: originalText
8502
- });
8503
- processedElements.push({ type: "text", text: originalText });
8504
8504
  }
8505
8505
  return tc.endIndex;
8506
8506
  }
@@ -8624,7 +8624,22 @@ ${yamlContent}</${toolCall.toolName}>`;
8624
8624
  var _a;
8625
8625
  const parsedArgs = parseYamlContent(toolContent, options);
8626
8626
  flushText(controller);
8627
- if (parsedArgs !== null) {
8627
+ if (parsedArgs === null) {
8628
+ const original = `<${toolName}>${toolContent}</${toolName}>`;
8629
+ const emitRawFallback = shouldEmitRawToolCallTextOnError(options);
8630
+ emitFailedToolInputLifecycle({
8631
+ controller,
8632
+ id: toolCallId,
8633
+ emitRawToolCallTextOnError: emitRawFallback,
8634
+ rawToolCallText: original,
8635
+ emitRawText: (rawText) => {
8636
+ flushText(controller, rawText);
8637
+ }
8638
+ });
8639
+ (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse streaming YAML tool call", {
8640
+ toolCall: original
8641
+ });
8642
+ } else {
8628
8643
  const finalInput = stringifyToolInputWithSchema({
8629
8644
  toolName,
8630
8645
  args: parsedArgs,
@@ -8647,21 +8662,6 @@ ${yamlContent}</${toolCall.toolName}>`;
8647
8662
  input: finalInput
8648
8663
  });
8649
8664
  }
8650
- } else {
8651
- const original = `<${toolName}>${toolContent}</${toolName}>`;
8652
- const emitRawFallback = shouldEmitRawToolCallTextOnError(options);
8653
- emitFailedToolInputLifecycle({
8654
- controller,
8655
- id: toolCallId,
8656
- emitRawToolCallTextOnError: emitRawFallback,
8657
- rawToolCallText: original,
8658
- emitRawText: (rawText) => {
8659
- flushText(controller, rawText);
8660
- }
8661
- });
8662
- (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse streaming YAML tool call", {
8663
- toolCall: original
8664
- });
8665
8665
  }
8666
8666
  };
8667
8667
  const finalizeUnclosedToolCall = (controller) => {
@@ -8674,21 +8674,7 @@ ${yamlContent}</${toolCall.toolName}>`;
8674
8674
  const reconciledBuffer = stripTrailingPartialCloseTag(buffer, toolName);
8675
8675
  const parsedArgs = parseYamlContent(reconciledBuffer, options);
8676
8676
  flushText(controller);
8677
- if (parsedArgs !== null) {
8678
- const finalInput = stringifyToolInputWithSchema({
8679
- toolName,
8680
- args: parsedArgs,
8681
- tools
8682
- });
8683
- emitFinalizedToolInputLifecycle({
8684
- controller,
8685
- id: toolCallId,
8686
- state: currentToolCall,
8687
- toolName,
8688
- finalInput,
8689
- onMismatch: options == null ? void 0 : options.onError
8690
- });
8691
- } else {
8677
+ if (parsedArgs === null) {
8692
8678
  const unfinishedContent = `<${toolName}>${buffer}`;
8693
8679
  const emitRawFallback = shouldEmitRawToolCallTextOnError(options);
8694
8680
  emitFailedToolInputLifecycle({
@@ -8705,6 +8691,20 @@ ${yamlContent}</${toolCall.toolName}>`;
8705
8691
  "Could not complete streaming YAML tool call at finish.",
8706
8692
  { toolCall: unfinishedContent }
8707
8693
  );
8694
+ } else {
8695
+ const finalInput = stringifyToolInputWithSchema({
8696
+ toolName,
8697
+ args: parsedArgs,
8698
+ tools
8699
+ });
8700
+ emitFinalizedToolInputLifecycle({
8701
+ controller,
8702
+ id: toolCallId,
8703
+ state: currentToolCall,
8704
+ toolName,
8705
+ finalInput,
8706
+ onMismatch: options == null ? void 0 : options.onError
8707
+ });
8708
8708
  }
8709
8709
  buffer = "";
8710
8710
  currentToolCall = null;
@@ -9160,7 +9160,7 @@ function extractJsonLikeCandidates(rawText) {
9160
9160
  }
9161
9161
  function mergeJsonCandidatesByStart(tagged, codeBlocks, balanced) {
9162
9162
  return [...tagged, ...codeBlocks, ...balanced].sort(
9163
- (a, b) => a.startIndex !== b.startIndex ? a.startIndex - b.startIndex : b.endIndex - a.endIndex
9163
+ (a, b) => a.startIndex === b.startIndex ? b.endIndex - a.endIndex : a.startIndex - b.startIndex
9164
9164
  );
9165
9165
  }
9166
9166
  function toToolCallPart(candidate) {