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, })