@warlock.js/devtools 5.59.0 → 5.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/cjs/{app-versions-DfpPZOI2.cjs → app-versions-C_ZyzuvD.cjs} +1 -116
  3. package/cjs/app-versions-C_ZyzuvD.cjs.map +1 -0
  4. package/cjs/attach-D5aMqUnA.cjs +1342 -0
  5. package/cjs/attach-D5aMqUnA.cjs.map +1 -0
  6. package/cjs/{auth-B3wyjJnQ.cjs → auth-ChHh5E7j.cjs} +6 -6
  7. package/cjs/{auth-B3wyjJnQ.cjs.map → auth-ChHh5E7j.cjs.map} +1 -1
  8. package/cjs/{boot-nczSvJ_F.cjs → boot-Dg5YZGGR.cjs} +77 -14
  9. package/cjs/boot-Dg5YZGGR.cjs.map +1 -0
  10. package/cjs/{capture-CuyT8Vab.cjs → capture-CBgONYhk.cjs} +4 -4
  11. package/cjs/{capture-CuyT8Vab.cjs.map → capture-CBgONYhk.cjs.map} +1 -1
  12. package/cjs/{cascade-store-CuRRYzt_.cjs → cascade-store-DUT2Laha.cjs} +3 -3
  13. package/cjs/{cascade-store-CuRRYzt_.cjs.map → cascade-store-DUT2Laha.cjs.map} +1 -1
  14. package/cjs/{current-request-id-CeQhRz9Q.cjs → current-request-id-Badec-TH.cjs} +2 -2
  15. package/cjs/{current-request-id-CeQhRz9Q.cjs.map → current-request-id-Badec-TH.cjs.map} +1 -1
  16. package/cjs/{errors-BadbSDX8.cjs → errors-DNQ-g49I.cjs} +198 -1
  17. package/cjs/errors-DNQ-g49I.cjs.map +1 -0
  18. package/cjs/extract-8kaX_cUV.cjs +1103 -0
  19. package/cjs/extract-8kaX_cUV.cjs.map +1 -0
  20. package/cjs/{histogram-DTOGnNBW.cjs → histogram-CkoVizdf.cjs} +6 -6
  21. package/cjs/{histogram-DTOGnNBW.cjs.map → histogram-CkoVizdf.cjs.map} +1 -1
  22. package/cjs/{http-Biauhqi0.cjs → http-DCVCf44M.cjs} +25 -8
  23. package/cjs/http-DCVCf44M.cjs.map +1 -0
  24. package/cjs/index.cjs +1 -1
  25. package/cjs/{insights-BjJA6Ret.cjs → insights-CFof59kF.cjs} +3 -3
  26. package/cjs/{insights-BjJA6Ret.cjs.map → insights-CFof59kF.cjs.map} +1 -1
  27. package/cjs/migrations-BQdNOL5_.cjs +30 -0
  28. package/cjs/migrations-BQdNOL5_.cjs.map +1 -0
  29. package/cjs/{migrations-BP4cYTGo.cjs → models-DF1agAm4.cjs} +106 -24
  30. package/cjs/models-DF1agAm4.cjs.map +1 -0
  31. package/cjs/{process-panel-DskSA7Cm.cjs → process-panel-D3D9Y_dc.cjs} +4 -4
  32. package/cjs/{process-panel-DskSA7Cm.cjs.map → process-panel-D3D9Y_dc.cjs.map} +1 -1
  33. package/cjs/production/index.cjs +4 -4
  34. package/cjs/runs-DECWPGnq.cjs +390 -0
  35. package/cjs/runs-DECWPGnq.cjs.map +1 -0
  36. package/cjs/{server-D3XRbSSb.cjs → server-CC5DpObz.cjs} +8 -7
  37. package/cjs/{server-D3XRbSSb.cjs.map → server-CC5DpObz.cjs.map} +1 -1
  38. package/cjs/{src-QcNghoYN.cjs → src-VyOjEEAo.cjs} +178 -23
  39. package/cjs/src-VyOjEEAo.cjs.map +1 -0
  40. package/cjs/{store-CNFv3wVp.cjs → store-EFn4wp0T.cjs} +2 -2
  41. package/cjs/{stream-route-BqyAlfxQ.cjs → stream-route-DFHuIWgg.cjs} +107 -15
  42. package/cjs/stream-route-DFHuIWgg.cjs.map +1 -0
  43. package/esm/ai/attach.mjs +92 -0
  44. package/esm/ai/attach.mjs.map +1 -0
  45. package/esm/ai/options.mjs +31 -0
  46. package/esm/ai/options.mjs.map +1 -0
  47. package/esm/ai/reports/aggregate.mjs +330 -0
  48. package/esm/ai/reports/aggregate.mjs.map +1 -0
  49. package/esm/ai/reports/evaluate.mjs +108 -0
  50. package/esm/ai/reports/evaluate.mjs.map +1 -0
  51. package/esm/ai/reports/range.mjs +121 -0
  52. package/esm/ai/reports/range.mjs.map +1 -0
  53. package/esm/ai/reports/runs.d.mts +2 -0
  54. package/esm/ai/reports/runs.mjs +212 -0
  55. package/esm/ai/reports/runs.mjs.map +1 -0
  56. package/esm/ai/reports/service.mjs +132 -0
  57. package/esm/ai/reports/service.mjs.map +1 -0
  58. package/esm/ai/rollup/cascade-store.mjs +84 -0
  59. package/esm/ai/rollup/cascade-store.mjs.map +1 -0
  60. package/esm/ai/rollup/categories.mjs +67 -0
  61. package/esm/ai/rollup/categories.mjs.map +1 -0
  62. package/esm/ai/rollup/extract.mjs +225 -0
  63. package/esm/ai/rollup/extract.mjs.map +1 -0
  64. package/esm/ai/rollup/file-store.mjs +147 -0
  65. package/esm/ai/rollup/file-store.mjs.map +1 -0
  66. package/esm/ai/rollup/histogram.mjs +42 -0
  67. package/esm/ai/rollup/histogram.mjs.map +1 -0
  68. package/esm/ai/rollup/increment-error.mjs +19 -0
  69. package/esm/ai/rollup/increment-error.mjs.map +1 -0
  70. package/esm/ai/rollup/index.mjs +9 -0
  71. package/esm/ai/rollup/mapping.mjs +69 -0
  72. package/esm/ai/rollup/mapping.mjs.map +1 -0
  73. package/esm/ai/rollup/memory-store.mjs +26 -0
  74. package/esm/ai/rollup/memory-store.mjs.map +1 -0
  75. package/esm/ai/rollup/writer.mjs +113 -0
  76. package/esm/ai/rollup/writer.mjs.map +1 -0
  77. package/esm/ai/types.d.mts +29 -0
  78. package/esm/ai/types.d.mts.map +1 -0
  79. package/esm/devtools-connector.d.mts.map +1 -1
  80. package/esm/devtools-connector.mjs +54 -2
  81. package/esm/devtools-connector.mjs.map +1 -1
  82. package/esm/index.d.mts +3 -2
  83. package/esm/options.mjs +4 -0
  84. package/esm/options.mjs.map +1 -1
  85. package/esm/production/boot.mjs +69 -3
  86. package/esm/production/boot.mjs.map +1 -1
  87. package/esm/production/contracts.d.mts +371 -2
  88. package/esm/production/contracts.d.mts.map +1 -1
  89. package/esm/production/contracts.mjs +64 -2
  90. package/esm/production/contracts.mjs.map +1 -1
  91. package/esm/production/errors.mjs +8 -0
  92. package/esm/production/errors.mjs.map +1 -1
  93. package/esm/production/http/access.mjs +6 -0
  94. package/esm/production/http/access.mjs.map +1 -1
  95. package/esm/production/http/mount.mjs +13 -0
  96. package/esm/production/http/mount.mjs.map +1 -1
  97. package/esm/production/index.d.mts +2 -2
  98. package/esm/production/store/migrations.d.mts +1 -1
  99. package/esm/production/store/migrations.d.mts.map +1 -1
  100. package/esm/production/store/migrations.mjs +4 -2
  101. package/esm/production/store/migrations.mjs.map +1 -1
  102. package/esm/production/store/models/ai-rollup.migration.mjs +48 -0
  103. package/esm/production/store/models/ai-rollup.migration.mjs.map +1 -0
  104. package/esm/production/store/models/ai-rollup.model.mjs +13 -0
  105. package/esm/production/store/models/ai-rollup.model.mjs.map +1 -0
  106. package/esm/production/store/models/index.mjs +3 -1
  107. package/esm/server/ai-report-routes.mjs +72 -0
  108. package/esm/server/ai-report-routes.mjs.map +1 -0
  109. package/esm/server/ai-routes.mjs +22 -1
  110. package/esm/server/ai-routes.mjs.map +1 -1
  111. package/esm/server/index.mjs +2 -0
  112. package/esm/server/index.mjs.map +1 -1
  113. package/esm/sources/agent-trace-source.d.mts.map +1 -1
  114. package/esm/sources/agent-trace-source.mjs.map +1 -1
  115. package/esm/sources/ai-source.d.mts +2 -0
  116. package/esm/sources/ai-source.d.mts.map +1 -1
  117. package/esm/sources/ai-source.mjs +58 -17
  118. package/esm/sources/ai-source.mjs.map +1 -1
  119. package/esm/types.d.mts +13 -3
  120. package/esm/types.d.mts.map +1 -1
  121. package/llms-full.txt +56 -17
  122. package/package.json +8 -8
  123. package/skills/SKILL.md +56 -17
  124. package/ui/dashboard/assets/app.css +1 -1
  125. package/ui/dashboard/assets/app.js +12 -5
  126. package/ui/dashboard/build-info.json +7 -7
  127. package/cjs/ai-source-BdvMfyKw.cjs +0 -448
  128. package/cjs/ai-source-BdvMfyKw.cjs.map +0 -1
  129. package/cjs/app-versions-DfpPZOI2.cjs.map +0 -1
  130. package/cjs/boot-nczSvJ_F.cjs.map +0 -1
  131. package/cjs/errors-BadbSDX8.cjs.map +0 -1
  132. package/cjs/http-Biauhqi0.cjs.map +0 -1
  133. package/cjs/migrations-BP4cYTGo.cjs.map +0 -1
  134. package/cjs/options-B9FHbRAJ.cjs +0 -205
  135. package/cjs/options-B9FHbRAJ.cjs.map +0 -1
  136. package/cjs/panels-D1ITm-jc.cjs +0 -384
  137. package/cjs/panels-D1ITm-jc.cjs.map +0 -1
  138. package/cjs/src-QcNghoYN.cjs.map +0 -1
  139. package/cjs/stream-route-BqyAlfxQ.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"mount.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/mount.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { FastifyInstance, FastifyReply, FastifyRequest } from \"fastify\";\nimport { listPanelInfos } from \"../../panels\";\nimport { registerAiRoutes } from \"../../server/ai-routes\";\nimport { registerShapeExplainRoute } from \"../../server/explain-route\";\nimport { registerInsightsRoutes } from \"../../server/insights-routes\";\nimport { registerLogRoutes } from \"../../server/log-routes\";\nimport { registerMailRoutes } from \"../../server/mail-routes\";\nimport { registerOpenApiRoutes } from \"../../server/openapi-routes\";\nimport { registerPanelRoutes } from \"../../server/panel-routes\";\nimport { registerRequestsRoutes } from \"../../server/requests-routes\";\nimport { registerRouteRoutes } from \"../../server/route-routes\";\nimport { registerStreamRoute } from \"../../server/stream-route\";\nimport type { DevtoolsStreamSession, MountDevtoolsRoutesDeps } from \"../../server/types\";\nimport { registerUiAssets } from \"../../server/ui-assets\";\nimport type { DevtoolsAuthenticated, DevtoolsRequestMeta } from \"../auth/types\";\nimport { DevtoolsApiError, createErrorRef, DEVTOOLS_ERROR_MESSAGES } from \"../errors\";\nimport { createAccessLookup, productionRouteAccess } from \"./access\";\nimport { registerAuthRoutes } from \"./auth-routes\";\nimport { resolveClient } from \"./client\";\nimport { setDevtoolsRequestContext, devtoolsRequestContext } from \"./context\";\nimport { readCookie, sessionCookieName } from \"./cookie\";\nimport { DASHBOARD_CSP, DASHBOARD_HEADERS, DOCS_CSP } from \"./headers\";\nimport { DEVTOOLS_CSRF_HEADER } from \"./constants\";\nimport { createDevtoolsShare } from \"./share\";\nimport { ipMatches } from \"./ip\";\nimport type { DevtoolsRouteAccess, MountProductionDevtoolsDeps } from \"./types\";\n\n/** Open live streams a session may hold, and an instance may serve. */\nconst MAX_STREAMS_PER_SESSION = 3;\nconst MAX_STREAMS_PER_INSTANCE = 50;\n\nconst MAX_USER_AGENT = 200;\n\n/** Methods that never change state. */\nconst SAFE_METHODS = new Set([\"GET\", \"HEAD\", \"OPTIONS\"]);\n\n/** The routes of the opt-in API documentation pages (they keep a CSP of their own). */\nconst DOCS_PATTERNS = new Set([\"/docs\", \"/docs/swagger\"]);\n\n/** The grant exchange of a share link: every failure of it answers the uniform 404. */\nconst SHARE_OPEN_PATTERN = \"/api/share/open\";\n\n/** The mail preview's HTML: framed by the dashboard, with a policy of its own. */\nconst MAIL_HTML_PATTERN = \"/api/mails/:id/html\";\n\n/** Which tab a route belongs to: a route of a tab that is off answers the uniform 404. */\nconst TAB_OF_ROUTE: readonly (readonly [prefix: string, tab: string])[] = [\n [\"/api/resources\", \"resources\"],\n [\"/api/queries\", \"queries\"],\n [\"/api/routes/stats\", \"routes\"],\n [\"/api/routes\", \"routes\"],\n [\"/api/health\", \"health\"],\n [\"/api/errors\", \"errors\"],\n [\"/api/jobs\", \"jobs\"],\n [\"/api/logs\", \"logs\"],\n [\"/api/requests\", \"requests\"],\n [\"/api/mails\", \"mail\"],\n [\"/api/ai/agent-runs\", \"agents\"],\n [\"/api/ai\", \"ai\"],\n [\"/api/openapi.json\", \"api\"],\n [\"/api/postman.json\", \"api\"],\n [\"/docs\", \"api\"],\n];\n\nfunction tabOf(pattern: string): string | undefined {\n return TAB_OF_ROUTE.find(\n ([prefix]) => pattern === prefix || pattern.startsWith(`${prefix}/`),\n )?.[1];\n}\n\nfunction tokenHash(token: string): string {\n return createHash(\"sha256\").update(token).digest(\"hex\");\n}\n\n/** Requests that were answered with the uniform 404: they get none of the dashboard's headers. */\nconst uniformNotFound = new WeakSet<FastifyRequest>();\n\n/**\n * The origin the browser must send for an unsafe request: `production.origin`,\n * else the scheme and host the request was addressed to.\n */\nfunction originAllowed(request: FastifyRequest, expected: string): boolean {\n const origin = request.headers.origin;\n const site = request.headers[\"sec-fetch-site\"];\n\n if (site !== undefined && site !== \"same-origin\") return false;\n\n if (origin !== undefined) return origin.toLowerCase() === expected.toLowerCase();\n\n // No Origin header: a same-origin fetch from an older browser. Accept it only with the fetch metadata that proves it.\n return site === \"same-origin\";\n}\n\nfunction hasBody(request: FastifyRequest): boolean {\n const length = request.headers[\"content-length\"];\n\n return (\n (length !== undefined && length !== \"0\") || request.headers[\"transfer-encoding\"] !== undefined\n );\n}\n\nfunction isJson(request: FastifyRequest): boolean {\n return /^application\\/json\\s*(;|$)/i.test(request.headers[\"content-type\"] ?? \"\");\n}\n\nfunction sessionAccessOk(\n access: Exclude<DevtoolsRouteAccess, { type: \"public\" }>,\n stage: string,\n): boolean {\n if (stage === \"active\") return true;\n\n return access.type === \"pending\" && (access.stages as readonly string[]).includes(stage);\n}\n\n/**\n * Mounts the production monitor under `production.path` in one encapsulated\n * Fastify context: the gate (uniform 404, HTTPS, allowed IPs, open state),\n * session and role checks from the access table, CSRF and origin checks,\n * security headers and CORS stripping, the auth/account/admin routes, and\n * the shared data routes of the enabled tabs.\n */\nexport function mountProductionDevtools(\n server: FastifyInstance,\n deps: MountProductionDevtoolsDeps,\n): void {\n const { production, auth, state, store } = deps;\n const prefix = production.path;\n const cookieName = sessionCookieName(production.requireHttps);\n const enabledTabs = new Set(deps.builtInPanels);\n const share = production.share.enabled ? createDevtoolsShare(deps) : null;\n const lookup = createAccessLookup(\n productionRouteAccess(\n deps.panels.map((panel) => panel.id),\n { share: share !== null },\n ),\n );\n const streamsPerSession = new Map<string, number>();\n let streamsInstance = 0;\n let lastWarningAt = 0;\n\n const warn = (message: string): void => {\n // At most one line a minute: a database outage must not flood the log.\n const now = Date.now();\n\n if (now - lastWarningAt < 60_000) return;\n\n lastWarningAt = now;\n deps.warn?.(message);\n };\n\n const notFound = (request: FastifyRequest, reply: FastifyReply): FastifyReply => {\n uniformNotFound.add(request);\n\n // The app's own not-found handler answers, so the reply is the one any unknown URL gets.\n reply.callNotFound();\n\n // Returning the reply is what stops an async hook's lifecycle.\n return reply;\n };\n\n const streamSession = async (request: FastifyRequest): Promise<DevtoolsStreamSession> => {\n const authenticated = devtoolsRequestContext(request)?.authenticated;\n\n if (!authenticated) throw new Error(\"A dashboard stream was opened without a session.\");\n\n const sessionId = authenticated.session.id;\n const token = readCookie(request.headers.cookie, cookieName);\n const open = streamsPerSession.get(sessionId) ?? 0;\n\n if (open >= MAX_STREAMS_PER_SESSION || streamsInstance >= MAX_STREAMS_PER_INSTANCE) {\n throw new DevtoolsApiError(\"stream.too-many\");\n }\n\n streamsPerSession.set(sessionId, open + 1);\n streamsInstance += 1;\n\n let released = false;\n\n return {\n role: authenticated.account.role,\n logLevels: production.logLevels,\n headers: DASHBOARD_HEADERS,\n // Reads the session without touching `lastSeenAt`: a stream left open must not keep the session alive.\n async revalidate() {\n if (token === undefined || !(await state.isOpen())) return false;\n\n const session = await store.sessions.findByTokenHash(tokenHash(token));\n const now = Date.now();\n\n if (\n session === null ||\n session.stage !== \"active\" ||\n now >= session.expiresAt ||\n now - session.lastSeenAt >= production.session.idleMinutes * 60_000\n ) {\n return false;\n }\n\n return (await store.accounts.findById(session.accountId)) !== null;\n },\n release() {\n if (released) return;\n\n released = true;\n streamsInstance -= 1;\n\n const left = (streamsPerSession.get(sessionId) ?? 1) - 1;\n\n if (left <= 0) streamsPerSession.delete(sessionId);\n else streamsPerSession.set(sessionId, left);\n },\n };\n };\n\n // The route deps the shared route files read: the development deps, completed.\n const routes: MountDevtoolsRoutesDeps = {\n ...deps.routes,\n mode: \"production\",\n isDevelopment: () => false,\n instance: deps.instance,\n insights: deps.insights,\n collector: deps.routes.collector ?? deps.capture.collector,\n requests: deps.routes.requests ?? deps.capture.requests,\n explainShape: deps.routes.explainShape ?? ((shapeId) => deps.capture.explain(shapeId)),\n builtInPanels: deps.builtInPanels,\n streamSession,\n };\n\n server.register(\n async (instance) => {\n // ---- The gate -------------------------------------------------------\n instance.addHook(\"onRequest\", async (request, reply) => {\n let open: boolean;\n\n try {\n open = await state.isOpen();\n } catch (error) {\n // Fail closed: when the state cannot be read the dashboard does not answer.\n warn(\n `The devtools dashboard state could not be read and the dashboard is closed: ${error instanceof Error ? error.message : String(error)}`,\n );\n open = false;\n }\n\n if (!open) return notFound(request, reply);\n\n const client = resolveClient(request, production.trustedProxies);\n\n if (production.requireHttps && client.proto !== \"https\") return notFound(request, reply);\n\n if (production.allowedIps.length > 0 && !ipMatches(client.ip, production.allowedIps)) {\n return notFound(request, reply);\n }\n\n const userAgent = request.headers[\"user-agent\"];\n const expectedOrigin = production.origin ?? `${client.proto}://${client.host}`;\n const meta: DevtoolsRequestMeta = {\n ip: client.ip,\n userAgent: typeof userAgent === \"string\" ? userAgent.slice(0, MAX_USER_AGENT) : null,\n origin: expectedOrigin,\n hostname: client.hostname,\n };\n\n const routeUrl = request.routeOptions.url ?? \"\";\n const relative = routeUrl.startsWith(prefix) ? routeUrl.slice(prefix.length) : routeUrl;\n // The shell is registered once for both `<path>` and `<path>/`.\n const pattern = relative === \"\" ? \"/\" : relative;\n const method = request.method;\n\n // The bare path (no trailing slash) redirects to the shell's address. The\n // address as sent: core's server drops a trailing slash before routing,\n // so the rewritten URL of `<path>/` is the bare path too.\n const sent = request.originalUrl ?? request.raw.url ?? \"\";\n\n if (sent.split(\"?\")[0] === prefix) {\n setDevtoolsRequestContext(request, {\n client,\n meta,\n rule: undefined,\n pattern,\n authenticated: null,\n });\n\n if (method !== \"GET\" && method !== \"HEAD\") return notFound(request, reply);\n\n const search = sent.includes(\"?\") ? `?${sent.split(\"?\").slice(1).join(\"?\")}` : \"\";\n\n return reply.redirect(`${prefix}/${search}`, 308);\n }\n\n const tab = tabOf(pattern);\n\n if (tab !== undefined && !enabledTabs.has(tab)) return notFound(request, reply);\n\n const rule = lookup(method, pattern);\n const access: DevtoolsRouteAccess = rule?.access ?? { type: \"admin\" };\n let authenticated: DevtoolsAuthenticated | null = null;\n\n // A share link has no account: its cookie grants one panel's shared view and nothing else.\n if (access.type === \"share\") {\n const grant = share ? await share.authorize(request, meta) : null;\n\n if (grant === null) return notFound(request, reply);\n\n setDevtoolsRequestContext(request, {\n client,\n meta,\n rule,\n pattern,\n authenticated: null,\n share: grant,\n });\n\n return;\n }\n\n if (access.type !== \"public\") {\n try {\n authenticated = await auth.authenticate(readCookie(request.headers.cookie, cookieName));\n } catch (error) {\n warn(\n `The devtools session could not be checked and the request was refused: ${error instanceof Error ? error.message : String(error)}`,\n );\n\n return notFound(request, reply);\n }\n\n if (authenticated === null || !sessionAccessOk(access, authenticated.stage)) {\n return notFound(request, reply);\n }\n\n if (access.type === \"admin\" && authenticated.account.role !== \"admin\") {\n setDevtoolsRequestContext(request, { client, meta, rule, pattern, authenticated });\n throw new DevtoolsApiError(\"role.forbidden\");\n }\n }\n\n setDevtoolsRequestContext(request, { client, meta, rule, pattern, authenticated });\n\n if (SAFE_METHODS.has(method)) return;\n\n if (!originAllowed(request, expectedOrigin)) {\n if (authenticated === null) return notFound(request, reply);\n\n throw new DevtoolsApiError(\"csrf.invalid\");\n }\n\n if (hasBody(request) && !isJson(request)) {\n if (pattern === SHARE_OPEN_PATTERN) return notFound(request, reply);\n\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n if (authenticated !== null) {\n const header = request.headers[DEVTOOLS_CSRF_HEADER];\n\n if (!auth.verifyCsrf(authenticated, Array.isArray(header) ? header[0] : header)) {\n throw new DevtoolsApiError(\"csrf.invalid\");\n }\n }\n });\n\n // ---- Headers --------------------------------------------------------\n instance.addHook(\"onSend\", async (request, reply, payload) => {\n // The uniform 404 must look like any other 404 of the app.\n if (uniformNotFound.has(request)) return payload;\n\n for (const name of Object.keys(reply.getHeaders())) {\n if (name.startsWith(\"access-control-\")) reply.removeHeader(name);\n }\n\n reply.headers(DASHBOARD_HEADERS);\n\n const pattern = devtoolsRequestContext(request)?.pattern ?? \"\";\n\n // The mail preview is the one page the dashboard frames, from its own origin, and it sends its own policy.\n if (pattern === MAIL_HTML_PATTERN) {\n reply.header(\"X-Frame-Options\", \"SAMEORIGIN\");\n\n return payload;\n }\n\n // The API docs pages are shown in a frame by the dashboard's API tab.\n if (DOCS_PATTERNS.has(pattern)) reply.header(\"X-Frame-Options\", \"SAMEORIGIN\");\n\n // Always the dashboard's policy: the app's own (core's security headers set one on every response) is not\n // written for this page and must not replace it.\n if (String(reply.getHeader(\"content-type\") ?? \"\").startsWith(\"text/html\")) {\n reply.header(\n \"Content-Security-Policy\",\n DOCS_PATTERNS.has(pattern) ? DOCS_CSP : DASHBOARD_CSP,\n );\n }\n\n return payload;\n });\n\n // ---- Audit ----------------------------------------------------------\n instance.addHook(\"onResponse\", async (request, reply) => {\n const context = devtoolsRequestContext(request);\n const type = context?.rule?.audit;\n\n if (!context || !type || reply.statusCode < 200 || reply.statusCode > 299) return;\n\n const params = (request.params ?? {}) as Record<string, string | undefined>;\n const detail: Record<string, string | number | boolean | null> =\n type === \"explain.run\"\n ? { shapeId: params.shapeId ?? null }\n : type === \"panel.action\"\n ? {\n panel: context.pattern.split(\"/\")[2] ?? null,\n method: request.method,\n route: context.pattern,\n }\n : {};\n\n await auth.audit(type, { auth: context.authenticated, meta: context.meta, detail });\n });\n\n // ---- Errors ---------------------------------------------------------\n instance.setErrorHandler(\n (error: Error & { statusCode?: number; code?: string }, request, reply) => {\n // A malformed grant exchange (bad JSON, too large) answers like any unknown URL.\n if (devtoolsRequestContext(request)?.pattern === SHARE_OPEN_PATTERN) {\n return notFound(request, reply);\n }\n\n if (error instanceof DevtoolsApiError) {\n return reply.code(error.statusCode).send(error.toBody());\n }\n\n const status = error.statusCode;\n\n // The request itself was wrong (bad JSON, too large): say so in the dashboard's own shape.\n if (status !== undefined && status >= 400 && status < 500) {\n return reply\n .code(status)\n .send(\n error.code?.startsWith(\"FST_ERR_\")\n ? new DevtoolsApiError(\"input.invalid\").toBody()\n : { error: error.message },\n );\n }\n\n const ref = createErrorRef();\n\n // Never rate limited: the reference the browser shows must always be findable in the log. The route is\n // written relative to the dashboard path, which never reaches the log.\n deps.warn?.(\n `Devtools dashboard error ${ref} on ${request.method} ${devtoolsRequestContext(request)?.pattern ?? \"(dashboard route)\"}: ${error.message}`,\n );\n request.log.error({ ref, err: error }, \"devtools dashboard error\");\n\n return reply.code(500).send({\n error: DEVTOOLS_ERROR_MESSAGES[\"server.error\"],\n code: \"server.error\",\n ref,\n });\n },\n );\n\n // ---- Routes ---------------------------------------------------------\n registerUiAssets(instance, { notFound });\n registerAuthRoutes(instance, deps);\n\n instance.get(\"/api/panels\", async () => listPanelInfos(deps.panels, deps.builtInPanels));\n\n registerRequestsRoutes(instance, routes);\n registerRouteRoutes(instance, routes);\n registerInsightsRoutes(instance, routes);\n registerLogRoutes(instance, routes);\n registerShapeExplainRoute(instance, routes);\n registerPanelRoutes(instance, deps.panels, { notFound });\n\n share?.register(instance, notFound);\n\n if (enabledTabs.has(\"mail\")) registerMailRoutes(instance, routes);\n if (enabledTabs.has(\"ai\") || enabledTabs.has(\"agents\")) registerAiRoutes(instance, routes);\n if (enabledTabs.has(\"api\")) registerOpenApiRoutes(instance, routes);\n\n registerStreamRoute(instance, routes);\n },\n { prefix },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,0BAA0B;AAChC,MAAM,2BAA2B;AAEjC,MAAM,iBAAiB;;AAGvB,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAO;CAAQ;AAAS,CAAC;;AAGvD,MAAM,gCAAgB,IAAI,IAAI,CAAC,SAA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.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { FastifyInstance, FastifyReply, FastifyRequest } from \"fastify\";\nimport { listPanelInfos } from \"../../panels\";\nimport { registerAiReportRoutes } from \"../../server/ai-report-routes\";\nimport { registerAiRoutes } from \"../../server/ai-routes\";\nimport { registerShapeExplainRoute } from \"../../server/explain-route\";\nimport { registerInsightsRoutes } from \"../../server/insights-routes\";\nimport { registerLogRoutes } from \"../../server/log-routes\";\nimport { registerMailRoutes } from \"../../server/mail-routes\";\nimport { registerOpenApiRoutes } from \"../../server/openapi-routes\";\nimport { registerPanelRoutes } from \"../../server/panel-routes\";\nimport { registerRequestsRoutes } from \"../../server/requests-routes\";\nimport { registerRouteRoutes } from \"../../server/route-routes\";\nimport { registerStreamRoute } from \"../../server/stream-route\";\nimport type { DevtoolsStreamSession, MountDevtoolsRoutesDeps } from \"../../server/types\";\nimport { registerUiAssets } from \"../../server/ui-assets\";\nimport type { DevtoolsAuthenticated, DevtoolsRequestMeta } from \"../auth/types\";\nimport { DevtoolsApiError, createErrorRef, DEVTOOLS_ERROR_MESSAGES } from \"../errors\";\nimport { createAccessLookup, productionRouteAccess } from \"./access\";\nimport { registerAuthRoutes } from \"./auth-routes\";\nimport { resolveClient } from \"./client\";\nimport { setDevtoolsRequestContext, devtoolsRequestContext } from \"./context\";\nimport { readCookie, sessionCookieName } from \"./cookie\";\nimport { DASHBOARD_CSP, DASHBOARD_HEADERS, DOCS_CSP } from \"./headers\";\nimport { DEVTOOLS_CSRF_HEADER } from \"./constants\";\nimport { createDevtoolsShare } from \"./share\";\nimport { ipMatches } from \"./ip\";\nimport type { DevtoolsRouteAccess, MountProductionDevtoolsDeps } from \"./types\";\n\n/** Open live streams a session may hold, and an instance may serve. */\nconst MAX_STREAMS_PER_SESSION = 3;\nconst MAX_STREAMS_PER_INSTANCE = 50;\n\nconst MAX_USER_AGENT = 200;\n\n/** Methods that never change state. */\nconst SAFE_METHODS = new Set([\"GET\", \"HEAD\", \"OPTIONS\"]);\n\n/** The routes of the opt-in API documentation pages (they keep a CSP of their own). */\nconst DOCS_PATTERNS = new Set([\"/docs\", \"/docs/swagger\"]);\n\n/** The grant exchange of a share link: every failure of it answers the uniform 404. */\nconst SHARE_OPEN_PATTERN = \"/api/share/open\";\n\n/** The mail preview's HTML: framed by the dashboard, with a policy of its own. */\nconst MAIL_HTML_PATTERN = \"/api/mails/:id/html\";\n\n/** Which tab a route belongs to: a route of a tab that is off answers the uniform 404. */\nconst TAB_OF_ROUTE: readonly (readonly [prefix: string, tab: string])[] = [\n [\"/api/resources\", \"resources\"],\n [\"/api/queries\", \"queries\"],\n [\"/api/routes/stats\", \"routes\"],\n [\"/api/routes\", \"routes\"],\n [\"/api/health\", \"health\"],\n [\"/api/errors\", \"errors\"],\n [\"/api/jobs\", \"jobs\"],\n [\"/api/logs\", \"logs\"],\n [\"/api/requests\", \"requests\"],\n [\"/api/mails\", \"mail\"],\n [\"/api/ai/agent-runs\", \"agents\"],\n [\"/api/ai/reports\", \"ai-reports\"],\n [\"/api/ai/models\", \"ai-models\"],\n [\"/api/ai/errors\", \"ai-errors\"],\n [\"/api/ai/evaluate\", \"ai-evaluate\"],\n [\"/api/ai\", \"ai\"],\n [\"/api/openapi.json\", \"api\"],\n [\"/api/postman.json\", \"api\"],\n [\"/docs\", \"api\"],\n];\n\n/** The tabs the AI report routes serve; the routes register when any of them is on. */\nconst AI_REPORT_TABS = [\"ai-reports\", \"ai-models\", \"ai-errors\", \"ai-evaluate\"] as const;\n\nfunction tabOf(pattern: string): string | undefined {\n return TAB_OF_ROUTE.find(\n ([prefix]) => pattern === prefix || pattern.startsWith(`${prefix}/`),\n )?.[1];\n}\n\nfunction tokenHash(token: string): string {\n return createHash(\"sha256\").update(token).digest(\"hex\");\n}\n\n/** Requests that were answered with the uniform 404: they get none of the dashboard's headers. */\nconst uniformNotFound = new WeakSet<FastifyRequest>();\n\n/**\n * The origin the browser must send for an unsafe request: `production.origin`,\n * else the scheme and host the request was addressed to.\n */\nfunction originAllowed(request: FastifyRequest, expected: string): boolean {\n const origin = request.headers.origin;\n const site = request.headers[\"sec-fetch-site\"];\n\n if (site !== undefined && site !== \"same-origin\") return false;\n\n if (origin !== undefined) return origin.toLowerCase() === expected.toLowerCase();\n\n // No Origin header: a same-origin fetch from an older browser. Accept it only with the fetch metadata that proves it.\n return site === \"same-origin\";\n}\n\nfunction hasBody(request: FastifyRequest): boolean {\n const length = request.headers[\"content-length\"];\n\n return (\n (length !== undefined && length !== \"0\") || request.headers[\"transfer-encoding\"] !== undefined\n );\n}\n\nfunction isJson(request: FastifyRequest): boolean {\n return /^application\\/json\\s*(;|$)/i.test(request.headers[\"content-type\"] ?? \"\");\n}\n\nfunction sessionAccessOk(\n access: Exclude<DevtoolsRouteAccess, { type: \"public\" }>,\n stage: string,\n): boolean {\n if (stage === \"active\") return true;\n\n return access.type === \"pending\" && (access.stages as readonly string[]).includes(stage);\n}\n\n/**\n * Mounts the production monitor under `production.path` in one encapsulated\n * Fastify context: the gate (uniform 404, HTTPS, allowed IPs, open state),\n * session and role checks from the access table, CSRF and origin checks,\n * security headers and CORS stripping, the auth/account/admin routes, and\n * the shared data routes of the enabled tabs.\n */\nexport function mountProductionDevtools(\n server: FastifyInstance,\n deps: MountProductionDevtoolsDeps,\n): void {\n const { production, auth, state, store } = deps;\n const prefix = production.path;\n const cookieName = sessionCookieName(production.requireHttps);\n const enabledTabs = new Set(deps.builtInPanels);\n const share = production.share.enabled ? createDevtoolsShare(deps) : null;\n const lookup = createAccessLookup(\n productionRouteAccess(\n deps.panels.map((panel) => panel.id),\n { share: share !== null },\n ),\n );\n const streamsPerSession = new Map<string, number>();\n let streamsInstance = 0;\n let lastWarningAt = 0;\n\n const warn = (message: string): void => {\n // At most one line a minute: a database outage must not flood the log.\n const now = Date.now();\n\n if (now - lastWarningAt < 60_000) return;\n\n lastWarningAt = now;\n deps.warn?.(message);\n };\n\n const notFound = (request: FastifyRequest, reply: FastifyReply): FastifyReply => {\n uniformNotFound.add(request);\n\n // The app's own not-found handler answers, so the reply is the one any unknown URL gets.\n reply.callNotFound();\n\n // Returning the reply is what stops an async hook's lifecycle.\n return reply;\n };\n\n const streamSession = async (request: FastifyRequest): Promise<DevtoolsStreamSession> => {\n const authenticated = devtoolsRequestContext(request)?.authenticated;\n\n if (!authenticated) throw new Error(\"A dashboard stream was opened without a session.\");\n\n const sessionId = authenticated.session.id;\n const token = readCookie(request.headers.cookie, cookieName);\n const open = streamsPerSession.get(sessionId) ?? 0;\n\n if (open >= MAX_STREAMS_PER_SESSION || streamsInstance >= MAX_STREAMS_PER_INSTANCE) {\n throw new DevtoolsApiError(\"stream.too-many\");\n }\n\n streamsPerSession.set(sessionId, open + 1);\n streamsInstance += 1;\n\n let released = false;\n\n return {\n role: authenticated.account.role,\n logLevels: production.logLevels,\n headers: DASHBOARD_HEADERS,\n // Reads the session without touching `lastSeenAt`: a stream left open must not keep the session alive.\n async revalidate() {\n if (token === undefined || !(await state.isOpen())) return false;\n\n const session = await store.sessions.findByTokenHash(tokenHash(token));\n const now = Date.now();\n\n if (\n session === null ||\n session.stage !== \"active\" ||\n now >= session.expiresAt ||\n now - session.lastSeenAt >= production.session.idleMinutes * 60_000\n ) {\n return false;\n }\n\n return (await store.accounts.findById(session.accountId)) !== null;\n },\n release() {\n if (released) return;\n\n released = true;\n streamsInstance -= 1;\n\n const left = (streamsPerSession.get(sessionId) ?? 1) - 1;\n\n if (left <= 0) streamsPerSession.delete(sessionId);\n else streamsPerSession.set(sessionId, left);\n },\n };\n };\n\n // The route deps the shared route files read: the development deps, completed.\n const routes: MountDevtoolsRoutesDeps = {\n ...deps.routes,\n mode: \"production\",\n isDevelopment: () => false,\n instance: deps.instance,\n insights: deps.insights,\n collector: deps.routes.collector ?? deps.capture.collector,\n requests: deps.routes.requests ?? deps.capture.requests,\n explainShape: deps.routes.explainShape ?? ((shapeId) => deps.capture.explain(shapeId)),\n builtInPanels: deps.builtInPanels,\n streamSession,\n };\n\n server.register(\n async (instance) => {\n // ---- The gate -------------------------------------------------------\n instance.addHook(\"onRequest\", async (request, reply) => {\n let open: boolean;\n\n try {\n open = await state.isOpen();\n } catch (error) {\n // Fail closed: when the state cannot be read the dashboard does not answer.\n warn(\n `The devtools dashboard state could not be read and the dashboard is closed: ${error instanceof Error ? error.message : String(error)}`,\n );\n open = false;\n }\n\n if (!open) return notFound(request, reply);\n\n const client = resolveClient(request, production.trustedProxies);\n\n if (production.requireHttps && client.proto !== \"https\") return notFound(request, reply);\n\n if (production.allowedIps.length > 0 && !ipMatches(client.ip, production.allowedIps)) {\n return notFound(request, reply);\n }\n\n const userAgent = request.headers[\"user-agent\"];\n const expectedOrigin = production.origin ?? `${client.proto}://${client.host}`;\n const meta: DevtoolsRequestMeta = {\n ip: client.ip,\n userAgent: typeof userAgent === \"string\" ? userAgent.slice(0, MAX_USER_AGENT) : null,\n origin: expectedOrigin,\n hostname: client.hostname,\n };\n\n const routeUrl = request.routeOptions.url ?? \"\";\n const relative = routeUrl.startsWith(prefix) ? routeUrl.slice(prefix.length) : routeUrl;\n // The shell is registered once for both `<path>` and `<path>/`.\n const pattern = relative === \"\" ? \"/\" : relative;\n const method = request.method;\n\n // The bare path (no trailing slash) redirects to the shell's address. The\n // address as sent: core's server drops a trailing slash before routing,\n // so the rewritten URL of `<path>/` is the bare path too.\n const sent = request.originalUrl ?? request.raw.url ?? \"\";\n\n if (sent.split(\"?\")[0] === prefix) {\n setDevtoolsRequestContext(request, {\n client,\n meta,\n rule: undefined,\n pattern,\n authenticated: null,\n });\n\n if (method !== \"GET\" && method !== \"HEAD\") return notFound(request, reply);\n\n const search = sent.includes(\"?\") ? `?${sent.split(\"?\").slice(1).join(\"?\")}` : \"\";\n\n return reply.redirect(`${prefix}/${search}`, 308);\n }\n\n const tab = tabOf(pattern);\n\n if (tab !== undefined && !enabledTabs.has(tab)) return notFound(request, reply);\n\n const rule = lookup(method, pattern);\n const access: DevtoolsRouteAccess = rule?.access ?? { type: \"admin\" };\n let authenticated: DevtoolsAuthenticated | null = null;\n\n // A share link has no account: its cookie grants one panel's shared view and nothing else.\n if (access.type === \"share\") {\n const grant = share ? await share.authorize(request, meta) : null;\n\n if (grant === null) return notFound(request, reply);\n\n setDevtoolsRequestContext(request, {\n client,\n meta,\n rule,\n pattern,\n authenticated: null,\n share: grant,\n });\n\n return;\n }\n\n if (access.type !== \"public\") {\n try {\n authenticated = await auth.authenticate(readCookie(request.headers.cookie, cookieName));\n } catch (error) {\n warn(\n `The devtools session could not be checked and the request was refused: ${error instanceof Error ? error.message : String(error)}`,\n );\n\n return notFound(request, reply);\n }\n\n if (authenticated === null || !sessionAccessOk(access, authenticated.stage)) {\n return notFound(request, reply);\n }\n\n if (access.type === \"admin\" && authenticated.account.role !== \"admin\") {\n setDevtoolsRequestContext(request, { client, meta, rule, pattern, authenticated });\n throw new DevtoolsApiError(\"role.forbidden\");\n }\n }\n\n setDevtoolsRequestContext(request, { client, meta, rule, pattern, authenticated });\n\n if (SAFE_METHODS.has(method)) return;\n\n if (!originAllowed(request, expectedOrigin)) {\n if (authenticated === null) return notFound(request, reply);\n\n throw new DevtoolsApiError(\"csrf.invalid\");\n }\n\n if (hasBody(request) && !isJson(request)) {\n if (pattern === SHARE_OPEN_PATTERN) return notFound(request, reply);\n\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n if (authenticated !== null) {\n const header = request.headers[DEVTOOLS_CSRF_HEADER];\n\n if (!auth.verifyCsrf(authenticated, Array.isArray(header) ? header[0] : header)) {\n throw new DevtoolsApiError(\"csrf.invalid\");\n }\n }\n });\n\n // ---- Headers --------------------------------------------------------\n instance.addHook(\"onSend\", async (request, reply, payload) => {\n // The uniform 404 must look like any other 404 of the app.\n if (uniformNotFound.has(request)) return payload;\n\n for (const name of Object.keys(reply.getHeaders())) {\n if (name.startsWith(\"access-control-\")) reply.removeHeader(name);\n }\n\n reply.headers(DASHBOARD_HEADERS);\n\n const pattern = devtoolsRequestContext(request)?.pattern ?? \"\";\n\n // The mail preview is the one page the dashboard frames, from its own origin, and it sends its own policy.\n if (pattern === MAIL_HTML_PATTERN) {\n reply.header(\"X-Frame-Options\", \"SAMEORIGIN\");\n\n return payload;\n }\n\n // The API docs pages are shown in a frame by the dashboard's API tab.\n if (DOCS_PATTERNS.has(pattern)) reply.header(\"X-Frame-Options\", \"SAMEORIGIN\");\n\n // Always the dashboard's policy: the app's own (core's security headers set one on every response) is not\n // written for this page and must not replace it.\n if (String(reply.getHeader(\"content-type\") ?? \"\").startsWith(\"text/html\")) {\n reply.header(\n \"Content-Security-Policy\",\n DOCS_PATTERNS.has(pattern) ? DOCS_CSP : DASHBOARD_CSP,\n );\n }\n\n return payload;\n });\n\n // ---- Audit ----------------------------------------------------------\n instance.addHook(\"onResponse\", async (request, reply) => {\n const context = devtoolsRequestContext(request);\n const type = context?.rule?.audit;\n\n if (!context || !type || reply.statusCode < 200 || reply.statusCode > 299) return;\n\n const params = (request.params ?? {}) as Record<string, string | undefined>;\n const detail: Record<string, string | number | boolean | null> =\n type === \"explain.run\"\n ? { shapeId: params.shapeId ?? null }\n : type === \"panel.action\"\n ? {\n panel: context.pattern.split(\"/\")[2] ?? null,\n method: request.method,\n route: context.pattern,\n }\n : {};\n\n await auth.audit(type, { auth: context.authenticated, meta: context.meta, detail });\n });\n\n // ---- Errors ---------------------------------------------------------\n instance.setErrorHandler(\n (error: Error & { statusCode?: number; code?: string }, request, reply) => {\n // A malformed grant exchange (bad JSON, too large) answers like any unknown URL.\n if (devtoolsRequestContext(request)?.pattern === SHARE_OPEN_PATTERN) {\n return notFound(request, reply);\n }\n\n if (error instanceof DevtoolsApiError) {\n return reply.code(error.statusCode).send(error.toBody());\n }\n\n const status = error.statusCode;\n\n // The request itself was wrong (bad JSON, too large): say so in the dashboard's own shape.\n if (status !== undefined && status >= 400 && status < 500) {\n return reply\n .code(status)\n .send(\n error.code?.startsWith(\"FST_ERR_\")\n ? new DevtoolsApiError(\"input.invalid\").toBody()\n : { error: error.message },\n );\n }\n\n const ref = createErrorRef();\n\n // Never rate limited: the reference the browser shows must always be findable in the log. The route is\n // written relative to the dashboard path, which never reaches the log.\n deps.warn?.(\n `Devtools dashboard error ${ref} on ${request.method} ${devtoolsRequestContext(request)?.pattern ?? \"(dashboard route)\"}: ${error.message}`,\n );\n request.log.error({ ref, err: error }, \"devtools dashboard error\");\n\n return reply.code(500).send({\n error: DEVTOOLS_ERROR_MESSAGES[\"server.error\"],\n code: \"server.error\",\n ref,\n });\n },\n );\n\n // ---- Routes ---------------------------------------------------------\n registerUiAssets(instance, { notFound });\n registerAuthRoutes(instance, deps);\n\n instance.get(\"/api/panels\", async () => listPanelInfos(deps.panels, deps.builtInPanels));\n\n registerRequestsRoutes(instance, routes);\n registerRouteRoutes(instance, routes);\n registerInsightsRoutes(instance, routes);\n registerLogRoutes(instance, routes);\n registerShapeExplainRoute(instance, routes);\n registerPanelRoutes(instance, deps.panels, { notFound });\n\n share?.register(instance, notFound);\n\n if (enabledTabs.has(\"mail\")) registerMailRoutes(instance, routes);\n if (enabledTabs.has(\"ai\") || enabledTabs.has(\"agents\")) registerAiRoutes(instance, routes);\n if (AI_REPORT_TABS.some((tab) => enabledTabs.has(tab)))\n registerAiReportRoutes(instance, routes);\n if (enabledTabs.has(\"api\")) registerOpenApiRoutes(instance, routes);\n\n registerStreamRoute(instance, routes);\n },\n { prefix },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,0BAA0B;AAChC,MAAM,2BAA2B;AAEjC,MAAM,iBAAiB;;AAGvB,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAO;CAAQ;AAAS,CAAC;;AAGvD,MAAM,gCAAgB,IAAI,IAAI,CAAC,SAAS,eAAe,CAAC;;AAGxD,MAAM,qBAAqB;;AAG3B,MAAM,oBAAoB;;AAG1B,MAAM,eAAoE;CACxE,CAAC,kBAAkB,WAAW;CAC9B,CAAC,gBAAgB,SAAS;CAC1B,CAAC,qBAAqB,QAAQ;CAC9B,CAA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}
