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:
1 parent
04dd63c4ca
commit
0035f4e031
69 files changed
+22501
-48
No files matched your search
@@ -0,0 +1,105 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { Maximize2, Minimize2, X } from 'lucide-vue-next'
|
||||
|
||||
const props = defineProps<{ roomId: string }>()
|
||||
|
||||
const port = ref<number | string>(3000)
|
||||
const url = ref('')
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const fullscreen = ref(false)
|
||||
|
||||
async function load() {
|
||||
const value = Number(port.value)
|
||||
if (!Number.isInteger(value) || value < 1 || value > 65535) {
|
||||
error.value = 'Enter a port between 1 and 65535.'
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const response = await fetch(`/api/rooms/${encodeURIComponent(props.roomId)}/preview?port=${value}`, {
|
||||
credentials: 'include',
|
||||
headers: { Accept: 'application/json' },
|
||||
})
|
||||
if (response.status === 401) {
|
||||
await navigateTo('/login')
|
||||
return
|
||||
}
|
||||
const type = response.headers.get('content-type') ?? ''
|
||||
if (!type.includes('application/json')) {
|
||||
throw new Error('The server did not return a preview address.')
|
||||
}
|
||||
const body: unknown = await response.json()
|
||||
if (!response.ok) {
|
||||
const message = body && typeof body === 'object' && 'error' in body
|
||||
? String((body as { error: unknown }).error)
|
||||
: 'The preview could not be opened.'
|
||||
throw new Error(message)
|
||||
}
|
||||
if (!body || typeof body !== 'object' || typeof (body as { url?: unknown }).url !== 'string') {
|
||||
throw new Error('The server returned no preview address.')
|
||||
}
|
||||
url.value = (body as { url: string }).url
|
||||
} catch (err) {
|
||||
url.value = ''
|
||||
error.value = err instanceof Error ? err.message : 'The preview could not be opened.'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function toggleFullscreen() {
|
||||
fullscreen.value = !fullscreen.value
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="preview-wrap" :class="{ 'preview-full': fullscreen }">
|
||||
<div class="preview-bar">
|
||||
<label class="sr-only" for="preview-port">Port</label>
|
||||
<input
|
||||
id="preview-port"
|
||||
v-model.number="port"
|
||||
class="input port-field"
|
||||
type="number"
|
||||
min="1"
|
||||
max="65535"
|
||||
aria-label="Preview port"
|
||||
>
|
||||
<button type="button" class="btn btn-sm" :disabled="loading" @click="load">
|
||||
{{ loading ? 'Opening' : url ? 'Reload' : 'Go' }}
|
||||
</button>
|
||||
<div class="room-topbar-spacer" />
|
||||
<button
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
:aria-label="fullscreen ? 'Exit full screen preview' : 'Full screen preview'"
|
||||
:title="fullscreen ? 'Exit full screen' : 'Full screen'"
|
||||
@click="toggleFullscreen"
|
||||
>
|
||||
<component :is="fullscreen ? Minimize2 : Maximize2" :size="16" aria-hidden="true" />
|
||||
</button>
|
||||
<button
|
||||
v-if="fullscreen"
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
aria-label="Close full screen preview"
|
||||
title="Close full screen preview"
|
||||
@click="fullscreen = false"
|
||||
>
|
||||
<X :size="16" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="preview-message form-error" role="alert">{{ error }}</p>
|
||||
|
||||
<div v-if="url" class="preview-frame-wrap">
|
||||
<iframe class="preview-frame" :src="url" :title="`Preview on port ${port}`" />
|
||||
</div>
|
||||
<p v-else-if="!error" class="preview-message">
|
||||
Enter the port the room serves and choose Go.
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user