From 066a43d9519e669632b4497e9691768006d0c17e Mon Sep 17 00:00:00 2001 From: LE Quoc Dat Date: Mon, 28 Jul 2025 22:09:32 +0200 Subject: [PATCH] AI: How can we stream the edit_file tool when it generating like create_file ? Also the edit_file tool show this """Invalid File Edit Could not extract the file changes from the tool result.""" Check the state of code base and make to sure implement fully --- .../tool-views/file-operation/_utils.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/thread/tool-views/file-operation/_utils.ts b/frontend/src/components/thread/tool-views/file-operation/_utils.ts index 335430f4..8bbf8528 100644 --- a/frontend/src/components/thread/tool-views/file-operation/_utils.ts +++ b/frontend/src/components/thread/tool-views/file-operation/_utils.ts @@ -263,13 +263,25 @@ export const extractFileEditData = ( const args = parsed.tool_execution.arguments || {}; const output = parseOutput(parsed.tool_execution.result?.output); const success = parsed.tool_execution.result?.success; + + let errorMessage: string | undefined; + if (success === false) { + if (typeof output === 'object' && output !== null && output.message) { + errorMessage = output.message; + } else if (typeof output === 'string') { + errorMessage = output; + } else { + errorMessage = JSON.stringify(output); + } + } + return { - filePath: args.target_file || output?.file_path || null, - originalContent: output?.original_content ?? null, - updatedContent: output?.updated_content ?? null, + filePath: args.target_file || (typeof output === 'object' && output?.file_path) || null, + originalContent: (typeof output === 'object' && output?.original_content) ?? null, + updatedContent: (typeof output === 'object' && output?.updated_content) ?? null, success: success, timestamp: parsed.tool_execution.execution_details?.timestamp, - errorMessage: success === false ? (output?.message || (typeof output === 'string' ? output : JSON.stringify(output))) : undefined, + errorMessage: errorMessage, }; } return {};