Skip to content

An open-source, faster Devin alternative

TypeScript

feat(agents): compose deployment and Slack onboarding

Igor Zalutskidc67a021a431
diff --git a/web/src/lib/deployment-slack-cta.test.ts b/web/src/lib/deployment-slack-cta.test.ts
new file mode 100644
index 00000000..e8c0cc8e
--- /dev/null
+++ b/web/src/lib/deployment-slack-cta.test.ts
@@ -0,0 +1,104 @@
+import { describe, expect, it } from 'vitest'
+import {
+ deploymentSlackPresentation,
+ deploymentStage,
+} from '@/lib/deployment-slack-cta'
+
+function presentation(
+ patch: Partial<Parameters<typeof deploymentSlackPresentation>[0]> = {},
+) {
+ return deploymentSlackPresentation({
+ deploymentState: 'building',
+ deploymentTerminal: false,
+ managedStatus: null,
+ openUrl: null,
+ connecting: false,
+ ...patch,
+ })
+}
+
+describe('deployment and managed Slack composition', () => {
+ it('derives running, ready, and failed from deployment truth', () => {
+ expect(deploymentStage('building', false)).toBe('running')
+ expect(deploymentStage('ready', true)).toBe('ready')
+ expect(deploymentStage('failed', true)).toBe('failed')
+ })
+
+ it('offers Slack setup immediately while a deployment runs', () => {
+ expect(presentation()).toMatchObject({
+ action: 'connect',
+ label: 'Connect Slack',
+ disclosure: true,
+ })
+ expect(presentation({ connecting: true })).toMatchObject({
+ action: 'connecting',
+ label: 'Connecting…',
+ })
+ })
+
+ it('keeps an active connection quiet until the deployment is ready', () => {
+ expect(presentation({ managedStatus: 'active' })).toMatchObject({
+ action: null,
+ status: 'Slack connected. Open Slack when this deployment is ready.',
+ })
+ })
+
+ it('promotes Open Slack only when ready and active', () => {
+ expect(
+ presentation({
+ deploymentState: 'ready',
+ deploymentTerminal: true,
+ managedStatus: 'active',
+ openUrl: 'https://slack.com/app_redirect?app=A123',
+ }),
+ ).toMatchObject({
+ action: 'open',
+ label: 'Open Slack',
+ announcement: 'Deployment ready. Open Slack is now available.',
+ })
+ })
+
+ it('offers setup from ready and keeps dashboard chat secondary', () => {
+ expect(
+ presentation({
+ deploymentState: 'ready',
+ deploymentTerminal: true,
+ }),
+ ).toMatchObject({ action: 'connect', label: 'Connect Slack' })
+ })
+
+ it('makes deployment recovery primary after failure', () => {
+ expect(
+ presentation({
+ deploymentState: 'failed',
+ deploymentTerminal: true,
+ }),
+ ).toMatchObject({ action: null, status: null })
+ expect(
+ presentation({
+ deploymentState: 'failed',
+ deploymentTerminal: true,
+ managedStatus: 'active',
+ }),
+ ).toMatchObject({
+ action: null,
+ status: 'Slack remains connected while you fix this deployment.',
+ })
+ })
+
+ it('does not mistake loading for a never-connected result', () => {
+ expect(presentation({ managedStatus: undefined })).toMatchObject({
+ action: null,
+ label: null,
+ })
+ })
+
+ it('keeps reconnect a connector-local action', () => {
+ for (const managedStatus of ['disconnected', 'error', 'revoked'] as const) {
+ expect(presentation({ managedStatus })).toMatchObject({
+ action: 'reconnect',
+ label: 'Reconnect Slack',
+ })
+ }
+ })
+})
diff --git a/web/src/lib/deployment-slack-cta.ts b/web/src/lib/deployment-slack-cta.ts
new file mode 100644
index 00000000..b1e1f2fc
--- /dev/null
+++ b/web/src/lib/deployment-slack-cta.ts
@@ -0,0 +1,130 @@
+export type ManagedSlackStatus =
+ | 'active'
+ | 'disconnected'
+ | 'error'
+ | 'revoked'
+ | null
+ | undefined
+
+export type DeploymentSlackAction =
+ | 'connect'
+ | 'connecting'
+ | 'reconnect'
+ | 'open'
+ | null
+
+export interface DeploymentSlackPresentation {
+ action: DeploymentSlackAction
+ label: string | null
+ disclosure: boolean
+ status: string | null
+ announcement: string
+}
+
+export function deploymentStage(
+ state: string,
+ terminal: boolean,
+): 'running' | 'ready' | 'failed' {
+ if (state === 'ready') return 'ready'
+ return terminal ? 'failed' : 'running'
+}
+
+/**
+ * Compose two independent resources without inventing a combined backend
+ * state: durable deployment readiness and the managed Slack connection.
+ * `undefined` means the connection query has not produced a trustworthy result;
+ * `null` is the durable "never connected" result.
+ */
+export function deploymentSlackPresentation(input: {
+ deploymentState: string
+ deploymentTerminal: boolean
+ managedStatus: ManagedSlackStatus
+ openUrl?: string | null
+ connecting: boolean
+}): DeploymentSlackPresentation {
+ const stage = deploymentStage(input.deploymentState, input.deploymentTerminal)
+
+ if (stage === 'failed') {
+ return {
+ action: null,
+ label: null,
+ disclosure: false,
+ status:
+ input.managedStatus === 'active'
+ ? 'Slack remains connected while you fix this deployment.'
+ : null,
+ announcement:
+ input.managedStatus === 'active'
+ ? 'Deployment failed. Slack remains connected.'
+ : 'Deployment failed.',
+ }
+ }
+
+ if (input.managedStatus === undefined) {
+ return {
+ action: null,
+ label: null,
+ disclosure: false,
+ status: null,
+ announcement: '',
+ }
+ }
+
+ if (input.managedStatus === 'active') {
+ if (stage === 'ready' && input.openUrl) {
+ return {
+ action: 'open',
+ label: 'Open Slack',
+ disclosure: false,
+ status: null,
+ announcement: 'Deployment ready. Open Slack is now available.',
+ }
+ }
+ return {
+ action: null,
+ label: null,
+ disclosure: false,
+ status:
+ stage === 'running'
+ ? 'Slack connected. Open Slack when this deployment is ready.'
+ : 'Slack is connected.',
+ announcement:
+ stage === 'running'
+ ? 'Slack connected. Open Slack will be available when the deployment is ready.'
+ : 'Slack connected.',
+ }
+ }
+
+ const reconnect =
+ input.managedStatus === 'disconnected' ||
+ input.managedStatus === 'error' ||
+ input.managedStatus === 'revoked'
+
+ if (input.connecting) {
+ return {
+ action: 'connecting',
+ label: 'Connecting…',
+ disclosure: input.managedStatus === null,
+ status: null,
+ announcement: 'Opening Slack authorization.',
+ }
+ }
+
+ if (reconnect) {
+ return {
+ action: 'reconnect',
+ label: 'Reconnect Slack',
+ disclosure: false,
+ status: 'The OpenComputer Slack app needs authorization.',
+ announcement: 'The Slack connection needs authorization.',
+ }
+ }
+
+ return {
+ action: 'connect',
+ label: 'Connect Slack',
+ disclosure: true,
+ status: null,
+ announcement: 'Connect Slack while the deployment continues.',
+ }
+}
diff --git a/web/src/pages/AgentDeployment.tsx b/web/src/pages/AgentDeployment.tsx
index 00c89efc..990c0740 100644
--- a/web/src/pages/AgentDeployment.tsx
+++ b/web/src/pages/AgentDeployment.tsx
@@ -1,6 +1,6 @@
import { Fragment, useEffect, useRef } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
-import { Link, useNavigate, useParams } from 'react-router-dom'
+import { Link, useNavigate, useParams, useSearchParams } from 'react-router-dom'
import {
ArrowLeft,
ArrowRight,
@@ -12,17 +12,25 @@ import {
GitCommitHorizontal,
Loader2,
RotateCw,
+ X,
} from 'lucide-react'
import {
ApiError,
+ authorizeManagedSlack,
deployFromGithub,
getAgent,
getAgentDeployment,
getAgentDeploymentLogs,
+ getManagedSlackConnection,
type AgentDeployment,
type AgentDeploymentLog,
} from '@/api/client'
-import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
+import {
+ Alert,
+ AlertAction,
+ AlertDescription,
+ AlertTitle,
+} from '@/components/ui/alert'
import { Button } from '@/components/ui/button'
import { Skeleton } from '@/components/ui/skeleton'
import {
@@ -34,6 +42,12 @@ import {
} from '@/components/panel'
import { StatusBadge } from '@/components/status-badge'
import { agentDeploymentOutcome } from '@/lib/agent-deployment-outcome'
+import {
+ deploymentSlackPresentation,
+ deploymentStage,
+} from '@/lib/deployment-slack-cta'
+import { notifyError } from '@/lib/errors'
+import { managedSlackNotice } from '@/lib/managed-slack-notice'
import { cn } from '@/lib/utils'
const PHASES = [
@@ -320,6 +334,7 @@ function DeploymentLog({
export default function AgentDeployment() {
const { agentId = '', deploymentId = '' } = useParams()
const navigate = useNavigate()
+ const [searchParams, setSearchParams] = useSearchParams()
const queryClient = useQueryClient()
const deployCommand = useRef<DeployCommand | null>(null)
const deployCommandStorage = `${DEPLOY_COMMAND_STORAGE}:${agentId}`
@@ -334,6 +349,12 @@ export default function AgentDeployment() {
queryFn: () => getAgent(agentId),
enabled: !!agentId,
})
+ const managedSlackQuery = useQuery({
+ queryKey: ['slack', 'managed', agentId],
+ queryFn: () => getManagedSlackConnection(agentId),
+ enabled: !!agentId,
+ refetchOnWindowFocus: 'always',
+ })
const logQueryKey = ['agent-deployment-logs', agentId, deploymentId] as const
const logsQuery = useQuery({
queryKey: logQueryKey,
@@ -387,6 +408,14 @@ export default function AgentDeployment() {
void navigate(`/agents/${agentId}/deployments/${deployment.id}`)
},
})
+ const authorizeManagedSlackMutation = useMutation({
+ mutationFn: () => authorizeManagedSlack(agentId, deploymentId),
+ onSuccess: ({ authorize_url }) => {
+ window.location.assign(authorize_url)
+ },
+ onError: (error) =>
+ notifyError("Couldn't start the Slack connection.", error),
+ })
const terminal = deploymentQuery.data?.terminal ?? false
const refetchLogs = logsQuery.refetch
@@ -428,12 +457,48 @@ export default function AgentDeployment() {
const deployment = deploymentQuery.data
const outcome = agentDeploymentOutcome(deployment)
+ const managedSlack = managedSlackQuery.data
+ const managedSlackStatus = managedSlackQuery.isSuccess
+ ? (managedSlack?.status ?? null)
+ : undefined
+ const slackPresentation = deploymentSlackPresentation({
+ deploymentState: deployment.state,
+ deploymentTerminal: deployment.terminal,
+ managedStatus: managedSlackStatus,
+ openUrl: managedSlack?.open_url,
+ connecting: authorizeManagedSlackMutation.isPending,
+ })
+ const stage = deploymentStage(deployment.state, deployment.terminal)
+ const oauthResult = searchParams.get('slack')
+ const connectedAgentId = searchParams.get('connected_agent')
+ const managedWorkspace =
+ managedSlack?.workspace?.name ?? managedSlack?.workspace?.id
+ const slackNotice = managedSlackNotice(
+ oauthResult,
+ managedWorkspace,
+ agent?.name ?? 'this agent',
+ )
+ const connectedAgentHref =
+ oauthResult === 'workspace_already_connected' &&
+ connectedAgentId?.startsWith('agt_')
+ ? `/agents/${encodeURIComponent(connectedAgentId)}`
+ : null
+ const dismissSlackNotice = () => {
+ const next = new URLSearchParams(searchParams)
+ next.delete('slack')
+ next.delete('connected_agent')
+ setSearchParams(next, { replace: true })
+ }
const commitUrl = deployment.source_relation?.commit_url ?? undefined
const canViewCommit =
deployment.allowed_actions.includes('view_commit') && !!commitUrl
const canOpenAgent = deployment.allowed_actions.includes('open_agent')
- const canStartSession = deployment.allowed_actions.includes('start_session')
- const canDeployLatest = deployment.allowed_actions.includes('deploy_latest')
+ const canStartSession =
+ stage === 'ready' && deployment.allowed_actions.includes('start_session')
+ // Keep routine ready/running pages focused on first use. Redeploy is the
+ // recovery action here; ordinary source management remains on the agent.
+ const canDeployLatest =
+ stage === 'failed' && deployment.allowed_actions.includes('deploy_latest')
const deployLatestFingerprint = JSON.stringify({
agent_id: agentId,
repo_id: deployment.source_relation?.repo?.id ?? null,
@@ -468,54 +533,124 @@ export default function AgentDeployment() {
{deployment.id}
</p>
</div>
- <div className="flex flex-wrap gap-2">
- {canViewCommit ? (
- <Button variant="outline" size="sm" asChild>
- <a href={commitUrl} target="_blank" rel="noreferrer">
- <GitCommitHorizontal className="size-4" />
- View commit
- <ExternalLink className="size-3.5" />
- </a>
- </Button>
- ) : null}
- {canOpenAgent ? (
- <Button variant="outline" size="sm" asChild>
- <Link to={`/agents/${agentId}`}>Open agent</Link>
- </Button>
- ) : null}
- {canDeployLatest ? (
- <Button
- size="sm"
- variant={canStartSession ? 'outline' : 'default'}
- disabled={deployLatestMutation.isPending}
- onClick={() =>
- deployLatestMutation.mutate(deployLatestFingerprint)
- }
- >
- <RotateCw
- className={cn(
- 'size-4',
- deployLatestMutation.isPending &&
- 'animate-spin motion-reduce:animate-none',
- )}
- />
- {deployLatestMutation.isPending
- ? 'Starting deployment…'
- : 'Deploy latest'}
- </Button>
- ) : null}
- {canStartSession ? (
- <Button size="sm" asChild>
- <Link to={`/agents/${agentId}/sessions`}>
- Start session
- <ArrowRight className="size-4" />
- </Link>
- </Button>
+ <div className="flex max-w-xl flex-col gap-1.5 sm:items-end">
+ <span className="sr-only" aria-live="polite" aria-atomic="true">
+ {slackPresentation.announcement}
+ </span>
+ <div className="flex flex-wrap gap-2 sm:justify-end">
+ {canViewCommit ? (
+ <Button variant="outline" size="sm" asChild>
+ <a href={commitUrl} target="_blank" rel="noreferrer">
+ <GitCommitHorizontal className="size-4" />
+ View commit
+ <ExternalLink className="size-3.5" />
+ </a>
+ </Button>
+ ) : null}
+ {canOpenAgent ? (
+ <Button variant="outline" size="sm" asChild>
+ <Link to={`/agents/${agentId}`}>Open agent</Link>
+ </Button>
+ ) : null}
+ {canStartSession ? (
+ <Button variant="outline" size="sm" asChild>
+ <Link to={`/agents/${agentId}/sessions`}>
+ Start session
+ <ArrowRight className="size-4" />
+ </Link>
+ </Button>
+ ) : null}
+ {canDeployLatest ? (
+ <Button
+ size="sm"
+ variant={stage === 'failed' ? 'default' : 'outline'}
+ disabled={deployLatestMutation.isPending}
+ onClick={() =>
+ deployLatestMutation.mutate(deployLatestFingerprint)
+ }
+ >
+ <RotateCw
+ className={cn(
+ 'size-4',
+ deployLatestMutation.isPending &&
+ 'animate-spin motion-reduce:animate-none',
+ )}
+ />
+ {deployLatestMutation.isPending
+ ? 'Starting deployment…'
+ : 'Deploy latest'}
+ </Button>
+ ) : null}
+ {slackPresentation.action === 'open' && managedSlack?.open_url ? (
+ <Button size="sm" asChild>
+ <a
+ href={managedSlack.open_url}
+ target="_blank"
+ rel="noreferrer"
+ >
+ Open Slack
+ <ExternalLink className="size-3.5" />
+ </a>
+ </Button>
+ ) : slackPresentation.action === 'connect' ||
+ slackPresentation.action === 'reconnect' ||
+ slackPresentation.action === 'connecting' ? (
+ <Button
+ size="sm"
+ disabled={authorizeManagedSlackMutation.isPending}
+ onClick={() => authorizeManagedSlackMutation.mutate()}
+ >
+ {slackPresentation.label}
+ </Button>
+ ) : null}
+ </div>
+ {slackPresentation.disclosure ? (
+ <p className="text-muted-foreground max-w-sm text-xs leading-relaxed sm:text-right">
+ Anyone in this Slack workspace who can message the app can use
+ this agent.
+ </p>
+ ) : managedSlackQuery.isError && stage !== 'failed' ? (
+ <div className="flex items-center gap-2 text-xs">
+ <span className="text-status-error">
+ Slack status is unavailable.
+ </span>
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => void managedSlackQuery.refetch()}
+ >
+ Retry
+ </Button>
+ </div>
) : null}
</div>
</div>
</div>
+ {slackNotice ? (
+ <Alert variant={slackNotice.destructive ? 'destructive' : 'default'}>
+ <AlertTitle>{slackNotice.title}</AlertTitle>
+ {slackNotice.description || connectedAgentHref ? (
+ <AlertDescription>
+ {slackNotice.description}{' '}
+ {connectedAgentHref ? (
+ <Link to={connectedAgentHref}>Open connected agent</Link>
+ ) : null}
+ </AlertDescription>
+ ) : null}
+ <AlertAction>
+ <Button
+ size="icon-sm"
+ variant="ghost"
+ aria-label="Dismiss Slack notice"
+ onClick={dismissSlackNotice}
+ >
+ <X aria-hidden />
+ </Button>
+ </AlertAction>
+ </Alert>
+ ) : null}
+
{deployLatestMutation.isError ? (
<Alert variant="destructive">
<CircleAlert className="size-4" />
@@ -552,7 +687,14 @@ export default function AgentDeployment() {
) : null}
</PanelDescription>
</div>
- <DeploymentPhases deployment={deployment} />
+ <div className="space-y-1.5 sm:text-right">
+ <DeploymentPhases deployment={deployment} />
+ {slackPresentation.status ? (
+ <p className="text-muted-foreground text-xs">
+ {slackPresentation.status}
+ </p>
+ ) : null}
+ </div>
</PanelHeader>
<PanelContent className="space-y-3">
<OutcomeDetail deployment={deployment} />