SurfSense/surfsense_web/lib/chat/mention-doc-key.ts
CREDO23 1f6934b980 feat(chat): extend composer mention model for thread references
Add the "thread" mention kind (makeThreadMention + stable dedup key) so a
chat can be referenced like a document. Also introduce submittedMentionsAtom
and a pure deriveMentionedPayload() helper, the building blocks for capturing
chips at submit time and mapping them to backend payload buckets.
2026-06-23 18:30:22 +02:00

21 lines
746 B
TypeScript

type MentionKeyInput = {
id: number;
document_type?: string | null;
connector_type?: string | null;
kind?: "doc" | "folder" | "connector" | "thread";
};
/**
* Build a stable dedup key for a mention chip.
*
* Each mention kind keys off its real identity fields:
* docs by document type, folders by folder id, connectors by
* connector type + account id, and threads by thread id.
*/
export function getMentionDocKey(doc: MentionKeyInput): string {
const kind = doc.kind ?? "doc";
if (kind === "folder") return `folder:${doc.id}`;
if (kind === "thread") return `thread:${doc.id}`;
if (kind === "connector") return `connector:${doc.connector_type ?? "UNKNOWN"}:${doc.id}`;
return `doc:${doc.document_type ?? "UNKNOWN"}:${doc.id}`;
}