Skip to content

An open-source, faster Devin alternative

TypeScript

Subscriptions move to Connections: a Models card, and the Slack link on the Slack card

Igor Zalutski via Computer723681a71881
diff --git a/web/src/managed-agents/AgentStep.test.tsx b/web/src/managed-agents/AgentStep.test.tsx
index 3d0f1bda..da1c16a8 100644
--- a/web/src/managed-agents/AgentStep.test.tsx
+++ b/web/src/managed-agents/AgentStep.test.tsx
@@ -29,7 +29,18 @@ vi.mock('./computer-api', async (importOriginal) => ({
...(await importOriginal<typeof import('./computer-api')>()),
...computerApi,
}))
-vi.mock('./api', () => ({ addManagedGitHubConnection: vi.fn() }))
+vi.mock('./api', () => ({
+ addManagedGitHubConnection: vi.fn(),
+ claimManagedAgentChannelIdentity: vi.fn(),
+ disconnectManagedAgentConnection: vi.fn(),
+ displayManagedAgentName: (agent: { id: string }) => agent.id,
+ getManagedAgentConnections: vi.fn(() => Promise.resolve([])),
+ getManagedAgents: vi.fn(() => Promise.resolve([])),
+ getManagedGitHubConnections: vi.fn(() =>
+ Promise.resolve({ connections: [] }),
+ ),
+ linkManagedAgentConnection: vi.fn(),
+}))
const capture = vi.hoisted(() => vi.fn())
vi.mock('posthog-js', () => ({ default: { capture } }))
const notify = vi.hoisted(() => ({
@@ -39,6 +50,20 @@ const notify = vi.hoisted(() => ({
vi.mock('@/lib/errors', () => notify)
const { default: ComputerPage } = await import('./Computer')
+const { default: ConnectionsPage } = await import('./Connections')
+const { AuthContext } = await import('@/hooks/useAuth')
+// Subscriptions are managed on Connections (work 083).
+const CONNECTIONS = '/managed-agents/connections'
+const auth = {
+ user: {
+ id: 'u1',
+ email: '[email protected]',
+ orgId: 'org_1',
+ durableSessionsEnabled: false,
+ infrastructureEnabled: false,
+ computerEnabled: true,
+ },
+} as never
const TOKEN = `sk-ant-oat01-${'a'.repeat(40)}`
const CODE = 'oc_7KQM2XP94HTRWN3F'
@@ -142,18 +167,24 @@ describe('choosing the coding agent', () => {
(b) => b.textContent?.trim() === label,
)
- async function show(status: object, until: string) {
+ async function show(status: object, until: string, path = '/computer') {
computerApi.getComputer.mockResolvedValue(status)
if ('slack' in status && (status.slack as { installed: boolean }).installed)
computerApi.getComputerSessions.mockResolvedValue([session])
act(() => {
root.render(
<QueryClientProvider client={client}>
- <MemoryRouter initialEntries={['/computer']}>
- <Routes>
- <Route path="computer" element={<ComputerPage />} />
- </Routes>
- </MemoryRouter>
+ <AuthContext.Provider value={path === CONNECTIONS ? auth : null}>
+ <MemoryRouter initialEntries={[path]}>
+ <Routes>
+ <Route path="computer" element={<ComputerPage />} />
+ <Route
+ path="managed-agents/connections"
+ element={<ConnectionsPage />}
+ />
+ </Routes>
+ </MemoryRouter>
+ </AuthContext.Provider>
</QueryClientProvider>,
)
})
@@ -474,11 +505,17 @@ describe('choosing the coding agent', () => {
act(() => {
root.render(
<QueryClientProvider client={client}>
- <MemoryRouter initialEntries={['/computer']}>
- <Routes>
- <Route path="computer" element={<ComputerPage />} />
- </Routes>
- </MemoryRouter>
+ <AuthContext.Provider value={null}>
+ <MemoryRouter initialEntries={['/computer']}>
+ <Routes>
+ <Route path="computer" element={<ComputerPage />} />
+ <Route
+ path="managed-agents/connections"
+ element={<ConnectionsPage />}
+ />
+ </Routes>
+ </MemoryRouter>
+ </AuthContext.Provider>
</QueryClientProvider>,
)
})
@@ -514,11 +551,17 @@ describe('choosing the coding agent', () => {
act(() => {
root.render(
<QueryClientProvider client={client}>
- <MemoryRouter initialEntries={['/computer']}>
- <Routes>
- <Route path="computer" element={<ComputerPage />} />
- </Routes>
- </MemoryRouter>
+ <AuthContext.Provider value={null}>
+ <MemoryRouter initialEntries={['/computer']}>
+ <Routes>
+ <Route path="computer" element={<ComputerPage />} />
+ <Route
+ path="managed-agents/connections"
+ element={<ConnectionsPage />}
+ />
+ </Routes>
+ </MemoryRouter>
+ </AuthContext.Provider>
</QueryClientProvider>,
)
})
@@ -589,11 +632,17 @@ describe('choosing the coding agent', () => {
act(() => {
root.render(
<QueryClientProvider client={client}>
- <MemoryRouter initialEntries={['/computer']}>
- <Routes>
- <Route path="computer" element={<ComputerPage />} />
- </Routes>
- </MemoryRouter>
+ <AuthContext.Provider value={null}>
+ <MemoryRouter initialEntries={['/computer']}>
+ <Routes>
+ <Route path="computer" element={<ComputerPage />} />
+ <Route
+ path="managed-agents/connections"
+ element={<ConnectionsPage />}
+ />
+ </Routes>
+ </MemoryRouter>
+ </AuthContext.Provider>
</QueryClientProvider>,
)
})
@@ -741,7 +790,8 @@ describe('choosing the coding agent', () => {
...onboarded,
agent: { ...fresh, choice: 'credits', linked: true },
},
- 'Your agent',
+ 'Models',
+ CONNECTIONS,
)
expect(button('Connect Claude Code')).toBeDefined()
expect(button('Use Codex instead')).toBeUndefined()
@@ -784,7 +834,8 @@ describe('choosing the coding agent', () => {
...onboarded,
agent: { ...withCodex, choice: 'credits', linked: true },
},
- 'Your agent',
+ 'Models',
+ CONNECTIONS,
)
expect(button('Connect Claude Code')).toBeDefined()
act(() => button('Use Codex instead')!.click())
@@ -861,7 +912,8 @@ describe('choosing the coding agent', () => {
subscription: subscription('invalid'),
},
},
- 'Your agent',
+ 'Models',
+ CONNECTIONS,
)
expect(text()).toContain('This token stopped working.')
expect(text()).toContain('Runs threads from @maya in Acme.')
@@ -889,7 +941,8 @@ describe('choosing the coding agent', () => {
subscription: subscription('unchecked'),
},
},
- 'Your agent',
+ 'Models',
+ CONNECTIONS,
)
expect(text()).toContain("Saved. We'll check it when your computer starts.")
expect(button('Resume')).toBeUndefined()
@@ -898,7 +951,8 @@ describe('choosing the coding agent', () => {
it('links someone not linked to Slack with a code', async () => {
await show(
{ ...onboarded, agent: { ...fresh, choice: 'credits' } },
- 'Your agent',
+ 'Models',
+ CONNECTIONS,
)
await settle(() => text().includes(`!link ${CODE}`), 'link command')
expect(computerApi.createConnectCode).toHaveBeenCalledWith('link')
@@ -926,6 +980,23 @@ describe('choosing the coding agent', () => {
expect(Object.keys(window.localStorage)).toEqual([])
})
+ it('sums the agent up on the page, and sends changes to Connections', async () => {
+ await show(
+ { ...onboarded, agent: { ...fresh, choice: 'credits' } },
+ 'Your agent',
+ )
+ expect(text()).toContain(
+ 'Link your Slack account to use your own subscription.',
+ )
+ const link = () =>
+ container.querySelector<HTMLAnchorElement>(
+ 'section[aria-labelledby="computer-agent"] a',
+ )!
+ expect(link().textContent).toBe('Link Slack')
+ expect(link().getAttribute('href')).toBe(CONNECTIONS)
+ expect(computerApi.createConnectCode).not.toHaveBeenCalled()
+ })
+
it('is not there for an older backend', async () => {
await show(empty, 'Add OpenComputer to Slack')
expect(text()).toContain('Step 1 of 3')
diff --git a/web/src/managed-agents/AgentStep.tsx b/web/src/managed-agents/AgentStep.tsx
index 42e86c20..f796555e 100644
--- a/web/src/managed-agents/AgentStep.tsx
+++ b/web/src/managed-agents/AgentStep.tsx
@@ -14,6 +14,7 @@ import {
useQueryClient,
} from '@tanstack/react-query'
import { Loader2 } from 'lucide-react'
+import { Link } from 'react-router-dom'
import { ApiError } from '@/api/errors'
import { ConfirmDialog } from '@/components/confirm-dialog'
import { CopyCommand, CopyRow } from '@/components/copy-row'
@@ -710,7 +711,7 @@ function CommandConnect({
* the card becomes the usual connect card, with this Slack user's
* subscriptions.
*/
-function LinkSlack() {
+export function LinkSlack() {
const [actedAt, setActedAt] = useState(() => Date.now())
// Set with the link, before this unmounts: the forgotten code's query is
// still observed until then, and must not mint again.
@@ -1047,12 +1048,12 @@ export function AgentManage({
if (!subscription) {
// After Slack, subscriptions belong to Slack users: a person not linked
- // to one links first (work 083), or connects from Slack.
+ // to one links first, on the Slack card above (work 083).
if (slackInstalled && !agent.linked) {
return (
- <div className="text-muted-foreground space-y-4 text-sm">
+ <div className="text-muted-foreground space-y-1 text-sm">
<p className="text-foreground font-medium">{agentSummary(agent)}</p>
- <LinkSlack />
+ <p>Link your Slack account above to use your own subscription.</p>
</div>
)
}
@@ -1196,19 +1197,34 @@ export function AgentChangeAction({ agent }: { agent: ComputerAgent }) {
)
}
-/** The Your agent card on the page once setup is done. */
+/**
+ * The Your agent line on the page once setup is done: what runs threads, and
+ * where to change it. Subscriptions are managed on Connections, one place
+ * for every account (work 083).
+ */
export function AgentCard({ status }: { status: ComputerStatus }) {
- if (!status.agent) return null
+ const { agent } = status
+ if (!agent) return null
+ const needsLink = status.slack.installed && !agent.linked
return (
<section aria-labelledby="computer-agent">
<h2 id="computer-agent" className="mb-3 text-sm font-semibold">
Your agent
</h2>
- <div className="bg-panel rounded-lg border px-5 py-4">
- <AgentManage
- agent={status.agent}
- slackInstalled={status.slack.installed}
- />
+ <div className="bg-panel flex flex-wrap items-center justify-between gap-3 rounded-lg border px-5 py-3 text-sm">
+ <div className="min-w-0">
+ <p className="text-foreground font-medium">{agentSummary(agent)}</p>
+ {needsLink ? (
+ <p className="text-muted-foreground">
+ Link your Slack account to use your own subscription.
+ </p>
+ ) : null}
+ </div>
+ <Button variant={needsLink ? 'default' : 'outline'} size="sm" asChild>
+ <Link to="/managed-agents/connections">
+ {needsLink ? 'Link Slack' : 'Manage'}
+ </Link>
+ </Button>
</div>
</section>
)
diff --git a/web/src/managed-agents/Connections.tsx b/web/src/managed-agents/Connections.tsx
index addc92ea..7247f328 100644
--- a/web/src/managed-agents/Connections.tsx
+++ b/web/src/managed-agents/Connections.tsx
@@ -1,6 +1,6 @@
import { useContext, useEffect, useRef, useState, type ReactNode } from 'react'
import { useQuery } from '@tanstack/react-query'
-import { ExternalLink, Loader2, Plus, RefreshCw } from 'lucide-react'
+import { Cpu, ExternalLink, Loader2, Plus, RefreshCw } from 'lucide-react'
import { useSearchParams } from 'react-router-dom'
import { ConfirmDialog } from '@/components/confirm-dialog'
import { GithubMark } from '@/components/github-mark'
@@ -30,12 +30,14 @@ import {
navigateAuthorizationWindow,
openAuthorizationWindow,
} from './authorization-window'
+import { AgentManage, LinkSlack } from './AgentStep'
import { computerQueryKey, getComputer } from './computer-api'
import { SlackInstallButton, UnlinkSlackDialog } from './computer-slack'
import { slackLinks } from './computer-state'
// The organization's connections: the Slack app the computer answers in and
-// the GitHub accounts it works in, then, less prominently, the Google and
+// the GitHub accounts it works in, each person's model subscriptions (and
+// the Slack user they belong to, work 083), then, less prominently, the Google and
// Linear accounts agents call through callService(). Serverless agents also
// send people here to link a channel identity or connect an account
// (`?channel_link=…`, `?connect=1&service=…`).
@@ -193,6 +195,7 @@ export default function ManagedAgentConnections() {
)}
{computerEnabled ? <SlackConnection /> : null}
+ {computerEnabled ? <ModelConnection /> : null}
<GitHubConnection />
<OtherConnections />
</div>
@@ -340,6 +343,7 @@ function SlackConnection() {
</>
}
/>
+ <SlackYou />
<UnlinkSlackDialog
teamName={slack.teamName}
open={confirmUnlink}
@@ -351,6 +355,53 @@ function SlackConnection() {
)
}
+/**
+ * Who you are in Slack: subscriptions belong to Slack users, so a person not
+ * linked to one links here, by sending a code to the app (work 083).
+ */
+function SlackYou() {
+ const status = useQuery({ queryKey: computerQueryKey, queryFn: getComputer })
+ const agent = status.data?.agent
+ if (!agent) return null
+ const user = agent.linkedSlackUser
+ if (agent.linked)
+ return (
+ <ServiceRow
+ title={user?.name ? `@${user.name}` : 'Linked'}
+ detail="You, in Slack"
+ />
+ )
+ return (
+ <div className="text-muted-foreground border-t py-3 pr-5 pl-18 text-sm">
+ <LinkSlack />
+ </div>
+ )
+}
+
+/**
+ * Your model subscription: what runs your threads, its health, Replace and
+ * Disconnect, or how to connect one. Per person, unlike the rest of the page.
+ */
+function ModelConnection() {
+ const status = useQuery({ queryKey: computerQueryKey, queryFn: getComputer })
+ const agent = status.data?.agent
+ if (!agent) return null
+ return (
+ <ServiceCard
+ icon={<Cpu className="size-4" aria-hidden />}
+ title="Models"
+ summary="Your Claude or ChatGPT subscription runs your threads."
+ >
+ <div className="py-4 pr-5 pl-18">
+ <AgentManage
+ agent={agent}
+ slackInstalled={status.data?.slack.installed ?? false}
+ />
+ </div>
+ </ServiceCard>
+ )
+}
+
function GitHubConnection() {
const installations = useQuery({
queryKey: ['managed-github-connections'],