Skip to main content

systemprompt_models/wire/
mod.rs

1//! Canonical AI wire types and per-protocol codecs, shared by the gateway and
2//! the agent provider clients.
3//!
4//! The gateway speaks one provider-neutral model internally. Inbound adapters
5//! parse a client wire request into a [`canonical::CanonicalRequest`]; outbound
6//! adapters render that request to an upstream provider, parse the upstream
7//! reply into a [`canonical::CanonicalResponse`], and map upstream SSE bytes to
8//! [`canonical::CanonicalEvent`]s.
9//!
10//! - [`canonical`] holds those provider-neutral request/response/event types.
11//! - The per-protocol modules ([`anthropic`], [`openai_chat`],
12//!   [`openai_responses`], [`gemini`]) hold the codec for one wire dialect:
13//!   request build, response parse, stop-reason + usage mapping, SSE-to-event
14//!   translation, and auth-header construction.
15//!
16//! These types are defined ONCE here and re-exported by the gateway and the
17//! agent provider clients so both layers share a single wire vocabulary.
18//!
19//! Copyright (c) systemprompt.io — Business Source License 1.1.
20//! See <https://systemprompt.io> for licensing details.
21
22/// The bridge proxy and the gateway body reader must agree on this ceiling: a
23/// body the bridge accepts and forwards must not be rejected by the gateway.
24pub const BUFFERED_BODY_LIMIT_BYTES: usize = 8 * 1024 * 1024;
25
26pub mod canonical;
27
28pub mod anthropic;
29pub mod gemini;
30pub mod inspect;
31pub mod openai_chat;
32pub mod openai_responses;
33pub mod sse;
34
35#[must_use]
36pub fn clamp_output_tokens(requested: u32, max_output_tokens: Option<u32>) -> u32 {
37    match max_output_tokens {
38        Some(cap) if cap > 0 => requested.min(cap),
39        _ => requested,
40    }
41}