@warlock.js/devtools 5.55.0 → 5.57.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.
- package/CHANGELOG.md +52 -0
- package/README.md +26 -13
- package/cjs/ai-source-DTpxumMA.cjs +381 -0
- package/cjs/ai-source-DTpxumMA.cjs.map +1 -0
- package/cjs/auth-DzU0gHDG.cjs +1655 -0
- package/cjs/auth-DzU0gHDG.cjs.map +1 -0
- package/cjs/boot-Dy5OqgTM.cjs +138 -0
- package/cjs/boot-Dy5OqgTM.cjs.map +1 -0
- package/cjs/capture-CqIiaznN.cjs +1342 -0
- package/cjs/capture-CqIiaznN.cjs.map +1 -0
- package/cjs/cascade-store-pHjKeSFm.cjs +863 -0
- package/cjs/cascade-store-pHjKeSFm.cjs.map +1 -0
- package/cjs/collector-CJbQbzzK.cjs +271 -0
- package/cjs/collector-CJbQbzzK.cjs.map +1 -0
- package/cjs/contracts-CVmplkNb.cjs +112 -0
- package/cjs/contracts-CVmplkNb.cjs.map +1 -0
- package/cjs/current-request-id-BoJJb3y7.cjs +37 -0
- package/cjs/current-request-id-BoJJb3y7.cjs.map +1 -0
- package/cjs/errors-CyZp5yS-.cjs +177 -0
- package/cjs/errors-CyZp5yS-.cjs.map +1 -0
- package/cjs/histogram-BaI-PnCv.cjs +102 -0
- package/cjs/histogram-BaI-PnCv.cjs.map +1 -0
- package/cjs/http-DCfXQvw-.cjs +870 -0
- package/cjs/http-DCfXQvw-.cjs.map +1 -0
- package/cjs/index.cjs +2 -1
- package/cjs/insights-BKtqxdnP.cjs +811 -0
- package/cjs/insights-BKtqxdnP.cjs.map +1 -0
- package/cjs/ip-DbNhPOzi.cjs +153 -0
- package/cjs/ip-DbNhPOzi.cjs.map +1 -0
- package/cjs/migrations-w7GMsrQw.cjs +297 -0
- package/cjs/migrations-w7GMsrQw.cjs.map +1 -0
- package/cjs/openapi-CC7OAUc6.cjs +52 -0
- package/cjs/openapi-CC7OAUc6.cjs.map +1 -0
- package/cjs/options-CWqFC5__.cjs +181 -0
- package/cjs/options-CWqFC5__.cjs.map +1 -0
- package/cjs/panels-Rcmeitu3.cjs +318 -0
- package/cjs/panels-Rcmeitu3.cjs.map +1 -0
- package/cjs/process-panel-DEOnLxoT.cjs +48 -0
- package/cjs/process-panel-DEOnLxoT.cjs.map +1 -0
- package/cjs/production/index.cjs +238 -0
- package/cjs/production/index.cjs.map +1 -0
- package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +52 -0
- package/cjs/server-ykxsOwob.cjs +184 -0
- package/cjs/server-ykxsOwob.cjs.map +1 -0
- package/cjs/{src-Xwm3Eel9.cjs → src-UPtTCI2j.cjs} +210 -293
- package/cjs/src-UPtTCI2j.cjs.map +1 -0
- package/cjs/store-aq207T8v.cjs +9 -0
- package/cjs/stream-route-CJTABkUy.cjs +875 -0
- package/cjs/stream-route-CJTABkUy.cjs.map +1 -0
- package/esm/devtools-connector.d.mts +16 -13
- package/esm/devtools-connector.d.mts.map +1 -1
- package/esm/devtools-connector.mjs +127 -18
- package/esm/devtools-connector.mjs.map +1 -1
- package/esm/index.d.mts +4 -2
- package/esm/index.mjs +2 -1
- package/esm/options.mjs +2 -1
- package/esm/options.mjs.map +1 -1
- package/esm/panel-tokens.d.mts +13 -0
- package/esm/panel-tokens.d.mts.map +1 -0
- package/esm/panel-tokens.mjs +45 -0
- package/esm/panel-tokens.mjs.map +1 -0
- package/esm/panels.mjs +73 -8
- package/esm/panels.mjs.map +1 -1
- package/esm/production/auth/common-passwords.mjs +303 -0
- package/esm/production/auth/common-passwords.mjs.map +1 -0
- package/esm/production/auth/default-crypto.mjs +19 -0
- package/esm/production/auth/default-crypto.mjs.map +1 -0
- package/esm/production/auth/helpers.mjs +77 -0
- package/esm/production/auth/helpers.mjs.map +1 -0
- package/esm/production/auth/index.mjs +6 -0
- package/esm/production/auth/passkeys.mjs +96 -0
- package/esm/production/auth/passkeys.mjs.map +1 -0
- package/esm/production/auth/service.mjs +1166 -0
- package/esm/production/auth/service.mjs.map +1 -0
- package/esm/production/boot.mjs +138 -0
- package/esm/production/boot.mjs.map +1 -0
- package/esm/production/capture/dev-stats.mjs +83 -0
- package/esm/production/capture/dev-stats.mjs.map +1 -0
- package/esm/production/capture/engine.mjs +442 -0
- package/esm/production/capture/engine.mjs.map +1 -0
- package/esm/production/capture/explain.mjs +271 -0
- package/esm/production/capture/explain.mjs.map +1 -0
- package/esm/production/capture/filter.mjs +24 -0
- package/esm/production/capture/filter.mjs.map +1 -0
- package/esm/production/capture/index.mjs +7 -0
- package/esm/production/capture/production-capture.mjs +134 -0
- package/esm/production/capture/production-capture.mjs.map +1 -0
- package/esm/production/capture/redact.mjs +109 -0
- package/esm/production/capture/redact.mjs.map +1 -0
- package/esm/production/capture/stats-stores.mjs +300 -0
- package/esm/production/capture/stats-stores.mjs.map +1 -0
- package/esm/production/cli/actions.mjs +151 -0
- package/esm/production/cli/actions.mjs.map +1 -0
- package/esm/production/cli/index.d.mts +17 -0
- package/esm/production/cli/index.d.mts.map +1 -0
- package/esm/production/cli/index.mjs +86 -0
- package/esm/production/cli/index.mjs.map +1 -0
- package/esm/production/contracts.d.mts +592 -0
- package/esm/production/contracts.d.mts.map +1 -0
- package/esm/production/contracts.mjs +95 -0
- package/esm/production/contracts.mjs.map +1 -0
- package/esm/production/errors.d.mts +31 -0
- package/esm/production/errors.d.mts.map +1 -0
- package/esm/production/errors.mjs +142 -0
- package/esm/production/errors.mjs.map +1 -0
- package/esm/production/http/access.mjs +124 -0
- package/esm/production/http/access.mjs.map +1 -0
- package/esm/production/http/auth-routes.mjs +280 -0
- package/esm/production/http/auth-routes.mjs.map +1 -0
- package/esm/production/http/client.mjs +57 -0
- package/esm/production/http/client.mjs.map +1 -0
- package/esm/production/http/constants.mjs +11 -0
- package/esm/production/http/constants.mjs.map +1 -0
- package/esm/production/http/context.mjs +14 -0
- package/esm/production/http/context.mjs.map +1 -0
- package/esm/production/http/cookie.mjs +39 -0
- package/esm/production/http/cookie.mjs.map +1 -0
- package/esm/production/http/headers.mjs +25 -0
- package/esm/production/http/headers.mjs.map +1 -0
- package/esm/production/http/index.mjs +10 -0
- package/esm/production/http/ip.mjs +130 -0
- package/esm/production/http/ip.mjs.map +1 -0
- package/esm/production/http/mount.mjs +300 -0
- package/esm/production/http/mount.mjs.map +1 -0
- package/esm/production/http/state.mjs +54 -0
- package/esm/production/http/state.mjs.map +1 -0
- package/esm/production/index.d.mts +6 -0
- package/esm/production/index.mjs +5 -0
- package/esm/production/insights/cap-report.mjs +67 -0
- package/esm/production/insights/cap-report.mjs.map +1 -0
- package/esm/production/insights/health.mjs +88 -0
- package/esm/production/insights/health.mjs.map +1 -0
- package/esm/production/insights/index.mjs +10 -0
- package/esm/production/insights/insights.mjs +167 -0
- package/esm/production/insights/insights.mjs.map +1 -0
- package/esm/production/insights/instance.mjs +24 -0
- package/esm/production/insights/instance.mjs.map +1 -0
- package/esm/production/insights/jobs.mjs +100 -0
- package/esm/production/insights/jobs.mjs.map +1 -0
- package/esm/production/insights/reporter.mjs +59 -0
- package/esm/production/insights/reporter.mjs.map +1 -0
- package/esm/production/insights/resources.mjs +139 -0
- package/esm/production/insights/resources.mjs.map +1 -0
- package/esm/production/insights/writer.mjs +72 -0
- package/esm/production/insights/writer.mjs.map +1 -0
- package/esm/production/openapi.mjs +52 -0
- package/esm/production/openapi.mjs.map +1 -0
- package/esm/production/options.d.mts +60 -0
- package/esm/production/options.d.mts.map +1 -0
- package/esm/production/options.mjs +170 -0
- package/esm/production/options.mjs.map +1 -0
- package/esm/production/stats/histogram.mjs +67 -0
- package/esm/production/stats/histogram.mjs.map +1 -0
- package/esm/production/stats/merge.mjs +106 -0
- package/esm/production/stats/merge.mjs.map +1 -0
- package/esm/production/store/cascade-store.mjs +322 -0
- package/esm/production/store/cascade-store.mjs.map +1 -0
- package/esm/production/store/index.mjs +5 -0
- package/esm/production/store/mapping.mjs +258 -0
- package/esm/production/store/mapping.mjs.map +1 -0
- package/esm/production/store/memory-store.mjs +291 -0
- package/esm/production/store/memory-store.mjs.map +1 -0
- package/esm/production/store/migrations.d.mts +11 -0
- package/esm/production/store/migrations.d.mts.map +1 -0
- package/esm/production/store/migrations.mjs +29 -0
- package/esm/production/store/migrations.mjs.map +1 -0
- package/esm/production/store/models/account.migration.mjs +34 -0
- package/esm/production/store/models/account.migration.mjs.map +1 -0
- package/esm/production/store/models/account.model.mjs +13 -0
- package/esm/production/store/models/account.model.mjs.map +1 -0
- package/esm/production/store/models/audit.migration.mjs +30 -0
- package/esm/production/store/models/audit.migration.mjs.map +1 -0
- package/esm/production/store/models/audit.model.mjs +13 -0
- package/esm/production/store/models/audit.model.mjs.map +1 -0
- package/esm/production/store/models/base.mjs +27 -0
- package/esm/production/store/models/base.mjs.map +1 -0
- package/esm/production/store/models/index.mjs +17 -0
- package/esm/production/store/models/invite.migration.mjs +26 -0
- package/esm/production/store/models/invite.migration.mjs.map +1 -0
- package/esm/production/store/models/invite.model.mjs +13 -0
- package/esm/production/store/models/invite.model.mjs.map +1 -0
- package/esm/production/store/models/report.migration.mjs +20 -0
- package/esm/production/store/models/report.migration.mjs.map +1 -0
- package/esm/production/store/models/report.model.mjs +13 -0
- package/esm/production/store/models/report.model.mjs.map +1 -0
- package/esm/production/store/models/sample.migration.mjs +25 -0
- package/esm/production/store/models/sample.migration.mjs.map +1 -0
- package/esm/production/store/models/sample.model.mjs +13 -0
- package/esm/production/store/models/sample.model.mjs.map +1 -0
- package/esm/production/store/models/session.migration.mjs +31 -0
- package/esm/production/store/models/session.migration.mjs.map +1 -0
- package/esm/production/store/models/session.model.mjs +13 -0
- package/esm/production/store/models/session.model.mjs.map +1 -0
- package/esm/production/store/models/state.migration.mjs +26 -0
- package/esm/production/store/models/state.migration.mjs.map +1 -0
- package/esm/production/store/models/state.model.mjs +13 -0
- package/esm/production/store/models/state.model.mjs.map +1 -0
- package/esm/query-shape.mjs +14 -1
- package/esm/query-shape.mjs.map +1 -1
- package/esm/server/explain-route.mjs +26 -1
- package/esm/server/explain-route.mjs.map +1 -1
- package/esm/server/index.mjs +9 -4
- package/esm/server/index.mjs.map +1 -1
- package/esm/server/insights-routes.mjs +62 -0
- package/esm/server/insights-routes.mjs.map +1 -0
- package/esm/server/log-routes.mjs +32 -5
- package/esm/server/log-routes.mjs.map +1 -1
- package/esm/server/openapi-routes.mjs +3 -2
- package/esm/server/openapi-routes.mjs.map +1 -1
- package/esm/server/requests-routes.mjs +125 -0
- package/esm/server/requests-routes.mjs.map +1 -1
- package/esm/server/session-routes.mjs +42 -0
- package/esm/server/session-routes.mjs.map +1 -0
- package/esm/server/stream-route.mjs +81 -11
- package/esm/server/stream-route.mjs.map +1 -1
- package/esm/server/ui-assets.mjs +34 -25
- package/esm/server/ui-assets.mjs.map +1 -1
- package/esm/sources/log-source.mjs +14 -1
- package/esm/sources/log-source.mjs.map +1 -1
- package/esm/types.d.mts +208 -3
- package/esm/types.d.mts.map +1 -1
- package/esm/ui-root.mjs +9 -4
- package/esm/ui-root.mjs.map +1 -1
- package/llms-full.txt +166 -21
- package/llms.txt +2 -2
- package/package.json +32 -8
- package/skills/SKILL.md +166 -21
- package/ui/dashboard/assets/app.css +3 -0
- package/ui/dashboard/assets/app.js +50 -0
- package/ui/dashboard/build-info.json +21 -0
- package/ui/dashboard/index.html +16 -0
- package/ui/panels/processes.js +12 -3
- package/cjs/ai-source-Dz_3tlZ5.cjs +0 -703
- package/cjs/ai-source-Dz_3tlZ5.cjs.map +0 -1
- package/cjs/server-B11ShQYE.cjs +0 -628
- package/cjs/server-B11ShQYE.cjs.map +0 -1
- package/cjs/src-Xwm3Eel9.cjs.map +0 -1
- package/ui/app.css +0 -376
- package/ui/app.js +0 -1158
- package/ui/index.html +0 -28
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-route-CJTABkUy.cjs","names":["AGENT_TRACE_INSTALL_GUIDANCE","DevtoolsApiError","createErrorRef","DevtoolsApiError","path","resolveUiRoot","readFileSync","existsSync","path","resolveUiRoot","panelContentType","DevtoolsApiError"],"sources":["../../../../../../../packages/devtools/src/server/ai-routes.ts","../../../../../../../packages/devtools/src/server/explain-route.ts","../../../../../../../packages/devtools/src/server/insights-routes.ts","../../../../../../../packages/devtools/src/server/log-routes.ts","../../../../../../../packages/devtools/src/server/mail-routes.ts","../../../../../../../packages/devtools/src/server/ui-assets.ts","../../../../../../../packages/devtools/src/server/openapi-routes.ts","../../../../../../../packages/devtools/src/server/panel-routes.ts","../../../../../../../packages/devtools/src/request-history.ts","../../../../../../../packages/devtools/src/server/requests-routes.ts","../../../../../../../packages/devtools/src/server/route-routes.ts","../../../../../../../packages/devtools/src/server/stream-route.ts"],"sourcesContent":["import type { FastifyInstance } from \"fastify\";\nimport { AGENT_TRACE_INSTALL_GUIDANCE } from \"../sources/agent-trace-source\";\nimport { AI_INSTALL_GUIDANCE } from \"../sources/ai-source\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\n/** Read-only AI metadata, inside the same development/loopback guard as every panel. */\nexport function registerAiRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.get<{ Querystring: { requestId?: string } }>(\"/api/ai\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.ai;\n if (!source?.available) {\n return { available: false, message: source?.message ?? AI_INSTALL_GUIDANCE, runs: [] };\n }\n const filter =\n request.query.requestId === undefined ? undefined : { requestId: request.query.requestId };\n return {\n available: true,\n runs: source.store.query(filter).map(source.summarize),\n aggregate: source.store.aggregate(filter),\n };\n });\n\n // Per-turn agent traces recorded by `@warlock.js/ai` itself (system prompt,\n // tools offered, tool calls, refusals, retries, usage and cost). Unlike the\n // Panoptic feed above, these carry prompt and tool content: they exist for\n // debugging in development and sit behind the same guard.\n server.get<{ Querystring: { requestId?: string } }>(\n \"/api/ai/agent-runs\",\n async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.agentTraces;\n\n if (!source?.available()) {\n return { available: false, message: AGENT_TRACE_INSTALL_GUIDANCE, runs: [] };\n }\n\n return {\n available: true,\n runs: source.list(\n request.query.requestId === undefined\n ? undefined\n : { requestId: request.query.requestId },\n ),\n };\n },\n );\n\n server.get<{ Params: { id: string } }>(\"/api/ai/agent-runs/:id\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const trace = deps.agentTraces?.get(request.params.id);\n\n if (!trace) return reply.code(404).send();\n\n return trace;\n });\n\n server.get<{ Params: { id: string } }>(\"/api/ai/runs/:id\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.ai;\n const trace = source?.available ? source.store.get(request.params.id) : undefined;\n if (!trace) return reply.code(404).send();\n return trace;\n });\n}\n","import { log } from \"@warlock.js/logger\";\nimport type { FastifyInstance } from \"fastify\";\nimport { createErrorRef, DevtoolsApiError } from \"../production/errors\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\n/**\n * The value the logger's redaction substitutes for a censored leaf\n * (`logger/src/redact/redact.ts`, `DEFAULT_CENSOR`). Not exported from\n * `@warlock.js/logger`, so matched by literal here.\n */\nconst REDACTED_PLACEHOLDER = \"[REDACTED]\";\n\nfunction isExplainableSql(sql: string | undefined): boolean {\n return /^\\s*(select|with)\\b/i.test(sql ?? \"\");\n}\n\n/** Registers the EXPLAIN route: Postgres `SELECT`/`WITH` queries only. */\nexport function registerExplainRoute(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.post<{ Params: { requestId: string; queryId: string } }>(\n \"/api/requests/:requestId/queries/:queryId/explain\",\n async (request, reply) => {\n const found = deps.collector.getRequest(request.params.requestId);\n const query = found?.queries.find((item) => item.id === request.params.queryId);\n\n if (!query) {\n reply.code(404).send();\n return;\n }\n\n if (query.driver !== \"postgres\" || !isExplainableSql(query.sql) || !deps.explain) {\n reply.code(400).send({ error: \"Only Postgres SELECT or WITH queries can be explained\" });\n return;\n }\n\n if (query.bindings?.some((binding) => binding === REDACTED_PLACEHOLDER)) {\n reply.code(400).send({ error: \"bindings redacted\" });\n return;\n }\n\n try {\n const plan = await deps.explain(query);\n return { plan };\n } catch (error) {\n reply.code(500).send({ error: error instanceof Error ? error.message : String(error) });\n }\n },\n );\n}\n\n/**\n * Registers `POST /api/queries/:shapeId/explain`: EXPLAIN for a query shape,\n * run by the process that kept an example of it (development and production).\n * A failure answers `{ error, code, ref?, instance? }` with the code's status.\n */\nexport function registerShapeExplainRoute(\n server: FastifyInstance,\n deps: MountDevtoolsRoutesDeps,\n): void {\n const explainShape = deps.explainShape;\n\n if (!explainShape) return;\n\n server.post<{ Params: { shapeId: string } }>(\n \"/api/queries/:shapeId/explain\",\n async (request, reply) => {\n try {\n return await explainShape(request.params.shapeId);\n } catch (error) {\n if (error instanceof DevtoolsApiError) {\n reply.code(error.statusCode).send(error.toBody());\n return;\n }\n\n const failure = new DevtoolsApiError(\"server.error\", { ref: createErrorRef() });\n\n log.error(\n \"devtools\",\n \"explain\",\n `EXPLAIN route failed (ref ${failure.ref}): ${error instanceof Error ? error.message : String(error)}`,\n );\n reply.code(failure.statusCode).send(failure.toBody());\n }\n },\n );\n}\n","import type { FastifyInstance } from \"fastify\";\nimport { DevtoolsApiError } from \"../production/errors\";\nimport type { DevtoolsInsightQuery, DevtoolsInsights } from \"../production/insights/types\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\ntype InsightsQuerystring = { instance?: string; sort?: string; limit?: string };\n\nconst QUERY_SORTS = [\"total\", \"p95\", \"count\", \"n+1\"] as const;\nconst ROUTE_SORTS = [\"total\", \"p95\", \"count\", \"errors\"] as const;\n\n/**\n * Reads `?instance=&sort=&limit=`. A sort outside `sorts` or a limit that is\n * not a whole number from 1 to 500 answers `input.invalid`.\n */\nexport function parseInsightQuery(\n query: InsightsQuerystring,\n sorts?: readonly string[],\n): DevtoolsInsightQuery {\n const result: DevtoolsInsightQuery = { instance: query.instance || \"all\" };\n\n if (sorts && query.sort !== undefined && query.sort !== \"\") {\n if (!sorts.includes(query.sort)) throw new DevtoolsApiError(\"input.invalid\");\n\n result.sort = query.sort;\n }\n\n if (query.limit !== undefined && query.limit !== \"\") {\n const limit = Number(query.limit);\n\n if (!Number.isInteger(limit) || limit < 1 || limit > 500) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n result.limit = limit;\n }\n\n return result;\n}\n\n/**\n * The read-only routes of the Resources, Queries (statistics), Routes\n * (statistics), Health, Errors, Logs (production) and Jobs tabs, over\n * `deps.insights`: `GET /api/instances`, `/api/resources`,\n * `/api/queries/stats`, `/api/routes/stats`, `/api/health`, `/api/errors`,\n * `/api/jobs`. Each takes `?instance=<id|all>` (default `all`). Without\n * `deps.insights` nothing is registered.\n */\nexport function registerInsightsRoutes(\n server: FastifyInstance,\n deps: MountDevtoolsRoutesDeps,\n): void {\n const insights: DevtoolsInsights | undefined = deps.insights;\n\n if (!insights) return;\n\n const route = (\n path: string,\n sorts: readonly string[] | undefined,\n read: (query: DevtoolsInsightQuery) => Promise<unknown>,\n ): void => {\n server.get<{ Querystring: InsightsQuerystring }>(path, async (request, reply) => {\n const query = parseInsightQuery(request.query, sorts);\n\n reply.header(\"Cache-Control\", \"no-store\");\n\n return read(query);\n });\n };\n\n route(\"/api/instances\", undefined, () => insights.instances());\n route(\"/api/resources\", undefined, (query) => insights.resources(query));\n route(\"/api/queries/stats\", QUERY_SORTS, (query) => insights.queryStats(query));\n route(\"/api/routes/stats\", ROUTE_SORTS, (query) => insights.routeStats(query));\n route(\"/api/health\", undefined, (query) => insights.health(query));\n route(\"/api/errors\", undefined, (query) => insights.errors(query));\n route(\"/api/jobs\", undefined, (query) => insights.jobs(query));\n}\n","import type { FastifyInstance } from \"fastify\";\nimport type { DevtoolsLogRow } from \"../production/contracts\";\nimport type { DevtoolsLogEntry } from \"../types\";\nimport { parseInsightQuery } from \"./insights-routes\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\ntype LogsQuery = {\n level?: DevtoolsLogEntry[\"level\"];\n module?: string;\n instance?: string;\n limit?: string;\n};\n\n/**\n * Registers the log listing route, filterable by `level` and `module`. In\n * production it answers from the insights (every instance, no `context`);\n * in development it answers from the collector's logs, which keep `context`.\n */\nexport function registerLogRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.get<{ Querystring: LogsQuery }>(\"/api/logs\", async (request, reply) => {\n const { level, module } = request.query;\n\n if (deps.mode === \"production\" && deps.insights) {\n const query = parseInsightQuery(request.query);\n\n reply.header(\"Cache-Control\", \"no-store\");\n\n return deps.insights.logs({\n ...query,\n ...(level ? { level } : {}),\n ...(module ? { module } : {}),\n });\n }\n\n const rows: DevtoolsLogRow[] = deps.collector.listLogs({ level, module }).map((entry) => ({\n level: entry.level,\n module: entry.module,\n action: entry.action,\n message: entry.message,\n at: entry.at,\n requestId: null,\n instance: null,\n context: entry.context,\n }));\n\n return rows;\n });\n}\n","import type { FastifyInstance } from \"fastify\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\nconst MAIL_HTML_CSP =\n \"sandbox; default-src 'none'; img-src data: https: http:; style-src 'unsafe-inline'\";\n\n/** Registers the mailbox list, single-mail detail, and mail HTML routes. */\nexport function registerMailRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.get(\"/api/mails\", async () => deps.collector.listMails());\n\n server.get<{ Params: { id: string } }>(\"/api/mails/:id\", async (request, reply) => {\n const mail = deps.collector.getMail(request.params.id);\n\n if (!mail) {\n reply.code(404).send();\n return;\n }\n\n const { html, ...rest } = mail;\n return rest;\n });\n\n server.get<{ Params: { id: string } }>(\"/api/mails/:id/html\", async (request, reply) => {\n const mail = deps.collector.getMail(request.params.id);\n\n if (!mail || !mail.html) {\n reply.code(404).send();\n return;\n }\n\n reply\n .header(\"Content-Security-Policy\", MAIL_HTML_CSP)\n .header(\"X-Content-Type-Options\", \"nosniff\")\n .header(\"Content-Type\", \"text/html; charset=utf-8\")\n .send(mail.html);\n });\n}\n","import { existsSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { FastifyInstance, FastifyReply, FastifyRequest } 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\": {\n contentType: \"text/javascript; charset=utf-8\",\n file: uiFile(\"dashboard/assets/app.js\"),\n },\n \"app.css\": { contentType: \"text/css; charset=utf-8\", file: uiFile(\"dashboard/assets/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\nconst NOT_BUILT_HTML =\n \"<!doctype html><title>Warlock Devtools</title><p>The devtools dashboard has not been built. Run <code>pnpm --filter @warlock.js/devtools build:ui</code>.</p>\";\n\n/**\n * Serves the static dashboard: the built `ui/dashboard/index.html` at the\n * dashboard root and the whitelisted assets (`app.js`, `app.css`, the\n * vendored Scalar bundle as `scalar.js`, and the vendored Swagger UI files\n * 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. Before the first `build:ui` the root answers 503 with\n * a note that says how to build. `notFound` answers an unknown asset (the\n * production gate passes its uniform 404, so the public asset route answers\n * like any unknown URL of the app); without it the answer is a bare 404.\n */\nexport function registerUiAssets(\n server: FastifyInstance,\n options: { notFound?: (request: FastifyRequest, reply: FastifyReply) => FastifyReply } = {},\n): void {\n const serveIndex = (request: FastifyRequest, reply: FastifyReply): void => {\n // The address as sent: core's server drops a trailing slash before routing.\n const [pathname = \"\", search] = (request.originalUrl ?? request.url).split(\"?\");\n\n // The page loads its assets by relative URL, so it must be served from `<path>/`. The target is built from\n // the route, never from the request, so it always stays on the dashboard path.\n if (!pathname.endsWith(\"/\")) {\n const base = (request.routeOptions.url ?? pathname).replace(/\\/+$/, \"\");\n\n reply\n .code(308)\n .header(\"Cache-Control\", \"no-store\")\n .redirect(`${base}/${search === undefined ? \"\" : `?${search}`}`, 308);\n return;\n }\n\n const index = path.join(resolveUiRoot(), \"dashboard\", \"index.html\");\n\n if (!existsSync(index)) {\n reply\n .code(503)\n .header(\"Cache-Control\", \"no-store\")\n .header(\"Content-Type\", \"text/html; charset=utf-8\")\n .send(NOT_BUILT_HTML);\n return;\n }\n\n reply\n .header(\"Cache-Control\", \"no-store\")\n .header(\"Content-Type\", \"text/html; charset=utf-8\")\n .send(readFileSync(index));\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 const file = asset?.file();\n\n if (!asset || !file || !existsSync(file)) {\n if (options.notFound) {\n options.notFound(request, reply);\n return;\n }\n\n reply.code(404).header(\"Cache-Control\", \"no-store\").send();\n return;\n }\n\n sendFile(reply, file, asset.contentType);\n });\n}\n","import path from \"node:path\";\nimport type { FastifyInstance, FastifyReply } from \"fastify\";\nimport { resolveUiRoot } from \"../ui-root\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\nimport { sendFile } from \"./ui-assets\";\n\n/**\n * Registers the API docs: `GET /api/openapi.json` returns the document core\n * builds from the registered routes (`deps.getOpenApiDocument`), and\n * `GET /docs` serves the page that renders it with Scalar and\n * `GET /docs/swagger` the same document in Swagger UI;\n * `GET /api/postman.json` returns the Postman collection core builds\n * (`deps.getPostmanCollection`). The pages use relative URLs, so it works under whatever base path the dashboard is\n * mounted on.\n */\nexport function registerOpenApiRoutes(\n server: FastifyInstance,\n deps: MountDevtoolsRoutesDeps,\n): void {\n server.get(\"/api/openapi.json\", async (_request, reply) => {\n if (!deps.getOpenApiDocument) {\n return reply.code(503).header(\"Cache-Control\", \"no-store\").send({\n error: \"The OpenAPI document is not available: the host did not provide a generator.\",\n });\n }\n\n reply.header(\"Cache-Control\", \"no-store\");\n\n return deps.getOpenApiDocument();\n });\n\n server.get(\"/api/postman.json\", async (_request, reply) => {\n if (!deps.getPostmanCollection) {\n return reply.code(503).header(\"Cache-Control\", \"no-store\").send({\n error: \"The Postman collection is not available: the host did not provide a generator.\",\n });\n }\n\n reply.header(\"Cache-Control\", \"no-store\");\n\n return deps.getPostmanCollection();\n });\n\n // The API tab shows these pages in a frame. The app's own headers (core's security headers forbid framing) are\n // replaced on the reply; production sets its full docs policy on top.\n const frameable = (reply: FastifyReply): FastifyReply =>\n reply\n .header(\"X-Frame-Options\", \"SAMEORIGIN\")\n .header(\"Content-Security-Policy\", \"frame-ancestors 'self'\");\n\n server.get(\"/docs\", (_request, reply) => {\n sendFile(frameable(reply), path.join(resolveUiRoot(), \"docs.html\"), \"text/html; charset=utf-8\");\n });\n\n server.get(\"/docs/swagger\", (_request, reply) => {\n sendFile(\n frameable(reply),\n path.join(resolveUiRoot(), \"docs-swagger.html\"),\n \"text/html; charset=utf-8\",\n );\n });\n}\n","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","import type { RequestLogFilter, RequestLogRecord, RequestLogSummary } from \"@warlock.js/core\";\nimport type {\n DevtoolsLogEntry,\n DevtoolsRequestDetail,\n DevtoolsRequestSummary,\n DevtoolsWarning,\n} from \"./types\";\n\n/** The list row filters run over, from an in-memory summary. */\nexport function summaryToRow(summary: DevtoolsRequestSummary): RequestLogSummary {\n return {\n id: summary.id,\n time: new Date(summary.startedAt).toISOString(),\n method: summary.method,\n url: summary.path,\n ...(summary.route ? { route: summary.route } : {}),\n status: summary.status ?? 0,\n durationMs: summary.durationMs ?? 0,\n };\n}\n\n/** An in-memory-shaped list row from a persisted one. */\nexport function rowToSummary(row: RequestLogSummary): DevtoolsRequestSummary {\n return {\n id: row.id,\n method: row.method,\n path: row.url,\n route: row.route,\n status: row.status,\n startedAt: Date.parse(row.time),\n durationMs: row.durationMs,\n queryCount: row.queryCount ?? 0,\n warningCount: row.nPlusOneCount ?? 0,\n persisted: true,\n };\n}\n\n/**\n * Merge the live ring buffer with the persisted log, newest first, without\n * duplicates: a request in both is shown from memory (it has the full\n * timeline). Persisted rows fill in what a restart or the ring buffer's size\n * evicted.\n */\nexport function mergeRequestHistory(\n live: readonly DevtoolsRequestSummary[],\n persisted: readonly RequestLogSummary[],\n limit: number,\n): DevtoolsRequestSummary[] {\n const seen = new Set(live.map((summary) => summary.id));\n const merged = [...live];\n\n for (const row of persisted) {\n if (seen.has(row.id)) continue;\n\n seen.add(row.id);\n merged.push(rowToSummary(row));\n }\n\n return merged.sort((first, second) => second.startedAt - first.startedAt).slice(0, limit);\n}\n\nconst FILTER_KEYS = [\"status\", \"route\", \"method\", \"since\", \"until\", \"q\"] as const;\n\n/** The request log filter in a `GET /api/requests` query string. */\nexport function filterFromQuery(query: Record<string, unknown>): RequestLogFilter {\n const filter: RequestLogFilter = {};\n\n for (const key of FILTER_KEYS) {\n const value = query[key];\n\n if (typeof value === \"string\" && value.trim() !== \"\") filter[key] = value.trim();\n }\n\n const limit = Number(query.limit);\n\n if (Number.isInteger(limit) && limit > 0) filter.limit = limit;\n\n return filter;\n}\n\n/** Whether a filter narrows anything. */\nexport function hasFilter(filter: RequestLogFilter): boolean {\n return FILTER_KEYS.some((key) => filter[key] !== undefined);\n}\n\nfunction toLogLevel(level: string): DevtoolsLogEntry[\"level\"] {\n return level === \"debug\" || level === \"info\" || level === \"warn\" || level === \"success\"\n ? level\n : \"error\";\n}\n\n/**\n * A request detail rebuilt from a persisted record, in the shape of an\n * in-memory one: phases, logs and N+1 warnings carry over; query-by-query\n * and cache detail live only in memory, so those lists are empty. `record`\n * has everything the log kept.\n */\nexport function recordToDetail(record: RequestLogRecord): DevtoolsRequestDetail {\n const startedAt = Date.parse(record.time);\n const warnings: DevtoolsWarning[] = (record.queries?.nPlusOne ?? []).map((finding) => ({\n type: \"n+1\",\n message: `${finding.query} ran ${finding.count} times`,\n shape: finding.query,\n count: finding.count,\n }));\n\n return {\n id: record.id,\n method: record.method,\n path: record.url,\n route: record.route.pattern,\n status: record.status,\n startedAt,\n durationMs: record.durationMs,\n error: record.error?.message,\n phases: (record.phases ?? []).map((phase) => ({\n name: phase.name,\n startedAt,\n durationMs: phase.durationMs,\n })),\n queries: [],\n cache: [],\n logs: (record.logs ?? []).map((entry) => ({\n level: toLogLevel(entry.level),\n module: entry.module,\n action: entry.action,\n message: entry.message,\n at: entry.at,\n ...(entry.context ? { context: entry.context } : {}),\n })),\n mails: [],\n warnings,\n persisted: true,\n record,\n };\n}\n","import type { RequestLogFilter } from \"@warlock.js/core\";\nimport type { FastifyInstance, FastifyReply } from \"fastify\";\nimport { DevtoolsApiError } from \"../production/errors\";\nimport type { DevtoolsSampleFilter } from \"../production/store/types\";\nimport {\n filterFromQuery,\n hasFilter,\n mergeRequestHistory,\n recordToDetail,\n summaryToRow,\n} from \"../request-history\";\nimport type { DevtoolsRequestDetail } from \"../types\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\nconst STATUS_FILTER = /^(?:[1-5]\\d\\d|[1-5]xx)$/i;\nconst METHOD_FILTER = /^[A-Za-z]{1,16}$/;\nconst RELATIVE_SINCE = /^(\\d+)(s|m|h|d)$/;\nconst UNIT_MS = { s: 1000, m: 60_000, h: 3_600_000, d: 86_400_000 } as const;\nconst DEFAULT_SAMPLE_LIMIT = 200;\nconst MAX_SAMPLE_LIMIT = 1000;\n\n/** A time bound as epoch ms: a number, an ISO date, or (for `since`) a duration back such as `15m`. */\nfunction parseTimeBound(value: string, allowRelative: boolean): number {\n if (/^\\d+$/.test(value)) return Number(value);\n\n const relative = allowRelative ? RELATIVE_SINCE.exec(value) : null;\n\n if (relative) {\n return Date.now() - Number(relative[1]) * UNIT_MS[relative[2] as keyof typeof UNIT_MS];\n }\n\n const parsed = Date.parse(value);\n\n if (Number.isNaN(parsed)) throw new DevtoolsApiError(\"request.invalid-filter\");\n\n return parsed;\n}\n\n/** The stored-sample filter in a `GET /api/requests` query string; throws `request.invalid-filter`. */\nfunction sampleFilterFromQuery(\n query: Record<string, unknown>,\n filter: RequestLogFilter,\n fallbackLimit: number,\n): DevtoolsSampleFilter {\n const result: DevtoolsSampleFilter = {\n limit: Math.min(MAX_SAMPLE_LIMIT, filter.limit ?? fallbackLimit),\n };\n\n if (filter.status !== undefined) {\n const status = String(filter.status);\n\n if (!STATUS_FILTER.test(status)) throw new DevtoolsApiError(\"request.invalid-filter\");\n\n result.status = status.toLowerCase();\n }\n\n if (filter.method !== undefined) {\n if (!METHOD_FILTER.test(String(filter.method))) {\n throw new DevtoolsApiError(\"request.invalid-filter\");\n }\n\n result.method = String(filter.method);\n }\n\n if (filter.route !== undefined) result.route = String(filter.route);\n if (filter.q !== undefined) result.q = String(filter.q);\n if (filter.since !== undefined) result.since = parseTimeBound(String(filter.since), true);\n if (filter.until !== undefined) result.until = parseTimeBound(String(filter.until), false);\n\n const instance = query.instance;\n\n if (typeof instance === \"string\" && instance.trim() !== \"\" && instance !== \"all\") {\n result.instance = instance.trim();\n }\n\n return result;\n}\n\nfunction sendApiError(reply: FastifyReply, error: DevtoolsApiError): void {\n reply.code(error.statusCode).send(error.toBody());\n}\n\n/**\n * Production: the same four routes over the request source (stored samples\n * and this process's memory), merged with the persisted request log the way\n * development merges it with the ring buffer.\n */\nfunction registerProductionRequestsRoutes(\n server: FastifyInstance,\n deps: MountDevtoolsRoutesDeps,\n): void {\n const source = deps.requests;\n\n if (!source) return;\n\n server.get<{ Querystring: Record<string, unknown> }>(\"/api/requests\", async (request, reply) => {\n const { requestLog, options } = deps;\n\n try {\n const filter = filterFromQuery(request.query);\n const sampleFilter = sampleFilterFromQuery(request.query, filter, DEFAULT_SAMPLE_LIMIT);\n const limit = Math.min(MAX_SAMPLE_LIMIT, filter.limit ?? options.maxRequests);\n let persisted: Awaited<ReturnType<NonNullable<typeof requestLog>[\"list\"]>> = [];\n\n if (requestLog) {\n try {\n requestLog.compile(filter);\n persisted = await requestLog.list({ ...filter, limit });\n } catch (error) {\n // A bad filter value is the caller's mistake; a read failure leaves the samples.\n if (error instanceof Error && /^Invalid /.test(error.message)) {\n throw new DevtoolsApiError(\"request.invalid-filter\");\n }\n }\n }\n\n const samples = await source.list({ ...sampleFilter, limit });\n\n return mergeRequestHistory(samples, persisted, limit);\n } catch (error) {\n if (error instanceof DevtoolsApiError) {\n sendApiError(reply, error);\n return;\n }\n\n throw error;\n }\n });\n\n server.get<{ Params: { id: string } }>(\"/api/requests/:id\", async (request, reply) => {\n const { id } = request.params;\n const persisted = await deps.requestLog?.get(id).catch(() => undefined);\n const found = await source.get(id);\n\n if (found) {\n const hasTimeline = \"phases\" in found;\n\n if (hasTimeline) return persisted ? { ...found, record: persisted } : found;\n\n // A slow or failed request that was not sampled: the summary, plus what the log kept.\n if (persisted) {\n return {\n ...recordToDetail(persisted),\n ...(found.instance === undefined ? {} : { instance: found.instance }),\n partial: true,\n };\n }\n\n return found;\n }\n\n if (!persisted) {\n sendApiError(reply, new DevtoolsApiError(\"request.not-found\"));\n return;\n }\n\n return recordToDetail(persisted);\n });\n\n server.get<{ Params: { id: string } }>(\"/api/requests/:id/curl\", async (request, reply) => {\n const { id } = request.params;\n const baseUrl = `${request.protocol}://${request.headers.host ?? \"localhost\"}`;\n const persisted = await deps.requestLog?.get(id).catch(() => undefined);\n\n if (persisted && deps.requestLog) return { curl: deps.requestLog.curl(persisted, baseUrl) };\n\n const found = await source.get(id);\n\n if (!found) {\n sendApiError(reply, new DevtoolsApiError(\"request.not-found\"));\n return;\n }\n\n return { curl: `curl -X ${found.method} '${baseUrl}${found.path.replace(/'/g, `'\\\\''`)}'` };\n });\n\n server.delete(\"/api/requests\", async (_request, reply) => {\n await source.clear();\n deps.collector.clear();\n reply.code(204).send();\n });\n}\n\n/**\n * Registers the request list, single-request detail, \"copy as curl\", and\n * clear routes.\n *\n * With core's persistent request log available, the list and the detail also\n * read the JSON-lines history, so requests survive a restart. The list\n * accepts `status` (404 or 5xx), `route`, `method`, `since`, `until`, `q`\n * and `limit` query parameters.\n */\nexport function registerRequestsRoutes(\n server: FastifyInstance,\n deps: MountDevtoolsRoutesDeps,\n): void {\n if (deps.requests) {\n registerProductionRequestsRoutes(server, deps);\n return;\n }\n\n server.get<{ Querystring: Record<string, unknown> }>(\"/api/requests\", async (request, reply) => {\n const { requestLog, collector, options } = deps;\n\n if (!requestLog) return collector.listRequests();\n\n try {\n const filter = filterFromQuery(request.query);\n const matches = requestLog.compile(filter);\n const live = hasFilter(filter)\n ? collector.listRequests().filter((summary) => matches(summaryToRow(summary)))\n : collector.listRequests();\n const limit = filter.limit ?? options.maxRequests;\n const persisted = await requestLog.list({ ...filter, limit });\n\n return mergeRequestHistory(live, persisted, limit);\n } catch (error) {\n // A bad filter value is the caller's mistake; a read failure leaves the live list.\n if (error instanceof Error && /^Invalid /.test(error.message)) {\n reply.code(400).send({ error: error.message });\n return;\n }\n\n return collector.listRequests();\n }\n });\n\n server.get<{ Params: { id: string } }>(\"/api/requests/:id\", async (request, reply) => {\n const { id } = request.params;\n const persisted = await deps.requestLog?.get(id).catch(() => undefined);\n const found = deps.collector.getRequest(id);\n\n if (found) {\n const detail: DevtoolsRequestDetail = persisted ? { ...found, record: persisted } : found;\n\n return detail;\n }\n\n if (!persisted) {\n reply.code(404).send();\n return;\n }\n\n return recordToDetail(persisted);\n });\n\n server.get<{ Params: { id: string } }>(\"/api/requests/:id/curl\", async (request, reply) => {\n const { id } = request.params;\n const baseUrl = `${request.protocol}://${request.headers.host ?? \"localhost\"}`;\n const persisted = await deps.requestLog?.get(id).catch(() => undefined);\n\n if (persisted && deps.requestLog) return { curl: deps.requestLog.curl(persisted, baseUrl) };\n\n // Without a persisted record only the method and path are known.\n const live = deps.collector.getRequest(id);\n\n if (!live) {\n reply.code(404).send();\n return;\n }\n\n return { curl: `curl -X ${live.method} '${baseUrl}${live.path.replace(/'/g, `'\\\\''`)}'` };\n });\n\n server.delete(\"/api/requests\", async (_request, reply) => {\n deps.collector.clear();\n if (deps.ai?.available) deps.ai.store.clear();\n reply.code(204).send();\n });\n}\n","import type { FastifyInstance } from \"fastify\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\n/** Registers the route map, sourced from core's router via `deps.listRoutes`. */\nexport function registerRouteRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.get(\"/api/routes\", async () => (deps.listRoutes ? deps.listRoutes() : []));\n}\n","import type { FastifyInstance } from \"fastify\";\nimport type { DevtoolsStreamSession, MountDevtoolsRoutesDeps } from \"./types\";\nimport type { DevtoolsLogEntry, DevtoolsStreamEvent } from \"../types\";\n\nconst PING_INTERVAL_MS = 15_000;\n\n/** How long a browser waits before it reconnects a dropped stream. */\nconst RETRY_MS = 5000;\n\n/** The log entry as the production stream sends it: no context (it may hold values). */\nfunction withoutContext(entry: DevtoolsLogEntry): DevtoolsLogEntry {\n return {\n level: entry.level,\n module: entry.module,\n action: entry.action,\n message: entry.message,\n at: entry.at,\n };\n}\n\n/**\n * Registers the SSE stream: one `event: <type>\\ndata: <json>\\n\\n` frame per\n * collector event, plus a `: ping` comment every 15s to keep intermediaries\n * from closing an idle connection. The reply is hijacked so Fastify never\n * tries to serialize or close the response itself.\n *\n * The first frames are `retry: 5000` and an `event: hello` with the mode,\n * instance and role. In production (`deps.streamSession` set) the session and\n * the open state are checked again at every ping and the stream ends when\n * either fails; log entries carry no context; mail, AI and agent events flow\n * only when those tabs are enabled.\n */\nexport function registerStreamRoute(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.get(\"/api/stream\", async (request, reply) => {\n // Opening first, so a refused stream (`stream.too-many`) is a normal JSON error.\n const session: DevtoolsStreamSession | null = deps.streamSession\n ? await deps.streamSession(request)\n : null;\n const enabled = new Set(deps.builtInPanels ?? []);\n const instanceId = deps.instance?.id;\n const mode = deps.mode ?? \"development\";\n\n reply.hijack();\n const res = reply.raw;\n\n res.writeHead(200, {\n ...session?.headers,\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-store\",\n Connection: \"keep-alive\",\n \"X-Accel-Buffering\": \"no\",\n });\n\n const write = (frame: string): void => {\n if (!res.writableEnded && !res.destroyed) res.write(frame);\n };\n\n write(`retry: ${RETRY_MS}\\n\\n`);\n\n const hello: Extract<DevtoolsStreamEvent, { type: \"hello\" }>[\"data\"] = {\n mode,\n instance: instanceId ?? null,\n role: session?.role ?? (mode === \"development\" ? \"admin\" : null),\n };\n\n write(`event: hello\\ndata: ${JSON.stringify(hello)}\\n\\n`);\n\n const dispose = deps.collector.subscribe((event) => {\n if (event.type === \"hello\") return;\n\n if (session !== null) {\n if (event.type === \"mail\" && !enabled.has(\"mail\")) return;\n\n if (event.type === \"log\") {\n if (!session.logLevels.includes(event.data.level)) return;\n\n const row = withoutContext(event.data);\n\n write(\n `event: log\\ndata: ${JSON.stringify(instanceId !== undefined ? { ...row, instance: instanceId } : row)}\\n\\n`,\n );\n return;\n }\n }\n\n const data =\n event.type === \"request\" && instanceId !== undefined\n ? { ...event.data, instance: instanceId }\n : event.data;\n\n write(`event: ${event.type}\\ndata: ${JSON.stringify(data)}\\n\\n`);\n });\n\n const aiAllowed = session === null || enabled.has(\"ai\");\n const agentsAllowed = session === null || enabled.has(\"agents\");\n\n const disposeAi =\n aiAllowed && deps.ai?.available\n ? deps.ai.subscribe((event) => {\n write(`event: ai\\ndata: ${JSON.stringify(event)}\\n\\n`);\n })\n : undefined;\n\n const disposeAgentTraces = agentsAllowed\n ? deps.agentTraces?.subscribe((event) => {\n write(`event: agent-trace\\ndata: ${JSON.stringify(event)}\\n\\n`);\n })\n : undefined;\n\n let closed = false;\n\n const close = (): void => {\n if (closed) return;\n\n closed = true;\n clearInterval(pingTimer);\n dispose();\n disposeAi?.();\n disposeAgentTraces?.();\n session?.release();\n\n if (!res.writableEnded && !res.destroyed) res.end();\n };\n\n const pingTimer = setInterval(() => {\n if (session === null) {\n write(\": ping\\n\\n\");\n return;\n }\n\n session.revalidate().then(\n (stillValid) => {\n if (closed) return;\n\n if (stillValid) write(\": ping\\n\\n\");\n else close();\n },\n () => close(),\n );\n }, PING_INTERVAL_MS);\n pingTimer.unref();\n\n request.raw.on(\"close\", close);\n res.on(\"error\", close);\n });\n}\n"],"mappings":";;;;;;;;;;;AAMA,SAAgB,iBAAiB,QAAyB,MAAqC;CAC7F,OAAO,IAA6C,WAAW,OAAO,SAAS,UAAU;EACvF,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QAAQ,WACX,OAAO;GAAE,WAAW;GAAO,SAAS,QAAQ;GAAgC,MAAM,CAAC;EAAE;EAEvF,MAAM,SACJ,QAAQ,MAAM,cAAc,SAAY,SAAY,EAAE,WAAW,QAAQ,MAAM,UAAU;EAC3F,OAAO;GACL,WAAW;GACX,MAAM,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,OAAO,SAAS;GACrD,WAAW,OAAO,MAAM,UAAU,MAAM;EAC1C;CACF,CAAC;CAMD,OAAO,IACL,sBACA,OAAO,SAAS,UAAU;EACxB,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,SAAS,KAAK;EAEpB,IAAI,CAAC,QAAQ,UAAU,GACrB,OAAO;GAAE,WAAW;GAAO,SAASA;GAA8B,MAAM,CAAC;EAAE;EAG7E,OAAO;GACL,WAAW;GACX,MAAM,OAAO,KACX,QAAQ,MAAM,cAAc,SACxB,SACA,EAAE,WAAW,QAAQ,MAAM,UAAU,CAC3C;EACF;CACF,CACF;CAEA,OAAO,IAAgC,0BAA0B,OAAO,SAAS,UAAU;EACzF,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,QAAQ,KAAK,aAAa,IAAI,QAAQ,OAAO,EAAE;EAErD,IAAI,CAAC,OAAO,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;EAExC,OAAO;CACT,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,MAAM,UAAU,MAAM,KAAK,UAAU,KAAK,UAAU,IAAI,EAAE,KAAK;EACjE,CAAC;EAED,MAAM,YAAY,YAAY,QAAQ,QAAQ,IAAI,IAAI;EACtD,MAAM,gBAAgB,YAAY,QAAQ,QAAQ,IAAI,QAAQ;EAE9D,MAAM,YACJ,aAAa,KAAK,IAAI,YAClB,KAAK,GAAG,WAAW,UAAU;GAC3B,MAAM,oBAAoB,KAAK,UAAU,KAAK,EAAE,KAAK;EACvD,CAAC,IACD;EAEN,MAAM,qBAAqB,gBACvB,KAAK,aAAa,WAAW,UAAU;GACrC,MAAM,6BAA6B,KAAK,UAAU,KAAK,EAAE,KAAK;EAChE,CAAC,IACD;EAEJ,IAAI,SAAS;EAEb,MAAM,cAAoB;GACxB,IAAI,QAAQ;GAEZ,SAAS;GACT,cAAc,SAAS;GACvB,QAAQ;GACR,YAAY;GACZ,qBAAqB;GACrB,SAAS,QAAQ;GAEjB,IAAI,CAAC,IAAI,iBAAiB,CAAC,IAAI,WAAW,IAAI,IAAI;EACpD;EAEA,MAAM,YAAY,kBAAkB;GAClC,IAAI,YAAY,MAAM;IACpB,MAAM,YAAY;IAClB;GACF;GAEA,QAAQ,WAAW,CAAC,CAAC,MAClB,eAAe;IACd,IAAI,QAAQ;IAEZ,IAAI,YAAY,MAAM,YAAY;SAC7B,MAAM;GACb,SACM,MAAM,CACd;EACF,GAAG,gBAAgB;EACnB,UAAU,MAAM;EAEhB,QAAQ,IAAI,GAAG,SAAS,KAAK;EAC7B,IAAI,GAAG,SAAS,KAAK;CACvB,CAAC;AACH"}
|
|
@@ -6,21 +6,24 @@ export type DevtoolsConnectorOptions = DevtoolsOptions;
|
|
|
6
6
|
/**
|
|
7
7
|
* Construct the devtools connector.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* `
|
|
9
|
+
* Outside development, `boot()` checks `Application.runtimeStrategy` and
|
|
10
|
+
* `devtools.production.enabled`: unless both say production, it logs one
|
|
11
11
|
* warning and returns without mounting a route or subscribing to anything.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* With `enabled: true` in production it starts the signed-in production
|
|
13
|
+
* monitor (`bootProductionDevtools`), which refuses to boot when its
|
|
14
|
+
* configuration is incomplete. In development it attaches every source
|
|
15
|
+
* (tracing, queries, cache, mail, logs), loads the panels listed in the
|
|
16
|
+
* `panels` option, then mounts the dashboard's routes on the HTTP server —
|
|
17
|
+
* before it starts listening, the only point in the boot sequence where
|
|
18
|
+
* mounting is possible (see `queue/src/dashboard-boot.ts` for the same
|
|
19
|
+
* constraint).
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
* package is installed (`warlock add devtools`).
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* Options come from the app's `src/config/devtools.ts`
|
|
23
|
-
*
|
|
21
|
+
* In development apps don't call this: `warlock dev` registers it
|
|
22
|
+
* automatically when the package is installed (`warlock add devtools`). To
|
|
23
|
+
* run the production monitor, list `devtoolsConnector()` in
|
|
24
|
+
* `warlock.config.ts > connectors` (and keep the package in `dependencies`).
|
|
25
|
+
* Options come from the app's `src/config/devtools.ts` (a plain object, no
|
|
26
|
+
* import of this package); options passed here win over it.
|
|
24
27
|
*/
|
|
25
28
|
export declare function devtoolsConnector(options?: DevtoolsConnectorOptions): Connector;
|
|
26
29
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-connector.d.mts","names":[],"sources":["../../../../../../../packages/devtools/src/devtools-connector.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"devtools-connector.d.mts","names":[],"sources":["../../../../../../../packages/devtools/src/devtools-connector.ts"],"mappings":";;;;YA+CY,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;wBAwBvB,kBAAkB,UAAS,2BAAgC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { loadDevtoolsPanels } from "./panels.mjs";
|
|
1
|
+
import { checkDevtoolsPanels, loadDevtoolsPanels } from "./panels.mjs";
|
|
2
2
|
import { loadProcessPanel, processesDevtoolsPanel } from "./process-panel.mjs";
|
|
3
3
|
import { createCollector } from "./collector.mjs";
|
|
4
4
|
import { resolveDevtoolsOptions } from "./options.mjs";
|
|
5
|
+
import { DEVTOOLS_PRODUCTION_DEFAULTS } from "./production/options.mjs";
|
|
5
6
|
import { attachAgentTraceSource } from "./sources/agent-trace-source.mjs";
|
|
6
7
|
import { attachAiSource } from "./sources/ai-source.mjs";
|
|
7
8
|
import { attachCacheSource } from "./sources/cache-source.mjs";
|
|
@@ -32,21 +33,24 @@ function readConfiguredOptions(readConfig) {
|
|
|
32
33
|
/**
|
|
33
34
|
* Construct the devtools connector.
|
|
34
35
|
*
|
|
35
|
-
*
|
|
36
|
-
* `
|
|
36
|
+
* Outside development, `boot()` checks `Application.runtimeStrategy` and
|
|
37
|
+
* `devtools.production.enabled`: unless both say production, it logs one
|
|
37
38
|
* warning and returns without mounting a route or subscribing to anything.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
39
|
+
* With `enabled: true` in production it starts the signed-in production
|
|
40
|
+
* monitor (`bootProductionDevtools`), which refuses to boot when its
|
|
41
|
+
* configuration is incomplete. In development it attaches every source
|
|
42
|
+
* (tracing, queries, cache, mail, logs), loads the panels listed in the
|
|
43
|
+
* `panels` option, then mounts the dashboard's routes on the HTTP server —
|
|
44
|
+
* before it starts listening, the only point in the boot sequence where
|
|
45
|
+
* mounting is possible (see `queue/src/dashboard-boot.ts` for the same
|
|
46
|
+
* constraint).
|
|
43
47
|
*
|
|
44
|
-
*
|
|
45
|
-
* package is installed (`warlock add devtools`).
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* Options come from the app's `src/config/devtools.ts`
|
|
49
|
-
*
|
|
48
|
+
* In development apps don't call this: `warlock dev` registers it
|
|
49
|
+
* automatically when the package is installed (`warlock add devtools`). To
|
|
50
|
+
* run the production monitor, list `devtoolsConnector()` in
|
|
51
|
+
* `warlock.config.ts > connectors` (and keep the package in `dependencies`).
|
|
52
|
+
* Options come from the app's `src/config/devtools.ts` (a plain object, no
|
|
53
|
+
* import of this package); options passed here win over it.
|
|
50
54
|
*/
|
|
51
55
|
function devtoolsConnector(options = {}) {
|
|
52
56
|
let active = false;
|
|
@@ -60,14 +64,19 @@ function devtoolsConnector(options = {}) {
|
|
|
60
64
|
const core = await import("@warlock.js/core");
|
|
61
65
|
const { Application, getHttpServer } = core;
|
|
62
66
|
const { log } = await import("@warlock.js/logger");
|
|
63
|
-
if (Application.runtimeStrategy !== "development") {
|
|
64
|
-
log.warn("devtools", "disabled", "@warlock.js/devtools only runs in development; it is not mounted");
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
67
|
const resolved = resolveDevtoolsOptions({
|
|
68
68
|
...readConfiguredOptions(() => core.config),
|
|
69
69
|
...options
|
|
70
70
|
});
|
|
71
|
+
if (Application.runtimeStrategy === "production" && resolved.production?.enabled === true) {
|
|
72
|
+
disposers.push(await bootProduction(core, log, resolved));
|
|
73
|
+
active = true;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (Application.runtimeStrategy !== "development") {
|
|
77
|
+
log.warn("devtools", "disabled", "@warlock.js/devtools only runs in development unless devtools.production.enabled is true; it is not mounted");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
71
80
|
const collector = createCollector(resolved);
|
|
72
81
|
await attachSource(log, "tracing", () => attachTracingSource(collector, resolved));
|
|
73
82
|
await attachSource(log, "query", () => attachQuerySource(collector));
|
|
@@ -88,6 +97,7 @@ function devtoolsConnector(options = {}) {
|
|
|
88
97
|
warn: (message) => log.warn("devtools", "panel", message),
|
|
89
98
|
taken: /* @__PURE__ */ new Map([[builtIn.id, builtIn.title]])
|
|
90
99
|
});
|
|
100
|
+
const insightsWiring = await wireDevelopmentInsights(collector, resolved, log, disposers);
|
|
91
101
|
mountDevtoolsRoutes(getHttpServer(), {
|
|
92
102
|
collector,
|
|
93
103
|
ai,
|
|
@@ -95,6 +105,7 @@ function devtoolsConnector(options = {}) {
|
|
|
95
105
|
...processPanel ? { processPanel } : {},
|
|
96
106
|
panels,
|
|
97
107
|
options: resolved,
|
|
108
|
+
...insightsWiring,
|
|
98
109
|
requestLog,
|
|
99
110
|
isDevelopment: () => Application.runtimeStrategy === "development",
|
|
100
111
|
warn: (message) => log.warn("devtools", "refused", message),
|
|
@@ -134,6 +145,104 @@ function devtoolsConnector(options = {}) {
|
|
|
134
145
|
}
|
|
135
146
|
return connector;
|
|
136
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Development: the statistics, resources, health and jobs behind the
|
|
150
|
+
* Resources, Queries (statistics), Routes (statistics), Errors, Health and
|
|
151
|
+
* Jobs tabs. Wrapped as a whole: when anything fails to start, one line is
|
|
152
|
+
* logged and the dashboard mounts without insights (those tabs then say they
|
|
153
|
+
* are not available). It never stops the dashboard.
|
|
154
|
+
*/
|
|
155
|
+
async function wireDevelopmentInsights(collector, resolved, log, disposers) {
|
|
156
|
+
const stops = [];
|
|
157
|
+
try {
|
|
158
|
+
const capture = await import("./production/capture/index.mjs");
|
|
159
|
+
const insights = await import("./production/insights/index.mjs");
|
|
160
|
+
const instance = insights.createInstanceInfo();
|
|
161
|
+
const queries = capture.createQueryStats({
|
|
162
|
+
maxShapes: DEVTOOLS_PRODUCTION_DEFAULTS.maxShapes,
|
|
163
|
+
instance: instance.id
|
|
164
|
+
});
|
|
165
|
+
const routes = capture.createRouteStats({
|
|
166
|
+
maxRoutes: DEVTOOLS_PRODUCTION_DEFAULTS.maxRoutes,
|
|
167
|
+
instance: instance.id
|
|
168
|
+
});
|
|
169
|
+
const errors = capture.createErrorGroups({ maxGroups: DEVTOOLS_PRODUCTION_DEFAULTS.maxErrorGroups });
|
|
170
|
+
const logs = capture.createRecentLogs({ maxEntries: 200 });
|
|
171
|
+
stops.push(capture.attachDevelopmentStats(collector, {
|
|
172
|
+
queries,
|
|
173
|
+
routes,
|
|
174
|
+
errors,
|
|
175
|
+
logs,
|
|
176
|
+
nPlusOneThreshold: resolved.nPlusOneThreshold
|
|
177
|
+
}));
|
|
178
|
+
const resources = insights.createResourceMonitor();
|
|
179
|
+
const health = insights.createHealthHistory();
|
|
180
|
+
resources.start();
|
|
181
|
+
health.start();
|
|
182
|
+
stops.push(() => resources.stop(), () => health.stop());
|
|
183
|
+
const reporter = insights.createLocalReporter({
|
|
184
|
+
instance,
|
|
185
|
+
resources,
|
|
186
|
+
health,
|
|
187
|
+
jobs: insights.createJobsReader(),
|
|
188
|
+
queries,
|
|
189
|
+
routes,
|
|
190
|
+
errors,
|
|
191
|
+
logs,
|
|
192
|
+
counters: null
|
|
193
|
+
});
|
|
194
|
+
const explainShape = capture.createShapeExplainer({
|
|
195
|
+
queries,
|
|
196
|
+
executing: false,
|
|
197
|
+
instance: instance.id
|
|
198
|
+
});
|
|
199
|
+
disposers.push(...stops);
|
|
200
|
+
return {
|
|
201
|
+
instance,
|
|
202
|
+
insights: insights.createLocalInsights(reporter),
|
|
203
|
+
explainShape
|
|
204
|
+
};
|
|
205
|
+
} catch (error) {
|
|
206
|
+
for (const stop of stops) try {
|
|
207
|
+
stop();
|
|
208
|
+
} catch {}
|
|
209
|
+
log.warn("devtools", "insights-failed", `devtools' statistics could not start, so the Resources, Queries, Routes, Errors, Health and Jobs tabs are not available: ${error instanceof Error ? error.message : String(error)}`);
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Starts the production monitor: loads the panels in production mode and
|
|
215
|
+
* hands everything to `bootProductionDevtools`, which refuses to boot (throws
|
|
216
|
+
* `DevtoolsProductionConfigError`) when the configuration is incomplete.
|
|
217
|
+
*/
|
|
218
|
+
async function bootProduction(core, log, resolved) {
|
|
219
|
+
const { bootProductionDevtools } = await import("./production/boot.mjs");
|
|
220
|
+
const requestLog = await findRequestLogSource();
|
|
221
|
+
const processPanel = resolved.production?.panels?.processes === true ? await loadProcessPanel() : void 0;
|
|
222
|
+
const builtIn = processesDevtoolsPanel(processPanel);
|
|
223
|
+
const packagePanels = await loadDevtoolsPanels(resolved.panels ?? [], {
|
|
224
|
+
root: "rootPath" in core ? core.rootPath() : process.cwd(),
|
|
225
|
+
warn: (message) => log.warn("devtools", "panel", message),
|
|
226
|
+
taken: /* @__PURE__ */ new Map([[builtIn.id, builtIn.title]]),
|
|
227
|
+
mode: "production"
|
|
228
|
+
});
|
|
229
|
+
const { createProductionOpenApi } = await import("./production/openapi.mjs");
|
|
230
|
+
const openApi = createProductionOpenApi(core);
|
|
231
|
+
return bootProductionDevtools({
|
|
232
|
+
options: resolved,
|
|
233
|
+
env: process.env,
|
|
234
|
+
server: core.getHttpServer(),
|
|
235
|
+
panels: [...checkDevtoolsPanels([builtIn]), ...packagePanels],
|
|
236
|
+
routes: {
|
|
237
|
+
...processPanel ? { processPanel } : {},
|
|
238
|
+
...requestLog ? { requestLog } : {},
|
|
239
|
+
listRoutes: () => listRoutes(),
|
|
240
|
+
getOpenApiDocument: openApi.getOpenApiDocument,
|
|
241
|
+
getPostmanCollection: openApi.getPostmanCollection
|
|
242
|
+
},
|
|
243
|
+
log
|
|
244
|
+
});
|
|
245
|
+
}
|
|
137
246
|
/** Runs `EXPLAIN (FORMAT JSON)` for a stored Postgres query on its own connection. */
|
|
138
247
|
async function explainQuery(query) {
|
|
139
248
|
const { dataSourceRegistry } = await import("@warlock.js/cascade");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-connector.mjs","names":[],"sources":["../../../../../../../packages/devtools/src/devtools-connector.ts"],"sourcesContent":["/**\n * The devtools connector for `warlock.config.ts > connectors`.\n *\n * Deliberately a plain object with TYPE-ONLY imports from core: the config\n * file that constructs it must not drag core's runtime graph in at\n * config-load time. Core is imported lazily inside `boot()`, where the app\n * has already loaded it — see `queue/src/queue-connector.ts`, the pattern\n * this mirrors.\n */\nimport type { Connector, ConnectorLifecyclePhase } from \"@warlock.js/core\";\nimport { loadDevtoolsPanels } from \"./panels\";\nimport { loadProcessPanel, processesDevtoolsPanel } from \"./process-panel\";\nimport { createCollector } from \"./collector\";\nimport { resolveDevtoolsOptions } from \"./options\";\nimport type { DevtoolsRequestLogSource, DevtoolsRouteRow } from \"./server\";\nimport { attachAgentTraceSource } from \"./sources/agent-trace-source\";\nimport { attachAiSource } from \"./sources/ai-source\";\nimport { attachCacheSource } from \"./sources/cache-source\";\nimport { attachLogSource } from \"./sources/log-source\";\nimport { attachMailSource } from \"./sources/mail-source\";\nimport { attachQuerySource } from \"./sources/query-source\";\nimport { attachTracingSource } from \"./sources/tracing-source\";\nimport type { DevtoolsDisposer, DevtoolsOptions, DevtoolsQuery } from \"./types\";\n\n/**\n * Boots after the queue connector (priority 11), which is the last\n * built-in/framework connector to claim a priority; devtools has nothing\n * that depends on it, so it simply goes last.\n */\nexport const DEVTOOLS_CONNECTOR_PRIORITY = 12;\n\n/**\n * The app's `src/config/devtools.ts`, or `{}` when there is none (or the\n * config store cannot be read, which must never stop the dev server).\n */\nfunction readConfiguredOptions(readConfig: () => { get(name: string): unknown }): DevtoolsOptions {\n try {\n const value = readConfig().get(\"devtools\");\n\n return value !== null && typeof value === \"object\" ? (value as DevtoolsOptions) : {};\n } catch {\n return {};\n }\n}\n\n/** Options accepted by `devtoolsConnector()`. */\nexport type DevtoolsConnectorOptions = DevtoolsOptions;\n\n/**\n * Construct the devtools connector.\n *\n * Refuses to run outside development: `boot()` checks\n * `Application.runtimeStrategy` and, when it isn't `\"development\"`, logs one\n * warning and returns without mounting a route or subscribing to anything.\n * In development it attaches every source (tracing, queries, cache, mail,\n * logs), loads the panels listed in the `panels` option, then mounts the\n * dashboard's routes on the HTTP server — before it\n * starts listening, the only point in the boot sequence where mounting is\n * possible (see `queue/src/dashboard-boot.ts` for the same constraint).\n *\n * Apps don't call this: `warlock dev` registers it automatically when the\n * package is installed (`warlock add devtools`). Keep it OUT of\n * `warlock.config.ts` — devtools is a dev dependency, so a production\n * install doesn't have it and a config import of it would fail there.\n * Options come from the app's `src/config/devtools.ts` instead (a plain\n * object, no import of this package); options passed here win over it.\n */\nexport function devtoolsConnector(options: DevtoolsConnectorOptions = {}): Connector {\n let active = false;\n const disposers: DevtoolsDisposer[] = [];\n\n const connector: Connector = {\n name: \"devtools\",\n priority: DEVTOOLS_CONNECTOR_PRIORITY,\n // Core's `ConnectorLifecyclePhase.Late`; spelled out so this module stays\n // free of a runtime import of core.\n lifecyclePhase: \"late\" as ConnectorLifecyclePhase,\n isActive: () => active,\n async boot() {\n const core = await import(\"@warlock.js/core\");\n const { Application, getHttpServer } = core;\n const { log } = await import(\"@warlock.js/logger\");\n\n if (Application.runtimeStrategy !== \"development\") {\n log.warn(\n \"devtools\",\n \"disabled\",\n \"@warlock.js/devtools only runs in development; it is not mounted\",\n );\n return;\n }\n\n const resolved = resolveDevtoolsOptions({\n ...readConfiguredOptions(() => core.config),\n ...options,\n });\n const collector = createCollector(resolved);\n\n await attachSource(log, \"tracing\", () => attachTracingSource(collector, resolved));\n await attachSource(log, \"query\", () => attachQuerySource(collector));\n await attachSource(log, \"cache\", () => attachCacheSource(collector));\n await attachSource(log, \"mail\", () => attachMailSource(collector));\n await attachSource(log, \"log\", () => attachLogSource(collector));\n\n const ai = await attachAiSource(resolved.maxRequests);\n disposers.push(ai.dispose);\n\n const agentTraces = await attachAgentTraceSource();\n disposers.push(agentTraces.dispose);\n\n const { mountDevtoolsRoutes } = await import(\"./server\");\n const postmanBuilder = await findPostmanBuilder();\n const requestLog = await findRequestLogSource();\n const processPanel = await loadProcessPanel();\n const builtIn = processesDevtoolsPanel(processPanel);\n // A panel that fails to load or reuses an id is reported and left out;\n // it never stops the dashboard or the app.\n const panels = await loadDevtoolsPanels(resolved.panels ?? [], {\n root: \"rootPath\" in core ? core.rootPath() : process.cwd(),\n warn: (message) => log.warn(\"devtools\", \"panel\", message),\n taken: new Map([[builtIn.id, builtIn.title]]),\n });\n\n mountDevtoolsRoutes(getHttpServer(), {\n collector,\n ai,\n agentTraces,\n ...(processPanel ? { processPanel } : {}),\n panels,\n options: resolved,\n requestLog,\n isDevelopment: () => Application.runtimeStrategy === \"development\",\n warn: (message) => log.warn(\"devtools\", \"refused\", message),\n explain: (query) => explainQuery(query),\n listRoutes: () => listRoutes(),\n getOpenApiDocument: () => getOpenApiDocument(),\n getPostmanCollection: postmanBuilder\n ? async () => unwrapCollection(await postmanBuilder())\n : undefined,\n });\n\n // An N+1 is worth a terminal line, not just a badge the developer has\n // to go looking for: one warning per offending query shape, with the\n // line that issued it.\n disposers.push(\n collector.subscribe((event) => {\n if (event.type !== \"request\" || event.data.warningCount === 0) return;\n\n for (const warning of collector.getRequest(event.data.id)?.warnings ?? []) {\n const where = warning.caller ? ` — ${warning.caller.file}:${warning.caller.line}` : \"\";\n\n log.warn(\n \"devtools\",\n \"n+1\",\n `${warning.message}${where} (${event.data.method} ${event.data.path})`,\n );\n }\n }),\n );\n\n active = true;\n\n log.info(\"devtools\", \"ready\", `devtools ready at ${resolved.path}`);\n },\n async start() {},\n async restart() {\n await connector.shutdown();\n await connector.start();\n },\n async shutdown() {\n for (const dispose of disposers.splice(0)) dispose();\n active = false;\n },\n shouldRestart: () => false,\n };\n\n /** Attaches one source, logging and continuing when it fails to attach. */\n async function attachSource(\n logger: { warn: (module: string, action: string, message: string) => unknown },\n name: string,\n attach: () => Promise<DevtoolsDisposer>,\n ): Promise<void> {\n try {\n disposers.push(await attach());\n } catch (error) {\n logger.warn(\n \"devtools\",\n \"source-failed\",\n `devtools' ${name} source failed to attach: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n return connector;\n}\n\n/** Runs `EXPLAIN (FORMAT JSON)` for a stored Postgres query on its own connection. */\nasync function explainQuery(query: DevtoolsQuery): Promise<unknown> {\n const { dataSourceRegistry } = await import(\"@warlock.js/cascade\");\n const dataSource = dataSourceRegistry.get(query.connection);\n const { rows } = await dataSource.raw(`EXPLAIN (FORMAT JSON) ${query.sql}`, query.bindings);\n\n return rows;\n}\n\n/** Lists every registered HTTP route — the same source `warlock routes --json` reads. */\nasync function listRoutes(): Promise<DevtoolsRouteRow[]> {\n const { router } = await import(\"@warlock.js/core\");\n\n return router.list().map((route) => ({\n method: route.method.toUpperCase(),\n path: route.path,\n name: route.name,\n middleware: route.middleware?.map((middleware) => middleware.name || \"anonymous\"),\n }));\n}\n\n/**\n * Builds the OpenAPI 3.1 document from the routes registered in this process —\n * the same generator behind `warlock generate.openapi`. Core is imported\n * lazily so this module stays free of a load-time dependency on it.\n */\nasync function getOpenApiDocument(): Promise<object> {\n const { getDevelopmentOpenApiDocument } = await import(\"@warlock.js/core\");\n const { document } = await getDevelopmentOpenApiDocument();\n\n return document;\n}\n\ntype PostmanBuilder = () => Promise<unknown>;\n\n/**\n * Looks up core's Postman collection builder, `getDevelopmentPostmanCollection`.\n * Older cores do not export it; the route then answers 503. The lookup is\n * guarded because a namespace without the export may throw on access. Core is\n * imported lazily, like the OpenAPI document above.\n */\nasync function findPostmanBuilder(): Promise<PostmanBuilder | undefined> {\n try {\n const core: Record<string, unknown> = await import(\"@warlock.js/core\");\n const build = core.getDevelopmentPostmanCollection;\n\n return typeof build === \"function\" ? (build as PostmanBuilder) : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Looks up core's persistent request log reader. Older cores do not export\n * it; the dashboard then shows the in-memory requests only. Core is imported\n * lazily, like the builders above.\n */\nasync function findRequestLogSource(): Promise<DevtoolsRequestLogSource | undefined> {\n try {\n const core: Record<string, unknown> = await import(\"@warlock.js/core\");\n const { listRequestLogs, getRequestLog, requestLogToCurl, compileRequestLogFilter } = core;\n\n if (\n typeof listRequestLogs !== \"function\" ||\n typeof getRequestLog !== \"function\" ||\n typeof requestLogToCurl !== \"function\" ||\n typeof compileRequestLogFilter !== \"function\"\n ) {\n return undefined;\n }\n\n return {\n list: (filter) => listRequestLogs(filter),\n get: (id) => getRequestLog(id),\n curl: (record, baseUrl) => requestLogToCurl(record, baseUrl),\n compile: (filter) => compileRequestLogFilter(filter),\n };\n } catch {\n return undefined;\n }\n}\n\n/**\n * Core may return the collection itself or wrap it in `{ collection, warnings }`,\n * like the OpenAPI generator's `{ document, warnings }`.\n */\nfunction unwrapCollection(result: unknown): object {\n if (result && typeof result === \"object\" && \"collection\" in result) {\n return (result as { collection: object }).collection;\n }\n\n return result as object;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,MAAa,8BAA8B;;;;;AAM3C,SAAS,sBAAsB,YAAmE;CAChG,IAAI;EACF,MAAM,QAAQ,WAAW,CAAC,CAAC,IAAI,UAAU;EAEzC,OAAO,UAAU,QAAQ,OAAO,UAAU,WAAY,QAA4B,CAAC;CACrF,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,kBAAkB,UAAoC,CAAC,GAAc;CACnF,IAAI,SAAS;CACb,MAAM,YAAgC,CAAC;CAEvC,MAAM,YAAuB;EAC3B,MAAM;EACN;EAGA,gBAAgB;EAChB,gBAAgB;EAChB,MAAM,OAAO;GACX,MAAM,OAAO,MAAM,OAAO;GAC1B,MAAM,EAAE,aAAa,kBAAkB;GACvC,MAAM,EAAE,QAAQ,MAAM,OAAO;GAE7B,IAAI,YAAY,oBAAoB,eAAe;IACjD,IAAI,KACF,YACA,YACA,kEACF;IACA;GACF;GAEA,MAAM,WAAW,uBAAuB;IACtC,GAAG,4BAA4B,KAAK,MAAM;IAC1C,GAAG;GACL,CAAC;GACD,MAAM,YAAY,gBAAgB,QAAQ;GAE1C,MAAM,aAAa,KAAK,iBAAiB,oBAAoB,WAAW,QAAQ,CAAC;GACjF,MAAM,aAAa,KAAK,eAAe,kBAAkB,SAAS,CAAC;GACnE,MAAM,aAAa,KAAK,eAAe,kBAAkB,SAAS,CAAC;GACnE,MAAM,aAAa,KAAK,cAAc,iBAAiB,SAAS,CAAC;GACjE,MAAM,aAAa,KAAK,aAAa,gBAAg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nE,QAAQ;EACN;CACF;AACF;;;;;;AAOA,eAAe,uBAAsE;CACnF,IAAI;EAEF,MAAM,EAAE,iBAAiB,eAAe,kBAAkB,4BAA4B,MAD1C,OAAO;EAGnD,IACE,OAAO,oBAAoB,cAC3B,OAAO,kBAAkB,cACzB,OAAO,qBAAqB,cAC5B,OAAO,4BAA4B,YAEnC;EAGF,OAAO;GACL,OAAO,WAAW,gBAAgB,MAAM;GACxC,MAAM,OAAO,cAAc,EAAE;GAC7B,OAAO,QAAQ,YAAY,iBAAiB,QAAQ,OAAO;GAC3D,UAAU,WAAW,wBAAwB,MAAM;EACrD;CACF,QAAQ;EACN;CACF;AACF;;;;;AAMA,SAAS,iBAAiB,QAAyB;CACjD,IAAI,UAAU,OAAO,WAAW,YAAY,gBAAgB,QAC1D,OAAQ,OAAkC;CAG5C,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"devtools-connector.mjs","names":[],"sources":["../../../../../../../packages/devtools/src/devtools-connector.ts"],"sourcesContent":["/**\n * The devtools connector for `warlock.config.ts > connectors`.\n *\n * Deliberately a plain object with TYPE-ONLY imports from core: the config\n * file that constructs it must not drag core's runtime graph in at\n * config-load time. Core is imported lazily inside `boot()`, where the app\n * has already loaded it — see `queue/src/queue-connector.ts`, the pattern\n * this mirrors.\n */\nimport type { Connector, ConnectorLifecyclePhase } from \"@warlock.js/core\";\nimport { checkDevtoolsPanels, loadDevtoolsPanels } from \"./panels\";\nimport { loadProcessPanel, processesDevtoolsPanel } from \"./process-panel\";\nimport { createCollector } from \"./collector\";\nimport { resolveDevtoolsOptions } from \"./options\";\nimport { DEVTOOLS_PRODUCTION_DEFAULTS } from \"./production/options\";\nimport type { DevtoolsRequestLogSource, DevtoolsRouteRow, MountDevtoolsRoutesDeps } from \"./server\";\nimport { attachAgentTraceSource } from \"./sources/agent-trace-source\";\nimport { attachAiSource } from \"./sources/ai-source\";\nimport { attachCacheSource } from \"./sources/cache-source\";\nimport { attachLogSource } from \"./sources/log-source\";\nimport { attachMailSource } from \"./sources/mail-source\";\nimport { attachQuerySource } from \"./sources/query-source\";\nimport { attachTracingSource } from \"./sources/tracing-source\";\nimport type { DevtoolsDisposer, DevtoolsOptions, DevtoolsQuery } from \"./types\";\n\n/**\n * Boots after the queue connector (priority 11), which is the last\n * built-in/framework connector to claim a priority; devtools has nothing\n * that depends on it, so it simply goes last.\n */\nexport const DEVTOOLS_CONNECTOR_PRIORITY = 12;\n\n/**\n * The app's `src/config/devtools.ts`, or `{}` when there is none (or the\n * config store cannot be read, which must never stop the dev server).\n */\nfunction readConfiguredOptions(readConfig: () => { get(name: string): unknown }): DevtoolsOptions {\n try {\n const value = readConfig().get(\"devtools\");\n\n return value !== null && typeof value === \"object\" ? (value as DevtoolsOptions) : {};\n } catch {\n return {};\n }\n}\n\n/** Options accepted by `devtoolsConnector()`. */\nexport type DevtoolsConnectorOptions = DevtoolsOptions;\n\n/**\n * Construct the devtools connector.\n *\n * Outside development, `boot()` checks `Application.runtimeStrategy` and\n * `devtools.production.enabled`: unless both say production, it logs one\n * warning and returns without mounting a route or subscribing to anything.\n * With `enabled: true` in production it starts the signed-in production\n * monitor (`bootProductionDevtools`), which refuses to boot when its\n * configuration is incomplete. In development it attaches every source\n * (tracing, queries, cache, mail, logs), loads the panels listed in the\n * `panels` option, then mounts the dashboard's routes on the HTTP server —\n * before it starts listening, the only point in the boot sequence where\n * mounting is possible (see `queue/src/dashboard-boot.ts` for the same\n * constraint).\n *\n * In development apps don't call this: `warlock dev` registers it\n * automatically when the package is installed (`warlock add devtools`). To\n * run the production monitor, list `devtoolsConnector()` in\n * `warlock.config.ts > connectors` (and keep the package in `dependencies`).\n * Options come from the app's `src/config/devtools.ts` (a plain object, no\n * import of this package); options passed here win over it.\n */\nexport function devtoolsConnector(options: DevtoolsConnectorOptions = {}): Connector {\n let active = false;\n const disposers: DevtoolsDisposer[] = [];\n\n const connector: Connector = {\n name: \"devtools\",\n priority: DEVTOOLS_CONNECTOR_PRIORITY,\n // Core's `ConnectorLifecyclePhase.Late`; spelled out so this module stays\n // free of a runtime import of core.\n lifecyclePhase: \"late\" as ConnectorLifecyclePhase,\n isActive: () => active,\n async boot() {\n const core = await import(\"@warlock.js/core\");\n const { Application, getHttpServer } = core;\n const { log } = await import(\"@warlock.js/logger\");\n\n const resolved = resolveDevtoolsOptions({\n ...readConfiguredOptions(() => core.config),\n ...options,\n });\n\n if (Application.runtimeStrategy === \"production\" && resolved.production?.enabled === true) {\n disposers.push(await bootProduction(core, log, resolved));\n active = true;\n\n return;\n }\n\n if (Application.runtimeStrategy !== \"development\") {\n log.warn(\n \"devtools\",\n \"disabled\",\n \"@warlock.js/devtools only runs in development unless devtools.production.enabled is true; it is not mounted\",\n );\n return;\n }\n\n const collector = createCollector(resolved);\n\n await attachSource(log, \"tracing\", () => attachTracingSource(collector, resolved));\n await attachSource(log, \"query\", () => attachQuerySource(collector));\n await attachSource(log, \"cache\", () => attachCacheSource(collector));\n await attachSource(log, \"mail\", () => attachMailSource(collector));\n await attachSource(log, \"log\", () => attachLogSource(collector));\n\n const ai = await attachAiSource(resolved.maxRequests);\n disposers.push(ai.dispose);\n\n const agentTraces = await attachAgentTraceSource();\n disposers.push(agentTraces.dispose);\n\n const { mountDevtoolsRoutes } = await import(\"./server\");\n const postmanBuilder = await findPostmanBuilder();\n const requestLog = await findRequestLogSource();\n const processPanel = await loadProcessPanel();\n const builtIn = processesDevtoolsPanel(processPanel);\n // A panel that fails to load or reuses an id is reported and left out;\n // it never stops the dashboard or the app.\n const panels = await loadDevtoolsPanels(resolved.panels ?? [], {\n root: \"rootPath\" in core ? core.rootPath() : process.cwd(),\n warn: (message) => log.warn(\"devtools\", \"panel\", message),\n taken: new Map([[builtIn.id, builtIn.title]]),\n });\n\n const insightsWiring = await wireDevelopmentInsights(collector, resolved, log, disposers);\n\n mountDevtoolsRoutes(getHttpServer(), {\n collector,\n ai,\n agentTraces,\n ...(processPanel ? { processPanel } : {}),\n panels,\n options: resolved,\n ...insightsWiring,\n requestLog,\n isDevelopment: () => Application.runtimeStrategy === \"development\",\n warn: (message) => log.warn(\"devtools\", \"refused\", message),\n explain: (query) => explainQuery(query),\n listRoutes: () => listRoutes(),\n getOpenApiDocument: () => getOpenApiDocument(),\n getPostmanCollection: postmanBuilder\n ? async () => unwrapCollection(await postmanBuilder())\n : undefined,\n });\n\n // An N+1 is worth a terminal line, not just a badge the developer has\n // to go looking for: one warning per offending query shape, with the\n // line that issued it.\n disposers.push(\n collector.subscribe((event) => {\n if (event.type !== \"request\" || event.data.warningCount === 0) return;\n\n for (const warning of collector.getRequest(event.data.id)?.warnings ?? []) {\n const where = warning.caller ? ` — ${warning.caller.file}:${warning.caller.line}` : \"\";\n\n log.warn(\n \"devtools\",\n \"n+1\",\n `${warning.message}${where} (${event.data.method} ${event.data.path})`,\n );\n }\n }),\n );\n\n active = true;\n\n log.info(\"devtools\", \"ready\", `devtools ready at ${resolved.path}`);\n },\n async start() {},\n async restart() {\n await connector.shutdown();\n await connector.start();\n },\n async shutdown() {\n for (const dispose of disposers.splice(0)) dispose();\n active = false;\n },\n shouldRestart: () => false,\n };\n\n /** Attaches one source, logging and continuing when it fails to attach. */\n async function attachSource(\n logger: { warn: (module: string, action: string, message: string) => unknown },\n name: string,\n attach: () => Promise<DevtoolsDisposer>,\n ): Promise<void> {\n try {\n disposers.push(await attach());\n } catch (error) {\n logger.warn(\n \"devtools\",\n \"source-failed\",\n `devtools' ${name} source failed to attach: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n\n return connector;\n}\n\ntype ConnectorLogger = {\n info: (module: string, action: string, message: string) => unknown;\n warn: (module: string, action: string, message: string) => unknown;\n error: (module: string, action: string, message: string) => unknown;\n};\n\n/**\n * Development: the statistics, resources, health and jobs behind the\n * Resources, Queries (statistics), Routes (statistics), Errors, Health and\n * Jobs tabs. Wrapped as a whole: when anything fails to start, one line is\n * logged and the dashboard mounts without insights (those tabs then say they\n * are not available). It never stops the dashboard.\n */\nasync function wireDevelopmentInsights(\n collector: ReturnType<typeof createCollector>,\n resolved: ReturnType<typeof resolveDevtoolsOptions>,\n log: ConnectorLogger,\n disposers: DevtoolsDisposer[],\n): Promise<Pick<MountDevtoolsRoutesDeps, \"instance\" | \"insights\" | \"explainShape\">> {\n const stops: DevtoolsDisposer[] = [];\n\n try {\n const capture = await import(\"./production/capture\");\n const insights = await import(\"./production/insights\");\n const instance = insights.createInstanceInfo();\n const queries = capture.createQueryStats({\n maxShapes: DEVTOOLS_PRODUCTION_DEFAULTS.maxShapes,\n instance: instance.id,\n });\n const routes = capture.createRouteStats({\n maxRoutes: DEVTOOLS_PRODUCTION_DEFAULTS.maxRoutes,\n instance: instance.id,\n });\n const errors = capture.createErrorGroups({\n maxGroups: DEVTOOLS_PRODUCTION_DEFAULTS.maxErrorGroups,\n });\n const logs = capture.createRecentLogs({ maxEntries: 200 });\n\n stops.push(\n capture.attachDevelopmentStats(collector, {\n queries,\n routes,\n errors,\n logs,\n nPlusOneThreshold: resolved.nPlusOneThreshold,\n }),\n );\n\n const resources = insights.createResourceMonitor();\n const health = insights.createHealthHistory();\n\n resources.start();\n health.start();\n stops.push(\n () => resources.stop(),\n () => health.stop(),\n );\n\n const reporter = insights.createLocalReporter({\n instance,\n resources,\n health,\n jobs: insights.createJobsReader(),\n queries,\n routes,\n errors,\n logs,\n counters: null,\n });\n const explainShape = capture.createShapeExplainer({\n queries,\n executing: false,\n instance: instance.id,\n });\n\n disposers.push(...stops);\n\n return { instance, insights: insights.createLocalInsights(reporter), explainShape };\n } catch (error) {\n for (const stop of stops) {\n try {\n stop();\n } catch {\n // Cleanup after a failed start must not hide the reason.\n }\n }\n\n log.warn(\n \"devtools\",\n \"insights-failed\",\n `devtools' statistics could not start, so the Resources, Queries, Routes, Errors, Health and Jobs tabs are not available: ${error instanceof Error ? error.message : String(error)}`,\n );\n\n return {};\n }\n}\n\n/**\n * Starts the production monitor: loads the panels in production mode and\n * hands everything to `bootProductionDevtools`, which refuses to boot (throws\n * `DevtoolsProductionConfigError`) when the configuration is incomplete.\n */\nasync function bootProduction(\n core: typeof import(\"@warlock.js/core\"),\n log: ConnectorLogger,\n resolved: ReturnType<typeof resolveDevtoolsOptions>,\n): Promise<DevtoolsDisposer> {\n const { bootProductionDevtools } = await import(\"./production/boot\");\n const requestLog = await findRequestLogSource();\n // The Processes panel reads an app file; load it only when the project turned that tab on.\n const processPanel =\n resolved.production?.panels?.processes === true ? await loadProcessPanel() : undefined;\n const builtIn = processesDevtoolsPanel(processPanel);\n const packagePanels = await loadDevtoolsPanels(resolved.panels ?? [], {\n root: \"rootPath\" in core ? core.rootPath() : process.cwd(),\n warn: (message) => log.warn(\"devtools\", \"panel\", message),\n taken: new Map([[builtIn.id, builtIn.title]]),\n mode: \"production\",\n });\n // `warlock start` registers no development OpenAPI provider: the API tab, when turned on, builds its own.\n const { createProductionOpenApi } = await import(\"./production/openapi\");\n const openApi = createProductionOpenApi(core);\n\n return bootProductionDevtools({\n options: resolved,\n env: process.env,\n server: core.getHttpServer(),\n panels: [...checkDevtoolsPanels([builtIn]), ...packagePanels],\n routes: {\n ...(processPanel ? { processPanel } : {}),\n ...(requestLog ? { requestLog } : {}),\n listRoutes: () => listRoutes(),\n getOpenApiDocument: openApi.getOpenApiDocument,\n getPostmanCollection: openApi.getPostmanCollection,\n },\n log,\n });\n}\n\n/** Runs `EXPLAIN (FORMAT JSON)` for a stored Postgres query on its own connection. */\nasync function explainQuery(query: DevtoolsQuery): Promise<unknown> {\n const { dataSourceRegistry } = await import(\"@warlock.js/cascade\");\n const dataSource = dataSourceRegistry.get(query.connection);\n const { rows } = await dataSource.raw(`EXPLAIN (FORMAT JSON) ${query.sql}`, query.bindings);\n\n return rows;\n}\n\n/** Lists every registered HTTP route — the same source `warlock routes --json` reads. */\nasync function listRoutes(): Promise<DevtoolsRouteRow[]> {\n const { router } = await import(\"@warlock.js/core\");\n\n return router.list().map((route) => ({\n method: route.method.toUpperCase(),\n path: route.path,\n name: route.name,\n middleware: route.middleware?.map((middleware) => middleware.name || \"anonymous\"),\n }));\n}\n\n/**\n * Builds the OpenAPI 3.1 document from the routes registered in this process —\n * the same generator behind `warlock generate.openapi`. Core is imported\n * lazily so this module stays free of a load-time dependency on it.\n */\nasync function getOpenApiDocument(): Promise<object> {\n const { getDevelopmentOpenApiDocument } = await import(\"@warlock.js/core\");\n const { document } = await getDevelopmentOpenApiDocument();\n\n return document;\n}\n\ntype PostmanBuilder = () => Promise<unknown>;\n\n/**\n * Looks up core's Postman collection builder, `getDevelopmentPostmanCollection`.\n * Older cores do not export it; the route then answers 503. The lookup is\n * guarded because a namespace without the export may throw on access. Core is\n * imported lazily, like the OpenAPI document above.\n */\nasync function findPostmanBuilder(): Promise<PostmanBuilder | undefined> {\n try {\n const core: Record<string, unknown> = await import(\"@warlock.js/core\");\n const build = core.getDevelopmentPostmanCollection;\n\n return typeof build === \"function\" ? (build as PostmanBuilder) : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Looks up core's persistent request log reader. Older cores do not export\n * it; the dashboard then shows the in-memory requests only. Core is imported\n * lazily, like the builders above.\n */\nasync function findRequestLogSource(): Promise<DevtoolsRequestLogSource | undefined> {\n try {\n const core: Record<string, unknown> = await import(\"@warlock.js/core\");\n const { listRequestLogs, getRequestLog, requestLogToCurl, compileRequestLogFilter } = core;\n\n if (\n typeof listRequestLogs !== \"function\" ||\n typeof getRequestLog !== \"function\" ||\n typeof requestLogToCurl !== \"function\" ||\n typeof compileRequestLogFilter !== \"function\"\n ) {\n return undefined;\n }\n\n return {\n list: (filter) => listRequestLogs(filter),\n get: (id) => getRequestLog(id),\n curl: (record, baseUrl) => requestLogToCurl(record, baseUrl),\n compile: (filter) => compileRequestLogFilter(filter),\n };\n } catch {\n return undefined;\n }\n}\n\n/**\n * Core may return the collection itself or wrap it in `{ collection, warnings }`,\n * like the OpenAPI generator's `{ document, warnings }`.\n */\nfunction unwrapCollection(result: unknown): object {\n if (result && typeof result === \"object\" && \"collection\" in result) {\n return (result as { collection: object }).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;EACN;CACF;AACF;;;;;AAMA,SAAS,iBAAiB,QAAyB;CACjD,IAAI,UAAU,OAAO,WAAW,YAAY,gBAAgB,QAC1D,OAAQ,OAAkC;CAG5C,OAAO;AACT"}
|
package/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DevtoolsAgentRun, DevtoolsAgentTraceEvent } from "./sources/agent-trace-source.mjs";
|
|
2
2
|
import { DevtoolsAiEvent, DevtoolsAiRun } from "./sources/ai-source.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { DEVTOOLS_BUILT_IN_PANELS, DEVTOOLS_FAILURE_AUDIT_TYPES, DEVTOOLS_LATENCY_BUCKETS_MS, DevtoolsAccountView, DevtoolsApiErrorBody, DevtoolsAuditEntry, DevtoolsAuditType, DevtoolsAuthStepResult, DevtoolsBuiltInPanelId, DevtoolsCaptureCounters, DevtoolsCreatedInvite, DevtoolsErrorCode, DevtoolsErrorGroup, DevtoolsErrorsView, DevtoolsExplainResult, DevtoolsHealthReport, DevtoolsHealthView, DevtoolsHistogram, DevtoolsInstanceInfo, DevtoolsInstanceReport, DevtoolsInstancesView, DevtoolsInviteView, DevtoolsJobsReport, DevtoolsJobsView, DevtoolsLogRow, DevtoolsLoginInput, DevtoolsLogsView, DevtoolsMode, DevtoolsPanelInfo, DevtoolsPasswordSource, DevtoolsQueryShapeRow, DevtoolsQueryShapeStats, DevtoolsQueryStatsView, DevtoolsRecoveryCodes, DevtoolsReportLogEntry, DevtoolsResourcePoint, DevtoolsResourceSnapshot, DevtoolsResourcesView, DevtoolsRole, DevtoolsRoutePhaseStats, DevtoolsRouteStats, DevtoolsRouteStatsRow, DevtoolsRouteStatsView, DevtoolsSampleDetail, DevtoolsSampleQuery, DevtoolsSampleSummary, DevtoolsScheduleInfo, DevtoolsSessionInfo, DevtoolsSessionStage, DevtoolsSessionView, DevtoolsTotpEnrolment, DevtoolsUserListView } from "./production/contracts.mjs";
|
|
4
|
+
import { DevtoolsBackground, DevtoolsCacheOperation, DevtoolsCallerLocation, DevtoolsCollector, DevtoolsDisposer, DevtoolsLogEntry, DevtoolsMail, DevtoolsMailAttachment, DevtoolsMailSummary, DevtoolsOptions, DevtoolsPanel, DevtoolsPanelEntry, DevtoolsPanelExport, DevtoolsPanelFactoryContext, DevtoolsPanelMethod, DevtoolsPanelRequest, DevtoolsPanelRoute, DevtoolsPanels, DevtoolsPhase, DevtoolsProductionOptions, DevtoolsQuery, DevtoolsRequest, DevtoolsRequestDetail, DevtoolsRequestSummary, DevtoolsStreamEvent, DevtoolsWarning, ResolvedDevtoolsOptions } from "./types.mjs";
|
|
4
5
|
import { devtoolsConnector } from "./devtools-connector.mjs";
|
|
5
|
-
|
|
6
|
+
import { DEVTOOLS_PANEL_TOKENS } from "./panel-tokens.mjs";
|
|
7
|
+
export { type DEVTOOLS_BUILT_IN_PANELS, type DEVTOOLS_FAILURE_AUDIT_TYPES, type DEVTOOLS_LATENCY_BUCKETS_MS, DEVTOOLS_PANEL_TOKENS, type DevtoolsAccountView, type DevtoolsAgentRun, type DevtoolsAgentTraceEvent, type DevtoolsAiEvent, type DevtoolsAiRun, type DevtoolsApiErrorBody, type DevtoolsAuditEntry, type DevtoolsAuditType, type DevtoolsAuthStepResult, type DevtoolsBackground, type DevtoolsBuiltInPanelId, type DevtoolsCacheOperation, type DevtoolsCallerLocation, type DevtoolsCaptureCounters, type DevtoolsCollector, type DevtoolsCreatedInvite, type DevtoolsDisposer, type DevtoolsErrorCode, type DevtoolsErrorGroup, type DevtoolsErrorsView, type DevtoolsExplainResult, type DevtoolsHealthReport, type DevtoolsHealthView, type DevtoolsHistogram, type DevtoolsInstanceInfo, type DevtoolsInstanceReport, type DevtoolsInstancesView, type DevtoolsInviteView, type DevtoolsJobsReport, type DevtoolsJobsView, type DevtoolsLogEntry, type DevtoolsLogRow, type DevtoolsLoginInput, type DevtoolsLogsView, type DevtoolsMail, type DevtoolsMailAttachment, type DevtoolsMailSummary, type DevtoolsMode, type DevtoolsOptions, type DevtoolsPanel, type DevtoolsPanelEntry, type DevtoolsPanelExport, type DevtoolsPanelFactoryContext, type DevtoolsPanelInfo, type DevtoolsPanelMethod, type DevtoolsPanelRequest, type DevtoolsPanelRoute, type DevtoolsPanels, type DevtoolsPasswordSource, type DevtoolsPhase, type DevtoolsProductionOptions, type DevtoolsQuery, type DevtoolsQueryShapeRow, type DevtoolsQueryShapeStats, type DevtoolsQueryStatsView, type DevtoolsRecoveryCodes, type DevtoolsReportLogEntry, type DevtoolsRequest, type DevtoolsRequestDetail, type DevtoolsRequestSummary, type DevtoolsResourcePoint, type DevtoolsResourceSnapshot, type DevtoolsResourcesView, type DevtoolsRole, type DevtoolsRoutePhaseStats, type DevtoolsRouteStats, type DevtoolsRouteStatsRow, type DevtoolsRouteStatsView, type DevtoolsSampleDetail, type DevtoolsSampleQuery, type DevtoolsSampleSummary, type DevtoolsScheduleInfo, type DevtoolsSessionInfo, type DevtoolsSessionStage, type DevtoolsSessionView, type DevtoolsStreamEvent, type DevtoolsTotpEnrolment, type DevtoolsUserListView, type DevtoolsWarning, type ResolvedDevtoolsOptions, devtoolsConnector };
|
package/esm/index.mjs
CHANGED
package/esm/options.mjs
CHANGED
|
@@ -13,7 +13,8 @@ function resolveDevtoolsOptions(options = {}) {
|
|
|
13
13
|
nPlusOneThreshold,
|
|
14
14
|
allowedHosts: options.allowedHosts ?? [],
|
|
15
15
|
allowProxied: options.allowProxied ?? false,
|
|
16
|
-
panels: options.panels ?? []
|
|
16
|
+
panels: options.panels ?? [],
|
|
17
|
+
...options.production === void 0 ? {} : { production: options.production }
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
|
package/esm/options.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","names":[],"sources":["../../../../../../../packages/devtools/src/options.ts"],"sourcesContent":["import type { DevtoolsOptions, ResolvedDevtoolsOptions } from \"./types\";\n\n/** Resolves dashboard options and rejects invalid capacity or URL-prefix values. */\nexport function resolveDevtoolsOptions(options: DevtoolsOptions = {}): ResolvedDevtoolsOptions {\n const path = (options.path ?? \"/__warlock\").replace(/\\/+$/, \"\");\n const maxRequests = options.maxRequests ?? 200;\n const nPlusOneThreshold = options.nPlusOneThreshold ?? 5;\n\n if (!path || !path.startsWith(\"/\")) {\n throw new Error('Devtools option \"path\" must be a non-root path starting with \"/\".');\n }\n\n if (maxRequests < 1) {\n throw new Error('Devtools option \"maxRequests\" must be at least 1.');\n }\n\n if (nPlusOneThreshold < 2) {\n throw new Error('Devtools option \"nPlusOneThreshold\" must be at least 2.');\n }\n\n return {\n path,\n maxRequests,\n nPlusOneThreshold,\n allowedHosts: options.allowedHosts ?? [],\n allowProxied: options.allowProxied ?? false,\n panels: options.panels ?? [],\n };\n}\n"],"mappings":";;AAGA,SAAgB,uBAAuB,UAA2B,CAAC,GAA4B;CAC7F,MAAM,QAAQ,QAAQ,QAAQ,aAAY,CAAE,QAAQ,QAAQ,EAAE;CAC9D,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,oBAAoB,QAAQ,qBAAqB;CAEvD,IAAI,CAAC,QAAQ,CAAC,KAAK,WAAW,GAAG,GAC/B,MAAM,IAAI,MAAM,uEAAmE;CAGrF,IAAI,cAAc,GAChB,MAAM,IAAI,MAAM,qDAAmD;CAGrE,IAAI,oBAAoB,GACtB,MAAM,IAAI,MAAM,2DAAyD;CAG3E,OAAO;EACL;EACA;EACA;EACA,cAAc,QAAQ,gBAAgB,CAAC;EACvC,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"options.mjs","names":[],"sources":["../../../../../../../packages/devtools/src/options.ts"],"sourcesContent":["import type { DevtoolsOptions, ResolvedDevtoolsOptions } from \"./types\";\n\n/** Resolves dashboard options and rejects invalid capacity or URL-prefix values. */\nexport function resolveDevtoolsOptions(options: DevtoolsOptions = {}): ResolvedDevtoolsOptions {\n const path = (options.path ?? \"/__warlock\").replace(/\\/+$/, \"\");\n const maxRequests = options.maxRequests ?? 200;\n const nPlusOneThreshold = options.nPlusOneThreshold ?? 5;\n\n if (!path || !path.startsWith(\"/\")) {\n throw new Error('Devtools option \"path\" must be a non-root path starting with \"/\".');\n }\n\n if (maxRequests < 1) {\n throw new Error('Devtools option \"maxRequests\" must be at least 1.');\n }\n\n if (nPlusOneThreshold < 2) {\n throw new Error('Devtools option \"nPlusOneThreshold\" must be at least 2.');\n }\n\n return {\n path,\n maxRequests,\n nPlusOneThreshold,\n allowedHosts: options.allowedHosts ?? [],\n allowProxied: options.allowProxied ?? false,\n panels: options.panels ?? [],\n ...(options.production === undefined ? {} : { production: options.production }),\n };\n}\n"],"mappings":";;AAGA,SAAgB,uBAAuB,UAA2B,CAAC,GAA4B;CAC7F,MAAM,QAAQ,QAAQ,QAAQ,aAAY,CAAE,QAAQ,QAAQ,EAAE;CAC9D,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,oBAAoB,QAAQ,qBAAqB;CAEvD,IAAI,CAAC,QAAQ,CAAC,KAAK,WAAW,GAAG,GAC/B,MAAM,IAAI,MAAM,uEAAmE;CAGrF,IAAI,cAAc,GAChB,MAAM,IAAI,MAAM,qDAAmD;CAGrE,IAAI,oBAAoB,GACtB,MAAM,IAAI,MAAM,2DAAyD;CAG3E,OAAO;EACL;EACA;EACA;EACA,cAAc,QAAQ,gBAAgB,CAAC;EACvC,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ,UAAU,CAAC;EAC3B,GAAI,QAAQ,eAAe,SAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,WAAW;CAC/E;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region ../../packages/devtools/src/panel-tokens.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The CSS variables the dashboard defines for package panels, in both themes.
|
|
4
|
+
*
|
|
5
|
+
* A package panel's stylesheet may use only these variables, plus variables it
|
|
6
|
+
* defines itself (in the same file). Anything else is undefined in the
|
|
7
|
+
* dashboard and renders as the browser default, which is how a panel ends up
|
|
8
|
+
* with unreadable text. The dashboard's own colours are checked for contrast
|
|
9
|
+
* (4.5:1 for the text tokens on `--background` and `--card`) in both themes.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEVTOOLS_PANEL_TOKENS: readonly string[];
|
|
12
|
+
//#endregion
|
|
13
|
+
//# sourceMappingURL=panel-tokens.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-tokens.d.mts","names":[],"sources":["../../../../../../../packages/devtools/src/panel-tokens.ts"],"mappings":";;;;;;;;;;qBASa"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region ../../packages/devtools/src/panel-tokens.ts
|
|
2
|
+
/**
|
|
3
|
+
* The CSS variables the dashboard defines for package panels, in both themes.
|
|
4
|
+
*
|
|
5
|
+
* A package panel's stylesheet may use only these variables, plus variables it
|
|
6
|
+
* defines itself (in the same file). Anything else is undefined in the
|
|
7
|
+
* dashboard and renders as the browser default, which is how a panel ends up
|
|
8
|
+
* with unreadable text. The dashboard's own colours are checked for contrast
|
|
9
|
+
* (4.5:1 for the text tokens on `--background` and `--card`) in both themes.
|
|
10
|
+
*/
|
|
11
|
+
const DEVTOOLS_PANEL_TOKENS = [
|
|
12
|
+
"--background",
|
|
13
|
+
"--foreground",
|
|
14
|
+
"--card",
|
|
15
|
+
"--card-foreground",
|
|
16
|
+
"--popover",
|
|
17
|
+
"--popover-foreground",
|
|
18
|
+
"--primary",
|
|
19
|
+
"--primary-foreground",
|
|
20
|
+
"--secondary",
|
|
21
|
+
"--secondary-foreground",
|
|
22
|
+
"--muted",
|
|
23
|
+
"--muted-foreground",
|
|
24
|
+
"--accent",
|
|
25
|
+
"--accent-foreground",
|
|
26
|
+
"--destructive",
|
|
27
|
+
"--border",
|
|
28
|
+
"--input",
|
|
29
|
+
"--ring",
|
|
30
|
+
"--radius",
|
|
31
|
+
"--brand",
|
|
32
|
+
"--brand-foreground",
|
|
33
|
+
"--success",
|
|
34
|
+
"--warning",
|
|
35
|
+
"--info",
|
|
36
|
+
"--chart-1",
|
|
37
|
+
"--chart-2",
|
|
38
|
+
"--chart-3",
|
|
39
|
+
"--chart-4",
|
|
40
|
+
"--chart-5"
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { DEVTOOLS_PANEL_TOKENS };
|
|
45
|
+
//# sourceMappingURL=panel-tokens.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-tokens.mjs","names":[],"sources":["../../../../../../../packages/devtools/src/panel-tokens.ts"],"sourcesContent":["/**\n * The CSS variables the dashboard defines for package panels, in both themes.\n *\n * A package panel's stylesheet may use only these variables, plus variables it\n * defines itself (in the same file). Anything else is undefined in the\n * dashboard and renders as the browser default, which is how a panel ends up\n * with unreadable text. The dashboard's own colours are checked for contrast\n * (4.5:1 for the text tokens on `--background` and `--card`) in both themes.\n */\nexport const DEVTOOLS_PANEL_TOKENS: readonly string[] = [\n \"--background\",\n \"--foreground\",\n \"--card\",\n \"--card-foreground\",\n \"--popover\",\n \"--popover-foreground\",\n \"--primary\",\n \"--primary-foreground\",\n \"--secondary\",\n \"--secondary-foreground\",\n \"--muted\",\n \"--muted-foreground\",\n \"--accent\",\n \"--accent-foreground\",\n \"--destructive\",\n \"--border\",\n \"--input\",\n \"--ring\",\n \"--radius\",\n \"--brand\",\n \"--brand-foreground\",\n \"--success\",\n \"--warning\",\n \"--info\",\n \"--chart-1\",\n \"--chart-2\",\n \"--chart-3\",\n \"--chart-4\",\n \"--chart-5\",\n];\n"],"mappings":";;;;;;;;;;AASA,MAAa,wBAA2C;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|