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
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Support AIMsight</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div id="racine"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+1186
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "support-aimsight",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mantine/core": "^9.7.5",
|
||||
"@mantine/hooks": "^9.7.5",
|
||||
"@mantine/notifications": "^9.7.5",
|
||||
"@tabler/icons-react": "^3.50.0",
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-react": "^6.2.1",
|
||||
"vite": "^8.3.6"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
ActionIcon, AppShell, Badge, Burger, Button, Card, Grid, Group, Image, NavLink, Paper, ScrollArea, SimpleGrid,
|
||||
Stack, Text, Textarea, Title, Tooltip, useComputedColorScheme, useMantineColorScheme,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
import { IconDownload, IconFilePlus, IconMoon, IconSend, IconSun } from "@tabler/icons-react";
|
||||
|
||||
const AGENTS = ["support", "analyste"];
|
||||
const NOMS = { support: "Support", analyste: "Analyste" };
|
||||
|
||||
async function poster(chemin, corps) {
|
||||
const r = await fetch(chemin, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(corps) });
|
||||
if (!r.ok) notifications.show({ color: "red", title: "Refusé", message: (await r.json()).erreur });
|
||||
return r.ok;
|
||||
}
|
||||
|
||||
// Un événement d'un agent → ce que montre son fil
|
||||
function message(e) {
|
||||
if (e.type === "outil") return { genre: "outil", texte: "→ " + e.texte };
|
||||
if (e.type === "erreur") return { genre: "erreur", texte: e.texte };
|
||||
if (e.type === "entree") {
|
||||
if (e.source === "marc") return { genre: "marc", qui: "Toi", texte: e.texte.replace(/^<mail>\n?|\n?<\/mail>[\s\S]*$/g, "") };
|
||||
return { genre: "relai", qui: "Demande du support", texte: e.texte };
|
||||
}
|
||||
return { genre: e.agent, qui: NOMS[e.agent], texte: e.texte };
|
||||
}
|
||||
|
||||
function Etat({ occupe }) {
|
||||
return <Badge variant="light" color={occupe ? "orange" : "teal"}>{occupe ? "occupé…" : "prêt"}</Badge>;
|
||||
}
|
||||
|
||||
function Entete({ dossier, mobile, bureau, basculer }) {
|
||||
const { setColorScheme } = useMantineColorScheme(), schema = useComputedColorScheme("light");
|
||||
return (
|
||||
<AppShell.Header className="entete">
|
||||
<Group h="100%" px="md" justify="space-between" wrap="nowrap">
|
||||
<Group gap="sm" wrap="nowrap">
|
||||
<Burger opened={mobile} onClick={basculer.mobile} hiddenFrom="sm" size="sm" color="white" aria-label="Menu" />
|
||||
<Burger opened={bureau} onClick={basculer.bureau} visibleFrom="sm" size="sm" color="white" aria-label="Barre latérale" />
|
||||
<Text fw={700} size="lg">AIMsight</Text>
|
||||
<Text size="sm" opacity={0.6}>Support</Text>
|
||||
</Group>
|
||||
<Group gap="sm" wrap="nowrap">
|
||||
{dossier && <Text ff="monospace" size="sm" opacity={0.75} visibleFrom="sm">{dossier}</Text>}
|
||||
<Tooltip label={schema === "dark" ? "Mode clair" : "Mode sombre"}>
|
||||
<ActionIcon variant="subtle" color="white" size="lg" aria-label="Changer de thème"
|
||||
onClick={() => setColorScheme(schema === "dark" ? "light" : "dark")}>
|
||||
{schema === "dark" ? <IconSun size={20} /> : <IconMoon size={20} />}
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
</Group>
|
||||
</AppShell.Header>
|
||||
);
|
||||
}
|
||||
|
||||
function Barre({ etat }) {
|
||||
const c = etat.cout, dollars = v => `${(v ?? 0).toFixed(2)} $`;
|
||||
return (
|
||||
<AppShell.Navbar p="xs">
|
||||
<ScrollArea type="scroll">
|
||||
<Text size="xs" fw={700} tt="uppercase" c="dimmed" px="sm" pt="sm" pb="xs">Séance</Text>
|
||||
<NavLink active label="Nouvelle séance" leftSection={<IconFilePlus size={18} />} />
|
||||
{AGENTS.map(a => <NavLink key={a} label={NOMS[a]} rightSection={<Etat occupe={etat.occupe[a]} />} />)}
|
||||
<Text size="xs" fw={700} tt="uppercase" c="dimmed" px="sm" pt="lg" pb="xs">Coût</Text>
|
||||
{AGENTS.map(a => <NavLink key={a} label={NOMS[a]} rightSection={<Text size="sm">{dollars(c?.[a])}</Text>} />)}
|
||||
<NavLink label={<b>Total</b>} rightSection={<Text size="sm" fw={700}>{dollars(c?.total)}</Text>} />
|
||||
</ScrollArea>
|
||||
</AppShell.Navbar>
|
||||
);
|
||||
}
|
||||
|
||||
function Carte({ surtitre, titre, action, children, ...reste }) {
|
||||
return (
|
||||
<Card shadow="sm" padding={0} withBorder {...reste}>
|
||||
<Group px="lg" py="md" justify="space-between" wrap="nowrap" style={{ borderBottom: "1px solid var(--mantine-color-default-border)" }}>
|
||||
<div>
|
||||
<Text size="xs" fw={700} tt="uppercase" c="dimmed">{surtitre}</Text>
|
||||
<Text fw={500}>{titre}</Text>
|
||||
</div>
|
||||
{action}
|
||||
</Group>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function Saisie({ occupe }) {
|
||||
const [mail, setMail] = useState(""), [contexte, setContexte] = useState(""), [images, setImages] = useState([]);
|
||||
|
||||
function coller(ev) {
|
||||
for (const item of ev.clipboardData.items) {
|
||||
if (!item.type.startsWith("image/")) continue;
|
||||
const lecteur = new FileReader();
|
||||
lecteur.onload = () => setImages(im => [...im, { type: item.type, url: lecteur.result, base64: lecteur.result.split(",")[1] }]);
|
||||
lecteur.readAsDataURL(item.getAsFile());
|
||||
}
|
||||
}
|
||||
|
||||
async function analyser() {
|
||||
if (!mail.trim()) return notifications.show({ color: "orange", message: "Colle d'abord le mail du client." });
|
||||
const envoi = images.map(({ type, base64 }, i) => ({ nom: `capture-${i + 1}`, type, base64 }));
|
||||
if (await poster("/api/analyser", { mail, contexte, images: envoi })) setImages([]); // pas de captures d'un client à l'autre
|
||||
}
|
||||
|
||||
return (
|
||||
<Carte surtitre="Demande" titre="Le mail du client" action={<Button onClick={analyser} disabled={occupe}>Analyser</Button>}>
|
||||
<Grid p="lg" gutter="lg">
|
||||
<Grid.Col span={{ base: 12, md: 8 }}>
|
||||
<Textarea label="Mail du client" description="Le texte ; colle les captures ici, elles s'ajoutent en vignettes"
|
||||
placeholder="Bonjour, …" autosize minRows={6} maxRows={16} value={mail}
|
||||
onChange={e => setMail(e.currentTarget.value)} onPaste={coller} />
|
||||
{images.length > 0 && (
|
||||
<Group gap="xs" mt="xs">{images.map((im, i) => <Image key={i} src={im.url} h={52} w="auto" radius="sm" alt={`Capture ${i + 1}`} />)}</Group>
|
||||
)}
|
||||
</Grid.Col>
|
||||
<Grid.Col span={{ base: 12, md: 4 }}>
|
||||
<Textarea label="Ton contexte" description="Station, plage, ce que tu sais du cas" autosize minRows={6} maxRows={16}
|
||||
value={contexte} onChange={e => setContexte(e.currentTarget.value)} />
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Carte>
|
||||
);
|
||||
}
|
||||
|
||||
function Fil({ agent, evenements, occupe, seance }) {
|
||||
const [texte, setTexte] = useState(""), vue = useRef(null);
|
||||
useEffect(() => { vue.current?.scrollTo({ top: vue.current.scrollHeight, behavior: "smooth" }); }, [evenements.length]);
|
||||
|
||||
async function envoyer() {
|
||||
if (texte.trim() && await poster("/api/message", { agent, texte })) setTexte("");
|
||||
}
|
||||
|
||||
return (
|
||||
<Carte surtitre={agent === "support" ? "Pilote la séance" : "Diagnostic"} titre={NOMS[agent]} action={<Etat occupe={occupe} />}
|
||||
h="62vh" style={{ display: "flex", flexDirection: "column" }}>
|
||||
<ScrollArea flex={1} viewportRef={vue} type="scroll">
|
||||
<Stack gap="xs" p="lg">
|
||||
{evenements.map((e, i) => {
|
||||
const m = message(e);
|
||||
if (m.genre === "outil") return <Text key={i} size="xs" c="dimmed" ff="monospace" style={{ overflowWrap: "anywhere" }}>{m.texte}</Text>;
|
||||
if (m.genre === "erreur") return <Paper key={i} p="xs" bg="var(--mantine-color-red-light)" c="red"><Text size="sm">Erreur : {m.texte}</Text></Paper>;
|
||||
return (
|
||||
<Paper key={i} px="md" py="xs" className={`message ${m.genre}`}>
|
||||
<Text size="xs" fw={700} tt="uppercase" c="dimmed">{m.qui}</Text>
|
||||
<Text size="sm">{m.texte}</Text>
|
||||
</Paper>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
<Group gap="sm" px="lg" py="md" wrap="nowrap" align="flex-end" style={{ borderTop: "1px solid var(--mantine-color-default-border)" }}>
|
||||
<Textarea flex={1} autosize minRows={1} maxRows={6} placeholder={agent === "support" ? "Au support…" : "À l'analyste…"}
|
||||
value={texte} onChange={e => setTexte(e.currentTarget.value)} disabled={occupe} />
|
||||
<Tooltip label="Envoyer">
|
||||
<ActionIcon size="input-sm" onClick={envoyer} disabled={occupe || !seance} aria-label="Envoyer"><IconSend size={18} /></ActionIcon>
|
||||
</Tooltip>
|
||||
</Group>
|
||||
</Carte>
|
||||
);
|
||||
}
|
||||
|
||||
function Rapport({ version, dossier }) {
|
||||
const src = `/api/pdf?v=${version}`;
|
||||
return (
|
||||
<Carte surtitre="Rapport" titre={version ? `Version ${version.replace(".pdf", "").slice(1)}` : "Pas encore de PDF"}
|
||||
action={version && <Button component="a" href={src} download={`${dossier}_${version}`} variant="light"
|
||||
leftSection={<IconDownload size={16} />}>Télécharger</Button>}>
|
||||
{version ? <iframe key={version} className="rapport" src={src} title="Rapport" />
|
||||
: <Text c="dimmed" ta="center" p="xl">Le PDF s'affiche ici dès que le support l'a compilé.</Text>}
|
||||
</Carte>
|
||||
);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [etat, setEtat] = useState({ occupe: { support: false, analyste: false } });
|
||||
const [evenements, setEvenements] = useState([]);
|
||||
const [mobile, { toggle: basculerMobile }] = useDisclosure(false);
|
||||
const [bureau, { toggle: basculerBureau }] = useDisclosure(true);
|
||||
|
||||
useEffect(() => {
|
||||
const flux = new EventSource("/api/flux");
|
||||
flux.onmessage = ev => {
|
||||
const r = JSON.parse(ev.data), nouveaux = r.evenements.filter(e => e.type !== "cout");
|
||||
// depuis = 0 : tout l'historique de la séance (nouvelle séance, ou reconnexion) ; sinon la suite
|
||||
setEvenements(evs => (r.depuis === 0 ? nouveaux : [...evs, ...nouveaux]));
|
||||
setEtat(r);
|
||||
};
|
||||
return () => flux.close();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AppShell header={{ height: 64 }} padding="lg"
|
||||
navbar={{ width: 260, breakpoint: "sm", collapsed: { mobile: !mobile, desktop: !bureau } }}>
|
||||
<Entete dossier={etat.dossier} mobile={mobile} bureau={bureau} basculer={{ mobile: basculerMobile, bureau: basculerBureau }} />
|
||||
<Barre etat={etat} />
|
||||
<AppShell.Main bg="var(--mantine-color-default-hover)">
|
||||
<Stack gap="lg">
|
||||
<div>
|
||||
<Title order={2}>Support</Title>
|
||||
<Text c="dimmed">Colle le mail du client et ton contexte, puis Analyser ; parle au support ou à l'analyste dans leur fil.</Text>
|
||||
</div>
|
||||
<Saisie occupe={etat.occupe.support || etat.occupe.analyste} />
|
||||
<SimpleGrid cols={{ base: 1, md: 2 }} spacing="lg">
|
||||
{AGENTS.map(a => <Fil key={a} agent={a} occupe={etat.occupe[a]} seance={etat.dossier}
|
||||
evenements={evenements.filter(e => e.agent === a)} />)}
|
||||
</SimpleGrid>
|
||||
<Rapport version={etat.version} dossier={etat.dossier} />
|
||||
</Stack>
|
||||
</AppShell.Main>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { MantineProvider, createTheme } from "@mantine/core";
|
||||
import { Notifications } from "@mantine/notifications";
|
||||
import "@mantine/core/styles.css";
|
||||
import "@mantine/notifications/styles.css";
|
||||
import "./style.css";
|
||||
import App from "./App.jsx";
|
||||
|
||||
// Bleu primaire #5383ff (shade 5), la palette retenue pour la page
|
||||
const theme = createTheme({
|
||||
primaryColor: "aimsight",
|
||||
primaryShade: 5,
|
||||
colors: { aimsight: ["#eef3ff", "#dce5ff", "#b8c9ff", "#91abff", "#6f92ff", "#5383ff", "#4574f5", "#3863dc", "#2c55c4", "#1d45ab"] },
|
||||
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
|
||||
headings: { fontFamily: "Roboto, Helvetica, Arial, sans-serif" },
|
||||
defaultRadius: "md",
|
||||
});
|
||||
|
||||
createRoot(document.getElementById("racine")).render(
|
||||
<MantineProvider theme={theme} defaultColorScheme="auto">
|
||||
<Notifications position="top-right" />
|
||||
<App />
|
||||
</MantineProvider>,
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
/* Le reste du visuel vient de Mantine (thème dans main.jsx) */
|
||||
.entete { background: #3d4977; color: #fff; border-bottom: 0; }
|
||||
.message { white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.message.support, .message.relai { background: var(--mantine-color-aimsight-light); }
|
||||
.message.analyste { background: var(--mantine-color-teal-light); }
|
||||
.message.marc { background: var(--mantine-color-yellow-light); align-self: flex-end; max-width: 85%; }
|
||||
.message.relai { border-left: 3px solid var(--mantine-color-aimsight-filled); }
|
||||
.rapport { width: 100%; height: 78vh; border: 0; display: block; background: #fff; }
|
||||
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
// npm run dev : la page sur http://localhost:5173, l'API demandée au serveur Python (port 8770)
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: { proxy: { "/api": "http://127.0.0.1:8770" } },
|
||||
});
|
||||
Reference in new issue
Block a user