okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
334dde73a
main
1import { useEffect , useRef , useState } from 'react' ; 2import { tr } from '../lib/i18n' ; 3import type { ChatMessage } from '../lib/types' ; 4import { atBottom , lastReasoningLine , thoughtDuration } from '../lib/reasoning' ; 5import { Icon } from './ui' ; 6 7/** 8* The model's reasoning as one quiet line above its answer. Closed by default: while it reasons the line shows what it is thinking about, 9* afterwards "Thought for 38s". Opened, it is a short muted box that follows the newest line unless the person scrolls up. 10*/ 11export function ReasoningBlock ({ message} :{ message :ChatMessage }) { 12const text = message . reasoning ?? '' ; 13const body = useRef < HTMLDivElement >( null ); 14const [ open , setOpen ] = useState ( false ); 15const [ stick , setStick ] = useState ( true ); 16const thinking = !! message . streaming && message . reasoningMs === undefined && ! message . content ; 17useEffect (() => { if ( open && stick && body . current ) body . current . scrollTop = body . current . scrollHeight ; }, [ text , open , stick ]); 18useEffect (() => { if ( open ) { setStick ( true ); requestAnimationFrame (() => { if ( body . current ) body . current . scrollTop = body . current . scrollHeight ; }); } }, [ open ]); 19const took = thoughtDuration ( message . reasoningMs ); 20const label = thinking ?lastReasoningLine ( text ) || tr ( 'Thinking…' ) :took ?tr ( 'Thought for {0}' , [ took ]) :tr ( 'Reasoning' ); 21return < details className = "rz" open = { open } data-live = { thinking || undefined } onToggle = { e => setOpen ( e . currentTarget . open )}> 22< summary >< Icon name = "thinking" size = { 14 }/>< span className = "rz__label" >{ label }</ span >< Icon name = "chevron" size = { 12 } className = "rz__chev" /></ summary > 23< div className = "rz__body" ref = { body } tabIndex = { 0 } aria-label = { tr ( 'Model reasoning' )} onScroll = { e => setStick ( atBottom ( e . currentTarget ))}>{ text }</ div > 24{ open && thinking && ! stick ?< button type = "button" className = "rz__jump" onClick = {() => { setStick ( true ); }}>< Icon name = "chevron" size = { 11 }/>{ tr ( 'Jump to latest' )}</ button > :null } 25</ details >; 26}