Skip to content

feat(api): say who is signed in on a ChatGPT account upstream, read from its own token - #195

Merged
fylorn merged 1 commit into
mainfrom
feat/oauth-account
Sep 25, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/oauth-account

Conversation

@fylorn

@fylorn fylorn commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

What

ProviderView.oauth (OAuthView) gains account: the signed-in account's email and plan, so the Upstreams page can label a ChatGPT account row without calling ChatgptUsage (a live call to the ChatGPT backend on every page open).

OAuthView.account?: AccountView | null        // ChatGPT account upstreams only
AccountView = { email?: string | null, plan?: ChatgptPlan | null }
ChatgptPlan = KnownChatgptPlan | string
KnownChatgptPlan = "free" | "go" | "plus" | "pro" | "prolite" | "promax" | "team" | "business"
  | "self_serve_business_prolite" | "self_serve_business_usage_based" | "enterprise" | "ent26"
  | "enterprise_cbp_automation" | "enterprise_cbp_usage_based" | "edu" | "edu_plus" | "edu_pro"

Where it comes from (no network, nothing new stored)

The access token core already keeps with the credential (written to config.yaml at sign-in and after every refresh) is a JWT that names the account: plan in https://api.openai.com/auth.chatgpt_plan_type, email in https://api.openai.com/profile.email (the id_token has email at the top level; both places are read). This is the same place Codex reads an access token handed to it from outside.

  • The view prefers the token in hand (oauth::Cache::access_in_use: just renewed, possibly not yet written back) and falls back to the configured one. It never refreshes and never records anything.
  • It follows the credential: a re-login, or a refresh whose token carries a new plan, changes it. The change reaches the UI with the config_reloaded that the sign-in / write-back already causes, so there is no new event.
  • After the credential expires (needs_login), it still names the last account.
  • Account id and user id from the same token are not exposed.
  • Only ChatGPT account upstreams (protocol: chatgpt) get it. Other OAuth upstreams do not, even if their token has an email.

The plan type

ChatgptPlan is Known(KnownChatgptPlan) | Other(String), untagged, so the wire is always the backend's word. The known set is the one the Codex client recognizes. It is open because OpenAI keeps adding plans (go, prolite, ...), and showing a new name as-is beats showing "unknown". hc reads as enterprise and education reads as edu. ChatgptLoginStatus.plan uses the same type (the wire is unchanged: still a string).

Removed

ChatgptUsage.email and ChatgptUsage.plan. Who is signed in now has one source, the credential, so the upstream row and the quota dialog cannot disagree. The backend's rate limiter has been seen reporting a different plan than the token (openai/codex#29243). An app built for protocol 20 would look for these in the usage answer, so CONTROL_API_VERSION is 21.

Z.ai / BigModel

These upstreams get no account block. That sign-in ends in a plain API key with no oauth section. The key does not say whose it is, and the account name seen during sign-in (ZaiLoginStatus.account) is not kept with it. This is documented on OAuthView.account.

Tests

All tests use synthetic JWTs and the fake OpenAI. No real token or account is involved.

  • tw-api: plan words (known, alias, unknown, blank) and their wire round trip; AccountView / OAuthView.account omit what the token did not say; the TS export is KnownChatgptPlan | string and account?: AccountView.
  • tw-gateway: claims parser (email at top level or in profile, plan known / alias / unknown, nothing → no block, ids not in the view); access_in_use (token in hand, then configured; a changed credential or an empty failed entry does not count; reading does not populate the cache).
  • tw-control (fake OpenAI):
    • After a browser sign-in, the overview shows the account.
    • A re-login as another account replaces it.
    • A refresh whose token says pro moves the plan along and survives a restart from the written-back config.
    • The overview carries no token.
    • Non-ChatGPT OAuth upstreams and opaque tokens get no block.
    • None of this calls the token endpoint or the backend.

Local: cargo fmt --all --check, cargo clippy --workspace --all-targets -D warnings, cargo clippy -p tw-api --features ts, cargo test --workspace (proxy unset), cargo test -p tw-api --features ts, and the exported tw-api.ts through tsc --strict.

For the desktop app

  • Label the row from p.oauth?.account (email, plus the plan through a Record<KnownChatgptPlan, string> with the raw word as fallback).
  • Stop calling ChatgptUsage just for that.
  • The quota dialog's sign-in box also reads editing.oauth.account now.

🤖 Generated with Claude Code

…rom its own token

ProviderView.oauth (OAuthView) gains `account`: the signed-in account's
email and plan, so the Upstreams page can label a ChatGPT account row
without calling ChatgptUsage, which is a live call to the ChatGPT backend.

Nothing new is stored and nothing goes online. The access token core
already keeps with the credential (written to config.yaml at sign-in and
after every refresh) is a JWT that names the account: the plan is in
`https://api.openai.com/auth`, the email in `https://api.openai.com/profile`
(the id_token has it at the top level; both are read). The view prefers the
token in hand (just renewed, possibly not yet written back) and falls back
to the configured one. It follows the credential: a re-login or a refresh
that brings a new plan changes it, and the change arrives with the config
reload the write-back already causes. After the credential expires it
still names the last account. The account id and user id in the same
token are not exposed.

