import { useEffect, useRef, useState } from "react"; import { Button, Card, Code, Group, ScrollArea, Stack, Table, Text, TextInput, Title, useComputedColorScheme } from "@mantine/core"; import { IconSearch } from "@tabler/icons-react"; import { call, Page } from "../common.jsx"; const when = t => (t ? t.slice(0, 16).replace("T", " ") : ""); // The LibreDesk conversations, pumped read-only by ~/aimsight-libredesk into labeling/auto/conversations/: a pumping (a range // of updates, or without dates what changed since the last one), its log read every 2 s; the pumped conversations, searched // on subject, contact and reference; a click shows the transcript (images inline, the client's text never run) export default function Conversations() { const [range, setRange] = useState({ start: "", end: "" }), [state, setState] = useState(null); const [list, setList] = useState([]), [search, setSearch] = useState(""), [open, setOpen] = useState(null); const dark = useComputedColorScheme("light") === "dark", wasRunning = useRef(false); const read = () => call("/api/conversations").then(l => l && setList(l)); useEffect(() => { read(); }, []); useEffect(() => { const poll = () => fetch("/api/conversations/pump").then(r => r.ok && r.json()).then(p => { if (!p) return; if (wasRunning.current && !p.running) read(); // a pumping ended: the list again wasRunning.current = p.running; setState(p); }).catch(() => {}); // silently: every 2 s poll(); const timer = setInterval(poll, 2000); return () => clearInterval(timer); }, []); const pump = () => call("/api/conversations/pump", "POST", range).then(p => { if (p) { wasRunning.current = p.running; setState(p); } }); const q = search.trim().toLowerCase(); const shown = list.filter(c => !q || [c.subject, c.contact, c.reference].some(x => x.toLowerCase().includes(q))); return (
Conversations The LibreDesk conversations, pumped read-only into labeling/auto/conversations/: the thread, its images and attachments, for the support and as training data.
setRange({ ...range, start: e.currentTarget.value })} /> setRange({ ...range, end: e.currentTarget.value })} /> Without dates: what changed since the last pumping; the first time, the whole history (a quiet hour). The key stays in ~/aimsight-libredesk/.env; nothing is ever written to LibreDesk. {state?.log?.length > 0 && ( v && (v.scrollTop = v.scrollHeight)}> {state.log.join("\n")} )} } value={search} onChange={e => setSearch(e.currentTarget.value)} maw={400} /> {list.length ? ( Ref.SubjectContact StatusLast message (UTC)MessagesAttachments {shown.map(c => ( setOpen(c.reference)} style={{ cursor: "pointer" }} bg={open === c.reference ? "var(--mantine-primary-color-light)" : undefined}> {c.reference}{c.subject}{c.contact} {c.status}{when(c.last)} {c.messages}{c.attachments} ))}
) : No conversation pumped yet.}
{open && ( )}
); }