@warlock.js/devtools 5.55.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 (234) hide show
  1. package/CHANGELOG.md +29 -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-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-Xwm3Eel9.cjs → src-Ce-3Lniv.cjs} +163 -295
  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 -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 +3 -2
  55. package/esm/options.mjs +2 -1
  56. package/esm/options.mjs.map +1 -1
  57. package/esm/panels.mjs +50 -5
  58. package/esm/panels.mjs.map +1 -1
  59. package/esm/production/auth/common-passwords.mjs +303 -0
  60. package/esm/production/auth/common-passwords.mjs.map +1 -0
  61. package/esm/production/auth/default-crypto.mjs +19 -0
  62. package/esm/production/auth/default-crypto.mjs.map +1 -0
  63. package/esm/production/auth/helpers.mjs +77 -0
  64. package/esm/production/auth/helpers.mjs.map +1 -0
  65. package/esm/production/auth/index.mjs +6 -0
  66. package/esm/production/auth/passkeys.mjs +96 -0
  67. package/esm/production/auth/passkeys.mjs.map +1 -0
  68. package/esm/production/auth/service.mjs +1166 -0
  69. package/esm/production/auth/service.mjs.map +1 -0
  70. package/esm/production/boot.mjs +138 -0
  71. package/esm/production/boot.mjs.map +1 -0
  72. package/esm/production/capture/dev-stats.mjs +83 -0
  73. package/esm/production/capture/dev-stats.mjs.map +1 -0
  74. package/esm/production/capture/engine.mjs +442 -0
  75. package/esm/production/capture/engine.mjs.map +1 -0
  76. package/esm/production/capture/explain.mjs +271 -0
  77. package/esm/production/capture/explain.mjs.map +1 -0
  78. package/esm/production/capture/filter.mjs +24 -0
  79. package/esm/production/capture/filter.mjs.map +1 -0
  80. package/esm/production/capture/index.mjs +7 -0
  81. package/esm/production/capture/production-capture.mjs +134 -0
  82. package/esm/production/capture/production-capture.mjs.map +1 -0
  83. package/esm/production/capture/redact.mjs +109 -0
  84. package/esm/production/capture/redact.mjs.map +1 -0
  85. package/esm/production/capture/stats-stores.mjs +300 -0
  86. package/esm/production/capture/stats-stores.mjs.map +1 -0
  87. package/esm/production/cli/actions.mjs +151 -0
  88. package/esm/production/cli/actions.mjs.map +1 -0
  89. package/esm/production/cli/index.d.mts +17 -0
  90. package/esm/production/cli/index.d.mts.map +1 -0
  91. package/esm/production/cli/index.mjs +86 -0
  92. package/esm/production/cli/index.mjs.map +1 -0
  93. package/esm/production/contracts.d.mts +592 -0
  94. package/esm/production/contracts.d.mts.map +1 -0
  95. package/esm/production/contracts.mjs +95 -0
  96. package/esm/production/contracts.mjs.map +1 -0
  97. package/esm/production/errors.d.mts +31 -0
  98. package/esm/production/errors.d.mts.map +1 -0
  99. package/esm/production/errors.mjs +142 -0
  100. package/esm/production/errors.mjs.map +1 -0
  101. package/esm/production/http/access.mjs +124 -0
  102. package/esm/production/http/access.mjs.map +1 -0
  103. package/esm/production/http/auth-routes.mjs +280 -0
  104. package/esm/production/http/auth-routes.mjs.map +1 -0
  105. package/esm/production/http/client.mjs +57 -0
  106. package/esm/production/http/client.mjs.map +1 -0
  107. package/esm/production/http/constants.mjs +11 -0
  108. package/esm/production/http/constants.mjs.map +1 -0
  109. package/esm/production/http/context.mjs +14 -0
  110. package/esm/production/http/context.mjs.map +1 -0
  111. package/esm/production/http/cookie.mjs +39 -0
  112. package/esm/production/http/cookie.mjs.map +1 -0
  113. package/esm/production/http/headers.mjs +25 -0
  114. package/esm/production/http/headers.mjs.map +1 -0
  115. package/esm/production/http/index.mjs +10 -0
  116. package/esm/production/http/ip.mjs +130 -0
  117. package/esm/production/http/ip.mjs.map +1 -0
  118. package/esm/production/http/mount.mjs +300 -0
  119. package/esm/production/http/mount.mjs.map +1 -0
  120. package/esm/production/http/state.mjs +54 -0
  121. package/esm/production/http/state.mjs.map +1 -0
  122. package/esm/production/index.d.mts +6 -0
  123. package/esm/production/index.mjs +5 -0
  124. package/esm/production/insights/cap-report.mjs +67 -0
  125. package/esm/production/insights/cap-report.mjs.map +1 -0
  126. package/esm/production/insights/health.mjs +88 -0
  127. package/esm/production/insights/health.mjs.map +1 -0
  128. package/esm/production/insights/index.mjs +10 -0
  129. package/esm/production/insights/insights.mjs +167 -0
  130. package/esm/production/insights/insights.mjs.map +1 -0
  131. package/esm/production/insights/instance.mjs +24 -0
  132. package/esm/production/insights/instance.mjs.map +1 -0
  133. package/esm/production/insights/jobs.mjs +100 -0
  134. package/esm/production/insights/jobs.mjs.map +1 -0
  135. package/esm/production/insights/reporter.mjs +59 -0
  136. package/esm/production/insights/reporter.mjs.map +1 -0
  137. package/esm/production/insights/resources.mjs +139 -0
  138. package/esm/production/insights/resources.mjs.map +1 -0
  139. package/esm/production/insights/writer.mjs +72 -0
  140. package/esm/production/insights/writer.mjs.map +1 -0
  141. package/esm/production/openapi.mjs +52 -0
  142. package/esm/production/openapi.mjs.map +1 -0
  143. package/esm/production/options.d.mts +60 -0
  144. package/esm/production/options.d.mts.map +1 -0
  145. package/esm/production/options.mjs +170 -0
  146. package/esm/production/options.mjs.map +1 -0
  147. package/esm/production/stats/histogram.mjs +67 -0
  148. package/esm/production/stats/histogram.mjs.map +1 -0
  149. package/esm/production/stats/merge.mjs +106 -0
  150. package/esm/production/stats/merge.mjs.map +1 -0
  151. package/esm/production/store/cascade-store.mjs +322 -0
  152. package/esm/production/store/cascade-store.mjs.map +1 -0
  153. package/esm/production/store/index.mjs +5 -0
  154. package/esm/production/store/mapping.mjs +258 -0
  155. package/esm/production/store/mapping.mjs.map +1 -0
  156. package/esm/production/store/memory-store.mjs +291 -0
  157. package/esm/production/store/memory-store.mjs.map +1 -0
  158. package/esm/production/store/migrations.d.mts +11 -0
  159. package/esm/production/store/migrations.d.mts.map +1 -0
  160. package/esm/production/store/migrations.mjs +29 -0
  161. package/esm/production/store/migrations.mjs.map +1 -0
  162. package/esm/production/store/models/account.migration.mjs +34 -0
  163. package/esm/production/store/models/account.migration.mjs.map +1 -0
  164. package/esm/production/store/models/account.model.mjs +13 -0
  165. package/esm/production/store/models/account.model.mjs.map +1 -0
  166. package/esm/production/store/models/audit.migration.mjs +30 -0
  167. package/esm/production/store/models/audit.migration.mjs.map +1 -0
  168. package/esm/production/store/models/audit.model.mjs +13 -0
  169. package/esm/production/store/models/audit.model.mjs.map +1 -0
  170. package/esm/production/store/models/base.mjs +27 -0
  171. package/esm/production/store/models/base.mjs.map +1 -0
  172. package/esm/production/store/models/index.mjs +17 -0
  173. package/esm/production/store/models/invite.migration.mjs +26 -0
  174. package/esm/production/store/models/invite.migration.mjs.map +1 -0
  175. package/esm/production/store/models/invite.model.mjs +13 -0
  176. package/esm/production/store/models/invite.model.mjs.map +1 -0
  177. package/esm/production/store/models/report.migration.mjs +20 -0
  178. package/esm/production/store/models/report.migration.mjs.map +1 -0
  179. package/esm/production/store/models/report.model.mjs +13 -0
  180. package/esm/production/store/models/report.model.mjs.map +1 -0
  181. package/esm/production/store/models/sample.migration.mjs +25 -0
  182. package/esm/production/store/models/sample.migration.mjs.map +1 -0
  183. package/esm/production/store/models/sample.model.mjs +13 -0
  184. package/esm/production/store/models/sample.model.mjs.map +1 -0
  185. package/esm/production/store/models/session.migration.mjs +31 -0
  186. package/esm/production/store/models/session.migration.mjs.map +1 -0
  187. package/esm/production/store/models/session.model.mjs +13 -0
  188. package/esm/production/store/models/session.model.mjs.map +1 -0
  189. package/esm/production/store/models/state.migration.mjs +26 -0
  190. package/esm/production/store/models/state.migration.mjs.map +1 -0
  191. package/esm/production/store/models/state.model.mjs +13 -0
  192. package/esm/production/store/models/state.model.mjs.map +1 -0
  193. package/esm/query-shape.mjs +14 -1
  194. package/esm/query-shape.mjs.map +1 -1
  195. package/esm/server/explain-route.mjs +26 -1
  196. package/esm/server/explain-route.mjs.map +1 -1
  197. package/esm/server/index.mjs +9 -4
  198. package/esm/server/index.mjs.map +1 -1
  199. package/esm/server/insights-routes.mjs +62 -0
  200. package/esm/server/insights-routes.mjs.map +1 -0
  201. package/esm/server/log-routes.mjs +32 -5
  202. package/esm/server/log-routes.mjs.map +1 -1
  203. package/esm/server/openapi-routes.mjs +3 -2
  204. package/esm/server/openapi-routes.mjs.map +1 -1
  205. package/esm/server/requests-routes.mjs +125 -0
  206. package/esm/server/requests-routes.mjs.map +1 -1
  207. package/esm/server/session-routes.mjs +42 -0
  208. package/esm/server/session-routes.mjs.map +1 -0
  209. package/esm/server/stream-route.mjs +81 -11
  210. package/esm/server/stream-route.mjs.map +1 -1
  211. package/esm/server/ui-assets.mjs +34 -25
  212. package/esm/server/ui-assets.mjs.map +1 -1
  213. package/esm/sources/log-source.mjs +14 -1
  214. package/esm/sources/log-source.mjs.map +1 -1
  215. package/esm/types.d.mts +202 -1
  216. package/esm/types.d.mts.map +1 -1
  217. package/esm/ui-root.mjs +9 -4
  218. package/esm/ui-root.mjs.map +1 -1
  219. package/llms-full.txt +159 -21
  220. package/llms.txt +2 -2
  221. package/package.json +32 -8
  222. package/skills/SKILL.md +159 -21
  223. package/ui/dashboard/assets/app.css +3 -0
  224. package/ui/dashboard/assets/app.js +50 -0
  225. package/ui/dashboard/build-info.json +21 -0
  226. package/ui/dashboard/index.html +15 -0
  227. package/cjs/ai-source-Dz_3tlZ5.cjs +0 -703
  228. package/cjs/ai-source-Dz_3tlZ5.cjs.map +0 -1
  229. package/cjs/server-B11ShQYE.cjs +0 -628
  230. package/cjs/server-B11ShQYE.cjs.map +0 -1
  231. package/cjs/src-Xwm3Eel9.cjs.map +0 -1
  232. package/ui/app.css +0 -376
  233. package/ui/app.js +0 -1158
  234. package/ui/index.html +0 -28