The plan is ChatgptPlan: KnownChatgptPlan (the words the Codex client
knows, a closed slug set) or the backend's own word as is, since OpenAI
keeps adding plans (go, prolite, ...). `hc` and `education` read as
`enterprise` and `edu`. TypeScript: `KnownChatgptPlan | string`.
ChatgptLoginStatus.plan uses the same type.

ChatgptUsage drops `email` and `plan`: who is signed in now has one source,
the credential, so the row and the quota dialog cannot disagree (the
backend's rate limiter has been seen to report a different plan than the
token). Control-plane protocol 21.

Z.ai / BigModel account upstreams get no account block: that sign-in ends
in a plain API key with no OAuth section, the key does not say whose it
is, and the account name seen during sign-in is not kept with it.

Tests use synthetic JWTs only and a fake OpenAI: the claims parser (email
in either place, known / alias / unknown plans), the token-in-use choice,
the overview after a browser sign-in and a re-login, a refresh that moves
the plan along and survives a restart from the written config, and that
none of it calls the token endpoint or the backend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 6d98e69 into main Sep 25, 2026
4 checks passed
@fylorn
fylorn deleted the feat/oauth-account branch September 25, 2026 03:50
fylorn added a commit that referenced this pull request Sep 25, 2026
v0.48.0 was published before the template landed, so its page holds
only GitHub's generated list. release-notes/0.48.0.md summarizes it
from #191-#198 so the page can be rewritten from the template:

- upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16
  (core 0.47.0, protocol 20) does not connect to it and a server used
  with that app stays on 0.47.0; the request store's schema 20, which
  empties the request history on the first start (and again on the way
  back); the /in-flight shape, RequestStarted.session and the removed
  ChatgptUsage fields;
- session and route on the start event, requests a rule decided
  without an upstream, the replayable /in-flight snapshot and the new
  /live fields, and /summary/routes (#197);
- per-group unpriced and no-usage counts, and security log totals
  (#193);
- the signed-in account on a ChatGPT account upstream (#195);
- releases published from one job, the server guide and the crate
  metadata (#191), and the test port fix (#192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn added a commit that referenced this pull request Sep 25, 2026
v0.48.0 was published before the template landed, so its page holds
only GitHub's generated list. release-notes/0.48.0.md summarizes it
from #191-#198 so the page can be rewritten from the template:

- upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16
  (core 0.47.0, protocol 20) does not connect to it and a server used
  with that app stays on 0.47.0; the request store's schema 20, which
  empties the request history on the first start (and again on the way
  back); the /in-flight shape, RequestStarted.session and the removed
  ChatgptUsage fields;
- session and route on the start event, requests a rule decided
  without an upstream, the replayable /in-flight snapshot and the new
  /live fields, and /summary/routes (#197);
- per-group unpriced and no-usage counts, and security log totals
  (#193);
- the signed-in account on a ChatGPT account upstream (#195);
- releases published from one job, the server guide and the crate
  metadata (#191), and the test port fix (#192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn added a commit that referenced this pull request Sep 25, 2026
…summary (#196)

* ci(release): write the release page from a template, with an English summary

#191 made the publish job write the release once, with GitHub's
generated list of pull requests as its only text and the tag as its
title. A release is now titled "ThinkWatch Core <version>", and its text
has, in order:

- an English summary from release-notes/<version>.md, when that file
  exists;
- a table of the files for each platform;
- the commands that install this version on a Linux server and switch
  an existing installation to it (install.sh --version, twcore upgrade
  --version --restart);
- how to verify a download against its .sha256;
- GitHub's generated list of pull requests.

scripts/release_notes.py builds the text; the publish job fetches the
generated list itself (releases/generate-notes) and hands the finished
text to action-gh-release, which no longer generates anything. The
"only once" rule from #191 stays: a release that already exists keeps
its text. A rehearsal (workflow_dispatch) now writes the text into the
run summary, using the version in Cargo.toml.

scripts/release_notes_test.py checks that the table links exactly the
files in release.yml's FILES list, that the install and upgrade options
exist, and that every file in release-notes/ renders; the Linux CI job
runs it before compiling.

release-notes/0.47.0.md summarizes 0.47.0 from #183-#190; the live
v0.47.0 release page now carries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* release-notes: summarize 0.48.0

v0.48.0 was published before the template landed, so its page holds
only GitHub's generated list. release-notes/0.48.0.md summarizes it
from #191-#198 so the page can be rewritten from the template:

- upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16
  (core 0.47.0, protocol 20) does not connect to it and a server used
  with that app stays on 0.47.0; the request store's schema 20, which
  empties the request history on the first start (and again on the way
  back); the /in-flight shape, RequestStarted.session and the removed
  ChatgptUsage fields;
- session and route on the start event, requests a rule decided
  without an upstream, the replayable /in-flight snapshot and the new
  /live fields, and /summary/routes (#197);
- per-group unpriced and no-usage counts, and security log totals
  (#193);
- the signed-in account on a ChatGPT account upstream (#195);
- releases published from one job, the server guide and the crate
  metadata (#191), and the test port fix (#192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* release-notes(0.48.0): say where the key is kept without naming the keychain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant