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 service_tier: Option<Box<str>>,
195 pub canonical_model_id: Box<str>,
196 pub cache_pricing: CachePricingSummary,
197 pub method: Box<str>,
198 pub path: Box<str>,
199 pub query: Option<Box<str>>,
200 pub headers: Box<[Header]>,
201 pub body: Box<[u8]>,
202 pub principal: Principal,
203 pub candidates: Box<[UpstreamCandidate]>,
204}
205
206#[derive(Archive, Serialize)]
211pub struct FilterRequestRef<'a> {
212 #[rkyv(with = InlineAsBox)]
213 pub request_id: &'a str,
214 pub thread_id: Option<QueryRef<'a>>,
215 pub service_tier: Option<QueryRef<'a>>,
216 #[rkyv(with = InlineAsBox)]
217 pub canonical_model_id: &'a str,
218 pub cache_pricing: CachePricingSummaryRef<'a>,
219 #[rkyv(with = InlineAsBox)]
220 pub method: &'a str,
221 #[rkyv(with = InlineAsBox)]
222 pub path: &'a str,
223 pub query: Option<QueryRef<'a>>,
224 #[rkyv(with = InlineAsBox)]
225 pub headers: &'a [HeaderRef<'a>],
226 #[rkyv(with = InlineAsBox)]
227 pub body: &'a [u8],
228 pub principal: PrincipalRef<'a>,
229 #[rkyv(with = InlineAsBox)]
230 pub candidates: &'a [UpstreamCandidateRef<'a>],
231}
232
233#[derive(Archive, Serialize)]
238pub struct QueryRef<'a> {
239 #[rkyv(with = InlineAsBox)]
240 pub value: &'a str,
241}
242
243#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
245#[rkyv(derive(Debug))]
246pub struct PerCandidateReason {
247 pub upstream_id: Box<str>,
248 pub decision: Box<str>,
251 pub reason: Box<str>,
252}
253
254#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
260#[rkyv(derive(Debug))]
261pub struct FilterResponse {
262 pub results: Box<[PerCandidateReason]>,
263}
264
265#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
270#[rkyv(derive(Debug))]
271pub enum Upstream {
272 AnthropicDirect {
273 base_url: Option<Box<str>>,
275 },
276}
277
278#[derive(Archive, Serialize)]
280pub enum UpstreamRef<'a> {
281 AnthropicDirect { base_url: Option<QueryRef<'a>> },
282}
283
284#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
286#[rkyv(derive(Debug))]
287pub struct ShapeRequest {
288 pub request_id: Box<str>,
289 pub method: Box<str>,
290 pub path: Box<str>,
291 pub query: Option<Box<str>>,
292 pub headers: Box<[Header]>,
293 pub body: Box<[u8]>,
294 pub principal: Principal,
295 pub upstream: Upstream,
296}
297
298#[derive(Archive, Serialize)]
300pub struct ShapeRequestRef<'a> {
301 #[rkyv(with = InlineAsBox)]
302 pub request_id: &'a str,
303 #[rkyv(with = InlineAsBox)]
304 pub method: &'a str,
305 #[rkyv(with = InlineAsBox)]
306 pub path: &'a str,
307 pub query: Option<QueryRef<'a>>,
308 #[rkyv(with = InlineAsBox)]
309 pub headers: &'a [HeaderRef<'a>],
310 #[rkyv(with = InlineAsBox)]
311 pub body: &'a [u8],
312 pub principal: PrincipalRef<'a>,
313 pub upstream: UpstreamRef<'a>,
314}
315
316#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
318#[rkyv(derive(Debug))]
319pub struct ShapeResponse {
320 pub url: Box<str>,
321 pub method: Box<str>,
322 pub headers: Box<[Header]>,
323 pub body: Box<[u8]>,
324}
325
326#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
327#[rkyv(derive(Debug))]
328pub struct TransformResponseRequest {
329 pub request_id: Box<str>,
330 pub principal: Principal,
331 pub upstream: Upstream,
332 pub request_method: Box<str>,
333 pub request_path: Box<str>,
334 pub canonical_model_id: Box<str>,
335 pub response_status: u16,
336 pub response_headers: Box<[Header]>,
337 pub body: Box<[u8]>,
338}
339
340#[derive(Archive, Serialize)]
341pub struct TransformResponseRequestRef<'a> {
342 #[rkyv(with = InlineAsBox)]
343 pub request_id: &'a str,
344 pub principal: PrincipalRef<'a>,
345 pub upstream: UpstreamRef<'a>,
346 #[rkyv(with = InlineAsBox)]
347 pub request_method: &'a str,
348 #[rkyv(with = InlineAsBox)]
349 pub request_path: &'a str,
350 #[rkyv(with = InlineAsBox)]
351 pub canonical_model_id: &'a str,
352 pub response_status: u16,
353 #[rkyv(with = InlineAsBox)]
354 pub response_headers: &'a [HeaderRef<'a>],
355 #[rkyv(with = InlineAsBox)]
356 pub body: &'a [u8],
357}
358
359#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
360#[rkyv(derive(Debug))]
361pub enum TransformResponseResult {
362 Unchanged,
363 Replace {
364 status: Option<u16>,
365 headers: Option<Box<[Header]>>,
366 body: Option<Box<[u8]>>,
367 },
368}
369
370#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
371#[rkyv(derive(Debug))]
372pub struct SseEvent {
373 pub event: Box<str>,
374 pub data: Box<[u8]>,
375}
376
377#[derive(Archive, Serialize)]
378pub struct SseEventRef<'a> {
379 #[rkyv(with = InlineAsBox)]
380 pub event: &'a str,
381 #[rkyv(with = InlineAsBox)]
382 pub data: &'a [u8],
383}
384
385#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
386#[rkyv(derive(Debug))]
387pub struct TransformSseEventRequest {
388 pub request_id: Box<str>,
389 pub principal: Principal,
390 pub upstream: Upstream,
391 pub request_method: Box<str>,
392 pub request_path: Box<str>,
393 pub canonical_model_id: Box<str>,
394 pub response_status: u16,
395 pub response_headers: Box<[Header]>,
396 pub event: SseEvent,
397}
398
399#[derive(Archive, Serialize)]
400pub struct TransformSseEventRequestRef<'a> {
401 #[rkyv(with = InlineAsBox)]
402 pub request_id: &'a str,
403 pub principal: PrincipalRef<'a>,
404 pub upstream: UpstreamRef<'a>,
405 #[rkyv(with = InlineAsBox)]
406 pub request_method: &'a str,
407 #[rkyv(with = InlineAsBox)]
408 pub request_path: &'a str,
409 #[rkyv(with = InlineAsBox)]
410 pub canonical_model_id: &'a str,
411 pub response_status: u16,
412 #[rkyv(with = InlineAsBox)]
413 pub response_headers: &'a [HeaderRef<'a>],
414 pub event: SseEventRef<'a>,
415}
416
417#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
418#[rkyv(derive(Debug))]
419pub enum TransformSseEventResult {
420 Unchanged,
421 Replace { events: Box<[SseEvent]> },
422 Drop,
423}
424
425#[derive(Archive, Serialize, Deserialize, Clone, Debug)]
428#[rkyv(derive(Debug))]
429pub enum ObserveEvent {
430 RequestStarted {
431 request_id: Box<str>,
432 downstream_user_agent: Option<Box<str>>,
433 },
434 AuthnComplete {
435 principal_id: Box<str>,
436 principal_kind: Box<str>,
437 },
438 UpstreamChosen {
439 upstream: Upstream,
440 },
441 Chunk {
442 batch_index: u64,
443 event_count: u64,
444 total_bytes: u64,
445 },
446 RequestFinished {
447 status: u16,
448 input_tokens: Option<u64>,
449 output_tokens: Option<u64>,
450 cache_creation_input_tokens: Option<u64>,
451 cache_read_input_tokens: Option<u64>,
452 duration_ms: u64,
453 },
454 Error {
455 code: Box<str>,
456 message: Box<str>,
457 source: Box<str>,
458 },
459}
460
461include!(concat!(env!("OUT_DIR"), "/wire_schema_impls.rs"));