An open-source, faster Devin alternative
TypeScript
fix(web): review round 3 — org-switch refetch, legacy redirect, Node pin, etc.
Igor Zalutski776294b867c0
diff --git a/.agents/work/done/web-ui-modernization.md b/.agents/work/done/web-ui-modernization.mdindex 5f1531b0..6dc245de 100644--- a/.agents/work/done/web-ui-modernization.md+++ b/.agents/work/done/web-ui-modernization.md@@ -415,8 +415,13 @@ oversized live components (Billing, SessionDetail) ·a `/design-system` gallery (or Ladle/Storybook) if wrapper drift becomes real ·axe/Playwright automation · full semantic palette (logs/chart/billing/ANSI) ·Newsreader for sparse titles · sticky table columns / mobile card fallback /-icon-rail · **upgrade-only** runtime bumps if nothing forces them sooner-(React 19 + RR7, Vite 8 + plugin, TS 6).+icon-rail.++> **Note (2026-06-27):** the **upgrade-only runtime bumps were done**+> intentionally (user-requested, post-modernization): React 19, React Router 7,+> Vite 8 + `@vitejs/plugin-react` 5.2, TS 6, zod 4. Vite 8 requires **Node+> ≥20.19** — pinned via `web/package.json` engines + `web/.nvmrc` + the+> deploy-server workflow on Node 22. ESLint held at 9 (jsx-a11y peers `^9`).## Referencesdiff --git a/.github/workflows/deploy-server.yml b/.github/workflows/deploy-server.ymlindex 15c1c909..0018e57f 100644--- a/.github/workflows/deploy-server.yml+++ b/.github/workflows/deploy-server.yml@@ -31,7 +31,7 @@ jobs:- uses: actions/setup-node@v4with:- node-version: '20'+ node-version: '22'- name: Build server binaryrun: |diff --git a/web/.nvmrc b/web/.nvmrcnew file mode 100644index 00000000..2bd5a0a9--- /dev/null+++ b/web/.nvmrc@@ -0,0 +1 @@+22diff --git a/web/package.json b/web/package.jsonindex 38a9ce45..be34d689 100644--- a/web/package.json+++ b/web/package.json@@ -3,6 +3,9 @@"private": true,"version": "0.1.0","type": "module",+ "engines": {+ "node": ">=20.19.0"+ },"scripts": {"dev": "vite","dev:preview": "VITE_PREVIEW=1 vite",diff --git a/web/src/App.tsx b/web/src/App.tsxindex 3d363b4e..e5c8c477 100644--- a/web/src/App.tsx+++ b/web/src/App.tsx@@ -1,5 +1,5 @@import { lazy } from 'react'-import { Routes, Route, Navigate } from 'react-router-dom'+import { Routes, Route, Navigate, useParams } from 'react-router-dom'import { AuthProvider } from './hooks/auth-provider'import ProtectedRoute from './components/ProtectedRoute'import AppShell from './components/app-shell'@@ -24,11 +24,16 @@ export default function App() {<Route index element={<Dashboard />} /><Route path="sandboxes" element={<Sessions />} /><Route path="sandboxes/:sandboxId" element={<SessionDetail />} />- {/* Back-compat: the tab was renamed Sessions → Sandboxes. */}+ {/* Back-compat: the tab was renamed Sessions → Sandboxes. Keep the+ old deep links working, including /sessions/:sandboxId. */}<Routepath="sessions"element={<Navigate to="/sandboxes" replace />}/>+ <Route+ path="sessions/:sandboxId"+ element={<LegacySandboxRedirect />}+ /><Route path="checkpoints" element={<Checkpoints />} /><Route path="templates" element={<Templates />} /><Route path="api-keys" element={<APIKeys />} />@@ -41,3 +46,9 @@ export default function App() {</AuthProvider>)}++// Preserves the :sandboxId when redirecting the old /sessions/:id deep link.+function LegacySandboxRedirect() {+ const { sandboxId } = useParams()+ return <Navigate to={`/sandboxes/${sandboxId ?? ''}`} replace />+}diff --git a/web/src/api/agents.ts b/web/src/api/agents.tsnew file mode 100644index 00000000..1d6d09b1--- /dev/null+++ b/web/src/api/agents.ts@@ -0,0 +1,316 @@+// Dormant agent API client — the agent dashboard pages were removed (orphaned).+// Kept for reference; the upcoming Durable Sessions UI will build its own.+// Nothing imports this yet.++import { apiFetch } from './client'++// ── Agents (proxied to sessions-api at /api/dashboard/agents/*) ──++export interface Agent {+ id: string+ display_name: string+ core: string | null+ model: string | null+ 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>+ created_at: string+ updated_at: string+}++export interface AgentDetail extends Agent {+ status: 'ready' | 'starting' | 'degraded' | 'error' | 'unknown'+ 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+ }>+ current_operation: AgentOperation | null+ last_error: { phase: string; message: string; at: string } | null+}++export interface AgentOperation {+ id: string+ agent_id: string+ kind: string+ target_type?: string | null+ target_key?: string | null+ phase: string+ state: 'queued' | 'running' | 'success' | 'error' | 'canceled'+ message?: string | null+ created_at: string+ updated_at: string+}++export const listAgents = () => apiFetch<{ agents: Agent[] }>('/agents')++export const getAgent = (id: string) =>+ apiFetch<AgentDetail>(`/agents/${encodeURIComponent(id)}`)++export const createAgent = (input: {+ id: string+ display_name?: string+ core?: string+ model?: string+ config?: Record<string, unknown>+ secrets?: Record<string, string>+}) =>+ apiFetch<AgentDetail>('/agents', {+ method: 'POST',+ body: JSON.stringify(input),+ })++export const deleteAgent = (id: string) =>+ 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',+ })++export const uninstallGbrain = (agentId: string) =>+ apiFetch<{ agent_id: string; package: string; status: string }>(+ `/agents/${encodeURIComponent(agentId)}/packages/gbrain`,+ { method: 'DELETE' },+ )++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 }),+ })++export const disconnectTelegram = (agentId: string) =>+ apiFetch<{ agent_id: string; channel: string; status: string }>(+ `/agents/${encodeURIComponent(agentId)}/channels/telegram`,+ { method: 'DELETE' },+ )++export interface AgentEvent {+ id: string+ agent_id: string+ type: 'info' | 'warning' | 'error'+ phase: string+ message: string+ at: string+}++export const getAgentEvents = (agentId: string, limit = 50) =>+ apiFetch<{ events: AgentEvent[]; next_before: string | null }>(+ `/agents/${encodeURIComponent(agentId)}/events?limit=${limit}`,+ )++export const getAgentOperations = (agentId: string, limit = 20) =>+ apiFetch<{ operations: AgentOperation[]; next_before: string | null }>(+ `/agents/${encodeURIComponent(agentId)}/operations?limit=${limit}`,+ )++export const restartAgent = (agentId: string) =>+ apiFetch<{ agent_id: string; status: string }>(+ `/agents/${encodeURIComponent(agentId)}/restart`,+ { method: 'POST' },+ )++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}`)++// ── Per-agent paywalled feature subscriptions (Telegram et al) ──++// Known values: 'ungated' | 'subscription_required'; typed as string so a new+// server reason never fails typing.+export type EntitlementReason = string++export interface AgentEntitlement {+ feature: string+ entitled: boolean+ reason?: EntitlementReason+ price_monthly_cents?: number+ status?: string+ current_period_end?: string+ cancel_at_period_end?: boolean+ stripe_subscription_id?: string+}++export const listAgentEntitlements = (agentId: string) =>+ apiFetch<{ agent_id: string; entitlements: AgentEntitlement[] }>(+ `/agents/${encodeURIComponent(agentId)}/entitlements`,+ )++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: 'ungated'; feature: string; agent_id: string }+ | {+ status: 'checkout_required'+ feature: string+ agent_id: string+ checkout_url: string+ }++export const subscribeAgentFeature = (agentId: string, feature: string) =>+ apiFetch<SubscribeResult>(+ `/agents/${encodeURIComponent(agentId)}/subscriptions/${encodeURIComponent(feature)}`,+ { method: 'POST' },+ )++export interface OrgAgentSubscription {+ agent_id: string+ feature: string+ status: string+ active: boolean+ price_monthly_cents: number+ current_period_end?: string+ cancel_at_period_end: boolean+ canceled_at?: string+ created_at: string+ stripe_subscription_id: string+}++export const listOrgAgentSubscriptions = () =>+ apiFetch<{ subscriptions: OrgAgentSubscription[] }>(+ '/billing/agent-subscriptions',+ )++export const cancelAgentFeature = (agentId: string, feature: string) =>+ apiFetch<{+ status: string+ feature: string+ agent_id: string+ cancel_at_period_end: boolean+ current_period_end?: string+ }>(+ `/agents/${encodeURIComponent(agentId)}/subscriptions/${encodeURIComponent(feature)}`,+ { method: 'DELETE' },+ )++/**+ * Streams a chat turn to an agent's instance and yields parsed SSE events+ * as they arrive. The upstream (sessions-api POST /v1/agents/:id/instances/:id/messages)+ * emits `data: {type:"text",content:"..."}` and `data: {type:"done"}`.+ *+ * Uses fetch + ReadableStream because EventSource is GET-only.+ */+export type ChatEvent =+ | { type: 'text'; content: string; conversation_id?: string }+ | { type: 'done' }+ | { type: 'raw'; data: string }++export interface ChatTurn {+ role: 'user' | 'assistant' | 'system'+ content: string+}++export async function* streamAgentChat(+ agentId: string,+ instanceId: string,+ content: string,+ conversationId?: string,+ history?: ChatTurn[],+): AsyncGenerator<ChatEvent, void, unknown> {+ // OpenAI-style chat-completions is stateless: the gateway needs the+ // full conversation each turn to have any memory of prior messages.+ // Caller passes `history` (already including the new user turn).+ // For backwards compat with older callers, we still accept `content`+ // as a single-turn shortcut.+ const body: Record<string, unknown> = {}+ if (history && history.length > 0) {+ body.messages = history+ } else {+ body.content = content+ }+ if (conversationId) body.conversation_id = conversationId++ const res = await fetch(+ `/api/dashboard/agents/${encodeURIComponent(agentId)}/instances/${encodeURIComponent(instanceId)}/messages`,+ {+ method: 'POST',+ credentials: 'include',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify(body),+ },+ )+ if (!res.ok || !res.body) {+ const text = await res.text().catch(() => '')+ throw new Error(`chat ${res.status}: ${text || 'no body'}`)+ }++ const reader = res.body.getReader()+ const decoder = new TextDecoder()+ let buffer = ''+ while (true) {+ const { done, value } = await reader.read()+ if (done) return+ buffer += decoder.decode(value, { stream: true })+ let idx: number+ while ((idx = buffer.indexOf('\n\n')) !== -1) {+ const block = buffer.slice(0, idx)+ buffer = buffer.slice(idx + 2)+ const data = block+ .split('\n')+ .filter((line) => line.startsWith('data:'))+ .map((line) => line.slice(5).trimStart())+ .join('\n')+ if (!data) continue+ try {+ yield JSON.parse(data) as ChatEvent+ } catch {+ yield { type: 'raw', data }+ }+ }+ }+}diff --git a/web/src/api/client.ts b/web/src/api/client.tsindex 1cf78e42..578d8d9c 100644--- a/web/src/api/client.ts+++ b/web/src/api/client.ts@@ -338,314 +338,3 @@ export const setAutumnAutoTopup = (cfg: {// Per-sandbox usage breakdown (compute cost over a recent window)export const getSandboxUsage = (days = 30) =>apiFetch(`/usage/sandboxes?days=${days}`, {}, S.SandboxUsageSchema)--// ── Agents (proxied to sessions-api at /api/dashboard/agents/*) ──--export interface Agent {- id: string- display_name: string- core: string | null- model: string | null- 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>- created_at: string- updated_at: string-}--export interface AgentDetail extends Agent {- status: 'ready' | 'starting' | 'degraded' | 'error' | 'unknown'- 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- }>- current_operation: AgentOperation | null- last_error: { phase: string; message: string; at: string } | null-}--export interface AgentOperation {- id: string- agent_id: string- kind: string- target_type?: string | null- target_key?: string | null- phase: string- state: 'queued' | 'running' | 'success' | 'error' | 'canceled'- message?: string | null- created_at: string- updated_at: string-}--export const listAgents = () => apiFetch<{ agents: Agent[] }>('/agents')--export const getAgent = (id: string) =>- apiFetch<AgentDetail>(`/agents/${encodeURIComponent(id)}`)--export const createAgent = (input: {- id: string- display_name?: string- core?: string- model?: string- config?: Record<string, unknown>- secrets?: Record<string, string>-}) =>- apiFetch<AgentDetail>('/agents', {- method: 'POST',- body: JSON.stringify(input),- })--export const deleteAgent = (id: string) =>- 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',- })--export const uninstallGbrain = (agentId: string) =>- apiFetch<{ agent_id: string; package: string; status: string }>(- `/agents/${encodeURIComponent(agentId)}/packages/gbrain`,- { method: 'DELETE' },- )--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 }),- })--export const disconnectTelegram = (agentId: string) =>- apiFetch<{ agent_id: string; channel: string; status: string }>(- `/agents/${encodeURIComponent(agentId)}/channels/telegram`,- { method: 'DELETE' },- )--export interface AgentEvent {- id: string- agent_id: string- type: 'info' | 'warning' | 'error'- phase: string- message: string- at: string-}--export const getAgentEvents = (agentId: string, limit = 50) =>- apiFetch<{ events: AgentEvent[]; next_before: string | null }>(- `/agents/${encodeURIComponent(agentId)}/events?limit=${limit}`,- )--export const getAgentOperations = (agentId: string, limit = 20) =>- apiFetch<{ operations: AgentOperation[]; next_before: string | null }>(- `/agents/${encodeURIComponent(agentId)}/operations?limit=${limit}`,- )--export const restartAgent = (agentId: string) =>- apiFetch<{ agent_id: string; status: string }>(- `/agents/${encodeURIComponent(agentId)}/restart`,- { method: 'POST' },- )--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}`)--// ── Per-agent paywalled feature subscriptions (Telegram et al) ──--// Known values: 'ungated' | 'subscription_required'; typed as string so a new-// server reason never fails typing.-export type EntitlementReason = string--export interface AgentEntitlement {- feature: string- entitled: boolean- reason?: EntitlementReason- price_monthly_cents?: number- status?: string- current_period_end?: string- cancel_at_period_end?: boolean- stripe_subscription_id?: string-}--export const listAgentEntitlements = (agentId: string) =>- apiFetch<{ agent_id: string; entitlements: AgentEntitlement[] }>(- `/agents/${encodeURIComponent(agentId)}/entitlements`,- )--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: 'ungated'; feature: string; agent_id: string }- | {- status: 'checkout_required'- feature: string- agent_id: string- checkout_url: string- }--export const subscribeAgentFeature = (agentId: string, feature: string) =>- apiFetch<SubscribeResult>(- `/agents/${encodeURIComponent(agentId)}/subscriptions/${encodeURIComponent(feature)}`,- { method: 'POST' },- )--export interface OrgAgentSubscription {- agent_id: string- feature: string- status: string- active: boolean- price_monthly_cents: number- current_period_end?: string- cancel_at_period_end: boolean- canceled_at?: string- created_at: string- stripe_subscription_id: string-}--export const listOrgAgentSubscriptions = () =>- apiFetch<{ subscriptions: OrgAgentSubscription[] }>(- '/billing/agent-subscriptions',- )--export const cancelAgentFeature = (agentId: string, feature: string) =>- apiFetch<{- status: string- feature: string- agent_id: string- cancel_at_period_end: boolean- current_period_end?: string- }>(- `/agents/${encodeURIComponent(agentId)}/subscriptions/${encodeURIComponent(feature)}`,- { method: 'DELETE' },- )--/**- * Streams a chat turn to an agent's instance and yields parsed SSE events- * as they arrive. The upstream (sessions-api POST /v1/agents/:id/instances/:id/messages)- * emits `data: {type:"text",content:"..."}` and `data: {type:"done"}`.- *- * Uses fetch + ReadableStream because EventSource is GET-only.- */-export type ChatEvent =- | { type: 'text'; content: string; conversation_id?: string }- | { type: 'done' }- | { type: 'raw'; data: string }--export interface ChatTurn {- role: 'user' | 'assistant' | 'system'- content: string-}--export async function* streamAgentChat(- agentId: string,- instanceId: string,- content: string,- conversationId?: string,- history?: ChatTurn[],-): AsyncGenerator<ChatEvent, void, unknown> {- // OpenAI-style chat-completions is stateless: the gateway needs the- // full conversation each turn to have any memory of prior messages.- // Caller passes `history` (already including the new user turn).- // For backwards compat with older callers, we still accept `content`- // as a single-turn shortcut.- const body: Record<string, unknown> = {}- if (history && history.length > 0) {- body.messages = history- } else {- body.content = content- }- if (conversationId) body.conversation_id = conversationId-- const res = await fetch(- `/api/dashboard/agents/${encodeURIComponent(agentId)}/instances/${encodeURIComponent(instanceId)}/messages`,- {- method: 'POST',- credentials: 'include',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify(body),- },- )- if (!res.ok || !res.body) {- const text = await res.text().catch(() => '')- throw new Error(`chat ${res.status}: ${text || 'no body'}`)- }-- const reader = res.body.getReader()- const decoder = new TextDecoder()- let buffer = ''- while (true) {- const { done, value } = await reader.read()- if (done) return- buffer += decoder.decode(value, { stream: true })- let idx: number- while ((idx = buffer.indexOf('\n\n')) !== -1) {- const block = buffer.slice(0, idx)- buffer = buffer.slice(idx + 2)- const data = block- .split('\n')- .filter((line) => line.startsWith('data:'))- .map((line) => line.slice(5).trimStart())- .join('\n')- if (!data) continue- try {- yield JSON.parse(data) as ChatEvent- } catch {- yield { type: 'raw', data }- }- }- }-}diff --git a/web/src/components/LogsPanel.tsx b/web/src/components/LogsPanel.tsxindex 4a1098b0..351afd61 100644--- a/web/src/components/LogsPanel.tsx+++ b/web/src/components/LogsPanel.tsx@@ -12,10 +12,10 @@// unpins it.// - Hard cap on retained events (visibleCap below). Once exceeded,// drop the oldest. Memory grows linearly with cap and is bounded.-// - Search filters server-side (the SSE re-opens with `?q=...`); we-// debounce so each keystroke isn't a new connection.-// - Source filter is a comma-separated allowlist that maps directly-// to the server's ?source= param.+// - The EventSource opens ONCE per sandbox; search + source filters are+// applied client-side against the in-memory buffer (no SSE re-open on+// filter change). Search is debounced only to avoid re-running the filter+// pipeline on every keystroke.// - Pause toggle freezes display only — the EventSource keeps// receiving so unpausing catches up; if buffer overflows, oldest// pending events drop.diff --git a/web/src/components/Terminal.tsx b/web/src/components/Terminal.tsxindex 63b989a4..d12660ed 100644--- a/web/src/components/Terminal.tsx+++ b/web/src/components/Terminal.tsx@@ -118,23 +118,27 @@ export default function Terminal({ sandboxId, onClose }: TerminalProps) {wsRef.current = wsws.onopen = () => {+ if (disposed) returnsetStatus('connected')term.clear()term.focus()}ws.onmessage = (event) => {+ if (disposed) returnconst data = new Uint8Array(event.data)term.write(data)}ws.onclose = () => {+ if (disposed) returnsetStatus('disconnected')term.writeln('')term.writeln('\x1b[2m Session ended.\x1b[0m')}ws.onerror = () => {+ if (disposed) returnsetStatus('error')setErrorMsg('WebSocket connection failed')}diff --git a/web/src/hooks/auth-provider.tsx b/web/src/hooks/auth-provider.tsxindex 12e53b81..fb7223c2 100644--- a/web/src/hooks/auth-provider.tsx+++ b/web/src/hooks/auth-provider.tsx@@ -32,11 +32,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {const switchOrg = useCallback(async (orgId: string) => {await switchOrgApi(orgId)- // Drop all cached queries so no previous-org data lingers in- // sandboxes / billing / API keys; the active ['me'] query refetches.+ // Drop all cached (previous-org) data, then explicitly refetch ['me'] —+ // clear() removes the query but does NOT refetch the active observer, so+ // the shell would otherwise keep showing the old org. Other screens'+ // queries refetch when they re-render against the cleared cache.queryClient.clear()+ await refetch()},- [queryClient],+ [queryClient, refetch],)// A 401 is an expected unauthenticated state, not a surfaced error.