@warlock.js/ai-panoptic 5.30.0 → 5.32.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 (161) hide show
  1. package/CHANGELOG.md +25 -3
  2. package/README.md +2 -2
  3. package/cjs/index.cjs +38 -84
  4. package/cjs/index.cjs.map +1 -1
  5. package/esm/collector/collector.d.mts +3 -5
  6. package/esm/collector/collector.d.mts.map +1 -1
  7. package/esm/collector/content-capture.type.d.mts +4 -5
  8. package/esm/collector/content-capture.type.d.mts.map +1 -1
  9. package/esm/collector/extract-span-attributes.d.mts +1 -3
  10. package/esm/collector/extract-span-attributes.d.mts.map +1 -1
  11. package/esm/collector/extract-span-attributes.mjs +2 -4
  12. package/esm/collector/extract-span-attributes.mjs.map +1 -1
  13. package/esm/collector/index.d.mts +2 -1
  14. package/esm/collector/index.mjs +1 -1
  15. package/esm/collector/normalize-error.d.mts +1 -3
  16. package/esm/collector/normalize-error.d.mts.map +1 -1
  17. package/esm/collector/report-to-span.d.mts +1 -3
  18. package/esm/collector/report-to-span.d.mts.map +1 -1
  19. package/esm/collector/report-to-span.mjs.map +1 -1
  20. package/esm/collector/report-to-trace.d.mts +1 -3
  21. package/esm/collector/report-to-trace.d.mts.map +1 -1
  22. package/esm/config/apply-panoptic-config.d.mts +2 -3
  23. package/esm/config/apply-panoptic-config.d.mts.map +1 -1
  24. package/esm/config/apply-panoptic-config.mjs.map +1 -1
  25. package/esm/config/index.d.mts +2 -1
  26. package/esm/config/index.mjs +1 -1
  27. package/esm/config/panoptic-config.type.d.mts +2 -4
  28. package/esm/config/panoptic-config.type.d.mts.map +1 -1
  29. package/esm/contracts/collector.contract.d.mts +1 -3
  30. package/esm/contracts/collector.contract.d.mts.map +1 -1
  31. package/esm/contracts/exporter.contract.d.mts +1 -3
  32. package/esm/contracts/exporter.contract.d.mts.map +1 -1
  33. package/esm/contracts/index.d.mts +2 -1
  34. package/esm/contracts/trace.type.d.mts +35 -20
  35. package/esm/contracts/trace.type.d.mts.map +1 -1
  36. package/esm/dashboard/dashboard.d.mts +1 -3
  37. package/esm/dashboard/dashboard.d.mts.map +1 -1
  38. package/esm/dashboard/dashboard.mjs +3 -2
  39. package/esm/dashboard/dashboard.mjs.map +1 -1
  40. package/esm/dashboard/dashboard.type.d.mts +9 -7
  41. package/esm/dashboard/dashboard.type.d.mts.map +1 -1
  42. package/esm/dashboard/index.d.mts +4 -1
  43. package/esm/dashboard/index.mjs +1 -1
  44. package/esm/dashboard/parse-query.d.mts +1 -1
  45. package/esm/dashboard/parse-query.mjs +1 -0
  46. package/esm/dashboard/parse-query.mjs.map +1 -1
  47. package/esm/dashboard/serve.d.mts +2 -1
  48. package/esm/dashboard/serve.mjs +1 -1
  49. package/esm/dashboard/serve.mjs.map +1 -1
  50. package/esm/dashboard/trace-filter.d.mts +44 -32
  51. package/esm/dashboard/trace-filter.d.mts.map +1 -1
  52. package/esm/dashboard/trace-filter.mjs +1 -1
  53. package/esm/dashboard/trace-filter.mjs.map +1 -1
  54. package/esm/dashboard/ui.html.mjs +5 -4
  55. package/esm/dashboard/ui.html.mjs.map +1 -1
  56. package/esm/evaluate/evaluate-system-prompt.d.mts +1 -3
  57. package/esm/evaluate/evaluate-system-prompt.d.mts.map +1 -1
  58. package/esm/evaluate/evaluate-system-prompt.mjs +3 -1
  59. package/esm/evaluate/evaluate-system-prompt.mjs.map +1 -1
  60. package/esm/evaluate/evaluate.type.d.mts +2 -4
  61. package/esm/evaluate/evaluate.type.d.mts.map +1 -1
  62. package/esm/evaluate/extract-last-system-prompt.d.mts +1 -3
  63. package/esm/evaluate/extract-last-system-prompt.d.mts.map +1 -1
  64. package/esm/evaluate/find-span-by-id.d.mts +1 -3
  65. package/esm/evaluate/find-span-by-id.d.mts.map +1 -1
  66. package/esm/evaluate/index.d.mts +2 -1
  67. package/esm/evaluate/index.mjs +1 -1
  68. package/esm/exporters/console/console-exporter.d.mts +2 -3
  69. package/esm/exporters/console/console-exporter.d.mts.map +1 -1
  70. package/esm/exporters/console/console-exporter.mjs +4 -3
  71. package/esm/exporters/console/console-exporter.mjs.map +1 -1
  72. package/esm/exporters/console/console-exporter.type.d.mts +2 -3
  73. package/esm/exporters/console/console-exporter.type.d.mts.map +1 -1
  74. package/esm/exporters/console/format-span-io.d.mts +2 -2
  75. package/esm/exporters/console/format-span-io.d.mts.map +1 -1
  76. package/esm/exporters/console/format-span-io.mjs.map +1 -1
  77. package/esm/exporters/console/format-span-line.d.mts +2 -2
  78. package/esm/exporters/console/format-span-line.d.mts.map +1 -1
  79. package/esm/exporters/console/format-span-line.mjs +2 -0
  80. package/esm/exporters/console/format-span-line.mjs.map +1 -1
  81. package/esm/exporters/console/index.d.mts +2 -1
  82. package/esm/exporters/console/index.mjs +5 -0
  83. package/esm/exporters/file/file-exporter.d.mts +2 -3
  84. package/esm/exporters/file/file-exporter.d.mts.map +1 -1
  85. package/esm/exporters/file/file-exporter.mjs.map +1 -1
  86. package/esm/exporters/file/file-exporter.type.d.mts +8 -5
  87. package/esm/exporters/file/file-exporter.type.d.mts.map +1 -1
  88. package/esm/exporters/file/index.d.mts +2 -1
  89. package/esm/exporters/index.d.mts +7 -1
  90. package/esm/exporters/index.mjs +3 -1
  91. package/esm/exporters/langfuse/index.d.mts +2 -1
  92. package/esm/exporters/langfuse/index.mjs +1 -1
  93. package/esm/exporters/langfuse/langfuse-exporter.d.mts +2 -3
  94. package/esm/exporters/langfuse/langfuse-exporter.d.mts.map +1 -1
  95. package/esm/exporters/langfuse/langfuse-exporter.mjs +4 -3
  96. package/esm/exporters/langfuse/langfuse-exporter.mjs.map +1 -1
  97. package/esm/exporters/langfuse/langfuse-exporter.type.d.mts +23 -17
  98. package/esm/exporters/langfuse/langfuse-exporter.type.d.mts.map +1 -1
  99. package/esm/exporters/otel/index.d.mts +2 -1
  100. package/esm/exporters/otel/index.mjs +1 -1
  101. package/esm/exporters/otel/otel-api.shim.type.d.mts +6 -7
  102. package/esm/exporters/otel/otel-api.shim.type.d.mts.map +1 -1
  103. package/esm/exporters/otel/otel-exporter.d.mts +2 -3
  104. package/esm/exporters/otel/otel-exporter.d.mts.map +1 -1
  105. package/esm/exporters/otel/otel-exporter.mjs +2 -1
  106. package/esm/exporters/otel/otel-exporter.mjs.map +1 -1
  107. package/esm/exporters/otel/otel-exporter.type.d.mts +1 -3
  108. package/esm/exporters/otel/otel-exporter.type.d.mts.map +1 -1
  109. package/esm/exporters/utils/gen-ai-attributes.d.mts +9 -7
  110. package/esm/exporters/utils/gen-ai-attributes.d.mts.map +1 -1
  111. package/esm/exporters/utils/index.d.mts +2 -1
  112. package/esm/exporters/utils/index.mjs +5 -0
  113. package/esm/exporters/utils/total-cost.d.mts +3 -7
  114. package/esm/exporters/utils/total-cost.d.mts.map +1 -1
  115. package/esm/exporters/utils/total-cost.mjs +5 -7
  116. package/esm/exporters/utils/total-cost.mjs.map +1 -1
  117. package/esm/exporters/utils/walk-spans.d.mts +2 -2
  118. package/esm/exporters/utils/walk-spans.d.mts.map +1 -1
  119. package/esm/index.d.mts +8 -0
  120. package/esm/panoptic/index.d.mts +2 -1
  121. package/esm/panoptic/index.mjs +1 -1
  122. package/esm/panoptic/panoptic-middleware.d.mts +1 -3
  123. package/esm/panoptic/panoptic-middleware.d.mts.map +1 -1
  124. package/esm/panoptic/panoptic-middleware.mjs.map +1 -1
  125. package/esm/panoptic/panoptic-target.type.d.mts +4 -5
  126. package/esm/panoptic/panoptic-target.type.d.mts.map +1 -1
  127. package/esm/panoptic/panoptic.d.mts +1 -3
  128. package/esm/panoptic/panoptic.d.mts.map +1 -1
  129. package/esm/panoptic/panoptic.mjs.map +1 -1
  130. package/esm/panoptic/panoptic.type.d.mts +8 -7
  131. package/esm/panoptic/panoptic.type.d.mts.map +1 -1
  132. package/esm/store/cache-trace-store.d.mts +4 -6
  133. package/esm/store/cache-trace-store.d.mts.map +1 -1
  134. package/esm/store/cache-trace-store.mjs +2 -4
  135. package/esm/store/cache-trace-store.mjs.map +1 -1
  136. package/esm/store/in-memory-trace-store.d.mts +2 -4
  137. package/esm/store/in-memory-trace-store.d.mts.map +1 -1
  138. package/esm/store/in-memory-trace-store.mjs +4 -5
  139. package/esm/store/in-memory-trace-store.mjs.map +1 -1
  140. package/esm/store/index.d.mts +2 -1
  141. package/esm/store/index.mjs +1 -1
  142. package/esm/store/match-trace.d.mts +1 -3
  143. package/esm/store/match-trace.d.mts.map +1 -1
  144. package/esm/store/sum-usage.d.mts +4 -30
  145. package/esm/store/sum-usage.d.mts.map +1 -1
  146. package/esm/store/sum-usage.mjs +6 -49
  147. package/esm/store/sum-usage.mjs.map +1 -1
  148. package/esm/store/trace-aggregate.type.d.mts +13 -14
  149. package/esm/store/trace-aggregate.type.d.mts.map +1 -1
  150. package/esm/store/trace-query.type.d.mts +5 -5
  151. package/esm/store/trace-query.type.d.mts.map +1 -1
  152. package/esm/store/trace-store.contract.d.mts +1 -3
  153. package/esm/store/trace-store.contract.d.mts.map +1 -1
  154. package/llms-full.txt +148 -117
  155. package/package.json +4 -4
  156. package/skills/evaluate-system-prompt/SKILL.md +21 -17
  157. package/skills/export-traces/SKILL.md +32 -24
  158. package/skills/index.md +3 -0
  159. package/skills/observe-with-panoptic/SKILL.md +18 -18
  160. package/skills/query-traces/SKILL.md +45 -33
  161. package/skills/use-local-dashboard/SKILL.md +33 -26
@@ -1,6 +1,6 @@
1
1
  import { ExporterContract } from "../../contracts/exporter.contract.mjs";
2
+ import "../../contracts/index.mjs";
2
3
  import { ConsoleExporterOptions } from "./console-exporter.type.mjs";
3
-
4
4
  //#region ../../packages/ai-panoptic/src/exporters/console/console-exporter.d.ts
5
5
  /**
6
6
  * Zero-dependency {@link ExporterContract} that prints traces to a
@@ -27,7 +27,6 @@ import { ConsoleExporterOptions } from "./console-exporter.type.mjs";
27
27
  * exporters: [consoleExporter({ tree: true, io: true })],
28
28
  * });
29
29
  */
30
- declare function consoleExporter(options?: ConsoleExporterOptions): ExporterContract;
30
+ export declare function consoleExporter(options?: ConsoleExporterOptions): ExporterContract;
31
31
  //#endregion
