Repository navigation
feat(ai-gateway): pool Claude and ChatGPT subscriptions - #3452
Merged
Merged
Conversation
`bun run gen` resolved every action path against the plopfile's own directory, so the documented root-level run wrote `services/<name>/…` into `tools/plop/`. Point plop at the repo root with `--dest .`. Three template defects made a freshly generated react service red: - `vitest.config.ts` called `yamlImports()` but imported it only in the Storybook branch, so a service scaffolded without Storybook failed `typecheck`. - `keys-dynamic.yml` ended at a valueless `entries:`, which parses to null where the i18n usage check wants a list, so `test` failed on the generated messages suite. - Four files disagreed with `oxfmt` on import and key order, so `bun run format:check` failed on the untouched output.
`bun run gen:service ai-gateway … react 3004 false`, plus the pieces the generator cannot emit itself: the three binary favicons (Handlebars would corrupt them) and the workspace's `.commitlintrc.json` scope. Nothing is wired yet — the index route renders the package name. The gateway itself lands next.
The runner stage carried no `node_modules` but started `bun server.ts`, so the very first import — `@tale/ui/server` — could not resolve and the image died on boot. Bundle the server the way `services/web` and `services/docs` do (`bun build --target=bun --outfile=server.js`) and ship that instead, so every import the entry makes is inlined. Two smaller things in the same shape: the entrypoint set `PORT` without exporting it, so the server never saw it and always took its default; and the workspace lint config carried no `ignorePatterns`, so a generated service linted its own `dist/` and its generated route tree and failed `unicorn/filename-case` on arrival.
Same shape as `ClaudeIcon`, and the same path `services/web` already draws in its connector set, so the two families stay visually aligned. Registered in the icon gallery and in the accessibility sweep that renders every mark.
A gateway that holds the AI subscriptions a team already pays for and hands their OAuth tokens out through one endpoint — the job `cc-gateway` does for Claude Pro/Max accounts, generalized so a second vendor is a module rather than a rewrite. Both subscriptions are reached through the public OAuth client their own CLI ships with, and they disagree on almost everything below that: Anthropic's console callback prints a code to copy, OpenAI's redirects to a loopback the browser cannot load; Anthropic names the account on a profile endpoint, OpenAI puts it in the id_token; Anthropic reports two general windows plus per-model caps, OpenAI two windows measured in minutes. A provider module owns those five moves — authorize, exchange, refresh, identity, usage — and everything above it is vendor-agnostic, so the panel, the refresh loop and the token endpoint have one code path. A third provider is a module and a registry line; the panel reads the catalog from the server, so only its label is the client's to add. Two doors, kept apart: the panel is behind one password and never returns a token, `GET /api/tokens` is behind an API key and returns nothing else. Neither opens the other — a leaked browser session cannot exfiltrate the pool, and a machine holding the key cannot add or remove accounts. Tokens are sealed with AES-256-GCM at a pinned 16-byte tag, so a truncated tag is refused rather than verified, and a tampered store fails loudly instead of decrypting to something plausible. The pool itself is one JSON document under `AI_GATEWAY_DATA_DIR`, written atomically and serialized against itself — a credential pool is a handful of records, and keeping it a file is what lets the service be one process with nothing to provision. The panel is one screen on `@tale/ui`: the accounts as a `DataTable`, each with its vendor mark, its plan, its status, its usage windows as bars, and the three verbs an operator needs — copy the CLI command, re-authenticate, remove. EN/DE/FR throughout. Production refuses to boot without its four secrets and says which are missing; development generates them for the process and prints them once. The Vite dev server mounts the same API the Bun server does, so a route behaves identically in both.
The `--dest .` half of the invocation is silent when it goes missing: plop prints the `/services/<name>/…` path it did not use and writes the tree inside `tools/plop/` instead. A test is the only thing that notices.
The service shipped a Dockerfile and a compose file that nothing built, so `ghcr.io/tale-project/tale/tale-ai-gateway` would never have existed and the fleet deployment that pulls it could not run. `release.yml` publishes it beside the other services, and `build.yml`'s change filter runs a pull request's checks when the service or the component library it builds on moves.
The fleet gives the gateway a GlitchTip project of its own; without this nothing reported to it. Same wiring as docs and ui-docs: absent a DSN it reports nothing and costs nothing, which is every local run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A new service,
services/ai-gateway: a gateway that holds the AI subscriptions a team already pays for — Claude Pro/Max and ChatGPT Plus/Pro accounts — and hands their OAuth tokens out through one endpoint.It is the job
cc-gatewaydoes for Claude accounts, rebuilt here on the Tale stack and generalized so a second vendor is a module rather than a rewrite.What it does
GET /api/tokensanswers with every account's access token, its expiry, its status, and the environment variable that hands it to the vendor's CLIWhy it is shaped this way
Both subscriptions are reached through the public OAuth client their own CLI ships with, and they disagree on almost everything below that: Anthropic's console callback prints a code to copy, OpenAI's redirects to a loopback the browser cannot load; Anthropic names the account on a profile endpoint, OpenAI puts it in the
id_token; Anthropic reports two general windows plus per-model caps, OpenAI two windows measured in minutes.A provider module owns those five moves — authorize, exchange, refresh, identity, usage — and everything above it is vendor-agnostic. A third provider is a module and a registry line; the panel reads the catalog from
GET /api/providers, so only itsproviders.<id>label is the client's to add.The pool itself is one JSON document under
AI_GATEWAY_DATA_DIR, written atomically and serialized against itself. A credential pool is a handful of records, and keeping it a file is what lets the service be one process with nothing to provision.The panel
One screen on
@tale/ui: the accounts as aDataTable, each with its vendor mark, its plan, its status, its usage windows as bars, and the three verbs an operator needs — copy the CLI command, re-authenticate, remove. EN/DE/FR throughout, light and dark.Also in here
fix(plop)×2 — the react service generator produced a service that was red on arrival:bun run genwrote intotools/plop/instead of the repo root,vitest.config.tsusedyamlImportswithout importing it,keys-dynamic.ymlparsed tonullwhere the i18n check wants a list, four files disagreed withoxfmt, the workspace lint config linted its owndist/, the container image started aserver.tswhose imports it could not resolve, and the entrypoint setPORTwithout exporting it. The scaffold commit is separated from the implementation so the generator's raw output is readable on its own. A test now holdsgento--dest ., because that one is silent when it regresses.feat(ui)— anOpenAIIconbeside the existingClaudeIcon, same shape and the same pathservices/webalready draws.ci(ai-gateway)— the service shipped a Dockerfile nothing built, sotale-ai-gatewaywould never have existed and the fleet deployment that pulls it could not run.release.ymlpublishes it beside the other services;build.yml's filter runs a PR's checks when the service or@tale/uimoves.feat(ai-gateway)monitoring — the fleet gives it a GlitchTip project of its own (ops 787620a), so the server reports failures to it the way docs and ui-docs do.compose.ai-gateway.yml— standalone, following thecompose.ui-docs.ymlpattern, with a named volume for the pool.Deploying it
tale-project/ops@787620a adds
deployments/tale/ai-gateway/pron its own droplet at ai.tale.dev and retires cc-gateway. Its image pin is a placeholder until this merges and a release publishestale-ai-gateway— replace it with the real digest before the first deploy.Verification
bun run check,bun run knip:check,bun run lint:sast,bun run lint:manual— green. (@tale/cli'sruntime-configuration.test.tsalternate-mount case is red on this machine before and after; nothing here touchestools/cli.)bun build server.ts→server.js, which is what the image runs) booted and answered/api/health,/api/tokensand the SPA; the missing-secrets path refuses with the four names.Not in here
No inference proxy, no account rotation, no multi-user panel, no usage history — each recorded with its reason in
tests/manual/reference/not-a-finding.md. The OAuth round trip itself cannot be automated (a vendor's consent screen, a real subscription), so it is the manualaccountssuite.