Skip to main content

Module version_signaling

Module version_signaling 

Source
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§

CodecVersionPolicyDocument
Shape of .well-known/codec/version-policy.json.
CodecVersionRequiredBody
Shape of the JSON body on a v0.4 server’s 426 response.

Enums§

VersionSignalingError
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§

HttpStatus
Trait abstracting an HTTP status code so we can test without pulling in reqwest. reqwest::StatusCode and u16 both 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). Returns Err on 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, and Err for 426s with malformed/non-JSON bodies — never silently swallows a 426.
well_known_version_policy_url
Build the well-known URL for an origin.