diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx index 276242b24f..114198e9a3 100644 --- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx +++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx @@ -37,16 +37,21 @@ type ContentGroup = | { type: "text"; block: TextBlock; index: number } | { type: "tool_calls"; blocks: ToolCallBlock[]; index: number }; +/** Extract domain + TLD from a hostname (e.g. "www.example.co.uk" → "example.co.uk"). */ +function extractDomain(hostname: string): string { + return hostname.replace(/^www\./, ""); +} + function getUniqueSiteCount(citations: LlmCitation[]): number { - const hosts = new Set(); + const domains = new Set(); for (const c of citations) { if (c.url) { try { - hosts.add(new URL(c.url).hostname); + domains.add(extractDomain(new URL(c.url).hostname)); } catch { /* ignore invalid URLs */ } } } - return hosts.size; + return domains.size; } function CitationsSection({ citations }: { citations: LlmCitation[] }) { @@ -65,10 +70,10 @@ function CitationsSection({ citations }: { citations: LlmCitation[] }) { {citations.map((citation, idx) => { const title = citation.title || citation.citedText?.slice(0, 80) || `Source ${idx + 1}`; - let hostname: string | null = null; + let domain: string | null = null; if (citation.url) { try { - hostname = new URL(citation.url).hostname; + domain = extractDomain(new URL(citation.url).hostname); } catch { /* ignore */ } } @@ -76,15 +81,15 @@ function CitationsSection({ citations }: { citations: LlmCitation[] }) { {citation.url ? ( - + {title} ) : ( {title} )} - {hostname && ( - {hostname} + {domain && ( + {domain} )} );