@warlock.js/devtools 5.59.0 → 5.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/cjs/{app-versions-DfpPZOI2.cjs → app-versions-C_ZyzuvD.cjs} +1 -116
  3. package/cjs/app-versions-C_ZyzuvD.cjs.map +1 -0
  4. package/cjs/attach-D5aMqUnA.cjs +1342 -0
  5. package/cjs/attach-D5aMqUnA.cjs.map +1 -0
  6. package/cjs/{auth-B3wyjJnQ.cjs → auth-ChHh5E7j.cjs} +6 -6
  7. package/cjs/{auth-B3wyjJnQ.cjs.map → auth-ChHh5E7j.cjs.map} +1 -1
  8. package/cjs/{boot-nczSvJ_F.cjs → boot-Dg5YZGGR.cjs} +77 -14
  9. package/cjs/boot-Dg5YZGGR.cjs.map +1 -0
  10. package/cjs/{capture-CuyT8Vab.cjs → capture-CBgONYhk.cjs} +4 -4
  11. package/cjs/{capture-CuyT8Vab.cjs.map → capture-CBgONYhk.cjs.map} +1 -1
  12. package/cjs/{cascade-store-CuRRYzt_.cjs → cascade-store-DUT2Laha.cjs} +3 -3
  13. package/cjs/{cascade-store-CuRRYzt_.cjs.map → cascade-store-DUT2Laha.cjs.map} +1 -1
  14. package/cjs/{current-request-id-CeQhRz9Q.cjs → current-request-id-Badec-TH.cjs} +2 -2
  15. package/cjs/{current-request-id-CeQhRz9Q.cjs.map → current-request-id-Badec-TH.cjs.map} +1 -1
  16. package/cjs/{errors-BadbSDX8.cjs → errors-DNQ-g49I.cjs} +198 -1
  17. package/cjs/errors-DNQ-g49I.cjs.map +1 -0
  18. package/cjs/extract-8kaX_cUV.cjs +1103 -0
  19. package/cjs/extract-8kaX_cUV.cjs.map +1 -0
  20. package/cjs/{histogram-DTOGnNBW.cjs → histogram-CkoVizdf.cjs} +6 -6
  21. package/cjs/{histogram-DTOGnNBW.cjs.map → histogram-CkoVizdf.cjs.map} +1 -1
  22. package/cjs/{http-Biauhqi0.cjs → http-DCVCf44M.cjs} +25 -8
  23. package/cjs/http-DCVCf44M.cjs.map +1 -0
  24. package/cjs/index.cjs +1 -1
  25. package/cjs/{insights-BjJA6Ret.cjs → insights-CFof59kF.cjs} +3 -3
  26. package/cjs/{insights-BjJA6Ret.cjs.map → insights-CFof59kF.cjs.map} +1 -1
  27. package/cjs/migrations-BQdNOL5_.cjs +30 -0
  28. package/cjs/migrations-BQdNOL5_.cjs.map +1 -0
  29. package/cjs/{migrations-BP4cYTGo.cjs → models-DF1agAm4.cjs} +106 -24
  30. package/cjs/models-DF1agAm4.cjs.map +1 -0
  31. package/cjs/{process-panel-DskSA7Cm.cjs → process-panel-D3D9Y_dc.cjs} +4 -4
  32. package/cjs/{process-panel-DskSA7Cm.cjs.map → process-panel-D3D9Y_dc.cjs.map} +1 -1
  33. package/cjs/production/index.cjs +4 -4
  34. package/cjs/runs-DECWPGnq.cjs +390 -0
  35. package/cjs/runs-DECWPGnq.cjs.map +1 -0
  36. package/cjs/{server-D3XRbSSb.cjs → server-CC5DpObz.cjs} +8 -7
  37. package/cjs/{server-D3XRbSSb.cjs.map → server-CC5DpObz.cjs.map} +1 -1
  38. package/cjs/{src-QcNghoYN.cjs → src-VyOjEEAo.cjs} +178 -23
  39. package/cjs/src-VyOjEEAo.cjs.map +1 -0
  40. package/cjs/{store-CNFv3wVp.cjs → store-EFn4wp0T.cjs} +2 -2
  41. package/cjs/{stream-route-BqyAlfxQ.cjs → stream-route-DFHuIWgg.cjs} +107 -15
  42. package/cjs/stream-route-DFHuIWgg.cjs.map +1 -0
  43. package/esm/ai/attach.mjs +92 -0
  44. package/esm/ai/attach.mjs.map +1 -0
  45. package/esm/ai/options.mjs +31 -0
  46. package/esm/ai/options.mjs.map +1 -0
  47. package/esm/ai/reports/aggregate.mjs +330 -0
  48. package/esm/ai/reports/aggregate.mjs.map +1 -0
  49. package/esm/ai/reports/evaluate.mjs +108 -0
  50. package/esm/ai/reports/evaluate.mjs.map +1 -0
  51. package/esm/ai/reports/range.mjs +121 -0
  52. package/esm/ai/reports/range.mjs.map +1 -0
  53. package/esm/ai/reports/runs.d.mts +2 -0
  54. package/esm/ai/reports/runs.mjs +212 -0
  55. package/esm/ai/reports/runs.mjs.map +1 -0
  56. package/esm/ai/reports/service.mjs +132 -0
  57. package/esm/ai/reports/service.mjs.map +1 -0
  58. package/esm/ai/rollup/cascade-store.mjs +84 -0
  59. package/esm/ai/rollup/cascade-store.mjs.map +1 -0
  60. package/esm/ai/rollup/categories.mjs +67 -0
  61. package/esm/ai/rollup/categories.mjs.map +1 -0
  62. package/esm/ai/rollup/extract.mjs +225 -0
  63. package/esm/ai/rollup/extract.mjs.map +1 -0
  64. package/esm/ai/rollup/file-store.mjs +147 -0
  65. package/esm/ai/rollup/file-store.mjs.map +1 -0
  66. package/esm/ai/rollup/histogram.mjs +42 -0
  67. package/esm/ai/rollup/histogram.mjs.map +1 -0
  68. package/esm/ai/rollup/increment-error.mjs +19 -0
  69. package/esm/ai/rollup/increment-error.mjs.map +1 -0
  70. package/esm/ai/rollup/index.mjs +9 -0
  71. package/esm/ai/rollup/mapping.mjs +69 -0
  72. package/esm/ai/rollup/mapping.mjs.map +1 -0
  73. package/esm/ai/rollup/memory-store.mjs +26 -0
  74. package/esm/ai/rollup/memory-store.mjs.map +1 -0
  75. package/esm/ai/rollup/writer.mjs +113 -0
  76. package/esm/ai/rollup/writer.mjs.map +1 -0
  77. package/esm/ai/types.d.mts +29 -0
  78. package/esm/ai/types.d.mts.map +1 -0
  79. package/esm/devtools-connector.d.mts.map +1 -1
  80. package/esm/devtools-connector.mjs +54 -2
  81. package/esm/devtools-connector.mjs.map +1 -1
  82. package/esm/index.d.mts +3 -2
  83. package/esm/options.mjs +4 -0
  84. package/esm/options.mjs.map +1 -1
  85. package/esm/production/boot.mjs +69 -3
  86. package/esm/production/boot.mjs.map +1 -1
  87. package/esm/production/contracts.d.mts +371 -2
  88. package/esm/production/contracts.d.mts.map +1 -1
  89. package/esm/production/contracts.mjs +64 -2
  90. package/esm/production/contracts.mjs.map +1 -1
  91. package/esm/production/errors.mjs +8 -0
  92. package/esm/production/errors.mjs.map +1 -1
  93. package/esm/production/http/access.mjs +6 -0
  94. package/esm/production/http/access.mjs.map +1 -1
  95. package/esm/production/http/mount.mjs +13 -0
  96. package/esm/production/http/mount.mjs.map +1 -1
  97. package/esm/production/index.d.mts +2 -2
  98. package/esm/production/store/migrations.d.mts +1 -1
  99. package/esm/production/store/migrations.d.mts.map +1 -1
  100. package/esm/production/store/migrations.mjs +4 -2
  101. package/esm/production/store/migrations.mjs.map +1 -1
  102. package/esm/production/store/models/ai-rollup.migration.mjs +48 -0
  103. package/esm/production/store/models/ai-rollup.migration.mjs.map +1 -0
  104. package/esm/production/store/models/ai-rollup.model.mjs +13 -0
  105. package/esm/production/store/models/ai-rollup.model.mjs.map +1 -0
  106. package/esm/production/store/models/index.mjs +3 -1
  107. package/esm/server/ai-report-routes.mjs +72 -0
  108. package/esm/server/ai-report-routes.mjs.map +1 -0
  109. package/esm/server/ai-routes.mjs +22 -1
  110. package/esm/server/ai-routes.mjs.map +1 -1
  111. package/esm/server/index.mjs +2 -0
  112. package/esm/server/index.mjs.map +1 -1
  113. package/esm/sources/agent-trace-source.d.mts.map +1 -1
  114. package/esm/sources/agent-trace-source.mjs.map +1 -1
  115. package/esm/sources/ai-source.d.mts +2 -0
  116. package/esm/sources/ai-source.d.mts.map +1 -1
  117. package/esm/sources/ai-source.mjs +58 -17
  118. package/esm/sources/ai-source.mjs.map +1 -1
  119. package/esm/types.d.mts +13 -3
  120. package/esm/types.d.mts.map +1 -1
  121. package/llms-full.txt +56 -17
  122. package/package.json +8 -8
  123. package/skills/SKILL.md +56 -17
  124. package/ui/dashboard/assets/app.css +1 -1
  125. package/ui/dashboard/assets/app.js +12 -5
  126. package/ui/dashboard/build-info.json +7 -7
  127. package/cjs/ai-source-BdvMfyKw.cjs +0 -448
  128. package/cjs/ai-source-BdvMfyKw.cjs.map +0 -1
  129. package/cjs/app-versions-DfpPZOI2.cjs.map +0 -1
  130. package/cjs/boot-nczSvJ_F.cjs.map +0 -1
  131. package/cjs/errors-BadbSDX8.cjs.map +0 -1
  132. package/cjs/http-Biauhqi0.cjs.map +0 -1
  133. package/cjs/migrations-BP4cYTGo.cjs.map +0 -1
  134. package/cjs/options-B9FHbRAJ.cjs +0 -205
  135. package/cjs/options-B9FHbRAJ.cjs.map +0 -1
  136. package/cjs/panels-D1ITm-jc.cjs +0 -384
  137. package/cjs/panels-D1ITm-jc.cjs.map +0 -1
  138. package/cjs/src-QcNghoYN.cjs.map +0 -1
  139. package/cjs/stream-route-BqyAlfxQ.cjs.map +0 -1
