@warlock.js/devtools 5.55.0 → 5.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +26 -13
  3. package/cjs/ai-source-DTpxumMA.cjs +381 -0
  4. package/cjs/ai-source-DTpxumMA.cjs.map +1 -0
  5. package/cjs/auth-DzU0gHDG.cjs +1655 -0
  6. package/cjs/auth-DzU0gHDG.cjs.map +1 -0
  7. package/cjs/boot-Dy5OqgTM.cjs +138 -0
  8. package/cjs/boot-Dy5OqgTM.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-DCfXQvw-.cjs +870 -0
  24. package/cjs/http-DCfXQvw-.cjs.map +1 -0
  25. package/cjs/index.cjs +2 -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-Rcmeitu3.cjs +318 -0
  37. package/cjs/panels-Rcmeitu3.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-ykxsOwob.cjs +184 -0
  44. package/cjs/server-ykxsOwob.cjs.map +1 -0
  45. package/cjs/{src-Xwm3Eel9.cjs → src-UPtTCI2j.cjs} +210 -293
  46. package/cjs/src-UPtTCI2j.cjs.map +1 -0
  47. package/cjs/store-aq207T8v.cjs +9 -0
  48. package/cjs/stream-route-CJTABkUy.cjs +875 -0
  49. package/cjs/stream-route-CJTABkUy.cjs.map +1 -0
  50. package/esm/devtools-connector.d.mts +16 -13
  51. package/esm/devtools-connector.d.mts.map +1 -1
  52. package/esm/devtools-connector.mjs +127 -18
  53. package/esm/devtools-connector.mjs.map +1 -1
  54. package/esm/index.d.mts +4 -2
  55. package/esm/index.mjs +2 -1
  56. package/esm/options.mjs +2 -1
  57. package/esm/options.mjs.map +1 -1
  58. package/esm/panel-tokens.d.mts +13 -0
  59. package/esm/panel-tokens.d.mts.map +1 -0
  60. package/esm/panel-tokens.mjs +45 -0
  61. package/esm/panel-tokens.mjs.map +1 -0
  62. package/esm/panels.mjs +73 -8
  63. package/esm/panels.mjs.map +1 -1
  64. package/esm/production/auth/common-passwords.mjs +303 -0
  65. package/esm/production/auth/common-passwords.mjs.map +1 -0
  66. package/esm/production/auth/default-crypto.mjs +19 -0
  67. package/esm/production/auth/default-crypto.mjs.map +1 -0
  68. package/esm/production/auth/helpers.mjs +77 -0
  69. package/esm/production/auth/helpers.mjs.map +1 -0
  70. package/esm/production/auth/index.mjs +6 -0
  71. package/esm/production/auth/passkeys.mjs +96 -0
  72. package/esm/production/auth/passkeys.mjs.map +1 -0
  73. package/esm/production/auth/service.mjs +1166 -0
  74. package/esm/production/auth/service.mjs.map +1 -0
  75. package/esm/production/boot.mjs +138 -0
  76. package/esm/production/boot.mjs.map +1 -0
  77. package/esm/production/capture/dev-stats.mjs +83 -0
  78. package/esm/production/capture/dev-stats.mjs.map +1 -0
  79. package/esm/production/capture/engine.mjs +442 -0
  80. package/esm/production/capture/engine.mjs.map +1 -0
  81. package/esm/production/capture/explain.mjs +271 -0
  82. package/esm/production/capture/explain.mjs.map +1 -0
  83. package/esm/production/capture/filter.mjs +24 -0
  84. package/esm/production/capture/filter.mjs.map +1 -0
  85. package/esm/production/capture/index.mjs +7 -0
  86. package/esm/production/capture/production-capture.mjs +134 -0
  87. package/esm/production/capture/production-capture.mjs.map +1 -0
  88. package/esm/production/capture/redact.mjs +109 -0
  89. package/esm/production/capture/redact.mjs.map +1 -0
  90. package/esm/production/capture/stats-stores.mjs +300 -0
  91. package/esm/production/capture/stats-stores.mjs.map +1 -0
  92. package/esm/production/cli/actions.mjs +151 -0
  93. package/esm/production/cli/actions.mjs.map +1 -0
  94. package/esm/production/cli/index.d.mts +17 -0
  95. package/esm/production/cli/index.d.mts.map +1 -0
  96. package/esm/production/cli/index.mjs +86 -0
  97. package/esm/production/cli/index.mjs.map +1 -0
  98. package/esm/production/contracts.d.mts +592 -0
  99. package/esm/production/contracts.d.mts.map +1 -0
  100. package/esm/production/contracts.mjs +95 -0
  101. package/esm/production/contracts.mjs.map +1 -0
  102. package/esm/production/errors.d.mts +31 -0
  103. package/esm/production/errors.d.mts.map +1 -0
  104. package/esm/production/errors.mjs +142 -0
  105. package/esm/production/errors.mjs.map +1 -0
  106. package/esm/production/http/access.mjs +124 -0
  107. package/esm/production/http/access.mjs.map +1 -0
  108. package/esm/production/http/auth-routes.mjs +280 -0
  109. package/esm/production/http/auth-routes.mjs.map +1 -0
  110. package/esm/production/http/client.mjs +57 -0
  111. package/esm/production/http/client.mjs.map +1 -0
  112. package/esm/production/http/constants.mjs +11 -0
  113. package/esm/production/http/constants.mjs.map +1 -0
  114. package/esm/production/http/context.mjs +14 -0
  115. package/esm/production/http/context.mjs.map +1 -0
  116. package/esm/production/http/cookie.mjs +39 -0
  117. package/esm/production/http/cookie.mjs.map +1 -0
  118. package/esm/production/http/headers.mjs +25 -0
  119. package/esm/production/http/headers.mjs.map +1 -0
  120. package/esm/production/http/index.mjs +10 -0
  121. package/esm/production/http/ip.mjs +130 -0
  122. package/esm/production/http/ip.mjs.map +1 -0
  123. package/esm/production/http/mount.mjs +300 -0
  124. package/esm/production/http/mount.mjs.map +1 -0
  125. package/esm/production/http/state.mjs +54 -0
  126. package/esm/production/http/state.mjs.map +1 -0
  127. package/esm/production/index.d.mts +6 -0
  128. package/esm/production/index.mjs +5 -0
  129. package/esm/production/insights/cap-report.mjs +67 -0
  130. package/esm/production/insights/cap-report.mjs.map +1 -0
  131. package/esm/production/insights/health.mjs +88 -0
  132. package/esm/production/insights/health.mjs.map +1 -0
  133. package/esm/production/insights/index.mjs +10 -0
  134. package/esm/production/insights/insights.mjs +167 -0
  135. package/esm/production/insights/insights.mjs.map +1 -0
  136. package/esm/production/insights/instance.mjs +24 -0
  137. package/esm/production/insights/instance.mjs.map +1 -0
  138. package/esm/production/insights/jobs.mjs +100 -0
  139. package/esm/production/insights/jobs.mjs.map +1 -0
  140. package/esm/production/insights/reporter.mjs +59 -0
  141. package/esm/production/insights/reporter.mjs.map +1 -0
  142. package/esm/production/insights/resources.mjs +139 -0
  143. package/esm/production/insights/resources.mjs.map +1 -0
  144. package/esm/production/insights/writer.mjs +72 -0
  145. package/esm/production/insights/writer.mjs.map +1 -0
  146. package/esm/production/openapi.mjs +52 -0
  147. package/esm/production/openapi.mjs.map +1 -0
  148. package/esm/production/options.d.mts +60 -0
  149. package/esm/production/options.d.mts.map +1 -0
  150. package/esm/production/options.mjs +170 -0
  151. package/esm/production/options.mjs.map +1 -0
  152. package/esm/production/stats/histogram.mjs +67 -0
  153. package/esm/production/stats/histogram.mjs.map +1 -0
  154. package/esm/production/stats/merge.mjs +106 -0
  155. package/esm/production/stats/merge.mjs.map +1 -0
  156. package/esm/production/store/cascade-store.mjs +322 -0
  157. package/esm/production/store/cascade-store.mjs.map +1 -0
  158. package/esm/production/store/index.mjs +5 -0
  159. package/esm/production/store/mapping.mjs +258 -0
  160. package/esm/production/store/mapping.mjs.map +1 -0
  161. package/esm/production/store/memory-store.mjs +291 -0
  162. package/esm/production/store/memory-store.mjs.map +1 -0
  163. package/esm/production/store/migrations.d.mts +11 -0
  164. package/esm/production/store/migrations.d.mts.map +1 -0
  165. package/esm/production/store/migrations.mjs +29 -0
  166. package/esm/production/store/migrations.mjs.map +1 -0
  167. package/esm/production/store/models/account.migration.mjs +34 -0
  168. package/esm/production/store/models/account.migration.mjs.map +1 -0
  169. package/esm/production/store/models/account.model.mjs +13 -0
  170. package/esm/production/store/models/account.model.mjs.map +1 -0
  171. package/esm/production/store/models/audit.migration.mjs +30 -0
  172. package/esm/production/store/models/audit.migration.mjs.map +1 -0
  173. package/esm/production/store/models/audit.model.mjs +13 -0
  174. package/esm/production/store/models/audit.model.mjs.map +1 -0
  175. package/esm/production/store/models/base.mjs +27 -0
  176. package/esm/production/store/models/base.mjs.map +1 -0
  177. package/esm/production/store/models/index.mjs +17 -0
  178. package/esm/production/store/models/invite.migration.mjs +26 -0
  179. package/esm/production/store/models/invite.migration.mjs.map +1 -0
  180. package/esm/production/store/models/invite.model.mjs +13 -0
  181. package/esm/production/store/models/invite.model.mjs.map +1 -0
  182. package/esm/production/store/models/report.migration.mjs +20 -0
  183. package/esm/production/store/models/report.migration.mjs.map +1 -0
  184. package/esm/production/store/models/report.model.mjs +13 -0
  185. package/esm/production/store/models/report.model.mjs.map +1 -0
  186. package/esm/production/store/models/sample.migration.mjs +25 -0
  187. package/esm/production/store/models/sample.migration.mjs.map +1 -0
  188. package/esm/production/store/models/sample.model.mjs +13 -0
  189. package/esm/production/store/models/sample.model.mjs.map +1 -0
  190. package/esm/production/store/models/session.migration.mjs +31 -0
  191. package/esm/production/store/models/session.migration.mjs.map +1 -0
  192. package/esm/production/store/models/session.model.mjs +13 -0
  193. package/esm/production/store/models/session.model.mjs.map +1 -0
  194. package/esm/production/store/models/state.migration.mjs +26 -0
  195. package/esm/production/store/models/state.migration.mjs.map +1 -0
  196. package/esm/production/store/models/state.model.mjs +13 -0
  197. package/esm/production/store/models/state.model.mjs.map +1 -0
  198. package/esm/query-shape.mjs +14 -1
  199. package/esm/query-shape.mjs.map +1 -1
  200. package/esm/server/explain-route.mjs +26 -1
  201. package/esm/server/explain-route.mjs.map +1 -1
  202. package/esm/server/index.mjs +9 -4
  203. package/esm/server/index.mjs.map +1 -1
  204. package/esm/server/insights-routes.mjs +62 -0
  205. package/esm/server/insights-routes.mjs.map +1 -0
  206. package/esm/server/log-routes.mjs +32 -5
  207. package/esm/server/log-routes.mjs.map +1 -1
  208. package/esm/server/openapi-routes.mjs +3 -2
  209. package/esm/server/openapi-routes.mjs.map +1 -1
  210. package/esm/server/requests-routes.mjs +125 -0
  211. package/esm/server/requests-routes.mjs.map +1 -1
  212. package/esm/server/session-routes.mjs +42 -0
  213. package/esm/server/session-routes.mjs.map +1 -0
  214. package/esm/server/stream-route.mjs +81 -11
  215. package/esm/server/stream-route.mjs.map +1 -1
  216. package/esm/server/ui-assets.mjs +34 -25
  217. package/esm/server/ui-assets.mjs.map +1 -1
  218. package/esm/sources/log-source.mjs +14 -1
  219. package/esm/sources/log-source.mjs.map +1 -1
  220. package/esm/types.d.mts +208 -3
  221. package/esm/types.d.mts.map +1 -1
  222. package/esm/ui-root.mjs +9 -4
  223. package/esm/ui-root.mjs.map +1 -1
  224. package/llms-full.txt +166 -21
  225. package/llms.txt +2 -2
  226. package/package.json +32 -8
  227. package/skills/SKILL.md +166 -21
  228. package/ui/dashboard/assets/app.css +3 -0
  229. package/ui/dashboard/assets/app.js +50 -0
  230. package/ui/dashboard/build-info.json +21 -0
  231. package/ui/dashboard/index.html +16 -0
  232. package/ui/panels/processes.js +12 -3
  233. package/cjs/ai-source-Dz_3tlZ5.cjs +0 -703
  234. package/cjs/ai-source-Dz_3tlZ5.cjs.map +0 -1
  235. package/cjs/server-B11ShQYE.cjs +0 -628
  236. package/cjs/server-B11ShQYE.cjs.map +0 -1
  237. package/cjs/src-Xwm3Eel9.cjs.map +0 -1
  238. package/ui/app.css +0 -376
  239. package/ui/app.js +0 -1158
  240. package/ui/index.html +0 -28
@@ -1,247 +1,13 @@
1
- const require_ai_source = require("./ai-source-Dz_3tlZ5.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-Zuuoy_Rh.cjs");
2
+ const require_panels = require("./panels-Rcmeitu3.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");
2
8
  let node_url = require("node:url");
3
- let _warlock_js_core = require("@warlock.js/core");
4
9
  let _warlock_js_logger = require("@warlock.js/logger");
5
10
 
6
- //#region ../../packages/devtools/src/n-plus-one.ts
7
- /** Finds repeated query shapes whose occurrence count reaches the supplied threshold. */
8
- function detectNPlusOne(queries, threshold) {
9
- const groups = /* @__PURE__ */ new Map();
10
- for (const query of queries) groups.set(query.shape, [...groups.get(query.shape) ?? [], query]);
11
- return [...groups.entries()].filter(([, grouped]) => grouped.length >= threshold).sort(([, left], [, right]) => right.length - left.length).map(([shape, grouped]) => ({
12
- type: "n+1",
13
- shape,
14
- count: grouped.length,
15
- message: `N+1: ${grouped.length}× "${truncate(shape, 120)}"`,
16
- ...mostFrequentCaller(grouped) ? { caller: mostFrequentCaller(grouped) } : {}
17
- }));
18
- }
19
- function truncate(value, maximum) {
20
- return value.length > maximum ? `${value.slice(0, maximum - 1)}…` : value;
21
- }
22
- function mostFrequentCaller(queries) {
23
- const callers = /* @__PURE__ */ new Map();
24
- for (const query of queries) {
25
- if (!query.caller) continue;
26
- const key = `${query.caller.file}:${query.caller.line}`;
27
- const found = callers.get(key);
28
- callers.set(key, found ? {
29
- ...found,
30
- count: found.count + 1
31
- } : {
32
- caller: query.caller,
33
- count: 1
34
- });
35
- }
36
- return [...callers.values()].sort((left, right) => right.count - left.count)[0]?.caller;
37
- }
38
-
39
- //#endregion
40
- //#region ../../packages/devtools/src/query-shape.ts
41
- const numericLiteral = /(?<![\w$])[-+]?(?:\d+(?:\.\d+)?|\.\d+)(?![\w$])/g;
42
- const quotedLiteral = /'(?:''|[^'])*'/g;
43
- /** Returns a binding-independent shape for a database query. */
44
- function queryShape(query) {
45
- if (query.driver === "postgres") return (query.sql ?? "").replace(quotedLiteral, "?").replace(numericLiteral, "?").replace(/\s+/g, " ").trim();
46
- return `${query.collection ?? ""}.${query.command ?? ""} ${JSON.stringify(normalizeMongoValue(query.pipeline))}`;
47
- }
48
- function normalizeMongoValue(value) {
49
- if (isMongoLeaf(value)) return "?";
50
- if (Array.isArray(value)) {
51
- if (value.every(isMongoLeaf)) return ["?"];
52
- return value.map(normalizeMongoValue);
53
- }
54
- const record = value;
55
- return Object.fromEntries(Object.keys(record).map((key) => [key, normalizeMongoValue(record[key])]));
56
- }
57
- function isMongoLeaf(value) {
58
- if (value === null || typeof value !== "object") return true;
59
- if (value instanceof Date) return true;
60
- const record = value;
61
- return typeof record.toHexString === "function" || typeof record.$oid === "string";
62
- }
63
-
64
- //#endregion
65
- //#region ../../packages/devtools/src/collector.ts
66
- const mailLimit = 100;
67
- const logLimit = 1e3;
68
- const backgroundLimit = 500;
69
- /**
70
- * Creates the in-memory devtools store.
71
- *
72
- * Read methods return shallow structural copies, including copied arrays, so consumers
73
- * cannot mutate collector-owned arrays. The individual nested entries are retained.
74
- */
75
- function createCollector(options) {
76
- const requests = /* @__PURE__ */ new Map();
77
- const mails = /* @__PURE__ */ new Map();
78
- const logs = [];
79
- const background = {
80
- queries: [],
81
- cache: [],
82
- logs: []
83
- };
84
- const listeners = /* @__PURE__ */ new Set();
85
- let querySequence = 0;
86
- const emit = (event) => {
87
- for (const listener of listeners) try {
88
- listener(event);
89
- } catch {}
90
- };
91
- const addBackground = (list, value) => {
92
- list.push(value);
93
- if (list.length > backgroundLimit) list.shift();
94
- };
95
- return {
96
- startRequest(request) {
97
- requests.delete(request.id);
98
- requests.set(request.id, {
99
- ...request,
100
- phases: [],
101
- queries: [],
102
- cache: [],
103
- logs: [],
104
- mails: [],
105
- warnings: []
106
- });
107
- while (requests.size > options.maxRequests) requests.delete(requests.keys().next().value);
108
- },
109
- endRequest(id, result) {
110
- const request = requests.get(id);
111
- if (!request) return;
112
- request.status = result.status;
113
- request.durationMs = result.durationMs;
114
- request.error = result.error;
115
- if (result.route !== void 0) request.route = result.route;
116
- request.warnings = detectNPlusOne(request.queries, options.nPlusOneThreshold);
117
- emit({
118
- type: "request",
119
- data: summary(request)
120
- });
121
- },
122
- addPhase(requestId, phase) {
123
- requests.get(requestId)?.phases.push(phase);
124
- },
125
- addQuery(requestId, query) {
126
- const stored = {
127
- ...query,
128
- id: `q${++querySequence}`,
129
- shape: queryShape(query)
130
- };
131
- const request = requestId ? requests.get(requestId) : void 0;
132
- if (request) request.queries.push(stored);
133
- else addBackground(background.queries, stored);
134
- return stored;
135
- },
136
- addCacheOperation(requestId, operation) {
137
- const request = requestId ? requests.get(requestId) : void 0;
138
- if (request) request.cache.push(operation);
139
- else addBackground(background.cache, operation);
140
- },
141
- addLog(requestId, entry) {
142
- const request = requestId ? requests.get(requestId) : void 0;
143
- if (request) request.logs.push(entry);
144
- else addBackground(background.logs, entry);
145
- logs.unshift(entry);
146
- if (logs.length > logLimit) logs.pop();
147
- emit({
148
- type: "log",
149
- data: entry
150
- });
151
- },
152
- addMail(mail) {
153
- mails.delete(mail.id);
154
- mails.set(mail.id, mail);
155
- while (mails.size > mailLimit) mails.delete(mails.keys().next().value);
156
- if (mail.requestId) requests.get(mail.requestId)?.mails.push(mail.id);
157
- emit({
158
- type: "mail",
159
- data: mailSummary(mail)
160
- });
161
- },
162
- listRequests() {
163
- return [...requests.values()].reverse().map(summary);
164
- },
165
- getRequest(id) {
166
- const request = requests.get(id);
167
- return request && copyRequest(request);
168
- },
169
- listMails() {
170
- return [...mails.values()].reverse().map(mailSummary);
171
- },
172
- getMail(id) {
173
- const mail = mails.get(id);
174
- return mail && {
175
- ...mail,
176
- to: [...mail.to],
177
- cc: [...mail.cc],
178
- bcc: [...mail.bcc],
179
- headers: { ...mail.headers },
180
- attachments: [...mail.attachments]
181
- };
182
- },
183
- listLogs(filter = {}) {
184
- const module = filter.module?.toLowerCase();
185
- return logs.filter((entry) => (!filter.level || entry.level === filter.level) && (!module || entry.module.toLowerCase().includes(module))).map((entry) => ({ ...entry }));
186
- },
187
- getBackground() {
188
- return {
189
- queries: [...background.queries],
190
- cache: [...background.cache],
191
- logs: [...background.logs]
192
- };
193
- },
194
- subscribe(listener) {
195
- listeners.add(listener);
196
- return () => listeners.delete(listener);
197
- },
198
- clear() {
199
- requests.clear();
200
- mails.clear();
201
- logs.length = 0;
202
- background.queries.length = 0;
203
- background.cache.length = 0;
204
- background.logs.length = 0;
205
- }
206
- };
207
- }
208
- function summary(request) {
209
- const { id, method, path, route, status, startedAt, durationMs } = request;
210
- return {
211
- id,
212
- method,
213
- path,
214
- route,
215
- status,
216
- startedAt,
217
- durationMs,
218
- queryCount: request.queries.length,
219
- warningCount: request.warnings.length
220
- };
221
- }
222
- function mailSummary(mail) {
223
- const { id, requestId, capturedAt, to, subject } = mail;
224
- return {
225
- id,
226
- requestId,
227
- capturedAt,
228
- to: [...to],
229
- subject
230
- };
231
- }
232
- function copyRequest(request) {
233
- return {
234
- ...request,
235
- phases: [...request.phases],
236
- queries: [...request.queries],
237
- cache: [...request.cache],
238
- logs: [...request.logs],
239
- mails: [...request.mails],
240
- warnings: [...request.warnings]
241
- };
242
- }
243
-
244
- //#endregion
245
11
  //#region ../../packages/devtools/src/options.ts
246
12
  /** Resolves dashboard options and rejects invalid capacity or URL-prefix values. */
247
13
  function resolveDevtoolsOptions(options = {}) {
@@ -257,31 +23,11 @@ function resolveDevtoolsOptions(options = {}) {
257
23
  nPlusOneThreshold,
258
24
  allowedHosts: options.allowedHosts ?? [],
259
25
  allowProxied: options.allowProxied ?? false,
260
- panels: options.panels ?? []
26
+ panels: options.panels ?? [],
27
+ ...options.production === void 0 ? {} : { production: options.production }
261
28
  };
262
29
  }
263
30
 
264
- //#endregion
265
- //#region ../../packages/devtools/src/current-request-id.ts
266
- var current_request_id_exports = /* @__PURE__ */ require_ai_source.__exportAll({ currentRequestId: () => currentRequestId });
267
- /**
268
- * The current request's id (core's `request.id`, threaded through
269
- * `AsyncLocalStorage`), or `undefined` outside a request — sources feed
270
- * devtools' background bucket in that case.
271
- *
272
- * Only ever reached through `./sources/*`, which the connector imports
273
- * dynamically inside `boot()` — by then core is already running, so this
274
- * static import never drags core's runtime graph into config-load time (see
275
- * `devtools-connector.ts`).
276
- */
277
- function currentRequestId() {
278
- try {
279
- return _warlock_js_core.requestContext.getRequest()?.id;
280
- } catch {
281
- return;
282
- }
283
- }
284
-
285
31
  //#endregion
286
32
  //#region ../../packages/devtools/src/sources/cache-source.ts
287
33
  /** Cache events the dashboard's waterfall and background bucket care about. */
@@ -316,7 +62,7 @@ async function attachCacheSource(collector) {
316
62
  at: Date.now(),
317
63
  durationMs: data.durationMs
318
64
  };
319
- collector.addCacheOperation(currentRequestId(), operation);
65
+ collector.addCacheOperation(require_current_request_id.currentRequestId(), operation);
320
66
  };
321
67
  cache.on(type, handler);
322
68
  return {
@@ -335,6 +81,19 @@ async function attachCacheSource(collector) {
335
81
  function toDevtoolsLevel(type) {
336
82
  return type === "fatal" ? "error" : type;
337
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
+ }
338
97
  var DevtoolsLogChannel = class extends _warlock_js_logger.LogChannel {
339
98
  constructor(collector) {
340
99
  super();
@@ -348,11 +107,11 @@ var DevtoolsLogChannel = class extends _warlock_js_logger.LogChannel {
348
107
  level: toDevtoolsLevel(data.type),
349
108
  module: data.module,
350
109
  action: data.action,
351
- message: data.message,
110
+ message: messageText(data.message),
352
111
  at: Date.now(),
353
112
  context: require_ai_source.toSafeValue(data.context)
354
113
  };
355
- this.collector.addLog(currentRequestId(), entry);
114
+ this.collector.addLog(require_current_request_id.currentRequestId(), entry);
356
115
  }
357
116
  };
358
117
  /**
@@ -371,6 +130,7 @@ async function attachLogSource(collector) {
371
130
 
372
131
  //#endregion
373
132
  //#region ../../packages/devtools/src/sources/mail-source.ts
133
+ var mail_source_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ attachMailSource: () => attachMailSource });
374
134
  function addressToString(address) {
375
135
  if (!address) return void 0;
376
136
  return typeof address === "string" ? address : `${address.name} <${address.address}>`;
@@ -397,7 +157,7 @@ async function attachMailSource(collector) {
397
157
  const { normalized } = mail;
398
158
  collector.addMail({
399
159
  id: mail.id,
400
- requestId: currentRequestId(),
160
+ requestId: require_current_request_id.currentRequestId(),
401
161
  capturedAt: mail.timestamp.getTime(),
402
162
  from: addressToString(normalized.from),
403
163
  to: normalized.to,
@@ -468,7 +228,7 @@ async function attachQuerySource(collector) {
468
228
  return () => {};
469
229
  }
470
230
  const listener = (event) => {
471
- collector.addQuery(currentRequestId(), {
231
+ collector.addQuery(require_current_request_id.currentRequestId(), {
472
232
  connection: event.connection,
473
233
  driver: event.driver,
474
234
  sql: event.sql,
@@ -553,21 +313,24 @@ function readConfiguredOptions(readConfig) {
553
313
  /**
554
314
  * Construct the devtools connector.
555
315
  *
556
- * Refuses to run outside development: `boot()` checks
557
- * `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
558
318
  * warning and returns without mounting a route or subscribing to anything.
559
- * In development it attaches every source (tracing, queries, cache, mail,
560
- * logs), loads the panels listed in the `panels` option, then mounts the
561
- * dashboard's routes on the HTTP server — before it
562
- * starts listening, the only point in the boot sequence where mounting is
563
- * 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).
564
327
  *
565
- * Apps don't call this: `warlock dev` registers it automatically when the
566
- * package is installed (`warlock add devtools`). Keep it OUT of
567
- * `warlock.config.ts` — devtools is a dev dependency, so a production
568
- * install doesn't have it and a config import of it would fail there.
569
- * Options come from the app's `src/config/devtools.ts` instead (a plain
570
- * 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.
571
334
  */
572
335
  function devtoolsConnector(options = {}) {
573
336
  let active = false;
@@ -581,15 +344,20 @@ function devtoolsConnector(options = {}) {
581
344
  const core = await import("@warlock.js/core");
582
345
  const { Application, getHttpServer } = core;
583
346
  const { log } = await import("@warlock.js/logger");
584
- if (Application.runtimeStrategy !== "development") {
585
- log.warn("devtools", "disabled", "@warlock.js/devtools only runs in development; it is not mounted");
586
- return;
587
- }
588
347
  const resolved = resolveDevtoolsOptions({
589
348
  ...readConfiguredOptions(() => core.config),
590
349
  ...options
591
350
  });
592
- 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);
593
361
  await attachSource(log, "tracing", () => attachTracingSource(collector, resolved));
594
362
  await attachSource(log, "query", () => attachQuerySource(collector));
595
363
  await attachSource(log, "cache", () => attachCacheSource(collector));
@@ -599,16 +367,17 @@ function devtoolsConnector(options = {}) {
599
367
  disposers.push(ai.dispose);
600
368
  const agentTraces = await require_ai_source.attachAgentTraceSource();
601
369
  disposers.push(agentTraces.dispose);
602
- const { mountDevtoolsRoutes } = await Promise.resolve().then(() => require("./server-B11ShQYE.cjs"));
370
+ const { mountDevtoolsRoutes } = await Promise.resolve().then(() => require("./server-ykxsOwob.cjs"));
603
371
  const postmanBuilder = await findPostmanBuilder();
604
372
  const requestLog = await findRequestLogSource();
605
- const processPanel = await require_ai_source.loadProcessPanel();
606
- const builtIn = require_ai_source.processesDevtoolsPanel(processPanel);
607
- const panels = await require_ai_source.loadDevtoolsPanels(resolved.panels ?? [], {
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 ?? [], {
608
376
  root: "rootPath" in core ? core.rootPath() : process.cwd(),
609
377
  warn: (message) => log.warn("devtools", "panel", message),
610
378
  taken: /* @__PURE__ */ new Map([[builtIn.id, builtIn.title]])
611
379
  });
380
+ const insightsWiring = await wireDevelopmentInsights(collector, resolved, log, disposers);
612
381
  mountDevtoolsRoutes(getHttpServer(), {
613
382
  collector,
614
383
  ai,
@@ -616,6 +385,7 @@ function devtoolsConnector(options = {}) {
616
385
  ...processPanel ? { processPanel } : {},
617
386
  panels,
618
387
  options: resolved,
388
+ ...insightsWiring,
619
389
  requestLog,
620
390
  isDevelopment: () => Application.runtimeStrategy === "development",
621
391
  warn: (message) => log.warn("devtools", "refused", message),
@@ -655,6 +425,104 @@ function devtoolsConnector(options = {}) {
655
425
  }
656
426
  return connector;
657
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-Dy5OqgTM.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
+ }
658
526
  /** Runs `EXPLAIN (FORMAT JSON)` for a stored Postgres query on its own connection. */
659
527
  async function explainQuery(query) {
660
528
  const { dataSourceRegistry } = await import("@warlock.js/cascade");
@@ -724,10 +592,53 @@ function unwrapCollection(result) {
724
592
  }
725
593
 
726
594
  //#endregion
727
- Object.defineProperty(exports, "current_request_id_exports", {
595
+ //#region ../../packages/devtools/src/panel-tokens.ts
596
+ /**
597
+ * The CSS variables the dashboard defines for package panels, in both themes.
598
+ *
599
+ * A package panel's stylesheet may use only these variables, plus variables it
600
+ * defines itself (in the same file). Anything else is undefined in the
601
+ * dashboard and renders as the browser default, which is how a panel ends up
602
+ * with unreadable text. The dashboard's own colours are checked for contrast
603
+ * (4.5:1 for the text tokens on `--background` and `--card`) in both themes.
604
+ */
605
+ const DEVTOOLS_PANEL_TOKENS = [
606
+ "--background",
607
+ "--foreground",
608
+ "--card",
609
+ "--card-foreground",
610
+ "--popover",
611
+ "--popover-foreground",
612
+ "--primary",
613
+ "--primary-foreground",
614
+ "--secondary",
615
+ "--secondary-foreground",
616
+ "--muted",
617
+ "--muted-foreground",
618
+ "--accent",
619
+ "--accent-foreground",
620
+ "--destructive",
621
+ "--border",
622
+ "--input",
623
+ "--ring",
624
+ "--radius",
625
+ "--brand",
626
+ "--brand-foreground",
627
+ "--success",
628
+ "--warning",
629
+ "--info",
630
+ "--chart-1",
631
+ "--chart-2",
632
+ "--chart-3",
633
+ "--chart-4",
634
+ "--chart-5"
635
+ ];
636
+
637
+ //#endregion
638
+ Object.defineProperty(exports, "DEVTOOLS_PANEL_TOKENS", {
728
639
  enumerable: true,
729
640
  get: function () {
730
- return current_request_id_exports;
641
+ return DEVTOOLS_PANEL_TOKENS;
731
642
  }
732
643
  });
733
644
  Object.defineProperty(exports, "devtoolsConnector", {
@@ -736,4 +647,10 @@ Object.defineProperty(exports, "devtoolsConnector", {
736
647
  return devtoolsConnector;
737
648
  }
738
649
  });
739
- //# sourceMappingURL=src-Xwm3Eel9.cjs.map
650
+ Object.defineProperty(exports, "mail_source_exports", {
651
+ enumerable: true,
652
+ get: function () {
653
+ return mail_source_exports;
654
+ }
655
+ });
656
+ //# sourceMappingURL=src-UPtTCI2j.cjs.map