@@ -1,6 +1,6 @@
1
- import { DEVTOOLS_BUILT_IN_PANELS, DEVTOOLS_FAILURE_AUDIT_TYPES, DEVTOOLS_LATENCY_BUCKETS_MS, DEVTOOLS_SHARE_LABEL_MAX, DevtoolsAccountView, DevtoolsApiErrorBody, DevtoolsAuditEntry, DevtoolsAuditType, DevtoolsAuthStepResult, DevtoolsBuiltInPanelId, DevtoolsCaptureCounters, DevtoolsCreatedInvite, DevtoolsCreatedShare, DevtoolsErrorCode, DevtoolsErrorGroup, DevtoolsErrorsView, DevtoolsExplainResult, DevtoolsHealthReport, DevtoolsHealthView, DevtoolsHistogram, DevtoolsInstanceInfo, DevtoolsInstanceReport, DevtoolsInstancesView, DevtoolsInviteView, DevtoolsJobsReport, DevtoolsJobsView, DevtoolsLogRow, DevtoolsLoginInput, DevtoolsLogsView, DevtoolsMode, DevtoolsPanelInfo, DevtoolsPasswordSource, DevtoolsQueryShapeRow, DevtoolsQueryShapeStats, DevtoolsQueryStatsView, DevtoolsRecoveryCodes, DevtoolsReportLogEntry, DevtoolsResourcePoint, DevtoolsResourceSnapshot, DevtoolsResourcesView, DevtoolsRole, DevtoolsRoutePhaseStats, DevtoolsRouteStats, DevtoolsRouteStatsRow, DevtoolsRouteStatsView, DevtoolsSampleDetail, DevtoolsSampleQuery, DevtoolsSampleSummary, DevtoolsScheduleInfo, DevtoolsSessionInfo, DevtoolsSessionStage, DevtoolsSessionView, DevtoolsShareCreateInput, DevtoolsShareList, DevtoolsShareOpenAnswer, DevtoolsShareStatus, DevtoolsShareView, DevtoolsTotpEnrolment, DevtoolsUserListView } from "./contracts.mjs";
1
+ import { DEVTOOLS_AI_ERROR_CATEGORIES, DEVTOOLS_AI_LATENCY_BUCKETS_MS, DEVTOOLS_BUILT_IN_PANELS, DEVTOOLS_FAILURE_AUDIT_TYPES, DEVTOOLS_LATENCY_BUCKETS_MS, DEVTOOLS_SHARE_LABEL_MAX, DevtoolsAccountView, DevtoolsAiBreakdownRow, DevtoolsAiCostTotals, DevtoolsAiErrorCategory, DevtoolsAiErrorGroup, DevtoolsAiErrorsView, DevtoolsAiEvaluatePrompt, DevtoolsAiEvaluateRequest, DevtoolsAiEvaluateResult, DevtoolsAiEvaluateView, DevtoolsAiFailedRun, DevtoolsAiFilterOptions, DevtoolsAiLatencyTotals, DevtoolsAiModelRow, DevtoolsAiModelsView, DevtoolsAiPricingState, DevtoolsAiRangePreset, DevtoolsAiRatePoint, DevtoolsAiReportView, DevtoolsAiResolvedRange, DevtoolsAiRunGroup, DevtoolsAiRunRow, DevtoolsAiRunsView, DevtoolsAiSeriesSet, DevtoolsAiTokenTotals, DevtoolsAiTotals, DevtoolsAiUnavailableReasonView, DevtoolsAiUnavailableView, DevtoolsAiUsageView, DevtoolsApiErrorBody, DevtoolsAuditEntry, DevtoolsAuditType, DevtoolsAuthStepResult, DevtoolsBuiltInPanelId, DevtoolsCaptureCounters, DevtoolsCreatedInvite, DevtoolsCreatedShare, DevtoolsErrorCode, DevtoolsErrorGroup, DevtoolsErrorsView, DevtoolsExplainResult, DevtoolsHealthReport, DevtoolsHealthView, DevtoolsHistogram, DevtoolsInstanceInfo, DevtoolsInstanceReport, DevtoolsInstancesView, DevtoolsInviteView, DevtoolsJobsReport, DevtoolsJobsView, DevtoolsLogRow, DevtoolsLoginInput, DevtoolsLogsView, DevtoolsMode, DevtoolsPanelInfo, DevtoolsPasswordSource, DevtoolsQueryShapeRow, DevtoolsQueryShapeStats, DevtoolsQueryStatsView, DevtoolsRecoveryCodes, DevtoolsReportLogEntry, DevtoolsResourcePoint, DevtoolsResourceSnapshot, DevtoolsResourcesView, DevtoolsRole, DevtoolsRoutePhaseStats, DevtoolsRouteStats, DevtoolsRouteStatsRow, DevtoolsRouteStatsView, DevtoolsSampleDetail, DevtoolsSampleQuery, DevtoolsSampleSummary, DevtoolsScheduleInfo, DevtoolsSessionInfo, DevtoolsSessionStage, DevtoolsSessionView, DevtoolsShareCreateInput, DevtoolsShareList, DevtoolsShareOpenAnswer, DevtoolsShareStatus, DevtoolsShareView, DevtoolsTotpEnrolment, DevtoolsUserListView } from "./contracts.mjs";
2
2
  import { registerDevtoolsCommands } from "./cli/index.mjs";
