1use crate::core::config::{Config, ContextPolicy};
5
6pub struct ProxyRunOptions {
8 pub listen: String,
9 pub upstream: String,
10 pub provider: String,
11 pub minify_json: bool,
12 pub compress_transport: bool,
13 pub max_response_bytes: u64,
14 pub max_request_bytes: u64,
15 pub context_policy: ContextPolicy,
16}
17
18impl ProxyRunOptions {
19 pub fn from_config(cfg: &Config) -> Self {
20 let p = &cfg.proxy;
21 Self {
22 listen: p.listen.clone(),
23 upstream: provider_upstream(&p.provider, &p.upstream),
24 provider: p.provider.clone(),
25 minify_json: p.minify_json,
26 compress_transport: p.compress_transport,
27 max_response_bytes: u64::from(p.max_response_body_mb) * 1024 * 1024,
28 max_request_bytes: u64::from(p.max_request_body_mb) * 1024 * 1024,
29 context_policy: p.context_policy.clone(),
30 }
31 }
32
33 pub fn from_config_with_overrides(
35 cfg: &Config,
36 listen: Option<String>,
37 upstream: Option<String>,
38 provider: Option<String>,
39 ) -> Self {
40 let mut o = Self::from_config(cfg);
41 if let Some(s) = listen {
42 o.listen = s;
43 }
44 if let Some(s) = provider {
45 o.provider = s;
46 o.upstream = provider_upstream(&o.provider, &o.upstream);
47 }
48 if let Some(s) = upstream {
49 o.upstream = s;
50 }
51 o
52 }
53}
54
55fn provider_upstream(provider: &str, upstream: &str) -> String {
56 if provider.eq_ignore_ascii_case("openai") && upstream == "https://api.anthropic.com" {
57 "https://api.openai.com".into()
58 } else {
59 upstream.to_string()
60 }
61}