Commit 4391788
authored
feat(codex): unify ChatGPT subscription onto pi-ai's openai-codex-responses wire (#155)
## Summary
Phase 2 of the Codex ChatGPT subscription login. Phase 1 shipped a
self-rolled client (SSE parser, ChatGPT headers, JWT accountId
extraction, 401 retry) behind a "coming soon" UI gate. pi-ai 0.67.68
ships all of that as a first-class `openai-codex-responses` wire, so
this PR deletes our version and routes ChatGPT subscription through the
same `core → pi-agent-core → pi-ai` path every other provider already
uses.
- **Link unified**: no more `isChatgptCodex` branches. `generate` /
`generateTitle` / `applyComment` all resolve codex exactly like
Anthropic or OpenAI — the only codex-specific code left is the OAuth
login flow (`oauth.ts` / `oauth-server.ts` / `token-store.ts`), and that
sits outside the generation link.
- **Long-agent-run safety**: `GenerateInput.getApiKey` is a new optional
async getter; the desktop passes it for codex so pi-agent-core re-reads
the token between turns (auto-refreshing within the token store's 5-min
buffer). Mid-run sign-out errors propagate the original
`CodesignError(PROVIDER_AUTH_MISSING)` rather than being flattened into
a plain `PROVIDER_ERROR`.
- **Upgrade migration**: boot-time `migrateStaleCodexEntryIfNeeded()`
rewrites any Phase-1-shaped provider entry so feat-branch testers don't
need to sign out/in.
- **UI flipped out of coming-soon**: `ChatgptLoginCard` returns to the
three-state login/status/logout flow with i18n in both locales.
Net diff: **+758 / −1104**, mostly deletions of Phase 1 self-rolled code
pi-ai now provides.
## PRINCIPLES §5b
- [x] Compatibility — old API-key configs unchanged; Phase 1 codex
entries auto-migrate on boot
- [x] Upgradeability — `CHATGPT_CODEX_PROVIDER_ID` + `WireApi` live in
`@open-codesign/shared` so future wire additions are one-line changes;
OAuth provider entry is system-managed (rewritten idempotently on
login/migrate)
- [x] No bloat — deletes 963 LOC of duplicated SSE/header/retry; adds
758 LOC (most of which is tests + the OAuth flow that was already there)
- [x] Elegance — one `generateViaAgent` code path for every provider; no
provider-specific dispatch branches
## Test plan
- [x] `pnpm -r typecheck` — green
- [x] `pnpm -r test` — **1289** tests pass across 10 packages (+11 new
tests: base-url codex behavior, `resolve-api-key` DI helper,
`migrateStaleCodexEntryIfNeeded` fork, agent.ts per-turn getApiKey +
capture/rethrow)
- [x] `pnpm lint` — green
- [ ] Manual smoke: sign-in flow, generate with codex active, switch
back to API-key provider mid-run
- [ ] Manual smoke: sign out mid-long-agent-run → confirm
PROVIDER_AUTH_MISSING toast (not generic PROVIDER_ERROR)
## Commits
1. `b8bb1b2` Main implementation — delete self-rolled client, register
pi-ai wire, flip UI
2. `375b9c5` First review pass — WireApi dedup, structured auth error,
modelsHint ordering, +4 tests
3. `dde3bf3` Second pass — migration, `CHATGPT_CODEX_PROVIDER_ID`
shared, `resolve-api-key` DI + 7 tests, per-turn getApiKey
4. `8c443b9` Third pass — capture+rethrow so mid-agent-run auth errors
preserve their structured code; +3 agent tests
5. `412f159` Fourth pass — remove dead `comingSoon` i18n key, update
changeset
6. `296ac25` Drop obsolete internal Phase 2 resume doc
## Known follow-ups (not blocking)
- Usage / cost tracking for codex responses (pi-ai's codex wire emits
usage events; `complete()` in `packages/providers` already surfaces them
via `GenerateResult`, but the desktop UI's cost display still reads zero
because Phase 1 hardcoded it).
- Image-attachment support — pi-ai's wire accepts `image` input blocks;
the `complete()` shim currently only forwards text. Tracked separately.
Signed-off-by: hqhq1025 <1506751656@qq.com>1 parent 4cec7ea commit 4391788
28 files changed
Lines changed: 1133 additions & 1456 deletions
File tree
- .changeset
- apps/desktop/src
- main
- renderer/src/components
- packages
- core/src
- i18n/src/locales
- providers/src
- codex
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
This file was deleted.
0 commit comments