"use client"; import { Brain, FileText, MessageSquareText } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { EmptyState } from "@/components/shared/empty-state"; import { CopyableId } from "@/components/shared/copyable-id"; import { formatScope } from "@/lib/memory"; import { useI18n } from "@/i18n/i18n-context"; import type { Locale } from "@/i18n/config"; import { formatDateTime } from "@/lib/format-datetime"; import type { MemoryFileSearchHit, SearchMemoryResponse } from "@/types/memory"; interface MemorySearchResultsProps { response: SearchMemoryResponse | null; elapsedMs?: number; scopeBlocked?: boolean; onChooseScope?: () => void; } function formatTimestamp( value: string | number | undefined, locale: Locale = "zh", ): string { return formatDateTime(value, locale, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", }); } export function MemorySearchResults({ response, elapsedMs, scopeBlocked = false, onChooseScope, }: MemorySearchResultsProps) { const { t, locale } = useI18n(); // `created_at` is the event time of the source message, not the write time — // surface the fallback rules on hover so the line isn't read as an insert // timestamp. const hintCreatedAt = t("memory.search.resultCreatedAtHint"); if (!response) { if (scopeBlocked) { return ( {t("memory.search.chooseScopeAction")} ) : undefined } /> ); } return ( ); } const results = response.results ?? []; const fileResults = response.fileResults ?? []; const evidence = response.evidence ?? []; if (!results.length && !fileResults.length && !evidence.length) { return ( ); } return (

{t("memory.search.resultsSummary", { memories: results.length, files: fileResults.length, evidence: evidence.length, })}

{elapsedMs !== undefined && ( {elapsedMs} ms )}
{results.length > 0 && ( } > {results.map((hit, index) => (
{hit.similarity !== undefined && ( {t("memory.search.similarity", { value: hit.similarity.toFixed(4), })} )} {hit.score !== undefined && ( {t("memory.search.relevance", { value: hit.score.toFixed(4), })} )} {hit.source && {hit.source}} {hit.rankingScore !== undefined && ( {t("memory.search.rankingScore", { value: hit.rankingScore.toFixed(4), })} )} {hit.rankingSignals?.sameSession !== undefined && ( {t("memory.search.rankingSignals", { session: hit.rankingSignals.sameSession ? t("memory.search.sameSession") : t("memory.search.otherSession"), weight: ( hit.rankingSignals.sessionAffinityWeight ?? 0 ).toFixed(4), })} )} {hit.unit.unit_type && ( {hit.unit.unit_type} )}

{hit.unit.text}

{t("memory.search.resultScope", { scope: formatScope(hit.unit.scope), })}
{t("memory.search.resultCreatedAt", { time: formatTimestamp( hit.unit.created_at ?? hit.unit.createdAt, locale, ), })} {t("memory.search.resultVersion", { version: hit.unit.version ?? "-", })}
))}
)} {fileResults.length > 0 && ( } > {fileResults.map((hit, index) => ( ))} )} {evidence.length > 0 && ( } > {evidence.map((hit, index) => (
{hit.score !== undefined && ( {t("memory.search.relevance", { value: hit.score.toFixed(4), })} )} {hit.similarity !== undefined && ( {t("memory.search.similarity", { value: hit.similarity.toFixed(4), })} )} {hit.source && {hit.source}}

{hit.unit.text}

{hit.unit.scope ? ( {t("memory.search.resultScope", { scope: formatScope(hit.unit.scope), })} ) : null} {hit.unit.created_at || hit.unit.createdAt ? ( {t("memory.search.resultCreatedAt", { time: formatTimestamp( hit.unit.created_at ?? hit.unit.createdAt, locale, ), })} ) : null}
))}
)}
); } function ResultSection({ title, icon, children, }: { title: string; icon: React.ReactNode; children: React.ReactNode; }) { return (

{icon} {title}

{children}
); } function FileResult({ hit }: { hit: MemoryFileSearchHit }) { const { t } = useI18n(); return (
{hit.type} {hit.similarity !== undefined && ( {t("memory.search.similarity", { value: hit.similarity.toFixed(4), })} )} {hit.score !== undefined && ( {t("memory.search.relevance", { value: hit.score.toFixed(4) })} )}

{hit.path}

{hit.summary && (

{hit.summary}

)}
{t("memory.search.fileVersion", { version: hit.versionId ?? "-" })}
); }