1use crate::anthropic::schema::MessagesRequest;
2use crate::monitor::MonitorHandle;
3use crate::traffic::TrafficCapture;
4use anyhow::Result;
5use async_trait::async_trait;
6use axum::response::Response;
7use clap::Subcommand;
8use std::sync::Arc;
9
10#[derive(Debug, Clone, Subcommand)]
11pub enum AuthCommand {
12 Login,
14 Device,
16 Status,
18 Logout,
20}
21
22#[async_trait]
23pub trait Provider: Send + Sync {
24 fn name(&self) -> &'static str;
25 fn supported_models(&self) -> Vec<String>;
26 fn cli(&self) -> &'static dyn CliHandlers;
27 async fn handle_messages(&self, body: MessagesRequest, ctx: RequestContext) -> Response;
28 async fn handle_count_tokens(&self, body: MessagesRequest, ctx: RequestContext) -> Response;
29}
30
31pub trait CliHandlers: Send + Sync {
32 fn login(&self) -> Result<()>;
33 fn device(&self) -> Result<()>;
34 fn status(&self) -> Result<()>;
35 fn logout(&self) -> Result<()>;
36}
37
38#[derive(Debug, Clone)]
39pub struct RequestContext {
40 pub req_id: String,
41 pub session_id: Option<String>,
42 pub session_seq: Option<u64>,
43 pub provider: String,
44 pub traffic: Option<Arc<TrafficCapture>>,
45 pub monitor: Option<MonitorHandle>,
46 pub passthrough: Option<Passthrough>,
50}
51
52#[derive(Debug, Clone)]
54pub struct Passthrough {
55 pub raw_body: axum::body::Bytes,
57 pub headers: axum::http::HeaderMap,
59 pub path_and_query: String,
61}