package/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ All notable changes to `@warlock.js/devtools` are documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
6
6
 
7
+ ## 5.56.0 - 2026-11-17
8
+
9
+ ### Upgrading
10
+
11
+ - The dashboard is now a React app and replaces `ui/app.js`. Panel view modules keep working unchanged. Styles of a view that relied on the old dashboard's CSS classes may look different.
12
+ - These panel ids are now reserved: `resources`, `health`, `errors`, `jobs`, `instances`, `auth`, `account` and `admin`. A panel that uses one is left out with a message.
13
+ - The production monitor is opt-in. Nothing changes until you set `production.enabled`. To use it, install `@warlock.js/devtools` as a regular dependency, add `devtoolsConnector()`, `devtoolsMigrations` and `registerDevtoolsCommands()` to `warlock.config.ts`, run `warlock migrate`, and set `DEVTOOLS_PATH` and the first admin in the environment. See "Devtools in production" in the docs.
14
+ - `GET api/logs` rows now carry `instance` and `requestId`.
15
+ - `GET <path>` without a trailing slash now redirects to `<path>/` in development too.
16
+
17
+ ### Added
18
+
19
+ - Production monitor: a dashboard at a secret path that answers your app's own 404 to anyone who is not signed in. It has its own accounts (admin and viewer roles) stored through Cascade, forced password change, authenticator-app and passkey two-factor, recovery codes, invite links, sign-in rate limits, an audit log, and a switch to disable it from the dashboard. It refuses to start without a path, a first admin and an encryption key (`DT001` to `DT010`). A correct password does not reset the failed-try count (only a completed sign-in does), the per-IP limit counts an IPv6 client by its /64, and a caller over the IP limit costs no password check. Adding or removing an authenticator app or a passkey, and making new recovery codes, asks for the current password or a fresh passkey check.
20
+ - Production capture: sampled requests, query shapes, routes, error groups and warn and error logs are kept per process with bounded memory and written to the database as redacted samples (shapes only, never values). Request errors and `error` log lines lose quoted values, emails and `{ … }` documents before they are grouped, stored or shown, and a request that fails in a handler shows its message and stack in the Errors tab. Slow and failed requests outside the sample are kept as summaries. At the default sample rate the added cost is about 1.3 µs per request.
21
+ - Several instances share one view: each process writes a report, and the dashboard merges them with an instance picker.
22
+ - EXPLAIN by query shape: plain `EXPLAIN` for PostgreSQL reads and `queryPlanner` for MongoDB reads. Executing plans run only with `explain.executing: true`, and never for statements that write. PostgreSQL plans run in a read-only transaction that is rolled back, a MongoDB aggregate with `$out` or `$merge` is never explained, and production plans show `?` in place of the query's values.
23
+ - New tabs: Resources (memory, CPU, event loop, garbage collection), Health, Errors and Jobs. Queries and Routes show latency statistics with histograms, in development too.
24
+ - `warlock devtools:enable` and `warlock devtools:reset-admin` (`registerDevtoolsCommands()`), and `devtoolsMigrations`, from `@warlock.js/devtools/production`.
25
+ - Error groups group log lines that carry a request id, and the Health tab records no error while the app boots.
26
+ - Panels can set `production: true`, and the panel factory receives `mode` (`"development"` or `"production"`). In production a panel's GET routes need a signed-in user, and every other method needs an admin, the CSRF header, and is written to the audit log.
27
+
28
+ ### Changed
29
+
30
+ - The dashboard tabs are rebuilt in React with the same features: requests with filters, waterfall, EXPLAIN and curl, queries, routes, logs, mail, AI runs, agent traces and API docs. The API docs tab works under `warlock start` (it builds the OpenAPI document from the registered routes). The dashboard shell loads in apps that drop a trailing slash before routing, its Content-Security-Policy replaces the app's own, an unknown asset under the dashboard path answers the app's own 404, and a dashboard error is logged with the route relative to the dashboard path.
31
+ - The live stream sends `retry` and `hello` first, and request and log events carry `instance`.
32
+ - Query shapes drop dollar-quoted strings.
33
+ - In development, a value logged as the message (such as an Error) shows as text, and a tab that fails to draw no longer blanks the dashboard.
34
+ - The server answers 503 with a build hint when `ui/dashboard/` is missing.
35
+
7
36
  ## 5.55.0 - 2026-11-17
