@warlock.js/devtools 5.54.0 → 5.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/cjs/ai-source-Dz_3tlZ5.cjs +703 -0
  3. package/cjs/ai-source-Dz_3tlZ5.cjs.map +1 -0
  4. package/cjs/index.cjs +1 -1
  5. package/cjs/{server-BlQshJLE.cjs → server-B11ShQYE.cjs} +67 -97
  6. package/cjs/server-B11ShQYE.cjs.map +1 -0
  7. package/cjs/{src-BzuntLcd.cjs → src-Xwm3Eel9.cjs} +18 -23
  8. package/cjs/src-Xwm3Eel9.cjs.map +1 -0
  9. package/esm/devtools-connector.d.mts +2 -1
  10. package/esm/devtools-connector.d.mts.map +1 -1
  11. package/esm/devtools-connector.mjs +13 -3
  12. package/esm/devtools-connector.mjs.map +1 -1
  13. package/esm/index.d.mts +2 -2
  14. package/esm/options.mjs +2 -1
  15. package/esm/options.mjs.map +1 -1
  16. package/esm/panels.mjs +222 -0
  17. package/esm/panels.mjs.map +1 -0
  18. package/esm/process-panel.mjs +20 -1
  19. package/esm/process-panel.mjs.map +1 -1
  20. package/esm/server/index.mjs +9 -4
  21. package/esm/server/index.mjs.map +1 -1
  22. package/esm/server/panel-routes.mjs +44 -0
  23. package/esm/server/panel-routes.mjs.map +1 -0
  24. package/esm/server/ui-assets.mjs +21 -8
  25. package/esm/server/ui-assets.mjs.map +1 -1
  26. package/esm/types.d.mts +70 -1
  27. package/esm/types.d.mts.map +1 -1
  28. package/esm/ui-root.mjs +2 -2
  29. package/llms-full.txt +52 -1
  30. package/llms.txt +1 -1
  31. package/package.json +6 -6
  32. package/skills/SKILL.md +52 -1
  33. package/ui/app.js +117 -13
  34. package/ui/index.html +1 -1
  35. package/ui/panels/processes.js +15 -0
  36. package/cjs/ai-source-CSPh1HqJ.cjs +0 -330
  37. package/cjs/ai-source-CSPh1HqJ.cjs.map +0 -1
  38. package/cjs/server-BlQshJLE.cjs.map +0 -1
  39. package/cjs/src-BzuntLcd.cjs.map +0 -1
  40. package/esm/server/process-routes.mjs +0 -11
  41. package/esm/server/process-routes.mjs.map +0 -1
@@ -1,3 +1,5 @@
1
+ import { checkDevtoolsPanels } from "../panels.mjs";
2
+ import { processesDevtoolsPanel } from "../process-panel.mjs";
1
3
  import { registerAiRoutes } from "./ai-routes.mjs";
2
4
  import { registerBackgroundRoutes } from "./background-routes.mjs";
3
5
  import { registerExplainRoute } from "./explain-route.mjs";
@@ -6,7 +8,7 @@ import { registerLogRoutes } from "./log-routes.mjs";
6
8
  import { registerMailRoutes } from "./mail-routes.mjs";
7
9
  import { registerUiAssets } from "./ui-assets.mjs";
8
10
  import { registerOpenApiRoutes } from "./openapi-routes.mjs";
9
- import { registerProcessRoutes } from "./process-routes.mjs";
11
+ import { registerPanelRoutes } from "./panel-routes.mjs";
10
12
  import { registerRequestsRoutes } from "./requests-routes.mjs";
11
13
  import { registerRouteRoutes } from "./route-routes.mjs";
12
14
  import { registerStreamRoute } from "./stream-route.mjs";
@@ -16,22 +18,25 @@ import { registerStreamRoute } from "./stream-route.mjs";
16
18
  * Mounts the devtools dashboard and its API under `deps.options.path` on
17
19
  * `server`. Every route is registered inside a single encapsulated Fastify
18
20
  * context so the dev-only, loopback-only guard never reaches the app's
19
- * other routes.
21
+ * other routes — the registered panels' data routes and files included.
22
+ *
23
+ * Throws before mounting anything when a panel is invalid or reuses an id.
20
24
  */
