Skip to content

An open-source, faster Devin alternative

TypeScript

Delete a project, rename from dashboard (#755)

Brian Reardonaecf914b7956
diff --git a/cli/src/dev.test.ts b/cli/src/dev.test.ts
index 4d62ddfa..3b200813 100644
--- a/cli/src/dev.test.ts
+++ b/cli/src/dev.test.ts
@@ -85,6 +85,7 @@ test("development publish builds an immutable artifact under the development ali
"hello-agent",
);
assert.equal(input?.agentId, "hello-agent");
+ assert.equal(input?.name, "Hello World");
assert.equal(input?.alias, "development");
assert.equal(input?.source.digest, result.built.digest);
assert.deepEqual(input?.models, [
diff --git a/cli/src/dev.ts b/cli/src/dev.ts
index 2feec0e2..b3f0a331 100644
--- a/cli/src/dev.ts
+++ b/cli/src/dev.ts
@@ -281,7 +281,7 @@ export async function runDeploymentWatch(
let timer: NodeJS.Timeout | undefined;
let publishing = false;
let pending = false;
- const lastDigests = new Map<string, string>();
+ const lastPublished = new Map<string, { digest: string; name: string }>();
const publish = async () => {
if (publishing) {
@@ -301,13 +301,17 @@ export async function runDeploymentWatch(
);
let changed = false;
for (const result of results) {
- if (
- result.built.digest !== lastDigests.get(result.deployment.agentId)
- ) {
+ const previous = lastPublished.get(result.deployment.agentId);
+ const runtimeChanged = result.built.digest !== previous?.digest;
+ const nameChanged = result.built.name !== previous?.name;
+ if (runtimeChanged || nameChanged) {
changed = true;
- lastDigests.set(result.deployment.agentId, result.built.digest);
+ lastPublished.set(result.deployment.agentId, {
+ digest: result.built.digest,
+ name: result.built.name,
+ });
process.stdout.write(
- `✓ Deployed ${result.deployment.agentId}@development\n` +
+ `${runtimeChanged ? "✓ Deployed" : "✓ Updated name for"} ${result.deployment.agentId}@development\n` +
` Deployment ${result.deployment.id}\n`,
);
}
@@ -334,7 +338,10 @@ export async function runDeploymentWatch(
binding,
);
for (const result of initial) {
- lastDigests.set(result.deployment.agentId, result.built.digest);
+ lastPublished.set(result.deployment.agentId, {
+ digest: result.built.digest,
+ name: result.built.name,
+ });
}
const spa = await hasReactSpa(projectRoot);
const startWebApp = behavior.startWebApp === true && spa;
diff --git a/cli/src/project.test.ts b/cli/src/project.test.ts
index 3f31ebb8..64becd53 100644
--- a/cli/src/project.test.ts
+++ b/cli/src/project.test.ts
@@ -75,12 +75,15 @@ test("init creates a multi-agent-ready hello-world agent by default", async () =
);
await assert.rejects(stat(resolve(root, "opencomputer", "package.json")));
const agentRoot = resolve(root, "opencomputer", "agents", "hello-world");
+ assert.match(
+ await readFile(resolve(agentRoot, "opencomputer.toml"), "utf8"),
+ /id = "hello-world"[\s\S]*name = "Hello World"/,
+ );
assert.match(
await readFile(resolve(agentRoot, "agent.ts"), "utf8"),
/useInput[\s\S]*useModel\("anthropic\/claude-sonnet-4\.6"\)/,
);
for (const removed of [
- "opencomputer.toml",
"opencomputer.config.ts",
"opencomputer.ts",
"opencode.json",
@@ -96,6 +99,7 @@ test("init creates a multi-agent-ready hello-world agent by default", async () =
assert.deepEqual(initialized.files, [
"opencomputer/project.ts",
"opencomputer/.env.example",
+ "opencomputer/agents/hello-world/opencomputer.toml",
"opencomputer/agents/hello-world/agent.ts",
"package.json",
"README.md",
@@ -285,6 +289,7 @@ test("init can explicitly include a separately-run React app", async () => {
assert.deepEqual(initialized.files, [
"opencomputer/project.ts",
"opencomputer/.env.example",
+ "opencomputer/agents/hello-world/opencomputer.toml",
"opencomputer/agents/hello-world/agent.ts",
"package.json",
"vite.config.ts",
@@ -306,6 +311,7 @@ test("the code-first compiler records hook resources without config files", asyn
const root = resolve(parent, "app");
try {
const initialized = await initializeAgentProject(root);
+ await rm(resolve(initialized.agentRoot, "opencomputer.toml"));
await writeFile(
resolve(initialized.agentRoot, "agent.ts"),
`import {
diff --git a/cli/src/project.ts b/cli/src/project.ts
index 72025705..ff1d38e9 100644
--- a/cli/src/project.ts
+++ b/cli/src/project.ts
@@ -456,6 +456,7 @@ export async function initializeAgentProject(
]) {
await rm(resolve(agentRoot, path), { recursive: true, force: true });
}
+ await writeManifest(agentRoot, manifest);
await writeFile(
resolve(agentRoot, "agent.ts"),
`import { useInput, useModel } from "@opencomputer/agent";
@@ -805,6 +806,7 @@ from \`defineConnection()\` declarations.
files: [
"opencomputer/project.ts",
"opencomputer/.env.example",
+ "opencomputer/agents/hello-world/opencomputer.toml",
"opencomputer/agents/hello-world/agent.ts",
...appFiles,
],
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.ts
index 167c344a..4b2dde96 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts
@@ -147,6 +147,47 @@ describe("managed agents proxy", () => {
);
});
+ it("forwards reversible project archive state changes", async () => {
+ const fetchMock = vi.fn().mockResolvedValue(
+ Response.json({
+ id: "prj_test",
+ slug: "archive-me",
+ name: "Archive me",
+ agentId: "archive-me",
+ environments: [],
+ archivedAt: "2026-09-22T18:00:00.000Z",
+ createdAt: "2026-09-22T17:00:00.000Z",
+ updatedAt: "2026-09-22T18:00:00.000Z",
+ }),
+ );
+ vi.stubGlobal("fetch", fetchMock);
+ const response = await proxyManagedAgents(
+ new Request(
+ "https://mo-oc-dev.com/api/managed-agents/projects/prj_test/archive",
+ {
+ method: "POST",
+ },
+ ),
+ {
+ MANAGED_AGENTS_API_URL: "https://manage-agents.mo-oc-dev.com",
+ OC_MANAGED_AGENTS_SECRET: "test-secret",
+ },
+ { orgID: "org_test", userID: "user_test" },
+ "/api/managed-agents",
+ );
+
+ expect(response.status).toBe(200);
+ await expect(response.json()).resolves.toMatchObject({
+ id: "prj_test",
+ slug: "archive-me",
+ archivedAt: "2026-09-22T18:00:00.000Z",
+ });
+ expect(fetchMock.mock.calls[0]?.[0].toString()).toBe(
+ "https://manage-agents.mo-oc-dev.com/v1/projects/prj_test/archive",
+ );
+ expect(fetchMock.mock.calls[0]?.[1]?.method).toBe("POST");
+ });
+
it("forwards the GitHub repository listing with its query and the page it returns", async () => {
const fetchMock = vi.fn().mockResolvedValue(
Response.json({
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index 43d7a899..6969faa4 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -231,7 +231,9 @@ async function publicErrorResponse(upstream: Response): Promise<Response> {
} else if (upstream.status === 404) {
message = "The requested agent resource was not found.";
} else if (upstream.status === 409) {
- if (backendCode === "invalid_model_selection") {
+ if (backendCode === "project_archived") {
+ message = "Restore this project before starting new work.";
+ } else if (backendCode === "invalid_model_selection") {
message =
backendMessage || "The deployment selects an unavailable model.";
} else if (backendCode === "database_not_provisioned") {
@@ -475,6 +477,21 @@ function publicDeployment(value: unknown): Record<string, unknown> {
};
}
+function publicAgent(value: unknown): Record<string, unknown> {
+ const agent = record(value) ?? {};
+ return {
+ id: agent.id,
+ // An agent that was never named falls back to its id, so the dashboard
+ // always has something to render.
+ name: typeof agent.name === "string" && agent.name ? agent.name : agent.id,
+ activeAlias: agent.activeAlias,
+ activeDeploymentId: agent.activeDeploymentId,
+ deploymentCount: agent.deploymentCount,
+ createdAt: agent.createdAt,
+ updatedAt: agent.updatedAt,
+ };
+}
+
function publicProject(value: unknown): Record<string, unknown> {
const project = record(value) ?? {};
const agentId =
@@ -510,6 +527,9 @@ function publicProject(value: unknown): Record<string, unknown> {
? stripPrivateValues(project.environments)
: [],
agents,
+ ...(typeof project.archivedAt === "string"
+ ? { archivedAt: project.archivedAt }
+ : {}),
createdAt: project.createdAt,
updatedAt: project.updatedAt,
};
@@ -1440,23 +1460,7 @@ function publicSuccessBody(
}
if (method === "GET" && suffix === "/agents") {
return {
- agents: Array.isArray(body.agents)
- ? body.agents.map((value) => {
- const agent = record(value) ?? {};
- return {
- id: agent.id,
- name:
- typeof agent.name === "string" && agent.name
- ? agent.name
- : agent.id,
- activeAlias: agent.activeAlias,
- activeDeploymentId: agent.activeDeploymentId,
- deploymentCount: agent.deploymentCount,
- createdAt: agent.createdAt,
- updatedAt: agent.updatedAt,
- };
- })
- : [],
+ agents: Array.isArray(body.agents) ? body.agents.map(publicAgent) : [],
};
}
if (method === "GET" && suffix === "/projects") {
@@ -1469,6 +1473,12 @@ function publicSuccessBody(
if (method === "POST" && suffix === "/projects") {
return publicProject(body);
}
+ if (
+ method === "POST" &&
+ /^\/projects\/[^/]+\/(archive|restore)$/.test(suffix)
+ ) {
+ return publicProject(body);
+ }
if (
method === "POST" &&
/^\/projects\/[^/]+\/database\/query$/.test(suffix)
@@ -2077,6 +2087,12 @@ function isAllowedManagedAgentsRoute(method: string, suffix: string): boolean {
if (method === "GET" && suffix === "/github") return true;
if (method === "POST" && suffix === "/github/connect") return true;
if (method === "GET" && /^\/projects\/[^/]+$/.test(suffix)) return true;
+ if (
+ method === "POST" &&
+ /^\/projects\/[^/]+\/(archive|restore)$/.test(suffix)
+ ) {
+ return true;
+ }
if (
method === "POST" &&
/^\/projects\/[^/]+\/database\/query$/.test(suffix)
diff --git a/docs/agents/projects.mdx b/docs/agents/projects.mdx
index 0f8b7f34..67093af8 100644
--- a/docs/agents/projects.mdx
+++ b/docs/agents/projects.mdx
@@ -117,3 +117,14 @@ The current project dashboard provides:
Project and agent behavior remains code-owned. The dashboard is for selection,
inspection, and testing. Use `opencomputer logs` to diagnose agent and
outbound-request failures.
+
+## Archive and restore a project
+
+Archive a project from the Projects page when you no longer want it active.
+Archiving stops running sessions and prevents new deployments, sessions,
+schedules, channel turns, and webhook deliveries. It preserves the project's
+agents, deployment history, secrets, connections, and other configuration.
+
+Archived projects remain available in the **Archived** section. Select
+**Restore** to return one to the active project list with its configuration
+intact.
diff --git a/web/src/managed-agents/Channels.tsx b/web/src/managed-agents/Channels.tsx
index a39c3163..fbdadeca 100644
--- a/web/src/managed-agents/Channels.tsx
+++ b/web/src/managed-agents/Channels.tsx
@@ -29,7 +29,7 @@ export default function ManagedAgentChannels() {
})
const projects = useQuery({
queryKey: ['managed-projects'],
- queryFn: getManagedProjects,
+ queryFn: () => getManagedProjects(),
})
const agentNames = new Map(
(agents.data ?? []).map((agent) => [
diff --git a/web/src/managed-agents/Detail.tsx b/web/src/managed-agents/Detail.tsx
index 2e46fcc7..9a13eac5 100644
--- a/web/src/managed-agents/Detail.tsx
+++ b/web/src/managed-agents/Detail.tsx
@@ -17,6 +17,7 @@ import {
Clipboard,
GitCommitHorizontal,
Loader2,
+ Pencil,
Plus,
Send,
TerminalSquare,
@@ -531,6 +532,36 @@ function PlaygroundChat({
)
}
+function AgentNameSourceDialog({
+ agent,
+}: {
+ agent: Pick<ManagedAgentSummary, 'id' | 'name'>
+}) {
+ return (
+ <Dialog>
+ <DialogTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ className="text-muted-foreground hover:text-foreground size-8"
+ aria-label={`Rename ${displayManagedAgentName(agent)}`}
+ >
+ <Pencil className="size-3.5" aria-hidden />
+ </Button>
+ </DialogTrigger>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Rename agent</DialogTitle>
+ <DialogDescription>
+ Agent names are defined in code. Update the name in the agent&apos;s{' '}
+ <code>opencomputer.toml</code>, then redeploy the project.
+ </DialogDescription>
+ </DialogHeader>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
export default function ManagedAgentDetail({
agentId: agentIdOverride,
project,
@@ -873,6 +904,7 @@ export default function ManagedAgentDetail({
</option>
))}
</select>
+ {projectAgent ? <AgentNameSourceDialog agent={projectAgent} /> : null}
</div>
) : null}
diff --git a/web/src/managed-agents/Home.test.tsx b/web/src/managed-agents/Home.test.tsx
index 24d68d9d..191f4551 100644
--- a/web/src/managed-agents/Home.test.tsx
+++ b/web/src/managed-agents/Home.test.tsx
@@ -5,9 +5,10 @@ import { describe, expect, it } from 'vitest'
import ProjectsHome from './Home'
import { INSTALL_CLI_COMMAND } from './ProjectOnboarding'
-function renderProjects(projects: unknown[]) {
+function renderProjects(projects: unknown[], archived: unknown[] = []) {
const queryClient = new QueryClient()
queryClient.setQueryData(['managed-projects'], projects)
+ queryClient.setQueryData(['managed-projects', 'archived'], archived)
return renderToStaticMarkup(
<QueryClientProvider client={queryClient}>
@@ -45,4 +46,57 @@ describe('projects home onboarding', () => {
expect(markup).toContain('href="/new"')
expect(markup).not.toContain('Start from a template')
})
+
+ it('offers each project its own archive control, named after the project', () => {
+ const now = new Date().toISOString()
+ const markup = renderProjects([
+ {
+ id: 'project_1',
+ slug: 'support',
+ name: 'Support',
+ environments: [{ name: 'development', updatedAt: now }],
+ agents: [{ id: 'agent_1', name: 'Support agent' }],
+ createdAt: now,
+ updatedAt: now,
+ },
+ {
+ id: 'project_2',
+ slug: 'billing',
+ name: 'Billing',
+ environments: [{ name: 'development', updatedAt: now }],
+ agents: [],
+ createdAt: now,
+ updatedAt: now,
+ },
+ ])
+
+ expect(markup).toContain('aria-label="Archive Support"')
+ expect(markup).toContain('aria-label="Archive Billing"')
+ expect(markup).not.toContain('Archive project')
+ })
+
+ it('hides archived projects behind a collapsed restore section', () => {
+ const now = new Date().toISOString()
+ const markup = renderProjects(
+ [],
+ [
+ {
+ id: 'project_1',
+ slug: 'support',
+ name: 'Support',
+ environments: [],
+ agents: [{ id: 'agent_1', name: 'Support agent' }],
+ archivedAt: now,
+ createdAt: now,
+ updatedAt: now,
+ },
+ ],
+ )
+
+ expect(markup).toContain('<details class="group space-y-3">')
+ expect(markup).not.toContain('<details open=""')
+ expect(markup).toContain('Archived (1)')
+ expect(markup).toContain('Support')
+ expect(markup).toContain('Restore')
+ })
})
diff --git a/web/src/managed-agents/Home.tsx b/web/src/managed-agents/Home.tsx
index 9076dfab..c7ca55e1 100644
--- a/web/src/managed-agents/Home.tsx
+++ b/web/src/managed-agents/Home.tsx
@@ -1,21 +1,64 @@
-import { useQuery } from '@tanstack/react-query'
+import { useState } from 'react'
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { Link } from 'react-router-dom'
-import { ChevronRight, FolderKanban, Loader2, Plus } from 'lucide-react'
+import {
+ Archive,
+ ChevronRight,
+ FolderKanban,
+ Loader2,
+ Plus,
+ RotateCcw,
+} from 'lucide-react'
+import { ConfirmDialog } from '@/components/confirm-dialog'
import { EmptyState } from '@/components/empty-state'
import { PageHeader } from '@/components/page-header'
import { Panel, PanelContent } from '@/components/panel'
import { Button } from '@/components/ui/button'
-import { getManagedProjects } from './api'
+import { notifyError, notifySuccess } from '@/lib/errors'
+import {
+ archiveManagedProject,
+ getManagedProjects,
+ restoreManagedProject,
+} from './api'
import ProjectOnboarding from './ProjectOnboarding'
export default function ProjectsHome() {
+ const queryClient = useQueryClient()
const projects = useQuery({
queryKey: ['managed-projects'],
- queryFn: getManagedProjects,
+ queryFn: () => getManagedProjects(),
+ })
+ const archivedProjects = useQuery({
+ queryKey: ['managed-projects', 'archived'],
+ queryFn: () => getManagedProjects({ archived: true }),
})
const items = projects.data ?? []
+ const archivedItems = archivedProjects.data ?? []
+ // The project the confirm dialog is open for, held whole so the dialog can
+ // name it after the list behind it has already been invalidated.
+ const [pendingArchive, setPendingArchive] = useState<{
+ id: string
+ name: string
+ } | null>(null)
+ const archive = useMutation({
+ mutationFn: archiveManagedProject,
+ onSuccess: async () => {
+ setPendingArchive(null)
+ await queryClient.invalidateQueries({ queryKey: ['managed-projects'] })
+ notifySuccess('Project archived.', 'You can restore it at any time.')
+ },
+ onError: (error) => notifyError("Couldn't archive the project.", error),
+ })
+ const restore = useMutation({
+ mutationFn: restoreManagedProject,
+ onSuccess: async () => {
+ await queryClient.invalidateQueries({ queryKey: ['managed-projects'] })
+ notifySuccess('Project restored.')
+ },
+ onError: (error) => notifyError("Couldn't restore the project.", error),
+ })
- if (projects.isLoading) {
+ if (projects.isLoading || archivedProjects.isLoading) {
return (
<div className="flex min-h-64 items-center justify-center">
<Loader2 className="text-muted-foreground size-5 animate-spin" />
@@ -23,7 +66,7 @@ export default function ProjectsHome() {
)
}
- if (projects.isError) {
+ if (projects.isError || archivedProjects.isError) {
return (
<Panel>
<EmptyState
@@ -40,7 +83,9 @@ export default function ProjectsHome() {
)
}
- if (items.length === 0) return <ProjectOnboarding />
+ if (items.length === 0 && archivedItems.length === 0) {
+ return <ProjectOnboarding />
+ }
return (
<div className="space-y-8">
@@ -79,6 +124,20 @@ export default function ProjectsHome() {
{project.environments.length} environments
</p>
</div>
+ <Button
+ variant="ghost"
+ size="icon"
+ aria-label={`Archive ${project.name}`}
+ className="text-muted-foreground size-8 shrink-0"
+ onClick={(event) => {
+ // The whole card is a link; archiving must not navigate.
+ event.preventDefault()
+ event.stopPropagation()
+ setPendingArchive({ id: project.id, name: project.name })
+ }}
+ >
+ <Archive className="size-4" aria-hidden />
+ </Button>
<ChevronRight className="text-muted-foreground size-4 transition-transform group-hover:translate-x-0.5" />
</PanelContent>
</Panel>
@@ -86,6 +145,62 @@ export default function ProjectsHome() {
))}
</div>
</section>
+
+ {archivedItems.length > 0 && (
+ <details className="group space-y-3">
+ <summary className="text-muted-foreground hover:text-foreground flex w-fit cursor-pointer list-none items-center gap-1.5 text-sm font-medium transition-colors [&::-webkit-details-marker]:hidden">
+ <ChevronRight className="size-4 transition-transform group-open:rotate-90" />
+ Archived ({archivedItems.length})
+ </summary>
+ <div className="space-y-3 pt-1">
+ <p className="text-muted-foreground text-xs">
+ Archived projects keep their configuration and can be restored.
+ </p>
+ <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
+ {archivedItems.map((project) => (
+ <Panel key={project.id} className="bg-muted/20">
+ <PanelContent className="flex items-center gap-3">
+ <div className="bg-muted text-muted-foreground flex size-10 shrink-0 items-center justify-center rounded-lg">
+ <Archive className="size-4" aria-hidden />
+ </div>
+ <div className="min-w-0 flex-1">
+ <p className="truncate text-sm font-medium">
+ {project.name}
+ </p>
+ <p className="text-muted-foreground mt-0.5 text-xs">
+ Archived
+ </p>
+ </div>
+ <Button
+ variant="outline"
+ size="sm"
+ disabled={restore.isPending}
+ onClick={() => restore.mutate(project.id)}
+ >
+ <RotateCcw className="size-4" aria-hidden />
+ Restore
+ </Button>
+ </PanelContent>
+ </Panel>
+ ))}
+ </div>
+ </div>
+ </details>
+ )}
+
+ <ConfirmDialog
+ open={pendingArchive !== null}
+ onOpenChange={(open) => {
+ if (!open) setPendingArchive(null)
+ }}
+ title={`Archive ${pendingArchive?.name ?? 'this project'}?`}
+ description="This hides the project and stops its running sessions. Its agents, deployments, secrets and connections are preserved, and you can restore it later."
+ confirmLabel="Archive project"
+ pending={archive.isPending}
+ onConfirm={() => {
+ if (pendingArchive) archive.mutate(pendingArchive.id)
+ }}
+ />
</div>
)
}
diff --git a/web/src/managed-agents/api.ts b/web/src/managed-agents/api.ts
index b4d65103..9353acf8 100644
--- a/web/src/managed-agents/api.ts
+++ b/web/src/managed-agents/api.ts
@@ -4,7 +4,8 @@ import { apiFetch, apiFetchResponse, validate } from '@/api/client'
const agentSchema = z.object({
id: z.string(),
name: z.string(),
- activeAlias: z.string(),
+ // Both are null until the agent has been deployed at least once.
+ activeAlias: z.string().nullish(),
activeDeploymentId: z.string().nullish(),
deploymentCount: z.number(),
createdAt: z.string(),
@@ -120,6 +121,7 @@ const projectSchema = z.object({
}),
),
agents: z.array(z.object({ id: z.string(), name: z.string() })),
+ archivedAt: z.string().optional(),
createdAt: z.string(),
updatedAt: z.string(),
})
@@ -863,10 +865,10 @@ export async function getManagedRuntimeProfile() {
)
}
-export async function getManagedProjects() {
+export async function getManagedProjects(options: { archived?: boolean } = {}) {
return (
await apiFetch(
- '/managed-agents/projects',
+ `/managed-agents/projects${options.archived ? '?archived=true' : ''}`,
undefined,
projectsResponseSchema,
)
@@ -881,6 +883,22 @@ export async function createManagedProject(name: string) {
)
}
+export async function archiveManagedProject(projectId: string) {
+ return apiFetch(
+ `/managed-agents/projects/${encodeURIComponent(projectId)}/archive`,
+ { method: 'POST' },
+ projectSchema,
+ )
+}
+
+export async function restoreManagedProject(projectId: string) {
+ return apiFetch(
+ `/managed-agents/projects/${encodeURIComponent(projectId)}/restore`,
+ { method: 'POST' },
+ projectSchema,
+ )
+}
+
export async function inspectManagedTemplate(
repositoryUrl: string,
): Promise<z.infer<typeof templateInspectionSchema>> {
diff --git a/web/vite.config.ts b/web/vite.config.ts
index 6ef4d4d0..0cb85b25 100644
--- a/web/vite.config.ts
+++ b/web/vite.config.ts
@@ -1,4 +1,5 @@
import { fileURLToPath, URL } from 'node:url'
+import type { Connect } from 'vite'
import { defineConfig, type ProxyOptions } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
@@ -19,6 +20,38 @@ const injectKey: ProxyOptions['configure'] = (proxy) => {
if (v3Key) proxyReq.setHeader('x-api-key', v3Key)
})
}
+// Dev-only managed-agents bypass. With OC_MANAGED_AGENTS_TOKEN set, Vite
+// forwards /api/managed-agents/* straight to a managed-agents backend
+// (OC_MANAGED_AGENTS_TARGET) and injects the agent token server-side — so the
+// projects UI works in `npm run dev` against a personal dev Worker, with no
+// api-edge deploy and no WorkOS session. The token lives only in the Node dev
+// server, never in the browser bundle (not a VITE_ var). Prod still goes
+// through the edge, which mints its own token per request; this shortcut is
+// local-only, and it bypasses the edge's route allowlist and response shaping.
+const managedAgentsToken = process.env.OC_MANAGED_AGENTS_TOKEN
+const managedAgentsTarget =
+ process.env.OC_MANAGED_AGENTS_TARGET || 'https://managedagents.opencomputer.dev'
+const managedAgentsProxy: Record<string, ProxyOptions> = managedAgentsToken
+ ? {
+ // The dashboard's API base is /api/dashboard, so its managed-agents
+ // calls arrive under /api/dashboard/managed-agents — the same prefix
+ // dashboard.ts proxies from in the edge.
+ '/api/dashboard/managed-agents': {
+ target: managedAgentsTarget,
+ changeOrigin: true,
+ rewrite: (p) => p.replace(/^\/api\/dashboard\/managed-agents/, '/v1'),
+ configure: (proxy) => {
+ proxy.on('proxyReq', (proxyReq) => {
+ proxyReq.setHeader(
+ 'x-opencomputer-agent-token',
+ managedAgentsToken,
+ )
+ })
+ },
+ },
+ }
+ : {}
+
// Both must precede '/api/' below — first matching rule wins.
const v3Proxy: Record<string, ProxyOptions> = v3Key
? {
@@ -40,8 +73,39 @@ const v3Proxy: Record<string, ProxyOptions> = v3Key
}
: {}
+// Paired with the bypass above: ProtectedRoute redirects to /auth/login unless
+// /me resolves, and /auth is the edge's own route, which a local dev server has
+// no way to satisfy. Single-tenant development mode is supposed to return a
+// local user from /me, so serve exactly that — gated on the same token, ahead
+// of the proxy, and only for this one path.
+const localUser = {
+ name: 'managed-agents-local-user',
+ configureServer(server: { middlewares: Connect.Server }) {
+ if (!managedAgentsToken) return
+ server.middlewares.use((req, res, next) => {
+ if (req.url !== '/api/dashboard/me') return next()
+ res.setHeader('content-type', 'application/json')
+ res.end(
+ JSON.stringify({
+ id: 'local-dev-user',
+ email: '[email protected]',
+ orgId: 'local-dev-org',
+ durableSessionsEnabled: false,
+ infrastructureEnabled: false,
+ authMode: 'development',
+ capabilities: {
+ signOut: false,
+ manageMembers: false,
+ switchOrganizations: false,
+ },
+ }),
+ )
+ })
+ },
+}
+
export default defineConfig({
- plugins: [react(), tailwindcss()],
+ plugins: [react(), tailwindcss(), localUser],
base: '/',
resolve: {
alias: {
@@ -52,6 +116,7 @@ export default defineConfig({
port: 3000,
proxy: {
...v3Proxy,
+ ...managedAgentsProxy,
'/auth': target,
// Trailing slash so the SPA route `/api-keys` isn't proxied to the
// backend; all real API paths live under `/api/dashboard/`.