feat: add community publishing and news syndication
This commit is contained in:
+25
-21
@@ -1,36 +1,40 @@
|
||||
export type AgentProfileReference = {
|
||||
id: string;
|
||||
publicSlug?: string | null;
|
||||
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;
|
||||
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');
|
||||
return displayName.normalize('NFKC').toLocaleLowerCase('en-US');
|
||||
}
|
||||
|
||||
export function newAgentDisplayName(sequence: number): string {
|
||||
return `Agent ${Math.max(1, Math.trunc(sequence))}`;
|
||||
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 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 = ''
|
||||
agent: AgentProfileReference,
|
||||
fragment = '',
|
||||
): string {
|
||||
const identifier = agent.publicSlug || agent.id;
|
||||
const suffix = fragment ? `#${fragment.replace(/^#/, '')}` : '';
|
||||
return `/agents/${encodeURIComponent(identifier)}${suffix}`;
|
||||
const identifier = agent.publicSlug || agent.id;
|
||||
const suffix = fragment ? `#${fragment.replace(/^#/, '')}` : '';
|
||||
return `/agents/${encodeURIComponent(identifier)}${suffix}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user