Files
PaperClipAI/ui/src/lib/recent-assignees.ts
T
DottaandPaperclip 2c43b39167 refactor(ui): share task composer and project/worktree controls (#15091)
Use the shared composer for new tasks, including project and worktree selection, rich mentions and slash commands, and remembered task settings.

Save project preferences after successful task updates. Show known agent models by name and use Default for unknown runtime defaults.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-05 18:06:40 -05:00

60 lines
2.0 KiB
TypeScript

import {
RECENT_SELECTION_DISPLAY_LIMIT,
readRecentSelectionIds,
trackRecentSelectionId,
} from "./recent-selections";
const STORAGE_KEY = "paperclip:recent-assignees";
function agentSelectionId(agentId: string): string {
return `agent:${agentId}`;
}
function userSelectionId(userId: string): string {
return `user:${userId}`;
}
function agentIdFromSelectionId(id: string): string | null {
if (id.startsWith("agent:")) return id.slice("agent:".length);
if (!id.includes(":")) return id;
return null;
}
export function getRecentAssigneeIds(): string[] {
return readRecentSelectionIds(STORAGE_KEY)
.map(agentIdFromSelectionId)
.filter((id): id is string => Boolean(id));
}
export function getRecentAssigneeSelectionIds(companyId?: string): string[] {
return readRecentSelectionIds(companyId ? `${STORAGE_KEY}:${companyId}` : STORAGE_KEY).map((id) => {
if (id.includes(":")) return id;
return agentSelectionId(id);
});
}
export function trackRecentAssignee(agentId: string, companyId?: string): void {
trackRecentSelectionId(STORAGE_KEY, agentSelectionId(agentId));
if (companyId) trackRecentSelectionId(`${STORAGE_KEY}:${companyId}`, agentSelectionId(agentId));
}
export function trackRecentAssigneeUser(userId: string, companyId?: string): void {
trackRecentSelectionId(STORAGE_KEY, userSelectionId(userId));
if (companyId) trackRecentSelectionId(`${STORAGE_KEY}:${companyId}`, userSelectionId(userId));
}
export function sortAgentsByRecency<T extends { id: string; name: string }>(
agents: T[],
recentIds: string[],
): T[] {
const recentIndex = new Map(recentIds.slice(0, RECENT_SELECTION_DISPLAY_LIMIT).map((id, i) => [id, i]));
return [...agents].sort((a, b) => {
const aRecent = recentIndex.get(a.id);
const bRecent = recentIndex.get(b.id);
if (aRecent !== undefined && bRecent !== undefined) return aRecent - bRecent;
if (aRecent !== undefined) return -1;
if (bRecent !== undefined) return 1;
return a.name.localeCompare(b.name);
});
}