Spaces:
Paused

park-copilot / app /api /static /index.html
github-actions
Deploy e87e565 from GitHub
1edf8a0
Raw History Blame Contribute Delete
22.1 kB
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Park Copilot</title>
<meta name="description" content="Assistant IA pour organiser sa journée dans les deux parcs de Disneyland Paris.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='9' fill='%235b5bf0'/%3E%3Cpath d='M16 6l2.6 7.4L26 16l-7.4 2.6L16 26l-2.6-7.4L6 16l7.4-2.6z' fill='%23fff'/%3E%3C/svg%3E">
<style>
:root {
--bg: #f5f4fb;
--bg-glow-1: rgba(120, 104, 255, .16);
--bg-glow-2: rgba(255, 184, 77, .14);
--surface: #ffffff;
--surface-2: #f0effa;
--text: #1b1a2e;
--muted: #6b6a85;
--border: #e4e2f2;
--primary: #5b5bf0;
--primary-2: #8f5cf7;
--gold: #e8a33d;
--ok: #1f9d62;
--err: #d9485f;
--plan: #6d4ef2;
--park: #139a74;
--info: #2f7de1;
--shadow: 0 1px 2px rgba(27, 26, 46, .05), 0 8px 24px rgba(27, 26, 46, .06);
--radius: 18px;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0d0e1a;
--bg-glow-1: rgba(111, 92, 255, .22);
--bg-glow-2: rgba(255, 170, 60, .10);
--surface: #161829;
--surface-2: #1e2136;
--text: #ecebf7;
--muted: #9d9cb8;
--border: #272a44;
--primary: #7b7bff;
--primary-2: #a77bff;
--gold: #f2b552;
--ok: #3ccf8e;
--err: #ff6b81;
--plan: #a58bff;
--park: #3fd3a7;
--info: #6aa8ff;
--shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .25);
}
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
margin: 0;
color: var(--text);
background:
radial-gradient(900px 500px at 10% -10%, var(--bg-glow-1), transparent 60%),
radial-gradient(700px 400px at 100% 0%, var(--bg-glow-2), transparent 60%),
var(--bg);
background-attachment: fixed;
font: 15px/1.55 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
-webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
.app { max-width: 820px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; padding: 0 16px; }
/* ---------------------------------------------------------------- header */
.top { display: flex; align-items: center; gap: 12px; padding: 16px 0; position: sticky; top: 0; z-index: 5;
background: linear-gradient(var(--bg) 70%, transparent); }
.logo { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 6px 18px rgba(91, 91, 240, .35); }
.brand { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-size: 16px; letter-spacing: -.01em; }
.brand span { font-size: 12.5px; color: var(--muted); }
.top .spacer { flex: 1; }
.ghost { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border);
border-radius: 999px; padding: 7px 13px; font-size: 13px; cursor: pointer; box-shadow: var(--shadow); }
.ghost:hover { border-color: var(--primary); }
/* ---------------------------------------------------------------- welcome */
.hero { padding: 36px 0 12px; animation: rise .5s ease both; }
.hero h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.1; letter-spacing: -.03em; margin: 0 0 10px; }
.hero h1 em { font-style: normal; background: linear-gradient(90deg, var(--primary), var(--primary-2) 55%, var(--gold));
-webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); margin: 0 0 24px; max-width: 560px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
padding: 16px; cursor: pointer; box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease; }
.card:hover { transform: translateY(-2px); border-color: var(--primary); }
.card .ico { font-size: 22px; line-height: 1; }
.card b { display: block; margin: 10px 0 4px; font-size: 14.5px; }
.card span { color: var(--muted); font-size: 13px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; color: var(--muted); font-size: 12.5px; }
.pills span { border: 1px dashed var(--border); border-radius: 999px; padding: 4px 10px; }
/* ---------------------------------------------------------------- conversation */
#log { display: flex; flex-direction: column; gap: 18px; padding: 8px 0 24px; flex: 1; }
.turn { display: flex; gap: 10px; animation: rise .25s ease both; }
.turn.user { justify-content: flex-end; }
.turn.user .bubble { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
border: 0; border-bottom-right-radius: 6px; max-width: 80%; white-space: pre-wrap; }
.avatar { width: 30px; height: 30px; border-radius: 10px; flex: none; display: grid; place-items: center; margin-top: 2px;
background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
border-top-left-radius: 6px; padding: 12px 16px; box-shadow: var(--shadow); min-width: 0; max-width: 100%;
overflow-wrap: anywhere; }
.turn.bot .bubble { flex: 1; }
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.steps:empty { display: none; }
.badge, .step { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 10px;
font-size: 12.5px; font-weight: 500; }
.badge { color: #fff; }
.badge.planning { background: var(--plan); }
.badge.in_park { background: var(--park); }
.badge.general { background: var(--info); }
.step { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.step .state { width: 12px; height: 12px; display: inline-grid; place-items: center; font-size: 11px; }
.step.run .state { border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.step.ok .state::before { content: "✓"; color: var(--ok); font-weight: 700; }
.step.err .state::before { content: "!"; color: var(--err); font-weight: 700; }
.step.err { border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .4; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h3 { font-size: 15px; margin: 16px 0 8px; letter-spacing: -.01em; }
.md ul, .md ol:not(.timeline) { margin: 0 0 10px; padding-left: 20px; }
.md li { margin: 3px 0; }
.md code { background: var(--surface-2); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
.md a { color: var(--primary); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
/* the day plan: "09:30 – Ride (detail)" lines become a timeline */
.timeline { list-style: none; margin: 4px 0 12px; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 27px; top: 10px; bottom: 10px; width: 2px;
background: linear-gradient(var(--primary), var(--primary-2), var(--gold)); opacity: .35; border-radius: 2px; }
.timeline li { display: flex; gap: 14px; align-items: flex-start; padding: 6px 0; position: relative; }
.timeline .t { flex: none; width: 56px; text-align: center; font-weight: 600; font-size: 12.5px; font-variant-numeric: tabular-nums;
background: var(--surface); border: 1.5px solid var(--primary); color: var(--primary); border-radius: 999px;
padding: 3px 0; position: relative; z-index: 1; }
.timeline .c { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; flex: 1; min-width: 0; }
.timeline .what { font-weight: 500; }
.timeline .detail { color: var(--muted); font-size: 13px; margin-top: 2px; }
.footnote { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); color: var(--muted); font-size: 12px; }
.error { color: var(--err); }
/* ---------------------------------------------------------------- composer */
.composer { position: sticky; bottom: 0; padding: 10px 0 max(12px, env(safe-area-inset-bottom));
background: linear-gradient(transparent, var(--bg) 30%); }
.box { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--border);
border-radius: 20px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow); transition: border-color .15s ease; }
.box:focus-within { border-color: var(--primary); }
textarea { flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--text); font: inherit;
padding: 8px 0; max-height: 160px; min-height: 24px; }
textarea::placeholder { color: var(--muted); }
.send { width: 40px; height: 40px; flex: none; border: 0; border-radius: 14px; cursor: pointer; display: grid; place-items: center;
background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; transition: opacity .15s ease; }
.send:disabled { opacity: .45; cursor: default; }
.credits { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 8px; }
.credits a { color: inherit; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .9; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 560px) {
.cards { grid-template-columns: 1fr; }
.hero { padding-top: 20px; }
.turn.user .bubble { max-width: 90%; }
.avatar { display: none; }
.brand span { display: none; }
}
</style>
</head>
<body>
<div class="app">
<header class="top">
<div class="logo" aria-hidden="true">
<svg width="20" height="20" viewBox="0 0 24 24" fill="#fff"><path d="M12 2.5l2.2 6.3 6.3 2.2-6.3 2.2L12 19.5l-2.2-6.3L3.5 11l6.3-2.2z"/><circle cx="19" cy="19" r="1.6"/><circle cx="5" cy="4.5" r="1.1"/></svg>
</div>
<div class="brand">
<strong>Park Copilot</strong>
<span>Assistant IA · Disneyland Paris, les deux parcs</span>
</div>
<div class="spacer"></div>
<button class="ghost" id="reset" type="button" hidden>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><path d="M12 5v14M5 12h14"/></svg>
Nouvelle conversation
</button>
</header>
<main id="main">
<section class="hero" id="welcome">
<h1>Ta journée au parc,<br><em>planifiée en quelques secondes.</em></h1>
<p>Park Copilot combine les temps d'attente habituels, les temps live, la météo heure par heure
et un guide de visite pour te proposer un programme concret.</p>
<div class="cards">
<button class="card" type="button" data-q="Je viens samedi au Disneyland Park avec des enfants de 5 et 9 ans, tu me fais un programme ?">
<div class="ico">📅</div><b>Planifier une journée</b><span>Un programme horodaté pour une date à venir</span>
</button>
<button class="card" type="button" data-q="Je suis au Disneyland Park, qu'est-ce qui est plus calme que d'habitude en ce moment ?">
<div class="ico">📍</div><b>Je suis au parc</b><span>Ce qui vaut le coup maintenant, live vs habituel</span>
</button>
<button class="card" type="button" data-q="Il va pleuvoir demain ? Quelles attractions faire au Disney Adventure World ?">
<div class="ico">🌦️</div><b>Météo et plan B</b><span>Attractions intérieures pendant les averses</span>
</button>
<button class="card" type="button" data-q="C'est quoi une file Single Rider et sur quelles attractions ?">
<div class="ico">💡</div><b>Astuces de visite</b><span>Single Rider, meilleurs moments, accessibilité</span>
</button>
</div>
<div class="pills"><span>Temps live</span><span>Historique d'attente</span><span>Météo horaire</span><span>Guide de visite</span></div>
</section>
<div id="log" aria-live="polite"></div>
</main>
<div class="composer">
<form class="box" id="form">
<textarea id="input" rows="1" maxlength="2000" placeholder="Pose ta question… (ex : on vient mardi, par quoi commencer ?)" aria-label="Message"></textarea>
<button class="send" id="send" type="submit" aria-label="Envoyer">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
</button>
</form>
<div class="credits">
Temps d'attente : <a href="https://queue-times.com/" target="_blank" rel="noopener">Powered by Queue-Times.com</a> (données non officielles)
· Météo : <a href="https://open-meteo.com/" target="_blank" rel="noopener">Open-Meteo.com</a>
· Projet indépendant, non affilié aux parcs.
</div>
</div>
</div>
<script>
const TOOLS = {
get_live_wait_times: ["⏱️", "Temps live"],
get_typical_wait: ["📊", "Attentes habituelles"],
compare_live_vs_typical: ["⚖️", "Live vs habituel"],
get_weather: ["🌦️", "Météo"],
search_park_guide: ["📖", "Guide"],
};
const MODES = {
planning: ["📅", "Planification"],
in_park: ["📍", "Au parc"],
general: ["💬", "Question générale"],
};
const AVATAR = '<svg width="16" height="16" viewBox="0 0 24 24" fill="#fff"><path d="M12 2.5l2.2 6.3 6.3 2.2-6.3 2.2L12 19.5l-2.2-6.3L3.5 11l6.3-2.2z"/></svg>';
const $ = id => document.getElementById(id);
const log = $("log"), form = $("form"), input = $("input"), send = $("send");
const welcome = $("welcome"), reset = $("reset");
let threadId = null;
try { threadId = sessionStorage.getItem("thread_id"); } catch (_) {}
// ------------------------------------------------------------------ markdown (safe subset)
function escapeHtml(s) {
return s.replace(/[&<>"']/g, c => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
}
function inline(s) { // s is already escaped
return s
.replace(/`([^`]+)`/g, "<code>$1</code>")
.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>")
.replace(/(^|[^*\w])\*([^*\n]+)\*(?!\*)/g, "$1<em>$2</em>")
.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>');
}
// "09:30 – Big Thunder Mountain (≈ 15 min, 6 jours de données)" -> timeline item
const TIME_LINE = /^(?:[-*•]\s*)?(\d{1,2})\s*[:h]\s*(\d{2})\s*[–—-]\s*(.+)$/;
function renderMarkdown(src) {
let html = "", list = null;
const close = () => { if (list) { html += `</${list === "timeline" ? "ol" : list}>`; list = null; } };
const open = kind => {
if (list === kind) return;
close();
html += kind === "timeline" ? '<ol class="timeline">' : `<${kind}>`;
list = kind;
};
for (const raw of src.replace(/\r/g, "").split("\n")) {
let line = raw.trim();
if (!line) { close(); continue; }
if (/^\|?\s*:?-{3,}/.test(line)) continue; // table separator rows
line = line.replace(/^\*\*(.+)\*\*$/, "$1"); // a fully bold line
let m;
if ((m = TIME_LINE.exec(line))) {
open("timeline");
let what = m[3].replace(/\*\*/g, ""), detail = "";
const p = /^(.*?)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)\s*$/.exec(what);
if (p && p[1]) { what = p[1]; detail = p[2]; }
html += `<li><span class="t">${m[1].padStart(2, "0")}:${m[2]}</span><div class="c">`
+ `<div class="what">${inline(escapeHtml(what))}</div>`
+ (detail ? `<div class="detail">${inline(escapeHtml(detail))}</div>` : "")
+ "</div></li>";
} else if ((m = /^#{1,6}\s+(.+)$/.exec(line))) {
close(); html += `<h3>${inline(escapeHtml(m[1]))}</h3>`;
} else if ((m = /^[-*•]\s+(.+)$/.exec(line))) {
open("ul"); html += `<li>${inline(escapeHtml(m[1]))}</li>`;
} else if ((m = /^\d+[.)]\s+(.+)$/.exec(line))) {
open("ol"); html += `<li>${inline(escapeHtml(m[1]))}</li>`;
} else if (/^(-{3,}|\*{3,})$/.test(line)) {
close(); html += "<hr>";
} else {
close(); html += `<p>${inline(escapeHtml(line.replace(/^\|\s*|\s*\|$/g, "").replace(/\s*\|\s*/g, " · ")))}</p>`;
}
}
close();
return html;
}
// ------------------------------------------------------------------ UI helpers
function el(tag, cls, html) {
const node = document.createElement(tag);
if (cls) node.className = cls;
if (html !== undefined) node.innerHTML = html;
return node;
}
function scrollDown() {
window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" });
}
function autoGrow() {
input.style.height = "auto";
input.style.height = Math.min(input.scrollHeight, 160) + "px";
}
function startConversation() {
welcome.hidden = true;
reset.hidden = false;
}
reset.addEventListener("click", () => {
threadId = null;
try { sessionStorage.removeItem("thread_id"); } catch (_) {}
log.innerHTML = "";
welcome.hidden = false;
reset.hidden = true;
input.focus();
});
// ------------------------------------------------------------------ chat
async function ask(message) {
startConversation();
const user = el("div", "turn user");
user.append(el("div", "bubble"));
user.firstChild.textContent = message;
log.append(user);
const bot = el("div", "turn bot");
const bubble = el("div", "bubble");
const steps = el("div", "steps");
const answer = el("div", "md");
const typing = el("div", "typing", "<span></span><span></span><span></span>");
bubble.append(steps, answer, typing);
bot.append(el("div", "avatar", AVATAR), bubble);
log.append(bot);
scrollDown();
send.disabled = true;
let text = "";
const running = {};
try {
const response = await fetch("chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(threadId ? { message, thread_id: threadId } : { message }),
});
if (!response.ok || !response.body) throw new Error("HTTP " + response.status);
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
for (;;) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
let cut;
while ((cut = buffer.indexOf("\n\n")) >= 0) { // one SSE event per blank line
const raw = buffer.slice(0, cut);
buffer = buffer.slice(cut + 2);
const event = /^event: (.*)$/m.exec(raw)?.[1];
const data = JSON.parse(/^data: (.*)$/m.exec(raw)?.[1] || "{}");
handle(event, data);
}
}
} catch (err) {
typing.remove();
answer.insertAdjacentHTML("beforeend", '<p class="error">Impossible de joindre le serveur. Réessaie dans un instant.</p>');
} finally {
typing.remove();
send.disabled = false;
input.focus();
}
function handle(event, data) {
if (event === "mode") {
const [icon, label] = MODES[data.mode] || ["", data.mode];
steps.append(el("span", `badge ${data.mode}`, `${icon} ${label}`));
} else if (event === "tool_start") {
const [icon, label] = TOOLS[data.name] || ["🔧", data.name];
running[data.id] = el("span", "step run", `<span class="state"></span>${icon} ${label}`);
steps.append(running[data.id]);
} else if (event === "tool_end" && running[data.id]) {
running[data.id].className = "step " + (data.ok ? "ok" : "err");
} else if (event === "token") {
text += data.text;
answer.innerHTML = renderMarkdown(text);
} else if (event === "done") {
if (data.thread_id) {
threadId = data.thread_id;
try { sessionStorage.setItem("thread_id", threadId); } catch (_) {}
}
if (data.latency_ms !== undefined) {
const parts = [];
if (data.mode && MODES[data.mode]) parts.push(MODES[data.mode][1]);
if (data.tools?.length) parts.push(`${data.tools.length} outil${data.tools.length > 1 ? "s" : ""}`);
parts.push(`${(data.latency_ms / 1000).toFixed(1).replace(".", ",")} s`);
bubble.append(el("div", "footnote", parts.join(" · ")));
}
} else if (event === "error") {
answer.insertAdjacentHTML("beforeend", `<p class="error">⚠️ ${escapeHtml(data.message || "Erreur")}</p>`);
}
if (event === "token" || event === "error") typing.remove();
scrollDown();
}
}
form.addEventListener("submit", e => {
e.preventDefault();
const message = input.value.trim();
if (!message || send.disabled) return;
input.value = "";
autoGrow();
ask(message);
});
input.addEventListener("input", autoGrow);
input.addEventListener("keydown", e => {
if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); form.requestSubmit(); }
});
document.querySelectorAll(".card").forEach(card => card.addEventListener("click", () => ask(card.dataset.q)));
</script>
</body>
</html>