android / debug (push) Successful in 2m16s
android / release (push) Successful in 2m9s
ci / checks (push) Successful in 3m39s
ci / test (push) Successful in 2m5s
ci / docker (push) Successful in 1m52s
ci / web (push) Successful in 13s
ci / publish-edge-images (deploy/docker/claw.Dockerfile, rhema-claw) (push) Successful in 1m56s
ci / chart (push) Successful in 6s
ci / publish-edge-images (deploy/docker/ui.Dockerfile, rhema-claw-ui) (push) Successful in 20s
ci / publish-edge-chart (push) Successful in 4s
The web client kept its own dark shell: an icon rail, neon jade accents, and rows that reported state with colored dots and pills. Rhema Together had since settled on a warmer, quieter language, and the two surfaces no longer looked like one product. The shell is now one 232px sidebar plus a view. Chat lists sessions in the sidebar and renders the transcript in a 760px column; settings moves its searchable nav into the same sidebar and its pages onto an 880px column. The palette, type scale, controls, cards, and markdown come from Together's light theme, with its dark values following the OS. FiraCode Nerd Font Mono sets code, and the product mark, logo, and lucide icons replace the glyph characters. Status is a word now: running, waiting, held, connected, live, snapshot. The rail, its dots, the duplicate consent deny action, and the session key tag are gone. The model backend moved into the chat topbar beside the stream state. The mobile shell keeps the composer fixed in chat and lets settings scroll as a document. README and component docs follow the new layout. nuxt typecheck and build pass; checked light and dark at 1280x800 and 390x844 against mock API data.
1156 lines
36 KiB
Vue
1156 lines
36 KiB
Vue
<script setup lang="ts">
|
|
// The one page: a sidebar, then either the chat view (session list and
|
|
// live transcript) or the settings view (nav and pages). A tiny hash
|
|
// router keeps views deep-linkable without vue-router. All state is
|
|
// in-memory; only the token and the active session persist.
|
|
// The claw owns the conversation and the config, so this page is a
|
|
// mirror, not a store.
|
|
import { ClawError, clawHealth, isInteractive, isResidentKey, useClaw } from '~/composables/useClaw'
|
|
import type {
|
|
AgentIdentity,
|
|
AgentImageKind,
|
|
BootstrapFiles,
|
|
ClawAccount,
|
|
ClawSession,
|
|
ConsentAnswer,
|
|
McpState,
|
|
IdentityTexts,
|
|
ModelCard,
|
|
NewAccount,
|
|
ProviderCredentials,
|
|
ProvidersState,
|
|
SandboxSelection,
|
|
SandboxState,
|
|
SkillsState,
|
|
StreamStatus,
|
|
} from '~/composables/useClaw'
|
|
import { composeChips, useTranscript } from '~/composables/useTranscript'
|
|
import type { AttachmentCard, StagedImage } from '~/composables/useTranscript'
|
|
|
|
const TOKEN_STORE_KEY = 'claw.token'
|
|
const ACTIVE_STORE_KEY = 'claw.activeKey'
|
|
const DEFAULT_KEY = 'interactive:web'
|
|
|
|
function stored(key: string): string | null {
|
|
if (!import.meta.client) return null
|
|
try {
|
|
return localStorage.getItem(key)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function persist(key: string, value: string | null): void {
|
|
if (!import.meta.client) return
|
|
try {
|
|
if (value === null) localStorage.removeItem(key)
|
|
else localStorage.setItem(key, value)
|
|
} catch {
|
|
// Storage unavailable (private mode): the session still works, it
|
|
// just forgets.
|
|
}
|
|
}
|
|
|
|
// --- the two views ---------------------------------------------------
|
|
type Route = { view: 'chat' } | { view: 'settings'; section: string }
|
|
|
|
const SETTINGS_SECTIONS: { label: string; entries: { id: string; label: string }[] }[] = [
|
|
{
|
|
label: 'Agent',
|
|
entries: [
|
|
{ id: 'agent/general', label: 'General' },
|
|
{ id: 'agent/bootstrap', label: 'Bootstrap' },
|
|
{ id: 'agent/accounts', label: 'Accounts' },
|
|
],
|
|
},
|
|
{ label: 'Providers', entries: [{ id: 'providers', label: 'Model providers' }] },
|
|
{
|
|
label: 'System',
|
|
entries: [
|
|
{ id: 'skills', label: 'Skills' },
|
|
{ id: 'mcp', label: 'MCP' },
|
|
{ id: 'sandbox', label: 'Sandbox' },
|
|
{ id: 'about', label: 'About' },
|
|
],
|
|
},
|
|
]
|
|
|
|
function parseHash(): Route {
|
|
if (!import.meta.client) return { view: 'chat' }
|
|
const hash = window.location.hash.replace(/^#\/?/, '')
|
|
if (hash.startsWith('settings')) {
|
|
// Section ids may carry their category ('agent/general'), so the
|
|
// section is everything after 'settings/', not the second segment.
|
|
const section = hash.replace(/^settings\/?/, '') || 'agent/general'
|
|
return {
|
|
view: 'settings',
|
|
section: SETTINGS_SECTIONS.some((s) => s.entries.some((e) => e.id === section))
|
|
? section
|
|
: 'providers',
|
|
}
|
|
}
|
|
return { view: 'chat' }
|
|
}
|
|
|
|
const route = ref<Route>(parseHash())
|
|
|
|
function go(next: Route): void {
|
|
window.location.hash = next.view === 'chat' ? '#/chat' : `#/settings/${next.section}`
|
|
}
|
|
|
|
function onHashChange(): void {
|
|
route.value = parseHash()
|
|
}
|
|
|
|
// --- claw state ------------------------------------------------------
|
|
const config = useRuntimeConfig()
|
|
const token = ref<string | null>(
|
|
stored(TOKEN_STORE_KEY) ?? (config.public.clawToken || null),
|
|
)
|
|
const claw = useClaw(token)
|
|
|
|
const activeKey = ref(stored(ACTIVE_STORE_KEY) ?? DEFAULT_KEY)
|
|
watch(activeKey, (key) => persist(ACTIVE_STORE_KEY, key))
|
|
|
|
const transcript = useTranscript()
|
|
const {
|
|
items: transcriptItems,
|
|
live: liveTurn,
|
|
loadingOlder,
|
|
prependCount,
|
|
} = transcript
|
|
|
|
// Whether the record still holds turns above what the mirror shows.
|
|
// The stream opens on the newest turn and the reader walks back page
|
|
// by page (ChatPanel asks when the scroller nears its top, or when the
|
|
// transcript is too short to fill the screen), so a session that ran
|
|
// for weeks costs nothing up front and still reaches its first message.
|
|
const olderAvailable = ref(true)
|
|
|
|
// The cards this page already tried to fetch. Keyed by the card object
|
|
// rather than the attachment id: a page read, a mirror reset, or a live
|
|
// turn folding into a record builds new cards, and a new card deserves
|
|
// its fetch, the useClaw cache answers a repeat with the blob it
|
|
// already holds, so a retry costs no request.
|
|
let attemptedAttachments = new WeakSet<object>()
|
|
|
|
// Image cards need their bytes before they can render: fetched as the
|
|
// card appears, not on any timer. code/file fetch on download instead.
|
|
// A replayed question's images fetch the same way, the stream carries
|
|
// their attachment ids, never the bytes; locally sent rows hold their
|
|
// own object URLs.
|
|
//
|
|
// The cards sit at two depths. One handed over mid-turn lands in the
|
|
// open turn's entries and rides into the finished turn with it, so a
|
|
// scan of the top-level rows alone would never see it and the card
|
|
// would stay a name with no picture. Every path that can hold a card is
|
|
// walked here; the attempt set makes a repeated pass free.
|
|
function requestAttachmentImages(): void {
|
|
const fetchAttachment = (attachment: AttachmentCard) => {
|
|
const { id, media, url } = attachment
|
|
if (media !== 'image' || url !== null || attemptedAttachments.has(attachment)) return
|
|
attemptedAttachments.add(attachment)
|
|
claw
|
|
.attachmentUrl(id)
|
|
.then((fetched) => transcript.setAttachmentUrl(id, fetched))
|
|
.catch((err) => noteApiError(err))
|
|
}
|
|
for (const item of transcriptItems.value) {
|
|
if (item.kind === 'attachment') {
|
|
fetchAttachment(item.attachment)
|
|
} else if (item.kind === 'turn') {
|
|
for (const entry of item.turn.entries) {
|
|
if (entry.kind === 'attachment') fetchAttachment(entry.attachment)
|
|
}
|
|
} else if (item.kind === 'sent') {
|
|
for (const image of item.images) {
|
|
const { id, url } = image
|
|
if (id === null || url !== null || attemptedAttachments.has(image)) continue
|
|
attemptedAttachments.add(image)
|
|
claw
|
|
.attachmentUrl(id)
|
|
.then((fetched) => transcript.setSentImageUrl(id, fetched))
|
|
.catch((err) => noteApiError(err))
|
|
}
|
|
}
|
|
}
|
|
for (const entry of transcript.live.value?.entries ?? []) {
|
|
if (entry.kind === 'attachment') fetchAttachment(entry.attachment)
|
|
}
|
|
}
|
|
|
|
watch([transcriptItems, transcript.live], requestAttachmentImages, {
|
|
deep: true,
|
|
immediate: true,
|
|
})
|
|
|
|
// --- the agent's identity --------------------------------------------
|
|
const identity = ref<AgentIdentity | null>(null)
|
|
const identityAvatarUrl = ref<string | null>(null)
|
|
const identityLogoUrl = ref<string | null>(null)
|
|
|
|
async function loadImageUrls(): Promise<void> {
|
|
// A new object URL per fetch; the old one is revoked, not leaked.
|
|
for (const [kind, url] of [
|
|
['avatar', identityAvatarUrl],
|
|
['logo', identityLogoUrl],
|
|
] as const) {
|
|
if (!identity.value?.[kind]) {
|
|
if (url.value) URL.revokeObjectURL(url.value)
|
|
url.value = null
|
|
continue
|
|
}
|
|
if (url.value) URL.revokeObjectURL(url.value)
|
|
try {
|
|
url.value = await claw.agentImage(kind)
|
|
} catch {
|
|
url.value = null
|
|
}
|
|
}
|
|
}
|
|
|
|
async function refreshIdentity(): Promise<void> {
|
|
try {
|
|
identity.value = await claw.agent()
|
|
await loadImageUrls()
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
}
|
|
|
|
async function saveIdentity(texts: IdentityTexts): Promise<void> {
|
|
savingIdentity.value = true
|
|
try {
|
|
identity.value = await claw.setAgent(texts)
|
|
pushNotice('identity saved')
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
savingIdentity.value = false
|
|
}
|
|
}
|
|
|
|
async function uploadIdentityImage(kind: AgentImageKind, file: File): Promise<void> {
|
|
mutatingIdentity.value = true
|
|
try {
|
|
identity.value = await claw.setAgentImage(kind, file)
|
|
await loadImageUrls()
|
|
pushNotice(`${kind} updated`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
mutatingIdentity.value = false
|
|
}
|
|
}
|
|
|
|
async function clearIdentityImage(kind: AgentImageKind): Promise<void> {
|
|
mutatingIdentity.value = true
|
|
try {
|
|
identity.value = await claw.clearAgentImage(kind)
|
|
await loadImageUrls()
|
|
pushNotice(`${kind} cleared`)
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
mutatingIdentity.value = false
|
|
}
|
|
}
|
|
|
|
// The window title answers to the identity and the view, as the design
|
|
// shows it: "Kosmos, Settings · Model providers".
|
|
const viewTitle = computed(() => {
|
|
const current = route.value
|
|
if (current.view === 'chat') return 'Chat'
|
|
const label = SETTINGS_SECTIONS.flatMap((section) => section.entries).find(
|
|
(entry) => entry.id === current.section,
|
|
)?.label
|
|
return `Settings · ${label ?? current.section}`
|
|
})
|
|
watch(
|
|
[identity, viewTitle],
|
|
() => {
|
|
const name = identity.value?.name?.trim()
|
|
document.title = name ? `${name} · ${viewTitle.value}` : `rhema claw · ${viewTitle.value}`
|
|
},
|
|
{ immediate: true },
|
|
)
|
|
|
|
const clawUp = ref<boolean | null>(null)
|
|
const sessions = ref<ClawSession[]>([])
|
|
const sessionsLoading = ref(false)
|
|
const providersState = ref<ProvidersState | null>(null)
|
|
const providerModels = ref<ModelCard[]>([])
|
|
const providerModelsLoading = ref(false)
|
|
const providerModelsError = ref<string | null>(null)
|
|
const selectedProvider = ref<string | null>(null)
|
|
const savingProviders = ref(false)
|
|
const mutatingProviders = ref(false)
|
|
const savingIdentity = ref(false)
|
|
const mutatingIdentity = ref(false)
|
|
const accounts = ref<ClawAccount[] | null>(null)
|
|
const accountsLoading = ref(false)
|
|
const mutatingAccounts = ref(false)
|
|
const sandboxState = ref<SandboxState | null>(null)
|
|
const savingSandbox = ref(false)
|
|
const skillsState = ref<SkillsState | null>(null)
|
|
const skillsLoading = ref(false)
|
|
const skillsSaving = ref<string | null>(null)
|
|
const bootstrapFiles = ref<BootstrapFiles | null>(null)
|
|
const bootstrapLoading = ref(false)
|
|
const bootstrapSaving = ref<string | null>(null)
|
|
const mcpState = ref<McpState | null>(null)
|
|
const mcpLoading = ref(false)
|
|
const streamStatus = ref<StreamStatus>('connecting')
|
|
const busy = ref(false)
|
|
const authRequired = ref(false)
|
|
const tokenDraft = ref('')
|
|
const apiError = ref<string | null>(null)
|
|
const notices = ref<{ id: number; text: string }[]>([])
|
|
let noticeId = 1
|
|
|
|
const activeSession = computed(
|
|
() => sessions.value.find((session) => session.key === activeKey.value) ?? null,
|
|
)
|
|
|
|
function noteApiError(err: unknown): void {
|
|
if (err instanceof ClawError && err.status === 401) {
|
|
authRequired.value = true
|
|
return
|
|
}
|
|
apiError.value = err instanceof Error ? err.message : String(err)
|
|
}
|
|
|
|
function pushNotice(text: string): void {
|
|
notices.value.push({ id: noticeId++, text })
|
|
if (notices.value.length > 4) notices.value.shift()
|
|
}
|
|
|
|
// --- claw calls ------------------------------------------------------
|
|
async function checkHealth(): Promise<void> {
|
|
clawUp.value = await clawHealth()
|
|
}
|
|
|
|
async function refreshSessions(): Promise<void> {
|
|
sessionsLoading.value = true
|
|
try {
|
|
sessions.value = await claw.sessions()
|
|
apiError.value = null
|
|
// A read-only thread has no stream to tell it a dispatch ran; the
|
|
// inventory's revision does. Reload the snapshot when it moved, and
|
|
// only then, a reload drops the pages the reader walked back to.
|
|
if (activeKey.value !== '' && !isResidentKey(activeKey.value) && !threadLoading) {
|
|
const revision = sessions.value.find((s) => s.key === activeKey.value)?.revision ?? null
|
|
if (revision !== threadRevision) void loadThread()
|
|
}
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
sessionsLoading.value = false
|
|
}
|
|
}
|
|
|
|
async function createSession(name: string): Promise<void> {
|
|
try {
|
|
// The SSE resubscribe watcher follows the switch; the inventory
|
|
// refresh lands the new key in the sidebar and closes its form.
|
|
activeKey.value = (await claw.createSession(name)).key
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
void refreshSessions()
|
|
}
|
|
|
|
// --- deleting a session ----------------------------------------------
|
|
/** The key the confirmation names; null while no dialog is open. */
|
|
const deletingKey = ref<string | null>(null)
|
|
const deleting = ref(false)
|
|
|
|
function askDeleteSession(key: string): void {
|
|
deletingKey.value = key
|
|
}
|
|
|
|
function closeDeleteSession(): void {
|
|
// A delete in flight is not cancellable: the claw is already writing.
|
|
if (deleting.value) return
|
|
deletingKey.value = null
|
|
}
|
|
|
|
/** The session to show once `gone` is deleted: the first interactive one
|
|
* the inventory still has, else the first of any kind, else none, an
|
|
* empty key opens no stream (see `resubscribe`). */
|
|
function nextActiveKey(gone: string): string {
|
|
const remaining = sessions.value.filter((session) => session.key !== gone)
|
|
const next = remaining.find((session) => isResidentKey(session.key))
|
|
return next?.key ?? ''
|
|
}
|
|
|
|
async function confirmDeleteSession(): Promise<void> {
|
|
const key = deletingKey.value
|
|
if (key === null || deleting.value) return
|
|
deleting.value = true
|
|
try {
|
|
await claw.deleteSession(key)
|
|
apiError.value = null
|
|
pushNotice(`session ${key} deleted`)
|
|
// The inventory first: the replacement key is whatever is left.
|
|
await refreshSessions()
|
|
// Moving activeKey resubscribes the stream (the watcher below), so
|
|
// the chat follows the delete instead of streaming a key that is
|
|
// gone.
|
|
if (activeKey.value === key) activeKey.value = nextActiveKey(key)
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
deleting.value = false
|
|
// The dialog closes either way: a refusal lands in the banner, where
|
|
// the rest of the claw's errors do.
|
|
deletingKey.value = null
|
|
}
|
|
}
|
|
|
|
/** The pause gate: hold a key's dispatch, lift the hold. The inventory
|
|
* refresh carries the `paused` flag back to the sidebar. */
|
|
async function pauseSession(key: string): Promise<void> {
|
|
try {
|
|
await claw.pauseSession(key)
|
|
pushNotice(`${key} held`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
void refreshSessions()
|
|
}
|
|
|
|
async function resumeSession(key: string): Promise<void> {
|
|
try {
|
|
await claw.resumeSession(key)
|
|
pushNotice(`${key} resumed`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
void refreshSessions()
|
|
}
|
|
|
|
/** Abort: cut a live turn, or drop the key's queued work. The answer
|
|
* says which happened; the inventory refresh settles the row. */
|
|
async function abortSession(key: string): Promise<void> {
|
|
try {
|
|
const result = await claw.abortSession(key)
|
|
pushNotice(
|
|
result.cut
|
|
? `turn on ${key} stopped`
|
|
: result.dropped > 0
|
|
? `${result.dropped} queued item(s) dropped on ${key}`
|
|
: `nothing running on ${key}`,
|
|
)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
void refreshSessions()
|
|
}
|
|
|
|
async function refreshProviders(): Promise<void> {
|
|
try {
|
|
providersState.value = await claw.providers()
|
|
if (providersState.value && !selectedProvider.value) {
|
|
selectedProvider.value = providersState.value.active.provider
|
|
await loadProviderModels(selectedProvider.value)
|
|
}
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
}
|
|
|
|
async function loadProviderModels(id: string): Promise<void> {
|
|
selectedProvider.value = id
|
|
providerModelsLoading.value = true
|
|
providerModelsError.value = null
|
|
try {
|
|
providerModels.value = await claw.models(id)
|
|
} catch (err) {
|
|
// A backend without a live listing is normal (404): the operator
|
|
// still sees the switch go through on the default model.
|
|
providerModels.value = []
|
|
providerModelsError.value = err instanceof Error ? err.message : String(err)
|
|
} finally {
|
|
providerModelsLoading.value = false
|
|
}
|
|
}
|
|
|
|
async function refreshAccounts(): Promise<void> {
|
|
accountsLoading.value = true
|
|
try {
|
|
accounts.value = await claw.accounts()
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
accountsLoading.value = false
|
|
}
|
|
}
|
|
|
|
async function addAccount(account: NewAccount): Promise<void> {
|
|
mutatingAccounts.value = true
|
|
try {
|
|
const saved = await claw.addAccount(account)
|
|
pushNotice(
|
|
saved.watchable_forge
|
|
? saved.watched
|
|
? `account ${saved.label} saved, following ${saved.service} notifications`
|
|
: `account ${saved.label} saved (already watched)`
|
|
: `account ${saved.label} saved. ${saved.service} is not a watchable forge`,
|
|
)
|
|
await refreshAccounts()
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
mutatingAccounts.value = false
|
|
}
|
|
}
|
|
|
|
async function removeAccount(account: ClawAccount): Promise<void> {
|
|
mutatingAccounts.value = true
|
|
try {
|
|
const forgot = await claw.removeAccount(account.id)
|
|
pushNotice(
|
|
forgot.forgot
|
|
? `account ${account.label} forgotten${forgot.watches_removed ? `, ${forgot.watches_removed} watch(es) removed` : ''}`
|
|
: `account ${account.label} was already gone`,
|
|
)
|
|
await refreshAccounts()
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
mutatingAccounts.value = false
|
|
}
|
|
}
|
|
|
|
async function saveProviders(provider: string, model?: string): Promise<void> {
|
|
savingProviders.value = true
|
|
try {
|
|
// The route answers the new pair only; carry the provider list
|
|
// forward so the state stays whole.
|
|
const { active } = await claw.setActive(provider, model)
|
|
providersState.value = providersState.value
|
|
? { ...providersState.value, active }
|
|
: { active, providers: [] }
|
|
pushNotice(`active backend: ${provider} / ${active.model}`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
savingProviders.value = false
|
|
}
|
|
}
|
|
|
|
async function addProvider(id: string, credentials: ProviderCredentials): Promise<void> {
|
|
mutatingProviders.value = true
|
|
const existed = providersState.value?.providers.some((p) => p.id === id) ?? false
|
|
try {
|
|
// The login answers the whole state: the roster with the new (or
|
|
// replaced) backend instance on it.
|
|
providersState.value = await claw.setCredentials(id, credentials)
|
|
selectedProvider.value = id
|
|
await loadProviderModels(id)
|
|
pushNotice(existed ? `provider ${id} replaced` : `provider ${id} added`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
mutatingProviders.value = false
|
|
}
|
|
}
|
|
|
|
async function removeProvider(id: string): Promise<void> {
|
|
mutatingProviders.value = true
|
|
try {
|
|
providersState.value = await claw.removeProvider(id)
|
|
// The removal may have moved the active pair: both re-ground on
|
|
// what remains.
|
|
if (selectedProvider.value === id) {
|
|
selectedProvider.value = providersState.value.active.provider
|
|
await loadProviderModels(selectedProvider.value)
|
|
}
|
|
pushNotice(`provider ${id} removed`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
mutatingProviders.value = false
|
|
}
|
|
}
|
|
|
|
async function refreshSkills(): Promise<void> {
|
|
skillsLoading.value = true
|
|
try {
|
|
skillsState.value = await claw.skills()
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
skillsLoading.value = false
|
|
}
|
|
}
|
|
|
|
async function toggleSkill(name: string, enabled: boolean): Promise<void> {
|
|
skillsSaving.value = name
|
|
try {
|
|
await claw.setSkillEnabled(name, enabled)
|
|
await refreshSkills()
|
|
pushNotice(`${name} ${enabled ? 'enabled' : 'disabled'}`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
skillsSaving.value = null
|
|
}
|
|
}
|
|
|
|
async function refreshBootstrap(): Promise<void> {
|
|
bootstrapLoading.value = true
|
|
try {
|
|
bootstrapFiles.value = await claw.bootstrapFiles()
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
bootstrapLoading.value = false
|
|
}
|
|
}
|
|
|
|
async function saveBootstrapFile(kind: string, content: string): Promise<void> {
|
|
bootstrapSaving.value = kind
|
|
try {
|
|
await claw.saveBootstrap(kind, content)
|
|
await refreshBootstrap()
|
|
pushNotice(`${kind === 'soul' ? 'SOUL.md' : 'USER.md'} saved`)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
bootstrapSaving.value = null
|
|
}
|
|
}
|
|
|
|
async function refreshMcp(): Promise<void> {
|
|
mcpLoading.value = true
|
|
try {
|
|
mcpState.value = await claw.mcp()
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
mcpLoading.value = false
|
|
}
|
|
}
|
|
|
|
async function refreshSandbox(): Promise<void> {
|
|
try {
|
|
sandboxState.value = await claw.sandbox()
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
}
|
|
|
|
async function saveSandbox(choice: SandboxSelection): Promise<void> {
|
|
savingSandbox.value = true
|
|
try {
|
|
sandboxState.value = await claw.setSandbox(choice)
|
|
pushNotice(
|
|
choice.kind === 'http'
|
|
? 'sandbox: remote host'
|
|
: choice.kind === 'ssh'
|
|
? 'sandbox: ssh host'
|
|
: 'sandbox: this machine',
|
|
)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
savingSandbox.value = false
|
|
}
|
|
}
|
|
|
|
async function send(message: { text: string; pastes: string[]; images: StagedImage[] }): Promise<void> {
|
|
// The optimistic row renders the staged previews and the composed
|
|
// chip record, the same plain text and spans the fold records on
|
|
// the other side, so the stream's user_message echo, which
|
|
// carries the stored ids beside that record, dedupes against it.
|
|
const composed = composeChips(message.text, message.pastes)
|
|
const rowId = transcript.addSent(
|
|
composed.text,
|
|
message.images.map(({ media_type, url, name }) => ({ id: null, media_type, url, name })),
|
|
composed.pastes,
|
|
)
|
|
busy.value = true
|
|
try {
|
|
// Fire-and-forget by design: the claw answers 202 and the reply
|
|
// arrives on the event stream. The chips and the images ride the
|
|
// body only when there are some.
|
|
await claw.sendMessage(
|
|
activeKey.value,
|
|
message.text,
|
|
message.pastes,
|
|
message.images.map(({ media_type, data }) => ({ media_type, data })),
|
|
)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
// The claw never took the message: retract the optimistic row, or
|
|
// it would sit there forever waiting for a reply that cannot come.
|
|
transcript.removeSent(rowId)
|
|
noteApiError(err)
|
|
} finally {
|
|
busy.value = false
|
|
}
|
|
void refreshSessions()
|
|
}
|
|
|
|
// A consent answers optimistically: the card flips as soon as the POST
|
|
// lands, and the stream's consent_resolved echo confirms the same
|
|
// value.
|
|
async function answerConsent(id: string, answer: ConsentAnswer): Promise<void> {
|
|
try {
|
|
await claw.resolveConsent(id, answer)
|
|
transcript.resolveConsent(id, 'secret' in answer ? true : answer.grant)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
}
|
|
|
|
async function denyConsent(id: string): Promise<void> {
|
|
try {
|
|
await claw.denyConsent(id)
|
|
transcript.resolveConsent(id, false)
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
}
|
|
|
|
async function downloadAttachment(id: string, name: string): Promise<void> {
|
|
try {
|
|
// The URL is cached per id, so a second download of the same file
|
|
// replays the blob, not the request.
|
|
const url = await claw.attachmentUrl(id)
|
|
const anchor = document.createElement('a')
|
|
anchor.href = url
|
|
anchor.download = name
|
|
// A click on a detached anchor is a no-op in some browsers; the
|
|
// element joins the document for the length of the click.
|
|
document.body.append(anchor)
|
|
anchor.click()
|
|
anchor.remove()
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
}
|
|
}
|
|
|
|
function saveToken(): void {
|
|
const next = tokenDraft.value.trim()
|
|
token.value = next || null
|
|
persist(TOKEN_STORE_KEY, next || null)
|
|
tokenDraft.value = ''
|
|
authRequired.value = false
|
|
apiError.value = null
|
|
// The stream's retry loop reads the token fresh each attempt, so it
|
|
// recovers on its own; everything the 401 froze reloads now, the
|
|
// polls confirm the token works, and the identity and accounts pages
|
|
// were left empty by the failed fetches that raised the banner.
|
|
void checkHealth()
|
|
void refreshProviders()
|
|
void refreshSessions()
|
|
void refreshIdentity()
|
|
void refreshAccounts()
|
|
void refreshSkills()
|
|
void refreshBootstrap()
|
|
void refreshMcp()
|
|
void refreshSandbox()
|
|
}
|
|
|
|
// --- the one live subscription ---------------------------------------
|
|
let stream: { close: () => void } | null = null
|
|
/** The revision the read-only thread on screen was loaded at; a poll
|
|
* that sees a newer one reloads it, since no stream will. */
|
|
let threadRevision: number | null = null
|
|
/** A load is in flight: a poll landing mid-load must not start a second
|
|
* one and append the same page twice. */
|
|
let threadLoading = false
|
|
/** Whether the key on screen answers a snapshot. The key's prefix says
|
|
* so before the fetch lands; the page's own `read_only` has the last
|
|
* word. */
|
|
const threadReadOnly = ref(false)
|
|
|
|
function resubscribe(): void {
|
|
stream?.close()
|
|
stream = null
|
|
transcript.reset()
|
|
olderAvailable.value = true
|
|
attemptedAttachments = new WeakSet<object>()
|
|
notices.value = []
|
|
streamStatus.value = 'connecting'
|
|
threadRevision = null
|
|
threadReadOnly.value = activeKey.value !== '' && !isResidentKey(activeKey.value)
|
|
// Deleting the last session clears the key, and an empty key is not a
|
|
// stream: subscribing to one would retry a 404 forever.
|
|
if (activeKey.value === '') return
|
|
// A key outside the resident context has no turn record: its handler
|
|
// never streams, and the events route answers 400. What the daemon
|
|
// does hold is the session stash, which the history route serves as a
|
|
// read-only snapshot. The panel shows it with the composer closed.
|
|
if (!isResidentKey(activeKey.value)) {
|
|
void loadThread()
|
|
return
|
|
}
|
|
stream = claw.subscribeEvents(activeKey.value, {
|
|
onEvent: (event, seq) => transcript.applyEvent(event, seq),
|
|
// The record lost what this mirror holds (a wiped or reset
|
|
// database): drop it, and the tail the claw sends next rebuilds it.
|
|
onReset: () => {
|
|
transcript.reset()
|
|
olderAvailable.value = true
|
|
attemptedAttachments = new WeakSet<object>()
|
|
requestAttachmentImages()
|
|
},
|
|
onStatus: (status) => {
|
|
streamStatus.value = status
|
|
// A retry resumes from the last seq this mirror holds, so the
|
|
// claw sends the gap and nothing else: the mirror stays as it
|
|
// is. Only the attachment set is cleared, a fetch that failed
|
|
// during the outage should retry against the recovered stream.
|
|
if (status === 'reconnecting') {
|
|
attemptedAttachments = new WeakSet<object>()
|
|
requestAttachmentImages()
|
|
}
|
|
if (status === 'open') void refreshSessions()
|
|
},
|
|
onNotice: pushNotice,
|
|
})
|
|
}
|
|
|
|
/** Loads the newest page of a read-only thread: a snapshot of the
|
|
* engine's own history, rendered by the same mirror the stream feeds.
|
|
* Pagination is the walk back, unchanged, a page lands, the scroller
|
|
* asks for the next one. */
|
|
async function loadThread(): Promise<void> {
|
|
const key = activeKey.value
|
|
threadLoading = true
|
|
streamStatus.value = 'open'
|
|
// A reload (a finished dispatch moved the revision) rebuilds from the
|
|
// newest page: the mirror holds the previous snapshot, and stacking
|
|
// the new one under it would duplicate every turn.
|
|
transcript.reset()
|
|
olderAvailable.value = true
|
|
attemptedAttachments = new WeakSet<object>()
|
|
try {
|
|
const page = await claw.history(key)
|
|
if (key !== activeKey.value) return
|
|
for (const { seq, event } of page.events) transcript.applyEvent(event, seq)
|
|
olderAvailable.value = page.more
|
|
threadReadOnly.value = page.readOnly
|
|
threadRevision = sessions.value.find((session) => session.key === key)?.revision ?? null
|
|
apiError.value = null
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
threadLoading = false
|
|
}
|
|
}
|
|
|
|
/** Fetches one page of turns older than the mirror's first and stacks
|
|
* it above. Whole turns only, so the page never duplicates or skips:
|
|
* the daemon ends it exactly where the mirror begins. */
|
|
async function loadOlder(): Promise<void> {
|
|
const before = transcript.firstSeq.value
|
|
if (before === null || !olderAvailable.value || transcript.loadingOlder.value) return
|
|
transcript.loadingOlder.value = true
|
|
const key = activeKey.value
|
|
try {
|
|
const page = await claw.history(key, before)
|
|
// The reader may have switched sessions while the page was in
|
|
// flight; a page belongs to the mirror it was asked for.
|
|
if (key !== activeKey.value) return
|
|
transcript.prependOlder(page.events)
|
|
olderAvailable.value = page.more
|
|
} catch (err) {
|
|
noteApiError(err)
|
|
} finally {
|
|
transcript.loadingOlder.value = false
|
|
}
|
|
}
|
|
|
|
watch(activeKey, resubscribe)
|
|
|
|
let healthTimer: ReturnType<typeof setInterval> | undefined
|
|
let sessionsTimer: ReturnType<typeof setInterval> | undefined
|
|
|
|
onMounted(() => {
|
|
window.addEventListener('hashchange', onHashChange)
|
|
resubscribe()
|
|
void checkHealth()
|
|
void refreshIdentity()
|
|
void refreshProviders()
|
|
void refreshAccounts()
|
|
void refreshSkills()
|
|
void refreshBootstrap()
|
|
void refreshMcp()
|
|
void refreshSandbox()
|
|
void refreshSessions()
|
|
healthTimer = setInterval(checkHealth, 30000)
|
|
sessionsTimer = setInterval(() => void refreshSessions(), 20000)
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
window.removeEventListener('hashchange', onHashChange)
|
|
stream?.close()
|
|
clearInterval(healthTimer)
|
|
clearInterval(sessionsTimer)
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="shell" :class="{ 'shell-settings': route.view === 'settings' }">
|
|
<SessionsSidebar
|
|
v-if="route.view === 'chat'"
|
|
:sessions="sessions"
|
|
:active-key="activeKey"
|
|
:loading="sessionsLoading"
|
|
:claw-up="clawUp"
|
|
:identity="identity"
|
|
:avatar-url="identityAvatarUrl"
|
|
@home="go({ view: 'chat' })"
|
|
@navigate-settings="go({ view: 'settings', section: 'providers' })"
|
|
@select="activeKey = $event"
|
|
@refresh="refreshSessions"
|
|
@create="createSession"
|
|
@delete="askDeleteSession"
|
|
@pause="pauseSession"
|
|
@resume="resumeSession"
|
|
@abort="abortSession"
|
|
/>
|
|
<SettingsNav
|
|
v-else
|
|
:sections="SETTINGS_SECTIONS"
|
|
:active="route.section"
|
|
:claw-up="clawUp"
|
|
@home="go({ view: 'chat' })"
|
|
@navigate-chat="go({ view: 'chat' })"
|
|
@select="go({ view: 'settings', section: $event })"
|
|
/>
|
|
|
|
<div class="body">
|
|
<div class="banners">
|
|
<ClawBanner v-if="authRequired" variant="error">
|
|
the claw requires a bearer token on /v1.
|
|
<template #actions>
|
|
<input
|
|
v-model="tokenDraft"
|
|
type="password"
|
|
placeholder="token"
|
|
autocomplete="off"
|
|
@keydown.enter="saveToken"
|
|
/>
|
|
<button @click="saveToken">Save</button>
|
|
</template>
|
|
</ClawBanner>
|
|
<ClawBanner v-if="clawUp === false" variant="error">
|
|
the claw is unreachable at {{ config.public.clawBase || 'same origin (dev proxy → 127.0.0.1:7799)' }};
|
|
start it with <code>rhema-claw</code>
|
|
</ClawBanner>
|
|
<ClawBanner v-if="apiError" variant="error" dismissible @dismiss="apiError = null">
|
|
{{ apiError }}
|
|
</ClawBanner>
|
|
<ClawBanner
|
|
v-for="notice in notices"
|
|
:key="notice.id"
|
|
variant="warn"
|
|
dismissible
|
|
@dismiss="notices = notices.filter((n) => n.id !== notice.id)"
|
|
>
|
|
{{ notice.text }}
|
|
</ClawBanner>
|
|
</div>
|
|
|
|
<main class="view">
|
|
<ChatPanel
|
|
v-if="route.view === 'chat'"
|
|
:items="transcriptItems"
|
|
:live="liveTurn"
|
|
:active-key="activeKey"
|
|
:can-send="isInteractive(activeKey)"
|
|
:read-only="threadReadOnly"
|
|
:busy="busy"
|
|
:session="activeSession"
|
|
:active-backend="providersState?.active ?? null"
|
|
:stream-status="streamStatus"
|
|
:loading-older="loadingOlder"
|
|
:older-available="olderAvailable"
|
|
:prepend-count="prependCount"
|
|
:identity="identity"
|
|
:avatar-url="identityAvatarUrl"
|
|
@older="loadOlder"
|
|
@send="send"
|
|
@open-providers="go({ view: 'settings', section: 'providers' })"
|
|
@consent-answer="answerConsent"
|
|
@consent-deny="denyConsent"
|
|
@download-attachment="downloadAttachment"
|
|
/>
|
|
|
|
<template v-else>
|
|
<SettingsAgentGeneralPage
|
|
v-show="route.section === 'agent/general'"
|
|
:identity="identity"
|
|
:avatar-url="identityAvatarUrl"
|
|
:logo-url="identityLogoUrl"
|
|
:saving="savingIdentity"
|
|
:mutating="mutatingIdentity"
|
|
@save="saveIdentity"
|
|
@upload-image="uploadIdentityImage"
|
|
@clear-image="clearIdentityImage"
|
|
/>
|
|
<SettingsAgentAccountsPage
|
|
v-show="route.section === 'agent/accounts'"
|
|
:accounts="accounts"
|
|
:loading="accountsLoading"
|
|
:mutating="mutatingAccounts"
|
|
@add="addAccount"
|
|
@remove="removeAccount"
|
|
/>
|
|
<SettingsProvidersPage
|
|
v-show="route.section === 'providers'"
|
|
:state="providersState"
|
|
:models="providerModels"
|
|
:models-loading="providerModelsLoading"
|
|
:models-error="providerModelsError"
|
|
:selected-provider="selectedProvider"
|
|
:saving="savingProviders"
|
|
:mutating="mutatingProviders"
|
|
@inspect="loadProviderModels"
|
|
@save="saveProviders"
|
|
@add="addProvider"
|
|
@remove="removeProvider"
|
|
/>
|
|
<SettingsSkillsPage
|
|
v-show="route.section === 'skills'"
|
|
:state="skillsState"
|
|
:loading="skillsLoading"
|
|
:saving="skillsSaving"
|
|
@refresh="refreshSkills"
|
|
@toggle="toggleSkill"
|
|
/>
|
|
<SettingsBootstrapPage
|
|
v-show="route.section === 'agent/bootstrap'"
|
|
:state="bootstrapFiles"
|
|
:loading="bootstrapLoading"
|
|
:saving="bootstrapSaving"
|
|
@refresh="refreshBootstrap"
|
|
@save="saveBootstrapFile"
|
|
/>
|
|
<SettingsMcpPage
|
|
v-show="route.section === 'mcp'"
|
|
:state="mcpState"
|
|
:loading="mcpLoading"
|
|
@refresh="refreshMcp"
|
|
/>
|
|
<SettingsSandboxPage
|
|
v-show="route.section === 'sandbox'"
|
|
:state="sandboxState"
|
|
:saving="savingSandbox"
|
|
@save="saveSandbox"
|
|
/>
|
|
<SettingsAboutPage v-show="route.section === 'about'" :claw-up="clawUp" />
|
|
</template>
|
|
</main>
|
|
</div>
|
|
|
|
<AppModal
|
|
:open="deletingKey !== null"
|
|
title="Delete session"
|
|
@close="closeDeleteSession"
|
|
>
|
|
<p>
|
|
Delete <span class="mono">{{ deletingKey }}</span>? Its dispatch record and its
|
|
turn history both go: the transcript cannot be recovered, and a session
|
|
created under the same name starts empty.
|
|
</p>
|
|
<template #actions>
|
|
<button class="btn-quiet" :disabled="deleting" @click="closeDeleteSession">
|
|
Cancel
|
|
</button>
|
|
<button class="btn-danger" :disabled="deleting" @click="confirmDeleteSession">
|
|
{{ deleting ? 'Deleting…' : 'Delete' }}
|
|
</button>
|
|
</template>
|
|
</AppModal>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.shell {
|
|
display: flex;
|
|
height: 100vh;
|
|
}
|
|
|
|
.body {
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex: 1;
|
|
min-width: 0;
|
|
}
|
|
|
|
.banners {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: var(--sp-2);
|
|
padding: var(--sp-2) var(--sp-4) 0;
|
|
}
|
|
|
|
.view {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 0;
|
|
}
|
|
|
|
.view > * {
|
|
min-height: 0;
|
|
}
|
|
|
|
@media (max-width: 860px) {
|
|
.shell {
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
min-height: 0;
|
|
}
|
|
|
|
.body {
|
|
flex: 1;
|
|
min-height: 0;
|
|
}
|
|
|
|
.view {
|
|
flex: 1;
|
|
min-height: 0;
|
|
}
|
|
|
|
/* Settings is a document on a phone: the nav and the page scroll
|
|
together instead of squeezing the page into the space left. */
|
|
.shell-settings {
|
|
height: auto;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.shell-settings .body,
|
|
.shell-settings .view {
|
|
flex: none;
|
|
}
|
|
}
|
|
</style>
|