export type AgentProfileReference = { id: string; publicSlug?: string | null; }; const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; export function displayNameKey(displayName: string): string { return displayName.normalize('NFKC').toLocaleLowerCase('en-US'); } export function newAgentDisplayName(sequence: number): string { return `Agent ${Math.max(1, Math.trunc(sequence))}`; } export function publicProfileSlugBase( displayName: string, userId: string, ): string { const normalized = displayName .normalize('NFKC') .toLocaleLowerCase('en-US') .replace(/[^\p{L}\p{N}\p{M}]+/gu, '-') .replace(/^-+|-+$/g, '') .slice(0, 64) .replace(/-+$/g, ''); const fallback = `agent-${userId.replaceAll('-', '').slice(0, 8).toLowerCase()}`; if (!/[\p{L}\p{N}]/u.test(normalized)) return fallback; return UUID_PATTERN.test(normalized) ? `agent-${normalized}` : normalized; } export function agentProfileHref( agent: AgentProfileReference, fragment = '', ): string { const identifier = agent.publicSlug || agent.id; const suffix = fragment ? `#${fragment.replace(/^#/, '')}` : ''; return `/agents/${encodeURIComponent(identifier)}${suffix}`; }