API: the support page becomes a web app, React with Mantine and FastAPI (D-137)
Same features as the local page; agents, tools, prompts and knowledge unchanged. - API/web/: React (Vite) with Mantine components: collapsible sidebar, mobile drawer, cards, notifications, dark mode - API/support/serveur.py: FastAPI serves the built page and /api; agent events pushed by server-sent events (/api/flux) instead of polling - data, cases folder and port set by AIMSIGHT_DATA, AIMSIGHT_CASES, AIMSIGHT_PORT - check.py: server check (host guard, analyse, stream, PDF) with a fake client - old page.html removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb10a6b735
commit
b0245c4067
17 files changed
+1666
-263
No files matched your search
+57
-1
@@ -262,7 +262,63 @@ def check_stations_dans_la_seance():
|
||||
assert "stations" in AVEC_SORTIE
|
||||
|
||||
|
||||
CHECKS = [check_lire_document, check_cartes, check_stabilite, check_image_proche, check_max_tokens, check_sans_repli, check_capture_reduite, check_stations_dans_la_seance, check_boucle, check_erreur, check_cout, check_source, check_outil_qui_leve, check_lecture_refusee,
|
||||
def check_serveur():
|
||||
# le vrai serveur sur un port libre, une séance au faux client : la garde, l'analyse, le flux, le PDF absent
|
||||
import json
|
||||
import shutil
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
import urllib.request
|
||||
from urllib.error import HTTPError
|
||||
import uvicorn
|
||||
import seance
|
||||
import serveur
|
||||
with socket.socket() as so:
|
||||
so.bind(("127.0.0.1", 0))
|
||||
port = so.getsockname()[1]
|
||||
cases = seance.CASES
|
||||
seance.CASES, serveur.CLIENT = seance_temporaire(), FauxClient(reponse([Bloc(type="text", text="Bonjour Marc")], "end_turn"))
|
||||
srv = uvicorn.Server(uvicorn.Config(serveur.app, host="127.0.0.1", port=port, log_level="error"))
|
||||
threading.Thread(target=srv.run, daemon=True).start()
|
||||
while not srv.started:
|
||||
time.sleep(0.05)
|
||||
base = f"http://127.0.0.1:{port}"
|
||||
|
||||
def appel(chemin, corps=None, entetes=None):
|
||||
r = urllib.request.Request(base + chemin, json.dumps(corps).encode() if corps is not None else None,
|
||||
{"Content-Type": "application/json", **(entetes or {})})
|
||||
try:
|
||||
with urllib.request.urlopen(r) as rep:
|
||||
return rep.status
|
||||
except HTTPError as e:
|
||||
return e.code
|
||||
try:
|
||||
assert appel("/api/pdf", entetes={"Host": "evil.example:80"}) == 403
|
||||
assert appel("/api/analyser", {"mail": "x"}, {"Content-Type": "text/plain"}) == 403
|
||||
assert appel("/api/analyser", {"mail": " "}) == 400
|
||||
assert appel("/api/analyser", {"mail": "Bonjour", "contexte": "", "images": []}) == 200
|
||||
with urllib.request.urlopen(base + "/api/flux", timeout=10) as f:
|
||||
premier, textes = None, []
|
||||
for ligne in f:
|
||||
if ligne.startswith(b"data: "):
|
||||
m = json.loads(ligne[6:])
|
||||
premier = premier or m
|
||||
textes += [e["texte"] for e in m["evenements"]]
|
||||
if "Bonjour Marc" in textes and not m["occupe"]["support"]:
|
||||
break
|
||||
assert premier["depuis"] == 0 and premier["id"], premier
|
||||
assert appel("/api/pdf") == 404
|
||||
(serveur.etat["seance"].dossier / "v1.pdf").write_bytes(b"%PDF-1.4")
|
||||
with urllib.request.urlopen(base + "/api/pdf") as rep:
|
||||
assert rep.read() == b"%PDF-1.4" and rep.headers["Content-Disposition"].startswith("inline"), rep.headers
|
||||
finally:
|
||||
srv.should_exit = True
|
||||
shutil.rmtree(seance.CASES)
|
||||
seance.CASES = cases
|
||||
|
||||
|
||||
CHECKS = [check_serveur, check_lire_document, check_cartes, check_stabilite, check_image_proche, check_max_tokens, check_sans_repli, check_capture_reduite, check_stations_dans_la_seance, check_boucle, check_erreur, check_cout, check_source, check_outil_qui_leve, check_lecture_refusee,
|
||||
check_chemin, check_station_absente, check_detecteurs, check_plafond, check_image, check_compiler]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user