Skip to content

An open-source, faster Devin alternative

TypeScript

refactor(web): rename sandbox data layer Session→Sandbox (frees "Session")

Igor Zalutskicca1f2f1214d
diff --git a/web/src/App.tsx b/web/src/App.tsx
index e5c8c477..05369638 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -5,15 +5,15 @@ import ProtectedRoute from './components/ProtectedRoute'
import AppShell from './components/app-shell'
// Route pages are code-split so the initial bundle stays small; the heaviest
-// deps (xterm, in Terminal/LogsPanel) only load on SessionDetail when opened.
+// deps (xterm, in Terminal/LogsPanel) only load on SandboxDetail when opened.
const Dashboard = lazy(() => import('./pages/Dashboard'))
-const Sessions = lazy(() => import('./pages/Sessions'))
+const Sandboxes = lazy(() => import('./pages/Sandboxes'))
const APIKeys = lazy(() => import('./pages/APIKeys'))
const Checkpoints = lazy(() => import('./pages/Checkpoints'))
const Templates = lazy(() => import('./pages/Templates'))
const Settings = lazy(() => import('./pages/Settings'))
const Billing = lazy(() => import('./pages/Billing'))
-const SessionDetail = lazy(() => import('./pages/SessionDetail'))
+const SandboxDetail = lazy(() => import('./pages/SandboxDetail'))
export default function App() {
return (
@@ -22,9 +22,9 @@ export default function App() {
<Route element={<ProtectedRoute />}>
<Route element={<AppShell />}>
<Route index element={<Dashboard />} />
- <Route path="sandboxes" element={<Sessions />} />
- <Route path="sandboxes/:sandboxId" element={<SessionDetail />} />
- {/* Back-compat: the tab was renamed Sessions → Sandboxes. Keep the
+ <Route path="sandboxes" element={<Sandboxes />} />
+ <Route path="sandboxes/:sandboxId" element={<SandboxDetail />} />
+ {/* Back-compat: the tab was renamed Sandboxes → Sandboxes. Keep the
old deep links working, including /sessions/:sandboxId. */}
<Route
path="sessions"
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 545f2676..22e25e44 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -3,13 +3,13 @@ import { z } from 'zod'
import * as S from './schemas'
// Re-export the inferred response types (schemas are the single source of
-// truth) so existing `import { type Session } from '@/api/client'` keeps working.
+// truth) so existing `import { type Sandbox } from '@/api/client'` keeps working.
export type {
OrgInfo,
MeResponse,
- Session,
+ Sandbox,
PreviewURL,
- SessionDetail,
+ SandboxDetail,
SandboxStats,
CheckpointItem,
CheckpointsResponse,
@@ -133,11 +133,11 @@ export async function logout(): Promise<void> {
// API functions
export const getMe = () => apiFetch('/me', {}, S.MeResponseSchema)
-export const getSessions = (status?: string) =>
+export const getSandboxes = (status?: string) =>
apiFetch(
`/sessions${status ? `?status=${status}` : ''}`,
{},
- S.SessionListSchema,
+ S.SandboxListSchema,
)
export const getAPIKeys = () =>
@@ -173,21 +173,21 @@ export const getImages = (all = false) =>
export const deleteImage = (id: string) =>
apiFetch<void>(`/images/${id}`, { method: 'DELETE' })
-export const getSessionDetail = (sandboxId: string) =>
- apiFetch(`/sessions/${sandboxId}`, {}, S.SessionDetailSchema)
+export const getSandboxDetail = (sandboxId: string) =>
+ apiFetch(`/sessions/${sandboxId}`, {}, S.SandboxDetailSchema)
-export const getSessionStats = (sandboxId: string) =>
+export const getSandboxStats = (sandboxId: string) =>
apiFetch(`/sessions/${sandboxId}/stats`, {}, S.SandboxStatsSchema)
-export const deleteSession = (sandboxId: string) =>
+export const deleteSandbox = (sandboxId: string) =>
apiFetch<void>(`/sessions/${sandboxId}`, { method: 'DELETE' })
// Soft restart: guest kernel reboots, QEMU process + workspace stay.
-export const rebootSession = (sandboxId: string) =>
+export const rebootSandbox = (sandboxId: string) =>
apiFetch<void>(`/sessions/${sandboxId}/reboot`, { method: 'POST' })
// Hard restart: QEMU process recreated, workspace data preserved.
-export const powerCycleSession = (sandboxId: string) =>
+export const powerCycleSandbox = (sandboxId: string) =>
apiFetch<void>(`/sessions/${sandboxId}/power-cycle`, { method: 'POST' })
// Sandbox session logs: SSE stream of /var/log + exec stdout/stderr.
@@ -217,7 +217,7 @@ export interface LogStreamOptions {
limit?: number // historical batch cap; default 1000, max 10000
}
-export function streamSessionLogs(
+export function streamSandboxLogs(
sandboxId: string,
opts: LogStreamOptions = {},
): EventSource {
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
index 95785f00..a4d5aa19 100644
--- a/web/src/api/mock.ts
+++ b/web/src/api/mock.ts
@@ -25,7 +25,7 @@ const me = {
],
}
-const sessions = [
+const sandboxes = [
{
id: 's1',
sandboxId: 'sbx_a1b2c3d4e5',
@@ -377,7 +377,7 @@ const ROUTES: Array<[RegExp, Handler]> = [
[/^\/me$/, () => me],
[/^\/sessions\/[^/]+\/stats$/, () => sandboxStats],
[/^\/sessions\/[^/]+$/, () => sessionDetail],
- [/^\/sessions(\?.*)?$/, () => sessions],
+ [/^\/sessions(\?.*)?$/, () => sandboxes],
[/^\/images(\?.*)?$/, () => images],
[
/^\/checkpoints(\?.*)?$/,
diff --git a/web/src/api/schemas.ts b/web/src/api/schemas.ts
index 8a8f3edf..f75717e2 100644
--- a/web/src/api/schemas.ts
+++ b/web/src/api/schemas.ts
@@ -21,7 +21,7 @@ export const MeResponseSchema = z.object({
orgs: z.array(OrgInfoSchema).optional(),
})
-export const SessionSchema = z.object({
+export const SandboxSchema = z.object({
id: z.string(),
sandboxId: z.string(),
orgId: z.string(),
@@ -33,7 +33,7 @@ export const SessionSchema = z.object({
stoppedAt: z.string().optional(),
errorMsg: z.string().optional(),
})
-export const SessionListSchema = z.array(SessionSchema)
+export const SandboxListSchema = z.array(SandboxSchema)
export const PreviewURLSchema = z.object({
id: z.string(),
@@ -48,7 +48,7 @@ export const PreviewURLSchema = z.object({
createdAt: z.string(),
})
-export const SessionDetailSchema = z.object({
+export const SandboxDetailSchema = z.object({
id: z.string(),
sandboxId: z.string(),
template: z.string(),
@@ -241,9 +241,9 @@ export const SandboxUsageSchema = z.object({
export type OrgInfo = z.infer<typeof OrgInfoSchema>
export type MeResponse = z.infer<typeof MeResponseSchema>
-export type Session = z.infer<typeof SessionSchema>
+export type Sandbox = z.infer<typeof SandboxSchema>
export type PreviewURL = z.infer<typeof PreviewURLSchema>
-export type SessionDetail = z.infer<typeof SessionDetailSchema>
+export type SandboxDetail = z.infer<typeof SandboxDetailSchema>
export type SandboxStats = z.infer<typeof SandboxStatsSchema>
export type CheckpointItem = z.infer<typeof CheckpointItemSchema>
export type CheckpointsResponse = z.infer<typeof CheckpointsResponseSchema>
diff --git a/web/src/components/LogsPanel.tsx b/web/src/components/LogsPanel.tsx
index f769317f..87fb0b0f 100644
--- a/web/src/components/LogsPanel.tsx
+++ b/web/src/components/LogsPanel.tsx
@@ -25,7 +25,7 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { X } from 'lucide-react'
-import { streamSessionLogs, type LogEvent } from '@/api/client'
+import { streamSandboxLogs, type LogEvent } from '@/api/client'
const visibleCap = 3000 // hard cap on retained events
const debounceMs = 200 // search-box debounce
@@ -98,7 +98,7 @@ export default function LogsPanel({ sandboxId, onClose }: LogsPanelProps) {
stickToBottomRef.current = true
setConnState('connecting')
- const es = streamSessionLogs(sandboxId, { tail: true })
+ const es = streamSandboxLogs(sandboxId, { tail: true })
es.onopen = () => setConnState('open')
es.onerror = () => setConnState('error')
diff --git a/web/src/hooks/use-prefetch.ts b/web/src/hooks/use-prefetch.ts
index 6c82fc4e..34a0d6f8 100644
--- a/web/src/hooks/use-prefetch.ts
+++ b/web/src/hooks/use-prefetch.ts
@@ -1,5 +1,5 @@
import { useQueryClient } from '@tanstack/react-query'
-import { getSessionDetail } from '@/api/client'
+import { getSandboxDetail } from '@/api/client'
/**
* Returns a prefetcher for a sandbox detail page. Call it on row hover/focus to
@@ -9,11 +9,11 @@ import { getSessionDetail } from '@/api/client'
export function usePrefetchSandbox() {
const queryClient = useQueryClient()
return (sandboxId: string) => {
- // Warm the code-split SessionDetail chunk (same module the route lazy-loads).
- void import('@/pages/SessionDetail')
+ // Warm the code-split SandboxDetail chunk (same module the route lazy-loads).
+ void import('@/pages/SandboxDetail')
void queryClient.prefetchQuery({
- queryKey: ['session-detail', sandboxId],
- queryFn: () => getSessionDetail(sandboxId),
+ queryKey: ['sandbox-detail', sandboxId],
+ queryFn: () => getSandboxDetail(sandboxId),
staleTime: 10_000,
})
}
diff --git a/web/src/pages/Dashboard.tsx b/web/src/pages/Dashboard.tsx
index a6200692..0eb931ea 100644
--- a/web/src/pages/Dashboard.tsx
+++ b/web/src/pages/Dashboard.tsx
@@ -5,8 +5,8 @@ import { Boxes } from 'lucide-react'
import {
createAPIKey,
getAPIKeys,
- getSessions,
- type Session,
+ getSandboxes,
+ type Sandbox,
} from '@/api/client'
import { usePrefetchSandbox } from '@/hooks/use-prefetch'
import { PageHeader } from '@/components/page-header'
@@ -25,7 +25,7 @@ import { Skeleton } from '@/components/ui/skeleton'
const SKILL_INSTALL_CMD = 'npx skills add diggerhq/opencomputer'
-function formatDuration(session: Session): string {
+function formatDuration(session: Sandbox): string {
const start = new Date(session.startedAt).getTime()
const end = session.stoppedAt
? new Date(session.stoppedAt).getTime()
@@ -36,7 +36,7 @@ function formatDuration(session: Session): string {
return `${Math.round((secs / 3600) * 10) / 10}h`
}
-function elapsedMinutes(session: Session): number {
+function elapsedMinutes(session: Sandbox): number {
return Math.round(
(Date.now() - new Date(session.startedAt).getTime()) / 1000 / 60,
)
@@ -45,12 +45,12 @@ function elapsedMinutes(session: Session): number {
export default function Dashboard() {
const prefetch = usePrefetchSandbox()
const { data: runningSessions, isLoading: loadingRunning } = useQuery({
- queryKey: ['sessions', 'running'],
- queryFn: () => getSessions('running'),
+ queryKey: ['sandboxes', 'running'],
+ queryFn: () => getSandboxes('running'),
})
const { data: allSessions, isLoading: loadingAll } = useQuery({
- queryKey: ['sessions', ''],
- queryFn: () => getSessions(),
+ queryKey: ['sandboxes', ''],
+ queryFn: () => getSandboxes(),
})
const active = runningSessions ?? []
@@ -61,7 +61,7 @@ export default function Dashboard() {
).length
const isFirstRun = !loadingAll && all.length === 0
- const recentColumns: Column<Session>[] = [
+ const recentColumns: Column<Sandbox>[] = [
{
key: 'id',
header: 'Sandbox ID',
@@ -186,7 +186,7 @@ export default function Dashboard() {
)
}
-function SandboxRow({ session }: { session: Session }) {
+function SandboxRow({ session }: { session: Sandbox }) {
const prefetch = usePrefetchSandbox()
const elapsed = elapsedMinutes(session)
return (
diff --git a/web/src/pages/SessionDetail.tsx b/web/src/pages/SandboxDetail.tsx
similarity index 93%
rename from web/src/pages/SessionDetail.tsx
rename to web/src/pages/SandboxDetail.tsx
index b5a8506d..ebac8e31 100644
--- a/web/src/pages/SessionDetail.tsx
+++ b/web/src/pages/SandboxDetail.tsx
@@ -13,13 +13,13 @@ import {
Loader2,
} from 'lucide-react'
import {
- deleteSession,
- getSessionDetail,
- getSessionStats,
- powerCycleSession,
- rebootSession,
- type Session,
- type SessionDetail as SessionDetailData,
+ deleteSandbox,
+ getSandboxDetail,
+ getSandboxStats,
+ powerCycleSandbox,
+ rebootSandbox,
+ type Sandbox,
+ type SandboxDetail as SessionDetailData,
} from '@/api/client'
// Lazy — these pull in xterm / the SSE stream; keep them out of the main chunk.
const Terminal = lazy(() => import('@/components/Terminal'))
@@ -52,7 +52,7 @@ function timeAgo(dateStr: string): string {
type ConfirmKind = 'delete' | 'reboot' | 'power-cycle' | null
-export default function SessionDetail() {
+export default function SandboxDetail() {
const { sandboxId } = useParams<{ sandboxId: string }>()
const navigate = useNavigate()
const queryClient = useQueryClient()
@@ -64,14 +64,14 @@ export default function SessionDetail() {
const [confirm, setConfirm] = useState<ConfirmKind>(null)
const { data: session, isLoading } = useQuery({
- queryKey: ['session-detail', sandboxId],
- queryFn: () => getSessionDetail(sandboxId!),
+ queryKey: ['sandbox-detail', sandboxId],
+ queryFn: () => getSandboxDetail(sandboxId!),
enabled: !!sandboxId,
})
const { data: stats } = useQuery({
- queryKey: ['session-stats', sandboxId],
- queryFn: () => getSessionStats(sandboxId!),
+ queryKey: ['sandbox-stats', sandboxId],
+ queryFn: () => getSandboxStats(sandboxId!),
enabled: !!sandboxId && session?.status === 'running',
refetchInterval: 5000,
retry: false,
@@ -79,31 +79,33 @@ export default function SessionDetail() {
const invalidate = () => {
void queryClient.invalidateQueries({
- queryKey: ['session-detail', sandboxId],
+ queryKey: ['sandbox-detail', sandboxId],
})
void queryClient.invalidateQueries({
- queryKey: ['session-stats', sandboxId],
+ queryKey: ['sandbox-stats', sandboxId],
})
- void queryClient.invalidateQueries({ queryKey: ['sessions'] })
+ void queryClient.invalidateQueries({ queryKey: ['sandboxes'] })
}
const deleteMutation = useMutation({
- mutationFn: () => deleteSession(sandboxId!),
+ mutationFn: () => deleteSandbox(sandboxId!),
onMutate: async () => {
await queryClient.cancelQueries({
- queryKey: ['session-detail', sandboxId],
+ queryKey: ['sandbox-detail', sandboxId],
})
const stoppedAt = new Date().toISOString()
queryClient.setQueryData<SessionDetailData>(
- ['session-detail', sandboxId],
+ ['sandbox-detail', sandboxId],
(old) => (old ? { ...old, status: 'stopped', stoppedAt } : old),
)
- queryClient.setQueriesData<Session[]>({ queryKey: ['sessions'] }, (old) =>
- old?.map((item) =>
- item.sandboxId === sandboxId
- ? { ...item, status: 'stopped', stoppedAt }
- : item,
- ),
+ queryClient.setQueriesData<Sandbox[]>(
+ { queryKey: ['sandboxes'] },
+ (old) =>
+ old?.map((item) =>
+ item.sandboxId === sandboxId
+ ? { ...item, status: 'stopped', stoppedAt }
+ : item,
+ ),
)
setShowTerminal(false)
},
@@ -112,13 +114,13 @@ export default function SessionDetail() {
})
const rebootMutation = useMutation({
- mutationFn: () => rebootSession(sandboxId!),
+ mutationFn: () => rebootSandbox(sandboxId!),
onError: (e) => notifyError("Couldn't reboot the sandbox.", e),
onSettled: invalidate,
})
const powerCycleMutation = useMutation({
- mutationFn: () => powerCycleSession(sandboxId!),
+ mutationFn: () => powerCycleSandbox(sandboxId!),
onError: (e) => notifyError("Couldn't power-cycle the sandbox.", e),
onSettled: invalidate,
})
diff --git a/web/src/pages/Sessions.tsx b/web/src/pages/Sandboxes.tsx
similarity index 91%
rename from web/src/pages/Sessions.tsx
rename to web/src/pages/Sandboxes.tsx
index 51f69395..b2223de2 100644
--- a/web/src/pages/Sessions.tsx
+++ b/web/src/pages/Sandboxes.tsx
@@ -4,7 +4,7 @@ import { Link } from 'react-router-dom'
import { Boxes } from 'lucide-react'
import { notifyError } from '@/lib/errors'
import { usePrefetchSandbox } from '@/hooks/use-prefetch'
-import { deleteSession, getSessions, type Session } from '@/api/client'
+import { deleteSandbox, getSandboxes, type Sandbox } from '@/api/client'
import { PageHeader } from '@/components/page-header'
import { Panel } from '@/components/panel'
import { Button } from '@/components/ui/button'
@@ -23,43 +23,45 @@ const STATUS_FILTERS = [
{ value: 'error', label: 'Error' },
] as const
-function canDeleteSession(session: Session) {
+function canDeleteSession(session: Sandbox) {
return session.status === 'running' || session.status === 'hibernated'
}
-export default function Sessions() {
+export default function Sandboxes() {
const queryClient = useQueryClient()
const prefetch = usePrefetchSandbox()
const [status, setStatus] = useState<string>('')
- const [toDelete, setToDelete] = useState<Session | null>(null)
+ const [toDelete, setToDelete] = useState<Sandbox | null>(null)
const { data: sessions, isLoading } = useQuery({
- queryKey: ['sessions', status],
- queryFn: () => getSessions(status || undefined),
+ queryKey: ['sandboxes', status],
+ queryFn: () => getSandboxes(status || undefined),
})
// Always fetch all sessions for the activity chart.
const { data: allSessions, isLoading: loadingAll } = useQuery({
- queryKey: ['sessions', ''],
- queryFn: () => getSessions(),
+ queryKey: ['sandboxes', ''],
+ queryFn: () => getSandboxes(),
})
const deleteMutation = useMutation({
- mutationFn: (sandboxId: string) => deleteSession(sandboxId),
+ mutationFn: (sandboxId: string) => deleteSandbox(sandboxId),
onMutate: async (sandboxId) => {
- await queryClient.cancelQueries({ queryKey: ['sessions'] })
+ await queryClient.cancelQueries({ queryKey: ['sandboxes'] })
const stoppedAt = new Date().toISOString()
- queryClient.setQueriesData<Session[]>({ queryKey: ['sessions'] }, (old) =>
- old?.map((session) =>
- session.sandboxId === sandboxId
- ? { ...session, status: 'stopped', stoppedAt }
- : session,
- ),
+ queryClient.setQueriesData<Sandbox[]>(
+ { queryKey: ['sandboxes'] },
+ (old) =>
+ old?.map((session) =>
+ session.sandboxId === sandboxId
+ ? { ...session, status: 'stopped', stoppedAt }
+ : session,
+ ),
)
},
onError: (error) => notifyError("Couldn't delete the sandbox.", error),
onSettled: () => {
- void queryClient.invalidateQueries({ queryKey: ['sessions'] })
+ void queryClient.invalidateQueries({ queryKey: ['sandboxes'] })
},
})
@@ -70,7 +72,7 @@ export default function Sessions() {
})
}
- const columns: Column<Session>[] = [
+ const columns: Column<Sandbox>[] = [
{
key: 'id',
header: 'Sandbox ID',
@@ -199,7 +201,7 @@ function ActivityChart({
sessions,
loading,
}: {
- sessions: Session[]
+ sessions: Sandbox[]
loading: boolean
}) {
const { days, maxCount } = useMemo(() => {