MCPcopy
hub / github.com/7836246/cursor2api / parseToolCallsWithFix

Function parseToolCallsWithFix

test/unit-tool-fixer.mjs:195–215  ·  view source on GitHub ↗
(responseText)

Source from the content-addressed store, hash-verified

193}
194
195function parseToolCallsWithFix(responseText) {
196 const toolCalls = [];
197 let cleanText = responseText;
198 const fullBlockRegex = /```json(?:\s+action)?\s*([\s\S]*?)\s*```/g;
199 let match;
200 while ((match = fullBlockRegex.exec(responseText)) !== null) {
201 let isToolCall = false;
202 try {
203 const parsed = tolerantParse(match[1]);
204 if (parsed.tool || parsed.name) {
205 const name = parsed.tool || parsed.name;
206 let args = parsed.parameters || parsed.arguments || parsed.input || {};
207 args = fixToolCallArguments(name, args);
208 toolCalls.push({ name, arguments: args });
209 isToolCall = true;
210 }
211 } catch (e) { /* skip */ }
212 if (isToolCall) cleanText = cleanText.replace(match[0], '');
213 }
214 return { toolCalls, cleanText: cleanText.trim() };
215}
216
217test('解析含 file_path 的工具调用 → 保持为 file_path', () => {
218 const text = `I'll read the file now.

Callers 1

Calls 3

pushMethod · 0.80
tolerantParseFunction · 0.70
fixToolCallArgumentsFunction · 0.70

Tested by

no test coverage detected