Expand description
Codec v0.4 version negotiation — client-side primitives.
Rust mirror of packages/web/src/version-signaling.ts and
packages/python/src/codecai/version_signaling.py.
See spec/versions/v0.4.md:
- § Version Compatibility Signaling (Codec-Client-Version, 426 path)
- § Capabilities are opt-on at the server (two-stage)
- § Graceful downgrade (response shaping)
Usage:
use codec_rs::version_signaling::{
CODEC_CLIENT_VERSION, CODEC_CLIENT_VERSION_HEADER,
parse_version_required,
};
let client = reqwest::blocking::Client::new();
let resp = client.post("https://server.test/v1/completions")
.header(CODEC_CLIENT_VERSION_HEADER, CODEC_CLIENT_VERSION)
.body("...")
.send()?;
if let Some(err) = parse_version_required(&resp.status(), &resp.text()?)? {
return Err(err.into());
}Structs§
- Codec
Version Policy Document - Shape of
.well-known/codec/version-policy.json. - Codec
Version Required Body - Shape of the JSON body on a v0.4 server’s 426 response.
Enums§
- Version
Signaling Error - Error raised when a v0.4-mandating server refuses with a 426.
Constants§
- CODEC_
CLIENT_ VERSION - The protocol version this crate speaks. Bumped when the crate implements support for a new minor protocol version.
- CODEC_
CLIENT_ VERSION_ HEADER - Request header name (canonical case).
- CODEC_
MIN_ VERSION_ HEADER - Response header name; advisory on 2xx, load-bearing on 426.
- CODEC_
REQUIRED_ FEATURES_ HEADER - Response header name; emitted on 426.
Traits§
- Http
Status - Trait abstracting an HTTP status code so we can test without
pulling in reqwest.
reqwest::StatusCodeandu16both implement it via the blanket impls below.
Functions§
- discover_
version_ policy_ blocking - Pre-flight fetch of the deployment’s minimum-version policy.
Returns
Ok(None)when the server returns 404 (unrestricted deployment). ReturnsErron 5xx or malformed body. - parse_
version_ policy_ document - Parse + validate a version-policy document.
- parse_
version_ required - Parse a (status, body) pair into a typed error. Returns
Ok(None)for non-426 responses,Ok(Some(err))for valid 426 bodies, andErrfor 426s with malformed/non-JSON bodies — never silently swallows a 426. - well_
known_ version_ policy_ url - Build the well-known URL for an origin.