/** * 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" > ); } function NotesSkeleton() { return (
); } /** * 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 (
{note && hasBody && !editing ? (
(mentions ? meetingNotesForCopy(note.body, mentions) : note.body)} />
) : null} setEditing(true)} onDone={() => setEditing(false)} save={(body) => notes.save("notes", body)} refresh={notes.refresh} onOpenChat={onOpenChat} mentions={mentions} attribution={false} />
); } /** The Notepad tab: what people jot down, saved as they type. */ export function MeetingNotepad({ notes }: { notes: UseRecordingNotesResult }) { if (notes.loading && !notes.notepad) return ; return ( notes.save("notepad", body)} /> ); } const COPIED_MS = 1600; /** Copies the notes, then says Copied for a moment. */ function CopyNotesButton({ text }: { text: () => string }) { const msg = useOpenGeniText(); const [copied, setCopied] = useState(false); const timer = useRef | null>(null); useEffect( () => () => { if (timer.current) clearTimeout(timer.current); }, [], ); return ( ); } /** "Written by an agent · time · Open the chat", or "Edited · time". */ function NotesAttribution({ note, onOpenChat, }: { note: RecordingNote; onOpenChat?: ((sessionId: string) => void) | undefined; }) { const msg = useOpenGeniText(); const sessionId = note.updatedBy.sessionId; return (

{sessionId ? ( <>

); } function WrittenNotes({ note, editing, onEdit, onDone, save, refresh, onOpenChat, mentions, attribution = true, }: { note: RecordingNote | null; editing: boolean; onEdit: () => void; onDone: () => void; save: (body: string) => Promise; refresh: () => Promise; onOpenChat?: ((sessionId: string) => void) | undefined; mentions?: MeetingMentionResolver | null | undefined; /** Say who wrote them under the notes; the Summary tab says it in its header. */ attribution?: boolean; }) { const msg = useOpenGeniText(); const [draft, setDraft] = useState(note?.body ?? ""); const [saving, setSaving] = useState(false); const [changedMeanwhile, setChangedMeanwhile] = useState(false); const editorId = useId(); const renderLink = useMemo( // Without a resolver, mentions read as their link text, never a dead link. () => meetingMentionLinkRenderer(mentions ?? (() => null)), [mentions], ); useEffect(() => { // Start each edit from the notes as they are now. if (editing) { setDraft(note?.body ?? ""); setChangedMeanwhile(false); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [editing]); if (editing) { const submit = async () => { setSaving(true); try { await save(draft); onDone(); toast.success(msg("meetings.notes.saved")); } catch (error) { if (isNotesChanged(error)) { // Load theirs so a second Save replaces it knowingly. await refresh(); setChangedMeanwhile(true); } else { toast.error(msg("meetings.notes.couldNotSave"), { description: errorText(error) }); } } finally { setSaving(false); } }; return (