use alloc::boxed::Box;
use rkyv::{Archive, Deserialize, Serialize, with::InlineAsBox};
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct Principal {
pub id: Box<str>,
pub kind: Box<str>,
pub claims: Box<[Claim]>,
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct Claim {
pub key: Box<str>,
pub value: Box<[u8]>,
}
#[derive(Archive, Serialize)]
pub struct PrincipalRef<'a> {
#[rkyv(with = InlineAsBox)]
pub id: &'a str,
#[rkyv(with = InlineAsBox)]
pub kind: &'a str,
#[rkyv(with = InlineAsBox)]
pub claims: &'a [ClaimRef<'a>],
}
#[derive(Archive, Serialize)]
pub struct ClaimRef<'a> {
#[rkyv(with = InlineAsBox)]
pub key: &'a str,
#[rkyv(with = InlineAsBox)]
pub value: &'a [u8],
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct UpstreamCandidate {
pub upstream_id: Box<str>,
pub name: Box<str>,
pub kind: Box<str>,
pub observed_at_unix_secs: u64,
pub predicted_cache_read_tokens: u32,
pub plan_capacity_ratio: f64,
pub organization_type: Box<str>,
pub rate_limit_tier: Box<str>,
pub seat_tier: Box<str>,
}
#[derive(Archive, Serialize)]
pub struct UpstreamCandidateRef<'a> {
#[rkyv(with = InlineAsBox)]
pub upstream_id: &'a str,
#[rkyv(with = InlineAsBox)]
pub name: &'a str,
#[rkyv(with = InlineAsBox)]
pub kind: &'a str,
pub observed_at_unix_secs: u64,
pub predicted_cache_read_tokens: u32,
pub plan_capacity_ratio: f64,
#[rkyv(with = InlineAsBox)]
pub organization_type: &'a str,
#[rkyv(with = InlineAsBox)]
pub rate_limit_tier: &'a str,
#[rkyv(with = InlineAsBox)]
pub seat_tier: &'a str,
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct Header {
pub name: Box<str>,
pub value: Box<[u8]>,
}
#[derive(Archive, Serialize)]
pub struct HeaderRef<'a> {
#[rkyv(with = InlineAsBox)]
pub name: &'a str,
#[rkyv(with = InlineAsBox)]
pub value: &'a [u8],
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct FilterRequest {
pub request_id: Box<str>,
pub thread_id: Option<Box<str>>,
pub method: Box<str>,
pub path: Box<str>,
pub query: Option<Box<str>>,
pub headers: Box<[Header]>,
pub body: Box<[u8]>,
pub principal: Principal,
pub candidates: Box<[UpstreamCandidate]>,
}
#[derive(Archive, Serialize)]
pub struct FilterRequestRef<'a> {
#[rkyv(with = InlineAsBox)]
pub request_id: &'a str,
pub thread_id: Option<QueryRef<'a>>,
#[rkyv(with = InlineAsBox)]
pub method: &'a str,
#[rkyv(with = InlineAsBox)]
pub path: &'a str,
pub query: Option<QueryRef<'a>>,
#[rkyv(with = InlineAsBox)]
pub headers: &'a [HeaderRef<'a>],
#[rkyv(with = InlineAsBox)]
pub body: &'a [u8],
pub principal: PrincipalRef<'a>,
#[rkyv(with = InlineAsBox)]
pub candidates: &'a [UpstreamCandidateRef<'a>],
}
#[derive(Archive, Serialize)]
pub struct QueryRef<'a> {
#[rkyv(with = InlineAsBox)]
pub value: &'a str,
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct PerCandidateReason {
pub upstream_id: Box<str>,
pub decision: Box<str>,
pub reason: Box<str>,
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct FilterResponse {
pub results: Box<[PerCandidateReason]>,
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub enum Upstream {
AnthropicDirect {
base_url: Option<Box<str>>,
},
}
#[derive(Archive, Serialize)]
pub enum UpstreamRef<'a> {
AnthropicDirect { base_url: Option<QueryRef<'a>> },
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct ShapeRequest {
pub request_id: Box<str>,
pub method: Box<str>,
pub path: Box<str>,
pub query: Option<Box<str>>,
pub headers: Box<[Header]>,
pub body: Box<[u8]>,
pub principal: Principal,
pub upstream: Upstream,
}
#[derive(Archive, Serialize)]
pub struct ShapeRequestRef<'a> {
#[rkyv(with = InlineAsBox)]
pub request_id: &'a str,
#[rkyv(with = InlineAsBox)]
pub method: &'a str,
#[rkyv(with = InlineAsBox)]
pub path: &'a str,
pub query: Option<QueryRef<'a>>,
#[rkyv(with = InlineAsBox)]
pub headers: &'a [HeaderRef<'a>],
#[rkyv(with = InlineAsBox)]
pub body: &'a [u8],
pub principal: PrincipalRef<'a>,
pub upstream: UpstreamRef<'a>,
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub struct ShapeResponse {
pub url: Box<str>,
pub method: Box<str>,
pub headers: Box<[Header]>,
pub body: Box<[u8]>,
}
#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
#[rkyv(derive(Debug))]
pub enum ObserveEvent {
RequestStarted {
request_id: Box<str>,
downstream_user_agent: Option<Box<str>>,
},
AuthnComplete {
principal_id: Box<str>,
principal_kind: Box<str>,
},
UpstreamChosen {
upstream: Upstream,
},
Chunk {
batch_index: u64,
event_count: u64,
total_bytes: u64,
},
RequestFinished {
status: u16,
input_tokens: Option<u64>,
output_tokens: Option<u64>,
cache_creation_input_tokens: Option<u64>,
cache_read_input_tokens: Option<u64>,
duration_ms: u64,
},
Error {
code: Box<str>,
message: Box<str>,
source: Box<str>,
},
}
include!(concat!(env!("OUT_DIR"), "/wire_schema_impls.rs"));