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
This commit is contained in:
LE Quoc Dat 2025-07-28 22:06:04 +02:00
parent 86aaa9e5ca
commit 0215b81b09
2 changed files with 20 additions and 2 deletions

View File

@ -57,7 +57,22 @@ class ContextManager:
return msg_content
elif isinstance(msg_content, dict):
if len(json.dumps(msg_content)) > max_length:
return json.dumps(msg_content)[:max_length] + "... (truncated)" + f"\n\nmessage_id \"{message_id}\"\nUse expand-message tool to see contents"
# Special handling for edit_file tool result to preserve JSON structure
tool_execution = msg_content.get("tool_execution", {})
if tool_execution.get("function_name") == "edit_file":
output = tool_execution.get("result", {}).get("output", {})
if isinstance(output, dict):
# Truncate file contents within the JSON
for key in ["original_content", "updated_content"]:
if isinstance(output.get(key), str) and len(output[key]) > max_length // 4:
output[key] = output[key][:max_length // 4] + "\n... (truncated)"
# After potential truncation, check size again
if len(json.dumps(msg_content)) > max_length:
# If still too large, fall back to string truncation
return json.dumps(msg_content)[:max_length] + "... (truncated)" + f"\n\nmessage_id \"{message_id}\"\nUse expand-message tool to see contents"
else:
return msg_content
else:
return msg_content

View File

@ -1730,7 +1730,10 @@ class ResponseProcessor:
output_to_use = output
# If this is for the LLM and it's an edit_file tool, create a concise output
if for_llm and function_name == 'edit_file' and isinstance(output, dict):
output_to_use = {"message": output.get("message", "File edited successfully.")}
# The frontend needs original_content and updated_content to render diffs.
# The concise version for the LLM was causing issues.
# We will now pass the full output, and rely on the ContextManager to truncate if needed.
output_to_use = output
# Create the structured result
structured_result_v1 = {