mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-14 04:02:26 +00:00
refactor(tui): clean thinking and viewport helpers
This commit is contained in:
parent
a30ffbe1d4
commit
7b5b524fc7
2 changed files with 15 additions and 40 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { THINKING_COT_MAX } from '../config/limits.js'
|
import { THINKING_COT_MAX } from '../config/limits.js'
|
||||||
|
import { VERBS } from '../content/verbs.js'
|
||||||
import type { ThinkingMode } from '../types.js'
|
import type { ThinkingMode } from '../types.js'
|
||||||
|
|
||||||
const ESC = String.fromCharCode(27)
|
const ESC = String.fromCharCode(27)
|
||||||
|
|
@ -70,32 +71,8 @@ export const pasteTokenLabel = (text: string, lineCount: number) => {
|
||||||
: `[[ ${preview} [${fmtK(lineCount)} lines] ]]`
|
: `[[ ${preview} [${fmtK(lineCount)} lines] ]]`
|
||||||
}
|
}
|
||||||
|
|
||||||
const THINKING_STATUS_WORDS = [
|
const THINKING_STATUS_RE = new RegExp(`^(?:${VERBS.join('|')})\\.{0,3}$`, 'i')
|
||||||
'pondering',
|
const THINKING_STATUS_CHUNK_RE = new RegExp(`[^A-Za-z\n]+\\s*(?:${VERBS.join('|')})\\.{0,3}\\s*`, 'giu')
|
||||||
'contemplating',
|
|
||||||
'musing',
|
|
||||||
'cogitating',
|
|
||||||
'ruminating',
|
|
||||||
'deliberating',
|
|
||||||
'mulling',
|
|
||||||
'reflecting',
|
|
||||||
'processing',
|
|
||||||
'reasoning',
|
|
||||||
'analyzing',
|
|
||||||
'computing',
|
|
||||||
'synthesizing',
|
|
||||||
'formulating',
|
|
||||||
'brainstorming'
|
|
||||||
]
|
|
||||||
|
|
||||||
const THINKING_STATUS_RE = new RegExp(`^(?:${THINKING_STATUS_WORDS.join('|')})\\.{0,3}$`, 'i')
|
|
||||||
|
|
||||||
const THINKING_FACE_SOURCE = '[^A-Za-z\n]+'
|
|
||||||
|
|
||||||
const THINKING_STATUS_CHUNK_RE = new RegExp(
|
|
||||||
`${THINKING_FACE_SOURCE}\\s*(?:${THINKING_STATUS_WORDS.join('|')})\\.{0,3}\\s*`,
|
|
||||||
'giu'
|
|
||||||
)
|
|
||||||
|
|
||||||
export const cleanThinkingText = (reasoning: string) =>
|
export const cleanThinkingText = (reasoning: string) =>
|
||||||
reasoning
|
reasoning
|
||||||
|
|
|
||||||
|
|
@ -45,19 +45,6 @@ export function viewportSnapshotKey(v: ViewportSnapshot) {
|
||||||
return `${v.atBottom ? 1 : 0}:${v.top}:${v.viewportHeight}:${v.scrollHeight}:${v.pending}`
|
return `${v.atBottom ? 1 : 0}:${v.top}:${v.viewportHeight}:${v.scrollHeight}:${v.pending}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const snapshotFromKey = (key: string): ViewportSnapshot => {
|
|
||||||
const [atBottom = '1', top = '0', viewportHeight = '0', scrollHeight = '0', pending = '0'] = key.split(':')
|
|
||||||
|
|
||||||
return {
|
|
||||||
atBottom: atBottom === '1',
|
|
||||||
bottom: Number(top) + Number(viewportHeight),
|
|
||||||
pending: Number(pending),
|
|
||||||
scrollHeight: Number(scrollHeight),
|
|
||||||
top: Number(top),
|
|
||||||
viewportHeight: Number(viewportHeight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useViewportSnapshot(scrollRef: RefObject<ScrollBoxHandle | null>): ViewportSnapshot {
|
export function useViewportSnapshot(scrollRef: RefObject<ScrollBoxHandle | null>): ViewportSnapshot {
|
||||||
const key = useSyncExternalStore(
|
const key = useSyncExternalStore(
|
||||||
useCallback((cb: () => void) => scrollRef.current?.subscribe(cb) ?? (() => {}), [scrollRef]),
|
useCallback((cb: () => void) => scrollRef.current?.subscribe(cb) ?? (() => {}), [scrollRef]),
|
||||||
|
|
@ -65,5 +52,16 @@ export function useViewportSnapshot(scrollRef: RefObject<ScrollBoxHandle | null>
|
||||||
() => viewportSnapshotKey(EMPTY)
|
() => viewportSnapshotKey(EMPTY)
|
||||||
)
|
)
|
||||||
|
|
||||||
return useMemo(() => snapshotFromKey(key), [key])
|
return useMemo(() => {
|
||||||
|
const [atBottom = '1', top = '0', viewportHeight = '0', scrollHeight = '0', pending = '0'] = key.split(':')
|
||||||
|
|
||||||
|
return {
|
||||||
|
atBottom: atBottom === '1',
|
||||||
|
bottom: Number(top) + Number(viewportHeight),
|
||||||
|
pending: Number(pending),
|
||||||
|
scrollHeight: Number(scrollHeight),
|
||||||
|
top: Number(top),
|
||||||
|
viewportHeight: Number(viewportHeight)
|
||||||
|
}
|
||||||
|
}, [key])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue