The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
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);
});
}