3
3
  import { DEVTOOLS_CONFIG_CODES, DevtoolsConfigCode, DevtoolsProductionConfigError } from "./errors.mjs";
4
4
  import { devtoolsMigrations } from "./store/migrations.mjs";
5
5
  import { ResolvedDevtoolsProductionOptions } from "./options.mjs";
6
- export { type DEVTOOLS_BUILT_IN_PANELS, DEVTOOLS_CONFIG_CODES, type DEVTOOLS_FAILURE_AUDIT_TYPES, type DEVTOOLS_LATENCY_BUCKETS_MS, type DEVTOOLS_SHARE_LABEL_MAX, type DevtoolsAccountView, type DevtoolsApiErrorBody, type DevtoolsAuditEntry, type DevtoolsAuditType, type DevtoolsAuthStepResult, type DevtoolsBuiltInPanelId, type DevtoolsCaptureCounters, type DevtoolsConfigCode, type DevtoolsCreatedInvite, type DevtoolsCreatedShare, type DevtoolsErrorCode, type DevtoolsErrorGroup, type DevtoolsErrorsView, type DevtoolsExplainResult, type DevtoolsHealthReport, type DevtoolsHealthView, type DevtoolsHistogram, type DevtoolsInstanceInfo, type DevtoolsInstanceReport, type DevtoolsInstancesView, type DevtoolsInviteView, type DevtoolsJobsReport, type DevtoolsJobsView, type DevtoolsLogRow, type DevtoolsLoginInput, type DevtoolsLogsView, type DevtoolsMode, type DevtoolsPanelInfo, type DevtoolsPasswordSource, DevtoolsProductionConfigError, type DevtoolsQueryShapeRow, type DevtoolsQueryShapeStats, type DevtoolsQueryStatsView, type DevtoolsRecoveryCodes, type DevtoolsReportLogEntry, type DevtoolsResourcePoint, type DevtoolsResourceSnapshot, type DevtoolsResourcesView, type DevtoolsRole, type DevtoolsRoutePhaseStats, type DevtoolsRouteStats, type DevtoolsRouteStatsRow, type DevtoolsRouteStatsView, type DevtoolsSampleDetail, type DevtoolsSampleQuery, type DevtoolsSampleSummary, type DevtoolsScheduleInfo, type DevtoolsSessionInfo, type DevtoolsSessionStage, type DevtoolsSessionView, type DevtoolsShareCreateInput, type DevtoolsShareList, type DevtoolsShareOpenAnswer, type DevtoolsShareStatus, type DevtoolsShareView, type DevtoolsTotpEnrolment, type DevtoolsUserListView, type ResolvedDevtoolsProductionOptions, devtoolsMigrations, registerDevtoolsCommands };
6
+ export { type DEVTOOLS_AI_ERROR_CATEGORIES, type DEVTOOLS_AI_LATENCY_BUCKETS_MS, type DEVTOOLS_BUILT_IN_PANELS, DEVTOOLS_CONFIG_CODES, type DEVTOOLS_FAILURE_AUDIT_TYPES, type DEVTOOLS_LATENCY_BUCKETS_MS, type DEVTOOLS_SHARE_LABEL_MAX, type DevtoolsAccountView, type DevtoolsAiBreakdownRow, type DevtoolsAiCostTotals, type DevtoolsAiErrorCategory, type DevtoolsAiErrorGroup, type DevtoolsAiErrorsView, type DevtoolsAiEvaluatePrompt, type DevtoolsAiEvaluateRequest, type DevtoolsAiEvaluateResult, type DevtoolsAiEvaluateView, type DevtoolsAiFailedRun, type DevtoolsAiFilterOptions, type DevtoolsAiLatencyTotals, type DevtoolsAiModelRow, type DevtoolsAiModelsView, type DevtoolsAiPricingState, type DevtoolsAiRangePreset, type DevtoolsAiRatePoint, type DevtoolsAiReportView, type DevtoolsAiResolvedRange, type DevtoolsAiRunGroup, type DevtoolsAiRunRow, type DevtoolsAiRunsView, type DevtoolsAiSeriesSet, type DevtoolsAiTokenTotals, type DevtoolsAiTotals, type DevtoolsAiUnavailableReasonView, type DevtoolsAiUnavailableView, type DevtoolsAiUsageView, type DevtoolsApiErrorBody, type DevtoolsAuditEntry, type DevtoolsAuditType, type DevtoolsAuthStepResult, type DevtoolsBuiltInPanelId, type DevtoolsCaptureCounters, type DevtoolsConfigCode, type DevtoolsCreatedInvite, type DevtoolsCreatedShare, type DevtoolsErrorCode, type DevtoolsErrorGroup, type DevtoolsErrorsView, type DevtoolsExplainResult, type DevtoolsHealthReport, type DevtoolsHealthView, type DevtoolsHistogram, type DevtoolsInstanceInfo, type DevtoolsInstanceReport, type DevtoolsInstancesView, type DevtoolsInviteView, type DevtoolsJobsReport, type DevtoolsJobsView, type DevtoolsLogRow, type DevtoolsLoginInput, type DevtoolsLogsView, type DevtoolsMode, type DevtoolsPanelInfo, type DevtoolsPasswordSource, DevtoolsProductionConfigError, type DevtoolsQueryShapeRow, type DevtoolsQueryShapeStats, type DevtoolsQueryStatsView, type DevtoolsRecoveryCodes, type DevtoolsReportLogEntry, type DevtoolsResourcePoint, type DevtoolsResourceSnapshot, type DevtoolsResourcesView, type DevtoolsRole, type DevtoolsRoutePhaseStats, type DevtoolsRouteStats, type DevtoolsRouteStatsRow, type DevtoolsRouteStatsView, type DevtoolsSampleDetail, type DevtoolsSampleQuery, type DevtoolsSampleSummary, type DevtoolsScheduleInfo, type DevtoolsSessionInfo, type DevtoolsSessionStage, type DevtoolsSessionView, type DevtoolsShareCreateInput, type DevtoolsShareList, type DevtoolsShareOpenAnswer, type DevtoolsShareStatus, type DevtoolsShareView, type DevtoolsTotpEnrolment, type DevtoolsUserListView, type ResolvedDevtoolsProductionOptions, devtoolsMigrations, registerDevtoolsCommands };
@@ -4,7 +4,7 @@ import { MigrationConstructor } from "@warlock.js/cascade";
4
4
  * The migrations of the production monitor's tables/collections:
