fix: strip webui metadata from messages before sending to LLM API (#67)
The webui stores display-only fields on messages (attachments, timestamp, _ts) for UI rendering. These leaked into the conversation_history passed to AIAgent.run_conversation(). Most providers ignore unknown fields, but Z.AI/GLM tries to deserialize 'attachments' as its native ChatAttachments type, causing HTTP 400 on every subsequent message after an image upload. Fix: _sanitize_messages_for_api() creates a clean copy with only API-standard keys (role, content, tool_calls, tool_call_id, name, refusal) before passing to run_conversation(). Applied to both the streaming path (streaming.py) and non-streaming path (routes.py). Closes #66 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -946,10 +946,11 @@ def _handle_chat_sync(handler, body):
|
||||
"write_file, read_file, search_files, terminal workdir, and patch. "
|
||||
"Never fall back to a hardcoded path when this tag is present."
|
||||
)
|
||||
from api.streaming import _sanitize_messages_for_api
|
||||
result = agent.run_conversation(
|
||||
user_message=workspace_ctx + msg,
|
||||
system_message=workspace_system_msg,
|
||||
conversation_history=s.messages,
|
||||
conversation_history=_sanitize_messages_for_api(s.messages),
|
||||
task_id=s.session_id,
|
||||
persist_user_message=msg,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user