From 539a29c06df322bcd8bfc9cbb20a2427d40c6bb9 Mon Sep 17 00:00:00 2001 From: John Ye Date: Wed, 10 Dec 2025 13:48:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Claude=20Code=20=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=E8=B7=B3=E8=BF=87=20FREE=20=E5=A5=97=E9=A4=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FREE 套餐不支持 Claude Code,只支持 Codex。 在 CC 环境下跳过 FREE,显示 PLUS/PAYGO 套餐的用量。 同时修复代码格式(cargo fmt)。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/api/client.rs | 5 ++++- src/api/mod.rs | 6 ++++-- src/core/segments/byebyecode_subscription.rs | 5 ++++- src/core/segments/byebyecode_usage.rs | 11 +++++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/api/client.rs b/src/api/client.rs index 9c8d8c7..998590f 100644 --- a/src/api/client.rs +++ b/src/api/client.rs @@ -68,7 +68,10 @@ impl ApiClient { Ok(usage) } - pub fn get_subscriptions(&self, model: Option<&str>) -> Result, Box> { + pub fn get_subscriptions( + &self, + model: Option<&str>, + ) -> Result, Box> { // 构建请求体,传入 model 参数以获取正确的套餐信息 // 如果不传 model,API 会默认返回 free 套餐 let body = match model { diff --git a/src/api/mod.rs b/src/api/mod.rs index 2942f89..ae2721f 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -147,12 +147,14 @@ impl UsageData { impl Code88UsageData { pub fn calculate(&mut self) { - // 优先从 subscriptionEntityList 中找到正在扣费的套餐 - // 判断逻辑:is_active=true 且 currentCredits < creditLimit(已产生消费) + // 从 subscriptionEntityList 中找到正在扣费的套餐 + // Claude Code 环境下跳过 FREE 套餐(FREE 不支持 CC) + // 选择第一个有消费(currentCredits < creditLimit)的非 FREE 活跃套餐 let active_subscription = self .subscription_entity_list .iter() .filter(|s| s.is_active) + .filter(|s| s.subscription_name.to_uppercase() != "FREE") // 跳过 FREE .find(|s| s.current_credits < s.credit_limit); // 如果找到正在扣费的套餐,用那个套餐的数据 diff --git a/src/core/segments/byebyecode_subscription.rs b/src/core/segments/byebyecode_subscription.rs index 3247c35..e4d7910 100644 --- a/src/core/segments/byebyecode_subscription.rs +++ b/src/core/segments/byebyecode_subscription.rs @@ -99,7 +99,10 @@ pub fn collect(config: &Config, input: &InputData) -> Option { let model_id = &input.model.id; let subscriptions = fetch_subscriptions_sync(&api_key, Some(model_id))?; - fn fetch_subscriptions_sync(api_key: &str, model: Option<&str>) -> Option> { + fn fetch_subscriptions_sync( + api_key: &str, + model: Option<&str>, + ) -> Option> { let api_config = ApiConfig { enabled: true, api_key: api_key.to_string(), diff --git a/src/core/segments/byebyecode_usage.rs b/src/core/segments/byebyecode_usage.rs index b637e0f..0ee9431 100644 --- a/src/core/segments/byebyecode_usage.rs +++ b/src/core/segments/byebyecode_usage.rs @@ -64,7 +64,11 @@ pub fn collect(config: &Config, input: &InputData) -> Option { let model_id = &input.model.id; let usage = fetch_usage_sync(&api_key, &usage_url, Some(model_id))?; - fn fetch_usage_sync(api_key: &str, usage_url: &str, model: Option<&str>) -> Option { + fn fetch_usage_sync( + api_key: &str, + usage_url: &str, + model: Option<&str>, + ) -> Option { let api_config = ApiConfig { enabled: true, api_key: api_key.to_string(), @@ -146,7 +150,10 @@ pub fn collect(config: &Config, input: &InputData) -> Option { let progress_bar = format!("{}{}", "▓".repeat(filled), "░".repeat(empty)); Some(SegmentData { - primary: format!("${:.2}/${:.0} {}", used_dollars, total_dollars, progress_bar), + primary: format!( + "${:.2}/${:.0} {}", + used_dollars, total_dollars, progress_bar + ), secondary: String::new(), metadata, })