Conversations page: pump, search, read the transcript; docs and the libredesk link

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-18 15:13:25 +01:00
1 parent 3544f29d85
commit 45db86d1ff
8 files changed
+127 -16

No files matched your search

+11 -2
View File
@@ -1,6 +1,6 @@
# The AIMsight web app
The tool of the manual diagnostic: two pages, **Data** and **Stations**.
The tool of the manual diagnostic: three pages, **Data**, **Stations** and **Conversations**.
## The Data page
@@ -46,12 +46,21 @@ cd app/web && npm install && npm run build # once, and after each change of
The page opens on `http://127.0.0.1:8770`. Settings by variables: `AIMSIGHT_DATA` (data, default `data/`), `AIMSIGHT_LABELS` (labels, default `labeling/`), `AIMSIGHT_PORT` (8770). To work on the page: `npm run dev` in `app/web/` (http://localhost:5173), the Python server launched next to it.
## The Conversations page
The LibreDesk conversations (`helpdesk.sensima.ch`), every inbox and status, private notes included, pumped **read-only** by `~/aimsight-libredesk` (link `libredesk/`, `conversations/pomper.sh` through `conversations/pompage.py`; the app only calls it, the read key stays in that repository's `.env`) into `labeling/auto/conversations/<reference>/`: `conversation.json`, `messages.json`, `attachments/`, and `transcript.md`, the readable thread.
- **Pump**: without dates, what changed since the last complete pumping (`pumped.json`; the first time, the whole history, at a quiet hour); with dates, the conversations updated in that range (To excluded). One at a time; the end of `out/conversations.log` of that repository read every 2 s. The commit of `auto/conversations/` in `~/aimsight-labeling` is the user's.
- **The list**: the pumped conversations, the most recent message first, searched on subject, contact and reference; a click shows the transcript.
- **What a client wrote is never run**: the transcript is escaped before Markdown, served with `Content-Security-Policy: default-src 'none'; img-src 'self'` (no script, no remote image or tracking pixel) in a sandboxed frame; a plain image (png, jpg, gif, webp) shows inline, any other attachment (an `.svg`, an `.html`) is downloaded.
## The folders
- `server/server.py`: FastAPI; serves the built page and the API under `/api` (stations, images, curves, detectors, labels, analyses, support); answers only the pages of the workstation (local Host, declared JSON).
- `server/server.py`: FastAPI; serves the built page and the API under `/api` (stations, images, curves, detectors, labels, analyses, support); answers only the pages of the workstation (local Host, declared JSON); the Conversations routes under `/api/conversations`.
- `server/station.py`: the data of the Data page; read-only on `data/` (through `tools/scripts/data.py`), writes only in `labeling/{auto,manual}/`.
- `server/analysis.py`: the Analysis tab; launches `claude` with the agent `agents:analyst` (Read, Write, Bash allowed without asking); and the optimization, `/optimize` in Optimizer (Read, Write, Edit, Bash, Agent).
- `server/support.py`: the Support tab; launches `claude` with the agent `agents:support` (Read, Write, Edit, Bash, Glob, Grep allowed without asking), through `analysis.run`.
- `server/conversations.py`: the Conversations page; calls `libredesk/conversations/pompage.py`, lists `labeling/auto/conversations/`, renders a transcript safely.
- `server/check.py`: checks, without calling claude: `.venv/bin/python app/server/check.py`.
- `web/`: React (Vite) and Mantine; `src/App.jsx` (header, sidebar, address), `src/pages/Data.jsx` (the page), `src/pages/Images.jsx` (the images, in Data), `src/common.jsx` (requests, selector), `src/main.jsx` (theme). Plotly, dressed in Mantine's colours, loads only with Data. `dist/` and `node_modules/` outside git.
+4 -2
View File
@@ -3,11 +3,12 @@ import {
ActionIcon, AppShell, Burger, ColorSwatch, Group, Loader, NavLink, ScrollArea, Text, Tooltip, useComputedColorScheme, useMantineColorScheme,
} from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import { IconChartLine, IconCircleCheck, IconCircleDashed, IconFolder, IconMoon, IconSatellite, IconSun } from "@tabler/icons-react";
import { IconChartLine, IconCircleCheck, IconCircleDashed, IconFolder, IconMessages, IconMoon, IconSatellite, IconSun } from "@tabler/icons-react";
const Data = lazy(() => import("./pages/Data.jsx")); // Plotly, loaded only here
const Stations = lazy(() => import("./pages/Stations.jsx"));
const PAGES = [["data", "Data", IconChartLine], ["stations", "Stations", IconSatellite]];
const Conversations = lazy(() => import("./pages/Conversations.jsx"));
const PAGES = [["data", "Data", IconChartLine], ["stations", "Stations", IconSatellite], ["conversations", "Conversations", IconMessages]];
// The address: #/<page>?station=…&start=…&end=…; reloading keeps the page and the selection, Back works; without dates, the
// last 5 UTC days, today included (end excluded: tomorrow)
@@ -142,6 +143,7 @@ export default function App() {
<AppShell.Main bg="var(--mantine-color-default-hover)">
<Suspense fallback={<Loader m="xl" />}>
{page === "stations" ? <Stations selection={selection} />
: page === "conversations" ? <Conversations />
: <Data selection={selection} choose={choose} analysis={analysis} setAnalysis={setAnalysis}
support={support} setSupport={setSupport} />}
</Suspense>
+9 -1
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { Button, Card, Group, Select, TextInput } from "@mantine/core";
import { notifications } from "@mantine/notifications";
@@ -34,3 +34,11 @@ export function Selector({ selection, choose }) {
</Card>
);
}
// A markdown rendered by the server (report, summary, transcript), at the height of its content once its images are loaded;
// sandboxed: no script runs in it
export function Page({ title, src }) {
const frame = useRef();
const fit = () => { const b = frame.current?.contentDocument?.body; if (b) frame.current.style.height = `${b.scrollHeight + 20}px`; };
return <iframe ref={frame} title={title} sandbox="allow-same-origin" onLoad={fit} style={{ border: 0, width: "100%", height: 400 }} src={src} />;
}
+85
View File
@@ -0,0 +1,85 @@
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 (
<Stack gap="lg" maw={1200}>
<div>
<Title order={2}>Conversations</Title>
<Text c="dimmed">The LibreDesk conversations, pumped read-only into labeling/auto/conversations/: the thread, its images and
attachments, for the support and as training data.</Text>
</div>
<Card shadow="sm" withBorder>
<Stack gap="md">
<Group align="flex-end" gap="md">
<TextInput label="Updated from (UTC)" type="date" value={range.start} onChange={e => setRange({ ...range, start: e.currentTarget.value })} />
<TextInput label="To (excluded)" type="date" value={range.end} onChange={e => setRange({ ...range, end: e.currentTarget.value })} />
<Button onClick={pump} loading={!!state?.running}>Pump</Button>
</Group>
<Text size="xs" c="dimmed">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.</Text>
{state?.log?.length > 0 && (
<ScrollArea h={200} viewportRef={v => v && (v.scrollTop = v.scrollHeight)}>
<Code block>{state.log.join("\n")}</Code>
</ScrollArea>
)}
</Stack>
</Card>
<Card shadow="sm" withBorder>
<Stack gap="md">
<TextInput placeholder="Search: subject, contact, reference" leftSection={<IconSearch size={16} />} value={search}
onChange={e => setSearch(e.currentTarget.value)} maw={400} />
{list.length ? (
<ScrollArea.Autosize mah={400}>
<Table highlightOnHover verticalSpacing={4} stickyHeader>
<Table.Thead><Table.Tr><Table.Th>Ref.</Table.Th><Table.Th>Subject</Table.Th><Table.Th>Contact</Table.Th>
<Table.Th>Status</Table.Th><Table.Th>Last message (UTC)</Table.Th><Table.Th>Messages</Table.Th><Table.Th>Attachments</Table.Th></Table.Tr></Table.Thead>
<Table.Tbody>
{shown.map(c => (
<Table.Tr key={c.reference} onClick={() => setOpen(c.reference)} style={{ cursor: "pointer" }}
bg={open === c.reference ? "var(--mantine-primary-color-light)" : undefined}>
<Table.Td ff="monospace">{c.reference}</Table.Td><Table.Td>{c.subject}</Table.Td><Table.Td>{c.contact}</Table.Td>
<Table.Td>{c.status}</Table.Td><Table.Td ff="monospace">{when(c.last)}</Table.Td>
<Table.Td>{c.messages}</Table.Td><Table.Td>{c.attachments}</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
</ScrollArea.Autosize>
) : <Text c="dimmed" size="sm">No conversation pumped yet.</Text>}
</Stack>
</Card>
{open && (
<Card shadow="sm" withBorder>
<Page key={`${open}-${dark}`} title="Transcript" src={`/api/conversations/${encodeURIComponent(open)}/report.html?dark=${dark}`} />
</Card>
)}
</Stack>
);
}
+1 -7
View File
@@ -4,7 +4,7 @@ import {
useComputedColorScheme,
} from "@mantine/core";
import { IconPlus, IconX } from "@tabler/icons-react";
import { call, Selector } from "../common.jsx";
import { call, Page, Selector } from "../common.jsx";
import { StationImages } from "./Images.jsx";
// Data, the curve viewer and the labelling: one plot at the start, others to add or remove,
@@ -515,12 +515,6 @@ function Thread({ lines }) {
);
}
// A markdown rendered by the server (report, summary), at the height of its content once its images are loaded
function Page({ title, src }) {
const frame = useRef();
const fit = () => { const b = frame.current?.contentDocument?.body; if (b) frame.current.style.height = `${b.scrollHeight + 20}px`; };
return <iframe ref={frame} title={title} sandbox="allow-same-origin" onLoad={fit} style={{ border: 0, width: "100%", height: 400 }} src={src} />;
}
const STATE_COLOR = { running: "blue", done: "teal", error: "red", interrupted: "orange" };