@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,658 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __exportAll = (all, no_symbols) => {
9
- let target = {};
10
- for (var name in all) {
11
- __defProp(target, name, {
12
- get: all[name],
13
- enumerable: true
14
- });
15
- }
16
- if (!no_symbols) {
17
- __defProp(target, Symbol.toStringTag, { value: "Module" });
18
- }
19
- return target;
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
- key = keys[i];
25
- if (!__hasOwnProp.call(to, key) && key !== except) {
26
- __defProp(to, key, {
27
- get: ((k) => from[k]).bind(null, key),
28
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
- });
30
- }
31
- }
32
- }
33
- return to;
34
- };
35
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
36
- value: mod,
37
- enumerable: true
38
- }) : target, mod));
39
-
40
- //#endregion
41
- const require_ai_source = require("./ai-source-CSPh1HqJ.cjs");
42
- let node_url = require("node:url");
43
- let node_path = require("node:path");
44
- node_path = __toESM(node_path, 1);
45
- let node_fs = require("node:fs");
46
-
47
- //#region ../../packages/devtools/src/server/ai-routes.ts
48
- /** Read-only AI metadata, inside the same development/loopback guard as every panel. */
49
- function registerAiRoutes(server, deps) {
50
- server.get("/api/ai", async (request, reply) => {
51
- reply.header("Cache-Control", "no-store");
52
- const source = deps.ai;
53
- if (!source?.available) return {
54
- available: false,
55
- message: source?.message ?? "Install @warlock.js/ai and @warlock.js/ai-panoptic, then restart warlock dev. Import @warlock.js/ai-panoptic and enable ai.config({ panoptic: { observeAll: true } }). If already installed, check that both packages are compatible and can be loaded.",
56
- runs: []
57
- };
58
- const filter = request.query.requestId === void 0 ? void 0 : { requestId: request.query.requestId };
59
- return {
60
- available: true,
61
- runs: source.store.query(filter).map(source.summarize),
62
- aggregate: source.store.aggregate(filter)
63
- };
64
- });
65
- server.get("/api/ai/agent-runs", async (request, reply) => {
66
- reply.header("Cache-Control", "no-store");
67
- const source = deps.agentTraces;
68
- if (!source?.available()) return {
69
- available: false,
70
- message: require_ai_source.AGENT_TRACE_INSTALL_GUIDANCE,
71
- runs: []
72
- };
73
- return {
74
- available: true,
75
- runs: source.list(request.query.requestId === void 0 ? void 0 : { requestId: request.query.requestId })
76
- };
77
- });
78
- server.get("/api/ai/agent-runs/:id", async (request, reply) => {
79
- reply.header("Cache-Control", "no-store");
80
- const trace = deps.agentTraces?.get(request.params.id);
81
- if (!trace) return reply.code(404).send();
82
- return trace;
83
- });
84
- server.get("/api/ai/runs/:id", async (request, reply) => {
85
- reply.header("Cache-Control", "no-store");
86
- const source = deps.ai;
87
- const trace = source?.available ? source.store.get(request.params.id) : void 0;
88
- if (!trace) return reply.code(404).send();
89
- return trace;
90
- });
91
- }
92
-
93
- //#endregion
94
- //#region ../../packages/devtools/src/server/background-routes.ts
95
- /** Registers the route that returns work recorded outside any request. */
96
- function registerBackgroundRoutes(server, deps) {
97
- server.get("/api/background", async () => deps.collector.getBackground());
98
- }
99
-
100
- //#endregion
101
- //#region ../../packages/devtools/src/server/explain-route.ts
102
- /**
103
- * The value the logger's redaction substitutes for a censored leaf
104
- * (`logger/src/redact/redact.ts`, `DEFAULT_CENSOR`). Not exported from
105
- * `@warlock.js/logger`, so matched by literal here.
106
- */
107
- const REDACTED_PLACEHOLDER = "[REDACTED]";
108
- function isExplainableSql(sql) {
109
- return /^\s*(select|with)\b/i.test(sql ?? "");
110
- }
111
- /** Registers the EXPLAIN route: Postgres `SELECT`/`WITH` queries only. */
112
- function registerExplainRoute(server, deps) {
113
- server.post("/api/requests/:requestId/queries/:queryId/explain", async (request, reply) => {
114
- const query = deps.collector.getRequest(request.params.requestId)?.queries.find((item) => item.id === request.params.queryId);
115
- if (!query) {
116
- reply.code(404).send();
117
- return;
118
- }
119
- if (query.driver !== "postgres" || !isExplainableSql(query.sql) || !deps.explain) {
120
- reply.code(400).send({ error: "Only Postgres SELECT or WITH queries can be explained" });
121
- return;
122
- }
123
- if (query.bindings?.some((binding) => binding === REDACTED_PLACEHOLDER)) {
124
- reply.code(400).send({ error: "bindings redacted" });
125
- return;
126
- }
127
- try {
128
- return { plan: await deps.explain(query) };
129
- } catch (error) {
130
- reply.code(500).send({ error: error instanceof Error ? error.message : String(error) });
131
- }
132
- });
133
- }
134
-
135
- //#endregion
136
- //#region ../../packages/devtools/src/server/guard.ts
137
- const LOOPBACK_ADDRESSES = /* @__PURE__ */ new Set([
138
- "127.0.0.1",
139
- "::1",
140
- "::ffff:127.0.0.1"
141
- ]);
142
- /** Host names that always reach this machine, so DNS cannot be pointed at them. */
143
- const LOOPBACK_HOSTS = /* @__PURE__ */ new Set([
144
- "localhost",
145
- "127.0.0.1",
146
- "[::1]"
147
- ]);
148
- /** Headers a proxy or tunnel adds; their presence means the loopback peer is not the visitor. */
149
- const PROXY_HEADERS = [
150
- "x-forwarded-for",
151
- "x-forwarded-host",
152
- "x-real-ip",
153
- "forwarded"
154
- ];
155
- /** At most this many distinct refusals are logged per boot. */
156
- const MAX_WARNINGS = 20;
157
- /**
158
- * Whether `address` is a loopback address. Deliberately reads
159
- * `request.socket.remoteAddress` rather than `request.ip`, which honours
160
- * `X-Forwarded-For` when the app trusts a proxy — a header any client can
161
- * set.
162
- */
163
- function isLoopbackAddress(address) {
164
- return address !== void 0 && LOOPBACK_ADDRESSES.has(address);
165
- }
166
- /** The lower-cased host name of a `Host` header value, without its port (`[::1]` keeps its brackets). */
167
- function hostnameOf(host) {
168
- const value = host.trim().toLowerCase();
169
- if (value.startsWith("[")) {
170
- const end = value.indexOf("]");
171
- return end === -1 ? "" : value.slice(0, end + 1);
172
- }
173
- const colon = value.indexOf(":");
174
- const name = colon === -1 ? value : value.slice(0, colon);
175
- return name.endsWith(".") ? name.slice(0, -1) : name;
176
- }
177
- /**
178
- * Whether `hostname` is a loopback name or one of `allowedHosts`. An entry
179
- * starting with `.` matches that domain and every subdomain of it.
180
- */
181
- function isAllowedDevtoolsHost(hostname, allowedHosts = []) {
182
- if (!hostname) return false;
183
- if (LOOPBACK_HOSTS.has(hostname) || hostname.endsWith(".localhost")) return true;
184
- return allowedHosts.some((entry) => {
185
- const allowed = entry.trim().toLowerCase();
186
- if (allowed.startsWith(".")) return hostname === allowed.slice(1) || hostname.endsWith(allowed);
187
- return hostname === allowed;
188
- });
189
- }
190
- /** The `Origin` header's host name, `""` for `null` or an unparsable value. */
191
- function originHostname(origin) {
192
- try {
193
- return new URL(origin).hostname.toLowerCase();
194
- } catch {
195
- return "";
196
- }
197
- }
198
- /**
199
- * Why `request` must be refused, or `undefined` when it may be served.
200
- * `"not-local"` is the silent case (production, or a remote socket). Beyond a
201
- * loopback socket, the request must be ADDRESSED to a loopback (or allowed)
202
- * host, come from such an origin, and not have passed through a proxy: a page
203
- * whose domain was re-pointed at 127.0.0.1, or a tunnel, also arrives on a
204
- * loopback socket.
205
- */
206
- function refusalReason(request, deps) {
207
- if (!deps.isDevelopment() || !isLoopbackAddress(request.socket.remoteAddress)) return "not-local";
208
- const allowedHosts = deps.options.allowedHosts ?? [];
209
- const host = hostnameOf(request.headers.host ?? "");
210
- if (!isAllowedDevtoolsHost(host, allowedHosts)) return `Devtools refused a request for host "${host}". Open the dashboard on localhost, or add the host to the devtools "allowedHosts" option.`;
211
- const origin = request.headers.origin;
212
- if (origin !== void 0 && !isAllowedDevtoolsHost(originHostname(origin), allowedHosts)) return `Devtools refused a request from origin "${origin}". Only pages served from localhost or a host in the devtools "allowedHosts" option may call the dashboard.`;
213
- if (!deps.options.allowProxied && PROXY_HEADERS.some((name) => request.headers[name] !== void 0)) return "Devtools refused a proxied request (it carries a forwarding header). Open the dashboard directly on localhost, or set the devtools \"allowProxied\" option for a local proxy nobody else can reach.";
214
- }
215
- /**
216
- * Registers the dev-only, local-only guard as an `onRequest` hook on
217
- * `server`. Callers must register this inside an encapsulated Fastify
218
- * context (a plugin/prefix) so the hook never reaches routes outside the
219
- * dashboard.
220
- */
221
- function registerDevtoolsGuard(server, deps) {
222
- const warned = /* @__PURE__ */ new Set();
223
- server.addHook("onRequest", async (request, reply) => {
224
- const reason = refusalReason(request, deps);
225
- if (reason === void 0) return;
226
- if (reason !== "not-local" && !warned.has(reason) && warned.size < MAX_WARNINGS) {
227
- warned.add(reason);
228
- deps.warn?.(reason);
229
- }
230
- return reply.code(404).send();
231
- });
232
- }
233
-
234
- //#endregion
235
- //#region ../../packages/devtools/src/server/log-routes.ts
236
- /** Registers the log listing route, filterable by `level` and `module`. */
237
- function registerLogRoutes(server, deps) {
238
- server.get("/api/logs", async (request) => deps.collector.listLogs({
239
- level: request.query.level,
240
- module: request.query.module
241
- }));
242
- }
243
-
244
- //#endregion
245
- //#region ../../packages/devtools/src/server/mail-routes.ts
246
- const MAIL_HTML_CSP = "sandbox; default-src 'none'; img-src data: https: http:; style-src 'unsafe-inline'";
247
- /** Registers the mailbox list, single-mail detail, and mail HTML routes. */
248
- function registerMailRoutes(server, deps) {
249
- server.get("/api/mails", async () => deps.collector.listMails());
250
- server.get("/api/mails/:id", async (request, reply) => {
251
- const mail = deps.collector.getMail(request.params.id);
252
- if (!mail) {
253
- reply.code(404).send();
254
- return;
255
- }
256
- const { html, ...rest } = mail;
257
- return rest;
258
- });
259
- server.get("/api/mails/:id/html", async (request, reply) => {
260
- const mail = deps.collector.getMail(request.params.id);
261
- if (!mail || !mail.html) {
262
- reply.code(404).send();
263
- return;
264
- }
265
- reply.header("Content-Security-Policy", MAIL_HTML_CSP).header("X-Content-Type-Options", "nosniff").header("Content-Type", "text/html; charset=utf-8").send(mail.html);
266
- });
267
- }
268
-
269
- //#endregion
270
- //#region ../../packages/devtools/src/ui-root.ts
271
- let cachedUiRoot;
272
- /** Whether `dir` is this package's root: it has `ui/index.html` beside a `package.json` named `@warlock.js/devtools`. */
273
- function isPackageRoot(dir) {
274
- const indexHtml = node_path.default.join(dir, "ui", "index.html");
275
- const packageJson = node_path.default.join(dir, "package.json");
276
- if (!(0, node_fs.existsSync)(indexHtml) || !(0, node_fs.existsSync)(packageJson)) return false;
277
- try {
278
- return JSON.parse((0, node_fs.readFileSync)(packageJson, "utf8")).name === "@warlock.js/devtools";
279
- } catch {
280
- return false;
281
- }
282
- }
283
- /**
284
- * Locate this package's `ui/` directory by walking up from the current
285
- * module's directory. Works from `src/` in development and from the built
286
- * `esm/`/`cjs/` output, since both sit beside `ui/` and `package.json` at
287
- * the package root.
288
- */
289
- function resolveUiRoot() {
290
- if (cachedUiRoot) return cachedUiRoot;
291
- let dir = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
292
- while (true) {
293
- if (isPackageRoot(dir)) {
294
- cachedUiRoot = node_path.default.join(dir, "ui");
295
- return cachedUiRoot;
296
- }
297
- const parent = node_path.default.dirname(dir);
298
- if (parent === dir) throw new Error("Could not locate the devtools UI directory: no ancestor of this module has a ui/index.html beside a package.json named @warlock.js/devtools.");
299
- dir = parent;
300
- }
301
- }
302
-
303
- //#endregion
304
- //#region ../../packages/devtools/src/server/ui-assets.ts
305
- const uiFile = (name) => () => node_path.default.join(resolveUiRoot(), name);
306
- /**
307
- * The only assets that can be requested. The request's asset name is looked
308
- * up here and never joined into a filesystem path.
309
- */
310
- const UI_ASSETS = {
311
- "app.js": {
312
- contentType: "text/javascript; charset=utf-8",
313
- file: uiFile("app.js")
314
- },
315
- "app.css": {
316
- contentType: "text/css; charset=utf-8",
317
- file: uiFile("app.css")
318
- },
319
- "scalar.js": {
320
- contentType: "text/javascript; charset=utf-8",
321
- file: uiFile("vendor/scalar/standalone.js")
322
- },
323
- "swagger-ui-bundle.js": {
324
- contentType: "text/javascript; charset=utf-8",
325
- file: uiFile("vendor/swagger-ui/swagger-ui-bundle.js")
326
- },
327
- "swagger-ui.css": {
328
- contentType: "text/css; charset=utf-8",
329
- file: uiFile("vendor/swagger-ui/swagger-ui.css")
330
- },
331
- "docs-swagger.js": {
332
- contentType: "text/javascript; charset=utf-8",
333
- file: uiFile("docs-swagger.js")
334
- }
335
- };
336
- /** Sends `file` with `contentType` and no caching. */
337
- function sendFile(reply, file, contentType) {
338
- reply.header("Cache-Control", "no-store").header("Content-Type", contentType).send((0, node_fs.readFileSync)(file));
339
- }
340
- /**
341
- * Serves the static dashboard: `index.html` at the dashboard root and the
342
- * whitelisted assets (`app.js`, `app.css`, the vendored Scalar bundle as
343
- * `scalar.js`, and the vendored Swagger UI files plus their init script). The asset name is matched against a fixed whitelist — never
344
- * joined into a filesystem path — so no request can traverse outside it.
345
- */
346
- function registerUiAssets(server) {
347
- const serveIndex = (_request, reply) => {
348
- sendFile(reply, node_path.default.join(resolveUiRoot(), "index.html"), "text/html; charset=utf-8");
349
- };
350
- server.get("/", serveIndex);
351
- server.get("/assets/:name", (request, reply) => {
352
- const asset = Object.hasOwn(UI_ASSETS, request.params.name) ? UI_ASSETS[request.params.name] : void 0;
353
- if (!asset) {
354
- reply.code(404).header("Cache-Control", "no-store").send();
355
- return;
356
- }
357
- sendFile(reply, asset.file(), asset.contentType);
358
- });
359
- }
360
-
361
- //#endregion
362
- //#region ../../packages/devtools/src/server/openapi-routes.ts
363
- /**
364
- * Registers the API docs: `GET /api/openapi.json` returns the document core
365
- * builds from the registered routes (`deps.getOpenApiDocument`), and
366
- * `GET /docs` serves the page that renders it with Scalar and
367
- * `GET /docs/swagger` the same document in Swagger UI;
368
- * `GET /api/postman.json` returns the Postman collection core builds
369
- * (`deps.getPostmanCollection`). The pages use relative URLs, so it works under whatever base path the dashboard is
370
- * mounted on.
371
- */
372
- function registerOpenApiRoutes(server, deps) {
373
- server.get("/api/openapi.json", async (_request, reply) => {
374
- if (!deps.getOpenApiDocument) return reply.code(503).header("Cache-Control", "no-store").send({ error: "The OpenAPI document is not available: the host did not provide a generator." });
375
- reply.header("Cache-Control", "no-store");
376
- return deps.getOpenApiDocument();
377
- });
378
- server.get("/api/postman.json", async (_request, reply) => {
379
- if (!deps.getPostmanCollection) return reply.code(503).header("Cache-Control", "no-store").send({ error: "The Postman collection is not available: the host did not provide a generator." });
380
- reply.header("Cache-Control", "no-store");
381
- return deps.getPostmanCollection();
382
- });
383
- server.get("/docs", (_request, reply) => {
384
- sendFile(reply, node_path.default.join(resolveUiRoot(), "docs.html"), "text/html; charset=utf-8");
385
- });
386
- server.get("/docs/swagger", (_request, reply) => {
387
- sendFile(reply, node_path.default.join(resolveUiRoot(), "docs-swagger.html"), "text/html; charset=utf-8");
388
- });
389
- }
390
-
391
- //#endregion
392
- //#region ../../packages/devtools/src/server/process-routes.ts
393
- function registerProcessRoutes(server, deps) {
394
- server.get("/api/processes", async (_request, reply) => {
395
- reply.header("cache-control", "no-store");
396
- return deps.processPanel ? await deps.processPanel.list() : [];
397
- });
398
- }
399
-
400
- //#endregion
401
- //#region ../../packages/devtools/src/request-history.ts
402
- /** The list row filters run over, from an in-memory summary. */
403
- function summaryToRow(summary) {
404
- return {
405
- id: summary.id,
406
- time: new Date(summary.startedAt).toISOString(),
407
- method: summary.method,
408
- url: summary.path,
409
- ...summary.route ? { route: summary.route } : {},
410
- status: summary.status ?? 0,
411
- durationMs: summary.durationMs ?? 0
412
- };
413
- }
414
- /** An in-memory-shaped list row from a persisted one. */
415
- function rowToSummary(row) {
416
- return {
417
- id: row.id,
418
- method: row.method,
419
- path: row.url,
420
- route: row.route,
421
- status: row.status,
422
- startedAt: Date.parse(row.time),
423
- durationMs: row.durationMs,
424
- queryCount: row.queryCount ?? 0,
425
- warningCount: row.nPlusOneCount ?? 0,
426
- persisted: true
427
- };
428
- }
429
- /**
430
- * Merge the live ring buffer with the persisted log, newest first, without
431
- * duplicates: a request in both is shown from memory (it has the full
432
- * timeline). Persisted rows fill in what a restart or the ring buffer's size
433
- * evicted.
434
- */
435
- function mergeRequestHistory(live, persisted, limit) {
436
- const seen = new Set(live.map((summary) => summary.id));
437
- const merged = [...live];
438
- for (const row of persisted) {
439
- if (seen.has(row.id)) continue;
440
- seen.add(row.id);
441
- merged.push(rowToSummary(row));
442
- }
443
- return merged.sort((first, second) => second.startedAt - first.startedAt).slice(0, limit);
444
- }
445
- const FILTER_KEYS = [
446
- "status",
447
- "route",
448
- "method",
449
- "since",
450
- "until",
451
- "q"
452
- ];
453
- /** The request log filter in a `GET /api/requests` query string. */
454
- function filterFromQuery(query) {
455
- const filter = {};
456
- for (const key of FILTER_KEYS) {
457
- const value = query[key];
458
- if (typeof value === "string" && value.trim() !== "") filter[key] = value.trim();
459
- }
460
- const limit = Number(query.limit);
461
- if (Number.isInteger(limit) && limit > 0) filter.limit = limit;
462
- return filter;
463
- }
464
- /** Whether a filter narrows anything. */
465
- function hasFilter(filter) {
466
- return FILTER_KEYS.some((key) => filter[key] !== void 0);
467
- }
468
- function toLogLevel(level) {
469
- return level === "debug" || level === "info" || level === "warn" || level === "success" ? level : "error";
470
- }
471
- /**
472
- * A request detail rebuilt from a persisted record, in the shape of an
473
- * in-memory one: phases, logs and N+1 warnings carry over; query-by-query
474
- * and cache detail live only in memory, so those lists are empty. `record`
475
- * has everything the log kept.
476
- */
477
- function recordToDetail(record) {
478
- const startedAt = Date.parse(record.time);
479
- const warnings = (record.queries?.nPlusOne ?? []).map((finding) => ({
480
- type: "n+1",
481
- message: `${finding.query} ran ${finding.count} times`,
482
- shape: finding.query,
483
- count: finding.count
484
- }));
485
- return {
486
- id: record.id,
487
- method: record.method,
488
- path: record.url,
489
- route: record.route.pattern,
490
- status: record.status,
491
- startedAt,
492
- durationMs: record.durationMs,
493
- error: record.error?.message,
494
- phases: (record.phases ?? []).map((phase) => ({
495
- name: phase.name,
496
- startedAt,
497
- durationMs: phase.durationMs
498
- })),
499
- queries: [],
500
- cache: [],
501
- logs: (record.logs ?? []).map((entry) => ({
502
- level: toLogLevel(entry.level),
503
- module: entry.module,
504
- action: entry.action,
505
- message: entry.message,
506
- at: entry.at,
507
- ...entry.context ? { context: entry.context } : {}
508
- })),
509
- mails: [],
510
- warnings,
511
- persisted: true,
512
- record
513
- };
514
- }
515
-
516
- //#endregion
517
- //#region ../../packages/devtools/src/server/requests-routes.ts
518
- /**
519
- * Registers the request list, single-request detail, "copy as curl", and
520
- * clear routes.
521
- *
522
- * With core's persistent request log available, the list and the detail also
523
- * read the JSON-lines history, so requests survive a restart. The list
524
- * accepts `status` (404 or 5xx), `route`, `method`, `since`, `until`, `q`
525
- * and `limit` query parameters.
526
- */
527
- function registerRequestsRoutes(server, deps) {
528
- server.get("/api/requests", async (request, reply) => {
529
- const { requestLog, collector, options } = deps;
530
- if (!requestLog) return collector.listRequests();
531
- try {
532
- const filter = filterFromQuery(request.query);
533
- const matches = requestLog.compile(filter);
534
- const live = hasFilter(filter) ? collector.listRequests().filter((summary) => matches(summaryToRow(summary))) : collector.listRequests();
535
- const limit = filter.limit ?? options.maxRequests;
536
- const persisted = await requestLog.list({
537
- ...filter,
538
- limit
539
- });
540
- return mergeRequestHistory(live, persisted, limit);
541
- } catch (error) {
542
- if (error instanceof Error && /^Invalid /.test(error.message)) {
543
- reply.code(400).send({ error: error.message });
544
- return;
545
- }
546
- return collector.listRequests();
547
- }
548
- });
549
- server.get("/api/requests/:id", async (request, reply) => {
550
- const { id } = request.params;
551
- const persisted = await deps.requestLog?.get(id).catch(() => void 0);
552
- const found = deps.collector.getRequest(id);
553
- if (found) return persisted ? {
554
- ...found,
555
- record: persisted
556
- } : found;
557
- if (!persisted) {
558
- reply.code(404).send();
559
- return;
560
- }
561
- return recordToDetail(persisted);
562
- });
563
- server.get("/api/requests/:id/curl", async (request, reply) => {
564
- const { id } = request.params;
565
- const baseUrl = `${request.protocol}://${request.headers.host ?? "localhost"}`;
566
- const persisted = await deps.requestLog?.get(id).catch(() => void 0);
567
- if (persisted && deps.requestLog) return { curl: deps.requestLog.curl(persisted, baseUrl) };
568
- const live = deps.collector.getRequest(id);
569
- if (!live) {
570
- reply.code(404).send();
571
- return;
572
- }
573
- return { curl: `curl -X ${live.method} '${baseUrl}${live.path.replace(/'/g, `'\\''`)}'` };
574
- });
575
- server.delete("/api/requests", async (_request, reply) => {
576
- deps.collector.clear();
577
- if (deps.ai?.available) deps.ai.store.clear();
578
- reply.code(204).send();
579
- });
580
- }
581
-
582
- //#endregion
583
- //#region ../../packages/devtools/src/server/route-routes.ts
584
- /** Registers the route map, sourced from core's router via `deps.listRoutes`. */
585
- function registerRouteRoutes(server, deps) {
586
- server.get("/api/routes", async () => deps.listRoutes ? deps.listRoutes() : []);
587
- }
588
-
589
- //#endregion
590
- //#region ../../packages/devtools/src/server/stream-route.ts
591
- const PING_INTERVAL_MS = 15e3;
592
- /**
593
- * Registers the SSE stream: one `event: <type>\ndata: <json>\n\n` frame per
594
- * collector event, plus a `: ping` comment every 15s to keep intermediaries
595
- * from closing an idle connection. The reply is hijacked so Fastify never
596
- * tries to serialize or close the response itself.
597
- */
598
- function registerStreamRoute(server, deps) {
599
- server.get("/api/stream", async (request, reply) => {
600
- reply.hijack();
601
- const res = reply.raw;
602
- res.writeHead(200, {
603
- "Content-Type": "text/event-stream",
604
- "Cache-Control": "no-store",
605
- Connection: "keep-alive"
606
- });
607
- const dispose = deps.collector.subscribe((event) => {
608
- res.write(`event: ${event.type}\ndata: ${JSON.stringify(event.data)}\n\n`);
609
- });
610
- const disposeAi = deps.ai?.available ? deps.ai.subscribe((event) => {
611
- res.write(`event: ai\ndata: ${JSON.stringify(event)}\n\n`);
612
- }) : void 0;
613
- const disposeAgentTraces = deps.agentTraces?.subscribe((event) => {
614
- res.write(`event: agent-trace\ndata: ${JSON.stringify(event)}\n\n`);
615
- });
616
- const pingTimer = setInterval(() => res.write(": ping\n\n"), PING_INTERVAL_MS);
617
- pingTimer.unref();
618
- request.raw.on("close", () => {
619
- clearInterval(pingTimer);
620
- dispose();
621
- disposeAi?.();
622
- disposeAgentTraces?.();
623
- });
624
- });
625
- }
626
-
627
- //#endregion
628
- //#region ../../packages/devtools/src/server/index.ts
629
- /**
630
- * Mounts the devtools dashboard and its API under `deps.options.path` on
631
- * `server`. Every route is registered inside a single encapsulated Fastify
632
- * context so the dev-only, loopback-only guard never reaches the app's
633
- * other routes.
634
- */
635
- function mountDevtoolsRoutes(server, deps) {
636
- server.register(async (instance) => {
637
- registerDevtoolsGuard(instance, deps);
638
- instance.setErrorHandler((error, _request, reply) => {
639
- reply.code(error.statusCode ?? 500).send({ error: error.message });
640
- });
641
- registerUiAssets(instance);
642
- registerRequestsRoutes(instance, deps);
643
- registerAiRoutes(instance, deps);
644
- registerBackgroundRoutes(instance, deps);
645
- registerMailRoutes(instance, deps);
646
- registerLogRoutes(instance, deps);
647
- registerRouteRoutes(instance, deps);
648
- registerProcessRoutes(instance, deps);
649
- registerOpenApiRoutes(instance, deps);
650
- registerExplainRoute(instance, deps);
651
- registerStreamRoute(instance, deps);
652
- }, { prefix: deps.options.path });
653
- }
654
-
655
- //#endregion
656
- exports.__exportAll = __exportAll;
657
- exports.mountDevtoolsRoutes = mountDevtoolsRoutes;
658
- //# sourceMappingURL=server-BlQshJLE.cjs.map