Skip to content

An open-source, faster Devin alternative

TypeScript

feat(web): opt-in dev preview mode (mock API, no auth) for local rendering

Igor Zalutski53f921c9d8e5
diff --git a/web/package.json b/web/package.json
index 96396103..c9833af5 100644
--- a/web/package.json
+++ b/web/package.json
@@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
+ "dev:preview": "VITE_PREVIEW=1 vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"lint": "eslint .",
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 13357b23..a30645fd 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -2,7 +2,18 @@ import posthog from 'posthog-js'
const API_BASE = '/api/dashboard'
-export async function apiFetch<T>(path: string, options: RequestInit = {}): Promise<T> {
+export async function apiFetch<T>(
+ path: string,
+ options: RequestInit = {},
+): Promise<T> {
+ // Opt-in, dev-only preview mode: serve canned data with no backend/auth so
+ // the dashboard can be rendered locally (VITE_PREVIEW=1 npm run dev). The
+ // dynamic import + dead-when-unset flag keep the mock out of normal builds.
+ if (import.meta.env.VITE_PREVIEW) {
+ const { mockFetch } = await import('./mock')
+ return mockFetch<T>(path, options)
+ }
+
const res = await fetch(`${API_BASE}${path}`, {
...options,
credentials: 'include',
@@ -25,7 +36,8 @@ export async function apiFetch<T>(path: string, options: RequestInit = {}): Prom
// "[object Object]" when the proxy talks to sessions-api.
let msg: string
if (typeof body.error === 'string') msg = body.error
- else if (body.error && typeof body.error.message === 'string') msg = body.error.message
+ else if (body.error && typeof body.error.message === 'string')
+ msg = body.error.message
else if (typeof body.message === 'string') msg = body.message
else msg = `Request failed: ${res.status}`
throw new Error(msg)
@@ -45,7 +57,10 @@ export async function apiFetch<T>(path: string, options: RequestInit = {}): Prom
export async function logout(): Promise<void> {
let dest = '/auth/login'
try {
- const res = await fetch('/auth/logout', { method: 'POST', credentials: 'include' })
+ const res = await fetch('/auth/logout', {
+ method: 'POST',
+ credentials: 'include',
+ })
const body = await res.json().catch(() => ({}))
if (body && typeof body.logoutUrl === 'string' && body.logoutUrl) {
dest = body.logoutUrl
@@ -66,10 +81,13 @@ export const getSessions = (status?: string) =>
export const getAPIKeys = () => apiFetch<APIKey[]>('/api-keys')
export const createAPIKey = (name: string) =>
- apiFetch<{ id: string; name: string; key: string; keyPrefix: string; createdAt: string }>(
- '/api-keys',
- { method: 'POST', body: JSON.stringify({ name }) },
- )
+ apiFetch<{
+ id: string
+ name: string
+ key: string
+ keyPrefix: string
+ createdAt: string
+ }>('/api-keys', { method: 'POST', body: JSON.stringify({ name }) })
export const deleteAPIKey = (keyId: string) =>
apiFetch<void>(`/api-keys/${keyId}`, { method: 'DELETE' })
@@ -120,23 +138,27 @@ export interface LogEvent {
}
export interface LogStreamOptions {
- tail?: boolean // default true; if false, returns historical batch then closes
- q?: string // free-text search (server applies "line contains")
- source?: string // comma-separated subset of source values
- since?: string // RFC3339; default = sandbox.startedAt
- limit?: number // historical batch cap; default 1000, max 10000
+ tail?: boolean // default true; if false, returns historical batch then closes
+ q?: string // free-text search (server applies "line contains")
+ source?: string // comma-separated subset of source values
+ since?: string // RFC3339; default = sandbox.startedAt
+ limit?: number // historical batch cap; default 1000, max 10000
}
export function streamSessionLogs(
sandboxId: string,
opts: LogStreamOptions = {},
): EventSource {
- const url = new URL(`${API_BASE}/sessions/${encodeURIComponent(sandboxId)}/logs`, window.location.origin)
+ const url = new URL(
+ `${API_BASE}/sessions/${encodeURIComponent(sandboxId)}/logs`,
+ window.location.origin,
+ )
if (opts.tail !== undefined) url.searchParams.set('tail', String(opts.tail))
if (opts.q) url.searchParams.set('q', opts.q)
if (opts.source) url.searchParams.set('source', opts.source)
if (opts.since) url.searchParams.set('since', opts.since)
- if (opts.limit !== undefined) url.searchParams.set('limit', String(opts.limit))
+ if (opts.limit !== undefined)
+ url.searchParams.set('limit', String(opts.limit))
return new EventSource(url.toString(), { withCredentials: true })
}
@@ -146,7 +168,10 @@ export const updateOrg = (name: string) =>
apiFetch<Org>('/org', { method: 'PUT', body: JSON.stringify({ name }) })
export const setCustomDomain = (domain: string) =>
- apiFetch<Org>('/org/custom-domain', { method: 'PUT', body: JSON.stringify({ domain }) })
+ apiFetch<Org>('/org/custom-domain', {
+ method: 'PUT',
+ body: JSON.stringify({ domain }),
+ })
export const deleteCustomDomain = () =>
apiFetch<Org>('/org/custom-domain', { method: 'DELETE' })
@@ -338,7 +363,8 @@ export const sendInvitation = (email: string, role = 'member') =>
body: JSON.stringify({ email, role }),
})
-export const getInvitations = () => apiFetch<OrgInvitation[]>('/org/invitations')
+export const getInvitations = () =>
+ apiFetch<OrgInvitation[]>('/org/invitations')
export const revokeInvitation = (id: string) =>
apiFetch<void>(`/org/invitations/${id}`, { method: 'DELETE' })
@@ -347,7 +373,10 @@ export const revokeInvitation = (id: string) =>
export const listOrgs = () => apiFetch<OrgInfo[]>('/orgs')
export const switchOrg = (orgId: string) =>
- apiFetch<Org>('/org/switch', { method: 'POST', body: JSON.stringify({ orgId }) })
+ apiFetch<Org>('/org/switch', {
+ method: 'POST',
+ body: JSON.stringify({ orgId }),
+ })
// Credits
export const getCredits = () => apiFetch<Credits>('/org/credits')
@@ -426,7 +455,11 @@ export const autumnSubscribeConcurrency = (plan: string) =>
// url is non-null when enabling auto-recharge requires capturing an off-session
// card first — the caller redirects there (a no-charge Stripe setup session).
-export const setAutumnAutoTopup = (cfg: { enabled: boolean; threshold: number; quantity: number }) =>
+export const setAutumnAutoTopup = (cfg: {
+ enabled: boolean
+ threshold: number
+ quantity: number
+}) =>
apiFetch<{ ok: boolean; url?: string | null }>('/billing/autumn/auto-topup', {
method: 'POST',
body: JSON.stringify(cfg),
@@ -455,7 +488,11 @@ export interface Agent {
display_name: string
core: string | null
model: string | null
- channels: Array<{ name: string; bot_username?: string | null; connected_at?: string }>
+ channels: Array<{
+ name: string
+ bot_username?: string | null
+ connected_at?: string
+ }>
packages: Array<{ name: string; installed_at?: string }>
secret_store: string | null
config: Record<string, unknown>
@@ -468,10 +505,26 @@ export interface AgentDetail extends Agent {
instance_id: string | null
instance_status: string | null
sandbox_id: string | null
- core_status: { status: string; reason?: string; message?: string; updated_at?: string } | null
- channel_status: Record<string, { status: string; phase?: string; message?: string }>
- package_status: Record<string, { status: string; phase?: string; message?: string }>
- conditions: Array<{ type: string; status: string; reason?: string; message?: string }>
+ core_status: {
+ status: string
+ reason?: string
+ message?: string
+ updated_at?: string
+ } | null
+ channel_status: Record<
+ string,
+ { status: string; phase?: string; message?: string }
+ >
+ package_status: Record<
+ string,
+ { status: string; phase?: string; message?: string }
+ >
+ conditions: Array<{
+ type: string
+ status: string
+ reason?: string
+ message?: string
+ }>
current_operation: AgentOperation | null
last_error: { phase: string; message: string; at: string } | null
}
@@ -489,8 +542,7 @@ export interface AgentOperation {
updated_at: string
}
-export const listAgents = () =>
- apiFetch<{ agents: Agent[] }>('/agents')
+export const listAgents = () => apiFetch<{ agents: Agent[] }>('/agents')
export const getAgent = (id: string) =>
apiFetch<AgentDetail>(`/agents/${encodeURIComponent(id)}`)
@@ -509,15 +561,22 @@ export const createAgent = (input: {
})
export const deleteAgent = (id: string) =>
- apiFetch<{ id: string; deleted: boolean }>(`/agents/${encodeURIComponent(id)}`, {
- method: 'DELETE',
- })
+ apiFetch<{ id: string; deleted: boolean }>(
+ `/agents/${encodeURIComponent(id)}`,
+ {
+ method: 'DELETE',
+ },
+ )
export const installGbrain = (agentId: string) =>
- apiFetch<{ agent_id: string; package: string; status: string; operation: AgentOperation }>(
- `/agents/${encodeURIComponent(agentId)}/packages/gbrain`,
- { method: 'POST' },
- )
+ apiFetch<{
+ agent_id: string
+ package: string
+ status: string
+ operation: AgentOperation
+ }>(`/agents/${encodeURIComponent(agentId)}/packages/gbrain`, {
+ method: 'POST',
+ })
export const uninstallGbrain = (agentId: string) =>
apiFetch<{ agent_id: string; package: string; status: string }>(
@@ -526,13 +585,15 @@ export const uninstallGbrain = (agentId: string) =>
)
export const connectTelegram = (agentId: string, botToken: string) =>
- apiFetch<{ agent_id: string; channel: string; status: string; operation: AgentOperation }>(
- `/agents/${encodeURIComponent(agentId)}/channels/telegram`,
- {
- method: 'POST',
- body: JSON.stringify({ bot_token: botToken }),
- },
- )
+ apiFetch<{
+ agent_id: string
+ channel: string
+ status: string
+ operation: AgentOperation
+ }>(`/agents/${encodeURIComponent(agentId)}/channels/telegram`, {
+ method: 'POST',
+ body: JSON.stringify({ bot_token: botToken }),
+ })
export const disconnectTelegram = (agentId: string) =>
apiFetch<{ agent_id: string; channel: string; status: string }>(
@@ -566,9 +627,13 @@ export const restartAgent = (agentId: string) =>
)
export const getAgentLogs = (agentId: string, tail = 300) =>
- apiFetch<{ agent_id: string; sandbox_id: string; source: string; lines: number; content: string }>(
- `/agents/${encodeURIComponent(agentId)}/logs?tail=${tail}`,
- )
+ apiFetch<{
+ agent_id: string
+ sandbox_id: string
+ source: string
+ lines: number
+ content: string
+ }>(`/agents/${encodeURIComponent(agentId)}/logs?tail=${tail}`)
// ── Per-agent paywalled feature subscriptions (Telegram et al) ──
@@ -591,10 +656,26 @@ export const listAgentEntitlements = (agentId: string) =>
)
export type SubscribeResult =
- | { status: 'active'; feature: string; agent_id: string; subscription_id: string; price_id: string }
- | { status: 'already_subscribed'; feature: string; agent_id: string; subscription_id: string }
+ | {
+ status: 'active'
+ feature: string
+ agent_id: string
+ subscription_id: string
+ price_id: string
+ }
+ | {
+ status: 'already_subscribed'
+ feature: string
+ agent_id: string
+ subscription_id: string
+ }
| { status: 'ungated'; feature: string; agent_id: string }
- | { status: 'checkout_required'; feature: string; agent_id: string; checkout_url: string }
+ | {
+ status: 'checkout_required'
+ feature: string
+ agent_id: string
+ checkout_url: string
+ }
export const subscribeAgentFeature = (agentId: string, feature: string) =>
apiFetch<SubscribeResult>(
@@ -644,7 +725,10 @@ export type ChatEvent =
| { type: 'done' }
| { type: 'raw'; data: string }
-export interface ChatTurn { role: 'user' | 'assistant' | 'system'; content: string }
+export interface ChatTurn {
+ role: 'user' | 'assistant' | 'system'
+ content: string
+}
export async function* streamAgentChat(
agentId: string,
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
new file mode 100644
index 00000000..eb7405b7
--- /dev/null
+++ b/web/src/api/mock.ts
@@ -0,0 +1,276 @@
+// Opt-in, dev-only mock API for VITE_PREVIEW.
+//
+// Lets the dashboard render with no backend and no WorkOS auth so screens can
+// be reviewed / screenshotted locally. It is gated behind `VITE_PREVIEW` in
+// apiFetch() and dynamically imported, so it is never included in a normal
+// build (the branch is dead code when the flag is unset).
+//
+// Run it with: VITE_PREVIEW=1 npm run dev
+//
+// Returns are cast to the caller's T — mock objects only need the fields a
+// screen actually reads, not the full interface.
+
+// Fixed clock so screenshots are deterministic.
+const BASE = new Date('2026-06-26T17:00:00Z').getTime()
+const at = (daysAgo: number, hoursAgo = 0) =>
+ new Date(BASE - daysAgo * 86_400_000 - hoursAgo * 3_600_000).toISOString()
+
+const me = {
+ id: 'user_2abc',
+ email: '[email protected]',
+ orgId: 'org_digger',
+ orgs: [
+ { id: 'org_digger', name: 'Digger', isPersonal: false, isActive: true },
+ { id: 'org_personal', name: 'Personal', isPersonal: true, isActive: false },
+ ],
+}
+
+const sessions = [
+ {
+ id: 's1',
+ sandboxId: 'sbx_a1b2c3d4e5',
+ orgId: 'org_digger',
+ template: 'python-3.12',
+ region: 'us-east-1',
+ workerId: 'w1',
+ status: 'running',
+ startedAt: at(0, 3),
+ },
+ {
+ id: 's2',
+ sandboxId: 'sbx_f6g7h8i9j0',
+ orgId: 'org_digger',
+ template: 'base',
+ region: 'us-east-1',
+ workerId: 'w1',
+ status: 'running',
+ startedAt: at(0, 6),
+ },
+ {
+ id: 's3',
+ sandboxId: 'sbx_k1l2m3n4o5',
+ orgId: 'org_digger',
+ template: 'node-20',
+ region: 'eu-west-1',
+ workerId: 'w2',
+ status: 'hibernated',
+ startedAt: at(1, 2),
+ },
+ {
+ id: 's4',
+ sandboxId: 'sbx_p6q7r8s9t0',
+ orgId: 'org_digger',
+ template: 'base',
+ region: 'us-east-1',
+ workerId: 'w1',
+ status: 'stopped',
+ startedAt: at(2, 5),
+ stoppedAt: at(2, 1),
+ },
+ {
+ id: 's5',
+ sandboxId: 'sbx_u1v2w3x4y5',
+ orgId: 'org_digger',
+ template: 'python-3.12',
+ region: 'us-east-1',
+ workerId: 'w2',
+ status: 'error',
+ startedAt: at(3, 4),
+ errorMsg: 'sandbox boot timed out after 120s',
+ },
+ {
+ id: 's6',
+ sandboxId: 'sbx_z6a7b8c9d0',
+ orgId: 'org_digger',
+ template: 'rust-1.80',
+ region: 'eu-west-1',
+ workerId: 'w2',
+ status: 'stopped',
+ startedAt: at(5, 8),
+ stoppedAt: at(5, 2),
+ },
+ {
+ id: 's7',
+ sandboxId: 'sbx_e1f2g3h4i5',
+ orgId: 'org_digger',
+ template: 'base',
+ region: 'us-east-1',
+ workerId: 'w1',
+ status: 'stopped',
+ startedAt: at(6, 3),
+ stoppedAt: at(6, 1),
+ },
+]
+
+const images = [
+ {
+ id: 'img1',
+ orgId: 'org_digger',
+ contentHash: 'sha256:aa11bb22',
+ checkpointId: 'ckpt_aa11bb22cc33',
+ name: 'ml-base',
+ manifest: {
+ steps: [
+ { type: 'apt_install', args: { packages: ['ffmpeg', 'git'] } },
+ {
+ type: 'pip_install',
+ args: { packages: ['torch', 'numpy', 'pandas'] },
+ },
+ ],
+ },
+ status: 'ready',
+ lastUsedAt: at(0, 5),
+ createdAt: at(12),
+ },
+ {
+ id: 'img2',
+ orgId: 'org_digger',
+ contentHash: 'sha256:cc33dd44',
+ checkpointId: 'ckpt_dd44ee55ff66',
+ name: 'node-web',
+ manifest: {
+ steps: [
+ { type: 'run', args: { commands: ['npm i -g pnpm'] } },
+ { type: 'env', args: { vars: { NODE_ENV: 'production' } } },
+ ],
+ },
+ status: 'building',
+ lastUsedAt: at(1),
+ createdAt: at(3),
+ },
+ {
+ id: 'img3',
+ orgId: 'org_digger',
+ contentHash: 'sha256:ee55ff66',
+ name: '',
+ manifest: { steps: [] },
+ status: 'ready',
+ lastUsedAt: at(4),
+ createdAt: at(20),
+ },
+ {
+ id: 'img4',
+ orgId: 'org_digger',
+ contentHash: 'sha256:gg77hh88',
+ name: 'broken-img',
+ manifest: {
+ steps: [{ type: 'apt_install', args: { packages: ['nonexistent-pkg'] } }],
+ },
+ status: 'failed',
+ lastUsedAt: at(8),
+ createdAt: at(8),
+ },
+]
+
+const checkpoints = [
+ {
+ id: 'cp1',
+ sandboxId: 'sbx_a1b2c3d4e5',
+ orgId: 'org_digger',
+ name: 'after-deps-install',
+ status: 'ready',
+ kind: 'disk_only',
+ promotionStatus: 'ready',
+ sizeBytes: 1_240_000_000,
+ activeForks: 3,
+ totalForks: 18,
+ createdAt: at(0, 4),
+ },
+ {
+ id: 'cp2',
+ sandboxId: 'sbx_f6g7h8i9j0',
+ orgId: 'org_digger',
+ name: 'clean-base',
+ status: 'ready',
+ kind: 'full',
+ sizeBytes: 2_900_000_000,
+ activeForks: 0,
+ totalForks: 2,
+ createdAt: at(1, 6),
+ },
+ {
+ id: 'cp3',
+ sandboxId: 'sbx_k1l2m3n4o5',
+ orgId: 'org_digger',
+ name: 'web-build',
+ status: 'processing',
+ kind: 'disk_only',
+ promotionStatus: 'processing',
+ sizeBytes: 800_000_000,
+ activeForks: 0,
+ totalForks: 0,
+ createdAt: at(0, 1),
+ },
+ {
+ id: 'cp4',
+ sandboxId: 'sbx_p6q7r8s9t0',
+ orgId: 'org_digger',
+ name: 'snapshot-failed',
+ status: 'failed',
+ kind: 'disk_only',
+ sizeBytes: 0,
+ activeForks: 0,
+ totalForks: 0,
+ createdAt: at(2, 2),
+ errorMsg: 'archive upload to object store failed: connection reset by peer',
+ failedAt: at(2, 1),
+ },
+]
+
+const apiKeys = [
+ {
+ id: 'k1',
+ orgId: 'org_digger',
+ keyPrefix: 'osb_live_7Hq2',
+ name: 'Default',
+ scopes: ['*'],
+ lastUsed: at(0, 2),
+ createdAt: at(30),
+ },
+ {
+ id: 'k2',
+ orgId: 'org_digger',
+ keyPrefix: 'osb_live_Lp9x',
+ name: 'CI pipeline',
+ scopes: ['sandboxes:write'],
+ createdAt: at(14),
+ },
+]
+
+const autumn = { isHalted: false, balance: 4210, currency: 'usd' }
+
+type Handler = () => unknown
+
+// Ordered most-specific first. Matched against the path (without /api/dashboard).
+const ROUTES: Array<[RegExp, Handler]> = [
+ [/^\/me$/, () => me],
+ [/^\/sessions\/[^/]+\/stats$/, () => ({})],
+ [/^\/sessions\/[^/]+$/, () => sessions[0]],
+ [/^\/sessions(\?.*)?$/, () => sessions],
+ [/^\/images(\?.*)?$/, () => images],
+ [
+ /^\/checkpoints(\?.*)?$/,
+ () => ({ checkpoints, total: checkpoints.length, page: 1, perPage: 20 }),
+ ],
+ [/^\/api-keys$/, () => apiKeys],
+ [/^\/billing\/autumn$/, () => autumn],
+ [/^\/billing\/invoices/, () => []],
+ [/^\/org\/members$/, () => []],
+ [/^\/org\/invitations$/, () => []],
+ [/^\/org\/custom-domain$/, () => ({})],
+ [/^\/usage\/sandboxes/, () => []],
+ [/^\/agents$/, () => []],
+]
+
+export async function mockFetch<T>(
+ path: string,
+ options: RequestInit = {},
+): Promise<T> {
+ const method = (options.method ?? 'GET').toUpperCase()
+ if (method !== 'GET') return {} as T
+ for (const [re, handler] of ROUTES) {
+ if (re.test(path)) return handler() as T
+ }
+ // Unknown GET: empty list is the safe default for the list-heavy screens.
+ return [] as T
+}
diff --git a/web/src/vite-env.d.ts b/web/src/vite-env.d.ts
index a5f23e11..93251f63 100644
--- a/web/src/vite-env.d.ts
+++ b/web/src/vite-env.d.ts
@@ -3,6 +3,8 @@
interface ImportMetaEnv {
readonly VITE_PUBLIC_POSTHOG_PROJECT_TOKEN?: string
readonly VITE_PUBLIC_POSTHOG_HOST?: string
+ /** Opt-in dev-only flag: serve mock data with no backend/auth (see api/mock.ts). */
+ readonly VITE_PREVIEW?: string
}
interface ImportMeta {