android / debug (push) Successful in 2m22s
android / release (push) Successful in 2m7s
ci / checks (push) Successful in 3m48s
ci / test (push) Successful in 2m9s
ci / chart (push) Successful in 7s
ci / docker (push) Successful in 1m51s
ci / web (push) Successful in 18s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 2m5s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 15s
ci / publish-edge-chart (push) Successful in 5s
The General page exposed Mark, Initials, and Tagline even though the new shell renders none of them, and a callout explained an identity split that no longer needed saying. The About identity block still drew a green tile with an R. General now edits name, email, and sign-off only. Its save payload omits the retired fields, so values already stored stay untouched. AgentAvatar keeps just the avatar image and the name's initial; the sidebar tooltip now carries the display name. About renders the uploaded logo, or the Rhema mark when none is set. README follows. nuxt typecheck and build pass; General and About checked in light and dark.
1059 lines
31 KiB
Vue
1059 lines
31 KiB
Vue
<script setup lang="ts">
|
|
// The transcript: sent lines and streamed turns, the turn in flight at
|
|
// the bottom. The claw owns the conversation, this renders what the
|
|
// event stream delivered, nothing more. The composer never closes for
|
|
// a running turn: sending while one streams steers it, the claw cuts
|
|
// the turn and answers the message instead (rhema-code's shape). The
|
|
// header names the session and hides the dispatch internals behind an
|
|
// info modal; the composer chips mirror live claw state; the backend
|
|
// chip jumps to settings.
|
|
import { Info, Paperclip, Send, Settings2, X } from 'lucide-vue-next'
|
|
import {
|
|
PASTE_INLINE_LINES,
|
|
chipLabel,
|
|
byteToIndex,
|
|
chipLinesLabel,
|
|
lineCount,
|
|
normalizePaste,
|
|
pasteParts,
|
|
} from '~/composables/useTranscript'
|
|
import type { ClawSession, ConsentAnswer, StreamStatus } from '~/composables/useClaw'
|
|
import type { PasteSpan } from '~/composables/useClaw'
|
|
import type { PastePart, SentImage, StagedImage, TranscriptItem, TurnBlock } from '~/composables/useTranscript'
|
|
|
|
const props = defineProps<{
|
|
items: TranscriptItem[]
|
|
live: TurnBlock | null
|
|
activeKey: string
|
|
/** Only `interactive:*` keys accept messages (the claw 400s the rest). */
|
|
canSend: boolean
|
|
/** The daemon answers this key with a snapshot, not a stream. */
|
|
readOnly: boolean
|
|
busy: boolean
|
|
session: ClawSession | null
|
|
activeBackend: { provider: string; model: string } | null
|
|
streamStatus: StreamStatus
|
|
/** An older page is in flight: the stream area shows it, so a slow
|
|
* claw reads as loading rather than as the top of the transcript. */
|
|
loadingOlder?: boolean
|
|
/** The record still holds turns above what the mirror shows. */
|
|
olderAvailable?: boolean
|
|
/** Bumped whenever a page was folded in above the mirror. */
|
|
prependCount?: number
|
|
identity?: { name: string | null } | null
|
|
avatarUrl?: string | null
|
|
}>()
|
|
|
|
const agentName = computed(() => props.identity?.name?.trim() || 'rhema')
|
|
|
|
/** Why the composer is closed. A resident key that is not `interactive:`
|
|
* runs on its own trigger; anything else is a snapshot of a stash the
|
|
* engine checkpointed, whose answer went out through its dispatch. */
|
|
const readOnlyNote = computed(() =>
|
|
!props.readOnly
|
|
? 'Only interactive: keys take messages. This key runs on its own trigger and the transcript is read-only.'
|
|
: 'Read-only snapshot of the turns this key ran. The dispatch takes its input and posts its answer outside the chat.',
|
|
)
|
|
|
|
/** Whose words a user row holds. A chat key's are the human's, on the
|
|
* web surface or on the phone; every other key's are the prompt its
|
|
* dispatch was started with. */
|
|
const userLabel = computed(() =>
|
|
/^(interactive|phone):/.test(props.activeKey) ? 'you' : 'dispatch',
|
|
)
|
|
|
|
/** Whether the key has a stream at all. A snapshot answers a page once
|
|
* and follows nothing, so the header says so instead of claiming to be
|
|
* live. */
|
|
const streaming = computed(() => !props.readOnly)
|
|
|
|
/** One send as the panel hands it up: the text (pastes embedded) and
|
|
* the staged images, previews included for the optimistic row. */
|
|
interface SendPayload {
|
|
text: string
|
|
/** The chip payloads, in staging order, the wire carries them
|
|
* beside the plain draft; the fold composes the record. */
|
|
pastes: string[]
|
|
images: StagedImage[]
|
|
}
|
|
|
|
const emit = defineEmits<{
|
|
send: [message: SendPayload]
|
|
openProviders: []
|
|
consentAnswer: [id: string, answer: ConsentAnswer]
|
|
consentDeny: [id: string]
|
|
downloadAttachment: [id: string, name: string]
|
|
older: []
|
|
}>()
|
|
|
|
const draft = ref('')
|
|
/** The draft each session typed before the view moved on: the composer
|
|
* belongs to the session it types into, so a draft never sends into a
|
|
* session it was not written for. Staged attachments and pastes stay
|
|
* with the composer itself, they sit visible in the chips, so the
|
|
* user still sees them carry. */
|
|
const drafts = new Map<string, string>()
|
|
watch(
|
|
() => props.activeKey,
|
|
(key, previous) => {
|
|
if (previous !== undefined) drafts.set(previous, draft.value)
|
|
draft.value = drafts.get(key) ?? ''
|
|
void nextTick(resizePrompt)
|
|
},
|
|
)
|
|
const scroller = ref<HTMLElement | null>(null)
|
|
/** Pin to the bottom only while the reader is already there. */
|
|
const pinned = ref(true)
|
|
|
|
/** How near the top counts as asking for the turn above. */
|
|
const OLDER_THRESHOLD = 160
|
|
|
|
/** The scroll state captured when a page was asked for, so the reader
|
|
* keeps looking at the same message once it lands above them: the
|
|
* content grew over the viewport, and the position must move down by
|
|
* that growth. */
|
|
let olderAnchor: { top: number; height: number } | null = null
|
|
|
|
/** Asks for the page above when the reader nears the top, or when the
|
|
* transcript is too short to fill the screen, an auto-walk that stops
|
|
* the moment the record runs out (`olderAvailable`) or a page lands. */
|
|
function requestOlder(): void {
|
|
if (props.loadingOlder || props.olderAvailable === false) return
|
|
const el = scroller.value
|
|
if (!el) return
|
|
const atTop = el.scrollTop < OLDER_THRESHOLD
|
|
const unfilled = el.scrollHeight - el.clientHeight < 8
|
|
if (!atTop && !unfilled) return
|
|
olderAnchor = { top: el.scrollTop, height: el.scrollHeight }
|
|
emit('older')
|
|
}
|
|
|
|
function onScroll(): void {
|
|
const el = scroller.value
|
|
if (!el) return
|
|
pinned.value = el.scrollHeight - el.scrollTop - el.clientHeight < 48
|
|
// Scrolling back into the history asks for the next page up; the
|
|
// anchor captured here is what keeps the reader's place when it
|
|
// lands.
|
|
if (el.scrollTop < OLDER_THRESHOLD) requestOlder()
|
|
}
|
|
|
|
/** A page landed above the viewport: hold the reader's place. */
|
|
watch(
|
|
() => props.prependCount,
|
|
async () => {
|
|
const el = scroller.value
|
|
const anchor = olderAnchor
|
|
olderAnchor = null
|
|
if (!el || !anchor) return
|
|
await nextTick()
|
|
el.scrollTop = anchor.top + (el.scrollHeight - anchor.height)
|
|
},
|
|
)
|
|
|
|
/** A transcript shorter than the screen has nothing to scroll, so no
|
|
* scroll event will ever ask for the page above: ask once the first
|
|
* turn has rendered, and keep asking as pages land until the screen
|
|
* fills or the record ends. */
|
|
watch(
|
|
() => [props.items.length, props.loadingOlder] as const,
|
|
async () => {
|
|
await nextTick()
|
|
const el = scroller.value
|
|
if (!el || props.items.length === 0) return
|
|
if (el.scrollHeight - el.clientHeight < 8) requestOlder()
|
|
},
|
|
)
|
|
|
|
// A consent or attachment card opening inside the trailing turn
|
|
// changes the rendered height, so the reply length and the entries
|
|
// length both join the watch that keeps the stream pinned at the
|
|
// bottom.
|
|
watch(
|
|
() => [props.items.length, props.live?.reply.length, props.live?.entries.length],
|
|
async () => {
|
|
if (!pinned.value) return
|
|
await nextTick()
|
|
const el = scroller.value
|
|
if (el) el.scrollTop = el.scrollHeight
|
|
},
|
|
)
|
|
|
|
function submit(): void {
|
|
const text = draft.value.trim()
|
|
// The draft stays the gate: the claw 422s an empty text even with
|
|
// images aboard. `busy` is only this send's POST in flight (the claw
|
|
// answers 202 at once), a running turn never blocks the composer,
|
|
// because a send into one steers it.
|
|
if (!text || !props.canSend || props.busy) return
|
|
emit('send', { text, pastes: pastes.value, images: stagedImages.value })
|
|
stageGeneration++
|
|
draft.value = ''
|
|
pastes.value = []
|
|
stagedImages.value = []
|
|
imageError.value = null
|
|
pinned.value = true
|
|
void nextTick(resizePrompt)
|
|
}
|
|
|
|
// --- the composer -----------------------------------------------------
|
|
const prompt = ref<HTMLTextAreaElement | null>(null)
|
|
|
|
/** The composer grows to this many rows, then scrolls instead. */
|
|
const MAX_PROMPT_ROWS = 10
|
|
|
|
/** Height follows the content; the CSS max-height clamps the growth. */
|
|
function resizePrompt(): void {
|
|
const el = prompt.value
|
|
if (!el) return
|
|
el.style.height = 'auto'
|
|
el.style.height = `${el.scrollHeight}px`
|
|
}
|
|
|
|
/** Enter submits, shift+enter is a newline, ctrl/cmd+enter submits. */
|
|
function onPromptKeydown(event: KeyboardEvent): void {
|
|
if (event.key === 'Enter' && !event.shiftKey) {
|
|
event.preventDefault()
|
|
submit()
|
|
}
|
|
}
|
|
|
|
// --- pasted attachments ----------------------------------------------
|
|
// A paste over PASTE_INLINE_LINES lines rides as a chip: the payload
|
|
// never lands in the box, it embeds into the sent text on submit ,
|
|
// the same record the TUI keeps.
|
|
|
|
const pastes = ref<string[]>([])
|
|
|
|
function onPaste(event: ClipboardEvent): void {
|
|
const transfer = event.clipboardData
|
|
if (!transfer) return
|
|
const text = transfer.getData('text/plain')
|
|
if (text !== '') {
|
|
if (absorbPaste(text)) event.preventDefault()
|
|
return
|
|
}
|
|
// A file paste: text files read inline or chip, images stage for the
|
|
// next send, the same door the (+) button opens; anything else the
|
|
// composer still ignores.
|
|
let handled = false
|
|
for (const file of Array.from(transfer.files)) {
|
|
if (file.type.startsWith('text/')) {
|
|
handled = true
|
|
void file.text().then((pasted) => {
|
|
if (!absorbPaste(pasted)) insertInline(pasted)
|
|
})
|
|
} else if (mediaTypeOf(file) !== null) {
|
|
stageImage(file)
|
|
handled = true
|
|
}
|
|
}
|
|
if (handled) event.preventDefault()
|
|
}
|
|
|
|
/** A long paste becomes one chip; whether it did is the answer. */
|
|
function absorbPaste(text: string): boolean {
|
|
const normalized = normalizePaste(text)
|
|
if (lineCount(normalized) <= PASTE_INLINE_LINES) return false
|
|
pastes.value.push(normalized)
|
|
return true
|
|
}
|
|
|
|
/** A short file paste joins the draft where the caret sits. */
|
|
function insertInline(text: string): void {
|
|
const el = prompt.value
|
|
if (el && !el.disabled) {
|
|
el.setRangeText(text, el.selectionStart ?? el.value.length, el.selectionEnd ?? el.value.length, 'end')
|
|
draft.value = el.value
|
|
} else {
|
|
draft.value += text
|
|
}
|
|
resizePrompt()
|
|
}
|
|
|
|
// --- staged images ----------------------------------------------------
|
|
// The (+) button and the clipboard both land here: files held for the
|
|
// next send, previewed from object URLs, read to base64 at stage time
|
|
// so a bad file surfaces before submit, not inside it. The budget is
|
|
// the claw's own (http.rs): eight images, 5 MiB decoded each.
|
|
|
|
const MAX_IMAGES = 8
|
|
const MAX_IMAGE_BYTES = 5 * 1024 * 1024
|
|
const IMAGE_TYPES: readonly string[] = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']
|
|
const IMAGE_ACCEPT = IMAGE_TYPES.join(',')
|
|
|
|
const stagedImages = ref<StagedImage[]>([])
|
|
const imageError = ref<string | null>(null)
|
|
const fileInput = ref<HTMLInputElement | null>(null)
|
|
|
|
/** Bumped on submit: a read still in flight when the draft cleared
|
|
* must not stage into a message that already left. */
|
|
let stageGeneration = 0
|
|
|
|
/** The wire media type a file stages as, or null when it is not one
|
|
* the claw accepts. The type usually rides the file; browsers that
|
|
* cannot name one leave it empty and the extension decides. */
|
|
function mediaTypeOf(file: File): string | null {
|
|
if (IMAGE_TYPES.includes(file.type)) return file.type
|
|
const byExt: Record<string, string> = {
|
|
png: 'image/png',
|
|
jpg: 'image/jpeg',
|
|
jpeg: 'image/jpeg',
|
|
gif: 'image/gif',
|
|
webp: 'image/webp',
|
|
}
|
|
return byExt[file.name.split('.').pop()?.toLowerCase() ?? ''] ?? null
|
|
}
|
|
|
|
/** B / KB / MB, one decimal past 1 KB, a chip label, not precision. */
|
|
function formatBytes(size: number): string {
|
|
if (size < 1024) return `${size} B`
|
|
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`
|
|
return `${(size / (1024 * 1024)).toFixed(1)} MB`
|
|
}
|
|
|
|
function pickImages(): void {
|
|
fileInput.value?.click()
|
|
}
|
|
|
|
function onPick(event: Event): void {
|
|
const input = event.target as HTMLInputElement
|
|
for (const file of Array.from(input.files ?? [])) stageImage(file)
|
|
// Cleared so picking the same file again still fires `change`.
|
|
input.value = ''
|
|
}
|
|
|
|
/** Stages one file, or surfaces why not: never a silent drop. */
|
|
function stageImage(file: File): void {
|
|
const label = file.name || 'clipboard image'
|
|
imageError.value = null
|
|
if (stagedImages.value.length >= MAX_IMAGES) {
|
|
imageError.value = `${label}: at most ${MAX_IMAGES} images a message`
|
|
return
|
|
}
|
|
const media_type = mediaTypeOf(file)
|
|
if (!media_type) {
|
|
imageError.value = `${label}: not a png, jpeg, gif, or webp image`
|
|
return
|
|
}
|
|
const generation = stageGeneration
|
|
const reader = new FileReader()
|
|
reader.onload = () => {
|
|
if (generation !== stageGeneration) return
|
|
// The data URL's head carries the mime back; the payload after the
|
|
// first comma is the bare base64 the body wants.
|
|
const dataUrl = typeof reader.result === 'string' ? reader.result : ''
|
|
const comma = dataUrl.indexOf(',')
|
|
const data = comma === -1 ? '' : dataUrl.slice(comma + 1)
|
|
if (data === '') {
|
|
imageError.value = `${label}: could not be read`
|
|
return
|
|
}
|
|
// Four base64 characters decode to three bytes, the same budget
|
|
// check the claw runs, no decode needed.
|
|
if (data.length * 3 / 4 > MAX_IMAGE_BYTES) {
|
|
imageError.value = `${label}: over the 5 MiB decoded budget`
|
|
return
|
|
}
|
|
stagedImages.value.push({ media_type, data, url: URL.createObjectURL(file), name: label })
|
|
}
|
|
reader.onerror = () => {
|
|
if (generation === stageGeneration) imageError.value = `${label}: could not be read`
|
|
}
|
|
reader.readAsDataURL(file)
|
|
}
|
|
|
|
function removeImage(index: number): void {
|
|
const [gone] = stagedImages.value.splice(index, 1)
|
|
if (gone) URL.revokeObjectURL(gone.url)
|
|
imageError.value = null
|
|
}
|
|
|
|
/** A stored image opens the same download path an attachment card
|
|
* uses; a local preview has nothing behind it to download. */
|
|
function downloadImage(image: SentImage): void {
|
|
if (image.id === null) return
|
|
emit('downloadAttachment', image.id, storedImageName(image))
|
|
}
|
|
|
|
/** A stored image's download name: the staged file's when the row is
|
|
* local, derived from the id when only the claw knows the bytes. */
|
|
function storedImageName(image: SentImage): string {
|
|
if (image.name) return image.name
|
|
const ext = image.media_type.replace('image/', '')
|
|
return `image-${image.id}.${ext === 'jpeg' ? 'jpg' : ext}`
|
|
}
|
|
|
|
/** One render piece of a user message: literal text or a paste chip. */
|
|
type MessageSegment = PastePart | { kind: 'chip'; label: string }
|
|
|
|
/** The message's render pieces: literal text and resolved chips, the
|
|
* chips' one-based ids counted across the message. The chips come
|
|
* from the row's span record, the plain text sliced at the spans'
|
|
* byte boundaries, and a row from before spans rode the wire
|
|
* carries none; that one still scans the mark form in its text. */
|
|
function messageSegments(text: string, pastes: PasteSpan[] = []): MessageSegment[] {
|
|
if (pastes.length === 0) {
|
|
const segments: MessageSegment[] = []
|
|
let chip = 0
|
|
for (const part of pasteParts(text)) {
|
|
if (part.kind === 'text') {
|
|
if (part.text !== '') segments.push(part)
|
|
} else {
|
|
segments.push({ kind: 'chip', label: chipLabel(part.text, chip++) })
|
|
}
|
|
}
|
|
return segments
|
|
}
|
|
const indexOf = byteToIndex(text)
|
|
const segments: MessageSegment[] = []
|
|
let chip = 0
|
|
let cut = 0
|
|
for (const span of [...pastes].sort((a, b) => a.start - b.start)) {
|
|
const start = indexOf(span.start)
|
|
const end = indexOf(span.end)
|
|
if (start === -1 || end === -1 || start < cut || end < start) continue
|
|
if (start > cut) segments.push({ kind: 'text', text: text.slice(cut, start) })
|
|
segments.push({ kind: 'chip', label: chipLinesLabel(span.lines, chip++) })
|
|
cut = end
|
|
}
|
|
if (cut < text.length) segments.push({ kind: 'text', text: text.slice(cut) })
|
|
return segments
|
|
}
|
|
|
|
const displayName = computed(() => props.activeKey.replace(/^interactive:/, '') || 'Chat')
|
|
|
|
/** The letter in the human row's avatar; the dispatch row speaks for
|
|
* its trigger, so it gets its own initial. */
|
|
const userInitial = computed(() => (userLabel.value === 'you' ? 'Y' : 'D'))
|
|
|
|
// The dispatch internals live behind the info modal, not in the header.
|
|
const infoOpen = ref(false)
|
|
|
|
const infoRows = computed(() => [
|
|
{ label: 'state', value: props.session?.state ?? 'unknown' },
|
|
{ label: 'revision', value: props.session ? String(props.session.revision) : 'unknown' },
|
|
{ label: 'inbox depth', value: props.session ? String(props.session.inbox_depth) : 'unknown' },
|
|
{ label: 'last outcome', value: props.session?.last_outcome ?? 'unknown' },
|
|
{ label: 'key', value: props.activeKey },
|
|
])
|
|
|
|
const streamLabel = computed(() =>
|
|
props.streamStatus === 'open' ? 'live' : props.streamStatus,
|
|
)
|
|
|
|
function streamTone(status: StreamStatus): 'ok' | 'warn' | 'error' {
|
|
if (status === 'open') return 'ok'
|
|
if (status === 'reconnecting') return 'error'
|
|
return 'warn'
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<section class="chat">
|
|
<header class="room-topbar">
|
|
<h1 class="room-name" :title="activeKey">{{ displayName }}</h1>
|
|
|
|
<div class="topbar-actions">
|
|
<button
|
|
class="backend"
|
|
:disabled="!activeBackend"
|
|
title="Switch the model backend in settings"
|
|
@click="emit('openProviders')"
|
|
>
|
|
<Settings2 :size="14" aria-hidden="true" />
|
|
<span>{{ activeBackend ? `${activeBackend.provider} · ${activeBackend.model}` : 'No backend' }}</span>
|
|
</button>
|
|
<span
|
|
class="stream"
|
|
:class="streaming ? streamTone(streamStatus) : 'idle'"
|
|
:title="streaming ? `Event stream: ${streamStatus}` : 'A snapshot of the stored session; no stream follows this key'"
|
|
>
|
|
{{ streaming ? streamLabel : 'snapshot' }}
|
|
</span>
|
|
<button class="icon-btn" title="Session info" aria-label="Session info" @click="infoOpen = true">
|
|
<Info :size="16" aria-hidden="true" />
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
<AppModal :open="infoOpen" title="Session info" @close="infoOpen = false">
|
|
<dl class="info-rows">
|
|
<div v-for="row in infoRows" :key="row.label" class="info-row">
|
|
<dt class="label">{{ row.label }}</dt>
|
|
<dd class="mono">{{ row.value }}</dd>
|
|
</div>
|
|
</dl>
|
|
</AppModal>
|
|
|
|
<div ref="scroller" class="stream-area" @scroll.passive="onScroll">
|
|
<div class="chat-inner">
|
|
<p v-if="items.length === 0 && !live" class="empty">
|
|
{{ streaming
|
|
? 'Nothing streamed yet. Messages post to the claw and replies arrive here live.'
|
|
: 'Nothing recorded for this key yet.' }}
|
|
</p>
|
|
|
|
<p v-if="loadingOlder" class="older-hint">Loading earlier turns</p>
|
|
|
|
<template v-for="item in items" :key="item.id">
|
|
<div v-if="item.kind === 'sent'" class="msg msg-human">
|
|
<span class="avatar user" aria-hidden="true">{{ userInitial }}</span>
|
|
<div class="msg-body">
|
|
<div class="msg-head">
|
|
<span class="msg-author">{{ userLabel }}</span>
|
|
</div>
|
|
<div v-if="item.images.length > 0" class="sent-images">
|
|
<button
|
|
v-for="(image, index) in item.images"
|
|
:key="index"
|
|
class="sent-image"
|
|
:disabled="image.url === null || image.id === null"
|
|
:title="image.url !== null && image.id !== null ? `Download ${storedImageName(image)}` : (image.name ?? 'Attached image')"
|
|
@click="downloadImage(image)"
|
|
>
|
|
<img v-if="image.url" :src="image.url" :alt="image.name ?? 'Attached image'">
|
|
</button>
|
|
</div>
|
|
<div class="msg-text plain">
|
|
<template v-for="(segment, index) in messageSegments(item.text, item.pastes)" :key="index">
|
|
<span v-if="segment.kind === 'chip'" class="badge">{{ segment.label }}</span>
|
|
<template v-else>{{ segment.text }}</template>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-else-if="item.kind === 'turn'" class="msg msg-agent">
|
|
<div class="msg-head">
|
|
<span class="msg-agent-label">{{ agentName }}</span>
|
|
</div>
|
|
<TurnEntries
|
|
:entries="item.turn.entries"
|
|
@consent-answer="(id, answer) => emit('consentAnswer', id, answer)"
|
|
@consent-deny="(id) => emit('consentDeny', id)"
|
|
@download-attachment="(id, name) => emit('downloadAttachment', id, name)"
|
|
/>
|
|
<AppMarkdown v-if="item.turn.reply" :text="item.turn.reply" class="msg-text" />
|
|
<div
|
|
v-if="item.turn.outcome"
|
|
class="outcome"
|
|
:class="{
|
|
failed: item.turn.outcome === 'failed',
|
|
steered: item.turn.outcome === 'steered',
|
|
aborted: item.turn.outcome === 'aborted',
|
|
}"
|
|
>
|
|
{{ item.turn.outcome }}
|
|
</div>
|
|
</div>
|
|
|
|
<div v-else class="msg msg-standalone">
|
|
<div class="msg-body">
|
|
<TurnEntries
|
|
:entries="[item.kind === 'consent' ? { kind: 'consent', consent: item.consent } : { kind: 'attachment', attachment: item.attachment }]"
|
|
@consent-answer="(id, answer) => emit('consentAnswer', id, answer)"
|
|
@consent-deny="(id) => emit('consentDeny', id)"
|
|
@download-attachment="(id, name) => emit('downloadAttachment', id, name)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<div v-if="live" class="msg msg-agent live">
|
|
<div class="msg-head">
|
|
<span class="msg-agent-label">{{ agentName }}</span>
|
|
</div>
|
|
<TurnEntries
|
|
:entries="live.entries"
|
|
@consent-answer="(id, answer) => emit('consentAnswer', id, answer)"
|
|
@consent-deny="(id) => emit('consentDeny', id)"
|
|
@download-attachment="(id, name) => emit('downloadAttachment', id, name)"
|
|
/>
|
|
<AppMarkdown v-if="live.reply" :text="live.reply" streaming class="msg-text" />
|
|
<p v-if="!live.reply" class="working" role="status">
|
|
<span class="spinner" aria-hidden="true" />
|
|
{{ agentName }} is working
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="composer">
|
|
<div class="composer-inner">
|
|
<div v-if="pastes.length > 0 || stagedImages.length > 0 || imageError" class="staging">
|
|
<span v-for="(paste, index) in pastes" :key="`paste-${index}`" class="badge">
|
|
{{ chipLabel(paste, index) }}
|
|
<button class="chip-x" :title="`Drop paste ${index + 1}`" @click="pastes.splice(index, 1)">
|
|
<X :size="11" aria-hidden="true" />
|
|
</button>
|
|
</span>
|
|
<span v-for="(image, index) in stagedImages" :key="image.url" class="badge">
|
|
{{ image.name }} {{ formatBytes(Math.round((image.data.length * 3) / 4)) }}
|
|
<button class="chip-x" :title="`Drop ${image.name}`" @click="removeImage(index)">
|
|
<X :size="11" aria-hidden="true" />
|
|
</button>
|
|
</span>
|
|
<p v-if="imageError" class="image-error" role="alert">
|
|
{{ imageError }}
|
|
<button class="chip-x" title="Dismiss" @click="imageError = null">
|
|
<X :size="11" aria-hidden="true" />
|
|
</button>
|
|
</p>
|
|
</div>
|
|
|
|
<p v-if="!canSend" class="read-only">{{ readOnlyNote }}</p>
|
|
|
|
<template v-else>
|
|
<textarea
|
|
ref="prompt"
|
|
v-model="draft"
|
|
class="composer-input"
|
|
rows="1"
|
|
:placeholder="live ? `Message ${agentName}. Sending steers the running turn.` : `Message ${agentName}`"
|
|
@keydown="onPromptKeydown"
|
|
@paste="onPaste"
|
|
@input="resizePrompt"
|
|
/>
|
|
<div class="composer-actions">
|
|
<button class="icon-btn" title="Attach images" aria-label="Attach images" @click="pickImages">
|
|
<Paperclip :size="16" aria-hidden="true" />
|
|
</button>
|
|
<span class="composer-hint">
|
|
{{ live ? 'Enter sends and steers the turn' : 'Enter sends, Shift+Enter adds a line' }}
|
|
</span>
|
|
<button
|
|
class="btn btn-primary btn-sm"
|
|
:disabled="busy || draft.trim() === ''"
|
|
:title="live ? 'Send and interrupt the running turn' : 'Send'"
|
|
@click="submit"
|
|
>
|
|
<Send :size="14" aria-hidden="true" />
|
|
Send
|
|
</button>
|
|
</div>
|
|
</template>
|
|
<input
|
|
ref="fileInput"
|
|
class="file-input"
|
|
type="file"
|
|
:accept="IMAGE_ACCEPT"
|
|
multiple
|
|
@change="onPick"
|
|
>
|
|
</div>
|
|
</footer>
|
|
</section>
|
|
</template>
|
|
<style scoped>
|
|
.chat {
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex: 1;
|
|
min-height: 0;
|
|
min-width: 0;
|
|
background: var(--bg);
|
|
}
|
|
|
|
.room-topbar {
|
|
height: var(--topbar-h);
|
|
flex: 0 0 var(--topbar-h);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--sp-3);
|
|
padding: 0 var(--sp-4);
|
|
border-bottom: 1px solid var(--border);
|
|
background: var(--bg);
|
|
}
|
|
|
|
.room-name {
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
font-size: var(--fs-title);
|
|
font-weight: 600;
|
|
line-height: var(--lh-heading);
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.topbar-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--sp-3);
|
|
margin-left: auto;
|
|
min-width: 0;
|
|
}
|
|
|
|
.backend {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: var(--sp-1);
|
|
max-width: 320px;
|
|
min-width: 0;
|
|
height: 28px;
|
|
min-height: 28px;
|
|
padding: 0 var(--sp-2);
|
|
border: 1px solid var(--border-strong);
|
|
border-radius: var(--r-control);
|
|
background: transparent;
|
|
color: var(--muted);
|
|
font-family: var(--font-mono);
|
|
font-size: var(--fs-small);
|
|
font-weight: 400;
|
|
}
|
|
|
|
.backend:hover:not(:disabled) {
|
|
background: var(--surface-2);
|
|
color: var(--text);
|
|
}
|
|
|
|
.backend span {
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.stream {
|
|
flex: none;
|
|
color: var(--muted);
|
|
font-size: var(--fs-small);
|
|
}
|
|
|
|
.stream.ok {
|
|
color: var(--accent);
|
|
}
|
|
|
|
.stream.warn {
|
|
color: var(--warn);
|
|
}
|
|
|
|
.stream.error {
|
|
color: var(--danger);
|
|
}
|
|
|
|
.info-rows {
|
|
margin: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.info-row {
|
|
display: flex;
|
|
align-items: baseline;
|
|
justify-content: space-between;
|
|
gap: var(--sp-4);
|
|
padding: var(--sp-2) 0;
|
|
}
|
|
|
|
.info-row + .info-row {
|
|
border-top: 1px solid var(--border);
|
|
}
|
|
|
|
.info-row dd {
|
|
margin: 0;
|
|
min-width: 0;
|
|
overflow-wrap: anywhere;
|
|
text-align: right;
|
|
}
|
|
|
|
.stream-area {
|
|
flex: 1;
|
|
min-height: 0;
|
|
overflow-y: auto;
|
|
padding: var(--sp-6) var(--sp-4) var(--sp-4);
|
|
scrollbar-width: thin;
|
|
}
|
|
|
|
.chat-inner {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: var(--sp-4);
|
|
width: 100%;
|
|
max-width: 760px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.empty {
|
|
padding: var(--sp-6) 0;
|
|
color: var(--muted);
|
|
font-size: var(--fs-ui);
|
|
}
|
|
|
|
.older-hint {
|
|
margin: 0;
|
|
color: var(--faint);
|
|
font-size: var(--fs-small);
|
|
text-align: center;
|
|
}
|
|
|
|
.msg {
|
|
min-width: 0;
|
|
}
|
|
|
|
.msg-human {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: var(--sp-3);
|
|
}
|
|
|
|
.avatar.user {
|
|
display: grid;
|
|
place-items: center;
|
|
width: 24px;
|
|
height: 24px;
|
|
flex: none;
|
|
margin-top: 1px;
|
|
border: 1px solid var(--border-strong);
|
|
border-radius: var(--r-avatar);
|
|
background: var(--surface-2);
|
|
color: var(--muted);
|
|
font-size: var(--fs-small);
|
|
font-weight: 600;
|
|
line-height: 1;
|
|
}
|
|
|
|
.msg-body {
|
|
flex: 1;
|
|
min-width: 0;
|
|
}
|
|
|
|
.msg-head {
|
|
display: flex;
|
|
align-items: baseline;
|
|
gap: var(--sp-2);
|
|
margin-bottom: var(--sp-1);
|
|
}
|
|
|
|
.msg-author {
|
|
font-size: var(--fs-small);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.msg-text {
|
|
color: var(--text);
|
|
font-size: var(--fs-ui);
|
|
line-height: var(--lh-body);
|
|
overflow-wrap: anywhere;
|
|
}
|
|
|
|
.plain {
|
|
white-space: pre-wrap;
|
|
}
|
|
|
|
.msg-agent {
|
|
padding: var(--sp-3);
|
|
border-left: 2px solid var(--accent);
|
|
border-radius: 0 var(--r-card) var(--r-card) 0;
|
|
background: var(--surface);
|
|
}
|
|
|
|
.msg-agent-label {
|
|
color: var(--accent);
|
|
font-size: var(--fs-small);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.msg-agent .msg-text > :first-child {
|
|
margin-top: 0;
|
|
}
|
|
|
|
.msg-agent .msg-text > :last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.outcome {
|
|
margin-top: var(--sp-1);
|
|
color: var(--muted);
|
|
font-size: var(--fs-small);
|
|
}
|
|
|
|
.outcome.failed {
|
|
color: var(--danger);
|
|
}
|
|
|
|
.outcome.steered {
|
|
color: var(--accent);
|
|
}
|
|
|
|
.outcome.aborted {
|
|
color: var(--warn);
|
|
}
|
|
|
|
.working {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--sp-2);
|
|
margin: var(--sp-1) 0 0;
|
|
color: var(--muted);
|
|
font-size: var(--fs-small);
|
|
}
|
|
|
|
.spinner {
|
|
flex: none;
|
|
width: 12px;
|
|
height: 12px;
|
|
border: 2px solid var(--border-strong);
|
|
border-top-color: var(--accent);
|
|
border-radius: 50%;
|
|
animation: spin 0.8s linear infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
|
|
.composer {
|
|
flex: 0 0 auto;
|
|
padding: var(--sp-3) var(--sp-4) var(--sp-4);
|
|
background: var(--bg);
|
|
}
|
|
|
|
.composer-inner {
|
|
max-width: 760px;
|
|
margin: 0 auto;
|
|
padding: var(--sp-2);
|
|
border: 1px solid var(--border-strong);
|
|
border-radius: var(--r-card);
|
|
background: var(--surface);
|
|
}
|
|
|
|
.composer-inner:focus-within {
|
|
border-color: var(--accent);
|
|
}
|
|
|
|
.composer-input {
|
|
display: block;
|
|
width: 100%;
|
|
min-height: 32px;
|
|
max-height: calc(10 * 1.5em + var(--sp-2));
|
|
padding: var(--sp-1) var(--sp-2);
|
|
overflow-y: auto;
|
|
border: 0;
|
|
outline: none;
|
|
background: transparent;
|
|
font-size: var(--fs-ui);
|
|
line-height: var(--lh-body);
|
|
overflow-wrap: anywhere;
|
|
resize: none;
|
|
}
|
|
|
|
.composer-input:focus {
|
|
border: 0;
|
|
outline: none;
|
|
}
|
|
|
|
.composer-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--sp-2);
|
|
padding-top: var(--sp-1);
|
|
}
|
|
|
|
.composer-hint {
|
|
flex: 1;
|
|
min-width: 0;
|
|
padding-left: var(--sp-1);
|
|
color: var(--faint);
|
|
font-size: var(--fs-small);
|
|
}
|
|
|
|
.staging {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: var(--sp-1);
|
|
padding: 0 var(--sp-1) var(--sp-2);
|
|
}
|
|
|
|
.chip-x {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 16px;
|
|
min-height: 16px;
|
|
padding: 0;
|
|
border: 0;
|
|
background: none;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.chip-x:hover:not(:disabled) {
|
|
background: none;
|
|
color: var(--danger);
|
|
}
|
|
|
|
.read-only {
|
|
margin: 0;
|
|
padding: var(--sp-1) var(--sp-2);
|
|
color: var(--muted);
|
|
font-size: var(--fs-meta);
|
|
}
|
|
|
|
.image-error {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: var(--sp-1);
|
|
flex-basis: 100%;
|
|
margin: 0;
|
|
color: var(--danger);
|
|
font-size: var(--fs-small);
|
|
}
|
|
|
|
.sent-images {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: var(--sp-2);
|
|
margin-bottom: var(--sp-1);
|
|
}
|
|
|
|
.sent-image {
|
|
display: block;
|
|
min-height: 0;
|
|
padding: 0;
|
|
border: none;
|
|
background: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.sent-image:disabled {
|
|
cursor: default;
|
|
}
|
|
|
|
.sent-image img {
|
|
display: block;
|
|
max-width: 100%;
|
|
max-height: 240px;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--r-control);
|
|
}
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.spinner {
|
|
animation: none;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 860px) {
|
|
.room-topbar {
|
|
height: auto;
|
|
flex: none;
|
|
flex-wrap: wrap;
|
|
gap: var(--sp-2);
|
|
padding: var(--sp-3) var(--sp-4);
|
|
}
|
|
|
|
.topbar-actions {
|
|
width: 100%;
|
|
margin-left: 0;
|
|
}
|
|
|
|
.backend {
|
|
flex: 1 1 0;
|
|
max-width: none;
|
|
}
|
|
}
|
|
</style>
|