Function sanitize_audio_markers
pub fn sanitize_audio_markers(
messages: &[ChatMessage],
) -> Cow<'_, [ChatMessage]>Expand description
Strip loadable audio markers (see strip_unplayable_audio_markers)
across every message in messages, logging one degradation warning when
any are removed. Returns the input borrowed when no candidate marker is
present (the common, allocation-free path) or an owned rebuilt vector
otherwise.
Assistant messages in native tool-call history are rewritten field-wise —
only their content string, through rewrite_model_visible_text — so
signed reasoning inside the envelope survives the seam.
This is the shared seam keeping a raw audio path out of provider payloads, whichever route the history takes:
- the main iteration prep (
prepare_messages_for_provider, viaprepare_messages_inner), and - one-shot queries that dispatch history directly without full prep (the
max-iteration graceful summary and the other
run_model_querycallers).
Non-audio media markers pass through untouched; see AUDIO_MARKER_KINDS
for why the split falls where it does.
A DECLARED carrier never has its text regex-stripped: its audio attachments drop from the declared list (the count the strict parser checks stays consistent, so a mixed declaration cannot degrade to legacy and lose its images), and its body is verbatim. A LEGACY carrier is cloned unchanged — its body is text and no seam rewrites it. Ordinary messages keep the regex strip.