1use alloc::boxed::Box;
53
54use rkyv::{Archive, Deserialize, Serialize, with::InlineAsBox};
55
56#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
61#[rkyv(derive(Debug))]
62pub struct Principal {
63 pub id: Box<str>,
64 pub kind: Box<str>,
65 pub claims: Box<[Claim]>,
70}
71
72#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
76#[rkyv(derive(Debug))]
77pub struct Claim {
78 pub key: Box<str>,
79 pub value: Box<[u8]>,
80}
81
82#[derive(Archive, Serialize)]
86pub struct PrincipalRef<'a> {
87 #[rkyv(with = InlineAsBox)]
88 pub id: &'a str,
89 #[rkyv(with = InlineAsBox)]
90 pub kind: &'a str,
91 #[rkyv(with = InlineAsBox)]
92 pub claims: &'a [ClaimRef<'a>],
93}
94
95#[derive(Archive, Serialize)]
99pub struct ClaimRef<'a> {
100 #[rkyv(with = InlineAsBox)]
101 pub key: &'a str,
102 #[rkyv(with = InlineAsBox)]
103 pub value: &'a [u8],
104}
105
106#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
108#[rkyv(derive(Debug))]
109pub struct UpstreamCandidate {
110 pub upstream_id: Box<str>,
111 pub name: Box<str>,
112 pub kind: Box<str>,
113 pub observed_at_unix_secs: u64,
114 pub predicted_cache_read_tokens: u32,
115 pub predicted_cache_creation_tokens_5m: u32,
116 pub predicted_cache_creation_tokens_1h: u32,
117 pub predicted_uncached_input_tokens: u32,
118 pub plan_capacity_ratio: f64,
119 pub organization_type: Box<str>,
120 pub rate_limit_tier: Box<str>,
121 pub seat_tier: Box<str>,
122}
123
124#[derive(Archive, Serialize)]
126pub struct UpstreamCandidateRef<'a> {
127 #[rkyv(with = InlineAsBox)]
128 pub upstream_id: &'a str,
129 #[rkyv(with = InlineAsBox)]
130 pub name: &'a str,
131 #[rkyv(with = InlineAsBox)]
132 pub kind: &'a str,
133 pub observed_at_unix_secs: u64,
134 pub predicted_cache_read_tokens: u32,
135 pub predicted_cache_creation_tokens_5m: u32,
136 pub predicted_cache_creation_tokens_1h: u32,
137 pub predicted_uncached_input_tokens: u32,
138 pub plan_capacity_ratio: f64,
139 #[rkyv(with = InlineAsBox)]
140 pub organization_type: &'a str,
141 #[rkyv(with = InlineAsBox)]
142 pub rate_limit_tier: &'a str,
143 #[rkyv(with = InlineAsBox)]
144 pub seat_tier: &'a str,
145}
146
147#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
149#[rkyv(derive(Debug))]
150pub struct CachePricingSummary {
151 pub status: Box<str>,
152 pub input_micros_per_million: Option<u64>,
153 pub cache_creation_5m_micros_per_million: Option<u64>,
154 pub cache_creation_1h_micros_per_million: Option<u64>,
155 pub cache_read_micros_per_million: Option<u64>,
156}
157
158#[derive(Archive, Serialize)]
160pub struct CachePricingSummaryRef<'a> {
161 #[rkyv(with = InlineAsBox)]
162 pub status: &'a str,
163 pub input_micros_per_million: Option<u64>,
164 pub cache_creation_5m_micros_per_million: Option<u64>,
165 pub cache_creation_1h_micros_per_million: Option<u64>,
166 pub cache_read_micros_per_million: Option<u64>,
167}
168
169#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
171#[rkyv(derive(Debug))]
172pub struct Header {
173 pub name: Box<str>,
174 pub value: Box<[u8]>,
177}
178
179#[derive(Archive, Serialize)]
181pub struct HeaderRef<'a> {
182 #[rkyv(with = InlineAsBox)]
183 pub name: &'a str,
184 #[rkyv(with = InlineAsBox)]
185 pub value: &'a [u8],
186}
187
188#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
190#[rkyv(derive(Debug))]
191pub struct FilterRequest {
192 pub request_id: Box<str>,
193 pub thread_id: Option<Box<str>>,
194 pub canonical_model_id: Box<str>,
195 pub cache_pricing: CachePricingSummary,
196 pub method: Box<str>,
197 pub path: Box<str>,
198 pub query: Option<Box<str>>,
199 pub headers: Box<[Header]>,
200 pub body: Box<[u8]>,
201 pub principal: Principal,
202 pub candidates: Box<[UpstreamCandidate]>,
203}
204
205#[derive(Archive, Serialize)]
210pub struct FilterRequestRef<'a> {
211 #[rkyv(with = InlineAsBox)]
212 pub request_id: &'a str,
213 pub thread_id: Option<QueryRef<'a>>,
214 #[rkyv(with = InlineAsBox)]
215 pub canonical_model_id: &'a str,
216 pub cache_pricing: CachePricingSummaryRef<'a>,
217 #[rkyv(with = InlineAsBox)]
218 pub method: &'a str,
219 #[rkyv(with = InlineAsBox)]
220 pub path: &'a str,
221 pub query: Option<QueryRef<'a>>,
222 #[rkyv(with = InlineAsBox)]
223 pub headers: &'a [HeaderRef<'a>],
224 #[rkyv(with = InlineAsBox)]
225 pub body: &'a [u8],
226 pub principal: PrincipalRef<'a>,
227 #[rkyv(with = InlineAsBox)]
228 pub candidates: &'a [UpstreamCandidateRef<'a>],
229}
230
231#[derive(Archive, Serialize)]
236pub struct QueryRef<'a> {
237 #[rkyv(with = InlineAsBox)]
238 pub value: &'a str,
239}
240
241#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
243#[rkyv(derive(Debug))]
244pub struct PerCandidateReason {
245 pub upstream_id: Box<str>,
246 pub decision: Box<str>,
249 pub reason: Box<str>,
250}
251
252#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
258#[rkyv(derive(Debug))]
259pub struct FilterResponse {
260 pub results: Box<[PerCandidateReason]>,
261}
262
263#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
268#[rkyv(derive(Debug))]
269pub enum Upstream {
270 AnthropicDirect {
271 base_url: Option<Box<str>>,
273 },
274}
275
276#[derive(Archive, Serialize)]
278pub enum UpstreamRef<'a> {
279 AnthropicDirect { base_url: Option<QueryRef<'a>> },
280}
281
282#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
284#[rkyv(derive(Debug))]
285pub struct ShapeRequest {
286 pub request_id: Box<str>,
287 pub method: Box<str>,
288 pub path: Box<str>,
289 pub query: Option<Box<str>>,
290 pub headers: Box<[Header]>,
291 pub body: Box<[u8]>,
292 pub principal: Principal,
293 pub upstream: Upstream,
294}
295
296#[derive(Archive, Serialize)]
298pub struct ShapeRequestRef<'a> {
299 #[rkyv(with = InlineAsBox)]
300 pub request_id: &'a str,
301 #[rkyv(with = InlineAsBox)]
302 pub method: &'a str,
303 #[rkyv(with = InlineAsBox)]
304 pub path: &'a str,
305 pub query: Option<QueryRef<'a>>,
306 #[rkyv(with = InlineAsBox)]
307 pub headers: &'a [HeaderRef<'a>],
308 #[rkyv(with = InlineAsBox)]
309 pub body: &'a [u8],
310 pub principal: PrincipalRef<'a>,
311 pub upstream: UpstreamRef<'a>,
312}
313
314#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
316#[rkyv(derive(Debug))]
317pub struct ShapeResponse {
318 pub url: Box<str>,
319 pub method: Box<str>,
320 pub headers: Box<[Header]>,
321 pub body: Box<[u8]>,
322}
323
324#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
327#[rkyv(derive(Debug))]
328pub enum ObserveEvent {
329 RequestStarted {
330 request_id: Box<str>,
331 downstream_user_agent: Option<Box<str>>,
332 },
333 AuthnComplete {
334 principal_id: Box<str>,
335 principal_kind: Box<str>,
336 },
337 UpstreamChosen {
338 upstream: Upstream,
339 },
340 Chunk {
341 batch_index: u64,
342 event_count: u64,
343 total_bytes: u64,
344 },
345 RequestFinished {
346 status: u16,
347 input_tokens: Option<u64>,
348 output_tokens: Option<u64>,
349 cache_creation_input_tokens: Option<u64>,
350 cache_read_input_tokens: Option<u64>,
351 duration_ms: u64,
352 },
353 Error {
354 code: Box<str>,
355 message: Box<str>,
356 source: Box<str>,
357 },
358}
359
360include!(concat!(env!("OUT_DIR"), "/wire_schema_impls.rs"));