21
25
  function mountDevtoolsRoutes(server, deps) {
26
+ const panels = checkDevtoolsPanels([processesDevtoolsPanel(deps.processPanel), ...deps.panels ?? []]);
22
27
  server.register(async (instance) => {
23
28
  registerDevtoolsGuard(instance, deps);
24
29
  instance.setErrorHandler((error, _request, reply) => {
25
30
  reply.code(error.statusCode ?? 500).send({ error: error.message });
26
31
  });
27
- registerUiAssets(instance);
32
+ registerUiAssets(instance, panels);
28
33
  registerRequestsRoutes(instance, deps);
29
34
  registerAiRoutes(instance, deps);
30
35
  registerBackgroundRoutes(instance, deps);
31
36
  registerMailRoutes(instance, deps);
32
37
  registerLogRoutes(instance, deps);
33
38
  registerRouteRoutes(instance, deps);
34
- registerProcessRoutes(instance, deps);
39
+ registerPanelRoutes(instance, panels);
35
40
  registerOpenApiRoutes(instance, deps);
36
41
  registerExplainRoute(instance, deps);
37
42
  registerStreamRoute(instance, deps);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/index.ts"],"sourcesContent":["import type { FastifyError, FastifyInstance } from \"fastify\";\nimport { registerAiRoutes } from \"./ai-routes\";\nimport { registerBackgroundRoutes } from \"./background-routes\";\nimport { registerExplainRoute } from \"./explain-route\";\nimport { registerDevtoolsGuard } from \"./guard\";\nimport { registerLogRoutes } from \"./log-routes\";\nimport { registerMailRoutes } from \"./mail-routes\";\nimport { registerOpenApiRoutes } from \"./openapi-routes\";\nimport { registerProcessRoutes } from \"./process-routes\";\nimport { registerRequestsRoutes } from \"./requests-routes\";\nimport { registerRouteRoutes } from \"./route-routes\";\nimport { registerStreamRoute } from \"./stream-route\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\nimport { registerUiAssets } from \"./ui-assets\";\n\nexport type { DevtoolsRequestLogSource, DevtoolsRouteRow, MountDevtoolsRoutesDeps } from \"./types\";\n\n/**\n * Mounts the devtools dashboard and its API under `deps.options.path` on\n * `server`. Every route is registered inside a single encapsulated Fastify\n * context so the dev-only, loopback-only guard never reaches the app's\n * other routes.\n */\nexport function mountDevtoolsRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.register(\n async (instance) => {\n registerDevtoolsGuard(instance, deps);\n\n instance.setErrorHandler((error: FastifyError, _request, reply) => {\n reply.code(error.statusCode ?? 500).send({ error: error.message });\n });\n\n registerUiAssets(instance);\n registerRequestsRoutes(instance, deps);\n registerAiRoutes(instance, deps);\n registerBackgroundRoutes(instance, deps);\n registerMailRoutes(instance, deps);\n registerLogRoutes(instance, deps);\n registerRouteRoutes(instance, deps);\n registerProcessRoutes(instance, deps);\n registerOpenApiRoutes(instance, deps);\n registerExplainRoute(instance, deps);\n registerStreamRoute(instance, deps);\n },\n { prefix: deps.options.path },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAAoB,QAAyB,MAAqC;CAChG,OAAO,SACL,OAAO,aAAa;EAClB,sBAAsB,UAAU,IAAI;EAEpC,SAAS,iBAAiB,OAAqB,UAAU,UAAU;GACjE,MAAM,KAAK,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,MAAM,QAAQ,CAAC;EACnE,CAAC;EAED,iBAAiB,QAAQ;EACzB,uBAAuB,UAAU,IAAI;EACrC,iBAAiB,UAAU,IAAI;EAC/B,yBAAyB,UAAU,IAAI;EACvC,mBAAmB,UAAU,IAAI;EACjC,kBAAkB,UAAU,IAAI;EAChC,oBAAoB,UAAU,IAAI;EAClC,sBAAsB,UAAU,IAAI;EACpC,sBAAsB,UAAU,IAAI;EACpC,qBAAqB,UAAU,IAAI;EACnC,oBAAoB,UAAU,IAAI;CACpC,GACA,EAAE,QAAQ,KAAK,QAAQ,KAAK,CAC9B;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/index.ts"],"sourcesContent":["import type { FastifyError, FastifyInstance } from \"fastify\";\nimport { checkDevtoolsPanels } from \"../panels\";\nimport { processesDevtoolsPanel } from \"../process-panel\";\nimport { registerAiRoutes } from \"./ai-routes\";\nimport { registerBackgroundRoutes } from \"./background-routes\";\nimport { registerExplainRoute } from \"./explain-route\";\nimport { registerDevtoolsGuard } from \"./guard\";\nimport { registerLogRoutes } from \"./log-routes\";\nimport { registerMailRoutes } from \"./mail-routes\";\nimport { registerOpenApiRoutes } from \"./openapi-routes\";\nimport { registerPanelRoutes } from \"./panel-routes\";\nimport { registerRequestsRoutes } from \"./requests-routes\";\nimport { registerRouteRoutes } from \"./route-routes\";\nimport { registerStreamRoute } from \"./stream-route\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\nimport { registerUiAssets } from \"./ui-assets\";\n\nexport type { DevtoolsRequestLogSource, DevtoolsRouteRow, MountDevtoolsRoutesDeps } from \"./types\";\n\n/**\n * Mounts the devtools dashboard and its API under `deps.options.path` on\n * `server`. Every route is registered inside a single encapsulated Fastify\n * context so the dev-only, loopback-only guard never reaches the app's\n * other routes — the registered panels' data routes and files included.\n *\n * Throws before mounting anything when a panel is invalid or reuses an id.\n */\nexport function mountDevtoolsRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n const panels = checkDevtoolsPanels([\n processesDevtoolsPanel(deps.processPanel),\n ...(deps.panels ?? []),\n ]);\n\n server.register(\n async (instance) => {\n registerDevtoolsGuard(instance, deps);\n\n instance.setErrorHandler((error: FastifyError, _request, reply) => {\n reply.code(error.statusCode ?? 500).send({ error: error.message });\n });\n\n registerUiAssets(instance, panels);\n registerRequestsRoutes(instance, deps);\n registerAiRoutes(instance, deps);\n registerBackgroundRoutes(instance, deps);\n registerMailRoutes(instance, deps);\n registerLogRoutes(instance, deps);\n registerRouteRoutes(instance, deps);\n registerPanelRoutes(instance, panels);\n registerOpenApiRoutes(instance, deps);\n registerExplainRoute(instance, deps);\n registerStreamRoute(instance, deps);\n },\n { prefix: deps.options.path },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,oBAAoB,QAAyB,MAAqC;CAChG,MAAM,SAAS,oBAAoB,CACjC,uBAAuB,KAAK,YAAY,GACxC,GAAI,KAAK,UAAU,CAAC,CACtB,CAAC;CAED,OAAO,SACL,OAAO,aAAa;EAClB,sBAAsB,UAAU,IAAI;EAEpC,SAAS,iBAAiB,OAAqB,UAAU,UAAU;GACjE,MAAM,KAAK,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,MAAM,QAAQ,CAAC;EACnE,CAAC;EAED,iBAAiB,UAAU,MAAM;EACjC,uBAAuB,UAAU,IAAI;EACrC,iBAAiB,UAAU,IAAI;EAC/B,yBAAyB,UAAU,IAAI;EACvC,mBAAmB,UAAU,IAAI;EACjC,kBAAkB,UAAU,IAAI;EAChC,oBAAoB,UAAU,IAAI;EAClC,oBAAoB,UAAU,MAAM;EACpC,sBAAsB,UAAU,IAAI;EACpC,qBAAqB,UAAU,IAAI;EACnC,oBAAoB,UAAU,IAAI;CACpC,GACA,EAAE,QAAQ,KAAK,QAAQ,KAAK,CAC9B;AACF"}
@@ -0,0 +1,44 @@
1
+ import { panelContentType } from "../panels.mjs";
2
+ import { sendFile } from "./ui-assets.mjs";
3
+
4
+ //#region ../../packages/devtools/src/server/panel-routes.ts
5
+ /**
6
+ * Mounts each panel's data routes at `/api/<id><route path>` and its view
7
+ * module and assets at `/panels/<id>/<name>`. Callers register this inside
8
+ * the devtools scope, so the guard covers every one of them. A file is
9
+ * served only when its name is listed by the panel; the request never
10
+ * becomes a filesystem path.
11
+ */
12
+ function registerPanelRoutes(server, panels) {
13
+ const byId = new Map(panels.map((panel) => [panel.id, panel]));
14
+ for (const panel of panels) for (const route of panel.routes) server.route({
15
+ method: route.method,
16
+ url: `/api/${panel.id}${route.path}`,
17
+ handler: async (request, reply) => {
18
+ const input = {
19
+ params: request.params ?? {},
20
+ query: request.query ?? {},
21
+ body: request.body
22
+ };
23
+ const result = await route.handler(input);
24
+ reply.header("cache-control", "no-store");
25
+ if (result === void 0) return reply.code(204).send();
26
+ return result;
27
+ }
28
+ });
29
+ server.get("/panels/:id/:name", (request, reply) => {
30
+ const panel = byId.get(request.params.id);
31
+ const name = request.params.name;
32
+ const file = panel === void 0 ? void 0 : name === "view.js" ? panel.view : Object.hasOwn(panel.assets, name) ? panel.assets[name] : void 0;
33
+ if (file === void 0) {
34
+ reply.code(404).header("Cache-Control", "no-store").send();
35
+ return;
36
+ }
37
+ reply.header("X-Content-Type-Options", "nosniff");
38
+ sendFile(reply, file, panelContentType(name));
39
+ });
40
+ }
41
+
42
+ //#endregion
43
+ export { registerPanelRoutes };
44
+ //# sourceMappingURL=panel-routes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel-routes.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/panel-routes.ts"],"sourcesContent":["import type { FastifyInstance } from \"fastify\";\nimport { type MountedDevtoolsPanel, panelContentType } from \"../panels\";\nimport type { DevtoolsPanelRequest } from \"../types\";\nimport { sendFile } from \"./ui-assets\";\n\n/**\n * Mounts each panel's data routes at `/api/<id><route path>` and its view\n * module and assets at `/panels/<id>/<name>`. Callers register this inside\n * the devtools scope, so the guard covers every one of them. A file is\n * served only when its name is listed by the panel; the request never\n * becomes a filesystem path.\n */\nexport function registerPanelRoutes(\n server: FastifyInstance,\n panels: readonly MountedDevtoolsPanel[],\n): void {\n const byId = new Map(panels.map((panel) => [panel.id, panel]));\n\n for (const panel of panels) {\n for (const route of panel.routes) {\n server.route({\n method: route.method,\n url: `/api/${panel.id}${route.path}`,\n handler: async (request, reply) => {\n const input: DevtoolsPanelRequest = {\n params: (request.params ?? {}) as Record<string, string>,\n query: (request.query ?? {}) as Record<string, string | string[]>,\n body: request.body,\n };\n const result = await route.handler(input);\n\n reply.header(\"cache-control\", \"no-store\");\n\n if (result === undefined) return reply.code(204).send();\n\n return result;\n },\n });\n }\n }\n\n server.get<{ Params: { id: string; name: string } }>(\"/panels/:id/:name\", (request, reply) => {\n const panel = byId.get(request.params.id);\n const name = request.params.name;\n const file =\n panel === undefined\n ? undefined\n : name === \"view.js\"\n ? panel.view\n : Object.hasOwn(panel.assets, name)\n ? panel.assets[name]\n : undefined;\n\n if (file === undefined) {\n reply.code(404).header(\"Cache-Control\", \"no-store\").send();\n return;\n }\n\n reply.header(\"X-Content-Type-Options\", \"nosniff\");\n sendFile(reply, file, panelContentType(name));\n });\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,oBACd,QACA,QACM;CACN,MAAM,OAAO,IAAI,IAAI,OAAO,KAAK,UAAU,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;CAE7D,KAAK,MAAM,SAAS,QAClB,KAAK,MAAM,SAAS,MAAM,QACxB,OAAO,MAAM;EACX,QAAQ,MAAM;EACd,KAAK,QAAQ,MAAM,KAAK,MAAM;EAC9B,SAAS,OAAO,SAAS,UAAU;GACjC,MAAM,QAA8B;IAClC,QAAS,QAAQ,UAAU,CAAC;IAC5B,OAAQ,QAAQ,SAAS,CAAC;IAC1B,MAAM,QAAQ;GAChB;GACA,MAAM,SAAS,MAAM,MAAM,QAAQ,KAAK;GAExC,MAAM,OAAO,iBAAiB,UAAU;GAExC,IAAI,WAAW,QAAW,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;GAEtD,OAAO;EACT;CACF,CAAC;CAIL,OAAO,IAA8C,sBAAsB,SAAS,UAAU;EAC5F,MAAM,QAAQ,KAAK,IAAI,QAAQ,OAAO,EAAE;EACxC,MAAM,OAAO,QAAQ,OAAO;EAC5B,MAAM,OACJ,UAAU,SACN,SACA,SAAS,YACP,MAAM,OACN,OAAO,OAAO,MAAM,QAAQ,IAAI,IAC9B,MAAM,OAAO,QACb;EAEV,IAAI,SAAS,QAAW;GACtB,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,iBAAiB,UAAU,CAAC,CAAC,KAAK;GACzD;EACF;EAEA,MAAM,OAAO,0BAA0B,SAAS;EAChD,SAAS,OAAO,MAAM,iBAAiB,IAAI,CAAC;CAC9C,CAAC;AACH"}
@@ -1,8 +1,10 @@
1
1
  import { resolveUiRoot } from "../ui-root.mjs";
2
- import path from "node:path";
3
2
  import { readFileSync } from "node:fs";
3
+ import path from "node:path";
4
4
 
5
5
  //#region ../../packages/devtools/src/server/ui-assets.ts
6
+ /** Where `index.html` takes the registered panels' tab buttons. */
7
+ const PANEL_TABS_MARKER = "<!-- devtools:panel-tabs -->";
6
8
  const uiFile = (name) => () => path.join(resolveUiRoot(), name);
7
9
  /**
8
10
  * The only assets that can be requested. The request's asset name is looked
@@ -38,15 +40,26 @@ const UI_ASSETS = {
38
40
  function sendFile(reply, file, contentType) {
39
41
  reply.header("Cache-Control", "no-store").header("Content-Type", contentType).send(readFileSync(file));
40
42
  }
43
+ function escapeHtml(value) {
44
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;");
45
+ }
46
+ /** `index.html` with one tab button per registered panel, in registration order. */
47
+ function renderIndexHtml(html, panels) {
48
+ const buttons = panels.map((panel) => `<button class="tab" data-tab="${panel.id}" data-panel="${panel.id}">${escapeHtml(panel.title)}</button>`).join("\n ");
49
+ return html.replace(PANEL_TABS_MARKER, buttons);
50
+ }
41
51
  /**
42
- * Serves the static dashboard: `index.html` at the dashboard root and the
43
- * whitelisted assets (`app.js`, `app.css`, the vendored Scalar bundle as
44
- * `scalar.js`, and the vendored Swagger UI files plus their init script). The asset name is matched against a fixed whitelist — never
45
- * joined into a filesystem path — so no request can traverse outside it.
52
+ * Serves the static dashboard: `index.html` at the dashboard root (with a
53
+ * tab per registered panel) and the whitelisted assets (`app.js`, `app.css`,
54
+ * the vendored Scalar bundle as `scalar.js`, and the vendored Swagger UI
55
+ * files plus their init script). The asset name is matched against a fixed
56
+ * whitelist — never joined into a filesystem path — so no request can
57
+ * traverse outside it.
46
58
  */
47
- function registerUiAssets(server) {
59
+ function registerUiAssets(server, panels = []) {
48
60
  const serveIndex = (_request, reply) => {
49
- sendFile(reply, path.join(resolveUiRoot(), "index.html"), "text/html; charset=utf-8");
61
+ const html = readFileSync(path.join(resolveUiRoot(), "index.html"), "utf8");
62
+ reply.header("Cache-Control", "no-store").header("Content-Type", "text/html; charset=utf-8").send(renderIndexHtml(html, panels));
50
63
  };
51
64
  server.get("/", serveIndex);
52
65
  server.get("/assets/:name", (request, reply) => {
@@ -60,5 +73,5 @@ function registerUiAssets(server) {
60
73
  }
61
74
 
62
75
  //#endregion
63
- export { registerUiAssets, sendFile };
76
+ export { registerUiAssets, renderIndexHtml, sendFile };
64
77
  //# sourceMappingURL=ui-assets.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ui-assets.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/ui-assets.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { FastifyInstance, FastifyReply } from \"fastify\";\nimport { resolveUiRoot } from \"../ui-root\";\n\n/**\n * Where an asset's bytes come from: a file in this package's `ui/` folder.\n */\ntype UiAsset = {\n contentType: string;\n file: () => string;\n};\n\nconst uiFile = (name: string) => () => path.join(resolveUiRoot(), name);\n\n/**\n * The only assets that can be requested. The request's asset name is looked\n * up here and never joined into a filesystem path.\n */\nconst UI_ASSETS: Record<string, UiAsset> = {\n \"app.js\": { contentType: \"text/javascript; charset=utf-8\", file: uiFile(\"app.js\") },\n \"app.css\": { contentType: \"text/css; charset=utf-8\", file: uiFile(\"app.css\") },\n \"scalar.js\": {\n contentType: \"text/javascript; charset=utf-8\",\n file: uiFile(\"vendor/scalar/standalone.js\"),\n },\n \"swagger-ui-bundle.js\": {\n contentType: \"text/javascript; charset=utf-8\",\n file: uiFile(\"vendor/swagger-ui/swagger-ui-bundle.js\"),\n },\n \"swagger-ui.css\": {\n contentType: \"text/css; charset=utf-8\",\n file: uiFile(\"vendor/swagger-ui/swagger-ui.css\"),\n },\n \"docs-swagger.js\": {\n contentType: \"text/javascript; charset=utf-8\",\n file: uiFile(\"docs-swagger.js\"),\n },\n};\n\n/** Sends `file` with `contentType` and no caching. */\nexport function sendFile(reply: FastifyReply, file: string, contentType: string): void {\n reply\n .header(\"Cache-Control\", \"no-store\")\n .header(\"Content-Type\", contentType)\n .send(readFileSync(file));\n}\n\n/**\n * Serves the static dashboard: `index.html` at the dashboard root and the\n * whitelisted assets (`app.js`, `app.css`, the vendored Scalar bundle as\n * `scalar.js`, and the vendored Swagger UI files plus their init script). The asset name is matched against a fixed whitelist — never\n * joined into a filesystem path — so no request can traverse outside it.\n */\nexport function registerUiAssets(server: FastifyInstance): void {\n const serveIndex = (_request: unknown, reply: FastifyReply): void => {\n sendFile(reply, path.join(resolveUiRoot(), \"index.html\"), \"text/html; charset=utf-8\");\n };\n\n server.get(\"/\", serveIndex);\n\n server.get<{ Params: { name: string } }>(\"/assets/:name\", (request, reply) => {\n const asset = Object.hasOwn(UI_ASSETS, request.params.name)\n ? UI_ASSETS[request.params.name]\n : undefined;\n\n if (!asset) {\n reply.code(404).header(\"Cache-Control\", \"no-store\").send();\n return;\n }\n\n sendFile(reply, asset.file(), asset.contentType);\n });\n}\n"],"mappings":";;;;;AAaA,MAAM,UAAU,eAAuB,KAAK,KAAK,cAAc,GAAG,IAAI;;;;;AAMtE,MAAM,YAAqC;CACzC,UAAU;EAAE,aAAa;EAAkC,MAAM,OAAO,QAAQ;CAAE;CAClF,WAAW;EAAE,aAAa;EAA2B,MAAM,OAAO,SAAS;CAAE;CAC7E,aAAa;EACX,aAAa;EACb,MAAM,OAAO,6BAA6B;CAC5C;CACA,wBAAwB;EACtB,aAAa;EACb,MAAM,OAAO,wCAAwC;CACvD;CACA,kBAAkB;EAChB,aAAa;EACb,MAAM,OAAO,kCAAkC;CACjD;CACA,mBAAmB;EACjB,aAAa;EACb,MAAM,OAAO,iBAAiB;CAChC;AACF;;AAGA,SAAgB,SAAS,OAAqB,MAAc,aAA2B;CACrF,MACG,OAAO,iBAAiB,UAAU,CAAC,CACnC,OAAO,gBAAgB,WAAW,CAAC,CACnC,KAAK,aAAa,IAAI,CAAC;AAC5B;;;;;;;AAQA,SAAgB,iBAAiB,QAA+B;CAC9D,MAAM,cAAc,UAAmB,UAA8B;EACnE,SAAS,OAAO,KAAK,KAAK,cAAc,GAAG,YAAY,GAAG,0BAA0B;CACtF;CAEA,OAAO,IAAI,KAAK,UAAU;CAE1B,OAAO,IAAkC,kBAAkB,SAAS,UAAU;EAC5E,MAAM,QAAQ,OAAO,OAAO,WAAW,QAAQ,OAAO,IAAI,IACtD,UAAU,QAAQ,OAAO,QACzB;EAEJ,IAAI,CAAC,OAAO;GACV,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,iBAAiB,UAAU,CAAC,CAAC,KAAK;GACzD;EACF;EAEA,SAAS,OAAO,MAAM,KAAK,GAAG,MAAM,WAAW;CACjD,CAAC;AACH"}
1
+ {"version":3,"file":"ui-assets.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/ui-assets.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { FastifyInstance, FastifyReply } from \"fastify\";\nimport type { MountedDevtoolsPanel } from \"../panels\";\nimport { resolveUiRoot } from \"../ui-root\";\n\n/** Where `index.html` takes the registered panels' tab buttons. */\nconst PANEL_TABS_MARKER = \"<!-- devtools:panel-tabs -->\";\n\n/**\n * Where an asset's bytes come from: a file in this package's `ui/` folder.\n */\ntype UiAsset = {\n contentType: string;\n file: () => string;\n};\n\nconst uiFile = (name: string) => () => path.join(resolveUiRoot(), name);\n\n/**\n * The only assets that can be requested. The request's asset name is looked\n * up here and never joined into a filesystem path.\n */\nconst UI_ASSETS: Record<string, UiAsset> = {\n \"app.js\": { contentType: \"text/javascript; charset=utf-8\", file: uiFile(\"app.js\") },\n \"app.css\": { contentType: \"text/css; charset=utf-8\", file: uiFile(\"app.css\") },\n \"scalar.js\": {\n contentType: \"text/javascript; charset=utf-8\",\n file: uiFile(\"vendor/scalar/standalone.js\"),\n },\n \"swagger-ui-bundle.js\": {\n contentType: \"text/javascript; charset=utf-8\",\n file: uiFile(\"vendor/swagger-ui/swagger-ui-bundle.js\"),\n },\n \"swagger-ui.css\": {\n contentType: \"text/css; charset=utf-8\",\n file: uiFile(\"vendor/swagger-ui/swagger-ui.css\"),\n },\n \"docs-swagger.js\": {\n contentType: \"text/javascript; charset=utf-8\",\n file: uiFile(\"docs-swagger.js\"),\n },\n};\n\n/** Sends `file` with `contentType` and no caching. */\nexport function sendFile(reply: FastifyReply, file: string, contentType: string): void {\n reply\n .header(\"Cache-Control\", \"no-store\")\n .header(\"Content-Type\", contentType)\n .send(readFileSync(file));\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replaceAll(\"&\", \"&amp;\")\n .replaceAll(\"<\", \"&lt;\")\n .replaceAll(\">\", \"&gt;\")\n .replaceAll('\"', \"&quot;\");\n}\n\n/** `index.html` with one tab button per registered panel, in registration order. */\nexport function renderIndexHtml(html: string, panels: readonly MountedDevtoolsPanel[]): string {\n const buttons = panels\n .map(\n (panel) =>\n `<button class=\"tab\" data-tab=\"${panel.id}\" data-panel=\"${panel.id}\">${escapeHtml(panel.title)}</button>`,\n )\n .join(\"\\n \");\n\n return html.replace(PANEL_TABS_MARKER, buttons);\n}\n\n/**\n * Serves the static dashboard: `index.html` at the dashboard root (with a\n * tab per registered panel) and the whitelisted assets (`app.js`, `app.css`,\n * the vendored Scalar bundle as `scalar.js`, and the vendored Swagger UI\n * files plus their init script). The asset name is matched against a fixed\n * whitelist — never joined into a filesystem path — so no request can\n * traverse outside it.\n */\nexport function registerUiAssets(\n server: FastifyInstance,\n panels: readonly MountedDevtoolsPanel[] = [],\n): void {\n const serveIndex = (_request: unknown, reply: FastifyReply): void => {\n const html = readFileSync(path.join(resolveUiRoot(), \"index.html\"), \"utf8\");\n\n reply\n .header(\"Cache-Control\", \"no-store\")\n .header(\"Content-Type\", \"text/html; charset=utf-8\")\n .send(renderIndexHtml(html, panels));\n };\n\n server.get(\"/\", serveIndex);\n\n server.get<{ Params: { name: string } }>(\"/assets/:name\", (request, reply) => {\n const asset = Object.hasOwn(UI_ASSETS, request.params.name)\n ? UI_ASSETS[request.params.name]\n : undefined;\n\n if (!asset) {\n reply.code(404).header(\"Cache-Control\", \"no-store\").send();\n return;\n }\n\n sendFile(reply, asset.file(), asset.contentType);\n });\n}\n"],"mappings":";;;;;;AAOA,MAAM,oBAAoB;AAU1B,MAAM,UAAU,eAAuB,KAAK,KAAK,cAAc,GAAG,IAAI;;;;;AAMtE,MAAM,YAAqC;CACzC,UAAU;EAAE,aAAa;EAAkC,MAAM,OAAO,QAAQ;CAAE;CAClF,WAAW;EAAE,aAAa;EAA2B,MAAM,OAAO,SAAS;CAAE;CAC7E,aAAa;EACX,aAAa;EACb,MAAM,OAAO,6BAA6B;CAC5C;CACA,wBAAwB;EACtB,aAAa;EACb,MAAM,OAAO,wCAAwC;CACvD;CACA,kBAAkB;EAChB,aAAa;EACb,MAAM,OAAO,kCAAkC;CACjD;CACA,mBAAmB;EACjB,aAAa;EACb,MAAM,OAAO,iBAAiB;CAChC;AACF;;AAGA,SAAgB,SAAS,OAAqB,MAAc,aAA2B;CACrF,MACG,OAAO,iBAAiB,UAAU,CAAC,CACnC,OAAO,gBAAgB,WAAW,CAAC,CACnC,KAAK,aAAa,IAAI,CAAC;AAC5B;AAEA,SAAS,WAAW,OAAuB;CACzC,OAAO,MACJ,WAAW,KAAK,OAAO,CAAC,CACxB,WAAW,KAAK,MAAM,CAAC,CACvB,WAAW,KAAK,MAAM,CAAC,CACvB,WAAW,MAAK,QAAQ;AAC7B;;AAGA,SAAgB,gBAAgB,MAAc,QAAiD;CAC7F,MAAM,UAAU,OACb,KACE,UACC,iCAAiC,MAAM,GAAG,gBAAgB,MAAM,GAAG,IAAI,WAAW,MAAM,KAAK,EAAE,UACnG,CAAC,CACA,KAAK,YAAY;CAEpB,OAAO,KAAK,QAAQ,mBAAmB,OAAO;AAChD;;;;;;;;;AAUA,SAAgB,iBACd,QACA,SAA0C,CAAC,GACrC;CACN,MAAM,cAAc,UAAmB,UAA8B;EACnE,MAAM,OAAO,aAAa,KAAK,KAAK,cAAc,GAAG,YAAY,GAAG,MAAM;EAE1E,MACG,OAAO,iBAAiB,UAAU,CAAC,CACnC,OAAO,gBAAgB,0BAA0B,CAAC,CAClD,KAAK,gBAAgB,MAAM,MAAM,CAAC;CACvC;CAEA,OAAO,IAAI,KAAK,UAAU;CAE1B,OAAO,IAAkC,kBAAkB,SAAS,UAAU;EAC5E,MAAM,QAAQ,OAAO,OAAO,WAAW,QAAQ,OAAO,IAAI,IACtD,UAAU,QAAQ,OAAO,QACzB;EAEJ,IAAI,CAAC,OAAO;GACV,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,iBAAiB,UAAU,CAAC,CAAC,KAAK;GACzD;EACF;EAEA,SAAS,OAAO,MAAM,KAAK,GAAG,MAAM,WAAW;CACjD,CAAC;AACH"}
package/esm/types.d.mts CHANGED
@@ -50,9 +50,78 @@ export type DevtoolsOptions = {
50
50
  * @default false
51
51
  */
52
52
  allowProxied?: boolean;
53
+ /**
54
+ * Extra dashboard tabs. Each entry is a module specifier, loaded only in
55
+ * development, whose default export is a `DevtoolsPanelExport`: a package
56
+ * export such as `"@warlock.js/grimoire/devtools"` (resolved from the app
57
+ * root) or a path starting with `./` (relative to the app root). An entry
58
+ * may also be a `DevtoolsPanel` object.
59
+ *
60
+ * @default []
61
+ */
62
+ panels?: readonly (string | DevtoolsPanel)[];
53
63
  };
54
64
  /** `DevtoolsOptions` with every default applied. */
55
- export type ResolvedDevtoolsOptions = Required<Pick<DevtoolsOptions, "path" | "maxRequests" | "nPlusOneThreshold">> & Pick<DevtoolsOptions, "allowedHosts" | "allowProxied">;
65
+ export type ResolvedDevtoolsOptions = Required<Pick<DevtoolsOptions, "path" | "maxRequests" | "nPlusOneThreshold">> & Pick<DevtoolsOptions, "allowedHosts" | "allowProxied" | "panels">;
66
+ /** HTTP methods a panel data route may answer. */
67
+ export type DevtoolsPanelMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
68
+ /** What a panel data route handler receives. */
69
+ export type DevtoolsPanelRequest = {
70
+ /** Path parameters, e.g. `{ name: "checkout" }` for the route path `/flows/:name`. */
71
+ params: Readonly<Record<string, string>>;
72
+ /** Query string values; a key given more than once is an array. */
73
+ query: Readonly<Record<string, string | readonly string[]>>;
74
+ /** The parsed request body; `undefined` when there is none. */
75
+ body: unknown;
76
+ };
77
+ /**
78
+ * One data route of a panel, served at `<path>/api/<panel id><route path>`
79
+ * behind the devtools guard. The handler's return value is sent as JSON with
80
+ * `Cache-Control: no-store`; `undefined` sends `204`. A thrown error with a
81
+ * numeric `statusCode` answers that status with `{ error: message }`.
82
+ */
83
+ export type DevtoolsPanelRoute = {
84
+ /** @default "GET" */
85
+ method?: DevtoolsPanelMethod;
86
+ /** `""` for the panel's base URL, or a path starting with `/` (`"/search"`, `"/flows/:name"`). */
87
+ path: string;
88
+ handler: (request: DevtoolsPanelRequest) => unknown;
89
+ };
90
+ /**
91
+ * A dashboard tab added through the devtools `panels` option.
92
+ *
93
+ * The tab shows `title`. Clicking it loads `view`, a browser ES module that
94
+ * devtools serves at `<path>/panels/<id>/view.js`; its default export renders
95
+ * the panel and calls the panel's `routes`.
96
+ */
97
+ export type DevtoolsPanel = {
98
+ /** Lower-case letters, digits and dashes, starting with a letter. Names the tab, the URL segment and the hash route. */
99
+ id: string;
100
+ /** The tab label. */
101
+ title: string;
102
+ /** The view module: an absolute file path or a `file:` URL. */
103
+ view: string | URL;
104
+ /** Data routes the view calls. */
105
+ routes?: readonly DevtoolsPanelRoute[];
106
+ /**
107
+ * More files the view loads, by served name: `{ "graph.js": "/abs/graph.js" }`
108
+ * is served at `<path>/panels/<id>/graph.js`, so the view can
109
+ * `import "./graph.js"`. Names are plain file names (no folders).
110
+ */
111
+ assets?: Readonly<Record<string, string | URL>>;
112
+ };
113
+ /** What a panel factory receives. */
114
+ export type DevtoolsPanelFactoryContext = {
115
+ /** The app's root directory. */
116
+ root: string;
117
+ };
118
+ /** One panel or several. */
119
+ export type DevtoolsPanels = DevtoolsPanel | readonly DevtoolsPanel[];
120
+ /**
121
+ * The default export of a module listed in the devtools `panels` option: a
122
+ * panel, a list of panels, or a function (sync or async) that returns either.
123
+ */
124
+ export type DevtoolsPanelExport = DevtoolsPanels | ((context: DevtoolsPanelFactoryContext) => DevtoolsPanels | Promise<DevtoolsPanels>);
56
125
  /** A source file position, as shown next to an N+1 warning. */
57
126
  export type DevtoolsCallerLocation = {
58
127
  /** Absolute path, forward slashes. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../packages/devtools/src/types.ts"],"mappings":";;;;;;;;;;;;;YAcY;;;;;;EAMV;;;;;;EAMA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;YAIU,0BAA0B,SACpC,KAAK,kEAEL,KAAK;;YAGK;;EAEV;EACA;EACA;;;YAIU;EACV;EACA;EACA;EACA,QAAQ;;;YAIE;;EAEV;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;;;;;EAMA;;EAEA,SAAS;;;YAIC;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;;YAIU;EACV;EACA;EACA;EACA;EACA;;EAEA;;;YAIU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS;EACT,aAAa;;;YAIH;EACV;EACA;EACA;;;YAIU;EACV;EACA;EACA;EACA;EACA,SAAS;;;YAIC;;EAEV;EACA;EACA;;EAEA;EACA;EACA;;EAEA;EACA;EACA,QAAQ;EACR,SAAS;EACT,OAAO;EACP,MAAM;;EAEN;EACA,UAAU;;;YAIA;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;;;;;;YAQU,wBAAwB;EAClC;EACA,SAAS;;;YAIC;EACV;EACA;EACA;EACA;EACA;;;;;;YAOU;EACV,SAAS;EACT,OAAO;EACP,MAAM;;;YAII;EACN;EAAiB,MAAM;;EACvB;EAAc,MAAM;;EACpB;EAAa,MAAM;;EACnB;EAAY,MAAM;;EAClB;EAAqB,MAAM;;;YAGrB;;;;;;YAOA;EACV,aAAa;IACX;IACA;IACA;IACA;IACA;;;EAGF,WACE,YACA;IAAU;IAAiB;IAAoB;IAAgB;;EAEjE,SAAS,mBAAmB,OAAO;;EAEnC,SACE,+BACA,OAAO,KAAK,iCACX;EACH,kBAAkB,+BAA+B,WAAW;EAC5D,OAAO,+BAA+B,OAAO;EAC7C,QAAQ,MAAM;EACd,gBAAgB;EAChB,WAAW,aAAa;EACxB,aAAa;EACb,QAAQ,aAAa;EACrB,SAAS;IAAW,QAAQ;IAA2B;MAAoB;EAC3E,iBAAiB;EACjB,UAAU,WAAW,OAAO,+BAA+B;EAC3D"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../packages/devtools/src/types.ts"],"mappings":";;;;;;;;;;;;;YAcY;;;;;;EAMV;;;;;;EAMA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;;;;;;;EAUA,4BAA4B;;;YAIlB,0BAA0B,SACpC,KAAK,kEAEL,KAAK;;YAGK;;YAGA;;EAEV,QAAQ,SAAS;;EAEjB,OAAO,SAAS;;EAEhB;;;;;;;;YASU;;EAEV,SAAS;;EAET;EACA,UAAU,SAAS;;;;;;;;;YAUT;;EAEV;;EAEA;;EAEA,eAAe;;EAEf,kBAAkB;;;;;;EAMlB,SAAS,SAAS,wBAAwB;;;YAIhC;;EAEV;;;YAIU,iBAAiB,yBAAyB;;;;;YAM1C,sBACR,mBACE,SAAS,gCAAgC,iBAAiB,QAAQ;;YAG5D;;EAEV;EACA;EACA;;;YAIU;EACV;EACA;EACA;EACA,QAAQ;;;YAIE;;EAEV;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;;;;;EAMA;;EAEA,SAAS;;;YAIC;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;;YAIU;EACV;EACA;EACA;EACA;EACA;;EAEA;;;YAIU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS;EACT,aAAa;;;YAIH;EACV;EACA;EACA;;;YAIU;EACV;EACA;EACA;EACA;EACA,SAAS;;;YAIC;;EAEV;EACA;EACA;;EAEA;EACA;EACA;;EAEA;EACA;EACA,QAAQ;EACR,SAAS;EACT,OAAO;EACP,MAAM;;EAEN;EACA,UAAU;;;YAIA;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;;;;;;YAQU,wBAAwB;EAClC;EACA,SAAS;;;YAIC;EACV;EACA;EACA;EACA;EACA;;;;;;YAOU;EACV,SAAS;EACT,OAAO;EACP,MAAM;;;YAII;EACN;EAAiB,MAAM;;EACvB;EAAc,MAAM;;EACpB;EAAa,MAAM;;EACnB;EAAY,MAAM;;EAClB;EAAqB,MAAM;;;YAGrB;;;;;;YAOA;EACV,aAAa;IACX;IACA;IACA;IACA;IACA;;;EAGF,WACE,YACA;IAAU;IAAiB;IAAoB;IAAgB;;EAEjE,SAAS,mBAAmB,OAAO;;EAEnC,SACE,+BACA,OAAO,KAAK,iCACX;EACH,kBAAkB,+BAA+B,WAAW;EAC5D,OAAO,+BAA+B,OAAO;EAC7C,QAAQ,MAAM;EACd,gBAAgB;EAChB,WAAW,aAAa;EACxB,aAAa;EACb,QAAQ,aAAa;EACrB,SAAS;IAAW,QAAQ;IAA2B;MAAoB;EAC3E,iBAAiB;EACjB,UAAU,WAAW,OAAO,+BAA+B;EAC3D"}
package/esm/ui-root.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { fileURLToPath } from "node:url";
2
- import path from "node:path";
3
1
  import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
4
 
5
5
  //#region ../../packages/devtools/src/ui-root.ts
6
6
  let cachedUiRoot;
package/llms-full.txt CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ---
10
10
  name: warlock-js-devtools
11
- description: 'Development dashboard for Warlock apps via `devtoolsConnector`. Inspect request timelines, middleware, validation, queries, N+1 warnings, logs, cache, mail, AI runs, routes and configuration. Use for "debug a slow endpoint", "inspect this request", "view captured mail" or "open devtools". Not this package → @warlock.js/core for `warlock trace`, CLI route inspection and OpenAPI; @warlock.js/ai-panoptic for AI tracing.'
11
+ description: 'Development dashboard for Warlock apps via `devtoolsConnector`. Inspect request timelines, middleware, validation, queries, N+1 warnings, logs, cache, mail, AI runs, routes and configuration. Use for "debug a slow endpoint", "inspect this request", "view captured mail", "open devtools" or "add a devtools panel". Not this package → @warlock.js/core for `warlock trace`, CLI route inspection and OpenAPI; @warlock.js/ai-panoptic for AI tracing.'
12
12
  ---
13
13
 
14
14
  # `@warlock.js/devtools` — overview
@@ -233,4 +233,55 @@ endpoint retains development/loopback guards and provides no stop action.
233
233
  Use the `warlock-js-process` skill for launch,
234
234
  recovery and stop APIs; configure one owner/registry per application instance.
235
235
 
236
+ ## Registering a panel
237
+
238
+ A package or the app adds a tab with one line in `src/config/devtools.ts`:
239
+
240
+ ```ts
241
+ export default {
242
+ panels: ["@acme/queue/devtools"], // or "./src/devtools/queue-panel.ts"
243
+ };
244
+ ```
245
+
246
+ Devtools imports each entry only in development (a package export resolves
247
+ from the app root, a `./` path is relative to it). The module's default export
248
+ is a `DevtoolsPanelExport`: a `DevtoolsPanel`, a list, or a function (sync or
249
+ async) receiving `{ root }` that returns either. Use `import type` so the
250
+ module never needs devtools at runtime.
251
+
252
+ ```ts
253
+ import type { DevtoolsPanelExport } from "@warlock.js/devtools";
254
+
255
+ const queuePanel: DevtoolsPanelExport = ({ root }) => ({
256
+ id: "queue", // lower-case letters, digits, dashes
257
+ title: "Queue", // the tab label
258
+ view: new URL("./queue-view.js", import.meta.url), // served at /__warlock/panels/queue/view.js
259
+ assets: { "chart.js": new URL("./queue-chart.js", import.meta.url) }, // /__warlock/panels/queue/chart.js
260
+ routes: [
261
+ { path: "", handler: () => ({ root, jobs: [] }) }, // GET /__warlock/api/queue
262
+ { path: "/jobs/:id", handler: ({ params }) => ({ id: params.id }) },
263
+ { method: "POST", path: "/retry", handler: ({ body }) => ({ retried: body }) },
264
+ ],
265
+ });
266
+
267
+ export default queuePanel;
268
+ ```
269
+
270
+ - A handler (`DevtoolsPanelRoute`) receives a `DevtoolsPanelRequest`
271
+ (`{ params, query, body }`); its return value is sent as JSON with
272
+ `Cache-Control: no-store`, `undefined` sends `204`, and a thrown error with a
273
+ `statusCode` answers that status with `{ error: message }`.
274
+ - The view module is browser JavaScript. Its default export receives
275
+ `{ id, root, api, route, href, navigate, refresh, asset, el, svg, empty }`
276
+ and fills `root` or returns an element. `api("search?q=a")` fetches
277
+ `api/<id>/search?q=a` as JSON; `href("jobs/7")` is `#queue/jobs/7`, a link
278
+ that opens that view (`route` is then `"jobs/7"`); `svg()` builds SVG
279
+ elements for small graphs. Build text with `text`, never `innerHTML`.
280
+ - Every panel route, view and asset sits behind the devtools guard
281
+ (development only, loopback socket and host, no foreign `Origin`, no proxy
282
+ headers). A reused id (the built-in `processes` included) or a dashboard id
283
+ such as `mail` is refused; devtools logs why and leaves the panel out.
284
+
285
+ Full reference: the "Registering a panel" page of the devtools docs.
286
+
236
287
 
package/llms.txt CHANGED
@@ -6,4 +6,4 @@
6
6
 
7
7
  ## Skills
8
8
 
9
- - [devtools](@warlock.js/devtools/skills/SKILL.md): Development dashboard for Warlock apps via `devtoolsConnector`. Inspect request timelines, middleware, validation, queries, N+1 warnings, logs, cache, mail, AI runs, routes and configuration. Use for "debug a slow endpoint", "inspect this request", "view captured mail" or "open devtools". Not this package → @warlock.js/core for `warlock trace`, CLI route inspection and OpenAPI; @warlock.js/ai-panoptic for AI tracing.
9
+ - [devtools](@warlock.js/devtools/skills/SKILL.md): Development dashboard for Warlock apps via `devtoolsConnector`. Inspect request timelines, middleware, validation, queries, N+1 warnings, logs, cache, mail, AI runs, routes and configuration. Use for "debug a slow endpoint", "inspect this request", "view captured mail", "open devtools" or "add a devtools panel". Not this package → @warlock.js/core for `warlock trace`, CLI route inspection and OpenAPI; @warlock.js/ai-panoptic for AI tracing.
package/package.json CHANGED
@@ -5,11 +5,11 @@
5
5
  "environment": "server"
6
6
  },
7
7
  "peerDependencies": {
8
- "@warlock.js/ai-panoptic": "5.54.0",
9
- "@warlock.js/cache": "5.54.0",
10
- "@warlock.js/cascade": "5.54.0",
11
- "@warlock.js/core": "5.54.0",
12
- "@warlock.js/logger": "5.54.0"
8
+ "@warlock.js/ai-panoptic": "5.55.0",
9
+ "@warlock.js/cache": "5.55.0",
10
+ "@warlock.js/cascade": "5.55.0",
11
+ "@warlock.js/core": "5.55.0",
12
+ "@warlock.js/logger": "5.55.0"
13
13
  },
14
14
  "peerDependenciesMeta": {
15
15
  "@warlock.js/ai-panoptic": {
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "author": "hassanzohdy",
40
40
  "license": "MIT",
41
- "version": "5.54.0",
41
+ "version": "5.55.0",
42
42
  "main": "./cjs/index.cjs",
43
43
  "module": "./esm/index.mjs",
44
44
  "types": "./esm/index.d.mts",
package/skills/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: warlock-js-devtools
3
- description: 'Development dashboard for Warlock apps via `devtoolsConnector`. Inspect request timelines, middleware, validation, queries, N+1 warnings, logs, cache, mail, AI runs, routes and configuration. Use for "debug a slow endpoint", "inspect this request", "view captured mail" or "open devtools". Not this package → @warlock.js/core for `warlock trace`, CLI route inspection and OpenAPI; @warlock.js/ai-panoptic for AI tracing.'
3
+ description: 'Development dashboard for Warlock apps via `devtoolsConnector`. Inspect request timelines, middleware, validation, queries, N+1 warnings, logs, cache, mail, AI runs, routes and configuration. Use for "debug a slow endpoint", "inspect this request", "view captured mail", "open devtools" or "add a devtools panel". Not this package → @warlock.js/core for `warlock trace`, CLI route inspection and OpenAPI; @warlock.js/ai-panoptic for AI tracing.'
4
4
  ---
5
5
 
6
6
  # `@warlock.js/devtools` — overview
@@ -224,3 +224,54 @@ It excludes ownership tokens. Without registration the list is empty. The
224
224
  endpoint retains development/loopback guards and provides no stop action.
225
225
  Use the `warlock-js-process` skill for launch,
226
226
  recovery and stop APIs; configure one owner/registry per application instance.
227
+
228
+ ## Registering a panel
229
+
230
+ A package or the app adds a tab with one line in `src/config/devtools.ts`:
231
+
232
+ ```ts
233
+ export default {
234
+ panels: ["@acme/queue/devtools"], // or "./src/devtools/queue-panel.ts"
235
+ };
236
+ ```
237
+
238
+ Devtools imports each entry only in development (a package export resolves
239
+ from the app root, a `./` path is relative to it). The module's default export
240
+ is a `DevtoolsPanelExport`: a `DevtoolsPanel`, a list, or a function (sync or
241
+ async) receiving `{ root }` that returns either. Use `import type` so the
242
+ module never needs devtools at runtime.
243
+
244
+ ```ts
245
+ import type { DevtoolsPanelExport } from "@warlock.js/devtools";
246
+
247
+ const queuePanel: DevtoolsPanelExport = ({ root }) => ({
248
+ id: "queue", // lower-case letters, digits, dashes
249
+ title: "Queue", // the tab label
250
+ view: new URL("./queue-view.js", import.meta.url), // served at /__warlock/panels/queue/view.js
251
+ assets: { "chart.js": new URL("./queue-chart.js", import.meta.url) }, // /__warlock/panels/queue/chart.js
252
+ routes: [
253
+ { path: "", handler: () => ({ root, jobs: [] }) }, // GET /__warlock/api/queue
254
+ { path: "/jobs/:id", handler: ({ params }) => ({ id: params.id }) },
255
+ { method: "POST", path: "/retry", handler: ({ body }) => ({ retried: body }) },
256
+ ],
257
+ });
258
+
259
+ export default queuePanel;
260
+ ```
261
+
262
+ - A handler (`DevtoolsPanelRoute`) receives a `DevtoolsPanelRequest`
263
+ (`{ params, query, body }`); its return value is sent as JSON with
264
+ `Cache-Control: no-store`, `undefined` sends `204`, and a thrown error with a
265
+ `statusCode` answers that status with `{ error: message }`.
266
+ - The view module is browser JavaScript. Its default export receives
267
+ `{ id, root, api, route, href, navigate, refresh, asset, el, svg, empty }`
268
+ and fills `root` or returns an element. `api("search?q=a")` fetches
269
+ `api/<id>/search?q=a` as JSON; `href("jobs/7")` is `#queue/jobs/7`, a link
270
+ that opens that view (`route` is then `"jobs/7"`); `svg()` builds SVG
271
+ elements for small graphs. Build text with `text`, never `innerHTML`.
272
+ - Every panel route, view and asset sits behind the devtools guard
273
+ (development only, loopback socket and host, no foreign `Origin`, no proxy
274
+ headers). A reused id (the built-in `processes` included) or a dashboard id
275
+ such as `mail` is refused; devtools logs why and leaves the panel out.
276
+
277
+ Full reference: the "Registering a panel" page of the devtools docs.
package/ui/app.js CHANGED
@@ -3,6 +3,8 @@ if (!location.pathname.endsWith("/"))
3
3
 
4
4
  const app = document.querySelector("#app");
5
5
  const tabs = document.querySelectorAll(".tab");
6
+ /** Ids of the registered panels: the server renders their tab buttons with `data-panel`. */
7
+ const panelIds = new Set(Array.from(tabs, (button) => button.dataset?.panel).filter(Boolean));
6
8
  const state = {
7
9
  tab: "requests",
8
10
  requests: [],
@@ -61,11 +63,16 @@ function sql(query) {
61
63
  function canExplain(query) {
62
64
  return query.driver === "postgres" && /^(select|with)\b/i.test((query.sql || "").trim());
63
65
  }
64
- function setTab(tab) {
66
+ function showTab(tab) {
65
67
  state.tab = tab;
66
68
  tabs.forEach((button) => button.classList.toggle("is-active", button.dataset.tab === tab));
67
69
  render();
68
70
  }
71
+ function setTab(tab) {
72
+ // A tab click opens the tab's first view, so a panel's hash route is dropped.
73
+ if (hashPanel()) history.replaceState(null, "", location.pathname + location.search);
74
+ showTab(tab);
75
+ }
69
76
 
70
77
  function requestRow(request, selected) {
71
78
  const status = request.status == null ? "—" : String(request.status);
@@ -977,16 +984,110 @@ function apiView() {
977
984
 
978
985
  let renderVersion = 0;
979
986
 
980
- async function processesView() {
981
- const rows = await api("api/processes");
982
- const section = el("section", { class: "card detail" }, [el("h2", { text: "Processes" })]);
983
- section.append(el("button", { text: "Refresh", onclick: () => render() }));
984
- if (!rows.length)
985
- section.append(empty("No supervised processes. Configure with warlock add process."));
986
- for (const row of rows) {
987
- section.append(el("pre", { text: JSON.stringify(row, null, 2) }));
987
+ const SVG_NS = "http://www.w3.org/2000/svg";
988
+
989
+ /** Like `el()`, for SVG elements (graphs drawn by panels). */
990
+ function svg(tag, attrs = {}, children = []) {
991
+ const node = document.createElementNS(SVG_NS, tag);
992
+ for (const [key, attr] of Object.entries(attrs)) {
993
+ if (attr == null) continue;
994
+ if (key === "text") node.textContent = attr;
995
+ else if (key.startsWith("on")) node.addEventListener(key.slice(2), attr);
996
+ else node.setAttribute(key, attr);
988
997
  }
989
- return section;
998
+ for (const child of Array.isArray(children) ? children : [children]) node.append(child);
999
+ return node;
1000
+ }
1001
+
1002
+ /** A panel's data URL: `""`, `"search?q=x"`, `"/flows/a"` and `"?page=2"` all resolve under `api/<id>`. */
1003
+ function panelApiUrl(id, path = "") {
1004
+ const suffix = !path || path.startsWith("/") || path.startsWith("?") ? path : `/${path}`;
1005
+ return `api/${id}${suffix}`;
1006
+ }
1007
+
1008
+ /** The link to one of a panel's views: `#<id>` or `#<id>/<route>`. */
1009
+ function panelHref(id, route = "") {
1010
+ return `#${id}${route ? `/${route}` : ""}`;
1011
+ }
1012
+
1013
+ /** The panel that owns the location hash, if any. */
1014
+ function hashPanel() {
1015
+ const owner = location.hash.slice(1).split("/")[0];
1016
+ return panelIds.has(owner) ? owner : undefined;
1017
+ }
1018
+
1019
+ /** The panel's part of the hash, as written: `#grimoire/flow/checkout` gives `flow/checkout`. */
1020
+ function panelRoute(id) {
1021
+ const hash = location.hash.slice(1);
1022
+ return hash.startsWith(`${id}/`) ? hash.slice(id.length + 1) : "";
1023
+ }
1024
+
1025
+ function panelTitle(id) {
1026
+ return (
1027
+ Array.from(tabs)
1028
+ .find((button) => button.dataset?.panel === id)
1029
+ ?.textContent?.trim() || id
1030
+ );
1031
+ }
1032
+
1033
+ const panelModules = new Map();
1034
+
1035
+ /** Imports a panel's view module once per page load; a failed import is retried next time. */
1036
+ function loadPanelModule(id) {
1037
+ if (!panelModules.has(id)) {
1038
+ const loading = import(new URL(`panels/${id}/view.js`, location.href).href);
1039
+ loading.catch(() => panelModules.delete(id));
1040
+ panelModules.set(id, loading);
1041
+ }
1042
+ return panelModules.get(id);
1043
+ }
1044
+
1045
+ /** What a panel's view module receives; see the devtools docs on registering a panel. */
1046
+ function panelContext(id, root) {
1047
+ return {
1048
+ id,
1049
+ root,
1050
+ route: panelRoute(id),
1051
+ api: (path, init) => api(panelApiUrl(id, path), init),
1052
+ asset: (name) => `panels/${id}/${name}`,
1053
+ href: (route) => panelHref(id, route),
1054
+ navigate(route) {
1055
+ const next = panelHref(id, route);
1056
+ if (location.hash === next) render();
1057
+ else location.hash = next;
1058
+ },
1059
+ refresh: () => render(),
1060
+ el,
1061
+ svg,
1062
+ empty,
1063
+ };
1064
+ }
1065
+
1066
+ async function panelView(id) {
1067
+ let module;
1068
+ try {
1069
+ module = await loadPanelModule(id);
1070
+ } catch (error) {
1071
+ throw new Error(
1072
+ `the ${panelTitle(id)} panel's view module did not load (${error.message}). Check the terminal running warlock dev.`,
1073
+ { cause: error },
1074
+ );
1075
+ }
1076
+ if (typeof module?.default !== "function")
1077
+ throw new Error(`the ${panelTitle(id)} panel's view module has no default export function.`);
1078
+ const root = el("section", { class: "panel", "data-panel": id });
1079
+ return (await module.default(panelContext(id, root))) ?? root;
1080
+ }
1081
+
1082
+ /**
1083
+ * A panel link (`#<id>/<route>`), typed, followed or reached with Back, opens
1084
+ * that panel view; Back to an address without one shows the open panel's
1085
+ * first view again.
1086
+ */
1087
+ function onHashChange() {
1088
+ const panel = hashPanel();
1089
+ if (panel) showTab(panel);
1090
+ else if (panelIds.has(state.tab)) render();
990
1091
  }
991
1092
 
992
1093
  async function render() {
@@ -1007,8 +1108,8 @@ async function render() {
1007
1108
  ? await logsView()
1008
1109
  : state.tab === "routes"
1009
1110
  ? await routesView()
1010
- : state.tab === "processes"
1011
- ? await processesView()
1111
+ : panelIds.has(state.tab)
1112
+ ? await panelView(state.tab)
1012
1113
  : apiView();
1013
1114
  if (version === renderVersion) app.replaceChildren(view);
1014
1115
  } catch (error) {
@@ -1051,4 +1152,7 @@ for (const type of ["request", "mail", "log", "ai", "agent-trace"])
1051
1152
  /* malformed stream data is ignored */
1052
1153
  }
1053
1154
  });
1054
- render();
1155
+ window.addEventListener("hashchange", onHashChange);
1156
+ const startPanel = hashPanel();
1157
+ if (startPanel) showTab(startPanel);
1158
+ else render();
package/ui/index.html CHANGED
@@ -17,7 +17,7 @@
17
17
  <button class="tab" data-tab="mail">Mail</button>
18
18
  <button class="tab" data-tab="logs">Logs</button>
19
19
  <button class="tab" data-tab="routes">Routes</button>
20
- <button class="tab" data-tab="processes">Processes</button>
20
+ <!-- devtools:panel-tabs -->
21
21
  <button class="tab" data-tab="api">API</button>
22
22
  </nav>
23
23
  <button id="clear" class="clear" type="button">Clear</button>