forked from vhaudiquet/rhema-together
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,190 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ChevronLeft, ChevronRight, File, Folder, Link as LinkIcon } from 'lucide-vue-next'
|
||||
import type { FileContentResponse, FileEntry, FileListResponse, GitSummaryResponse } from '~/types'
|
||||
import { apiErrorMessage } from '~/utils/errors'
|
||||
import { formatSize } from '~/utils/format'
|
||||
|
||||
const props = defineProps<{ roomId: string; roomName: string }>()
|
||||
const api = useApi()
|
||||
|
||||
const path = ref('.')
|
||||
const entries = ref<FileEntry[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
const selected = ref<FileEntry | null>(null)
|
||||
const file = ref<FileContentResponse | null>(null)
|
||||
const fileLoading = ref(false)
|
||||
const fileError = ref('')
|
||||
|
||||
const git = ref<GitSummaryResponse | null>(null)
|
||||
const gitLoading = ref(false)
|
||||
const gitError = ref('')
|
||||
|
||||
let dirRequest = 0
|
||||
let fileRequest = 0
|
||||
|
||||
const segments = computed(() => (path.value === '.' ? [] : path.value.split('/').filter(Boolean)))
|
||||
const hasParent = computed(() => segments.value.length > 0)
|
||||
|
||||
const lineNumbers = computed(() => {
|
||||
const content = file.value?.content ?? ''
|
||||
const count = content === '' ? 1 : content.replace(/\n$/, '').split('\n').length
|
||||
return Array.from({ length: count }, (_, index) => index + 1).join('\n')
|
||||
})
|
||||
|
||||
function crumbPath(index: number) {
|
||||
return segments.value.slice(0, index + 1).join('/')
|
||||
}
|
||||
|
||||
async function loadDir(target: string) {
|
||||
const request = ++dirRequest
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const response = await api.get<FileListResponse>(`/rooms/${props.roomId}/files`, { path: target })
|
||||
if (request !== dirRequest) return
|
||||
path.value = response.path
|
||||
entries.value = response.entries
|
||||
} catch (err) {
|
||||
if (request !== dirRequest) return
|
||||
entries.value = []
|
||||
error.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
if (request === dirRequest) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function openFile(entry: FileEntry) {
|
||||
const request = ++fileRequest
|
||||
selected.value = entry
|
||||
file.value = null
|
||||
fileError.value = ''
|
||||
fileLoading.value = true
|
||||
try {
|
||||
const response = await api.get<FileContentResponse>(`/rooms/${props.roomId}/file`, { path: entry.path })
|
||||
if (request !== fileRequest) return
|
||||
file.value = response
|
||||
} catch (err) {
|
||||
if (request !== fileRequest) return
|
||||
fileError.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
if (request === fileRequest) fileLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openEntry(entry: FileEntry) {
|
||||
if (entry.kind === 'dir') {
|
||||
selected.value = null
|
||||
file.value = null
|
||||
fileError.value = ''
|
||||
void loadDir(entry.path)
|
||||
} else {
|
||||
void openFile(entry)
|
||||
}
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
const parent = segments.value.slice(0, -1).join('/')
|
||||
void loadDir(parent)
|
||||
}
|
||||
|
||||
async function loadGit() {
|
||||
gitLoading.value = true
|
||||
gitError.value = ''
|
||||
try {
|
||||
git.value = await api.get<GitSummaryResponse>(`/rooms/${props.roomId}/git`)
|
||||
} catch (err) {
|
||||
gitError.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
gitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadDir('')
|
||||
void loadGit()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="files-pane">
|
||||
<div class="files">
|
||||
<div class="files-browser">
|
||||
<div class="crumbs">
|
||||
<button v-if="hasParent" type="button" class="crumb-back" @click="goBack">
|
||||
<ChevronLeft :size="12" aria-hidden="true" />
|
||||
Back
|
||||
</button>
|
||||
<div class="crumbs-row">
|
||||
<button type="button" class="crumb" @click="loadDir('')">Workspace</button>
|
||||
<template v-for="(segment, index) in segments" :key="crumbPath(index)">
|
||||
<ChevronRight :size="12" class="faint" aria-hidden="true" />
|
||||
<button type="button" class="crumb" @click="loadDir(crumbPath(index))">
|
||||
{{ segment }}
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="file-list">
|
||||
<p v-if="loading" class="meta pane-pad">Loading files.</p>
|
||||
<p v-else-if="error" class="form-error pane-pad">{{ error }}</p>
|
||||
<p v-else-if="entries.length === 0" class="empty pane-pad">This folder is empty.</p>
|
||||
<template v-else>
|
||||
<button
|
||||
v-for="entry in entries"
|
||||
:key="entry.path"
|
||||
type="button"
|
||||
class="file-row"
|
||||
:class="{ active: selected?.path === entry.path }"
|
||||
:title="entry.path"
|
||||
@click="openEntry(entry)"
|
||||
>
|
||||
<Folder v-if="entry.kind === 'dir'" :size="14" aria-hidden="true" />
|
||||
<LinkIcon v-else-if="entry.kind === 'link'" :size="14" aria-hidden="true" />
|
||||
<File v-else :size="14" aria-hidden="true" />
|
||||
<span class="file-row-name">{{ entry.name }}</span>
|
||||
<span v-if="entry.kind === 'file'" class="file-row-size">{{ formatSize(entry.size) }}</span>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="files-viewer">
|
||||
<template v-if="selected">
|
||||
<div class="viewer-head">
|
||||
<span class="viewer-path" :title="selected.path">{{ selected.path }}</span>
|
||||
<span v-if="file" class="file-row-size">{{ formatSize(file.size) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="viewer-scroll">
|
||||
<p v-if="fileLoading" class="meta pane-pad-3">Reading file.</p>
|
||||
<p v-else-if="fileError" class="form-error pane-pad-3">{{ fileError }}</p>
|
||||
<p v-else-if="file?.binary" class="meta pane-pad-3">Binary file. Preview is not available.</p>
|
||||
<p v-else-if="file && file.content === ''" class="meta pane-pad-3">This file is empty.</p>
|
||||
<template v-else-if="file">
|
||||
<pre class="gutter" aria-hidden="true">{{ lineNumbers }}</pre>
|
||||
<pre class="viewer-code">{{ file.content }}</pre>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<p v-if="file?.truncated" class="meta viewer-note">
|
||||
Showing the first 400 KB.
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<p v-else class="empty pane-pad-3">Select a file to read.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details class="git-strip">
|
||||
<summary>Git status</summary>
|
||||
<p v-if="gitLoading" class="meta pane-note">Reading git status.</p>
|
||||
<p v-else-if="gitError" class="form-error pane-note">{{ gitError }}</p>
|
||||
<pre v-else-if="git?.text">{{ git.text }}</pre>
|
||||
<p v-else class="meta pane-note">No git output.</p>
|
||||
</details>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user