Skip to content

An open-source, faster Devin alternative

TypeScript

feat(agents): shift Slack conflicts before OAuth

Igor Zalutski39228d9503f8
diff --git a/docs/agent-sessions/agents.mdx b/docs/agent-sessions/agents.mdx
index c2b21ab1..e2c76b43 100644
--- a/docs/agent-sessions/agents.mdx
+++ b/docs/agent-sessions/agents.mdx
@@ -78,6 +78,12 @@ Choose **Agents → Create agent → Import from GitHub**, install the OpenCompu
Review and import are intentionally separate. Import rechecks the exact source plan; if the repository changed in between, nothing is created and the dashboard asks you to review again. A successful import returns the new agent and its first deployment immediately, then opens guided setup instead of making you wait on a log screen. Connect Slack while the deployment continues in the background; its compact phases and expandable log remain available. When both are ready, setup changes to **Open Slack** without a refresh and invites you to send the first message. Manually configured agents use the same setup journey.
+If one of your Slack workspaces already sends messages to another agent, setup
+shows that claim before OAuth. Open the connected agent, choose another
+workspace, or disconnect it in place after reviewing the routing impact. A
+completed first conversation adds direct exits to the agent home, full session,
+session history, and Slack.
+
The repository picker marks roots already used by another agent before review.
An exact linked root cannot be reviewed again: open its owning agent, choose a
different monorepo root, or unlink it in place after confirming that
diff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdx
index c49c8009..f2e52a3f 100644
--- a/docs/agent-sessions/api-reference.mdx
+++ b/docs/agent-sessions/api-reference.mdx
@@ -753,6 +753,7 @@ context, not a redirect URL. Status responses never contain credentials.
| --- | --- |
| `oc.agents.authorizeManagedSlack(id, { returnDeploymentId? })` | Start managed-app OAuth. |
| `oc.agents.getManagedSlack(id)` | Read workspace, app identity, state, and `openUrl`. |
+| `oc.agents.listManagedSlackConnections()` | List this owner's current workspace claims and owning agents before OAuth. |
| `oc.agents.disconnectManagedSlack(id)` | Stop routing this agent without uninstalling the workspace app. |
</Tab>
@@ -764,6 +765,7 @@ context, not a redirect URL. Status responses never contain credentials.
| `POST /agents/:id/slack/managed/authorize` | Start managed-app OAuth; accepts `return_deployment_id?`. |
| `GET /agents/:id/slack/managed` | Read the managed connection. |
| `DELETE /agents/:id/slack/managed` | Disconnect the agent from the shared app. |
+| `GET /slack/managed/connections` | List current owner-scoped workspace claims with safe agent id/name projections. |
</Tab>
@@ -772,6 +774,10 @@ context, not a redirect URL. Status responses never contain credentials.
The managed status is `active`, `disconnected`, `error`, or `revoked`. An active
response includes `workspace`, `app`, `open_url`, and `connected_at`; error
states expose only a stable `error_code`.
+The connection list returns `{ data }`; each item has the same public status
+shape plus `agent: { id, name }`. It contains no Slack token, signing secret, or
+credential reference. Treat it as a preflight convenience: authorization still
+enforces the one-workspace-to-one-agent claim transactionally.
Builder-owned Slack apps remain a separate resource and can overlap during an
explicit handoff:
diff --git a/docs/agent-sessions/slack.mdx b/docs/agent-sessions/slack.mdx
index d3dbabd1..3f98baef 100644
--- a/docs/agent-sessions/slack.mdx
+++ b/docs/agent-sessions/slack.mdx
@@ -16,6 +16,14 @@ opens guided setup; choose **Connect Slack**, approve the workspace
installation, and return to the same setup page. You can also connect or manage
Slack later from the agent overview.
+Before sending you to Slack, the dashboard lists any workspace in your account
+that already sends messages to another agent. You can open that agent, connect a
+different workspace, or disconnect the workspace in place. The confirmation
+names the affected agent and explains that new Slack messages stop routing to
+it; the agent, existing sessions, and installed OpenComputer app remain. OAuth
+still checks the claim again in case another tab connects the workspace after
+this preflight.
+
You can connect Slack while a repository deployment is still running. The
connection remains in place if that deployment fails, but the app cannot run a
message until the agent has a ready deployment. A message sent too early gets a
@@ -59,6 +67,9 @@ if ("authorizeUrl" in authorization) {
const connection = await oc.agents.getManagedSlack(agentId);
// { mode: "managed", status: "active", workspace, app, openUrl, ... }
+const { data: workspaceClaims } = await oc.agents.listManagedSlackConnections();
+// [{ workspace, app, agent: { id, name }, status, ... }]
+
await oc.agents.disconnectManagedSlack(agentId);
```
@@ -66,6 +77,7 @@ await oc.agents.disconnectManagedSlack(agentId);
POST https://api.opencomputer.dev/v3/agents/{agent_id}/slack/managed/authorize
GET https://api.opencomputer.dev/v3/agents/{agent_id}/slack/managed
DELETE https://api.opencomputer.dev/v3/agents/{agent_id}/slack/managed
+GET https://api.opencomputer.dev/v3/slack/managed/connections
Authorization: Bearer $OPENCOMPUTER_API_KEY
// optional authorize body
diff --git a/sdks/typescript/package-lock.json b/sdks/typescript/package-lock.json
index bc20364b..50e0c186 100644
--- a/sdks/typescript/package-lock.json
+++ b/sdks/typescript/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@opencomputer/sdk",
- "version": "0.12.3",
+ "version": "0.12.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@opencomputer/sdk",
- "version": "0.12.3",
+ "version": "0.12.4",
"license": "MIT",
"devDependencies": {
"@types/node": "^25.3.0",
diff --git a/sdks/typescript/package.json b/sdks/typescript/package.json
index ed7af07f..9341e6f9 100644
--- a/sdks/typescript/package.json
+++ b/sdks/typescript/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/sdk",
- "version": "0.12.3",
+ "version": "0.12.4",
"description": "TypeScript SDK for OpenComputer - cloud sandbox platform",
"type": "module",
"main": "dist/index.js",
diff --git a/sdks/typescript/src/agents/agents.test.ts b/sdks/typescript/src/agents/agents.test.ts
index 624904d9..6f7b2674 100644
--- a/sdks/typescript/src/agents/agents.test.ts
+++ b/sdks/typescript/src/agents/agents.test.ts
@@ -114,6 +114,41 @@ describe("Agents Slack", () => {
);
});
+ it("lists current owner workspace claims before OAuth", async () => {
+ const fetcher = vi.fn(async () =>
+ Response.json({
+ data: [
+ {
+ mode: "managed",
+ status: "active",
+ workspace: { id: "T1", name: "Acme" },
+ app: { id: "A1", handle: "OpenComputer" },
+ open_url: "https://slack.com/app_redirect?app=A1&team=T1",
+ connected_at: "2026-07-16T17:00:00Z",
+ agent: { id: "agt_1", name: "Support triage" },
+ },
+ ],
+ }),
+ );
+ const oc = new OpenComputer({
+ apiKey: "test-key",
+ baseUrl: "https://api.example.test/v3",
+ fetch: fetcher as typeof fetch,
+ maxRetries: 0,
+ });
+
+ const result = await oc.agents.listManagedSlackConnections();
+
+ expect(result.data[0]).toMatchObject({
+ workspace: { id: "T1", name: "Acme" },
+ agent: { id: "agt_1", name: "Support triage" },
+ });
+ expect(fetcher).toHaveBeenCalledWith(
+ "https://api.example.test/v3/slack/managed/connections",
+ expect.objectContaining({ method: "GET" }),
+ );
+ });
+
it("disconnects the managed connection without uninstalling the app", async () => {
const fetcher = vi.fn(async () =>
Response.json({ ok: true, status: "disconnected" }),
diff --git a/sdks/typescript/src/agents/agents.ts b/sdks/typescript/src/agents/agents.ts
index 436e5e82..f349009f 100644
--- a/sdks/typescript/src/agents/agents.ts
+++ b/sdks/typescript/src/agents/agents.ts
@@ -78,6 +78,11 @@ export interface ManagedSlackConnection {
errorCode?: string | null;
}
+/** One current owner-scoped workspace claim for pre-OAuth conflict discovery. */
+export interface ManagedSlackWorkspaceConnection extends ManagedSlackConnection {
+ agent: { id: string; name: string };
+}
+
/** Reusable agents — the "what" a session runs. */
export class Agents {
/** Deploy behavior (inline or from a linked repo) — each deployment produces a revision. */
@@ -156,6 +161,10 @@ export class Agents {
getManagedSlack(id: string): Promise<ManagedSlackConnection> {
return this.http.request("GET", `/agents/${id}/slack/managed`);
}
+ /** Current workspaces already routed to this owner's agents. */
+ listManagedSlackConnections(): Promise<Page<ManagedSlackWorkspaceConnection>> {
+ return this.http.request("GET", "/slack/managed/connections");
+ }
/** Disconnect this agent without uninstalling the shared app from Slack. */
disconnectManagedSlack(id: string): Promise<{ ok: true; status: "disconnected" }> {
return this.http.request("DELETE", `/agents/${id}/slack/managed`);
diff --git a/sdks/typescript/src/agents/index.ts b/sdks/typescript/src/agents/index.ts
index c9b3d0db..a57822e9 100644
--- a/sdks/typescript/src/agents/index.ts
+++ b/sdks/typescript/src/agents/index.ts
@@ -11,7 +11,7 @@ export { Agents } from "./agents.js";
export type {
CreateAgentParams, UpdateAgentParams, Page,
SlackManifest, SlackConnection, ConnectSlackParams,
- ManagedSlackAuthorization, ManagedSlackConnection,
+ ManagedSlackAuthorization, ManagedSlackConnection, ManagedSlackWorkspaceConnection,
} from "./agents.js";
export { AgentRepository } from "./repository-agents.js";
export type {
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index ceae07ff..ef950781 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -38,6 +38,7 @@ export type {
RepositorySourceInspection,
ManagedSlackAuthorizeResponse,
ManagedSlackConnection,
+ ManagedSlackWorkspaceConnection,
ManagedSlackDisconnectResponse,
Session,
AgentSnapshot,
@@ -851,6 +852,13 @@ export async function getManagedSlackConnection(agentId: string) {
}
}
+export const getManagedSlackConnections = () =>
+ apiFetch(
+ '/v3/slack/managed/connections',
+ {},
+ S.ManagedSlackWorkspaceConnectionListSchema,
+ ).then((result) => result.data)
+
export const disconnectManagedSlack = (agentId: string) =>
apiFetch(
`/v3/agents/${encodeURIComponent(agentId)}/slack/managed`,
diff --git a/web/src/api/schemas.ts b/web/src/api/schemas.ts
index ea670cb4..2d550ec9 100644
--- a/web/src/api/schemas.ts
+++ b/web/src/api/schemas.ts
@@ -817,6 +817,15 @@ export const ManagedSlackConnectionSchema = z.object({
error_code: z.string().nullish(),
})
+export const ManagedSlackWorkspaceConnectionSchema =
+ ManagedSlackConnectionSchema.extend({
+ agent: z.object({ id: z.string(), name: z.string() }),
+ })
+
+export const ManagedSlackWorkspaceConnectionListSchema = z.object({
+ data: z.array(ManagedSlackWorkspaceConnectionSchema),
+})
+
// A race-safe authorize is idempotent: if the connection became active after
// the dashboard status read, the API returns that active connection instead of
// minting another OAuth intent.
@@ -973,6 +982,9 @@ export type ManagedSlackAuthorizeResponse = z.infer<
export type ManagedSlackConnection = z.infer<
typeof ManagedSlackConnectionSchema
>
+export type ManagedSlackWorkspaceConnection = z.infer<
+ typeof ManagedSlackWorkspaceConnectionSchema
+>
export type ManagedSlackDisconnectResponse = z.infer<
typeof ManagedSlackDisconnectResponseSchema
>
diff --git a/web/src/api/slack-schemas.test.ts b/web/src/api/slack-schemas.test.ts
index e7444f1c..b9cc8ea7 100644
--- a/web/src/api/slack-schemas.test.ts
+++ b/web/src/api/slack-schemas.test.ts
@@ -3,6 +3,7 @@ import { authorizeManagedSlack } from './client'
import {
ManagedSlackAuthorizeResponseSchema,
ManagedSlackConnectionSchema,
+ ManagedSlackWorkspaceConnectionListSchema,
} from './schemas'
afterEach(() => {
@@ -24,6 +25,25 @@ describe('managed Slack response schemas', () => {
expect(JSON.stringify(result)).not.toContain('xoxb-')
})
+ it('accepts owner-scoped workspace claims without credentials', () => {
+ const result = ManagedSlackWorkspaceConnectionListSchema.parse({
+ data: [
+ {
+ mode: 'managed',
+ status: 'active',
+ workspace: { id: 'T1', name: 'Acme' },
+ app: { id: 'A1', handle: 'OpenComputer' },
+ open_url: 'https://slack.com/app_redirect?app=A1&team=T1',
+ connected_at: '2026-07-16T18:00:00Z',
+ agent: { id: 'agt_1', name: 'Support triage' },
+ },
+ ],
+ })
+
+ expect(result.data[0]?.agent.name).toBe('Support triage')
+ expect(JSON.stringify(result)).not.toContain('xoxb-')
+ })
+
it('accepts only the fixed managed OAuth start shape', () => {
expect(
ManagedSlackAuthorizeResponseSchema.parse({
diff --git a/web/src/components/managed-slack-workspace-claims.tsx b/web/src/components/managed-slack-workspace-claims.tsx
new file mode 100644
index 00000000..f352daa5
--- /dev/null
+++ b/web/src/components/managed-slack-workspace-claims.tsx
@@ -0,0 +1,179 @@
+import { useState } from 'react'
+import {
+ useMutation,
+ useQueryClient,
+ type UseQueryResult,
+} from '@tanstack/react-query'
+import { Link } from 'react-router-dom'
+import { Unplug } from 'lucide-react'
+import {
+ disconnectManagedSlack,
+ type ManagedSlackWorkspaceConnection,
+} from '@/api/client'
+import { ConfirmDialog } from '@/components/confirm-dialog'
+import { Button } from '@/components/ui/button'
+import { Skeleton } from '@/components/ui/skeleton'
+import { notifyError, notifySuccess } from '@/lib/errors'
+import {
+ managedSlackConnectionsQueryKey,
+ managedSlackDisconnectCopy,
+} from '@/lib/managed-slack-connections'
+import { cn } from '@/lib/utils'
+
+type ClaimsQuery = Pick<
+ UseQueryResult<ManagedSlackWorkspaceConnection[]>,
+ 'data' | 'isLoading' | 'isError' | 'refetch'
+>
+
+export function ManagedSlackWorkspaceClaims({
+ currentAgentId,
+ currentAgentName,
+ query,
+ className,
+}: {
+ currentAgentId: string
+ currentAgentName: string
+ query: ClaimsQuery
+ className?: string
+}) {
+ const queryClient = useQueryClient()
+ const [disconnecting, setDisconnecting] =
+ useState<ManagedSlackWorkspaceConnection | null>(null)
+ const connections = (query.data ?? []).filter(
+ (connection) => connection.agent.id !== currentAgentId,
+ )
+ const disconnectMutation = useMutation({
+ mutationFn: (connection: ManagedSlackWorkspaceConnection) =>
+ disconnectManagedSlack(connection.agent.id),
+ onSuccess: (_result, connection) => {
+ queryClient.setQueryData<ManagedSlackWorkspaceConnection[]>(
+ managedSlackConnectionsQueryKey,
+ (current) =>
+ current?.filter(
+ (candidate) => candidate.agent.id !== connection.agent.id,
+ ) ?? [],
+ )
+ void queryClient.invalidateQueries({
+ queryKey: managedSlackConnectionsQueryKey,
+ })
+ void queryClient.invalidateQueries({
+ queryKey: ['slack', 'managed', connection.agent.id],
+ })
+ setDisconnecting(null)
+ const workspace =
+ connection.workspace?.name ||
+ connection.workspace?.id ||
+ 'Slack workspace'
+ notifySuccess(
+ `${workspace} disconnected from ${connection.agent.name}.`,
+ `Connect Slack again to select it for ${currentAgentName}.`,
+ )
+ },
+ onError: (error) =>
+ notifyError("Couldn't disconnect the Slack workspace.", error),
+ })
+
+ if (!query.isLoading && !query.isError && connections.length === 0) {
+ return null
+ }
+
+ const copy = disconnecting
+ ? managedSlackDisconnectCopy(disconnecting, currentAgentName)
+ : null
+ const heading = query.isLoading
+ ? 'Checking existing Slack workspaces'
+ : query.isError
+ ? 'Existing Slack connections are unavailable'
+ : 'Slack workspaces already in use'
+ const description = query.isLoading
+ ? `Checking whether a workspace already sends messages to another agent before connecting ${currentAgentName}.`
+ : query.isError
+ ? 'You can retry this check or continue. Slack will verify the workspace claim again before connecting.'
+ : `Disconnect a workspace before selecting it for ${currentAgentName}. You can connect a different workspace without changing these.`
+
+ return (
+ <>
+ <section className={cn('border-t pt-4', className)} aria-label={heading}>
+ <div>
+ <p className="text-sm font-medium">{heading}</p>
+ <p className="text-muted-foreground mt-0.5 max-w-xl text-xs leading-relaxed">
+ {description}
+ </p>
+ </div>
+
+ {query.isLoading ? (
+ <div
+ className="mt-3 space-y-2"
+ aria-label="Checking Slack workspaces"
+ >
+ <Skeleton className="h-4 w-52" />
+ <Skeleton className="h-8 w-full" />
+ </div>
+ ) : query.isError ? (
+ <div className="mt-3 flex flex-wrap items-center gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={() => void query.refetch()}
+ >
+ Retry
+ </Button>
+ </div>
+ ) : (
+ <div className="mt-3 divide-y">
+ {connections.map((connection) => {
+ const workspace =
+ connection.workspace?.name ||
+ connection.workspace?.id ||
+ 'Slack workspace'
+ return (
+ <div
+ key={`${connection.workspace?.id ?? connection.agent.id}:${connection.agent.id}`}
+ className="flex flex-col gap-2 py-2.5 first:pt-0 last:pb-0 sm:flex-row sm:items-center sm:justify-between"
+ >
+ <div className="min-w-0">
+ <p className="truncate text-sm font-medium">{workspace}</p>
+ <p className="text-muted-foreground mt-0.5 truncate text-xs">
+ Sends messages to {connection.agent.name}
+ </p>
+ </div>
+ <div className="flex shrink-0 flex-wrap items-center gap-1">
+ <Button variant="outline" size="sm" asChild>
+ <Link to={`/agents/${connection.agent.id}`}>
+ Open agent
+ </Link>
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ disabled={disconnectMutation.isPending}
+ onClick={() => setDisconnecting(connection)}
+ >
+ <Unplug className="size-4" aria-hidden />
+ Disconnect
+ </Button>
+ </div>
+ </div>
+ )
+ })}
+ </div>
+ )}
+ </section>
+
+ <ConfirmDialog
+ open={disconnecting != null}
+ onOpenChange={(open) => {
+ if (!open) setDisconnecting(null)
+ }}
+ title={copy?.title ?? 'Disconnect Slack workspace?'}
+ description={copy?.description}
+ confirmLabel="Disconnect workspace"
+ destructive
+ pending={disconnectMutation.isPending}
+ onConfirm={() => {
+ if (disconnecting) disconnectMutation.mutate(disconnecting)
+ }}
+ />
+ </>
+ )
+}
diff --git a/web/src/components/slack-connect.render.test.tsx b/web/src/components/slack-connect.render.test.tsx
index 9315f931..347e7320 100644
--- a/web/src/components/slack-connect.render.test.tsx
+++ b/web/src/components/slack-connect.render.test.tsx
@@ -3,6 +3,7 @@ import { renderToStaticMarkup } from 'react-dom/server'
import { MemoryRouter } from 'react-router-dom'
import { describe, expect, it } from 'vitest'
import { SlackConnect } from './slack-connect'
+import { managedSlackConnectionsQueryKey } from '@/lib/managed-slack-connections'
const agentId = 'agt_aaaaaaaaaaaaaaaaaaaaaaaa'
const connectedAgentId = 'agt_bbbbbbbbbbbbbbbbbbbbbbbb'
@@ -11,6 +12,7 @@ function renderSlackConnect(
managed: Record<string, unknown> | null | undefined,
url = `/agents/${agentId}`,
connectedAgentName?: string,
+ managedConnections: Array<Record<string, unknown>> = [],
) {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
@@ -19,6 +21,7 @@ function renderSlackConnect(
queryClient.setQueryData(['slack', 'managed', agentId], managed)
}
queryClient.setQueryData(['slack', 'byo', agentId], null)
+ queryClient.setQueryData(managedSlackConnectionsQueryKey, managedConnections)
if (connectedAgentName) {
queryClient.setQueryData(['agent', connectedAgentId], {
id: connectedAgentId,
@@ -90,7 +93,27 @@ describe('SlackConnect managed states', () => {
`/agents/${agentId}?slack=workspace_already_connected`,
)
- expect(markup).toContain('Use your own Slack app for this agent.')
+ expect(markup).toContain(
+ 'Connect a different workspace or use your own Slack app for this agent.',
+ )
expect(markup).not.toContain('Open connected agent')
})
+
+ it('shows and links an existing workspace claim before OAuth', () => {
+ const markup = renderSlackConnect(null, `/agents/${agentId}`, undefined, [
+ {
+ mode: 'managed',
+ status: 'active',
+ workspace: { id: 'T1', name: 'Acme' },
+ app: { id: 'A1', handle: 'OpenComputer' },
+ connected_at: '2026-07-16T18:00:00Z',
+ agent: { id: connectedAgentId, name: 'Docs writer' },
+ },
+ ])
+
+ expect(markup).toContain('Slack workspaces already in use')
+ expect(markup).toContain('Sends messages to Docs writer')
+ expect(markup).toContain(`href="/agents/${connectedAgentId}"`)
+ expect(markup).toContain('Connect another workspace')
+ })
})
diff --git a/web/src/components/slack-connect.test.ts b/web/src/components/slack-connect.test.ts
index 6adcc48f..e95ca495 100644
--- a/web/src/components/slack-connect.test.ts
+++ b/web/src/components/slack-connect.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import { managedSlackNotice } from '@/lib/managed-slack-notice'
+import { managedSlackDisconnectCopy } from '@/lib/managed-slack-connections'
describe('managed Slack OAuth notices', () => {
it('uses the active connection data for a successful return', () => {
@@ -34,13 +35,40 @@ describe('managed Slack OAuth notices', () => {
'Docs writer',
),
).toMatchObject({
- description: 'This workspace sends messages to Docs writer.',
+ description:
+ 'This workspace sends messages to Docs writer. Disconnect it below before connecting it to Support triage.',
})
})
it('does not suggest an inaccessible agent for a cross-owner conflict', () => {
expect(
managedSlackNotice('workspace_already_connected', null, 'Support triage'),
- ).toMatchObject({ description: 'Use your own Slack app for this agent.' })
+ ).toMatchObject({
+ description:
+ 'Connect a different workspace or use your own Slack app for this agent.',
+ })
+ })
+
+ it('states the impact before moving a workspace between agents', () => {
+ expect(
+ managedSlackDisconnectCopy(
+ {
+ mode: 'managed',
+ status: 'active',
+ workspace: { id: 'T1', name: 'Acme' },
+ app: { id: 'A1', handle: 'OpenComputer' },
+ connected_at: '2026-07-16T18:00:00Z',
+ agent: {
+ id: 'agt_bbbbbbbbbbbbbbbbbbbbbbbb',
+ name: 'Docs writer',
+ },
+ },
+ 'Support triage',
+ ),
+ ).toEqual({
+ title: 'Disconnect Acme from Docs writer?',
+ description:
+ 'New Slack messages from Acme will stop going to Docs writer. The agent and its existing sessions stay available, and the OpenComputer app stays installed. After disconnecting, connect Slack again and select this workspace for Support triage.',
+ })
})
})
diff --git a/web/src/components/slack-connect.tsx b/web/src/components/slack-connect.tsx
index 625df131..07190a1a 100644
--- a/web/src/components/slack-connect.tsx
+++ b/web/src/components/slack-connect.tsx
@@ -33,9 +33,11 @@ import {
} from '@/components/ui/dialog'
import { Field, Input } from '@/components/form'
import { ConfirmDialog } from '@/components/confirm-dialog'
+import { ManagedSlackWorkspaceClaims } from '@/components/managed-slack-workspace-claims'
import { useTransientFlag } from '@/lib/use-transient-flag'
import { cn } from '@/lib/utils'
import { managedSlackNotice } from '@/lib/managed-slack-notice'
+import { useManagedSlackConnections } from '@/lib/managed-slack-connections'
// An agent connects its OWN Slack app (BYO, 1:1:1). Connect is a two-step,
// manifest-route wizard (oc-bg-agents/.agents/design/008-slack-presence.md §2):
@@ -131,6 +133,7 @@ export function SlackConnect({
queryKey: ['slack', 'managed', agentId],
queryFn: () => getManagedSlackConnection(agentId),
})
+ const managedConnectionsQuery = useManagedSlackConnections(!!agentId)
// Wizard state.
const [open, setOpen] = useState(false)
@@ -239,6 +242,15 @@ export function SlackConnect({
managed?.status === 'error' || managed?.status === 'revoked'
const managedDisconnected = managed?.status === 'disconnected'
const managedWorkspace = managed?.workspace?.name || managed?.workspace?.id
+ const hasOtherManagedConnections =
+ managedConnectionsQuery.data?.some(
+ (connection) => connection.agent.id !== agentId,
+ ) ?? false
+ const checkingManagedConnections =
+ !managedActive &&
+ !managedNeedsReconnect &&
+ !managedDisconnected &&
+ managedConnectionsQuery.isLoading
const oauthResult = searchParams.get('slack')
const connectedAgentId = searchParams.get('connected_agent')
const sameOwnerConnectedAgentId =
@@ -431,14 +443,26 @@ export function SlackConnect({
Anyone in this Slack workspace who can message the app can use
this agent.
</p>
+ <ManagedSlackWorkspaceClaims
+ currentAgentId={agentId}
+ currentAgentName={agentName}
+ query={managedConnectionsQuery}
+ />
<Button
size="sm"
onClick={() => authorizeManagedMutation.mutate()}
- disabled={authorizeManagedMutation.isPending}
+ disabled={
+ authorizeManagedMutation.isPending ||
+ checkingManagedConnections
+ }
>
- {authorizeManagedMutation.isPending
- ? 'Connecting…'
- : 'Connect OpenComputer Slack'}
+ {checkingManagedConnections
+ ? 'Checking Slack…'
+ : authorizeManagedMutation.isPending
+ ? 'Connecting…'
+ : hasOtherManagedConnections
+ ? 'Connect another workspace'
+ : 'Connect OpenComputer Slack'}
</Button>
</div>
)}
diff --git a/web/src/lib/managed-slack-connections.ts b/web/src/lib/managed-slack-connections.ts
new file mode 100644
index 00000000..d73b7105
--- /dev/null
+++ b/web/src/lib/managed-slack-connections.ts
@@ -0,0 +1,32 @@
+import { useQuery } from '@tanstack/react-query'
+import {
+ getManagedSlackConnections,
+ type ManagedSlackWorkspaceConnection,
+} from '@/api/client'
+
+export const managedSlackConnectionsQueryKey = [
+ 'slack',
+ 'managed',
+ 'connections',
+] as const
+
+export function useManagedSlackConnections(enabled = true) {
+ return useQuery({
+ queryKey: managedSlackConnectionsQueryKey,
+ queryFn: getManagedSlackConnections,
+ enabled,
+ refetchOnWindowFocus: 'always',
+ })
+}
+
+export function managedSlackDisconnectCopy(
+ connection: ManagedSlackWorkspaceConnection,
+ nextAgentName: string,
+) {
+ const workspace = connection.workspace?.name || connection.workspace?.id
+ const workspaceLabel = workspace || 'this Slack workspace'
+ return {
+ title: `Disconnect ${workspaceLabel} from ${connection.agent.name}?`,
+ description: `New Slack messages from ${workspaceLabel} will stop going to ${connection.agent.name}. The agent and its existing sessions stay available, and the OpenComputer app stays installed. After disconnecting, connect Slack again and select this workspace for ${nextAgentName}.`,
+ }
+}
diff --git a/web/src/lib/managed-slack-notice.ts b/web/src/lib/managed-slack-notice.ts
index 8877ae8d..84029f8d 100644
--- a/web/src/lib/managed-slack-notice.ts
+++ b/web/src/lib/managed-slack-notice.ts
@@ -57,8 +57,8 @@ export function managedSlackNotice(
return {
title: 'This Slack workspace is already connected',
description: connectedAgentName
- ? `This workspace sends messages to ${connectedAgentName}.`
- : 'Use your own Slack app for this agent.',
+ ? `This workspace sends messages to ${connectedAgentName}. Disconnect it below before connecting it to ${agentName}.`
+ : 'Connect a different workspace or use your own Slack app for this agent.',
destructive: true,
}
case 'oauth_exchange_failed':
diff --git a/web/src/pages/AgentDeployment.tsx b/web/src/pages/AgentDeployment.tsx
index 37de3fb8..10449dce 100644
--- a/web/src/pages/AgentDeployment.tsx
+++ b/web/src/pages/AgentDeployment.tsx
@@ -35,6 +35,7 @@ import {
DeploymentPhases,
} from '@/components/deployment-progress'
import { SourceProfileChangedRecovery } from '@/components/source-profile-changed-recovery'
+import { ManagedSlackWorkspaceClaims } from '@/components/managed-slack-workspace-claims'
import {
Panel,
PanelContent,
@@ -50,6 +51,7 @@ import {
} from '@/lib/deployment-slack-cta'
import { notifyError, notifySuccess } from '@/lib/errors'
import { managedSlackNotice } from '@/lib/managed-slack-notice'
+import { useManagedSlackConnections } from '@/lib/managed-slack-connections'
import { cn } from '@/lib/utils'
import { useAgentDeploymentLogs } from '@/hooks/use-agent-deployment-logs'
@@ -168,6 +170,7 @@ export default function AgentDeployment() {
enabled: !!agentId,
refetchOnWindowFocus: 'always',
})
+ const managedSlackConnectionsQuery = useManagedSlackConnections(!!agentId)
const oauthResult = searchParams.get('slack')
const connectedAgentId = searchParams.get('connected_agent')
const sameOwnerConnectedAgentId =
@@ -326,6 +329,13 @@ export default function AgentDeployment() {
connectedAgentQuery.data && sameOwnerConnectedAgentId
? `/agents/${encodeURIComponent(sameOwnerConnectedAgentId)}`
: null
+ const hasOtherManagedSlackConnections =
+ managedSlackConnectionsQuery.data?.some(
+ (connection) => connection.agent.id !== agentId,
+ ) ?? false
+ const checkingManagedSlackConnections =
+ slackPresentation.action === 'connect' &&
+ managedSlackConnectionsQuery.isLoading
const dismissSlackNotice = () => {
const next = new URLSearchParams(searchParams)
next.delete('slack')
@@ -445,10 +455,18 @@ export default function AgentDeployment() {
slackPresentation.action === 'connecting' ? (
<Button
size="sm"
- disabled={authorizeManagedSlackMutation.isPending}
+ disabled={
+ authorizeManagedSlackMutation.isPending ||
+ checkingManagedSlackConnections
+ }
onClick={() => authorizeManagedSlackMutation.mutate()}
>
- {slackPresentation.label}
+ {checkingManagedSlackConnections
+ ? 'Checking Slack…'
+ : slackPresentation.action === 'connect' &&
+ hasOtherManagedSlackConnections
+ ? 'Connect another workspace'
+ : slackPresentation.label}
</Button>
) : null}
</div>
@@ -499,6 +517,19 @@ export default function AgentDeployment() {
</Alert>
) : null}
+ {slackPresentation.action === 'connect' && agent ? (
+ <Panel>
+ <PanelContent>
+ <ManagedSlackWorkspaceClaims
+ currentAgentId={agentId}
+ currentAgentName={agent.name}
+ query={managedSlackConnectionsQuery}
+ className="border-t-0 pt-0"
+ />
+ </PanelContent>
+ </Panel>
+ ) : null}
+
{deployLatestMutation.isError ? (
<Alert variant="destructive">
<CircleAlert className="size-4" />
diff --git a/web/src/pages/AgentSetup.tsx b/web/src/pages/AgentSetup.tsx
index ef8551c0..224546fa 100644
--- a/web/src/pages/AgentSetup.tsx
+++ b/web/src/pages/AgentSetup.tsx
@@ -33,6 +33,7 @@ import {
} from '@/components/panel'
import { StatusBadge } from '@/components/status-badge'
import { MessageBubble } from '@/components/session-conversation'
+import { ManagedSlackWorkspaceClaims } from '@/components/managed-slack-workspace-claims'
import {
Alert,
AlertAction,
@@ -54,6 +55,7 @@ import {
import { deploymentStage } from '@/lib/deployment-slack-cta'
import { notifyError } from '@/lib/errors'
import { managedSlackNotice } from '@/lib/managed-slack-notice'
+import { useManagedSlackConnections } from '@/lib/managed-slack-connections'
import { latestManagedSlackSession } from '@/lib/managed-slack-session'
import {
bodyText,
@@ -147,6 +149,7 @@ export default function AgentSetup() {
: false,
refetchOnWindowFocus: 'always',
})
+ const managedSlackConnectionsQuery = useManagedSlackConnections(!!agentId)
const connectedAgentQuery = useQuery({
queryKey: ['agent', sameOwnerConnectedAgentId],
queryFn: () => getAgent(sameOwnerConnectedAgentId!),
@@ -279,6 +282,12 @@ export default function AgentSetup() {
connecting: authorizeManagedSlackMutation.isPending,
activated: !!activationSession,
})
+ const hasOtherManagedSlackConnections =
+ managedSlackConnectionsQuery.data?.some(
+ (connection) => connection.agent.id !== agentId,
+ ) ?? false
+ const checkingManagedSlackConnections =
+ presentation.action === 'connect' && managedSlackConnectionsQuery.isLoading
const managedWorkspace =
managedSlack?.workspace?.name ?? managedSlack?.workspace?.id
const waitingForConnectedState =
@@ -405,32 +414,57 @@ export default function AgentSetup() {
{presentation.description}
</p>
+ {presentation.action === 'connect' ? (
+ <ManagedSlackWorkspaceClaims
+ currentAgentId={agentId}
+ currentAgentName={agent.name}
+ query={managedSlackConnectionsQuery}
+ className="mt-4"
+ />
+ ) : null}
+
<div className="mt-4 flex flex-wrap items-center gap-3">
{presentation.action === 'open' && managedSlack?.open_url ? (
- <Button asChild>
- <a
- href={managedSlack.open_url}
- target="_blank"
- rel="noreferrer"
- >
- {presentation.label}
- <ExternalLink className="size-4" />
- </a>
- </Button>
+ <>
+ <Button asChild>
+ <a
+ href={managedSlack.open_url}
+ target="_blank"
+ rel="noreferrer"
+ >
+ {presentation.label}
+ <ExternalLink className="size-4" />
+ </a>
+ </Button>
+ {activationSession ? (
+ <Button variant="outline" asChild>
+ <Link to={`/agents/${agentId}`}>View agent</Link>
+ </Button>
+ ) : null}
+ </>
) : presentation.action === 'connect' ||
presentation.action === 'reconnect' ||
presentation.action === 'connecting' ? (
<Button
- disabled={authorizeManagedSlackMutation.isPending}
+ disabled={
+ authorizeManagedSlackMutation.isPending ||
+ checkingManagedSlackConnections
+ }
onClick={() => authorizeManagedSlackMutation.mutate()}
>
- {authorizeManagedSlackMutation.isPending ? (
+ {authorizeManagedSlackMutation.isPending ||
+ checkingManagedSlackConnections ? (
<Loader2
className="size-4 animate-spin motion-reduce:animate-none"
aria-hidden
/>
) : null}
- {presentation.label}
+ {checkingManagedSlackConnections
+ ? 'Checking Slack…'
+ : presentation.action === 'connect' &&
+ hasOtherManagedSlackConnections
+ ? 'Connect another workspace'
+ : presentation.label}
</Button>
) : stage === 'failed' && deploymentHref ? (
<Button asChild>
diff --git a/web/src/pages/agent-deployment-slack.test.tsx b/web/src/pages/agent-deployment-slack.test.tsx
index 33b3e78c..5ba00b64 100644
--- a/web/src/pages/agent-deployment-slack.test.tsx
+++ b/web/src/pages/agent-deployment-slack.test.tsx
@@ -4,6 +4,7 @@ import { MemoryRouter, Route, Routes } from 'react-router-dom'
import { describe, expect, it } from 'vitest'
import type { AgentDeployment as AgentDeploymentRecord } from '@/api/client'
import AgentDeployment from './AgentDeployment'
+import { managedSlackConnectionsQueryKey } from '@/lib/managed-slack-connections'
const agentId = 'agt_aaaaaaaaaaaaaaaaaaaaaaaa'
const deploymentId = 'dep_aaaaaaaaaaaaaaaaaaaaaaaa'
@@ -65,6 +66,7 @@ function renderDeployment(
managed: Record<string, unknown> | null | undefined,
search = '',
connectedAgentName?: string,
+ managedConnections: Array<Record<string, unknown>> = [],
) {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
@@ -84,6 +86,7 @@ function renderDeployment(
if (managed !== undefined) {
queryClient.setQueryData(['slack', 'managed', agentId], managed)
}
+ queryClient.setQueryData(managedSlackConnectionsQueryKey, managedConnections)
if (connectedAgentName) {
queryClient.setQueryData(['agent', connectedAgentId], {
id: connectedAgentId,
@@ -148,7 +151,26 @@ describe('deployment managed Slack composition', () => {
null,
'?slack=workspace_already_connected&connected_agent=agt_not-an-id',
)
- expect(malformed).toContain('Use your own Slack app for this agent.')
+ expect(malformed).toContain(
+ 'Connect a different workspace or use your own Slack app for this agent.',
+ )
expect(malformed).not.toContain('Open connected agent')
})
+
+ it('surfaces a known workspace claim before starting OAuth', () => {
+ const markup = renderDeployment(null, '', undefined, [
+ {
+ mode: 'managed',
+ status: 'active',
+ workspace: { id: 'T1', name: 'Acme' },
+ app: { id: 'A1', handle: 'OpenComputer' },
+ connected_at: '2026-07-16T18:00:00Z',
+ agent: { id: connectedAgentId, name: 'Docs writer' },
+ },
+ ])
+
+ expect(markup).toContain('Slack workspaces already in use')
+ expect(markup).toContain('Sends messages to Docs writer')
+ expect(markup).toContain('Connect another workspace')
+ })
})
diff --git a/web/src/pages/agent-setup.test.tsx b/web/src/pages/agent-setup.test.tsx
index 403536fc..fc13020c 100644
--- a/web/src/pages/agent-setup.test.tsx
+++ b/web/src/pages/agent-setup.test.tsx
@@ -2,7 +2,13 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { renderToStaticMarkup } from 'react-dom/server'
import { MemoryRouter, Route, Routes } from 'react-router-dom'
import { describe, expect, it } from 'vitest'
-import type { AgentDeployment, Session, SessionEvent } from '@/api/client'
+import type {
+ AgentDeployment,
+ ManagedSlackWorkspaceConnection,
+ Session,
+ SessionEvent,
+} from '@/api/client'
+import { managedSlackConnectionsQueryKey } from '@/lib/managed-slack-connections'
import AgentSetup from './AgentSetup'
const agentId = 'agt_aaaaaaaaaaaaaaaaaaaaaaaa'
@@ -61,8 +67,8 @@ const buildingDeployment: AgentDeployment = {
}
const activeSlack = {
- mode: 'managed',
- status: 'active',
+ mode: 'managed' as const,
+ status: 'active' as const,
workspace: { id: 'T1', name: 'Acme' },
app: { id: 'A1', handle: 'OpenComputer' },
open_url: 'https://slack.com/app_redirect?app=A1&team=T1',
@@ -76,6 +82,7 @@ function renderSetup(input: {
agent?: Record<string, unknown>
sessions?: Session[]
events?: { sessionId: string; data: SessionEvent[] }
+ managedConnections?: ManagedSlackWorkspaceConnection[]
}) {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
@@ -99,6 +106,10 @@ function renderSetup(input: {
if ('managed' in input) {
queryClient.setQueryData(['slack', 'managed', agentId], input.managed)
}
+ queryClient.setQueryData(
+ managedSlackConnectionsQueryKey,
+ input.managedConnections ?? [],
+ )
if (input.sessions) {
queryClient.setQueryData(
[
@@ -225,6 +236,29 @@ describe('agent setup', () => {
expect(markup).toContain('Hello! Your agent is ready.')
expect(markup).toContain(`href="/sessions/${sessionId}"`)
expect(markup).toContain(`href="/agents/${agentId}/sessions"`)
+ expect(markup).toContain(`href="/agents/${agentId}"`)
+ expect(markup).toContain('>View agent<')
+ })
+
+ it('shows an existing workspace claim before OAuth', () => {
+ const connectedAgentId = 'agt_bbbbbbbbbbbbbbbbbbbbbbbb'
+ const markup = renderSetup({
+ deployment: buildingDeployment,
+ managed: null,
+ managedConnections: [
+ {
+ ...activeSlack,
+ agent: { id: connectedAgentId, name: 'Docs writer' },
+ },
+ ],
+ search: `?deployment=${deploymentId}`,
+ })
+
+ expect(markup).toContain('Slack workspaces already in use')
+ expect(markup).toContain('Sends messages to Docs writer')
+ expect(markup).toContain(`href="/agents/${connectedAgentId}"`)
+ expect(markup).toContain('>Disconnect</button>')
+ expect(markup).toContain('>Connect another workspace</button>')
})
it('uses the same activation flow for a manually created agent', () => {