8
37
 
9
38
  ### Added
package/README.md CHANGED
@@ -1,14 +1,19 @@
1
1
  # @warlock.js/devtools
2
2
 
3
- A development-only dashboard for Warlock.js apps, served at `/__warlock`:
3
+ A dashboard for Warlock.js apps. It runs in two modes:
4
+
5
+ - **Development**: served at `/__warlock`, for loopback clients only, with no sign-in.
6
+ - **Production monitor**: opt-in, served at a secret path behind accounts and two-factor sign-in.
7
+
8
+ It shows:
4
9
 
5
10
  - a **request timeline**: router and page middleware, loaders, page cache, render and deferred values;
6
- - every **SQL and Mongo query**, with `EXPLAIN` for Postgres;
11
+ - every **SQL and Mongo query**, with `EXPLAIN`, and per-shape statistics;
7
12
  - **N+1 warnings** that name the file and line;
8
- - a **dev mailbox** with every mail your app sent;
9
- - **logs**, **cache operations** and the **route map**.
13
+ - **routes**, **errors**, **logs**, **resources**, **health** and **jobs**;
14
+ - a **dev mailbox**, **cache operations**, and AI and agent traces in development.
10
15
 
11
- ## Install
16
+ ## Install for development
12
17
 
13
18
  ```bash
14
19
  warlock add devtools
@@ -16,17 +21,25 @@ warlock dev
16
21
  # open http://localhost:<port>/__warlock
17
22
  ```
18
23
 
19
- That's all: `warlock dev` loads it automatically. Don't add it to
20
- `warlock.config.ts`; it's a dev dependency, so a production install doesn't
21
- have it.
24
+ `warlock dev` loads it automatically. In development, nothing needs configuring.
25
+
26
+ ## Production in five lines
27
+
28
+ 1. Install it as a regular dependency: `npm install @warlock.js/devtools`.
29
+ 2. Add `devtoolsConnector()`, `registerDevtoolsCommands()` and `devtoolsMigrations` to `warlock.config.ts`
30
+ (from `@warlock.js/devtools` and `@warlock.js/devtools/production`), then run `warlock migrate`.
31
+ 3. Set `production: { enabled: true }` in `src/config/devtools.ts`.
32
+ 4. Set `DEVTOOLS_PATH`, `DEVTOOLS_ADMIN_EMAIL` and `DEVTOOLS_ADMIN_PASSWORD` (or `DEVTOOLS_SETUP_TOKEN`) in the environment.
33
+ 5. Open `https://<your-app><DEVTOOLS_PATH>/` and sign in.
34
+
35
+ Without `production.enabled`, nothing is mounted and nothing is captured. The app refuses to start when the monitor
36
+ is enabled but misconfigured. Full guide: https://warlock.js.org/v/latest/devtools/production/
22
37
 
23
38
  ## Safe by construction
24
39
 
25
- - It isn't installed in production (it's a dev dependency).
26
- - If it is present anyway, it refuses to run outside development.
27
- - It answers loopback clients only. Anything else gets a 404, and
28
- `X-Forwarded-For` can't unlock it.
29
- - Everything lives in memory, and nothing is written to disk.
40
+ - In development it answers loopback clients only. Anything else gets a 404, and `X-Forwarded-For` cannot unlock it.
41
+ - In production it is off until you enable it, answers a plain 404 to anyone without a session, and removes
42
+ request values before anything is stored.
30
43
 
31
44
  Full guide: [`skills/SKILL.md`](skills/SKILL.md).
32
45
 
