The web chat is now a persistent slide-over drawer available on any page
(not just the /chat route), and the agent is told which dashboard page the
operator is on so it can point them to the relevant page with a clickable chip.
Backend (gateway):
- Message gains a per-message Page field; the system prompt renders it in
the <env> block (Current page), so Archie knows where the operator is.
- New dashboard_tools.go: a DashboardPages registry plus two web-only tools
— page_index (lists every page and what it shows) and dashboard_navigate
(validates a path, returns {path,label}; rejects unknown/empty paths).
- The web chat sink emits a dedicated navigate stream event when the model
calls dashboard_navigate, independent of ShowToolCalls.
Frontend (webui):
- chat sends currentPage() (location.hash) with each stream request; a
dashboard_navigate result renders as a clickable link chip (href=#/path).
- The chat is mounted once in a slide-over drawer with a topbar launcher,
scrim and Esc-to-close; /chat opens the drawer instead of a second page.
- ui/dist rebuilt (committed) with the bundled changes.
- .gitignore: ignore .impeccable/ (impeccable tool critique snapshots).
New capability (per scope discipline): designed in
docs/prds/dashboard-aware-chat-navigation.md.
Tests: dashboard_tools_test (registry, resolve/reject, web-only gating),
prompt page-line cases, webui Message.Page + navigate-frame capture, and
chat-tools chip tests. task check is green.
252 lines
9.0 KiB
JavaScript
252 lines
9.0 KiB
JavaScript
import "./css/_main.css";
|
|
import { el, mount } from "./base/dom.js";
|
|
import { icon } from "./base/icons.js";
|
|
import { dashboardPage } from "./dashboard/dashboard.js";
|
|
import { tasksPage } from "./tasks/tasks.js";
|
|
import { skillsPage } from "./skills/skills.js";
|
|
import { workflowsPage } from "./workflows/workflows.js";
|
|
import { channelsPage } from "./channels/channels.js";
|
|
import { settingsPage } from "./settings/settings.js";
|
|
import { logsPage } from "./logs/logs.js";
|
|
import { capturesPage } from "./captures/captures.js";
|
|
import { mappingsPage } from "./mappings/mappings.js";
|
|
import { memoryPage } from "./memory/memory.js";
|
|
import { chatPage } from "./chat/chat.js";
|
|
|
|
/**
|
|
* Routes are declared once here. Adding a section means adding a feature
|
|
* folder and one entry -- there is no switch statement to hunt for.
|
|
*
|
|
* `soon: true` sections are deliberately visible before they are built: a
|
|
* greyed, labelled entry tells you the capability exists and is coming, which
|
|
* is more honest than hiding it and more useful than a 404.
|
|
*/
|
|
const routes = [
|
|
{ path: "/", label: "Dashboard", icon: "dashboard", view: dashboardPage },
|
|
{ path: "/chat", label: "Chat", icon: "chat", view: chatPage },
|
|
{ path: "/tasks", label: "Tasks", icon: "tasks", view: tasksPage },
|
|
{ path: "/logs", label: "Logs", icon: "logs", view: logsPage },
|
|
{ path: "/captures", label: "Event inspector", icon: "captures", view: capturesPage },
|
|
{ path: "/mappings", label: "Field mappings", icon: "mappings", view: mappingsPage },
|
|
{ path: "/skills", label: "Skills", icon: "skills", view: skillsPage },
|
|
{ path: "/workflows", label: "Workflows", icon: "workflows", view: workflowsPage },
|
|
{ path: "/memory", label: "Memory", icon: "memory", view: memoryPage },
|
|
{ path: "/channels", label: "Channels", icon: "channels", view: channelsPage },
|
|
{ path: "/settings", label: "Configuration", icon: "settings", view: settingsPage },
|
|
];
|
|
|
|
const THEME_KEY = "archie.theme";
|
|
|
|
function applyTheme(theme) {
|
|
document.documentElement.dataset.theme = theme;
|
|
localStorage.setItem(THEME_KEY, theme);
|
|
}
|
|
|
|
function currentTheme() {
|
|
return localStorage.getItem(THEME_KEY) || "dark";
|
|
}
|
|
|
|
function commandBar(onNavigate, onToggleChat) {
|
|
const items = new Map();
|
|
|
|
const nav = el(
|
|
"nav.nav",
|
|
...[null].flatMap(() => [
|
|
...routes
|
|
.map((route) => {
|
|
const item = el(
|
|
"a.nav-item",
|
|
{
|
|
href: `#${route.path}`,
|
|
onclick: (e) => {
|
|
if (route.soon) e.preventDefault();
|
|
else onNavigate(route.path);
|
|
},
|
|
"aria-disabled": route.soon || undefined,
|
|
title: route.soon ? "Coming soon" : undefined,
|
|
},
|
|
icon(route.icon),
|
|
el("span.nav-label", route.label),
|
|
route.soon && el("span.nav-soon", "soon"),
|
|
);
|
|
items.set(route.path, item);
|
|
return item;
|
|
}),
|
|
]),
|
|
);
|
|
|
|
const themeBtn = el("button.icon-btn", {
|
|
title: "Toggle light and dark",
|
|
"aria-label": "Toggle light and dark",
|
|
onclick: () => {
|
|
applyTheme(currentTheme() === "dark" ? "light" : "dark");
|
|
mount(themeBtn, icon(currentTheme() === "dark" ? "moon" : "sun"));
|
|
},
|
|
});
|
|
mount(themeBtn, icon(currentTheme() === "dark" ? "moon" : "sun"));
|
|
|
|
// Search jumps between sections. It is deliberately not a data search: the
|
|
// sections own their own filtering, and a second search that means something
|
|
// different in each place is worse than none.
|
|
let searchWrap;
|
|
const closeMobileSearch = () => {
|
|
searchWrap?.classList.remove("is-open");
|
|
searchToggle.setAttribute("aria-expanded", "false");
|
|
};
|
|
const searchToggle = el(
|
|
"button.icon-btn.mobile-search-toggle",
|
|
{
|
|
type: "button",
|
|
"aria-label": "Open Jump to navigation",
|
|
"aria-expanded": "false",
|
|
onclick: () => {
|
|
searchWrap.classList.add("is-open");
|
|
searchToggle.setAttribute("aria-expanded", "true");
|
|
search.focus();
|
|
},
|
|
},
|
|
icon("search", { size: 15 }),
|
|
);
|
|
const search = el("input", {
|
|
type: "search",
|
|
placeholder: "Jump to\u2026",
|
|
"aria-label": "Jump to a section",
|
|
onkeydown: (e) => {
|
|
if (e.key === "Escape") {
|
|
// preventDefault so the window-level handler (chat drawer close) does
|
|
// not also fire: dismissing the search should not dismiss the drawer.
|
|
e.preventDefault();
|
|
closeMobileSearch();
|
|
e.target.blur();
|
|
return;
|
|
}
|
|
if (e.key !== "Enter") return;
|
|
const q = e.target.value.trim().toLowerCase();
|
|
const hit = routes.find((r) => !r.soon && r.label.toLowerCase().startsWith(q));
|
|
if (hit) {
|
|
onNavigate(hit.path);
|
|
e.target.value = "";
|
|
e.target.blur();
|
|
closeMobileSearch();
|
|
}
|
|
},
|
|
});
|
|
searchWrap = el(
|
|
"div.topbar-search",
|
|
el("span.topbar-search-icon", { "aria-hidden": "true" }, icon("search", { size: 15 })),
|
|
searchToggle,
|
|
search,
|
|
);
|
|
|
|
return {
|
|
node: el(
|
|
"header.topbar",
|
|
el("div.brand", el("span.brand-mark", "A"), "Archie"),
|
|
nav,
|
|
el(
|
|
"div.topbar-end",
|
|
searchWrap,
|
|
el("button.icon-btn.icon-btn-chat", {
|
|
"aria-label": "Open chat",
|
|
title: "Chat with Archie",
|
|
"aria-expanded": "false",
|
|
onclick: () => onToggleChat?.(),
|
|
}, icon("chat")),
|
|
el("button.icon-btn", { title: "Documentation", "aria-label": "Documentation" }, icon("help")),
|
|
themeBtn,
|
|
el("div.avatar", { title: "Signed in locally" }, "A"),
|
|
),
|
|
),
|
|
highlight(path) {
|
|
for (const [p, node] of items) {
|
|
if (p === path) node.setAttribute("aria-current", "page");
|
|
else node.removeAttribute("aria-current");
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
function start() {
|
|
applyTheme(currentTheme());
|
|
|
|
const outlet = el("main.main");
|
|
// The chat drawer lives beside the outlet, mounted once. It is closed by
|
|
// default and opened from the topbar launcher; because it is a slide-over
|
|
// rather than a route, the operator can talk to Archie from any page
|
|
// without leaving the work that prompted the question. It hosts a single
|
|
// chatPage() instance, so session state and the stream survive navigation
|
|
// and are not duplicated per page.
|
|
const chatDrawer = el("aside.chat-drawer", { "aria-label": "Chat with Archie" });
|
|
const chatClose = el("button.icon-btn.chat-drawer-close", {
|
|
"aria-label": "Close chat",
|
|
title: "Close chat",
|
|
onclick: () => toggleChat(false),
|
|
}, icon("close"));
|
|
const drawerHead = el("div.chat-drawer-head", el("strong", "Archie"), chatClose);
|
|
chatDrawer.append(el("div.chat-drawer-panel", drawerHead, chatPage()),
|
|
el("div.chat-scrim", { onclick: () => toggleChat(false) }));
|
|
const bar = commandBar(navigate, () => toggleChat());
|
|
const shell = el("div.shell", bar.node, outlet, chatDrawer);
|
|
mount(document.getElementById("app"), shell);
|
|
|
|
function toggleChat(open) {
|
|
const shouldOpen = open === undefined ? !chatDrawer.classList.contains("is-open") : open;
|
|
chatDrawer.classList.toggle("is-open", shouldOpen);
|
|
document.body.classList.toggle("chat-open", shouldOpen);
|
|
const btn = shell.querySelector(".icon-btn-chat");
|
|
if (btn) btn.setAttribute("aria-expanded", String(shouldOpen));
|
|
}
|
|
window.__archieToggleChat = toggleChat;
|
|
|
|
function navigate(path) {
|
|
if (location.hash !== '#' + path) location.hash = path;
|
|
else show(path);
|
|
}
|
|
|
|
function show(rawPath) {
|
|
// Let a page release its subscriptions before it is replaced, so the SSE
|
|
// stream does not leak a connection per navigation.
|
|
outlet.firstElementChild?.dispatchEvent(new CustomEvent("archie:teardown"));
|
|
const [path, query = ""] = rawPath.split("?", 2);
|
|
const route = routes.find((r) => r.path === path) || routes[0];
|
|
bar.highlight(route.path);
|
|
// The chat is a drawer, not a page: /chat opens it rather than mounting a
|
|
// second chatPage() (which would duplicate session state and the stream).
|
|
if (route.path === "/chat") {
|
|
mount(outlet);
|
|
toggleChat(true);
|
|
return;
|
|
}
|
|
mount(outlet, route.view ? route.view(new URLSearchParams(query)) : comingSoon(route));
|
|
// Navigating to a page dismisses the chat drawer; the operator has moved on.
|
|
toggleChat(false);
|
|
}
|
|
|
|
window.addEventListener("hashchange", () => show(location.hash.slice(1) || "/"));
|
|
window.addEventListener("keydown", (e) => {
|
|
// A focused control (the composer dismissing its command menu, or the
|
|
// topbar search) already handled Escape via preventDefault; closing the
|
|
// drawer too would make the menu impossible to dismiss alone.
|
|
if (e.defaultPrevented) return;
|
|
if (e.key === "Escape" && chatDrawer.classList.contains("is-open")) toggleChat(false);
|
|
});
|
|
show(location.hash.slice(1) || "/");
|
|
}
|
|
|
|
function comingSoon(route) {
|
|
return el(
|
|
"div",
|
|
el("div.page-head", el("div", el("h1.page-title", route.label))),
|
|
el(
|
|
"div.card",
|
|
el(
|
|
"div.empty",
|
|
el("div.empty-title", `${route.label} is not built yet`),
|
|
el("div", "This section is next up. Nothing is broken."),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
start();
|