okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

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