Skip to main content

Module splice

Module splice 

Source
Expand description

The byte-level model splice.

The request body is never deserialized: the splice finds the top-level "model" key, optionally replaces its string value, and fixes Content-Length. Everything else - tool schemas, betas, context_management - passes through byte for byte, which is the whole reason the gateway forwards instead of re-encoding.

Enumsยง

SpliceError
Why a body could not be spliced. Both are loud by design: a splice that silently forwarded the wrong model would be worse than a failure naming the session.

Functionsยง

find_top_level_model ๐Ÿ”’
Locate the top-level "model" string value: its byte span (excluding the quotes) and its content. Scans with a string/escape state machine so a "model" that is only a nested key or a value elsewhere is skipped.
read_string ๐Ÿ”’
Read a JSON string starting at start (the opening quote). Returns the raw content bytes and the index just past the closing quote.
skip_ws ๐Ÿ”’
splice_model
Extract the top-level model string and, when replacement is Some, rewrite it in place. Returns the (possibly new) body and the extracted model. Nested "model" keys are never touched: only a string key at brace depth 1 counts.
unescape ๐Ÿ”’
Model names are plain ASCII slugs in practice; unescape the two escapes that could appear around them and reject exotic ones rather than misreporting the name.

Type Aliasesยง

ModelSpan ๐Ÿ”’
The located top-level model: its byte span (excluding the quotes) and its content.