Skip to content

Registering a panel

A package or an app can add its own tab to the dashboard at /__warlock (or at the secret path in production). A panel declares three things:

  • an id and a title: the tab,
  • data routes, mounted under the dashboard’s API behind the same guard as the built-in routes,
  • a view module: a browser JavaScript file that devtools serves and loads when the tab opens.

The built-in Processes tab is registered this way.

The dashboard is a React app. It mounts every panel’s view module inside its shell and passes the same context as before, so existing panels keep working unchanged. The page styles of a view that relied on the old dashboard’s CSS classes may look different.

List the panel’s module in src/config/devtools.ts:

src/config/devtools.ts
export default {
panels: ["@acme/queue/devtools"],
};

The config stays a plain object: devtools imports the listed module itself, after it has checked where the app runs. Without the production monitor nothing is imported in production, and the build bundles nothing from it.

An entry is one of:

  • a package export, such as "@acme/queue/devtools", resolved from the app root;
  • a path starting with ./, relative to the app root, such as "./src/devtools/queue-panel.ts";
  • a panel object.

A module that fails to load, or a panel that is invalid or reuses an id, is reported in the terminal and left out; the rest of the dashboard still works.

The module’s default export is a panel, a list of panels, or a function (it may be async) that returns either. The function receives { root }, the app’s root directory.

src/devtools/queue-panel.ts
import type { DevtoolsPanelExport } from "@warlock.js/devtools";
const queuePanel: DevtoolsPanelExport = ({ root }) => ({
id: "queue",
title: "Queue",
// The browser module, served at /__warlock/panels/queue/view.js.
view: new URL("./queue-view.js", import.meta.url),
// More files the view imports, served next to it.
assets: { "chart.js": new URL("./queue-chart.js", import.meta.url) },
routes: [
// GET /__warlock/api/queue
{ path: "", handler: () => ({ root, jobs: [] }) },
// GET /__warlock/api/queue/jobs/:id
{ path: "/jobs/:id", handler: ({ params }) => ({ id: params.id }) },
// POST /__warlock/api/queue/retry
{ method: "POST", path: "/retry", handler: ({ body }) => ({ retried: body }) },
],
});
export default queuePanel;

Use import type only: the module must not need devtools at runtime.

FieldRequiredWhat it is
idyesLower-case letters, digits and dashes, starting with a letter. Names the tab, the URLs and the hash route.
titleyesThe tab label.
viewyesThe browser module: an absolute file path or a file: URL. It must exist when devtools starts.
routesnoData routes: { method?, path, handler }.
assetsnoMore files by served name: { "chart.js": <path or file: URL> }. Plain file names, no folders.
filesnoA folder of images the view shows: { dir, extensions? }. See Images.
sharenoThe shared view a read-only link opens: { view, routes, assets?, files? }. See Share a panel.
productionnotrue when the panel is safe to show in the production monitor. Without it the panel is left out in production unless the project sets production.panels[<id>]: true.

An id that another panel already uses is refused with a message naming that panel. The dashboard’s own ids (requests, ai, agents, queries, mail, logs, routes, api, and the API names mails, background, stream, docs, assets, panels, and the newer resources, health, errors, jobs, instances, auth, account, admin, share) and the built-in processes are taken.

A route is served at /__warlock/api/<id><path>. path is "" for the panel’s base URL or starts with / and may hold parameters (/flows/:name). method is GET (the default), POST, PUT, PATCH or DELETE.

The handler receives { params, query, body }. What it returns is sent as JSON with Cache-Control: no-store; undefined sends 204. To answer with another status, throw an error that has a statusCode:

import type { DevtoolsPanelRoute } from "@warlock.js/devtools";
const flowRoute: DevtoolsPanelRoute = {
path: "/flows/:name",
handler: ({ params }) => {
throw Object.assign(new Error(`No flow named "${params.name}".`), { statusCode: 404 });
},
};

The client then gets 404 with { "error": "No flow named \"checkout\"." }.

files serves a folder of images, such as screenshots, at /__warlock/panels/<id>/files/<path inside the folder>.

files: {
dir: new URL("./screenshots/", import.meta.url);
}
  • dir is an absolute path or a file: URL. A folder that does not exist serves nothing.
  • extensions lists the lower-case extensions that are served. The default is .png, .jpg, .jpeg, .webp and .gif. .svg, .html, .htm, .js and .mjs are refused when the panel loads, because a browser can run them.
  • The path is decoded once, and a path is refused when it is empty, absolute, has an empty, . or .. segment, a backslash, a colon or a NUL byte, or an extension that is not listed. The real path of the file (links followed) must stay inside the real path of the folder.
  • Every refusal answers 404. Images are sent with X-Content-Type-Options: nosniff and Cache-Control: no-store. In the production monitor the route needs a signed-in user.