5
5
  * `devtools_accounts`, `devtools_sessions`, `devtools_invites`,
6
6
  * `devtools_audit`, `devtools_state`, `devtools_samples`, `devtools_reports`,
7
- * `devtools_shares`.
7
+ * `devtools_shares`, `devtools_ai_rollups`.
8
8
  * An app lists them in `warlock.config.ts > database.migrations`.
9
9
  */
10
10
  export declare const devtoolsMigrations: readonly MigrationConstructor[];
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.mts","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/migrations.ts"],"mappings":";;;;;;;;;qBAmBa,6BAA6B"}
1
+ {"version":3,"file":"migrations.d.mts","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/migrations.ts"],"mappings":";;;;;;;;;qBAoBa,6BAA6B"}
@@ -1,3 +1,4 @@
1
+ import { DevtoolsAiRollupsMigration } from "./models/ai-rollup.migration.mjs";
1
2
  import { DevtoolsAccountsMigration } from "./models/account.migration.mjs";
2
3
  import { DevtoolsAuditMigration } from "./models/audit.migration.mjs";
3
4
  import { DevtoolsInvitesMigration } from "./models/invite.migration.mjs";
@@ -13,7 +14,7 @@ import "./models/index.mjs";
13
14
  * The migrations of the production monitor's tables/collections:
