diff --git a/ui-tui/src/lib/text.ts b/ui-tui/src/lib/text.ts index 18d5a5a649f..9407c8fae8a 100644 --- a/ui-tui/src/lib/text.ts +++ b/ui-tui/src/lib/text.ts @@ -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 diff --git a/ui-tui/src/lib/viewportStore.ts b/ui-tui/src/lib/viewportStore.ts index 0a52e99a877..58e24ab87c5 100644 --- a/ui-tui/src/lib/viewportStore.ts +++ b/ui-tui/src/lib/viewportStore.ts @@ -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): ViewportSnapshot { const key = useSyncExternalStore( useCallback((cb: () => void) => scrollRef.current?.subscribe(cb) ?? (() => {}), [scrollRef]), @@ -65,5 +52,16 @@ export function useViewportSnapshot(scrollRef: RefObject () => 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]) }