The view builds the URL with context.file("login/step-1.png").

In the production monitor an admin can give someone a read-only link to a panel, with no account. A panel is shareable only when it declares share:

share: {
view: new URL("./shared-view.js", import.meta.url),
routes: ["/product", "/product/features/:feature"],
assets: ["shared.css"],
files: true,
}
FieldWhat it is
viewThe browser module the link opens. It is called like view, with context.shared === true. It must exist.
routesThe paths of the panel’s GET routes, as written in routes, that the shared page may call. Any other path answers 404.
assetsServed names from assets the shared page may load. Default: none.
filestrue lets the shared page load images from files. The panel must declare files. Default: false.

The panel fails to load, with a message naming the panel and the field, when view is missing, a routes entry is not the path of one of its GET routes, an assets entry is not a name in assets, or files is set without a folder.

A route called through a link receives shared: true in its request. Use it to leave developer detail out of the answer: file paths, code, test names and error messages. Everything a shared route returns reaches someone who is not signed in.

The view is a plain ES module that runs in the browser. Devtools serves it at /__warlock/panels/<id>/view.js with no caching, so an edit shows on the next page load. Files listed in assets are served at /__warlock/panels/<id>/<name>, so the view can import "./chart.js".

Its default export renders the panel. It receives a context object and either fills context.root or returns the element to show. It may be async.

queue-view.js
import { barChart } from "./chart.js";
export default async function renderQueue({ api, el, empty, href, route, root }) {
if (route.startsWith("jobs/")) {
const job = await api(`jobs/${route.slice("jobs/".length)}`);
root.append(el("h2", { text: `Job ${job.id}` }), el("a", { href: href(), text: "All jobs" }));
return;
}
const { jobs } = await api();
root.append(el("h2", { text: "Queue" }));
if (!jobs.length) root.append(empty("No jobs yet."));
for (const job of jobs) {
root.append(el("a", { href: href(`jobs/${encodeURIComponent(job.id)}`), text: job.name }));
}
root.append(barChart(jobs));
}
Context fieldWhat it does
idThe panel id.
rootAn empty <section class="panel"> to render into. Shown when the function returns nothing.
api(path, init)fetch on the panel’s data routes, parsed as JSON. api(), api("search?q=a"), api("/jobs/1") and api("?page=2") all stay under api/<id>. A failed request throws an Error with the server’s error message. init is passed to fetch (method, headers, body).
routeThe panel’s part of the URL hash: "jobs/7" for #queue/jobs/7, "" otherwise. Values are as written; encode them with encodeURIComponent.
href(route)The link to one of the panel’s views: href("jobs/7") is #queue/jobs/7, href() is #queue. A link opens the tab and renders that view.
navigate(route)Goes to that view, as following href(route) would.
refresh()Renders the panel again.
asset(name)The absolute URL of one of the panel’s assets, for a <link rel="stylesheet">, an image or import() of another module.
file(path)The URL of an image in the panel’s files folder: file("login/step-1.png"). Behind a share link it points at the shared image route.
sharedtrue when the view runs behind a read-only share link. Show the shared view only: no file paths, code or developer detail.
shareFor an admin in the production monitor, when sharing is on and the panel declares share: { enabled: true, manageHref }, where manageHref opens the link manager for this panel. Otherwise null. Behind a link it is always null.
el(tag, attrs, children)Builds an element. text sets the text, class the class name, on<event> adds a listener, anything else is an attribute.
svg(tag, attrs, children)The same for SVG elements, for small graphs drawn without a chart library.
empty(message)The dashboard’s empty-state paragraph.

Hash routes make views linkable: #<id>/<route> in the address bar opens the panel on that view, and the browser’s Back button returns to the previous one. Clicking a tab opens its first view. Build text with text (never innerHTML) so data from the app cannot inject markup.

A panel function receives { root, mode, errors }. mode is "development" or "production". Use it to avoid side effects in production: a panel must not write files there. Grimoire opens its book read-only when mode is "production".

