Skip to content

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

TypeScript

feat: open Add subscription with a live draft and full setup form

Miguelon Peluchonb428b23b2aa0
diff --git a/control-ui/components/CodexSubscriptionHub/index.tsx b/control-ui/components/CodexSubscriptionHub/index.tsx
index 7f9356a21..2fd5bbed5 100644
--- a/control-ui/components/CodexSubscriptionHub/index.tsx
+++ b/control-ui/components/CodexSubscriptionHub/index.tsx
@@ -64,7 +64,6 @@ export function CodexSubscriptionHub() {
const [searchQuery, setSearchQuery] = useState('')
const [busyKey, setBusyKey] = useState<string | null>(null)
const [creating, setCreating] = useState(false)
- const [createName, setCreateName] = useState('')
const [editing, setEditing] = useState<CodexSubscriptionConnectionView | null>(null)
const [editName, setEditName] = useState('')
const [editDefault, setEditDefault] = useState('')
@@ -122,25 +121,18 @@ export function CodexSubscriptionHub() {
)
}, [connections, searchQuery])
- async function handleCreate() {
- const displayName = createName.trim()
- if (!displayName) {
- setError('Subscription name is required.')
- return
- }
+ // Opening the Add dialog immediately creates a backend draft grant so the
+ // FULL setup form (name, sign-in, models, default) is live right away — no
+ // name-only gate. If the operator cancels without signing in, the pristine
+ // draft is revoked again so no empty rows linger in the table.
+ async function createDraft() {
setBusyKey('create')
+ setError('')
try {
- const created = await createCodexSubscriptionConnection({ displayName })
- setCreateName('')
- setError('')
- // Transition the SAME modal into setup — openEdit sets the editing state
- // before creating flips off, so the dialog never unmounts in between and
- // the name field the operator just typed into stays mounted.
- await openEdit(created)
+ const created = await createCodexSubscriptionConnection({ displayName: '' })
+ openEdit(created)
setSetupNew(true)
- setCreating(false)
- await load()
- showToast(`Subscription ${displayName} created.`, { tone: 'success' })
+ setEditName('')
} catch (err) {
setError(err instanceof Error ? err.message : 'Could not create subscription')
} finally {
@@ -148,6 +140,35 @@ export function CodexSubscriptionHub() {
}
}
+ function beginCreate() {
+ setCreating(true)
+ setEditing(null)
+ setEditName('')
+ setEditDefault('')
+ setEditModels([])
+ setSetupNew(false)
+ setUserCode(null)
+ setVerificationUri(null)
+ setDeviceTabBlocked(false)
+ setError('')
+ void createDraft()
+ }
+
+ // Cancel in create mode. A pristine draft (never signed in) is removed again;
+ // once the operator signed in the grant is real and is kept.
+ function cancelCreate() {
+ const draftRow = editing
+ const revokePristine = Boolean(draftRow && draftRow.status === 'disconnected')
+ setCreating(false)
+ closeEdit()
+ if (revokePristine && draftRow) {
+ void revokeCodexSubscription(draftRow.connectionKey)
+ .catch(() => {})
+ .then(() => load())
+ .catch(() => {})
+ }
+ }
+
async function openEdit(row: CodexSubscriptionConnectionView) {
setEditing(row)
setEditName(grantLabel(row))
@@ -183,6 +204,10 @@ export function CodexSubscriptionHub() {
async function handleSaveEdit() {
if (!editing) return
+ if (setupNew && !editName.trim()) {
+ setError('Give the subscription a name before finishing.')
+ return
+ }
setBusyKey(editing.connectionKey)
try {
const updated = await patchCodexSubscriptionConnection(editing.connectionKey, {
@@ -379,9 +404,7 @@ export function CodexSubscriptionHub() {
type="button"
className="cu-btn cu-btn--primary cu-btn--sm"
onClick={() => {
- setCreating(true)
- setCreateName('')
- setError('')
+ beginCreate()
}}
disabled={initialLoad}
>
@@ -490,7 +513,7 @@ export function CodexSubscriptionHub() {
role="presentation"
onClick={e => {
if (e.target === e.currentTarget && !busyKey) {
- if (creating) setCreating(false)
+ if (creating) cancelCreate()
else closeEdit()
}
}}
@@ -516,7 +539,7 @@ export function CodexSubscriptionHub() {
type="button"
className="cu-btn cu-btn--icon cu-btn--ghost"
onClick={() => {
- if (creating) setCreating(false)
+ if (creating) cancelCreate()
else closeEdit()
}}
disabled={Boolean(busyKey)}
@@ -531,26 +554,34 @@ export function CodexSubscriptionHub() {
<label htmlFor="codex-sub-name">Name</label>
<input
id="codex-sub-name"
- value={creating ? createName : editName}
- onChange={e => (creating ? setCreateName : setEditName)(e.target.value)}
+ value={editName}
+ onChange={e => setEditName(e.target.value)}
disabled={Boolean(busyKey)}
+ placeholder="The name agents see when they pick this subscription"
/>
- {creating ? (
- <span className="cu-field__hint">
- The name agents see when they pick this subscription.
- </span>
- ) : null}
</div>
- {creating ? (
+ {creating && !editing ? (
<div className="cu-modal-steps">
- <span className="cu-modal-steps__title">What happens next</span>
+ <span className="cu-modal-steps__title">
+ {busyKey === 'create'
+ ? 'Creating your subscription…'
+ : 'Could not create the subscription.'}
+ </span>
<ol className="cu-modal-steps__list">
- <li>Create the subscription with this name.</li>
<li>
Sign in with ChatGPT — ChatGPT opens in a new tab and you enter a device code.
</li>
<li>Pick the models to offer and choose a default.</li>
</ol>
+ {busyKey !== 'create' ? (
+ <button
+ type="button"
+ className="cu-btn cu-btn--ghost cu-btn--sm"
+ onClick={() => void createDraft()}
+ >
+ Try again
+ </button>
+ ) : null}
</div>
) : editing ? (
<>
@@ -723,23 +754,24 @@ export function CodexSubscriptionHub() {
type="button"
className="cu-btn cu-btn--ghost cu-btn--sm"
onClick={() => {
- if (creating) setCreating(false)
- else closeEdit()
+ if (creating) {
+ // "Finish later" keeps the draft (the operator already
+ // signed in or configured it); Cancel removes a pristine one.
+ if (editing && setupNew) {
+ setCreating(false)
+ closeEdit()
+ } else {
+ cancelCreate()
+ }
+ } else {
+ closeEdit()
+ }
}}
disabled={Boolean(busyKey)}
>
- {creating || !setupNew ? 'Cancel' : 'Finish later'}
+ {creating && editing && setupNew ? 'Finish later' : 'Cancel'}
</button>
- {creating ? (
- <button
- type="button"
- className="cu-btn cu-btn--primary"
- onClick={() => void handleCreate()}
- disabled={busyKey === 'create'}
- >
- {busyKey === 'create' ? 'Creating…' : 'Create and set up'}
- </button>
- ) : (
+ {editing ? (
<button
type="button"
className="cu-btn cu-btn--primary"
@@ -748,7 +780,7 @@ export function CodexSubscriptionHub() {
>
{busyKey ? 'Saving…' : setupNew ? 'Finish setup' : 'Update subscription'}
</button>
- )}
+ ) : null}
</div>
</div>
</div>
diff --git a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
index 88d5c7756..6456d8d4a 100644
--- a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
+++ b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
@@ -84,9 +84,16 @@ describe('CodexSubscriptionHub', () => {
vi.unstubAllGlobals()
})
- it('creates a subscription from the Add modal and continues into setup', async () => {
+ it('opens Add with a draft grant and the full setup form, and finishes with the typed name', async () => {
vi.mocked(createCodexSubscriptionConnection).mockResolvedValue(
- connection({ connectionKey: 'codex-bbb', displayName: 'New team' })
+ connection({
+ connectionKey: 'codex-bbb',
+ displayName: 'Codex subscription',
+ defaultModel: null,
+ })
+ )
+ vi.mocked(patchCodexSubscriptionConnection).mockResolvedValue(
+ connection({ connectionKey: 'codex-bbb', displayName: 'New team', defaultModel: null })
)
render(
<ToastProvider>
@@ -95,17 +102,49 @@ describe('CodexSubscriptionHub', () => {
)
expect(await screen.findByText('Team A')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'Add subscription' }))
- fireEvent.change(screen.getByRole('textbox', { name: 'Name' }), {
- target: { value: 'New team' },
- })
- fireEvent.click(screen.getByRole('button', { name: 'Create and set up' }))
+ const nameInput = await screen.findByRole('textbox', { name: 'Name' })
+ fireEvent.change(nameInput, { target: { value: 'New team' } })
+ expect(await screen.findByRole('button', { name: 'Finish setup' })).toBeInTheDocument()
+ expect(createCodexSubscriptionConnection).toHaveBeenCalledWith({ displayName: '' })
+ expect(screen.getByRole('button', { name: 'Sign in with ChatGPT' })).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Finish setup' }))
await waitFor(() => {
- expect(createCodexSubscriptionConnection).toHaveBeenCalledWith({ displayName: 'New team' })
+ expect(patchCodexSubscriptionConnection).toHaveBeenCalledWith('codex-bbb', {
+ displayName: 'New team',
+ defaultModel: null,
+ })
})
expect(revokeCodexSubscription).not.toHaveBeenCalled()
- expect(await screen.findByText('Set up ChatGPT subscription New team')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Sign in with ChatGPT' })).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Finish setup' })).toBeInTheDocument()
+ })
+
+ it('revokes the pristine draft when the Add dialog is cancelled', async () => {
+ vi.mocked(createCodexSubscriptionConnection).mockResolvedValue(
+ connection({
+ connectionKey: 'codex-ccc',
+ displayName: 'Codex subscription',
+ defaultModel: null,
+ status: 'disconnected',
+ })
+ )
+ vi.mocked(revokeCodexSubscription).mockResolvedValue(
+ connection({
+ connectionKey: 'codex-ccc',
+ displayName: 'Codex subscription',
+ status: 'revoked',
+ })
+ )
+ render(
+ <ToastProvider>
+ <CodexSubscriptionHub />
+ </ToastProvider>
+ )
+ expect(await screen.findByText('Team A')).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Add subscription' }))
+ await screen.findByRole('button', { name: 'Finish setup' })
+ fireEvent.click(screen.getByRole('button', { name: 'Close' }))
+ await waitFor(() => {
+ expect(revokeCodexSubscription).toHaveBeenCalledWith('codex-ccc')
+ })
})
it('renders subscriptions as a Secrets table with a row actions menu', async () => {
@@ -189,7 +228,9 @@ describe('CodexSubscriptionHub', () => {
vi.mocked(startCodexDeviceConnect).mockResolvedValue({
userCode: 'ABCD-1234',
verificationUri: 'https://chatgpt.com/device',
- intervalSeconds: 0.01,
+ // Long enough that the card is observable; short enough that the
+ // auto-dismiss waitFor completes comfortably inside its timeout.
+ intervalSeconds: 0.3,
state: 'state-1',
intent: 'connect',
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 41ee6ede4..4fd4e58c3 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.481",
+ "version": "0.1.482",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.481",
+ "version": "0.1.482",
"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 c01e8feb6..08689fd75 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.481",
+ "version": "0.1.482",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",