okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
743a6b3c6
main
1import { useEffect , useState } from 'react' ; 2import { tr } from '../lib/i18n' ; 3import { elapsedText , isPlayful , statusWords , useLiveStatus } from '../lib/live-status' ; 4 5/** 6* The line under the newest message while the model works: a small pulse, what it is doing (a playful word while it only thinks, 7* the real action once a tool runs), how long, and how many tokens. It shows the latest status frame only and nothing older. 8*/ 9export function StatusLine ({ sessionId, startedAt, tokens} :{ sessionId :string | null ; startedAt :number ; tokens ?:number }) { 10const frame = useLiveStatus ( sessionId ); 11const [ now , setNow ] = useState (() => Date . now ()); 12const [ rotation , setRotation ] = useState ( 0 ); 13useEffect (() => { 14if ( ! frame ) return ; 15const tick = setInterval (() => setNow ( Date . now ()), 1000 ); 16return () => clearInterval ( tick ); 17}, [ !! frame ]); 18const playful = !! frame && isPlayful ( frame ); 19useEffect (() => { 20if ( ! playful ) return ; 21const spin = setInterval (() => setRotation ( r => r + 1 ), 3500 ); 22return () => clearInterval ( spin ); 23}, [ playful ]); 24if ( ! frame ) return null ; 25const count = frame . tokens ?? tokens ; 26return < div className = "live-status" data-phase = { frame . phase } aria-live = "off" > 27< span className = "live-status__pulse" aria-hidden = "true" >< i />< i /></ span > 28< span className = "live-status__verb" key = { playful ?rotation :frame . code + String ( frame . args ?. target ?? '' )} title = { statusWords ( frame , rotation )}>{ statusWords ( frame , rotation )}</ span > 29< span className = "live-status__time" >{ elapsedText ( startedAt , now )}</ span > 30< span className = "live-status__tokens" >{ count ?tr ( '{0} tokens' , [ count . toLocaleString ()]) :'' }</ span > 31</ div >; 32}