Handle one client connection: serve requests in a keep-alive loop, rewritingthe Chat Completions system message on the way and reusing pooled upstreamconnections. SSE / chunked responses are streamed chunk-by-chunk. Everyrequest is recorded in the flow store for the monitor UI.
The built-in required opening sentence of the system message.
This is only the default: the actual sentence comes from the config(SYSTEM_PROMPT in .env / the environment, or --system-prompt), see@config.Config::system_prompt.
Rewrite a raw UTF-8 Chat Completions JSON body so its first system messageopens with prompt. Uses a zero-DOM byte-level surgical splice fast path(5-20x faster on large LLM conversation bodies) and seamlessly falls backto full @json.parse + ensure_system_prefix_with for multimodal content,escaped prefixes, or invalid JSON.
Returns Ok(Some(new_bytes)) when modified, Ok(None) when unchanged, orErr(msg) when the body is not valid JSON.