src/devtools/queue-panel.ts
import type { DevtoolsPanelExport } from "@warlock.js/devtools";
const queuePanel: DevtoolsPanelExport = ({ mode }) => ({
id: "queue",
title: "Queue",
view: new URL("./queue-view.js", import.meta.url),
// Safe to show in the production monitor: it only reads.
production: true,
routes: [{ path: "", handler: () => ({ readOnly: mode === "production", jobs: [] }) }],
});
export default queuePanel;

The factory also receives errors, a function that reads the captured error groups of the last hour. In development it reads this process; in the production monitor it merges every instance. Each group is counts only (no message and no stack):

type DevtoolsPanelErrorSummary = {
route: string | null; // the route pattern, "/products/:id"
status: number | null;
name: string | null; // the error class, "TypeError"
source: "request" | "log";
count: number;
firstSeen: number;
lastSeen: number;
};
const healthPanel: DevtoolsPanelExport = ({ errors }) => ({
id: "health-map",
title: "Health map",
view: new URL("./view.js", import.meta.url),
routes: [{ path: "", handler: async () => ({ errors: errors ? await errors() : [] }) }],
});

The function answers an empty list while capture is still starting. Read it per request: do not call it when the factory runs.

A package panel can take options. List it as a pair, the module specifier and a plain options object:

src/config/devtools.ts
export default {
panels: [["@warlock.js/grimoire/devtools", { ttlMs: 60_000 }]],
};

The options object is spread into the factory’s context next to root, mode and errors, so the factory receives { ttlMs: 60000, root, mode, errors }. root, mode and errors always come from devtools and cannot be overridden. A plain string entry still works and passes no options. Which options a panel reads is up to the panel; see its own page.

A pair must be exactly [string, plain object]. Anything else (a missing options object, an array, a string, a third item) is reported in the server log with the entry and what to change, and that entry is skipped; the other entries still load. production.panels[<id>] keys by the panel’s id, so it works the same for a pair.

In the production monitor, a panel’s GET routes need a signed-in user. Every other method needs an admin, an origin check and the CSRF header X-Devtools-Csrf, and is written to the audit log as panel.action. The view context’s api() adds the header for you. If your view calls fetch directly for a write, it must send X-Devtools-Csrf itself and a JSON body with Content-Type: application/json. Read the token from the csrf field of GET api/auth/session. The same answer carries warlockVersion and app ({ name, version }), both null when signed out or unknown. A write without the header is refused with csrf.invalid.

Turn a panel off in production with production.panels[<id>]: false; see Devtools in production.

The dashboard has a light and a dark theme, and a panel’s view renders inside it. Style the panel with the dashboard’s CSS variables so it follows the theme and stays readable in both. A panel stylesheet (the files in assets, or styles written by the view) may use only these variables, plus variables it defines itself:

GroupVariables
Surfaces--background, --card, --card-foreground, --popover, --popover-foreground, --muted, --secondary, --secondary-foreground, --accent, --accent-foreground
Text--foreground, --muted-foreground
Brand--primary, --primary-foreground, --brand, --brand-foreground, --ring
Status--success, --warning, --info, --destructive
Lines--border, --input, --radius
Charts--chart-1 to --chart-5
queue.css
.queue-row {
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--card);
color: var(--card-foreground);
}
.queue-row .late {
color: var(--warning);
}

In the light theme --primary is the gold fill (put --primary-foreground on it) and --brand is a deep amber that is safe to use as text; in the dark theme both are gold. --foreground, --muted-foreground, --brand, --success, --warning, --info and --destructive are at least 4.5:1 against --background and --card in both themes, so text in these colours is readable. A variable that is not in the list (or defined by the panel itself) is not set by the dashboard and falls back to the browser default, which can make text unreadable. The list is exported as DEVTOOLS_PANEL_TOKENS from @warlock.js/devtools, so a package can check its own stylesheet in a test.

The view’s DOM also gets the dashboard’s base styles: elements with the classes card, muted, empty and error, plus plain h2, a, button, input, select, table and pre, are styled to match.

A panel’s data routes, its view module, its assets and its images are mounted in the same scope as the dashboard, so the same guard applies to each request. In development:

  • devtools mounts nothing outside development unless the production monitor is enabled;
  • only a loopback socket is answered;
  • the Host must be a loopback name (or one in allowedHosts);
  • an Origin from another site is refused, so a web page you visit cannot call a panel’s routes;
  • a request with a proxy header is refused unless allowProxied is set.

A refused request gets an empty 404 before the handler runs. Only the files a panel lists are served (images only from inside its files folder); a request never becomes an unchecked file path.

In the production monitor the loopback rules do not apply. The sign-in gate does: see Devtools security.