mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
'top' and 'bottom' are positions relative to the input row, not the alt screen viewport: - top (default) → inline above the input, where the bar originally lived (what 'on' used to mean) - bottom → below the input, pinned to the last row - off → hidden Drops the literal top-of-screen placement; 'on' is kept as a backward- compat alias that resolves to 'top' at both the config layer (normalizeStatusBar, _coerce_statusbar) and the slash command.
114 lines
3.4 KiB
TypeScript
114 lines
3.4 KiB
TypeScript
import { useEffect, useRef } from 'react'
|
|
|
|
import { resolveDetailsMode } from '../domain/details.js'
|
|
import type { GatewayClient } from '../gatewayClient.js'
|
|
import type {
|
|
ConfigFullResponse,
|
|
ConfigMtimeResponse,
|
|
ReloadMcpResponse,
|
|
VoiceToggleResponse
|
|
} from '../gatewayTypes.js'
|
|
import { asRpcResult } from '../lib/rpc.js'
|
|
|
|
import type { StatusBarMode } from './interfaces.js'
|
|
import { turnController } from './turnController.js'
|
|
import { patchUiState } from './uiStore.js'
|
|
|
|
const STATUSBAR_MODES = new Set<StatusBarMode>(['bottom', 'off', 'top'])
|
|
|
|
// Legacy configs stored tui_statusbar as a bool; the short-lived 4-mode
|
|
// variant wrote 'on'. Both map to 'top' (inline above the input) — the
|
|
// original feature's default — so users keep their preference without
|
|
// manual migration.
|
|
export const normalizeStatusBar = (raw: unknown): StatusBarMode => {
|
|
if (raw === false) return 'off'
|
|
if (raw === true || raw == null || raw === 'on') return 'top'
|
|
if (typeof raw === 'string' && STATUSBAR_MODES.has(raw as StatusBarMode)) return raw as StatusBarMode
|
|
|
|
return 'top'
|
|
}
|
|
|
|
const MTIME_POLL_MS = 5000
|
|
|
|
const quietRpc = async <T extends Record<string, any> = Record<string, any>>(
|
|
gw: GatewayClient,
|
|
method: string,
|
|
params: Record<string, unknown> = {}
|
|
): Promise<null | T> => {
|
|
try {
|
|
return asRpcResult<T>(await gw.request<T>(method, params))
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const applyDisplay = (cfg: ConfigFullResponse | null, setBell: (v: boolean) => void) => {
|
|
const d = cfg?.config?.display ?? {}
|
|
|
|
setBell(!!d.bell_on_complete)
|
|
patchUiState({
|
|
compact: !!d.tui_compact,
|
|
detailsMode: resolveDetailsMode(d),
|
|
inlineDiffs: d.inline_diffs !== false,
|
|
showCost: !!d.show_cost,
|
|
showReasoning: !!d.show_reasoning,
|
|
statusBar: normalizeStatusBar(d.tui_statusbar),
|
|
streaming: d.streaming !== false
|
|
})
|
|
}
|
|
|
|
export function useConfigSync({ gw, setBellOnComplete, setVoiceEnabled, sid }: UseConfigSyncOptions) {
|
|
const mtimeRef = useRef(0)
|
|
|
|
useEffect(() => {
|
|
if (!sid) {
|
|
return
|
|
}
|
|
|
|
quietRpc<VoiceToggleResponse>(gw, 'voice.toggle', { action: 'status' }).then(r => setVoiceEnabled(!!r?.enabled))
|
|
quietRpc<ConfigMtimeResponse>(gw, 'config.get', { key: 'mtime' }).then(r => {
|
|
mtimeRef.current = Number(r?.mtime ?? 0)
|
|
})
|
|
quietRpc<ConfigFullResponse>(gw, 'config.get', { key: 'full' }).then(r => applyDisplay(r, setBellOnComplete))
|
|
}, [gw, setBellOnComplete, setVoiceEnabled, sid])
|
|
|
|
useEffect(() => {
|
|
if (!sid) {
|
|
return
|
|
}
|
|
|
|
const id = setInterval(() => {
|
|
quietRpc<ConfigMtimeResponse>(gw, 'config.get', { key: 'mtime' }).then(r => {
|
|
const next = Number(r?.mtime ?? 0)
|
|
|
|
if (!mtimeRef.current) {
|
|
if (next) {
|
|
mtimeRef.current = next
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if (!next || next === mtimeRef.current) {
|
|
return
|
|
}
|
|
|
|
mtimeRef.current = next
|
|
|
|
quietRpc<ReloadMcpResponse>(gw, 'reload.mcp', { session_id: sid }).then(
|
|
r => r && turnController.pushActivity('MCP reloaded after config change')
|
|
)
|
|
quietRpc<ConfigFullResponse>(gw, 'config.get', { key: 'full' }).then(r => applyDisplay(r, setBellOnComplete))
|
|
})
|
|
}, MTIME_POLL_MS)
|
|
|
|
return () => clearInterval(id)
|
|
}, [gw, setBellOnComplete, sid])
|
|
}
|
|
|
|
export interface UseConfigSyncOptions {
|
|
gw: GatewayClient
|
|
setBellOnComplete: (v: boolean) => void
|
|
setVoiceEnabled: (v: boolean) => void
|
|
sid: null | string
|
|
}
|