@@ -24,6 +24,12 @@ const DEVTOOLS_LATENCY_BUCKETS_MS = [
24
24
  /**
25
25
  * The built-in tabs, in display order, with whether production shows them
26
26
  * when the project says nothing (`production.panels` overrides per id).
27
+ *
28
+ * The AI section (`ai-reports`, `ai`, `agents`, `ai-models`, `ai-errors`,
29
+ * `ai-evaluate`) sits under "AI" in the sidebar. `ai` keeps its id (it is the
30
+ * Runs page) so existing links and `production.panels.ai` keep working. In
31
+ * production the three report tabs show only when the AI feed is available
32
+ * (Panoptic loads), unless `production.panels` turns one on explicitly.
27
33
  */
28
34
  const DEVTOOLS_BUILT_IN_PANELS = [
29
35
  {
@@ -71,9 +77,14 @@ const DEVTOOLS_BUILT_IN_PANELS = [
71
77
  title: "Mail",
72
78
  production: false
73
79
  },
80
+ {
81
+ id: "ai-reports",
82
+ title: "Reports",
83
+ production: true
84
+ },
74
85
  {
75
86
  id: "ai",
76
- title: "AI",
87
+ title: "Runs",
77
88
  production: false
78
89
  },
79
90
  {
@@ -81,6 +92,21 @@ const DEVTOOLS_BUILT_IN_PANELS = [
81
92
  title: "Agents",
82
93
  production: false
83
94
  },
95
+ {
96
+ id: "ai-models",
97
+ title: "Models",
98
+ production: true
99
+ },
100
+ {
101
+ id: "ai-errors",
102
+ title: "Errors",
103
+ production: true
104
+ },
105
+ {
106
+ id: "ai-evaluate",
107
+ title: "Evaluate",
108
+ production: false
109
+ },
84
110
  {
85
111
  id: "api",
86
112
  title: "API",
@@ -93,7 +119,43 @@ const DEVTOOLS_FAILURE_AUDIT_TYPES = [
93
119
  "mfa.failed",
94
120
  "share.failed"
95
121
  ];
122
+ /**
123
+ * Upper bounds (inclusive, ms) of the latency buckets of the AI rollups.
124
+ * Model calls take seconds, so these differ from `DEVTOOLS_LATENCY_BUCKETS_MS`.
125
+ * A histogram has one more count than this list: the last counts everything
126
+ * above five minutes. Fixed bounds make rollups from several processes add up
127
+ * exactly. Changing them is a breaking change of the stored rollups.
128
+ */
129
+ const DEVTOOLS_AI_LATENCY_BUCKETS_MS = [
130
+ 250,
131
+ 500,
132
+ 1e3,
133
+ 2e3,
134
+ 3e3,
135
+ 5e3,
136
+ 7500,
137
+ 1e4,
138
+ 15e3,
139
+ 2e4,
140
+ 3e4,
141
+ 45e3,
142
+ 6e4,
143
+ 12e4,
144
+ 3e5
145
+ ];
146
+ /** Every category, in the order the Errors page lists them. */
147
+ const DEVTOOLS_AI_ERROR_CATEGORIES = [
148
+ "rate-limit",
149
+ "timeout",
150
+ "refusal",
151
+ "provider",
152
+ "budget",
153
+ "tool",
154
+ "schema",
155
+ "incomplete",
156
+ "other"
157
+ ];
96
158
 
97
159
  //#endregion
98
- export { DEVTOOLS_BUILT_IN_PANELS, DEVTOOLS_FAILURE_AUDIT_TYPES, DEVTOOLS_LATENCY_BUCKETS_MS };
160
+ export { DEVTOOLS_AI_ERROR_CATEGORIES, DEVTOOLS_AI_LATENCY_BUCKETS_MS, DEVTOOLS_BUILT_IN_PANELS, DEVTOOLS_FAILURE_AUDIT_TYPES, DEVTOOLS_LATENCY_BUCKETS_MS };
99
161
  //# sourceMappingURL=contracts.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/contracts.ts"],"sourcesContent":["/**\n * The contracts of the devtools production monitor: the shapes the server\n * stores, the JSON its API returns, and the few constants both sides share.\n *\n * This file has NO imports, so the dashboard (`ui-src/`) can import its types\n * too. Every timestamp is epoch milliseconds, every duration milliseconds,\n * every size bytes. Absent values are `null`, never missing.\n */\n\n// ---------------------------------------------------------------------------\n// Modes, roles and stages\n// ---------------------------------------------------------------------------\n\n/** Where the dashboard runs: the loopback development dashboard or the signed-in production monitor. */\nexport type DevtoolsMode = \"development\" | \"production\";\n\n/** What an account may do: `admin` manages users and the dashboard, `viewer` reads. */\nexport type DevtoolsRole = \"admin\" | \"viewer\";\n\n/**\n * Where a browser session stands. Only `active` reaches the data routes;\n * every other stage reaches only the sign-in steps it needs next.\n */\nexport type DevtoolsSessionStage =\n | \"signed-out\"\n | \"password-change\"\n | \"mfa-enrol\"\n | \"mfa-verify\"\n | \"active\";\n\n/** How an account's current password was set. `env` and `reset` passwords must be changed at the next sign-in. */\nexport type DevtoolsPasswordSource = \"env\" | \"setup\" | \"invite\" | \"user\" | \"reset\";\n\n// ---------------------------------------------------------------------------\n// Instances\n// ---------------------------------------------------------------------------\n\n/** One process that runs the monitor (a pm2 or cluster worker, a container). */\nexport type DevtoolsInstanceInfo = {\n /** Stable for the life of the process: `<host>:<pid>:<start time base36>`. */\n id: string;\n /** What the dashboard shows: `<host> #<worker>` or `<host> pid <pid>`. */\n label: string;\n host: string;\n pid: number;\n /** pm2's `NODE_APP_INSTANCE` / `pm_id`, or the cluster worker id; `null` when neither is set. */\n worker: string | null;\n startedAt: number;\n /** When the instance last wrote its report (the current time for the instance answering). */\n seenAt: number;\n nodeVersion: string;\n};\n\n// ---------------------------------------------------------------------------\n// Histograms (mergeable across instances)\n// ---------------------------------------------------------------------------\n\n/**\n * Upper bounds (inclusive, ms) of the latency buckets every histogram uses.\n * A histogram's `counts` has one more entry than this list: the last entry\n * counts everything above the highest bound. Fixed bounds make histograms\n * from several instances merge exactly.\n */\nexport const DEVTOOLS_LATENCY_BUCKETS_MS = [\n 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 30000,\n] as const;\n\n/** A latency histogram over `DEVTOOLS_LATENCY_BUCKETS_MS`. */\nexport type DevtoolsHistogram = {\n /** `DEVTOOLS_LATENCY_BUCKETS_MS.length + 1` entries. */\n counts: number[];\n count: number;\n sumMs: number;\n maxMs: number;\n};\n\n// ---------------------------------------------------------------------------\n// Query, route and error statistics\n// ---------------------------------------------------------------------------\n\n/** Statistics for one normalized query shape (literals and bindings replaced by `?`). */\nexport type DevtoolsQueryShapeStats = {\n /** First 16 hex characters of the SHA-256 of `shape`; the id the API and EXPLAIN use. */\n id: string;\n /** The normalized query, at most 2000 characters. Never holds a value. */\n shape: string;\n driver: \"postgres\" | \"mongodb\";\n connection: string;\n count: number;\n errors: number;\n histogram: DevtoolsHistogram;\n /** Sampled requests in which this shape reached the N+1 threshold, and the highest count in one request. */\n nPlusOne: { requests: number; maxPerRequest: number };\n /** The slowest run seen; its values stay in the process that ran it (see EXPLAIN). */\n slowest: {\n durationMs: number;\n at: number;\n route: string | null;\n requestId: string | null;\n instance: string;\n } | null;\n firstSeen: number;\n lastSeen: number;\n /** Whether EXPLAIN can run for this shape (a Postgres `SELECT`/`WITH`, or a MongoDB `find`/`aggregate`/`count`). */\n explainable: boolean;\n};\n\n/** Time spent in one named request phase (middleware, validation, handler, …) on one route. */\nexport type DevtoolsRoutePhaseStats = {\n name: string;\n count: number;\n sumMs: number;\n maxMs: number;\n};\n\n/** Statistics for one route pattern and method. */\nexport type DevtoolsRouteStats = {\n /** `\"<METHOD> <route pattern>\"`, e.g. `\"GET /posts/:slug\"`. */\n key: string;\n method: string;\n route: string;\n count: number;\n /** Responses with a 5xx status or a thrown error. */\n errors: number;\n histogram: DevtoolsHistogram;\n /** At most 30 phases, slowest total first. */\n phases: DevtoolsRoutePhaseStats[];\n slowest: { durationMs: number; at: number; requestId: string | null; instance: string } | null;\n};\n\n/** Errors grouped by fingerprint (normalized message + route + source). */\nexport type DevtoolsErrorGroup = {\n /** First 16 hex characters of the SHA-256 of the fingerprint. */\n id: string;\n /** The latest message as raised, at most 500 characters. */\n message: string;\n /** The error class name when known (`TypeError`). */\n name: string | null;\n source: \"request\" | \"log\";\n route: string | null;\n status: number | null;\n count: number;\n firstSeen: number;\n lastSeen: number;\n lastRequestId: string | null;\n /** The latest stack, at most 4000 characters; `null` when none was available. */\n stack: string | null;\n};\n\n/** A warn/error log entry kept for the Logs panel in production (no context: it may hold values). */\nexport type DevtoolsReportLogEntry = {\n level: \"debug\" | \"info\" | \"warn\" | \"error\" | \"success\";\n module: string;\n action: string;\n /** At most 1000 characters. */\n message: string;\n at: number;\n requestId: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Resources, health, jobs\n// ---------------------------------------------------------------------------\n\n/** One resource reading of a process. */\nexport type DevtoolsResourcePoint = {\n at: number;\n rssBytes: number;\n heapUsedBytes: number;\n heapTotalBytes: number;\n externalBytes: number;\n /** Process CPU time over wall time since the previous point, 0–100 per core (can exceed 100). */\n cpuPercent: number;\n eventLoopDelayP50Ms: number;\n eventLoopDelayP99Ms: number;\n eventLoopDelayMaxMs: number;\n /** `performance.eventLoopUtilization()` since the previous point, 0–1. */\n eventLoopUtilization: number;\n /** Garbage collections since the previous point. */\n gcCount: number;\n /** Total GC pause since the previous point. */\n gcPauseMs: number;\n};\n\n/** The latest resource reading plus values that change rarely. */\nexport type DevtoolsResourceSnapshot = DevtoolsResourcePoint & {\n heapLimitBytes: number;\n uptimeSeconds: number;\n /** Totals since the monitor started, by GC kind. */\n gcByKind: Record<\n \"minor\" | \"major\" | \"incremental\" | \"weakcb\",\n { count: number; pauseMs: number }\n >;\n};\n\n/** Readiness checks (core's `health` registry) of one process, with a short history. */\nexport type DevtoolsHealthReport = {\n status: \"ok\" | \"error\" | \"unknown\";\n checkedAt: number | null;\n checks: Record<string, boolean>;\n /** Newest last, at most 60 entries. */\n history: { at: number; status: \"ok\" | \"error\"; failed: string[] }[];\n};\n\n/** One scheduled job (`@warlock.js/scheduler`). */\nexport type DevtoolsScheduleInfo = {\n name: string;\n /** The cron expression, or `null` for an interval schedule. */\n cron: string | null;\n /** A readable interval such as `\"every 5 minutes\"`, or `null`. */\n interval: string | null;\n isRunning: boolean;\n lastRunAt: number | null;\n nextRunAt: number | null;\n lastDurationMs: number | null;\n lastError: string | null;\n runs: number;\n failures: number;\n};\n\n/** Background work of one process: schedules and queue counts, each `available: false` when its package is not installed. */\nexport type DevtoolsJobsReport = {\n available: { scheduler: boolean; queue: boolean };\n schedules: DevtoolsScheduleInfo[];\n /** Job counts per queue and state (`waiting`, `active`, `delayed`, `failed`, `completed`). */\n queues: { name: string; counts: Record<string, number> }[];\n};\n\n/** What the capture did since the process started. */\nexport type DevtoolsCaptureCounters = {\n sampleRate: number;\n requests: number;\n sampled: number;\n /** Unsampled requests kept as a summary because they were slow or failed. */\n keptUnsampled: number;\n /** Samples written to the database. */\n stored: number;\n /** Samples not written because the per-minute budget was spent. */\n droppedStored: number;\n /** Query shapes, routes and error groups evicted to keep memory bounded. */\n evictedShapes: number;\n evictedRoutes: number;\n evictedErrors: number;\n /** Queries not kept inside a sampled request because it reached its per-request limit. */\n droppedQueries: number;\n};\n\n/**\n * Everything one process reports, written to the database every\n * `reportIntervalMs` (one row per instance) and merged by the dashboard.\n * Serialized it stays under 256 KB: lists are trimmed from the end.\n */\nexport type DevtoolsInstanceReport = {\n instance: DevtoolsInstanceInfo;\n at: number;\n resources: { snapshot: DevtoolsResourceSnapshot; history: DevtoolsResourcePoint[] };\n /** At most 200, highest total time first. */\n queries: DevtoolsQueryShapeStats[];\n /** At most 200, highest total time first. */\n routes: DevtoolsRouteStats[];\n /** At most 50, newest first. */\n errors: DevtoolsErrorGroup[];\n /** At most 50, newest first. */\n logs: DevtoolsReportLogEntry[];\n health: DevtoolsHealthReport;\n jobs: DevtoolsJobsReport;\n capture: DevtoolsCaptureCounters;\n};\n\n// ---------------------------------------------------------------------------\n// Requests (stored samples)\n// ---------------------------------------------------------------------------\n\n/**\n * A request row. Matches the development `DevtoolsRequestSummary` field for\n * field, plus where it was captured.\n */\nexport type DevtoolsSampleSummary = {\n id: string;\n method: string;\n path: string;\n route?: string;\n status?: number;\n startedAt: number;\n durationMs?: number;\n queryCount: number;\n warningCount: number;\n /** Read from the persisted request log only. */\n persisted?: true;\n /** The instance that served the request. */\n instance?: string;\n /** Kept because it was slow or failed, without a timeline (the request was not sampled). */\n partial?: true;\n};\n\n/** A query inside a stored sample: the shape only, never the SQL text with values or the bindings. */\nexport type DevtoolsSampleQuery = {\n id: string;\n connection: string;\n driver: \"postgres\" | \"mongodb\";\n /** Same as `shape`: kept under this name so the request view renders it like a development query. */\n sql?: string;\n collection?: string;\n command?: string;\n shape: string;\n shapeId: string;\n startedAt: number;\n durationMs: number;\n rowCount?: number;\n error?: string;\n};\n\n/** The timeline of a sampled request, with every value removed (see the redaction rules). */\nexport type DevtoolsSampleDetail = DevtoolsSampleSummary & {\n error?: string;\n phases: { name: string; startedAt: number; durationMs: number }[];\n queries: DevtoolsSampleQuery[];\n /** Cache operation counts only; keys are not kept. */\n cache: { hits: number; misses: number; writes: number };\n /** Log entries without context. */\n logs: { level: string; module: string; action: string; message: string; at: number }[];\n warnings: { type: \"n+1\"; message: string; shape: string; count: number }[];\n /** Queries left out because the request reached `maxQueriesPerRequest`. */\n droppedQueries: number;\n};\n\n// ---------------------------------------------------------------------------\n// API views (what the dashboard reads)\n// ---------------------------------------------------------------------------\n\n/** `GET api/instances`. */\nexport type DevtoolsInstancesView = {\n /** The instance that answered this request. */\n current: string;\n /** Instances seen in the last 5 minutes (the answering one included), newest first. */\n instances: DevtoolsInstanceInfo[];\n};\n\n/** `GET api/resources?instance=<id|all>`. */\nexport type DevtoolsResourcesView = {\n instances: {\n instance: DevtoolsInstanceInfo;\n snapshot: DevtoolsResourceSnapshot;\n history: DevtoolsResourcePoint[];\n }[];\n};\n\n/** A shape row with figures computed from its histogram. */\nexport type DevtoolsQueryShapeRow = DevtoolsQueryShapeStats & {\n p50Ms: number;\n p95Ms: number;\n meanMs: number;\n /** Ids of the instances that reported this shape. */\n instances: string[];\n};\n\n/** `GET api/queries/stats?instance=&sort=total|p95|count|n+1&limit=`. */\nexport type DevtoolsQueryStatsView = {\n shapes: DevtoolsQueryShapeRow[];\n /** The sample rate the counts come from; counts are of sampled requests only. */\n sampleRate: number;\n instanceCount: number;\n evicted: number;\n};\n\n/** A route row with figures computed from its histogram. */\nexport type DevtoolsRouteStatsRow = DevtoolsRouteStats & {\n p50Ms: number;\n p95Ms: number;\n meanMs: number;\n instances: string[];\n};\n\n/** `GET api/routes/stats?instance=&sort=total|p95|count|errors&limit=`. */\nexport type DevtoolsRouteStatsView = {\n routes: DevtoolsRouteStatsRow[];\n sampleRate: number;\n instanceCount: number;\n};\n\n/** `GET api/health?instance=`. */\nexport type DevtoolsHealthView = {\n instances: { instance: DevtoolsInstanceInfo; report: DevtoolsHealthReport }[];\n};\n\n/** `GET api/errors?instance=&limit=`. */\nexport type DevtoolsErrorsView = {\n groups: (DevtoolsErrorGroup & { instances: string[] })[];\n};\n\n/**\n * One row of `GET api/logs?level=&module=&instance=` (newest first), in both\n * modes. Development rows carry `context` and no `instance`; production rows\n * carry `instance` and never `context`.\n */\nexport type DevtoolsLogRow = DevtoolsReportLogEntry & {\n instance: string | null;\n context?: unknown;\n};\n\n/** `GET api/logs`: the rows, newest first (a plain array, as in 5.55). */\nexport type DevtoolsLogsView = DevtoolsLogRow[];\n\n/** `GET api/jobs?instance=`. */\nexport type DevtoolsJobsView = {\n instances: { instance: DevtoolsInstanceInfo; report: DevtoolsJobsReport }[];\n};\n\n/** `POST api/queries/:shapeId/explain`. */\nexport type DevtoolsExplainResult = {\n shapeId: string;\n driver: \"postgres\" | \"mongodb\";\n /** `true` only when the project allows executing plans (`explain.executing`). */\n executing: boolean;\n plan: unknown;\n /** The instance whose example ran the EXPLAIN. */\n instance: string;\n};\n\n/** One dashboard tab, as `GET api/panels` lists it (enabled tabs only, in display order). */\nexport type DevtoolsPanelInfo = {\n id: string;\n title: string;\n /** `built-in` tabs are React views in the bundle; `package` tabs load `panels/<id>/view.js`. */\n type: \"built-in\" | \"package\";\n /** Whether the panel declares a shared view (`DevtoolsPanel.share`); always `false` for built-in tabs. */\n shareable: boolean;\n};\n\n/**\n * The built-in tabs, in display order, with whether production shows them\n * when the project says nothing (`production.panels` overrides per id).\n */\nexport const DEVTOOLS_BUILT_IN_PANELS = [\n { id: \"requests\", title: \"Requests\", production: true },\n { id: \"queries\", title: \"Queries\", production: true },\n { id: \"routes\", title: \"Routes\", production: true },\n { id: \"resources\", title: \"Resources\", production: true },\n { id: \"health\", title: \"Health\", production: true },\n { id: \"errors\", title: \"Errors\", production: true },\n { id: \"logs\", title: \"Logs\", production: true },\n { id: \"jobs\", title: \"Jobs\", production: true },\n { id: \"mail\", title: \"Mail\", production: false },\n { id: \"ai\", title: \"AI\", production: false },\n { id: \"agents\", title: \"Agents\", production: false },\n { id: \"api\", title: \"API\", production: false },\n] as const;\n\n/** The id of a built-in tab. */\nexport type DevtoolsBuiltInPanelId = (typeof DEVTOOLS_BUILT_IN_PANELS)[number][\"id\"];\n\n// ---------------------------------------------------------------------------\n// Accounts, sessions, invites\n// ---------------------------------------------------------------------------\n\n/** An account as the API shows it (never a hash or a secret). */\nexport type DevtoolsAccountView = {\n id: string;\n email: string;\n role: DevtoolsRole;\n twoFactor: {\n totp: boolean;\n passkeys: { id: string; name: string; createdAt: number; lastUsedAt: number | null }[];\n recoveryCodesLeft: number;\n };\n mustChangePassword: boolean;\n createdAt: number;\n lastLoginAt: number | null;\n};\n\n/** `GET api/auth/session`: who is signed in and what comes next. */\nexport type DevtoolsSessionView = {\n mode: DevtoolsMode;\n stage: DevtoolsSessionStage;\n /** `null` when signed out, and in development (no accounts there). */\n account: DevtoolsAccountView | null;\n /** `admin` in development; `null` when signed out. */\n role: DevtoolsRole | null;\n /** The token to send as `X-Devtools-Csrf` on every POST/PUT/PATCH/DELETE; `null` when signed out and in development. */\n csrf: string | null;\n /** When the session ends at the latest; `null` when signed out and in development. */\n expiresAt: number | null;\n /** The instance that answered; `null` when signed out. */\n instance: DevtoolsInstanceInfo | null;\n /** Sign-in methods the server offers; `null` when signed out. */\n methods: { totp: true; passkeys: boolean } | null;\n /** Read-only share links: `enabled` mirrors `production.share.enabled`; `null` when signed out and in development. */\n share: { enabled: boolean } | null;\n /** The installed `@warlock.js/core` version; `null` when signed out or not found. */\n warlockVersion: string | null;\n /** The app's own `package.json` name and version (nothing else is read); `null` when signed out or not found. */\n app: { name: string; version: string } | null;\n};\n\n/** `POST api/auth/login` body. */\nexport type DevtoolsLoginInput = { email: string; password: string };\n\n/** Answer of every sign-in step: the next stage, and the new CSRF token when the session changed. */\nexport type DevtoolsAuthStepResult = { stage: DevtoolsSessionStage; csrf: string | null };\n\n/** `POST api/auth/totp/start` (and `api/account/totp/start`). */\nexport type DevtoolsTotpEnrolment = {\n /** Base32, for manual entry. */\n secret: string;\n /** `otpauth://totp/...`, rendered as a QR code by the dashboard. */\n uri: string;\n issuer: string;\n account: string;\n};\n\n/** Recovery codes, shown once. */\nexport type DevtoolsRecoveryCodes = { codes: string[] };\n\n/** A pending or used invite. */\nexport type DevtoolsInviteView = {\n id: string;\n email: string;\n role: DevtoolsRole;\n createdAt: number;\n expiresAt: number;\n createdBy: string | null;\n usedAt: number | null;\n};\n\n/** `POST api/admin/invites`: the token appears only in this answer. */\nexport type DevtoolsCreatedInvite = { invite: DevtoolsInviteView; token: string };\n\n/** `GET api/admin/users`. */\nexport type DevtoolsUserListView = {\n accounts: DevtoolsAccountView[];\n invites: DevtoolsInviteView[];\n};\n\n/** A session as its owner sees it (`GET api/account/sessions`). */\nexport type DevtoolsSessionInfo = {\n id: string;\n current: boolean;\n createdAt: number;\n lastSeenAt: number;\n expiresAt: number;\n ip: string | null;\n userAgent: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Share links\n// ---------------------------------------------------------------------------\n\n/** Where a share link stands. `revoked` wins over `expired`. */\nexport type DevtoolsShareStatus = \"active\" | \"expired\" | \"revoked\";\n\n/** A share link as the admin screen shows it (never the token or its hash). */\nexport type DevtoolsShareView = {\n id: string;\n /** The id of the panel the link opens. */\n panel: string;\n /** What the admin called it, 1-80 characters. */\n label: string;\n /** The email of the admin who made it; `null` when that account is gone. */\n createdBy: string | null;\n createdAt: number;\n expiresAt: number;\n revokedAt: number | null;\n lastUsedAt: number | null;\n /** How many times the link was used, counted at most once a minute. */\n uses: number;\n status: DevtoolsShareStatus;\n};\n\n/** `GET api/admin/shares`. */\nexport type DevtoolsShareList = {\n enabled: boolean;\n /** The longest life a link may have, in days. */\n maxDays: number;\n /** The panels that declare a shared view. */\n panels: { id: string; title: string }[];\n /** Newest first. */\n shares: DevtoolsShareView[];\n};\n\n/** `POST api/admin/shares` body. `label` is 1-80 characters, `days` a whole number from 1 to `maxDays`. */\nexport type DevtoolsShareCreateInput = { panel: string; label: string; days: number };\n\n/** `POST api/admin/shares`: the URL (with the token in its fragment) appears only in this answer. */\nexport type DevtoolsCreatedShare = { share: DevtoolsShareView; url: string };\n\n/**\n * What a share link opens, answered by `POST api/share/open` and\n * `GET api/share/info`: the panel and the names the shared view may load.\n */\nexport type DevtoolsShareOpenAnswer = {\n panel: string;\n /** The panel's title. */\n title: string;\n label: string;\n expiresAt: number;\n /** Served names from the panel's `assets` the shared page may load. */\n assets: string[];\n /** Whether the shared page may load images from the panel's `files`. */\n files: boolean;\n};\n\n/** The longest label of a share link. */\nexport const DEVTOOLS_SHARE_LABEL_MAX = 80;\n\n// ---------------------------------------------------------------------------\n// Audit log\n// ---------------------------------------------------------------------------\n\n/** Every audited event. `login.failed` and `mfa.failed` are the ones rate limits count. */\nexport type DevtoolsAuditType =\n | \"admin.seeded\"\n | \"admin.reset\"\n | \"setup.completed\"\n | \"login.succeeded\"\n | \"login.failed\"\n | \"login.blocked\"\n | \"mfa.succeeded\"\n | \"mfa.failed\"\n | \"mfa.enrolled\"\n | \"mfa.removed\"\n | \"recovery-code.used\"\n | \"recovery-codes.regenerated\"\n | \"passkey.added\"\n | \"passkey.removed\"\n | \"password.changed\"\n | \"logout\"\n | \"session.revoked\"\n | \"invite.created\"\n | \"invite.revoked\"\n | \"invite.accepted\"\n | \"account.role-changed\"\n | \"account.removed\"\n | \"account.mfa-reset\"\n | \"account.signed-out\"\n | \"dashboard.disabled\"\n | \"dashboard.enabled\"\n | \"dashboard.locked\"\n | \"explain.run\"\n | \"requests.cleared\"\n | \"panel.action\"\n | \"share.created\"\n | \"share.revoked\"\n | \"share.failed\";\n\n/** The audit types that count toward the account, IP and global failure limits. */\nexport const DEVTOOLS_FAILURE_AUDIT_TYPES: readonly DevtoolsAuditType[] = [\n \"login.failed\",\n \"mfa.failed\",\n \"share.failed\",\n];\n\n/** One audit log entry. */\nexport type DevtoolsAuditEntry = {\n id: string;\n at: number;\n type: DevtoolsAuditType;\n /** The account acting or targeted; `null` for an unknown email or the CLI. */\n accountId: string | null;\n /** The email as typed or as stored, lower-cased; `null` when there was none. */\n email: string | null;\n /** `\"cli\"` for a command, else the client IP after trusted-proxy resolution. */\n ip: string | null;\n /** At most 200 characters. */\n userAgent: string | null;\n /** Small flat facts: target account, role, shape id, panel route. Never a secret. */\n detail: Record<string, string | number | boolean | null>;\n /** Short reference shown to users in error messages (8 characters). */\n ref: string;\n};\n\n// ---------------------------------------------------------------------------\n// Errors the API returns\n// ---------------------------------------------------------------------------\n\n/**\n * Error codes in API answers. Each has a fixed message (see\n * `DEVTOOLS_ERROR_MESSAGES` in `errors.ts`) that says what failed and what to\n * do next.\n */\nexport type DevtoolsErrorCode =\n | \"auth.invalid-credentials\"\n | \"auth.invalid-code\"\n | \"auth.invalid-setup-token\"\n | \"auth.password-too-short\"\n | \"auth.password-too-long\"\n | \"auth.password-common\"\n | \"auth.password-same-as-email\"\n | \"auth.password-unchanged\"\n | \"auth.wrong-current-password\"\n | \"auth.busy\"\n | \"invite.invalid\"\n | \"invite.email-taken\"\n | \"account.not-found\"\n | \"account.last-admin\"\n | \"account.self\"\n | \"account.last-factor\"\n | \"role.forbidden\"\n | \"csrf.invalid\"\n | \"passkey.unavailable\"\n | \"passkey.failed\"\n | \"explain.not-allowed\"\n | \"explain.unsupported\"\n | \"explain.elsewhere\"\n | \"explain.failed\"\n | \"request.not-found\"\n | \"request.invalid-filter\"\n | \"share.not-found\"\n | \"stream.too-many\"\n | \"input.invalid\"\n | \"server.error\";\n\n/** The JSON body of every failed API call. */\nexport type DevtoolsApiErrorBody = {\n /** What failed and what to do next. */\n error: string;\n code: DevtoolsErrorCode;\n /** Short reference to quote to an admin; also written to the audit log or server log. */\n ref?: string;\n /** The instance that answered, when it matters (`explain.elsewhere`). */\n instance?: string;\n};\n"],"mappings":";;;;;;;AA+DA,MAAa,8BAA8B;CACzC;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAK;CAAK;CAAK;CAAM;CAAM;CAAM;CAAO;AAC/D;;;;;AAgXA,MAAa,2BAA2B;CACtC;EAAE,IAAI;EAAY,OAAO;EAAY,YAAY;CAAK;CACtD;EAAE,IAAI;EAAW,OAAO;EAAW,YAAY;CAAK;CACpD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAa,OAAO;EAAa,YAAY;CAAK;CACxD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAK;CAC9C;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAK;CAC9C;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAM;CAC/C;EAAE,IAAI;EAAM,OAAO;EAAM,YAAY;CAAM;CAC3C;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAM;CACnD;EAAE,IAAI;EAAO,OAAO;EAAO,YAAY;CAAM;AAC/C;;AAwMA,MAAa,+BAA6D;CACxE;CACA;CACA;AACF"}
1
+ {"version":3,"file":"contracts.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/contracts.ts"],"sourcesContent":["/**\n * The contracts of the devtools production monitor: the shapes the server\n * stores, the JSON its API returns, and the few constants both sides share.\n *\n * This file has NO imports, so the dashboard (`ui-src/`) can import its types\n * too. Every timestamp is epoch milliseconds, every duration milliseconds,\n * every size bytes. Absent values are `null`, never missing.\n */\n\n// ---------------------------------------------------------------------------\n// Modes, roles and stages\n// ---------------------------------------------------------------------------\n\n/** Where the dashboard runs: the loopback development dashboard or the signed-in production monitor. */\nexport type DevtoolsMode = \"development\" | \"production\";\n\n/** What an account may do: `admin` manages users and the dashboard, `viewer` reads. */\nexport type DevtoolsRole = \"admin\" | \"viewer\";\n\n/**\n * Where a browser session stands. Only `active` reaches the data routes;\n * every other stage reaches only the sign-in steps it needs next.\n */\nexport type DevtoolsSessionStage =\n | \"signed-out\"\n | \"password-change\"\n | \"mfa-enrol\"\n | \"mfa-verify\"\n | \"active\";\n\n/** How an account's current password was set. `env` and `reset` passwords must be changed at the next sign-in. */\nexport type DevtoolsPasswordSource = \"env\" | \"setup\" | \"invite\" | \"user\" | \"reset\";\n\n// ---------------------------------------------------------------------------\n// Instances\n// ---------------------------------------------------------------------------\n\n/** One process that runs the monitor (a pm2 or cluster worker, a container). */\nexport type DevtoolsInstanceInfo = {\n /** Stable for the life of the process: `<host>:<pid>:<start time base36>`. */\n id: string;\n /** What the dashboard shows: `<host> #<worker>` or `<host> pid <pid>`. */\n label: string;\n host: string;\n pid: number;\n /** pm2's `NODE_APP_INSTANCE` / `pm_id`, or the cluster worker id; `null` when neither is set. */\n worker: string | null;\n startedAt: number;\n /** When the instance last wrote its report (the current time for the instance answering). */\n seenAt: number;\n nodeVersion: string;\n};\n\n// ---------------------------------------------------------------------------\n// Histograms (mergeable across instances)\n// ---------------------------------------------------------------------------\n\n/**\n * Upper bounds (inclusive, ms) of the latency buckets every histogram uses.\n * A histogram's `counts` has one more entry than this list: the last entry\n * counts everything above the highest bound. Fixed bounds make histograms\n * from several instances merge exactly.\n */\nexport const DEVTOOLS_LATENCY_BUCKETS_MS = [\n 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 30000,\n] as const;\n\n/** A latency histogram over `DEVTOOLS_LATENCY_BUCKETS_MS`. */\nexport type DevtoolsHistogram = {\n /** `DEVTOOLS_LATENCY_BUCKETS_MS.length + 1` entries. */\n counts: number[];\n count: number;\n sumMs: number;\n maxMs: number;\n};\n\n// ---------------------------------------------------------------------------\n// Query, route and error statistics\n// ---------------------------------------------------------------------------\n\n/** Statistics for one normalized query shape (literals and bindings replaced by `?`). */\nexport type DevtoolsQueryShapeStats = {\n /** First 16 hex characters of the SHA-256 of `shape`; the id the API and EXPLAIN use. */\n id: string;\n /** The normalized query, at most 2000 characters. Never holds a value. */\n shape: string;\n driver: \"postgres\" | \"mongodb\";\n connection: string;\n count: number;\n errors: number;\n histogram: DevtoolsHistogram;\n /** Sampled requests in which this shape reached the N+1 threshold, and the highest count in one request. */\n nPlusOne: { requests: number; maxPerRequest: number };\n /** The slowest run seen; its values stay in the process that ran it (see EXPLAIN). */\n slowest: {\n durationMs: number;\n at: number;\n route: string | null;\n requestId: string | null;\n instance: string;\n } | null;\n firstSeen: number;\n lastSeen: number;\n /** Whether EXPLAIN can run for this shape (a Postgres `SELECT`/`WITH`, or a MongoDB `find`/`aggregate`/`count`). */\n explainable: boolean;\n};\n\n/** Time spent in one named request phase (middleware, validation, handler, …) on one route. */\nexport type DevtoolsRoutePhaseStats = {\n name: string;\n count: number;\n sumMs: number;\n maxMs: number;\n};\n\n/** Statistics for one route pattern and method. */\nexport type DevtoolsRouteStats = {\n /** `\"<METHOD> <route pattern>\"`, e.g. `\"GET /posts/:slug\"`. */\n key: string;\n method: string;\n route: string;\n count: number;\n /** Responses with a 5xx status or a thrown error. */\n errors: number;\n histogram: DevtoolsHistogram;\n /** At most 30 phases, slowest total first. */\n phases: DevtoolsRoutePhaseStats[];\n slowest: { durationMs: number; at: number; requestId: string | null; instance: string } | null;\n};\n\n/** Errors grouped by fingerprint (normalized message + route + source). */\nexport type DevtoolsErrorGroup = {\n /** First 16 hex characters of the SHA-256 of the fingerprint. */\n id: string;\n /** The latest message as raised, at most 500 characters. */\n message: string;\n /** The error class name when known (`TypeError`). */\n name: string | null;\n source: \"request\" | \"log\";\n route: string | null;\n status: number | null;\n count: number;\n firstSeen: number;\n lastSeen: number;\n lastRequestId: string | null;\n /** The latest stack, at most 4000 characters; `null` when none was available. */\n stack: string | null;\n};\n\n/** A warn/error log entry kept for the Logs panel in production (no context: it may hold values). */\nexport type DevtoolsReportLogEntry = {\n level: \"debug\" | \"info\" | \"warn\" | \"error\" | \"success\";\n module: string;\n action: string;\n /** At most 1000 characters. */\n message: string;\n at: number;\n requestId: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Resources, health, jobs\n// ---------------------------------------------------------------------------\n\n/** One resource reading of a process. */\nexport type DevtoolsResourcePoint = {\n at: number;\n rssBytes: number;\n heapUsedBytes: number;\n heapTotalBytes: number;\n externalBytes: number;\n /** Process CPU time over wall time since the previous point, 0–100 per core (can exceed 100). */\n cpuPercent: number;\n eventLoopDelayP50Ms: number;\n eventLoopDelayP99Ms: number;\n eventLoopDelayMaxMs: number;\n /** `performance.eventLoopUtilization()` since the previous point, 0–1. */\n eventLoopUtilization: number;\n /** Garbage collections since the previous point. */\n gcCount: number;\n /** Total GC pause since the previous point. */\n gcPauseMs: number;\n};\n\n/** The latest resource reading plus values that change rarely. */\nexport type DevtoolsResourceSnapshot = DevtoolsResourcePoint & {\n heapLimitBytes: number;\n uptimeSeconds: number;\n /** Totals since the monitor started, by GC kind. */\n gcByKind: Record<\n \"minor\" | \"major\" | \"incremental\" | \"weakcb\",\n { count: number; pauseMs: number }\n >;\n};\n\n/** Readiness checks (core's `health` registry) of one process, with a short history. */\nexport type DevtoolsHealthReport = {\n status: \"ok\" | \"error\" | \"unknown\";\n checkedAt: number | null;\n checks: Record<string, boolean>;\n /** Newest last, at most 60 entries. */\n history: { at: number; status: \"ok\" | \"error\"; failed: string[] }[];\n};\n\n/** One scheduled job (`@warlock.js/scheduler`). */\nexport type DevtoolsScheduleInfo = {\n name: string;\n /** The cron expression, or `null` for an interval schedule. */\n cron: string | null;\n /** A readable interval such as `\"every 5 minutes\"`, or `null`. */\n interval: string | null;\n isRunning: boolean;\n lastRunAt: number | null;\n nextRunAt: number | null;\n lastDurationMs: number | null;\n lastError: string | null;\n runs: number;\n failures: number;\n};\n\n/** Background work of one process: schedules and queue counts, each `available: false` when its package is not installed. */\nexport type DevtoolsJobsReport = {\n available: { scheduler: boolean; queue: boolean };\n schedules: DevtoolsScheduleInfo[];\n /** Job counts per queue and state (`waiting`, `active`, `delayed`, `failed`, `completed`). */\n queues: { name: string; counts: Record<string, number> }[];\n};\n\n/** What the capture did since the process started. */\nexport type DevtoolsCaptureCounters = {\n sampleRate: number;\n requests: number;\n sampled: number;\n /** Unsampled requests kept as a summary because they were slow or failed. */\n keptUnsampled: number;\n /** Samples written to the database. */\n stored: number;\n /** Samples not written because the per-minute budget was spent. */\n droppedStored: number;\n /** Query shapes, routes and error groups evicted to keep memory bounded. */\n evictedShapes: number;\n evictedRoutes: number;\n evictedErrors: number;\n /** Queries not kept inside a sampled request because it reached its per-request limit. */\n droppedQueries: number;\n};\n\n/**\n * Everything one process reports, written to the database every\n * `reportIntervalMs` (one row per instance) and merged by the dashboard.\n * Serialized it stays under 256 KB: lists are trimmed from the end.\n */\nexport type DevtoolsInstanceReport = {\n instance: DevtoolsInstanceInfo;\n at: number;\n resources: { snapshot: DevtoolsResourceSnapshot; history: DevtoolsResourcePoint[] };\n /** At most 200, highest total time first. */\n queries: DevtoolsQueryShapeStats[];\n /** At most 200, highest total time first. */\n routes: DevtoolsRouteStats[];\n /** At most 50, newest first. */\n errors: DevtoolsErrorGroup[];\n /** At most 50, newest first. */\n logs: DevtoolsReportLogEntry[];\n health: DevtoolsHealthReport;\n jobs: DevtoolsJobsReport;\n capture: DevtoolsCaptureCounters;\n};\n\n// ---------------------------------------------------------------------------\n// Requests (stored samples)\n// ---------------------------------------------------------------------------\n\n/**\n * A request row. Matches the development `DevtoolsRequestSummary` field for\n * field, plus where it was captured.\n */\nexport type DevtoolsSampleSummary = {\n id: string;\n method: string;\n path: string;\n route?: string;\n status?: number;\n startedAt: number;\n durationMs?: number;\n queryCount: number;\n warningCount: number;\n /** Read from the persisted request log only. */\n persisted?: true;\n /** The instance that served the request. */\n instance?: string;\n /** Kept because it was slow or failed, without a timeline (the request was not sampled). */\n partial?: true;\n};\n\n/** A query inside a stored sample: the shape only, never the SQL text with values or the bindings. */\nexport type DevtoolsSampleQuery = {\n id: string;\n connection: string;\n driver: \"postgres\" | \"mongodb\";\n /** Same as `shape`: kept under this name so the request view renders it like a development query. */\n sql?: string;\n collection?: string;\n command?: string;\n shape: string;\n shapeId: string;\n startedAt: number;\n durationMs: number;\n rowCount?: number;\n error?: string;\n};\n\n/** The timeline of a sampled request, with every value removed (see the redaction rules). */\nexport type DevtoolsSampleDetail = DevtoolsSampleSummary & {\n error?: string;\n phases: { name: string; startedAt: number; durationMs: number }[];\n queries: DevtoolsSampleQuery[];\n /** Cache operation counts only; keys are not kept. */\n cache: { hits: number; misses: number; writes: number };\n /** Log entries without context. */\n logs: { level: string; module: string; action: string; message: string; at: number }[];\n warnings: { type: \"n+1\"; message: string; shape: string; count: number }[];\n /** Queries left out because the request reached `maxQueriesPerRequest`. */\n droppedQueries: number;\n};\n\n// ---------------------------------------------------------------------------\n// API views (what the dashboard reads)\n// ---------------------------------------------------------------------------\n\n/** `GET api/instances`. */\nexport type DevtoolsInstancesView = {\n /** The instance that answered this request. */\n current: string;\n /** Instances seen in the last 5 minutes (the answering one included), newest first. */\n instances: DevtoolsInstanceInfo[];\n};\n\n/** `GET api/resources?instance=<id|all>`. */\nexport type DevtoolsResourcesView = {\n instances: {\n instance: DevtoolsInstanceInfo;\n snapshot: DevtoolsResourceSnapshot;\n history: DevtoolsResourcePoint[];\n }[];\n};\n\n/** A shape row with figures computed from its histogram. */\nexport type DevtoolsQueryShapeRow = DevtoolsQueryShapeStats & {\n p50Ms: number;\n p95Ms: number;\n meanMs: number;\n /** Ids of the instances that reported this shape. */\n instances: string[];\n};\n\n/** `GET api/queries/stats?instance=&sort=total|p95|count|n+1&limit=`. */\nexport type DevtoolsQueryStatsView = {\n shapes: DevtoolsQueryShapeRow[];\n /** The sample rate the counts come from; counts are of sampled requests only. */\n sampleRate: number;\n instanceCount: number;\n evicted: number;\n};\n\n/** A route row with figures computed from its histogram. */\nexport type DevtoolsRouteStatsRow = DevtoolsRouteStats & {\n p50Ms: number;\n p95Ms: number;\n meanMs: number;\n instances: string[];\n};\n\n/** `GET api/routes/stats?instance=&sort=total|p95|count|errors&limit=`. */\nexport type DevtoolsRouteStatsView = {\n routes: DevtoolsRouteStatsRow[];\n sampleRate: number;\n instanceCount: number;\n};\n\n/** `GET api/health?instance=`. */\nexport type DevtoolsHealthView = {\n instances: { instance: DevtoolsInstanceInfo; report: DevtoolsHealthReport }[];\n};\n\n/** `GET api/errors?instance=&limit=`. */\nexport type DevtoolsErrorsView = {\n groups: (DevtoolsErrorGroup & { instances: string[] })[];\n};\n\n/**\n * One row of `GET api/logs?level=&module=&instance=` (newest first), in both\n * modes. Development rows carry `context` and no `instance`; production rows\n * carry `instance` and never `context`.\n */\nexport type DevtoolsLogRow = DevtoolsReportLogEntry & {\n instance: string | null;\n context?: unknown;\n};\n\n/** `GET api/logs`: the rows, newest first (a plain array, as in 5.55). */\nexport type DevtoolsLogsView = DevtoolsLogRow[];\n\n/** `GET api/jobs?instance=`. */\nexport type DevtoolsJobsView = {\n instances: { instance: DevtoolsInstanceInfo; report: DevtoolsJobsReport }[];\n};\n\n/** `POST api/queries/:shapeId/explain`. */\nexport type DevtoolsExplainResult = {\n shapeId: string;\n driver: \"postgres\" | \"mongodb\";\n /** `true` only when the project allows executing plans (`explain.executing`). */\n executing: boolean;\n plan: unknown;\n /** The instance whose example ran the EXPLAIN. */\n instance: string;\n};\n\n/** One dashboard tab, as `GET api/panels` lists it (enabled tabs only, in display order). */\nexport type DevtoolsPanelInfo = {\n id: string;\n title: string;\n /** `built-in` tabs are React views in the bundle; `package` tabs load `panels/<id>/view.js`. */\n type: \"built-in\" | \"package\";\n /** Whether the panel declares a shared view (`DevtoolsPanel.share`); always `false` for built-in tabs. */\n shareable: boolean;\n};\n\n/**\n * The built-in tabs, in display order, with whether production shows them\n * when the project says nothing (`production.panels` overrides per id).\n *\n * The AI section (`ai-reports`, `ai`, `agents`, `ai-models`, `ai-errors`,\n * `ai-evaluate`) sits under \"AI\" in the sidebar. `ai` keeps its id (it is the\n * Runs page) so existing links and `production.panels.ai` keep working. In\n * production the three report tabs show only when the AI feed is available\n * (Panoptic loads), unless `production.panels` turns one on explicitly.\n */\nexport const DEVTOOLS_BUILT_IN_PANELS = [\n { id: \"requests\", title: \"Requests\", production: true },\n { id: \"queries\", title: \"Queries\", production: true },\n { id: \"routes\", title: \"Routes\", production: true },\n { id: \"resources\", title: \"Resources\", production: true },\n { id: \"health\", title: \"Health\", production: true },\n { id: \"errors\", title: \"Errors\", production: true },\n { id: \"logs\", title: \"Logs\", production: true },\n { id: \"jobs\", title: \"Jobs\", production: true },\n { id: \"mail\", title: \"Mail\", production: false },\n { id: \"ai-reports\", title: \"Reports\", production: true },\n { id: \"ai\", title: \"Runs\", production: false },\n { id: \"agents\", title: \"Agents\", production: false },\n { id: \"ai-models\", title: \"Models\", production: true },\n { id: \"ai-errors\", title: \"Errors\", production: true },\n { id: \"ai-evaluate\", title: \"Evaluate\", production: false },\n { id: \"api\", title: \"API\", production: false },\n] as const;\n\n/** The id of a built-in tab. */\nexport type DevtoolsBuiltInPanelId = (typeof DEVTOOLS_BUILT_IN_PANELS)[number][\"id\"];\n\n// ---------------------------------------------------------------------------\n// Accounts, sessions, invites\n// ---------------------------------------------------------------------------\n\n/** An account as the API shows it (never a hash or a secret). */\nexport type DevtoolsAccountView = {\n id: string;\n email: string;\n role: DevtoolsRole;\n twoFactor: {\n totp: boolean;\n passkeys: { id: string; name: string; createdAt: number; lastUsedAt: number | null }[];\n recoveryCodesLeft: number;\n };\n mustChangePassword: boolean;\n createdAt: number;\n lastLoginAt: number | null;\n};\n\n/** `GET api/auth/session`: who is signed in and what comes next. */\nexport type DevtoolsSessionView = {\n mode: DevtoolsMode;\n stage: DevtoolsSessionStage;\n /** `null` when signed out, and in development (no accounts there). */\n account: DevtoolsAccountView | null;\n /** `admin` in development; `null` when signed out. */\n role: DevtoolsRole | null;\n /** The token to send as `X-Devtools-Csrf` on every POST/PUT/PATCH/DELETE; `null` when signed out and in development. */\n csrf: string | null;\n /** When the session ends at the latest; `null` when signed out and in development. */\n expiresAt: number | null;\n /** The instance that answered; `null` when signed out. */\n instance: DevtoolsInstanceInfo | null;\n /** Sign-in methods the server offers; `null` when signed out. */\n methods: { totp: true; passkeys: boolean } | null;\n /** Read-only share links: `enabled` mirrors `production.share.enabled`; `null` when signed out and in development. */\n share: { enabled: boolean } | null;\n /** The installed `@warlock.js/core` version; `null` when signed out or not found. */\n warlockVersion: string | null;\n /** The app's own `package.json` name and version (nothing else is read); `null` when signed out or not found. */\n app: { name: string; version: string } | null;\n};\n\n/** `POST api/auth/login` body. */\nexport type DevtoolsLoginInput = { email: string; password: string };\n\n/** Answer of every sign-in step: the next stage, and the new CSRF token when the session changed. */\nexport type DevtoolsAuthStepResult = { stage: DevtoolsSessionStage; csrf: string | null };\n\n/** `POST api/auth/totp/start` (and `api/account/totp/start`). */\nexport type DevtoolsTotpEnrolment = {\n /** Base32, for manual entry. */\n secret: string;\n /** `otpauth://totp/...`, rendered as a QR code by the dashboard. */\n uri: string;\n issuer: string;\n account: string;\n};\n\n/** Recovery codes, shown once. */\nexport type DevtoolsRecoveryCodes = { codes: string[] };\n\n/** A pending or used invite. */\nexport type DevtoolsInviteView = {\n id: string;\n email: string;\n role: DevtoolsRole;\n createdAt: number;\n expiresAt: number;\n createdBy: string | null;\n usedAt: number | null;\n};\n\n/** `POST api/admin/invites`: the token appears only in this answer. */\nexport type DevtoolsCreatedInvite = { invite: DevtoolsInviteView; token: string };\n\n/** `GET api/admin/users`. */\nexport type DevtoolsUserListView = {\n accounts: DevtoolsAccountView[];\n invites: DevtoolsInviteView[];\n};\n\n/** A session as its owner sees it (`GET api/account/sessions`). */\nexport type DevtoolsSessionInfo = {\n id: string;\n current: boolean;\n createdAt: number;\n lastSeenAt: number;\n expiresAt: number;\n ip: string | null;\n userAgent: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Share links\n// ---------------------------------------------------------------------------\n\n/** Where a share link stands. `revoked` wins over `expired`. */\nexport type DevtoolsShareStatus = \"active\" | \"expired\" | \"revoked\";\n\n/** A share link as the admin screen shows it (never the token or its hash). */\nexport type DevtoolsShareView = {\n id: string;\n /** The id of the panel the link opens. */\n panel: string;\n /** What the admin called it, 1-80 characters. */\n label: string;\n /** The email of the admin who made it; `null` when that account is gone. */\n createdBy: string | null;\n createdAt: number;\n expiresAt: number;\n revokedAt: number | null;\n lastUsedAt: number | null;\n /** How many times the link was used, counted at most once a minute. */\n uses: number;\n status: DevtoolsShareStatus;\n};\n\n/** `GET api/admin/shares`. */\nexport type DevtoolsShareList = {\n enabled: boolean;\n /** The longest life a link may have, in days. */\n maxDays: number;\n /** The panels that declare a shared view. */\n panels: { id: string; title: string }[];\n /** Newest first. */\n shares: DevtoolsShareView[];\n};\n\n/** `POST api/admin/shares` body. `label` is 1-80 characters, `days` a whole number from 1 to `maxDays`. */\nexport type DevtoolsShareCreateInput = { panel: string; label: string; days: number };\n\n/** `POST api/admin/shares`: the URL (with the token in its fragment) appears only in this answer. */\nexport type DevtoolsCreatedShare = { share: DevtoolsShareView; url: string };\n\n/**\n * What a share link opens, answered by `POST api/share/open` and\n * `GET api/share/info`: the panel and the names the shared view may load.\n */\nexport type DevtoolsShareOpenAnswer = {\n panel: string;\n /** The panel's title. */\n title: string;\n label: string;\n expiresAt: number;\n /** Served names from the panel's `assets` the shared page may load. */\n assets: string[];\n /** Whether the shared page may load images from the panel's `files`. */\n files: boolean;\n};\n\n/** The longest label of a share link. */\nexport const DEVTOOLS_SHARE_LABEL_MAX = 80;\n\n// ---------------------------------------------------------------------------\n// Audit log\n// ---------------------------------------------------------------------------\n\n/** Every audited event. `login.failed` and `mfa.failed` are the ones rate limits count. */\nexport type DevtoolsAuditType =\n | \"admin.seeded\"\n | \"admin.reset\"\n | \"setup.completed\"\n | \"login.succeeded\"\n | \"login.failed\"\n | \"login.blocked\"\n | \"mfa.succeeded\"\n | \"mfa.failed\"\n | \"mfa.enrolled\"\n | \"mfa.removed\"\n | \"recovery-code.used\"\n | \"recovery-codes.regenerated\"\n | \"passkey.added\"\n | \"passkey.removed\"\n | \"password.changed\"\n | \"logout\"\n | \"session.revoked\"\n | \"invite.created\"\n | \"invite.revoked\"\n | \"invite.accepted\"\n | \"account.role-changed\"\n | \"account.removed\"\n | \"account.mfa-reset\"\n | \"account.signed-out\"\n | \"dashboard.disabled\"\n | \"dashboard.enabled\"\n | \"dashboard.locked\"\n | \"explain.run\"\n | \"requests.cleared\"\n | \"panel.action\"\n | \"share.created\"\n | \"share.revoked\"\n | \"share.failed\";\n\n/** The audit types that count toward the account, IP and global failure limits. */\nexport const DEVTOOLS_FAILURE_AUDIT_TYPES: readonly DevtoolsAuditType[] = [\n \"login.failed\",\n \"mfa.failed\",\n \"share.failed\",\n];\n\n/** One audit log entry. */\nexport type DevtoolsAuditEntry = {\n id: string;\n at: number;\n type: DevtoolsAuditType;\n /** The account acting or targeted; `null` for an unknown email or the CLI. */\n accountId: string | null;\n /** The email as typed or as stored, lower-cased; `null` when there was none. */\n email: string | null;\n /** `\"cli\"` for a command, else the client IP after trusted-proxy resolution. */\n ip: string | null;\n /** At most 200 characters. */\n userAgent: string | null;\n /** Small flat facts: target account, role, shape id, panel route. Never a secret. */\n detail: Record<string, string | number | boolean | null>;\n /** Short reference shown to users in error messages (8 characters). */\n ref: string;\n};\n\n// ---------------------------------------------------------------------------\n// Errors the API returns\n// ---------------------------------------------------------------------------\n\n/**\n * Error codes in API answers. Each has a fixed message (see\n * `DEVTOOLS_ERROR_MESSAGES` in `errors.ts`) that says what failed and what to\n * do next.\n */\nexport type DevtoolsErrorCode =\n | \"auth.invalid-credentials\"\n | \"auth.invalid-code\"\n | \"auth.invalid-setup-token\"\n | \"auth.password-too-short\"\n | \"auth.password-too-long\"\n | \"auth.password-common\"\n | \"auth.password-same-as-email\"\n | \"auth.password-unchanged\"\n | \"auth.wrong-current-password\"\n | \"auth.busy\"\n | \"invite.invalid\"\n | \"invite.email-taken\"\n | \"account.not-found\"\n | \"account.last-admin\"\n | \"account.self\"\n | \"account.last-factor\"\n | \"role.forbidden\"\n | \"csrf.invalid\"\n | \"passkey.unavailable\"\n | \"passkey.failed\"\n | \"explain.not-allowed\"\n | \"explain.unsupported\"\n | \"explain.elsewhere\"\n | \"explain.failed\"\n | \"request.not-found\"\n | \"request.invalid-filter\"\n | \"share.not-found\"\n | \"stream.too-many\"\n | \"ai.range-invalid\"\n | \"ai.evaluate-unavailable\"\n | \"ai.prompt-not-found\"\n | \"ai.evaluate-failed\"\n | \"input.invalid\"\n | \"server.error\";\n\n/** The JSON body of every failed API call. */\nexport type DevtoolsApiErrorBody = {\n /** What failed and what to do next. */\n error: string;\n code: DevtoolsErrorCode;\n /** Short reference to quote to an admin; also written to the audit log or server log. */\n ref?: string;\n /** The instance that answered, when it matters (`explain.elsewhere`). */\n instance?: string;\n};\n\n// ---------------------------------------------------------------------------\n// AI section: reports, runs, models, errors, evaluate\n// ---------------------------------------------------------------------------\n\n/**\n * Upper bounds (inclusive, ms) of the latency buckets of the AI rollups.\n * Model calls take seconds, so these differ from `DEVTOOLS_LATENCY_BUCKETS_MS`.\n * A histogram has one more count than this list: the last counts everything\n * above five minutes. Fixed bounds make rollups from several processes add up\n * exactly. Changing them is a breaking change of the stored rollups.\n */\nexport const DEVTOOLS_AI_LATENCY_BUCKETS_MS = [\n 250, 500, 1000, 2000, 3000, 5000, 7500, 10000, 15000, 20000, 30000, 45000, 60000, 120000, 300000,\n] as const;\n\n/** The date-range presets of the Reports, Models and Errors pages. */\nexport type DevtoolsAiRangePreset = \"24h\" | \"7d\" | \"30d\";\n\n/** The range a report covers, after the server aligned it to its buckets. */\nexport type DevtoolsAiResolvedRange = {\n preset: DevtoolsAiRangePreset | \"custom\";\n /** Inclusive start, on an hour boundary. */\n from: number;\n /** Exclusive end, on an hour boundary. */\n to: number;\n /** Bucket width of the charts: 1 hour, 6 hours or 1 day. */\n stepMs: number;\n /** The browser's offset from UTC (minutes east), used to align day buckets. */\n utcOffsetMinutes: number;\n};\n\n/** Why an AI page has nothing to show; `title`, `message` and `command` are written for the page. */\nexport type DevtoolsAiUnavailableReasonView =\n | \"ai-missing\"\n | \"panoptic-missing\"\n | \"panoptic-failed\"\n | \"observation-off\"\n | \"not-collected\"\n | \"table-missing\"\n | \"reports-off\";\n\n/** The answer of any AI route that cannot serve its data. */\nexport type DevtoolsAiUnavailableView = {\n available: false;\n reason: DevtoolsAiUnavailableReasonView;\n title: string;\n message: string;\n /** A command or config line to copy; `null` when there is none. */\n command: string | null;\n /** The load error and versions for `panoptic-failed`; otherwise `null`. */\n detail: string | null;\n};\n\n/** Token counts. `input` is the whole prompt (cache reads and writes included) on every provider. */\nexport type DevtoolsAiTokenTotals = {\n input: number;\n output: number;\n /** Prompt tokens read from the provider's cache (part of `input`). */\n cached: number;\n /** Prompt tokens written to the provider's cache (part of `input`). */\n cacheWrite: number;\n /** Reasoning tokens (part of `output`). */\n reasoning: number;\n};\n\n/**\n * Estimated cost. `estimatedUsd` sums only runs whose model has pricing; runs\n * that used tokens on a model without pricing are counted in `unpricedRuns`\n * and `unpricedTokens`, never as zero cost.\n */\nexport type DevtoolsAiCostTotals = {\n estimatedUsd: number;\n pricedRuns: number;\n unpricedRuns: number;\n unpricedTokens: number;\n};\n\n/** Latency from the bucketed histogram: each figure is a bucket's upper bound (`null` with no runs). */\nexport type DevtoolsAiLatencyTotals = {\n p50Ms: number | null;\n p95Ms: number | null;\n meanMs: number | null;\n};\n\n/** Totals over a range (or one row of a breakdown). */\nexport type DevtoolsAiTotals = {\n runs: number;\n completed: number;\n failed: number;\n /** Runs that stopped early: `incomplete` and `max-iterations`. */\n incomplete: number;\n cancelled: number;\n /** `(failed + incomplete) / runs`, from 0 to 1; 0 with no runs. Cancelled runs are not errors. */\n errorRate: number;\n tokens: DevtoolsAiTokenTotals;\n cost: DevtoolsAiCostTotals;\n latency: DevtoolsAiLatencyTotals;\n /** Runs where a `fallbackModel()` chain answered from a later model at least once. */\n fallbackRuns: number;\n /** Runs where the provider refused at least once (finish reason `refusal` or a content filter). */\n refusals: number;\n};\n\n/**\n * Time series for a stacked chart: `values[i]` belongs to `buckets[i]`. At\n * most five named series; the rest are summed into one `other` series.\n */\nexport type DevtoolsAiSeriesSet = {\n /** Bucket starts, oldest first. */\n buckets: number[];\n series: {\n /** Stable identity (`provider/model`, an agent name, a category); the UI keys colours on it. */\n key: string;\n label: string;\n values: number[];\n /** `true` for the summed \"Other\" series. */\n other: boolean;\n }[];\n};\n\n/** One bucket of the error-rate line. */\nexport type DevtoolsAiRatePoint = {\n at: number;\n runs: number;\n /** Failed plus incomplete runs. */\n errors: number;\n /** `errors / runs`; `null` for a bucket without runs (the line has a gap there). */\n rate: number | null;\n};\n\n/** A row of the top agents or top models table. */\nexport type DevtoolsAiBreakdownRow = {\n /** The agent name, or `provider/model`. */\n key: string;\n label: string;\n /** The provider for a model row; `null` for an agent row. */\n provider: string | null;\n totals: DevtoolsAiTotals;\n /** Share of the range's estimated cost, 0 to 1 (share of runs when nothing was priced). */\n share: number;\n};\n\n/** The filter values present in a range, for the filter row. */\nexport type DevtoolsAiFilterOptions = {\n agents: string[];\n /** `provider/model` keys. */\n models: string[];\n providers: string[];\n};\n\n/** `GET api/ai/reports`. */\nexport type DevtoolsAiReportView =\n | DevtoolsAiUnavailableView\n | {\n available: true;\n range: DevtoolsAiResolvedRange;\n /** The period of the same length just before `range`. */\n previousRange: { from: number; to: number };\n /** `false` when part of the previous period is older than the kept history: its totals are partial. */\n previousComplete: boolean;\n totals: DevtoolsAiTotals;\n previous: DevtoolsAiTotals;\n /** Estimated USD per bucket, by model (top five plus Other). */\n costByModel: DevtoolsAiSeriesSet;\n /** Tokens per bucket: series `uncached`, `cached`, `output`. */\n tokens: DevtoolsAiSeriesSet;\n errorRate: DevtoolsAiRatePoint[];\n /** Up to 10 rows, highest estimated cost first (most runs when nothing was priced). */\n topAgents: DevtoolsAiBreakdownRow[];\n topModels: DevtoolsAiBreakdownRow[];\n /** `provider/model` keys that used tokens without pricing in the range. */\n unpricedModels: string[];\n filters: DevtoolsAiFilterOptions;\n /** `true` when `@warlock.js/ai` observes nothing, so new runs are not counted. */\n observationOff: boolean;\n generatedAt: number;\n };\n\n/** Whether a model's runs carried pricing in the range; `no-tokens` when no run used tokens. */\nexport type DevtoolsAiPricingState = \"set\" | \"missing\" | \"partial\" | \"no-tokens\";\n\n/** One row of the Models page. */\nexport type DevtoolsAiModelRow = {\n /** `provider/model`. */\n key: string;\n model: string;\n provider: string;\n totals: DevtoolsAiTotals;\n pricing: DevtoolsAiPricingState;\n /** Estimated USD per priced run; `null` when no run was priced. */\n costPerRunUsd: number | null;\n /** `fallbackRuns / runs`, 0 to 1. */\n fallbackRate: number;\n /** Agents that used the model, most runs first (at most 5). */\n agents: string[];\n /** Start of the last hour with a run. */\n lastSeenAt: number;\n};\n\n/** `GET api/ai/models`. */\nexport type DevtoolsAiModelsView =\n | DevtoolsAiUnavailableView\n | {\n available: true;\n range: DevtoolsAiResolvedRange;\n totals: DevtoolsAiTotals;\n /** Most runs first. */\n models: DevtoolsAiModelRow[];\n /** Runs per bucket by model (top five plus Other). */\n runsByModel: DevtoolsAiSeriesSet;\n filters: DevtoolsAiFilterOptions;\n observationOff: boolean;\n generatedAt: number;\n };\n\n/** How failed runs are grouped on the Errors page. */\nexport type DevtoolsAiErrorCategory =\n | \"rate-limit\"\n | \"timeout\"\n | \"refusal\"\n | \"provider\"\n | \"budget\"\n | \"tool\"\n | \"schema\"\n | \"incomplete\"\n | \"other\";\n\n/** Every category, in the order the Errors page lists them. */\nexport const DEVTOOLS_AI_ERROR_CATEGORIES = [\n \"rate-limit\",\n \"timeout\",\n \"refusal\",\n \"provider\",\n \"budget\",\n \"tool\",\n \"schema\",\n \"incomplete\",\n \"other\",\n] as const satisfies readonly DevtoolsAiErrorCategory[];\n\n/** One category of failed runs. */\nexport type DevtoolsAiErrorGroup = {\n category: DevtoolsAiErrorCategory;\n /** \"Rate limit\", \"Timeout\", \"Refusal\", \"Provider error\", \"Budget\", \"Tool failed\", \"Invalid output\", \"Incomplete\", \"Other\". */\n label: string;\n count: number;\n /** Share of all failed runs in the range, 0 to 1. */\n share: number;\n previousCount: number;\n /** At most 5 each, most first. */\n byModel: { key: string; count: number }[];\n byAgent: { key: string; count: number }[];\n};\n\n/** A recent failed run (development only: production keeps no run details). */\nexport type DevtoolsAiFailedRun = {\n traceId: string;\n /** The agent span that failed. */\n agent: string;\n /** `provider/model`, or `null` when unreported. */\n model: string | null;\n status: string;\n category: DevtoolsAiErrorCategory;\n /** The error code (`PROVIDER_RATE_LIMIT`) or error name. */\n code: string | null;\n /** The error message, secrets scrubbed, at most 300 characters. */\n message: string | null;\n endedAt: number;\n requestId: string | null;\n};\n\n/** `GET api/ai/errors`. */\nexport type DevtoolsAiErrorsView =\n | DevtoolsAiUnavailableView\n | {\n available: true;\n range: DevtoolsAiResolvedRange;\n totals: DevtoolsAiTotals;\n previous: DevtoolsAiTotals;\n /** `false` when part of the previous period is older than the kept history: its totals are partial. */\n previousComplete: boolean;\n /** Categories with at least one failed run, most first. */\n groups: DevtoolsAiErrorGroup[];\n /** Failed runs per bucket by category (top five plus Other). */\n overTime: DevtoolsAiSeriesSet;\n /** Newest first, at most 50; `null` in production. */\n recent: DevtoolsAiFailedRun[] | null;\n filters: DevtoolsAiFilterOptions;\n observationOff: boolean;\n generatedAt: number;\n };\n\n/** Usage of one run as the Runs page shows it. */\nexport type DevtoolsAiUsageView = {\n input: number;\n output: number;\n total: number;\n cachedTokens: number | null;\n cacheWriteTokens: number | null;\n /** `false` when `input` excludes cache tokens (the provider reports them on top). */\n inputIncludesCache: boolean | null;\n};\n\n/** One row of the Runs page (a Panoptic trace, content-free). */\nexport type DevtoolsAiRunRow = {\n traceId: string;\n requestId: string | null;\n sessionId: string | null;\n name: string;\n /** The root span type: `agent`, `workflow`, `supervisor`, … */\n type: string;\n status: string;\n startedAt: string;\n duration: number;\n usage: DevtoolsAiUsageView;\n /** Estimated USD; `null` when the run carried no pricing. */\n cost: number | null;\n models: string[];\n /** `promptName@promptVersion` of the root agent, or `null`. */\n promptKey: string | null;\n toolCalls: number;\n retries: number;\n incomplete: boolean;\n};\n\n/** A group of the Runs page (`groupBy=session|prompt|type`). */\nexport type DevtoolsAiRunGroup = {\n key: string;\n label: string;\n runs: number;\n failed: number;\n estimatedCostUsd: number;\n p95Ms: number | null;\n /** Trace ids of the group, newest first (at most 50). */\n traceIds: string[];\n};\n\n/** `GET api/ai/runs`. */\nexport type DevtoolsAiRunsView =\n | DevtoolsAiUnavailableView\n | {\n available: true;\n /** Newest first, at most `limit` (default 200). */\n runs: DevtoolsAiRunRow[];\n /** `null` unless `groupBy` was given. */\n groups: DevtoolsAiRunGroup[] | null;\n stats: {\n /** Runs matching the filter (before `limit`). */\n count: number;\n failed: number;\n /** Priced runs only. */\n estimatedCostUsd: number;\n /** Runs that used tokens on a model without pricing (not in `estimatedCostUsd`). */\n unpricedRuns: number;\n p50Ms: number | null;\n p95Ms: number | null;\n };\n /** How many traces the dashboard keeps (`maxRequests`). */\n capacity: number;\n };\n\n/** A distinct system prompt seen in recent agent runs (the Evaluate picker). */\nexport type DevtoolsAiEvaluatePrompt = {\n /** The prompt's hash from the agent trace. */\n hash: string;\n /** Agents that used it, most recent first. */\n agents: string[];\n /** The newest run that carried its text. */\n runId: string;\n lastSeenAt: string;\n /** The first 200 characters. */\n preview: string;\n length: number;\n};\n\n/** `GET api/ai/evaluate`. */\nexport type DevtoolsAiEvaluateView =\n | DevtoolsAiUnavailableView\n | {\n available: true;\n /** Whether `panoptic.evaluate` (or `panoptic.dashboard.evaluate`) has a judge model. */\n configured: boolean;\n /** The judge model as `provider/name`; `null` when not configured. */\n judge: string | null;\n /** The configured default grading instructions; `\"\"` when none. */\n instructions: string;\n /** Newest first, at most 50. */\n prompts: DevtoolsAiEvaluatePrompt[];\n };\n\n/** `POST api/ai/evaluate` body: exactly one of `runId` and `systemPrompt`. */\nexport type DevtoolsAiEvaluateRequest = {\n /** An agent run whose system prompt text is kept. */\n runId?: string;\n /** A pasted prompt, 1 to 100,000 characters. */\n systemPrompt?: string;\n /** Overrides the configured instructions for this run; at most 4,000 characters. */\n instructions?: string;\n};\n\n/** `POST api/ai/evaluate` answer. */\nexport type DevtoolsAiEvaluateResult = {\n /** 0 to 1; `null` when the judge returned no score. */\n score: number | null;\n issues: string[];\n /** The judge model as `provider/name`. */\n judge: string;\n durationMs: number;\n};\n"],"mappings":";;;;;;;AA+DA,MAAa,8BAA8B;CACzC;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAK;CAAK;CAAK;CAAM;CAAM;CAAM;CAAO;AAC/D;;;;;;;;;;;AAsXA,MAAa,2BAA2B;CACtC;EAAE,IAAI;EAAY,OAAO;EAAY,YAAY;CAAK;CACtD;EAAE,IAAI;EAAW,OAAO;EAAW,YAAY;CAAK;CACpD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAa,OAAO;EAAa,YAAY;CAAK;CACxD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAK;CAC9C;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAK;CAC9C;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAM;CAC/C;EAAE,IAAI;EAAc,OAAO;EAAW,YAAY;CAAK;CACvD;EAAE,IAAI;EAAM,OAAO;EAAQ,YAAY;CAAM;CAC7C;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAM;CACnD;EAAE,IAAI;EAAa,OAAO;EAAU,YAAY;CAAK;CACrD;EAAE,IAAI;EAAa,OAAO;EAAU,YAAY;CAAK;CACrD;EAAE,IAAI;EAAe,OAAO;EAAY,YAAY;CAAM;CAC1D;EAAE,IAAI;EAAO,OAAO;EAAO,YAAY;CAAM;AAC/C;;AAwMA,MAAa,+BAA6D;CACxE;CACA;CACA;AACF;;;;;;;;AAwFA,MAAa,iCAAiC;CAC5C;CAAK;CAAK;CAAM;CAAM;CAAM;CAAM;CAAM;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAQ;AAC5F;;AAuNA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -60,6 +60,10 @@ const DEVTOOLS_ERROR_MESSAGES = {
60
60
  "request.invalid-filter": "A filter value is not valid. Check the status, method and dates.",
61
61
  "share.not-found": "This share link no longer exists or is already revoked. Reload the list.",
62
62
  "stream.too-many": "Too many live views are open for this session. Close another dashboard tab and reload.",
63
+ "ai.range-invalid": "The date range is not valid. Pick 24 hours, 7 days or 30 days, or a custom range of at least one hour inside the kept history.",
64
+ "ai.evaluate-unavailable": "Evaluate is not set up. Add panoptic.evaluate with a judge model to src/config/ai.ts, then restart.",
65
+ "ai.prompt-not-found": "This run's system prompt is no longer kept. Pick a newer run or paste the prompt.",
66
+ "ai.evaluate-failed": "The judge model could not grade this prompt. Check its API key and quota; the reference is in the server log.",
63
67
  "input.invalid": "Some fields are missing or not valid. Check the form and try again.",
64
68
  "server.error": "The dashboard could not complete this action. Try again; if it keeps failing, give your admin the reference shown."
65
69
  };
@@ -93,6 +97,10 @@ const DEVTOOLS_ERROR_STATUS = {
93
97
  "request.invalid-filter": 400,
94
98
  "share.not-found": 404,
95
99
  "stream.too-many": 429,
100
+ "ai.range-invalid": 400,
101
+ "ai.evaluate-unavailable": 409,
102
+ "ai.prompt-not-found": 404,
103
+ "ai.evaluate-failed": 502,
96
104
  "input.invalid": 422,
97
105
  "server.error": 500
98
106
  };
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/errors.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport type { DevtoolsApiErrorBody, DevtoolsErrorCode } from \"./contracts\";\n\n/**\n * Why production mode refused to start. Each code names one missing or\n * invalid setting; the message says which and how to fix it.\n */\nexport const DEVTOOLS_CONFIG_CODES = {\n DT001:\n \"Devtools production mode needs a dashboard path. Set DEVTOOLS_PATH (for example /ops-7f3k2q) or devtools.production.path.\",\n DT002:\n 'The devtools dashboard path must start with \"/\", be at least 8 characters, use only letters, digits, \"-\", \"_\", \".\", \"~\" and \"/\", and not be \"/__warlock\".',\n DT003:\n \"Devtools production mode has no admin yet. Set DEVTOOLS_ADMIN_EMAIL with DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin --email <email>`.\",\n DT004:\n \"DEVTOOLS_ADMIN_PASSWORD does not meet the password rules (the minimum length, at most 72 bytes, not a common password unless `passwords.rejectCommon` is false, not the email). Choose another one.\",\n DT005:\n \"Devtools production mode stores its accounts in the database. Install @warlock.js/cascade and configure a database connection.\",\n DT006:\n \"Devtools production mode encrypts two-factor secrets with the app key. Set encryption.key (64 hex characters) in src/config/encryption.ts.\",\n DT007:\n \"A devtools production option has an invalid value. The message names the option and the accepted values.\",\n DT008:\n \"The devtools tables are missing. Add devtoolsMigrations from @warlock.js/devtools/production to database.migrations in warlock.config.ts and run `warlock migrate`.\",\n DT009: \"Set either DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, not both.\",\n DT010:\n \"DEVTOOLS_SETUP_TOKEN must be at least 32 characters. Generate one with: openssl rand -base64 32\",\n} as const;\n\n/** A production configuration error code (`DT001`–`DT010`). */\nexport type DevtoolsConfigCode = keyof typeof DEVTOOLS_CONFIG_CODES;\n\n/**\n * Thrown while the devtools connector boots in production when the monitor is\n * enabled but cannot start safely. It stops the app from booting, so a\n * misconfigured deploy fails at once instead of serving an unprotected\n * dashboard.\n */\nexport class DevtoolsProductionConfigError extends Error {\n public readonly code: DevtoolsConfigCode;\n\n public constructor(code: DevtoolsConfigCode, detail?: string) {\n super(`[${code}] ${detail ? `${detail} ` : \"\"}${DEVTOOLS_CONFIG_CODES[code]}`);\n this.name = \"DevtoolsProductionConfigError\";\n this.code = code;\n }\n}\n\n/** The message every API error code answers with: what failed and what to do next. */\nexport const DEVTOOLS_ERROR_MESSAGES: Record<DevtoolsErrorCode, string> = {\n \"auth.invalid-credentials\":\n \"The email or password is not correct. Check both and try again; after several failed tries, wait 15 minutes.\",\n \"auth.invalid-code\":\n \"The code is not correct or has expired. Enter the current 6-digit code from your authenticator app, or a recovery code.\",\n \"auth.invalid-setup-token\":\n \"This setup link is not valid. Use the link built from DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin`.\",\n \"auth.password-too-short\":\n \"Use a longer password. The minimum length is set by passwords.minLength (8 characters by default).\",\n \"auth.password-too-long\": \"Use a password of at most 72 bytes (about 72 letters).\",\n \"auth.password-common\": \"This password is too common. Choose one that is harder to guess.\",\n \"auth.password-same-as-email\": \"The password must not be your email address. Choose another one.\",\n \"auth.password-unchanged\": \"Choose a new password that differs from the current one.\",\n \"auth.wrong-current-password\": \"The current password is not correct. Enter it again.\",\n \"auth.busy\": \"The server is busy checking other sign-ins. Wait a few seconds and try again.\",\n \"invite.invalid\":\n \"This invite link is not valid, was already used, or has expired. Ask an admin for a new one.\",\n \"invite.email-taken\": \"An account with this email already exists. Sign in instead.\",\n \"account.not-found\": \"This account no longer exists. Reload the list.\",\n \"account.last-admin\": \"This is the last admin. Make another account an admin first.\",\n \"account.self\": \"You cannot do this to your own account. Ask another admin.\",\n \"account.last-factor\":\n \"This is your only second factor. Add another one (an authenticator app or a passkey) before removing it.\",\n \"role.forbidden\": \"Only admins can do this. Ask an admin.\",\n \"csrf.invalid\": \"This page is out of date. Reload the dashboard and try again.\",\n \"passkey.unavailable\":\n \"Passkeys are not available on this server (the @simplewebauthn/server package is not installed). Use an authenticator app instead.\",\n \"passkey.failed\": \"The passkey could not be verified. Try again, or use your authenticator app.\",\n \"explain.not-allowed\": \"Only admins can run EXPLAIN. Ask an admin.\",\n \"explain.unsupported\":\n \"This query cannot be explained: only PostgreSQL SELECT/WITH queries and MongoDB find, aggregate and count commands can.\",\n \"explain.elsewhere\":\n \"Only the instance that ran this query can explain it, and this request reached another one. Try again later or from that instance.\",\n \"explain.failed\":\n \"The database could not explain this query. The reference is in the server log.\",\n \"request.not-found\":\n \"This request is no longer stored. Requests are kept for a limited time (24 hours by default).\",\n \"request.invalid-filter\": \"A filter value is not valid. Check the status, method and dates.\",\n \"share.not-found\": \"This share link no longer exists or is already revoked. Reload the list.\",\n \"stream.too-many\":\n \"Too many live views are open for this session. Close another dashboard tab and reload.\",\n \"input.invalid\": \"Some fields are missing or not valid. Check the form and try again.\",\n \"server.error\":\n \"The dashboard could not complete this action. Try again; if it keeps failing, give your admin the reference shown.\",\n};\n\n/** The HTTP status each code answers with. */\nexport const DEVTOOLS_ERROR_STATUS: Record<DevtoolsErrorCode, number> = {\n \"auth.invalid-credentials\": 401,\n \"auth.invalid-code\": 401,\n \"auth.invalid-setup-token\": 401,\n \"auth.password-too-short\": 422,\n \"auth.password-too-long\": 422,\n \"auth.password-common\": 422,\n \"auth.password-same-as-email\": 422,\n \"auth.password-unchanged\": 422,\n \"auth.wrong-current-password\": 401,\n \"auth.busy\": 503,\n \"invite.invalid\": 410,\n \"invite.email-taken\": 409,\n \"account.not-found\": 404,\n \"account.last-admin\": 409,\n \"account.self\": 409,\n \"account.last-factor\": 409,\n \"role.forbidden\": 403,\n \"csrf.invalid\": 403,\n \"passkey.unavailable\": 501,\n \"passkey.failed\": 401,\n \"explain.not-allowed\": 403,\n \"explain.unsupported\": 400,\n \"explain.elsewhere\": 409,\n \"explain.failed\": 502,\n \"request.not-found\": 404,\n \"request.invalid-filter\": 400,\n \"share.not-found\": 404,\n \"stream.too-many\": 429,\n \"input.invalid\": 422,\n \"server.error\": 500,\n};\n\n/** A short reference id (8 characters, base32 alphabet) to quote to support. */\nexport function createErrorRef(): string {\n const alphabet = \"ABCDEFGHJKMNPQRSTUVWXYZ23456789\";\n const bytes = randomBytes(8);\n let ref = \"\";\n\n for (const byte of bytes) ref += alphabet[byte % alphabet.length];\n\n return ref;\n}\n\n/**\n * An error a dashboard route answers with. The production error handler turns\n * it into `{ error, code, ref?, instance? }` with `statusCode`.\n */\nexport class DevtoolsApiError extends Error {\n public readonly code: DevtoolsErrorCode;\n public readonly statusCode: number;\n public readonly ref: string | undefined;\n public readonly instance: string | undefined;\n\n public constructor(\n code: DevtoolsErrorCode,\n options: { ref?: string; instance?: string; cause?: unknown; message?: string } = {},\n ) {\n super(\n options.message ?? DEVTOOLS_ERROR_MESSAGES[code],\n options.cause === undefined ? {} : { cause: options.cause },\n );\n this.name = \"DevtoolsApiError\";\n this.code = code;\n this.statusCode = DEVTOOLS_ERROR_STATUS[code];\n this.ref = options.ref;\n this.instance = options.instance;\n }\n\n /** The JSON body this error answers with. */\n public toBody(): DevtoolsApiErrorBody {\n return {\n error: this.message,\n code: this.code,\n ...(this.ref === undefined ? {} : { ref: this.ref }),\n ...(this.instance === undefined ? {} : { instance: this.instance }),\n };\n }\n}\n\n/**\n * Raised by a store when a unique value is taken (an email) so callers can\n * answer with their own error code.\n */\nexport class DevtoolsStoreConflictError extends Error {\n public constructor(public readonly field: string) {\n super(`A devtools record with this ${field} already exists.`);\n this.name = \"DevtoolsStoreConflictError\";\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAa,wBAAwB;CACnC,OACE;CACF,OACE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CAAC;CAC3B,IAAI,MAAM;CAEV,KAAK,MAAM,QAAQ,OAAO,OAAO,SAAS,OAAO;CAEjD,OAAO;AACT;;;;;AAMA,IAAa,mBAAb,cAAsC,MAAM;CAM1C,AAAO,YACL,MACA,UAAkF,CAAC,GACnF;EACA,MACE,QAAQ,WAAW,wBAAwB,OAC3C,QAAQ,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM,CAC5D;EACA,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,aAAa,sBAAsB;EACxC,KAAK,MAAM,QAAQ;EACnB,KAAK,WAAW,QAAQ;CAC1B;;CAGA,AAAO,SAA+B;EACpC,OAAO;GACL,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,GAAI,KAAK,QAAQ,SAAY,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI;GAClD,GAAI,KAAK,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,KAAK,SAAS;EACnE;CACF;AACF;;;;;AAMA,IAAa,6BAAb,cAAgD,MAAM;CACpD,AAAO,YAAY,AAAgB,OAAe;EAChD,MAAM,+BAA+B,MAAM,iBAAiB;EAD3B;EAEjC,KAAK,OAAO;CACd;AACF"}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/errors.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport type { DevtoolsApiErrorBody, DevtoolsErrorCode } from \"./contracts\";\n\n/**\n * Why production mode refused to start. Each code names one missing or\n * invalid setting; the message says which and how to fix it.\n */\nexport const DEVTOOLS_CONFIG_CODES = {\n DT001:\n \"Devtools production mode needs a dashboard path. Set DEVTOOLS_PATH (for example /ops-7f3k2q) or devtools.production.path.\",\n DT002:\n 'The devtools dashboard path must start with \"/\", be at least 8 characters, use only letters, digits, \"-\", \"_\", \".\", \"~\" and \"/\", and not be \"/__warlock\".',\n DT003:\n \"Devtools production mode has no admin yet. Set DEVTOOLS_ADMIN_EMAIL with DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin --email <email>`.\",\n DT004:\n \"DEVTOOLS_ADMIN_PASSWORD does not meet the password rules (the minimum length, at most 72 bytes, not a common password unless `passwords.rejectCommon` is false, not the email). Choose another one.\",\n DT005:\n \"Devtools production mode stores its accounts in the database. Install @warlock.js/cascade and configure a database connection.\",\n DT006:\n \"Devtools production mode encrypts two-factor secrets with the app key. Set encryption.key (64 hex characters) in src/config/encryption.ts.\",\n DT007:\n \"A devtools production option has an invalid value. The message names the option and the accepted values.\",\n DT008:\n \"The devtools tables are missing. Add devtoolsMigrations from @warlock.js/devtools/production to database.migrations in warlock.config.ts and run `warlock migrate`.\",\n DT009: \"Set either DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, not both.\",\n DT010:\n \"DEVTOOLS_SETUP_TOKEN must be at least 32 characters. Generate one with: openssl rand -base64 32\",\n} as const;\n\n/** A production configuration error code (`DT001`–`DT010`). */\nexport type DevtoolsConfigCode = keyof typeof DEVTOOLS_CONFIG_CODES;\n\n/**\n * Thrown while the devtools connector boots in production when the monitor is\n * enabled but cannot start safely. It stops the app from booting, so a\n * misconfigured deploy fails at once instead of serving an unprotected\n * dashboard.\n */\nexport class DevtoolsProductionConfigError extends Error {\n public readonly code: DevtoolsConfigCode;\n\n public constructor(code: DevtoolsConfigCode, detail?: string) {\n super(`[${code}] ${detail ? `${detail} ` : \"\"}${DEVTOOLS_CONFIG_CODES[code]}`);\n this.name = \"DevtoolsProductionConfigError\";\n this.code = code;\n }\n}\n\n/** The message every API error code answers with: what failed and what to do next. */\nexport const DEVTOOLS_ERROR_MESSAGES: Record<DevtoolsErrorCode, string> = {\n \"auth.invalid-credentials\":\n \"The email or password is not correct. Check both and try again; after several failed tries, wait 15 minutes.\",\n \"auth.invalid-code\":\n \"The code is not correct or has expired. Enter the current 6-digit code from your authenticator app, or a recovery code.\",\n \"auth.invalid-setup-token\":\n \"This setup link is not valid. Use the link built from DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin`.\",\n \"auth.password-too-short\":\n \"Use a longer password. The minimum length is set by passwords.minLength (8 characters by default).\",\n \"auth.password-too-long\": \"Use a password of at most 72 bytes (about 72 letters).\",\n \"auth.password-common\": \"This password is too common. Choose one that is harder to guess.\",\n \"auth.password-same-as-email\": \"The password must not be your email address. Choose another one.\",\n \"auth.password-unchanged\": \"Choose a new password that differs from the current one.\",\n \"auth.wrong-current-password\": \"The current password is not correct. Enter it again.\",\n \"auth.busy\": \"The server is busy checking other sign-ins. Wait a few seconds and try again.\",\n \"invite.invalid\":\n \"This invite link is not valid, was already used, or has expired. Ask an admin for a new one.\",\n \"invite.email-taken\": \"An account with this email already exists. Sign in instead.\",\n \"account.not-found\": \"This account no longer exists. Reload the list.\",\n \"account.last-admin\": \"This is the last admin. Make another account an admin first.\",\n \"account.self\": \"You cannot do this to your own account. Ask another admin.\",\n \"account.last-factor\":\n \"This is your only second factor. Add another one (an authenticator app or a passkey) before removing it.\",\n \"role.forbidden\": \"Only admins can do this. Ask an admin.\",\n \"csrf.invalid\": \"This page is out of date. Reload the dashboard and try again.\",\n \"passkey.unavailable\":\n \"Passkeys are not available on this server (the @simplewebauthn/server package is not installed). Use an authenticator app instead.\",\n \"passkey.failed\": \"The passkey could not be verified. Try again, or use your authenticator app.\",\n \"explain.not-allowed\": \"Only admins can run EXPLAIN. Ask an admin.\",\n \"explain.unsupported\":\n \"This query cannot be explained: only PostgreSQL SELECT/WITH queries and MongoDB find, aggregate and count commands can.\",\n \"explain.elsewhere\":\n \"Only the instance that ran this query can explain it, and this request reached another one. Try again later or from that instance.\",\n \"explain.failed\":\n \"The database could not explain this query. The reference is in the server log.\",\n \"request.not-found\":\n \"This request is no longer stored. Requests are kept for a limited time (24 hours by default).\",\n \"request.invalid-filter\": \"A filter value is not valid. Check the status, method and dates.\",\n \"share.not-found\": \"This share link no longer exists or is already revoked. Reload the list.\",\n \"stream.too-many\":\n \"Too many live views are open for this session. Close another dashboard tab and reload.\",\n \"ai.range-invalid\":\n \"The date range is not valid. Pick 24 hours, 7 days or 30 days, or a custom range of at least one hour inside the kept history.\",\n \"ai.evaluate-unavailable\":\n \"Evaluate is not set up. Add panoptic.evaluate with a judge model to src/config/ai.ts, then restart.\",\n \"ai.prompt-not-found\":\n \"This run's system prompt is no longer kept. Pick a newer run or paste the prompt.\",\n \"ai.evaluate-failed\":\n \"The judge model could not grade this prompt. Check its API key and quota; the reference is in the server log.\",\n \"input.invalid\": \"Some fields are missing or not valid. Check the form and try again.\",\n \"server.error\":\n \"The dashboard could not complete this action. Try again; if it keeps failing, give your admin the reference shown.\",\n};\n\n/** The HTTP status each code answers with. */\nexport const DEVTOOLS_ERROR_STATUS: Record<DevtoolsErrorCode, number> = {\n \"auth.invalid-credentials\": 401,\n \"auth.invalid-code\": 401,\n \"auth.invalid-setup-token\": 401,\n \"auth.password-too-short\": 422,\n \"auth.password-too-long\": 422,\n \"auth.password-common\": 422,\n \"auth.password-same-as-email\": 422,\n \"auth.password-unchanged\": 422,\n \"auth.wrong-current-password\": 401,\n \"auth.busy\": 503,\n \"invite.invalid\": 410,\n \"invite.email-taken\": 409,\n \"account.not-found\": 404,\n \"account.last-admin\": 409,\n \"account.self\": 409,\n \"account.last-factor\": 409,\n \"role.forbidden\": 403,\n \"csrf.invalid\": 403,\n \"passkey.unavailable\": 501,\n \"passkey.failed\": 401,\n \"explain.not-allowed\": 403,\n \"explain.unsupported\": 400,\n \"explain.elsewhere\": 409,\n \"explain.failed\": 502,\n \"request.not-found\": 404,\n \"request.invalid-filter\": 400,\n \"share.not-found\": 404,\n \"stream.too-many\": 429,\n \"ai.range-invalid\": 400,\n \"ai.evaluate-unavailable\": 409,\n \"ai.prompt-not-found\": 404,\n \"ai.evaluate-failed\": 502,\n \"input.invalid\": 422,\n \"server.error\": 500,\n};\n\n/** A short reference id (8 characters, base32 alphabet) to quote to support. */\nexport function createErrorRef(): string {\n const alphabet = \"ABCDEFGHJKMNPQRSTUVWXYZ23456789\";\n const bytes = randomBytes(8);\n let ref = \"\";\n\n for (const byte of bytes) ref += alphabet[byte % alphabet.length];\n\n return ref;\n}\n\n/**\n * An error a dashboard route answers with. The production error handler turns\n * it into `{ error, code, ref?, instance? }` with `statusCode`.\n */\nexport class DevtoolsApiError extends Error {\n public readonly code: DevtoolsErrorCode;\n public readonly statusCode: number;\n public readonly ref: string | undefined;\n public readonly instance: string | undefined;\n\n public constructor(\n code: DevtoolsErrorCode,\n options: { ref?: string; instance?: string; cause?: unknown; message?: string } = {},\n ) {\n super(\n options.message ?? DEVTOOLS_ERROR_MESSAGES[code],\n options.cause === undefined ? {} : { cause: options.cause },\n );\n this.name = \"DevtoolsApiError\";\n this.code = code;\n this.statusCode = DEVTOOLS_ERROR_STATUS[code];\n this.ref = options.ref;\n this.instance = options.instance;\n }\n\n /** The JSON body this error answers with. */\n public toBody(): DevtoolsApiErrorBody {\n return {\n error: this.message,\n code: this.code,\n ...(this.ref === undefined ? {} : { ref: this.ref }),\n ...(this.instance === undefined ? {} : { instance: this.instance }),\n };\n }\n}\n\n/**\n * Raised by a store when a unique value is taken (an email) so callers can\n * answer with their own error code.\n */\nexport class DevtoolsStoreConflictError extends Error {\n public constructor(public readonly field: string) {\n super(`A devtools record with this ${field} already exists.`);\n this.name = \"DevtoolsStoreConflictError\";\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAa,wBAAwB;CACnC,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OAAO;CACP,OACE;AACJ;;;;;;;AAWA,IAAa,gCAAb,cAAmD,MAAM;CAGvD,AAAO,YAAY,MAA0B,QAAiB;EAC5D,MAAM,IAAI,KAAK,IAAI,SAAS,GAAG,OAAO,KAAK,KAAK,sBAAsB,OAAO;EAC7E,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;AAGA,MAAa,0BAA6D;CACxE,4BACE;CACF,qBACE;CAC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AY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM,CAC5D;EACA,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,aAAa,sBAAsB;EACxC,KAAK,MAAM,QAAQ;EACnB,KAAK,WAAW,QAAQ;CAC1B;;CAGA,AAAO,SAA+B;EACpC,OAAO;GACL,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,GAAI,KAAK,QAAQ,SAAY,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI;GAClD,GAAI,KAAK,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,KAAK,SAAS;EACnE;CACF;AACF;;;;;AAMA,IAAa,6BAAb,cAAgD,MAAM;CACpD,AAAO,YAAY,AAAgB,OAAe;EAChD,MAAM,+BAA+B,MAAM,iBAAiB;EAD3B;EAEjC,KAAK,OAAO;CACd;AACF"}
@@ -87,6 +87,12 @@ function productionRouteAccess(panelIds, options = {}) {
87
87
  rule("GET", "/api/ai/agent-runs", VIEWER),
88
88
  rule("GET", "/api/ai/agent-runs/:id", VIEWER),
89
89
  rule("GET", "/api/ai/runs/:id", VIEWER),
90
+ rule("GET", "/api/ai/runs", VIEWER),
91
+ rule("GET", "/api/ai/reports", VIEWER),
92
+ rule("GET", "/api/ai/models", VIEWER),
93
+ rule("GET", "/api/ai/errors", VIEWER),
94
+ rule("GET", "/api/ai/evaluate", VIEWER),
95
+ rule("POST", "/api/ai/evaluate", ADMIN),
90
96
  rule("GET", "/api/openapi.json", VIEWER),
91
97
  rule("GET", "/api/postman.json", VIEWER),
92
98
  rule("GET", "/docs", VIEWER),
@@ -1 +1 @@
1
- {"version":3,"file":"access.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/access.ts"],"sourcesContent":["import type { DevtoolsRouteAccess, DevtoolsRouteAccessRule } from \"./types\";\n\ntype Method = DevtoolsRouteAccessRule[\"method\"];\n\nconst PUBLIC: DevtoolsRouteAccess = { type: \"public\" };\nconst VIEWER: DevtoolsRouteAccess = { type: \"viewer\" };\nconst ADMIN: DevtoolsRouteAccess = { type: \"admin\" };\nconst SHARE: DevtoolsRouteAccess = { type: \"share\" };\n\nconst pending = (...stages: Extract<DevtoolsRouteAccess, { type: \"pending\" }>[\"stages\"]) =>\n ({ type: \"pending\", stages }) satisfies DevtoolsRouteAccess;\n\nconst ALL_STEPS = [\"password-change\", \"mfa-enrol\", \"mfa-verify\"] as const;\n\n/**\n * The access table: every production route, its method and who may call it.\n * A route with no entry is `admin` (fail closed). A package panel `<id>`\n * gets `GET /api/<id>` and `GET /api/<id>/*` for viewers and every other\n * method there for admins, audited as `panel.action`; a url ending in `/*`\n * matches every pattern below it. The share routes exist only when\n * `options.share` is `true` (`production.share.enabled`).\n */\nexport function productionRouteAccess(\n panelIds: readonly string[],\n options: { share?: boolean } = {},\n): DevtoolsRouteAccessRule[] {\n const rule = (\n method: Method,\n url: string,\n access: DevtoolsRouteAccess,\n audit?: DevtoolsRouteAccessRule[\"audit\"],\n ): DevtoolsRouteAccessRule => ({ method, url, access, ...(audit ? { audit } : {}) });\n\n const rules: DevtoolsRouteAccessRule[] = [\n // The shell and its sign-in steps.\n rule(\"GET\", \"/\", PUBLIC),\n rule(\"GET\", \"/assets/:name\", PUBLIC),\n rule(\"GET\", \"/api/auth/session\", PUBLIC),\n rule(\"POST\", \"/api/auth/login\", PUBLIC),\n rule(\"POST\", \"/api/auth/setup\", PUBLIC),\n rule(\"POST\", \"/api/auth/invite/inspect\", PUBLIC),\n rule(\"POST\", \"/api/auth/invite/accept\", PUBLIC),\n rule(\"POST\", \"/api/auth/password\", pending(\"password-change\")),\n rule(\"POST\", \"/api/auth/totp/start\", pending(\"mfa-enrol\")),\n rule(\"POST\", \"/api/auth/totp/confirm\", pending(\"mfa-enrol\")),\n rule(\"POST\", \"/api/auth/passkey/options\", pending(\"mfa-enrol\", \"mfa-verify\")),\n rule(\"POST\", \"/api/auth/passkey/verify\", pending(\"mfa-enrol\", \"mfa-verify\")),\n rule(\"POST\", \"/api/auth/mfa\", pending(\"mfa-verify\")),\n rule(\"POST\", \"/api/auth/logout\", pending(...ALL_STEPS)),\n\n // The signed-in account.\n rule(\"GET\", \"/api/panels\", VIEWER),\n rule(\"GET\", \"/api/account\", VIEWER),\n rule(\"GET\", \"/api/account/sessions\", VIEWER),\n rule(\"DELETE\", \"/api/account/sessions/:id\", VIEWER),\n rule(\"POST\", \"/api/account/password\", VIEWER),\n rule(\"POST\", \"/api/account/totp/start\", VIEWER),\n rule(\"POST\", \"/api/account/totp/confirm\", VIEWER),\n rule(\"DELETE\", \"/api/account/totp\", VIEWER),\n rule(\"POST\", \"/api/account/recovery-codes\", VIEWER),\n rule(\"POST\", \"/api/account/passkey/options\", VIEWER),\n rule(\"POST\", \"/api/account/passkey/verify\", VIEWER),\n rule(\"DELETE\", \"/api/account/passkeys/:id\", VIEWER),\n\n // Administration.\n rule(\"GET\", \"/api/admin/users\", ADMIN),\n rule(\"POST\", \"/api/admin/invites\", ADMIN),\n rule(\"DELETE\", \"/api/admin/invites/:id\", ADMIN),\n rule(\"PATCH\", \"/api/admin/users/:id\", ADMIN),\n rule(\"DELETE\", \"/api/admin/users/:id\", ADMIN),\n rule(\"POST\", \"/api/admin/users/:id/reset-mfa\", ADMIN),\n rule(\"POST\", \"/api/admin/users/:id/sign-out\", ADMIN),\n rule(\"GET\", \"/api/admin/audit\", ADMIN),\n rule(\"POST\", \"/api/admin/disable\", ADMIN),\n\n // Data.\n rule(\"GET\", \"/api/stream\", VIEWER),\n rule(\"GET\", \"/api/instances\", VIEWER),\n rule(\"GET\", \"/api/resources\", VIEWER),\n rule(\"GET\", \"/api/queries/stats\", VIEWER),\n rule(\"GET\", \"/api/routes/stats\", VIEWER),\n rule(\"GET\", \"/api/health\", VIEWER),\n rule(\"GET\", \"/api/errors\", VIEWER),\n rule(\"GET\", \"/api/jobs\", VIEWER),\n rule(\"GET\", \"/api/logs\", VIEWER),\n rule(\"GET\", \"/api/requests\", VIEWER),\n rule(\"GET\", \"/api/requests/:id\", VIEWER),\n rule(\"GET\", \"/api/requests/:id/curl\", VIEWER),\n rule(\"DELETE\", \"/api/requests\", ADMIN, \"requests.cleared\"),\n rule(\"POST\", \"/api/queries/:shapeId/explain\", ADMIN, \"explain.run\"),\n rule(\"GET\", \"/api/routes\", VIEWER),\n rule(\"GET\", \"/panels/:id/:name\", VIEWER),\n rule(\"GET\", \"/panels/:id/files/*\", VIEWER),\n\n // Tabs that are off unless the project turns them on.\n rule(\"GET\", \"/api/mails\", VIEWER),\n rule(\"GET\", \"/api/mails/:id\", VIEWER),\n rule(\"GET\", \"/api/mails/:id/html\", VIEWER),\n rule(\"GET\", \"/api/ai\", VIEWER),\n rule(\"GET\", \"/api/ai/agent-runs\", VIEWER),\n rule(\"GET\", \"/api/ai/agent-runs/:id\", VIEWER),\n rule(\"GET\", \"/api/ai/runs/:id\", VIEWER),\n rule(\"GET\", \"/api/openapi.json\", VIEWER),\n rule(\"GET\", \"/api/postman.json\", VIEWER),\n rule(\"GET\", \"/docs\", VIEWER),\n rule(\"GET\", \"/docs/swagger\", VIEWER),\n ];\n\n if (options.share === true) {\n rules.push(\n // The grant exchange: public, answered only for a valid token.\n rule(\"POST\", \"/api/share/open\", PUBLIC),\n // What a share grant may reach.\n rule(\"GET\", \"/api/share/info\", SHARE),\n rule(\"GET\", \"/api/share/view.js\", SHARE),\n rule(\"GET\", \"/api/share/assets/:name\", SHARE),\n rule(\"GET\", \"/api/share/files/*\", SHARE),\n rule(\"GET\", \"/api/share/panel\", SHARE),\n rule(\"GET\", \"/api/share/panel/*\", SHARE),\n // Managing the links.\n rule(\"GET\", \"/api/admin/shares\", ADMIN),\n rule(\"POST\", \"/api/admin/shares\", ADMIN),\n rule(\"DELETE\", \"/api/admin/shares/:id\", ADMIN),\n rule(\"POST\", \"/api/admin/shares/revoke-all\", ADMIN),\n );\n }\n\n for (const id of panelIds) {\n rules.push(rule(\"GET\", `/api/${id}`, VIEWER), rule(\"GET\", `/api/${id}/*`, VIEWER));\n\n for (const method of [\"POST\", \"PUT\", \"PATCH\", \"DELETE\"] as const) {\n rules.push(\n rule(method, `/api/${id}`, ADMIN, \"panel.action\"),\n rule(method, `/api/${id}/*`, ADMIN, \"panel.action\"),\n );\n }\n }\n\n return rules;\n}\n\n/** Looks routes up by method and URL pattern: exact first, then the longest `/*` prefix. */\nexport function createAccessLookup(\n rules: readonly DevtoolsRouteAccessRule[],\n): (method: string, pattern: string) => DevtoolsRouteAccessRule | undefined {\n const exact = new Map<string, DevtoolsRouteAccessRule>();\n const wildcards: { method: Method; prefix: string; rule: DevtoolsRouteAccessRule }[] = [];\n\n for (const rule of rules) {\n if (rule.url.endsWith(\"/*\")) {\n wildcards.push({ method: rule.method, prefix: rule.url.slice(0, -1), rule });\n } else {\n exact.set(`${rule.method} ${rule.url}`, rule);\n }\n }\n\n wildcards.sort((a, b) => b.prefix.length - a.prefix.length);\n\n return (method, pattern) => {\n // A HEAD request is answered by the GET route.\n const verb = method === \"HEAD\" ? \"GET\" : method;\n const found = exact.get(`${verb} ${pattern}`);\n\n if (found) return found;\n\n return wildcards.find((item) => item.method === verb && pattern.startsWith(item.prefix))?.rule;\n };\n}\n"],"mappings":";AAIA,MAAM,SAA8B,EAAE,MAAM,SAAS;AACrD,MAAM,SAA8B,EAAE,MAAM,SAAS;AACrD,MAAM,QAA6B,EAAE,MAAM,QAAQ;AACnD,MAAM,QAA6B,EAAE,MAAM,QAAQ;AAEnD,MAAM,WAAW,GAAG,YACjB;CAAE,MAAM;CAAW;AAAO;AAE7B,MAAM,YAAY;CAAC;CAAmB;CAAa;AAAY;;;;;;;;;AAU/D,SAAgB,sBACd,UACA,UAA+B,CAAC,GACL;CAC3B,MAAM,QACJ,QACA,KACA,QACA,WAC6B;EAAE;EAAQ;EAAK;EAAQ,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;CAAG;CAElF,MAAM,QAAmC;EAEvC,KAAK,OAAO,KAAK,MAAM;EACvB,KAAK,OAAO,iBAAiB,MAAM;EACnC,KAAK,O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AAK,GACvC,KAAK,UAAU,yBAAyB,KAAK,GAC7C,KAAK,QAAQ,gCAAgC,KAAK,CACpD;CAGF,KAAK,MAAM,MAAM,UAAU;EACzB,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,MAAM,GAAG,KAAK,OAAO,QAAQ,GAAG,KAAK,MAAM,CAAC;EAEjF,KAAK,MAAM,UAAU;GAAC;GAAQ;GAAO;GAAS;EAAQ,GACpD,MAAM,KACJ,KAAK,QAAQ,QAAQ,MAAM,OAAO,cAAc,GAChD,KAAK,QAAQ,QAAQ,GAAG,KAAK,OAAO,cAAc,CACpD;CAEJ;CAEA,OAAO;AACT;;AAGA,SAAgB,mBACd,OAC0E;CAC1E,MAAM,wBAAQ,IAAI,IAAqC;CACvD,MAAM,YAAiF,CAAC;CAExF,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,IAAI,SAAS,IAAI,GACxB,UAAU,KAAK;EAAE,QAAQ,KAAK;EAAQ,QAAQ,KAAK,IAAI,MAAM,GAAG,EAAE;EAAG;CAAK,CAAC;MAE3E,MAAM,IAAI,GAAG,KAAK,OAAO,GAAG,KAAK,OAAO,IAAI;CAIhD,UAAU,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,EAAE,OAAO,MAAM;CAE1D,QAAQ,QAAQ,YAAY;EAE1B,MAAM,OAAO,WAAW,SAAS,QAAQ;EACzC,MAAM,QAAQ,MAAM,IAAI,GAAG,KAAK,GAAG,SAAS;EAE5C,IAAI,OAAO,OAAO;EAElB,OAAO,UAAU,MAAM,SAAS,KAAK,WAAW,QAAQ,QAAQ,WAAW,KAAK,MAAM,CAAC,CAAC,EAAE;CAC5F;AACF"}
1
+ {"version":3,"file":"access.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/access.ts"],"sourcesContent":["import type { DevtoolsRouteAccess, DevtoolsRouteAccessRule } from \"./types\";\n\ntype Method = DevtoolsRouteAccessRule[\"method\"];\n\nconst PUBLIC: DevtoolsRouteAccess = { type: \"public\" };\nconst VIEWER: DevtoolsRouteAccess = { type: \"viewer\" };\nconst ADMIN: DevtoolsRouteAccess = { type: \"admin\" };\nconst SHARE: DevtoolsRouteAccess = { type: \"share\" };\n\nconst pending = (...stages: Extract<DevtoolsRouteAccess, { type: \"pending\" }>[\"stages\"]) =>\n ({ type: \"pending\", stages }) satisfies DevtoolsRouteAccess;\n\nconst ALL_STEPS = [\"password-change\", \"mfa-enrol\", \"mfa-verify\"] as const;\n\n/**\n * The access table: every production route, its method and who may call it.\n * A route with no entry is `admin` (fail closed). A package panel `<id>`\n * gets `GET /api/<id>` and `GET /api/<id>/*` for viewers and every other\n * method there for admins, audited as `panel.action`; a url ending in `/*`\n * matches every pattern below it. The share routes exist only when\n * `options.share` is `true` (`production.share.enabled`).\n */\nexport function productionRouteAccess(\n panelIds: readonly string[],\n options: { share?: boolean } = {},\n): DevtoolsRouteAccessRule[] {\n const rule = (\n method: Method,\n url: string,\n access: DevtoolsRouteAccess,\n audit?: DevtoolsRouteAccessRule[\"audit\"],\n ): DevtoolsRouteAccessRule => ({ method, url, access, ...(audit ? { audit } : {}) });\n\n const rules: DevtoolsRouteAccessRule[] = [\n // The shell and its sign-in steps.\n rule(\"GET\", \"/\", PUBLIC),\n rule(\"GET\", \"/assets/:name\", PUBLIC),\n rule(\"GET\", \"/api/auth/session\", PUBLIC),\n rule(\"POST\", \"/api/auth/login\", PUBLIC),\n rule(\"POST\", \"/api/auth/setup\", PUBLIC),\n rule(\"POST\", \"/api/auth/invite/inspect\", PUBLIC),\n rule(\"POST\", \"/api/auth/invite/accept\", PUBLIC),\n rule(\"POST\", \"/api/auth/password\", pending(\"password-change\")),\n rule(\"POST\", \"/api/auth/totp/start\", pending(\"mfa-enrol\")),\n rule(\"POST\", \"/api/auth/totp/confirm\", pending(\"mfa-enrol\")),\n rule(\"POST\", \"/api/auth/passkey/options\", pending(\"mfa-enrol\", \"mfa-verify\")),\n rule(\"POST\", \"/api/auth/passkey/verify\", pending(\"mfa-enrol\", \"mfa-verify\")),\n rule(\"POST\", \"/api/auth/mfa\", pending(\"mfa-verify\")),\n rule(\"POST\", \"/api/auth/logout\", pending(...ALL_STEPS)),\n\n // The signed-in account.\n rule(\"GET\", \"/api/panels\", VIEWER),\n rule(\"GET\", \"/api/account\", VIEWER),\n rule(\"GET\", \"/api/account/sessions\", VIEWER),\n rule(\"DELETE\", \"/api/account/sessions/:id\", VIEWER),\n rule(\"POST\", \"/api/account/password\", VIEWER),\n rule(\"POST\", \"/api/account/totp/start\", VIEWER),\n rule(\"POST\", \"/api/account/totp/confirm\", VIEWER),\n rule(\"DELETE\", \"/api/account/totp\", VIEWER),\n rule(\"POST\", \"/api/account/recovery-codes\", VIEWER),\n rule(\"POST\", \"/api/account/passkey/options\", VIEWER),\n rule(\"POST\", \"/api/account/passkey/verify\", VIEWER),\n rule(\"DELETE\", \"/api/account/passkeys/:id\", VIEWER),\n\n // Administration.\n rule(\"GET\", \"/api/admin/users\", ADMIN),\n rule(\"POST\", \"/api/admin/invites\", ADMIN),\n rule(\"DELETE\", \"/api/admin/invites/:id\", ADMIN),\n rule(\"PATCH\", \"/api/admin/users/:id\", ADMIN),\n rule(\"DELETE\", \"/api/admin/users/:id\", ADMIN),\n rule(\"POST\", \"/api/admin/users/:id/reset-mfa\", ADMIN),\n rule(\"POST\", \"/api/admin/users/:id/sign-out\", ADMIN),\n rule(\"GET\", \"/api/admin/audit\", ADMIN),\n rule(\"POST\", \"/api/admin/disable\", ADMIN),\n\n // Data.\n rule(\"GET\", \"/api/stream\", VIEWER),\n rule(\"GET\", \"/api/instances\", VIEWER),\n rule(\"GET\", \"/api/resources\", VIEWER),\n rule(\"GET\", \"/api/queries/stats\", VIEWER),\n rule(\"GET\", \"/api/routes/stats\", VIEWER),\n rule(\"GET\", \"/api/health\", VIEWER),\n rule(\"GET\", \"/api/errors\", VIEWER),\n rule(\"GET\", \"/api/jobs\", VIEWER),\n rule(\"GET\", \"/api/logs\", VIEWER),\n rule(\"GET\", \"/api/requests\", VIEWER),\n rule(\"GET\", \"/api/requests/:id\", VIEWER),\n rule(\"GET\", \"/api/requests/:id/curl\", VIEWER),\n rule(\"DELETE\", \"/api/requests\", ADMIN, \"requests.cleared\"),\n rule(\"POST\", \"/api/queries/:shapeId/explain\", ADMIN, \"explain.run\"),\n rule(\"GET\", \"/api/routes\", VIEWER),\n rule(\"GET\", \"/panels/:id/:name\", VIEWER),\n rule(\"GET\", \"/panels/:id/files/*\", VIEWER),\n\n // Tabs that are off unless the project turns them on.\n rule(\"GET\", \"/api/mails\", VIEWER),\n rule(\"GET\", \"/api/mails/:id\", VIEWER),\n rule(\"GET\", \"/api/mails/:id/html\", VIEWER),\n rule(\"GET\", \"/api/ai\", VIEWER),\n rule(\"GET\", \"/api/ai/agent-runs\", VIEWER),\n rule(\"GET\", \"/api/ai/agent-runs/:id\", VIEWER),\n rule(\"GET\", \"/api/ai/runs/:id\", VIEWER),\n rule(\"GET\", \"/api/ai/runs\", VIEWER),\n rule(\"GET\", \"/api/ai/reports\", VIEWER),\n rule(\"GET\", \"/api/ai/models\", VIEWER),\n rule(\"GET\", \"/api/ai/errors\", VIEWER),\n rule(\"GET\", \"/api/ai/evaluate\", VIEWER),\n rule(\"POST\", \"/api/ai/evaluate\", ADMIN),\n rule(\"GET\", \"/api/openapi.json\", VIEWER),\n rule(\"GET\", \"/api/postman.json\", VIEWER),\n rule(\"GET\", \"/docs\", VIEWER),\n rule(\"GET\", \"/docs/swagger\", VIEWER),\n ];\n\n if (options.share === true) {\n rules.push(\n // The grant exchange: public, answered only for a valid token.\n rule(\"POST\", \"/api/share/open\", PUBLIC),\n // What a share grant may reach.\n rule(\"GET\", \"/api/share/info\", SHARE),\n rule(\"GET\", \"/api/share/view.js\", SHARE),\n rule(\"GET\", \"/api/share/assets/:name\", SHARE),\n rule(\"GET\", \"/api/share/files/*\", SHARE),\n rule(\"GET\", \"/api/share/panel\", SHARE),\n rule(\"GET\", \"/api/share/panel/*\", SHARE),\n // Managing the links.\n rule(\"GET\", \"/api/admin/shares\", ADMIN),\n rule(\"POST\", \"/api/admin/shares\", ADMIN),\n rule(\"DELETE\", \"/api/admin/shares/:id\", ADMIN),\n rule(\"POST\", \"/api/admin/shares/revoke-all\", ADMIN),\n );\n }\n\n for (const id of panelIds) {\n rules.push(rule(\"GET\", `/api/${id}`, VIEWER), rule(\"GET\", `/api/${id}/*`, VIEWER));\n\n for (const method of [\"POST\", \"PUT\", \"PATCH\", \"DELETE\"] as const) {\n rules.push(\n rule(method, `/api/${id}`, ADMIN, \"panel.action\"),\n rule(method, `/api/${id}/*`, ADMIN, \"panel.action\"),\n );\n }\n }\n\n return rules;\n}\n\n/** Looks routes up by method and URL pattern: exact first, then the longest `/*` prefix. */\nexport function createAccessLookup(\n rules: readonly DevtoolsRouteAccessRule[],\n): (method: string, pattern: string) => DevtoolsRouteAccessRule | undefined {\n const exact = new Map<string, DevtoolsRouteAccessRule>();\n const wildcards: { method: Method; prefix: string; rule: DevtoolsRouteAccessRule }[] = [];\n\n for (const rule of rules) {\n if (rule.url.endsWith(\"/*\")) {\n wildcards.push({ method: rule.method, prefix: rule.url.slice(0, -1), rule });\n } else {\n exact.set(`${rule.method} ${rule.url}`, rule);\n }\n }\n\n wildcards.sort((a, b) => b.prefix.length - a.prefix.length);\n\n return (method, pattern) => {\n // A HEAD request is answered by the GET route.\n const verb = method === \"HEAD\" ? \"GET\" : method;\n const found = exact.get(`${verb} ${pattern}`);\n\n if (found) return found;\n\n return wildcards.find((item) => item.method === verb && pattern.startsWith(item.prefix))?.rule;\n };\n}\n"],"mappings":";AAIA,MAAM,SAA8B,EAAE,MAAM,SAAS;AACrD,MAAM,SAA8B,EAAE,MAAM,SAAS;AACrD,MAAM,QAA6B,EAAE,MAAM,QAAQ;AACnD,MAAM,QAA6B,EAAE,MAAM,QAAQ;AAEnD,MAAM,WAAW,GAAG,YACjB;CAAE,MAAM;CAAW;AAAO;AAE7B,MAAM,YAAY;CAAC;CAAmB;CAAa;AAAY;;;;;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AE1D,QAAQ,QAAQ,YAAY;EAE1B,MAAM,OAAO,WAAW,SAAS,QAAQ;EACzC,MAAM,QAAQ,MAAM,IAAI,GAAG,KAAK,GAAG,SAAS;EAE5C,IAAI,OAAO,OAAO;EAElB,OAAO,UAAU,MAAM,SAAS,KAAK,WAAW,QAAQ,QAAQ,WAAW,KAAK,MAAM,CAAC,CAAC,EAAE;CAC5F;AACF"}
@@ -6,6 +6,7 @@ import { resolveClient } from "./client.mjs";
6
6
  import { DEVTOOLS_CSRF_HEADER } from "./constants.mjs";
7
7
  import { devtoolsRequestContext, setDevtoolsRequestContext } from "./context.mjs";
8
8
  import { readCookie, sessionCookieName } from "./cookie.mjs";
9
+ import { registerAiReportRoutes } from "../../server/ai-report-routes.mjs";
9
10
  import { registerAiRoutes } from "../../server/ai-routes.mjs";
10
11
  import { registerShapeExplainRoute } from "../../server/explain-route.mjs";
11
12
  import { registerInsightsRoutes } from "../../server/insights-routes.mjs";
@@ -52,11 +53,22 @@ const TAB_OF_ROUTE = [
52
53
  ["/api/requests", "requests"],
53
54
  ["/api/mails", "mail"],
54
55
  ["/api/ai/agent-runs", "agents"],
56
+ ["/api/ai/reports", "ai-reports"],
57
+ ["/api/ai/models", "ai-models"],
58
+ ["/api/ai/errors", "ai-errors"],
59
+ ["/api/ai/evaluate", "ai-evaluate"],
55
60
  ["/api/ai", "ai"],
56
61
  ["/api/openapi.json", "api"],
57
62
  ["/api/postman.json", "api"],
58
63
  ["/docs", "api"]
59
64
  ];
65
+ /** The tabs the AI report routes serve; the routes register when any of them is on. */
66
+ const AI_REPORT_TABS = [
67
+ "ai-reports",
68
+ "ai-models",
69
+ "ai-errors",
70
+ "ai-evaluate"
71
+ ];
60
72
  function tabOf(pattern) {
61
73
  return TAB_OF_ROUTE.find(([prefix]) => pattern === prefix || pattern.startsWith(`${prefix}/`))?.[1];
62
74
  }
@@ -312,6 +324,7 @@ function mountProductionDevtools(server, deps) {
312
324
  share?.register(instance, notFound);
313
325
  if (enabledTabs.has("mail")) registerMailRoutes(instance, routes);
314
326
  if (enabledTabs.has("ai") || enabledTabs.has("agents")) registerAiRoutes(instance, routes);
327
+ if (AI_REPORT_TABS.some((tab) => enabledTabs.has(tab))) registerAiReportRoutes(instance, routes);
315
328
  if (enabledTabs.has("api")) registerOpenApiRoutes(instance, routes);
316
329
  registerStreamRoute(instance, routes);
317
330
  }, { prefix });