Commit 0f07dc7
feat(agentex-ui): account picker via same-origin BFF proxy (#350)
## Summary
First of a **2-PR stack** bringing account scoping + OIDC login to
agentex-ui. This base PR routes the SDK through a same-origin BFF and
adds an account switcher. Chart + deploy side lives in
scaleapi/sgp#3961.
- Routes the agentex SDK through a same-origin **BFF** (`/api/agentex`)
instead of calling the API directly from the browser — the upstream URL
and credentials never reach client JS.
- Shared `applyBffCredentials` forwards `x-selected-account-id`, drops
any client-sent `Authorization`, and strips the account-scoped `_jwt`
cookie so SGP honors the **selected** account rather than the one you
linked in with (identity stays via `_identityJwt`). The proxy also
strips `Location` on upstream 3xx so internal redirect targets don't
leak.
- Account selection is driven by the `account_id` query param (no
cookie), injected on every SDK request via a synchronous ref. Switching
accounts resets the open task + selected agent to the account's home
grid, and `resetQueries` drops the previous account's cached data so it
never briefly renders the old agents.
- `/api/user-info` fetches the caller's accounts; the picker bootstraps
to the first when the param is missing/stale, shows a disabled/empty
loading state (not a skeleton), renders single-account as static
context, and lives in the sidebar footer (collapsed → icon-only).
- Env-gated on the platform API being configured (`SGP_API_URL` /
`NEXT_PUBLIC_SGP_APP_URL`); no-op otherwise.
**Env:** `NEXT_PUBLIC_AGENTEX_API_BASE_URL` → server-only
`AGENTEX_API_URL`.
In this PR the BFF runs in default (cookie) mode — no auth dependency.
The token-hiding Bearer path arrives in the stacked PR.
## Stack
1. **This PR** — account picker + same-origin BFF proxy → `main`
2. #351 — OIDC login with server-side access token → stacked on this
branch
3. scaleapi/sgp#3961 — Helm chart + system-manager pack (deploy side)
## Test plan
- [x] `npm run typecheck` / `npm run lint` — clean
- [x] Runtime: switching accounts re-scopes agents/tasks (and SGP calls
via the `_jwt` strip); single / multi / no-account render; loading
state; no stale-account flash
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 3b722f6 commit 0f07dc7
16 files changed
Lines changed: 523 additions & 97 deletions
File tree
- agentex-ui
- app
- api
- _lib
- agentex/[...path]
- feedback
- user-info
- components
- account-picker
- providers
- task-sidebar
- ui
- hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
| 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 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 18 | | |
40 | 19 | | |
41 | 20 | | |
42 | | - | |
| 21 | + | |
43 | 22 | | |
44 | 23 | | |
45 | 24 | | |
| |||
57 | 36 | | |
58 | 37 | | |
59 | 38 | | |
60 | | - | |
61 | | - | |
| 39 | + | |
62 | 40 | | |
63 | 41 | | |
64 | 42 | | |
| |||
100 | 78 | | |
101 | 79 | | |
102 | 80 | | |
103 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
104 | 84 | | |
105 | 85 | | |
106 | 86 | | |
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
21 | 14 | | |
22 | 15 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 16 | + | |
27 | 17 | | |
28 | 18 | | |
29 | 19 | | |
| |||
0 commit comments