14
15
  * `devtools_accounts`, `devtools_sessions`, `devtools_invites`,
15
16
  * `devtools_audit`, `devtools_state`, `devtools_samples`, `devtools_reports`,
16
- * `devtools_shares`.
17
+ * `devtools_shares`, `devtools_ai_rollups`.
17
18
  * An app lists them in `warlock.config.ts > database.migrations`.
18
19
  */
19
20
  const devtoolsMigrations = [
@@ -24,7 +25,8 @@ const devtoolsMigrations = [
24
25
  DevtoolsStateMigration,
25
26
  DevtoolsSamplesMigration,
26
27
  DevtoolsReportsMigration,
27
- DevtoolsSharesMigration
28
+ DevtoolsSharesMigration,
29
+ DevtoolsAiRollupsMigration
28
30
  ];
29
31
 
30
32
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/migrations.ts"],"sourcesContent":["import type { MigrationConstructor } from \"@warlock.js/cascade\";\nimport {\n DevtoolsAccountsMigration,\n DevtoolsAuditMigration,\n DevtoolsInvitesMigration,\n DevtoolsReportsMigration,\n DevtoolsSamplesMigration,\n DevtoolsSessionsMigration,\n DevtoolsSharesMigration,\n DevtoolsStateMigration,\n} from \"./models\";\n\n/**\n * The migrations of the production monitor's tables/collections:\n * `devtools_accounts`, `devtools_sessions`, `devtools_invites`,\n * `devtools_audit`, `devtools_state`, `devtools_samples`, `devtools_reports`,\n * `devtools_shares`.\n * An app lists them in `warlock.config.ts > database.migrations`.\n */\nexport const devtoolsMigrations: readonly MigrationConstructor[] = [\n DevtoolsAccountsMigration,\n DevtoolsSessionsMigration,\n DevtoolsInvitesMigration,\n DevtoolsAuditMigration,\n DevtoolsStateMigration,\n DevtoolsSamplesMigration,\n DevtoolsReportsMigration,\n DevtoolsSharesMigration,\n];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAa,qBAAsD;CACjE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"migrations.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/migrations.ts"],"sourcesContent":["import type { MigrationConstructor } from \"@warlock.js/cascade\";\nimport {\n DevtoolsAccountsMigration,\n DevtoolsAiRollupsMigration,\n DevtoolsAuditMigration,\n DevtoolsInvitesMigration,\n DevtoolsReportsMigration,\n DevtoolsSamplesMigration,\n DevtoolsSessionsMigration,\n DevtoolsSharesMigration,\n DevtoolsStateMigration,\n} from \"./models\";\n\n/**\n * The migrations of the production monitor's tables/collections:\n * `devtools_accounts`, `devtools_sessions`, `devtools_invites`,\n * `devtools_audit`, `devtools_state`, `devtools_samples`, `devtools_reports`,\n * `devtools_shares`, `devtools_ai_rollups`.\n * An app lists them in `warlock.config.ts > database.migrations`.\n */\nexport const devtoolsMigrations: readonly MigrationConstructor[] = [\n DevtoolsAccountsMigration,\n DevtoolsSessionsMigration,\n DevtoolsInvitesMigration,\n DevtoolsAuditMigration,\n DevtoolsStateMigration,\n DevtoolsSamplesMigration,\n DevtoolsReportsMigration,\n DevtoolsSharesMigration,\n DevtoolsAiRollupsMigration,\n];\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,qBAAsD;CACjE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,48 @@
1
+ import { DEVTOOLS_AI_ERROR_CATEGORIES, DEVTOOLS_AI_LATENCY_BUCKETS_MS } from "../../contracts.mjs";
2
+ import { DevtoolsAiRollupRow } from "./ai-rollup.model.mjs";
3
+ import { migrate } from "@warlock.js/cascade";
4
+
5
+ //#region ../../packages/devtools/src/production/store/models/ai-rollup.migration.ts
6
+ const DevtoolsAiRollupsMigration = migrate(DevtoolsAiRollupRow, {
7
+ name: "devtoolsAiRollups",
8
+ up() {
9
+ this.createTableIfNotExists();
10
+ this.string("id", 64).primary().unique();
11
+ this.bigInteger("hour").index();
12
+ this.string("agent", 200).index();
13
+ this.string("model", 200).index();
14
+ this.string("provider", 100);
15
+ for (const column of [
16
+ "runs",
17
+ "completed",
18
+ "failed",
19
+ "incomplete",
20
+ "cancelled"
21
+ ]) this.integer(column).default(0);
22
+ for (const column of [
23
+ "input_tokens",
24
+ "output_tokens",
25
+ "cached_tokens",
26
+ "cache_write_tokens",
27
+ "reasoning_tokens"
28
+ ]) this.bigInteger(column).default(0);
29
+ this.double("cost_usd").default(0);
30
+ this.integer("priced_runs").default(0);
31
+ this.integer("unpriced_runs").default(0);
32
+ this.bigInteger("unpriced_tokens").default(0);
33
+ this.integer("fallback_runs").default(0);
34
+ this.integer("refusals").default(0);
35
+ for (const category of DEVTOOLS_AI_ERROR_CATEGORIES) this.integer(`err_${category.replaceAll("-", "_")}`).default(0);
36
+ for (let index = 0; index <= DEVTOOLS_AI_LATENCY_BUCKETS_MS.length; index++) this.integer(`lat_${index}`).default(0);
37
+ this.integer("latency_count").default(0);
38
+ this.double("latency_sum_ms").default(0);
39
+ this.bigInteger("updated_at");
40
+ },
41
+ down() {
42
+ this.dropTableIfExists();
43
+ }
44
+ });
45
+
46
+ //#endregion
47
+ export { DevtoolsAiRollupsMigration };
48
+ //# sourceMappingURL=ai-rollup.migration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-rollup.migration.mjs","names":[],"sources":["../../../../../../../../../../packages/devtools/src/production/store/models/ai-rollup.migration.ts"],"sourcesContent":["import { migrate } from \"@warlock.js/cascade\";\nimport { DEVTOOLS_AI_ERROR_CATEGORIES, DEVTOOLS_AI_LATENCY_BUCKETS_MS } from \"../../contracts\";\nimport { DevtoolsAiRollupRow } from \"./ai-rollup.model\";\n\nexport const DevtoolsAiRollupsMigration = migrate(DevtoolsAiRollupRow, {\n name: \"devtoolsAiRollups\",\n up() {\n this.createTableIfNotExists();\n\n // The id is `rollupId(key)`; `unique` also covers MongoDB, which ignores primary keys.\n this.string(\"id\", 64).primary().unique();\n\n this.bigInteger(\"hour\").index();\n this.string(\"agent\", 200).index();\n this.string(\"model\", 200).index();\n this.string(\"provider\", 100);\n\n for (const column of [\"runs\", \"completed\", \"failed\", \"incomplete\", \"cancelled\"]) {\n this.integer(column).default(0);\n }\n\n for (const column of [\n \"input_tokens\",\n \"output_tokens\",\n \"cached_tokens\",\n \"cache_write_tokens\",\n \"reasoning_tokens\",\n ]) {\n this.bigInteger(column).default(0);\n }\n\n this.double(\"cost_usd\").default(0);\n this.integer(\"priced_runs\").default(0);\n this.integer(\"unpriced_runs\").default(0);\n this.bigInteger(\"unpriced_tokens\").default(0);\n this.integer(\"fallback_runs\").default(0);\n this.integer(\"refusals\").default(0);\n\n for (const category of DEVTOOLS_AI_ERROR_CATEGORIES) {\n this.integer(`err_${category.replaceAll(\"-\", \"_\")}`).default(0);\n }\n\n for (let index = 0; index <= DEVTOOLS_AI_LATENCY_BUCKETS_MS.length; index++) {\n this.integer(`lat_${index}`).default(0);\n }\n\n this.integer(\"latency_count\").default(0);\n this.double(\"latency_sum_ms\").default(0);\n this.bigInteger(\"updated_at\");\n },\n down() {\n this.dropTableIfExists();\n },\n});\n"],"mappings":";;;;;AAIA,MAAa,6BAA6B,QAAQ,qBAAqB;CACrE,MAAM;CACN,KAAK;EACH,KAAK,uBAAuB;EAG5B,KAAK,OAAO,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO;EAEvC,KAAK,WAAW,MAAM,CAAC,CAAC,MAAM;EAC9B,KAAK,OAAO,SAAS,GAAG,CAAC,CAAC,MAAM;EAChC,KAAK,OAAO,SAAS,GAAG,CAAC,CAAC,MAAM;EAChC,KAAK,OAAO,YAAY,GAAG;EAE3B,KAAK,MAAM,UAAU;GAAC;GAAQ;GAAa;GAAU;GAAc;EAAW,GAC5E,KAAK,QAAQ,MAAM,CAAC,CAAC,QAAQ,CAAC;EAGhC,KAAK,MAAM,UAAU;GACnB;GACA;GACA;GACA;GACA;EACF,GACE,KAAK,WAAW,MAAM,CAAC,CAAC,QAAQ,CAAC;EAGnC,KAAK,OAAO,UAAU,CAAC,CAAC,QAAQ,CAAC;EACjC,KAAK,QAAQ,aAAa,CAAC,CAAC,QAAQ,CAAC;EACrC,KAAK,QAAQ,eAAe,CAAC,CAAC,QAAQ,CAAC;EACvC,KAAK,WAAW,iBAAiB,CAAC,CAAC,QAAQ,CAAC;EAC5C,KAAK,QAAQ,eAAe,CAAC,CAAC,QAAQ,CAAC;EACvC,KAAK,QAAQ,UAAU,CAAC,CAAC,QAAQ,CAAC;EAElC,KAAK,MAAM,YAAY,8BACrB,KAAK,QAAQ,OAAO,SAAS,WAAW,KAAK,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC;EAGhE,KAAK,IAAI,QAAQ,GAAG,SAAS,+BAA+B,QAAQ,SAClE,KAAK,QAAQ,OAAO,OAAO,CAAC,CAAC,QAAQ,CAAC;EAGxC,KAAK,QAAQ,eAAe,CAAC,CAAC,QAAQ,CAAC;EACvC,KAAK,OAAO,gBAAgB,CAAC,CAAC,QAAQ,CAAC;EACvC,KAAK,WAAW,YAAY;CAC9B;CACA,OAAO;EACL,KAAK,kBAAkB;CACzB;AACF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { DevtoolsRowModel } from "./base.mjs";
2
+
3
+ //#region ../../packages/devtools/src/production/store/models/ai-rollup.model.ts
4
+ /** A row of `devtools_ai_rollups`: hourly AI counters per agent, model and provider. */
5
+ var DevtoolsAiRollupRow = class extends DevtoolsRowModel {
6
+ static {
7
+ this.table = "devtools_ai_rollups";
8
+ }
9
+ };
10
+
11
+ //#endregion
12
+ export { DevtoolsAiRollupRow };
13
+ //# sourceMappingURL=ai-rollup.model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-rollup.model.mjs","names":[],"sources":["../../../../../../../../../../packages/devtools/src/production/store/models/ai-rollup.model.ts"],"sourcesContent":["import { DevtoolsRowModel } from \"./base\";\n\n/** A row of `devtools_ai_rollups`: hourly AI counters per agent, model and provider. */\nexport class DevtoolsAiRollupRow extends DevtoolsRowModel {\n public static table = \"devtools_ai_rollups\";\n}\n"],"mappings":";;;;AAGA,IAAa,sBAAb,cAAyC,iBAAiB;;eAClC;;AACxB"}
@@ -1,4 +1,6 @@
1
1
  import { DevtoolsRowModel } from "./base.mjs";
2
+ import { DevtoolsAiRollupRow } from "./ai-rollup.model.mjs";
3
+ import { DevtoolsAiRollupsMigration } from "./ai-rollup.migration.mjs";
2
4
  import { DevtoolsAccountRow } from "./account.model.mjs";
3
5
  import { DevtoolsAccountsMigration } from "./account.migration.mjs";
4
6
  import { DevtoolsAuditRow } from "./audit.model.mjs";
@@ -16,4 +18,4 @@ import { DevtoolsSharesMigration } from "./share.migration.mjs";
16
18
  import { DevtoolsStateRow } from "./state.model.mjs";
17
19
  import { DevtoolsStateMigration } from "./state.migration.mjs";
18
20
 
19
- export { DevtoolsAccountRow, DevtoolsAccountsMigration, DevtoolsAuditMigration, DevtoolsAuditRow, DevtoolsInviteRow, DevtoolsInvitesMigration, DevtoolsReportRow, DevtoolsReportsMigration, DevtoolsRowModel, DevtoolsSampleRow, DevtoolsSamplesMigration, DevtoolsSessionRow, DevtoolsSessionsMigration, DevtoolsShareRow, DevtoolsSharesMigration, DevtoolsStateMigration, DevtoolsStateRow };
21
+ export { DevtoolsAccountRow, DevtoolsAccountsMigration, DevtoolsAiRollupRow, DevtoolsAiRollupsMigration, DevtoolsAuditMigration, DevtoolsAuditRow, DevtoolsInviteRow, DevtoolsInvitesMigration, DevtoolsReportRow, DevtoolsReportsMigration, DevtoolsRowModel, DevtoolsSampleRow, DevtoolsSamplesMigration, DevtoolsSessionRow, DevtoolsSessionsMigration, DevtoolsShareRow, DevtoolsSharesMigration, DevtoolsStateMigration, DevtoolsStateRow };
@@ -0,0 +1,72 @@
1
+ import { DevtoolsApiError } from "../production/errors.mjs";
2
+ import { describeAiUnavailable, toAiUnavailableView } from "../sources/ai-source.mjs";
3
+
4
+ //#region ../../packages/devtools/src/server/ai-report-routes.ts
5
+ /** The answer of a route whose data source is not wired in this mode. */
6
+ const notCollected = () => toAiUnavailableView(describeAiUnavailable("not-collected"));
7
+ /** Sends a known failure as the dashboard's error body; anything else goes to the error handler. */
8
+ function sendKnown(reply, error) {
9
+ if (error instanceof DevtoolsApiError) return reply.code(error.statusCode).send(error.toBody());
10
+ throw error;
11
+ }
12
+ /**
13
+ * The AI section's report routes, inside the same guard as every panel
14
+ * (development loopback guard, or the production session and access table):
15
+ *
16
+ * - `GET /api/ai/reports` → `DevtoolsAiReportView`
17
+ * - `GET /api/ai/models` → `DevtoolsAiModelsView`
18
+ * - `GET /api/ai/errors` → `DevtoolsAiErrorsView`
19
+ * - `GET /api/ai/evaluate` → `DevtoolsAiEvaluateView`
20
+ * - `POST /api/ai/evaluate` → `DevtoolsAiEvaluateResult` (development only)
21
+ *
22
+ * Every answer is `Cache-Control: no-store`. Without `deps.aiReports` the
23
+ * report routes answer the `not-collected` view; with an unavailable one they
24
+ * answer it. Without `deps.aiEvaluator` both evaluate routes answer
25
+ * `not-collected` (GET) / `ai.evaluate-unavailable` (POST).
26
+ */
27
+ function registerAiReportRoutes(server, deps) {
28
+ for (const [route, view] of [
29
+ ["/api/ai/reports", "report"],
30
+ ["/api/ai/models", "models"],
31
+ ["/api/ai/errors", "errors"]
32
+ ]) server.get(route, async (request, reply) => {
33
+ reply.header("Cache-Control", "no-store");
34
+ const reports = deps.aiReports;
35
+ if (!reports) return notCollected();
36
+ if (!reports.available) {
37
+ const { dispose: _dispose, ...unavailable } = reports;
38
+ return unavailable;
39
+ }
40
+ try {
41
+ return await reports.service[view](request.query);
42
+ } catch (error) {
43
+ return sendKnown(reply, error);
44
+ }
45
+ });
46
+ server.get("/api/ai/evaluate", async (_request, reply) => {
47
+ reply.header("Cache-Control", "no-store");
48
+ if (!deps.aiEvaluator) return notCollected();
49
+ return deps.aiEvaluator.view();
50
+ });
51
+ if (deps.mode === "production") return;
52
+ server.post("/api/ai/evaluate", async (request, reply) => {
53
+ reply.header("Cache-Control", "no-store");
54
+ try {
55
+ if (!deps.aiEvaluator) throw new DevtoolsApiError("ai.evaluate-unavailable");
56
+ const body = request.body;
57
+ if (typeof body !== "object" || body === null || Array.isArray(body)) throw new DevtoolsApiError("input.invalid");
58
+ const { runId, systemPrompt, instructions } = body;
59
+ return await deps.aiEvaluator.evaluate({
60
+ ...runId === void 0 ? {} : { runId },
61
+ ...systemPrompt === void 0 ? {} : { systemPrompt },
62
+ ...instructions === void 0 ? {} : { instructions }
63
+ });
64
+ } catch (error) {
65
+ return sendKnown(reply, error);
66
+ }
67
+ });
68
+ }
69
+
70
+ //#endregion
71
+ export { registerAiReportRoutes };
72
+ //# sourceMappingURL=ai-report-routes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-report-routes.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/ai-report-routes.ts"],"sourcesContent":["import type { FastifyInstance, FastifyReply } from \"fastify\";\nimport type { DevtoolsAiRangeQuery } from \"../ai/reports/range\";\nimport { DevtoolsApiError } from \"../production/errors\";\nimport { describeAiUnavailable, toAiUnavailableView } from \"../sources/ai-source\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\n/** The answer of a route whose data source is not wired in this mode. */\nconst notCollected = () => toAiUnavailableView(describeAiUnavailable(\"not-collected\"));\n\n/** Sends a known failure as the dashboard's error body; anything else goes to the error handler. */\nfunction sendKnown(reply: FastifyReply, error: unknown): FastifyReply {\n if (error instanceof DevtoolsApiError) return reply.code(error.statusCode).send(error.toBody());\n\n throw error;\n}\n\n/**\n * The AI section's report routes, inside the same guard as every panel\n * (development loopback guard, or the production session and access table):\n *\n * - `GET /api/ai/reports` → `DevtoolsAiReportView`\n * - `GET /api/ai/models` → `DevtoolsAiModelsView`\n * - `GET /api/ai/errors` → `DevtoolsAiErrorsView`\n * - `GET /api/ai/evaluate` → `DevtoolsAiEvaluateView`\n * - `POST /api/ai/evaluate` → `DevtoolsAiEvaluateResult` (development only)\n *\n * Every answer is `Cache-Control: no-store`. Without `deps.aiReports` the\n * report routes answer the `not-collected` view; with an unavailable one they\n * answer it. Without `deps.aiEvaluator` both evaluate routes answer\n * `not-collected` (GET) / `ai.evaluate-unavailable` (POST).\n */\nexport function registerAiReportRoutes(\n server: FastifyInstance,\n deps: MountDevtoolsRoutesDeps,\n): void {\n for (const [route, view] of [\n [\"/api/ai/reports\", \"report\"],\n [\"/api/ai/models\", \"models\"],\n [\"/api/ai/errors\", \"errors\"],\n ] as const) {\n server.get<{ Querystring: DevtoolsAiRangeQuery }>(route, async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n\n const reports = deps.aiReports;\n\n if (!reports) return notCollected();\n\n if (!reports.available) {\n const { dispose: _dispose, ...unavailable } = reports;\n\n return unavailable;\n }\n\n try {\n return await reports.service[view](request.query);\n } catch (error) {\n return sendKnown(reply, error);\n }\n });\n }\n\n server.get(\"/api/ai/evaluate\", async (_request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n\n if (!deps.aiEvaluator) return notCollected();\n\n return deps.aiEvaluator.view();\n });\n\n // Evaluate spends a model call and reads prompt text: it exists in development only.\n if (deps.mode === \"production\") return;\n\n server.post<{ Body: unknown }>(\"/api/ai/evaluate\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n\n try {\n if (!deps.aiEvaluator) throw new DevtoolsApiError(\"ai.evaluate-unavailable\");\n\n const body = request.body;\n\n if (typeof body !== \"object\" || body === null || Array.isArray(body)) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n const { runId, systemPrompt, instructions } = body as Record<string, unknown>;\n\n return await deps.aiEvaluator.evaluate({\n ...(runId === undefined ? {} : { runId: runId as string }),\n ...(systemPrompt === undefined ? {} : { systemPrompt: systemPrompt as string }),\n ...(instructions === undefined ? {} : { inst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,IAAI,GACjE,MAAM,IAAI,iBAAiB,eAAe;GAG5C,MAAM,EAAE,OAAO,cAAc,iBAAiB;GAE9C,OAAO,MAAM,KAAK,YAAY,SAAS;IACrC,GAAI,UAAU,SAAY,CAAC,IAAI,EAAS,MAAgB;IACxD,GAAI,iBAAiB,SAAY,CAAC,IAAI,EAAgB,aAAuB;IAC7E,GAAI,iBAAiB,SAAY,CAAC,IAAI,EAAgB,aAAuB;GAC/E,CAAC;EACH,SAAS,OAAO;GACd,OAAO,UAAU,OAAO,KAAK;EAC/B;CACF,CAAC;AACH"}
@@ -1,5 +1,7 @@
1
+ import { DevtoolsApiError } from "../production/errors.mjs";
1
2
  import { AGENT_TRACE_INSTALL_GUIDANCE } from "../sources/agent-trace-source.mjs";
2
- import { describeAiUnavailable } from "../sources/ai-source.mjs";
3
+ import { describeAiUnavailable, toAiUnavailableView } from "../sources/ai-source.mjs";
4
+ import { listAiRuns } from "../ai/reports/runs.mjs";
3
5
 
4
6
  //#region ../../packages/devtools/src/server/ai-routes.ts
5
7
  /** Read-only AI metadata, inside the same development/loopback guard as every panel. */
@@ -33,6 +35,25 @@ function registerAiRoutes(server, deps) {
33
35
  aggregate: source.store.aggregate(filter)
34
36
  };
35
37
  });
