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

+52
View File
@@ -0,0 +1,52 @@
import { ApiRequestError, normalizeApiError } from '~/utils/errors'
type ApiMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE'
interface RequestOptions {
method?: ApiMethod
body?: unknown
query?: Record<string, string | number | boolean | undefined>
}
const PUBLIC_PREFIXES = ['/setup', '/login', '/register', '/join']
export function useApi() {
const router = useRouter()
const route = useRoute()
const csrf = useCookie<string | null>('together_csrf', { sameSite: 'lax' })
function mayRedirect() {
return !PUBLIC_PREFIXES.some((prefix) => route.path === prefix || route.path.startsWith(`${prefix}/`))
}
async function request<T>(path: string, options: RequestOptions = {}): Promise<T> {
const method = options.method ?? 'GET'
const headers: Record<string, string> = { Accept: 'application/json' }
if (method !== 'GET' && csrf.value) headers['X-CSRF-Token'] = csrf.value
try {
return await $fetch<T>(path, {
baseURL: '/api',
method,
body: options.body as Record<string, unknown> | undefined,
query: options.query,
headers,
credentials: 'include',
retry: 0,
})
} catch (error) {
const failure = normalizeApiError(error)
if (failure.status === 401 && mayRedirect()) {
void router.replace('/login')
}
throw failure
}
}
return {
get: <T>(path: string, query?: RequestOptions['query']) => request<T>(path, { query }),
post: <T>(path: string, body?: unknown) => request<T>(path, { method: 'POST', body }),
patch: <T>(path: string, body?: unknown) => request<T>(path, { method: 'PATCH', body }),
del: <T>(path: string) => request<T>(path, { method: 'DELETE' }),
ApiRequestError,
}
}