@warlock.js/devtools 5.61.0 → 5.63.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 (46) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/cjs/{extract-8kaX_cUV.cjs → ai-source-CeHZDYG1.cjs} +449 -408
  3. package/cjs/ai-source-CeHZDYG1.cjs.map +1 -0
  4. package/cjs/{attach-D5aMqUnA.cjs → attach-D9gWc6lU.cjs} +19 -19
  5. package/cjs/attach-D9gWc6lU.cjs.map +1 -0
  6. package/cjs/{boot-D0nF-7w3.cjs → boot-Guumt-du.cjs} +10 -8
  7. package/cjs/boot-Guumt-du.cjs.map +1 -0
  8. package/cjs/{http-1nnpAoI7.cjs → http-CPbhLN61.cjs} +5 -5
  9. package/cjs/{http-1nnpAoI7.cjs.map → http-CPbhLN61.cjs.map} +1 -1
  10. package/cjs/index.cjs +1 -1
  11. package/cjs/{process-panel-D3D9Y_dc.cjs → process-panel-Dev6eg_f.cjs} +2 -2
  12. package/cjs/{process-panel-D3D9Y_dc.cjs.map → process-panel-Dev6eg_f.cjs.map} +1 -1
  13. package/cjs/{runs-DECWPGnq.cjs → runs-DXTf_o5P.cjs} +10 -11
  14. package/cjs/runs-DXTf_o5P.cjs.map +1 -0
  15. package/cjs/{server-DLT3uPef.cjs → server-Dc0YdP6Y.cjs} +6 -6
  16. package/cjs/{server-DLT3uPef.cjs.map → server-Dc0YdP6Y.cjs.map} +1 -1
  17. package/cjs/{src-BZiSv8A1.cjs → src-Ca1gNdZj.cjs} +15 -15
  18. package/cjs/{src-BZiSv8A1.cjs.map → src-Ca1gNdZj.cjs.map} +1 -1
  19. package/cjs/{stream-route-B6WAjbPG.cjs → stream-route-qEHoPVth.cjs} +21 -15
  20. package/cjs/stream-route-qEHoPVth.cjs.map +1 -0
  21. package/esm/ai/reports/runs.mjs +5 -6
  22. package/esm/ai/reports/runs.mjs.map +1 -1
  23. package/esm/ai/rollup/extract.mjs +21 -4
  24. package/esm/ai/rollup/extract.mjs.map +1 -1
  25. package/esm/panels.mjs +14 -1
  26. package/esm/panels.mjs.map +1 -1
  27. package/esm/production/boot.mjs +4 -2
  28. package/esm/production/boot.mjs.map +1 -1
  29. package/esm/production/options.d.mts +5 -0
  30. package/esm/production/options.d.mts.map +1 -1
  31. package/esm/production/options.mjs.map +1 -1
  32. package/esm/server/ai-routes.mjs +11 -5
  33. package/esm/server/ai-routes.mjs.map +1 -1
  34. package/esm/sources/ai-source.d.mts.map +1 -1
  35. package/esm/sources/ai-source.mjs +3 -3
  36. package/esm/sources/ai-source.mjs.map +1 -1
  37. package/esm/types.d.mts +5 -2
  38. package/esm/types.d.mts.map +1 -1
  39. package/llms-full.txt +5 -2
  40. package/package.json +8 -8
  41. package/skills/SKILL.md +5 -2
  42. package/cjs/attach-D5aMqUnA.cjs.map +0 -1
  43. package/cjs/boot-D0nF-7w3.cjs.map +0 -1
  44. package/cjs/extract-8kaX_cUV.cjs.map +0 -1
  45. package/cjs/runs-DECWPGnq.cjs.map +0 -1
  46. package/cjs/stream-route-B6WAjbPG.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"options.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/options.ts"],"sourcesContent":["import type { DevtoolsLogEntry, DevtoolsProductionOptions } from \"../types\";\nimport { DevtoolsProductionConfigError } from \"./errors\";\nimport { isValidNetworkEntry } from \"./http/ip\";\n\n/**\n * `DevtoolsProductionOptions` with every default applied and the environment\n * read. Built once at boot by `resolveProductionOptions`.\n */\nexport type ResolvedDevtoolsProductionOptions = {\n /** The dashboard path, without a trailing slash. */\n path: string;\n /** The first admin from the environment; every field `null` when unset. */\n admin: { email: string | null; password: string | null; setupToken: string | null };\n sampleRate: number;\n slowRequestMs: number;\n slowQueryMs: number;\n maxRequests: number;\n /** Queries kept per sampled request; the rest are counted in `droppedQueries`. */\n maxQueriesPerRequest: number;\n /** Query shapes kept in memory per process (least recently seen evicted). */\n maxShapes: number;\n /** Route keys kept in memory per process. */\n maxRoutes: number;\n /** Error groups kept in memory per process. */\n maxErrorGroups: number;\n requestRetentionHours: number;\n maxStoredSamplesPerMinute: number;\n reportIntervalMs: number;\n trustedProxies: readonly string[];\n requireHttps: boolean;\n allowedIps: readonly string[];\n origin: string | null;\n session: { idleMinutes: number; maxHours: number; pendingMinutes: number };\n twoFactor: \"off\" | \"admins\" | \"everyone\";\n passwords: { minLength: number; rejectCommon: boolean };\n rateLimits: {\n windowMinutes: number;\n account: number;\n ip: number;\n global: number;\n lockMinutes: number;\n };\n explain: { executing: boolean };\n panels: Readonly<Record<string, boolean>>;\n logLevels: readonly DevtoolsLogEntry[\"level\"][];\n auditRetentionDays: number;\n passkeys: { rpName: string; rpId: string | null };\n /** Read-only share links. */\n share: { enabled: boolean; maxDays: number };\n};\n\n/** The defaults `resolveProductionOptions` applies (environment values excluded). */\nexport const DEVTOOLS_PRODUCTION_DEFAULTS = {\n sampleRate: 0.1,\n slowRequestMs: 1000,\n slowQueryMs: 200,\n maxRequests: 200,\n maxQueriesPerRequest: 200,\n maxShapes: 500,\n maxRoutes: 300,\n maxErrorGroups: 100,\n requestRetentionHours: 24,\n maxStoredSamplesPerMinute: 120,\n reportIntervalMs: 10_000,\n requireHttps: true,\n session: { idleMinutes: 30, maxHours: 8, pendingMinutes: 10 },\n twoFactor: \"admins\",\n passwords: { minLength: 8, rejectCommon: true },\n rateLimits: { windowMinutes: 15, account: 5, ip: 20, global: 100, lockMinutes: 15 },\n explain: { executing: false },\n logLevels: [\"warn\", \"error\"],\n auditRetentionDays: 90,\n passkeys: { rpName: \"Warlock monitor\" },\n share: { enabled: false, maxDays: 30 },\n} as const;\n\n/** The environment variables production mode reads. */\nexport const DEVTOOLS_ENV = {\n path: \"DEVTOOLS_PATH\",\n adminEmail: \"DEVTOOLS_ADMIN_EMAIL\",\n adminPassword: \"DEVTOOLS_ADMIN_PASSWORD\",\n setupToken: \"DEVTOOLS_SETUP_TOKEN\",\n} as const;\n\nconst LOG_LEVELS: readonly DevtoolsLogEntry[\"level\"][] = [\n \"debug\",\n \"info\",\n \"warn\",\n \"error\",\n \"success\",\n];\n\nconst PATH_CHARACTERS = /^[A-Za-z0-9._~/-]+$/;\nconst MIN_PATH_LENGTH = 8;\nconst MIN_SETUP_TOKEN_LENGTH = 32;\n\nfunction invalid(option: string, expected: string): never {\n throw new DevtoolsProductionConfigError(\n \"DT007\",\n `Option \"devtools.production.${option}\" is not valid: ${expected}.`,\n );\n}\n\nfunction present(value: string | undefined): string | null {\n return value === undefined || value === \"\" ? null : value;\n}\n\nfunction integerAtLeastOne(option: string, value: number | undefined, fallback: number): number {\n if (value === undefined) return fallback;\n\n if (!Number.isInteger(value) || value < 1) invalid(option, \"use a whole number of 1 or more\");\n\n return value;\n}\n\nfunction networkList(option: string, value: readonly string[] | undefined): readonly string[] {\n if (value === undefined) return [];\n\n if (!Array.isArray(value)) {\n invalid(option, 'use a list of IPs, CIDR ranges, \"loopback\" or \"private\"');\n }\n\n for (const entry of value as readonly unknown[]) {\n if (!isValidNetworkEntry(entry)) {\n invalid(option, `\"${String(entry)}\" is not an IP, a CIDR range, \"loopback\" or \"private\"`);\n }\n }\n\n return [...value];\n}\n\n/** The dashboard path without a trailing slash, or a DT001/DT002 error. */\nfunction resolvePath(value: string | undefined): string {\n const given = present(value);\n\n if (given === null) throw new DevtoolsProductionConfigError(\"DT001\");\n\n const path = given.replace(/\\/+$/, \"\");\n const segments = path.split(\"/\").slice(1);\n const lower = path.toLowerCase();\n\n if (\n !path.startsWith(\"/\") ||\n path.length < MIN_PATH_LENGTH ||\n !PATH_CHARACTERS.test(path) ||\n segments.some((segment) => segment === \"\" || segment === \".\" || segment === \"..\") ||\n lower === \"/__warlock\" ||\n lower.startsWith(\"/__warlock/\")\n ) {\n throw new DevtoolsProductionConfigError(\"DT002\");\n }\n\n return path;\n}\n\n/**\n * Applies the defaults to `options`, reads the path and first admin from\n * `env`, and validates everything.\n *\n * Throws `DevtoolsProductionConfigError`: DT001 (no path), DT002 (bad path),\n * DT007 (an option out of range: sampleRate outside 0–1, share.maxDays outside 1–365, a non-positive\n * limit, an unknown twoFactor value, a bad CIDR, an origin that is not\n * `https://host[:port]`), DT009 (both a password and a setup token), DT010\n * (setup token shorter than 32 characters). DT003/DT004 (admin) are checked\n * later by `ensureFirstAdmin`, which needs the database.\n */\nexport function resolveProductionOptions(\n options: DevtoolsProductionOptions | undefined,\n env: Readonly<Record<string, string | undefined>>,\n): ResolvedDevtoolsProductionOptions {\n const given = options ?? {};\n const defaults = DEVTOOLS_PRODUCTION_DEFAULTS;\n const path = resolvePath(given.path ?? env[DEVTOOLS_ENV.path]);\n\n const sampleRate = given.sampleRate ?? defaults.sampleRate;\n\n if (\n typeof sampleRate !== \"number\" ||\n !Number.isFinite(sampleRate) ||\n sampleRate < 0 ||\n sampleRate > 1\n ) {\n invalid(\"sampleRate\", \"use a number from 0 to 1\");\n }\n\n const requireHttps: boolean = given.requireHttps ?? defaults.requireHttps;\n\n if (typeof requireHttps !== \"boolean\") invalid(\"requireHttps\", \"use true or false\");\n\n const twoFactor = given.twoFactor ?? defaults.twoFactor;\n\n if (twoFactor !== \"off\" && twoFactor !== \"admins\" && twoFactor !== \"everyone\") {\n invalid(\"twoFactor\", 'use \"off\", \"admins\" or \"everyone\"');\n }\n\n const minLength: number = given.passwords?.minLength ?? defaults.passwords.minLength;\n\n if (!Number.isInteger(minLength) || minLength < 8 || minLength > 72) {\n invalid(\n \"passwords.minLength\",\n \"use a whole number from 8 to 72 (passwords are limited to 72 bytes, so a longer minimum would refuse every password)\",\n );\n }\n\n const rejectCommon: boolean = given.passwords?.rejectCommon ?? defaults.passwords.rejectCommon;\n\n if (typeof rejectCommon !== \"boolean\") invalid(\"passwords.rejectCommon\", \"use true or false\");\n\n const origin = given.origin ?? null;\n\n if (origin !== null) {\n const pattern = requireHttps ? /^https:\\/\\/[^/\\s]+$/ : /^https?:\\/\\/[^/\\s]+$/;\n\n if (typeof origin !== \"string\" || !pattern.test(origin)) {\n invalid(\n \"origin\",\n requireHttps\n ? \"use an origin such as https://app.example.com, without a path or a trailing slash\"\n : \"use an origin such as http://localhost:3000, without a path or a trailing slash\",\n );\n }\n }\n\n const panels: Readonly<Record<string, unknown>> = given.panels ?? {};\n\n if (panels === null || typeof panels !== \"object\" || Array.isArray(panels)) {\n invalid(\"panels\", \"use an object of tab ids and true or false\");\n }\n\n for (const [id, enabled] of Object.entries(panels)) {\n if (typeof enabled !== \"boolean\") invalid(`panels.${id}`, \"use true or false\");\n }\n\n const logLevels = given.logLevels ?? defaults.logLevels;\n\n if (!Array.isArray(logLevels) || logLevels.some((level) => !LOG_LEVELS.includes(level))) {\n invalid(\"logLevels\", `use a list of ${LOG_LEVELS.join(\", \")}`);\n }\n\n const executing: boolean = given.explain?.executing ?? defaults.explain.executing;\n\n if (typeof executing !== \"boolean\") invalid(\"explain.executing\", \"use true or false\");\n\n const rpName: string = given.passkeys?.rpName ?? defaults.passkeys.rpName;\n const rpId = given.passkeys?.rpId ?? null;\n\n if (typeof rpName !== \"string\" || rpName.trim() === \"\") {\n invalid(\"passkeys.rpName\", \"use a non-empty name\");\n }\n\n if (rpId !== null && (typeof rpId !== \"string\" || rpId.trim() === \"\")) {\n invalid(\"passkeys.rpId\", \"use a host name such as app.example.com\");\n }\n\n const shareEnabled: boolean = given.share?.enabled ?? defaults.share.enabled;\n const shareMaxDays: number = given.share?.maxDays ?? defaults.share.maxDays;\n\n if (typeof shareEnabled !== \"boolean\") invalid(\"share.enabled\", \"use true or false\");\n\n if (!Number.isInteger(shareMaxDays) || shareMaxDays < 1 || shareMaxDays > 365) {\n invalid(\"share.maxDays\", \"use a whole number of days from 1 to 365\");\n }\n\n const limits = given.rateLimits ?? {};\n const session = given.session ?? {};\n\n const resolved: ResolvedDevtoolsProductionOptions = {\n path,\n admin: {\n email: present(env[DEVTOOLS_ENV.adminEmail]),\n password: present(env[DEVTOOLS_ENV.adminPassword]),\n setupToken: present(env[DEVTOOLS_ENV.setupToken]),\n },\n sampleRate,\n slowRequestMs: integerAtLeastOne(\"slowRequestMs\", given.slowRequestMs, defaults.slowRequestMs),\n slowQueryMs: integerAtLeastOne(\"slowQueryMs\", given.slowQueryMs, defaults.slowQueryMs),\n maxRequests: integerAtLeastOne(\"maxRequests\", given.maxRequests, defaults.maxRequests),\n maxQueriesPerRequest: defaults.maxQueriesPerRequest,\n maxShapes: defaults.maxShapes,\n maxRoutes: defaults.maxRoutes,\n maxErrorGroups: defaults.maxErrorGroups,\n requestRetentionHours: integerAtLeastOne(\n \"requestRetentionHours\",\n given.requestRetentionHours,\n defaults.requestRetentionHours,\n ),\n maxStoredSamplesPerMinute: integerAtLeastOne(\n \"maxStoredSamplesPerMinute\",\n given.maxStoredSamplesPerMinute,\n defaults.maxStoredSamplesPerMinute,\n ),\n reportIntervalMs: integerAtLeastOne(\n \"reportIntervalMs\",\n given.reportIntervalMs,\n defaults.reportIntervalMs,\n ),\n trustedProxies: networkList(\"trustedProxies\", given.trustedProxies),\n requireHttps,\n allowedIps: networkList(\"allowedIps\", given.allowedIps),\n origin,\n session: {\n idleMinutes: integerAtLeastOne(\n \"session.idleMinutes\",\n session.idleMinutes,\n defaults.session.idleMinutes,\n ),\n maxHours: integerAtLeastOne(\"session.maxHours\", session.maxHours, defaults.session.maxHours),\n pendingMinutes: defaults.session.pendingMinutes,\n },\n twoFactor,\n passwords: { minLength, rejectCommon },\n rateLimits: {\n windowMinutes: integerAtLeastOne(\n \"rateLimits.windowMinutes\",\n limits.windowMinutes,\n defaults.rateLimits.windowMinutes,\n ),\n account: integerAtLeastOne(\"rateLimits.account\", limits.account, defaults.rateLimits.account),\n ip: integerAtLeastOne(\"rateLimits.ip\", limits.ip, defaults.rateLimits.ip),\n global: integerAtLeastOne(\"rateLimits.global\", limits.global, defaults.rateLimits.global),\n lockMinutes: integerAtLeastOne(\n \"rateLimits.lockMinutes\",\n limits.lockMinutes,\n defaults.rateLimits.lockMinutes,\n ),\n },\n explain: { executing },\n panels: { ...(panels as Readonly<Record<string, boolean>>) },\n logLevels: [...logLevels],\n auditRetentionDays: integerAtLeastOne(\n \"auditRetentionDays\",\n given.auditRetentionDays,\n defaults.auditRetentionDays,\n ),\n passkeys: { rpName, rpId },\n share: { enabled: shareEnabled, maxDays: shareMaxDays },\n };\n\n if (resolved.admin.password !== null && resolved.admin.setupToken !== null) {\n throw new DevtoolsProductionConfigError(\"DT009\");\n }\n\n if (\n resolved.admin.setupToken !== null &&\n resolved.admin.setupToken.length < MIN_SETUP_TOKEN_LENGTH\n ) {\n throw new DevtoolsProductionConfigError(\"DT010\");\n }\n\n return resolved;\n}\n"],"mappings":";;;;;AAoDA,MAAa,+BAA+B;CAC1C,YAAY;CACZ,eAAe;CACf,aAAa;CACb,aAAa;CACb,sBAAsB;CACtB,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,uBAAuB;CACvB,2BAA2B;CAC3B,kBAAkB;CAClB,cAAc;CACd,SAAS;EAAE,aAAa;EAAI,UAAU;EAAG,gBAAgB;CAAG;CAC5D,WAAW;CACX,WAAW;EAAE,WAAW;EAAG,cAAc;CAAK;CAC9C,YAAY;EAAE,eAAe;EAAI,SAAS;EAAG,IAAI;EAAI,QAAQ;EAAK,aAAa;CAAG;CAClF,SAAS,EAAE,WAAW,MAAM;CAC5B,WAAW,CAAC,QAAQ,OAAO;CAC3B,oBAAoB;CACpB,UAAU,EAAE,QAAQ,kBAAkB;CACtC,OAAO;EAAE,SAAS;EAAO,SAAS;CAAG;AACvC;;AAGA,MAAa,eAAe;CAC1B,MAAM;CACN,YAAY;CACZ,eAAe;CACf,YAAY;AACd;AAEA,MAAM,aAAmD;CACvD;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,yBAAyB;AAE/B,SAAS,QAAQ,QAAgB,UAAyB;CACxD,MAAM,IAAI,8BACR,SACA,+BAA+B,OAAO,kBAAkB,SAAS,EACnE;AACF;AAEA,SAA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aACR,SAAS,QAAQ,WACnB;GACA,UAAU,kBAAkB,oBAAoB,QAAQ,UAAU,SAAS,QAAQ,QAAQ;GAC3F,gBAAgB,SAAS,QAAQ;EACnC;EACA;EACA,WAAW;GAAE;GAAW;EAAa;EACrC,YAAY;GACV,eAAe,kBACb,4BACA,OAAO,eACP,SAAS,WAAW,aACtB;GACA,SAAS,kBAAkB,sBAAsB,OAAO,SAAS,SAAS,WAAW,OAAO;GAC5F,IAAI,kBAAkB,iBAAiB,OAAO,IAAI,SAAS,WAAW,EAAE;GACxE,QAAQ,kBAAkB,qBAAqB,OAAO,QAAQ,SAAS,WAAW,MAAM;GACxF,aAAa,kBACX,0BACA,OAAO,aACP,SAAS,WAAW,WACtB;EACF;EACA,SAAS,EAAE,UAAU;EACrB,QAAQ,EAAE,GAAI,OAA6C;EAC3D,WAAW,CAAC,GAAG,SAAS;EACxB,oBAAoB,kBAClB,sBACA,MAAM,oBACN,SAAS,kBACX;EACA,UAAU;GAAE;GAAQ;EAAK;EACzB,OAAO;GAAE,SAAS;GAAc,SAAS;EAAa;CACxD;CAEA,IAAI,SAAS,MAAM,aAAa,QAAQ,SAAS,MAAM,eAAe,MACpE,MAAM,IAAI,8BAA8B,OAAO;CAGjD,IACE,SAAS,MAAM,eAAe,QAC9B,SAAS,MAAM,WAAW,SAAS,wBAEnC,MAAM,IAAI,8BAA8B,OAAO;CAGjD,OAAO;AACT"}
