Skip to main content

lean_ctx/proxy/web_app/
mod.rs

1#[allow(dead_code)]
2pub(crate) mod conversation_tracker;
3pub(crate) mod dashboard;
4#[allow(dead_code)]
5pub(crate) mod normalize;
6#[cfg(test)]
7mod proof_tests;
8
9/// Recognized web-app AI providers (domain-detected, not path-detected).
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum WebAppProvider {
12    ClaudeWeb,
13    ChatGptWeb,
14    GeminiWeb,
15}
16
17/// A web-app request normalized to the canonical messages format that
18/// the existing compression pipeline understands.
19#[derive(Debug, Clone)]
20pub struct NormalizedRequest {
21    pub provider: WebAppProvider,
22    pub messages: Vec<serde_json::Value>,
23    pub system_prompt: Option<String>,
24    pub model: Option<String>,
25    pub conversation_id: Option<String>,
26    pub parent_message_id: Option<String>,
27}
28
29pub(crate) fn detect_web_provider(host: &str, path: &str) -> Option<WebAppProvider> {
30    let _ = path;
31    let host = host
32        .trim()
33        .trim_end_matches('.')
34        .split(':')
35        .next()
36        .unwrap_or_default();
37
38    if host.eq_ignore_ascii_case("claude.ai") {
39        Some(WebAppProvider::ClaudeWeb)
40    } else if host.eq_ignore_ascii_case("chat.openai.com")
41        || host.eq_ignore_ascii_case("chatgpt.com")
42    {
43        Some(WebAppProvider::ChatGptWeb)
44    } else if host.eq_ignore_ascii_case("gemini.google.com") {
45        Some(WebAppProvider::GeminiWeb)
46    } else {
47        None
48    }
49}