Repository navigation
Unify ChatMessage and ChatMessageInput into a single message type - #1339
Conversation
#1325) Move ChatMessage, Role, and ToolCallRaw to nlp-engine as the single source of truth. Remove ChatMessageInput and ToolCallInput from nlp-engine. Delete the hand-written field-by-field conversion in inference.rs — generate_streaming now accepts ChatMessage directly. agent_types re-exports the three types from nlp-engine so all call sites are unchanged. Adding a new message field is now reflected everywhere by construction; silent field drops are no longer possible. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Code Review — PR #1339: Unify ChatMessage and ChatMessageInputOverall assessment: This PR achieves its primary goal cleanly. The structural fix is sound, the hand-written field map is genuinely eliminated, and the compiler now enforces field totality on the critical llama.cpp inference path. One stale docstring, two missing serde annotations, and one pre-existing note for the Ollama path are the only items requiring attention before merge. Requirements Validation
FindingsImprovement
The original pub tool_call_id: Option<String>,
pub name: Option<String>,These will serialize as
The // Current: map_role(&msg.role) → "system"/"user"/"assistant"/"tool"
// Could be: msg.role.as_str().to_string() or impl Display for RoleNit
The /// Convert one `ChatMessage` into an OpenAI-format message value for the
The constructor unit tests verify field assignment but there is no Architecture AssessmentThe chosen approach — moving the canonical type down to the lower-level crate ( The compiler-enforcement claim holds on the primary path: because The Ollama backend ( Verdict: Approve with suggestions. The two missing |
- Add skip_serializing_if to tool_call_id and name on ChatMessage; aligns with reasoning field annotation, prevents null serialization on non-tool-result turns during session persistence - Fix stale doc comment: ChatMessageInput → ChatMessage in chat_message_to_oai_value - Delete map_role() in ollama_inference.rs; replace with Role::as_str(), which is now the canonical method on the unified type; update test to call as_str() directly and scope Role import to test module Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Address Review Summary✅ Addressed (3/3 actionable findings)🟡 🟢 Redundant 🟢 Stale doc comment — Fixed ⏭️ Skipped (1 out-of-scope finding)Ollama path drops |
) * Unify ChatMessage into nlp-engine, eliminating ChatMessageInput (closes #1325) Move ChatMessage, Role, and ToolCallRaw to nlp-engine as the single source of truth. Remove ChatMessageInput and ToolCallInput from nlp-engine. Delete the hand-written field-by-field conversion in inference.rs — generate_streaming now accepts ChatMessage directly. agent_types re-exports the three types from nlp-engine so all call sites are unchanged. Adding a new message field is now reflected everywhere by construction; silent field drops are no longer possible. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: serde annotations, stale doc, redundant map_role - Add skip_serializing_if to tool_call_id and name on ChatMessage; aligns with reasoning field annotation, prevents null serialization on non-tool-result turns during session persistence - Fix stale doc comment: ChatMessageInput → ChatMessage in chat_message_to_oai_value - Delete map_role() in ollama_inference.rs; replace with Role::as_str(), which is now the canonical method on the unified type; update test to call as_str() directly and scope Role import to test module Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Closes #1325