Browse Source

fix: respect ANTHROPIC_BASE_URL in all client instantiations

Yeachan-Heo 2 tháng trước cách đây
mục cha
commit
fedb748ea3

+ 1 - 0
.claude/sessions/session-1775007533836.json

@@ -0,0 +1 @@
+{"messages":[],"version":1}

+ 1 - 0
.claude/sessions/session-1775007622154.json

@@ -0,0 +1 @@
+{"messages":[{"blocks":[{"text":"What is 2+2? Reply with just the number.","type":"text"}],"role":"user"},{"blocks":[{"text":"4","type":"text"}],"role":"assistant","usage":{"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":19,"output_tokens":5}}],"version":1}

+ 1 - 0
.claude/sessions/session-1775007632904.json

@@ -0,0 +1 @@
+{"messages":[{"blocks":[{"text":"Say hello in exactly 3 words","type":"text"}],"role":"user"},{"blocks":[{"text":"Hello there, friend!","type":"text"}],"role":"assistant","usage":{"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":14,"output_tokens":8}}],"version":1}

+ 1 - 0
rust/.claude/sessions/session-1775007453382.json

@@ -0,0 +1 @@
+{"messages":[],"version":1}

+ 1 - 0
rust/.claude/sessions/session-1775007484031.json

@@ -0,0 +1 @@
+{"messages":[],"version":1}

+ 1 - 0
rust/.claude/sessions/session-1775007490104.json

@@ -0,0 +1 @@
+{"messages":[],"version":1}

+ 1 - 1
rust/crates/api/src/client.rs

@@ -520,7 +520,7 @@ fn read_auth_token() -> Option<String> {
         .and_then(std::convert::identity)
 }
 
-fn read_base_url() -> String {
+pub fn read_base_url() -> String {
     std::env::var("ANTHROPIC_BASE_URL").unwrap_or_else(|_| DEFAULT_BASE_URL.to_string())
 }
 

+ 2 - 2
rust/crates/api/src/lib.rs

@@ -4,8 +4,8 @@ mod sse;
 mod types;
 
 pub use client::{
-    oauth_token_is_expired, resolve_saved_oauth_token, resolve_startup_auth_source,
-    AnthropicClient, AuthSource, MessageStream, OAuthTokenSet,
+    oauth_token_is_expired, read_base_url, resolve_saved_oauth_token,
+    resolve_startup_auth_source, AnthropicClient, AuthSource, MessageStream, OAuthTokenSet,
 };
 pub use error::ApiError;
 pub use sse::{parse_frame, SseParser};

+ 3 - 3
rust/crates/rusty-claude-cli/src/main.rs

@@ -450,7 +450,7 @@ fn run_login() -> Result<(), Box<dyn std::error::Error>> {
         return Err(io::Error::new(io::ErrorKind::InvalidData, "oauth state mismatch").into());
     }
 
-    let client = AnthropicClient::from_auth(AuthSource::None);
+    let client = AnthropicClient::from_auth(AuthSource::None).with_base_url(api::read_base_url());
     let exchange_request =
         OAuthTokenExchangeRequest::from_config(oauth, code, state, pkce.verifier, redirect_uri);
     let runtime = tokio::runtime::Runtime::new()?;
@@ -1021,7 +1021,7 @@ impl LiveCli {
     }
 
     fn run_prompt_json(&mut self, input: &str) -> Result<(), Box<dyn std::error::Error>> {
-        let client = AnthropicClient::from_auth(resolve_cli_auth_source()?);
+        let client = AnthropicClient::from_auth(resolve_cli_auth_source()?).with_base_url(api::read_base_url());
         let request = MessageRequest {
             model: self.model.clone(),
             max_tokens: DEFAULT_MAX_TOKENS,
@@ -1922,7 +1922,7 @@ impl AnthropicRuntimeClient {
     ) -> Result<Self, Box<dyn std::error::Error>> {
         Ok(Self {
             runtime: tokio::runtime::Runtime::new()?,
-            client: AnthropicClient::from_auth(resolve_cli_auth_source()?),
+            client: AnthropicClient::from_auth(resolve_cli_auth_source()?).with_base_url(api::read_base_url()),
             model,
             enable_tools,
             allowed_tools,