@warlock.js/devtools 5.54.0 → 5.56.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 (239) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +26 -13
  3. package/cjs/{ai-source-CSPh1HqJ.cjs → ai-source-DTpxumMA.cjs} +54 -3
  4. package/cjs/{ai-source-CSPh1HqJ.cjs.map → ai-source-DTpxumMA.cjs.map} +1 -1
  5. package/cjs/auth-DzU0gHDG.cjs +1655 -0
  6. package/cjs/auth-DzU0gHDG.cjs.map +1 -0
  7. package/cjs/boot-BQi0Etor.cjs +138 -0
  8. package/cjs/boot-BQi0Etor.cjs.map +1 -0
  9. package/cjs/capture-CqIiaznN.cjs +1342 -0
  10. package/cjs/capture-CqIiaznN.cjs.map +1 -0
  11. package/cjs/cascade-store-pHjKeSFm.cjs +863 -0
  12. package/cjs/cascade-store-pHjKeSFm.cjs.map +1 -0
  13. package/cjs/collector-CJbQbzzK.cjs +271 -0
  14. package/cjs/collector-CJbQbzzK.cjs.map +1 -0
  15. package/cjs/contracts-CVmplkNb.cjs +112 -0
  16. package/cjs/contracts-CVmplkNb.cjs.map +1 -0
  17. package/cjs/current-request-id-BoJJb3y7.cjs +37 -0
  18. package/cjs/current-request-id-BoJJb3y7.cjs.map +1 -0
  19. package/cjs/errors-CyZp5yS-.cjs +177 -0
  20. package/cjs/errors-CyZp5yS-.cjs.map +1 -0
  21. package/cjs/histogram-BaI-PnCv.cjs +102 -0
  22. package/cjs/histogram-BaI-PnCv.cjs.map +1 -0
  23. package/cjs/http-CabcUwBx.cjs +870 -0
  24. package/cjs/http-CabcUwBx.cjs.map +1 -0
  25. package/cjs/index.cjs +1 -1
  26. package/cjs/insights-BKtqxdnP.cjs +811 -0
  27. package/cjs/insights-BKtqxdnP.cjs.map +1 -0
  28. package/cjs/ip-DbNhPOzi.cjs +153 -0
  29. package/cjs/ip-DbNhPOzi.cjs.map +1 -0
  30. package/cjs/migrations-w7GMsrQw.cjs +297 -0
  31. package/cjs/migrations-w7GMsrQw.cjs.map +1 -0
  32. package/cjs/openapi-CC7OAUc6.cjs +52 -0
  33. package/cjs/openapi-CC7OAUc6.cjs.map +1 -0
  34. package/cjs/options-CWqFC5__.cjs +181 -0
  35. package/cjs/options-CWqFC5__.cjs.map +1 -0
  36. package/cjs/panels-B0dAfGbJ.cjs +298 -0
  37. package/cjs/panels-B0dAfGbJ.cjs.map +1 -0
  38. package/cjs/process-panel-DEOnLxoT.cjs +48 -0
  39. package/cjs/process-panel-DEOnLxoT.cjs.map +1 -0
  40. package/cjs/production/index.cjs +238 -0
  41. package/cjs/production/index.cjs.map +1 -0
  42. package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +52 -0
  43. package/cjs/server-B6xdeKS8.cjs +184 -0
  44. package/cjs/server-B6xdeKS8.cjs.map +1 -0
  45. package/cjs/{src-BzuntLcd.cjs → src-Ce-3Lniv.cjs} +171 -308
  46. package/cjs/src-Ce-3Lniv.cjs.map +1 -0
  47. package/cjs/store-aq207T8v.cjs +9 -0
  48. package/cjs/stream-route-BGJa-zQu.cjs +875 -0
  49. package/cjs/stream-route-BGJa-zQu.cjs.map +1 -0
  50. package/esm/devtools-connector.d.mts +16 -12
  51. package/esm/devtools-connector.d.mts.map +1 -1
  52. package/esm/devtools-connector.mjs +137 -18
  53. package/esm/devtools-connector.mjs.map +1 -1
  54. package/esm/index.d.mts +3 -2
  55. package/esm/options.mjs +3 -1
  56. package/esm/options.mjs.map +1 -1
  57. package/esm/panels.mjs +267 -0
  58. package/esm/panels.mjs.map +1 -0
  59. package/esm/process-panel.mjs +20 -1
  60. package/esm/process-panel.mjs.map +1 -1
  61. package/esm/production/auth/common-passwords.mjs +303 -0
  62. package/esm/production/auth/common-passwords.mjs.map +1 -0
  63. package/esm/production/auth/default-crypto.mjs +19 -0
  64. package/esm/production/auth/default-crypto.mjs.map +1 -0
  65. package/esm/production/auth/helpers.mjs +77 -0
  66. package/esm/production/auth/helpers.mjs.map +1 -0
  67. package/esm/production/auth/index.mjs +6 -0
  68. package/esm/production/auth/passkeys.mjs +96 -0
  69. package/esm/production/auth/passkeys.mjs.map +1 -0
  70. package/esm/production/auth/service.mjs +1166 -0
  71. package/esm/production/auth/service.mjs.map +1 -0
  72. package/esm/production/boot.mjs +138 -0
  73. package/esm/production/boot.mjs.map +1 -0
  74. package/esm/production/capture/dev-stats.mjs +83 -0
  75. package/esm/production/capture/dev-stats.mjs.map +1 -0
  76. package/esm/production/capture/engine.mjs +442 -0
  77. package/esm/production/capture/engine.mjs.map +1 -0
  78. package/esm/production/capture/explain.mjs +271 -0
  79. package/esm/production/capture/explain.mjs.map +1 -0
  80. package/esm/production/capture/filter.mjs +24 -0
  81. package/esm/production/capture/filter.mjs.map +1 -0
  82. package/esm/production/capture/index.mjs +7 -0
  83. package/esm/production/capture/production-capture.mjs +134 -0
  84. package/esm/production/capture/production-capture.mjs.map +1 -0
  85. package/esm/production/capture/redact.mjs +109 -0
  86. package/esm/production/capture/redact.mjs.map +1 -0
  87. package/esm/production/capture/stats-stores.mjs +300 -0
  88. package/esm/production/capture/stats-stores.mjs.map +1 -0
  89. package/esm/production/cli/actions.mjs +151 -0
  90. package/esm/production/cli/actions.mjs.map +1 -0
  91. package/esm/production/cli/index.d.mts +17 -0
  92. package/esm/production/cli/index.d.mts.map +1 -0
  93. package/esm/production/cli/index.mjs +86 -0
  94. package/esm/production/cli/index.mjs.map +1 -0
  95. package/esm/production/contracts.d.mts +592 -0
  96. package/esm/production/contracts.d.mts.map +1 -0
  97. package/esm/production/contracts.mjs +95 -0
  98. package/esm/production/contracts.mjs.map +1 -0
  99. package/esm/production/errors.d.mts +31 -0
  100. package/esm/production/errors.d.mts.map +1 -0
  101. package/esm/production/errors.mjs +142 -0
  102. package/esm/production/errors.mjs.map +1 -0
  103. package/esm/production/http/access.mjs +124 -0
  104. package/esm/production/http/access.mjs.map +1 -0
  105. package/esm/production/http/auth-routes.mjs +280 -0
  106. package/esm/production/http/auth-routes.mjs.map +1 -0
  107. package/esm/production/http/client.mjs +57 -0
  108. package/esm/production/http/client.mjs.map +1 -0
  109. package/esm/production/http/constants.mjs +11 -0
  110. package/esm/production/http/constants.mjs.map +1 -0
  111. package/esm/production/http/context.mjs +14 -0
  112. package/esm/production/http/context.mjs.map +1 -0
  113. package/esm/production/http/cookie.mjs +39 -0
  114. package/esm/production/http/cookie.mjs.map +1 -0
  115. package/esm/production/http/headers.mjs +25 -0
  116. package/esm/production/http/headers.mjs.map +1 -0
  117. package/esm/production/http/index.mjs +10 -0
  118. package/esm/production/http/ip.mjs +130 -0
  119. package/esm/production/http/ip.mjs.map +1 -0
  120. package/esm/production/http/mount.mjs +300 -0
  121. package/esm/production/http/mount.mjs.map +1 -0
  122. package/esm/production/http/state.mjs +54 -0
  123. package/esm/production/http/state.mjs.map +1 -0
  124. package/esm/production/index.d.mts +6 -0
  125. package/esm/production/index.mjs +5 -0
  126. package/esm/production/insights/cap-report.mjs +67 -0
  127. package/esm/production/insights/cap-report.mjs.map +1 -0
  128. package/esm/production/insights/health.mjs +88 -0
  129. package/esm/production/insights/health.mjs.map +1 -0
  130. package/esm/production/insights/index.mjs +10 -0
  131. package/esm/production/insights/insights.mjs +167 -0
  132. package/esm/production/insights/insights.mjs.map +1 -0
  133. package/esm/production/insights/instance.mjs +24 -0
  134. package/esm/production/insights/instance.mjs.map +1 -0
  135. package/esm/production/insights/jobs.mjs +100 -0
  136. package/esm/production/insights/jobs.mjs.map +1 -0
  137. package/esm/production/insights/reporter.mjs +59 -0
  138. package/esm/production/insights/reporter.mjs.map +1 -0
  139. package/esm/production/insights/resources.mjs +139 -0
  140. package/esm/production/insights/resources.mjs.map +1 -0
  141. package/esm/production/insights/writer.mjs +72 -0
  142. package/esm/production/insights/writer.mjs.map +1 -0
  143. package/esm/production/openapi.mjs +52 -0
  144. package/esm/production/openapi.mjs.map +1 -0
  145. package/esm/production/options.d.mts +60 -0
  146. package/esm/production/options.d.mts.map +1 -0
  147. package/esm/production/options.mjs +170 -0
  148. package/esm/production/options.mjs.map +1 -0
  149. package/esm/production/stats/histogram.mjs +67 -0
  150. package/esm/production/stats/histogram.mjs.map +1 -0
  151. package/esm/production/stats/merge.mjs +106 -0
  152. package/esm/production/stats/merge.mjs.map +1 -0
  153. package/esm/production/store/cascade-store.mjs +322 -0
  154. package/esm/production/store/cascade-store.mjs.map +1 -0
  155. package/esm/production/store/index.mjs +5 -0
  156. package/esm/production/store/mapping.mjs +258 -0
  157. package/esm/production/store/mapping.mjs.map +1 -0
  158. package/esm/production/store/memory-store.mjs +291 -0
  159. package/esm/production/store/memory-store.mjs.map +1 -0
  160. package/esm/production/store/migrations.d.mts +11 -0
  161. package/esm/production/store/migrations.d.mts.map +1 -0
  162. package/esm/production/store/migrations.mjs +29 -0
  163. package/esm/production/store/migrations.mjs.map +1 -0
  164. package/esm/production/store/models/account.migration.mjs +34 -0
  165. package/esm/production/store/models/account.migration.mjs.map +1 -0
  166. package/esm/production/store/models/account.model.mjs +13 -0
  167. package/esm/production/store/models/account.model.mjs.map +1 -0
  168. package/esm/production/store/models/audit.migration.mjs +30 -0
  169. package/esm/production/store/models/audit.migration.mjs.map +1 -0
  170. package/esm/production/store/models/audit.model.mjs +13 -0
  171. package/esm/production/store/models/audit.model.mjs.map +1 -0
  172. package/esm/production/store/models/base.mjs +27 -0
  173. package/esm/production/store/models/base.mjs.map +1 -0
  174. package/esm/production/store/models/index.mjs +17 -0
  175. package/esm/production/store/models/invite.migration.mjs +26 -0
  176. package/esm/production/store/models/invite.migration.mjs.map +1 -0
  177. package/esm/production/store/models/invite.model.mjs +13 -0
  178. package/esm/production/store/models/invite.model.mjs.map +1 -0
  179. package/esm/production/store/models/report.migration.mjs +20 -0
  180. package/esm/production/store/models/report.migration.mjs.map +1 -0
  181. package/esm/production/store/models/report.model.mjs +13 -0
  182. package/esm/production/store/models/report.model.mjs.map +1 -0
  183. package/esm/production/store/models/sample.migration.mjs +25 -0
  184. package/esm/production/store/models/sample.migration.mjs.map +1 -0
  185. package/esm/production/store/models/sample.model.mjs +13 -0
  186. package/esm/production/store/models/sample.model.mjs.map +1 -0
  187. package/esm/production/store/models/session.migration.mjs +31 -0
  188. package/esm/production/store/models/session.migration.mjs.map +1 -0
  189. package/esm/production/store/models/session.model.mjs +13 -0
  190. package/esm/production/store/models/session.model.mjs.map +1 -0
  191. package/esm/production/store/models/state.migration.mjs +26 -0
  192. package/esm/production/store/models/state.migration.mjs.map +1 -0
  193. package/esm/production/store/models/state.model.mjs +13 -0
  194. package/esm/production/store/models/state.model.mjs.map +1 -0
  195. package/esm/query-shape.mjs +14 -1
  196. package/esm/query-shape.mjs.map +1 -1
  197. package/esm/server/explain-route.mjs +26 -1
  198. package/esm/server/explain-route.mjs.map +1 -1
  199. package/esm/server/index.mjs +16 -6
  200. package/esm/server/index.mjs.map +1 -1
  201. package/esm/server/insights-routes.mjs +62 -0
  202. package/esm/server/insights-routes.mjs.map +1 -0
  203. package/esm/server/log-routes.mjs +32 -5
  204. package/esm/server/log-routes.mjs.map +1 -1
  205. package/esm/server/openapi-routes.mjs +3 -2
  206. package/esm/server/openapi-routes.mjs.map +1 -1
  207. package/esm/server/panel-routes.mjs +44 -0
  208. package/esm/server/panel-routes.mjs.map +1 -0
  209. package/esm/server/requests-routes.mjs +125 -0
  210. package/esm/server/requests-routes.mjs.map +1 -1
  211. package/esm/server/session-routes.mjs +42 -0
  212. package/esm/server/session-routes.mjs.map +1 -0
  213. package/esm/server/stream-route.mjs +81 -11
  214. package/esm/server/stream-route.mjs.map +1 -1
  215. package/esm/server/ui-assets.mjs +34 -12
  216. package/esm/server/ui-assets.mjs.map +1 -1
  217. package/esm/sources/log-source.mjs +14 -1
  218. package/esm/sources/log-source.mjs.map +1 -1
  219. package/esm/types.d.mts +271 -1
  220. package/esm/types.d.mts.map +1 -1
  221. package/esm/ui-root.mjs +11 -6
  222. package/esm/ui-root.mjs.map +1 -1
  223. package/llms-full.txt +208 -19
  224. package/llms.txt +2 -2
  225. package/package.json +32 -8
  226. package/skills/SKILL.md +208 -19
  227. package/ui/dashboard/assets/app.css +3 -0
  228. package/ui/dashboard/assets/app.js +50 -0
  229. package/ui/dashboard/build-info.json +21 -0
  230. package/ui/dashboard/index.html +15 -0
  231. package/ui/panels/processes.js +15 -0
  232. package/cjs/server-BlQshJLE.cjs +0 -658
  233. package/cjs/server-BlQshJLE.cjs.map +0 -1
  234. package/cjs/src-BzuntLcd.cjs.map +0 -1
  235. package/esm/server/process-routes.mjs +0 -11
  236. package/esm/server/process-routes.mjs.map +0 -1
  237. package/ui/app.css +0 -376
  238. package/ui/app.js +0 -1054
  239. package/ui/index.html +0 -28
@@ -1,262 +1,13 @@
1
- const require_ai_source = require("./ai-source-CSPh1HqJ.cjs");
2
- const require_server = require("./server-BlQshJLE.cjs");
3
- let _warlock_js_core = require("@warlock.js/core");
4
- let _warlock_js_logger = require("@warlock.js/logger");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-Zuuoy_Rh.cjs");
2
+ const require_panels = require("./panels-B0dAfGbJ.cjs");
3
+ const require_ai_source = require("./ai-source-DTpxumMA.cjs");
4
+ const require_process_panel = require("./process-panel-DEOnLxoT.cjs");
5
+ const require_collector = require("./collector-CJbQbzzK.cjs");
6
+ const require_options = require("./options-CWqFC5__.cjs");
7
+ const require_current_request_id = require("./current-request-id-BoJJb3y7.cjs");
5
8
  let node_url = require("node:url");
9
+ let _warlock_js_logger = require("@warlock.js/logger");
6
10
 
7
- //#region ../../packages/devtools/src/process-panel.ts
8
- /** Load app-owned generated registration only when devtools boots in development. */
9
- async function loadProcessPanel() {
10
- const core = await import("@warlock.js/core");
11
- if (!("srcPath" in core)) return void 0;
12
- const { srcPath } = core;
13
- const { existsSync } = await import("node:fs");
14
- const { pathToFileURL } = await import("node:url");
15
- const file = srcPath("app/processes/devtools.ts");
16
- if (!existsSync(file)) return void 0;
17
- return (await import(pathToFileURL(file).href)).processPanel;
18
- }
19
-
20
- //#endregion
21
- //#region ../../packages/devtools/src/n-plus-one.ts
22
- /** Finds repeated query shapes whose occurrence count reaches the supplied threshold. */
23
- function detectNPlusOne(queries, threshold) {
24
- const groups = /* @__PURE__ */ new Map();
25
- for (const query of queries) groups.set(query.shape, [...groups.get(query.shape) ?? [], query]);
26
- return [...groups.entries()].filter(([, grouped]) => grouped.length >= threshold).sort(([, left], [, right]) => right.length - left.length).map(([shape, grouped]) => ({
27
- type: "n+1",
28
- shape,
29
- count: grouped.length,
30
- message: `N+1: ${grouped.length}× "${truncate(shape, 120)}"`,
31
- ...mostFrequentCaller(grouped) ? { caller: mostFrequentCaller(grouped) } : {}
32
- }));
33
- }
34
- function truncate(value, maximum) {
35
- return value.length > maximum ? `${value.slice(0, maximum - 1)}…` : value;
36
- }
37
- function mostFrequentCaller(queries) {
38
- const callers = /* @__PURE__ */ new Map();
39
- for (const query of queries) {
40
- if (!query.caller) continue;
41
- const key = `${query.caller.file}:${query.caller.line}`;
42
- const found = callers.get(key);
43
- callers.set(key, found ? {
44
- ...found,
45
- count: found.count + 1
46
- } : {
47
- caller: query.caller,
48
- count: 1
49
- });
50
- }
51
- return [...callers.values()].sort((left, right) => right.count - left.count)[0]?.caller;
52
- }
53
-
54
- //#endregion
55
- //#region ../../packages/devtools/src/query-shape.ts
56
- const numericLiteral = /(?<![\w$])[-+]?(?:\d+(?:\.\d+)?|\.\d+)(?![\w$])/g;
57
- const quotedLiteral = /'(?:''|[^'])*'/g;
58
- /** Returns a binding-independent shape for a database query. */
59
- function queryShape(query) {
60
- if (query.driver === "postgres") return (query.sql ?? "").replace(quotedLiteral, "?").replace(numericLiteral, "?").replace(/\s+/g, " ").trim();
61
- return `${query.collection ?? ""}.${query.command ?? ""} ${JSON.stringify(normalizeMongoValue(query.pipeline))}`;
62
- }
63
- function normalizeMongoValue(value) {
64
- if (isMongoLeaf(value)) return "?";
65
- if (Array.isArray(value)) {
66
- if (value.every(isMongoLeaf)) return ["?"];
67
- return value.map(normalizeMongoValue);
68
- }
69
- const record = value;
70
- return Object.fromEntries(Object.keys(record).map((key) => [key, normalizeMongoValue(record[key])]));
71
- }
72
- function isMongoLeaf(value) {
73
- if (value === null || typeof value !== "object") return true;
74
- if (value instanceof Date) return true;
75
- const record = value;
76
- return typeof record.toHexString === "function" || typeof record.$oid === "string";
77
- }
78
-
79
- //#endregion
80
- //#region ../../packages/devtools/src/collector.ts
81
- const mailLimit = 100;
82
- const logLimit = 1e3;
83
- const backgroundLimit = 500;
84
- /**
85
- * Creates the in-memory devtools store.
86
- *
87
- * Read methods return shallow structural copies, including copied arrays, so consumers
88
- * cannot mutate collector-owned arrays. The individual nested entries are retained.
89
- */
90
- function createCollector(options) {
91
- const requests = /* @__PURE__ */ new Map();
92
- const mails = /* @__PURE__ */ new Map();
93
- const logs = [];
94
- const background = {
95
- queries: [],
96
- cache: [],
97
- logs: []
98
- };
99
- const listeners = /* @__PURE__ */ new Set();
100
- let querySequence = 0;
101
- const emit = (event) => {
102
- for (const listener of listeners) try {
103
- listener(event);
104
- } catch {}
105
- };
106
- const addBackground = (list, value) => {
107
- list.push(value);
108
- if (list.length > backgroundLimit) list.shift();
109
- };
110
- return {
111
- startRequest(request) {
112
- requests.delete(request.id);
113
- requests.set(request.id, {
114
- ...request,
115
- phases: [],
116
- queries: [],
117
- cache: [],
118
- logs: [],
119
- mails: [],
120
- warnings: []
121
- });
122
- while (requests.size > options.maxRequests) requests.delete(requests.keys().next().value);
123
- },
124
- endRequest(id, result) {
125
- const request = requests.get(id);
126
- if (!request) return;
127
- request.status = result.status;
128
- request.durationMs = result.durationMs;
129
- request.error = result.error;
130
- if (result.route !== void 0) request.route = result.route;
131
- request.warnings = detectNPlusOne(request.queries, options.nPlusOneThreshold);
132
- emit({
133
- type: "request",
134
- data: summary(request)
135
- });
136
- },
137
- addPhase(requestId, phase) {
138
- requests.get(requestId)?.phases.push(phase);
139
- },
140
- addQuery(requestId, query) {
141
- const stored = {
142
- ...query,
143
- id: `q${++querySequence}`,
144
- shape: queryShape(query)
145
- };
146
- const request = requestId ? requests.get(requestId) : void 0;
147
- if (request) request.queries.push(stored);
148
- else addBackground(background.queries, stored);
149
- return stored;
150
- },
151
- addCacheOperation(requestId, operation) {
152
- const request = requestId ? requests.get(requestId) : void 0;
153
- if (request) request.cache.push(operation);
154
- else addBackground(background.cache, operation);
155
- },
156
- addLog(requestId, entry) {
157
- const request = requestId ? requests.get(requestId) : void 0;
158
- if (request) request.logs.push(entry);
159
- else addBackground(background.logs, entry);
160
- logs.unshift(entry);
161
- if (logs.length > logLimit) logs.pop();
162
- emit({
163
- type: "log",
164
- data: entry
165
- });
166
- },
167
- addMail(mail) {
168
- mails.delete(mail.id);
169
- mails.set(mail.id, mail);
170
- while (mails.size > mailLimit) mails.delete(mails.keys().next().value);
171
- if (mail.requestId) requests.get(mail.requestId)?.mails.push(mail.id);
172
- emit({
173
- type: "mail",
174
- data: mailSummary(mail)
175
- });
176
- },
177
- listRequests() {
178
- return [...requests.values()].reverse().map(summary);
179
- },
180
- getRequest(id) {
181
- const request = requests.get(id);
182
- return request && copyRequest(request);
183
- },
184
- listMails() {
185
- return [...mails.values()].reverse().map(mailSummary);
186
- },
187
- getMail(id) {
188
- const mail = mails.get(id);
189
- return mail && {
190
- ...mail,
191
- to: [...mail.to],
192
- cc: [...mail.cc],
193
- bcc: [...mail.bcc],
194
- headers: { ...mail.headers },
195
- attachments: [...mail.attachments]
196
- };
197
- },
198
- listLogs(filter = {}) {
199
- const module = filter.module?.toLowerCase();
200
- return logs.filter((entry) => (!filter.level || entry.level === filter.level) && (!module || entry.module.toLowerCase().includes(module))).map((entry) => ({ ...entry }));
201
- },
202
- getBackground() {
203
- return {
204
- queries: [...background.queries],
205
- cache: [...background.cache],
206
- logs: [...background.logs]
207
- };
208
- },
209
- subscribe(listener) {
210
- listeners.add(listener);
211
- return () => listeners.delete(listener);
212
- },
213
- clear() {
214
- requests.clear();
215
- mails.clear();
216
- logs.length = 0;
217
- background.queries.length = 0;
218
- background.cache.length = 0;
219
- background.logs.length = 0;
220
- }
221
- };
222
- }
223
- function summary(request) {
224
- const { id, method, path, route, status, startedAt, durationMs } = request;
225
- return {
226
- id,
227
- method,
228
- path,
229
- route,
230
- status,
231
- startedAt,
232
- durationMs,
233
- queryCount: request.queries.length,
234
- warningCount: request.warnings.length
235
- };
236
- }
237
- function mailSummary(mail) {
238
- const { id, requestId, capturedAt, to, subject } = mail;
239
- return {
240
- id,
241
- requestId,
242
- capturedAt,
243
- to: [...to],
244
- subject
245
- };
246
- }
247
- function copyRequest(request) {
248
- return {
249
- ...request,
250
- phases: [...request.phases],
251
- queries: [...request.queries],
252
- cache: [...request.cache],
253
- logs: [...request.logs],
254
- mails: [...request.mails],
255
- warnings: [...request.warnings]
256
- };
257
- }
258
-
259
- //#endregion
260
11
  //#region ../../packages/devtools/src/options.ts
