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

+136
View File
@@ -0,0 +1,136 @@
<script setup lang="ts">
import { nextTick, onBeforeUnmount, ref } from 'vue'
import { AtSign, Send } from 'lucide-vue-next'
import type { Message, SendMessageResponse } from '~/types'
import { apiErrorMessage } from '~/utils/errors'
const props = defineProps<{ roomId: string }>()
const emit = defineEmits<{ sent: [message: Message]; typing: [active: boolean] }>()
const api = useApi()
const text = ref('')
const sending = ref(false)
const error = ref('')
const input = ref<HTMLTextAreaElement | null>(null)
let typingTimer: number | null = null
let typingActive = false
function resize() {
const element = input.value
if (!element) return
element.style.height = 'auto'
element.style.height = `${element.scrollHeight}px`
}
function notifyTyping(active: boolean) {
if (typingActive === active) return
typingActive = active
emit('typing', active)
}
function onInput() {
resize()
notifyTyping(true)
if (typingTimer !== null) window.clearTimeout(typingTimer)
typingTimer = window.setTimeout(() => {
typingTimer = null
notifyTyping(false)
}, 2000)
}
function insertMention() {
const element = input.value
const current = text.value
const start = element?.selectionStart ?? current.length
const end = element?.selectionEnd ?? current.length
const before = current.slice(0, start)
const after = current.slice(end)
const spacer = before.length > 0 && !/\s$/.test(before) ? ' ' : ''
const insertion = `${spacer}@rhema `
text.value = `${before}${insertion}${after}`
const cursor = before.length + insertion.length
void nextTick(() => {
element?.focus()
element?.setSelectionRange(cursor, cursor)
resize()
})
}
function onKeydown(event: KeyboardEvent) {
if (event.key !== 'Enter' || event.shiftKey || event.isComposing) return
event.preventDefault()
void send()
}
async function send() {
const value = text.value.trim()
if (!value || sending.value) return
sending.value = true
error.value = ''
try {
const response = await api.post<SendMessageResponse>(`/rooms/${props.roomId}/messages`, { text: value })
text.value = ''
if (typingTimer !== null) {
window.clearTimeout(typingTimer)
typingTimer = null
}
notifyTyping(false)
emit('sent', response.message)
await nextTick()
resize()
input.value?.focus()
} catch (err) {
error.value = apiErrorMessage(err)
} finally {
sending.value = false
}
}
onBeforeUnmount(() => {
if (typingTimer !== null) window.clearTimeout(typingTimer)
})
</script>
<template>
<div class="composer">
<div class="composer-inner">
<label class="sr-only" for="room-composer">Message the room</label>
<textarea
id="room-composer"
ref="input"
v-model="text"
class="composer-input"
rows="1"
placeholder="Message the room. Use @rhema to ask the agent."
@input="onInput"
@keydown="onKeydown"
/>
<div class="composer-actions">
<span class="composer-hint">Enter sends, Shift+Enter adds a line.</span>
<div class="composer-buttons">
<button
type="button"
class="icon-btn"
aria-label="Insert @rhema mention"
title="Insert @rhema mention"
@click="insertMention"
>
<AtSign :size="16" aria-hidden="true" />
</button>
<button
type="button"
class="btn btn-primary btn-sm"
:disabled="!text.trim() || sending"
aria-label="Send message"
title="Send"
@click="send"
>
<Send :size="14" aria-hidden="true" />
{{ sending ? 'Sending' : 'Send' }}
</button>
</div>
</div>
</div>
<p v-if="error" class="form-error composer-error" role="alert">{{ error }}</p>
</div>
</template>