mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
refactor(tui): clean thinking and viewport helpers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { THINKING_COT_MAX } from '../config/limits.js'
|
||||
import { VERBS } from '../content/verbs.js'
|
||||
import type { ThinkingMode } from '../types.js'
|
||||
|
||||
const ESC = String.fromCharCode(27)
|
||||
@@ -70,32 +71,8 @@ export const pasteTokenLabel = (text: string, lineCount: number) => {
|
||||
: `[[ ${preview} [${fmtK(lineCount)} lines] ]]`
|
||||
}
|
||||
|
||||
const THINKING_STATUS_WORDS = [
|
||||
'pondering',
|
||||
'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'
|
||||
)
|
||||
const THINKING_STATUS_RE = new RegExp(`^(?:${VERBS.join('|')})\\.{0,3}$`, 'i')
|
||||
const THINKING_STATUS_CHUNK_RE = new RegExp(`[^A-Za-z\n]+\\s*(?:${VERBS.join('|')})\\.{0,3}\\s*`, 'giu')
|
||||
|
||||
export const cleanThinkingText = (reasoning: string) =>
|
||||
reasoning
|
||||
|
||||
@@ -45,19 +45,6 @@ export function viewportSnapshotKey(v: ViewportSnapshot) {
|
||||
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 {
|
||||
const key = useSyncExternalStore(
|
||||
useCallback((cb: () => void) => scrollRef.current?.subscribe(cb) ?? (() => {}), [scrollRef]),
|
||||
@@ -65,5 +52,16 @@ export function useViewportSnapshot(scrollRef: RefObject<ScrollBoxHandle | null>
|
||||
() => 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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user