Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

refactor: align subscription dialog with connect-side catalog sync

Miguelon Peluchon140112b6aeb0
diff --git a/control-ui/components/CodexSubscriptionHub/index.tsx b/control-ui/components/CodexSubscriptionHub/index.tsx
index 7287199e2..1ad1377c7 100644
--- a/control-ui/components/CodexSubscriptionHub/index.tsx
+++ b/control-ui/components/CodexSubscriptionHub/index.tsx
@@ -13,7 +13,6 @@ import {
pollCodexDevice,
revokeCodexSubscription,
startCodexDeviceConnect,
- syncCodexSubscriptionCatalog,
} from '@lib/codexSubscription'
import {
type CodexSubscriptionCapability,
@@ -77,9 +76,6 @@ export function CodexSubscriptionHub() {
>([])
const [userCode, setUserCode] = useState<string | null>(null)
const [verificationUri, setVerificationUri] = useState<string | null>(null)
- // True when the browser blocked the automatic ChatGPT tab, so the card tells
- // the operator to use the manual link instead of assuming the tab opened.
- const [deviceTabBlocked, setDeviceTabBlocked] = useState(false)
// Ported from dev: bumps whenever the dialog closes/reopens or a new connect
// starts, so a stale device-poll loop (closed dialog, switched row) can no
// longer touch state after it was abandoned.
@@ -133,8 +129,9 @@ export function CodexSubscriptionHub() {
}, [connections, searchQuery])
// The name check (or the footer CTA) confirms the name: it creates the empty
- // grant with that display name and unlocks the rest of the setup form
- // (sign-in, models, default) in the same dialog.
+ // grant with that display name and starts the device sign-in right away —
+ // by the time the operator approves the code, the catalog is already synced
+ // server-side (connect handshake) and the models grid is populated.
async function confirmNameAndCreate() {
const displayName = editName.trim()
if (!displayName) {
@@ -149,9 +146,11 @@ export function CodexSubscriptionHub() {
setSetupNew(true)
await load()
showToast(`Subscription ${displayName} created.`, { tone: 'success' })
+ // Ownership of busyKey hands over to handleConnect; it clears it when
+ // the device flow settles. Only the failure path resets it here.
+ void handleConnect(created)
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not create subscription')
- } finally {
setBusyKey(null)
}
}
@@ -165,7 +164,6 @@ export function CodexSubscriptionHub() {
setSetupNew(false)
setUserCode(null)
setVerificationUri(null)
- setDeviceTabBlocked(false)
setError('')
}
@@ -177,7 +175,6 @@ export function CodexSubscriptionHub() {
setSetupNew(false)
setUserCode(null)
setVerificationUri(null)
- setDeviceTabBlocked(false)
setError('')
if (row.status === 'connected') {
try {
@@ -201,7 +198,6 @@ export function CodexSubscriptionHub() {
setSetupNew(false)
setUserCode(null)
setVerificationUri(null)
- setDeviceTabBlocked(false)
void load().catch(err => {
setError(err instanceof Error ? err.message : 'Failed to load ChatGPT subscriptions')
})
@@ -246,17 +242,6 @@ export function CodexSubscriptionHub() {
if (epoch !== connectEpoch.current) return
setUserCode(started.userCode)
setVerificationUri(started.verificationUri)
- // Open the verification page straight away so the operator never has to
- // copy the URL by hand. Browsers may still block the popup (especially
- // after the await), so remember the failure and surface a manual link.
- let opened: Window | null = null
- try {
- opened = window.open(started.verificationUri, '_blank', 'noopener,noreferrer')
- } catch {
- opened = null
- }
- if (epoch !== connectEpoch.current) return
- setDeviceTabBlocked(!opened)
const deadline = Date.now() + started.intervalSeconds * 1000 * 40
while (Date.now() < deadline) {
await new Promise(resolve => setTimeout(resolve, started.intervalSeconds * 1000))
@@ -306,26 +291,6 @@ export function CodexSubscriptionHub() {
}
}
- async function handleSync(row: CodexSubscriptionConnectionView) {
- if (row.status !== 'connected') return
- setBusyKey(row.connectionKey)
- try {
- const synced = await syncCodexSubscriptionCatalog(row.connectionKey)
- if (synced.outcome !== 'ready') {
- setError(`Catalog sync ${synced.outcome}`)
- return
- }
- const models = await listCodexConnectionModels(row.connectionKey)
- setEditModels(models)
- await load()
- showToast(`Catalog synced: ${grantLabel(row)}`, { tone: 'success' })
- } catch (err) {
- setError(err instanceof Error ? err.message : 'Catalog sync failed')
- } finally {
- setBusyKey(null)
- }
- }
-
async function handleToggleModel(
row: CodexSubscriptionConnectionView,
model: string,
@@ -612,7 +577,7 @@ export function CodexSubscriptionHub() {
</div>
{setupNew && editing ? (
<p className="cu-field__hint" style={{ margin: 0 }}>
- Grant created — sign in with ChatGPT, choose the models to offer, and set a
+ Grant created — sign-in started. Once connected, pick the models to offer and a
default to finish setup.
</p>
) : null}
@@ -624,8 +589,8 @@ export function CodexSubscriptionHub() {
</div>
<p className="cu-field__hint" style={{ margin: 0 }}>
{setupNew || !editing
- ? 'Agents authorize through this subscription’s ChatGPT grant. Sign in to connect it.'
- : 'Agents authorize through this subscription’s ChatGPT grant. Reconnect if the grant expired, or sync to refresh the model catalog.'}
+ ? 'Agents authorize through this subscription’s ChatGPT grant. Sign in to connect it — the catalog syncs automatically.'
+ : 'Agents authorize through this subscription’s ChatGPT grant. Reconnect if the grant expired — the catalog refreshes automatically.'}
</p>
<div className="cu-form-inline">
<span
@@ -643,28 +608,11 @@ export function CodexSubscriptionHub() {
Sign in with ChatGPT
</button>
</span>
- <span
- title={editing ? undefined : 'Please confirm the name first'}
- className="cu-hover-hint"
- >
- <button
- type="button"
- className="cu-btn cu-btn--ghost cu-btn--sm"
- onClick={() => {
- if (editing) void handleSync(editing)
- }}
- disabled={Boolean(busyKey) || !editing || editing.status !== 'connected'}
- >
- Sync catalog
- </button>
- </span>
</div>
{userCode ? (
<div className="cu-device-setup" data-testid="codex-device-code">
<p className="cu-device-setup__step">
- {deviceTabBlocked
- ? '1. Your browser blocked the pop-up — open ChatGPT with this link:'
- : '1. ChatGPT opened in a new tab. If it did not, use this link:'}
+ 1. Open the ChatGPT verification page:
</p>
{(() => {
// Locked fallback (from dev): even if the backend
@@ -674,6 +622,7 @@ export function CodexSubscriptionHub() {
<div className="cu-copy-field">
<a
className="cu-readonly-field cu-copy-field__value cu-device-setup__link"
+ data-testid="codex-device-verification-link"
href={deviceUri}
target="_blank"
rel="noopener noreferrer"
@@ -702,9 +651,9 @@ export function CodexSubscriptionHub() {
<button
type="button"
className="cu-btn cu-btn--icon cu-btn--ghost"
- onClick={() => void copyDeviceValue(userCode, 'Device code', showToast)}
- aria-label="Copy device code"
- title="Copy device code"
+ onClick={() => void copyDeviceValue(userCode, 'Code', showToast)}
+ aria-label="Copy code"
+ title="Copy code"
>
<IconCopy width={14} height={14} />
</button>
diff --git a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
index 4fc506c41..20e3e4ae5 100644
--- a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
+++ b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
@@ -10,7 +10,6 @@ import {
pollCodexDevice,
revokeCodexSubscription,
startCodexDeviceConnect,
- syncCodexSubscriptionCatalog,
} from '@lib/codexSubscription'
import { CodexSubscriptionHub } from '../CodexSubscriptionHub'
import { ToastProvider } from '../Toast'
@@ -84,7 +83,7 @@ describe('CodexSubscriptionHub', () => {
vi.unstubAllGlobals()
})
- it('creates the subscription when the name is confirmed and unlocks the setup form', async () => {
+ it('creates the subscription when the name is confirmed and auto-starts sign-in', async () => {
vi.mocked(createCodexSubscriptionConnection).mockResolvedValue(
connection({
connectionKey: 'codex-bbb',
@@ -93,6 +92,17 @@ describe('CodexSubscriptionHub', () => {
defaultModel: null,
})
)
+ vi.mocked(startCodexDeviceConnect).mockResolvedValue({
+ userCode: 'ABCD-1234',
+ verificationUri: 'https://chatgpt.com/device',
+ intervalSeconds: 0.3,
+ state: 'state-1',
+ intent: 'connect',
+ })
+ vi.mocked(pollCodexDevice).mockResolvedValue({
+ status: 'connected',
+ connection: connection({ connectionKey: 'codex-bbb', displayName: 'New team' }),
+ })
vi.mocked(patchCodexSubscriptionConnection).mockResolvedValue(
connection({ connectionKey: 'codex-bbb', displayName: 'New team', defaultModel: null })
)
@@ -115,18 +125,23 @@ describe('CodexSubscriptionHub', () => {
'Please confirm the name first'
)
- // Confirming the name creates the grant and unlocks the flow.
+ // Confirming the name creates the grant and starts the device sign-in.
fireEvent.change(nameInput, { target: { value: 'New team' } })
fireEvent.click(screen.getByRole('button', { name: 'Confirm name' }))
await waitFor(() => {
expect(createCodexSubscriptionConnection).toHaveBeenCalledWith({ displayName: 'New team' })
})
- const unlockedSignIn = await screen.findByRole('button', { name: 'Sign in with ChatGPT' })
- expect(unlockedSignIn).toBeEnabled()
- expect(screen.getByRole('button', { name: 'Finish setup' })).toBeInTheDocument()
+ await waitFor(() => {
+ expect(startCodexDeviceConnect).toHaveBeenCalledWith('connect', 'codex-bbb')
+ })
expect(screen.getByTitle('Name confirmed')).toBeInTheDocument()
-
- fireEvent.click(screen.getByRole('button', { name: 'Finish setup' }))
+ // Once the device flow settles the dialog keeps the setup form with the
+ // models synced by the connect handshake.
+ await waitFor(() => {
+ expect(listCodexConnectionModels).toHaveBeenCalledWith('codex-bbb')
+ })
+ const finish = await screen.findByRole('button', { name: 'Finish setup' })
+ fireEvent.click(finish)
await waitFor(() => {
expect(patchCodexSubscriptionConnection).toHaveBeenCalledWith('codex-bbb', {
displayName: 'New team',
@@ -160,20 +175,13 @@ describe('CodexSubscriptionHub', () => {
expect(screen.getByRole('menuitem', { name: 'Delete' })).toBeInTheDocument()
})
- it('opens the grant modal for Sign in, Sync, and model toggles without binding hosts', async () => {
+ it('opens the grant modal for reconnect and model toggles without binding hosts', async () => {
vi.mocked(startCodexDeviceConnect).mockResolvedValue({
userCode: 'ABCD-1234',
verificationUri: 'https://chatgpt.com/device',
intervalSeconds: 1,
state: 'state-1',
- intent: 'connect',
- })
- vi.mocked(syncCodexSubscriptionCatalog).mockResolvedValue({
- outcome: 'ready',
- added: 1,
- refreshed: 0,
- staled: 0,
- connection: connection({ connectionKey: 'codex-aaa', displayName: 'Team A' }),
+ intent: 'reconnect',
})
vi.mocked(patchCodexCatalogModel).mockResolvedValue([
{ model: 'gpt-5.1', enabled: true, stale: false },
@@ -192,12 +200,9 @@ describe('CodexSubscriptionHub', () => {
)
fireEvent.click(await screen.findByRole('menuitem', { name: 'Update' }))
expect(await screen.findByRole('button', { name: 'Sign in with ChatGPT' })).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Sync catalog' })).toBeInTheDocument()
+ // The catalog syncs automatically during connect — no manual sync button.
+ expect(screen.queryByRole('button', { name: 'Sync catalog' })).not.toBeInTheDocument()
expect(listCodexConnectionModels).toHaveBeenCalledWith('codex-aaa')
- fireEvent.click(screen.getByRole('button', { name: 'Sync catalog' }))
- await waitFor(() => {
- expect(syncCodexSubscriptionCatalog).toHaveBeenCalledWith('codex-aaa')
- })
fireEvent.click(screen.getByLabelText('gpt-5.3-codex'))
await waitFor(() => {
expect(patchCodexCatalogModel).toHaveBeenCalledWith('codex-aaa', 'gpt-5.3-codex', true)
@@ -211,9 +216,7 @@ describe('CodexSubscriptionHub', () => {
})
})
- it('opens ChatGPT in a new tab and shows the device code with copy actions', async () => {
- const openMock = vi.fn(() => null)
- vi.stubGlobal('open', openMock)
+ it('shows the device code card with the verification link and copy actions', async () => {
vi.mocked(startCodexDeviceConnect).mockResolvedValue({
userCode: 'ABCD-1234',
verificationUri: 'https://chatgpt.com/device',
@@ -221,7 +224,7 @@ describe('CodexSubscriptionHub', () => {
// auto-dismiss waitFor completes comfortably inside its timeout.
intervalSeconds: 0.3,
state: 'state-1',
- intent: 'connect',
+ intent: 'reconnect',
})
vi.mocked(pollCodexDevice).mockResolvedValue({
status: 'connected',
@@ -239,17 +242,11 @@ describe('CodexSubscriptionHub', () => {
fireEvent.click(await screen.findByRole('button', { name: 'Sign in with ChatGPT' }))
const card = await screen.findByTestId('codex-device-code')
expect(card).toHaveTextContent('ABCD-1234')
- expect(openMock).toHaveBeenCalledWith(
- 'https://chatgpt.com/device',
- '_blank',
- 'noopener,noreferrer'
- )
- expect(screen.getByRole('link', { name: 'https://chatgpt.com/device' })).toHaveAttribute(
- 'target',
- '_blank'
- )
+ const link = screen.getByTestId('codex-device-verification-link')
+ expect(link).toHaveAttribute('href', 'https://chatgpt.com/device')
+ expect(link).toHaveAttribute('target', '_blank')
expect(screen.getByRole('button', { name: 'Copy sign-in link' })).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Copy device code' })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Copy code' })).toBeInTheDocument()
await waitFor(() => {
expect(screen.queryByTestId('codex-device-code')).not.toBeInTheDocument()
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index ecb75d0c5..97eabc9bc 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.478",
+ "version": "0.1.480",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.478",
+ "version": "0.1.480",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 79200bdfe..609de6926 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.479",
+ "version": "0.1.480",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",