@warlock.js/ai-panoptic 5.31.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.
- package/CHANGELOG.md +10 -0
- package/cjs/index.cjs +16 -65
- package/cjs/index.cjs.map +1 -1
- package/esm/collector/collector.d.mts +3 -5
- package/esm/collector/collector.d.mts.map +1 -1
- package/esm/collector/content-capture.type.d.mts +4 -5
- package/esm/collector/content-capture.type.d.mts.map +1 -1
- package/esm/collector/extract-span-attributes.d.mts +1 -3
- package/esm/collector/extract-span-attributes.d.mts.map +1 -1
- package/esm/collector/extract-span-attributes.mjs +1 -4
- package/esm/collector/extract-span-attributes.mjs.map +1 -1
- package/esm/collector/index.d.mts +2 -1
- package/esm/collector/index.mjs +1 -1
- package/esm/collector/normalize-error.d.mts +1 -3
- package/esm/collector/normalize-error.d.mts.map +1 -1
- package/esm/collector/report-to-span.d.mts +1 -3
- package/esm/collector/report-to-span.d.mts.map +1 -1
- package/esm/collector/report-to-trace.d.mts +1 -3
- package/esm/collector/report-to-trace.d.mts.map +1 -1
- package/esm/config/apply-panoptic-config.d.mts +2 -3
- package/esm/config/apply-panoptic-config.d.mts.map +1 -1
- package/esm/config/index.d.mts +2 -1
- package/esm/config/index.mjs +1 -1
- package/esm/config/panoptic-config.type.d.mts +2 -4
- package/esm/config/panoptic-config.type.d.mts.map +1 -1
- package/esm/contracts/collector.contract.d.mts +1 -3
- package/esm/contracts/collector.contract.d.mts.map +1 -1
- package/esm/contracts/exporter.contract.d.mts +1 -3
- package/esm/contracts/exporter.contract.d.mts.map +1 -1
- package/esm/contracts/index.d.mts +2 -1
- package/esm/contracts/trace.type.d.mts +35 -20
- package/esm/contracts/trace.type.d.mts.map +1 -1
- package/esm/dashboard/dashboard.d.mts +1 -3
- package/esm/dashboard/dashboard.d.mts.map +1 -1
- package/esm/dashboard/dashboard.mjs +3 -2
- package/esm/dashboard/dashboard.mjs.map +1 -1
- package/esm/dashboard/dashboard.type.d.mts +9 -7
- package/esm/dashboard/dashboard.type.d.mts.map +1 -1
- package/esm/dashboard/index.d.mts +4 -1
- package/esm/dashboard/index.mjs +1 -1
- package/esm/dashboard/parse-query.d.mts +1 -1
- package/esm/dashboard/serve.d.mts +2 -1
- package/esm/dashboard/serve.mjs +1 -1
- package/esm/dashboard/serve.mjs.map +1 -1
- package/esm/dashboard/trace-filter.d.mts +44 -32
- package/esm/dashboard/trace-filter.d.mts.map +1 -1
- package/esm/evaluate/evaluate-system-prompt.d.mts +1 -3
- package/esm/evaluate/evaluate-system-prompt.d.mts.map +1 -1
- package/esm/evaluate/evaluate-system-prompt.mjs +3 -1
- package/esm/evaluate/evaluate-system-prompt.mjs.map +1 -1
- package/esm/evaluate/evaluate.type.d.mts +2 -4
- package/esm/evaluate/evaluate.type.d.mts.map +1 -1
- package/esm/evaluate/extract-last-system-prompt.d.mts +1 -3
- package/esm/evaluate/extract-last-system-prompt.d.mts.map +1 -1
- package/esm/evaluate/find-span-by-id.d.mts +1 -3
- package/esm/evaluate/find-span-by-id.d.mts.map +1 -1
- package/esm/evaluate/index.d.mts +2 -1
- package/esm/evaluate/index.mjs +1 -1
- package/esm/exporters/console/console-exporter.d.mts +2 -3
- package/esm/exporters/console/console-exporter.d.mts.map +1 -1
- package/esm/exporters/console/console-exporter.type.d.mts +2 -3
- package/esm/exporters/console/console-exporter.type.d.mts.map +1 -1
- package/esm/exporters/console/format-span-io.d.mts +2 -2
- package/esm/exporters/console/format-span-io.d.mts.map +1 -1
- package/esm/exporters/console/format-span-line.d.mts +2 -2
- package/esm/exporters/console/format-span-line.d.mts.map +1 -1
- package/esm/exporters/console/index.d.mts +2 -1
- package/esm/exporters/console/index.mjs +1 -1
- package/esm/exporters/file/file-exporter.d.mts +2 -3
- package/esm/exporters/file/file-exporter.d.mts.map +1 -1
- package/esm/exporters/file/file-exporter.type.d.mts +8 -5
- package/esm/exporters/file/file-exporter.type.d.mts.map +1 -1
- package/esm/exporters/file/index.d.mts +2 -1
- package/esm/exporters/index.d.mts +7 -1
- package/esm/exporters/index.mjs +1 -1
- package/esm/exporters/langfuse/index.d.mts +2 -1
- package/esm/exporters/langfuse/index.mjs +1 -1
- package/esm/exporters/langfuse/langfuse-exporter.d.mts +2 -3
- package/esm/exporters/langfuse/langfuse-exporter.d.mts.map +1 -1
- package/esm/exporters/langfuse/langfuse-exporter.mjs +1 -1
- package/esm/exporters/langfuse/langfuse-exporter.mjs.map +1 -1
- package/esm/exporters/langfuse/langfuse-exporter.type.d.mts +23 -17
- package/esm/exporters/langfuse/langfuse-exporter.type.d.mts.map +1 -1
- package/esm/exporters/otel/index.d.mts +2 -1
- package/esm/exporters/otel/index.mjs +1 -1
- package/esm/exporters/otel/otel-api.shim.type.d.mts +6 -7
- package/esm/exporters/otel/otel-api.shim.type.d.mts.map +1 -1
- package/esm/exporters/otel/otel-exporter.d.mts +2 -3
- package/esm/exporters/otel/otel-exporter.d.mts.map +1 -1
- package/esm/exporters/otel/otel-exporter.type.d.mts +1 -3
- package/esm/exporters/otel/otel-exporter.type.d.mts.map +1 -1
- package/esm/exporters/utils/gen-ai-attributes.d.mts +9 -7
- package/esm/exporters/utils/gen-ai-attributes.d.mts.map +1 -1
- package/esm/exporters/utils/index.d.mts +2 -1
- package/esm/exporters/utils/index.mjs +1 -1
- package/esm/exporters/utils/total-cost.d.mts +1 -3
- package/esm/exporters/utils/total-cost.d.mts.map +1 -1
- package/esm/exporters/utils/walk-spans.d.mts +2 -2
- package/esm/exporters/utils/walk-spans.d.mts.map +1 -1
- package/esm/index.d.mts +8 -0
- package/esm/panoptic/index.d.mts +2 -1
- package/esm/panoptic/index.mjs +1 -1
- package/esm/panoptic/panoptic-middleware.d.mts +1 -3
- package/esm/panoptic/panoptic-middleware.d.mts.map +1 -1
- package/esm/panoptic/panoptic-target.type.d.mts +4 -5
- package/esm/panoptic/panoptic-target.type.d.mts.map +1 -1
- package/esm/panoptic/panoptic.d.mts +1 -3
- package/esm/panoptic/panoptic.d.mts.map +1 -1
- package/esm/panoptic/panoptic.type.d.mts +8 -7
- package/esm/panoptic/panoptic.type.d.mts.map +1 -1
- package/esm/store/cache-trace-store.d.mts +4 -6
- package/esm/store/cache-trace-store.d.mts.map +1 -1
- package/esm/store/cache-trace-store.mjs +1 -4
- package/esm/store/cache-trace-store.mjs.map +1 -1
- package/esm/store/in-memory-trace-store.d.mts +2 -4
- package/esm/store/in-memory-trace-store.d.mts.map +1 -1
- package/esm/store/in-memory-trace-store.mjs +1 -4
- package/esm/store/in-memory-trace-store.mjs.map +1 -1
- package/esm/store/index.d.mts +2 -1
- package/esm/store/index.mjs +1 -1
- package/esm/store/match-trace.d.mts +1 -3
- package/esm/store/match-trace.d.mts.map +1 -1
- package/esm/store/sum-usage.d.mts +4 -30
- package/esm/store/sum-usage.d.mts.map +1 -1
- package/esm/store/sum-usage.mjs +6 -49
- package/esm/store/sum-usage.mjs.map +1 -1
- package/esm/store/trace-aggregate.type.d.mts +12 -9
- package/esm/store/trace-aggregate.type.d.mts.map +1 -1
- package/esm/store/trace-query.type.d.mts +5 -5
- package/esm/store/trace-query.type.d.mts.map +1 -1
- package/esm/store/trace-store.contract.d.mts +1 -3
- package/esm/store/trace-store.contract.d.mts.map +1 -1
- package/llms-full.txt +14 -0
- package/package.json +4 -4
- package/skills/query-traces/SKILL.md +14 -0
|
@@ -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 };
|
package/esm/exporters/index.mjs
CHANGED
|
@@ -12,4 +12,4 @@ import "./langfuse/index.mjs";
|
|
|
12
12
|
import { otelExporter } from "./otel/otel-exporter.mjs";
|
|
13
13
|
import "./otel/index.mjs";
|
|
14
14
|
|
|
15
|
-
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,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":"
|
|
1
|
+
{"version":3,"file":"langfuse-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/langfuse/langfuse-exporter.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqFgB,iBAAiB,SAAS,0BAA0B"}
|
|
@@ -175,7 +175,7 @@ function ownUsage(span) {
|
|
|
175
175
|
* rolled-up subtree totals next to an own-usage `usage` block. Cost is
|
|
176
176
|
* omitted for the same reason; Langfuse prices the own tokens itself.
|
|
177
177
|
*/
|
|
178
|
-
const LANGFUSE_METADATA_OMIT = new Set([
|
|
178
|
+
const LANGFUSE_METADATA_OMIT = /* @__PURE__ */ new Set([
|
|
179
179
|
GEN_AI_ATTRIBUTES.usageInputTokens,
|
|
180
180
|
GEN_AI_ATTRIBUTES.usageOutputTokens,
|
|
181
181
|
WARLOCK_ATTRIBUTES.totalTokens,
|
|
@@ -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/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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"}
|
|
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>;
|
|
41
|
-
|
|
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>;
|
|
55
|
-
|
|
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;
|
|
88
|
-
|
|
89
|
-
|
|
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":"
|
|
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"}
|
|
@@ -19,20 +19,20 @@
|
|
|
19
19
|
* not the whole OTel API.
|
|
20
20
|
*/
|
|
21
21
|
/** Subset of OTel `TimeInput` the exporter passes (epoch millis). */
|
|
22
|
-
type OtelTimeInput = number;
|
|
22
|
+
export type OtelTimeInput = number;
|
|
23
23
|
/** Opaque OTel `Context` — the exporter only threads it through. */
|
|
24
|
-
type OtelContext = object;
|
|
24
|
+
export type OtelContext = object;
|
|
25
25
|
/**
|
|
26
26
|
* Exception shape accepted by `Span.recordException`. Mirrors the
|
|
27
27
|
* `Exception` object form OTel accepts (name/message/stack).
|
|
28
28
|
*/
|
|
29
|
-
type OtelException = {
|
|
29
|
+
export type OtelException = {
|
|
30
30
|
name?: string;
|
|
31
31
|
message?: string;
|
|
32
32
|
stack?: string;
|
|
33
33
|
};
|
|
34
34
|
/** Status object passed to `Span.setStatus`. */
|
|
35
|
-
type OtelSpanStatus = {
|
|
35
|
+
export type OtelSpanStatus = {
|
|
36
36
|
code: number;
|
|
37
37
|
message?: string;
|
|
38
38
|
};
|
|
@@ -40,7 +40,7 @@ type OtelSpanStatus = {
|
|
|
40
40
|
* Subset of OTel `Span` the exporter drives — set attributes/status,
|
|
41
41
|
* record exceptions, and end with a timestamp.
|
|
42
42
|
*/
|
|
43
|
-
type OtelSpan = {
|
|
43
|
+
export type OtelSpan = {
|
|
44
44
|
setAttributes(attributes: Record<string, unknown>): void;
|
|
45
45
|
setStatus(status: OtelSpanStatus): void;
|
|
46
46
|
recordException(exception: OtelException): void;
|
|
@@ -50,11 +50,10 @@ type OtelSpan = {
|
|
|
50
50
|
* Subset of OTel `Tracer` the exporter calls. `startSpan` is invoked
|
|
51
51
|
* with a name, a `{ startTime }` options object, and a parent context.
|
|
52
52
|
*/
|
|
53
|
-
type OtelTracer = {
|
|
53
|
+
export type OtelTracer = {
|
|
54
54
|
startSpan(name: string, options: {
|
|
55
55
|
startTime?: OtelTimeInput;
|
|
56
56
|
}, context?: OtelContext): OtelSpan;
|
|
57
57
|
};
|
|
58
58
|
//#endregion
|
|
59
|
-
export { OtelTracer };
|
|
60
59
|
//# sourceMappingURL=otel-api.shim.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-api.shim.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-api.shim.type.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"otel-api.shim.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-api.shim.type.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;YAqBY;;YAGA;;;;;YAMA;EACV;EACA;EACA;;;YAIU;EACV;EACA;;;;;;YAOU;EACV,cAAc,YAAY;EAC1B,UAAU,QAAQ;EAClB,gBAAgB,WAAW;EAC3B,IAAI,UAAU;;;;;;YAOJ;EACV,UAAU,cAAc;IAAW,YAAY;KAAiB,UAAU,cAAc"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExporterContract } from "../../contracts/exporter.contract.mjs";
|
|
2
|
+
import "../../contracts/index.mjs";
|
|
2
3
|
import { OtelExporterOptions } from "./otel-exporter.type.mjs";
|
|
3
|
-
|
|
4
4
|
//#region ../../packages/ai-panoptic/src/exporters/otel/otel-exporter.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* {@link ExporterContract} that maps Panoptic traces onto OpenTelemetry
|
|
@@ -23,7 +23,6 @@ import { OtelExporterOptions } from "./otel-exporter.type.mjs";
|
|
|
23
23
|
* // app already set up @opentelemetry/sdk-trace-base + a provider
|
|
24
24
|
* collector.use(otelExporter({ tracerName: "my-app", system: "openai" }));
|
|
25
25
|
*/
|
|
26
|
-
declare function otelExporter(options?: OtelExporterOptions): ExporterContract;
|
|
26
|
+
export declare function otelExporter(options?: OtelExporterOptions): ExporterContract;
|
|
27
27
|
//#endregion
|
|
28
|
-
export { otelExporter };
|
|
29
28
|
//# sourceMappingURL=otel-exporter.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-exporter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"otel-exporter.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-exporter.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;wBAuFgB,aAAa,UAAS,sBAA2B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { OtelTracer } from "./otel-api.shim.type.mjs";
|
|
2
|
-
|
|
3
2
|
//#region ../../packages/ai-panoptic/src/exporters/otel/otel-exporter.type.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Options for {@link otelExporter}.
|
|
@@ -10,7 +9,7 @@ import { OtelTracer } from "./otel-api.shim.type.mjs";
|
|
|
10
9
|
* exporter fetch one from the globally registered provider via
|
|
11
10
|
* `trace.getTracer(name)`.
|
|
12
11
|
*/
|
|
13
|
-
type OtelExporterOptions = {
|
|
12
|
+
export type OtelExporterOptions = {
|
|
14
13
|
/**
|
|
15
14
|
* A `Tracer` to emit spans on. When omitted, the exporter lazily calls
|
|
16
15
|
* `trace.getTracer(tracerName, tracerVersion)` against the globally
|
|
@@ -39,5 +38,4 @@ type OtelExporterOptions = {
|
|
|
39
38
|
system?: string;
|
|
40
39
|
};
|
|
41
40
|
//#endregion
|
|
42
|
-
export { OtelExporterOptions };
|
|
43
41
|
//# sourceMappingURL=otel-exporter.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-exporter.type.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"otel-exporter.type.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-exporter.type.ts"],"mappings":";;;;;;;;;;;YAWY;;;;;;;;;;EAUV,SAAS;;;;;EAKT;;;;;EAKA;;;;;;EAMA"}
|
|
@@ -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/utils/gen-ai-attributes.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Subset of the OpenTelemetry GenAI semantic-convention attribute keys
|
|
@@ -8,15 +9,17 @@ import { TraceSpan } from "../../contracts/trace.type.mjs";
|
|
|
8
9
|
*
|
|
9
10
|
* @see https://opentelemetry.io/docs/specs/semconv/gen-ai/
|
|
10
11
|
*/
|
|
11
|
-
declare const GEN_AI_ATTRIBUTES: {
|
|
12
|
+
export declare const GEN_AI_ATTRIBUTES: {
|
|
12
13
|
readonly operationName: "gen_ai.operation.name";
|
|
13
14
|
readonly system: "gen_ai.system";
|
|
14
15
|
readonly requestModel: "gen_ai.request.model";
|
|
15
16
|
readonly responseModel: "gen_ai.response.model";
|
|
16
17
|
readonly usageInputTokens: "gen_ai.usage.input_tokens";
|
|
17
18
|
readonly usageOutputTokens: "gen_ai.usage.output_tokens";
|
|
18
|
-
readonly conversationId: "gen_ai.conversation.id";
|
|
19
|
-
|
|
19
|
+
readonly conversationId: "gen_ai.conversation.id";
|
|
20
|
+
/** Captured prompt/input (set only under content capture). */
|
|
21
|
+
readonly prompt: "gen_ai.prompt";
|
|
22
|
+
/** Captured completion/output (set only under content capture). */
|
|
20
23
|
readonly completion: "gen_ai.completion";
|
|
21
24
|
};
|
|
22
25
|
/**
|
|
@@ -24,7 +27,7 @@ declare const GEN_AI_ATTRIBUTES: {
|
|
|
24
27
|
* equivalent. Namespaced under `warlock.*` so they never collide with a
|
|
25
28
|
* future `gen_ai.*` key the spec might add.
|
|
26
29
|
*/
|
|
27
|
-
declare const WARLOCK_ATTRIBUTES: {
|
|
30
|
+
export declare const WARLOCK_ATTRIBUTES: {
|
|
28
31
|
readonly reportType: "warlock.report.type";
|
|
29
32
|
readonly version: "warlock.version";
|
|
30
33
|
readonly durationMs: "warlock.duration_ms";
|
|
@@ -38,7 +41,7 @@ declare const WARLOCK_ATTRIBUTES: {
|
|
|
38
41
|
* GenAI attributes are scalars; the framework's free-form
|
|
39
42
|
* `TraceSpan.attributes` may also carry these.
|
|
40
43
|
*/
|
|
41
|
-
type AttributeValue = string | number | boolean;
|
|
44
|
+
export type AttributeValue = string | number | boolean;
|
|
42
45
|
/**
|
|
43
46
|
* Project a {@link TraceSpan} onto the OpenTelemetry GenAI
|
|
44
47
|
* semantic-convention attribute set.
|
|
@@ -61,7 +64,6 @@ type AttributeValue = string | number | boolean;
|
|
|
61
64
|
* const attributes = toGenAiAttributes(span);
|
|
62
65
|
* // { "gen_ai.usage.input_tokens": 150, "gen_ai.usage.output_tokens": 320, ... }
|
|
63
66
|
*/
|
|
64
|
-
declare function toGenAiAttributes(span: TraceSpan): Record<string, AttributeValue>;
|
|
67
|
+
export declare function toGenAiAttributes(span: TraceSpan): Record<string, AttributeValue>;
|
|
65
68
|
//#endregion
|
|
66
|
-
export { AttributeValue, GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes };
|
|
67
69
|
//# sourceMappingURL=gen-ai-attributes.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen-ai-attributes.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/gen-ai-attributes.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"gen-ai-attributes.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/gen-ai-attributes.ts"],"mappings":";;;;;;;;;;;qBAWa;WACX;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;;WAEA;;;;;;;qBAQW;WACX;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;;YAQU;;;;;;;;;;;;;;;;;;;;;;;wBAwBI,kBAAkB,MAAM,YAAY,eAAe"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { AttributeValue, GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes } from "./gen-ai-attributes.mjs";
|
|
2
2
|
import { totalCostUsd } from "./total-cost.mjs";
|
|
3
|
-
import { walkSpans } from "./walk-spans.mjs";
|
|
3
|
+
import { walkSpans } from "./walk-spans.mjs";
|
|
4
|
+
export { type AttributeValue, GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes, totalCostUsd, walkSpans };
|
|
@@ -2,4 +2,4 @@ import { walkSpans } from "./walk-spans.mjs";
|
|
|
2
2
|
import { totalCostUsd } from "./total-cost.mjs";
|
|
3
3
|
import { GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes } from "./gen-ai-attributes.mjs";
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export { GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes, totalCostUsd, walkSpans };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Usage } from "@warlock.js/ai";
|
|
2
|
-
|
|
3
2
|
//#region ../../packages/ai-panoptic/src/exporters/utils/total-cost.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Collapse a {@link Usage.cost} breakdown into a single USD scalar by
|
|
@@ -12,7 +11,6 @@ import { Usage } from "@warlock.js/ai";
|
|
|
12
11
|
* totalCostUsd({ input: 1, output: 2, total: 3, cost: { input: 0.01, output: 0.04 } });
|
|
13
12
|
* // => 0.05
|
|
14
13
|
*/
|
|
15
|
-
declare function totalCostUsd(usage: Usage): number | undefined;
|
|
14
|
+
export declare function totalCostUsd(usage: Usage): number | undefined;
|
|
16
15
|
//#endregion
|
|
17
|
-
export { totalCostUsd };
|
|
18
16
|
//# sourceMappingURL=total-cost.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"total-cost.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/total-cost.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"total-cost.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/total-cost.ts"],"mappings":";;;;;;;;;;;;;wBAagB,aAAa,OAAO"}
|
|
@@ -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/utils/walk-spans.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Depth-first pre-order traversal of a {@link TraceSpan} tree, yielding
|
|
@@ -12,7 +13,6 @@ import { TraceSpan } from "../../contracts/trace.type.mjs";
|
|
|
12
13
|
* emit(span);
|
|
13
14
|
* }
|
|
14
15
|
*/
|
|
15
|
-
declare function walkSpans(root: TraceSpan): Generator<TraceSpan>;
|
|
16
|
+
export declare function walkSpans(root: TraceSpan): Generator<TraceSpan>;
|
|
16
17
|
//#endregion
|
|
17
|
-
export { walkSpans };
|
|
18
18
|
//# sourceMappingURL=walk-spans.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk-spans.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/walk-spans.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"walk-spans.d.mts","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/walk-spans.ts"],"mappings":";;;;;;;;;;;;;;;wBAciB,UAAU,MAAM,YAAY,UAAU"}
|
package/esm/index.d.mts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Trace, TraceSpan, TraceSpanError } from "./contracts/trace.type.mjs";
|
|
2
2
|
import { ExporterContract } from "./contracts/exporter.contract.mjs";
|
|
3
3
|
import { CollectorContract } from "./contracts/collector.contract.mjs";
|
|
4
|
+
import "./contracts/index.mjs";
|
|
4
5
|
import { ContentCaptureOptions, ContentRedactor } from "./collector/content-capture.type.mjs";
|
|
5
6
|
import { CollectorOptions, ExporterErrorHandler, createCollector } from "./collector/collector.mjs";
|
|
6
7
|
import { reportToTrace } from "./collector/report-to-trace.mjs";
|
|
7
8
|
import { reportToSpan } from "./collector/report-to-span.mjs";
|
|
8
9
|
import { extractSpanAttributes } from "./collector/extract-span-attributes.mjs";
|
|
9
10
|
import { normalizeError } from "./collector/normalize-error.mjs";
|
|
11
|
+
import "./collector/index.mjs";
|
|
10
12
|
import { TraceAggregate } from "./store/trace-aggregate.type.mjs";
|
|
11
13
|
import { TraceQuery } from "./store/trace-query.type.mjs";
|
|
12
14
|
import { TraceStoreContract } from "./store/trace-store.contract.mjs";
|
|
@@ -14,6 +16,7 @@ import { CacheDriverInput, CacheTraceStoreHandle, CacheTraceStoreOptions, create
|
|
|
14
16
|
import { InMemoryTraceStoreOptions, createInMemoryTraceStore } from "./store/in-memory-trace-store.mjs";
|
|
15
17
|
import { matchTrace } from "./store/match-trace.mjs";
|
|
16
18
|
import { emptyUsage, sumUsage } from "./store/sum-usage.mjs";
|
|
19
|
+
import "./store/index.mjs";
|
|
17
20
|
import { ConsoleExporterOptions, ConsoleLike } from "./exporters/console/console-exporter.type.mjs";
|
|
18
21
|
import { consoleExporter } from "./exporters/console/console-exporter.mjs";
|
|
19
22
|
import { formatSpanLine } from "./exporters/console/format-span-line.mjs";
|
|
@@ -27,18 +30,23 @@ import { otelExporter } from "./exporters/otel/otel-exporter.mjs";
|
|
|
27
30
|
import { AttributeValue, GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes } from "./exporters/utils/gen-ai-attributes.mjs";
|
|
28
31
|
import { totalCostUsd } from "./exporters/utils/total-cost.mjs";
|
|
29
32
|
import { walkSpans } from "./exporters/utils/walk-spans.mjs";
|
|
33
|
+
import "./exporters/index.mjs";
|
|
30
34
|
import { CompletedEventPayload, PanopticTarget } from "./panoptic/panoptic-target.type.mjs";
|
|
31
35
|
import { Panoptic, PanopticOptions } from "./panoptic/panoptic.type.mjs";
|
|
32
36
|
import { panoptic } from "./panoptic/panoptic.mjs";
|
|
33
37
|
import { createPanopticMiddleware } from "./panoptic/panoptic-middleware.mjs";
|
|
38
|
+
import "./panoptic/index.mjs";
|
|
34
39
|
import { EvaluateConfig, EvaluateVerdict } from "./evaluate/evaluate.type.mjs";
|
|
35
40
|
import { evaluateSystemPrompt } from "./evaluate/evaluate-system-prompt.mjs";
|
|
36
41
|
import { extractLastSystemPrompt } from "./evaluate/extract-last-system-prompt.mjs";
|
|
37
42
|
import { findSpanById } from "./evaluate/find-span-by-id.mjs";
|
|
43
|
+
import "./evaluate/index.mjs";
|
|
38
44
|
import { DashboardHandle, DashboardOptions } from "./dashboard/dashboard.type.mjs";
|
|
39
45
|
import { dashboard } from "./dashboard/dashboard.mjs";
|
|
40
46
|
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 "./dashboard/trace-filter.mjs";
|
|
47
|
+
import "./dashboard/index.mjs";
|
|
41
48
|
import { PanopticConfig } from "./config/panoptic-config.type.mjs";
|
|
42
49
|
import { applyPanopticConfig } from "./config/apply-panoptic-config.mjs";
|
|
50
|
+
import "./config/index.mjs";
|
|
43
51
|
export { type AttributeValue, type CacheDriverInput, type CacheTraceStoreHandle, type CacheTraceStoreOptions, type CollectorContract, type CollectorOptions, type CompletedEventPayload, type ConsoleExporterOptions, type ConsoleLike, type ContentCaptureOptions, type ContentRedactor, type DashboardHandle, type DashboardOptions, type EvaluateConfig, type EvaluateVerdict, type ExporterContract, type ExporterErrorHandler, type FileExporterOptions, GEN_AI_ATTRIBUTES, type InMemoryTraceStoreOptions, type LangfuseClientLike, type LangfuseExporterOptions, type LangfuseObservationBody, type LangfuseObservationEndBody, type LangfuseObservationLevel, type LangfuseObservationLike, type LangfuseTraceBody, type LangfuseTraceLike, type LangfuseUsageBody, NO_PROMPT_KEY, NO_SESSION_KEY, NO_TYPE_KEY, type OtelExporterOptions, type Panoptic, type PanopticConfig, type PanopticOptions, type PanopticTarget, type PromptGroup, type SessionGroup, type Trace, type TraceAggregate, type TraceFilter, type TraceQuery, type TraceRecord, type TraceSpan, type TraceSpanError, type TraceStoreContract, type TypeGroup, type TypeStat, WARLOCK_ATTRIBUTES, aggregateByType, applyPanopticConfig, consoleExporter, createCacheTraceStore, createCollector, createInMemoryTraceStore, createPanopticMiddleware, dashboard, emptyUsage, evaluateSystemPrompt, extractLastSystemPrompt, extractSpanAttributes, fileExporter, filterTraces, findSpanById, formatSpanIO, formatSpanLine, groupByPrompt, groupBySession, groupByType, heatIntensity, langfuseExporter, matchTrace, matchesFilter, maxNodeCost, normalizeError, otelExporter, panoptic, percentile, reportToSpan, reportToTrace, rollupCost, sumUsage, toGenAiAttributes, totalCostUsd, traceCost, tracePromptKey, walkSpans };
|
|
44
52
|
import "./config/panoptic-config.type.mjs";
|
package/esm/panoptic/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CompletedEventPayload, PanopticTarget } from "./panoptic-target.type.mjs";
|
|
2
2
|
import { Panoptic, PanopticOptions } from "./panoptic.type.mjs";
|
|
3
3
|
import { panoptic } from "./panoptic.mjs";
|
|
4
|
-
import { createPanopticMiddleware } from "./panoptic-middleware.mjs";
|
|
4
|
+
import { createPanopticMiddleware } from "./panoptic-middleware.mjs";
|
|
5
|
+
export { type CompletedEventPayload, type Panoptic, type PanopticOptions, type PanopticTarget, createPanopticMiddleware, panoptic };
|
package/esm/panoptic/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CollectorContract } from "../contracts/collector.contract.mjs";
|
|
2
2
|
import { AgentMiddleware } from "@warlock.js/ai";
|
|
3
|
-
|
|
4
3
|
//#region ../../packages/ai-panoptic/src/panoptic/panoptic-middleware.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Build an {@link AgentMiddleware} that feeds a collector from the
|
|
@@ -32,7 +31,6 @@ import { AgentMiddleware } from "@warlock.js/ai";
|
|
|
32
31
|
* @param name - stable middleware name (kebab-case). Defaults to
|
|
33
32
|
* `"panoptic"`.
|
|
34
33
|
*/
|
|
35
|
-
declare function createPanopticMiddleware(collector: CollectorContract, name?: string): AgentMiddleware;
|
|
34
|
+
export declare function createPanopticMiddleware(collector: CollectorContract, name?: string): AgentMiddleware;
|
|
36
35
|
//#endregion
|
|
37
|
-
export { createPanopticMiddleware };
|
|
38
36
|
//# sourceMappingURL=panoptic-middleware.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panoptic-middleware.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic-middleware.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"panoptic-middleware.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic-middleware.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiCgB,yBACd,WAAW,mBACX,gBACC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseReport, BaseResult } from "@warlock.js/ai";
|
|
2
|
-
|
|
3
2
|
//#region ../../packages/ai-panoptic/src/panoptic/panoptic-target.type.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* The minimal completed-event payload Panoptic reads off any primitive's
|
|
@@ -10,8 +9,9 @@ import { BaseReport, BaseResult } from "@warlock.js/ai";
|
|
|
10
9
|
* `*.completed` still fires). Reading the report off this single event is
|
|
11
10
|
* therefore enough to capture every run regardless of outcome.
|
|
12
11
|
*/
|
|
13
|
-
type CompletedEventPayload = {
|
|
14
|
-
/** The finalized result of the run; carries the full `report` tree. */
|
|
12
|
+
export type CompletedEventPayload = {
|
|
13
|
+
/** The finalized result of the run; carries the full `report` tree. */
|
|
14
|
+
result: BaseResult & {
|
|
15
15
|
report: BaseReport;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
@@ -34,7 +34,7 @@ type CompletedEventPayload = {
|
|
|
34
34
|
* const sub = panoptic({ exporters: [consoleExporter()] });
|
|
35
35
|
* const detach = sub.attach(agent); // agent is a PanopticTarget
|
|
36
36
|
*/
|
|
37
|
-
type PanopticTarget = {
|
|
37
|
+
export type PanopticTarget = {
|
|
38
38
|
/**
|
|
39
39
|
* Stable identifier of the primitive. Used only for diagnostics
|
|
40
40
|
* (Panoptic never branches behavior on it). Present on every core
|
|
@@ -49,5 +49,4 @@ type PanopticTarget = {
|
|
|
49
49
|
on(event: string, handler: (payload: unknown) => void): () => void;
|
|
50
50
|
};
|
|
51
51
|
//#endregion
|
|
52
|
-
export { CompletedEventPayload, PanopticTarget };
|
|
53
52
|
//# sourceMappingURL=panoptic-target.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panoptic-target.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic-target.type.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"panoptic-target.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic-target.type.ts"],"mappings":";;;;;;;;;;;YAWY;;EAEV,QAAQ;IAAe,QAAQ;;;;;;;;;;;;;;;;;;;;;;YAsBrB;;;;;;WAMD;;;;;;EAMT,GAAG,eAAe,UAAU"}
|