32
- export { consoleExporter };
33
32
  //# sourceMappingURL=console-exporter.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"console-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/console-exporter.ts"],"mappings":";;;;;;;AAiCA;;;;;;;;AAAuF;;;;;;;;;;;;;;iBAAvE,eAAA,CAAgB,OAAA,GAAS,sBAAA,GAA8B,gBAAgB"}
1
+ {"version":3,"file":"console-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/console-exporter.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiCgB,gBAAgB,UAAS,yBAA8B"}
@@ -1,4 +1,5 @@
1
1
  import { walkSpans } from "../utils/walk-spans.mjs";
2
+ import "../utils/index.mjs";
2
3
  import { formatSpanIO } from "./format-span-io.mjs";
3
4
  import { formatSpanLine } from "./format-span-line.mjs";
4
5
 
@@ -69,11 +70,11 @@ function writeSpan(sink, span, depth, io, ioMaxChars) {
69
70
  if (io) for (const line of formatSpanIO(span, depth, ioMaxChars)) writeAtSeverity(sink, span.status, line);
70
71
  }
71
72
  /**
72
- * Route a line to `error` when the span failed/cancelled, otherwise to
73
- * `log`. Keeps healthy traces out of the error stream.
73
+ * Route a line to `error` when the span failed/cancelled/incomplete,
74
+ * otherwise to `log`. Keeps healthy traces out of the error stream.
74
75
  */
75
76
  function writeAtSeverity(sink, status, line) {
76
- if (status === "failed" || status === "cancelled") {
77
+ if (status === "failed" || status === "cancelled" || status === "incomplete") {
77
78
  sink.error(line);
78
79
  return;
79
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"console-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/console-exporter.ts"],"sourcesContent":["import type { ExporterContract, Trace, TraceSpan } from \"../../contracts\";\nimport { walkSpans } from \"../utils\";\nimport type { ConsoleExporterOptions, ConsoleLike } from \"./console-exporter.type\";\nimport { formatSpanIO } from \"./format-span-io\";\nimport { formatSpanLine } from \"./format-span-line\";\n\nconst EXPORTER_NAME = \"console\";\n\n/**\n * Zero-dependency {@link ExporterContract} that prints traces to a\n * console-like sink. The simplest exporter — useful in development and\n * as the reference implementation of the contract.\n *\n * By default it prints one summary line per completed trace. Set\n * `tree: true` to print the full indented span tree, `io: true` to also\n * print each span's captured `input` / `output` (needs the collector's\n * `captureContent`), and `streaming: true` to print each span the moment\n * it finalizes (via the optional `exportSpan` hook).\n *\n * @example\n * collector.use(consoleExporter());\n * // ok workflow \"checkout\" — 2103ms, 1820 tok, $0.0094\n *\n * @example\n * collector.use(consoleExporter({ tree: true }));\n *\n * @example\n * // Full content trace — prompts, responses, and tool I/O:\n * const observe = panoptic({\n * captureContent: true,\n * exporters: [consoleExporter({ tree: true, io: true })],\n * });\n */\nexport function consoleExporter(options: ConsoleExporterOptions = {}): ExporterContract {\n const sink: ConsoleLike = options.console ?? console;\n const tree = options.tree ?? false;\n const io = options.io ?? false;\n const ioMaxChars = options.ioMaxChars;\n\n const exporter: ExporterContract = {\n name: EXPORTER_NAME,\n export(trace: Trace): void {\n writeTrace(sink, trace, tree, io, ioMaxChars);\n },\n };\n\n if (options.streaming) {\n exporter.exportSpan = (span: TraceSpan): void => {\n sink.log(formatSpanLine(span));\n\n if (io) {\n for (const line of formatSpanIO(span, 0, ioMaxChars)) {\n sink.log(line);\n }\n }\n };\n }\n\n return exporter;\n}\n\n/**\n * Write a completed trace — either a single root summary line or the\n * full indented tree, each span optionally followed by its captured\n * `input` / `output`. Failed / cancelled spans route to `console.error`\n * so they surface at the right severity in log aggregators.\n */\nfunction writeTrace(\n sink: ConsoleLike,\n trace: Trace,\n tree: boolean,\n io: boolean,\n ioMaxChars: number | undefined,\n): void {\n if (!tree) {\n writeSpan(sink, trace.root, 0, io, ioMaxChars);\n return;\n }\n\n for (const span of walkSpans(trace.root)) {\n const depth = spanDepth(trace.root, span.spanId);\n writeSpan(sink, span, depth, io, ioMaxChars);\n }\n}\n\n/**\n * Write one span's line and — when `io` is on — its captured content,\n * all routed at the span's own severity so a failed span keeps its\n * content beside it in the error stream.\n */\nfunction writeSpan(\n sink: ConsoleLike,\n span: TraceSpan,\n depth: number,\n io: boolean,\n ioMaxChars: number | undefined,\n): void {\n writeAtSeverity(sink, span.status, formatSpanLine(span, depth));\n\n if (io) {\n for (const line of formatSpanIO(span, depth, ioMaxChars)) {\n writeAtSeverity(sink, span.status, line);\n }\n }\n}\n\n/**\n * Route a line to `error` when the span failed/cancelled, otherwise to\n * `log`. Keeps healthy traces out of the error stream.\n */\nfunction writeAtSeverity(sink: ConsoleLike, status: TraceSpan[\"status\"], line: string): void {\n if (status === \"failed\" || status === \"cancelled\") {\n sink.error(line);\n return;\n }\n\n sink.log(line);\n}\n\n/**\n * Depth of `targetSpanId` below `root` for indentation. Walks the tree\n * once; returns 0 when the span is the root or not found.\n */\nfunction spanDepth(root: TraceSpan, targetSpanId: string, depth = 0): number {\n if (root.spanId === targetSpanId) {\n return depth;\n }\n\n for (const child of root.children) {\n const found = spanDepth(child, targetSpanId, depth + 1);\n\n if (found > 0) {\n return found;\n }\n }\n\n return 0;\n}\n"],"mappings":";;;;;AAMA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BtB,SAAgB,gBAAgB,UAAkC,CAAC,GAAqB;CACtF,MAAM,OAAoB,QAAQ,WAAW;CAC7C,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,KAAK,QAAQ,MAAM;CACzB,MAAM,aAAa,QAAQ;CAE3B,MAAM,WAA6B;EACjC,MAAM;EACN,OAAO,OAAoB;GACzB,WAAW,MAAM,OAAO,MAAM,IAAI,UAAU;EAC9C;CACF;CAEA,IAAI,QAAQ,WACV,SAAS,cAAc,SAA0B;EAC/C,KAAK,IAAI,eAAe,IAAI,CAAC;EAE7B,IAAI,IACF,KAAK,MAAM,QAAQ,aAAa,MAAM,GAAG,UAAU,GACjD,KAAK,IAAI,IAAI;CAGnB;CAGF,OAAO;AACT;;;;;;;AAQA,SAAS,WACP,MACA,OACA,MACA,IACA,YACM;CACN,IAAI,CAAC,MAAM;EACT,UAAU,MAAM,MAAM,MAAM,GAAG,IAAI,UAAU;EAC7C;CACF;CAEA,KAAK,MAAM,QAAQ,UAAU,MAAM,IAAI,GAErC,UAAU,MAAM,MADF,UAAU,MAAM,MAAM,KAAK,MACf,GAAG,IAAI,UAAU;AAE/C;;;;;;AAOA,SAAS,UACP,MACA,MACA,OACA,IACA,YACM;CACN,gBAAgB,MAAM,KAAK,QAAQ,eAAe,MAAM,KAAK,CAAC;CAE9D,IAAI,IACF,KAAK,MAAM,QAAQ,aAAa,MAAM,OAAO,UAAU,GACrD,gBAAgB,MAAM,KAAK,QAAQ,IAAI;AAG7C;;;;;AAMA,SAAS,gBAAgB,MAAmB,QAA6B,MAAoB;CAC3F,IAAI,WAAW,YAAY,WAAW,aAAa;EACjD,KAAK,MAAM,IAAI;EACf;CACF;CAEA,KAAK,IAAI,IAAI;AACf;;;;;AAMA,SAAS,UAAU,MAAiB,cAAsB,QAAQ,GAAW;CAC3E,IAAI,KAAK,WAAW,cAClB,OAAO;CAGT,KAAK,MAAM,SAAS,KAAK,UAAU;EACjC,MAAM,QAAQ,UAAU,OAAO,cAAc,QAAQ,CAAC;EAEtD,IAAI,QAAQ,GACV,OAAO;CAEX;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"console-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/console-exporter.ts"],"sourcesContent":["import type { ExporterContract, Trace, TraceSpan } from \"../../contracts\";\nimport { walkSpans } from \"../utils\";\nimport type { ConsoleExporterOptions, ConsoleLike } from \"./console-exporter.type\";\nimport { formatSpanIO } from \"./format-span-io\";\nimport { formatSpanLine } from \"./format-span-line\";\n\nconst EXPORTER_NAME = \"console\";\n\n/**\n * Zero-dependency {@link ExporterContract} that prints traces to a\n * console-like sink. The simplest exporter — useful in development and\n * as the reference implementation of the contract.\n *\n * By default it prints one summary line per completed trace. Set\n * `tree: true` to print the full indented span tree, `io: true` to also\n * print each span's captured `input` / `output` (needs the collector's\n * `captureContent`), and `streaming: true` to print each span the moment\n * it finalizes (via the optional `exportSpan` hook).\n *\n * @example\n * collector.use(consoleExporter());\n * // ok workflow \"checkout\" — 2103ms, 1820 tok, $0.0094\n *\n * @example\n * collector.use(consoleExporter({ tree: true }));\n *\n * @example\n * // Full content trace — prompts, responses, and tool I/O:\n * const observe = panoptic({\n * captureContent: true,\n * exporters: [consoleExporter({ tree: true, io: true })],\n * });\n */\nexport function consoleExporter(options: ConsoleExporterOptions = {}): ExporterContract {\n const sink: ConsoleLike = options.console ?? console;\n const tree = options.tree ?? false;\n const io = options.io ?? false;\n const ioMaxChars = options.ioMaxChars;\n\n const exporter: ExporterContract = {\n name: EXPORTER_NAME,\n export(trace: Trace): void {\n writeTrace(sink, trace, tree, io, ioMaxChars);\n },\n };\n\n if (options.streaming) {\n exporter.exportSpan = (span: TraceSpan): void => {\n sink.log(formatSpanLine(span));\n\n if (io) {\n for (const line of formatSpanIO(span, 0, ioMaxChars)) {\n sink.log(line);\n }\n }\n };\n }\n\n return exporter;\n}\n\n/**\n * Write a completed trace — either a single root summary line or the\n * full indented tree, each span optionally followed by its captured\n * `input` / `output`. Failed / cancelled spans route to `console.error`\n * so they surface at the right severity in log aggregators.\n */\nfunction writeTrace(\n sink: ConsoleLike,\n trace: Trace,\n tree: boolean,\n io: boolean,\n ioMaxChars: number | undefined,\n): void {\n if (!tree) {\n writeSpan(sink, trace.root, 0, io, ioMaxChars);\n return;\n }\n\n for (const span of walkSpans(trace.root)) {\n const depth = spanDepth(trace.root, span.spanId);\n writeSpan(sink, span, depth, io, ioMaxChars);\n }\n}\n\n/**\n * Write one span's line and — when `io` is on — its captured content,\n * all routed at the span's own severity so a failed span keeps its\n * content beside it in the error stream.\n */\nfunction writeSpan(\n sink: ConsoleLike,\n span: TraceSpan,\n depth: number,\n io: boolean,\n ioMaxChars: number | undefined,\n): void {\n writeAtSeverity(sink, span.status, formatSpanLine(span, depth));\n\n if (io) {\n for (const line of formatSpanIO(span, depth, ioMaxChars)) {\n writeAtSeverity(sink, span.status, line);\n }\n }\n}\n\n/**\n * Route a line to `error` when the span failed/cancelled/incomplete,\n * otherwise to `log`. Keeps healthy traces out of the error stream.\n */\nfunction writeAtSeverity(sink: ConsoleLike, status: TraceSpan[\"status\"], line: string): void {\n if (status === \"failed\" || status === \"cancelled\" || status === \"incomplete\") {\n sink.error(line);\n return;\n }\n\n sink.log(line);\n}\n\n/**\n * Depth of `targetSpanId` below `root` for indentation. Walks the tree\n * once; returns 0 when the span is the root or not found.\n */\nfunction spanDepth(root: TraceSpan, targetSpanId: string, depth = 0): number {\n if (root.spanId === targetSpanId) {\n return depth;\n }\n\n for (const child of root.children) {\n const found = spanDepth(child, targetSpanId, depth + 1);\n\n if (found > 0) {\n return found;\n }\n }\n\n return 0;\n}\n"],"mappings":";;;;;;AAMA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BtB,SAAgB,gBAAgB,UAAkC,CAAC,GAAqB;CACtF,MAAM,OAAoB,QAAQ,WAAW;CAC7C,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,KAAK,QAAQ,MAAM;CACzB,MAAM,aAAa,QAAQ;CAE3B,MAAM,WAA6B;EACjC,MAAM;EACN,OAAO,OAAoB;GACzB,WAAW,MAAM,OAAO,MAAM,IAAI,UAAU;EAC9C;CACF;CAEA,IAAI,QAAQ,WACV,SAAS,cAAc,SAA0B;EAC/C,KAAK,IAAI,eAAe,IAAI,CAAC;EAE7B,IAAI,IACF,KAAK,MAAM,QAAQ,aAAa,MAAM,GAAG,UAAU,GACjD,KAAK,IAAI,IAAI;CAGnB;CAGF,OAAO;AACT;;;;;;;AAQA,SAAS,WACP,MACA,OACA,MACA,IACA,YACM;CACN,IAAI,CAAC,MAAM;EACT,UAAU,MAAM,MAAM,MAAM,GAAG,IAAI,UAAU;EAC7C;CACF;CAEA,KAAK,MAAM,QAAQ,UAAU,MAAM,IAAI,GAErC,UAAU,MAAM,MADF,UAAU,MAAM,MAAM,KAAK,MACf,GAAG,IAAI,UAAU;AAE/C;;;;;;AAOA,SAAS,UACP,MACA,MACA,OACA,IACA,YACM;CACN,gBAAgB,MAAM,KAAK,QAAQ,eAAe,MAAM,KAAK,CAAC;CAE9D,IAAI,IACF,KAAK,MAAM,QAAQ,aAAa,MAAM,OAAO,UAAU,GACrD,gBAAgB,MAAM,KAAK,QAAQ,IAAI;AAG7C;;;;;AAMA,SAAS,gBAAgB,MAAmB,QAA6B,MAAoB;CAC3F,IAAI,WAAW,YAAY,WAAW,eAAe,WAAW,cAAc;EAC5E,KAAK,MAAM,IAAI;EACf;CACF;CAEA,KAAK,IAAI,IAAI;AACf;;;;;AAMA,SAAS,UAAU,MAAiB,cAAsB,QAAQ,GAAW;CAC3E,IAAI,KAAK,WAAW,cAClB,OAAO;CAGT,KAAK,MAAM,SAAS,KAAK,UAAU;EACjC,MAAM,QAAQ,UAAU,OAAO,cAAc,QAAQ,CAAC;EAEtD,IAAI,QAAQ,GACV,OAAO;CAEX;CAEA,OAAO;AACT"}
@@ -5,14 +5,14 @@
5
5
  * monkey-patching the global. Only the two levels the exporter uses are
