mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-30 01:41:43 +00:00
feat: small refactors
This commit is contained in:
parent
e2b3b1c5e4
commit
afd670a36f
12 changed files with 2780 additions and 68 deletions
|
|
@ -90,11 +90,17 @@ export function Md({ compact, t, text }: { compact?: boolean; t: Theme; text: st
|
|||
}
|
||||
|
||||
i++
|
||||
const isDiff = lang === 'diff'
|
||||
|
||||
nodes.push(
|
||||
<Box flexDirection="column" key={key} paddingLeft={2}>
|
||||
{lang && <Text color={t.color.dim}>{'─ ' + lang}</Text>}
|
||||
{lang && !isDiff && <Text color={t.color.dim}>{'─ ' + lang}</Text>}
|
||||
{block.map((l, j) => (
|
||||
<Text color={t.color.cornsilk} key={j}>
|
||||
<Text
|
||||
color={isDiff && l.startsWith('+') ? '#a6e3a1' : isDiff && l.startsWith('-') ? '#f38ba8' : t.color.cornsilk}
|
||||
dimColor={isDiff && !l.startsWith('+') && !l.startsWith('-') && l.startsWith(' ')}
|
||||
key={j}
|
||||
>
|
||||
{l}
|
||||
</Text>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,27 @@ import { Box, Text } from 'ink'
|
|||
import { compactPreview } from '../lib/text.js'
|
||||
import type { Theme } from '../theme.js'
|
||||
|
||||
export const QUEUE_WINDOW = 3
|
||||
|
||||
export function getQueueWindow(queueLen: number, queueEditIdx: number | null) {
|
||||
const start =
|
||||
queueEditIdx === null ? 0 : Math.max(0, Math.min(queueEditIdx - 1, Math.max(0, queueLen - QUEUE_WINDOW)))
|
||||
|
||||
const end = Math.min(queueLen, start + QUEUE_WINDOW)
|
||||
|
||||
return { end, showLead: start > 0, showTail: end < queueLen, start }
|
||||
}
|
||||
|
||||
export function estimateQueuedRows(queueLen: number, queueEditIdx: number | null): number {
|
||||
if (!queueLen) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const win = getQueueWindow(queueLen, queueEditIdx)
|
||||
|
||||
return 1 + (win.showLead ? 1 : 0) + (win.end - win.start) + (win.showTail ? 1 : 0)
|
||||
}
|
||||
|
||||
export function QueuedMessages({
|
||||
cols,
|
||||
queueEditIdx,
|
||||
|
|
@ -18,23 +39,21 @@ export function QueuedMessages({
|
|||
return null
|
||||
}
|
||||
|
||||
const qWindow = 3
|
||||
const qStart = queueEditIdx === null ? 0 : Math.max(0, Math.min(queueEditIdx - 1, queued.length - qWindow))
|
||||
const qEnd = Math.min(queued.length, qStart + qWindow)
|
||||
const q = getQueueWindow(queued.length, queueEditIdx)
|
||||
|
||||
return (
|
||||
<Box flexDirection="column">
|
||||
<Text color={t.color.dim} dimColor>
|
||||
queued ({queued.length}){queueEditIdx !== null ? ` · editing ${queueEditIdx + 1}` : ''}
|
||||
</Text>
|
||||
{qStart > 0 && (
|
||||
{q.showLead && (
|
||||
<Text color={t.color.dim} dimColor>
|
||||
{' '}
|
||||
…
|
||||
</Text>
|
||||
)}
|
||||
{queued.slice(qStart, qEnd).map((item, i) => {
|
||||
const idx = qStart + i
|
||||
{queued.slice(q.start, q.end).map((item, i) => {
|
||||
const idx = q.start + i
|
||||
const active = queueEditIdx === idx
|
||||
|
||||
return (
|
||||
|
|
@ -43,9 +62,9 @@ export function QueuedMessages({
|
|||
</Text>
|
||||
)
|
||||
})}
|
||||
{qEnd < queued.length && (
|
||||
{q.showTail && (
|
||||
<Text color={t.color.dim} dimColor>
|
||||
{' '}…and {queued.length - qEnd} more
|
||||
{' '}…and {queued.length - q.end} more
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ export function Thinking({
|
|||
return () => clearInterval(id)
|
||||
}, [])
|
||||
|
||||
const tail = (reasoning || thinking || '').slice(-120).replace(/\n/g, ' ')
|
||||
|
||||
return (
|
||||
<Box flexDirection="column">
|
||||
{tools.length ? (
|
||||
|
|
@ -35,17 +37,15 @@ export function Thinking({
|
|||
{SPINNER[frame]} {TOOL_VERBS[tool.name] ?? '⚡ ' + tool.name}…
|
||||
</Text>
|
||||
))
|
||||
) : tail ? (
|
||||
<Text color={t.color.dim} dimColor wrap="truncate-end">
|
||||
{SPINNER[frame]} 💭 {tail}
|
||||
</Text>
|
||||
) : (
|
||||
<Text color={t.color.dim}>
|
||||
{SPINNER[frame]} {face} {verb}…
|
||||
</Text>
|
||||
)}
|
||||
{(reasoning || thinking) && (
|
||||
<Text color={t.color.dim} dimColor wrap="truncate-end">
|
||||
{' 💭 '}
|
||||
{(reasoning || thinking || '').slice(-120).replace(/\n/g, ' ')}
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue