@warlock.js/ai-panoptic 4.3.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 +47 -0
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/cjs/index.cjs +1370 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/collector/collector.d.mts +19 -0
- package/esm/collector/collector.d.mts.map +1 -0
- package/esm/collector/collector.mjs +89 -0
- package/esm/collector/collector.mjs.map +1 -0
- package/esm/collector/extract-span-attributes.d.mts +29 -0
- package/esm/collector/extract-span-attributes.d.mts.map +1 -0
- package/esm/collector/extract-span-attributes.mjs +76 -0
- package/esm/collector/extract-span-attributes.mjs.map +1 -0
- package/esm/collector/index.d.mts +5 -0
- package/esm/collector/normalize-error.d.mts +27 -0
- package/esm/collector/normalize-error.d.mts.map +1 -0
- package/esm/collector/normalize-error.mjs +49 -0
- package/esm/collector/normalize-error.mjs.map +1 -0
- package/esm/collector/report-to-span.d.mts +31 -0
- package/esm/collector/report-to-span.d.mts.map +1 -0
- package/esm/collector/report-to-span.mjs +53 -0
- package/esm/collector/report-to-span.mjs.map +1 -0
- package/esm/collector/report-to-trace.d.mts +35 -0
- package/esm/collector/report-to-trace.d.mts.map +1 -0
- package/esm/collector/report-to-trace.mjs +53 -0
- package/esm/collector/report-to-trace.mjs.map +1 -0
- package/esm/contracts/collector.contract.d.mts +63 -0
- package/esm/contracts/collector.contract.d.mts.map +1 -0
- package/esm/contracts/exporter.contract.d.mts +76 -0
- package/esm/contracts/exporter.contract.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +3 -0
- package/esm/contracts/trace.type.d.mts +122 -0
- package/esm/contracts/trace.type.d.mts.map +1 -0
- package/esm/exporters/console/console-exporter.d.mts +25 -0
- package/esm/exporters/console/console-exporter.d.mts.map +1 -0
- package/esm/exporters/console/console-exporter.mjs +79 -0
- package/esm/exporters/console/console-exporter.mjs.map +1 -0
- package/esm/exporters/console/console-exporter.type.d.mts +36 -0
- package/esm/exporters/console/console-exporter.type.d.mts.map +1 -0
- package/esm/exporters/console/format-span-line.d.mts +17 -0
- package/esm/exporters/console/format-span-line.d.mts.map +1 -0
- package/esm/exporters/console/format-span-line.mjs +41 -0
- package/esm/exporters/console/format-span-line.mjs.map +1 -0
- package/esm/exporters/console/index.d.mts +3 -0
- package/esm/exporters/file/file-exporter.d.mts +23 -0
- package/esm/exporters/file/file-exporter.d.mts.map +1 -0
- package/esm/exporters/file/file-exporter.mjs +93 -0
- package/esm/exporters/file/file-exporter.mjs.map +1 -0
- package/esm/exporters/file/file-exporter.type.d.mts +39 -0
- package/esm/exporters/file/file-exporter.type.d.mts.map +1 -0
- package/esm/exporters/file/index.d.mts +2 -0
- package/esm/exporters/index.d.mts +12 -0
- package/esm/exporters/index.mjs +12 -0
- package/esm/exporters/langfuse/index.d.mts +2 -0
- package/esm/exporters/langfuse/index.mjs +3 -0
- package/esm/exporters/langfuse/langfuse-exporter.d.mts +27 -0
- package/esm/exporters/langfuse/langfuse-exporter.d.mts.map +1 -0
- package/esm/exporters/langfuse/langfuse-exporter.mjs +158 -0
- package/esm/exporters/langfuse/langfuse-exporter.mjs.map +1 -0
- package/esm/exporters/langfuse/langfuse-exporter.type.d.mts +90 -0
- package/esm/exporters/langfuse/langfuse-exporter.type.d.mts.map +1 -0
- package/esm/exporters/otel/index.d.mts +2 -0
- package/esm/exporters/otel/index.mjs +3 -0
- package/esm/exporters/otel/otel-exporter.d.mts +29 -0
- package/esm/exporters/otel/otel-exporter.d.mts.map +1 -0
- package/esm/exporters/otel/otel-exporter.mjs +142 -0
- package/esm/exporters/otel/otel-exporter.mjs.map +1 -0
- package/esm/exporters/otel/otel-exporter.type.d.mts +39 -0
- package/esm/exporters/otel/otel-exporter.type.d.mts.map +1 -0
- package/esm/exporters/utils/gen-ai-attributes.d.mts +65 -0
- package/esm/exporters/utils/gen-ai-attributes.d.mts.map +1 -0
- package/esm/exporters/utils/gen-ai-attributes.mjs +88 -0
- package/esm/exporters/utils/gen-ai-attributes.mjs.map +1 -0
- package/esm/exporters/utils/index.d.mts +3 -0
- package/esm/exporters/utils/total-cost.d.mts +20 -0
- package/esm/exporters/utils/total-cost.d.mts.map +1 -0
- package/esm/exporters/utils/total-cost.mjs +23 -0
- package/esm/exporters/utils/total-cost.mjs.map +1 -0
- package/esm/exporters/utils/walk-spans.d.mts +18 -0
- package/esm/exporters/utils/walk-spans.d.mts.map +1 -0
- package/esm/exporters/utils/walk-spans.mjs +21 -0
- package/esm/exporters/utils/walk-spans.mjs.map +1 -0
- package/esm/index.d.mts +31 -0
- package/esm/index.mjs +22 -0
- package/esm/panoptic/index.d.mts +4 -0
- package/esm/panoptic/panoptic-middleware.d.mts +38 -0
- package/esm/panoptic/panoptic-middleware.d.mts.map +1 -0
- package/esm/panoptic/panoptic-middleware.mjs +68 -0
- package/esm/panoptic/panoptic-middleware.mjs.map +1 -0
- package/esm/panoptic/panoptic-target.type.d.mts +53 -0
- package/esm/panoptic/panoptic-target.type.d.mts.map +1 -0
- package/esm/panoptic/panoptic.d.mts +37 -0
- package/esm/panoptic/panoptic.d.mts.map +1 -0
- package/esm/panoptic/panoptic.mjs +134 -0
- package/esm/panoptic/panoptic.mjs.map +1 -0
- package/esm/panoptic/panoptic.type.d.mts +100 -0
- package/esm/panoptic/panoptic.type.d.mts.map +1 -0
- package/esm/store/in-memory-trace-store.d.mts +32 -0
- package/esm/store/in-memory-trace-store.d.mts.map +1 -0
- package/esm/store/in-memory-trace-store.mjs +134 -0
- package/esm/store/in-memory-trace-store.mjs.map +1 -0
- package/esm/store/index.d.mts +6 -0
- package/esm/store/index.mjs +5 -0
- package/esm/store/match-trace.d.mts +21 -0
- package/esm/store/match-trace.d.mts.map +1 -0
- package/esm/store/match-trace.mjs +44 -0
- package/esm/store/match-trace.mjs.map +1 -0
- package/esm/store/sum-usage.d.mts +34 -0
- package/esm/store/sum-usage.d.mts.map +1 -0
- package/esm/store/sum-usage.mjs +65 -0
- package/esm/store/sum-usage.mjs.map +1 -0
- package/esm/store/trace-aggregate.type.d.mts +51 -0
- package/esm/store/trace-aggregate.type.d.mts.map +1 -0
- package/esm/store/trace-query.type.d.mts +45 -0
- package/esm/store/trace-query.type.d.mts.map +1 -0
- package/esm/store/trace-store.contract.d.mts +55 -0
- package/esm/store/trace-store.contract.d.mts.map +1 -0
- package/llms-full.txt +450 -0
- package/llms.txt +11 -0
- package/package.json +40 -0
- package/skills/README.md +17 -0
- package/skills/export-traces/SKILL.md +152 -0
- package/skills/observe-with-panoptic/SKILL.md +128 -0
- package/skills/query-traces/SKILL.md +152 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog — @warlock.js/ai-panoptic
|
|
2
|
+
|
|
3
|
+
All notable changes to `@warlock.js/ai-panoptic` are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## 4.3.0 - 2026-06-21
|
|
10
|
+
|
|
11
|
+
Initial release — observability collector + exporters for `@warlock.js/ai`.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `panoptic()` — the one-call subscriber factory. Builds a collector, registers exporters, and feeds traces three ways: `attach()` to an agent/workflow/supervisor `*.completed` event stream, `middleware()` for the agent pipeline, and `collect()` for a report directly (e.g. an orchestrator turn). Plus `use()`, `toTrace()`, `flush()`, `shutdown()`, and a `collector` accessor.
|
|
16
|
+
- `createPanopticMiddleware()` — the underlying `AgentMiddleware` adapter feeding the collector from the `execute.after` / `execute.onError` hooks
|
|
17
|
+
- `Panoptic` / `PanopticOptions` / `PanopticTarget` / `CompletedEventPayload` types
|
|
18
|
+
- `panoptic` + middleware + types exported from the root barrel
|
|
19
|
+
- `scripts/generate-llms.mjs` and the generated `llms.txt` / `llms-full.txt` projections of `skills/`
|
|
20
|
+
- `skills/observe-with-panoptic/SKILL.md` — wiring the subscriber into a run
|
|
21
|
+
- `consoleExporter()` — zero-dep exporter printing trace summary or full span tree
|
|
22
|
+
- `fileExporter()` — zero-dep buffered JSON-Lines exporter with `flushEvery`
|
|
23
|
+
- `otelExporter()` — OpenTelemetry exporter mapping spans to GenAI semantic conventions (`gen_ai.*`)
|
|
24
|
+
- `langfuseExporter()` — Langfuse exporter mapping spans to traces, generations, and spans
|
|
25
|
+
- `toGenAiAttributes()` / `walkSpans()` / `totalCostUsd()` exporter utilities
|
|
26
|
+
- Optional peers `@opentelemetry/api` and `langfuse` are lazily imported by their exporters
|
|
27
|
+
- `createCollector()` — consumes the core `BaseReport` tree, projects it to a `Trace`, fans out to exporters
|
|
28
|
+
- `reportToTrace()` / `reportToSpan()` pure projections of a report node to spans
|
|
29
|
+
- `createInMemoryTraceStore()` — queryable in-memory store, doubles as an `ExporterContract`
|
|
30
|
+
- `TraceStoreContract` with `query` / `aggregate` by runId, sessionId, status, and time window
|
|
31
|
+
- `TraceQuery` and `TraceAggregate` types for slicing and rolling up usage + cost
|
|
32
|
+
- `sumUsage()` usage + cost rollup across stored traces, backed by core `accumulateCost`
|
|
33
|
+
- optional `capacity` cap on the in-memory store with FIFO eviction
|
|
34
|
+
- contract surface: `CollectorContract`, `ExporterContract`, and the vendor-neutral trace types `Trace` / `TraceSpan` / `TraceSpanError`, derived 1:1 from the core `BaseReport` tree and event stream
|
|
35
|
+
- `@opentelemetry/api`, `@opentelemetry/sdk-trace-base`, and `langfuse` declared as OPTIONAL peer dependencies (lazily imported by the exporters that need them)
|
|
36
|
+
- `skills/query-traces/SKILL.md` — dedicated skill for the in-memory queryable trace store (`createInMemoryTraceStore`, `query` / `aggregate`, `TraceQuery` / `TraceAggregate`, `capacity` FIFO eviction, `sumUsage` / `emptyUsage` / `matchTrace` helpers)
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- `skills/export-traces/SKILL.md` — OTel attribute notes: `gen_ai.system` / `gen_ai.request.model` / `gen_ai.operation.name` are only forwarded when the span's attribute bag carried them (`system` backfilled from options), never invented
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- **Failed root runs now carry their error in every export** — `collect()` / `reportToTrace()` / `attach()` / `middleware()` thread the result-envelope error (`BaseResult.error`) onto the root span (which `BaseReport` doesn't carry); `collect()` / `reportToTrace()` gained an optional `rootError` parameter
|
|
45
|
+
- **Per-span exporters now receive every span** — the collector's `dispatch` walks the finalized tree (`walkSpans`), invoking `exportSpan` once per node (a post-completion per-span projection, not live streaming)
|
|
46
|
+
- **`panoptic().middleware()` now works on a supervisor** — the middleware declares a `supervisor` hook map (not only `execute`), so `ai.supervisor({ middleware: [observe.middleware()] })` collects a trace
|
|
47
|
+
- `totalCostUsd()` folds in `cost.reasoning`; the Langfuse exporter `end()`s every observation; the OTel exporter maps `max-iterations` / `awaiting-input` to `UNSET` (a hit cap no longer reads as clean success)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Hassan Zohdy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @warlock.js/ai-panoptic
|
|
2
|
+
|
|
3
|
+
Observability collector + exporters for [`@warlock.js/ai`](../ai).
|
|
4
|
+
|
|
5
|
+
Panoptic turns the execution reports that every `@warlock.js/ai`
|
|
6
|
+
primitive already produces (the `BaseReport` tree from a `.execute()` /
|
|
7
|
+
`.invoke()` call) into vendor-neutral traces, then fans them out to
|
|
8
|
+
observability backends — OpenTelemetry, Langfuse, or a custom sink.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @warlock.js/ai @warlock.js/ai-panoptic
|
|
12
|
+
# plus whichever backend SDK you export to (all OPTIONAL peers):
|
|
13
|
+
npm install @opentelemetry/api @opentelemetry/sdk-trace-base # OTel
|
|
14
|
+
npm install langfuse # Langfuse
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
> The backend SDKs are **optional peer dependencies**. They are lazily
|
|
18
|
+
> imported inside the exporter that needs them, so installing
|
|
19
|
+
> `@warlock.js/ai-panoptic` never pulls in an SDK you don't use.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
`panoptic(...)` is the one-call entry point. It builds a collector, registers
|
|
24
|
+
your exporters, and hands back a subscriber you can feed three ways — all
|
|
25
|
+
converging on the same collector so each run reaches every exporter exactly once.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { ai } from "@warlock.js/ai";
|
|
29
|
+
import { panoptic, consoleExporter, otelExporter } from "@warlock.js/ai-panoptic";
|
|
30
|
+
|
|
31
|
+
const observe = panoptic({
|
|
32
|
+
exporters: [consoleExporter({ tree: true }), otelExporter({ tracerName: "my-app" })],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// 1) Attach to an agent/workflow/supervisor event stream — every run is captured.
|
|
36
|
+
const agent = ai.agent({ model });
|
|
37
|
+
const detach = observe.attach(agent);
|
|
38
|
+
|
|
39
|
+
await agent.execute("Summarize this");
|
|
40
|
+
|
|
41
|
+
// ...later, on teardown:
|
|
42
|
+
detach();
|
|
43
|
+
await observe.shutdown();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// 2) Or wire it through the agent middleware pipeline:
|
|
48
|
+
const agent = ai.agent({ model, middleware: [observe.middleware()] });
|
|
49
|
+
|
|
50
|
+
// 3) Or feed a report directly (the orchestrator turn carries no result event):
|
|
51
|
+
const result = await orchestrator.execute(input, { sessionId });
|
|
52
|
+
await observe.collect(result.report);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
By default `attach` subscribes to `agent.completed` / `workflow.completed` /
|
|
56
|
+
`supervisor.completed` — the terminal events that fire once per run (completed,
|
|
57
|
+
failed, or cancelled) carrying the finalized report. An observability fault is
|
|
58
|
+
fully isolated: a throwing exporter never crashes or blocks the AI run. See
|
|
59
|
+
[`skills/observe-with-panoptic`](./skills/observe-with-panoptic/SKILL.md) for the
|
|
60
|
+
three feed paths in depth, `completedEvents` overrides, and bring-your-own
|
|
61
|
+
collector/store wiring.
|
|
62
|
+
|
|
63
|
+
## Concepts
|
|
64
|
+
|
|
65
|
+
- **Collector** (`CollectorContract`) — the source end. Ingests a core
|
|
66
|
+
`BaseReport` tree, projects it into a `Trace`, and dispatches that
|
|
67
|
+
trace to every registered exporter. Wire it into your agents via the
|
|
68
|
+
`onComplete` report hook.
|
|
69
|
+
- **Trace / TraceSpan** (`Trace`, `TraceSpan`) — the vendor-neutral
|
|
70
|
+
projection of a `BaseReport`. A `TraceSpan` mirrors one execution node
|
|
71
|
+
(identity, timing, status, rolled-up `usage`, error) in the span
|
|
72
|
+
vocabulary shared across observability backends.
|
|
73
|
+
- **Exporter** (`ExporterContract`) — the sink end. Translates traces
|
|
74
|
+
into a backend's wire format (`export` per trace, optional
|
|
75
|
+
`exportSpan` for live streaming, `flush` / `shutdown` for draining).
|
|
76
|
+
|
|
77
|
+
## Exporters
|
|
78
|
+
|
|
79
|
+
Four exporters ship today, each a factory returning an `ExporterContract`:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import {
|
|
83
|
+
consoleExporter, // zero-dep — print trace summary or full span tree
|
|
84
|
+
fileExporter, // zero-dep — append traces as JSON Lines, buffered
|
|
85
|
+
otelExporter, // OpenTelemetry — gen_ai.* semantic conventions (lazy @opentelemetry/api)
|
|
86
|
+
langfuseExporter, // Langfuse — traces + generations (lazy langfuse)
|
|
87
|
+
} from "@warlock.js/ai-panoptic";
|
|
88
|
+
|
|
89
|
+
collector
|
|
90
|
+
.use(consoleExporter({ tree: true }))
|
|
91
|
+
.use(fileExporter({ path: "storage/traces.jsonl" }))
|
|
92
|
+
.use(otelExporter({ tracerName: "my-app", system: "openai" }))
|
|
93
|
+
.use(langfuseExporter({ publicKey: "pk-...", secretKey: "sk-..." }));
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`otelExporter` and `langfuseExporter` lazily import their SDK, so it stays
|
|
97
|
+
an optional peer — a missing SDK surfaces as a curated "install this"
|
|
98
|
+
error on first export, never a boot-time stack trace. See
|
|
99
|
+
[`skills/export-traces`](./skills/export-traces/SKILL.md) for the full
|
|
100
|
+
mapping (GenAI attribute keys, generation-vs-span rules) and how to write
|
|
101
|
+
a custom exporter.
|
|
102
|
+
|
|
103
|
+
## Tests
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm test
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|