feat: add the multiplayer room server and client

A room is one conversation, one ssh sandbox, and one agent. Accounts
create rooms; friends join through a single-use invite link and a
display name; the agent speaks only through the message tool.

The server is Axum and SQLite. It serves the built Nuxt client, streams
room events over SSE, and runs one serialized turn loop per room with
turn-level steering copied from rhema-code. The client has the chat,
preview iframe, read-only file pane, xterm terminal, and presence.

Preview URLs are signed wildcard hosts, and the proxy tunnels HTTP over
ssh direct-tcpip. HostAgent::step remains deferred in the framework.
This commit is contained in:
vhaudiquet committed 2026-11-28 01:09:37 +01:00
1 parent 04dd63c4ca
commit 0035f4e031
69 files changed
+22501 -48

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
export class ApiRequestError extends Error {
status: number
constructor(message: string, status = 0) {
super(message)
this.name = 'ApiRequestError'
this.status = status
}
}
export function apiErrorMessage(error: unknown): string {
if (error instanceof ApiRequestError) return error.message
if (error instanceof Error && error.message) return error.message
return 'The request failed. Try again.'
}
function serverMessage(data: unknown): string | null {
if (!data || typeof data !== 'object') return null
if ('error' in data) {
const value = (data as { error: unknown }).error
if (typeof value === 'string' && value.trim()) return value
if (value && typeof value === 'object' && 'message' in value) {
const message = (value as { message: unknown }).message
if (typeof message === 'string' && message.trim()) return message
}
}
if ('message' in data) {
const value = (data as { message: unknown }).message
if (typeof value === 'string' && value.trim()) return value
}
return null
}
export function normalizeApiError(error: unknown): ApiRequestError {
if (error instanceof ApiRequestError) return error
if (error && typeof error === 'object') {
const status = 'status' in error && typeof (error as { status: unknown }).status === 'number'
? (error as { status: number }).status
: 0
const data = 'data' in error ? (error as { data: unknown }).data : null
const message = serverMessage(data)
if (message) return new ApiRequestError(message, status)
if (status === 0 && error instanceof Error && error.message) {
return new ApiRequestError(error.message, status)
}
if (status === 401) return new ApiRequestError('Your session has expired. Sign in again.', 401)
if (status === 403) return new ApiRequestError('You do not have access to that.', 403)
if (status === 404) return new ApiRequestError('That was not found.', 404)
}
return new ApiRequestError('The request failed. Try again.')
}
+54
View File
@@ -0,0 +1,54 @@
const MINUTE = 60_000
const HOUR = 3_600_000
const DAY = 86_400_000
export function relativeTime(at: number | null | undefined): string {
if (!at) return ''
const diff = Date.now() - at
if (diff < 45_000) return 'just now'
if (diff < HOUR) return `${Math.max(1, Math.round(diff / MINUTE))}m ago`
if (diff < DAY) return `${Math.round(diff / HOUR)}h ago`
if (diff < 7 * DAY) return `${Math.round(diff / DAY)}d ago`
return new Date(at).toLocaleDateString('en', { month: 'short', day: 'numeric' })
}
export function fullTime(at: number | null | undefined): string {
if (!at) return ''
return new Date(at).toLocaleString('en', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
})
}
export function formatDate(at: number | null | undefined): string {
if (!at) return ''
return new Date(at).toLocaleDateString('en', { year: 'numeric', month: 'short', day: 'numeric' })
}
export function formatSize(bytes: number): string {
if (bytes < 1024) return `${bytes} B`
if (bytes < 1024 * 1024) return `${Math.round((bytes / 1024) * 10) / 10} KB`
return `${Math.round((bytes / (1024 * 1024)) * 10) / 10} MB`
}
export function initials(name: string): string {
const parts = name.trim().split(/\s+/).filter(Boolean)
if (parts.length === 0) return '?'
const first = parts[0]?.[0] ?? ''
const second = parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? '') : ''
return (first + second).toUpperCase()
}
export function formatCost(cost: number | null | undefined): string {
if (cost === null || cost === undefined) return ''
if (cost === 0) return '$0.00'
if (cost < 0.01) return `$${cost.toFixed(4)}`
return `$${cost.toFixed(2)}`
}
export function plural(count: number, one: string, many: string): string {
return count === 1 ? one : many
}
+17
View File
@@ -0,0 +1,17 @@
const MEMBER_COLORS = [
'#3f6f5a',
'#8a5a2b',
'#4f5f8f',
'#8f4f5a',
'#6a5a8f',
'#2f6f6f',
'#7a6a2f',
'#5a6a3f',
]
/** Maps a server-provided identity color to its design token. */
export function memberColorVar(color: string | null | undefined): string {
if (color?.startsWith('var(')) return color
const index = color ? MEMBER_COLORS.indexOf(color.toLowerCase()) : -1
return index >= 0 ? `var(--member-${index + 1})` : 'var(--muted)'
}