web: give chat details a real back route

Opening a chat now pushes /chat/:id, so Android/browser Back returns to the
chat list rather than the previous destination. The conversation header owns a
compact Back to chats control matching the create pane, replacing the
full-width Back to list row on phones.
This commit is contained in:
2026-10-20 03:25:31 +01:00
parent 526c19fc21
commit c291327610
6 changed files with 90 additions and 10 deletions
+20 -2
View File
@@ -12,7 +12,8 @@
// /runs Runs list
// /runs/:id run detail (optional ?action=decide)
// /runs/:id/stage/:key[?visit=N] one visit's stage pane
// /chat Chat
// /chat Chat list
// /chat/:id one chat session
// /templates template gallery
// /templates/:key template detail
// /settings Settings
@@ -47,6 +48,12 @@ function parseId(value) {
}
/** A non-negative safe integer (a pipeline version; 0 means latest), or null. */
/** A chat session id segment: nonempty, bounded, URL-safe. */
function parseChatId(value) {
const id = String(value ?? "");
return id !== "" && id.length <= 200 && /^[A-Za-z0-9_-]+$/.test(id) ? id : null;
}
function parseVersion(value) {
if (!ID_PATTERN.test(value)) return null;
const version = Number(value);
@@ -131,7 +138,14 @@ export function parseRoute(pathname, search = "") {
if (head === "pipelines" && second == null) return { kind: "pipelines" };
if (head === "runs" && second == null) return { kind: "runs" };
if (head === "chat" && second == null) return { kind: "chat" };
if (head === "chat") {
if (second == null) return { kind: "chat" };
if (third == null) {
const id = parseChatId(second);
return id == null ? { ...DEFAULT_ROUTE } : { kind: "chatSession", id };
}
return { ...DEFAULT_ROUTE };
}
if (head === "settings" && second == null) return { kind: "settings" };
if (head === "templates") {
if (second == null) return { kind: "templates" };
@@ -230,6 +244,10 @@ export function serializeRoute(route) {
return "/runs";
case "chat":
return "/chat";
case "chatSession": {
const id = parseChatId(r.id);
return id == null ? "/chat" : `/chat/${encode(id)}`;
}
case "settings":
return "/settings";
case "templates":