Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
chore: merge dev codex connect-sync rework into branch setup dialog
Miguelon Peluchon1bf3089d51d4
diff --cc control-ui/components/CodexSubscriptionHub/index.tsxindex 89280543e,e089eb941..7287199e2--- a/control-ui/components/CodexSubscriptionHub/index.tsx+++ b/control-ui/components/CodexSubscriptionHub/index.tsx@@@ -1,8 -1,8 +1,9 @@@'use client'- import React, { useCallback, useEffect, useMemo, useState } from 'react'+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { copyTextToClipboard } from '@lib/clipboard'import {++ CODEX_DEVICE_VERIFICATION_URI,type CodexSubscriptionConnectionView,createCodexSubscriptionConnection,listCodexConnectionModels,@@@ -76,9 -57,7 +77,13 @@@ 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.+ const connectEpoch = useRef(0)const enabled = isCodexSubscriptionUiEnabled(capability)useEffect(() => {@@@ -145,20 -137,10 +156,21 @@@}}+ function beginCreate() {+ setCreating(true)+ setEditing(null)+ setEditName('')+ setEditDefault('')+ setEditModels([])+ setSetupNew(false)+ setUserCode(null)+ setVerificationUri(null)+ setDeviceTabBlocked(false)+ setError('')+ }+async function openEdit(row: CodexSubscriptionConnectionView) {+ connectEpoch.current += 1- setBusyKey(null)- setDeviceConnecting(false)setEditing(row)setEditName(grantLabel(row))setEditDefault(row.defaultModel ?? '')@@@ -181,14 -161,18 +193,18 @@@}function closeEdit() {+ connectEpoch.current += 1- setBusyKey(null)- setDeviceConnecting(false)setEditing(null)setEditName('')setEditDefault('')setEditModels([])+ setSetupNew(false)setUserCode(null)setVerificationUri(null)+ setDeviceTabBlocked(false)+ void load().catch(err => {+ setError(err instanceof Error ? err.message : 'Failed to load ChatGPT subscriptions')+ })}async function handleSaveEdit() {@@@ -219,25 -194,18 +235,28 @@@}}- async function startDeviceConnect(row: CodexSubscriptionConnectionView) {+ async function handleConnect(row: CodexSubscriptionConnectionView) {+ const epoch = ++connectEpoch.currentsetBusyKey(row.connectionKey)- setDeviceConnecting(true)try {const started = await startCodexDeviceConnect(row.status === 'connected' ? 'reconnect' : 'connect',row.connectionKey)+ if (epoch !== connectEpoch.current) returnsetUserCode(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 * 40while (Date.now() < deadline) {await new Promise(resolve => setTimeout(resolve, started.intervalSeconds * 1000))@@@ -248,8 -218,17 +269,18 @@@const latest = polled.connectionsetEditing(latest)const models = await listCodexConnectionModels(latest.connectionKey)+ if (epoch !== connectEpoch.current) returnsetEditModels(models)await load()+ if (epoch !== connectEpoch.current) return++ // The backend syncs the catalog during connect — surface the outcome.+ if (latest.catalogStatus === 'ready') {+ showToast('Connected — catalog synced', { tone: 'success' })+ } else {+ showToast('Connected, but catalog sync failed. Sign in again to retry.', {+ tone: 'error',+ })+ }return}if (polled.status === 'expired' || polled.status === 'denied') {@@@ -267,7 -248,10 +300,9 @@@setVerificationUri(null)setError(err instanceof Error ? err.message : 'ChatGPT sign-in failed')} finally {- setBusyKey(null)+ if (epoch === connectEpoch.current) {+ setBusyKey(null)- setDeviceConnecting(false)+ }}}@@@ -536,261 -553,97 +571,266 @@@<IconX width={18} height={18} /></button></div>- <div className="cu-form-stack" style={{ maxWidth: '100%' }}>+ <div className="cu-form-stack cu-form-stack--wide" style={{ maxWidth: '100%' }}>{error ? <div className="cu-banner cu-banner--error">{error}</div> : null}<div className="cu-field">- <label htmlFor="codex-edit-name">Name</label>- <input- id="codex-edit-name"- value={editName}- onChange={e => setEditName(e.target.value)}- disabled={Boolean(busyKey)}- />- </div>- <div className="cu-field">- <span className="cu-field__label">Status</span>- <span className={statusTagClass(uiStatus)}>{statusLabel(uiStatus)}</span>- </div>- <div>- <button- type="button"- className="cu-btn cu-btn--ghost cu-btn--sm"- onClick={() => void startDeviceConnect(editing)}- disabled={Boolean(busyKey)}- >- Sign in with ChatGPT- </button>- </div>- {userCode ? (- <div className="cu-codex-device-code" role="status">- <p className="cu-field__hint">- Enter this code at{' '}- {verificationUri ? (- <a- className="cu-link"- data-testid="codex-device-verification-link"- href={verificationUri}- target="_blank"- rel="noopener noreferrer"- >- {verificationUri}- </a>- ) : (- 'the ChatGPT verification page'- )}- </p>- <div className="cu-codex-device-code__row">- <code data-testid="codex-device-code" className="cu-codex-device-code__value">- {userCode}- </code>+ <label htmlFor="codex-sub-name">Name</label>+ <div className="cu-copy-field">+ <input+ id="codex-sub-name"+ value={editName}+ onChange={e => setEditName(e.target.value)}+ disabled={Boolean(busyKey) || Boolean(creating && editing)}+ placeholder="The name agents see when they pick this subscription"+ />+ {creating && editing ? (+ <span+ className="cu-name-check cu-name-check--confirmed"+ title="Name confirmed"+ aria-label="Name confirmed"+ >+ <IconCheck width={16} height={16} />+ </span>+ ) : (<buttontype="button"- className="cu-btn cu-btn--ghost cu-btn--sm"- onClick={() => void handleCopyUserCode()}- aria-label="Copy code"+ className="cu-btn cu-btn--icon cu-btn--ghost"+ onClick={() => void confirmNameAndCreate()}+ disabled={!editName.trim() || Boolean(busyKey)}+ aria-label="Confirm name"+ title="Confirm name">- <IconCopy width={15} height={15} />- Copy+ <IconCheck width={16} height={16} /></button>- </div>+ )}</div>- ) : null}- <div className="cu-field">- <label htmlFor="codex-edit-default">Default model</label>- <SelectionDropdown- id="codex-edit-default"- value={editDefault ? [editDefault] : []}- options={offeredDefaults.map(model => ({- value: model,- label: model,- icon: <LlmProviderIcon provider="codex-subscription" label={model} />,- }))}- placeholder={offeredDefaults.length === 0 ? 'No enabled models' : 'Select model…'}- searchPlaceholder="Search models…"- selectionLabel="model"- multiple={false}- showSelectedChips={false}- disabled={Boolean(busyKey) || offeredDefaults.length === 0}- onChange={next => setEditDefault(next[0] ?? '')}- />+ <span className="cu-field__hint">+ {creating && editing+ ? 'Name confirmed — the subscription exists. Sign in and pick models to finish.'+ : 'Confirm the name to create the subscription and unlock sign-in.'}+ </span></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+ default to finish setup.+ </p>+ ) : null}+ <section className="cu-llm-config" aria-label="Subscription configuration">+ <div className="cu-llm-config__block">+ <div className="cu-llm-config__block-head">+ <span className="cu-llm-config__block-title">ChatGPT sign-in</span>+ <span className={statusTagClass(uiStatus)}>{statusLabel(uiStatus)}</span>+ </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.'}+ </p>+ <div className="cu-form-inline">+ <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 handleConnect(editing)+ }}+ disabled={Boolean(busyKey) || !editing}+ >+ 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:'}+ </p>- {verificationUri ? (- <div className="cu-copy-field">- <a- className="cu-readonly-field cu-copy-field__value cu-device-setup__link"- href={verificationUri}- target="_blank"- rel="noopener noreferrer"- >- {verificationUri}- </a>- <button- type="button"- className="cu-btn cu-btn--icon cu-btn--ghost"- onClick={() =>- void copyDeviceValue(verificationUri, 'Sign-in link', showToast)- }- aria-label="Copy sign-in link"- title="Copy sign-in link"- >- <IconCopy width={14} height={14} />- </button>- </div>- ) : null}++ {(() => {++ // Locked fallback (from dev): even if the backend++ // omits the verification URI, the card keeps a link.++ const deviceUri = verificationUri ?? CODEX_DEVICE_VERIFICATION_URI++ return (++ <div className="cu-copy-field">++ <a++ className="cu-readonly-field cu-copy-field__value cu-device-setup__link"++ href={deviceUri}++ target="_blank"++ rel="noopener noreferrer"++ >++ {deviceUri}++ </a>++ <button++ type="button"++ className="cu-btn cu-btn--icon cu-btn--ghost"++ onClick={() =>++ void copyDeviceValue(deviceUri, 'Sign-in link', showToast)++ }++ aria-label="Copy sign-in link"++ title="Copy sign-in link"++ >++ <IconCopy width={14} height={14} />++ </button>++ </div>++ )++ })()}+ <p className="cu-device-setup__step">2. Enter this code:</p>+ <div className="cu-copy-field">+ <div className="cu-readonly-field cu-copy-field__value cu-device-setup__code">+ {userCode}+ </div>+ <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"+ >+ <IconCopy width={14} height={14} />+ </button>+ </div>+ <p className="cu-device-setup__note" role="status">+ Checking automatically — this dialog continues as soon as you approve the+ code in ChatGPT.+ </p>+ </div>+ ) : null}+ </div>+ {editModels.length > 0 || setupNew ? (+ <div className="cu-llm-config__block">+ <div className="cu-llm-config__block-head">+ <span className="cu-llm-config__block-title">Enabled models</span>+ {editModels.length > 0 ? (+ <span className="cu-llm-config__block-tag cu-llm-config__block-tag--muted">+ {editModels.filter(model => model.enabled && !model.stale).length} of{' '}+ {editModels.length} enabled+ </span>+ ) : null}+ </div>+ {editModels.length > 0 ? (+ <div className="cu-llm-config__model-row">+ {editModels.map(model => (+ <CheckboxField+ key={model.model}+ checked={model.enabled}+ disabled={Boolean(busyKey) || model.stale}+ label={+ <span className="cu-px-provider">+ <LlmProviderIcon+ provider="codex-subscription"+ label={model.model}+ />+ {model.model}+ </span>+ }+ description={+ model.stale ? 'No longer in the ChatGPT catalog.' : undefined+ }+ onChange={e =>+ editing+ ? void handleToggleModel(editing, model.model, e.target.checked)+ : undefined+ }+ />+ ))}+ </div>+ ) : (+ <p className="cu-field__hint" style={{ margin: 0 }}>+ No models yet — confirm the name, sign in with ChatGPT, and sync the catalog+ to load the models this grant offers.+ </p>+ )}+ <span className="cu-field__hint">+ Synced from the ChatGPT catalog. Disabled models are not offered to agents.+ </span>+ </div>+ ) : null}+ <div className="cu-llm-config__block">+ <div className="cu-llm-config__block-head">+ <span className="cu-llm-config__block-title">Primary model</span>+ <span className="cu-llm-config__block-tag cu-llm-config__block-tag--muted">+ Optional+ </span>+ </div>+ <div className="cu-field">+ <label htmlFor="codex-edit-default">Default model</label>+ <SelectionDropdown+ id="codex-edit-default"+ value={editDefault ? [editDefault] : []}+ options={offeredDefaults.map(model => ({+ value: model,+ label: model,+ icon: <LlmProviderIcon provider="codex-subscription" label={model} />,+ }))}+ placeholder={+ offeredDefaults.length === 0 ? 'No enabled models' : 'Select model…'+ }+ searchPlaceholder="Search models…"+ selectionLabel="model"+ multiple={false}+ showSelectedChips={false}+ disabled={Boolean(busyKey) || !editing || offeredDefaults.length === 0}+ onChange={next => setEditDefault(next[0] ?? '')}+ />+ <span className="cu-field__hint">+ Preselected for new chats; agents can pick any enabled model.+ </span>+ </div>+ </div>+ </section></div><div className="cu-modal-panel__foot">- <button type="button" className="cu-btn cu-btn--ghost cu-btn--sm" onClick={closeEdit}>- Cancel- </button><buttontype="button"- className="cu-btn cu-btn--primary"- onClick={() => void handleSaveEdit()}+ className="cu-btn cu-btn--ghost cu-btn--sm"+ onClick={() => {+ setCreating(false)+ closeEdit()+ }}disabled={Boolean(busyKey)}>- {busyKey && !deviceConnecting ? 'Saving…' : 'Update subscription'}+ {creating && editing && setupNew ? 'Finish later' : 'Cancel'}</button>+ {editing ? (+ <button+ type="button"+ className="cu-btn cu-btn--primary"+ onClick={() => void handleSaveEdit()}+ disabled={Boolean(busyKey)}+ >+ {busyKey ? 'Saving…' : setupNew ? 'Finish setup' : 'Update subscription'}+ </button>+ ) : (+ <button+ type="button"+ className="cu-btn cu-btn--primary"+ onClick={() => void confirmNameAndCreate()}+ disabled={!editName.trim() || Boolean(busyKey)}+ title={editName.trim() ? undefined : 'Please confirm the name first'}+ >+ {busyKey === 'create' ? 'Creating…' : 'Create and set up'}+ </button>+ )}</div></div></div>diff --cc control-ui/lib/codexSubscription.tsindex 4ff61bc91,5fb0cdff7..3ef5c69cd--- a/control-ui/lib/codexSubscription.ts+++ b/control-ui/lib/codexSubscription.ts@@@ -2,12 -2,15 +2,11 @@@ import { apiGet, apiSend } from './apiexport const CODEX_SUBSCRIPTION_API_BASE = '/api/v1/admin/llm/providers/codex-subscription'+ /** Canonical ChatGPT device verification page. Reject any other href from device/start. */+ export const CODEX_DEVICE_VERIFICATION_URI = 'https://auth.openai.com/codex/device'+export type CodexConnectionStatus =-- | 'disconnected'-- | 'connecting'-- | 'connected'-- | 'reauth_required'-- | 'revoked'++ 'disconnected' | 'connecting' | 'connected' | 'reauth_required' | 'revoked'export type CodexCatalogStatus = 'never_synced' | 'ready' | 'auth-rejected' | 'unavailable'