Skip to content

A desktop coding agent with free access to frontier models.

TypeScript
1.0 KB
Raw Blame
import type { SearchableSession } from "@/react-app/domains/session/search/session-search";

/** Same titles as the shared home view (apps/server/src/workspace/home-view.mjs). */
export const HOME_RECENT_CHATS = 8;

export type HomeWorkspace = {
  id: string;
  name: string;
  /** A parallel task's own workspace: listed on its repository's task board, not here. */
  task: boolean;
};

/** A chat's title for lists (the engine's default "New session - <date>" reads "Untitled chat"). */
export function homeChatTitle(title: string | null | undefined): string {
  const text = String(title ?? "").replace(/\s+/g, " ").trim();
  if (!text || /^(new session|child session)\s*-\s*\d{4}-/i.test(text)) return "Untitled chat";
  return text.length > 72 ? `${text.slice(0, 69).trimEnd()}…` : text;
}

/** The newest chats across every workspace on this computer. */
export function recentChats(sessions: SearchableSession[], limit = HOME_RECENT_CHATS): SearchableSession[] {
  return [...sessions].sort((a, b) => b.updatedAt - a.updatedAt).slice(0, limit);
}