Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-ui): render the auto-claim connecting state and distinct registration errors
Jose Ramirez10bb10045b9e
diff --git a/control-ui/components/RegistryConnectPanel.tsx b/control-ui/components/RegistryConnectPanel.tsxindex b78597b58..747bb90d9 100644--- a/control-ui/components/RegistryConnectPanel.tsx+++ b/control-ui/components/RegistryConnectPanel.tsx@@ -2,8 +2,10 @@import { useCallback, useEffect, useState } from 'react'import {+ type RegistryRecoveryError,disconnectRegistryConnection,getRegistryConnection,+ recoverRegistryConnection,requestRegistryConnection,submitRegistryClaim,} from '../lib/api'@@ -16,6 +18,13 @@ type View =| { kind: 'loading' }| { kind: 'request' }| { kind: 'pending'; deploymentId?: string; requestedOrgName?: string }+ | {+ kind: 'connecting'+ deploymentId?: string+ requestedOrgName?: string+ authEnabled?: boolean+ recoveryError?: RegistryRecoveryError+ }| { kind: 'approved'; deploymentId?: string; requestedOrgName?: string }| { kind: 'rejected'; requestedOrgName?: string }| { kind: 'connected'; org?: string; authEnabled?: boolean }@@ -34,15 +43,28 @@ export default function RegistryConnectPanel() {const [busy, setBusy] = useState(false)const [formError, setFormError] = useState<string | null>(null)- // GET returns one of five states (registryConnect.ts): disconnected | pending |- // approved | rejected | connected. The reducer maps each to exactly one View —- // `approved` (not `pending`) carries the claim-entry form, because A1's claim- // token only becomes redeemable once the registry poll flips pending → approved.+ // GET returns one of six states (registryConnect.ts): disconnected | pending |+ // connecting | approved | rejected | connected. The reducer maps each to+ // exactly one View. `connecting` means the registry auto-approved the request+ // and the inline claim did not land yet — it is finished by pressing "Finish+ // connecting" (handleRecover), never by pasting a token; under auto-approval no+ // operator ever issues one. `approved` keeps its original meaning: an operator+ // approved and a human must paste the token they were given out of band —+ // A1's claim token only becomes redeemable once the registry poll flips+ // pending → approved.const load = useCallback(async () => {try {const s = await getRegistryConnection()if (s.state === 'connected')setView({ kind: 'connected', org: s.org, authEnabled: s.authEnabled })+ else if (s.state === 'connecting')+ setView({+ kind: 'connecting',+ deploymentId: s.deploymentId,+ requestedOrgName: s.requestedOrgName,+ authEnabled: s.authEnabled,+ recoveryError: s.recoveryError,+ })else if (s.state === 'approved')setView({kind: 'approved',@@ -57,7 +79,16 @@ export default function RegistryConnectPanel() {deploymentId: s.deploymentId,requestedOrgName: s.requestedOrgName,})- else setView({ kind: 'request' }) // disconnected+ else if (s.state === 'disconnected') setView({ kind: 'request' })+ else {+ // Exhaustiveness guard. The old default was `{kind:'request'}`, which+ // renders the registration FORM for any unrecognised state — and+ // re-registering deletes the deployment keypair. A new state must be a+ // compile error here, never a data-loss path.+ const never: never = s.state+ void never+ setView({ kind: 'error' })+ }} catch (e) {const code = (e as { code?: string }).codeif (code === 'not_self_hosted') setView({ kind: 'not-self-hosted' })@@ -75,27 +106,64 @@ export default function RegistryConnectPanel() {setFormError('Organization name and contact email are required.')return}+ // The registry requires a dot-TLD (isValidContactEmail). Failing that check+ // server-side costs one of ~5 daily registration attempts per IP, so spend+ // it only on an address that can succeed.+ if (!/^[^\s@]{1,64}@[^\s@]{1,255}\.[^\s@.]{2,}$/.test(email.trim())) {+ setFormError('Enter a full contact email such as [email protected].')+ return+ }setBusy(true)try {const s = await requestRegistryConnection({requestedOrgName: orgName.trim(),contactEmail: email.trim(),})- // A fresh request always lands pending — the operator must approve it before- // the claim token is usable, so we go to the waiting view (not claim-entry).- setView({- kind: 'pending',- deploymentId: s.deploymentId,- requestedOrgName: s.requestedOrgName,- })- showToast('Registration requested — an Evenfire operator must approve it.', {- tone: 'success',- })+ // The request endpoint can now settle three ways: the registry auto-claims+ // the deployment inline (connected), auto-approves but the inline claim did+ // not land (connecting — finished via handleRecover), or an operator must+ // approve it by hand (pending, the original claim-token flow).+ if (s.state === 'connected') {+ setView({ kind: 'connected', org: s.org, authEnabled: s.authEnabled })+ showToast(`Connected to @${s.org}.`, { tone: 'success' })+ } else if (s.state === 'connecting') {+ setView({+ kind: 'connecting',+ deploymentId: s.deploymentId,+ requestedOrgName: s.requestedOrgName,+ authEnabled: s.authEnabled,+ })+ showToast('Registered — finishing the connection.', { tone: 'success' })+ } else {+ setView({+ kind: 'pending',+ deploymentId: s.deploymentId,+ requestedOrgName: s.requestedOrgName,+ })+ showToast('Registration requested — an Evenfire operator must approve it.', {+ tone: 'success',+ })+ }} catch (e) {const code = (e as { code?: string }).codeif (code === 'already_connected') await load()+ else if (code === 'recovery_in_progress') await load()else if (code === 'org_blocklisted')setFormError('That organization name is not available. Try a different one.')+ else if (code === 'org_name_taken')+ setFormError(+ 'That organization name is already taken. Try a different one. Registration attempts are limited to about 5 per day, so choose carefully.'+ )+ else if (code === 'registration_capacity')+ setFormError('The registry is not accepting new registrations right now. Try again later.')+ else if (code === 'rate_limited')+ setFormError('Too many registration attempts from this network. Try again tomorrow.')+ else if (code === 'invalid_contact_email')+ setFormError(+ 'That contact email is not a valid address. Use a full address such as [email protected].'+ )+ else if (code === 'jti_replayed')+ setFormError('That registration attempt could not be completed. Try again.')else setFormError('Could not request registration. Try again shortly.')} finally {setBusy(false)@@ -129,6 +197,38 @@ export default function RegistryConnectPanel() {}}+ // Finish an auto-approved connection whose inline claim failed. Explicit+ // user action: recovery rotates a claim token at the registry, so it must+ // never fire from a passive render.+ async function handleRecover() {+ setFormError(null)+ setBusy(true)+ try {+ const s = await recoverRegistryConnection()+ if (s.state === 'connected') {+ setView({ kind: 'connected', org: s.org, authEnabled: s.authEnabled })+ showToast(`Connected to @${s.org}.`, { tone: 'success' })+ } else {+ await load()+ setFormError('Still finishing the connection. Try again in a moment.')+ }+ } catch (e) {+ const code = (e as { code?: string }).code+ if (code === 'already_claimed' || code === 'connection_superseded')+ setFormError(+ 'This deployment can no longer authenticate: its one-time credentials were issued but never stored. Disconnect, then register again with a different organization name.'+ )+ else if (code === 'deployment_suspended')+ setFormError('This deployment has been suspended by Evenfire. Contact support.')+ else if (code === 'client_unavailable')+ setFormError('This deployment can no longer authenticate. Contact support.')+ else if (code === 'not_recoverable') await load()+ else setFormError('Could not finish connecting. Try again shortly.')+ } finally {+ setBusy(false)+ }+ }+// From the terminal `rejected` view: drop the dead request row (DELETE) so the// operator can submit a fresh one. Best-effort — land on the request form either way.async function handleStartOver() {@@ -145,6 +245,33 @@ export default function RegistryConnectPanel() {setView({ kind: 'request' })}+ // From the `connecting` view: with re-registration blocked server-side by+ // recovery_in_progress, this DELETE is now the ONLY remaining path that can+ // destroy a recoverable deployment — it deletes the keypair and permanently+ // squats the org name at the registry. Route it through the same confirm+ // dialog as handleDisconnect instead of a bare button.+ async function handleStartOverFromConnecting() {+ const ok = await confirm({+ title: 'Start over',+ message:+ 'Starting over deletes this deployment’s stored registry credentials. The organization name will be lost permanently and this deployment cannot be recovered afterwards — you would need to register again under a different name. This cannot be undone.',+ confirmLabel: 'Start over',+ tone: 'danger',+ })+ if (!ok) return+ setBusy(true)+ try {+ await disconnectRegistryConnection()+ } catch {+ /* best-effort — the next GET reports disconnected once the row is gone */+ } finally {+ setBusy(false)+ }+ setClaimToken('')+ setFormError(null)+ setView({ kind: 'request' })+ }+async function handleDisconnect() {const ok = await confirm({title: 'Disconnect from the Evenfire Registry',@@ -255,6 +382,54 @@ export default function RegistryConnectPanel() {</div>) : null}+ {view.kind === 'connecting' ? (+ <div className="cu-form-stack">+ <p className="cu-banner">+ Registration approved+ {view.requestedOrgName ? ` for @${view.requestedOrgName}` : ''}. Finishing the+ connection — no operator approval is needed.+ </p>+ {view.recoveryError === 'already_claimed' ||+ view.recoveryError === 'connection_superseded' ? (+ <p className="cu-banner cu-banner--warn">+ This deployment can no longer authenticate: its one-time credentials were issued+ but never stored. Disconnect, then register again with a different organization+ name.+ </p>+ ) : null}+ {view.recoveryError === 'deployment_suspended' ? (+ <p className="cu-banner cu-banner--warn">+ This deployment has been suspended by Evenfire. Contact support.+ </p>+ ) : null}+ {formError ? <p className="cu-banner cu-banner--warn">{formError}</p> : null}+ <div className="cu-form-inline">+ <Button+ type="button"+ variant="primary"+ size="sm"+ disabled={busy}+ onClick={() => void handleRecover()}+ >+ {busy ? 'Finishing…' : 'Finish connecting'}+ </Button>+ {/* Gated by confirm(), not a bare Disconnect: with re-registration+ blocked by recovery_in_progress, this is the only remaining path+ that can delete a recoverable deployment's keypair and squat its+ org name. */}+ <Button+ type="button"+ variant="ghost"+ size="sm"+ disabled={busy}+ onClick={() => void handleStartOverFromConnecting()}+ >+ Start over+ </Button>+ </div>+ </div>+ ) : null}+{view.kind === 'approved' ? (<div className="cu-form-stack"><p className="cu-banner cu-banner--ok">diff --git a/control-ui/components/__tests__/RegistryConnectPanel.test.tsx b/control-ui/components/__tests__/RegistryConnectPanel.test.tsxindex 5cc6c3d58..e19e47fab 100644--- a/control-ui/components/__tests__/RegistryConnectPanel.test.tsx+++ b/control-ui/components/__tests__/RegistryConnectPanel.test.tsx@@ -1,6 +1,7 @@// control-ui/components/__tests__/RegistryConnectPanel.test.tsximport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { cleanup, fireEvent, render as rtlRender, screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'import * as api from '../../lib/api'import * as ConfirmDialogModule from '../ConfirmDialog'import RegistryConnectPanel from '../RegistryConnectPanel'@@ -11,6 +12,7 @@ vi.mock('../../lib/api', () => ({requestRegistryConnection: vi.fn(),submitRegistryClaim: vi.fn(),disconnectRegistryConnection: vi.fn(),+ recoverRegistryConnection: vi.fn(),}))vi.mock('../ConfirmDialog', () => ({ useConfirmDialog: vi.fn() }))@@ -174,4 +176,209 @@ describe('RegistryConnectPanel', () => {)expect(screen.queryByText(/enable registry authentication/i)).toBeNull()})++ it('lands on the connected view when registration auto-claims', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({ state: 'disconnected' })+ vi.mocked(api.requestRegistryConnection).mockResolvedValue({+ state: 'connected',+ org: 'acme',+ authEnabled: true,+ })+ render(<RegistryConnectPanel />)+ await userEvent.type(await screen.findByLabelText(/organization/i), 'acme')+ await userEvent.type(screen.getByLabelText(/email/i), '[email protected]')+ await userEvent.click(screen.getByRole('button', { name: /request registration/i }))+ // Scoped to the banner text (not just "@acme") because the success toast also+ // renders "Connected to @acme." — a bare /@acme/ match would be ambiguous.+ expect(await screen.findByText(/Connected to the Evenfire Registry.*@acme/)).toBeInTheDocument()+ // The toast is a SEPARATE mutation from the view: branching the view but+ // leaving the toast unconditional tells a connected user to wait for an+ // operator who does not exist.+ expect(screen.queryByText(/must approve it/i)).toBeNull()+ })++ it('renders the connecting view with a finish button and no paste box', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ render(<RegistryConnectPanel />)+ expect(await screen.findByRole('button', { name: /finish connecting/i })).toBeInTheDocument()+ expect(screen.queryByLabelText(/claim token/i)).toBeNull()+ })++ // load()'s default arm renders the registration form. Shipping a new state+ // without a branch would show "Register this deployment" to an already-approved+ // deployment, and re-registering destroys its keypair.+ it('never renders the registration form for the connecting state', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ render(<RegistryConnectPanel />)+ await screen.findByRole('button', { name: /finish connecting/i })+ expect(screen.queryByRole('button', { name: /request registration/i })).toBeNull()+ })++ it('shows the terminal message when recovery is already claimed', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ recoveryError: 'already_claimed',+ })+ render(<RegistryConnectPanel />)+ expect(await screen.findByText(/can no longer authenticate/i)).toBeInTheDocument()+ })++ it('rejects a malformed contact email before calling the server', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({ state: 'disconnected' })+ render(<RegistryConnectPanel />)+ await userEvent.type(await screen.findByLabelText(/organization/i), 'acme')+ await userEvent.type(screen.getByLabelText(/email/i), 'not-an-email')+ await userEvent.click(screen.getByRole('button', { name: /request registration/i }))+ expect(await screen.findByText(/full contact email/i)).toBeInTheDocument()+ expect(api.requestRegistryConnection).not.toHaveBeenCalled()+ })++ // `recovery_in_progress` is deliberately NOT in this table: it re-syncs via+ // load() rather than setting form copy, so it needs its own mock and gets its+ // own test below.+ it.each([+ ['org_name_taken', /already taken/i],+ ['registration_capacity', /not accepting new registrations/i],+ ['rate_limited', /too many registration attempts/i],+ ['invalid_contact_email', /not a valid/i],+ // The registry maps some register conflicts to jti_replayed. Copy must read+ // as "could not complete", never surface "replay attack" to an operator.+ ['jti_replayed', /could not be completed/i],+ ])('renders distinct copy for %s', async (code, matcher) => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({ state: 'disconnected' })+ vi.mocked(api.requestRegistryConnection).mockRejectedValue(+ Object.assign(new Error('x'), { code })+ )+ render(<RegistryConnectPanel />)+ await userEvent.type(await screen.findByLabelText(/organization/i), 'acme')+ await userEvent.type(screen.getByLabelText(/email/i), '[email protected]')+ await userEvent.click(screen.getByRole('button', { name: /request registration/i }))+ expect(await screen.findByText(matcher)).toBeInTheDocument()+ })++ // control-api now sends a non-empty deployment_info, so these become reachable.+ // They share the generic fallback copy — the bar here is just "doesn't crash or+ // render blank".+ it.each(['invalid_deployment_info', 'deployment_info_too_large'])(+ 'falls back to the generic registration error for %s without crashing',+ async code => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({ state: 'disconnected' })+ vi.mocked(api.requestRegistryConnection).mockRejectedValue(+ Object.assign(new Error('x'), { code })+ )+ render(<RegistryConnectPanel />)+ await userEvent.type(await screen.findByLabelText(/organization/i), 'acme')+ await userEvent.type(screen.getByLabelText(/email/i), '[email protected]')+ await userEvent.click(screen.getByRole('button', { name: /request registration/i }))+ expect(+ await screen.findByText(/Could not request registration\. Try again shortly\./i)+ ).toBeInTheDocument()+ }+ )++ it('re-syncs to the connecting view when a re-request is refused', async () => {+ vi.mocked(api.getRegistryConnection)+ .mockResolvedValueOnce({ state: 'disconnected' })+ .mockResolvedValue({ state: 'connecting', deploymentId: 'dep-1', requestedOrgName: 'acme' })+ vi.mocked(api.requestRegistryConnection).mockRejectedValue(+ Object.assign(new Error('x'), { code: 'recovery_in_progress' })+ )+ render(<RegistryConnectPanel />)+ await userEvent.type(await screen.findByLabelText(/organization/i), 'acme')+ await userEvent.type(screen.getByLabelText(/email/i), '[email protected]')+ await userEvent.click(screen.getByRole('button', { name: /request registration/i }))+ expect(await screen.findByRole('button', { name: /finish connecting/i })).toBeInTheDocument()+ })++ it('completes the connection via the recover button', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ vi.mocked(api.recoverRegistryConnection).mockResolvedValue({+ state: 'connected',+ org: 'acme',+ authEnabled: true,+ })+ render(<RegistryConnectPanel />)+ await userEvent.click(await screen.findByRole('button', { name: /finish connecting/i }))+ expect(await screen.findByText(/Connected to the Evenfire Registry.*@acme/)).toBeInTheDocument()+ })++ it('shows a retry message when recovery is not yet finished', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ vi.mocked(api.recoverRegistryConnection).mockRejectedValue(+ Object.assign(new Error('x'), { code: 'client_unavailable' })+ )+ render(<RegistryConnectPanel />)+ await userEvent.click(await screen.findByRole('button', { name: /finish connecting/i }))+ expect(+ await screen.findByText(/can no longer authenticate. Contact support/i)+ ).toBeInTheDocument()+ })++ // --- Addition: Disconnect/Start over on the `connecting` view must be gated by+ // confirm(), because it is now the only remaining path that can delete a+ // recoverable deployment's keypair and permanently squat its org name.+ it('start over on the connecting view requires confirmation before disconnecting', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ const confirmMock = vi.fn().mockResolvedValue(true)+ vi.mocked(ConfirmDialogModule.useConfirmDialog).mockReturnValue({+ confirm: confirmMock,+ confirmDialog: null,+ })+ render(<RegistryConnectPanel />)+ await userEvent.click(await screen.findByRole('button', { name: /start over/i }))+ expect(confirmMock).toHaveBeenCalledTimes(1)+ const message = confirmMock.mock.calls[0]?.[0]?.message as string+ expect(message).toMatch(/lost permanently/i)+ expect(message).toMatch(/cannot be recovered/i)+ await waitFor(() => expect(api.disconnectRegistryConnection).toHaveBeenCalledTimes(1))+ })++ it('does not disconnect the connecting view when Start over is cancelled', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ vi.mocked(ConfirmDialogModule.useConfirmDialog).mockReturnValue({+ confirm: vi.fn().mockResolvedValue(false),+ confirmDialog: null,+ })+ render(<RegistryConnectPanel />)+ await userEvent.click(await screen.findByRole('button', { name: /start over/i }))+ expect(api.disconnectRegistryConnection).not.toHaveBeenCalled()+ expect(screen.getByRole('button', { name: /finish connecting/i })).toBeInTheDocument()+ })++ it('does not render a bare Disconnect button on the connecting view', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ render(<RegistryConnectPanel />)+ await screen.findByRole('button', { name: /finish connecting/i })+ expect(screen.queryByRole('button', { name: /^disconnect$/i })).toBeNull()+ })})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 3ae5053ab..e929212db 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.353",+ "version": "0.1.354","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.353",+ "version": "0.1.354","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 836023b36..276e86133 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.353",+ "version": "0.1.354","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",