261
12
  /** Resolves dashboard options and rejects invalid capacity or URL-prefix values. */
262
13
  function resolveDevtoolsOptions(options = {}) {
@@ -271,31 +22,12 @@ function resolveDevtoolsOptions(options = {}) {
271
22
  maxRequests,
272
23
  nPlusOneThreshold,
273
24
  allowedHosts: options.allowedHosts ?? [],
274
- allowProxied: options.allowProxied ?? false
25
+ allowProxied: options.allowProxied ?? false,
26
+ panels: options.panels ?? [],
27
+ ...options.production === void 0 ? {} : { production: options.production }
275
28
  };
276
29
  }
277
30
 
278
- //#endregion
279
- //#region ../../packages/devtools/src/current-request-id.ts
280
- var current_request_id_exports = /* @__PURE__ */ require_server.__exportAll({ currentRequestId: () => currentRequestId });
281
- /**
282
- * The current request's id (core's `request.id`, threaded through
283
- * `AsyncLocalStorage`), or `undefined` outside a request — sources feed
284
- * devtools' background bucket in that case.
285
- *
286
- * Only ever reached through `./sources/*`, which the connector imports
287
- * dynamically inside `boot()` — by then core is already running, so this
288
- * static import never drags core's runtime graph into config-load time (see
289
- * `devtools-connector.ts`).
290
- */
291
- function currentRequestId() {
292
- try {
293
- return _warlock_js_core.requestContext.getRequest()?.id;
294
- } catch {
295
- return;
296
- }
297
- }
298
-
299
31
  //#endregion