@@ -0,0 +1,381 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-Zuuoy_Rh.cjs");
2
+ let node_fs = require("node:fs");
3
+ let node_path = require("node:path");
4
+ node_path = require_rolldown_runtime.__toESM(node_path, 1);
5
+ let node_url = require("node:url");
6
+
7
+ //#region ../../packages/devtools/src/ui-root.ts
8
+ let cachedUiRoot;
9
+ /**
10
+ * Whether `dir` is this package's root: it has the built dashboard
11
+ * (`ui/dashboard/index.html`) or, before the first build, the Processes panel
12
+ * view (`ui/panels/processes.js`), beside a `package.json` named
13
+ * `@warlock.js/devtools`.
14
+ */
15
+ function isPackageRoot(dir) {
16
+ const hasUi = (0, node_fs.existsSync)(node_path.default.join(dir, "ui", "dashboard", "index.html")) || (0, node_fs.existsSync)(node_path.default.join(dir, "ui", "panels", "processes.js"));
17
+ const packageJson = node_path.default.join(dir, "package.json");
18
+ if (!hasUi || !(0, node_fs.existsSync)(packageJson)) return false;
19
+ try {
20
+ return JSON.parse((0, node_fs.readFileSync)(packageJson, "utf8")).name === "@warlock.js/devtools";
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * Locate this package's `ui/` directory by walking up from the current
27
+ * module's directory. Works from `src/` in development and from the built
28
+ * `esm/`/`cjs/` output, since both sit beside `ui/` and `package.json` at
29
+ * the package root.
30
+ */
31
+ function resolveUiRoot() {
32
+ if (cachedUiRoot) return cachedUiRoot;
33
+ let dir = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
34
+ while (true) {
35
+ if (isPackageRoot(dir)) {
36
+ cachedUiRoot = node_path.default.join(dir, "ui");
37
+ return cachedUiRoot;
38
+ }
39
+ const parent = node_path.default.dirname(dir);
40
+ if (parent === dir) throw new Error("Could not locate the devtools UI directory: no ancestor of this module has ui/dashboard/index.html or ui/panels/processes.js beside a package.json named @warlock.js/devtools.");
41
+ dir = parent;
42
+ }
43
+ }
44
+
45
+ //#endregion
46
+ //#region ../../packages/devtools/src/sources/agent-trace-source.ts
47
+ /**
48
+ * Key `@warlock.js/ai` publishes its agent trace store under on
49
+ * `globalThis`. Reading the store from the registry, not by importing the
50
+ * package, keeps devtools free of an AI dependency and shares one store
51
+ * even when two copies of the package are installed.
52
+ */
53
+ const AGENT_TRACES_KEY = Symbol.for("@warlock.js/ai.agentTraces");
54
+ const AGENT_TRACE_INSTALL_GUIDANCE = "No agent traces yet. Install @warlock.js/ai 5.38 or newer and run an agent in development (agents record traces by default there; `trace: true` turns it on elsewhere), then reload.";
55
+ /** One list row for a trace. */
56
+ function summarizeAgentTrace(trace, requestId) {
57
+ let toolCalls = 0;
58
+ let refusals = 0;
59
+ for (const turn of trace.turns) {
60
+ toolCalls += turn.toolCalls.length;
61
+ refusals += turn.toolCalls.filter((call) => call.refusal !== void 0).length;
62
+ }
63
+ return {
64
+ runId: trace.runId,
65
+ agent: trace.agent,
66
+ status: trace.status,
67
+ startedAt: trace.startedAt,
68
+ durationMs: trace.durationMs,
69
+ model: `${trace.model.provider}/${trace.model.name}`,
70
+ turns: trace.turns.length,
71
+ toolCalls,
72
+ refusals,
73
+ usage: {
74
+ input: trace.usage.input,
75
+ output: trace.usage.output
76
+ },
77
+ cost: trace.cost,
78
+ ...requestId ? { requestId } : {}
79
+ };
80
+ }
81
+ const MAX_REQUEST_LINKS = 500;
82
+ /**
83
+ * Attach to the shared agent trace store. The store is looked up lazily on
84
+ * every call, so it works whichever of devtools and `@warlock.js/ai` loads
85
+ * first. Runs are linked to the HTTP request that was active when the
86
+ * store first reported them.
87
+ */
88
+ async function attachAgentTraceSource() {
89
+ const { currentRequestId } = await Promise.resolve().then(() => require("./current-request-id-BoJJb3y7.cjs")).then((n) => n.current_request_id_exports);
90
+ const listeners = /* @__PURE__ */ new Set();
91
+ const requestIds = /* @__PURE__ */ new Map();
92
+ let attachedStore;
93
+ let detach;
94
+ const findStore = () => {
95
+ const store = globalThis[AGENT_TRACES_KEY];
96
+ return store && typeof store.list === "function" ? store : void 0;
97
+ };
98
+ const ensureAttached = () => {
99
+ const store = findStore();
100
+ if (store && store !== attachedStore) {
101
+ detach?.();
102
+ attachedStore = store;
103
+ detach = store.subscribe((event) => {
104
+ let requestId = requestIds.get(event.runId);
105
+ if (!requestId) {
106
+ requestId = currentRequestId();
107
+ if (requestId) {
108
+ requestIds.set(event.runId, requestId);
109
+ if (requestIds.size > MAX_REQUEST_LINKS) {
110
+ const oldest = requestIds.keys().next();
111
+ if (!oldest.done) requestIds.delete(oldest.value);
112
+ }
113
+ }
114
+ }
115
+ for (const listener of listeners) try {
116
+ listener({
117
+ ...event,
118
+ ...requestId ? { requestId } : {}
119
+ });
120
+ } catch {}
121
+ });
122
+ }
123
+ return store;
124
+ };
125
+ ensureAttached();
126
+ return {
127
+ available: () => ensureAttached() !== void 0,
128
+ list(filter) {
129
+ const store = ensureAttached();
130
+ if (!store) return [];
131
+ return store.list().map((trace) => summarizeAgentTrace(trace, requestIds.get(trace.runId))).filter((run) => filter?.requestId === void 0 || run.requestId === filter.requestId);
132
+ },
133
+ get: (runId) => ensureAttached()?.get(runId),
134
+ subscribe(listener) {
135
+ ensureAttached();
136
+ listeners.add(listener);
137
+ return () => {
138
+ listeners.delete(listener);
139
+ };
140
+ },
141
+ dispose() {
142
+ detach?.();
143
+ detach = void 0;
144
+ attachedStore = void 0;
145
+ listeners.clear();
146
+ requestIds.clear();
147
+ }
148
+ };
149
+ }
150
+
151
+ //#endregion
152
+ //#region ../../packages/devtools/src/safe-value.ts
153
+ const MAX_DEPTH = 6;
154
+ /**
155
+ * A JSON-safe snapshot of a value devtools keeps for later display.
156
+ *
157
+ * Log contexts and phase attributes are app data: they can hold live objects
158
+ * (a request, its socket) whose graphs are circular and which must not be kept
159
+ * alive by the collector anyway. Plain objects and arrays are copied; anything
160
+ * with a `toJSON()` is serialized through it; other class instances collapse
161
+ * to `[ClassName]`, cycles to `[Circular]`, and nesting past a fixed depth to
162
+ * `[Object]` / `[Array]`.
163
+ */
164
+ function toSafeValue(value) {
165
+ return snapshot(value, 0, /* @__PURE__ */ new WeakSet());
166
+ }
167
+ function snapshot(value, depth, seen) {
168
+ if (value === null || value === void 0) return value;
169
+ switch (typeof value) {
170
+ case "string":
171
+ case "number":
172
+ case "boolean": return value;
173
+ case "bigint": return value.toString();
174
+ case "symbol": return value.toString();
175
+ case "function": return;
176
+ }
177
+ const object = value;
178
+ if (seen.has(object)) return "[Circular]";
179
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
180
+ if (value instanceof Error) return {
181
+ name: value.name,
182
+ message: value.message
183
+ };
184
+ if (depth >= MAX_DEPTH) return Array.isArray(value) ? "[Array]" : "[Object]";
185
+ seen.add(object);
186
+ try {
187
+ if (Array.isArray(value)) return value.map((item) => snapshot(item, depth + 1, seen));
188
+ const prototype = Object.getPrototypeOf(object);
189
+ if (prototype !== Object.prototype && prototype !== null) {
190
+ const toJSON = object.toJSON;
191
+ if (typeof toJSON === "function") try {
192
+ return snapshot(toJSON.call(object), depth + 1, seen);
193
+ } catch {
194
+ return `[${constructorName(object)}]`;
195
+ }
196
+ return `[${constructorName(object)}]`;
197
+ }
198
+ const copy = {};
199
+ for (const [key, entry] of Object.entries(object)) {
200
+ const safe = snapshot(entry, depth + 1, seen);
201
+ if (safe !== void 0) copy[key] = safe;
202
+ }
203
+ return copy;
204
+ } finally {
205
+ seen.delete(object);
206
+ }
207
+ }
208
+ function constructorName(object) {
209
+ return object.constructor?.name || "Object";
210
+ }
211
+
212
+ //#endregion
213
+ //#region ../../packages/devtools/src/sources/ai-source.ts
214
+ const AI_INSTALL_GUIDANCE = "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.";
215
+ /** Summaries use root usage once: nested spans already roll up into it. */
216
+ function summarizeAiTrace(trace, cost) {
217
+ const models = /* @__PURE__ */ new Set();
218
+ let toolCalls = 0;
219
+ let retries = 0;
220
+ let cacheHits;
221
+ let incomplete = false;
222
+ let truncatedTrips = 0;
223
+ let compactions = 0;
224
+ let skippedCompactions = 0;
225
+ let providerCompactions = 0;
226
+ const visit = (span) => {
227
+ const attributes = span.attributes ?? {};
228
+ const model = attributes["agent.model.name"];
229
+ const provider = attributes["agent.model.provider"];
230
+ if (typeof model === "string") models.add(typeof provider === "string" ? `${provider}/${model}` : model);
231
+ if (span.type === "tool") toolCalls += 1;
232
+ if (typeof attributes.retries === "number") retries += attributes.retries;
233
+ if (typeof attributes["agent.cacheHits"] === "number") cacheHits = (cacheHits ?? 0) + attributes["agent.cacheHits"];
234
+ if (typeof attributes["agent.truncatedTrips"] === "number") truncatedTrips += attributes["agent.truncatedTrips"];
235
+ if (typeof attributes["agent.providerCompactions"] === "number") providerCompactions += attributes["agent.providerCompactions"];
236
+ if (Array.isArray(attributes["agent.compactions"])) {
237
+ const records = attributes["agent.compactions"];
238
+ for (const record of records) {
239
+ if (typeof record !== "object" || record === null || !("type" in record)) continue;
240
+ if (record.type === "applied") compactions += 1;
241
+ if (record.type === "skipped") skippedCompactions += 1;
242
+ }
243
+ }
244
+ incomplete ||= span.status === "incomplete" || span.error?.type === "AgentIncompleteError" || span.error?.type === "AGENT_INCOMPLETE";
245
+ span.children.forEach(visit);
246
+ };
247
+ visit(trace.root);
248
+ return {
249
+ traceId: trace.traceId,
250
+ requestId: trace.requestId,
251
+ sessionId: trace.sessionId,
252
+ name: trace.root.name,
253
+ status: trace.root.status,
254
+ startedAt: trace.startedAt,
255
+ duration: trace.duration,
256
+ usage: trace.usage,
257
+ cost,
258
+ models: [...models],
259
+ toolCalls,
260
+ retries,
261
+ cacheHits,
262
+ incomplete,
263
+ truncatedTrips,
264
+ compactions,
265
+ skippedCompactions,
266
+ providerCompactions
267
+ };
268
+ }
269
+ /** Content-free snapshot; never retain prompts, completions or tool arguments/results. */
270
+ function snapshotSpan(span) {
271
+ return {
272
+ spanId: span.spanId,
273
+ parentSpanId: span.parentSpanId,
274
+ traceId: span.traceId,
275
+ sessionId: span.sessionId,
276
+ name: span.name,
277
+ version: span.version,
278
+ type: span.type,
279
+ status: span.status,
280
+ startedAt: span.startedAt,
281
+ endedAt: span.endedAt,
282
+ duration: span.duration,
283
+ usage: structuredClone(span.usage),
284
+ error: span.error ? {
285
+ type: span.error.type,
286
+ message: span.error.message
287
+ } : void 0,
288
+ attributes: toSafeValue(span.attributes),
289
+ children: span.children.map(snapshotSpan)
290
+ };
291
+ }
292
+ /**
293
+ * Optional, lazy integration. Retains only traces collected after devtools boots,
294
+ * using Panoptic's bounded query store; existing exporter/cache stores stay independent.
295
+ */
296
+ async function attachAiSource(capacity) {
297
+ let panoptic;
298
+ try {
299
+ panoptic = await import("@warlock.js/ai-panoptic");
300
+ if (typeof panoptic.subscribeTraces !== "function") throw new Error("Trace subscription unavailable");
301
+ } catch {
302
+ return {
303
+ available: false,
304
+ message: AI_INSTALL_GUIDANCE,
305
+ dispose() {}
306
+ };
307
+ }
308
+ const { currentRequestId } = await Promise.resolve().then(() => require("./current-request-id-BoJJb3y7.cjs")).then((n) => n.current_request_id_exports);
309
+ const store = panoptic.createInMemoryTraceStore({ capacity });
310
+ const listeners = /* @__PURE__ */ new Set();
311
+ const detach = panoptic.subscribeTraces((trace) => {
312
+ const requestId = currentRequestId() ?? trace.requestId;
313
+ store.add({
314
+ ...trace,
315
+ requestId,
316
+ usage: structuredClone(trace.usage),
317
+ root: snapshotSpan(trace.root)
318
+ });
319
+ for (const listener of listeners) try {
320
+ listener({
321
+ traceId: trace.traceId,
322
+ requestId
323
+ });
324
+ } catch {}
325
+ });
326
+ return {
327
+ available: true,
328
+ store,
329
+ summarize: (trace) => summarizeAiTrace(trace, panoptic.totalCostUsd(trace.usage)),
330
+ subscribe(listener) {
331
+ listeners.add(listener);
332
+ return () => {
333
+ listeners.delete(listener);
334
+ };
335
+ },
336
+ dispose() {
337
+ detach();
338
+ listeners.clear();
339
+ store.clear();
340
+ }
341
+ };
342
+ }
343
+
344
+ //#endregion
345
+ Object.defineProperty(exports, "AGENT_TRACE_INSTALL_GUIDANCE", {
346
+ enumerable: true,
347
+ get: function () {
348
+ return AGENT_TRACE_INSTALL_GUIDANCE;
349
+ }
350
+ });
351
+ Object.defineProperty(exports, "AI_INSTALL_GUIDANCE", {
352
+ enumerable: true,
353
+ get: function () {
354
+ return AI_INSTALL_GUIDANCE;
355
+ }
356
+ });
357
+ Object.defineProperty(exports, "attachAgentTraceSource", {
358
+ enumerable: true,
359
+ get: function () {
360
+ return attachAgentTraceSource;
361
+ }
362
+ });
363
+ Object.defineProperty(exports, "attachAiSource", {
364
+ enumerable: true,
365
+ get: function () {
366
+ return attachAiSource;
367
+ }
368
+ });
369
+ Object.defineProperty(exports, "resolveUiRoot", {
370
+ enumerable: true,
371
+ get: function () {
372
+ return resolveUiRoot;
373
+ }
374
+ });
375
+ Object.defineProperty(exports, "toSafeValue", {
376
+ enumerable: true,
377
+ get: function () {
378
+ return toSafeValue;
379
+ }
380
+ });
381
+ //# sourceMappingURL=ai-source-DTpxumMA.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-source-DTpxumMA.cjs","names":["existsSync","path","readFileSync","fileURLToPath"],"sources":["../../../../../../../packages/devtools/src/ui-root.ts","../../../../../../../packages/devtools/src/sources/agent-trace-source.ts","../../../../../../../packages/devtools/src/safe-value.ts","../../../../../../../packages/devtools/src/sources/ai-source.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nlet cachedUiRoot: string | undefined;\n\n/**\n * Whether `dir` is this package's root: it has the built dashboard\n * (`ui/dashboard/index.html`) or, before the first build, the Processes panel\n * view (`ui/panels/processes.js`), beside a `package.json` named\n * `@warlock.js/devtools`.\n */\nfunction isPackageRoot(dir: string): boolean {\n const hasUi =\n existsSync(path.join(dir, \"ui\", \"dashboard\", \"index.html\")) ||\n existsSync(path.join(dir, \"ui\", \"panels\", \"processes.js\"));\n const packageJson = path.join(dir, \"package.json\");\n\n if (!hasUi || !existsSync(packageJson)) {\n return false;\n }\n\n try {\n const parsed = JSON.parse(readFileSync(packageJson, \"utf8\")) as { name?: string };\n return parsed.name === \"@warlock.js/devtools\";\n } catch {\n return false;\n }\n}\n\n/**\n * Locate this package's `ui/` directory by walking up from the current\n * module's directory. Works from `src/` in development and from the built\n * `esm/`/`cjs/` output, since both sit beside `ui/` and `package.json` at\n * the package root.\n */\nexport function resolveUiRoot(): string {\n if (cachedUiRoot) {\n return cachedUiRoot;\n }\n\n let dir = path.dirname(fileURLToPath(import.meta.url));\n\n while (true) {\n if (isPackageRoot(dir)) {\n cachedUiRoot = path.join(dir, \"ui\");\n return cachedUiRoot;\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) {\n throw new Error(\n \"Could not locate the devtools UI directory: no ancestor of \" +\n \"this module has ui/dashboard/index.html or ui/panels/processes.js beside a package.json named \" +\n \"@warlock.js/devtools.\",\n );\n }\n\n dir = parent;\n }\n}\n","import type { DevtoolsDisposer } from \"../types\";\n\n/**\n * Key `@warlock.js/ai` publishes its agent trace store under on\n * `globalThis`. Reading the store from the registry, not by importing the\n * package, keeps devtools free of an AI dependency and shares one store\n * even when two copies of the package are installed.\n */\nexport const AGENT_TRACES_KEY = Symbol.for(\"@warlock.js/ai.agentTraces\");\n\nexport const AGENT_TRACE_INSTALL_GUIDANCE =\n \"No agent traces yet. Install @warlock.js/ai 5.38 or newer and run an agent in development (agents record traces by default there; `trace: true` turns it on elsewhere), then reload.\";\n\n/** The part of `@warlock.js/ai`'s `AgentTrace` this panel reads; the rest passes through untouched. */\nexport type DevtoolsAgentTrace = {\n runId: string;\n agent: string;\n status: string;\n startedAt: string;\n durationMs?: number;\n model: { name: string; provider: string };\n usage: { input: number; output: number; total: number };\n cost?: number;\n turns: Array<{ toolCalls: Array<{ refusal?: string }> }>;\n};\n\n/** The part of `@warlock.js/ai`'s `AgentTraceStore` devtools uses. */\nexport type DevtoolsAgentTraceStore = {\n get(runId: string): DevtoolsAgentTrace | undefined;\n list(filter?: { limit?: number }): DevtoolsAgentTrace[];\n subscribe(listener: (event: { runId: string; status: string }) => void): () => void;\n};\n\nexport type DevtoolsAgentTraceEvent = { runId: string; status: string; requestId?: string };\n\n/** One row of the run list. */\nexport type DevtoolsAgentRun = {\n runId: string;\n agent: string;\n status: string;\n startedAt: string;\n durationMs?: number;\n model: string;\n turns: number;\n toolCalls: number;\n refusals: number;\n usage: { input: number; output: number };\n cost?: number;\n requestId?: string;\n};\n\n/** Reads agent traces from the shared store; the connector builds one in development only. */\nexport type DevtoolsAgentTraceSource = {\n /** `false` until `@warlock.js/ai` has created its store in this process. */\n available(): boolean;\n list(filter?: { requestId?: string }): DevtoolsAgentRun[];\n get(runId: string): DevtoolsAgentTrace | undefined;\n subscribe(listener: (event: DevtoolsAgentTraceEvent) => void): DevtoolsDisposer;\n dispose: DevtoolsDisposer;\n};\n\n/** One list row for a trace. */\nexport function summarizeAgentTrace(\n trace: DevtoolsAgentTrace,\n requestId?: string,\n): DevtoolsAgentRun {\n let toolCalls = 0;\n let refusals = 0;\n\n for (const turn of trace.turns) {\n toolCalls += turn.toolCalls.length;\n refusals += turn.toolCalls.filter((call) => call.refusal !== undefined).length;\n }\n\n return {\n runId: trace.runId,\n agent: trace.agent,\n status: trace.status,\n startedAt: trace.startedAt,\n durationMs: trace.durationMs,\n model: `${trace.model.provider}/${trace.model.name}`,\n turns: trace.turns.length,\n toolCalls,\n refusals,\n usage: { input: trace.usage.input, output: trace.usage.output },\n cost: trace.cost,\n ...(requestId ? { requestId } : {}),\n };\n}\n\nconst MAX_REQUEST_LINKS = 500;\n\n/**\n * Attach to the shared agent trace store. The store is looked up lazily on\n * every call, so it works whichever of devtools and `@warlock.js/ai` loads\n * first. Runs are linked to the HTTP request that was active when the\n * store first reported them.\n */\nexport async function attachAgentTraceSource(): Promise<DevtoolsAgentTraceSource> {\n const { currentRequestId } = await import(\"../current-request-id\");\n const listeners = new Set<(event: DevtoolsAgentTraceEvent) => void>();\n const requestIds = new Map<string, string>();\n let attachedStore: DevtoolsAgentTraceStore | undefined;\n let detach: (() => void) | undefined;\n\n const findStore = (): DevtoolsAgentTraceStore | undefined => {\n const store = (globalThis as { [AGENT_TRACES_KEY]?: DevtoolsAgentTraceStore })[\n AGENT_TRACES_KEY\n ];\n\n return store && typeof store.list === \"function\" ? store : undefined;\n };\n\n const ensureAttached = (): DevtoolsAgentTraceStore | undefined => {\n const store = findStore();\n\n if (store && store !== attachedStore) {\n detach?.();\n attachedStore = store;\n detach = store.subscribe((event) => {\n // Read the request id before anything asynchronous: the store\n // publishes synchronously from inside the agent run.\n let requestId = requestIds.get(event.runId);\n\n if (!requestId) {\n requestId = currentRequestId();\n\n if (requestId) {\n requestIds.set(event.runId, requestId);\n\n if (requestIds.size > MAX_REQUEST_LINKS) {\n const oldest = requestIds.keys().next();\n\n if (!oldest.done) requestIds.delete(oldest.value);\n }\n }\n }\n\n for (const listener of listeners) {\n try {\n listener({ ...event, ...(requestId ? { requestId } : {}) });\n } catch {\n /* isolate clients */\n }\n }\n });\n }\n\n return store;\n };\n\n ensureAttached();\n\n return {\n available: () => ensureAttached() !== undefined,\n\n list(filter) {\n const store = ensureAttached();\n\n if (!store) return [];\n\n return store\n .list()\n .map((trace) => summarizeAgentTrace(trace, requestIds.get(trace.runId)))\n .filter((run) => filter?.requestId === undefined || run.requestId === filter.requestId);\n },\n\n get: (runId) => ensureAttached()?.get(runId),\n\n subscribe(listener) {\n ensureAttached();\n listeners.add(listener);\n\n return () => {\n listeners.delete(listener);\n };\n },\n\n dispose() {\n detach?.();\n detach = undefined;\n attachedStore = undefined;\n listeners.clear();\n requestIds.clear();\n },\n };\n}\n","const MAX_DEPTH = 6;\n\n/**\n * A JSON-safe snapshot of a value devtools keeps for later display.\n *\n * Log contexts and phase attributes are app data: they can hold live objects\n * (a request, its socket) whose graphs are circular and which must not be kept\n * alive by the collector anyway. Plain objects and arrays are copied; anything\n * with a `toJSON()` is serialized through it; other class instances collapse\n * to `[ClassName]`, cycles to `[Circular]`, and nesting past a fixed depth to\n * `[Object]` / `[Array]`.\n */\nexport function toSafeValue(value: unknown): unknown {\n return snapshot(value, 0, new WeakSet());\n}\n\nfunction snapshot(value: unknown, depth: number, seen: WeakSet<object>): unknown {\n if (value === null || value === undefined) return value;\n\n switch (typeof value) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n return value;\n case \"bigint\":\n return value.toString();\n case \"symbol\":\n return value.toString();\n case \"function\":\n return undefined;\n }\n\n const object = value as object;\n\n if (seen.has(object)) return \"[Circular]\";\n if (value instanceof Date)\n return Number.isNaN(value.getTime()) ? \"Invalid Date\" : value.toISOString();\n if (value instanceof Error) return { name: value.name, message: value.message };\n\n if (depth >= MAX_DEPTH) return Array.isArray(value) ? \"[Array]\" : \"[Object]\";\n\n seen.add(object);\n\n try {\n if (Array.isArray(value)) return value.map((item) => snapshot(item, depth + 1, seen));\n\n const prototype = Object.getPrototypeOf(object);\n\n if (prototype !== Object.prototype && prototype !== null) {\n const toJSON = (object as { toJSON?: unknown }).toJSON;\n\n if (typeof toJSON === \"function\") {\n try {\n return snapshot(toJSON.call(object), depth + 1, seen);\n } catch {\n return `[${constructorName(object)}]`;\n }\n }\n\n return `[${constructorName(object)}]`;\n }\n\n const copy: Record<string, unknown> = {};\n\n for (const [key, entry] of Object.entries(object)) {\n const safe = snapshot(entry, depth + 1, seen);\n if (safe !== undefined) copy[key] = safe;\n }\n\n return copy;\n } finally {\n seen.delete(object);\n }\n}\n\nfunction constructorName(object: object): string {\n return (object as { constructor?: { name?: string } }).constructor?.name || \"Object\";\n}\n","import type { Trace, TraceSpan, TraceStoreContract } from \"@warlock.js/ai-panoptic\";\nimport { toSafeValue } from \"../safe-value\";\nimport type { DevtoolsDisposer } from \"../types\";\n\nexport const AI_INSTALL_GUIDANCE =\n \"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.\";\n\nexport type DevtoolsAiEvent = { traceId: string; requestId?: string };\n\n/** Only the connector's development branch constructs this source. */\nexport type DevtoolsAiSource =\n | { available: false; message: string; dispose: DevtoolsDisposer }\n | {\n available: true;\n store: TraceStoreContract;\n summarize: (trace: Trace) => DevtoolsAiRun;\n subscribe: (listener: (event: DevtoolsAiEvent) => void) => DevtoolsDisposer;\n dispose: DevtoolsDisposer;\n };\n\nexport type DevtoolsAiRun = {\n traceId: string;\n requestId?: string;\n sessionId?: string;\n name: string;\n status: TraceSpan[\"status\"];\n startedAt: string;\n duration: number;\n usage: Trace[\"usage\"];\n cost?: number;\n models: string[];\n toolCalls: number;\n retries: number;\n cacheHits?: number;\n incomplete: boolean;\n truncatedTrips: number;\n compactions: number;\n skippedCompactions: number;\n providerCompactions: number;\n};\n\n/** Summaries use root usage once: nested spans already roll up into it. */\nexport function summarizeAiTrace(trace: Trace, cost?: number): DevtoolsAiRun {\n const models = new Set<string>();\n let toolCalls = 0;\n let retries = 0;\n let cacheHits: number | undefined;\n let incomplete = false;\n let truncatedTrips = 0;\n let compactions = 0;\n let skippedCompactions = 0;\n let providerCompactions = 0;\n const visit = (span: TraceSpan): void => {\n const attributes = span.attributes ?? {};\n const model = attributes[\"agent.model.name\"];\n const provider = attributes[\"agent.model.provider\"];\n if (typeof model === \"string\")\n models.add(typeof provider === \"string\" ? `${provider}/${model}` : model);\n if (span.type === \"tool\") toolCalls += 1;\n if (typeof attributes.retries === \"number\") retries += attributes.retries;\n if (typeof attributes[\"agent.cacheHits\"] === \"number\")\n cacheHits = (cacheHits ?? 0) + attributes[\"agent.cacheHits\"];\n if (typeof attributes[\"agent.truncatedTrips\"] === \"number\")\n truncatedTrips += attributes[\"agent.truncatedTrips\"];\n if (typeof attributes[\"agent.providerCompactions\"] === \"number\")\n providerCompactions += attributes[\"agent.providerCompactions\"];\n if (Array.isArray(attributes[\"agent.compactions\"])) {\n const records: unknown[] = attributes[\"agent.compactions\"];\n for (const record of records) {\n if (typeof record !== \"object\" || record === null || !(\"type\" in record)) continue;\n if (record.type === \"applied\") compactions += 1;\n if (record.type === \"skipped\") skippedCompactions += 1;\n }\n }\n incomplete ||=\n span.status === \"incomplete\" ||\n span.error?.type === \"AgentIncompleteError\" ||\n span.error?.type === \"AGENT_INCOMPLETE\";\n span.children.forEach(visit);\n };\n visit(trace.root);\n return {\n traceId: trace.traceId,\n requestId: trace.requestId,\n sessionId: trace.sessionId,\n name: trace.root.name,\n status: trace.root.status,\n startedAt: trace.startedAt,\n duration: trace.duration,\n usage: trace.usage,\n cost,\n models: [...models],\n toolCalls,\n retries,\n cacheHits,\n incomplete,\n truncatedTrips,\n compactions,\n skippedCompactions,\n providerCompactions,\n };\n}\n\n/** Content-free snapshot; never retain prompts, completions or tool arguments/results. */\nfunction snapshotSpan(span: TraceSpan): TraceSpan {\n return {\n spanId: span.spanId,\n parentSpanId: span.parentSpanId,\n traceId: span.traceId,\n sessionId: span.sessionId,\n name: span.name,\n version: span.version,\n type: span.type,\n status: span.status,\n startedAt: span.startedAt,\n endedAt: span.endedAt,\n duration: span.duration,\n usage: structuredClone(span.usage),\n error: span.error ? { type: span.error.type, message: span.error.message } : undefined,\n attributes: toSafeValue(span.attributes) as Record<string, unknown> | undefined,\n children: span.children.map(snapshotSpan),\n };\n}\n\n/**\n * Optional, lazy integration. Retains only traces collected after devtools boots,\n * using Panoptic's bounded query store; existing exporter/cache stores stay independent.\n */\nexport async function attachAiSource(capacity: number): Promise<DevtoolsAiSource> {\n let panoptic: typeof import(\"@warlock.js/ai-panoptic\");\n try {\n panoptic = await import(\"@warlock.js/ai-panoptic\");\n if (typeof panoptic.subscribeTraces !== \"function\")\n throw new Error(\"Trace subscription unavailable\");\n } catch {\n return { available: false, message: AI_INSTALL_GUIDANCE, dispose() {} };\n }\n\n const { currentRequestId } = await import(\"../current-request-id\");\n const store = panoptic.createInMemoryTraceStore({ capacity });\n const listeners = new Set<(event: DevtoolsAiEvent) => void>();\n const detach = panoptic.subscribeTraces((trace) => {\n // Read ALS before any asynchronous exporter work, including for runs that\n // finish after the HTTP response. Never use sessionId as a request id.\n const requestId = currentRequestId() ?? trace.requestId;\n store.add({\n ...trace,\n requestId,\n usage: structuredClone(trace.usage),\n root: snapshotSpan(trace.root),\n });\n for (const listener of listeners) {\n try {\n listener({ traceId: trace.traceId, requestId });\n } catch {\n /* isolate clients */\n }\n }\n });\n\n return {\n available: true,\n store,\n summarize: (trace) => summarizeAiTrace(trace, panoptic.totalCostUsd(trace.usage)),\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n dispose() {\n detach();\n listeners.clear();\n store.clear();\n },\n };\n}\n"],"mappings":";;;;;;;AAIA,IAAI;;;;;;;AAQJ,SAAS,cAAc,KAAsB;CAC3C,MAAM,YACJA,oBAAWC,kBAAK,KAAK,KAAK,MAAM,aAAa,YAAY,CAAC,SAC1DD,oBAAWC,kBAAK,KAAK,KAAK,MAAM,UAAU,cAAc,CAAC;CAC3D,MAAM,cAAcA,kBAAK,KAAK,KAAK,cAAc;CAEjD,IAAI,CAAC,SAAS,KAACD,oBAAW,WAAW,GACnC,OAAO;CAGT,IAAI;EAEF,OADe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