Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat: auto-open ChatGPT sign-in tab with device code card
Miguelon Peluchon5bd950a49cd0
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.cssindex 0b0c8eabf..fcabe3ecb 100644--- a/control-ui/app/globals.css+++ b/control-ui/app/globals.css@@ -8583,6 +8583,40 @@ textarea.cu-input {margin: 0;}+/* ChatGPT device sign-in card shown while the subscription modal waits for the+ operator to approve the device code in the auto-opened ChatGPT tab. */+.cu-device-setup {+ display: grid;+ gap: var(--cu-space-2);+ padding: var(--cu-space-3) var(--cu-space-4);+ border: 1px solid var(--cu-border-subtle);+ border-radius: var(--cu-radius-sm);+ background: var(--cu-bg-elevated);+}++.cu-device-setup__step {+ margin: 0;+ color: var(--cu-text-soft);+ font-size: 0.8125rem;+}++.cu-device-setup__link {+ color: var(--cu-accent);+}++.cu-device-setup__code {+ font-size: 1.05rem;+ font-weight: 600;+ letter-spacing: 0.14em;+ text-align: center;+}++.cu-device-setup__note {+ margin: 0;+ color: var(--cu-text-muted);+ font-size: 0.75rem;+}+/* Read-only model configuration summary. It mirrors the editor's providerblocks so operators can understand the configured model surface withoutopening edit mode. */diff --git a/control-ui/components/CodexSubscriptionHub/index.tsx b/control-ui/components/CodexSubscriptionHub/index.tsxindex ec0f18b3f..a93c9e8c4 100644--- a/control-ui/components/CodexSubscriptionHub/index.tsx+++ b/control-ui/components/CodexSubscriptionHub/index.tsx@@ -1,6 +1,7 @@'use client'import React, { useCallback, useEffect, useMemo, useState } from 'react'+import { copyTextToClipboard } from '@lib/clipboard'import {type CodexSubscriptionConnectionView,createCodexSubscriptionConnection,@@ -32,13 +33,27 @@ import { SelectionDropdown } from '../SelectionDropdown'import { IconKey } from '../Sidebar/icons'import { TablePanelHeader } from '../TablePanelHeader'import { useToast } from '../Toast'-import { IconRefresh, IconX } from '../icons'+import { IconCopy, IconRefresh, IconX } from '../icons'import { CheckboxField } from '../ui'function grantLabel(row: CodexSubscriptionConnectionView): string {return row.displayName || row.connectionKey}+async function copyDeviceValue(+ value: string,+ label: string,+ showToast: ReturnType<typeof useToast>['showToast']+) {+ const copied = await copyTextToClipboard(value)+ showToast(+ copied+ ? `${label} copied.`+ : `Could not copy the ${label.toLowerCase()} — select it and copy manually.`,+ { tone: copied ? 'success' : 'error' }+ )+}+export function CodexSubscriptionHub() {const { showToast } = useToast()const { confirm, confirmDialog } = useConfirmDialog()@@ -62,6 +77,9 @@ 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)const enabled = isCodexSubscriptionUiEnabled(capability)useEffect(() => {@@ -136,6 +154,7 @@ export function CodexSubscriptionHub() {setSetupNew(false)setUserCode(null)setVerificationUri(null)+ setDeviceTabBlocked(false)setError('')if (row.status === 'connected') {try {@@ -158,6 +177,7 @@ export function CodexSubscriptionHub() {setSetupNew(false)setUserCode(null)setVerificationUri(null)+ setDeviceTabBlocked(false)}async function handleSaveEdit() {@@ -193,6 +213,16 @@ export function CodexSubscriptionHub() {)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+ }+ setDeviceTabBlocked(!opened)const deadline = Date.now() + started.intervalSeconds * 1000 * 40while (Date.now() < deadline) {await new Promise(resolve => setTimeout(resolve, started.intervalSeconds * 1000))@@ -599,14 +629,55 @@ export function CodexSubscriptionHub() {</button></div>{userCode ? (- <p- className="cu-field__hint"- data-testid="codex-device-code"- style={{ margin: 0 }}- >- Enter {userCode}- {verificationUri ? ` at ${verificationUri}` : ''}- </p>+ <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}+ <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 ? (diff --git a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsxindex 89f5e2169..88d5c7756 100644--- a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx+++ b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx@@ -7,6 +7,7 @@ import {listCodexSubscriptionConnections,patchCodexCatalogModel,patchCodexSubscriptionConnection,+ pollCodexDevice,revokeCodexSubscription,startCodexDeviceConnect,syncCodexSubscriptionCatalog,@@ -80,6 +81,7 @@ describe('CodexSubscriptionHub', () => {afterEach(() => {cleanup()vi.clearAllMocks()+ vi.unstubAllGlobals()})it('creates a subscription from the Add modal and continues into setup', async () => {@@ -181,6 +183,49 @@ 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)+ vi.mocked(startCodexDeviceConnect).mockResolvedValue({+ userCode: 'ABCD-1234',+ verificationUri: 'https://chatgpt.com/device',+ intervalSeconds: 0.01,+ state: 'state-1',+ intent: 'connect',+ })+ vi.mocked(pollCodexDevice).mockResolvedValue({+ status: 'connected',+ connection: connection({ connectionKey: 'codex-aaa', displayName: 'Team A' }),+ })+ render(+ <ToastProvider>+ <CodexSubscriptionHub />+ </ToastProvider>+ )+ fireEvent.click(+ await screen.findByRole('button', { name: 'Actions for ChatGPT subscription Team A' })+ )+ fireEvent.click(await screen.findByRole('menuitem', { name: 'Update' }))+ 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'+ )+ expect(screen.getByRole('button', { name: 'Copy sign-in link' })).toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Copy device code' })).toBeInTheDocument()+ await waitFor(() => {+ expect(screen.queryByTestId('codex-device-code')).not.toBeInTheDocument()+ })+ expect(listCodexConnectionModels).toHaveBeenCalledWith('codex-aaa')+ })+it('revokes from the table delete action after confirm', async () => {confirmMock.mockResolvedValue(true)vi.mocked(revokeCodexSubscription).mockResolvedValue(diff --git a/control-ui/next-env.d.ts b/control-ui/next-env.d.tsindex 9edff1c7c..c4b7818fb 100644--- a/control-ui/next-env.d.ts+++ b/control-ui/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/types/routes.d.ts";+import "./.next/dev/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 493cbc400..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.479",+ "version": "0.1.480","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.479",+ "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.jsonindex 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",