Files
hermes-web-ui/packages
ekko bfb0da2806 fix(chat): reconstruct tool_call_id from conversation context to fix #298 (#309)
* fix(chat): ensure tool_call_id is always included for tool messages

Fixes #298

When role='tool', OpenAI API requires the tool_call_id field to be present
even if it's null or empty. Previously, the field was only added when
tool_call_id had a truthy value, causing API errors when continuing
conversations with tool calls.

Changes:
- Always include tool_call_id for role='tool' messages (set to empty string if null)
- Only include tool_call_id for other roles if it has a value
- Add comment explaining the OpenAI API requirement

This fixes the error: "角色为 'tool' 时必须提供 'tool_call_id'"
that occurred when continuing conversations after updating to v0.5.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(chat): reconstruct tool_call_id from conversation context to fix #298

Fixes issue where tool messages without tool_call_id caused API errors:
"角色为 'tool' 时必须提供 'tool_call_id'"

Changes:
- Reconstruct missing tool_call_id from previous assistant message's tool_calls
- Match by tool_name to find the correct tool_call.id
- Filter out only unreconstructable tool messages (data anomalies)
- Add debug logging for conversation context and API requests
- Replace console.log with logger.debug

Testing:
- Verified 99.6% tool message retention (233/234) in production DB
- Only 0.4% filtered (anomalous data without valid context)
- All normal tool calls preserved and API-compliant

Resolves #298

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-29 19:54:51 +08:00
..