/**
* A meeting's notes: the written-up notes (summary, decisions, action items)
* shown as Markdown with Edit, and the notepad people jot into while the
* meeting is recorded, which saves as they type.
*
* The meeting page shows them as its Summary and Notepad tabs. While the
* meeting is being recorded here they share one Notes section, notepad
* first. Notes an agent wrote say so and link to its chat; mentions of
* speakers and people show as chips (see ./meeting-mentions).
*/
import { useOpenGeniText } from "../messages/runtime";
import { useEffect, useId, useMemo, useRef, useState, type ComponentProps } from "react";
import { BotIcon, CheckIcon, CopyIcon, LoaderCircleIcon, PencilIcon } from "lucide-react";
import { toast } from "sonner";
import { userErrorText } from "../ui/api-error";
import type { RecordingNote } from "@opengeni/contracts";
import { OpenGeniApiError } from "@opengeni/sdk";
import { Markdown } from "../components/markdown";
import {
useRecordingNotes,
type RecordingsClientOverride,
type UseRecordingNotesResult,
} from "../recordings";
import { copyTextToClipboard } from "../lib/clipboard";
import { Button } from "../ui/button";
import { DetailSection } from "../ui/detail-sheet";
import { TextArea } from "../ui/field";
import { Notice } from "../ui/notice";
import { formatAbsoluteTime } from "../ui/relative-time";
import { Skeleton } from "../ui/skeleton";
import { MeetingsOverlayScope } from "./overlay-scope";
import {
meetingMentionLinkRenderer,
meetingNotesForCopy,
type MeetingMentionResolver,
} from "./meeting-mentions";
/** How long typing pauses before the notepad saves. */
export const NOTEPAD_SAVE_DELAY_MS = 800;
function isNotesChanged(error: unknown): boolean {
return (
error instanceof OpenGeniApiError &&
error.status === 409 &&
error.details?.code === "notes_changed"
);
}
function errorText(error: unknown): string | undefined {
return error instanceof Error ? userErrorText(error) : undefined;
}
function MeetingNotesContent({
recordingId,
recording: override,
capturing,
onOpenChat,
}: {
recordingId: string;
recording: RecordingsClientOverride;
/** The meeting is being recorded now, so the notepad comes first. */
capturing: boolean;
/** Opens the chat whose agent wrote the notes. */
onOpenChat?: ((sessionId: string) => void) | undefined;
}) {
const notes = useRecordingNotes(recordingId, override);
return ;
}
/** The Notes section over notes the page already loads: notepad and written notes together. */
export function MeetingNotesSection({
notes,
capturing,
onOpenChat,
mentions,
}: {
notes: UseRecordingNotesResult;
/** The meeting is being recorded now, so the notepad comes first. */
capturing: boolean;
onOpenChat?: ((sessionId: string) => void) | undefined;
/** Resolves speaker and person mentions in the written notes. */
mentions?: MeetingMentionResolver | null | undefined;
}) {
const msg = useOpenGeniText();
const [editing, setEditing] = useState(false);
if (notes.loading && !notes.notes && !notes.notepad) {
return (
);
}
const written = (
setEditing(true)}
onDone={() => setEditing(false)}
save={(body) => notes.save("notes", body)}
refresh={notes.refresh}
onOpenChat={onOpenChat}
mentions={mentions}
/>
);
const notepad = (
notes.save("notepad", body)}
/>
);
return (
setEditing(true)}
className="pointer-coarse:h-11"
>
{msg("meetings.notes.edit")}
) : undefined
}
>
);
}
/**
* The Summary tab: the written notes as Markdown, who wrote them, Copy and
* Edit. Mentions of speakers and people show as chips with current names.
*/
export function MeetingSummary({
notes,
onOpenChat,
mentions,
}: {
notes: UseRecordingNotesResult;
onOpenChat?: ((sessionId: string) => void) | undefined;
mentions: MeetingMentionResolver | null;
}) {
const msg = useOpenGeniText();
const [editing, setEditing] = useState(false);
// A reload (such as after the window was hidden) never replaces an edit.
if (notes.loading && !notes.notes && !editing) return ;
const note = notes.notes;
const hasBody = Boolean(note?.body.trim());
return (