(responseText)
| 193 | } |
| 194 | |
| 195 | function 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 | |
| 217 | test('解析含 file_path 的工具调用 → 保持为 file_path', () => { |
| 218 | const text = `I'll read the file now. |
no test coverage detected