6
6
  * required.
7
7
  */
8
- type ConsoleLike = {
8
+ export type ConsoleLike = {
9
9
  log(...args: unknown[]): void;
10
10
  error(...args: unknown[]): void;
11
11
  };
12
12
  /**
13
13
  * Options for {@link consoleExporter}.
14
14
  */
15
- type ConsoleExporterOptions = {
15
+ export type ConsoleExporterOptions = {
16
16
  /**
17
17
  * Where to write. Defaults to the global `console`. Inject a custom
18
18
  * sink in tests or to redirect to a structured logger.
@@ -47,5 +47,4 @@ type ConsoleExporterOptions = {
47
47
  ioMaxChars?: number;
48
48
  };
49
49
  //#endregion
50
- export { ConsoleExporterOptions, ConsoleLike };
51
50
  //# sourceMappingURL=console-exporter.type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"console-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/console-exporter.type.ts"],"mappings":";;AAMA;;;;;KAAY,WAAA;EACV,GAAA,IAAO,IAAA;EACP,KAAA,IAAS,IAAA;AAAA;AAAI;AAMf;;AANe,KAMH,sBAAA;EAKW;;;;EAArB,OAAA,GAAU,WAAW;EAoBrB;;;AAOU;;EArBV,IAAA;;;;;;EAMA,SAAA;;;;;;;;EAQA,EAAA;;;;;;;EAOA,UAAA;AAAA"}
1
+ {"version":3,"file":"console-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/console-exporter.type.ts"],"mappings":";;;;;;;YAMY;EACV,OAAO;EACP,SAAS;;;;;YAMC;;;;;EAKV,UAAU;;;;;;EAMV;;;;;;EAMA;;;;;;;;EAQA;;;;;;;EAOA"}
@@ -1,4 +1,5 @@
1
1
  import { TraceSpan } from "../../contracts/trace.type.mjs";
2
+ import "../../contracts/index.mjs";
2
3
  //#region ../../packages/ai-panoptic/src/exporters/console/format-span-io.d.ts
3
4
  /**
4
5
  * Render a span's captured content ({@link TraceSpan.input} /
@@ -21,7 +22,6 @@ import { TraceSpan } from "../../contracts/trace.type.mjs";
21
22
  * formatSpanIO(toolSpan, 1);
22
23
  * // [' in: {"query":"specialty coffee demand"}', ' out: {"results":[…]}']
23
24
  */
24
- declare function formatSpanIO(span: TraceSpan, depth?: number, maxChars?: number): string[];
25
+ export declare function formatSpanIO(span: TraceSpan, depth?: number, maxChars?: number): string[];
25
26
  //#endregion
26
- export { formatSpanIO };
27
27
  //# sourceMappingURL=format-span-io.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-span-io.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-io.ts"],"mappings":";;;;;AA0BA;;;;;;;;;AAAwF;;;;;;;;;iBAAxE,YAAA,CAAa,IAAA,EAAM,SAAS,EAAE,KAAA,WAAW,QAAA"}
1
+ {"version":3,"file":"format-span-io.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-io.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;wBA0BgB,aACd,MAAM,WACN,gBACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"format-span-io.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-io.ts"],"sourcesContent":["import type { TraceSpan } from \"../../contracts\";\n\n/** Default cap on how many characters of captured content a console line shows. */\nconst DEFAULT_IO_MAX_CHARS = 500;\n\n/**\n * Render a span's captured content ({@link TraceSpan.input} /\n * {@link TraceSpan.output}) as extra indented console lines, one level\n * below the span's own line:\n *\n * ```text\n * ok agent \"market-research\" — 1794ms, 224 tok, $0.0008\n * in: Research the market for Acme Coffee Roasters …\n * out: Demand is steady; specialty buyers skew premium …\n * ```\n *\n * Returns `[]` when the span carries no content — capture disabled, or a\n * composite node with no own I/O. Each value is stringified (JSON for\n * non-strings), whitespace-collapsed to stay scannable, and truncated to\n * `maxChars` (default {@link DEFAULT_IO_MAX_CHARS}) with an ellipsis. Use\n * the file exporter for the full, untruncated payload.\n *\n * @example\n * formatSpanIO(toolSpan, 1);\n * // [' in: {\"query\":\"specialty coffee demand\"}', ' out: {\"results\":[…]}']\n */\nexport function formatSpanIO(span: TraceSpan, depth = 0, maxChars = DEFAULT_IO_MAX_CHARS): string[] {\n const lines: string[] = [];\n const indent = \" \".repeat(depth + 1);\n\n if (span.input !== undefined) {\n lines.push(`${indent}in: ${preview(span.input, maxChars)}`);\n }\n\n if (span.output !== undefined) {\n lines.push(`${indent}out: ${preview(span.output, maxChars)}`);\n }\n\n return lines;\n}\n\n/**\n * One-line, length-capped preview of a captured value. Strings pass\n * through; everything else is JSON-stringified (falling back to\n * `String()` on a circular / unstringifiable value). Internal whitespace\n * is collapsed so the preview never breaks the tree layout.\n */\nfunction preview(value: unknown, maxChars: number): string {\n const text = typeof value === \"string\" ? value : stringify(value);\n const collapsed = text.replace(/\\s+/g, \" \").trim();\n\n return collapsed.length > maxChars ? `${collapsed.slice(0, maxChars)}…` : collapsed;\n}\n\nfunction stringify(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n"],"mappings":";;AAGA,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;AAuB7B,SAAgB,aAAa,MAAiB,QAAQ,GAAG,WAAW,sBAAgC;CAClG,MAAM,QAAkB,CAAC;CACzB,MAAM,SAAS,KAAK,OAAO,QAAQ,CAAC;CAEpC,IAAI,KAAK,UAAU,QACjB,MAAM,KAAK,GAAG,OAAO,OAAO,QAAQ,KAAK,OAAO,QAAQ,GAAG;CAG7D,IAAI,KAAK,WAAW,QAClB,MAAM,KAAK,GAAG,OAAO,OAAO,QAAQ,KAAK,QAAQ,QAAQ,GAAG;CAG9D,OAAO;AACT;;;;;;;AAQA,SAAS,QAAQ,OAAgB,UAA0B;CAEzD,MAAM,aADO,OAAO,UAAU,WAAW,QAAQ,UAAU,KAAK,EAC1C,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;CAEjD,OAAO,UAAU,SAAS,WAAW,GAAG,UAAU,MAAM,GAAG,QAAQ,EAAE,KAAK;AAC5E;AAEA,SAAS,UAAU,OAAwB;CACzC,IAAI;EACF,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC9C,QAAQ;EACN,OAAO,OAAO,KAAK;CACrB;AACF"}
1
+ {"version":3,"file":"format-span-io.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-io.ts"],"sourcesContent":["import type { TraceSpan } from \"../../contracts\";\n\n/** Default cap on how many characters of captured content a console line shows. */\nconst DEFAULT_IO_MAX_CHARS = 500;\n\n/**\n * Render a span's captured content ({@link TraceSpan.input} /\n * {@link TraceSpan.output}) as extra indented console lines, one level\n * below the span's own line:\n *\n * ```text\n * ok agent \"market-research\" — 1794ms, 224 tok, $0.0008\n * in: Research the market for Acme Coffee Roasters …\n * out: Demand is steady; specialty buyers skew premium …\n * ```\n *\n * Returns `[]` when the span carries no content — capture disabled, or a\n * composite node with no own I/O. Each value is stringified (JSON for\n * non-strings), whitespace-collapsed to stay scannable, and truncated to\n * `maxChars` (default {@link DEFAULT_IO_MAX_CHARS}) with an ellipsis. Use\n * the file exporter for the full, untruncated payload.\n *\n * @example\n * formatSpanIO(toolSpan, 1);\n * // [' in: {\"query\":\"specialty coffee demand\"}', ' out: {\"results\":[…]}']\n */\nexport function formatSpanIO(\n span: TraceSpan,\n depth = 0,\n maxChars = DEFAULT_IO_MAX_CHARS,\n): string[] {\n const lines: string[] = [];\n const indent = \" \".repeat(depth + 1);\n\n if (span.input !== undefined) {\n lines.push(`${indent}in: ${preview(span.input, maxChars)}`);\n }\n\n if (span.output !== undefined) {\n lines.push(`${indent}out: ${preview(span.output, maxChars)}`);\n }\n\n return lines;\n}\n\n/**\n * One-line, length-capped preview of a captured value. Strings pass\n * through; everything else is JSON-stringified (falling back to\n * `String()` on a circular / unstringifiable value). Internal whitespace\n * is collapsed so the preview never breaks the tree layout.\n */\nfunction preview(value: unknown, maxChars: number): string {\n const text = typeof value === \"string\" ? value : stringify(value);\n const collapsed = text.replace(/\\s+/g, \" \").trim();\n\n return collapsed.length > maxChars ? `${collapsed.slice(0, maxChars)}…` : collapsed;\n}\n\nfunction stringify(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n"],"mappings":";;AAGA,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;AAuB7B,SAAgB,aACd,MACA,QAAQ,GACR,WAAW,sBACD;CACV,MAAM,QAAkB,CAAC;CACzB,MAAM,SAAS,KAAK,OAAO,QAAQ,CAAC;CAEpC,IAAI,KAAK,UAAU,QACjB,MAAM,KAAK,GAAG,OAAO,OAAO,QAAQ,KAAK,OAAO,QAAQ,GAAG;CAG7D,IAAI,KAAK,WAAW,QAClB,MAAM,KAAK,GAAG,OAAO,OAAO,QAAQ,KAAK,QAAQ,QAAQ,GAAG;CAG9D,OAAO;AACT;;;;;;;AAQA,SAAS,QAAQ,OAAgB,UAA0B;CAEzD,MAAM,aADO,OAAO,UAAU,WAAW,QAAQ,UAAU,KAAK,EAC1C,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;CAEjD,OAAO,UAAU,SAAS,WAAW,GAAG,UAAU,MAAM,GAAG,QAAQ,EAAE,KAAK;AAC5E;AAEA,SAAS,UAAU,OAAwB;CACzC,IAAI;EACF,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC9C,QAAQ;EACN,OAAO,OAAO,KAAK;CACrB;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { TraceSpan } from "../../contracts/trace.type.mjs";
2
+ import "../../contracts/index.mjs";
2
3
  //#region ../../packages/ai-panoptic/src/exporters/console/format-span-line.d.ts
3
4
  /**
4
5
  * Render a single {@link TraceSpan} as one scannable console line:
@@ -11,7 +12,6 @@ import { TraceSpan } from "../../contracts/trace.type.mjs";
11
12
  * formatSpanLine(span, 1);
12
13
  * // ' ok agent "router" — 1240ms, 470 tok, $0.0021'
13
14
  */
14
- declare function formatSpanLine(span: TraceSpan, depth?: number): string;
15
+ export declare function formatSpanLine(span: TraceSpan, depth?: number): string;
15
16
  //#endregion
16
- export { formatSpanLine };
17
17
  //# sourceMappingURL=format-span-line.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-span-line.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-line.ts"],"mappings":";;;;;AAcA;;;;;;;;iBAAgB,cAAA,CAAe,IAAA,EAAM,SAAS,EAAE,KAAA"}
1
+ {"version":3,"file":"format-span-line.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-line.ts"],"mappings":";;;;;;;;;;;;;;wBAcgB,eAAe,MAAM,WAAW"}
@@ -1,4 +1,5 @@
1
1
  import { totalCostUsd } from "../utils/total-cost.mjs";
2
+ import "../utils/index.mjs";
2
3
 
3
4
  //#region ../../packages/ai-panoptic/src/exporters/console/format-span-line.ts
4
5
  /**
@@ -30,6 +31,7 @@ function statusMarker(status) {
30
31
  case "completed": return "ok";
31
32
  case "failed": return "ERR";
32
33
  case "cancelled": return "cancel";
34
+ case "incomplete": return "INCOMPLETE";
33
35
  case "max-iterations": return "max-iter";
34
36
  case "awaiting-input": return "await";
35
37
  default: return status;
@@ -1 +1 @@
1
- {"version":3,"file":"format-span-line.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-line.ts"],"sourcesContent":["import type { TraceSpan } from \"../../contracts\";\nimport { totalCostUsd } from \"../utils\";\n\n/**\n * Render a single {@link TraceSpan} as one scannable console line:\n * `<status> <type> \"<name>\" — <duration>ms, <tokens> tok[, $<cost>]`.\n * `depth` controls leading indentation when printing a tree. Pure — no\n * side effects — so it is trivially testable and reused by both the\n * per-trace summary and the per-span streaming line.\n *\n * @example\n * formatSpanLine(span, 1);\n * // ' ok agent \"router\" — 1240ms, 470 tok, $0.0021'\n */\nexport function formatSpanLine(span: TraceSpan, depth = 0): string {\n const indent = \" \".repeat(depth);\n const marker = statusMarker(span.status);\n const cost = totalCostUsd(span.usage);\n const costSuffix = cost === undefined ? \"\" : `, $${cost.toFixed(4)}`;\n\n let line = `${indent}${marker} ${span.type} \"${span.name}\" — ${span.duration}ms, ${span.usage.total} tok${costSuffix}`;\n\n if (span.error) {\n line += ` [${span.error.type}: ${span.error.message}]`;\n }\n\n return line;\n}\n\n/**\n * Short ASCII marker for a span's terminal status. Plain ASCII (no\n * emoji/color codes) so output stays clean in log aggregators and CI.\n */\nfunction statusMarker(status: TraceSpan[\"status\"]): string {\n switch (status) {\n case \"completed\":\n return \"ok\";\n case \"failed\":\n return \"ERR\";\n case \"cancelled\":\n return \"cancel\";\n case \"max-iterations\":\n return \"max-iter\";\n case \"awaiting-input\":\n return \"await\";\n default:\n return status;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,eAAe,MAAiB,QAAQ,GAAW;CACjE,MAAM,SAAS,KAAK,OAAO,KAAK;CAChC,MAAM,SAAS,aAAa,KAAK,MAAM;CACvC,MAAM,OAAO,aAAa,KAAK,KAAK;CACpC,MAAM,aAAa,SAAS,SAAY,KAAK,MAAM,KAAK,QAAQ,CAAC;CAEjE,IAAI,OAAO,GAAG,SAAS,OAAO,GAAG,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM,KAAK,SAAS,MAAM,KAAK,MAAM,MAAM,MAAM;CAE1G,IAAI,KAAK,OACP,QAAQ,KAAK,KAAK,MAAM,KAAK,IAAI,KAAK,MAAM,QAAQ;CAGtD,OAAO;AACT;;;;;AAMA,SAAS,aAAa,QAAqC;CACzD,QAAQ,QAAR;EACE,KAAK,aACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,kBACH,OAAO;EACT,KAAK,kBACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
1
+ {"version":3,"file":"format-span-line.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/console/format-span-line.ts"],"sourcesContent":["import type { TraceSpan } from \"../../contracts\";\nimport { totalCostUsd } from \"../utils\";\n\n/**\n * Render a single {@link TraceSpan} as one scannable console line:\n * `<status> <type> \"<name>\" — <duration>ms, <tokens> tok[, $<cost>]`.\n * `depth` controls leading indentation when printing a tree. Pure — no\n * side effects — so it is trivially testable and reused by both the\n * per-trace summary and the per-span streaming line.\n *\n * @example\n * formatSpanLine(span, 1);\n * // ' ok agent \"router\" — 1240ms, 470 tok, $0.0021'\n */\nexport function formatSpanLine(span: TraceSpan, depth = 0): string {\n const indent = \" \".repeat(depth);\n const marker = statusMarker(span.status);\n const cost = totalCostUsd(span.usage);\n const costSuffix = cost === undefined ? \"\" : `, $${cost.toFixed(4)}`;\n\n let line = `${indent}${marker} ${span.type} \"${span.name}\" — ${span.duration}ms, ${span.usage.total} tok${costSuffix}`;\n\n if (span.error) {\n line += ` [${span.error.type}: ${span.error.message}]`;\n }\n\n return line;\n}\n\n/**\n * Short ASCII marker for a span's terminal status. Plain ASCII (no\n * emoji/color codes) so output stays clean in log aggregators and CI.\n */\nfunction statusMarker(status: TraceSpan[\"status\"]): string {\n switch (status) {\n case \"completed\":\n return \"ok\";\n case \"failed\":\n return \"ERR\";\n case \"cancelled\":\n return \"cancel\";\n case \"incomplete\":\n return \"INCOMPLETE\";\n case \"max-iterations\":\n return \"max-iter\";\n case \"awaiting-input\":\n return \"await\";\n default:\n return status;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,eAAe,MAAiB,QAAQ,GAAW;CACjE,MAAM,SAAS,KAAK,OAAO,KAAK;CAChC,MAAM,SAAS,aAAa,KAAK,MAAM;CACvC,MAAM,OAAO,aAAa,KAAK,KAAK;CACpC,MAAM,aAAa,SAAS,SAAY,KAAK,MAAM,KAAK,QAAQ,CAAC;CAEjE,IAAI,OAAO,GAAG,SAAS,OAAO,GAAG,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM,KAAK,SAAS,MAAM,KAAK,MAAM,MAAM,MAAM;CAE1G,IAAI,KAAK,OACP,QAAQ,KAAK,KAAK,MAAM,KAAK,IAAI,KAAK,MAAM,QAAQ;CAGtD,OAAO;AACT;;;;;AAMA,SAAS,aAAa,QAAqC;CACzD,QAAQ,QAAR;EACE,KAAK,aACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,KAAK,kBACH,OAAO;EACT,KAAK,kBACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { ConsoleExporterOptions, ConsoleLike } from "./console-exporter.type.mjs";
2
2
  import { consoleExporter } from "./console-exporter.mjs";
3
3
  import { formatSpanLine } from "./format-span-line.mjs";
4
- import { formatSpanIO } from "./format-span-io.mjs";
4
+ import { formatSpanIO } from "./format-span-io.mjs";
5
+ export { type ConsoleExporterOptions, type ConsoleLike, consoleExporter, formatSpanIO, formatSpanLine };
@@ -0,0 +1,5 @@
1
+ import { formatSpanIO } from "./format-span-io.mjs";
2
+ import { formatSpanLine } from "./format-span-line.mjs";
3
+ import { consoleExporter } from "./console-exporter.mjs";
4
+
5
+ export { consoleExporter, formatSpanIO, formatSpanLine };
@@ -1,6 +1,6 @@
1
1
  import { ExporterContract } from "../../contracts/exporter.contract.mjs";
2
+ import "../../contracts/index.mjs";
2
3
  import { FileExporterOptions } from "./file-exporter.type.mjs";
3
-
4
4
  //#region ../../packages/ai-panoptic/src/exporters/file/file-exporter.d.ts
5
5
  /**
6
6
  * Zero-dependency {@link ExporterContract} that appends completed traces
@@ -17,7 +17,6 @@ import { FileExporterOptions } from "./file-exporter.type.mjs";
17
17
  * // on shutdown:
18
18
  * await collector.shutdown(); // drains the buffer
19
19
  */
20
- declare function fileExporter(options: FileExporterOptions): ExporterContract;
20
+ export declare function fileExporter(options: FileExporterOptions): ExporterContract;
21
21
  //#endregion
22
- export { fileExporter };
23
22
  //# sourceMappingURL=file-exporter.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/file/file-exporter.ts"],"mappings":";;;;;;;AAsBA;;;;;;;;AAA4E;;;;iBAA5D,YAAA,CAAa,OAAA,EAAS,mBAAA,GAAsB,gBAAgB"}
1
+ {"version":3,"file":"file-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/file/file-exporter.ts"],"mappings":";;;;;;;;;;;;;;;;;;;wBAsBgB,aAAa,SAAS,sBAAsB"}
@@ -1 +1 @@
1
- {"version":3,"file":"file-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/file/file-exporter.ts"],"sourcesContent":["import { appendFile, mkdir } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { ExporterContract, Trace } from \"../../contracts\";\nimport type { FileExporterOptions, TraceRecord } from \"./file-exporter.type\";\n\nconst EXPORTER_NAME = \"file\";\n\n/**\n * Zero-dependency {@link ExporterContract} that appends completed traces\n * to a JSON-Lines file (one JSON record per line by default). Buffers in\n * memory and flushes either every `flushEvery` traces or on an explicit\n * `flush()` / `shutdown()`, so a batch of traces costs one append.\n *\n * Useful as a durable local sink (replay traces later, ship the file to\n * a backend out of band) and as a test fixture for the pipeline without\n * a vendor SDK.\n *\n * @example\n * collector.use(fileExporter({ path: \"storage/traces.jsonl\" }));\n * // on shutdown:\n * await collector.shutdown(); // drains the buffer\n */\nexport function fileExporter(options: FileExporterOptions): ExporterContract {\n const writer = new FileTraceWriter(options);\n\n return {\n name: EXPORTER_NAME,\n async export(trace: Trace): Promise<void> {\n await writer.add(trace);\n },\n async flush(): Promise<void> {\n await writer.flush();\n },\n async shutdown(): Promise<void> {\n await writer.flush();\n },\n };\n}\n\n/**\n * Internal buffered writer for {@link fileExporter}. Owns the pending\n * trace buffer and the directory-created guard across the exporter's\n * lifetime; kept unexported so callers only ever see the factory.\n */\nclass FileTraceWriter {\n private readonly path: string;\n private readonly flushEvery: number;\n private readonly pretty: boolean;\n private buffer: TraceRecord[] = [];\n private directoryReady = false;\n\n public constructor(options: FileExporterOptions) {\n this.path = options.path;\n this.flushEvery = Math.max(1, options.flushEvery ?? 1);\n this.pretty = options.pretty ?? false;\n }\n\n /**\n * Buffer one trace and flush when the buffer reaches `flushEvery`.\n */\n public async add(trace: Trace): Promise<void> {\n this.buffer.push({\n type: \"trace\",\n exportedAt: new Date().toISOString(),\n trace,\n });\n\n if (this.buffer.length >= this.flushEvery) {\n await this.flush();\n }\n }\n\n /**\n * Serialize and append every buffered record, then clear the buffer.\n * No-op when nothing is pending so callers can flush defensively.\n */\n public async flush(): Promise<void> {\n if (this.buffer.length === 0) {\n return;\n }\n\n const pending = this.buffer;\n this.buffer = [];\n\n await this.ensureDirectory();\n\n const payload = pending.map((record) => this.serialize(record)).join(\"\");\n\n await appendFile(this.path, payload, \"utf8\");\n }\n\n /**\n * Create the parent directory once, lazily, on the first write. Stores\n * a guard so subsequent flushes skip the syscall.\n */\n private async ensureDirectory(): Promise<void> {\n if (this.directoryReady) {\n return;\n }\n\n await mkdir(dirname(this.path), { recursive: true });\n this.directoryReady = true;\n }\n\n /**\n * Render one record as a newline-terminated JSON string. Pretty mode\n * indents for human reading; compact mode keeps the file valid JSON\n * Lines (exactly one record per physical line).\n */\n private serialize(record: TraceRecord): string {\n const json = this.pretty\n ? JSON.stringify(record, undefined, 2)\n : JSON.stringify(record);\n\n return `${json}\\n`;\n }\n}\n"],"mappings":";;;;AAKA,MAAM,gBAAgB;;;;;;;;;;;;;;;;AAiBtB,SAAgB,aAAa,SAAgD;CAC3E,MAAM,SAAS,IAAI,gBAAgB,OAAO;CAE1C,OAAO;EACL,MAAM;EACN,MAAM,OAAO,OAA6B;GACxC,MAAM,OAAO,IAAI,KAAK;EACxB;EACA,MAAM,QAAuB;GAC3B,MAAM,OAAO,MAAM;EACrB;EACA,MAAM,WAA0B;GAC9B,MAAM,OAAO,MAAM;EACrB;CACF;AACF;;;;;;AAOA,IAAM,kBAAN,MAAsB;CACpB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ,SAAwB,CAAC;CACjC,AAAQ,iBAAiB;CAEzB,AAAO,YAAY,SAA8B;EAC/C,KAAK,OAAO,QAAQ;EACpB,KAAK,aAAa,KAAK,IAAI,GAAG,QAAQ,cAAc,CAAC;EACrD,KAAK,SAAS,QAAQ,UAAU;CAClC;;;;CAKA,MAAa,IAAI,OAA6B;EAC5C,KAAK,OAAO,KAAK;GACf,MAAM;GACN,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;GACnC;EACF,CAAC;EAED,IAAI,KAAK,OAAO,UAAU,KAAK,YAC7B,MAAM,KAAK,MAAM;CAErB;;;;;CAMA,MAAa,QAAuB;EAClC,IAAI,KAAK,OAAO,WAAW,GACzB;EAGF,MAAM,UAAU,KAAK;EACrB,KAAK,SAAS,CAAC;EAEf,MAAM,KAAK,gBAAgB;EAE3B,MAAM,UAAU,QAAQ,KAAK,WAAW,KAAK,UAAU,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE;EAEvE,MAAM,WAAW,KAAK,MAAM,SAAS,MAAM;CAC7C;;;;;CAMA,MAAc,kBAAiC;EAC7C,IAAI,KAAK,gBACP;EAGF,MAAM,MAAM,QAAQ,KAAK,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;EACnD,KAAK,iBAAiB;CACxB;;;;;;CAOA,AAAQ,UAAU,QAA6B;EAK7C,OAAO,GAJM,KAAK,SACd,KAAK,UAAU,QAAQ,QAAW,CAAC,IACnC,KAAK,UAAU,MAAM,EAEV;CACjB;AACF"}
1
+ {"version":3,"file":"file-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/file/file-exporter.ts"],"sourcesContent":["import { appendFile, mkdir } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { ExporterContract, Trace } from \"../../contracts\";\nimport type { FileExporterOptions, TraceRecord } from \"./file-exporter.type\";\n\nconst EXPORTER_NAME = \"file\";\n\n/**\n * Zero-dependency {@link ExporterContract} that appends completed traces\n * to a JSON-Lines file (one JSON record per line by default). Buffers in\n * memory and flushes either every `flushEvery` traces or on an explicit\n * `flush()` / `shutdown()`, so a batch of traces costs one append.\n *\n * Useful as a durable local sink (replay traces later, ship the file to\n * a backend out of band) and as a test fixture for the pipeline without\n * a vendor SDK.\n *\n * @example\n * collector.use(fileExporter({ path: \"storage/traces.jsonl\" }));\n * // on shutdown:\n * await collector.shutdown(); // drains the buffer\n */\nexport function fileExporter(options: FileExporterOptions): ExporterContract {\n const writer = new FileTraceWriter(options);\n\n return {\n name: EXPORTER_NAME,\n async export(trace: Trace): Promise<void> {\n await writer.add(trace);\n },\n async flush(): Promise<void> {\n await writer.flush();\n },\n async shutdown(): Promise<void> {\n await writer.flush();\n },\n };\n}\n\n/**\n * Internal buffered writer for {@link fileExporter}. Owns the pending\n * trace buffer and the directory-created guard across the exporter's\n * lifetime; kept unexported so callers only ever see the factory.\n */\nclass FileTraceWriter {\n private readonly path: string;\n private readonly flushEvery: number;\n private readonly pretty: boolean;\n private buffer: TraceRecord[] = [];\n private directoryReady = false;\n\n public constructor(options: FileExporterOptions) {\n this.path = options.path;\n this.flushEvery = Math.max(1, options.flushEvery ?? 1);\n this.pretty = options.pretty ?? false;\n }\n\n /**\n * Buffer one trace and flush when the buffer reaches `flushEvery`.\n */\n public async add(trace: Trace): Promise<void> {\n this.buffer.push({\n type: \"trace\",\n exportedAt: new Date().toISOString(),\n trace,\n });\n\n if (this.buffer.length >= this.flushEvery) {\n await this.flush();\n }\n }\n\n /**\n * Serialize and append every buffered record, then clear the buffer.\n * No-op when nothing is pending so callers can flush defensively.\n */\n public async flush(): Promise<void> {\n if (this.buffer.length === 0) {\n return;\n }\n\n const pending = this.buffer;\n this.buffer = [];\n\n await this.ensureDirectory();\n\n const payload = pending.map((record) => this.serialize(record)).join(\"\");\n\n await appendFile(this.path, payload, \"utf8\");\n }\n\n /**\n * Create the parent directory once, lazily, on the first write. Stores\n * a guard so subsequent flushes skip the syscall.\n */\n private async ensureDirectory(): Promise<void> {\n if (this.directoryReady) {\n return;\n }\n\n await mkdir(dirname(this.path), { recursive: true });\n this.directoryReady = true;\n }\n\n /**\n * Render one record as a newline-terminated JSON string. Pretty mode\n * indents for human reading; compact mode keeps the file valid JSON\n * Lines (exactly one record per physical line).\n */\n private serialize(record: TraceRecord): string {\n const json = this.pretty ? JSON.stringify(record, undefined, 2) : JSON.stringify(record);\n\n return `${json}\\n`;\n }\n}\n"],"mappings":";;;;AAKA,MAAM,gBAAgB;;;;;;;;;;;;;;;;AAiBtB,SAAgB,aAAa,SAAgD;CAC3E,MAAM,SAAS,IAAI,gBAAgB,OAAO;CAE1C,OAAO;EACL,MAAM;EACN,MAAM,OAAO,OAA6B;GACxC,MAAM,OAAO,IAAI,KAAK;EACxB;EACA,MAAM,QAAuB;GAC3B,MAAM,OAAO,MAAM;EACrB;EACA,MAAM,WAA0B;GAC9B,MAAM,OAAO,MAAM;EACrB;CACF;AACF;;;;;;AAOA,IAAM,kBAAN,MAAsB;CACpB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ,SAAwB,CAAC;CACjC,AAAQ,iBAAiB;CAEzB,AAAO,YAAY,SAA8B;EAC/C,KAAK,OAAO,QAAQ;EACpB,KAAK,aAAa,KAAK,IAAI,GAAG,QAAQ,cAAc,CAAC;EACrD,KAAK,SAAS,QAAQ,UAAU;CAClC;;;;CAKA,MAAa,IAAI,OAA6B;EAC5C,KAAK,OAAO,KAAK;GACf,MAAM;GACN,6BAAY,IAAI,KAAK,EAAC,CAAC,YAAY;GACnC;EACF,CAAC;EAED,IAAI,KAAK,OAAO,UAAU,KAAK,YAC7B,MAAM,KAAK,MAAM;CAErB;;;;;CAMA,MAAa,QAAuB;EAClC,IAAI,KAAK,OAAO,WAAW,GACzB;EAGF,MAAM,UAAU,KAAK;EACrB,KAAK,SAAS,CAAC;EAEf,MAAM,KAAK,gBAAgB;EAE3B,MAAM,UAAU,QAAQ,KAAK,WAAW,KAAK,UAAU,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE;EAEvE,MAAM,WAAW,KAAK,MAAM,SAAS,MAAM;CAC7C;;;;;CAMA,MAAc,kBAAiC;EAC7C,IAAI,KAAK,gBACP;EAGF,MAAM,MAAM,QAAQ,KAAK,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;EACnD,KAAK,iBAAiB;CACxB;;;;;;CAOA,AAAQ,UAAU,QAA6B;EAG7C,OAAO,GAFM,KAAK,SAAS,KAAK,UAAU,QAAQ,QAAW,CAAC,IAAI,KAAK,UAAU,MAAM,EAExE;CACjB;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { Trace } from "../../contracts/trace.type.mjs";
2
+ import "../../contracts/index.mjs";
2
3
  //#region ../../packages/ai-panoptic/src/exporters/file/file-exporter.type.d.ts
3
4
  /**
4
5
  * One JSON-Lines record the {@link fileExporter} appends per trace. A
@@ -6,15 +7,18 @@ import { Trace } from "../../contracts/trace.type.mjs";
6
7
  * the time the line was written, so a downstream reader can tell records
7
8
  * apart and order them without re-deriving anything from the payload.
8
9
  */
9
- type TraceRecord = {
10
- /** Discriminator for the record format — always `"trace"` today. */type: "trace"; /** ISO-8601 timestamp the exporter wrote this record. */
11
- exportedAt: string; /** The completed trace, verbatim. */
10
+ export type TraceRecord = {
11
+ /** Discriminator for the record format — always `"trace"` today. */
12
+ type: "trace";
13
+ /** ISO-8601 timestamp the exporter wrote this record. */
14
+ exportedAt: string;
15
+ /** The completed trace, verbatim. */
12
16
  trace: Trace;
13
17
  };
14
18
  /**
15
19
  * Options for {@link fileExporter}.
16
20
  */
17
- type FileExporterOptions = {
21
+ export type FileExporterOptions = {
18
22
  /**
19
23
  * Absolute or cwd-relative path of the JSON-Lines file traces are
20
24
  * appended to. The parent directory is created on first write if
@@ -35,5 +39,4 @@ type FileExporterOptions = {
35
39
  pretty?: boolean;
36
40
  };
37
41
  //#endregion
38
- export { FileExporterOptions, TraceRecord };
39
42
  //# sourceMappingURL=file-exporter.type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/file/file-exporter.type.ts"],"mappings":";;;;;AAQA;;;KAAY,WAAA;EAEV,oEAAA,IAAA,WAIA;EAFA,UAAA,UAEY;EAAZ,KAAA,EAAO,KAAK;AAAA;;;;KAMF,mBAAA;EAYV;;;AAMM;;EAZN,IAAA;;;;;;EAMA,UAAA;;;;;;EAMA,MAAA;AAAA"}
1
+ {"version":3,"file":"file-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/file/file-exporter.type.ts"],"mappings":";;;;;;;;;YAQY;;EAEV;;EAEA;;EAEA,OAAO;;;;;YAMG;;;;;;EAMV;;;;;;EAMA;;;;;;EAMA"}
@@ -1,2 +1,3 @@
1
1
  import { FileExporterOptions, TraceRecord } from "./file-exporter.type.mjs";
2
- import { fileExporter } from "./file-exporter.mjs";
2
+ import { fileExporter } from "./file-exporter.mjs";
3
+ export { type FileExporterOptions, type TraceRecord, fileExporter };
@@ -2,12 +2,18 @@ import { ConsoleExporterOptions, ConsoleLike } from "./console/console-exporter.
2
2
  import { consoleExporter } from "./console/console-exporter.mjs";
3
3
  import { formatSpanLine } from "./console/format-span-line.mjs";
4
4
  import { formatSpanIO } from "./console/format-span-io.mjs";
5
+ import "./console/index.mjs";
5
6
  import { FileExporterOptions, TraceRecord } from "./file/file-exporter.type.mjs";
6
7
  import { fileExporter } from "./file/file-exporter.mjs";
8
+ import "./file/index.mjs";
7
9
  import { LangfuseClientLike, LangfuseExporterOptions, LangfuseObservationBody, LangfuseObservationEndBody, LangfuseObservationLevel, LangfuseObservationLike, LangfuseTraceBody, LangfuseTraceLike, LangfuseUsageBody } from "./langfuse/langfuse-exporter.type.mjs";
8
10
  import { langfuseExporter } from "./langfuse/langfuse-exporter.mjs";
11
+ import "./langfuse/index.mjs";
9
12
  import { OtelExporterOptions } from "./otel/otel-exporter.type.mjs";
10
13
  import { otelExporter } from "./otel/otel-exporter.mjs";
14
+ import "./otel/index.mjs";
11
15
  import { AttributeValue, GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes } from "./utils/gen-ai-attributes.mjs";
12
16
  import { totalCostUsd } from "./utils/total-cost.mjs";
13
- import { walkSpans } from "./utils/walk-spans.mjs";
17
+ import { walkSpans } from "./utils/walk-spans.mjs";
18
+ import "./utils/index.mjs";
19
+ export { type AttributeValue, type ConsoleExporterOptions, type ConsoleLike, type FileExporterOptions, GEN_AI_ATTRIBUTES, type LangfuseClientLike, type LangfuseExporterOptions, type LangfuseObservationBody, type LangfuseObservationEndBody, type LangfuseObservationLevel, type LangfuseObservationLike, type LangfuseTraceBody, type LangfuseTraceLike, type LangfuseUsageBody, type OtelExporterOptions, type TraceRecord, WARLOCK_ATTRIBUTES, consoleExporter, fileExporter, formatSpanIO, formatSpanLine, langfuseExporter, otelExporter, toGenAiAttributes, totalCostUsd, walkSpans };
@@ -1,13 +1,15 @@
1
1
  import { walkSpans } from "./utils/walk-spans.mjs";
2
2
  import { totalCostUsd } from "./utils/total-cost.mjs";
3
3
  import { GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes } from "./utils/gen-ai-attributes.mjs";
4
+ import "./utils/index.mjs";
4
5
  import { formatSpanIO } from "./console/format-span-io.mjs";
5
6
  import { formatSpanLine } from "./console/format-span-line.mjs";
6
7
  import { consoleExporter } from "./console/console-exporter.mjs";
8
+ import "./console/index.mjs";
7
9
  import { fileExporter } from "./file/file-exporter.mjs";
8
10
  import { langfuseExporter } from "./langfuse/langfuse-exporter.mjs";
9
11
  import "./langfuse/index.mjs";
10
12
  import { otelExporter } from "./otel/otel-exporter.mjs";
11
13
  import "./otel/index.mjs";
12
14
 
13
- export { };
15
+ export { GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, consoleExporter, fileExporter, formatSpanIO, formatSpanLine, langfuseExporter, otelExporter, toGenAiAttributes, totalCostUsd, walkSpans };
@@ -1,2 +1,3 @@
1
1
  import { LangfuseClientLike, LangfuseExporterOptions, LangfuseObservationBody, LangfuseObservationEndBody, LangfuseObservationLevel, LangfuseObservationLike, LangfuseTraceBody, LangfuseTraceLike, LangfuseUsageBody } from "./langfuse-exporter.type.mjs";
2
- import { langfuseExporter } from "./langfuse-exporter.mjs";
2
+ import { langfuseExporter } from "./langfuse-exporter.mjs";
3
+ export { type LangfuseClientLike, type LangfuseExporterOptions, type LangfuseObservationBody, type LangfuseObservationEndBody, type LangfuseObservationLevel, type LangfuseObservationLike, type LangfuseTraceBody, type LangfuseTraceLike, type LangfuseUsageBody, langfuseExporter };
@@ -1,3 +1,3 @@
1
1
  import { langfuseExporter } from "./langfuse-exporter.mjs";
2
2
 
3
- export { };
3
+ export { langfuseExporter };
@@ -1,6 +1,6 @@
1
1
  import { ExporterContract } from "../../contracts/exporter.contract.mjs";
2
+ import "../../contracts/index.mjs";
2
3
  import { LangfuseExporterOptions } from "./langfuse-exporter.type.mjs";
3
-
4
4
  //#region ../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.d.ts
5
5
  /**
6
6
  * {@link ExporterContract} that maps Panoptic traces onto Langfuse
@@ -25,7 +25,6 @@ import { LangfuseExporterOptions } from "./langfuse-exporter.type.mjs";
25
25
  * // or reuse an existing client:
26
26
  * collector.use(langfuseExporter({ client: myLangfuse }));
27
27
  */
28
- declare function langfuseExporter(options: LangfuseExporterOptions): ExporterContract;
28
+ export declare function langfuseExporter(options: LangfuseExporterOptions): ExporterContract;
29
29
  //#endregion
30
- export { langfuseExporter };
31
30
  //# sourceMappingURL=langfuse-exporter.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"langfuse-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.ts"],"mappings":";;;;;;;AAqFA;;;;;;;;AAAoF;;;;;;;;;;;;iBAApE,gBAAA,CAAiB,OAAA,EAAS,uBAAA,GAA0B,gBAAgB"}
1
+ {"version":3,"file":"langfuse-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqFgB,iBAAiB,SAAS,0BAA0B"}
@@ -1,4 +1,5 @@
1
1
  import { GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes } from "../utils/gen-ai-attributes.mjs";
2
+ import "../utils/index.mjs";
2
3
 
3
4
  //#region ../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.ts
4
5
  const EXPORTER_NAME = "langfuse";
@@ -174,7 +175,7 @@ function ownUsage(span) {
174
175
  * rolled-up subtree totals next to an own-usage `usage` block. Cost is
175
176
  * omitted for the same reason; Langfuse prices the own tokens itself.
176
177
  */
177
- const LANGFUSE_METADATA_OMIT = new Set([
178
+ const LANGFUSE_METADATA_OMIT = /* @__PURE__ */ new Set([
178
179
  GEN_AI_ATTRIBUTES.usageInputTokens,
179
180
  GEN_AI_ATTRIBUTES.usageOutputTokens,
180
181
  WARLOCK_ATTRIBUTES.totalTokens,
@@ -196,10 +197,10 @@ function langfuseMetadata(span) {
196
197
  }
197
198
  /**
198
199
  * Map the Panoptic span status onto a Langfuse observation level —
199
- * failed/cancelled spans surface as `ERROR`, everything else `DEFAULT`.
200
+ * failed/cancelled/incomplete spans surface as `ERROR`, everything else `DEFAULT`.
200
201
  */
201
202
  function toLevel(span) {
202
- if (span.status === "failed" || span.status === "cancelled") return "ERROR";
203
+ if (span.status === "failed" || span.status === "cancelled" || span.status === "incomplete") return "ERROR";
203
204
  return "DEFAULT";
204
205
  }
205
206
 
@@ -1 +1 @@
1
- {"version":3,"file":"langfuse-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.ts"],"sourcesContent":["import type { ExporterContract, Trace, TraceSpan } from \"../../contracts\";\nimport type { AttributeValue } from \"../utils\";\nimport { GEN_AI_ATTRIBUTES, toGenAiAttributes, WARLOCK_ATTRIBUTES } from \"../utils\";\nimport type {\n LangfuseClientLike,\n LangfuseExporterOptions,\n LangfuseObservationBody,\n LangfuseObservationLevel,\n LangfuseObservationLike,\n LangfuseTraceBody,\n LangfuseTraceLike,\n} from \"./langfuse-exporter.type\";\n\nconst EXPORTER_NAME = \"langfuse\";\n\n// ============================================================\n// Lazily-loaded langfuse SDK (OPTIONAL peer)\n// ============================================================\n\nlet LangfuseSdk: typeof import(\"langfuse\");\nlet isModuleExists: boolean | null = null;\nlet loadingPromise: Promise<void> | undefined;\n\nconst LANGFUSE_INSTALL_INSTRUCTIONS = `\nThe Panoptic Langfuse exporter requires the langfuse package.\nInstall it with:\n\n npm install langfuse\n\nOr with your preferred package manager:\n\n pnpm add langfuse\n yarn add langfuse\n`.trim();\n\n/**\n * Settle the lazy import of `langfuse` once, concurrency-safe. Only\n * needed when the caller did not pass a ready `client`. A bare `catch`\n * flips the flag to `false`; the curated install string surfaces at use\n * time, never a raw module-resolution stack trace.\n */\nfunction loadLangfuse(): Promise<void> {\n if (isModuleExists !== null) {\n return Promise.resolve();\n }\n\n if (loadingPromise) {\n return loadingPromise;\n }\n\n loadingPromise = (async () => {\n try {\n LangfuseSdk = await import(\"langfuse\");\n isModuleExists = true;\n } catch {\n isModuleExists = false;\n }\n })();\n\n return loadingPromise;\n}\n\n/**\n * {@link ExporterContract} that maps Panoptic traces onto Langfuse\n * traces and observations. Lazily imports `langfuse` so it stays an\n * OPTIONAL peer — importing this module never forces the SDK to be\n * installed, and a missing SDK surfaces as a curated \"install this\"\n * error when the exporter first needs to build a client.\n *\n * The root {@link TraceSpan} becomes a Langfuse trace AND its top\n * observation (so the root execution's own tokens are metered, not just\n * its children's); every node is an observation — a `generation` when it\n * metered its OWN tokens (LLM-backed agents, supervisors), otherwise a\n * plain `span` (tools, callbacks, and composite nodes whose tokens came\n * only from children). Timing, status, and version map 1:1; each\n * generation reports its own token usage (rolled-up minus children) so\n * the trace total isn't double-counted; non-usage GenAI attributes ride\n * along as metadata, and captured content (under `captureContent`)\n * surfaces as native `input` / `output`.\n *\n * @example\n * collector.use(langfuseExporter({ publicKey: \"pk-...\", secretKey: \"sk-...\" }));\n * // or reuse an existing client:\n * collector.use(langfuseExporter({ client: myLangfuse }));\n */\nexport function langfuseExporter(options: LangfuseExporterOptions): ExporterContract {\n let client: LangfuseClientLike | undefined = options.client;\n\n if (!client) {\n loadLangfuse();\n }\n\n const resolveClient = async (): Promise<LangfuseClientLike> => {\n if (client) {\n return client;\n }\n\n await loadLangfuse();\n\n if (!isModuleExists) {\n throw new Error(LANGFUSE_INSTALL_INSTRUCTIONS);\n }\n\n client = new LangfuseSdk.Langfuse({\n publicKey: options.publicKey,\n secretKey: options.secretKey,\n baseUrl: options.baseUrl,\n }) as unknown as LangfuseClientLike;\n\n return client;\n };\n\n return {\n name: EXPORTER_NAME,\n async export(trace: Trace): Promise<void> {\n const activeClient = await resolveClient();\n emitTrace(activeClient, trace);\n },\n async flush(): Promise<void> {\n if (!client) {\n return;\n }\n\n await client.flushAsync();\n },\n async shutdown(): Promise<void> {\n if (!client) {\n return;\n }\n\n await client.shutdownAsync();\n },\n };\n}\n\n/**\n * Create the Langfuse trace from the root span, then recurse the\n * children into nested observations.\n */\nfunction emitTrace(client: LangfuseClientLike, trace: Trace): void {\n const root = trace.root;\n\n const traceBody: LangfuseTraceBody = {\n id: root.traceId,\n name: root.name,\n sessionId: trace.sessionId,\n version: root.version,\n timestamp: new Date(root.startedAt),\n metadata: langfuseMetadata(root),\n };\n\n // Surface the root's captured content at the TRACE level too — not only on\n // the root observation — so Langfuse's trace Preview shows the top-level\n // input/output instead of \"this trace received no input/output\". Present\n // only under content capture, and only for roots that carry I/O (an agent\n // or tool; a composite root like a planner has none of its own).\n if (root.input !== undefined) {\n traceBody.input = root.input;\n }\n\n if (root.output !== undefined) {\n traceBody.output = root.output;\n }\n\n const langfuseTrace = client.trace(traceBody);\n\n // Emit the ROOT as an observation too — not just its children — so the\n // root execution's OWN tokens are metered. Langfuse derives the trace\n // total by summing observation usage; leaving the root (often the single\n // top-level agent) as trace-only would drop its own spend. Children nest\n // under the root observation, mirroring the execution tree, and own-usage\n // metering telescopes the per-node sums back to the true trace total.\n emitObservation(langfuseTrace, root);\n}\n\n/**\n * Map one {@link TraceSpan} onto a Langfuse observation under `parent`,\n * then recurse its children. Spans that metered their OWN tokens become\n * `generation`s; everything else (tools, callbacks, composite nodes)\n * becomes a plain `span`.\n */\nfunction emitObservation(\n parent: LangfuseTraceLike | LangfuseObservationLike,\n span: TraceSpan,\n): void {\n const body: LangfuseObservationBody = {\n id: span.spanId,\n name: span.name,\n startTime: new Date(span.startedAt),\n endTime: new Date(span.endedAt),\n level: toLevel(span),\n statusMessage: span.error?.message,\n version: span.version,\n metadata: langfuseMetadata(span),\n };\n\n // Captured content (only present under `captureContent`) maps onto\n // Langfuse's native observation input/output.\n if (span.input !== undefined) {\n body.input = span.input;\n }\n\n if (span.output !== undefined) {\n body.output = span.output;\n }\n\n let observation: LangfuseObservationLike;\n\n // Classify + meter on OWN tokens (this node's rolled-up usage minus its\n // children's), not the subtree rollup. A composite node whose tokens\n // came only from descendants has zero own-usage and becomes a plain\n // span — so its children's tokens aren't counted twice in the trace\n // total Langfuse sums across observations.\n const own = ownUsage(span);\n\n if (own.total > 0) {\n body.usage = {\n input: own.input,\n output: own.output,\n total: own.total,\n unit: \"TOKENS\",\n };\n observation = parent.generation(body);\n } else {\n observation = parent.span(body);\n }\n\n for (const child of span.children) {\n emitObservation(observation, child);\n }\n\n // Explicitly end the observation. The body already carries `endTime`,\n // so this is idempotent — but the SDK only finalizes (and flushes) an\n // observation on `end()`, so without it long-lived clients can leave\n // observations open. Safe against the local `LangfuseObservationLike`\n // shape, which declares `end(body?)`.\n observation.end({ endTime: body.endTime });\n}\n\n/**\n * Own token usage for a span — its rolled-up {@link TraceSpan.usage}\n * minus the rolled-up usage of its direct children. `TraceSpan.usage` is\n * the subtree total (this node plus every descendant), so subtracting the\n * children leaves the tokens THIS node alone metered, clamped at zero\n * defensively.\n *\n * Langfuse sums observation usage into the trace total, so reporting\n * own-usage on each generation (rather than the subtree rollup) is what\n * keeps the trace total correct instead of multiply-counting nested\n * spans. A composite node with no own tokens (e.g. a workflow whose\n * tokens all came from agent children) yields `total: 0` and is emitted\n * as a plain span, not a generation.\n */\nfunction ownUsage(span: TraceSpan): { input: number; output: number; total: number } {\n let childInput = 0;\n let childOutput = 0;\n let childTotal = 0;\n\n for (const child of span.children) {\n childInput += child.usage.input;\n childOutput += child.usage.output;\n childTotal += child.usage.total;\n }\n\n return {\n input: Math.max(0, span.usage.input - childInput),\n output: Math.max(0, span.usage.output - childOutput),\n total: Math.max(0, span.usage.total - childTotal),\n };\n}\n\n/**\n * Token-usage + cost keys that the per-observation `usage` block already\n * carries authoritatively (as OWN usage). Omitting them from `metadata`\n * avoids a confusing contradiction — metadata would otherwise show the\n * rolled-up subtree totals next to an own-usage `usage` block. Cost is\n * omitted for the same reason; Langfuse prices the own tokens itself.\n */\nconst LANGFUSE_METADATA_OMIT = new Set<string>([\n GEN_AI_ATTRIBUTES.usageInputTokens,\n GEN_AI_ATTRIBUTES.usageOutputTokens,\n WARLOCK_ATTRIBUTES.totalTokens,\n WARLOCK_ATTRIBUTES.cachedTokens,\n WARLOCK_ATTRIBUTES.reasoningTokens,\n WARLOCK_ATTRIBUTES.costUsd,\n]);\n\n/**\n * Observation metadata — the GenAI attribute set minus the usage/cost\n * keys that live authoritatively on the `usage` block (see\n * {@link LANGFUSE_METADATA_OMIT}). Keeps model identity, report type,\n * version, session id, and any collector-set attributes.\n */\nfunction langfuseMetadata(span: TraceSpan): Record<string, AttributeValue> {\n const all = toGenAiAttributes(span);\n const metadata: Record<string, AttributeValue> = {};\n\n for (const [key, value] of Object.entries(all)) {\n if (!LANGFUSE_METADATA_OMIT.has(key)) {\n metadata[key] = value;\n }\n }\n\n return metadata;\n}\n\n/**\n * Map the Panoptic span status onto a Langfuse observation level —\n * failed/cancelled spans surface as `ERROR`, everything else `DEFAULT`.\n */\nfunction toLevel(span: TraceSpan): LangfuseObservationLevel {\n if (span.status === \"failed\" || span.status === \"cancelled\") {\n return \"ERROR\";\n }\n\n return \"DEFAULT\";\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"langfuse-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.ts"],"sourcesContent":["import type { ExporterContract, Trace, TraceSpan } from \"../../contracts\";\nimport type { AttributeValue } from \"../utils\";\nimport { GEN_AI_ATTRIBUTES, toGenAiAttributes, WARLOCK_ATTRIBUTES } from \"../utils\";\nimport type {\n LangfuseClientLike,\n LangfuseExporterOptions,\n LangfuseObservationBody,\n LangfuseObservationLevel,\n LangfuseObservationLike,\n LangfuseTraceBody,\n LangfuseTraceLike,\n} from \"./langfuse-exporter.type\";\n\nconst EXPORTER_NAME = \"langfuse\";\n\n// ============================================================\n// Lazily-loaded langfuse SDK (OPTIONAL peer)\n// ============================================================\n\nlet LangfuseSdk: typeof import(\"langfuse\");\nlet isModuleExists: boolean | null = null;\nlet loadingPromise: Promise<void> | undefined;\n\nconst LANGFUSE_INSTALL_INSTRUCTIONS = `\nThe Panoptic Langfuse exporter requires the langfuse package.\nInstall it with:\n\n npm install langfuse\n\nOr with your preferred package manager:\n\n pnpm add langfuse\n yarn add langfuse\n`.trim();\n\n/**\n * Settle the lazy import of `langfuse` once, concurrency-safe. Only\n * needed when the caller did not pass a ready `client`. A bare `catch`\n * flips the flag to `false`; the curated install string surfaces at use\n * time, never a raw module-resolution stack trace.\n */\nfunction loadLangfuse(): Promise<void> {\n if (isModuleExists !== null) {\n return Promise.resolve();\n }\n\n if (loadingPromise) {\n return loadingPromise;\n }\n\n loadingPromise = (async () => {\n try {\n LangfuseSdk = await import(\"langfuse\");\n isModuleExists = true;\n } catch {\n isModuleExists = false;\n }\n })();\n\n return loadingPromise;\n}\n\n/**\n * {@link ExporterContract} that maps Panoptic traces onto Langfuse\n * traces and observations. Lazily imports `langfuse` so it stays an\n * OPTIONAL peer — importing this module never forces the SDK to be\n * installed, and a missing SDK surfaces as a curated \"install this\"\n * error when the exporter first needs to build a client.\n *\n * The root {@link TraceSpan} becomes a Langfuse trace AND its top\n * observation (so the root execution's own tokens are metered, not just\n * its children's); every node is an observation — a `generation` when it\n * metered its OWN tokens (LLM-backed agents, supervisors), otherwise a\n * plain `span` (tools, callbacks, and composite nodes whose tokens came\n * only from children). Timing, status, and version map 1:1; each\n * generation reports its own token usage (rolled-up minus children) so\n * the trace total isn't double-counted; non-usage GenAI attributes ride\n * along as metadata, and captured content (under `captureContent`)\n * surfaces as native `input` / `output`.\n *\n * @example\n * collector.use(langfuseExporter({ publicKey: \"pk-...\", secretKey: \"sk-...\" }));\n * // or reuse an existing client:\n * collector.use(langfuseExporter({ client: myLangfuse }));\n */\nexport function langfuseExporter(options: LangfuseExporterOptions): ExporterContract {\n let client: LangfuseClientLike | undefined = options.client;\n\n if (!client) {\n loadLangfuse();\n }\n\n const resolveClient = async (): Promise<LangfuseClientLike> => {\n if (client) {\n return client;\n }\n\n await loadLangfuse();\n\n if (!isModuleExists) {\n throw new Error(LANGFUSE_INSTALL_INSTRUCTIONS);\n }\n\n client = new LangfuseSdk.Langfuse({\n publicKey: options.publicKey,\n secretKey: options.secretKey,\n baseUrl: options.baseUrl,\n }) as unknown as LangfuseClientLike;\n\n return client;\n };\n\n return {\n name: EXPORTER_NAME,\n async export(trace: Trace): Promise<void> {\n const activeClient = await resolveClient();\n emitTrace(activeClient, trace);\n },\n async flush(): Promise<void> {\n if (!client) {\n return;\n }\n\n await client.flushAsync();\n },\n async shutdown(): Promise<void> {\n if (!client) {\n return;\n }\n\n await client.shutdownAsync();\n },\n };\n}\n\n/**\n * Create the Langfuse trace from the root span, then recurse the\n * children into nested observations.\n */\nfunction emitTrace(client: LangfuseClientLike, trace: Trace): void {\n const root = trace.root;\n\n const traceBody: LangfuseTraceBody = {\n id: root.traceId,\n name: root.name,\n sessionId: trace.sessionId,\n version: root.version,\n timestamp: new Date(root.startedAt),\n metadata: langfuseMetadata(root),\n };\n\n // Surface the root's captured content at the TRACE level too — not only on\n // the root observation — so Langfuse's trace Preview shows the top-level\n // input/output instead of \"this trace received no input/output\". Present\n // only under content capture, and only for roots that carry I/O (an agent\n // or tool; a composite root like a planner has none of its own).\n if (root.input !== undefined) {\n traceBody.input = root.input;\n }\n\n if (root.output !== undefined) {\n traceBody.output = root.output;\n }\n\n const langfuseTrace = client.trace(traceBody);\n\n // Emit the ROOT as an observation too — not just its children — so the\n // root execution's OWN tokens are metered. Langfuse derives the trace\n // total by summing observation usage; leaving the root (often the single\n // top-level agent) as trace-only would drop its own spend. Children nest\n // under the root observation, mirroring the execution tree, and own-usage\n // metering telescopes the per-node sums back to the true trace total.\n emitObservation(langfuseTrace, root);\n}\n\n/**\n * Map one {@link TraceSpan} onto a Langfuse observation under `parent`,\n * then recurse its children. Spans that metered their OWN tokens become\n * `generation`s; everything else (tools, callbacks, composite nodes)\n * becomes a plain `span`.\n */\nfunction emitObservation(\n parent: LangfuseTraceLike | LangfuseObservationLike,\n span: TraceSpan,\n): void {\n const body: LangfuseObservationBody = {\n id: span.spanId,\n name: span.name,\n startTime: new Date(span.startedAt),\n endTime: new Date(span.endedAt),\n level: toLevel(span),\n statusMessage: span.error?.message,\n version: span.version,\n metadata: langfuseMetadata(span),\n };\n\n // Captured content (only present under `captureContent`) maps onto\n // Langfuse's native observation input/output.\n if (span.input !== undefined) {\n body.input = span.input;\n }\n\n if (span.output !== undefined) {\n body.output = span.output;\n }\n\n let observation: LangfuseObservationLike;\n\n // Classify + meter on OWN tokens (this node's rolled-up usage minus its\n // children's), not the subtree rollup. A composite node whose tokens\n // came only from descendants has zero own-usage and becomes a plain\n // span — so its children's tokens aren't counted twice in the trace\n // total Langfuse sums across observations.\n const own = ownUsage(span);\n\n if (own.total > 0) {\n body.usage = {\n input: own.input,\n output: own.output,\n total: own.total,\n unit: \"TOKENS\",\n };\n observation = parent.generation(body);\n } else {\n observation = parent.span(body);\n }\n\n for (const child of span.children) {\n emitObservation(observation, child);\n }\n\n // Explicitly end the observation. The body already carries `endTime`,\n // so this is idempotent — but the SDK only finalizes (and flushes) an\n // observation on `end()`, so without it long-lived clients can leave\n // observations open. Safe against the local `LangfuseObservationLike`\n // shape, which declares `end(body?)`.\n observation.end({ endTime: body.endTime });\n}\n\n/**\n * Own token usage for a span — its rolled-up {@link TraceSpan.usage}\n * minus the rolled-up usage of its direct children. `TraceSpan.usage` is\n * the subtree total (this node plus every descendant), so subtracting the\n * children leaves the tokens THIS node alone metered, clamped at zero\n * defensively.\n *\n * Langfuse sums observation usage into the trace total, so reporting\n * own-usage on each generation (rather than the subtree rollup) is what\n * keeps the trace total correct instead of multiply-counting nested\n * spans. A composite node with no own tokens (e.g. a workflow whose\n * tokens all came from agent children) yields `total: 0` and is emitted\n * as a plain span, not a generation.\n */\nfunction ownUsage(span: TraceSpan): { input: number; output: number; total: number } {\n let childInput = 0;\n let childOutput = 0;\n let childTotal = 0;\n\n for (const child of span.children) {\n childInput += child.usage.input;\n childOutput += child.usage.output;\n childTotal += child.usage.total;\n }\n\n return {\n input: Math.max(0, span.usage.input - childInput),\n output: Math.max(0, span.usage.output - childOutput),\n total: Math.max(0, span.usage.total - childTotal),\n };\n}\n\n/**\n * Token-usage + cost keys that the per-observation `usage` block already\n * carries authoritatively (as OWN usage). Omitting them from `metadata`\n * avoids a confusing contradiction — metadata would otherwise show the\n * rolled-up subtree totals next to an own-usage `usage` block. Cost is\n * omitted for the same reason; Langfuse prices the own tokens itself.\n */\nconst LANGFUSE_METADATA_OMIT = new Set<string>([\n GEN_AI_ATTRIBUTES.usageInputTokens,\n GEN_AI_ATTRIBUTES.usageOutputTokens,\n WARLOCK_ATTRIBUTES.totalTokens,\n WARLOCK_ATTRIBUTES.cachedTokens,\n WARLOCK_ATTRIBUTES.reasoningTokens,\n WARLOCK_ATTRIBUTES.costUsd,\n]);\n\n/**\n * Observation metadata — the GenAI attribute set minus the usage/cost\n * keys that live authoritatively on the `usage` block (see\n * {@link LANGFUSE_METADATA_OMIT}). Keeps model identity, report type,\n * version, session id, and any collector-set attributes.\n */\nfunction langfuseMetadata(span: TraceSpan): Record<string, AttributeValue> {\n const all = toGenAiAttributes(span);\n const metadata: Record<string, AttributeValue> = {};\n\n for (const [key, value] of Object.entries(all)) {\n if (!LANGFUSE_METADATA_OMIT.has(key)) {\n metadata[key] = value;\n }\n }\n\n return metadata;\n}\n\n/**\n * Map the Panoptic span status onto a Langfuse observation level —\n * failed/cancelled/incomplete spans surface as `ERROR`, everything else `DEFAULT`.\n */\nfunction toLevel(span: TraceSpan): LangfuseObservationLevel {\n if (span.status === \"failed\" || span.status === \"cancelled\" || span.status === \"incomplete\") {\n return \"ERROR\";\n }\n\n return \"DEFAULT\";\n}\n"],"mappings":"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"}
@@ -8,7 +8,7 @@
8
8
  * creates nested `span` / `generation` observations, and the client is
9
9
  * drained with `flushAsync` / `shutdownAsync`.
10
10
  */
11
- type LangfuseClientLike = {
11
+ export type LangfuseClientLike = {
12
12
  trace(body: LangfuseTraceBody): LangfuseTraceLike;
13
13
  flushAsync(): Promise<unknown>;
14
14
  shutdownAsync(): Promise<unknown>;
@@ -17,7 +17,7 @@ type LangfuseClientLike = {
17
17
  * A Langfuse trace handle — creates nested observations and carries the
18
18
  * trace-level metadata Panoptic maps the root span onto.
19
19
  */
20
- type LangfuseTraceLike = {
20
+ export type LangfuseTraceLike = {
21
21
  span(body: LangfuseObservationBody): LangfuseObservationLike;
22
22
  generation(body: LangfuseObservationBody): LangfuseObservationLike;
23
23
  };
@@ -25,24 +25,26 @@ type LangfuseTraceLike = {
25
25
  * A Langfuse observation handle (span or generation) — nests further
26
26
  * children and is closed with `end()`.
27
27
  */
28
- type LangfuseObservationLike = {
28
+ export type LangfuseObservationLike = {
29
29
  span(body: LangfuseObservationBody): LangfuseObservationLike;
30
30
  generation(body: LangfuseObservationBody): LangfuseObservationLike;
31
31
  end(body?: LangfuseObservationEndBody): unknown;
32
32
  };
33
33
  /** Subset of the Langfuse trace-creation body Panoptic populates. */
34
- type LangfuseTraceBody = {
34
+ export type LangfuseTraceBody = {
35
35
  id?: string;
36
36
  name?: string;
37
37
  sessionId?: string;
38
38
  version?: string;
39
39
  timestamp?: Date;
40
- metadata?: Record<string, unknown>; /** Root input surfaced at trace level (set only under content capture). */
41
- input?: unknown; /** Root output surfaced at trace level (set only under content capture). */
40
+ metadata?: Record<string, unknown>;
41
+ /** Root input surfaced at trace level (set only under content capture). */
42
+ input?: unknown;
43
+ /** Root output surfaced at trace level (set only under content capture). */
42
44
  output?: unknown;
43
45
  };
44
46
  /** Subset of the Langfuse observation-creation body Panoptic populates. */
45
- type LangfuseObservationBody = {
47
+ export type LangfuseObservationBody = {
46
48
  id?: string;
47
49
  name?: string;
48
50
  startTime?: Date;
@@ -51,25 +53,27 @@ type LangfuseObservationBody = {
51
53
  statusMessage?: string;
52
54
  version?: string;
53
55
  usage?: LangfuseUsageBody;
54
- metadata?: Record<string, unknown>; /** Captured input (prompt / tool args), set only under content capture. */
55
- input?: unknown; /** Captured output (completion / tool result), set only under content capture. */
56
+ metadata?: Record<string, unknown>;
57
+ /** Captured input (prompt / tool args), set only under content capture. */
58
+ input?: unknown;
59
+ /** Captured output (completion / tool result), set only under content capture. */
56
60
  output?: unknown;
57
61
  };
58
62
  /** Body accepted by `observation.end()`. */
59
- type LangfuseObservationEndBody = {
63
+ export type LangfuseObservationEndBody = {
60
64
  endTime?: Date;
61
65
  level?: LangfuseObservationLevel;
62
66
  statusMessage?: string;
63
67
  };
64
68
  /** Langfuse usage block (`input`/`output`/`total` token counts). */
65
- type LangfuseUsageBody = {
69
+ export type LangfuseUsageBody = {
66
70
  input?: number;
67
71
  output?: number;
68
72
  total?: number;
69
73
  unit?: "TOKENS";
70
74
  };
71
75
  /** Langfuse observation severity levels. */
72
- type LangfuseObservationLevel = "DEFAULT" | "DEBUG" | "WARNING" | "ERROR";
76
+ export type LangfuseObservationLevel = "DEFAULT" | "DEBUG" | "WARNING" | "ERROR";
73
77
  /**
74
78
  * Options for {@link langfuseExporter}.
75
79
  *
@@ -78,17 +82,19 @@ type LangfuseObservationLevel = "DEFAULT" | "DEBUG" | "WARNING" | "ERROR";
78
82
  * stays an optional peer that is only imported when this exporter is
79
83
  * actually used).
80
84
  */
81
- type LangfuseExporterOptions = {
85
+ export type LangfuseExporterOptions = {
82
86
  /**
83
87
  * A pre-built Langfuse client (any object matching
84
88
  * {@link LangfuseClientLike}, including a real `Langfuse` instance).
85
89
  * When supplied, the exporter never imports the SDK itself.
86
90
  */
87
- client?: LangfuseClientLike; /** Langfuse public key — used to construct a client when `client` is omitted. */
88
- publicKey?: string; /** Langfuse secret key — used to construct a client when `client` is omitted. */
89
- secretKey?: string; /** Langfuse host base URL. Optional; defaults to the SDK's own default. */
91
+ client?: LangfuseClientLike;
92
+ /** Langfuse public key — used to construct a client when `client` is omitted. */
93
+ publicKey?: string;
94
+ /** Langfuse secret key — used to construct a client when `client` is omitted. */
95
+ secretKey?: string;
96
+ /** Langfuse host base URL. Optional; defaults to the SDK's own default. */
90
97
  baseUrl?: string;
91
98
  };
92
99
  //#endregion
93
- export { LangfuseClientLike, LangfuseExporterOptions, LangfuseObservationBody, LangfuseObservationEndBody, LangfuseObservationLevel, LangfuseObservationLike, LangfuseTraceBody, LangfuseTraceLike, LangfuseUsageBody };
94
100
  //# sourceMappingURL=langfuse-exporter.type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"langfuse-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.type.ts"],"mappings":";;AASA;;;;;;;;KAAY,kBAAA;EACV,KAAA,CAAM,IAAA,EAAM,iBAAA,GAAoB,iBAAA;EAChC,UAAA,IAAc,OAAA;EACd,aAAA,IAAiB,OAAA;AAAA;;;;;KAOP,iBAAA;EACV,IAAA,CAAK,IAAA,EAAM,uBAAA,GAA0B,uBAAA;EACrC,UAAA,CAAW,IAAA,EAAM,uBAAA,GAA0B,uBAAA;AAAA;;;;;KAOjC,uBAAA;EACV,IAAA,CAAK,IAAA,EAAM,uBAAA,GAA0B,uBAAA;EACrC,UAAA,CAAW,IAAA,EAAM,uBAAA,GAA0B,uBAAA;EAC3C,GAAA,CAAI,IAAA,GAAO,0BAAA;AAAA;;KAID,iBAAA;EACV,EAAA;EACA,IAAA;EACA,SAAA;EACA,OAAA;EACA,SAAA,GAAY,IAAA;EACZ,QAAA,GAAW,MAAM,mBAbP;EAeV,KAAA;EAEA,MAAA;AAAA;;KAIU,uBAAA;EACV,EAAA;EACA,IAAA;EACA,SAAA,GAAY,IAAA;EACZ,OAAA,GAAU,IAAA;EACV,KAAA,GAAQ,wBAAA;EACR,aAAA;EACA,OAAA;EACA,KAAA,GAAQ,iBAAA;EACR,QAAA,GAAW,MAAA,mBA5BA;EA8BX,KAAA,YA7BA;EA+BA,MAAA;AAAA;;KAIU,0BAAA;EACV,OAAA,GAAU,IAAA;EACV,KAAA,GAAQ,wBAAwB;EAChC,aAAA;AAAA;;KAIU,iBAAA;EACV,KAAA;EACA,MAAA;EACA,KAAA;EACA,IAAA;AAAA;;KAIU,wBAAA;;;AApCJ;AAIR;;;;;KA0CY,uBAAA;EAlCF;;;;;EAwCR,MAAA,GAAS,kBAAkB,EA7C3B;EA+CA,SAAA,WA9CA;EAgDA,SAAA,WA/CA;EAiDA,OAAA;AAAA"}
1
+ {"version":3,"file":"langfuse-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.type.ts"],"mappings":";;;;;;;;;;YASY;EACV,MAAM,MAAM,oBAAoB;EAChC,cAAc;EACd,iBAAiB;;;;;;YAOP;EACV,KAAK,MAAM,0BAA0B;EACrC,WAAW,MAAM,0BAA0B;;;;;;YAOjC;EACV,KAAK,MAAM,0BAA0B;EACrC,WAAW,MAAM,0BAA0B;EAC3C,IAAI,OAAO;;;YAID;EACV;EACA;EACA;EACA;EACA,YAAY;EACZ,WAAW;;EAEX;;EAEA;;;YAIU;EACV;EACA;EACA,YAAY;EACZ,UAAU;EACV,QAAQ;EACR;EACA;EACA,QAAQ;EACR,WAAW;;EAEX;;EAEA;;;YAIU;EACV,UAAU;EACV,QAAQ;EACR;;;YAIU;EACV;EACA;EACA;EACA;;;YAIU;;;;;;;;;YAUA;;;;;;EAMV,SAAS;;EAET;;EAEA;;EAEA"}
@@ -1,2 +1,3 @@
1
1
  import { OtelExporterOptions } from "./otel-exporter.type.mjs";
2
- import { otelExporter } from "./otel-exporter.mjs";
2
+ import { otelExporter } from "./otel-exporter.mjs";
3
+ export { type OtelExporterOptions, otelExporter };
@@ -1,3 +1,3 @@
1
1
  import { otelExporter } from "./otel-exporter.mjs";
2
2
 
3
- export { };
3
+ export { otelExporter };