@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.
@@ -2163,7 +2163,7 @@ function getTopLevelStringProps(s) {
2163
2163
  function restorePlaceholderString(val, placeholderMap) {
2164
2164
  if (val.startsWith("__RXML_PLACEHOLDER_")) {
2165
2165
  const orig = placeholderMap.get(val);
2166
- return orig !== void 0 ? orig : val;
2166
+ return orig === void 0 ? val : orig;
2167
2167
  }
2168
2168
  return val;
2169
2169
  }
@@ -3787,7 +3787,7 @@ function popToken(tokens, state) {
3787
3787
  const token = tokens[state.pos];
3788
3788
  state.pos += 1;
3789
3789
  if (!token) {
3790
- const lastLine = tokens.length !== 0 ? (_b = (_a = tokens.at(-1)) == null ? void 0 : _a.line) != null ? _b : 1 : 1;
3790
+ const lastLine = tokens.length === 0 ? 1 : (_b = (_a = tokens.at(-1)) == null ? void 0 : _a.line) != null ? _b : 1;
3791
3791
  return { type: "eof", match: "", value: void 0, line: lastLine };
3792
3792
  }
3793
3793
  return token;
@@ -8956,19 +8956,19 @@ function processToolCallMatch(text, tc, currentIndex, processedElements, options
8956
8956
  processedElements
8957
8957
  );
8958
8958
  const parsedArgs = parseYamlContent(tc.content, options);
8959
- if (parsedArgs !== null) {
8959
+ if (parsedArgs === null) {
8960
+ const originalText = text.substring(tc.startIndex, tc.endIndex);
8961
+ (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse YAML tool call", {
8962
+ toolCall: originalText
8963
+ });
8964
+ processedElements.push({ type: "text", text: originalText });
8965
+ } else {
8960
8966
  processedElements.push({
8961
8967
  type: "tool-call",
8962
8968
  toolCallId: generateToolCallId(),
8963
8969
  toolName: tc.toolName,
8964
8970
  input: JSON.stringify(parsedArgs)
8965
8971
  });
8966
- } else {
8967
- const originalText = text.substring(tc.startIndex, tc.endIndex);
8968
- (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse YAML tool call", {
8969
- toolCall: originalText
8970
- });
8971
- processedElements.push({ type: "text", text: originalText });
8972
8972
  }
8973
8973
  return tc.endIndex;
8974
8974
  }
@@ -9092,7 +9092,22 @@ ${yamlContent}</${toolCall.toolName}>`;
9092
9092
  var _a;
9093
9093
  const parsedArgs = parseYamlContent(toolContent, options);
9094
9094
  flushText(controller);
9095
- if (parsedArgs !== null) {
9095
+ if (parsedArgs === null) {
9096
+ const original = `<${toolName}>${toolContent}</${toolName}>`;
9097
+ const emitRawFallback = shouldEmitRawToolCallTextOnError(options);
9098
+ emitFailedToolInputLifecycle({
9099
+ controller,
9100
+ id: toolCallId,
9101
+ emitRawToolCallTextOnError: emitRawFallback,
9102
+ rawToolCallText: original,
9103
+ emitRawText: (rawText) => {
9104
+ flushText(controller, rawText);
9105
+ }
9106
+ });
9107
+ (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse streaming YAML tool call", {
9108
+ toolCall: original
9109
+ });
9110
+ } else {
9096
9111
  const finalInput = stringifyToolInputWithSchema({
9097
9112
  toolName,
9098
9113
  args: parsedArgs,
@@ -9115,21 +9130,6 @@ ${yamlContent}</${toolCall.toolName}>`;
9115
9130
  input: finalInput
9116
9131
  });
9117
9132
  }
9118
- } else {
9119
- const original = `<${toolName}>${toolContent}</${toolName}>`;
9120
- const emitRawFallback = shouldEmitRawToolCallTextOnError(options);
9121
- emitFailedToolInputLifecycle({
9122
- controller,
9123
- id: toolCallId,
9124
- emitRawToolCallTextOnError: emitRawFallback,
9125
- rawToolCallText: original,
9126
- emitRawText: (rawText) => {
9127
- flushText(controller, rawText);
9128
- }
9129
- });
9130
- (_a = options == null ? void 0 : options.onError) == null ? void 0 : _a.call(options, "Could not parse streaming YAML tool call", {
9131
- toolCall: original
9132
- });
9133
9133
  }
9134
9134
  };
9135
9135
  const finalizeUnclosedToolCall = (controller) => {
@@ -9142,21 +9142,7 @@ ${yamlContent}</${toolCall.toolName}>`;
9142
9142
  const reconciledBuffer = stripTrailingPartialCloseTag(buffer, toolName);
9143
9143
  const parsedArgs = parseYamlContent(reconciledBuffer, options);
9144
9144
  flushText(controller);
9145
- if (parsedArgs !== null) {
9146
- const finalInput = stringifyToolInputWithSchema({
9147
- toolName,
9148
- args: parsedArgs,
9149
- tools
9150
- });
9151
- emitFinalizedToolInputLifecycle({
9152
- controller,
9153
- id: toolCallId,
9154
- state: currentToolCall,
9155
- toolName,
9156
- finalInput,
9157
- onMismatch: options == null ? void 0 : options.onError
9158
- });
9159
- } else {
9145
+ if (parsedArgs === null) {
9160
9146
  const unfinishedContent = `<${toolName}>${buffer}`;
9161
9147
  const emitRawFallback = shouldEmitRawToolCallTextOnError(options);
9162
9148
  emitFailedToolInputLifecycle({
@@ -9173,6 +9159,20 @@ ${yamlContent}</${toolCall.toolName}>`;
9173
9159
  "Could not complete streaming YAML tool call at finish.",
9174
9160
  { toolCall: unfinishedContent }
9175
9161
  );
9162
+ } else {
9163
+ const finalInput = stringifyToolInputWithSchema({
9164
+ toolName,
9165
+ args: parsedArgs,
9166
+ tools
9167
+ });
9168
+ emitFinalizedToolInputLifecycle({
9169
+ controller,
9170
+ id: toolCallId,
9171
+ state: currentToolCall,
9172
+ toolName,
9173
+ finalInput,
9174
+ onMismatch: options == null ? void 0 : options.onError
9175
+ });
9176
9176
  }
9177
9177
  buffer = "";
9178
9178
  currentToolCall = null;
@@ -9613,7 +9613,7 @@ function extractJsonLikeCandidates(rawText) {
9613
9613
  }
9614
9614
  function mergeJsonCandidatesByStart(tagged, codeBlocks, balanced) {
9615
9615
  return [...tagged, ...codeBlocks, ...balanced].sort(
9616
- (a, b) => a.startIndex !== b.startIndex ? a.startIndex - b.startIndex : b.endIndex - a.endIndex
9616
+ (a, b) => a.startIndex === b.startIndex ? b.endIndex - a.endIndex : a.startIndex - b.startIndex
9617
9617
  );
9618
9618
  }
9619
9619
  function toToolCallPart(candidate) {