A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
fix(agy): skip quota queries without usable local sign-in (#10233)
Ruixia Zhong80113bfde4b5
diff --git a/src-tauri/src/services/agy_account/mod.rs b/src-tauri/src/services/agy_account/mod.rsindex d308ad305..7ea1864d8 100644--- a/src-tauri/src/services/agy_account/mod.rs+++ b/src-tauri/src/services/agy_account/mod.rs@@ -1254,7 +1254,7 @@ fn sorted_accounts(store: &StoreFile) -> Vec<AgyAccount> {accounts}-fn refresh_token_of(credential: &Value) -> Option<&str> {+pub(super) fn refresh_token_of(credential: &Value) -> Option<&str> {credential.pointer("/token/refresh_token").and_then(Value::as_str)diff --git a/src-tauri/src/services/subscription_agy.rs b/src-tauri/src/services/subscription_agy.rsindex 6a5bf341d..2b22b2352 100644--- a/src-tauri/src/services/subscription_agy.rs+++ b/src-tauri/src/services/subscription_agy.rs@@ -12,7 +12,12 @@ use process_wrap::tokio::{ChildWrapper, CommandWrap, KillOnDrop};use serde::Deserialize;use tokio::io::{AsyncRead, AsyncReadExt};+use super::agy_account::{+ keychain::{self, AgyLoginStore, SystemKeychain},+ refresh_token_of,+};use super::subscription::{CredentialStatus, QuotaTier, SubscriptionQuota};+use crate::error::AppError;const TOOL: &str = "agy";const TIMEOUT: Duration = Duration::from_secs(30);@@ -219,6 +224,44 @@ fn build_usage_command(bin: &std::path::Path) -> tokio::process::Command {command}+fn keychain_quota_failure(read: Result<Option<String>, AppError>) -> Option<SubscriptionQuota> {+ let raw = match read {+ Ok(raw) => raw,+ Err(_) => {+ return Some(SubscriptionQuota::error(+ TOOL,+ CredentialStatus::Valid,+ "Could not read the Antigravity sign-in. Check keychain access and try again."+ .to_string(),+ ));+ }+ };+ if let Some(credential) = raw.as_deref().and_then(|raw| keychain::decode(raw).ok()) {+ if refresh_token_of(&credential).is_some() {+ return None;+ }+ let has_access_token = credential+ .pointer("/token/access_token")+ .and_then(serde_json::Value::as_str)+ .is_some_and(|token| !token.is_empty());+ let access_token_current = match credential.pointer("/token/expiry") {+ None | Some(serde_json::Value::Null) => true,+ Some(expiry) => expiry+ .as_str()+ .and_then(|expiry| chrono::DateTime::parse_from_rfc3339(expiry).ok())+ .is_some_and(|expiry| expiry.timestamp() > chrono::Utc::now().timestamp()),+ };+ if has_access_token && access_token_current {+ return None;+ }+ }+ Some(SubscriptionQuota::error(+ TOOL,+ CredentialStatus::Expired,+ "Sign in with Antigravity before checking quota.".to_string(),+ ))+}+/// 由 `subscription::get_subscription_quota("agy")` 分发。没装 agy、或网关在用(官方登录没在用)/// 时按「没有凭据」处理(卡片不显示);超时、没登录或输出看不懂都写成查询失败,错误里不带/// agy 的原始输出。@@ -233,6 +276,19 @@ pub(crate) async fn get_agy_subscription_quota() -> Result<SubscriptionQuota, Stlog::debug!("[AgyQuota] 未找到 agy 可执行文件,跳过额度查询");return Ok(SubscriptionQuota::not_found(TOOL));};+ // 查额度是后台操作,缺少可用的钥匙串凭据时别让 agy 回退到交互式登录。+ // 显式选择 ADC 的 CLI 不依赖这个钥匙串条目。+ if keychain::supported()+ && !std::env::var("AGY_ADC_AUTH").is_ok_and(|value| value.eq_ignore_ascii_case("true"))+ {+ let failure =+ tokio::task::spawn_blocking(|| keychain_quota_failure(SystemKeychain::agy().read()))+ .await+ .map_err(|e| e.to_string())?;+ if let Some(quota) = failure {+ return Ok(quota);+ }+ }// build_usage_command 带上设置里的全局代理并隔离后台子进程环境;进程树的清理// 和 Windows 隐藏窗口由 run_command_output 负责。let command = build_usage_command(&bin);@@ -291,6 +347,32 @@ fn now_millis() -> i64 {mod tests {use super::*;+ #[test]+ fn quota_requires_a_usable_local_login() {+ for raw in [+ None,+ Some("not JSON"),+ Some(r#"{"writer_id":"fixture","auth_method":"consumer"}"#),+ Some(r#"{"token":{"refresh_token":""}}"#),+ Some(r#"{"token":{"access_token":"fixture","expiry":"2000-01-01T00:00:00Z"}}"#),+ ] {+ let quota = keychain_quota_failure(Ok(raw.map(str::to_owned))).unwrap();+ assert!(matches!(quota.credential_status, CredentialStatus::Expired));+ assert!(!quota.success);+ }++ for raw in [+ r#"{"token":{"refresh_token":"fixture","expiry":"2000-01-01T00:00:00Z"}}"#,+ r#"{"token":{"access_token":"fixture","expiry":"2099-01-01T00:00:00Z"}}"#,+ ] {+ assert!(keychain_quota_failure(Ok(Some(raw.to_owned()))).is_none());+ }++ let quota = keychain_quota_failure(Err(AppError::Config("PRIVATE".into()))).unwrap();+ assert!(matches!(quota.credential_status, CredentialStatus::Valid));+ assert!(!quota.error.unwrap().contains("PRIVATE"));+ }+// agy 1.4.3 `/usage --output-format json` 的真实结构(数值改过)const SAMPLE: &str = r#"{"conversation_id": "", "status": "SUCCESS", "response": "...",