// The computers page (`/computers`): every computer the owner has, whether its runner is connected, // and which agents it works for. Plain forms, no script, like the ChatGPT settings page. Kept out of // web.ts so the chat's design work there and this page don't step on each other. import { ago, esc, page, riskNotice, sentence, type Page } from './web.ts' export interface ComputerRow { name: string /** Its runner is connected now. */ online: boolean lastSeenAt?: string registeredAt?: string /** It has a runner token. False: only agents' records name it (removed, or never joined). */ registered: boolean /** Registered before runner tokens; needs to join again. */ legacy?: boolean /** The owner's agents it works for. */ agents: string[] } export interface ComputersView { computers: ComputerRow[] /** Every agent the owner has, for the assignment checkboxes. */ agents: string[] /** Each agent's full handle, by name: what the page shows. */ handles?: Record /** A fresh join code, right after the owner asked for one. */ invite?: { code: string; expiresAt: string; url: string; agents: string[] } /** What the last action did, or why it failed. */ notice?: { text: string; error?: boolean } /** Cloud sandboxes: whether they're offered here, and whether this owner has one. */ cloud?: { active: boolean; state: 'running' | 'starting' | 'asleep'; usd: number; hours: number; used?: number } } const CSS_GET = '' const CSS = '' /** "5m ago", "3h ago", or "on Nov 2" for older dates; "just now" under a minute. */ const since = (iso: string) => { const a = ago(iso) return a === 'now' ? 'just now' : /\d$/.test(a) ? `on ${a}` : `${a} ago` } const hidden = (name: string, value: string) => `` function computerHtml(c: ComputerRow, agents: string[], handles: Record = {}): string { const status = c.legacy ? `needs to join again` : !c.registered ? `not joined` : c.online ? `online` : `offline` const meta = [ c.online ? undefined : c.lastSeenAt ? `last seen ${since(c.lastSeenAt)}` : c.registered ? 'not connected since the service started' : undefined, c.registeredAt ? `joined ${since(c.registeredAt)}` : undefined, ].filter(Boolean) const boxes = agents.length ? `
${agents .map((a) => ``) .join('')}
` : `

No agents yet.

` return ( `

${esc(c.name)} ${status}

` + (meta.length ? `

${esc(sentence(meta.join(' · ')))}

` : '

') + `
${hidden('action', 'assign')}${hidden('name', c.name)}` + `
Works for
${boxes}
` + `
` + (agents.length ? `` : '') + `
${hidden('action', 'remove')}${hidden('name', c.name)}` + `
` + `
` ) } export function computersPage(v: ComputersView): Page { const notice = v.notice ? `

${esc(v.notice.text)}

` : '' const list = v.computers.length ? v.computers.map((c) => computerHtml(c, v.agents, v.handles)).join('') : `

No computers yet.

` const invite = v.invite ? `

On the new computer, in a Languid checkout, run this within ${Math.max(1, Math.round((Date.parse(v.invite.expiresAt) - Date.now()) / 60_000))} minutes:

` + `
bun run languid computer join ${esc(v.invite.url)} ${esc(v.invite.code)}
` + `

Joins as its hostname (--name to change) for ${esc(v.invite.agents.map((a) => v.handles?.[a] ?? a).join(', ') || 'no agents')}. Works once.

` : `
${hidden('action', 'invite')}
` return page( 200, 'Computers · Languid', CSS + CSS_GET + `

Computers

` + `

Where your agents read files and run commands. Docs

` + notice + list + `

Add a computer

` + riskNotice() + `

On a computer where you're signed in with languid login:

languid computer setup
` + `

Or join without signing in:

` + invite + `

Cloud sandbox

` + (!v.cloud ? `

Coming soon.

` : v.cloud.active ? `

languid-cloud · ${v.cloud.state === 'running' ? 'Running' : v.cloud.state === 'starting' ? 'Starting' : 'Asleep'}

` + `

$${v.cloud.usd}/month · ${(v.cloud.used ?? 0).toFixed(1)} of ${v.cloud.hours} hours used · Billing

` : `

A Linux computer that starts when your agents use it and sleeps after 5 idle minutes. $${v.cloud.usd}/month, ${v.cloud.hours} hours included.

Get a cloud sandbox · $${v.cloud.usd}/month

`), { path: '/computers', app: true }, ) }