38
+ server.get("/api/ai/runs", async (request, reply) => {
39
+ reply.header("Cache-Control", "no-store");
40
+ const source = deps.ai;
41
+ if (!source) return toAiUnavailableView(describeAiUnavailable(deps.mode === "production" ? "not-collected" : "ai-missing"));
42
+ if (!source.available) {
43
+ const { dispose: _dispose, ...unavailable } = source;
44
+ return toAiUnavailableView(unavailable);
45
+ }
46
+ try {
47
+ return listAiRuns(source.store.query(), request.query, {
48
+ totalCost: source.totalCost,
49
+ capacity: deps.options.maxRequests,
50
+ helpers: source.helpers
51
+ });
52
+ } catch (error) {
53
+ if (error instanceof DevtoolsApiError) return reply.code(error.statusCode).send(error.toBody());
54
+ throw error;
55
+ }
56
+ });
36
57
  server.get("/api/ai/agent-runs", async (request, reply) => {
37
58
  reply.header("Cache-Control", "no-store");
38
59
  const source = deps.agentTraces;
@@ -1 +1 @@
1
- {"version":3,"file":"ai-routes.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/ai-routes.ts"],"sourcesContent":["import type { FastifyInstance } from \"fastify\";\nimport { AGENT_TRACE_INSTALL_GUIDANCE } from \"../sources/agent-trace-source\";\nimport { describeAiUnavailable } from \"../sources/ai-source\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\n/** Read-only AI metadata, inside the same development/loopback guard as every panel. */\nexport function registerAiRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.get<{ Querystring: { requestId?: string } }>(\"/api/ai\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.ai;\n if (!source?.available) {\n if (!source) {\n // Production never attaches the feed: say so instead of claiming AI is missing.\n const reason = deps.mode === \"production\" ? \"not-collected\" : \"ai-missing\";\n return { ...describeAiUnavailable(reason), runs: [] };\n }\n const { dispose: _dispose, ...unavailable } = source;\n return { ...unavailable, runs: [] };\n }\n const filter =\n request.query.requestId === undefined ? undefined : { requestId: request.query.requestId };\n const runs = source.store.query(filter).map(source.summarize);\n // Nothing collected and nothing that would collect: say how to turn it on.\n if (!runs.length && filter === undefined && source.observationOff?.()) {\n return { ...describeAiUnavailable(\"observation-off\"), runs: [] };\n }\n return {\n available: true,\n runs,\n aggregate: source.store.aggregate(filter),\n };\n });\n\n // Per-turn agent traces recorded by `@warlock.js/ai` itself (system prompt,\n // tools offered, tool calls, refusals, retries, usage and cost). Unlike the\n // Panoptic feed above, these carry prompt and tool content: they exist for\n // debugging in development and sit behind the same guard.\n server.get<{ Querystring: { requestId?: string } }>(\n \"/api/ai/agent-runs\",\n async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.agentTraces;\n\n if (!source?.available()) {\n return { available: false, message: AGENT_TRACE_INSTALL_GUIDANCE, runs: [] };\n }\n\n return {\n available: true,\n runs: source.list(\n request.query.requestId === undefined\n ? undefined\n : { requestId: request.query.requestId },\n ),\n };\n },\n );\n\n server.get<{ Params: { id: string } }>(\"/api/ai/agent-runs/:id\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const trace = deps.agentTraces?.get(request.params.id);\n\n if (!trace) return reply.code(404).send();\n\n return trace;\n });\n\n server.get<{ Params: { id: string } }>(\"/api/ai/runs/:id\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.ai;\n const trace = source?.available ? source.store.get(request.params.id) : undefined;\n if (!trace) return reply.code(404).send();\n return trace;\n });\n}\n"],"mappings":";;;;;AAMA,SAAgB,iBAAiB,QAAyB,MAAqC;CAC7F,OAAO,IAA6C,WAAW,OAAO,SAAS,UAAU;EACvF,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QAAQ,WAAW;GACtB,IAAI,CAAC,QAAQ;IAEX,MAAM,SAAS,KAAK,SAAS,eAAe,kBAAkB;IAC9D,OAAO;KAAE,GAAG,sBAAsB,MAAM;KAAG,MAAM,CAAC;IAAE;GACtD;GACA,MAAM,EAAE,SAAS,UAAU,GAAG,gBAAgB;GAC9C,OAAO;IAAE,GAAG;IAAa,MAAM,CAAC;GAAE;EACpC;EACA,MAAM,SACJ,QAAQ,MAAM,cAAc,SAAY,SAAY,EAAE,WAAW,QAAQ,MAAM,UAAU;EAC3F,MAAM,OAAO,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,OAAO,SAAS;EAE5D,IAAI,CAAC,KAAK,UAAU,WAAW,UAAa,OAAO,iBAAiB,GAClE,OAAO;GAAE,GAAG,sBAAsB,iBAAiB;GAAG,MAAM,CAAC;EAAE;EAEjE,OAAO;GACL,WAAW;GACX;GACA,WAAW,OAAO,MAAM,UAAU,MAAM;EAC1C;CACF,CAAC;CAMD,OAAO,IACL,sBACA,OAAO,SAAS,UAAU;EACxB,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,SAAS,KAAK;EAEpB,IAAI,CAAC,QAAQ,UAAU,GACrB,OAAO;GAAE,WAAW;GAAO,SAAS;GAA8B,MAAM,CAAC;EAAE;EAG7E,OAAO;GACL,WAAW;GACX,MAAM,OAAO,KACX,QAAQ,MAAM,cAAc,SACxB,SACA,EAAE,WAAW,QAAQ,MAAM,UAAU,CAC3C;EACF;CACF,CACF;CAEA,OAAO,IAAgC,0BAA0B,OAAO,SAAS,UAAU;EACzF,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,QAAQ,KAAK,aAAa,IAAI,QAAQ,OAAO,EAAE;EAErD,IAAI,CAAC,OAAO,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;EAExC,OAAO;CACT,CAAC;CAED,OAAO,IAAgC,oBAAoB,OAAO,SAAS,UAAU;EACnF,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,SAAS,KAAK;EACpB,MAAM,QAAQ,QAAQ,YAAY,OAAO,MAAM,IAAI,QAAQ,OAAO,EAAE,IAAI;EACxE,IAAI,CAAC,OAAO,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;EACxC,OAAO;CACT,CAAC;AACH"}
1
+ {"version":3,"file":"ai-routes.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/ai-routes.ts"],"sourcesContent":["import type { FastifyInstance } from \"fastify\";\nimport { listAiRuns, type DevtoolsAiRunsQuery } from \"../ai/reports/runs\";\nimport { DevtoolsApiError } from \"../production/errors\";\nimport { AGENT_TRACE_INSTALL_GUIDANCE } from \"../sources/agent-trace-source\";\nimport { describeAiUnavailable, toAiUnavailableView } from \"../sources/ai-source\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\n\n/** Read-only AI metadata, inside the same development/loopback guard as every panel. */\nexport function registerAiRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n server.get<{ Querystring: { requestId?: string } }>(\"/api/ai\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.ai;\n if (!source?.available) {\n if (!source) {\n // Production never attaches the feed: say so instead of claiming AI is missing.\n const reason = deps.mode === \"production\" ? \"not-collected\" : \"ai-missing\";\n return { ...describeAiUnavailable(reason), runs: [] };\n }\n const { dispose: _dispose, ...unavailable } = source;\n return { ...unavailable, runs: [] };\n }\n const filter =\n request.query.requestId === undefined ? undefined : { requestId: request.query.requestId };\n const runs = source.store.query(filter).map(source.summarize);\n // Nothing collected and nothing that would collect: say how to turn it on.\n if (!runs.length && filter === undefined && source.observationOff?.()) {\n return { ...describeAiUnavailable(\"observation-off\"), runs: [] };\n }\n return {\n available: true,\n runs,\n aggregate: source.store.aggregate(filter),\n };\n });\n\n // The filtered, grouped and summarised run list the Runs page reads. Production keeps no run details.\n server.get<{ Querystring: DevtoolsAiRunsQuery }>(\"/api/ai/runs\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.ai;\n\n if (!source) {\n return toAiUnavailableView(\n describeAiUnavailable(deps.mode === \"production\" ? \"not-collected\" : \"ai-missing\"),\n );\n }\n\n if (!source.available) {\n const { dispose: _dispose, ...unavailable } = source;\n\n return toAiUnavailableView(unavailable);\n }\n\n try {\n return listAiRuns(source.store.query(), request.query, {\n totalCost: source.totalCost,\n capacity: deps.options.maxRequests,\n helpers: source.helpers,\n });\n } catch (error) {\n if (error instanceof DevtoolsApiError)\n return reply.code(error.statusCode).send(error.toBody());\n\n throw error;\n }\n });\n\n // Per-turn agent traces recorded by `@warlock.js/ai` itself (system prompt,\n // tools offered, tool calls, refusals, retries, usage and cost). Unlike the\n // Panoptic feed above, these carry prompt and tool content: they exist for\n // debugging in development and sit behind the same guard.\n server.get<{ Querystring: { requestId?: string } }>(\n \"/api/ai/agent-runs\",\n async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.agentTraces;\n\n if (!source?.available()) {\n return { available: false, message: AGENT_TRACE_INSTALL_GUIDANCE, runs: [] };\n }\n\n return {\n available: true,\n runs: source.list(\n request.query.requestId === undefined\n ? undefined\n : { requestId: request.query.requestId },\n ),\n };\n },\n );\n\n server.get<{ Params: { id: string } }>(\"/api/ai/agent-runs/:id\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const trace = deps.agentTraces?.get(request.params.id);\n\n if (!trace) return reply.code(404).send();\n\n return trace;\n });\n\n server.get<{ Params: { id: string } }>(\"/api/ai/runs/:id\", async (request, reply) => {\n reply.header(\"Cache-Control\", \"no-store\");\n const source = deps.ai;\n const trace = source?.available ? source.store.get(request.params.id) : undefined;\n if (!trace) return reply.code(404).send();\n return trace;\n });\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,iBAAiB,QAAyB,MAAqC;CAC7F,OAAO,IAA6C,WAAW,OAAO,SAAS,UAAU;EACvF,MAAM,OAAO,iBAAiB,UAAU;EACxC,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QAAQ,WAAW;GACtB,IAAI,CAAC,QAAQ;IAEX,MAAM,SAAS,KAAK,SAAS,eAAe,kBAAkB;IAC9D,OAAO;KAAE,GAAG,sBAAsB,MAAM;KAAG,MAAM,CAAC;IAAE;GACtD;GACA,MAAM,EAAE,SAAS,UAAU,GAAG,gBAAgB;GAC9C,OAAO;IAAE,GAAG;IAAa,MAAM,CAAC;GAAE;EACpC;EACA,MAAM,SACJ,QAAQ,MAAM,cAAc,SAAY,SAAY,EAAE,WAAW,QAAQ,MAAM,UAAU;EAC3F,MAAM,OAAO,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,OAAO,SAAS;EAE5D,IAAI,CAAC,KAAK,UAAU,WAAW,UAAa,OAAO,iBAAiB,GAClE,OAAO;GAAE,GAAG,sBAAsB,iBAAiB;GAAG,MAAM,CAAC;EAAE;EAEjE,OAAO;GACL,WAAW;GACX;GACA,WAAW,OAAO,MAAM,UAAU,MAAM;EAC1C;CACF,CAAC;CAGD,OAAO,IAA0C,gBAAgB,OAAO,SAAS,UAAU;EACzF,MAAM,OAAO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xE,IAAI,CAAC,OAAO,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;EACxC,OAAO;CACT,CAAC;AACH"}
@@ -1,5 +1,6 @@
1
1
  import { checkDevtoolsPanels } from "../panels.mjs";
2
2
  import { processesDevtoolsPanel } from "../process-panel.mjs";
3
+ import { registerAiReportRoutes } from "./ai-report-routes.mjs";
3
4
  import { registerAiRoutes } from "./ai-routes.mjs";
4
5
  import { registerExplainRoute, registerShapeExplainRoute } from "./explain-route.mjs";
5
6
  import { registerInsightsRoutes } from "./insights-routes.mjs";
@@ -35,6 +36,7 @@ function mountDevtoolsRoutes(server, deps) {
35
36
  registerSessionRoutes(instance, deps, panels);
36
37
  registerRequestsRoutes(instance, deps);
37
38
  registerAiRoutes(instance, deps);
39
+ registerAiReportRoutes(instance, deps);
38
40
  registerBackgroundRoutes(instance, deps);
39
41
  registerMailRoutes(instance, deps);
40
42
  registerLogRoutes(instance, deps);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/index.ts"],"sourcesContent":["import type { FastifyError, FastifyInstance } from \"fastify\";\nimport { checkDevtoolsPanels } from \"../panels\";\nimport { processesDevtoolsPanel } from \"../process-panel\";\nimport { registerAiRoutes } from \"./ai-routes\";\nimport { registerBackgroundRoutes } from \"./background-routes\";\nimport { registerExplainRoute, registerShapeExplainRoute } from \"./explain-route\";\nimport { registerInsightsRoutes } from \"./insights-routes\";\nimport { registerDevtoolsGuard } from \"./guard\";\nimport { registerLogRoutes } from \"./log-routes\";\nimport { registerMailRoutes } from \"./mail-routes\";\nimport { registerOpenApiRoutes } from \"./openapi-routes\";\nimport { registerPanelRoutes } from \"./panel-routes\";\nimport { registerRequestsRoutes } from \"./requests-routes\";\nimport { registerRouteRoutes } from \"./route-routes\";\nimport { registerSessionRoutes } from \"./session-routes\";\nimport { registerStreamRoute } from \"./stream-route\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\nimport { registerUiAssets } from \"./ui-assets\";\n\nexport type { DevtoolsRequestLogSource, DevtoolsRouteRow, MountDevtoolsRoutesDeps } from \"./types\";\n\n/**\n * Mounts the devtools dashboard and its API under `deps.options.path` on\n * `server`. Every route is registered inside a single encapsulated Fastify\n * context so the dev-only, loopback-only guard never reaches the app's\n * other routes — the registered panels' data routes and files included.\n *\n * Throws before mounting anything when a panel is invalid or reuses an id.\n */\nexport function mountDevtoolsRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n const panels = checkDevtoolsPanels([\n processesDevtoolsPanel(deps.processPanel),\n ...(deps.panels ?? []),\n ]);\n\n server.register(\n async (instance) => {\n registerDevtoolsGuard(instance, deps);\n\n instance.setErrorHandler((error: FastifyError, _request, reply) => {\n reply.code(error.statusCode ?? 500).send({ error: error.message });\n });\n\n registerUiAssets(instance);\n registerSessionRoutes(instance, deps, panels);\n registerRequestsRoutes(instance, deps);\n registerAiRoutes(instance, deps);\n registerBackgroundRoutes(instance, deps);\n registerMailRoutes(instance, deps);\n registerLogRoutes(instance, deps);\n registerRouteRoutes(instance, deps);\n registerPanelRoutes(instance, panels);\n registerOpenApiRoutes(instance, deps);\n registerExplainRoute(instance, deps);\n registerShapeExplainRoute(instance, deps);\n if (deps.insights) registerInsightsRoutes(instance, deps);\n registerStreamRoute(instance, deps);\n },\n { prefix: deps.options.path },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,oBAAoB,QAAyB,MAAqC;CAChG,MAAM,SAAS,oBAAoB,CACjC,uBAAuB,KAAK,YAAY,GACxC,GAAI,KAAK,UAAU,CAAC,CACtB,CAAC;CAED,OAAO,SACL,OAAO,aAAa;EAClB,sBAAsB,UAAU,IAAI;EAEpC,SAAS,iBAAiB,OAAqB,UAAU,UAAU;GACjE,MAAM,KAAK,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,MAAM,QAAQ,CAAC;EACnE,CAAC;EAED,iBAAiB,QAAQ;EACzB,sBAAsB,UAAU,MAAM,MAAM;EAC5C,uBAAuB,UAAU,IAAI;EACrC,iBAAiB,UAAU,IAAI;EAC/B,yBAAyB,UAAU,IAAI;EACvC,mBAAmB,UAAU,IAAI;EACjC,kBAAkB,UAAU,IAAI;EAChC,oBAAoB,UAAU,IAAI;EAClC,oBAAoB,UAAU,MAAM;EACpC,sBAAsB,UAAU,IAAI;EACpC,qBAAqB,UAAU,IAAI;EACnC,0BAA0B,UAAU,IAAI;EACxC,IAAI,KAAK,UAAU,uBAAuB,UAAU,IAAI;EACxD,oBAAoB,UAAU,IAAI;CACpC,GACA,EAAE,QAAQ,KAAK,QAAQ,KAAK,CAC9B;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/server/index.ts"],"sourcesContent":["import type { FastifyError, FastifyInstance } from \"fastify\";\nimport { checkDevtoolsPanels } from \"../panels\";\nimport { processesDevtoolsPanel } from \"../process-panel\";\nimport { registerAiReportRoutes } from \"./ai-report-routes\";\nimport { registerAiRoutes } from \"./ai-routes\";\nimport { registerBackgroundRoutes } from \"./background-routes\";\nimport { registerExplainRoute, registerShapeExplainRoute } from \"./explain-route\";\nimport { registerInsightsRoutes } from \"./insights-routes\";\nimport { registerDevtoolsGuard } from \"./guard\";\nimport { registerLogRoutes } from \"./log-routes\";\nimport { registerMailRoutes } from \"./mail-routes\";\nimport { registerOpenApiRoutes } from \"./openapi-routes\";\nimport { registerPanelRoutes } from \"./panel-routes\";\nimport { registerRequestsRoutes } from \"./requests-routes\";\nimport { registerRouteRoutes } from \"./route-routes\";\nimport { registerSessionRoutes } from \"./session-routes\";\nimport { registerStreamRoute } from \"./stream-route\";\nimport type { MountDevtoolsRoutesDeps } from \"./types\";\nimport { registerUiAssets } from \"./ui-assets\";\n\nexport type { DevtoolsRequestLogSource, DevtoolsRouteRow, MountDevtoolsRoutesDeps } from \"./types\";\n\n/**\n * Mounts the devtools dashboard and its API under `deps.options.path` on\n * `server`. Every route is registered inside a single encapsulated Fastify\n * context so the dev-only, loopback-only guard never reaches the app's\n * other routes — the registered panels' data routes and files included.\n *\n * Throws before mounting anything when a panel is invalid or reuses an id.\n */\nexport function mountDevtoolsRoutes(server: FastifyInstance, deps: MountDevtoolsRoutesDeps): void {\n const panels = checkDevtoolsPanels([\n processesDevtoolsPanel(deps.processPanel),\n ...(deps.panels ?? []),\n ]);\n\n server.register(\n async (instance) => {\n registerDevtoolsGuard(instance, deps);\n\n instance.setErrorHandler((error: FastifyError, _request, reply) => {\n reply.code(error.statusCode ?? 500).send({ error: error.message });\n });\n\n registerUiAssets(instance);\n registerSessionRoutes(instance, deps, panels);\n registerRequestsRoutes(instance, deps);\n registerAiRoutes(instance, deps);\n registerAiReportRoutes(instance, deps);\n registerBackgroundRoutes(instance, deps);\n registerMailRoutes(instance, deps);\n registerLogRoutes(instance, deps);\n registerRouteRoutes(instance, deps);\n registerPanelRoutes(instance, panels);\n registerOpenApiRoutes(instance, deps);\n registerExplainRoute(instance, deps);\n registerShapeExplainRoute(instance, deps);\n if (deps.insights) registerInsightsRoutes(instance, deps);\n registerStreamRoute(instance, deps);\n },\n { prefix: deps.options.path },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,oBAAoB,QAAyB,MAAqC;CAChG,MAAM,SAAS,oBAAoB,CACjC,uBAAuB,KAAK,YAAY,GACxC,GAAI,KAAK,UAAU,CAAC,CACtB,CAAC;CAED,OAAO,SACL,OAAO,aAAa;EAClB,sBAAsB,UAAU,IAAI;EAEpC,SAAS,iBAAiB,OAAqB,UAAU,UAAU;GACjE,MAAM,KAAK,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,MAAM,QAAQ,CAAC;EACnE,CAAC;EAED,iBAAiB,QAAQ;EACzB,sBAAsB,UAAU,MAAM,MAAM;EAC5C,uBAAuB,UAAU,IAAI;EACrC,iBAAiB,UAAU,IAAI;EAC/B,uBAAuB,UAAU,IAAI;EACrC,yBAAyB,UAAU,IAAI;EACvC,mBAAmB,UAAU,IAAI;EACjC,kBAAkB,UAAU,IAAI;EAChC,oBAAoB,UAAU,IAAI;EAClC,oBAAoB,UAAU,MAAM;EACpC,sBAAsB,UAAU,IAAI;EACpC,qBAAqB,UAAU,IAAI;EACnC,0BAA0B,UAAU,IAAI;EACxC,IAAI,KAAK,UAAU,uBAAuB,UAAU,IAAI;EACxD,oBAAoB,UAAU,IAAI;CACpC,GACA,EAAE,QAAQ,KAAK,QAAQ,KAAK,CAC9B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"agent-trace-source.d.mts","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/agent-trace-source.ts"],"mappings":";;YAiCY;EAA4B;EAAe;EAAgB;;;YAG3D;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IAAS;IAAe;;EACxB;EACA"}
1
+ {"version":3,"file":"agent-trace-source.d.mts","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/agent-trace-source.ts"],"mappings":";;YAmCY;EAA4B;EAAe;EAAgB;;;YAG3D;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IAAS;IAAe;;EACxB;EACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"agent-trace-source.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/agent-trace-source.ts"],"sourcesContent":["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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;MAErC,IAAI,WAAW,OAAO,mBAAmB;OACvC,MAAM,SAAS,WAAW,KAAK,CAAC,CAAC,KAAK;OAEtC,IAAI,CAAC,OAAO,MAAM,WAAW,OAAO,OAAO,KAAK;MAClD;KACF;IACF;IAEA,KAAK,MAAM,YAAY,WACrB,IAAI;KACF,SAAS;MAAE,GAAG;MAAO,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;KAAG,CAAC;IAC5D,QAAQ,CAER;GAEJ,CAAC;EACH;EAEA,OAAO;CACT;CAEA,eAAe;CAEf,OAAO;EACL,iBAAiB,eAAe,MAAM;EAEtC,KAAK,QAAQ;GACX,MAAM,QAAQ,eAAe;GAE7B,IAAI,CAAC,OAAO,OAAO,CAAC;GAEpB,OAAO,MACJ,KAAK,CAAC,CACN,KAAK,UAAU,oBAAoB,OAAO,WAAW,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,CACvE,QAAQ,QAAQ,QAAQ,cAAc,UAAa,IAAI,cAAc,OAAO,SAAS;EAC1F;EAEA,MAAM,UAAU,eAAe,CAAC,EAAE,IAAI,KAAK;EAE3C,UAAU,UAAU;GAClB,eAAe;GACf,UAAU,IAAI,QAAQ;GAEtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EAEA,UAAU;GACR,SAAS;GACT,SAAS;GACT,gBAAgB;GAChB,UAAU,MAAM;GAChB,WAAW,MAAM;EACnB;CACF;AACF"}
1
+ {"version":3,"file":"agent-trace-source.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/agent-trace-source.ts"],"sourcesContent":["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 /** The system prompt's hash; `text` is kept only when the agent records prompt text (development). */\n systemPrompt?: { hash: string; text?: string };\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"],"mappings":";;;;;;;AAQA,MAAa,mBAAmB,OAAO,IAAI,4BAA4B;AAEvE,MAAa,+BACX;;AAqDF,SAAgB,oBACd,OACA,WACkB;CAClB,IAAI,YAAY;CAChB,IAAI,WAAW;CAEf,KAAK,MAAM,QAAQ,MAAM,OAAO;EAC9B,aAAa,KAAK,UAAU;EAC5B,YAAY,KAAK,UAAU,QAAQ,SAAS,KAAK,YAAY,MAAS,CAAC,CAAC;CAC1E;CAEA,OAAO;EACL,OAAO,MAAM;EACb,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB,YAAY,MAAM;EAClB,OAAO,GAAG,MAAM,MAAM,SAAS,GAAG,MAAM,MAAM;EAC9C,OAAO,MAAM,MAAM;EACnB;EACA;EACA,OAAO;GAAE,OAAO,MAAM,MAAM;GAAO,QAAQ,MAAM,MAAM;EAAO;EAC9D,MAAM,MAAM;EACZ,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;CACnC;AACF;AAEA,MAAM,oBAAoB;;;;;;;AAQ1B,eAAsB,yBAA4D;CAChF,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,MAAM,4BAAY,IAAI,IAA8C;CACpE,MAAM,6BAAa,IAAI,IAAoB;CAC3C,IAAI;CACJ,IAAI;CAEJ,MAAM,kBAAuD;EAC3D,MAAM,QAAS,WACb;EAGF,OAAO,SAAS,OAAO,MAAM,SAAS,aAAa,QAAQ;CAC7D;CAEA,MAAM,uBAA4D;EAChE,MAAM,QAAQ,UAAU;EAExB,IAAI,SAAS,UAAU,eAAe;GACpC,SAAS;GACT,gBAAgB;GAChB,SAAS,MAAM,WAAW,UAAU;IAGlC,IAAI,YAAY,WAAW,IAAI,MAAM,KAAK;IAE1C,IAAI,CAAC,WAAW;KACd,YAAY,iBAAiB;KAE7B,IAAI,WAAW;MACb,WAAW,IAAI,MAAM,OAAO,SAAS;MAErC,IAAI,WAAW,OAAO,mBAAmB;OACvC,MAAM,SAAS,WAAW,KAAK,CAAC,CAAC,KAAK;OAEtC,IAAI,CAAC,OAAO,MAAM,WAAW,OAAO,OAAO,KAAK;MAClD;KACF;IACF;IAEA,KAAK,MAAM,YAAY,WACrB,IAAI;KACF,SAAS;MAAE,GAAG;MAAO,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;KAAG,CAAC;IAC5D,QAAQ,CAER;GAEJ,CAAC;EACH;EAEA,OAAO;CACT;CAEA,eAAe;CAEf,OAAO;EACL,iBAAiB,eAAe,MAAM;EAEtC,KAAK,QAAQ;GACX,MAAM,QAAQ,eAAe;GAE7B,IAAI,CAAC,OAAO,OAAO,CAAC;GAEpB,OAAO,MACJ,KAAK,CAAC,CACN,KAAK,UAAU,oBAAoB,OAAO,WAAW,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,CACvE,QAAQ,QAAQ,QAAQ,cAAc,UAAa,IAAI,cAAc,OAAO,SAAS;EAC1F;EAEA,MAAM,UAAU,eAAe,CAAC,EAAE,IAAI,KAAK;EAE3C,UAAU,UAAU;GAClB,eAAe;GACf,UAAU,IAAI,QAAQ;GAEtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EAEA,UAAU;GACR,SAAS;GACT,SAAS;GACT,gBAAgB;GAChB,UAAU,MAAM;GAChB,WAAW,MAAM;EACnB;CACF;AACF"}
@@ -1,3 +1,5 @@
1
+ import "../ai/types.mjs";
2
+ import "../ai/reports/runs.mjs";
1
3
  import "../types.mjs";
2
4
  import { Trace, TraceSpan } from "@warlock.js/ai-panoptic";
3
5
  //#region ../../packages/devtools/src/sources/ai-source.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"ai-source.d.mts","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/ai-source.ts"],"mappings":";;;YA0FY;EAAoB;EAAiB;;YAerC;EACV;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"ai-source.d.mts","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/ai-source.ts"],"mappings":";;;;;YA2HY;EAAoB;EAAiB;;YAmBrC;EACV;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA"}