Skip to content

An open-source, faster Devin alternative

TypeScript

fix: simplify subscription selection and management

Igor Zalutski via Computer234ad5d07af0
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
index c23545d5..aa0cf8b7 100644
--- a/web/src/api/mock.ts
+++ b/web/src/api/mock.ts
@@ -1425,6 +1425,11 @@ function previewAgentRequest(path: string, method: string, body: unknown) {
) as { token?: string; choice?: PreviewAgent['choice']; purpose?: string }
if (path.endsWith('/choice')) {
agent.choice = choice ?? null
+ if (agent.subscriptions) {
+ const { claude, codex } = agent.subscriptions
+ agent.subscription =
+ choice === 'codex' ? (codex ?? claude) : (claude ?? codex)
+ }
return { agent: structuredClone(agent) }
}
if (path.endsWith('/connect-code')) {
diff --git a/web/src/managed-agents/AgentStep.test.tsx b/web/src/managed-agents/AgentStep.test.tsx
index 85e28128..38231eae 100644
--- a/web/src/managed-agents/AgentStep.test.tsx
+++ b/web/src/managed-agents/AgentStep.test.tsx
@@ -199,6 +199,31 @@ describe('choosing the coding agent', () => {
| HTMLButtonElement
| undefined
+ const providerRadio = (provider: string) =>
+ container.querySelector<HTMLInputElement>(
+ `input[type="radio"][value="${provider}"]`,
+ )!
+
+ async function openSubscriptionMenu(name: string) {
+ const trigger = container.querySelector<HTMLButtonElement>(
+ `button[aria-label="Manage ${name} subscription"]`,
+ )!
+ act(() => {
+ trigger.dispatchEvent(
+ new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }),
+ )
+ })
+ await settle(
+ () => document.querySelector('[role="menu"]') !== null,
+ 'subscription menu',
+ )
+ }
+
+ const menuItem = (label: string) =>
+ [...document.querySelectorAll<HTMLElement>('[role="menuitem"]')].find(
+ (item) => item.textContent?.trim() === label,
+ )!
+
function openPaste() {
act(() => button('Or paste a token')!.click())
}
@@ -377,6 +402,59 @@ describe('choosing the coding agent', () => {
})
})
+ it('keeps the previous selection after a failed switch and allows retry', async () => {
+ const codex = {
+ provider: 'codex' as const,
+ health: 'ok' as const,
+ setAt: '2026-10-22T10:00:00Z',
+ }
+ const both = {
+ ...withCodex,
+ choice: 'claude' as const,
+ linked: true,
+ subscription: subscription('ok'),
+ subscriptions: { claude: subscription('ok'), codex },
+ }
+ await show({ ...onboarded, agent: both }, 'Models', CONNECTIONS)
+ const error = new Error('Connection interrupted')
+ computerApi.setAgentChoice.mockRejectedValueOnce(error)
+ act(() => providerRadio('codex').click())
+ await settle(
+ () => notify.notifyError.mock.calls.some((call) => call[1] === error),
+ 'switch failed',
+ )
+ await settle(() => !providerRadio('codex').disabled, 'retry available')
+ expect(providerRadio('claude').checked).toBe(true)
+ expect(providerRadio('codex').checked).toBe(false)
+ computerApi.setAgentChoice.mockResolvedValueOnce({
+ ...both,
+ choice: 'codex',
+ subscription: codex,
+ })
+ act(() => providerRadio('codex').click())
+ await settle(() => providerRadio('codex').checked, 'retry succeeded')
+ })
+
+ it('requires a connection before an agent can be selected', async () => {
+ await show(
+ {
+ ...onboarded,
+ agent: {
+ ...withCodex,
+ linked: true,
+ choice: 'claude',
+ subscription: subscription('ok'),
+ },
+ },
+ 'Models',
+ CONNECTIONS,
+ )
+ expect(providerRadio('codex').disabled).toBe(true)
+ expect(rowButton('Codex', 'Connect')).toBeDefined()
+ act(() => providerRadio('codex').click())
+ expect(computerApi.setAgentChoice).not.toHaveBeenCalled()
+ })
+
it('says an unchecked token is saved', async () => {
await show({ ...empty, agent: fresh }, 'Choose your coding agent')
computerApi.connectClaudeSubscription.mockResolvedValue({
@@ -923,10 +1001,21 @@ describe('choosing the coding agent', () => {
CONNECTIONS,
)
expect(text()).toContain('This token stopped working.')
- expect(text()).toContain('Runs threads from @maya in Acme.')
+ expect(text()).toContain('For @maya in Acme')
expect(text()).not.toContain('@U1')
- expect(button('Replace')).toBeDefined()
- expect(button('Disconnect')).toBeDefined()
+ await openSubscriptionMenu('Claude Code')
+ expect(menuItem('Replace')).toBeDefined()
+ act(() => menuItem('Disconnect').click())
+ await settle(
+ () => text().includes('Disconnect Claude Code?'),
+ 'disconnect confirmation',
+ )
+ expect(computerApi.disconnectClaudeSubscription).not.toHaveBeenCalled()
+ act(() => button('Cancel')!.click())
+ await settle(
+ () => !text().includes('Disconnect Claude Code?'),
+ 'cancel disconnect',
+ )
computerApi.resumeClaudeSubscription.mockResolvedValue({
...fresh,
choice: 'claude',
@@ -952,21 +1041,30 @@ describe('choosing the coding agent', () => {
subscriptions: { claude: subscription('ok'), codex },
}
await show({ ...onboarded, agent: both }, 'Models', CONNECTIONS)
- const row = (name: string) =>
- document.querySelector(`section[aria-label="${name}"]`)!.textContent
- expect(row('Claude Code')).toContain('Runs your threads')
- expect(row('Codex')).not.toContain('Runs your threads')
- expect(rowButton('Claude Code', 'Use for threads')).toBeUndefined()
- computerApi.setAgentChoice.mockResolvedValue({
- ...both,
- choice: 'codex',
- subscription: codex,
- })
- act(() => rowButton('Codex', 'Use for threads')!.click())
- await settle(
- () => row('Codex')?.includes('Runs your threads') === true,
- 'codex runs',
+ expect(providerRadio('claude').checked).toBe(true)
+ expect(providerRadio('codex').checked).toBe(false)
+ let resolveSwitch!: (agent: ComputerAgent) => void
+ computerApi.setAgentChoice.mockImplementation(
+ () =>
+ new Promise<ComputerAgent>((resolve) => {
+ resolveSwitch = resolve
+ }),
+ )
+ act(() => providerRadio('codex').click())
+ await settle(() => providerRadio('codex').disabled, 'switching')
+ expect(providerRadio('claude').disabled).toBe(true)
+ expect(providerRadio('claude').checked).toBe(true)
+ expect(providerRadio('codex').checked).toBe(false)
+ act(() =>
+ resolveSwitch({
+ ...both,
+ choice: 'codex',
+ subscription: codex,
+ }),
)
+ await settle(() => providerRadio('codex').checked, 'codex selected')
+ expect(providerRadio('claude').checked).toBe(false)
+ expect(providerRadio('claude').disabled).toBe(false)
expect(computerApi.setAgentChoice).toHaveBeenCalledWith('codex')
expect(notify.notifySuccess).toHaveBeenCalledWith(
'Codex runs your threads now.',
diff --git a/web/src/managed-agents/AgentStep.tsx b/web/src/managed-agents/AgentStep.tsx
index 7cfcc3e3..915eec20 100644
--- a/web/src/managed-agents/AgentStep.tsx
+++ b/web/src/managed-agents/AgentStep.tsx
@@ -13,7 +13,7 @@ import {
useQuery,
useQueryClient,
} from '@tanstack/react-query'
-import { Loader2 } from 'lucide-react'
+import { Ellipsis, Loader2 } from 'lucide-react'
import { Link } from 'react-router-dom'
import { ApiError } from '@/api/errors'
import { ConfirmDialog } from '@/components/confirm-dialog'
@@ -27,6 +27,12 @@ import {
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu'
import { Input } from '@/components/ui/input'
import { AuthContext } from '@/hooks/useAuth'
import { BASE_GRANT_CENTS } from '@/lib/billing-onramp'
@@ -1035,19 +1041,38 @@ export function AgentManage({
const needsLink = slackInstalled && !agent.linked
const linked = linkedSlackUserLine(agent, slackInstalled)
const subscriptions = subscriptionsOf(agent)
+ const groupName = useId()
+ const { setAgent } = useAgentCache()
+ const select = useMutation({
+ mutationFn: (provider: SubscriptionProvider) => setAgentChoice(provider),
+ onSuccess: async (next, provider) => {
+ await setAgent(next)
+ trackAgentChosen(provider)
+ notifySuccess(`${PROVIDER_NAME[provider]} runs your threads now.`)
+ },
+ onError: (error) => notifyError("Couldn't switch.", error),
+ })
return (
<div className="text-muted-foreground space-y-3 text-sm">
- <div className="space-y-0.5">
- <p className="text-foreground font-medium">{agentSummary(agent)}</p>
- {needsLink ? (
- // After Slack, subscriptions belong to Slack users: a person not
- // linked to one links first, on the Slack card above.
- <p>Link your Slack account above to use your own subscription.</p>
- ) : linked ? (
- <p>{linked}</p>
- ) : null}
- </div>
- <div className="divide-y rounded-lg border">
+ {!agent.subscription || needsLink || linked ? (
+ <div className="space-y-0.5">
+ {!agent.subscription ? (
+ <p className="text-foreground font-medium">{agentSummary(agent)}</p>
+ ) : null}
+ {needsLink ? (
+ // After Slack, subscriptions belong to Slack users: a person not
+ // linked to one links first, on the Slack card above.
+ <p>Link your Slack account above to use your own subscription.</p>
+ ) : linked ? (
+ <p>
+ For @{agent.linkedSlackUser?.name} in{' '}
+ {agent.linkedSlackUser?.teamName}
+ </p>
+ ) : null}
+ </div>
+ ) : null}
+ <fieldset className="space-y-2" aria-busy={select.isPending}>
+ <legend className="sr-only">Agent for your threads</legend>
{subscriptionProviderSchema.options.map((provider) => (
<ProviderRow
key={provider}
@@ -1055,9 +1080,13 @@ export function AgentManage({
provider={provider}
subscription={subscriptions[provider]}
locked={needsLink}
+ groupName={groupName}
+ switching={select.isPending}
+ selecting={select.isPending && select.variables === provider}
+ onSelect={() => select.mutate(provider)}
/>
))}
- </div>
+ </fieldset>
</div>
)
}
@@ -1067,11 +1096,19 @@ function ProviderRow({
provider,
subscription,
locked,
+ groupName,
+ switching,
+ selecting,
+ onSelect,
}: {
agent: ComputerAgent
provider: SubscriptionProvider
subscription: AgentSubscription | null
locked: boolean
+ groupName: string
+ switching: boolean
+ selecting: boolean
+ onSelect: () => void
}) {
const { setAgent, reread } = useAgentCache()
const [connecting, setConnecting] = useState(false)
@@ -1090,15 +1127,6 @@ function ProviderRow({
notifyError("Couldn't resume.", error)
},
})
- const use = useMutation({
- mutationFn: () => setAgentChoice(provider),
- onSuccess: async (next) => {
- await setAgent(next)
- trackAgentChosen(provider)
- notifySuccess(`${name} runs your threads now.`)
- },
- onError: (error) => notifyError("Couldn't switch.", error),
- })
const disconnect = useMutation({
mutationFn: disconnectSubscription,
onSuccess: () => {
@@ -1119,43 +1147,68 @@ function ProviderRow({
: "Coming soon. We'll let you know."
return (
- <section aria-label={name} className="space-y-3 px-4 py-3">
- <div className="flex flex-wrap items-center gap-3">
- <div className="bg-muted flex size-8 shrink-0 items-center justify-center rounded-md">
- <ServiceLogo
- service={PROVIDER_ROW[provider].logo}
- className="text-foreground size-4"
+ <section
+ aria-label={name}
+ className={cn(
+ 'space-y-3 rounded-lg border px-3 py-3 transition-colors',
+ runs && 'bg-muted/40',
+ )}
+ >
+ <div className="flex items-center gap-2">
+ <label className="flex min-w-0 flex-1 cursor-pointer items-center gap-3 has-disabled:cursor-default">
+ <input
+ type="radio"
+ name={groupName}
+ value={provider}
+ aria-label={name}
+ aria-describedby={`${groupName}-${provider}-status`}
+ checked={runs}
+ disabled={
+ locked || connecting || switching || !subscription || !available
+ }
+ onChange={onSelect}
+ className="accent-foreground focus-visible:outline-ring size-4 shrink-0 cursor-pointer focus-visible:outline-2 focus-visible:outline-offset-4 disabled:cursor-default"
/>
- </div>
- <div className="min-w-0 flex-1">
- <p className="text-foreground font-medium">
- {name}
- {runs ? (
- <span className="bg-muted text-muted-foreground ml-2 rounded px-1.5 py-0.5 text-xs font-normal">
- Runs your threads
- </span>
- ) : null}
- </p>
- <p
- className={cn(
- 'text-xs',
- subscription?.health === 'invalid' && 'text-destructive',
- )}
+ <span className="bg-background flex size-9 shrink-0 items-center justify-center rounded-md border">
+ <ServiceLogo
+ service={PROVIDER_ROW[provider].logo}
+ className="text-foreground size-5"
+ />
+ </span>
+ <span className="min-w-0 space-y-0.5">
+ <span className="text-foreground block font-medium">{name}</span>
+ <span
+ id={`${groupName}-${provider}-status`}
+ className={cn(
+ 'block text-xs',
+ subscription?.health === 'invalid' && 'text-destructive',
+ )}
+ >
+ {subscription?.plan
+ ? `ChatGPT ${subscription.plan.charAt(0).toUpperCase()}${subscription.plan.slice(1)} · ${status}`
+ : subscription
+ ? status
+ : `${PROVIDER_ROW[provider].plans} · ${status}`}
+ </span>
+ </span>
+ </label>
+ {selecting ? (
+ <span
+ role="status"
+ className="text-muted-foreground flex items-center gap-1.5 text-xs"
>
- {subscription?.plan
- ? `ChatGPT ${subscription.plan.charAt(0).toUpperCase()}${subscription.plan.slice(1)} · ${status}`
- : subscription
- ? status
- : `${PROVIDER_ROW[provider].plans} · ${status}`}
- </p>
- </div>
+ <Loader2 className="size-3.5 animate-spin" aria-hidden />
+ <span className="sr-only sm:not-sr-only">Switching…</span>
+ </span>
+ ) : null}
{locked || connecting ? null : (
- <div className="flex flex-wrap items-center gap-1">
+ <div className="flex shrink-0 items-center gap-1">
{canResume ? (
<Button
size="sm"
+ variant="outline"
onClick={() => resume.mutate()}
- disabled={resume.isPending}
+ disabled={resume.isPending || switching}
>
{resume.isPending ? (
<Loader2 className="size-4 animate-spin" aria-hidden />
@@ -1163,40 +1216,40 @@ function ProviderRow({
Resume
</Button>
) : null}
- {subscription && !runs && available ? (
+ {!subscription && available ? (
<Button
size="sm"
variant="outline"
- onClick={() => use.mutate()}
- disabled={use.isPending}
- >
- Use for threads
- </Button>
- ) : null}
- {available ? (
- // A login whose harness the gate switched off can still be
- // disconnected, not signed in again.
- <Button
- size="sm"
- variant={subscription ? 'ghost' : 'outline'}
+ disabled={switching}
onClick={() => setConnecting(true)}
>
- {!subscription
- ? 'Connect'
- : provider === 'codex'
- ? 'Reconnect'
- : 'Replace'}
+ Connect
</Button>
) : null}
{subscription ? (
- <Button
- size="sm"
- variant="ghost"
- className="text-muted-foreground"
- onClick={() => setConfirmDisconnect(true)}
- >
- Disconnect
- </Button>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ size="icon-sm"
+ variant="ghost"
+ className="text-muted-foreground"
+ aria-label={`Manage ${name} subscription`}
+ disabled={switching || resume.isPending}
+ >
+ <Ellipsis aria-hidden />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="min-w-40">
+ {available ? (
+ <DropdownMenuItem onSelect={() => setConnecting(true)}>
+ {provider === 'codex' ? 'Reconnect' : 'Replace'}
+ </DropdownMenuItem>
+ ) : null}
+ <DropdownMenuItem onSelect={() => setConfirmDisconnect(true)}>
+ Disconnect
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
) : null}
</div>
)}
diff --git a/web/src/managed-agents/Connections.tsx b/web/src/managed-agents/Connections.tsx
index 7247f328..98b99b62 100644
--- a/web/src/managed-agents/Connections.tsx
+++ b/web/src/managed-agents/Connections.tsx
@@ -390,9 +390,9 @@ function ModelConnection() {
<ServiceCard
icon={<Cpu className="size-4" aria-hidden />}
title="Models"
- summary="Your Claude or ChatGPT subscription runs your threads."
+ summary="Choose your coding agent."
>
- <div className="py-4 pr-5 pl-18">
+ <div className="px-5 py-4 sm:pl-18">
<AgentManage
agent={agent}
slackInstalled={status.data?.slack.installed ?? false}