1
+ {"version":3,"file":"options.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/options.ts"],"sourcesContent":["import type { DevtoolsLogEntry, DevtoolsProductionOptions } from \"../types\";\nimport { DevtoolsProductionConfigError } from \"./errors\";\nimport { isValidNetworkEntry } from \"./http/ip\";\n\n/**\n * `DevtoolsProductionOptions` with every default applied and the environment\n * read. Built once at boot by `resolveProductionOptions`.\n */\nexport type ResolvedDevtoolsProductionOptions = {\n /** The dashboard path, without a trailing slash. */\n path: string;\n /** The first admin from the environment; every field `null` when unset. */\n admin: { email: string | null; password: string | null; setupToken: string | null };\n sampleRate: number;\n slowRequestMs: number;\n slowQueryMs: number;\n maxRequests: number;\n /** Queries kept per sampled request; the rest are counted in `droppedQueries`. */\n maxQueriesPerRequest: number;\n /** Query shapes kept in memory per process (least recently seen evicted). */\n maxShapes: number;\n /** Route keys kept in memory per process. */\n maxRoutes: number;\n /** Error groups kept in memory per process. */\n maxErrorGroups: number;\n requestRetentionHours: number;\n maxStoredSamplesPerMinute: number;\n reportIntervalMs: number;\n trustedProxies: readonly string[];\n requireHttps: boolean;\n allowedIps: readonly string[];\n origin: string | null;\n session: { idleMinutes: number; maxHours: number; pendingMinutes: number };\n twoFactor: \"off\" | \"admins\" | \"everyone\";\n passwords: { minLength: number; rejectCommon: boolean };\n rateLimits: {\n windowMinutes: number;\n account: number;\n ip: number;\n global: number;\n lockMinutes: number;\n };\n explain: { executing: boolean };\n /**\n * Turn a dashboard tab on or off by id. `ai` (Runs) and `agents` are development\n * tabs: they are ignored in production, with one warning at boot. Production\n * shows AI totals in the Reports, Models and Errors tabs.\n */\n panels: Readonly<Record<string, boolean>>;\n logLevels: readonly DevtoolsLogEntry[\"level\"][];\n auditRetentionDays: number;\n passkeys: { rpName: string; rpId: string | null };\n /** Read-only share links. */\n share: { enabled: boolean; maxDays: number };\n};\n\n/** The defaults `resolveProductionOptions` applies (environment values excluded). */\nexport const DEVTOOLS_PRODUCTION_DEFAULTS = {\n sampleRate: 0.1,\n slowRequestMs: 1000,\n slowQueryMs: 200,\n maxRequests: 200,\n maxQueriesPerRequest: 200,\n maxShapes: 500,\n maxRoutes: 300,\n maxErrorGroups: 100,\n requestRetentionHours: 24,\n maxStoredSamplesPerMinute: 120,\n reportIntervalMs: 10_000,\n requireHttps: true,\n session: { idleMinutes: 30, maxHours: 8, pendingMinutes: 10 },\n twoFactor: \"admins\",\n passwords: { minLength: 8, rejectCommon: true },\n rateLimits: { windowMinutes: 15, account: 5, ip: 20, global: 100, lockMinutes: 15 },\n explain: { executing: false },\n logLevels: [\"warn\", \"error\"],\n auditRetentionDays: 90,\n passkeys: { rpName: \"Warlock monitor\" },\n share: { enabled: false, maxDays: 30 },\n} as const;\n\n/** The environment variables production mode reads. */\nexport const DEVTOOLS_ENV = {\n path: \"DEVTOOLS_PATH\",\n adminEmail: \"DEVTOOLS_ADMIN_EMAIL\",\n adminPassword: \"DEVTOOLS_ADMIN_PASSWORD\",\n setupToken: \"DEVTOOLS_SETUP_TOKEN\",\n} as const;\n\nconst LOG_LEVELS: readonly DevtoolsLogEntry[\"level\"][] = [\n \"debug\",\n \"info\",\n \"warn\",\n \"error\",\n \"success\",\n];\n\nconst PATH_CHARACTERS = /^[A-Za-z0-9._~/-]+$/;\nconst MIN_PATH_LENGTH = 8;\nconst MIN_SETUP_TOKEN_LENGTH = 32;\n\nfunction invalid(option: string, expected: string): never {\n throw new DevtoolsProductionConfigError(\n \"DT007\",\n `Option \"devtools.production.${option}\" is not valid: ${expected}.`,\n );\n}\n\nfunction present(value: string | undefined): string | null {\n return value === undefined || value === \"\" ? null : value;\n}\n\nfunction integerAtLeastOne(option: string, value: number | undefined, fallback: number): number {\n if (value === undefined) return fallback;\n\n if (!Number.isInteger(value) || value < 1) invalid(option, \"use a whole number of 1 or more\");\n\n return value;\n}\n\nfunction networkList(option: string, value: readonly string[] | undefined): readonly string[] {\n if (value === undefined) return [];\n\n if (!Array.isArray(value)) {\n invalid(option, 'use a list of IPs, CIDR ranges, \"loopback\" or \"private\"');\n }\n\n for (const entry of value as readonly unknown[]) {\n if (!isValidNetworkEntry(entry)) {\n invalid(option, `\"${String(entry)}\" is not an IP, a CIDR range, \"loopback\" or \"private\"`);\n }\n }\n\n return [...value];\n}\n\n/** The dashboard path without a trailing slash, or a DT001/DT002 error. */\nfunction resolvePath(value: string | undefined): string {\n const given = present(value);\n\n if (given === null) throw new DevtoolsProductionConfigError(\"DT001\");\n\n const path = given.replace(/\\/+$/, \"\");\n const segments = path.split(\"/\").slice(1);\n const lower = path.toLowerCase();\n\n if (\n !path.startsWith(\"/\") ||\n path.length < MIN_PATH_LENGTH ||\n !PATH_CHARACTERS.test(path) ||\n segments.some((segment) => segment === \"\" || segment === \".\" || segment === \"..\") ||\n lower === \"/__warlock\" ||\n lower.startsWith(\"/__warlock/\")\n ) {\n throw new DevtoolsProductionConfigError(\"DT002\");\n }\n\n return path;\n}\n\n/**\n * Applies the defaults to `options`, reads the path and first admin from\n * `env`, and validates everything.\n *\n * Throws `DevtoolsProductionConfigError`: DT001 (no path), DT002 (bad path),\n * DT007 (an option out of range: sampleRate outside 0–1, share.maxDays outside 1–365, a non-positive\n * limit, an unknown twoFactor value, a bad CIDR, an origin that is not\n * `https://host[:port]`), DT009 (both a password and a setup token), DT010\n * (setup token shorter than 32 characters). DT003/DT004 (admin) are checked\n * later by `ensureFirstAdmin`, which needs the database.\n */\nexport function resolveProductionOptions(\n options: DevtoolsProductionOptions | undefined,\n env: Readonly<Record<string, string | undefined>>,\n): ResolvedDevtoolsProductionOptions {\n const given = options ?? {};\n const defaults = DEVTOOLS_PRODUCTION_DEFAULTS;\n const path = resolvePath(given.path ?? env[DEVTOOLS_ENV.path]);\n\n const sampleRate = given.sampleRate ?? defaults.sampleRate;\n\n if (\n typeof sampleRate !== \"number\" ||\n !Number.isFinite(sampleRate) ||\n sampleRate < 0 ||\n sampleRate > 1\n ) {\n invalid(\"sampleRate\", \"use a number from 0 to 1\");\n }\n\n const requireHttps: boolean = given.requireHttps ?? defaults.requireHttps;\n\n if (typeof requireHttps !== \"boolean\") invalid(\"requireHttps\", \"use true or false\");\n\n const twoFactor = given.twoFactor ?? defaults.twoFactor;\n\n if (twoFactor !== \"off\" && twoFactor !== \"admins\" && twoFactor !== \"everyone\") {\n invalid(\"twoFactor\", 'use \"off\", \"admins\" or \"everyone\"');\n }\n\n const minLength: number = given.passwords?.minLength ?? defaults.passwords.minLength;\n\n if (!Number.isInteger(minLength) || minLength < 8 || minLength > 72) {\n invalid(\n \"passwords.minLength\",\n \"use a whole number from 8 to 72 (passwords are limited to 72 bytes, so a longer minimum would refuse every password)\",\n );\n }\n\n const rejectCommon: boolean = given.passwords?.rejectCommon ?? defaults.passwords.rejectCommon;\n\n if (typeof rejectCommon !== \"boolean\") invalid(\"passwords.rejectCommon\", \"use true or false\");\n\n const origin = given.origin ?? null;\n\n if (origin !== null) {\n const pattern = requireHttps ? /^https:\\/\\/[^/\\s]+$/ : /^https?:\\/\\/[^/\\s]+$/;\n\n if (typeof origin !== \"string\" || !pattern.test(origin)) {\n invalid(\n \"origin\",\n requireHttps\n ? \"use an origin such as https://app.example.com, without a path or a trailing slash\"\n : \"use an origin such as http://localhost:3000, without a path or a trailing slash\",\n );\n }\n }\n\n const panels: Readonly<Record<string, unknown>> = given.panels ?? {};\n\n if (panels === null || typeof panels !== \"object\" || Array.isArray(panels)) {\n invalid(\"panels\", \"use an object of tab ids and true or false\");\n }\n\n for (const [id, enabled] of Object.entries(panels)) {\n if (typeof enabled !== \"boolean\") invalid(`panels.${id}`, \"use true or false\");\n }\n\n const logLevels = given.logLevels ?? defaults.logLevels;\n\n if (!Array.isArray(logLevels) || logLevels.some((level) => !LOG_LEVELS.includes(level))) {\n invalid(\"logLevels\", `use a list of ${LOG_LEVELS.join(\", \")}`);\n }\n\n const executing: boolean = given.explain?.executing ?? defaults.explain.executing;\n\n if (typeof executing !== \"boolean\") invalid(\"explain.executing\", \"use true or false\");\n\n const rpName: string = given.passkeys?.rpName ?? defaults.passkeys.rpName;\n const rpId = given.passkeys?.rpId ?? null;\n\n if (typeof rpName !== \"string\" || rpName.trim() === \"\") {\n invalid(\"passkeys.rpName\", \"use a non-empty name\");\n }\n\n if (rpId !== null && (typeof rpId !== \"string\" || rpId.trim() === \"\")) {\n invalid(\"passkeys.rpId\", \"use a host name such as app.example.com\");\n }\n\n const shareEnabled: boolean = given.share?.enabled ?? defaults.share.enabled;\n const shareMaxDays: number = given.share?.maxDays ?? defaults.share.maxDays;\n\n if (typeof shareEnabled !== \"boolean\") invalid(\"share.enabled\", \"use true or false\");\n\n if (!Number.isInteger(shareMaxDays) || shareMaxDays < 1 || shareMaxDays > 365) {\n invalid(\"share.maxDays\", \"use a whole number of days from 1 to 365\");\n }\n\n const limits = given.rateLimits ?? {};\n const session = given.session ?? {};\n\n const resolved: ResolvedDevtoolsProductionOptions = {\n path,\n admin: {\n email: present(env[DEVTOOLS_ENV.adminEmail]),\n password: present(env[DEVTOOLS_ENV.adminPassword]),\n setupToken: present(env[DEVTOOLS_ENV.setupToken]),\n },\n sampleRate,\n slowRequestMs: integerAtLeastOne(\"slowRequestMs\", given.slowRequestMs, defaults.slowRequestMs),\n slowQueryMs: integerAtLeastOne(\"slowQueryMs\", given.slowQueryMs, defaults.slowQueryMs),\n maxRequests: integerAtLeastOne(\"maxRequests\", given.maxRequests, defaults.maxRequests),\n maxQueriesPerRequest: defaults.maxQueriesPerRequest,\n maxShapes: defaults.maxShapes,\n maxRoutes: defaults.maxRoutes,\n maxErrorGroups: defaults.maxErrorGroups,\n requestRetentionHours: integerAtLeastOne(\n \"requestRetentionHours\",\n given.requestRetentionHours,\n defaults.requestRetentionHours,\n ),\n maxStoredSamplesPerMinute: integerAtLeastOne(\n \"maxStoredSamplesPerMinute\",\n given.maxStoredSamplesPerMinute,\n defaults.maxStoredSamplesPerMinute,\n ),\n reportIntervalMs: integerAtLeastOne(\n \"reportIntervalMs\",\n given.reportIntervalMs,\n defaults.reportIntervalMs,\n ),\n trustedProxies: networkList(\"trustedProxies\", given.trustedProxies),\n requireHttps,\n allowedIps: networkList(\"allowedIps\", given.allowedIps),\n origin,\n session: {\n idleMinutes: integerAtLeastOne(\n \"session.idleMinutes\",\n session.idleMinutes,\n defaults.session.idleMinutes,\n ),\n maxHours: integerAtLeastOne(\"session.maxHours\", session.maxHours, defaults.session.maxHours),\n pendingMinutes: defaults.session.pendingMinutes,\n },\n twoFactor,\n passwords: { minLength, rejectCommon },\n rateLimits: {\n windowMinutes: integerAtLeastOne(\n \"rateLimits.windowMinutes\",\n limits.windowMinutes,\n defaults.rateLimits.windowMinutes,\n ),\n account: integerAtLeastOne(\"rateLimits.account\", limits.account, defaults.rateLimits.account),\n ip: integerAtLeastOne(\"rateLimits.ip\", limits.ip, defaults.rateLimits.ip),\n global: integerAtLeastOne(\"rateLimits.global\", limits.global, defaults.rateLimits.global),\n lockMinutes: integerAtLeastOne(\n \"rateLimits.lockMinutes\",\n limits.lockMinutes,\n defaults.rateLimits.lockMinutes,\n ),\n },\n explain: { executing },\n panels: { ...(panels as Readonly<Record<string, boolean>>) },\n logLevels: [...logLevels],\n auditRetentionDays: integerAtLeastOne(\n \"auditRetentionDays\",\n given.auditRetentionDays,\n defaults.auditRetentionDays,\n ),\n passkeys: { rpName, rpId },\n share: { enabled: shareEnabled, maxDays: shareMaxDays },\n };\n\n if (resolved.admin.password !== null && resolved.admin.setupToken !== null) {\n throw new DevtoolsProductionConfigError(\"DT009\");\n }\n\n if (\n resolved.admin.setupToken !== null &&\n resolved.admin.setupToken.length < MIN_SETUP_TOKEN_LENGTH\n ) {\n throw new DevtoolsProductionConfigError(\"DT010\");\n }\n\n return resolved;\n}\n"],"mappings":";;;;;AAyDA,MAAa,+BAA+B;CAC1C,YAAY;CACZ,eAAe;CACf,aAAa;CACb,aAAa;CACb,sBAAsB;CACtB,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,uBAAuB;CACvB,2BAA2B;CAC3B,kBAAkB;CAClB,cAAc;CACd,SAAS;EAAE,aAAa;EAAI,UAAU;EAAG,gBAAgB;CAAG;CAC5D,WAAW;CACX,WAAW;EAAE,WAAW;EAAG,cAAc;CAAK;CAC9C,YAAY;EAAE,eAAe;EAAI,SAAS;EAAG,IAAI;EAAI,QAAQ;EAAK,aAAa;CAAG;CAClF,SAAS,EAAE,WAAW,MAAM;CAC5B,WAAW,CAAC,QAAQ,OAAO;CAC3B,oBAAoB;CACpB,UAAU,EAAE,QAAQ,kBAAkB;CACtC,OAAO;EAAE,SAAS;EAAO,SAAS;CAAG;AACvC;;AAGA,MAAa,eAA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zB,uBAAuB,kBACrB,yBACA,MAAM,uBACN,SAAS,qBACX;EACA,2BAA2B,kBACzB,6BACA,MAAM,2BACN,SAAS,yBACX;EACA,kBAAkB,kBAChB,oBACA,MAAM,kBACN,SAAS,gBACX;EACA,gBAAgB,YAAY,kBAAkB,MAAM,cAAc;EAClE;EACA,YAAY,YAAY,cAAc,MAAM,UAAU;EACtD;EACA,SAAS;GACP,aAAa,kBACX,uBACA,QAAQ,aACR,SAAS,QAAQ,WACnB;GACA,UAAU,kBAAkB,oBAAoB,QAAQ,UAAU,SAAS,QAAQ,QAAQ;GAC3F,gBAAgB,SAAS,QAAQ;EACnC;EACA;EACA,WAAW;GAAE;GAAW;EAAa;EACrC,YAAY;GACV,eAAe,kBACb,4BACA,OAAO,eACP,SAAS,WAAW,aACtB;GACA,SAAS,kBAAkB,sBAAsB,OAAO,SAAS,SAAS,WAAW,OAAO;GAC5F,IAAI,kBAAkB,iBAAiB,OAAO,IAAI,SAAS,WAAW,EAAE;GACxE,QAAQ,kBAAkB,qBAAqB,OAAO,QAAQ,SAAS,WAAW,MAAM;GACxF,aAAa,kBACX,0BACA,OAAO,aACP,SAAS,WAAW,WACtB;EACF;EACA,SAAS,EAAE,UAAU;EACrB,QAAQ,EAAE,GAAI,OAA6C;EAC3D,WAAW,CAAC,GAAG,SAAS;EACxB,oBAAoB,kBAClB,sBACA,MAAM,oBACN,SAAS,kBACX;EACA,UAAU;GAAE;GAAQ;EAAK;EACzB,OAAO;GAAE,SAAS;GAAc,SAAS;EAAa;CACxD;CAEA,IAAI,SAAS,MAAM,aAAa,QAAQ,SAAS,MAAM,eAAe,MACpE,MAAM,IAAI,8BAA8B,OAAO;CAGjD,IACE,SAAS,MAAM,eAAe,QAC9B,SAAS,MAAM,WAAW,SAAS,wBAEnC,MAAM,IAAI,8BAA8B,OAAO;CAGjD,OAAO;AACT"}
@@ -57,11 +57,17 @@ function registerAiRoutes(server, deps) {
57
57
  server.get("/api/ai/agent-runs", async (request, reply) => {
58
58
  reply.header("Cache-Control", "no-store");
59
59
  const source = deps.agentTraces;
60
- if (!source?.available()) return {
61
- available: false,
62
- message: AGENT_TRACE_INSTALL_GUIDANCE,
63
- runs: []
64
- };
60
+ if (!source?.available()) {
61
+ if (deps.mode === "production") return {
62
+ ...describeAiUnavailable("not-collected"),
63
+ runs: []
64
+ };
65
+ return {
66
+ available: false,
67
+ message: AGENT_TRACE_INSTALL_GUIDANCE,
68
+ runs: []
69
+ };
70
+ }
65
71
  return {
66
72
  available: true,
67
73
  runs: source.list(request.query.requestId === void 0 ? void 0 : { requestId: request.query.requestId })
@@ -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 { 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 (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AO;GAClB,CAAC;EACH,SAAS,OAAO;GACd,IAAI,iBAAiB,kBACnB,OAAO,MAAM,KAAK,MAAM,UAAU,CAAC,CAAC,KAAK,MAAM,OAAO,CAAC;GAEzD,MAAM;EACR;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 // Production never records agent traces: say so instead of the development install guidance.\n if (deps.mode === \"production\") {\n return { ...describeAiUnavailable(\"not-collected\"), runs: [] };\n }\n\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,OAA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AC3C;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 +1 @@
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"}
1
+ {"version":3,"file":"ai-source.d.mts","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/ai-source.ts"],"mappings":";;;;;YA4HY;EAAoB;EAAiB;;YAmBrC;EACV;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA"}
@@ -1,4 +1,5 @@
1
1
  import { installedVersion } from "../app-versions.mjs";
2
+ import { spanModelOf } from "../ai/rollup/extract.mjs";
2
3
  import { toSafeValue } from "../safe-value.mjs";
3
4
 
4
5
  //#region ../../packages/devtools/src/sources/ai-source.ts
@@ -87,9 +88,8 @@ function summarizeAiTrace(trace, cost) {
87
88
  let providerCompactions = 0;
88
89
  const visit = (span) => {
89
90
  const attributes = span.attributes ?? {};
90
- const model = attributes["agent.model.name"];
91
- const provider = attributes["agent.model.provider"];
92
- if (typeof model === "string") models.add(typeof provider === "string" ? `${provider}/${model}` : model);
91
+ const { name: model, provider } = spanModelOf(span);
92
+ if (model !== void 0) models.add(provider !== void 0 ? `${provider}/${model}` : model);
93
93
  if (span.type === "tool") toolCalls += 1;
94
94
  if (typeof attributes.retries === "number") retries += attributes.retries;
95
95
  if (typeof attributes["agent.cacheHits"] === "number") cacheHits = (cacheHits ?? 0) + attributes["agent.cacheHits"];
@@ -1 +1 @@
1
- {"version":3,"file":"ai-source.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/ai-source.ts"],"sourcesContent":["import type { Trace, TraceSpan, TraceStoreContract } from \"@warlock.js/ai-panoptic\";\nimport { installedVersion } from \"../app-versions\";\nimport type { DevtoolsAiRunHelpers } from \"../ai/reports/runs\";\nimport type { DevtoolsAiTotalCost } from \"../ai/types\";\nimport type { DevtoolsAiUnavailableView } from \"../production/contracts\";\nimport { toSafeValue } from \"../safe-value\";\nimport type { DevtoolsDisposer } from \"../types\";\n\nexport type DevtoolsAiUnavailableReason =\n | \"ai-missing\"\n | \"panoptic-missing\"\n | \"panoptic-failed\"\n | \"observation-off\"\n | \"not-collected\"\n | \"table-missing\"\n | \"reports-off\";\n\n/** Why the AI tab is empty, as sent to the dashboard: a title, one line and an optional command. */\nexport type DevtoolsAiUnavailable = {\n available: false;\n reason: DevtoolsAiUnavailableReason;\n title: string;\n message: string;\n command?: string;\n detail?: string;\n};\n\n/** Replaces absolute file paths in an error line with their package-relative part, or `<path>`. */\nexport function redactPaths(text: string): string {\n return text.replace(/(?:file:\\/\\/)?(?:[A-Za-z]:)?[\\\\/][^\\s'\"`()]*/g, (match) => {\n const normalized = match.replace(/^file:\\/\\//, \"\").replaceAll(\"\\\\\", \"/\");\n const index = normalized.lastIndexOf(\"node_modules/\");\n\n return index === -1 ? \"<path>\" : normalized.slice(index + \"node_modules/\".length);\n });\n}\n\nconst OBSERVATION_COMMAND = \"ai.config({ panoptic: { observeAll: true } })\";\n\n/** The answer for each reason; `detail` carries the load error and versions for `panoptic-failed`. */\nexport function describeAiUnavailable(\n reason: DevtoolsAiUnavailableReason,\n detail?: string,\n): DevtoolsAiUnavailable {\n switch (reason) {\n case \"ai-missing\":\n return {\n available: false,\n reason,\n title: \"AI isn't installed\",\n message: \"Add @warlock.js/ai to see AI runs here.\",\n command: \"warlock add ai\",\n };\n case \"panoptic-missing\":\n return {\n available: false,\n reason,\n title: \"Panoptic isn't installed\",\n message: \"Your app uses @warlock.js/ai. Add Panoptic to see its runs.\",\n command: \"warlock add ai-panoptic\",\n };\n case \"panoptic-failed\":\n return {\n available: false,\n reason,\n title: \"Panoptic could not be loaded\",\n message:\n \"Panoptic is installed but failed to load. Check that both packages share a version.\",\n detail,\n };\n case \"not-collected\":\n return {\n available: false,\n reason,\n title: \"AI runs are not collected here\",\n message:\n \"Production keeps hourly AI totals, not run details. Open Reports, Models or Errors here, or the Runs tab in development (warlock dev).\",\n };\n case \"table-missing\":\n return {\n available: false,\n reason,\n title: \"AI reports need their table\",\n message: \"Run the devtools migrations to create devtools_ai_rollups, then restart the app.\",\n command: \"warlock migrate\",\n };\n case \"reports-off\":\n return {\n available: false,\n reason,\n title: \"AI reports are off\",\n message:\n \"Set devtools.ai.reports to true in src/config/devtools.ts to keep hourly AI totals.\",\n };\n case \"observation-off\":\n return {\n available: false,\n reason,\n title: \"AI observation is off\",\n message: \"Turn it on in src/config/ai.ts, then restart warlock dev.\",\n command: OBSERVATION_COMMAND,\n };\n }\n}\n\n/** The unavailable answer as the AI routes send it: `command` and `detail` are `null` when absent. */\nexport function toAiUnavailableView(unavailable: DevtoolsAiUnavailable): DevtoolsAiUnavailableView {\n return {\n available: false,\n reason: unavailable.reason,\n title: unavailable.title,\n message: unavailable.message,\n command: unavailable.command ?? null,\n detail: unavailable.detail ?? null,\n };\n}\n\n/** Test seam: how packages are loaded and their versions read. */\nexport type AiSourceDeps = {\n load?: (name: string) => Promise<unknown>;\n version?: (name: string) => string | null;\n};\n\nexport type DevtoolsAiEvent = { traceId: string; requestId?: string };\n\n/** Only the connector's development branch constructs this source. */\nexport type DevtoolsAiSource =\n | (DevtoolsAiUnavailable & { dispose: DevtoolsDisposer })\n | {\n available: true;\n /** True when `@warlock.js/ai` has no `observeAll` and no registered observer (read per request). */\n observationOff?: () => boolean;\n /** Totals a trace's priced usage (Panoptic's `totalCostUsd`). */\n totalCost: DevtoolsAiTotalCost;\n /** Panoptic's trace filter, grouping and percentile helpers for the Runs list. */\n helpers: DevtoolsAiRunHelpers;\n store: TraceStoreContract;\n summarize: (trace: Trace) => DevtoolsAiRun;\n subscribe: (listener: (event: DevtoolsAiEvent) => void) => DevtoolsDisposer;\n dispose: DevtoolsDisposer;\n };\n\nexport type DevtoolsAiRun = {\n traceId: string;\n requestId?: string;\n sessionId?: string;\n name: string;\n status: TraceSpan[\"status\"];\n startedAt: string;\n duration: number;\n usage: Trace[\"usage\"];\n cost?: number;\n models: string[];\n toolCalls: number;\n retries: number;\n cacheHits?: number;\n incomplete: boolean;\n truncatedTrips: number;\n compactions: number;\n skippedCompactions: number;\n providerCompactions: number;\n};\n\n/** Summaries use root usage once: nested spans already roll up into it. */\nexport function summarizeAiTrace(trace: Trace, cost?: number): DevtoolsAiRun {\n const models = new Set<string>();\n let toolCalls = 0;\n let retries = 0;\n let cacheHits: number | undefined;\n let incomplete = false;\n let truncatedTrips = 0;\n let compactions = 0;\n let skippedCompactions = 0;\n let providerCompactions = 0;\n const visit = (span: TraceSpan): void => {\n const attributes = span.attributes ?? {};\n const model = attributes[\"agent.model.name\"];\n const provider = attributes[\"agent.model.provider\"];\n if (typeof model === \"string\")\n models.add(typeof provider === \"string\" ? `${provider}/${model}` : model);\n if (span.type === \"tool\") toolCalls += 1;\n if (typeof attributes.retries === \"number\") retries += attributes.retries;\n if (typeof attributes[\"agent.cacheHits\"] === \"number\")\n cacheHits = (cacheHits ?? 0) + attributes[\"agent.cacheHits\"];\n if (typeof attributes[\"agent.truncatedTrips\"] === \"number\")\n truncatedTrips += attributes[\"agent.truncatedTrips\"];\n if (typeof attributes[\"agent.providerCompactions\"] === \"number\")\n providerCompactions += attributes[\"agent.providerCompactions\"];\n if (Array.isArray(attributes[\"agent.compactions\"])) {\n const records: unknown[] = attributes[\"agent.compactions\"];\n for (const record of records) {\n if (typeof record !== \"object\" || record === null || !(\"type\" in record)) continue;\n if (record.type === \"applied\") compactions += 1;\n if (record.type === \"skipped\") skippedCompactions += 1;\n }\n }\n incomplete ||=\n span.status === \"incomplete\" ||\n span.error?.type === \"AgentIncompleteError\" ||\n span.error?.type === \"AGENT_INCOMPLETE\";\n span.children.forEach(visit);\n };\n visit(trace.root);\n return {\n traceId: trace.traceId,\n requestId: trace.requestId,\n sessionId: trace.sessionId,\n name: trace.root.name,\n status: trace.root.status,\n startedAt: trace.startedAt,\n duration: trace.duration,\n usage: trace.usage,\n cost,\n models: [...models],\n toolCalls,\n retries,\n cacheHits,\n incomplete,\n truncatedTrips,\n compactions,\n skippedCompactions,\n providerCompactions,\n };\n}\n\n/** Content-free snapshot; never retain prompts, completions or tool arguments/results. */\nfunction snapshotSpan(span: TraceSpan): TraceSpan {\n return {\n spanId: span.spanId,\n parentSpanId: span.parentSpanId,\n traceId: span.traceId,\n sessionId: span.sessionId,\n name: span.name,\n version: span.version,\n type: span.type,\n status: span.status,\n startedAt: span.startedAt,\n endedAt: span.endedAt,\n duration: span.duration,\n usage: structuredClone(span.usage),\n error: span.error ? { type: span.error.type, message: span.error.message } : undefined,\n attributes: toSafeValue(span.attributes) as Record<string, unknown> | undefined,\n children: span.children.map(snapshotSpan),\n };\n}\n\ntype PanopticModule = typeof import(\"@warlock.js/ai-panoptic\");\ntype AiCoreModule = { isObserveAll?: () => boolean; getObservers?: () => readonly unknown[] };\n\n/**\n * Loads Panoptic (required) and `@warlock.js/ai` (for the observation check)\n * lazily, or says why not. Shared by the development source and the AI\n * reports wiring, so both answer the same unavailable reasons.\n */\nexport async function loadAiPackages(\n deps: AiSourceDeps = {},\n): Promise<\n | { panoptic: PanopticModule; observationOff: () => boolean }\n | { unavailable: DevtoolsAiUnavailable }\n> {\n const aiPackage: string = \"@warlock.js/ai\"; // not a dependency of devtools: never resolved at build time\n const load =\n deps.load ??\n ((name: string) =>\n name === \"@warlock.js/ai-panoptic\" ? import(\"@warlock.js/ai-panoptic\") : import(aiPackage));\n const version =\n deps.version ?? ((name: string) => installedVersion(name, process.cwd(), import.meta.resolve));\n let panoptic: PanopticModule;\n try {\n panoptic = (await load(\"@warlock.js/ai-panoptic\")) as PanopticModule;\n if (typeof panoptic.subscribeTraces !== \"function\")\n throw new Error(\"Trace subscription unavailable\");\n } catch (error) {\n const aiVersion = version(\"@warlock.js/ai\");\n const panopticVersion = version(\"@warlock.js/ai-panoptic\");\n if (aiVersion === null) return { unavailable: describeAiUnavailable(\"ai-missing\") };\n if (panopticVersion === null) return { unavailable: describeAiUnavailable(\"panoptic-missing\") };\n const text = redactPaths(\n (error instanceof Error ? error.message : String(error)).split(\"\\n\")[0] ?? \"\",\n ).slice(0, 300);\n return {\n unavailable: describeAiUnavailable(\n \"panoptic-failed\",\n `${text} (@warlock.js/ai ${aiVersion}, @warlock.js/ai-panoptic ${panopticVersion})`,\n ),\n };\n }\n\n let core: AiCoreModule | undefined;\n try {\n core = (await load(\"@warlock.js/ai\")) as AiCoreModule;\n } catch {\n core = undefined;\n }\n const observationOff = (): boolean =>\n typeof core?.isObserveAll === \"function\" &&\n typeof core.getObservers === \"function\" &&\n !core.isObserveAll() &&\n core.getObservers().length === 0;\n\n return { panoptic, observationOff };\n}\n\n/**\n * Optional, lazy integration. Retains only traces collected after devtools boots,\n * using Panoptic's bounded query store; existing exporter/cache stores stay independent.\n */\nexport async function attachAiSource(\n capacity: number,\n deps: AiSourceDeps = {},\n): Promise<DevtoolsAiSource> {\n const loaded = await loadAiPackages(deps);\n if (\"unavailable\" in loaded) return { ...loaded.unavailable, dispose() {} };\n const { panoptic, observationOff } = loaded;\n\n const { currentRequestId } = await import(\"../current-request-id\");\n const store = panoptic.createInMemoryTraceStore({ capacity });\n const listeners = new Set<(event: DevtoolsAiEvent) => void>();\n const detach = panoptic.subscribeTraces((trace) => {\n // Read ALS before any asynchronous exporter work, including for runs that\n // finish after the HTTP response. Never use sessionId as a request id.\n const requestId = currentRequestId() ?? trace.requestId;\n store.add({\n ...trace,\n requestId,\n usage: structuredClone(trace.usage),\n root: snapshotSpan(trace.root),\n });\n for (const listener of listeners) {\n try {\n listener({ traceId: trace.traceId, requestId });\n } catch {\n /* isolate clients */\n }\n }\n });\n\n return {\n available: true,\n observationOff,\n totalCost: (usage) => panoptic.totalCostUsd(usage),\n helpers: {\n filterTraces: panoptic.filterTraces,\n groupBySession: panoptic.groupBySession,\n groupByPrompt: panoptic.groupByPrompt,\n groupByType: panoptic.groupByType,\n percentile: panoptic.percentile,\n tracePromptKey: panoptic.tracePromptKey,\n },\n store,\n summarize: (trace) => summarizeAiTrace(trace, panoptic.totalCostUsd(trace.usage)),\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n dispose() {\n detach();\n listeners.clear();\n store.clear();\n },\n };\n}\n"],"mappings":";;;;;AA4BA,SAAgB,YAAY,MAAsB;CAChD,OAAO,KAAK,QAAQ,kDAAkD,UAAU;EAC9E,MAAM,aAAa,MAAM,QAAQ,cAAc,EAAE,CAAC,CAAC,WAAW,MAAM,GAAG;EACvE,MAAM,QAAQ,WAAW,YAAY,eAAe;EAEpD,OAAO,UAAU,KAAK,WAAW,WAAW,MAAM,QAAQ,EAAsB;CAClF,CAAC;AACH;AAEA,MAAM,sBAAsB;;AAG5B,SAAgB,sBACd,QACA,QACuB;CACvB,QAAQ,QAAR;EACE,KAAK,cACH,OAAO;GACL,WAAW;GACX;GACA,OAAO;GACP,SAAS;GACT,SAAS;EACX;EACF,KAAK,oBACH,OAAO;GACL,WAAW;GACX;GACA,OAAO;GACP,SAAS;GACT,SAA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AC9C,MAAM,IAAI;GACR,GAAG;GACH;GACA,OAAO,gBAAgB,MAAM,KAAK;GAClC,MAAM,aAAa,MAAM,IAAI;EAC/B,CAAC;EACD,KAAK,MAAM,YAAY,WACrB,IAAI;GACF,SAAS;IAAE,SAAS,MAAM;IAAS;GAAU,CAAC;EAChD,QAAQ,CAER;CAEJ,CAAC;CAED,OAAO;EACL,WAAW;EACX;EACA,YAAY,UAAU,SAAS,aAAa,KAAK;EACjD,SAAS;GACP,cAAc,SAAS;GACvB,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,aAAa,SAAS;GACtB,YAAY,SAAS;GACrB,gBAAgB,SAAS;EAC3B;EACA;EACA,YAAY,UAAU,iBAAiB,OAAO,SAAS,aAAa,MAAM,KAAK,CAAC;EAChF,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,UAAU;GACR,OAAO;GACP,UAAU,MAAM;GAChB,MAAM,MAAM;EACd;CACF;AACF"}
1
+ {"version":3,"file":"ai-source.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/sources/ai-source.ts"],"sourcesContent":["import type { Trace, TraceSpan, TraceStoreContract } from \"@warlock.js/ai-panoptic\";\nimport { installedVersion } from \"../app-versions\";\nimport type { DevtoolsAiRunHelpers } from \"../ai/reports/runs\";\nimport { spanModelOf } from \"../ai/rollup/extract\";\nimport type { DevtoolsAiTotalCost } from \"../ai/types\";\nimport type { DevtoolsAiUnavailableView } from \"../production/contracts\";\nimport { toSafeValue } from \"../safe-value\";\nimport type { DevtoolsDisposer } from \"../types\";\n\nexport type DevtoolsAiUnavailableReason =\n | \"ai-missing\"\n | \"panoptic-missing\"\n | \"panoptic-failed\"\n | \"observation-off\"\n | \"not-collected\"\n | \"table-missing\"\n | \"reports-off\";\n\n/** Why the AI tab is empty, as sent to the dashboard: a title, one line and an optional command. */\nexport type DevtoolsAiUnavailable = {\n available: false;\n reason: DevtoolsAiUnavailableReason;\n title: string;\n message: string;\n command?: string;\n detail?: string;\n};\n\n/** Replaces absolute file paths in an error line with their package-relative part, or `<path>`. */\nexport function redactPaths(text: string): string {\n return text.replace(/(?:file:\\/\\/)?(?:[A-Za-z]:)?[\\\\/][^\\s'\"`()]*/g, (match) => {\n const normalized = match.replace(/^file:\\/\\//, \"\").replaceAll(\"\\\\\", \"/\");\n const index = normalized.lastIndexOf(\"node_modules/\");\n\n return index === -1 ? \"<path>\" : normalized.slice(index + \"node_modules/\".length);\n });\n}\n\nconst OBSERVATION_COMMAND = \"ai.config({ panoptic: { observeAll: true } })\";\n\n/** The answer for each reason; `detail` carries the load error and versions for `panoptic-failed`. */\nexport function describeAiUnavailable(\n reason: DevtoolsAiUnavailableReason,\n detail?: string,\n): DevtoolsAiUnavailable {\n switch (reason) {\n case \"ai-missing\":\n return {\n available: false,\n reason,\n title: \"AI isn't installed\",\n message: \"Add @warlock.js/ai to see AI runs here.\",\n command: \"warlock add ai\",\n };\n case \"panoptic-missing\":\n return {\n available: false,\n reason,\n title: \"Panoptic isn't installed\",\n message: \"Your app uses @warlock.js/ai. Add Panoptic to see its runs.\",\n command: \"warlock add ai-panoptic\",\n };\n case \"panoptic-failed\":\n return {\n available: false,\n reason,\n title: \"Panoptic could not be loaded\",\n message:\n \"Panoptic is installed but failed to load. Check that both packages share a version.\",\n detail,\n };\n case \"not-collected\":\n return {\n available: false,\n reason,\n title: \"AI runs are not collected here\",\n message:\n \"Production keeps hourly AI totals, not run details. Open Reports, Models or Errors here, or the Runs tab in development (warlock dev).\",\n };\n case \"table-missing\":\n return {\n available: false,\n reason,\n title: \"AI reports need their table\",\n message: \"Run the devtools migrations to create devtools_ai_rollups, then restart the app.\",\n command: \"warlock migrate\",\n };\n case \"reports-off\":\n return {\n available: false,\n reason,\n title: \"AI reports are off\",\n message:\n \"Set devtools.ai.reports to true in src/config/devtools.ts to keep hourly AI totals.\",\n };\n case \"observation-off\":\n return {\n available: false,\n reason,\n title: \"AI observation is off\",\n message: \"Turn it on in src/config/ai.ts, then restart warlock dev.\",\n command: OBSERVATION_COMMAND,\n };\n }\n}\n\n/** The unavailable answer as the AI routes send it: `command` and `detail` are `null` when absent. */\nexport function toAiUnavailableView(unavailable: DevtoolsAiUnavailable): DevtoolsAiUnavailableView {\n return {\n available: false,\n reason: unavailable.reason,\n title: unavailable.title,\n message: unavailable.message,\n command: unavailable.command ?? null,\n detail: unavailable.detail ?? null,\n };\n}\n\n/** Test seam: how packages are loaded and their versions read. */\nexport type AiSourceDeps = {\n load?: (name: string) => Promise<unknown>;\n version?: (name: string) => string | null;\n};\n\nexport type DevtoolsAiEvent = { traceId: string; requestId?: string };\n\n/** Only the connector's development branch constructs this source. */\nexport type DevtoolsAiSource =\n | (DevtoolsAiUnavailable & { dispose: DevtoolsDisposer })\n | {\n available: true;\n /** True when `@warlock.js/ai` has no `observeAll` and no registered observer (read per request). */\n observationOff?: () => boolean;\n /** Totals a trace's priced usage (Panoptic's `totalCostUsd`). */\n totalCost: DevtoolsAiTotalCost;\n /** Panoptic's trace filter, grouping and percentile helpers for the Runs list. */\n helpers: DevtoolsAiRunHelpers;\n store: TraceStoreContract;\n summarize: (trace: Trace) => DevtoolsAiRun;\n subscribe: (listener: (event: DevtoolsAiEvent) => void) => DevtoolsDisposer;\n dispose: DevtoolsDisposer;\n };\n\nexport type DevtoolsAiRun = {\n traceId: string;\n requestId?: string;\n sessionId?: string;\n name: string;\n status: TraceSpan[\"status\"];\n startedAt: string;\n duration: number;\n usage: Trace[\"usage\"];\n cost?: number;\n models: string[];\n toolCalls: number;\n retries: number;\n cacheHits?: number;\n incomplete: boolean;\n truncatedTrips: number;\n compactions: number;\n skippedCompactions: number;\n providerCompactions: number;\n};\n\n/** Summaries use root usage once: nested spans already roll up into it. */\nexport function summarizeAiTrace(trace: Trace, cost?: number): DevtoolsAiRun {\n const models = new Set<string>();\n let toolCalls = 0;\n let retries = 0;\n let cacheHits: number | undefined;\n let incomplete = false;\n let truncatedTrips = 0;\n let compactions = 0;\n let skippedCompactions = 0;\n let providerCompactions = 0;\n const visit = (span: TraceSpan): void => {\n const attributes = span.attributes ?? {};\n const { name: model, provider } = spanModelOf(span);\n if (model !== undefined) models.add(provider !== undefined ? `${provider}/${model}` : model);\n if (span.type === \"tool\") toolCalls += 1;\n if (typeof attributes.retries === \"number\") retries += attributes.retries;\n if (typeof attributes[\"agent.cacheHits\"] === \"number\")\n cacheHits = (cacheHits ?? 0) + attributes[\"agent.cacheHits\"];\n if (typeof attributes[\"agent.truncatedTrips\"] === \"number\")\n truncatedTrips += attributes[\"agent.truncatedTrips\"];\n if (typeof attributes[\"agent.providerCompactions\"] === \"number\")\n providerCompactions += attributes[\"agent.providerCompactions\"];\n if (Array.isArray(attributes[\"agent.compactions\"])) {\n const records: unknown[] = attributes[\"agent.compactions\"];\n for (const record of records) {\n if (typeof record !== \"object\" || record === null || !(\"type\" in record)) continue;\n if (record.type === \"applied\") compactions += 1;\n if (record.type === \"skipped\") skippedCompactions += 1;\n }\n }\n incomplete ||=\n span.status === \"incomplete\" ||\n span.error?.type === \"AgentIncompleteError\" ||\n span.error?.type === \"AGENT_INCOMPLETE\";\n span.children.forEach(visit);\n };\n visit(trace.root);\n return {\n traceId: trace.traceId,\n requestId: trace.requestId,\n sessionId: trace.sessionId,\n name: trace.root.name,\n status: trace.root.status,\n startedAt: trace.startedAt,\n duration: trace.duration,\n usage: trace.usage,\n cost,\n models: [...models],\n toolCalls,\n retries,\n cacheHits,\n incomplete,\n truncatedTrips,\n compactions,\n skippedCompactions,\n providerCompactions,\n };\n}\n\n/** Content-free snapshot; never retain prompts, completions or tool arguments/results. */\nfunction snapshotSpan(span: TraceSpan): TraceSpan {\n return {\n spanId: span.spanId,\n parentSpanId: span.parentSpanId,\n traceId: span.traceId,\n sessionId: span.sessionId,\n name: span.name,\n version: span.version,\n type: span.type,\n status: span.status,\n startedAt: span.startedAt,\n endedAt: span.endedAt,\n duration: span.duration,\n usage: structuredClone(span.usage),\n error: span.error ? { type: span.error.type, message: span.error.message } : undefined,\n attributes: toSafeValue(span.attributes) as Record<string, unknown> | undefined,\n children: span.children.map(snapshotSpan),\n };\n}\n\ntype PanopticModule = typeof import(\"@warlock.js/ai-panoptic\");\ntype AiCoreModule = { isObserveAll?: () => boolean; getObservers?: () => readonly unknown[] };\n\n/**\n * Loads Panoptic (required) and `@warlock.js/ai` (for the observation check)\n * lazily, or says why not. Shared by the development source and the AI\n * reports wiring, so both answer the same unavailable reasons.\n */\nexport async function loadAiPackages(\n deps: AiSourceDeps = {},\n): Promise<\n | { panoptic: PanopticModule; observationOff: () => boolean }\n | { unavailable: DevtoolsAiUnavailable }\n> {\n const aiPackage: string = \"@warlock.js/ai\"; // not a dependency of devtools: never resolved at build time\n const load =\n deps.load ??\n ((name: string) =>\n name === \"@warlock.js/ai-panoptic\" ? import(\"@warlock.js/ai-panoptic\") : import(aiPackage));\n const version =\n deps.version ?? ((name: string) => installedVersion(name, process.cwd(), import.meta.resolve));\n let panoptic: PanopticModule;\n try {\n panoptic = (await load(\"@warlock.js/ai-panoptic\")) as PanopticModule;\n if (typeof panoptic.subscribeTraces !== \"function\")\n throw new Error(\"Trace subscription unavailable\");\n } catch (error) {\n const aiVersion = version(\"@warlock.js/ai\");\n const panopticVersion = version(\"@warlock.js/ai-panoptic\");\n if (aiVersion === null) return { unavailable: describeAiUnavailable(\"ai-missing\") };\n if (panopticVersion === null) return { unavailable: describeAiUnavailable(\"panoptic-missing\") };\n const text = redactPaths(\n (error instanceof Error ? error.message : String(error)).split(\"\\n\")[0] ?? \"\",\n ).slice(0, 300);\n return {\n unavailable: describeAiUnavailable(\n \"panoptic-failed\",\n `${text} (@warlock.js/ai ${aiVersion}, @warlock.js/ai-panoptic ${panopticVersion})`,\n ),\n };\n }\n\n let core: AiCoreModule | undefined;\n try {\n core = (await load(\"@warlock.js/ai\")) as AiCoreModule;\n } catch {\n core = undefined;\n }\n const observationOff = (): boolean =>\n typeof core?.isObserveAll === \"function\" &&\n typeof core.getObservers === \"function\" &&\n !core.isObserveAll() &&\n core.getObservers().length === 0;\n\n return { panoptic, observationOff };\n}\n\n/**\n * Optional, lazy integration. Retains only traces collected after devtools boots,\n * using Panoptic's bounded query store; existing exporter/cache stores stay independent.\n */\nexport async function attachAiSource(\n capacity: number,\n deps: AiSourceDeps = {},\n): Promise<DevtoolsAiSource> {\n const loaded = await loadAiPackages(deps);\n if (\"unavailable\" in loaded) return { ...loaded.unavailable, dispose() {} };\n const { panoptic, observationOff } = loaded;\n\n const { currentRequestId } = await import(\"../current-request-id\");\n const store = panoptic.createInMemoryTraceStore({ capacity });\n const listeners = new Set<(event: DevtoolsAiEvent) => void>();\n const detach = panoptic.subscribeTraces((trace) => {\n // Read ALS before any asynchronous exporter work, including for runs that\n // finish after the HTTP response. Never use sessionId as a request id.\n const requestId = currentRequestId() ?? trace.requestId;\n store.add({\n ...trace,\n requestId,\n usage: structuredClone(trace.usage),\n root: snapshotSpan(trace.root),\n });\n for (const listener of listeners) {\n try {\n listener({ traceId: trace.traceId, requestId });\n } catch {\n /* isolate clients */\n }\n }\n });\n\n return {\n available: true,\n observationOff,\n totalCost: (usage) => panoptic.totalCostUsd(usage),\n helpers: {\n filterTraces: panoptic.filterTraces,\n groupBySession: panoptic.groupBySession,\n groupByPrompt: panoptic.groupByPrompt,\n groupByType: panoptic.groupByType,\n percentile: panoptic.percentile,\n tracePromptKey: panoptic.tracePromptKey,\n },\n store,\n summarize: (trace) => summarizeAiTrace(trace, panoptic.totalCostUsd(trace.usage)),\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n dispose() {\n detach();\n listeners.clear();\n store.clear();\n },\n };\n}\n"],"mappings":";;;;;;AA6BA,SAAgB,YAAY,MAAsB;CAChD,OAAO,KAAK,QAAQ,kDAAkD,UAAU;EAC9E,MAAM,aAAa,MAAM,QAAQ,cAAc,EAAE,CAAC,CAAC,WAAW,MAAM,GAAG;EACvE,MAAM,QAAQ,WAAW,Y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AAO;EAAE,GAAG,OAAO;EAAa,UAAU,CAAC;CAAE;CAC1E,MAAM,EAAE,UAAU,mBAAmB;CAErC,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,MAAM,QAAQ,SAAS,yBAAyB,EAAE,SAAS,CAAC;CAC5D,MAAM,4BAAY,IAAI,IAAsC;CAC5D,MAAM,SAAS,SAAS,iBAAiB,UAAU;EAGjD,MAAM,YAAY,iBAAiB,KAAK,MAAM;EAC9C,MAAM,IAAI;GACR,GAAG;GACH;GACA,OAAO,gBAAgB,MAAM,KAAK;GAClC,MAAM,aAAa,MAAM,IAAI;EAC/B,CAAC;EACD,KAAK,MAAM,YAAY,WACrB,IAAI;GACF,SAAS;IAAE,SAAS,MAAM;IAAS;GAAU,CAAC;EAChD,QAAQ,CAER;CAEJ,CAAC;CAED,OAAO;EACL,WAAW;EACX;EACA,YAAY,UAAU,SAAS,aAAa,KAAK;EACjD,SAAS;GACP,cAAc,SAAS;GACvB,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,aAAa,SAAS;GACtB,YAAY,SAAS;GACrB,gBAAgB,SAAS;EAC3B;EACA;EACA,YAAY,UAAU,iBAAiB,OAAO,SAAS,aAAa,MAAM,KAAK,CAAC;EAChF,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,UAAU;GACR,OAAO;GACP,UAAU,MAAM;GAChB,MAAM,MAAM;EACd;CACF;AACF"}
package/esm/types.d.mts CHANGED
@@ -228,8 +228,11 @@ export type DevtoolsProductionOptions = {
228
228
  executing?: boolean;
229
229
  };
230
230
  /**
231
- * Turn tabs on or off by id. Built-in tabs `mail`, `ai`, `agents`, `api`
232
- * and `processes` are off in production unless set to `true`; a package
231
+ * Turn tabs on or off by id. Built-in tabs `mail`, `api` and `processes`
232
+ * are off in production unless set to `true`. `ai` (Runs) and `agents` are
233
+ * development tabs: setting them to `true` is ignored in production, with
234
+ * one warning at boot (production shows AI totals in Reports, Models and
235
+ * Errors). A package
233
236
  * panel shows only when it declares `production: true` or is set to `true`
234
237
  * here.
235
238
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../packages/devtools/src/types.ts"],"mappings":";;;;;;;;;;;;;;;YAmBY;;;;;;EAMV;;;;;;EAMA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;;;;;;;;;EAYA,kBAAkB;;;;;;;;;EASlB,KAAK;;;;;;;;;;;EAWL,aAAa;;;;;;;YAQH;;;;;;;EAOV;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;EASA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;EAQA;;EAEA;;IAEE;;IAEA;;;;;;;;;EASF;;EAEA;;IAEE;;IAEA;;;EAGF;;IAEE;;IAEA;;IAEA;;IAEA;;IAEA;;;EAGF;;;;;;;IAOE;;;;;;;;;;EAUF,SAAS,SAAS;;;;;;EAMlB,qBAAqB;;;;;;EAMrB;;EAEA;;IAEE;;IAEA;;;;;;;;EAQF;;IAEE;;IAEA;;;;YAKQ,0BAA0B,SACpC,KAAK,kEAEL,KAAK;;YAGK;;YAGA;;EAEV,QAAQ,SAAS;;EAEjB,OAAO,SAAS;;EAEhB;;;;;;;EAOA;;;;;;;;YASU;;EAEV,SAAS;;EAET;EACA,UAAU,SAAS;;;;;;;;;YAUT;;EAEV;;EAEA;;EAEA,eAAe;;EAEf,kBAAkB;;;;;;;;;;EAUlB;;;;;;EAMA,SAAS,SAAS,wBAAwB;;;;;;EAM1C,QAAQ;;;;;EAKR,QAAQ;;;YAIE;;EAEV,cAAc;;;;;;EAMd;;;YAIU;;;;;EAKV,eAAe;;;;;;EAMf;;EAEA;;EAEA;;;;;;YAOU;;EAEV;EACA;;EAEA;EACA;EACA;EACA;EACA;;;YAIU,8BAER,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K,iCACX;EACH,kBAAkB,+BAA+B,WAAW;EAC5D,OAAO,+BAA+B,OAAO;EAC7C,QAAQ,MAAM;EACd,gBAAgB;EAChB,WAAW,aAAa;EACxB,aAAa;EACb,QAAQ,aAAa;EACrB,SAAS;IAAW,QAAQ;IAA2B;MAAoB;EAC3E,iBAAiB;EACjB,UAAU,WAAW,OAAO,+BAA+B;EAC3D"}
package/llms-full.txt CHANGED
@@ -109,7 +109,9 @@ An older core without the request log leaves the panel in-memory only.
109
109
  The **AI** sidebar group has six pages. Reports (`ai-reports`), Models (`ai-models`) and Errors (`ai-errors`) read
110
110
  **hourly rollups** (names and numbers only: agent, model, provider, runs, tokens, estimated cost, errors by category,
111
111
  latency histogram, fallback and refusal counts). Runs (`ai`, id unchanged), Agents (`agents`) and Evaluate
112
- (`ai-evaluate`) read in-memory data and exist in development only. Cost is always "Estimated from model pricing"; runs of
112
+ (`ai-evaluate`) read in-memory data and exist in development only; `production.panels.ai` / `.agents` are ignored in
113
+ production (one boot warning, tabs and routes not registered). Image, speech and transcription runs show their model in
114
+ Runs, Models and Reports. Cost is always "Estimated from model pricing"; runs of
113
115
  models without pricing are counted as unpriced and shown next to every cost (a model priced at 0 counts as priced).
114
116
  Runs filters by text, status, type and exact HTTP request id (`GET api/ai/runs?requestId=`). A comparison whose
115
117
  previous period is older than the kept history reads "No earlier data". Custom ranges longer than 8 days use daily
@@ -131,7 +133,8 @@ export default {
131
133
  `devtoolsMigrations`. After upgrading run `warlock migrate`; without it one warning is logged and the pages answer
132
134
  `table-missing` ("AI reports need their table", command `warlock migrate`).
133
135
  - Production tabs: Reports, Models and Errors are on by default when Panoptic is installed and loads; Runs, Agents and
134
- Evaluate stay off. `production.panels` overrides by id (`{ "ai-reports": false }`). Every process that boots the
136
+ Evaluate are development only (`panels.ai` / `panels.agents` are ignored, with one warning). `production.panels`
137
+ overrides the other tabs by id (`{ "ai-reports": false }`). Every process that boots the
135
138
  connector writes to the same table, so totals add up all instances and workers.
136
139
  - Needs Panoptic and observation (`ai.config({ panoptic: { observeAll: true } })`). Evaluate also needs
137
140
  `ai.config({ panoptic: { evaluate: { model, instructions? } } })`; without it the page shows the setup.
package/package.json CHANGED
@@ -6,13 +6,13 @@
6
6
  },
7
7
  "peerDependencies": {
8
8
  "@simplewebauthn/server": "^13.1.0",
9
- "@warlock.js/ai-panoptic": "5.61.0",
10
- "@warlock.js/cache": "5.61.0",
11
- "@warlock.js/cascade": "5.61.0",
12
- "@warlock.js/core": "5.61.0",
13
- "@warlock.js/logger": "5.61.0",
14
- "@warlock.js/queue": "5.61.0",
15
- "@warlock.js/scheduler": "5.61.0"
9
+ "@warlock.js/ai-panoptic": "5.63.0",
10
+ "@warlock.js/cache": "5.63.0",
11
+ "@warlock.js/cascade": "5.63.0",
12
+ "@warlock.js/core": "5.63.0",
13
+ "@warlock.js/logger": "5.63.0",
14
+ "@warlock.js/queue": "5.63.0",
15
+ "@warlock.js/scheduler": "5.63.0"
16
16
  },
17
17
  "peerDependenciesMeta": {
18
18
  "@simplewebauthn/server": {
@@ -52,7 +52,7 @@
52
52
  ],
53
53
  "author": "hassanzohdy",
54
54
  "license": "MIT",
55
- "version": "5.61.0",
55
+ "version": "5.63.0",
56
56
  "main": "./cjs/index.cjs",
57
57
  "module": "./esm/index.mjs",
58
58
  "types": "./esm/index.d.mts",
package/skills/SKILL.md CHANGED
@@ -101,7 +101,9 @@ An older core without the request log leaves the panel in-memory only.
101
101
  The **AI** sidebar group has six pages. Reports (`ai-reports`), Models (`ai-models`) and Errors (`ai-errors`) read
102
102
  **hourly rollups** (names and numbers only: agent, model, provider, runs, tokens, estimated cost, errors by category,
103
103
  latency histogram, fallback and refusal counts). Runs (`ai`, id unchanged), Agents (`agents`) and Evaluate
104
- (`ai-evaluate`) read in-memory data and exist in development only. Cost is always "Estimated from model pricing"; runs of
104
+ (`ai-evaluate`) read in-memory data and exist in development only; `production.panels.ai` / `.agents` are ignored in
105
+ production (one boot warning, tabs and routes not registered). Image, speech and transcription runs show their model in
106
+ Runs, Models and Reports. Cost is always "Estimated from model pricing"; runs of
105
107
  models without pricing are counted as unpriced and shown next to every cost (a model priced at 0 counts as priced).
106
108
  Runs filters by text, status, type and exact HTTP request id (`GET api/ai/runs?requestId=`). A comparison whose
107
109
  previous period is older than the kept history reads "No earlier data". Custom ranges longer than 8 days use daily
@@ -123,7 +125,8 @@ export default {
123
125
  `devtoolsMigrations`. After upgrading run `warlock migrate`; without it one warning is logged and the pages answer
124
126
  `table-missing` ("AI reports need their table", command `warlock migrate`).
125
127
  - Production tabs: Reports, Models and Errors are on by default when Panoptic is installed and loads; Runs, Agents and
126
- Evaluate stay off. `production.panels` overrides by id (`{ "ai-reports": false }`). Every process that boots the
128
+ Evaluate are development only (`panels.ai` / `panels.agents` are ignored, with one warning). `production.panels`
129
+ overrides the other tabs by id (`{ "ai-reports": false }`). Every process that boots the
127
130
  connector writes to the same table, so totals add up all instances and workers.
128
131
  - Needs Panoptic and observation (`ai.config({ panoptic: { observeAll: true } })`). Evaluate also needs
129
132
  `ai.config({ panoptic: { evaluate: { model, instructions? } } })`; without it the page shows the setup.