8.6 KiB
8.6 KiB
The Conversations tab: pumping the LibreDesk conversations
2026-11-18. Two repositories: ~/aimsight-libredesk (the pumping) and aimsight-app (the tab).
Intent
The client requests arrive by mail in LibreDesk (helpdesk.sensima.ch, v2.9.0). The user wants their conversations on the workstation, in full (the messages, the inline images, the attachments), for two uses: to help the support (a conversation read next to the station's data, the analyses and the support answers), and as training data. Nothing is ever written to LibreDesk.
Goals, non-goals, anti-goals
- Goals: a Conversations page in the app that pumps the conversations on demand and shows them; each conversation stored in
labeling/auto/conversations/<reference>/, committed in~/aimsight-labelinglike the analyses and the support answers; the second pumping fetches only what changed. - Non-goals (for now): linking a conversation to its stations (later:
acces/of~/aimsight-libredeskmaps a contact's e-mail to its serials); teaching the support agent to readlabeling/auto/conversations/(agents/agents/support.md, a later change in~/aimsight-agents); turning the conversations into a training set (a later step; the raw material comes first); a scheduled pumping. - Anti-goals: any request to LibreDesk other than a
GET; the API key passing through the app or read by Claude; the HTML of a client's mail rendered as HTML in the page (a mail can carry scripts or tracking pixels).
Constraints
- Read-only on LibreDesk, enforced by a guard test in
~/aimsight-libredesk, liketests/test_garde_fou_snippets.pyfor the snippets. - The key: a dedicated LibreDesk agent "Lecture conversations" whose role has only
conversations:read_allandmessages:read, created by the user; its key and secret in~/aimsight-libredesk/.env(LIBREDESK_API_KEY,LIBREDESK_API_SECRET), never read by Claude. TheAuthorization: token <key>:<secret>header goes only to the LibreDesk host (add_unredirected_header, as insnippets/envoyer.py). - Standard library only in
~/aimsight-libredesk(its rule); its code and docs in French (its language); the app in English. - The app holds no domain logic: it calls the pumping of
~/aimsight-libredeskas it callsextraction/pumping.pyof~/aimsight-data. - Every conversation, by the user's decision: all the inboxes, all the statuses, no filter.
- Committed in git, by the user's decision: the contacts' names and e-mails, and the attachments, go into the history of
~/aimsight-labeling. - Every time in UTC.
Approaches
- A. The pumping in
~/aimsight-libredesk, called by the app (chosen): all the LibreDesk code in one repository, the key never in the app, the guard test next to the existing one. Costs: two repositories touched, one more link in the app. - B. Everything in the app (
app/server/conversations.py): shorter, one repository; but the app would carry LibreDesk's logic and the API key, which the rule of the repository forbids. - Dropped: a
claudeagent that pumps: too heavy for a download.
The design
~/aimsight-libredesk/conversations/ (French)
pomper.py: the client restricted to three routes, allGET:/api/v1/conversations/all(page,page_sizeup to 500,order_by=updated_at,order=desc),/api/v1/conversations/{uuid}/messages(every page, private notes included), and the attachment URLs that the messages carry (attachments[].url, signed:/uploads/{uuid}?…on LibreDesk, or a bucket's host if production stores in S3), downloaded wherever they point, theAuthorizationheader only to the LibreDesk host; never a URL found in a message's text.python3 -m conversations.pomper [--depuis YYYY-MM-DD --jusqu-a YYYY-MM-DD] --sortie <folder>.- Incremental by default:
<sortie>/pumped.json({"until": <UTC time>}, committed with the conversations) holds the start time of the last pumping that completed; a run walks the list from the most recently updated and stops below that mark (minus an hour of margin), and writes the new mark only at its end: a run cut short is caught up by the next one. No mark: the whole history. With--depuis/--jusqu-a, the conversations updated in that range (--jusqu-aexcluded), stored ones fetched again; the mark untouched. (Builder's call.) - A conversation is fetched in full each time it changed:
conversation.jsonandmessages.jsonrewritten, attachments already present not downloaded again (same name and size).
- Incremental by default:
pomper.sh: loads.env(set -a, asextraction/pump.sh), one pumping at a time (flockonout/conversations.lock), output appended toout/conversations.log.pompage.py: what the app calls, the twin ofextraction/pumping.py:start(depuis, jusqu_a, sortie)→ the process,running(),log(lines).- Tests (
tests/,unittest, the fake servertests/faux_libredesk.pyextended): onlyGET, the key never sent to another host, the incremental stop, the transcript (below), an attachment re-download skipped.
One conversation: labeling/auto/conversations/<reference_number>/
conversation.json: the conversation as the API gives it (subject, status, contact, inbox, dates, tags),previous_conversationsremoved.messages.json: the messages as the API gives them, the oldest first, attachment URLs replaced by their local path (attachments/<name>; a signed URL expires).attachments/: the files, under their name (a duplicate name prefixed by the attachment's uuid).transcript.md: the readable thread, written frommessages.json: per message, a heading## <UTC time> — <author> (<client | agent | private note>), the text (text_content, or the HTML reduced to text: tags removed, entities decoded, paragraphs kept), the images as, the other attachments as links. Theactivitymessages (assignments, status changes) on one line in italics. No raw HTML in it.
The app: the Conversations page
- A link
libredesk/→~/aimsight-libredesk(ignored by git, in the README's table and install line, and inCLAUDE.md's links). app/server/conversations.py: importspompage(asstation.pyimportspumping);pump(body)(optional From/To),pump_state()(running,log),list()(each folder oflabeling/auto/conversations/: reference, subject, contact name, status, last message time, message and attachment counts, read fromconversation.json/messages.json),transcript(reference, dark)(transcript.mdHTML-escaped before Markdown, so a client's<script>stays text; the page sent withContent-Security-Policy: default-src 'none'; img-src 'self'; style-src 'unsafe-inline': no script, no remote image or tracking pixel), and the files of the folder throughanalysis.file(…, FOLDER), images inline, any other attachment as a download (Content-Disposition: attachment: an.htmlor.svgattachment never runs at the app's address). The frame of the transcript sandboxed. (Builder's call: the protection in the app,transcript.mdstays plain readable text for the agents and the training.)server.py:GET/POST /api/conversations/pump,GET /api/conversations,GET /api/conversations/{reference}/report.html,GET /api/conversations/{reference}/{path}.web/src/pages/Conversations.jsx, a page of the header next to Data and Stations: a card "Pump" (From/To optional, empty: what changed since the last pumping; the button; the end of the log read every 2 s), a table of the pumped conversations (the most recent first, a search field on subject and contact), a click shows its transcript in a frame, as the report of an analysis.check.py: the list and the transcript on a temporary folder, without LibreDesk.- Docs:
app/README.md(the page),README.md(the link, the tab),docs/architecture.drawio(the arrow app → aimsight-libredesk → labeling);~/aimsight-libredesk/README.md(the pumping, the key's role).
Left to the builder
- The exact fields of an attachment in v2.9.0 (
name,content_type,size,url,content_idexpected): confirm on the first real response; the fake server follows it. - Whether
updated_atmoves on a new message; if not, comparelast_message_atas well. - The commit in
~/aimsight-labelingafter a pumping: by the user, by path (auto/conversations/), not by the app. - The order of the work: everything against the fake server first; then the user creates the read-only agent and puts its key in
.env; then a first real pumping on a short range (Claude may launch it: the key stays in the subprocess), which settles the two points above; the whole history after, at a quiet hour. Nothing committed in~/aimsight-labelingbefore the user has looked at that first range.