Skip to content

An open-source, faster Devin alternative

TypeScript

fix(web): gate repository deploy creation

Igor Zalutskia08dafc9f70d
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 296b9d18..180aac89 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -34,6 +34,7 @@ export type {
AgentDeploy,
AgentDeployment,
AgentDeploymentLog,
+ DeployApp,
FlueSourceInspection,
Session,
AgentSnapshot,
diff --git a/web/src/api/deploy-app-client.test.ts b/web/src/api/deploy-app-client.test.ts
new file mode 100644
index 00000000..f1d22906
--- /dev/null
+++ b/web/src/api/deploy-app-client.test.ts
@@ -0,0 +1,46 @@
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { getDeployApp } from './client'
+
+const deployAppResponse = {
+ installed: false,
+ install_url: null,
+ configure_url: null,
+ account: null,
+ repository_selection: null,
+ repositories: [],
+}
+
+afterEach(() => {
+ vi.unstubAllGlobals()
+})
+
+describe('deploy app client', () => {
+ it('preserves an explicit repository-deploy availability grant', async () => {
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(() =>
+ Promise.resolve(
+ Response.json({
+ ...deployAppResponse,
+ repository_deploys_available: true,
+ }),
+ ),
+ ),
+ )
+
+ await expect(getDeployApp()).resolves.toMatchObject({
+ repository_deploys_available: true,
+ })
+ })
+
+ it('fails closed when an older response omits availability', async () => {
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(() => Promise.resolve(Response.json(deployAppResponse))),
+ )
+
+ await expect(getDeployApp()).resolves.toMatchObject({
+ repository_deploys_available: false,
+ })
+ })
+})
diff --git a/web/src/api/deployment-schemas.test.ts b/web/src/api/deployment-schemas.test.ts
index 5c8677cf..59e20fd0 100644
--- a/web/src/api/deployment-schemas.test.ts
+++ b/web/src/api/deployment-schemas.test.ts
@@ -143,6 +143,7 @@ describe('repository deployment API schemas', () => {
it('filters repositories without a registered import coordinate safely', () => {
const parsed = DeployAppSchema.parse({
+ repository_deploys_available: true,
installed: true,
install_url: null,
configure_url: null,
@@ -159,6 +160,20 @@ describe('repository deployment API schemas', () => {
})
expect(parsed.repositories[0]?.id).toBeNull()
+ expect(parsed.repository_deploys_available).toBe(true)
+ })
+
+ it('keeps repository deploys unavailable for older API responses', () => {
+ const parsed = DeployAppSchema.parse({
+ installed: false,
+ install_url: null,
+ configure_url: null,
+ account: null,
+ repository_selection: null,
+ repositories: [],
+ })
+
+ expect(parsed.repository_deploys_available).toBe(false)
})
it('fails closed when deployment identity or canonical state is absent', () => {
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
index 2db4c7d6..2ffb1cec 100644
--- a/web/src/api/mock.ts
+++ b/web/src/api/mock.ts
@@ -488,6 +488,7 @@ const DEPLOY_PREVIEW = 'installed' as
| 'connected'
const deployAppInstalled = {
+ repository_deploys_available: true,
installed: true,
install_url: 'https://github.com/apps/opencomputerdev/installations/new',
configure_url:
@@ -516,6 +517,7 @@ const deployAppInstalled = {
],
}
const deployAppNotInstalled = {
+ repository_deploys_available: true,
installed: false,
install_url: 'https://github.com/apps/opencomputerdev/installations/new',
configure_url: null,
diff --git a/web/src/api/schemas.ts b/web/src/api/schemas.ts
index 7e7f233c..914a8434 100644
--- a/web/src/api/schemas.ts
+++ b/web/src/api/schemas.ts
@@ -614,6 +614,9 @@ export const DeployAppRepoSchema = z.object({
private: z.boolean().nullish(),
})
export const DeployAppSchema = z.object({
+ // Rollout is owner-gated server-side. Missing stays unavailable so an older
+ // API cannot accidentally expose repository deploy controls.
+ repository_deploys_available: z.boolean().default(false),
installed: z.boolean(),
install_url: z.string().nullish(),
configure_url: z.string().nullish(),
@@ -831,6 +834,7 @@ export type SkillItem = z.infer<typeof SkillItemSchema>
export type AgentDeploy = z.infer<typeof AgentDeploySchema>
export type AgentDeployment = z.infer<typeof AgentDeploymentSchema>
export type AgentDeploymentLog = z.infer<typeof AgentDeploymentLogSchema>
+export type DeployApp = z.infer<typeof DeployAppSchema>
export type FlueSourceInspection = z.infer<typeof FlueSourceInspectionSchema>
export type Credential = z.infer<typeof CredentialSchema>
export type SlackConnection = z.infer<typeof SlackConnectionSchema>
diff --git a/web/src/lib/agent-creation-mode.test.ts b/web/src/lib/agent-creation-mode.test.ts
new file mode 100644
index 00000000..2cd3898c
--- /dev/null
+++ b/web/src/lib/agent-creation-mode.test.ts
@@ -0,0 +1,15 @@
+import { describe, expect, it } from 'vitest'
+import { resolveAgentCreationMode } from './agent-creation-mode'
+
+describe('agent creation mode', () => {
+ it('fails a direct GitHub request over to manual until availability is true', () => {
+ expect(resolveAgentCreationMode('github', false)).toBe('manual')
+ expect(resolveAgentCreationMode(null, false)).toBe('manual')
+ })
+
+ it('keeps repository-first defaults for an allowed owner', () => {
+ expect(resolveAgentCreationMode(null, true)).toBe('github')
+ expect(resolveAgentCreationMode('github', true)).toBe('github')
+ expect(resolveAgentCreationMode('manual', true)).toBe('manual')
+ })
+})
diff --git a/web/src/lib/agent-creation-mode.ts b/web/src/lib/agent-creation-mode.ts
new file mode 100644
index 00000000..2c72dedd
--- /dev/null
+++ b/web/src/lib/agent-creation-mode.ts
@@ -0,0 +1,9 @@
+export type AgentCreationMode = 'github' | 'manual'
+
+export function resolveAgentCreationMode(
+ requestedMode: string | null,
+ repositoryDeploysAvailable: boolean,
+): AgentCreationMode {
+ if (!repositoryDeploysAvailable) return 'manual'
+ return requestedMode === 'manual' ? 'manual' : 'github'
+}
diff --git a/web/src/pages/AgentNew.tsx b/web/src/pages/AgentNew.tsx
index 4d6fed51..095df86b 100644
--- a/web/src/pages/AgentNew.tsx
+++ b/web/src/pages/AgentNew.tsx
@@ -16,6 +16,7 @@ import {
getDeployApp,
importAgentFromGithub,
inspectFlueRepository,
+ type DeployApp,
type FlueSourceInspection,
} from '@/api/client'
import { Field, FieldError, Input } from '@/components/form'
@@ -32,6 +33,10 @@ import { Button } from '@/components/ui/button'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
+import {
+ resolveAgentCreationMode,
+ type AgentCreationMode,
+} from '@/lib/agent-creation-mode'
import { cn } from '@/lib/utils'
const STARTER_URL = 'https://github.com/diggerhq/oc-flue-starter'
@@ -225,7 +230,7 @@ function DetectedAgent({ inspection }: { inspection: FlueSourceInspection }) {
)
}
-function GithubImport() {
+function GithubImport({ app }: { app: DeployApp }) {
const navigate = useNavigate()
const queryClient = useQueryClient()
const importCommand = useRef<ImportCommand | null>(null)
@@ -235,20 +240,9 @@ function GithubImport() {
const [root, setRoot] = useState('')
const [name, setName] = useState('')
- const {
- data: app,
- isLoading,
- isError,
- refetch,
- } = useQuery({
- queryKey: ['deploy-app'],
- queryFn: getDeployApp,
- refetchOnWindowFocus: 'always',
- })
-
const repositories = useMemo(() => {
const needle = repoSearch.trim().toLowerCase()
- return (app?.repositories ?? [])
+ return app.repositories
.filter(
(repo): repo is typeof repo & { id: string } =>
typeof repo.id === 'string' && repo.id.length > 0,
@@ -256,9 +250,9 @@ function GithubImport() {
.filter(
(repo) => !needle || repo.full_name.toLowerCase().includes(needle),
)
- }, [app?.repositories, repoSearch])
+ }, [app.repositories, repoSearch])
- const selectedRepo = app?.repositories.find((repo) => repo.id === repoId)
+ const selectedRepo = app.repositories.find((repo) => repo.id === repoId)
const rootValid = isValidRoot(root.trim())
const inspectMutation = useMutation({
@@ -294,7 +288,7 @@ function GithubImport() {
}
const selectRepo = (id: string) => {
- const repo = app?.repositories.find((candidate) => candidate.id === id)
+ const repo = app.repositories.find((candidate) => candidate.id === id)
setRepoId(id)
setProductionRef(repo?.default_branch || 'main')
setRoot('')
@@ -329,34 +323,6 @@ function GithubImport() {
})
}
- if (isLoading) {
- return (
- <Panel>
- <PanelContent className="space-y-3 py-6">
- <Skeleton className="h-4 w-40" />
- <Skeleton className="h-8 w-full" />
- <Skeleton className="h-8 w-3/4" />
- </PanelContent>
- </Panel>
- )
- }
-
- if (isError || !app) {
- return (
- <Alert variant="destructive">
- <AlertTitle>GitHub connection could not be loaded</AlertTitle>
- <AlertDescription>
- Retry the request. No repository or agent was changed.
- </AlertDescription>
- <div className="mt-2">
- <Button size="sm" variant="outline" onClick={() => void refetch()}>
- Retry
- </Button>
- </div>
- </Alert>
- )
- }
-
if (!app.installed) {
return (
<Panel>
@@ -636,13 +602,37 @@ function GithubImport() {
}
export default function AgentNew() {
+ const navigate = useNavigate()
const [searchParams, setSearchParams] = useSearchParams()
- const mode = searchParams.get('mode') === 'manual' ? 'manual' : 'github'
- const setMode = (next: 'github' | 'manual') =>
+ const deployAppQuery = useQuery({
+ queryKey: ['deploy-app'],
+ queryFn: getDeployApp,
+ refetchOnWindowFocus: 'always',
+ })
+ const availableDeployApp =
+ !deployAppQuery.isError &&
+ deployAppQuery.data?.repository_deploys_available === true
+ ? deployAppQuery.data
+ : null
+ const repositoryDeploysAvailable = availableDeployApp !== null
+ const mode = resolveAgentCreationMode(
+ searchParams.get('mode'),
+ repositoryDeploysAvailable,
+ )
+ const setMode = (next: AgentCreationMode) =>
setSearchParams(next === 'github' ? {} : { mode: 'manual' }, {
replace: true,
})
+ // A cold request starts in the fully usable manual flow. If someone begins
+ // using it before the availability read returns, keep that choice instead
+ // of replacing their in-progress form with the repository flow.
+ const preserveManualIntent = () => {
+ if (!repositoryDeploysAvailable && searchParams.get('mode') !== 'manual') {
+ setMode('manual')
+ }
+ }
+
return (
<div className="mx-auto max-w-4xl">
<Link
@@ -656,73 +646,97 @@ export default function AgentNew() {
<div className="mb-6">
<h1 className="text-xl font-semibold tracking-tight">Create agent</h1>
<p className="text-muted-foreground mt-1 text-sm">
- Deploy an existing Flue repository or configure an agent manually.
+ {repositoryDeploysAvailable
+ ? 'Deploy an existing Flue repository or configure an agent manually.'
+ : 'Configure an agent from a prompt, runtime, and model.'}
</p>
</div>
- <div className="bg-muted mb-6 flex flex-col gap-1 rounded-lg p-1 sm:flex-row">
- <ModeButton
- active={mode === 'github'}
- onClick={() => setMode('github')}
- icon={GithubMark}
- title="Import from GitHub"
- description="Build and deploy an existing Flue agent."
- />
- <ModeButton
- active={mode === 'manual'}
- onClick={() => setMode('manual')}
- icon={Bot}
- title="Configure manually"
- description="Create a built-in runtime agent from a prompt."
- />
- </div>
+ {deployAppQuery.isLoading ? (
+ <div
+ className="bg-muted mb-6 rounded-lg p-1"
+ role="status"
+ aria-label="Checking available creation methods"
+ >
+ <Skeleton className="h-[58px] w-full rounded-md" />
+ </div>
+ ) : repositoryDeploysAvailable ? (
+ <div className="bg-muted mb-6 flex flex-col gap-1 rounded-lg p-1 sm:flex-row">
+ <ModeButton
+ active={mode === 'github'}
+ onClick={() => setMode('github')}
+ icon={GithubMark}
+ title="Import from GitHub"
+ description="Build and deploy an existing Flue agent."
+ />
+ <ModeButton
+ active={mode === 'manual'}
+ onClick={() => setMode('manual')}
+ icon={Bot}
+ title="Configure manually"
+ description="Create a built-in runtime agent from a prompt."
+ />
+ </div>
+ ) : null}
- {mode === 'github' ? (
- <GithubImport />
+ {availableDeployApp && mode === 'github' ? (
+ <GithubImport app={availableDeployApp} />
) : (
- <Panel>
- <PanelHeader>
- <div>
- <PanelTitle>Configure manually</PanelTitle>
- <PanelDescription className="mt-1">
- Sessions pin a snapshot of this definition when they are
- created.
- </PanelDescription>
- </div>
- </PanelHeader>
- <PanelContent>
- <ManualAgentForm onCancel={() => setMode('github')} />
- </PanelContent>
- </Panel>
+ <div onFocusCapture={preserveManualIntent}>
+ <Panel>
+ <PanelHeader>
+ <div>
+ <PanelTitle>Configure manually</PanelTitle>
+ <PanelDescription className="mt-1">
+ Sessions pin a snapshot of this definition when they are
+ created.
+ </PanelDescription>
+ </div>
+ </PanelHeader>
+ <PanelContent>
+ <ManualAgentForm
+ onCancel={() => {
+ if (repositoryDeploysAvailable) setMode('github')
+ else void navigate('/agents')
+ }}
+ />
+ </PanelContent>
+ </Panel>
+ </div>
)}
- <section className="mt-8 border-t pt-6" aria-labelledby="starter-heading">
- <div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
- <div className="max-w-xl">
- <h2 id="starter-heading" className="text-sm font-semibold">
- Need a starting point?
- </h2>
- <p className="text-muted-foreground mt-1 text-sm">
- Fork the Flue starter, add your agent logic, then return here to
- deploy it.
- </p>
- </div>
- <div className="flex flex-wrap gap-2">
- <Button variant="outline" size="sm" asChild>
- <a href={STARTER_URL} target="_blank" rel="noreferrer">
- View repository
- <ExternalLink className="size-3.5" />
- </a>
- </Button>
- <Button variant="outline" size="sm" asChild>
- <a href={STARTER_FORK_URL} target="_blank" rel="noreferrer">
- Fork on GitHub
- <ExternalLink className="size-3.5" />
- </a>
- </Button>
+ {repositoryDeploysAvailable ? (
+ <section
+ className="mt-8 border-t pt-6"
+ aria-labelledby="starter-heading"
+ >
+ <div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
+ <div className="max-w-xl">
+ <h2 id="starter-heading" className="text-sm font-semibold">
+ Need a starting point?
+ </h2>
+ <p className="text-muted-foreground mt-1 text-sm">
+ Fork the Flue starter, add your agent logic, then return here to
+ deploy it.
+ </p>
+ </div>
+ <div className="flex flex-wrap gap-2">
+ <Button variant="outline" size="sm" asChild>
+ <a href={STARTER_URL} target="_blank" rel="noreferrer">
+ View repository
+ <ExternalLink className="size-3.5" />
+ </a>
+ </Button>
+ <Button variant="outline" size="sm" asChild>
+ <a href={STARTER_FORK_URL} target="_blank" rel="noreferrer">
+ Fork on GitHub
+ <ExternalLink className="size-3.5" />
+ </a>
+ </Button>
+ </div>
</div>
- </div>
- </section>
+ </section>
+ ) : null}
</div>
)
}
diff --git a/web/src/pages/Agents.tsx b/web/src/pages/Agents.tsx
index 71cce981..f5e065b7 100644
--- a/web/src/pages/Agents.tsx
+++ b/web/src/pages/Agents.tsx
@@ -1,7 +1,7 @@
-import { useQuery } from '@tanstack/react-query'
+import { useQuery, useQueryClient } from '@tanstack/react-query'
import { Link, useNavigate } from 'react-router-dom'
import { Bot, Plus } from 'lucide-react'
-import { getAgents, type Agent } from '@/api/client'
+import { getAgents, getDeployApp, type Agent } from '@/api/client'
import { EmptyState } from '@/components/empty-state'
import { PageHeader } from '@/components/page-header'
import { Panel } from '@/components/panel'
@@ -12,6 +12,7 @@ import { agentDeploymentDisplayStatus } from '@/lib/agent-deployment-status'
export default function Agents() {
const navigate = useNavigate()
+ const queryClient = useQueryClient()
const { data: agents, isLoading } = useQuery({
queryKey: ['agents'],
queryFn: getAgents,
@@ -91,7 +92,23 @@ export default function Agents() {
},
]
- const openCreate = () => void navigate('/agents/new')
+ const prefetchCreate = () => {
+ void import('@/pages/AgentNew')
+ void queryClient.prefetchQuery({
+ queryKey: ['deploy-app'],
+ queryFn: getDeployApp,
+ staleTime: 30_000,
+ })
+ }
+ const openCreate = () => {
+ prefetchCreate()
+ void navigate('/agents/new')
+ }
+
+ const createIntentProps = {
+ onPointerEnter: prefetchCreate,
+ onFocus: prefetchCreate,
+ }
return (
<div>
@@ -105,7 +122,7 @@ export default function Agents() {
docs: 'https://docs.opencomputer.dev/agent-sessions/agents',
}}
actions={
- <Button onClick={openCreate}>
+ <Button onClick={openCreate} {...createIntentProps}>
<Plus className="size-4" />
Create agent
</Button>
@@ -124,7 +141,7 @@ export default function Agents() {
title="No agents yet"
description="Define an agent once, then start durable sessions from it."
action={
- <Button size="sm" onClick={openCreate}>
+ <Button size="sm" onClick={openCreate} {...createIntentProps}>
<Plus className="size-4" />
Create agent
</Button>