1import { ASSISTANT_CITATION_MAX_COMMENT_LENGTH } from "@t3tools/contracts";
2
3export type AssistantCitationCommentDismissal =
4 | { kind: "commit"; comment: string }
5 | { kind: "close" }
6 | { kind: "keep-open" };
7
8export function resolveAssistantCitationCommentDismissal({
9 reason,
10 draft,
11 savedComment,
12}: {
13 reason: string;
14 draft: string | null;
15 savedComment: string | undefined;
16}): AssistantCitationCommentDismissal {
17 if (reason === "escape-key" || draft === null) return { kind: "close" };
18 if (draft.trim() === (savedComment ?? "").trim()) return { kind: "close" };
19 if (draft.length > ASSISTANT_CITATION_MAX_COMMENT_LENGTH) return { kind: "keep-open" };
20 return { kind: "commit", comment: draft };
21}