From 5396f5fd7aab55c15bc253aa81a6f77a5f70d78a Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Sat, 19 Sep 2026 13:06:58 +0800 Subject: [PATCH] feat: say which account is signed in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An upstream's name is whatever the user typed. With two ChatGPT accounts configured, nothing in the app said which one a row was — the usage call had the email in hand and dropped it on the floor. It is now in the answer. The user id and account id still are not: the interface cannot tell a person anything with them, and once they are in a response they end up in logs. Co-Authored-By: Claude Opus 5 --- Cargo.lock | 40 +++++++++++++++--------------- Cargo.toml | 2 +- crates/tw-api/src/lib.rs | 4 +++ crates/tw-control/src/chatgpt.rs | 14 ++++++----- crates/tw-control/tests/chatgpt.rs | 5 +++- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a194a023..e38733d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2775,7 +2775,7 @@ dependencies = [ [[package]] name = "tw-adopt" -version = "0.8.0" +version = "0.8.1" dependencies = [ "serde", "serde_json", @@ -2789,7 +2789,7 @@ dependencies = [ [[package]] name = "tw-api" -version = "0.8.0" +version = "0.8.1" dependencies = [ "serde", "serde_json", @@ -2797,7 +2797,7 @@ dependencies = [ [[package]] name = "tw-config" -version = "0.8.0" +version = "0.8.1" dependencies = [ "blake3", "notify", @@ -2817,7 +2817,7 @@ dependencies = [ [[package]] name = "tw-control" -version = "0.8.0" +version = "0.8.1" dependencies = [ "axum", "base64", @@ -2854,7 +2854,7 @@ dependencies = [ [[package]] name = "tw-crypto" -version = "0.8.0" +version = "0.8.1" dependencies = [ "aes-gcm", "anyhow", @@ -2866,7 +2866,7 @@ dependencies = [ [[package]] name = "tw-dialect" -version = "0.8.0" +version = "0.8.1" dependencies = [ "serde", "serde_json", @@ -2874,7 +2874,7 @@ dependencies = [ [[package]] name = "tw-engine" -version = "0.8.0" +version = "0.8.1" dependencies = [ "serde", "serde_json", @@ -2887,7 +2887,7 @@ dependencies = [ [[package]] name = "tw-gateway" -version = "0.8.0" +version = "0.8.1" dependencies = [ "arc-swap", "async-stream", @@ -2930,7 +2930,7 @@ dependencies = [ [[package]] name = "tw-observe" -version = "0.8.0" +version = "0.8.1" dependencies = [ "tokio", "tracing", @@ -2939,7 +2939,7 @@ dependencies = [ [[package]] name = "tw-pricing" -version = "0.8.0" +version = "0.8.1" dependencies = [ "arc-swap", "flate2", @@ -2951,7 +2951,7 @@ dependencies = [ [[package]] name = "tw-protocol" -version = "0.8.0" +version = "0.8.1" dependencies = [ "bytes", "futures", @@ -2963,7 +2963,7 @@ dependencies = [ [[package]] name = "tw-provider" -version = "0.8.0" +version = "0.8.1" dependencies = [ "async-stream", "aws-credential-types", @@ -2988,7 +2988,7 @@ dependencies = [ [[package]] name = "tw-redact" -version = "0.8.0" +version = "0.8.1" dependencies = [ "base64", "serde", @@ -2998,7 +2998,7 @@ dependencies = [ [[package]] name = "tw-resil" -version = "0.8.0" +version = "0.8.1" dependencies = [ "futures", "metrics", @@ -3011,7 +3011,7 @@ dependencies = [ [[package]] name = "tw-scan" -version = "0.8.0" +version = "0.8.1" dependencies = [ "notify", "regex", @@ -3028,14 +3028,14 @@ dependencies = [ [[package]] name = "tw-secret" -version = "0.8.0" +version = "0.8.1" dependencies = [ "thiserror", ] [[package]] name = "tw-store" -version = "0.8.0" +version = "0.8.1" dependencies = [ "bytes", "libc", @@ -3053,7 +3053,7 @@ dependencies = [ [[package]] name = "tw-types" -version = "0.8.0" +version = "0.8.1" dependencies = [ "serde", "serde_json", @@ -3062,7 +3062,7 @@ dependencies = [ [[package]] name = "tw-yaml" -version = "0.8.0" +version = "0.8.1" dependencies = [ "saphyr-parser", "serde_yaml_ng", @@ -3071,7 +3071,7 @@ dependencies = [ [[package]] name = "twcore" -version = "0.8.0" +version = "0.8.1" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 8a02d8b2..1ffcd4ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ repository = "https://github.com/ThinkWatchProject/ThinkWatch-Core" # 二进制走 CalVer,crate 走 SemVer —— 两者是两回事,卖给不同的人。 # 这里是 crate 的版本。 -version = "0.8.0" +version = "0.8.1" [workspace.dependencies] # ── 内部 crate ─────────────────────────────────────────── diff --git a/crates/tw-api/src/lib.rs b/crates/tw-api/src/lib.rs index 3c065f95..f01f6745 100644 --- a/crates/tw-api/src/lib.rs +++ b/crates/tw-api/src/lib.rs @@ -1899,6 +1899,10 @@ pub struct ChatgptLoginStatus { /// ChatGPT 账号的用量(`GET /providers/{name}/chatgpt/usage`)。 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ChatgptUsage { + /// 登的是哪个账号。**只有邮箱** —— 同一份回答里的用户 ID + /// 和账户 ID 不往外带:界面认账号靠邮箱,那两个读不出是谁 + #[serde(default, skip_serializing_if = "Option::is_none")] + pub email: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub plan: Option, /// 额度窗口,词表同 [`QuotaWindow`] diff --git a/crates/tw-control/src/chatgpt.rs b/crates/tw-control/src/chatgpt.rs index a47dbc94..2729a532 100644 --- a/crates/tw-control/src/chatgpt.rs +++ b/crates/tw-control/src/chatgpt.rs @@ -928,7 +928,9 @@ async fn usage( Ok(Json(usage)) } -/// `wham/usage` 的回答。**只取额度相关的几项**:同一份回答里还有邮箱和用户 ID,不往外带 +/// `wham/usage` 的回答。**只取界面要用的几项**:额度、套餐,以及邮箱 +/// —— 账号不止一个时,邮箱是用户分得清哪个是哪个的唯一一项。同一份回答里 +/// 的用户 ID 和账户 ID 不往外带:界面用不上,而它们一旦出去就会进日志 fn parse_usage(v: &Value) -> tw_api::ChatgptUsage { let window = |w: &Value| { let secs = w.get("limit_window_seconds")?.as_u64().filter(|s| *s > 0)?; @@ -942,6 +944,7 @@ fn parse_usage(v: &Value) -> tw_api::ChatgptUsage { }; let limits = &v["rate_limit"]; tw_api::ChatgptUsage { + email: v["email"].as_str().map(str::to_string), plan: v["plan_type"].as_str().map(str::to_string), windows: [&limits["primary_window"], &limits["secondary_window"]] .into_iter() @@ -1039,7 +1042,7 @@ mod tests { } #[test] - fn usage_keeps_only_the_limits() { + fn usage_keeps_the_limits_and_who_is_signed_in() { let v = serde_json::json!({ "email": "someone@example.com", "user_id": "user-1", @@ -1053,16 +1056,15 @@ mod tests { "rate_limit_reset_credits": {"available_count": 2} }); let u = parse_usage(&v); + assert_eq!(u.email.as_deref(), Some("someone@example.com")); assert_eq!(u.plan.as_deref(), Some("plus")); assert_eq!(u.windows.len(), 1); assert_eq!(u.windows[0].window, "weekly"); assert_eq!(u.windows[0].used_percent, 21.0); assert_eq!(u.windows[0].reset_in_secs, Some(410907)); assert_eq!(u.reset_credits, Some(2)); + // 用户 ID 不往外带:界面读不出是谁,而它一旦出去就会进日志 let json = serde_json::to_string(&u).unwrap(); - assert!( - !json.contains("someone@example.com") && !json.contains("user-1"), - "{json}" - ); + assert!(!json.contains("user-1"), "{json}"); } } diff --git a/crates/tw-control/tests/chatgpt.rs b/crates/tw-control/tests/chatgpt.rs index ca426c21..8240e722 100644 --- a/crates/tw-control/tests/chatgpt.rs +++ b/crates/tw-control/tests/chatgpt.rs @@ -817,9 +817,12 @@ async fn usage_shows_the_limits_without_personal_details() { json!([{"window": "weekly", "used_percent": 21.0, "reset_in_secs": 410907}]), "长度为 0 的窗口不算" ); + // 邮箱要给:账号不止一个时,它是用户分辨哪个是哪个的唯一一项 + assert_eq!(v["email"], "someone@example.com"); + // 用户 ID 和账户 ID 不给:界面读不出是谁,而它们一旦出去就会进日志 let text = v.to_string(); assert!( - !text.contains("someone@example.com") && !text.contains("user-1"), + !text.contains("user-1") && !text.contains("acct-1"), "{text}" );