okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
1import type { Session } from './types' ; 2 3export function recentChats ( sessions :Session [], activeId ?:string | null ) { 4const ordered = sessions . filter ( session => ! session . archived ) 5. sort (( a , b ) => b . updatedAt . localeCompare ( a . updatedAt )); 6const current = ordered . find ( session => session . id === activeId ); 7const latest = ordered . filter ( session => session . id !== current ?. id ). slice ( 0 , 5 ); 8const ids = new Set ([ ...latest , ...( current ?[ current ] :[])]. map ( session => session . id )); 9// Activity order keeps number shortcuts stable when simply switching chats. 10return ordered . filter ( session => ids . has ( session . id )); 11} 12 13export function recentChatDescription ( session :Session ) { 14const message = session . messages . filter ( message => message . role === 'user' ). at ( - 1 ) ?? session . messages . at ( - 1 ); 15const text = message ?. content . replace ( / \s+ / g , ' ' ). trim () || 'No messages yet' ; 16return text . length > 160 ?` ${ text . slice ( 0 , 157 ). trimEnd ()} …` :text ; 17}