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,121 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { ToolActivity, TurnActivity } from '~/types'
|
||||
import { formatCost } from '~/utils/format'
|
||||
|
||||
const props = defineProps<{ activity: TurnActivity }>()
|
||||
|
||||
const stateLabel = computed(() => {
|
||||
switch (props.activity.status) {
|
||||
case 'running':
|
||||
return 'is working'
|
||||
case 'error':
|
||||
return 'failed'
|
||||
case 'interrupted':
|
||||
return 'stopped'
|
||||
case 'step_limit':
|
||||
return 'hit the step limit'
|
||||
case 'max_tokens':
|
||||
return 'hit the token limit'
|
||||
default:
|
||||
return 'finished'
|
||||
}
|
||||
})
|
||||
|
||||
const usageText = computed(() => {
|
||||
const usage = props.activity.usage
|
||||
if (!usage) return ''
|
||||
const parts = [
|
||||
`${usage.input_tokens.toLocaleString()} in`,
|
||||
`${usage.output_tokens.toLocaleString()} out`,
|
||||
]
|
||||
if (usage.cached_input_tokens > 0) parts.push(`${usage.cached_input_tokens.toLocaleString()} cached`)
|
||||
const cost = formatCost(usage.cost_usd)
|
||||
if (cost) parts.push(cost)
|
||||
return parts.join(', ')
|
||||
})
|
||||
|
||||
function parseArgs(raw: string): Record<string, unknown> | null {
|
||||
const trimmed = raw.trim()
|
||||
if (!trimmed.startsWith('{')) return null
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(trimmed)
|
||||
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||||
return parsed as Record<string, unknown>
|
||||
}
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function toolSummary(tool: ToolActivity): string {
|
||||
if (!tool.args.trim()) return ''
|
||||
const parsed = parseArgs(tool.args)
|
||||
let summary = tool.args.trim()
|
||||
if (parsed) {
|
||||
summary = JSON.stringify(parsed)
|
||||
for (const key of ['command', 'cmd', 'path', 'file_path', 'pattern', 'url', 'query']) {
|
||||
const value = parsed[key]
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
summary = value.trim()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return summary.length > 240 ? `${summary.slice(0, 240)}...` : summary
|
||||
}
|
||||
|
||||
function outputText(tool: ToolActivity): string {
|
||||
return tool.content ?? tool.output
|
||||
}
|
||||
|
||||
function toolLabel(tool: ToolActivity): string {
|
||||
return tool.name || 'tool'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="activity">
|
||||
<div class="activity-head">
|
||||
<div class="row">
|
||||
<span class="activity-label">rhema</span>
|
||||
<span class="activity-steps">{{ stateLabel }}</span>
|
||||
</div>
|
||||
<span v-if="activity.steps > 0" class="activity-state">
|
||||
{{ activity.steps }} {{ activity.steps === 1 ? 'step' : 'steps' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<details v-if="activity.thinking" class="activity-draft">
|
||||
<summary>thinking</summary>
|
||||
<div>{{ activity.thinking }}</div>
|
||||
</details>
|
||||
|
||||
<details v-if="activity.text" class="activity-draft">
|
||||
<summary>draft</summary>
|
||||
<div>{{ activity.text }}</div>
|
||||
</details>
|
||||
|
||||
<div v-for="tool in activity.tools" :key="tool.call_id" class="tool">
|
||||
<div class="tool-head">
|
||||
<span class="tool-name">{{ toolLabel(tool) }}</span>
|
||||
<span v-if="tool.isError" class="tool-state tool-error">failed</span>
|
||||
<span v-else-if="tool.done && tool.code !== null" class="tool-state">exit {{ tool.code }}</span>
|
||||
<span v-else-if="!tool.done" class="tool-state">running</span>
|
||||
<span v-else class="tool-state">done</span>
|
||||
</div>
|
||||
<div v-if="toolSummary(tool)" class="tool-args">{{ toolSummary(tool) }}</div>
|
||||
<details v-if="tool.done && outputText(tool)">
|
||||
<summary>output</summary>
|
||||
<pre class="code-block tool-output">{{ outputText(tool) }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div v-if="activity.status === 'error' && activity.error" class="activity-error">{{ activity.error }}</div>
|
||||
|
||||
<div v-if="usageText" class="activity-foot">
|
||||
<span>{{ usageText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user