@warlock.js/ai-panoptic 5.51.0 → 5.53.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.
- package/CHANGELOG.md +23 -0
- package/cjs/index.cjs +592 -424
- package/cjs/index.cjs.map +1 -1
- package/esm/collector/collector.mjs.map +1 -1
- package/esm/collector/extract-span-attributes.mjs.map +1 -1
- package/esm/collector/normalize-error.mjs.map +1 -1
- package/esm/collector/report-to-span.mjs.map +1 -1
- package/esm/collector/report-to-trace.mjs.map +1 -1
- package/esm/collector/trace-subscriptions.mjs.map +1 -1
- package/esm/config/apply-panoptic-config.d.mts.map +1 -1
- package/esm/config/apply-panoptic-config.mjs +9 -3
- package/esm/config/apply-panoptic-config.mjs.map +1 -1
- package/esm/config/panoptic-config.type.d.mts +7 -0
- package/esm/config/panoptic-config.type.d.mts.map +1 -1
- package/esm/dashboard/dashboard.mjs.map +1 -1
- package/esm/dashboard/index.d.mts +1 -0
- package/esm/dashboard/index.mjs +1 -1
- package/esm/dashboard/parse-query.mjs +23 -1
- package/esm/dashboard/parse-query.mjs.map +1 -1
- package/esm/dashboard/serve.mjs +55 -10
- package/esm/dashboard/serve.mjs.map +1 -1
- package/esm/dashboard/trace-filter.mjs.map +1 -1
- package/esm/dashboard/trace-summary.d.mts +24 -0
- package/esm/dashboard/trace-summary.d.mts.map +1 -0
- package/esm/dashboard/trace-summary.mjs +27 -0
- package/esm/dashboard/trace-summary.mjs.map +1 -0
- package/esm/dashboard/ui.html.mjs +68 -18
- package/esm/dashboard/ui.html.mjs.map +1 -1
- package/esm/dashboard/warlock-logo.mjs.map +1 -1
- package/esm/evaluate/evaluate-system-prompt.mjs.map +1 -1
- package/esm/evaluate/extract-last-system-prompt.mjs.map +1 -1
- package/esm/evaluate/find-span-by-id.mjs.map +1 -1
- package/esm/exporters/console/console-exporter.mjs.map +1 -1
- package/esm/exporters/console/format-span-io.mjs.map +1 -1
- package/esm/exporters/console/format-span-line.mjs.map +1 -1
- package/esm/exporters/file/file-exporter.mjs.map +1 -1
- package/esm/exporters/langfuse/langfuse-exporter.mjs.map +1 -1
- package/esm/exporters/otel/otel-exporter.mjs.map +1 -1
- package/esm/exporters/utils/gen-ai-attributes.mjs.map +1 -1
- package/esm/exporters/utils/total-cost.mjs.map +1 -1
- package/esm/exporters/utils/walk-spans.mjs.map +1 -1
- package/esm/index.d.mts +2 -1
- package/esm/index.mjs +1 -1
- package/esm/panoptic/panoptic-middleware.mjs.map +1 -1
- package/esm/panoptic/panoptic.mjs.map +1 -1
- package/esm/register.mjs.map +1 -1
- package/esm/store/cache-trace-store.d.mts.map +1 -1
- package/esm/store/cache-trace-store.mjs +37 -17
- package/esm/store/cache-trace-store.mjs.map +1 -1
- package/esm/store/in-memory-trace-store.d.mts.map +1 -1
- package/esm/store/in-memory-trace-store.mjs +2 -9
- package/esm/store/in-memory-trace-store.mjs.map +1 -1
- package/esm/store/match-trace.mjs.map +1 -1
- package/esm/store/sort-newest-first.mjs +14 -0
- package/esm/store/sort-newest-first.mjs.map +1 -0
- package/esm/store/sum-usage.mjs.map +1 -1
- package/llms-full.txt +9 -9
- package/llms.txt +1 -1
- package/package.json +4 -4
- package/skills/use-local-dashboard/SKILL.md +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collector.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/collector.ts"],"
|
|
1
|
+
{"version":3,"file":"collector.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/collector.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAM,YAAN,MAA6C;CAmBP;;;;;;CAbpC,AAAiB,4BAAY,IAAI,IAA8B;;;;;CAM/D,AAAiB,kCAAkB,IAAI,IAAY;;;;;;CAOnD,AAAO,YAAY,AAAiB,UAA4B,CAAC,GAAG;EAAhC;CAAiC;CAErE,AAAO,IAAI,UAAkC;EAC3C,IAAI,CAAC,KAAK,UAAU,IAAI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M,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,QAAQ,KAAK,wBAAwB,KAAK,6BAA6B,SAAS;CAClF;AACF;;;;;;;;;;;;;AAcA,SAAgB,gBAAgB,UAA4B,CAAC,GAAsB;CACjF,OAAO,IAAI,UAAU,OAAO;AAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-span-attributes.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/extract-span-attributes.ts"],"sourcesContent":["import type { AgentCompactionRecord, BaseReport, LLMTrip } from \"@warlock.js/ai\";\n\n/**\n * Per-primitive `BaseReport` extension fields the collector surfaces as\n * span attributes. Declared as a structural superset (every field\n * optional) so a single reader can pull whatever the concrete report\n * carried without narrowing on `type` first — a `BaseReport` widened to\n * this shape exposes `undefined` for the fields its primitive doesn't\n * set, and the extractor simply skips those.\n *\n * Mirrors the public per-primitive report types in `@warlock.js/ai`\n * (`AgentReport`, `WorkflowReport`, `SupervisorReport`,\n * `OrchestratorReport`, `ToolCall`) — kept structural rather than a\n * union import so adding a new optional report field upstream is a\n * non-breaking read here.\n */\ntype ReportExtensions = {\n model?: { name?: string; provider?: string };\n trips?: LLMTrip[];\n compactions?: AgentCompactionRecord[];\n promptName?: string;\n promptVersion?: string;\n workflowName?: string;\n supervisorName?: string;\n signature?: string;\n terminatedBy?: string;\n iterations?: number;\n steps?: Record<string, unknown>;\n turns?: unknown[];\n turnIndex?: number;\n tripIndex?: number;\n callId?: string;\n recoveredFrom?: string;\n};\n\n/**\n * Build the free-form `TraceSpan.attributes` bag for one report node.\n *\n * The collector keeps the first-class span fields (identity, timing,\n * status, usage, error) on the span itself and routes everything\n * primitive-specific here — trip/step/iteration counts, the model\n * identity an agent ran against, the tool's originating trip index, a\n * supervisor's termination reason. Exporters forward this verbatim as\n * backend span attributes (OTel attributes, Langfuse metadata).\n *\n * Only populated keys are emitted; the function returns `undefined`\n * when the node carried no extra detail, so the optional\n * `TraceSpan.attributes` field stays absent rather than holding an\n * empty object (matches the contract's \"absent when empty\" note).\n *\n * Retry count is surfaced from the shared `BaseReport.attempts` for\n * every primitive so cost dashboards see the real call count.\n *\n * @example\n * const attributes = extractSpanAttributes(agentReport);\n * // { \"agent.trips\": 3, \"agent.model.name\": \"gpt-4o\", \"agent.model.provider\": \"openai\" }\n */\nexport function extractSpanAttributes(report: BaseReport): Record<string, unknown> | undefined {\n const extensions = report as BaseReport & ReportExtensions;\n const attributes: Record<string, unknown> = {};\n\n if (report.attempts !== undefined && report.attempts.length > 0) {\n attributes[\"retries\"] = report.attempts.length;\n attributes[\"retry.attempts\"] = report.attempts.map((attempt) => ({\n index: attempt.index,\n startedAt: attempt.startedAt,\n endedAt: attempt.endedAt,\n duration: attempt.duration,\n status: attempt.status,\n }));\n }\n\n switch (report.type) {\n case \"agent\": {\n addAgentAttributes(attributes, extensions);\n break;\n }\n\n case \"workflow\": {\n addWorkflowAttributes(attributes, extensions);\n break;\n }\n\n case \"supervisor\":\n case \"team\": {\n // ai.team reuses the supervisor engine, so a team report carries the\n // same supervisorName / terminatedBy / iterations fields.\n addSupervisorAttributes(attributes, extensions);\n break;\n }\n\n case \"orchestrator\": {\n addOrchestratorAttributes(attributes, extensions);\n break;\n }\n\n case \"tool\": {\n addToolAttributes(attributes, extensions);\n break;\n }\n\n default: {\n break;\n }\n }\n\n if (Object.keys(attributes).length === 0) {\n return undefined;\n }\n\n return attributes;\n}\n\nfunction addAgentAttributes(\n attributes: Record<string, unknown>,\n extensions: ReportExtensions,\n): void {\n if (Array.isArray(extensions.trips)) {\n attributes[\"agent.trips\"] = extensions.trips.length;\n // Reported provider cache reads only. Zero-token synthetic responses do\n // not identify semantic-cache hits in the core report contract.\n if (extensions.trips.some((trip) => trip.usage?.cachedTokens !== undefined)) {\n attributes[\"agent.cacheHits\"] = extensions.trips.filter(\n (trip) => (trip.usage?.cachedTokens ?? 0) > 0,\n ).length;\n }\n const truncatedTrips = extensions.trips.filter(\n (trip) => trip.finishReason === \"length\" || trip.finishReason === \"context_exceeded\",\n ).length;\n if (truncatedTrips > 0) attributes[\"agent.truncatedTrips\"] = truncatedTrips;\n const providerCompactions = extensions.trips.reduce(\n (count, trip) =>\n count + (trip.blocks?.filter((block) => block.type === \"compaction\").length ?? 0),\n 0,\n );\n if (providerCompactions > 0) attributes[\"agent.providerCompactions\"] = providerCompactions;\n }\n\n if (extensions.compactions?.length) {\n // Do not copy summary text, callback errors or raw conversation content.\n attributes[\"agent.compactions\"] = extensions.compactions.map((record) => ({\n type: record.type,\n tripIndex: record.tripIndex,\n inputTokens: record.inputTokens,\n counting: record.counting,\n reason: record.reason,\n ...(record.compaction\n ? {\n replacesFromIndex: record.compaction.replacesFromIndex,\n replacesToIndex: record.compaction.replacesToIndex,\n }\n : {}),\n }));\n }\n\n if (extensions.model?.name !== undefined) {\n attributes[\"agent.model.name\"] = extensions.model.name;\n }\n\n if (extensions.model?.provider !== undefined) {\n attributes[\"agent.model.provider\"] = extensions.model.provider;\n }\n\n // Prompt-version linkage (core `AgentReport.promptName` / `promptVersion`).\n // Present only when the agent ran against a *named* `ai.prompts` builder;\n // surfaced so the dashboard can group / filter runs by `name@version` and\n // attribute behavior shifts to a specific prompt revision.\n if (extensions.promptName !== undefined) {\n attributes[\"agent.promptName\"] = extensions.promptName;\n }\n\n if (extensions.promptVersion !== undefined) {\n attributes[\"agent.promptVersion\"] = extensions.promptVersion;\n }\n}\n\nfunction addWorkflowAttributes(\n attributes: Record<string, unknown>,\n extensions: ReportExtensions,\n): void {\n if (extensions.workflowName !== undefined) {\n attributes[\"workflow.name\"] = extensions.workflowName;\n }\n\n if (extensions.signature !== undefined) {\n attributes[\"workflow.signature\"] = extensions.signature;\n }\n\n if (extensions.steps !== undefined) {\n attributes[\"workflow.steps\"] = Object.keys(extensions.steps).length;\n }\n}\n\nfunction addSupervisorAttributes(\n attributes: Record<string, unknown>,\n extensions: ReportExtensions,\n): void {\n if (extensions.supervisorName !== undefined) {\n attributes[\"supervisor.name\"] = extensions.supervisorName;\n }\n\n if (extensions.terminatedBy !== undefined) {\n attributes[\"supervisor.terminatedBy\"] = extensions.terminatedBy;\n }\n\n if (extensions.iterations !== undefined) {\n attributes[\"supervisor.iterations\"] = extensions.iterations;\n }\n}\n\nfunction addOrchestratorAttributes(\n attributes: Record<string, unknown>,\n extensions: ReportExtensions,\n): void {\n if (extensions.turnIndex !== undefined) {\n attributes[\"orchestrator.turnIndex\"] = extensions.turnIndex;\n }\n\n if (extensions.signature !== undefined) {\n attributes[\"orchestrator.signature\"] = extensions.signature;\n }\n\n if (Array.isArray(extensions.turns)) {\n attributes[\"orchestrator.turns\"] = extensions.turns.length;\n }\n}\n\nfunction addToolAttributes(\n attributes: Record<string, unknown>,\n extensions: ReportExtensions,\n): void {\n if (extensions.tripIndex !== undefined) {\n attributes[\"tool.tripIndex\"] = extensions.tripIndex;\n }\n\n if (extensions.callId !== undefined) {\n attributes[\"tool.callId\"] = extensions.callId;\n }\n\n if (extensions.recoveredFrom !== undefined) {\n attributes[\"tool.recoveredFrom\"] = extensions.recoveredFrom;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,sBAAsB,QAAyD;CAC7F,MAAM,aAAa;CACnB,MAAM,aAAsC,CAAC;CAE7C,IAAI,OAAO,aAAa,UAAa,OAAO,SAAS,SAAS,GAAG;EAC/D,WAAW,aAAa,OAAO,SAAS;EACxC,WAAW,oBAAoB,OAAO,SAAS,KAAK,aAAa;GAC/D,OAAO,QAAQ;GACf,WAAW,QAAQ;GACnB,SAAS,QAAQ;GACjB,UAAU,QAAQ;GAClB,QAAQ,QAAQ;EAClB,EAAE;CACJ;CAEA,QAAQ,OAAO,MAAf;EACE,KAAK;GACH,mBAAmB,YAAY,UAAU;GACzC;EAGF,KAAK;GACH,sBAAsB,YAAY,UAAU;GAC5C;EAGF,KAAK;EACL,KAAK;GAGH,wBAAwB,YAAY,UAAU;GAC9C;EAGF,KAAK;GACH,0BA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ACP,YACA,YACM;CACN,IAAI,WAAW,iBAAiB,QAC9B,WAAW,mBAAmB,WAAW;CAG3C,IAAI,WAAW,cAAc,QAC3B,WAAW,wBAAwB,WAAW;CAGhD,IAAI,WAAW,UAAU,QACvB,WAAW,oBAAoB,OAAO,KAAK,WAAW,KAAK,CAAC,CAAC;AAEjE;AAEA,SAAS,wBACP,YACA,YACM;CACN,IAAI,WAAW,mBAAmB,QAChC,WAAW,qBAAqB,WAAW;CAG7C,IAAI,WAAW,iBAAiB,QAC9B,WAAW,6BAA6B,WAAW;CAGrD,IAAI,WAAW,eAAe,QAC5B,WAAW,2BAA2B,WAAW;AAErD;AAEA,SAAS,0BACP,YACA,YACM;CACN,IAAI,WAAW,cAAc,QAC3B,WAAW,4BAA4B,WAAW;CAGpD,IAAI,WAAW,cAAc,QAC3B,WAAW,4BAA4B,WAAW;CAGpD,IAAI,MAAM,QAAQ,WAAW,KAAK,GAChC,WAAW,wBAAwB,WAAW,MAAM;AAExD;AAEA,SAAS,kBACP,YACA,YACM;CACN,IAAI,WAAW,cAAc,QAC3B,WAAW,oBAAoB,WAAW;CAG5C,IAAI,WAAW,WAAW,QACxB,WAAW,iBAAiB,WAAW;CAGzC,IAAI,WAAW,kBAAkB,QAC/B,WAAW,wBAAwB,WAAW;AAElD"}
|
|
1
|
+
{"version":3,"file":"extract-span-attributes.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/extract-span-attributes.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,sBAAsB,QAAyD;CAC7F,MAAM,aAAa;CACnB,MAAM,aAAsC,CAAC;CAE7C,IAAI,OAAO,aAAa,UAAa,OAAO,SAAS,SAAS,GAAG;EAC/D,WAAW,aAAa,OAAO,SAAS;EACxC,WAAW,oBAAoB,OAAO,SAAS,KAAK,aAAa;GAC/D,OAAO,QAAQ;GACf,WAAW,QAAQ;GACnB,SAAS,QAAQ;GACjB,UAAU,QAAQ;GAClB,QAAQ,QAA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AsB,WAAW,MAAM;CAGpD,IAAI,WAAW,OAAO,aAAa,QACjC,WAAW,0BAA0B,WAAW,MAAM;CAOxD,IAAI,WAAW,eAAe,QAC5B,WAAW,sBAAsB,WAAW;CAG9C,IAAI,WAAW,kBAAkB,QAC/B,WAAW,yBAAyB,WAAW;AAEnD;AAEA,SAAS,sBACP,YACA,YACM;CACN,IAAI,WAAW,iBAAiB,QAC9B,WAAW,mBAAmB,WAAW;CAG3C,IAAI,WAAW,cAAc,QAC3B,WAAW,wBAAwB,WAAW;CAGhD,IAAI,WAAW,UAAU,QACvB,WAAW,oBAAoB,OAAO,KAAK,WAAW,KAAK,CAAC,CAAC;AAEjE;AAEA,SAAS,wBACP,YACA,YACM;CACN,IAAI,WAAW,mBAAmB,QAChC,WAAW,qBAAqB,WAAW;CAG7C,IAAI,WAAW,iBAAiB,QAC9B,WAAW,6BAA6B,WAAW;CAGrD,IAAI,WAAW,eAAe,QAC5B,WAAW,2BAA2B,WAAW;AAErD;AAEA,SAAS,0BACP,YACA,YACM;CACN,IAAI,WAAW,cAAc,QAC3B,WAAW,4BAA4B,WAAW;CAGpD,IAAI,WAAW,cAAc,QAC3B,WAAW,4BAA4B,WAAW;CAGpD,IAAI,MAAM,QAAQ,WAAW,KAAK,GAChC,WAAW,wBAAwB,WAAW,MAAM;AAExD;AAEA,SAAS,kBACP,YACA,YACM;CACN,IAAI,WAAW,cAAc,QAC3B,WAAW,oBAAoB,WAAW;CAG5C,IAAI,WAAW,WAAW,QACxB,WAAW,iBAAiB,WAAW;CAGzC,IAAI,WAAW,kBAAkB,QAC/B,WAAW,wBAAwB,WAAW;AAElD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-error.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/normalize-error.ts"],"
|
|
1
|
+
{"version":3,"file":"normalize-error.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/normalize-error.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,eAAe,OAA4C;CACzE,IAAI,UAAU,UAAa,UAAU,MACnC;CAGF,IAAI,OAAO,UAAU,UACnB,OAAO;EACL,MAAM;EACN,SAAS,aAAa,OAAO,KAAK,CAAC;CACrC;CAGF,MAAM,YAAY;CAQlB,MAAM,OAAO,WAAW,UAAU,IAAI,KAAK,WAAW,UAAU,IAAI,KAAK;CACzE,MAAM,UAAU,WAAW,UAAU,OAAO,KAAK;CACjD,MAAM,QAAQ,WAAW,UAAU,KAAK;CAKxC,MAAM,aAA6B;EACjC;EACA,SAAS,aAAa,OAAO;CAC/B;CAEA,IAAI,UAAU,QACZ,WAAW,QAAQ,aAAa,KAAK;CAGvC,IAAI,UAAU,UAAU,UAAa,UAAU,UAAU,MACvD,WAAW,QACT,OAAO,UAAU,UAAU,WACvB,OAAO,UAAU,KAAK,IACtB,aAAa,OAAO,UAAU,KAAK,CAAC;CAG5C,OAAO;AACT;;;;;AAMA,SAAS,WAAW,OAAoC;CACtD,IAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAC9C,OAAO;AAIX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report-to-span.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/report-to-span.ts"],"
|
|
1
|
+
{"version":3,"file":"report-to-span.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/report-to-span.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,aAAa,QAAoB,SAA4C;CAC3F,MAAM,OAAkB;EACtB,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,MAAM,OAAO;EACb,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,WAAW,OAAO;EAClB,SAAS,OAAO;EAChB,UAAU,OAAO;EACjB,OAAO,OAAO;EACd,UAAU,OAAO,SAAS,KAAK,UAAU,aAAa,OAAO,OAAO,CAAC;CACvE;CAEA,IAAI,OAAO,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AW;EACxB,MAAM,QAAQ,SACV,OAAO,QAAQ;GAAE,MAAM,KAAK;GAAM,MAAM,KAAK;GAAM,OAAO;EAAS,CAAC,IACpE;EACJ,IAAI,UAAU,QACZ,KAAK,SAAS;CAElB;AACF;;;;;;;;;AAUA,SAAS,mBAAmB,OAA6C;CACvE,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;EAC7C,MAAM,MAAM,MAAM,EAAE,EAAE;EAGtB,IAFgB,OAAO,QAAQ,WAAW,IAAI,SAAS,IAAI,QAAQ,QAGjE,OAAO;CAEX;AAGF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report-to-trace.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/report-to-trace.ts"],"
|
|
1
|
+
{"version":3,"file":"report-to-trace.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/report-to-trace.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,cACd,QACA,WACA,SACO;CACP,MAAM,OAAO,aAAa,QAAQ,OAAO;CAEzC,IAAI,KAAK,UAAU,QAAW;EAC5B,MAAM,QAAQ,eAAe,SAAS;EAEtC,IAAI,UAAU,QACZ,KAAK,QAAQ;CAEjB;CAEA,MAAM,QAAe;EACnB,SAAS,KAAK;EACd;EACA,WAAW,KAAK;EAChB,SAAS,KAAK;EACd,UAAU,KAAK;EACf,OAAO,KAAK;CACd;CAEA,IAAI,KAAK,cAAc,QACrB,MAAM,YAAY,KAAK;CAGzB,IAAI,OAAO,wBAAwB,QACjC,MAAM,sBAAsB,OAAO;CAGrC,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-subscriptions.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/trace-subscriptions.ts"],"
|
|
1
|
+
{"version":3,"file":"trace-subscriptions.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/collector/trace-subscriptions.ts"],"mappings":";AAKA,MAAM,4BAAY,IAAI,IAAmB;;;;;;;;AASzC,SAAgB,gBAAgB,UAAqC;CACnE,MAAM,gBAA+B,UAAU,SAAS,KAAK;CAC7D,UAAU,IAAI,YAAY;CAC1B,aAAa;EACX,UAAU,OAAO,YAAY;CAC/B;AACF;;AAGA,SAAgB,aAAa,OAAoB;CAC/C,KAAK,MAAM,YAAY,WACrB,IAAI;EACF,AAAK,QAAQ,QAAQ,SAAS,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;CACtD,QAAQ,CAER;AAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-panoptic-config.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/config/apply-panoptic-config.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"apply-panoptic-config.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/config/apply-panoptic-config.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;wBAoDgB,oBAAoB,SAAS"}
|
|
@@ -7,6 +7,8 @@ import { log } from "@warlock.js/logger";
|
|
|
7
7
|
|
|
8
8
|
//#region ../../packages/ai-panoptic/src/config/apply-panoptic-config.ts
|
|
9
9
|
let applied;
|
|
10
|
+
/** Traces kept by the store panoptic creates for the dashboard, unless `capacity` says otherwise. */
|
|
11
|
+
const DEFAULT_DASHBOARD_STORE_CAPACITY = 1e3;
|
|
10
12
|
/**
|
|
11
13
|
* Read a {@link PanopticConfig} and wire panoptic onto the core observe
|
|
12
14
|
* seam — the bridge `ai.config({ panoptic })` resolves through. Builds a
|
|
@@ -35,11 +37,15 @@ function applyPanopticConfig(config) {
|
|
|
35
37
|
let store = findStore(exporters);
|
|
36
38
|
let cacheStore;
|
|
37
39
|
if (store === void 0 && config.dashboard) {
|
|
40
|
+
const capacity = config.capacity ?? 1e3;
|
|
38
41
|
if (config.cache !== void 0) {
|
|
39
42
|
const onError = config.onError ?? ((error) => log.error("ai-panoptic", "cacheStore", error));
|
|
40
|
-
cacheStore = createCacheTraceStore(config.cache, {
|
|
43
|
+
cacheStore = createCacheTraceStore(config.cache, {
|
|
44
|
+
onError,
|
|
45
|
+
capacity
|
|
46
|
+
});
|
|
41
47
|
store = cacheStore;
|
|
42
|
-
} else store = createInMemoryTraceStore();
|
|
48
|
+
} else store = createInMemoryTraceStore({ capacity });
|
|
43
49
|
exporters.push(store);
|
|
44
50
|
}
|
|
45
51
|
const panopticInstance = panoptic({
|
|
@@ -87,5 +93,5 @@ function startDashboard(store, dashboardConfig) {
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
//#endregion
|
|
90
|
-
export { applyPanopticConfig };
|
|
96
|
+
export { DEFAULT_DASHBOARD_STORE_CAPACITY, applyPanopticConfig };
|
|
91
97
|
//# sourceMappingURL=apply-panoptic-config.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-panoptic-config.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/config/apply-panoptic-config.ts"],"
|
|
1
|
+
{"version":3,"file":"apply-panoptic-config.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/config/apply-panoptic-config.ts"],"mappings":";;;;;;;;AA2BA,IAAI;;AAGJ,MAAa,mCAAmC;;;;;;;;;;;;;;;;;;;;;AAsBhD,SAAgB,oBAAoB,QAA+B;CACjE,IAAI,WAAW,QACb;CAIF,cAAc,QAAQ,OAAO,UAAU,CAAC;CAExC,IAAI,YAAY,QAAW;EACzB,MAAM,YAAY,CAAC,GAAI,OAAO,aAAa,CAAC,CAAE;EAC9C,IAAI,QAAQ,UAAU,SAAS;EAI/B,IAAI;EAOJ,IAAI,UAAU,UAAa,OAAO,WAAW;GAC3C,MAAM,WAAW,OAAO;GAExB,IAAI,OAAO,UAAU,QAAW;IAC9B,MAAM,UACJ,OAAO,aAAa,UAAmB,IAAI,MAAM,eAAe,cAAc,KAAK;IAErF,aAAa,sBAAsB,OAAO,OAAO;KAAE;KAAS;IAAS,CAAC;IACtE,QAAQ;GACV,OACE,QAAQ,yBAAyB,EAAE,SAAS,CAAC;GAG/C,UAAU,KAAK,KAAoC;EACrD;EAEA,MAAM,mBAAmB,SAAS;GAChC;GACA,gBAAgB,OAAO;GACvB,aAAa,OAAO;EACtB,CAAC;EACD,iBAAiB,WAAW,gBAAgB,CAAC;EAE7C,UAAU,EAAE,iBAAiB;EAE7B,IAAI,OAAO,aAAa,UAAU,QAAW;GAC3C,MAAM,gBAAgB;GAOtB,CAFkB,eAAe,SAAY,WAAW,MAAM,IAAI,QAAQ,QAAQ,EAEpE,CACX,YAAY,CAEb,CAAC,CAAC,CACD,WAAW,eAAe,eAAe,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CACjE,MAAM,WAAW;IAChB,IAAI,YAAY,QACd,QAAQ,kBAAkB;GAE9B,CAAC;EACL;CACF;AACF;;;;;;;;AAkCA,SAAS,WAAW,UAA8B;CAChD,OAAO,EACL,QAAQ,QAAwC;EAC9C,OAAO,SAAS,QAAQ,MAAM;CAChC,EACF;AACF;;;;;;;AAQA,SAAS,UAAU,WAA+D;CAChF,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,YAAY;EAElB,IACE,OAAO,UAAU,UAAU,cAC3B,OAAO,UAAU,QAAQ,cACzB,OAAO,UAAU,cAAc,YAE/B,OAAO;CAEX;AAGF;;AAGA,SAAS,eACP,OACA,iBAC0B;CAG1B,OAAO,UAAU,OAFiB,OAAO,oBAAoB,WAAW,kBAAkB,CAAC,CAE5D;AACjC"}
|
|
@@ -53,6 +53,13 @@ export type PanopticConfig = {
|
|
|
53
53
|
* and registers when none was supplied.
|
|
54
54
|
*/
|
|
55
55
|
dashboard?: boolean | DashboardOptions;
|
|
56
|
+
/**
|
|
57
|
+
* How many traces the store panoptic creates for the dashboard keeps (the
|
|
58
|
+
* in-memory store, or the cache-backed one when {@link cache} is set).
|
|
59
|
+
* Past it the oldest trace is dropped. Default `1000`; `0` keeps every
|
|
60
|
+
* trace. Ignored when you supply your own store through `exporters`.
|
|
61
|
+
*/
|
|
62
|
+
capacity?: number;
|
|
56
63
|
/**
|
|
57
64
|
* Observe every flow (`ai.agent` / `ai.workflow` / `ai.supervisor` /
|
|
58
65
|
* `ai.team`) by default. Individual flows opt out with `observe: false`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panoptic-config.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/config/panoptic-config.type.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;YA0BY;;;;;;;EAOV,YAAY;;;;;;;;;;;;;EAaZ,QAAQ;;;;;;;;EAQR,sBAAsB;;;;;;
|
|
1
|
+
{"version":3,"file":"panoptic-config.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/config/panoptic-config.type.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;YA0BY;;;;;;;EAOV,YAAY;;;;;;;;;;;;;EAaZ,QAAQ;;;;;;;;EAQR,sBAAsB;;;;;;;EAOtB;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;;;;;EAWA,WAAW;;;YAQD;;IAER,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/dashboard/dashboard.ts"],"
|
|
1
|
+
{"version":3,"file":"dashboard.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/dashboard/dashboard.ts"],"mappings":";;;;AAKA,MAAM,eAAe;AACrB,MAAM,eAAe;AACrB,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;AA0BtB,SAAgB,UACd,OACA,UAA4B,CAAC,GACH;CAC1B,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,QAAQ,QAAQ,SAAS;CAC/B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nD,IAAI,eAAe,IAAI,GACrB,OAAO;EAAC;EAAa;EAAa;EAAS;CAAK;CAElD,OAAO,CAAC,IAAI;AACd;;;;;AAMA,SAAS,kBAAkB,UAA2B;CACpD,IAAI,aAAa,UAAa,SAAS,WAAW,KAAK,aAAa,KAClE,OAAO;CAGT,MAAM,cAAc,SAAS,WAAW,GAAG,IAAI,WAAW,IAAI;CAE9D,OAAO,YAAY,SAAS,GAAG,IAAI,cAAc,GAAG,YAAY;AAClE;;;;;;;;AASA,SAAS,YAAY,KAAmB;CACtC,AAAK,OAAO,qBAAqB,CAC9B,MAAM,EAAE,YAAY;EAKnB,MAAM,QAAQ,MAHZ,QAAQ,aAAa,UAAU,QAAQ,QAAQ,aAAa,WAAW,SAAS,YACrE,QAAQ,aAAa,UAAU;GAAC;GAAM;GAAS;GAAI;EAAG,IAAI,CAAC,GAAG,GAExC;GAAE,OAAO;GAAU,UAAU;EAAK,CAAC;EACtE,MAAM,GAAG,eAAe,CAExB,CAAC;EACD,MAAM,MAAM;CACd,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;AACL"}
|
|
@@ -3,4 +3,5 @@ import { dashboard } from "./dashboard.mjs";
|
|
|
3
3
|
import "./serve.mjs";
|
|
4
4
|
import "./parse-query.mjs";
|
|
5
5
|
import { NO_PROMPT_KEY, NO_SESSION_KEY, NO_TYPE_KEY, PromptGroup, SessionGroup, TraceFilter, TypeGroup, TypeStat, aggregateByType, filterTraces, groupByPrompt, groupBySession, groupByType, heatIntensity, matchesFilter, maxNodeCost, percentile, rollupCost, traceCost, tracePromptKey } from "./trace-filter.mjs";
|
|
6
|
+
import { TraceSpanSummary, TraceSummary } from "./trace-summary.mjs";
|
|
6
7
|
export { type DashboardHandle, type DashboardOptions, dashboard };
|
package/esm/dashboard/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseQuery } from "./parse-query.mjs";
|
|
2
|
+
import { NO_PROMPT_KEY, NO_SESSION_KEY, NO_TYPE_KEY, aggregateByType, filterTraces, groupByPrompt, groupBySession, groupByType, heatIntensity, matchesFilter, maxNodeCost, percentile, rollupCost, traceCost, tracePromptKey } from "./trace-filter.mjs";
|
|
2
3
|
import { dashboardHtml } from "./ui.html.mjs";
|
|
3
4
|
import { createRequestHandler } from "./serve.mjs";
|
|
4
5
|
import { dashboard } from "./dashboard.mjs";
|
|
5
|
-
import { NO_PROMPT_KEY, NO_SESSION_KEY, NO_TYPE_KEY, aggregateByType, filterTraces, groupByPrompt, groupBySession, groupByType, heatIntensity, matchesFilter, maxNodeCost, percentile, rollupCost, traceCost, tracePromptKey } from "./trace-filter.mjs";
|
|
6
6
|
|
|
7
7
|
export { dashboard };
|
|
@@ -49,7 +49,29 @@ function parseQuery(params) {
|
|
|
49
49
|
if (startedBefore !== null && startedBefore.length > 0) query.startedBefore = startedBefore;
|
|
50
50
|
return query;
|
|
51
51
|
}
|
|
52
|
+
/** Traces `GET api/traces` returns when the request names no `limit`. */
|
|
53
|
+
const DEFAULT_TRACE_LIST_LIMIT = 200;
|
|
54
|
+
/**
|
|
55
|
+
* Read `?limit=` (a positive integer, default {@link DEFAULT_TRACE_LIST_LIMIT})
|
|
56
|
+
* and `?full=1` from a `GET api/traces` request. An invalid `limit` falls
|
|
57
|
+
* back to the default. Page further back with `?startedBefore=` set to the
|
|
58
|
+
* `startedAt` of the last trace received.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* parseListOptions(new URLSearchParams("limit=50&full=1"));
|
|
62
|
+
* // → { limit: 50, full: true }
|
|
63
|
+
*/
|
|
64
|
+
function parseListOptions(params) {
|
|
65
|
+
const raw = params.get("limit");
|
|
66
|
+
const parsed = raw === null ? NaN : Number(raw);
|
|
67
|
+
const limit = Number.isInteger(parsed) && parsed > 0 ? parsed : 200;
|
|
68
|
+
const full = params.get("full");
|
|
69
|
+
return {
|
|
70
|
+
limit,
|
|
71
|
+
full: full === "1" || full === "true"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
52
74
|
|
|
53
75
|
//#endregion
|
|
54
|
-
export { parseQuery };
|
|
76
|
+
export { parseListOptions, parseQuery };
|
|
55
77
|
//# sourceMappingURL=parse-query.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-query.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/dashboard/parse-query.ts"],"
|
|
1
|
+
{"version":3,"file":"parse-query.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/dashboard/parse-query.ts"],"mappings":";;;;;AAOA,MAAM,iBAA0C;CAC9C;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,WAAW,QAAqC;CAC9D,MAAM,QAAoB,CAAC;CAE3B,MAAM,UAAU,OAAO,IAAI,SAAS;CACpC,IAAI,YAAY,QAAQ,QAAQ,SAAS,GACvC,MAAM,UAAU;CAGlB,MAAM,YAAY,OAAO,IAAI,WAAW;CACxC,IAAI,cAAc,QAAQ,UAAU,SAAS,GAC3C,MAAM,YAAY;CAGpB,MAAM,WAAW,OACd,OAAO,QAAQ,CAAC,CAChB,QAAQ,UACN,eAAqC,SAAS,KAAK,CACtD;CACF,IAAI,SAAS,WAAW,GACtB,MAAM,SAAS,SAAS;MACnB,IAAI,SAAS,SAAS,GAC3B,MAAM,SAAS;CAGjB,MAAM,eAAe,OAAO,IAAI,cAAc;CAC9C,IAAI,iBAAiB,QAAQ,aAAa,SAAS,GACjD,MAAM,eAAe;CAGvB,MAAM,gBAAgB,OAAO,IAAI,eAAe;CAChD,IAAI,kBAAkB,QAAQ,cAAc,SAAS,GACnD,MAAM,gBAAgB;CAGxB,OAAO;AACT;;AAGA,MAAa,2BAA2B;;;;;;;;;;;AAoBxC,SAAgB,iBAAiB,QAA2C;CAC1E,MAAM,MAAM,OAAO,IAAI,OAAO;CAC9B,MAAM,SAAS,QAAQ,OAAO,MAAa,OAAO,GAAG;CACrD,MAAM,QAAQ,OAAO,UAAU,MAAM,KAAK,SAAS,IAAI;CACvD,MAAM,OAAO,OAAO,IAAI,MAAM;CAE9B,OAAO;EAAE;EAAO,MAAM,SAAS,OAAO,SAAS;CAAO;AACxD"}
|
package/esm/dashboard/serve.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { evaluateSystemPrompt } from "../evaluate/evaluate-system-prompt.mjs";
|
|
2
2
|
import { extractLastSystemPrompt } from "../evaluate/extract-last-system-prompt.mjs";
|
|
3
3
|
import { findSpanById } from "../evaluate/find-span-by-id.mjs";
|
|
4
|
-
import { parseQuery } from "./parse-query.mjs";
|
|
4
|
+
import { parseListOptions, parseQuery } from "./parse-query.mjs";
|
|
5
|
+
import { toTraceSummary } from "./trace-summary.mjs";
|
|
5
6
|
import { dashboardHtml } from "./ui.html.mjs";
|
|
6
7
|
import { timingSafeEqual } from "node:crypto";
|
|
7
8
|
|
|
@@ -69,8 +70,10 @@ function isAuthorized(req, url, token, allowQueryToken) {
|
|
|
69
70
|
*
|
|
70
71
|
* Routes (all under `config.basePath`):
|
|
71
72
|
*
|
|
72
|
-
* - `GET api/traces` →
|
|
73
|
-
*
|
|
73
|
+
* - `GET api/traces` → the newest `?limit=` (default 200) matches of
|
|
74
|
+
* `store.query(parseQuery(searchParams))`, as {@link TraceSummary}
|
|
75
|
+
* entries (no span tree or captured content); `?full=1` returns full traces
|
|
76
|
+
* - `GET api/traces/:id` → `store.get(id)` or `404` (`400` for a malformed id)
|
|
74
77
|
* - `GET api/aggregate` → `store.aggregate(parseQuery(searchParams))`
|
|
75
78
|
* - `GET {basePath}` → the self-contained HTML page
|
|
76
79
|
* - `POST api/traces/:traceId/spans/:spanId/evaluate` → ONLY when
|
|
@@ -80,6 +83,8 @@ function isAuthorized(req, url, token, allowQueryToken) {
|
|
|
80
83
|
* other route (the path is never even pattern-matched).
|
|
81
84
|
*
|
|
82
85
|
* Anything else → `404`. A method the matched route doesn't accept → `405`.
|
|
86
|
+
* A handler failure answers `500` instead of escaping the server's
|
|
87
|
+
* `request` listener, so one bad request can never take the app down.
|
|
83
88
|
* Host allowlist + bearer-token auth (S4) are checked for EVERY request,
|
|
84
89
|
* regardless of method, before any routing. The store shapes
|
|
85
90
|
* ({@link Trace}/{@link TraceSpan}) are already JSON-safe, so GET responses
|
|
@@ -93,6 +98,13 @@ function createRequestHandler(store, config) {
|
|
|
93
98
|
const base = config.basePath;
|
|
94
99
|
const apiPrefix = `${base}api`;
|
|
95
100
|
return function handle(req, res) {
|
|
101
|
+
try {
|
|
102
|
+
route(req, res);
|
|
103
|
+
} catch {
|
|
104
|
+
sendInternalError(res);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
function route(req, res) {
|
|
96
108
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
97
109
|
const pathname = url.pathname;
|
|
98
110
|
const host = hostHeaderName(req.headers.host);
|
|
@@ -107,8 +119,12 @@ function createRequestHandler(store, config) {
|
|
|
107
119
|
}
|
|
108
120
|
if (req.method === "POST" && config.evaluate) {
|
|
109
121
|
const match = matchEvaluatePath(pathname, apiPrefix);
|
|
122
|
+
if (match === "malformed") {
|
|
123
|
+
sendJson(res, 400, { error: "bad_trace_id" });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
110
126
|
if (match) {
|
|
111
|
-
handleEvaluate(store, config.evaluate, match.traceId, match.spanId, req, res);
|
|
127
|
+
handleEvaluate(store, config.evaluate, match.traceId, match.spanId, req, res).catch(() => sendInternalError(res));
|
|
112
128
|
return;
|
|
113
129
|
}
|
|
114
130
|
}
|
|
@@ -117,11 +133,17 @@ function createRequestHandler(store, config) {
|
|
|
117
133
|
return;
|
|
118
134
|
}
|
|
119
135
|
if (pathname === `${apiPrefix}/traces`) {
|
|
120
|
-
|
|
136
|
+
const { limit, full } = parseListOptions(url.searchParams);
|
|
137
|
+
const traces = store.query(parseQuery(url.searchParams)).slice(0, limit);
|
|
138
|
+
sendJson(res, 200, full ? traces : traces.map(toTraceSummary));
|
|
121
139
|
return;
|
|
122
140
|
}
|
|
123
141
|
if (pathname.startsWith(`${apiPrefix}/traces/`)) {
|
|
124
|
-
const traceId =
|
|
142
|
+
const traceId = safeDecode(pathname.slice(`${apiPrefix}/traces/`.length));
|
|
143
|
+
if (traceId === void 0) {
|
|
144
|
+
sendJson(res, 400, { error: "bad_trace_id" });
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
125
147
|
const trace = traceId.length > 0 ? store.get(traceId) : void 0;
|
|
126
148
|
if (trace === void 0) {
|
|
127
149
|
sendJson(res, 404, {
|
|
@@ -146,7 +168,26 @@ function createRequestHandler(store, config) {
|
|
|
146
168
|
return;
|
|
147
169
|
}
|
|
148
170
|
sendJson(res, 404, { error: "not_found" });
|
|
149
|
-
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* `decodeURIComponent` that answers `undefined` for a malformed escape
|
|
175
|
+
* (`%E0%A4%A`) instead of throwing a `URIError`.
|
|
176
|
+
*/
|
|
177
|
+
function safeDecode(value) {
|
|
178
|
+
try {
|
|
179
|
+
return decodeURIComponent(value);
|
|
180
|
+
} catch {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** Answer `500` unless a response is already on its way. */
|
|
185
|
+
function sendInternalError(res) {
|
|
186
|
+
if (res.headersSent) {
|
|
187
|
+
res.end();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
sendJson(res, 500, { error: "internal" });
|
|
150
191
|
}
|
|
151
192
|
/** Write a JSON response with the given status code and security headers. */
|
|
152
193
|
function sendJson(res, status, body) {
|
|
@@ -160,16 +201,20 @@ function sendJson(res, status, body) {
|
|
|
160
201
|
* Match `{apiPrefix}/traces/:traceId/spans/:spanId/evaluate` — the one
|
|
161
202
|
* write route. Returns `undefined` for anything else, including the plain
|
|
162
203
|
* `{apiPrefix}/traces/:id` read route (no `/spans/.../evaluate` suffix),
|
|
163
|
-
* so the two never collide.
|
|
204
|
+
* so the two never collide. `"malformed"` when an id is not valid
|
|
205
|
+
* percent-encoding.
|
|
164
206
|
*/
|
|
165
207
|
function matchEvaluatePath(pathname, apiPrefix) {
|
|
166
208
|
const prefix = `${apiPrefix}/traces/`;
|
|
167
209
|
if (!pathname.startsWith(prefix)) return;
|
|
168
210
|
const match = /^([^/]+)\/spans\/([^/]+)\/evaluate$/.exec(pathname.slice(prefix.length));
|
|
169
211
|
if (!match) return;
|
|
212
|
+
const traceId = safeDecode(match[1] ?? "");
|
|
213
|
+
const spanId = safeDecode(match[2] ?? "");
|
|
214
|
+
if (traceId === void 0 || spanId === void 0) return "malformed";
|
|
170
215
|
return {
|
|
171
|
-
traceId
|
|
172
|
-
spanId
|
|
216
|
+
traceId,
|
|
217
|
+
spanId
|
|
173
218
|
};
|
|
174
219
|
}
|
|
175
220
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/dashboard/serve.ts"],"sourcesContent":["import { timingSafeEqual } from \"node:crypto\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { EvaluateConfig } from \"../evaluate/evaluate.type\";\nimport { evaluateSystemPrompt } from \"../evaluate/evaluate-system-prompt\";\nimport { extractLastSystemPrompt } from \"../evaluate/extract-last-system-prompt\";\nimport { findSpanById } from \"../evaluate/find-span-by-id\";\nimport type { TraceStoreContract } from \"../store/trace-store.contract\";\nimport { parseQuery } from \"./parse-query\";\nimport { dashboardHtml } from \"./ui.html\";\n\n/** Fully-resolved routing config the request handler closes over. */\nexport type ServeConfig = {\n /** Normalized mount path, always ending in `/` (e.g. `\"/\"`). */\n basePath: string;\n /** Header title baked into the served page. */\n title: string;\n /** Bearer token required on every request when set (S4). */\n authToken?: string;\n /** `Host` header allowlist — defends against DNS-rebinding (S4). */\n allowedHosts: string[];\n /**\n * Enables the one write route: `POST\n * {basePath}api/traces/:traceId/spans/:spanId/evaluate`. Absent ⇒ the\n * route 405s (POST isn't accepted by any route) and the served page never\n * renders the Evaluate button.\n */\n evaluate?: EvaluateConfig;\n};\n\n/** Request body accepted by the evaluate route — everything optional. */\ntype EvaluateRequestBody = {\n /** Per-run instructions override; falls back to `config.evaluate.instructions`. */\n instructions?: string;\n};\n\n/** Hard cap on the evaluate route's request body — well beyond a real instructions string. */\nconst MAX_EVALUATE_BODY_BYTES = 64 * 1024;\n\n/**\n * Security response headers added to every dashboard response (S4):\n * block MIME-sniffing, framing, referrer leakage, and lock the page's\n * content sources down to itself (the UI is fully self-contained — no CDN).\n */\nconst SECURITY_HEADERS: Record<string, string> = {\n \"x-content-type-options\": \"nosniff\",\n \"x-frame-options\": \"DENY\",\n \"referrer-policy\": \"no-referrer\",\n \"content-security-policy\":\n \"default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src 'self'; img-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\",\n};\n\n/** Extract the host (no port) from a `Host` header value. */\nfunction hostHeaderName(hostHeader: string | undefined): string | undefined {\n if (!hostHeader) return undefined;\n // IPv6 literal `[::1]:4319` → `[::1]`; otherwise strip `:port`.\n if (hostHeader.startsWith(\"[\")) {\n return hostHeader.slice(0, hostHeader.indexOf(\"]\") + 1);\n }\n const colon = hostHeader.indexOf(\":\");\n return colon === -1 ? hostHeader : hostHeader.slice(0, colon);\n}\n\n/**\n * Constant-time string equality (S4) — guards against a timing\n * side-channel that could otherwise let a network-adjacent attacker\n * recover the token byte-by-byte via repeated timed guesses. Plain `===`\n * short-circuits on the first differing byte, so response latency leaks\n * how many leading bytes matched; `timingSafeEqual` does not. Lengths are\n * compared first (a length mismatch is not secret and `timingSafeEqual`\n * requires equal-length buffers anyway).\n */\nfunction constantTimeEqual(a: string, b: string): boolean {\n const bufA = Buffer.from(a);\n const bufB = Buffer.from(b);\n\n if (bufA.length !== bufB.length) return false;\n\n return timingSafeEqual(bufA, bufB);\n}\n\n/**\n * Bearer-token check (S4): `Authorization: Bearer <token>` header, or\n * (only when `allowQueryToken`) a `?token=` query param.\n *\n * The query-string form only exists for the one request that structurally\n * cannot carry a custom header — the initial browser navigation that\n * loads the HTML shell (a typed/clicked/bookmarked URL). Every other\n * request the served page makes is same-origin `fetch()`, which can and\n * does set `Authorization` (see `ui.html.ts`'s `fetchAuthed`), so the API\n * routes never need to accept a query-string token. Restricting the\n * fallback to just the page route minimizes the token's exposure in\n * server access logs, proxy logs, and browser history to a single route\n * instead of every poll.\n */\nfunction isAuthorized(\n req: IncomingMessage,\n url: URL,\n token: string,\n allowQueryToken: boolean,\n): boolean {\n const header = req.headers.authorization;\n if (header && constantTimeEqual(header, `Bearer ${token}`)) return true;\n if (!allowQueryToken) return false;\n const queryToken = url.searchParams.get(\"token\");\n return queryToken !== null && constantTimeEqual(queryToken, token);\n}\n\n/**\n * Build the `node:http` request handler for the dashboard over a given\n * trace store. Kept separate from the server lifecycle so it can be unit\n * tested by feeding it a fake `req`/`res` without binding a port.\n *\n * Routes (all under `config.basePath`):\n *\n * - `GET api/traces` → `store.query(parseQuery(searchParams))`\n * - `GET api/traces/:id` → `store.get(id)` or `404`\n * - `GET api/aggregate` → `store.aggregate(parseQuery(searchParams))`\n * - `GET {basePath}` → the self-contained HTML page\n * - `POST api/traces/:traceId/spans/:spanId/evaluate` → ONLY when\n * `config.evaluate` is set; grades the span's last captured system\n * prompt and returns a {@link EvaluateVerdict}. The dashboard's one\n * write route — absent config, POST 405s like it would against any\n * other route (the path is never even pattern-matched).\n *\n * Anything else → `404`. A method the matched route doesn't accept → `405`.\n * Host allowlist + bearer-token auth (S4) are checked for EVERY request,\n * regardless of method, before any routing. The store shapes\n * ({@link Trace}/{@link TraceSpan}) are already JSON-safe, so GET responses\n * are a plain `JSON.stringify` with no serializer.\n *\n * @example\n * const handler = createRequestHandler(store, { basePath: \"/\", title: \"Panoptic\" });\n * http.createServer(handler).listen(4319, \"127.0.0.1\");\n */\nexport function createRequestHandler(\n store: TraceStoreContract,\n config: ServeConfig,\n): (req: IncomingMessage, res: ServerResponse) => void {\n const base = config.basePath;\n const apiPrefix = `${base}api`;\n\n return function handle(req: IncomingMessage, res: ServerResponse): void {\n // `req.url` is path + query only; a dummy origin lets URL parse it.\n const url = new URL(req.url ?? \"/\", \"http://localhost\");\n const pathname = url.pathname;\n\n // Host-header allowlist — blocks DNS-rebinding attacks that point a\n // hostile domain at this loopback port (S4). Checked for every method.\n const host = hostHeaderName(req.headers.host);\n if (!host || !config.allowedHosts.includes(host.toLowerCase())) {\n sendJson(res, 403, { error: \"host_not_allowed\" });\n\n return;\n }\n\n // Bearer-token auth when configured (always required off loopback, S4).\n // `?token=` is only honored on the HTML page route — see `isAuthorized`.\n const isPageRoute = pathname === base || pathname === base.replace(/\\/$/, \"\");\n if (config.authToken && !isAuthorized(req, url, config.authToken, isPageRoute)) {\n sendJson(res, 401, { error: \"unauthorized\" });\n\n return;\n }\n\n // The one write route — opt-in via `config.evaluate`, so it must be\n // checked before the blanket GET-only gate below.\n if (req.method === \"POST\" && config.evaluate) {\n const match = matchEvaluatePath(pathname, apiPrefix);\n\n if (match) {\n void handleEvaluate(store, config.evaluate, match.traceId, match.spanId, req, res);\n\n return;\n }\n }\n\n if (req.method !== \"GET\") {\n sendJson(res, 405, { error: \"method_not_allowed\" });\n\n return;\n }\n\n if (pathname === `${apiPrefix}/traces`) {\n sendJson(res, 200, store.query(parseQuery(url.searchParams)));\n\n return;\n }\n\n if (pathname.startsWith(`${apiPrefix}/traces/`)) {\n const traceId = decodeURIComponent(pathname.slice(`${apiPrefix}/traces/`.length));\n const trace = traceId.length > 0 ? store.get(traceId) : undefined;\n\n if (trace === undefined) {\n sendJson(res, 404, { error: \"trace_not_found\", traceId });\n\n return;\n }\n\n sendJson(res, 200, trace);\n\n return;\n }\n\n if (pathname === `${apiPrefix}/aggregate`) {\n sendJson(res, 200, store.aggregate(parseQuery(url.searchParams)));\n\n return;\n }\n\n if (pathname === base || pathname === base.replace(/\\/$/, \"\")) {\n res.writeHead(200, {\n \"content-type\": \"text/html; charset=utf-8\",\n ...SECURITY_HEADERS,\n });\n res.end(\n dashboardHtml(\n base,\n config.title,\n Boolean(config.evaluate),\n config.evaluate?.instructions ?? \"\",\n ),\n );\n\n return;\n }\n\n sendJson(res, 404, { error: \"not_found\" });\n };\n}\n\n/** Write a JSON response with the given status code and security headers. */\nfunction sendJson(res: ServerResponse, status: number, body: unknown): void {\n res.writeHead(status, {\n \"content-type\": \"application/json; charset=utf-8\",\n ...SECURITY_HEADERS,\n });\n res.end(JSON.stringify(body));\n}\n\n/**\n * Match `{apiPrefix}/traces/:traceId/spans/:spanId/evaluate` — the one\n * write route. Returns `undefined` for anything else, including the plain\n * `{apiPrefix}/traces/:id` read route (no `/spans/.../evaluate` suffix),\n * so the two never collide.\n */\nfunction matchEvaluatePath(\n pathname: string,\n apiPrefix: string,\n): { traceId: string; spanId: string } | undefined {\n const prefix = `${apiPrefix}/traces/`;\n\n if (!pathname.startsWith(prefix)) {\n return undefined;\n }\n\n const match = /^([^/]+)\\/spans\\/([^/]+)\\/evaluate$/.exec(pathname.slice(prefix.length));\n\n if (!match) {\n return undefined;\n }\n\n return {\n traceId: decodeURIComponent(match[1]),\n spanId: decodeURIComponent(match[2]),\n };\n}\n\n/**\n * Collect and JSON-parse a request body, capped at\n * {@link MAX_EVALUATE_BODY_BYTES} so an oversized body can't hold the\n * connection open indefinitely. An empty body resolves to `undefined` —\n * the evaluate route treats that as \"no per-run override\".\n */\nfunction readJsonBody<T>(req: IncomingMessage): Promise<T | undefined> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let size = 0;\n\n req.on(\"data\", (chunk: Buffer) => {\n size += chunk.length;\n\n if (size > MAX_EVALUATE_BODY_BYTES) {\n req.destroy();\n reject(new Error(\"payload_too_large\"));\n\n return;\n }\n\n chunks.push(chunk);\n });\n\n req.on(\"end\", () => {\n if (chunks.length === 0) {\n resolve(undefined);\n\n return;\n }\n\n try {\n resolve(JSON.parse(Buffer.concat(chunks).toString(\"utf-8\")) as T);\n } catch {\n reject(new Error(\"invalid_json\"));\n }\n });\n\n req.on(\"error\", reject);\n });\n}\n\n/**\n * Handle `POST {apiPrefix}/traces/:traceId/spans/:spanId/evaluate`. Looks\n * up the trace + span, extracts its last captured system prompt, and\n * grades it via {@link evaluateSystemPrompt}. `judgePromptBody` itself\n * never throws (a broken judge degrades to an issues-only outcome) — the\n * try/catch here only guards `config.evaluate.model` resolution, the one\n * step that CAN throw (e.g. a factory constructing an SDK client).\n */\nasync function handleEvaluate(\n store: TraceStoreContract,\n evaluate: EvaluateConfig,\n traceId: string,\n spanId: string,\n req: IncomingMessage,\n res: ServerResponse,\n): Promise<void> {\n const trace = store.get(traceId);\n\n if (trace === undefined) {\n sendJson(res, 404, { error: \"trace_not_found\", traceId });\n\n return;\n }\n\n const span = findSpanById(trace.root, spanId);\n\n if (span === undefined) {\n sendJson(res, 404, { error: \"span_not_found\", spanId });\n\n return;\n }\n\n const systemPrompt = extractLastSystemPrompt(span);\n\n if (systemPrompt === undefined) {\n sendJson(res, 422, { error: \"no_system_prompt\" });\n\n return;\n }\n\n let body: EvaluateRequestBody | undefined;\n\n try {\n body = await readJsonBody<EvaluateRequestBody>(req);\n } catch (error) {\n const message = error instanceof Error ? error.message : \"invalid_json\";\n sendJson(res, message === \"payload_too_large\" ? 413 : 400, { error: message });\n\n return;\n }\n\n try {\n const verdict = await evaluateSystemPrompt(systemPrompt, evaluate, body?.instructions);\n sendJson(res, 200, verdict);\n } catch (error) {\n sendJson(res, 502, {\n error: \"evaluate_failed\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n}\n"],"mappings":";;;;;;;;;AAoCA,MAAM,0BAA0B;;;;;;AAOhC,MAAM,mBAA2C;CAC/C,0BAA0B;CAC1B,mBAAmB;CACnB,mBAAmB;CACnB,2BACE;AACJ;;AAGA,SAAS,eAAe,YAAoD;CAC1E,IAAI,CAAC,YAAY,OAAO;CAExB,IAAI,WAAW,WAAW,GAAG,GAC3B,OAAO,WAAW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AAC;EAED,IAAI,GAAG,SAAS,MAAM;CACxB,CAAC;AACH;;;;;;;;;AAUA,eAAe,eACb,OACA,UACA,SACA,QACA,KACA,KACe;CACf,MAAM,QAAQ,MAAM,IAAI,OAAO;CAE/B,IAAI,UAAU,QAAW;EACvB,SAAS,KAAK,KAAK;GAAE,OAAO;GAAmB;EAAQ,CAAC;EAExD;CACF;CAEA,MAAM,OAAO,aAAa,MAAM,MAAM,MAAM;CAE5C,IAAI,SAAS,QAAW;EACtB,SAAS,KAAK,KAAK;GAAE,OAAO;GAAkB;EAAO,CAAC;EAEtD;CACF;CAEA,MAAM,eAAe,wBAAwB,IAAI;CAEjD,IAAI,iBAAiB,QAAW;EAC9B,SAAS,KAAK,KAAK,EAAE,OAAO,mBAAmB,CAAC;EAEhD;CACF;CAEA,IAAI;CAEJ,IAAI;EACF,OAAO,MAAM,aAAkC,GAAG;CACpD,SAAS,OAAO;EACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;EACzD,SAAS,KAAK,YAAY,sBAAsB,MAAM,KAAK,EAAE,OAAO,QAAQ,CAAC;EAE7E;CACF;CAEA,IAAI;EAEF,SAAS,KAAK,KAAK,MADG,qBAAqB,cAAc,UAAU,MAAM,YAAY,CAC3D;CAC5B,SAAS,OAAO;EACd,SAAS,KAAK,KAAK;GACjB,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAChE,CAAC;CACH;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace-filter.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/dashboard/trace-filter.ts"],"sourcesContent":["import type { ReportStatus, ReportType } from \"@warlock.js/ai\";\nimport type { Trace, TraceSpan } from \"../contracts/trace.type\";\n\n/**\n * Client-side trace-list filter criteria. The dashboard polls the full\n * trace list every 2s and narrows it in the browser with these — search\n * box, filter chips, and the errors-only header toggle all feed one\n * {@link TraceFilter}. Kept as a pure, framework-free module so the exact\n * matching rules are unit-tested here and the inlined dashboard JS in\n * {@link import(\"./ui.html\").dashboardHtml} mirrors them 1:1.\n *\n * Every field is optional — an absent field is \"don't care\". An empty\n * filter therefore matches every trace.\n */\nexport type TraceFilter = {\n /**\n * Free-text needle matched case-insensitively against a trace's root\n * span name and session id. Whitespace-trimmed; an empty/blank string\n * is treated as absent.\n */\n text?: string;\n /**\n * Restrict to these terminal statuses (root span status). Empty array\n * is treated as \"don't care\" (matches every status).\n */\n statuses?: ReportStatus[];\n /**\n * Restrict to these executable types (root span type). Empty array is\n * treated as \"don't care\".\n */\n types?: ReportType[];\n /**\n * Exact session-id chip. When set, only traces whose `sessionId`\n * equals this value match. Distinct from {@link TraceFilter.text},\n * which is a fuzzy substring across name + session.\n */\n sessionId?: string;\n /**\n * Exact prompt chip — a `name@version` key (see {@link tracePromptKey}).\n * When set, only traces whose root span resolved that exact named prompt\n * version match. Mirrors {@link TraceFilter.sessionId} but over the\n * prompt-version-linkage attributes the collector stamps on agent spans.\n */\n promptKey?: string;\n /**\n * Errors-only header toggle. When `true`, only `failed` / `cancelled`\n * traces match — independent of (and intersected with) `statuses`.\n */\n errorsOnly?: boolean;\n};\n\n/** Statuses the errors-only toggle keeps. */\nconst ERROR_STATUSES: readonly ReportStatus[] = [\"failed\", \"cancelled\"] as const;\n\n/**\n * Span-attribute keys the collector stamps with prompt-version linkage when\n * an agent ran against a *named* `ai.prompts` builder. Read here (not\n * imported) so this pure module stays decoupled from the collector.\n */\nconst PROMPT_NAME_ATTR = \"agent.promptName\";\nconst PROMPT_VERSION_ATTR = \"agent.promptVersion\";\n\n/**\n * The `name@version` prompt key a trace falls under, read from its root\n * span's prompt-version-linkage attributes (`agent.promptName` /\n * `agent.promptVersion`). Returns `undefined` when the run carried no named\n * prompt (raw-string / anonymous / no prompt), so callers can bucket those\n * under a synthetic \"no prompt\" key or skip them.\n *\n * The version is included so two runs of the same prompt name at different\n * versions are distinct keys — that is the whole point of the linkage: to\n * group / filter by the *exact* prompt revision that produced a run.\n */\nexport function tracePromptKey(trace: Trace): string | undefined {\n const attributes = trace.root.attributes;\n\n if (attributes === undefined) {\n return undefined;\n }\n\n const name = attributes[PROMPT_NAME_ATTR];\n\n if (typeof name !== \"string\" || name.length === 0) {\n return undefined;\n }\n\n const version = attributes[PROMPT_VERSION_ATTR];\n const versionLabel = typeof version === \"string\" && version.length > 0 ? version : \"1\";\n\n return `${name}@${versionLabel}`;\n}\n\n/**\n * Does a single trace pass the given filter? Pure predicate — all\n * conditions are ANDed; an unset field never excludes. Used by\n * {@link filterTraces} and mirrored by the dashboard's inlined JS.\n */\nexport function matchesFilter(trace: Trace, filter: TraceFilter): boolean {\n const root = trace.root;\n\n if (filter.errorsOnly === true && !ERROR_STATUSES.includes(root.status)) {\n return false;\n }\n\n if (filter.statuses !== undefined && filter.statuses.length > 0) {\n if (!filter.statuses.includes(root.status)) {\n return false;\n }\n }\n\n if (filter.types !== undefined && filter.types.length > 0) {\n if (!filter.types.includes(root.type)) {\n return false;\n }\n }\n\n if (filter.sessionId !== undefined && filter.sessionId.length > 0) {\n if (trace.sessionId !== filter.sessionId) {\n return false;\n }\n }\n\n if (filter.promptKey !== undefined && filter.promptKey.length > 0) {\n if (tracePromptKey(trace) !== filter.promptKey) {\n return false;\n }\n }\n\n const text = filter.text?.trim().toLowerCase();\n if (text !== undefined && text.length > 0) {\n const haystack = `${root.name} ${trace.sessionId ?? \"\"}`.toLowerCase();\n if (!haystack.includes(text)) {\n return false;\n }\n }\n\n return true;\n}\n\n/** Narrow a trace list to those matching the filter, order preserved. */\nexport function filterTraces(traces: Trace[], filter: TraceFilter): Trace[] {\n return traces.filter((trace) => matchesFilter(trace, filter));\n}\n\n/**\n * The grouping key a trace falls under when the list is grouped by\n * session. Traces without a `sessionId` collapse into one synthetic\n * \"(no session)\" bucket so they remain visible.\n */\nexport const NO_SESSION_KEY = \"(no session)\";\n\n/** One session bucket — its key plus the traces under it, order preserved. */\nexport type SessionGroup = {\n /** The `sessionId`, or {@link NO_SESSION_KEY} for sessionless traces. */\n sessionId: string;\n /** Traces in this group, in the order they appeared in the input. */\n traces: Trace[];\n};\n\n/**\n * Group an (already filtered, newest-first) trace list by session id,\n * preserving first-seen order of both the groups and the traces within\n * each. Sessionless traces bucket under {@link NO_SESSION_KEY}.\n */\nexport function groupBySession(traces: Trace[]): SessionGroup[] {\n const order: string[] = [];\n const byKey = new Map<string, Trace[]>();\n\n for (const trace of traces) {\n const key = trace.sessionId ?? NO_SESSION_KEY;\n let bucket = byKey.get(key);\n\n if (bucket === undefined) {\n bucket = [];\n byKey.set(key, bucket);\n order.push(key);\n }\n\n bucket.push(trace);\n }\n\n return order.map((sessionId) => ({ sessionId, traces: byKey.get(sessionId) ?? [] }));\n}\n\n/**\n * The grouping key a trace falls under when the list is grouped by prompt\n * version. Runs that resolved no named prompt collapse into one synthetic\n * \"(no prompt)\" bucket so they remain visible.\n */\nexport const NO_PROMPT_KEY = \"(no prompt)\";\n\n/** One prompt-version bucket — its `name@version` key plus its traces. */\nexport type PromptGroup = {\n /** The `name@version` key, or {@link NO_PROMPT_KEY} for unlinked traces. */\n promptKey: string;\n /** Traces in this group, in the order they appeared in the input. */\n traces: Trace[];\n};\n\n/**\n * Group an (already filtered, newest-first) trace list by prompt version —\n * the `name@version` key {@link tracePromptKey} derives from each run's\n * prompt-version-linkage attributes. Preserves first-seen order of both the\n * groups and the traces within each. Runs with no named prompt bucket under\n * {@link NO_PROMPT_KEY}.\n *\n * The dashboard offers this as a second group-by dimension beside session,\n * so a reviewer can see every run of \"support@2\" together and compare its\n * cost / failure rate against \"support@3\".\n */\nexport function groupByPrompt(traces: Trace[]): PromptGroup[] {\n const order: string[] = [];\n const byKey = new Map<string, Trace[]>();\n\n for (const trace of traces) {\n const key = tracePromptKey(trace) ?? NO_PROMPT_KEY;\n let bucket = byKey.get(key);\n\n if (bucket === undefined) {\n bucket = [];\n byKey.set(key, bucket);\n order.push(key);\n }\n\n bucket.push(trace);\n }\n\n return order.map((promptKey) => ({ promptKey, traces: byKey.get(promptKey) ?? [] }));\n}\n\n/**\n * The grouping key a trace falls under when the list is grouped by root\n * type. `root.type` is always present, so this is only a defensive\n * fallback for a malformed trace with no typed root.\n */\nexport const NO_TYPE_KEY = \"(no type)\";\n\n/** One root-type bucket — its type discriminator plus its traces. */\nexport type TypeGroup = {\n /** The root span's `type` (e.g. `agent` / `workflow` / `planner`), or {@link NO_TYPE_KEY}. */\n type: string;\n /** Traces in this group, in the order they appeared in the input. */\n traces: Trace[];\n};\n\n/**\n * Group an (already filtered, newest-first) trace list by root type —\n * the `agent` / `workflow` / `supervisor` / `orchestrator` / `planner` /\n * `tool` / `batch` / `callback` discriminator on each trace's root span.\n * Preserves first-seen order of both the groups and the traces within each.\n *\n * The dashboard offers this as the coarsest group-by dimension beside\n * session and prompt: when a benchmark floods the flat list with hundreds\n * of one primitive (e.g. standalone `agent` runs), this collapses them\n * behind a per-type header so the structural primitives (the lone planner,\n * the team, the supervisors) are one click away instead of a scroll past.\n */\nexport function groupByType(traces: Trace[]): TypeGroup[] {\n const order: string[] = [];\n const byKey = new Map<string, Trace[]>();\n\n for (const trace of traces) {\n const key = trace.root.type || NO_TYPE_KEY;\n let bucket = byKey.get(key);\n\n if (bucket === undefined) {\n bucket = [];\n byKey.set(key, bucket);\n order.push(key);\n }\n\n bucket.push(trace);\n }\n\n return order.map((type) => ({ type, traces: byKey.get(type) ?? [] }));\n}\n\n/** One row of the per-type aggregate-stats panel. */\nexport type TypeStat = {\n /** Root type discriminator, or {@link NO_TYPE_KEY}. */\n type: string;\n /** Number of traces of this type. */\n count: number;\n /** Traces whose status is `failed` / `cancelled`. */\n failed: number;\n /** `failed / count` in `[0, 1]`. */\n failRate: number;\n /** Median (p50) root duration in ms. */\n p50: number;\n /** p95 root duration in ms. */\n p95: number;\n /** Summed `usage.total` tokens across the bucket. */\n tokens: number;\n /** Summed per-trace USD cost across the bucket. */\n cost: number;\n};\n\n/**\n * Nearest-rank percentile of `values` at `p` (0–100). Returns 0 for an\n * empty input and sorts a copy so the caller's array is left untouched.\n */\nexport function percentile(values: number[], p: number): number {\n if (values.length === 0) {\n return 0;\n }\n\n const sorted = values.slice().sort((a, b) => a - b);\n const rank = Math.ceil((p / 100) * sorted.length) - 1;\n const index = Math.min(Math.max(rank, 0), sorted.length - 1);\n\n return sorted[index];\n}\n\n/**\n * One trace's total USD cost: its explicit root-usage cost when priced,\n * else the rollup of its subtree. Mirrors the dashboard's `traceCost` so the\n * stats panel and the trace rows agree to the cent.\n */\nexport function traceCost(trace: Trace): number {\n const own = costSumObj(trace.usage.cost);\n return own > 0 ? own : rollupCost(trace.root);\n}\n\n/**\n * Aggregate an (already filtered) trace list into one {@link TypeStat} row\n * per root type — count, failure rate, p50/p95 latency, total tokens, total\n * cost — preserving first-seen type order. Powers the dashboard's per-type\n * stats panel; computed over the same filtered list the trace view shows, so\n * the panel always reflects the active filters.\n */\nexport function aggregateByType(traces: Trace[]): TypeStat[] {\n const order: string[] = [];\n const byKey = new Map<string, Trace[]>();\n\n for (const trace of traces) {\n const key = trace.root.type || NO_TYPE_KEY;\n let bucket = byKey.get(key);\n\n if (bucket === undefined) {\n bucket = [];\n byKey.set(key, bucket);\n order.push(key);\n }\n\n bucket.push(trace);\n }\n\n return order.map((type) => {\n const bucket = byKey.get(type) ?? [];\n const durations = bucket.map((trace) => trace.duration);\n let failed = 0;\n let tokens = 0;\n let cost = 0;\n\n for (const trace of bucket) {\n if (ERROR_STATUSES.includes(trace.root.status)) {\n failed += 1;\n }\n\n tokens += trace.usage.total ?? 0;\n cost += traceCost(trace);\n }\n\n return {\n type,\n count: bucket.length,\n failed,\n failRate: bucket.length > 0 ? failed / bucket.length : 0,\n p50: percentile(durations, 50),\n p95: percentile(durations, 95),\n tokens,\n cost,\n };\n });\n}\n\n/**\n * Sum every priced lane of a usage cost object into one USD number.\n * Mirrors the dashboard's `costSumObj` so heatmap intensities computed\n * here match what the page renders.\n */\nfunction costSumObj(cost: TraceSpan[\"usage\"][\"cost\"]): number {\n if (cost === undefined) {\n return 0;\n }\n\n return (\n (cost.input ?? 0) +\n (cost.output ?? 0) +\n (cost.cachedInput ?? 0) +\n (cost.cacheWrite ?? 0) +\n (cost.cachedOutput ?? 0) +\n (cost.reasoning ?? 0)\n );\n}\n\n/**\n * Rollup-aware subtree cost: a node's own cost when it carries one\n * (it already rolls up its trips), otherwise the sum of its children.\n * Avoids double-counting wrapper nodes (workflow/supervisor roots carry\n * tokens but no cost). Mirrors the dashboard's `rollupCost`.\n */\nexport function rollupCost(span: TraceSpan): number {\n const own = costSumObj(span.usage.cost);\n if (own > 0) {\n return own;\n }\n\n let sum = 0;\n for (const child of span.children) {\n sum += rollupCost(child);\n }\n\n return sum;\n}\n\n/**\n * Heatmap intensity in `[0, 1]` for a node's `rollupCost` relative to the\n * trace's most-expensive node. The dashboard tints each tree node's left\n * accent by this. `max <= 0` (a free trace) yields `0` for every node so\n * the heatmap simply stays cold rather than dividing by zero.\n */\nexport function heatIntensity(nodeCost: number, maxCost: number): number {\n if (maxCost <= 0 || nodeCost <= 0) {\n return 0;\n }\n\n const ratio = nodeCost / maxCost;\n\n return ratio > 1 ? 1 : ratio;\n}\n\n/**\n * The largest single-node {@link rollupCost} anywhere in a span tree —\n * the denominator for {@link heatIntensity}. Walks the whole subtree.\n */\nexport function maxNodeCost(root: TraceSpan): number {\n let max = rollupCost(root);\n\n for (const child of root.children) {\n const childMax = maxNodeCost(child);\n if (childMax > max) {\n max = childMax;\n }\n }\n\n return max;\n}\n"],"mappings":";;AAoDA,MAAM,iBAA0C,CAAC,UAAU,WAAW;;;;;;AAOtE,MAAM,mBAAmB;AACzB,MAAM,sBAAsB;;;;;;;;;;;;AAa5B,SAAgB,eAAe,OAAkC;CAC/D,MAAM,aAAa,MAAM,KAAK;CAE9B,IAAI,eAAe,QACjB;CAGF,MAAM,OAAO,WAAW;CAExB,IAAI,OAAO,SAAS,YAAY,KAAK,WAAW,GAC9C;CAGF,MAAM,UAAU,WAAW;CAG3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T;;;;;;;AAQA,SAAgB,cAAc,UAAkB,SAAyB;CACvE,IAAI,WAAW,KAAK,YAAY,GAC9B,OAAO;CAGT,MAAM,QAAQ,WAAW;CAEzB,OAAO,QAAQ,IAAI,IAAI;AACzB;;;;;AAMA,SAAgB,YAAY,MAAyB;CACnD,IAAI,MAAM,WAAW,IAAI;CAEzB,KAAK,MAAM,SAAS,KAAK,UAAU;EACjC,MAAM,WAAW,YAAY,KAAK;EAClC,IAAI,WAAW,KACb,MAAM;CAEV;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Trace, TraceSpan, TraceSpanError } from "../contracts/trace.type.mjs";
|
|
2
|
+
//#region ../../packages/ai-panoptic/src/dashboard/trace-summary.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The root span of a {@link TraceSummary}: identity, timing, status,
|
|
5
|
+
* usage and attributes, without captured content (`input` / `output`),
|
|
6
|
+
* children or the error's stack and cause.
|
|
7
|
+
*/
|
|
8
|
+
export type TraceSpanSummary = Omit<TraceSpan, "input" | "output" | "children" | "error"> & {
|
|
9
|
+
error?: Pick<TraceSpanError, "type" | "message">;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* One entry of the dashboard's `GET api/traces` list: everything the trace
|
|
13
|
+
* list renders, without the span tree or captured content. The full trace
|
|
14
|
+
* stays on `GET api/traces/:id` (or the list with `?full=1`).
|
|
15
|
+
*/
|
|
16
|
+
export type TraceSummary = Omit<Trace, "root"> & {
|
|
17
|
+
root: TraceSpanSummary;
|
|
18
|
+
/** Number of spans in the trace tree, the root included. */
|
|
19
|
+
spanCount: number;
|
|
20
|
+
/** Total USD cost of the trace (its priced root usage, else the rollup of its subtree). */
|
|
21
|
+
totalCost: number;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//# sourceMappingURL=trace-summary.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-summary.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/dashboard/trace-summary.ts"],"mappings":";;;;;;;YAQY,mBAAmB,KAAK;EAClC,QAAQ,KAAK;;;;;;;YAQH,eAAe,KAAK;EAC9B,MAAM;;EAEN;;EAEA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { traceCost } from "./trace-filter.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/ai-panoptic/src/dashboard/trace-summary.ts
|
|
4
|
+
function countSpans(span) {
|
|
5
|
+
let count = 1;
|
|
6
|
+
for (const child of span.children) count += countSpans(child);
|
|
7
|
+
return count;
|
|
8
|
+
}
|
|
9
|
+
/** Project a stored trace onto the list summary served by `GET api/traces`. */
|
|
10
|
+
function toTraceSummary(trace) {
|
|
11
|
+
const { input: _input, output: _output, children: _children, error, ...root } = trace.root;
|
|
12
|
+
const summaryRoot = root;
|
|
13
|
+
if (error !== void 0) summaryRoot.error = {
|
|
14
|
+
type: error.type,
|
|
15
|
+
message: error.message
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
...trace,
|
|
19
|
+
root: summaryRoot,
|
|
20
|
+
spanCount: countSpans(trace.root),
|
|
21
|
+
totalCost: traceCost(trace)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { toTraceSummary };
|
|
27
|
+
//# sourceMappingURL=trace-summary.mjs.map
|