Skip to content
24 linesCodeBlameRaw
1/**
2 * The Archived section of the Agents page (docs.g1t.sh/guides/agents/,
3 * "Archive, restore and delete"): what each archived agent's row says
4 * about what deleting it would take. Pure, so it is tested on its own.
5 */
6import type { ArchivedAgent } from "@g1t/contracts";
7
8const COUNTED: [keyof ArchivedAgent["counts"], string, string][] = [
9 ["sessions", "session", "sessions"],
10 ["replies", "reply", "replies"],
11 ["memories", "memory", "memories"],
12 ["routines", "routine", "routines"],
13];
14
15/** "14 sessions · 231 replies · 3 memories": what is kept about the agent, zeros left out. */
16export function countsLine(counts: ArchivedAgent["counts"]): string {
17 const parts = COUNTED.filter(([key]) => counts[key] > 0).map(([key, one, many]) => `${counts[key].toLocaleString("en-US")} ${counts[key] === 1 ? one : many}`);
18 return parts.length ? parts.join(" · ") : "Nothing recorded";
19}
20
21/** Whether what was typed confirms deleting the agent: its handle, with or without the @, in any case. */
22export function confirmsHandle(typed: string, handle: string): boolean {
23 return typed.trim().replace(/^@/, "").toLowerCase() === handle.toLowerCase();
24}