Conversations: pump LibreDesk through aimsight-libredesk, list and show the transcripts safely
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ca2f66ce3d
commit
3544f29d85
6 files changed
+449
-2
No files matched your search
+37
-1
@@ -2,7 +2,8 @@
|
||||
|
||||
The FastAPI server serves the built React page (app/web/dist, `npm run build` in app/web) and the API under /api.
|
||||
The Data page reads data/ and the labels of labeling/ (station.py); its Analysis tab launches the analyst, and the
|
||||
optimization of the detectors (analysis.py); its Support tab, the support (support.py).
|
||||
optimization of the detectors (analysis.py); its Support tab, the support (support.py). The Conversations page, the
|
||||
LibreDesk conversations pumped by ~/aimsight-libredesk (conversations.py).
|
||||
Settings: AIMSIGHT_DATA (data), AIMSIGHT_LABELS (labels), AIMSIGHT_PORT (port, 8770).
|
||||
"""
|
||||
import json
|
||||
@@ -19,6 +20,7 @@ from fastapi import FastAPI, Query, Request
|
||||
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
|
||||
|
||||
import analysis
|
||||
import conversations
|
||||
import station
|
||||
import support
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
@@ -200,6 +202,40 @@ def support_file(name: str, path: str):
|
||||
return FileResponse(analysis.file(name, path, support.FOLDER))
|
||||
|
||||
|
||||
# --- the Conversations page (conversations.py): the LibreDesk conversations, pumped read-only, and their transcripts
|
||||
|
||||
CSP = "default-src 'none'; img-src 'self'; style-src 'unsafe-inline'" # a client's mail: no script, no remote image
|
||||
|
||||
|
||||
@app.get("/api/conversations/pump")
|
||||
def conversations_pump_state():
|
||||
return conversations.pump_state()
|
||||
|
||||
|
||||
@app.post("/api/conversations/pump")
|
||||
def conversations_pump(body: dict):
|
||||
return conversations.pump(body)
|
||||
|
||||
|
||||
@app.get("/api/conversations")
|
||||
def conversations_list():
|
||||
return conversations.list_conversations()
|
||||
|
||||
|
||||
@app.get("/api/conversations/{reference}/report.html")
|
||||
def conversation_transcript(reference: str, dark: bool = False):
|
||||
return HTMLResponse(conversations.transcript(reference, dark), headers={"Content-Security-Policy": CSP})
|
||||
|
||||
|
||||
@app.get("/api/conversations/{reference}/{path:path}")
|
||||
def conversation_file(reference: str, path: str):
|
||||
"""A plain image inline; any other attachment (an .html, an .svg) as a download: it never runs at the app's address."""
|
||||
f = analysis.file(reference, path, conversations.FOLDER)
|
||||
headers = {"X-Content-Type-Options": "nosniff", "Content-Security-Policy": CSP}
|
||||
return FileResponse(f, headers=headers) if f.suffix.lower() in conversations.INLINE \
|
||||
else FileResponse(f, filename=f.name, headers=headers)
|
||||
|
||||
|
||||
if PAGE.is_dir():
|
||||
app.mount("/", StaticFiles(directory=PAGE, html=True), name="page")
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user