pub fn to_chat_message(m: &Message) -> Option<ChatMessage>Expand description
Converts a projected Message into the request-body chat shape
(dialect v2). Plain string content passes through unchanged
(byte-identical to dialect v1); structured content is translated to
the strict openai wire shape — anything else is serialized compactly,
deterministic under the frozen serialization (lexicographic keys).
role:"tool"{call_id, output, is_error}→{role:"tool", tool_call_id, content: <output as a JSON string>}(theis_errorflag stays in the event stream; the wire carries the output only, the shape verified live against the real DeepSeek API).- assistant
{"text", "tool_calls": [...]}→{role:"assistant", content: <text or null>, tool_calls: [{id, type:"function", function:{name, arguments: <JSON string>}}]}. - assistant
{"id", "name", "arguments"}(the per-calltool/calltranscript duplicate) → dropped: the enclosing assistant turn’stool_callsalready carries the same call id, and strict endpoints reject the duplicate. ReturnsNone.
Public: kian session replay re-derives the model context
from the event stream and must rebuild the exact chat shape the
loop sent, so the A2 byte-identity check compares like with like.
This conversion is part of the frozen request-serialization contract
(constraint 3) — changing it invalidates every replay comparison and
every provider prefix cache.