Skip to content

An open-source, faster Devin alternative

TypeScript

Make template links viewable without signing in; gate deploy behind login

Devin AIe7be62596c92
diff --git a/cloudflare-workers/api-edge/src/index.ts b/cloudflare-workers/api-edge/src/index.ts
index 1ae70f0e..e92b9272 100644
--- a/cloudflare-workers/api-edge/src/index.ts
+++ b/cloudflare-workers/api-edge/src/index.ts
@@ -90,6 +90,7 @@ import {
handleManagedSlackCallback,
handleManagedAgentChannelConnection,
proxyManagedAgents,
+ proxyPublicTemplateInspection,
} from "./managed_agents";
export interface Env extends DashboardEnv {
@@ -5498,6 +5499,14 @@ export default {
) {
const caller = await authenticate(req, env, ctx);
if (!caller) {
+ // Template preview is the one anonymous entry point: visitors can see
+ // a template's deploy form before signing up.
+ if (
+ path === "/api/managed-agents/template-inspections" &&
+ req.method === "POST"
+ ) {
+ return proxyPublicTemplateInspection(req, env);
+ }
return json({ error: "missing or invalid API key" }, 401);
}
const scopeError = provisionScopeGate(caller, path);
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.ts
index 472d1241..e750b9bb 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts
@@ -8,6 +8,7 @@ import {
hasBYOKPlanAccess,
mintManagedAgentsAssertion,
proxyManagedAgents,
+ proxyPublicTemplateInspection,
publicFailure,
} from "./managed_agents";
@@ -1553,6 +1554,58 @@ describe("managed agents proxy", () => {
);
});
+ it("proxies anonymous template inspection to the public upstream route without an org assertion", async () => {
+ const fetchSpy = vi.fn(
+ async (request: URL | RequestInfo, init?: RequestInit) => {
+ expect(String(request)).toBe(
+ "https://managedagents.test/v1/public/template-inspections",
+ );
+ expect(
+ new Headers(init?.headers).get("x-opencomputer-agent-token"),
+ ).toBeNull();
+ return Response.json({
+ id: "tin_test",
+ repository: {
+ url: "https://github.com/diggerhq/example",
+ fullName: "diggerhq/example",
+ defaultBranch: "main",
+ commitSha: "a".repeat(40),
+ },
+ template: { name: "Example", description: "Example agent" },
+ agents: [{ id: "example", name: "Example" }],
+ requirements: {
+ secrets: [],
+ runtimeVariables: [],
+ connections: [],
+ },
+ expiresAt: "2026-09-01T01:00:00.000Z",
+ builderCredential: "must-not-leak",
+ });
+ },
+ );
+ vi.stubGlobal("fetch", fetchSpy);
+
+ const response = await proxyPublicTemplateInspection(
+ new Request(
+ "https://app.opencomputer.dev/api/managed-agents/template-inspections",
+ {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ repositoryUrl: "https://github.com/diggerhq/example",
+ }),
+ },
+ ),
+ { MANAGED_AGENTS_API_URL: "https://managedagents.test" },
+ );
+
+ expect(response.status).toBe(200);
+ expect(fetchSpy).toHaveBeenCalledOnce();
+ expect(JSON.stringify(await response.json())).not.toContain(
+ "builderCredential",
+ );
+ });
+
it("reports a missing root template manifest without leaking builder details", async () => {
vi.stubGlobal(
"fetch",
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index 77025162..ca5b0783 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -2799,6 +2799,55 @@ export async function handleAgentWebhookInvocation(
}
}
+// Anonymous template preview: the dashboard shows a template's deploy form
+// before sign-up, so inspection is proxied without an org assertion to the
+// backend's public route. Installation still requires an authenticated caller.
+export async function proxyPublicTemplateInspection(
+ request: Request,
+ env: ManagedAgentsEnv,
+): Promise<Response> {
+ if (request.method.toUpperCase() !== "POST") {
+ return Response.json({ error: "method not allowed" }, { status: 405 });
+ }
+ const base = (
+ env.MANAGED_AGENTS_API_URL ?? DEFAULT_MANAGED_AGENTS_API_URL
+ ).replace(/\/+$/, "");
+ const target = new URL(`${base}/v1/public/template-inspections`);
+ if (target.protocol !== "https:" && target.hostname !== "localhost") {
+ return Response.json(
+ { error: "managed agents upstream must use HTTPS" },
+ { status: 503 },
+ );
+ }
+ try {
+ const upstream = await fetch(target, {
+ method: "POST",
+ headers: copyRequestHeaders(request),
+ body: request.body,
+ redirect: "manual",
+ });
+ if (!upstream.ok) return publicErrorResponse(upstream);
+ return publicSuccessResponse(
+ upstream,
+ "POST",
+ "/template-inspections",
+ new URL(request.url).origin,
+ );
+ } catch (error) {
+ console.error(
+ JSON.stringify({
+ level: "error",
+ event: "managed_agents.upstream_failed",
+ message: error instanceof Error ? error.message : String(error),
+ }),
+ );
+ return Response.json(
+ { error: "managed agents service is unavailable" },
+ { status: 502 },
+ );
+ }
+}
+
export async function proxyManagedAgents(
request: Request,
env: ManagedAgentsEnv,
diff --git a/web/src/App.tsx b/web/src/App.tsx
index 8db0503e..f6a284ae 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -3,6 +3,7 @@ import { Routes, Route, Navigate, useSearchParams } from 'react-router-dom'
import { AuthProvider } from './hooks/auth-provider'
import ProtectedRoute from './components/ProtectedRoute'
import AppShell from './components/app-shell'
+import PublicTemplateRoute from './components/PublicTemplateRoute'
import { managedAgentsExperimentEnabled } from './managed-agents/feature'
import { templateDeployPathFromSearch } from './managed-agents/templates'
@@ -56,6 +57,11 @@ export default function App() {
{/* Deferred-action executor — outside ProtectedRoute so the anonymous
branch can fire analytics + capture returnTo before login. */}
<Route path="do" element={<DeferredAction />} />
+ {/* Template links are shareable: anonymous visitors see the template
+ and its deploy form, and sign up when they actually deploy. */}
+ <Route element={<PublicTemplateRoute />}>
+ <Route path="template" element={<ManagedTemplateNew />} />
+ </Route>
<Route element={<ProtectedRoute />}>
<Route element={<AppShell />}>
<Route
@@ -91,7 +97,6 @@ export default function App() {
element={<Navigate to="/new" replace />}
/>
<Route path="new" element={<NewProject />} />
- <Route path="template" element={<ManagedTemplateNew />} />
<Route
path="projects/:projectId"
element={<ManagedProjectDetail />}
diff --git a/web/src/components/PublicTemplateRoute.tsx b/web/src/components/PublicTemplateRoute.tsx
new file mode 100644
index 00000000..41e85557
--- /dev/null
+++ b/web/src/components/PublicTemplateRoute.tsx
@@ -0,0 +1,53 @@
+import { Suspense } from 'react'
+import { Link, Outlet, useLocation } from 'react-router-dom'
+import { Loader2 } from 'lucide-react'
+import { useAuth } from '@/hooks/useAuth'
+import AppShell from '@/components/app-shell'
+import { Button } from '@/components/ui/button'
+import { loginPathForReturn } from '@/lib/login-path'
+
+// Layout for pages a visitor may open before signing up (a shared template
+// link). Signed-in users get the regular AppShell; anonymous visitors get a
+// bare header with a sign-in link that brings them back to the same URL.
+export default function PublicTemplateRoute() {
+ const { user, loading } = useAuth()
+ const location = useLocation()
+
+ if (loading) {
+ return (
+ <div className="bg-background flex min-h-screen items-center justify-center">
+ <Loader2 className="text-muted-foreground size-5 animate-spin" />
+ </div>
+ )
+ }
+
+ if (user) return <AppShell />
+
+ return (
+ <div className="bg-background text-foreground min-h-screen font-sans">
+ <header className="bg-sidebar flex h-16 items-center justify-between border-b px-6">
+ <Link to="/" className="flex items-center" aria-label="OpenComputer">
+ <span className="text-foreground font-mono text-[17px] font-semibold tracking-tight">
+ opencomputer
+ </span>
+ </Link>
+ <Button asChild size="sm">
+ <a href={loginPathForReturn(location.pathname + location.search)}>
+ Sign in
+ </a>
+ </Button>
+ </header>
+ <main className="mx-auto max-w-3xl px-6 py-8">
+ <Suspense
+ fallback={
+ <div className="flex min-h-[60vh] items-center justify-center">
+ <Loader2 className="text-muted-foreground size-5 animate-spin" />
+ </div>
+ }
+ >
+ <Outlet />
+ </Suspense>
+ </main>
+ </div>
+ )
+}
diff --git a/web/src/lib/login-path.ts b/web/src/lib/login-path.ts
new file mode 100644
index 00000000..52f001ab
--- /dev/null
+++ b/web/src/lib/login-path.ts
@@ -0,0 +1,7 @@
+// Server-owned login route carrying the URL to land on after the round-trip
+// (the edge threads it through the WorkOS `state`).
+export function loginPathForReturn(returnTo: string) {
+ return returnTo === '/'
+ ? '/auth/login'
+ : `/auth/login?returnTo=${encodeURIComponent(returnTo)}`
+}
diff --git a/web/src/managed-agents/TemplateNew.tsx b/web/src/managed-agents/TemplateNew.tsx
index 52cc5906..505671f8 100644
--- a/web/src/managed-agents/TemplateNew.tsx
+++ b/web/src/managed-agents/TemplateNew.tsx
@@ -1,8 +1,10 @@
import { FormEvent, useEffect, useRef, useState } from 'react'
import { useMutation, useQuery } from '@tanstack/react-query'
import { ExternalLink, FolderGit2, Loader2, Rocket } from 'lucide-react'
-import { useNavigate, useSearchParams } from 'react-router-dom'
+import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'
import { EmptyState } from '@/components/empty-state'
+import { loginPathForReturn } from '@/lib/login-path'
+import { useAuth } from '@/hooks/useAuth'
import { PageHeader } from '@/components/page-header'
import {
Panel,
@@ -46,6 +48,9 @@ async function waitForInstallation(id: string) {
export default function TemplateNew() {
const navigate = useNavigate()
+ const location = useLocation()
+ const { user } = useAuth()
+ const anonymous = !user
const [searchParams] = useSearchParams()
const repositoryUrl = searchParams.get('repository-url')?.trim() ?? ''
const quickStart = searchParams.get('quick-start') === '1'
@@ -160,6 +165,12 @@ export default function TemplateNew() {
function submit(event: FormEvent) {
event.preventDefault()
+ if (anonymous) {
+ window.location.assign(
+ loginPathForReturn(location.pathname + location.search),
+ )
+ return
+ }
install.mutate()
}
@@ -232,6 +243,12 @@ export default function TemplateNew() {
: reviewed.template.description
}
/>
+ {anonymous ? (
+ <p className="text-muted-foreground text-sm">
+ Sign in or create a free account to configure and deploy this template
+ to your own project.
+ </p>
+ ) : null}
{!quickStart ? (
<Panel>
<PanelHeader>
@@ -269,7 +286,8 @@ export default function TemplateNew() {
<Input
value={projectName}
onChange={(event) => setProjectName(event.target.value)}
- autoFocus={quickStart}
+ disabled={anonymous}
+ autoFocus={quickStart && !anonymous}
onFocus={(event) => {
if (quickStart) event.currentTarget.select()
}}
@@ -290,6 +308,7 @@ export default function TemplateNew() {
<Input
type="password"
autoComplete="off"
+ disabled={anonymous}
value={secrets[requirement.name] ?? ''}
onChange={(event) =>
setSecrets((current) => ({
@@ -312,6 +331,7 @@ export default function TemplateNew() {
<Input
value={variables[requirement.name] ?? ''}
placeholder={requirement.example}
+ disabled={anonymous}
required={requirement.required}
onChange={(event) =>
setVariables((current) => ({
@@ -328,10 +348,11 @@ export default function TemplateNew() {
<Button
type="submit"
disabled={
- !projectName.trim() ||
- missingSecret ||
- missingRequiredVariable ||
- install.isPending
+ !anonymous &&
+ (!projectName.trim() ||
+ missingSecret ||
+ missingRequiredVariable ||
+ install.isPending)
}
>
{install.isPending ? (
@@ -339,13 +360,15 @@ export default function TemplateNew() {
) : (
<Rocket />
)}
- {install.isPending
- ? quickStart
- ? 'Creating…'
- : 'Deploying…'
- : quickStart
- ? 'Create agent'
- : 'Deploy to Development'}
+ {anonymous
+ ? 'Sign in to deploy'
+ : install.isPending
+ ? quickStart
+ ? 'Creating…'
+ : 'Deploying…'
+ : quickStart
+ ? 'Create agent'
+ : 'Deploy to Development'}
</Button>
</div>
</form>