systemprompt_wire/lib.rs
1//! Canonical AI wire types and per-protocol codecs for systemprompt.io,
2//! shared by the gateway and 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//! - [`protocol`] names the wire dialect a provider speaks ([`WireProtocol`]),
17//! [`hosting`] the platform in front of it ([`Hosting`]), and [`limits`] the
18//! per-model token ceilings a codec clamps to ([`ModelLimits`]).
19//! - [`schema`] holds the per-provider JSON-Schema capability matrices and the
20//! tool-schema sanitiser the codecs apply before sending.
21//!
22//! These types are defined ONCE here and re-exported by the gateway and the
23//! agent provider clients so both layers share a single wire vocabulary. The
24//! crate depends only on `systemprompt-identifiers` among the workspace
25//! crates.
26//!
27//! Copyright (c) systemprompt.io — Business Source License 1.1.
28//! See <https://systemprompt.io> for licensing details.
29
30pub mod canonical;
31pub mod defect;
32pub mod error;
33
34pub mod anthropic;
35pub mod gemini;
36pub mod hosting;
37pub mod inspect;
38pub mod limits;
39pub mod openai_chat;
40pub mod openai_responses;
41pub mod protocol;
42pub mod schema;
43pub mod sse;
44pub mod upstream;
45
46pub use hosting::Hosting;
47pub use limits::ModelLimits;
48pub use protocol::WireProtocol;
49
50#[must_use]
51pub fn clamp_output_tokens(requested: u32, max_output_tokens: Option<u32>) -> u32 {
52 match max_output_tokens {
53 Some(cap) if cap > 0 => requested.min(cap),
54 _ => requested,
55 }
56}