300
32
  //#region ../../packages/devtools/src/sources/cache-source.ts
301
33
  /** Cache events the dashboard's waterfall and background bucket care about. */
@@ -330,7 +62,7 @@ async function attachCacheSource(collector) {
330
62
  at: Date.now(),
331
63
  durationMs: data.durationMs
332
64
  };
333
- collector.addCacheOperation(currentRequestId(), operation);
65
+ collector.addCacheOperation(require_current_request_id.currentRequestId(), operation);
334
66
  };
335
67
  cache.on(type, handler);
336
68
  return {
@@ -349,6 +81,19 @@ async function attachCacheSource(collector) {
349
81
  function toDevtoolsLevel(type) {
350
82
  return type === "fatal" ? "error" : type;
351
83
  }
84
+ /**
85
+ * The entry's message as text. `request.log(error)` and friends log an Error
86
+ * (or any value) as the message; kept as is, it reached the dashboard as `{}`.
87
+ */
88
+ function messageText(message) {
89
+ if (typeof message === "string") return message;
90
+ if (message instanceof Error) return `${message.name}: ${message.message}`;
91
+ try {
92
+ return JSON.stringify(message) ?? String(message);
93
+ } catch {
94
+ return String(message);
95
+ }
96
+ }
352
97
  var DevtoolsLogChannel = class extends _warlock_js_logger.LogChannel {
353
98
  constructor(collector) {
354
99
  super();
@@ -362,11 +107,11 @@ var DevtoolsLogChannel = class extends _warlock_js_logger.LogChannel {
362
107
  level: toDevtoolsLevel(data.type),
363
108
  module: data.module,
364
109
  action: data.action,
365
- message: data.message,
110
+ message: messageText(data.message),
366
111
  at: Date.now(),
367
112
  context: require_ai_source.toSafeValue(data.context)
368
113
  };
369
- this.collector.addLog(currentRequestId(), entry);
114
+ this.collector.addLog(require_current_request_id.currentRequestId(), entry);
370
115
  }
371
116
  };
372
117
  /**
@@ -385,6 +130,7 @@ async function attachLogSource(collector) {
385
130
 
386
131
  //#endregion
387
132
  //#region ../../packages/devtools/src/sources/mail-source.ts
133
+ var mail_source_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ attachMailSource: () => attachMailSource });
388
134
  function addressToString(address) {
389
135
  if (!address) return void 0;
390
136
  return typeof address === "string" ? address : `${address.name} <${address.address}>`;
@@ -411,7 +157,7 @@ async function attachMailSource(collector) {
411
157
  const { normalized } = mail;
412
158
  collector.addMail({
413
159
  id: mail.id,
414
- requestId: currentRequestId(),
160
+ requestId: require_current_request_id.currentRequestId(),
415
161
  capturedAt: mail.timestamp.getTime(),
416
162
  from: addressToString(normalized.from),
417
163
  to: normalized.to,
@@ -482,7 +228,7 @@ async function attachQuerySource(collector) {
482
228
  return () => {};
483
229
  }
484
230
  const listener = (event) => {
485
- collector.addQuery(currentRequestId(), {
231
+ collector.addQuery(require_current_request_id.currentRequestId(), {
486
232
  connection: event.connection,
487
233
  driver: event.driver,
488
234
  sql: event.sql,
@@ -567,20 +313,24 @@ function readConfiguredOptions(readConfig) {
567
313
  /**
568
314
  * Construct the devtools connector.
569
315
  *
570
- * Refuses to run outside development: `boot()` checks
571
- * `Application.runtimeStrategy` and, when it isn't `"development"`, logs one
316
+ * Outside development, `boot()` checks `Application.runtimeStrategy` and
317
+ * `devtools.production.enabled`: unless both say production, it logs one
572
318
  * warning and returns without mounting a route or subscribing to anything.
573
- * In development it attaches every source (tracing, queries, cache, mail,
574
- * logs), then mounts the dashboard's routes on the HTTP server — before it
575
- * starts listening, the only point in the boot sequence where mounting is
576
- * possible (see `queue/src/dashboard-boot.ts` for the same constraint).
319
+ * With `enabled: true` in production it starts the signed-in production
320
+ * monitor (`bootProductionDevtools`), which refuses to boot when its
321
+ * configuration is incomplete. In development it attaches every source
322
+ * (tracing, queries, cache, mail, logs), loads the panels listed in the
323
+ * `panels` option, then mounts the dashboard's routes on the HTTP server —
324
+ * before it starts listening, the only point in the boot sequence where
325
+ * mounting is possible (see `queue/src/dashboard-boot.ts` for the same
326
+ * constraint).
577
327
  *
578
- * Apps don't call this: `warlock dev` registers it automatically when the
579
- * package is installed (`warlock add devtools`). Keep it OUT of
580
- * `warlock.config.ts` — devtools is a dev dependency, so a production
581
- * install doesn't have it and a config import of it would fail there.
582
- * Options come from the app's `src/config/devtools.ts` instead (a plain
583
- * object, no import of this package); options passed here win over it.
328
+ * In development apps don't call this: `warlock dev` registers it
329
+ * automatically when the package is installed (`warlock add devtools`). To
330
+ * run the production monitor, list `devtoolsConnector()` in
331
+ * `warlock.config.ts > connectors` (and keep the package in `dependencies`).
332
+ * Options come from the app's `src/config/devtools.ts` (a plain object, no
333
+ * import of this package); options passed here win over it.
584
334
  */
585
335
  function devtoolsConnector(options = {}) {
586
336
  let active = false;
@@ -594,15 +344,20 @@ function devtoolsConnector(options = {}) {
594
344
  const core = await import("@warlock.js/core");
595
345
  const { Application, getHttpServer } = core;
596
346
  const { log } = await import("@warlock.js/logger");
597
- if (Application.runtimeStrategy !== "development") {
598
- log.warn("devtools", "disabled", "@warlock.js/devtools only runs in development; it is not mounted");
599
- return;
600
- }
601
347
  const resolved = resolveDevtoolsOptions({
602
348
  ...readConfiguredOptions(() => core.config),
603
349
  ...options
604
350
  });
605
- const collector = createCollector(resolved);
351
+ if (Application.runtimeStrategy === "production" && resolved.production?.enabled === true) {
352
+ disposers.push(await bootProduction(core, log, resolved));
353
+ active = true;
354
+ return;
355
+ }
356
+ if (Application.runtimeStrategy !== "development") {
357
+ log.warn("devtools", "disabled", "@warlock.js/devtools only runs in development unless devtools.production.enabled is true; it is not mounted");
358
+ return;
359
+ }
360
+ const collector = require_collector.createCollector(resolved);
606
361
  await attachSource(log, "tracing", () => attachTracingSource(collector, resolved));
607
362
  await attachSource(log, "query", () => attachQuerySource(collector));
608
363
  await attachSource(log, "cache", () => attachCacheSource(collector));
@@ -612,15 +367,25 @@ function devtoolsConnector(options = {}) {
612
367
  disposers.push(ai.dispose);
613
368
  const agentTraces = await require_ai_source.attachAgentTraceSource();
614
369
  disposers.push(agentTraces.dispose);
615
- const { mountDevtoolsRoutes } = await Promise.resolve().then(() => require("./server-BlQshJLE.cjs"));
370
+ const { mountDevtoolsRoutes } = await Promise.resolve().then(() => require("./server-B6xdeKS8.cjs"));
616
371
  const postmanBuilder = await findPostmanBuilder();
617
372
  const requestLog = await findRequestLogSource();
373
+ const processPanel = await require_process_panel.loadProcessPanel();
374
+ const builtIn = require_process_panel.processesDevtoolsPanel(processPanel);
375
+ const panels = await require_panels.loadDevtoolsPanels(resolved.panels ?? [], {
376
+ root: "rootPath" in core ? core.rootPath() : process.cwd(),
377
+ warn: (message) => log.warn("devtools", "panel", message),
378
+ taken: /* @__PURE__ */ new Map([[builtIn.id, builtIn.title]])
379
+ });
380
+ const insightsWiring = await wireDevelopmentInsights(collector, resolved, log, disposers);
618
381
  mountDevtoolsRoutes(getHttpServer(), {
619
382
  collector,
620
383
  ai,
621
384
  agentTraces,
622
- processPanel: await loadProcessPanel(),
385
+ ...processPanel ? { processPanel } : {},
386
+ panels,
623
387
  options: resolved,
388
+ ...insightsWiring,
624
389
  requestLog,
625
390
  isDevelopment: () => Application.runtimeStrategy === "development",
626
391
  warn: (message) => log.warn("devtools", "refused", message),
@@ -660,6 +425,104 @@ function devtoolsConnector(options = {}) {
660
425
  }
661
426
  return connector;
662
427
  }
428
+ /**
429
+ * Development: the statistics, resources, health and jobs behind the
430
+ * Resources, Queries (statistics), Routes (statistics), Errors, Health and
431
+ * Jobs tabs. Wrapped as a whole: when anything fails to start, one line is
432
+ * logged and the dashboard mounts without insights (those tabs then say they
433
+ * are not available). It never stops the dashboard.
434
+ */
435
+ async function wireDevelopmentInsights(collector, resolved, log, disposers) {
436
+ const stops = [];
437
+ try {
438
+ const capture = await Promise.resolve().then(() => require("./capture-CqIiaznN.cjs"));
439
+ const insights = await Promise.resolve().then(() => require("./insights-BKtqxdnP.cjs"));
440
+ const instance = insights.createInstanceInfo();
441
+ const queries = capture.createQueryStats({
442
+ maxShapes: require_options.DEVTOOLS_PRODUCTION_DEFAULTS.maxShapes,
443
+ instance: instance.id
444
+ });
445
+ const routes = capture.createRouteStats({
446
+ maxRoutes: require_options.DEVTOOLS_PRODUCTION_DEFAULTS.maxRoutes,
447
+ instance: instance.id
448
+ });
449
+ const errors = capture.createErrorGroups({ maxGroups: require_options.DEVTOOLS_PRODUCTION_DEFAULTS.maxErrorGroups });
450
+ const logs = capture.createRecentLogs({ maxEntries: 200 });
451
+ stops.push(capture.attachDevelopmentStats(collector, {
452
+ queries,
453
+ routes,
454
+ errors,
455
+ logs,
456
+ nPlusOneThreshold: resolved.nPlusOneThreshold
457
+ }));
458
+ const resources = insights.createResourceMonitor();
459
+ const health = insights.createHealthHistory();
460
+ resources.start();
461
+ health.start();
462
+ stops.push(() => resources.stop(), () => health.stop());
463
+ const reporter = insights.createLocalReporter({
464
+ instance,
465
+ resources,
466
+ health,
467
+ jobs: insights.createJobsReader(),
468
+ queries,
469
+ routes,
470
+ errors,
471
+ logs,
472
+ counters: null
473
+ });
474
+ const explainShape = capture.createShapeExplainer({
475
+ queries,
476
+ executing: false,
477
+ instance: instance.id
478
+ });
479
+ disposers.push(...stops);
480
+ return {
481
+ instance,
482
+ insights: insights.createLocalInsights(reporter),
483
+ explainShape
484
+ };
485
+ } catch (error) {
486
+ for (const stop of stops) try {
487
+ stop();
488
+ } catch {}
489
+ log.warn("devtools", "insights-failed", `devtools' statistics could not start, so the Resources, Queries, Routes, Errors, Health and Jobs tabs are not available: ${error instanceof Error ? error.message : String(error)}`);
490
+ return {};
491
+ }
492
+ }
493
+ /**
494
+ * Starts the production monitor: loads the panels in production mode and
495
+ * hands everything to `bootProductionDevtools`, which refuses to boot (throws
496
+ * `DevtoolsProductionConfigError`) when the configuration is incomplete.
497
+ */
498
+ async function bootProduction(core, log, resolved) {
499
+ const { bootProductionDevtools } = await Promise.resolve().then(() => require("./boot-BQi0Etor.cjs"));
500
+ const requestLog = await findRequestLogSource();
501
+ const processPanel = resolved.production?.panels?.processes === true ? await require_process_panel.loadProcessPanel() : void 0;
502
+ const builtIn = require_process_panel.processesDevtoolsPanel(processPanel);
503
+ const packagePanels = await require_panels.loadDevtoolsPanels(resolved.panels ?? [], {
504
+ root: "rootPath" in core ? core.rootPath() : process.cwd(),
505
+ warn: (message) => log.warn("devtools", "panel", message),
506
+ taken: /* @__PURE__ */ new Map([[builtIn.id, builtIn.title]]),
507
+ mode: "production"
508
+ });
509
+ const { createProductionOpenApi } = await Promise.resolve().then(() => require("./openapi-CC7OAUc6.cjs"));
510
+ const openApi = createProductionOpenApi(core);
511
+ return bootProductionDevtools({
512
+ options: resolved,
513
+ env: process.env,
514
+ server: core.getHttpServer(),
515
+ panels: [...require_panels.checkDevtoolsPanels([builtIn]), ...packagePanels],
516
+ routes: {
517
+ ...processPanel ? { processPanel } : {},
518
+ ...requestLog ? { requestLog } : {},
519
+ listRoutes: () => listRoutes(),
520
+ getOpenApiDocument: openApi.getOpenApiDocument,
521
+ getPostmanCollection: openApi.getPostmanCollection
522
+ },
523
+ log
524
+ });
525
+ }
663
526
  /** Runs `EXPLAIN (FORMAT JSON)` for a stored Postgres query on its own connection. */
664
527
  async function explainQuery(query) {
665
528
  const { dataSourceRegistry } = await import("@warlock.js/cascade");
@@ -729,16 +592,16 @@ function unwrapCollection(result) {
729
592
  }
730
593
 
731
594
  //#endregion
732
- Object.defineProperty(exports, "current_request_id_exports", {
595
+ Object.defineProperty(exports, "devtoolsConnector", {
733
596
  enumerable: true,
734
597
  get: function () {
735
- return current_request_id_exports;
598
+ return devtoolsConnector;
736
599
  }
737
600
  });
738
- Object.defineProperty(exports, "devtoolsConnector", {
601
+ Object.defineProperty(exports, "mail_source_exports", {
739
602
  enumerable: true,
740
603
  get: function () {
741
- return devtoolsConnector;
604
+ return mail_source_exports;
742
605
  }
743
606
  });
744
- //# sourceMappingURL=src-BzuntLcd.cjs.map
607
+ //# sourceMappingURL=src-Ce-3Lniv.cjs.map