@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.
- package/CHANGELOG.md +25 -3
- package/README.md +2 -2
- package/cjs/index.cjs +38 -84
- 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 +2 -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-span.mjs.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/apply-panoptic-config.mjs.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/parse-query.mjs +1 -0
- package/esm/dashboard/parse-query.mjs.map +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/dashboard/trace-filter.mjs +1 -1
- package/esm/dashboard/trace-filter.mjs.map +1 -1
- package/esm/dashboard/ui.html.mjs +5 -4
- package/esm/dashboard/ui.html.mjs.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.mjs +4 -3
- package/esm/exporters/console/console-exporter.mjs.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-io.mjs.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/format-span-line.mjs +2 -0
- package/esm/exporters/console/format-span-line.mjs.map +1 -1
- package/esm/exporters/console/index.d.mts +2 -1
- package/esm/exporters/console/index.mjs +5 -0
- 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.mjs.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 +3 -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 +4 -3
- 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.mjs +2 -1
- package/esm/exporters/otel/otel-exporter.mjs.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 +5 -0
- package/esm/exporters/utils/total-cost.d.mts +3 -7
- package/esm/exporters/utils/total-cost.d.mts.map +1 -1
- package/esm/exporters/utils/total-cost.mjs +5 -7
- package/esm/exporters/utils/total-cost.mjs.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-middleware.mjs.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.mjs.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 +2 -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 +4 -5
- 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 +13 -14
- 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 +148 -117
- package/package.json +4 -4
- package/skills/evaluate-system-prompt/SKILL.md +21 -17
- package/skills/export-traces/SKILL.md +32 -24
- package/skills/index.md +3 -0
- package/skills/observe-with-panoptic/SKILL.md +18 -18
- package/skills/query-traces/SKILL.md +45 -33
- package/skills/use-local-dashboard/SKILL.md +33 -26
|
@@ -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,4 +1,5 @@
|
|
|
1
1
|
import { GEN_AI_ATTRIBUTES, toGenAiAttributes } from "../utils/gen-ai-attributes.mjs";
|
|
2
|
+
import "../utils/index.mjs";
|
|
2
3
|
|
|
3
4
|
//#region ../../packages/ai-panoptic/src/exporters/otel/otel-exporter.ts
|
|
4
5
|
const EXPORTER_NAME = "otel";
|
|
@@ -128,7 +129,7 @@ function applyStatus(otelSpan, span) {
|
|
|
128
129
|
message: span.error.message,
|
|
129
130
|
stack: span.error.stack
|
|
130
131
|
});
|
|
131
|
-
if (span.status === "failed" || span.status === "cancelled") {
|
|
132
|
+
if (span.status === "failed" || span.status === "cancelled" || span.status === "incomplete") {
|
|
132
133
|
otelSpan.setStatus({
|
|
133
134
|
code: codes.ERROR,
|
|
134
135
|
message: span.error?.message
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-exporter.ts"],"sourcesContent":["import type { ExporterContract, Trace, TraceSpan } from \"../../contracts\";\nimport { toGenAiAttributes, GEN_AI_ATTRIBUTES } from \"../utils\";\nimport type {\n OtelApiModule,\n OtelContext,\n OtelSpan,\n OtelSpanStatusCode,\n OtelTracer,\n} from \"./otel-api.shim.type\";\nimport type { OtelExporterOptions } from \"./otel-exporter.type\";\n\nconst EXPORTER_NAME = \"otel\";\nconst DEFAULT_TRACER_NAME = \"@warlock.js/ai-panoptic\";\n\n// ============================================================\n// Lazily-loaded @opentelemetry/api (OPTIONAL peer)\n// ============================================================\n\nlet OtelApi: OtelApiModule;\nlet isModuleExists: boolean | null = null;\nlet loadingPromise: Promise<void> | undefined;\n\nconst OTEL_INSTALL_INSTRUCTIONS = `\nThe Panoptic OpenTelemetry exporter requires the @opentelemetry/api package.\nInstall it with:\n\n npm install @opentelemetry/api\n\nOr with your preferred package manager:\n\n pnpm add @opentelemetry/api\n yarn add @opentelemetry/api\n`.trim();\n\n/**\n * Settle the lazy import of `@opentelemetry/api` once, concurrency-safe.\n * A bare `catch` flips the flag to `false`; the curated install string\n * surfaces at use time so a missing SDK never throws a raw module\n * resolution error.\n */\nfunction loadOtel(): 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 // Indirect specifier so TS does not statically resolve the\n // optional `@opentelemetry/api` peer at compile time (it is\n // intentionally not installed). The result is structurally the\n // `OtelApiModule` shim — the exporter only touches that surface.\n const moduleName = \"@opentelemetry/api\";\n OtelApi = (await import(moduleName)) as OtelApiModule;\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 OpenTelemetry\n * spans following the GenAI semantic conventions (`gen_ai.*`\n * attributes). Lazily imports `@opentelemetry/api` 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 on first `export`, not a boot-time stack trace.\n *\n * The exporter emits onto a `Tracer` you supply (or fetches one from the\n * globally registered provider). It never configures the SDK — wiring a\n * `TracerProvider`, processors, and span exporters is the host app's\n * job, exactly as with any other OTel instrumentation.\n *\n * Each {@link TraceSpan} becomes one OTel span with the source span's\n * start/end times and parent relationship reconstructed, so the emitted\n * tree matches the original execution tree.\n *\n * @example\n * // app already set up @opentelemetry/sdk-trace-base + a provider\n * collector.use(otelExporter({ tracerName: \"my-app\", system: \"openai\" }));\n */\nexport function otelExporter(options: OtelExporterOptions = {}): ExporterContract {\n loadOtel();\n\n return {\n name: EXPORTER_NAME,\n async export(trace: Trace): Promise<void> {\n await loadOtel();\n\n if (!isModuleExists) {\n throw new Error(OTEL_INSTALL_INSTRUCTIONS);\n }\n\n const tracer = resolveTracer(options);\n emitSpan(tracer, trace.root, undefined, options);\n },\n };\n}\n\n/**\n * Resolve the `Tracer` spans are emitted on — the caller-supplied one,\n * or one fetched from the globally registered provider by name.\n */\nfunction resolveTracer(options: OtelExporterOptions): OtelTracer {\n if (options.tracer) {\n return options.tracer;\n }\n\n return OtelApi.trace.getTracer(\n options.tracerName ?? DEFAULT_TRACER_NAME,\n options.tracerVersion,\n );\n}\n\n/**\n * Recreate one {@link TraceSpan} (and its subtree) as OTel spans. The\n * span is started with the source `startedAt`, parented under\n * `parentContext` so the tree is preserved, annotated with GenAI\n * attributes, given the mapped status, and ended at `endedAt`. Children\n * recurse under this span's context.\n */\nfunction emitSpan(\n tracer: OtelTracer,\n span: TraceSpan,\n parentContext: OtelContext | undefined,\n options: OtelExporterOptions,\n): void {\n const startTime = toEpochMillis(span.startedAt);\n const baseContext = parentContext ?? OtelApi.context.active();\n\n const otelSpan = tracer.startSpan(span.name, { startTime }, baseContext);\n\n applyAttributes(otelSpan, span, options);\n applyStatus(otelSpan, span);\n\n const childContext = OtelApi.trace.setSpan(baseContext, otelSpan);\n\n for (const child of span.children) {\n emitSpan(tracer, child, childContext, options);\n }\n\n otelSpan.end(toEpochMillis(span.endedAt));\n}\n\n/**\n * Set the GenAI + Warlock attributes on the OTel span, defaulting\n * `gen_ai.system` from the exporter options when the span carried none.\n */\nfunction applyAttributes(\n otelSpan: OtelSpan,\n span: TraceSpan,\n options: OtelExporterOptions,\n): void {\n const attributes = toGenAiAttributes(span);\n\n if (options.system !== undefined && attributes[GEN_AI_ATTRIBUTES.system] === undefined) {\n attributes[GEN_AI_ATTRIBUTES.system] = options.system;\n }\n\n // Captured content (only present under `captureContent`) maps onto the\n // GenAI prompt/completion attributes, stringified since OTel attribute\n // values must be primitives.\n if (span.input !== undefined) {\n attributes[GEN_AI_ATTRIBUTES.prompt] = stringifyContent(span.input);\n }\n\n if (span.output !== undefined) {\n attributes[GEN_AI_ATTRIBUTES.completion] = stringifyContent(span.output);\n }\n\n otelSpan.setAttributes(attributes);\n}\n\n/**\n * Coerce a captured content value to a string OTel attribute. Strings\n * pass through; structured values are JSON-encoded (falling back to\n * `String()` if they can't be serialized).\n */\nfunction stringifyContent(value: unknown): string {\n if (typeof value === \"string\") {\n return value;\n }\n\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n\n/**\n * Map the Panoptic span status onto the OTel span status, recording the\n * normalized error as an exception event + ERROR status when present.\n */\nfunction applyStatus(otelSpan: OtelSpan, span: TraceSpan): void {\n const codes: OtelSpanStatusCode = OtelApi.SpanStatusCode;\n\n if (span.error) {\n otelSpan.recordException({\n name: span.error.type,\n message: span.error.message,\n stack: span.error.stack,\n });\n }\n\n if (span.status === \"failed\" || span.status === \"cancelled\") {\n otelSpan.setStatus({\n code: codes.ERROR,\n message: span.error?.message,\n });\n return;\n }\n\n // A capped / paused run is neither a failure nor a clean success.\n // Mapping it to OK would let a hit iteration cap read as a healthy\n // run; leave the OTel status UNSET with a descriptive message so the\n // outcome is visible without being miscounted as an error.\n if (span.status === \"max-iterations\" || span.status === \"awaiting-input\") {\n otelSpan.setStatus({\n code: codes.UNSET,\n message:\n span.status === \"max-iterations\"\n ? \"Run hit the iteration cap without an explicit end\"\n : \"Run is awaiting the next input turn\",\n });\n return;\n }\n\n otelSpan.setStatus({ code: codes.OK });\n}\n\n/**\n * Convert an ISO-8601 timestamp to epoch milliseconds — the `TimeInput`\n * form OTel's `startSpan` / `Span.end` accept directly.\n */\nfunction toEpochMillis(isoTimestamp: string): number {\n return new Date(isoTimestamp).getTime();\n}\n"],"mappings":";;;AAWA,MAAM,gBAAgB;AACtB,MAAM,sBAAsB;AAM5B,IAAI;AACJ,IAAI,iBAAiC;AACrC,IAAI;AAEJ,MAAM,4BAA4B;;;;;;;;;;EAUhC,KAAK;;;;;;;AAQP,SAAS,WAA0B;CACjC,IAAI,mBAAmB,MACrB,OAAO,QAAQ,QAAQ;CAGzB,IAAI,gBACF,OAAO;CAGT,kBAAkB,YAAY;EAC5B,IAAI;GAMF,UAAW,MAAM,OAAO;GACxB,iBAAiB;EACnB,QAAQ;GACN,iBAAiB;EACnB;CACF,EAAC,CAAE;CAEH,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,aAAa,UAA+B,CAAC,GAAqB;CAChF,SAAS;CAET,OAAO;EACL,MAAM;EACN,MAAM,OAAO,OAA6B;GACxC,MAAM,SAAS;GAEf,IAAI,CAAC,gBACH,MAAM,IAAI,MAAM,yBAAyB;GAI3C,SADe,cAAc,OACf,GAAG,MAAM,MAAM,QAAW,OAAO;EACjD;CACF;AACF;;;;;AAMA,SAAS,cAAc,SAA0C;CAC/D,IAAI,QAAQ,QACV,OAAO,QAAQ;CAGjB,OAAO,QAAQ,MAAM,UACnB,QAAQ,cAAc,qBACtB,QAAQ,aACV;AACF;;;;;;;;AASA,SAAS,SACP,QACA,MACA,eACA,SACM;CACN,MAAM,YAAY,cAAc,KAAK,SAAS;CAC9C,MAAM,cAAc,iBAAiB,QAAQ,QAAQ,OAAO;CAE5D,MAAM,WAAW,OAAO,UAAU,KAAK,MAAM,EAAE,UAAU,GAAG,WAAW;CAEvE,gBAAgB,UAAU,MAAM,OAAO;CACvC,YAAY,UAAU,IAAI;CAE1B,MAAM,eAAe,QAAQ,MAAM,QAAQ,aAAa,QAAQ;CAEhE,KAAK,MAAM,SAAS,KAAK,UACvB,SAAS,QAAQ,OAAO,cAAc,OAAO;CAG/C,SAAS,IAAI,cAAc,KAAK,OAAO,CAAC;AAC1C;;;;;AAMA,SAAS,gBACP,UACA,MACA,SACM;CACN,MAAM,aAAa,kBAAkB,IAAI;CAEzC,IAAI,QAAQ,WAAW,UAAa,WAAW,kBAAkB,YAAY,QAC3E,WAAW,kBAAkB,UAAU,QAAQ;CAMjD,IAAI,KAAK,UAAU,QACjB,WAAW,kBAAkB,UAAU,iBAAiB,KAAK,KAAK;CAGpE,IAAI,KAAK,WAAW,QAClB,WAAW,kBAAkB,cAAc,iBAAiB,KAAK,MAAM;CAGzE,SAAS,cAAc,UAAU;AACnC;;;;;;AAOA,SAAS,iBAAiB,OAAwB;CAChD,IAAI,OAAO,UAAU,UACnB,OAAO;CAGT,IAAI;EACF,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC9C,QAAQ;EACN,OAAO,OAAO,KAAK;CACrB;AACF;;;;;AAMA,SAAS,YAAY,UAAoB,MAAuB;CAC9D,MAAM,QAA4B,QAAQ;CAE1C,IAAI,KAAK,OACP,SAAS,gBAAgB;EACvB,MAAM,KAAK,MAAM;EACjB,SAAS,KAAK,MAAM;EACpB,OAAO,KAAK,MAAM;CACpB,CAAC;CAGH,IAAI,KAAK,WAAW,YAAY,KAAK,WAAW,aAAa;EAC3D,SAAS,UAAU;GACjB,MAAM,MAAM;GACZ,SAAS,KAAK,OAAO;EACvB,CAAC;EACD;CACF;CAMA,IAAI,KAAK,WAAW,oBAAoB,KAAK,WAAW,kBAAkB;EACxE,SAAS,UAAU;GACjB,MAAM,MAAM;GACZ,SACE,KAAK,WAAW,mBACZ,sDACA;EACR,CAAC;EACD;CACF;CAEA,SAAS,UAAU,EAAE,MAAM,MAAM,GAAG,CAAC;AACvC;;;;;AAMA,SAAS,cAAc,cAA8B;CACnD,OAAO,IAAI,KAAK,YAAY,CAAC,CAAC,QAAQ;AACxC"}
|
|
1
|
+
{"version":3,"file":"otel-exporter.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/otel/otel-exporter.ts"],"sourcesContent":["import type { ExporterContract, Trace, TraceSpan } from \"../../contracts\";\nimport { toGenAiAttributes, GEN_AI_ATTRIBUTES } from \"../utils\";\nimport type {\n OtelApiModule,\n OtelContext,\n OtelSpan,\n OtelSpanStatusCode,\n OtelTracer,\n} from \"./otel-api.shim.type\";\nimport type { OtelExporterOptions } from \"./otel-exporter.type\";\n\nconst EXPORTER_NAME = \"otel\";\nconst DEFAULT_TRACER_NAME = \"@warlock.js/ai-panoptic\";\n\n// ============================================================\n// Lazily-loaded @opentelemetry/api (OPTIONAL peer)\n// ============================================================\n\nlet OtelApi: OtelApiModule;\nlet isModuleExists: boolean | null = null;\nlet loadingPromise: Promise<void> | undefined;\n\nconst OTEL_INSTALL_INSTRUCTIONS = `\nThe Panoptic OpenTelemetry exporter requires the @opentelemetry/api package.\nInstall it with:\n\n npm install @opentelemetry/api\n\nOr with your preferred package manager:\n\n pnpm add @opentelemetry/api\n yarn add @opentelemetry/api\n`.trim();\n\n/**\n * Settle the lazy import of `@opentelemetry/api` once, concurrency-safe.\n * A bare `catch` flips the flag to `false`; the curated install string\n * surfaces at use time so a missing SDK never throws a raw module\n * resolution error.\n */\nfunction loadOtel(): 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 // Indirect specifier so TS does not statically resolve the\n // optional `@opentelemetry/api` peer at compile time (it is\n // intentionally not installed). The result is structurally the\n // `OtelApiModule` shim — the exporter only touches that surface.\n const moduleName = \"@opentelemetry/api\";\n OtelApi = (await import(moduleName)) as OtelApiModule;\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 OpenTelemetry\n * spans following the GenAI semantic conventions (`gen_ai.*`\n * attributes). Lazily imports `@opentelemetry/api` 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 on first `export`, not a boot-time stack trace.\n *\n * The exporter emits onto a `Tracer` you supply (or fetches one from the\n * globally registered provider). It never configures the SDK — wiring a\n * `TracerProvider`, processors, and span exporters is the host app's\n * job, exactly as with any other OTel instrumentation.\n *\n * Each {@link TraceSpan} becomes one OTel span with the source span's\n * start/end times and parent relationship reconstructed, so the emitted\n * tree matches the original execution tree.\n *\n * @example\n * // app already set up @opentelemetry/sdk-trace-base + a provider\n * collector.use(otelExporter({ tracerName: \"my-app\", system: \"openai\" }));\n */\nexport function otelExporter(options: OtelExporterOptions = {}): ExporterContract {\n loadOtel();\n\n return {\n name: EXPORTER_NAME,\n async export(trace: Trace): Promise<void> {\n await loadOtel();\n\n if (!isModuleExists) {\n throw new Error(OTEL_INSTALL_INSTRUCTIONS);\n }\n\n const tracer = resolveTracer(options);\n emitSpan(tracer, trace.root, undefined, options);\n },\n };\n}\n\n/**\n * Resolve the `Tracer` spans are emitted on — the caller-supplied one,\n * or one fetched from the globally registered provider by name.\n */\nfunction resolveTracer(options: OtelExporterOptions): OtelTracer {\n if (options.tracer) {\n return options.tracer;\n }\n\n return OtelApi.trace.getTracer(options.tracerName ?? DEFAULT_TRACER_NAME, options.tracerVersion);\n}\n\n/**\n * Recreate one {@link TraceSpan} (and its subtree) as OTel spans. The\n * span is started with the source `startedAt`, parented under\n * `parentContext` so the tree is preserved, annotated with GenAI\n * attributes, given the mapped status, and ended at `endedAt`. Children\n * recurse under this span's context.\n */\nfunction emitSpan(\n tracer: OtelTracer,\n span: TraceSpan,\n parentContext: OtelContext | undefined,\n options: OtelExporterOptions,\n): void {\n const startTime = toEpochMillis(span.startedAt);\n const baseContext = parentContext ?? OtelApi.context.active();\n\n const otelSpan = tracer.startSpan(span.name, { startTime }, baseContext);\n\n applyAttributes(otelSpan, span, options);\n applyStatus(otelSpan, span);\n\n const childContext = OtelApi.trace.setSpan(baseContext, otelSpan);\n\n for (const child of span.children) {\n emitSpan(tracer, child, childContext, options);\n }\n\n otelSpan.end(toEpochMillis(span.endedAt));\n}\n\n/**\n * Set the GenAI + Warlock attributes on the OTel span, defaulting\n * `gen_ai.system` from the exporter options when the span carried none.\n */\nfunction applyAttributes(otelSpan: OtelSpan, span: TraceSpan, options: OtelExporterOptions): void {\n const attributes = toGenAiAttributes(span);\n\n if (options.system !== undefined && attributes[GEN_AI_ATTRIBUTES.system] === undefined) {\n attributes[GEN_AI_ATTRIBUTES.system] = options.system;\n }\n\n // Captured content (only present under `captureContent`) maps onto the\n // GenAI prompt/completion attributes, stringified since OTel attribute\n // values must be primitives.\n if (span.input !== undefined) {\n attributes[GEN_AI_ATTRIBUTES.prompt] = stringifyContent(span.input);\n }\n\n if (span.output !== undefined) {\n attributes[GEN_AI_ATTRIBUTES.completion] = stringifyContent(span.output);\n }\n\n otelSpan.setAttributes(attributes);\n}\n\n/**\n * Coerce a captured content value to a string OTel attribute. Strings\n * pass through; structured values are JSON-encoded (falling back to\n * `String()` if they can't be serialized).\n */\nfunction stringifyContent(value: unknown): string {\n if (typeof value === \"string\") {\n return value;\n }\n\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n\n/**\n * Map the Panoptic span status onto the OTel span status, recording the\n * normalized error as an exception event + ERROR status when present.\n */\nfunction applyStatus(otelSpan: OtelSpan, span: TraceSpan): void {\n const codes: OtelSpanStatusCode = OtelApi.SpanStatusCode;\n\n if (span.error) {\n otelSpan.recordException({\n name: span.error.type,\n message: span.error.message,\n stack: span.error.stack,\n });\n }\n\n // An incomplete run (the model's answer was cut off) has no usable\n // result, so it is an error like a failed one.\n if (span.status === \"failed\" || span.status === \"cancelled\" || span.status === \"incomplete\") {\n otelSpan.setStatus({\n code: codes.ERROR,\n message: span.error?.message,\n });\n return;\n }\n\n // A capped / paused run is neither a failure nor a clean success.\n // Mapping it to OK would let a hit iteration cap read as a healthy\n // run; leave the OTel status UNSET with a descriptive message so the\n // outcome is visible without being miscounted as an error.\n if (span.status === \"max-iterations\" || span.status === \"awaiting-input\") {\n otelSpan.setStatus({\n code: codes.UNSET,\n message:\n span.status === \"max-iterations\"\n ? \"Run hit the iteration cap without an explicit end\"\n : \"Run is awaiting the next input turn\",\n });\n return;\n }\n\n otelSpan.setStatus({ code: codes.OK });\n}\n\n/**\n * Convert an ISO-8601 timestamp to epoch milliseconds — the `TimeInput`\n * form OTel's `startSpan` / `Span.end` accept directly.\n */\nfunction toEpochMillis(isoTimestamp: string): number {\n return new Date(isoTimestamp).getTime();\n}\n"],"mappings":";;;;AAWA,MAAM,gBAAgB;AACtB,MAAM,sBAAsB;AAM5B,IAAI;AACJ,IAAI,iBAAiC;AACrC,IAAI;AAEJ,MAAM,4BAA4B;;;;;;;;;;EAUhC,KAAK;;;;;;;AAQP,SAAS,WAA0B;CACjC,IAAI,mBAAmB,MACrB,OAAO,QAAQ,QAAQ;CAGzB,IAAI,gBACF,OAAO;CAGT,kBAAkB,YAAY;EAC5B,IAAI;GAMF,UAAW,MAAM,OAAO;GACxB,iBAAiB;EACnB,QAAQ;GACN,iBAAiB;EACnB;CACF,EAAC,CAAE;CAEH,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,aAAa,UAA+B,CAAC,GAAqB;CAChF,SAAS;CAET,OAAO;EACL,MAAM;EACN,MAAM,OAAO,OAA6B;GACxC,MAAM,SAAS;GAEf,IAAI,CAAC,gBACH,MAAM,IAAI,MAAM,yBAAyB;GAI3C,SADe,cAAc,OACf,GAAG,MAAM,MAAM,QAAW,OAAO;EACjD;CACF;AACF;;;;;AAMA,SAAS,cAAc,SAA0C;CAC/D,IAAI,QAAQ,QACV,OAAO,QAAQ;CAGjB,OAAO,QAAQ,MAAM,UAAU,QAAQ,cAAc,qBAAqB,QAAQ,aAAa;AACjG;;;;;;;;AASA,SAAS,SACP,QACA,MACA,eACA,SACM;CACN,MAAM,YAAY,cAAc,KAAK,SAAS;CAC9C,MAAM,cAAc,iBAAiB,QAAQ,QAAQ,OAAO;CAE5D,MAAM,WAAW,OAAO,UAAU,KAAK,MAAM,EAAE,UAAU,GAAG,WAAW;CAEvE,gBAAgB,UAAU,MAAM,OAAO;CACvC,YAAY,UAAU,IAAI;CAE1B,MAAM,eAAe,QAAQ,MAAM,QAAQ,aAAa,QAAQ;CAEhE,KAAK,MAAM,SAAS,KAAK,UACvB,SAAS,QAAQ,OAAO,cAAc,OAAO;CAG/C,SAAS,IAAI,cAAc,KAAK,OAAO,CAAC;AAC1C;;;;;AAMA,SAAS,gBAAgB,UAAoB,MAAiB,SAAoC;CAChG,MAAM,aAAa,kBAAkB,IAAI;CAEzC,IAAI,QAAQ,WAAW,UAAa,WAAW,kBAAkB,YAAY,QAC3E,WAAW,kBAAkB,UAAU,QAAQ;CAMjD,IAAI,KAAK,UAAU,QACjB,WAAW,kBAAkB,UAAU,iBAAiB,KAAK,KAAK;CAGpE,IAAI,KAAK,WAAW,QAClB,WAAW,kBAAkB,cAAc,iBAAiB,KAAK,MAAM;CAGzE,SAAS,cAAc,UAAU;AACnC;;;;;;AAOA,SAAS,iBAAiB,OAAwB;CAChD,IAAI,OAAO,UAAU,UACnB,OAAO;CAGT,IAAI;EACF,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC9C,QAAQ;EACN,OAAO,OAAO,KAAK;CACrB;AACF;;;;;AAMA,SAAS,YAAY,UAAoB,MAAuB;CAC9D,MAAM,QAA4B,QAAQ;CAE1C,IAAI,KAAK,OACP,SAAS,gBAAgB;EACvB,MAAM,KAAK,MAAM;EACjB,SAAS,KAAK,MAAM;EACpB,OAAO,KAAK,MAAM;CACpB,CAAC;CAKH,IAAI,KAAK,WAAW,YAAY,KAAK,WAAW,eAAe,KAAK,WAAW,cAAc;EAC3F,SAAS,UAAU;GACjB,MAAM,MAAM;GACZ,SAAS,KAAK,OAAO;EACvB,CAAC;EACD;CACF;CAMA,IAAI,KAAK,WAAW,oBAAoB,KAAK,WAAW,kBAAkB;EACxE,SAAS,UAAU;GACjB,MAAM,MAAM;GACZ,SACE,KAAK,WAAW,mBACZ,sDACA;EACR,CAAC;EACD;CACF;CAEA,SAAS,UAAU,EAAE,MAAM,MAAM,GAAG,CAAC;AACvC;;;;;AAMA,SAAS,cAAc,cAA8B;CACnD,OAAO,IAAI,KAAK,YAAY,CAAC,CAAC,QAAQ;AACxC"}
|
|
@@ -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 };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { walkSpans } from "./walk-spans.mjs";
|
|
2
|
+
import { totalCostUsd } from "./total-cost.mjs";
|
|
3
|
+
import { GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes } from "./gen-ai-attributes.mjs";
|
|
4
|
+
|
|
5
|
+
export { GEN_AI_ATTRIBUTES, WARLOCK_ATTRIBUTES, toGenAiAttributes, totalCostUsd, walkSpans };
|
|
@@ -1,12 +1,9 @@
|
|
|
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
|
|
6
|
-
* summing every populated
|
|
7
|
-
*
|
|
8
|
-
* folds in `reasoning` for forward-safety when a provider prices
|
|
9
|
-
* reasoning tokens as a separate channel. Returns `undefined` when no
|
|
5
|
+
* summing every populated channel (input, output, cache reads, cache
|
|
6
|
+
* writes, reasoning) via `totalCost` from `@warlock.js/ai`. Returns `undefined` when no
|
|
10
7
|
* pricing was attached, so exporters can omit the cost attribute
|
|
11
8
|
* entirely rather than reporting a misleading `0`.
|
|
12
9
|
*
|
|
@@ -14,7 +11,6 @@ import { Usage } from "@warlock.js/ai";
|
|
|
14
11
|
* totalCostUsd({ input: 1, output: 2, total: 3, cost: { input: 0.01, output: 0.04 } });
|
|
15
12
|
* // => 0.05
|
|
16
13
|
*/
|
|
17
|
-
declare function totalCostUsd(usage: Usage): number | undefined;
|
|
14
|
+
export declare function totalCostUsd(usage: Usage): number | undefined;
|
|
18
15
|
//#endregion
|
|
19
|
-
export { totalCostUsd };
|
|
20
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,10 +1,10 @@
|
|
|
1
|
+
import { totalCost } from "@warlock.js/ai";
|
|
2
|
+
|
|
1
3
|
//#region ../../packages/ai-panoptic/src/exporters/utils/total-cost.ts
|
|
2
4
|
/**
|
|
3
5
|
* Collapse a {@link Usage.cost} breakdown into a single USD scalar by
|
|
4
|
-
* summing every populated
|
|
5
|
-
*
|
|
6
|
-
* folds in `reasoning` for forward-safety when a provider prices
|
|
7
|
-
* reasoning tokens as a separate channel. Returns `undefined` when no
|
|
6
|
+
* summing every populated channel (input, output, cache reads, cache
|
|
7
|
+
* writes, reasoning) via `totalCost` from `@warlock.js/ai`. Returns `undefined` when no
|
|
8
8
|
* pricing was attached, so exporters can omit the cost attribute
|
|
9
9
|
* entirely rather than reporting a misleading `0`.
|
|
10
10
|
*
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
* // => 0.05
|
|
14
14
|
*/
|
|
15
15
|
function totalCostUsd(usage) {
|
|
16
|
-
|
|
17
|
-
if (!cost) return;
|
|
18
|
-
return (cost.input ?? 0) + (cost.output ?? 0) + (cost.cachedInput ?? 0) + (cost.cachedOutput ?? 0) + (cost.reasoning ?? 0);
|
|
16
|
+
return totalCost(usage.cost);
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"total-cost.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/total-cost.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"total-cost.mjs","names":[],"sources":["../../../../../../../../../packages/ai-panoptic/src/exporters/utils/total-cost.ts"],"sourcesContent":["import { totalCost, type Usage } from \"@warlock.js/ai\";\n\n/**\n * Collapse a {@link Usage.cost} breakdown into a single USD scalar by\n * summing every populated channel (input, output, cache reads, cache\n * writes, reasoning) via `totalCost` from `@warlock.js/ai`. Returns `undefined` when no\n * pricing was attached, so exporters can omit the cost attribute\n * entirely rather than reporting a misleading `0`.\n *\n * @example\n * totalCostUsd({ input: 1, output: 2, total: 3, cost: { input: 0.01, output: 0.04 } });\n * // => 0.05\n */\nexport function totalCostUsd(usage: Usage): number | undefined {\n return totalCost(usage.cost);\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,aAAa,OAAkC;CAC7D,OAAO,UAAU,MAAM,IAAI;AAC7B"}
|
|
@@ -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panoptic-middleware.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic-middleware.ts"],"sourcesContent":["import type { AgentMiddleware } from \"@warlock.js/ai\";\nimport type { CollectorContract } from \"../contracts/collector.contract\";\n\n/**\n * Build an {@link AgentMiddleware} that feeds a collector from the\n * `execute`- and `supervisor`-level hooks. An alternative wiring to event\n * subscription for apps that already compose cross-cutting concerns\n * through the agent middleware pipeline (`[cache, budget, guardrail,\n * observability]`). Declaring both hook maps lets a single middleware\n * object work uniformly on agents (which fire the `execute` map) and\n * supervisors (which fire the `supervisor` map) — registering it on a\n * supervisor would otherwise install and collect nothing silently.\n *\n * Both terminal paths are covered on each surface:\n * - `after` — fires on a run that produced a result. A run can complete\n * with `result.error` populated (the engine still calls `after`), so\n * the report AND the envelope error are collected; the error type and\n * message land on the root span.\n * - `onError` — fires when the run threw before assembling a result. The\n * error carries the partial result's report on its envelope; when\n * present it is collected, with the error itself threaded onto the\n * root span so failed runs still produce a trace.\n *\n * The hooks never return a value, so they never mutate the agent's /\n * supervisor's result. The `collect` call is fire-and-forget relative to\n * the run — the collector isolates exporter failures internally, and we\n * additionally swallow any rejection here so an observability fault can\n * never surface on the run's hot path.\n *\n * @param collector - the collector traces are fed into.\n * @param name - stable middleware name (kebab-case). Defaults to\n * `\"panoptic\"`.\n */\nexport function createPanopticMiddleware(\n collector: CollectorContract,\n name = \"panoptic\",\n): AgentMiddleware {\n const collectReport = (report: unknown, rootError?: unknown): void => {\n if (!isReport(report)) {\n return;\n }\n\n void collector.collect(report, rootError).catch(() => {\n // Swallow — the collector already isolates exporter failures; this\n // guard keeps an observability fault off the run's hot path.\n });\n };\n\n const onResult = (result: unknown): void => {\n // A run can complete with `result.error` populated (`after` still\n // fires); thread that envelope error onto the root span.\n collectReport(
|
|
1
|
+
{"version":3,"file":"panoptic-middleware.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic-middleware.ts"],"sourcesContent":["import type { AgentMiddleware } from \"@warlock.js/ai\";\nimport type { CollectorContract } from \"../contracts/collector.contract\";\n\n/**\n * Build an {@link AgentMiddleware} that feeds a collector from the\n * `execute`- and `supervisor`-level hooks. An alternative wiring to event\n * subscription for apps that already compose cross-cutting concerns\n * through the agent middleware pipeline (`[cache, budget, guardrail,\n * observability]`). Declaring both hook maps lets a single middleware\n * object work uniformly on agents (which fire the `execute` map) and\n * supervisors (which fire the `supervisor` map) — registering it on a\n * supervisor would otherwise install and collect nothing silently.\n *\n * Both terminal paths are covered on each surface:\n * - `after` — fires on a run that produced a result. A run can complete\n * with `result.error` populated (the engine still calls `after`), so\n * the report AND the envelope error are collected; the error type and\n * message land on the root span.\n * - `onError` — fires when the run threw before assembling a result. The\n * error carries the partial result's report on its envelope; when\n * present it is collected, with the error itself threaded onto the\n * root span so failed runs still produce a trace.\n *\n * The hooks never return a value, so they never mutate the agent's /\n * supervisor's result. The `collect` call is fire-and-forget relative to\n * the run — the collector isolates exporter failures internally, and we\n * additionally swallow any rejection here so an observability fault can\n * never surface on the run's hot path.\n *\n * @param collector - the collector traces are fed into.\n * @param name - stable middleware name (kebab-case). Defaults to\n * `\"panoptic\"`.\n */\nexport function createPanopticMiddleware(\n collector: CollectorContract,\n name = \"panoptic\",\n): AgentMiddleware {\n const collectReport = (report: unknown, rootError?: unknown): void => {\n if (!isReport(report)) {\n return;\n }\n\n void collector.collect(report, rootError).catch(() => {\n // Swallow — the collector already isolates exporter failures; this\n // guard keeps an observability fault off the run's hot path.\n });\n };\n\n const onResult = (result: unknown): void => {\n // A run can complete with `result.error` populated (`after` still\n // fires); thread that envelope error onto the root span.\n collectReport((result as { report?: unknown }).report, (result as { error?: unknown }).error);\n };\n\n const onError = (error: unknown): void => {\n // A failed run's report rides on the error envelope when the engine\n // built one before throwing; collect it so failures trace, threading\n // the error itself onto the root span.\n collectReport((error as { report?: unknown }).report, error);\n };\n\n const terminalHooks = {\n after(_ctx: unknown, result: unknown) {\n onResult(result);\n },\n onError(_ctx: unknown, error: unknown) {\n onError(error);\n },\n };\n\n return {\n name,\n execute: terminalHooks as AgentMiddleware[\"execute\"],\n supervisor: terminalHooks as AgentMiddleware[\"supervisor\"],\n };\n}\n\n/**\n * Narrow an unknown value to a `BaseReport`-shaped object. Structural\n * (checks the lineage fields the collector reads) so it accepts any\n * primitive's report subtype without importing each concrete type.\n */\nfunction isReport(value: unknown): value is import(\"@warlock.js/ai\").BaseReport {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { runId?: unknown }).runId === \"string\" &&\n typeof (value as { rootRunId?: unknown }).rootRunId === \"string\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,yBACd,WACA,OAAO,YACU;CACjB,MAAM,iBAAiB,QAAiB,cAA8B;EACpE,IAAI,CAAC,SAAS,MAAM,GAClB;EAGF,AAAK,UAAU,QAAQ,QAAQ,SAAS,CAAC,CAAC,YAAY,CAGtD,CAAC;CACH;CAEA,MAAM,YAAY,WAA0B;EAG1C,cAAe,OAAgC,QAAS,OAA+B,KAAK;CAC9F;CAEA,MAAM,WAAW,UAAyB;EAIxC,cAAe,MAA+B,QAAQ,KAAK;CAC7D;CAEA,MAAM,gBAAgB;EACpB,MAAM,MAAe,QAAiB;GACpC,SAAS,MAAM;EACjB;EACA,QAAQ,MAAe,OAAgB;GACrC,QAAQ,KAAK;EACf;CACF;CAEA,OAAO;EACL;EACA,SAAS;EACT,YAAY;CACd;AACF;;;;;;AAOA,SAAS,SAAS,OAA8D;CAC9E,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA8B,UAAU,YAChD,OAAQ,MAAkC,cAAc;AAE5D"}
|
|
@@ -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"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Panoptic, PanopticOptions } from "./panoptic.type.mjs";
|
|
2
|
-
|
|
3
2
|
//#region ../../packages/ai-panoptic/src/panoptic/panoptic.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Create a Panoptic subscriber — the one-call entry point that wires the
|
|
@@ -31,7 +30,6 @@ import { Panoptic, PanopticOptions } from "./panoptic.type.mjs";
|
|
|
31
30
|
* const result = await orchestrator.execute(input, { sessionId });
|
|
32
31
|
* await observe.collect(result.report);
|
|
33
32
|
*/
|
|
34
|
-
declare function panoptic(options?: PanopticOptions): Panoptic;
|
|
33
|
+
export declare function panoptic(options?: PanopticOptions): Panoptic;
|
|
35
34
|
//#endregion
|
|
36
|
-
export { panoptic };
|
|
37
35
|
//# sourceMappingURL=panoptic.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panoptic.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"panoptic.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8LgB,SAAS,UAAS,kBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panoptic.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic.ts"],"sourcesContent":["import type { AgentMiddleware, BaseReport } from \"@warlock.js/ai\";\nimport { createCollector } from \"../collector/collector\";\nimport type { CollectorContract } from \"../contracts/collector.contract\";\nimport type { ExporterContract } from \"../contracts/exporter.contract\";\nimport type { Trace } from \"../contracts/trace.type\";\nimport { createPanopticMiddleware } from \"./panoptic-middleware\";\nimport type { CompletedEventPayload, PanopticTarget } from \"./panoptic-target.type\";\nimport type { Panoptic, PanopticOptions } from \"./panoptic.type\";\n\n/**\n * Terminal `*.completed` events of every core primitive that carries the\n * finalized `result` (and therefore the `report` tree). These fire once\n * per run regardless of outcome — the matching `*.error` event fires\n * first on failure, then `*.completed` still fires — so subscribing here\n * captures completed, failed, and cancelled runs alike.\n *\n * The orchestrator is intentionally absent: its `orchestrator.turn.*`\n * events carry only session identity, not a result. Collect an\n * orchestrator turn via {@link Panoptic.collect} with\n * `result.report` instead.\n */\nconst DEFAULT_COMPLETED_EVENTS = [\n \"agent.completed\",\n \"workflow.completed\",\n \"supervisor.completed\",\n] as const;\n\n/**\n * The Panoptic subscriber — binds a collector + its exporters to the\n * three feed paths (events, middleware, direct). Instantiated via\n * {@link panoptic}; callers never see `new`.\n */\nclass PanopticSubscriber implements Panoptic {\n public readonly collector: CollectorContract;\n\n private readonly completedEvents: string[];\n\n private readonly middlewareName: string;\n\n public constructor(options: PanopticOptions = {}) {\n this.collector =\n options.collector ??\n createCollector({\n captureContent: options.captureContent,\n redactContent: options.redactContent,\n fullHistory: options.fullHistory,\n onError: options.onError,\n });\n\n for (const exporter of options.exporters ?? []) {\n this.collector.use(exporter);\n }\n\n this.completedEvents
|
|
1
|
+
{"version":3,"file":"panoptic.mjs","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic.ts"],"sourcesContent":["import type { AgentMiddleware, BaseReport } from \"@warlock.js/ai\";\nimport { createCollector } from \"../collector/collector\";\nimport type { CollectorContract } from \"../contracts/collector.contract\";\nimport type { ExporterContract } from \"../contracts/exporter.contract\";\nimport type { Trace } from \"../contracts/trace.type\";\nimport { createPanopticMiddleware } from \"./panoptic-middleware\";\nimport type { CompletedEventPayload, PanopticTarget } from \"./panoptic-target.type\";\nimport type { Panoptic, PanopticOptions } from \"./panoptic.type\";\n\n/**\n * Terminal `*.completed` events of every core primitive that carries the\n * finalized `result` (and therefore the `report` tree). These fire once\n * per run regardless of outcome — the matching `*.error` event fires\n * first on failure, then `*.completed` still fires — so subscribing here\n * captures completed, failed, and cancelled runs alike.\n *\n * The orchestrator is intentionally absent: its `orchestrator.turn.*`\n * events carry only session identity, not a result. Collect an\n * orchestrator turn via {@link Panoptic.collect} with\n * `result.report` instead.\n */\nconst DEFAULT_COMPLETED_EVENTS = [\n \"agent.completed\",\n \"workflow.completed\",\n \"supervisor.completed\",\n] as const;\n\n/**\n * The Panoptic subscriber — binds a collector + its exporters to the\n * three feed paths (events, middleware, direct). Instantiated via\n * {@link panoptic}; callers never see `new`.\n */\nclass PanopticSubscriber implements Panoptic {\n public readonly collector: CollectorContract;\n\n private readonly completedEvents: string[];\n\n private readonly middlewareName: string;\n\n public constructor(options: PanopticOptions = {}) {\n this.collector =\n options.collector ??\n createCollector({\n captureContent: options.captureContent,\n redactContent: options.redactContent,\n fullHistory: options.fullHistory,\n onError: options.onError,\n });\n\n for (const exporter of options.exporters ?? []) {\n this.collector.use(exporter);\n }\n\n this.completedEvents = options.completedEvents ?? [...DEFAULT_COMPLETED_EVENTS];\n this.middlewareName = options.middlewareName ?? \"panoptic\";\n }\n\n public use(exporter: ExporterContract): Panoptic {\n this.collector.use(exporter);\n\n return this;\n }\n\n public attach(target: PanopticTarget): () => void {\n const unsubscribes: Array<() => void> = [];\n\n for (const event of this.completedEvents) {\n const unsubscribe = target.on(event, (payload) => {\n this.handleCompleted(payload);\n });\n\n unsubscribes.push(unsubscribe);\n }\n\n return () => {\n for (const unsubscribe of unsubscribes) {\n unsubscribe();\n }\n };\n }\n\n public middleware(): AgentMiddleware {\n return createPanopticMiddleware(this.collector, this.middlewareName);\n }\n\n public async collect(report: BaseReport): Promise<void> {\n await this.collector.collect(report);\n }\n\n public toTrace(report: BaseReport): Trace {\n return this.collector.toTrace(report);\n }\n\n public async flush(): Promise<void> {\n await this.collector.flush();\n }\n\n public async shutdown(): Promise<void> {\n await this.collector.shutdown();\n }\n\n /**\n * Project one terminal `*.completed` payload's report into the\n * collector. The fan-out is fire-and-forget relative to the emitting\n * run: the core swallows handler errors, the collector isolates\n * exporter failures, and we additionally guard the rejection here so an\n * observability fault never escapes the event handler.\n */\n private handleCompleted(payload: unknown): void {\n const report = readReport(payload);\n\n if (!report) {\n return;\n }\n\n // The failing run's typed error lives on the result envelope\n // (`BaseResult.error`), never on the report tree — thread it so a\n // failed root span carries its error type/message.\n const rootError = readResultError(payload);\n\n void this.collector.collect(report, rootError).catch(() => {\n // Swallow — see the JSDoc above. Never surface on the run.\n });\n }\n}\n\n/**\n * Read the envelope error off a primitive's completed-event payload\n * (`{ result: { error } }`). The error rides on the result envelope, not\n * the report tree, so the collector needs it separately to populate a\n * failed root span. Returns `undefined` when the run succeeded.\n */\nfunction readResultError(payload: unknown): unknown {\n const result = (payload as Partial<CompletedEventPayload>)?.result;\n\n return (result as { error?: unknown })?.error;\n}\n\n/**\n * Read the `report` tree off a primitive's completed-event payload.\n * Structural (no concrete-type import) so it accepts every primitive's\n * result subtype; returns `undefined` when the payload isn't the\n * expected `{ result: { report } }` shape.\n */\nfunction readReport(payload: unknown): BaseReport | undefined {\n const result = (payload as Partial<CompletedEventPayload>)?.result;\n const report = (result as { report?: unknown })?.report;\n\n if (\n typeof report === \"object\" &&\n report !== null &&\n typeof (report as { runId?: unknown }).runId === \"string\" &&\n typeof (report as { rootRunId?: unknown }).rootRunId === \"string\"\n ) {\n return report as BaseReport;\n }\n\n return undefined;\n}\n\n/**\n * Create a Panoptic subscriber — the one-call entry point that wires the\n * observability pipeline. Pass the exporters you want and Panoptic\n * builds a collector, registers them, and hands back a subscriber you can\n * `attach()` to any agent/workflow/supervisor, install as agent\n * `middleware()`, or feed reports to directly with `collect()`.\n *\n * @example\n * // Attach to a primitive's event stream (captures every run):\n * const observe = panoptic({\n * exporters: [consoleExporter(), otelExporter({ tracerName: \"app\" })],\n * });\n *\n * const agent = ai.agent({ model });\n * const detach = observe.attach(agent);\n *\n * await agent.execute(\"Summarize this\");\n * // ...later, on shutdown:\n * await observe.shutdown();\n *\n * @example\n * // Or wire it through the agent middleware pipeline:\n * const observe = panoptic({ exporters: [langfuseExporter({ ... })] });\n * const agent = ai.agent({ model, middleware: [observe.middleware()] });\n *\n * @example\n * // Orchestrator turns carry no result-bearing event — collect directly:\n * const result = await orchestrator.execute(input, { sessionId });\n * await observe.collect(result.report);\n */\nexport function panoptic(options: PanopticOptions = {}): Panoptic {\n return new PanopticSubscriber(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAM,2BAA2B;CAC/B;CACA;CACA;AACF;;;;;;AAOA,IAAM,qBAAN,MAA6C;CAC3C,AAAgB;CAEhB,AAAiB;CAEjB,AAAiB;CAEjB,AAAO,YAAY,UAA2B,CAAC,GAAG;EAChD,KAAK,YACH,QAAQ,aACR,gBAAgB;GACd,gBAAgB,QAAQ;GACxB,eAAe,QAAQ;GACvB,aAAa,QAAQ;GACrB,SAAS,QAAQ;EACnB,CAAC;EAEH,KAAK,MAAM,YAAY,QAAQ,aAAa,CAAC,GAC3C,KAAK,UAAU,IAAI,QAAQ;EAG7B,KAAK,kBAAkB,QAAQ,mBAAmB,CAAC,GAAG,wBAAwB;EAC9E,KAAK,iBAAiB,QAAQ,kBAAkB;CAClD;CAEA,AAAO,IAAI,UAAsC;EAC/C,KAAK,UAAU,IAAI,QAAQ;EAE3B,OAAO;CACT;CAEA,AAAO,OAAO,QAAoC;EAChD,MAAM,eAAkC,CAAC;EAEzC,KAAK,MAAM,SAAS,KAAK,iBAAiB;GACxC,MAAM,cAAc,OAAO,GAAG,QAAQ,YAAY;IAChD,KAAK,gBAAgB,OAAO;GAC9B,CAAC;GAED,aAAa,KAAK,WAAW;EAC/B;EAEA,aAAa;GACX,KAAK,MAAM,eAAe,cACxB,YAAY;EAEhB;CACF;CAEA,AAAO,aAA8B;EACnC,OAAO,yBAAyB,KAAK,WAAW,KAAK,cAAc;CACrE;CAEA,MAAa,QAAQ,QAAmC;EACtD,MAAM,KAAK,UAAU,QAAQ,MAAM;CACrC;CAEA,AAAO,QAAQ,QAA2B;EACxC,OAAO,KAAK,UAAU,QAAQ,MAAM;CACtC;CAEA,MAAa,QAAuB;EAClC,MAAM,KAAK,UAAU,MAAM;CAC7B;CAEA,MAAa,WAA0B;EACrC,MAAM,KAAK,UAAU,SAAS;CAChC;;;;;;;;CASA,AAAQ,gBAAgB,SAAwB;EAC9C,MAAM,SAAS,WAAW,OAAO;EAEjC,IAAI,CAAC,QACH;EAMF,MAAM,YAAY,gBAAgB,OAAO;EAEzC,AAAK,KAAK,UAAU,QAAQ,QAAQ,SAAS,CAAC,CAAC,YAAY,CAE3D,CAAC;CACH;AACF;;;;;;;AAQA,SAAS,gBAAgB,SAA2B;CAGlD,QAFgB,SAA4C,OAE9C,EAA0B;AAC1C;;;;;;;AAQA,SAAS,WAAW,SAA0C;CAE5D,MAAM,UADU,SAA4C,OACtC,EAA2B;CAEjD,IACE,OAAO,WAAW,YAClB,WAAW,QACX,OAAQ,OAA+B,UAAU,YACjD,OAAQ,OAAmC,cAAc,UAEzD,OAAO;AAIX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,SAAS,UAA2B,CAAC,GAAa;CAChE,OAAO,IAAI,mBAAmB,OAAO;AACvC"}
|
|
@@ -5,7 +5,6 @@ import { ContentRedactor } from "../collector/content-capture.type.mjs";
|
|
|
5
5
|
import { ExporterErrorHandler } from "../collector/collector.mjs";
|
|
6
6
|
import { PanopticTarget } from "./panoptic-target.type.mjs";
|
|
7
7
|
import { AgentMiddleware, BaseReport } from "@warlock.js/ai";
|
|
8
|
-
|
|
9
8
|
//#region ../../packages/ai-panoptic/src/panoptic/panoptic.type.d.ts
|
|
10
9
|
/**
|
|
11
10
|
* Options for the {@link panoptic} subscriber factory.
|
|
@@ -15,7 +14,7 @@ import { AgentMiddleware, BaseReport } from "@warlock.js/ai";
|
|
|
15
14
|
* a pre-built collector (e.g. one that already has a store registered);
|
|
16
15
|
* any `exporters` supplied are registered onto it as well.
|
|
17
16
|
*/
|
|
18
|
-
type PanopticOptions = {
|
|
17
|
+
export type PanopticOptions = {
|
|
19
18
|
/**
|
|
20
19
|
* Exporters to register on the collector. Each is deduped by
|
|
21
20
|
* `ExporterContract.name` (registering the same exporter twice is a
|
|
@@ -92,8 +91,9 @@ type PanopticOptions = {
|
|
|
92
91
|
* All three converge on the same collector, so a trace flows to every
|
|
93
92
|
* registered exporter exactly once per run.
|
|
94
93
|
*/
|
|
95
|
-
type Panoptic = {
|
|
96
|
-
/** The underlying collector — exposed for `use()`, `toTrace()`, etc. */
|
|
94
|
+
export type Panoptic = {
|
|
95
|
+
/** The underlying collector — exposed for `use()`, `toTrace()`, etc. */
|
|
96
|
+
readonly collector: CollectorContract;
|
|
97
97
|
/**
|
|
98
98
|
* Register another exporter on the collector. Returns `this` for
|
|
99
99
|
* chaining; mirrors `CollectorContract.use`.
|
|
@@ -123,10 +123,11 @@ type Panoptic = {
|
|
|
123
123
|
* Pure projection of a report into a {@link Trace} without dispatching
|
|
124
124
|
* — passthrough to `CollectorContract.toTrace`.
|
|
125
125
|
*/
|
|
126
|
-
toTrace(report: BaseReport): Trace;
|
|
127
|
-
|
|
126
|
+
toTrace(report: BaseReport): Trace;
|
|
127
|
+
/** Flush every registered exporter that supports it. */
|
|
128
|
+
flush(): Promise<void>;
|
|
129
|
+
/** Flush and shut down every registered exporter. */
|
|
128
130
|
shutdown(): Promise<void>;
|
|
129
131
|
};
|
|
130
132
|
//#endregion
|
|
131
|
-
export { Panoptic, PanopticOptions };
|
|
132
133
|
//# sourceMappingURL=panoptic.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panoptic.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic.type.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"panoptic.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-panoptic/src/panoptic/panoptic.type.ts"],"mappings":";;;;;;;;;;;;;;;;YAgBY;;;;;;EAMV,YAAY;;;;;;;EAOZ,YAAY;;;;;;;;;EASZ;;;;;;EAMA;;;;;;;;;;EAUA;;;;;;EAMA,gBAAgB;;;;;;EAMhB;;;;;;;;EAQA,UAAU;;;;;;;;;;;;;;;;;;;YAoBA;;WAED,WAAW;;;;;EAKpB,IAAI,UAAU,mBAAmB;;;;;;;EAOjC,OAAO,QAAQ;;;;;;;EAOf,cAAc;;;;;;EAMd,QAAQ,QAAQ,aAAa;;;;;EAK7B,QAAQ,QAAQ,aAAa;;EAE7B,SAAS;;EAET,YAAY"}
|