@warlock.js/ai-panoptic 5.52.0 → 5.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/cjs/index.cjs +592 -424
- package/cjs/index.cjs.map +1 -1
- package/esm/config/apply-panoptic-config.d.mts.map +1 -1
- package/esm/config/apply-panoptic-config.mjs +9 -3
- package/esm/config/apply-panoptic-config.mjs.map +1 -1
- package/esm/config/panoptic-config.type.d.mts +7 -0
- package/esm/config/panoptic-config.type.d.mts.map +1 -1
- package/esm/dashboard/index.d.mts +1 -0
- package/esm/dashboard/index.mjs +1 -1
- package/esm/dashboard/parse-query.mjs +23 -1
- package/esm/dashboard/parse-query.mjs.map +1 -1
- package/esm/dashboard/serve.mjs +55 -10
- package/esm/dashboard/serve.mjs.map +1 -1
- package/esm/dashboard/trace-summary.d.mts +24 -0
- package/esm/dashboard/trace-summary.d.mts.map +1 -0
- package/esm/dashboard/trace-summary.mjs +27 -0
- package/esm/dashboard/trace-summary.mjs.map +1 -0
- package/esm/dashboard/ui.html.mjs +68 -18
- package/esm/dashboard/ui.html.mjs.map +1 -1
- package/esm/index.d.mts +2 -1
- package/esm/index.mjs +1 -1
- package/esm/store/cache-trace-store.d.mts.map +1 -1
- package/esm/store/cache-trace-store.mjs +37 -17
- package/esm/store/cache-trace-store.mjs.map +1 -1
- package/esm/store/in-memory-trace-store.d.mts.map +1 -1
- package/esm/store/in-memory-trace-store.mjs +2 -9
- package/esm/store/in-memory-trace-store.mjs.map +1 -1
- package/esm/store/sort-newest-first.mjs +14 -0
- package/esm/store/sort-newest-first.mjs.map +1 -0
- package/llms-full.txt +9 -9
- package/llms.txt +1 -1
- package/package.json +4 -4
- package/skills/use-local-dashboard/SKILL.md +9 -9
package/cjs/index.cjs
CHANGED
|
@@ -550,6 +550,18 @@ function toEpoch(bound) {
|
|
|
550
550
|
return Date.parse(bound);
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region ../../packages/ai-panoptic/src/store/sort-newest-first.ts
|
|
555
|
+
/**
|
|
556
|
+
* Sort traces newest-started first, in place. Each `startedAt` is parsed
|
|
557
|
+
* once up front instead of twice per comparison.
|
|
558
|
+
*/
|
|
559
|
+
function sortNewestFirst(traces) {
|
|
560
|
+
const startedAt = /* @__PURE__ */ new Map();
|
|
561
|
+
for (const trace of traces) startedAt.set(trace, Date.parse(trace.startedAt));
|
|
562
|
+
return traces.sort((left, right) => (startedAt.get(right) ?? NaN) - (startedAt.get(left) ?? NaN));
|
|
563
|
+
}
|
|
564
|
+
|
|
553
565
|
//#endregion
|
|
554
566
|
//#region ../../packages/ai-panoptic/src/store/sum-usage.ts
|
|
555
567
|
/** Return an independent all-channel usage rollup, preserving hosted-tool counters. */
|
|
@@ -626,6 +638,15 @@ var CacheTraceStore = class {
|
|
|
626
638
|
resolvedDriver;
|
|
627
639
|
driverPending;
|
|
628
640
|
onError;
|
|
641
|
+
/**
|
|
642
|
+
* Every cache write runs on this one chain, in `add` order, so an older
|
|
643
|
+
* index can never land after a newer one.
|
|
644
|
+
*/
|
|
645
|
+
writes = Promise.resolve();
|
|
646
|
+
/** Trace writes queued on {@link writes} and not yet finished. */
|
|
647
|
+
pendingWrites = 0;
|
|
648
|
+
/** The persisted index is behind the mirror and must be rewritten. */
|
|
649
|
+
indexDirty = false;
|
|
629
650
|
constructor(input, options = {}) {
|
|
630
651
|
this.input = input;
|
|
631
652
|
this.prefix = options.prefix ?? DEFAULT_PREFIX;
|
|
@@ -665,10 +686,11 @@ var CacheTraceStore = class {
|
|
|
665
686
|
add(trace) {
|
|
666
687
|
this.mirror.delete(trace.traceId);
|
|
667
688
|
this.mirror.set(trace.traceId, trace);
|
|
668
|
-
const addedAt = this.addCounter;
|
|
669
689
|
this.addCounter += 1;
|
|
670
690
|
const evicted = this.evictOverflow();
|
|
671
|
-
this.
|
|
691
|
+
this.indexDirty = true;
|
|
692
|
+
this.pendingWrites += 1;
|
|
693
|
+
this.enqueue(() => this.persist(trace, evicted));
|
|
672
694
|
}
|
|
673
695
|
/**
|
|
674
696
|
* `ExporterContract.export` — a collector dispatches a completed trace
|
|
@@ -683,7 +705,7 @@ var CacheTraceStore = class {
|
|
|
683
705
|
query(filter) {
|
|
684
706
|
const matched = [];
|
|
685
707
|
for (const trace of this.mirror.values()) if (matchTrace(trace, filter)) matched.push(trace);
|
|
686
|
-
return
|
|
708
|
+
return sortNewestFirst(matched);
|
|
687
709
|
}
|
|
688
710
|
aggregate(filter) {
|
|
689
711
|
const aggregate = {
|
|
@@ -707,20 +729,36 @@ var CacheTraceStore = class {
|
|
|
707
729
|
clear() {
|
|
708
730
|
const ids = [...this.mirror.keys()];
|
|
709
731
|
this.mirror.clear();
|
|
710
|
-
this.
|
|
732
|
+
this.indexDirty = false;
|
|
733
|
+
this.enqueue(() => this.purge(ids));
|
|
734
|
+
}
|
|
735
|
+
/** Append one write to the serial write chain. */
|
|
736
|
+
enqueue(write) {
|
|
737
|
+
this.writes = this.writes.then(write);
|
|
711
738
|
}
|
|
712
739
|
/**
|
|
713
|
-
* Persist one trace
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
740
|
+
* Persist one trace to the cache, optionally removing a trace evicted by
|
|
741
|
+
* the capacity cap, then — when no later trace write is queued — the
|
|
742
|
+
* index rebuilt from the mirror. A burst of adds therefore writes the
|
|
743
|
+
* index once, after every trace in the burst. Best-effort: any cache
|
|
744
|
+
* failure is routed to `onError`, never thrown — the mirror already
|
|
745
|
+
* reflects the write so runtime reads are unaffected.
|
|
717
746
|
*/
|
|
718
|
-
async persist(trace,
|
|
747
|
+
async persist(trace, evictedId) {
|
|
748
|
+
this.pendingWrites -= 1;
|
|
719
749
|
try {
|
|
720
750
|
const driver = await this.resolveDriver();
|
|
721
751
|
await driver.set(this.traceKey(trace.traceId), trace);
|
|
722
752
|
if (evictedId !== void 0) await driver.remove(this.traceKey(evictedId));
|
|
723
|
-
|
|
753
|
+
if (this.pendingWrites === 0 && this.indexDirty) {
|
|
754
|
+
this.indexDirty = false;
|
|
755
|
+
try {
|
|
756
|
+
await driver.set(this.indexKey(), this.buildIndex(this.addCounter - 1));
|
|
757
|
+
} catch (error) {
|
|
758
|
+
this.indexDirty = true;
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
724
762
|
} catch (error) {
|
|
725
763
|
this.reportError(error);
|
|
726
764
|
}
|
|
@@ -796,13 +834,6 @@ var CacheTraceStore = class {
|
|
|
796
834
|
}
|
|
797
835
|
}
|
|
798
836
|
/**
|
|
799
|
-
* Sort matched traces newest-started first. A copy is sorted so the
|
|
800
|
-
* mirror's insertion order (which eviction depends on) is never disturbed.
|
|
801
|
-
*/
|
|
802
|
-
sortNewestFirst(traces) {
|
|
803
|
-
return traces.sort((left, right) => Date.parse(right.startedAt) - Date.parse(left.startedAt));
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
837
|
* Evict oldest-inserted traces from the mirror until within `capacity`.
|
|
807
838
|
* Returns the id of the single evicted trace (the common case — one `add`
|
|
808
839
|
* pushes at most one over the cap) so the caller can remove it from the
|
|
@@ -904,7 +935,7 @@ var InMemoryTraceStore = class {
|
|
|
904
935
|
query(filter) {
|
|
905
936
|
const matched = [];
|
|
906
937
|
for (const trace of this.traces.values()) if (matchTrace(trace, filter)) matched.push(trace);
|
|
907
|
-
return
|
|
938
|
+
return sortNewestFirst(matched);
|
|
908
939
|
}
|
|
909
940
|
aggregate(filter) {
|
|
910
941
|
const aggregate = {
|
|
@@ -949,14 +980,6 @@ var InMemoryTraceStore = class {
|
|
|
949
980
|
}
|
|
950
981
|
}
|
|
951
982
|
/**
|
|
952
|
-
* Sort matched traces newest-started first. A copy is sorted so the
|
|
953
|
-
* underlying insertion order (which eviction depends on) is never
|
|
954
|
-
* disturbed.
|
|
955
|
-
*/
|
|
956
|
-
sortNewestFirst(traces) {
|
|
957
|
-
return traces.sort((left, right) => Date.parse(right.startedAt) - Date.parse(left.startedAt));
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
983
|
* Evict oldest-inserted traces until the store is within `capacity`.
|
|
961
984
|
* No-op when unbounded. The `Map` iterator yields keys in insertion
|
|
962
985
|
* order, so the first key is always the oldest.
|
|
@@ -2026,114 +2049,431 @@ function parseQuery(params) {
|
|
|
2026
2049
|
if (startedBefore !== null && startedBefore.length > 0) query.startedBefore = startedBefore;
|
|
2027
2050
|
return query;
|
|
2028
2051
|
}
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
//#region ../../packages/ai-panoptic/src/dashboard/warlock-logo.ts
|
|
2052
|
+
/** Traces `GET api/traces` returns when the request names no `limit`. */
|
|
2053
|
+
const DEFAULT_TRACE_LIST_LIMIT = 200;
|
|
2032
2054
|
/**
|
|
2033
|
-
*
|
|
2034
|
-
*
|
|
2035
|
-
*
|
|
2036
|
-
*
|
|
2037
|
-
*
|
|
2055
|
+
* Read `?limit=` (a positive integer, default {@link DEFAULT_TRACE_LIST_LIMIT})
|
|
2056
|
+
* and `?full=1` from a `GET api/traces` request. An invalid `limit` falls
|
|
2057
|
+
* back to the default. Page further back with `?startedBefore=` set to the
|
|
2058
|
+
* `startedAt` of the last trace received.
|
|
2059
|
+
*
|
|
2060
|
+
* @example
|
|
2061
|
+
* parseListOptions(new URLSearchParams("limit=50&full=1"));
|
|
2062
|
+
* // → { limit: 50, full: true }
|
|
2038
2063
|
*/
|
|
2039
|
-
const WARLOCK_LOGO_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAkvklEQVR42nV7Z5hb1bX2u9Y+RRpNn7E9425s02wMxgZMNc1AqIkJLTcxgQChpBEC94bwpVwSCCQBEkghECD0DiZwIRBaAhhiMGCDccEejz3F0zQzGrVT9l7fj6MjaQzR8+iRdHTO3nutvcq7yiYikAgAAESASPQJRN8BgLnyO/6fCDCmfC+JoHQ3QEQQkfg+MqbqPwDE0f3xfACiGySay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JESosy3JFHy5/+dOfVOdbrrrDbfrpceVyVOOdJyfo7LoSilvSRULHOcwY4ZL2chFAE2qD3jt8tDnBEOlBuJokMi4ltUhFuvYA1TXEavwAKotrAhIRKTUJgeRam8qYKVgDGA0CdAqQH+pyFEeu+zXxjX4YxxBZWmMpSLuAYlPocZt8buqa3lsqe4Si7MmVDkUvau+RMygXfSrrAUUtdBHx2NLalB1GiXagKg0DRAZiYjOEpXPdpYZHtshqtrJcUdkq84My7jCTqk/8/MkurTOcQxUFRqq3AZVFxYq/33OgKg2OJXui5igMvwc99o1KVEenysnmaJSbUQz7zJ3PHbMrCrdHpfzr143VSVGqpkzrk9w1wPUu4r8f8AFn8uQ6vHGZ+L/8xjxzsVCGif4d13L5611PHM+O+fnrRMA/j9u09405ZezXQAAAABJRU5ErkJggg==";
|
|
2064
|
+
function parseListOptions(params) {
|
|
2065
|
+
const raw = params.get("limit");
|
|
2066
|
+
const parsed = raw === null ? NaN : Number(raw);
|
|
2067
|
+
const limit = Number.isInteger(parsed) && parsed > 0 ? parsed : 200;
|
|
2068
|
+
const full = params.get("full");
|
|
2069
|
+
return {
|
|
2070
|
+
limit,
|
|
2071
|
+
full: full === "1" || full === "true"
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2040
2074
|
|
|
2041
2075
|
//#endregion
|
|
2042
|
-
//#region ../../packages/ai-panoptic/src/dashboard/
|
|
2076
|
+
//#region ../../packages/ai-panoptic/src/dashboard/trace-filter.ts
|
|
2077
|
+
/** Statuses the errors-only toggle keeps. */
|
|
2078
|
+
const ERROR_STATUSES = ["failed", "cancelled"];
|
|
2043
2079
|
/**
|
|
2044
|
-
*
|
|
2045
|
-
*
|
|
2046
|
-
*
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
*
|
|
2052
|
-
*
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2056
|
-
* ids, version, attributes).
|
|
2057
|
-
*
|
|
2058
|
-
* Span input/output is rendered structurally (chat bubbles / key-value /
|
|
2059
|
-
* Markdown), durations in seconds, tokens as ↓input · ↑output · total.
|
|
2060
|
-
* Theme is light / dark / system (persisted to localStorage). All UI
|
|
2061
|
-
* state — selected trace, selected span, collapsed nodes — lives in JS,
|
|
2062
|
-
* NOT the DOM, so the 2s poll never disturbs an open drawer.
|
|
2080
|
+
* Span-attribute keys the collector stamps with prompt-version linkage when
|
|
2081
|
+
* an agent ran against a *named* `ai.prompts` builder. Read here (not
|
|
2082
|
+
* imported) so this pure module stays decoupled from the collector.
|
|
2083
|
+
*/
|
|
2084
|
+
const PROMPT_NAME_ATTR = "agent.promptName";
|
|
2085
|
+
const PROMPT_VERSION_ATTR = "agent.promptVersion";
|
|
2086
|
+
/**
|
|
2087
|
+
* The `name@version` prompt key a trace falls under, read from its root
|
|
2088
|
+
* span's prompt-version-linkage attributes (`agent.promptName` /
|
|
2089
|
+
* `agent.promptVersion`). Returns `undefined` when the run carried no named
|
|
2090
|
+
* prompt (raw-string / anonymous / no prompt), so callers can bucket those
|
|
2091
|
+
* under a synthetic "no prompt" key or skip them.
|
|
2063
2092
|
*
|
|
2064
|
-
* The
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2093
|
+
* The version is included so two runs of the same prompt name at different
|
|
2094
|
+
* versions are distinct keys — that is the whole point of the linkage: to
|
|
2095
|
+
* group / filter by the *exact* prompt revision that produced a run.
|
|
2096
|
+
*/
|
|
2097
|
+
function tracePromptKey(trace) {
|
|
2098
|
+
const attributes = trace.root.attributes;
|
|
2099
|
+
if (attributes === void 0) return;
|
|
2100
|
+
const name = attributes[PROMPT_NAME_ATTR];
|
|
2101
|
+
if (typeof name !== "string" || name.length === 0) return;
|
|
2102
|
+
const version = attributes[PROMPT_VERSION_ATTR];
|
|
2103
|
+
return `${name}@${typeof version === "string" && version.length > 0 ? version : "1"}`;
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Does a single trace pass the given filter? Pure predicate — all
|
|
2107
|
+
* conditions are ANDed; an unset field never excludes. Used by
|
|
2108
|
+
* {@link filterTraces} and mirrored by the dashboard's inlined JS.
|
|
2109
|
+
*/
|
|
2110
|
+
function matchesFilter(trace, filter) {
|
|
2111
|
+
const root = trace.root;
|
|
2112
|
+
if (filter.errorsOnly === true && !ERROR_STATUSES.includes(root.status)) return false;
|
|
2113
|
+
if (filter.statuses !== void 0 && filter.statuses.length > 0) {
|
|
2114
|
+
if (!filter.statuses.includes(root.status)) return false;
|
|
2115
|
+
}
|
|
2116
|
+
if (filter.types !== void 0 && filter.types.length > 0) {
|
|
2117
|
+
if (!filter.types.includes(root.type)) return false;
|
|
2118
|
+
}
|
|
2119
|
+
if (filter.sessionId !== void 0 && filter.sessionId.length > 0) {
|
|
2120
|
+
if (trace.sessionId !== filter.sessionId) return false;
|
|
2121
|
+
}
|
|
2122
|
+
if (filter.promptKey !== void 0 && filter.promptKey.length > 0) {
|
|
2123
|
+
if (tracePromptKey(trace) !== filter.promptKey) return false;
|
|
2124
|
+
}
|
|
2125
|
+
const text = filter.text?.trim().toLowerCase();
|
|
2126
|
+
if (text !== void 0 && text.length > 0) {
|
|
2127
|
+
if (!`${root.name} ${trace.sessionId ?? ""}`.toLowerCase().includes(text)) return false;
|
|
2128
|
+
}
|
|
2129
|
+
return true;
|
|
2130
|
+
}
|
|
2131
|
+
/** Narrow a trace list to those matching the filter, order preserved. */
|
|
2132
|
+
function filterTraces(traces, filter) {
|
|
2133
|
+
return traces.filter((trace) => matchesFilter(trace, filter));
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* The grouping key a trace falls under when the list is grouped by
|
|
2137
|
+
* session. Traces without a `sessionId` collapse into one synthetic
|
|
2138
|
+
* "(no session)" bucket so they remain visible.
|
|
2139
|
+
*/
|
|
2140
|
+
const NO_SESSION_KEY = "(no session)";
|
|
2141
|
+
/**
|
|
2142
|
+
* Group an (already filtered, newest-first) trace list by session id,
|
|
2143
|
+
* preserving first-seen order of both the groups and the traces within
|
|
2144
|
+
* each. Sessionless traces bucket under {@link NO_SESSION_KEY}.
|
|
2145
|
+
*/
|
|
2146
|
+
function groupBySession(traces) {
|
|
2147
|
+
const order = [];
|
|
2148
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2149
|
+
for (const trace of traces) {
|
|
2150
|
+
const key = trace.sessionId ?? "(no session)";
|
|
2151
|
+
let bucket = byKey.get(key);
|
|
2152
|
+
if (bucket === void 0) {
|
|
2153
|
+
bucket = [];
|
|
2154
|
+
byKey.set(key, bucket);
|
|
2155
|
+
order.push(key);
|
|
2156
|
+
}
|
|
2157
|
+
bucket.push(trace);
|
|
2158
|
+
}
|
|
2159
|
+
return order.map((sessionId) => ({
|
|
2160
|
+
sessionId,
|
|
2161
|
+
traces: byKey.get(sessionId) ?? []
|
|
2162
|
+
}));
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* The grouping key a trace falls under when the list is grouped by prompt
|
|
2166
|
+
* version. Runs that resolved no named prompt collapse into one synthetic
|
|
2167
|
+
* "(no prompt)" bucket so they remain visible.
|
|
2168
|
+
*/
|
|
2169
|
+
const NO_PROMPT_KEY = "(no prompt)";
|
|
2170
|
+
/**
|
|
2171
|
+
* Group an (already filtered, newest-first) trace list by prompt version —
|
|
2172
|
+
* the `name@version` key {@link tracePromptKey} derives from each run's
|
|
2173
|
+
* prompt-version-linkage attributes. Preserves first-seen order of both the
|
|
2174
|
+
* groups and the traces within each. Runs with no named prompt bucket under
|
|
2175
|
+
* {@link NO_PROMPT_KEY}.
|
|
2075
2176
|
*
|
|
2076
|
-
*
|
|
2077
|
-
*
|
|
2177
|
+
* The dashboard offers this as a second group-by dimension beside session,
|
|
2178
|
+
* so a reviewer can see every run of "support@2" together and compare its
|
|
2179
|
+
* cost / failure rate against "support@3".
|
|
2180
|
+
*/
|
|
2181
|
+
function groupByPrompt(traces) {
|
|
2182
|
+
const order = [];
|
|
2183
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2184
|
+
for (const trace of traces) {
|
|
2185
|
+
const key = tracePromptKey(trace) ?? "(no prompt)";
|
|
2186
|
+
let bucket = byKey.get(key);
|
|
2187
|
+
if (bucket === void 0) {
|
|
2188
|
+
bucket = [];
|
|
2189
|
+
byKey.set(key, bucket);
|
|
2190
|
+
order.push(key);
|
|
2191
|
+
}
|
|
2192
|
+
bucket.push(trace);
|
|
2193
|
+
}
|
|
2194
|
+
return order.map((promptKey) => ({
|
|
2195
|
+
promptKey,
|
|
2196
|
+
traces: byKey.get(promptKey) ?? []
|
|
2197
|
+
}));
|
|
2198
|
+
}
|
|
2199
|
+
/**
|
|
2200
|
+
* The grouping key a trace falls under when the list is grouped by root
|
|
2201
|
+
* type. `root.type` is always present, so this is only a defensive
|
|
2202
|
+
* fallback for a malformed trace with no typed root.
|
|
2203
|
+
*/
|
|
2204
|
+
const NO_TYPE_KEY = "(no type)";
|
|
2205
|
+
/**
|
|
2206
|
+
* Group an (already filtered, newest-first) trace list by root type —
|
|
2207
|
+
* the `agent` / `workflow` / `supervisor` / `orchestrator` / `planner` /
|
|
2208
|
+
* `tool` / `batch` / `callback` discriminator on each trace's root span.
|
|
2209
|
+
* Preserves first-seen order of both the groups and the traces within each.
|
|
2078
2210
|
*
|
|
2079
|
-
*
|
|
2080
|
-
*
|
|
2211
|
+
* The dashboard offers this as the coarsest group-by dimension beside
|
|
2212
|
+
* session and prompt: when a benchmark floods the flat list with hundreds
|
|
2213
|
+
* of one primitive (e.g. standalone `agent` runs), this collapses them
|
|
2214
|
+
* behind a per-type header so the structural primitives (the lone planner,
|
|
2215
|
+
* the team, the supervisors) are one click away instead of a scroll past.
|
|
2081
2216
|
*/
|
|
2082
|
-
function
|
|
2083
|
-
const
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
})
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2217
|
+
function groupByType(traces) {
|
|
2218
|
+
const order = [];
|
|
2219
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2220
|
+
for (const trace of traces) {
|
|
2221
|
+
const key = trace.root.type || "(no type)";
|
|
2222
|
+
let bucket = byKey.get(key);
|
|
2223
|
+
if (bucket === void 0) {
|
|
2224
|
+
bucket = [];
|
|
2225
|
+
byKey.set(key, bucket);
|
|
2226
|
+
order.push(key);
|
|
2227
|
+
}
|
|
2228
|
+
bucket.push(trace);
|
|
2229
|
+
}
|
|
2230
|
+
return order.map((type) => ({
|
|
2231
|
+
type,
|
|
2232
|
+
traces: byKey.get(type) ?? []
|
|
2233
|
+
}));
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* Nearest-rank percentile of `values` at `p` (0–100). Returns 0 for an
|
|
2237
|
+
* empty input and sorts a copy so the caller's array is left untouched.
|
|
2238
|
+
*/
|
|
2239
|
+
function percentile(values, p) {
|
|
2240
|
+
if (values.length === 0) return 0;
|
|
2241
|
+
const sorted = values.slice().sort((a, b) => a - b);
|
|
2242
|
+
const rank = Math.ceil(p / 100 * sorted.length) - 1;
|
|
2243
|
+
return sorted[Math.min(Math.max(rank, 0), sorted.length - 1)];
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* One trace's total USD cost: its explicit root-usage cost when priced,
|
|
2247
|
+
* else the rollup of its subtree. Mirrors the dashboard's `traceCost` so the
|
|
2248
|
+
* stats panel and the trace rows agree to the cent.
|
|
2249
|
+
*/
|
|
2250
|
+
function traceCost(trace) {
|
|
2251
|
+
const own = costSumObj(trace.usage.cost);
|
|
2252
|
+
return own > 0 ? own : rollupCost(trace.root);
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* Aggregate an (already filtered) trace list into one {@link TypeStat} row
|
|
2256
|
+
* per root type — count, failure rate, p50/p95 latency, total tokens, total
|
|
2257
|
+
* cost — preserving first-seen type order. Powers the dashboard's per-type
|
|
2258
|
+
* stats panel; computed over the same filtered list the trace view shows, so
|
|
2259
|
+
* the panel always reflects the active filters.
|
|
2260
|
+
*/
|
|
2261
|
+
function aggregateByType(traces) {
|
|
2262
|
+
const order = [];
|
|
2263
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2264
|
+
for (const trace of traces) {
|
|
2265
|
+
const key = trace.root.type || "(no type)";
|
|
2266
|
+
let bucket = byKey.get(key);
|
|
2267
|
+
if (bucket === void 0) {
|
|
2268
|
+
bucket = [];
|
|
2269
|
+
byKey.set(key, bucket);
|
|
2270
|
+
order.push(key);
|
|
2271
|
+
}
|
|
2272
|
+
bucket.push(trace);
|
|
2273
|
+
}
|
|
2274
|
+
return order.map((type) => {
|
|
2275
|
+
const bucket = byKey.get(type) ?? [];
|
|
2276
|
+
const durations = bucket.map((trace) => trace.duration);
|
|
2277
|
+
let failed = 0;
|
|
2278
|
+
let tokens = 0;
|
|
2279
|
+
let cost = 0;
|
|
2280
|
+
for (const trace of bucket) {
|
|
2281
|
+
if (ERROR_STATUSES.includes(trace.root.status)) failed += 1;
|
|
2282
|
+
tokens += trace.usage.total ?? 0;
|
|
2283
|
+
cost += traceCost(trace);
|
|
2284
|
+
}
|
|
2285
|
+
return {
|
|
2286
|
+
type,
|
|
2287
|
+
count: bucket.length,
|
|
2288
|
+
failed,
|
|
2289
|
+
failRate: bucket.length > 0 ? failed / bucket.length : 0,
|
|
2290
|
+
p50: percentile(durations, 50),
|
|
2291
|
+
p95: percentile(durations, 95),
|
|
2292
|
+
tokens,
|
|
2293
|
+
cost
|
|
2294
|
+
};
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
/**
|
|
2298
|
+
* Sum every priced lane of a usage cost object into one USD number.
|
|
2299
|
+
* Mirrors the dashboard's `costSumObj` so heatmap intensities computed
|
|
2300
|
+
* here match what the page renders.
|
|
2301
|
+
*/
|
|
2302
|
+
function costSumObj(cost) {
|
|
2303
|
+
if (cost === void 0) return 0;
|
|
2304
|
+
return (cost.input ?? 0) + (cost.output ?? 0) + (cost.cachedInput ?? 0) + (cost.cacheWrite ?? 0) + (cost.cachedOutput ?? 0) + (cost.reasoning ?? 0);
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Rollup-aware subtree cost: a node's own cost when it carries one
|
|
2308
|
+
* (it already rolls up its trips), otherwise the sum of its children.
|
|
2309
|
+
* Avoids double-counting wrapper nodes (workflow/supervisor roots carry
|
|
2310
|
+
* tokens but no cost). Mirrors the dashboard's `rollupCost`.
|
|
2311
|
+
*/
|
|
2312
|
+
function rollupCost(span) {
|
|
2313
|
+
const own = costSumObj(span.usage.cost);
|
|
2314
|
+
if (own > 0) return own;
|
|
2315
|
+
let sum = 0;
|
|
2316
|
+
for (const child of span.children) sum += rollupCost(child);
|
|
2317
|
+
return sum;
|
|
2318
|
+
}
|
|
2319
|
+
/**
|
|
2320
|
+
* Heatmap intensity in `[0, 1]` for a node's `rollupCost` relative to the
|
|
2321
|
+
* trace's most-expensive node. The dashboard tints each tree node's left
|
|
2322
|
+
* accent by this. `max <= 0` (a free trace) yields `0` for every node so
|
|
2323
|
+
* the heatmap simply stays cold rather than dividing by zero.
|
|
2324
|
+
*/
|
|
2325
|
+
function heatIntensity(nodeCost, maxCost) {
|
|
2326
|
+
if (maxCost <= 0 || nodeCost <= 0) return 0;
|
|
2327
|
+
const ratio = nodeCost / maxCost;
|
|
2328
|
+
return ratio > 1 ? 1 : ratio;
|
|
2329
|
+
}
|
|
2330
|
+
/**
|
|
2331
|
+
* The largest single-node {@link rollupCost} anywhere in a span tree —
|
|
2332
|
+
* the denominator for {@link heatIntensity}. Walks the whole subtree.
|
|
2333
|
+
*/
|
|
2334
|
+
function maxNodeCost(root) {
|
|
2335
|
+
let max = rollupCost(root);
|
|
2336
|
+
for (const child of root.children) {
|
|
2337
|
+
const childMax = maxNodeCost(child);
|
|
2338
|
+
if (childMax > max) max = childMax;
|
|
2339
|
+
}
|
|
2340
|
+
return max;
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
//#endregion
|
|
2344
|
+
//#region ../../packages/ai-panoptic/src/dashboard/trace-summary.ts
|
|
2345
|
+
function countSpans(span) {
|
|
2346
|
+
let count = 1;
|
|
2347
|
+
for (const child of span.children) count += countSpans(child);
|
|
2348
|
+
return count;
|
|
2349
|
+
}
|
|
2350
|
+
/** Project a stored trace onto the list summary served by `GET api/traces`. */
|
|
2351
|
+
function toTraceSummary(trace) {
|
|
2352
|
+
const { input: _input, output: _output, children: _children, error, ...root } = trace.root;
|
|
2353
|
+
const summaryRoot = root;
|
|
2354
|
+
if (error !== void 0) summaryRoot.error = {
|
|
2355
|
+
type: error.type,
|
|
2356
|
+
message: error.message
|
|
2357
|
+
};
|
|
2358
|
+
return {
|
|
2359
|
+
...trace,
|
|
2360
|
+
root: summaryRoot,
|
|
2361
|
+
spanCount: countSpans(trace.root),
|
|
2362
|
+
totalCost: traceCost(trace)
|
|
2363
|
+
};
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
//#endregion
|
|
2367
|
+
//#region ../../packages/ai-panoptic/src/dashboard/warlock-logo.ts
|
|
2368
|
+
/**
|
|
2369
|
+
* The Warlock logo as an inlined base64 PNG data URI (64x64, ~9KB).
|
|
2370
|
+
* Inlined so the dashboard stays a single self-contained, offline-capable
|
|
2371
|
+
* page with no external asset request. Regenerate from
|
|
2372
|
+
* @warlock.js/docs/public/logo.png via:
|
|
2373
|
+
* magick logo.png -resize 64x64 -strip out.png && base64 -w0 out.png
|
|
2374
|
+
*/
|
|
2375
|
+
const WARLOCK_LOGO_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAkvklEQVR42nV7Z5hb1bX2u9Y+RRpNn7E9425s02wMxgZMNc1AqIkJLTcxgQChpBEC94bwpVwSCCQBEkghECD0DiZwIRBaAhhiMGCDccEejz3F0zQzGrVT9l7fj6MjaQzR8+iRdHTO3nutvcq7yiYikAgAAESASPQJRN8BgLnyO/6fCDCmfC+JoHQ3QEQQkfg+MqbqPwDE0f3xfACiGySayxiMe1XPt+ureoz4d7zW6DvFo4OZSAQipQdEAFW6o/xgPBlz5drnvZiJiBC/owkZYKKqiSMGACDmykKVGj+ySOlGqsy/K5HVa6v+nyNmUnnC0pd4/fG7mkkxc5hLDIh27PNviHe9tLFlYkq7DiKCEZLKRESAxJPSODoIUIpJpLwJ5XuoakwRUPyKmUiVbaLKWNF/1RJcuoMqdBGqSPsMU8dJQCzqpe9kTGXw6oeqGC3VkwMAKy7vSCwJVEVBdD99ZjyOLxHATON2Lh4nVquYuOjaeKkoTSVVdFH8VB2A2397sNO1Y8T09PsVEaVoYi49zK5LzDyO20wEVqpyPf6tFDGVOR7xrrR3pBSYuTxu6U2sFLPtEFeNTzGfEGsRR3NwNAcxl2WCiOLfFamsfts2sWWBmUEAURNAN14M1btl2aK+jmXznJKWlHYHpFRpsmjS8mRlokrEKB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
2377
|
+
//#endregion
|
|
2378
|
+
//#region ../../packages/ai-panoptic/src/dashboard/ui.html.ts
|
|
2379
|
+
/**
|
|
2380
|
+
* Build the single self-contained dashboard HTML page. No external
|
|
2381
|
+
* assets, no bundler, no framework — one inlined string that polls the
|
|
2382
|
+
* read-only JSON API (`{basePath}api/aggregate`, `{basePath}api/traces`,
|
|
2383
|
+
* `{basePath}api/traces/:id`) and renders:
|
|
2384
|
+
*
|
|
2385
|
+
* - the {@link TraceAggregate} headline counts (traces / completed /
|
|
2386
|
+
* failed / cancelled / tokens in·out·total / cost);
|
|
2387
|
+
* - a newest-first trace list as clickable master rows, each led by a
|
|
2388
|
+
* colour-coded, title-cased type label (Supervisor / Agent / Tool / …);
|
|
2389
|
+
* - a two-pane drawer: a collapsible call tree on the left (the nested
|
|
2390
|
+
* span hierarchy) and the selected node's detail on the right — rich
|
|
2391
|
+
* input/output, token breakdown, and a metadata panel (session id,
|
|
2392
|
+
* ids, version, attributes).
|
|
2393
|
+
*
|
|
2394
|
+
* Span input/output is rendered structurally (chat bubbles / key-value /
|
|
2395
|
+
* Markdown), durations in seconds, tokens as ↓input · ↑output · total.
|
|
2396
|
+
* Theme is light / dark / system (persisted to localStorage). All UI
|
|
2397
|
+
* state — selected trace, selected span, collapsed nodes — lives in JS,
|
|
2398
|
+
* NOT the DOM, so the 2s poll never disturbs an open drawer.
|
|
2399
|
+
*
|
|
2400
|
+
* The 2s poll reads the newest trace summaries (`api/traces`: no span
|
|
2401
|
+
* tree, no captured content); opening a trace fetches its full tree from
|
|
2402
|
+
* `api/traces/:id` and re-fetches it only when its summary changes.
|
|
2403
|
+
*
|
|
2404
|
+
* The list is filterable entirely client-side over the polled traces: a
|
|
2405
|
+
* free-text search (name + session), status / type / session filter
|
|
2406
|
+
* chips, an "errors only" header toggle, and an optional group-by-session
|
|
2407
|
+
* view with collapsible headers. Each tree node and trace row carries a
|
|
2408
|
+
* cost heatmap accent scaled to the trace's most expensive node, with a
|
|
2409
|
+
* small legend. The drawer's left pane toggles between the nested call
|
|
2410
|
+
* TREE and a Gantt TIMELINE (span offset from root start + duration,
|
|
2411
|
+
* critical path highlighted). The selected trace and span are reflected
|
|
2412
|
+
* in the URL hash (`#trace=&span=`) and re-opened from it on load — so a
|
|
2413
|
+
* drawer view is shareable/bookmarkable. A live socket tail is a noted
|
|
2414
|
+
* follow-up; this pass stays on the 2s poll.
|
|
2415
|
+
*
|
|
2416
|
+
* `basePath` and `title` are baked in at serve time. The page is
|
|
2417
|
+
* intentionally dependency-free vanilla JS so it works offline.
|
|
2418
|
+
*
|
|
2419
|
+
* @param basePath Normalized mount path ending in `/` (e.g. `"/"`).
|
|
2420
|
+
* @param title Header title shown in the page.
|
|
2421
|
+
*/
|
|
2422
|
+
function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefaultInstructions = "") {
|
|
2423
|
+
const apiBase = `${basePath}api`;
|
|
2424
|
+
const safeTitle = escapeHtml(title);
|
|
2425
|
+
return `<!doctype html>
|
|
2426
|
+
<html lang="en">
|
|
2427
|
+
<head>
|
|
2428
|
+
<meta charset="utf-8" />
|
|
2429
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
2430
|
+
<title>${safeTitle}</title>
|
|
2431
|
+
<script>
|
|
2432
|
+
(function () {
|
|
2433
|
+
try {
|
|
2434
|
+
var m = localStorage.getItem("panoptic-theme") || "system";
|
|
2435
|
+
var light = m === "light" || (m === "system" && window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches);
|
|
2436
|
+
document.documentElement.setAttribute("data-theme", light ? "light" : "dark");
|
|
2437
|
+
} catch (e) {}
|
|
2438
|
+
})();
|
|
2439
|
+
<\/script>
|
|
2440
|
+
<style>
|
|
2441
|
+
:root {
|
|
2442
|
+
color-scheme: dark;
|
|
2443
|
+
--bg: #0b0d10; --surface: #101317; --surface2: #14171c; --panel: #0d1014;
|
|
2444
|
+
--border: #23272e; --border2: #2d333b;
|
|
2445
|
+
--text: #e6e8eb; --text2: #adbac7; --dim: #8b949e;
|
|
2446
|
+
--sel-bg: #0f1722; --sel-border: #316dca;
|
|
2447
|
+
--ty-agent: #539bf5; --ty-tool: #c297ff; --ty-model: #4cc2b0; --ty-prim: #e3b341; --ty-other: #adbac7;
|
|
2448
|
+
--tok-in: #58a6ff; --tok-out: #3fb950; --tok-total: #b899ff; --cost: #e3b341;
|
|
2449
|
+
--ok: #56d364; --ok-bg: #0f2e1d; --fail: #f85149; --fail-bg: #3a1416; --cancel: #d29922; --cancel-bg: #332701; --other: #8b949e; --other-bg: #1c2128;
|
|
2450
|
+
--code-bg: #0b0d10; --inline-bg: #1c2128; --link: #539bf5;
|
|
2451
|
+
}
|
|
2452
|
+
:root[data-theme="light"] {
|
|
2453
|
+
color-scheme: light;
|
|
2454
|
+
--bg: #ffffff; --surface: #f6f8fa; --surface2: #eef1f4; --panel: #ffffff;
|
|
2455
|
+
--border: #d0d7de; --border2: #afb8c1;
|
|
2456
|
+
--text: #1f2328; --text2: #3b4350; --dim: #636c76;
|
|
2457
|
+
--sel-bg: #ddf4ff; --sel-border: #0969da;
|
|
2458
|
+
--ty-agent: #0969da; --ty-tool: #8250df; --ty-model: #0f7d6b; --ty-prim: #9a6700; --ty-other: #57606a;
|
|
2459
|
+
--tok-in: #0969da; --tok-out: #1a7f37; --tok-total: #8250df; --cost: #9a6700;
|
|
2460
|
+
--ok: #1a7f37; --ok-bg: #dafbe1; --fail: #cf222e; --fail-bg: #ffebe9; --cancel: #9a6700; --cancel-bg: #fff8c5; --other: #57606a; --other-bg: #eaeef2;
|
|
2461
|
+
--code-bg: #f6f8fa; --inline-bg: #eaeef2; --link: #0969da;
|
|
2462
|
+
}
|
|
2463
|
+
* { box-sizing: border-box; }
|
|
2464
|
+
body { margin: 0; font: 14px/1.5 ui-sans-serif, system-ui, sans-serif; background: var(--bg); color: var(--text); }
|
|
2465
|
+
header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
|
|
2466
|
+
header img.logo { height: 26px; width: 26px; display: block; flex: none; }
|
|
2467
|
+
header h1 { font-size: 16px; margin: 0; font-weight: 600; }
|
|
2468
|
+
header .meta { color: var(--dim); font-size: 12px; }
|
|
2469
|
+
.theme { margin-left: auto; display: flex; gap: 2px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
|
|
2470
|
+
.theme button { background: transparent; border: none; color: var(--dim); cursor: pointer; font-size: 14px; line-height: 1; padding: 4px 8px; border-radius: 6px; }
|
|
2471
|
+
.theme button:hover { color: var(--text); }
|
|
2472
|
+
.theme button.active { background: var(--surface2); color: var(--text); }
|
|
2473
|
+
.stats { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
|
|
2474
|
+
.stat { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; min-width: 84px; }
|
|
2475
|
+
.stat .label { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
|
|
2476
|
+
.stat .value { font-size: 18px; font-weight: 600; }
|
|
2137
2477
|
main { padding: 12px 20px 40px; }
|
|
2138
2478
|
|
|
2139
2479
|
.trace-row { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface); padding: 9px 12px; display: flex; align-items: center; gap: 9px; cursor: pointer; transition: background .12s ease, border-color .12s ease; }
|
|
@@ -2361,6 +2701,8 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
2361
2701
|
|
|
2362
2702
|
var state = {
|
|
2363
2703
|
traces: [], selectedId: null, selectedSpanId: null, collapsed: {}, sig: null,
|
|
2704
|
+
detail: null, // full trace of the open drawer (GET /traces/:id)
|
|
2705
|
+
loadingId: null, // trace id whose full tree is being fetched
|
|
2364
2706
|
// Client-side filter state (search box + chips + errors-only header toggle).
|
|
2365
2707
|
filter: { text: "", statuses: {}, types: {}, sessionId: null, promptKey: null, errorsOnly: false },
|
|
2366
2708
|
groupBySession: false, // session-grouping list toggle
|
|
@@ -2466,7 +2808,11 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
2466
2808
|
for (var i = 0; i < k.length; i++) n += countSpans(k[i]);
|
|
2467
2809
|
return n;
|
|
2468
2810
|
}
|
|
2469
|
-
|
|
2811
|
+
// Works on a list summary (spanCount) and on a full trace (counted).
|
|
2812
|
+
function traceSig(t) {
|
|
2813
|
+
var spans = t.spanCount != null ? t.spanCount : countSpans(t.root);
|
|
2814
|
+
return t.root.status + "|" + spans + "|" + t.duration + "|" + (t.usage && t.usage.total);
|
|
2815
|
+
}
|
|
2470
2816
|
// Sum every priced lane of a cost object into one USD number.
|
|
2471
2817
|
function costSumObj(c) {
|
|
2472
2818
|
if (!c) return 0;
|
|
@@ -2486,6 +2832,7 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
2486
2832
|
return sum;
|
|
2487
2833
|
}
|
|
2488
2834
|
function traceCost(t) {
|
|
2835
|
+
if (typeof t.totalCost === "number") return t.totalCost; // list summary: computed server-side
|
|
2489
2836
|
var explicit = costSumObj(t.cost);
|
|
2490
2837
|
return explicit > 0 ? explicit : rollupCost(t.root);
|
|
2491
2838
|
}
|
|
@@ -3145,8 +3492,12 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
3145
3492
|
+ (st.result ? evalResultHtml(st.result) : "")
|
|
3146
3493
|
+ "</div>";
|
|
3147
3494
|
}
|
|
3495
|
+
// The full trace of the open drawer, once it has loaded.
|
|
3496
|
+
function openDetail() {
|
|
3497
|
+
return state.detail && state.detail.traceId === state.selectedId ? state.detail : null;
|
|
3498
|
+
}
|
|
3148
3499
|
function rerenderDetail() {
|
|
3149
|
-
var t =
|
|
3500
|
+
var t = openDetail();
|
|
3150
3501
|
if (!t) return;
|
|
3151
3502
|
var sel = findSpan(t.root, state.selectedSpanId) || t.root;
|
|
3152
3503
|
document.getElementById("drawer-detail").innerHTML = renderDetail(sel, t);
|
|
@@ -3238,14 +3589,14 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
3238
3589
|
// Re-render only the left pane (after a view switch) without disturbing
|
|
3239
3590
|
// the detail panel or scroll position of the detail side.
|
|
3240
3591
|
function renderLeftPane() {
|
|
3241
|
-
var t =
|
|
3592
|
+
var t = openDetail();
|
|
3242
3593
|
if (!t) return;
|
|
3243
3594
|
document.getElementById("drawer-tree").innerHTML = viewSwitcher() + leftPaneHtml(t);
|
|
3244
3595
|
}
|
|
3245
3596
|
|
|
3246
3597
|
function selectSpan(id) {
|
|
3247
3598
|
state.selectedSpanId = id;
|
|
3248
|
-
var t =
|
|
3599
|
+
var t = openDetail();
|
|
3249
3600
|
if (!t) return;
|
|
3250
3601
|
document.getElementById("drawer-detail").innerHTML = renderDetail(findSpan(t.root, id) || t.root, t);
|
|
3251
3602
|
// Highlight in whichever left pane is active (tree nodes or Gantt rows).
|
|
@@ -3258,7 +3609,7 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
3258
3609
|
}
|
|
3259
3610
|
function toggleSpan(id) {
|
|
3260
3611
|
state.collapsed[id] = !state.collapsed[id];
|
|
3261
|
-
var t =
|
|
3612
|
+
var t = openDetail();
|
|
3262
3613
|
if (t) renderLeftPane();
|
|
3263
3614
|
}
|
|
3264
3615
|
function setView(v) {
|
|
@@ -3267,15 +3618,49 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
3267
3618
|
renderLeftPane();
|
|
3268
3619
|
}
|
|
3269
3620
|
|
|
3621
|
+
// Drawer placeholder while the full trace loads, or when it cannot.
|
|
3622
|
+
function renderDrawerMessage(text) {
|
|
3623
|
+
document.getElementById("drawer-head").innerHTML =
|
|
3624
|
+
'<button class="drawer-close" type="button" title="Close (Esc)">✕ Close</button>';
|
|
3625
|
+
document.getElementById("drawer-body").innerHTML = '<div class="empty">' + esc(text) + "</div>";
|
|
3626
|
+
}
|
|
3627
|
+
// Fetch the full trace (span tree + captured content) for the drawer.
|
|
3628
|
+
// The list only carries summaries, so the drawer always reads this.
|
|
3629
|
+
function loadDetail(id, spanId) {
|
|
3630
|
+
state.loadingId = id;
|
|
3631
|
+
fetchAuthed(API + "/traces/" + encodeURIComponent(id)).then(function (r) {
|
|
3632
|
+
return r.json().then(function (data) { return { ok: r.ok, status: r.status, data: data }; });
|
|
3633
|
+
}).then(function (res) {
|
|
3634
|
+
if (state.loadingId === id) state.loadingId = null;
|
|
3635
|
+
if (state.selectedId !== id) return;
|
|
3636
|
+
if (!res.ok) {
|
|
3637
|
+
var code = res.data && res.data.error;
|
|
3638
|
+
renderDrawerMessage(res.status === 404
|
|
3639
|
+
? "This trace is no longer in the store: older traces are dropped once the store reaches its capacity. Close this panel and pick a recent trace."
|
|
3640
|
+
: "Could not load this trace (" + (code || ("HTTP " + res.status)) + "). Close this panel and try again.");
|
|
3641
|
+
return;
|
|
3642
|
+
}
|
|
3643
|
+
var t = res.data;
|
|
3644
|
+
var wanted = spanId || state.selectedSpanId;
|
|
3645
|
+
state.detail = t;
|
|
3646
|
+
state.selectedSpanId = (wanted && findSpan(t.root, wanted)) ? wanted : t.root.spanId;
|
|
3647
|
+
state.sig = traceSig(t);
|
|
3648
|
+
renderDrawer(t);
|
|
3649
|
+
writeHash();
|
|
3650
|
+
}).catch(function () {
|
|
3651
|
+
if (state.loadingId === id) state.loadingId = null;
|
|
3652
|
+
if (state.selectedId !== id) return;
|
|
3653
|
+
renderDrawerMessage("Could not reach the dashboard server to load this trace. Check that the app is still running, then reopen the trace.");
|
|
3654
|
+
});
|
|
3655
|
+
}
|
|
3270
3656
|
function openTrace(id, spanId) {
|
|
3271
3657
|
state.selectedId = id;
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
}
|
|
3658
|
+
state.selectedSpanId = spanId || null;
|
|
3659
|
+
state.collapsed = {};
|
|
3660
|
+
state.detail = null;
|
|
3661
|
+
state.sig = null;
|
|
3662
|
+
renderDrawerMessage("Loading trace…");
|
|
3663
|
+
loadDetail(id, spanId);
|
|
3279
3664
|
document.getElementById("drawer").classList.add("open");
|
|
3280
3665
|
document.getElementById("drawer").setAttribute("aria-hidden", "false");
|
|
3281
3666
|
document.getElementById("backdrop").classList.add("open");
|
|
@@ -3283,7 +3668,7 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
3283
3668
|
writeHash();
|
|
3284
3669
|
}
|
|
3285
3670
|
function closeDrawer() {
|
|
3286
|
-
state.selectedId = null; state.selectedSpanId = null; state.sig = null;
|
|
3671
|
+
state.selectedId = null; state.selectedSpanId = null; state.sig = null; state.detail = null;
|
|
3287
3672
|
document.getElementById("drawer").classList.remove("open");
|
|
3288
3673
|
document.getElementById("drawer").setAttribute("aria-hidden", "true");
|
|
3289
3674
|
document.getElementById("backdrop").classList.remove("open");
|
|
@@ -3323,15 +3708,15 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
3323
3708
|
});
|
|
3324
3709
|
return out;
|
|
3325
3710
|
}
|
|
3326
|
-
// Open whatever the hash points at
|
|
3327
|
-
//
|
|
3711
|
+
// Open whatever the hash points at. The drawer fetches the trace by id,
|
|
3712
|
+
// so a deep link works even when the trace is past the polled list.
|
|
3713
|
+
// Returns true when it acted so the caller can mark the one-time load as done.
|
|
3328
3714
|
function applyHash() {
|
|
3329
3715
|
var h = readHash();
|
|
3330
3716
|
if (!h.trace) {
|
|
3331
3717
|
if (state.selectedId) closeDrawer();
|
|
3332
3718
|
return true;
|
|
3333
3719
|
}
|
|
3334
|
-
if (!findTrace(h.trace)) return false; // not polled yet — retry next poll
|
|
3335
3720
|
openTrace(h.trace, h.span || undefined);
|
|
3336
3721
|
return true;
|
|
3337
3722
|
}
|
|
@@ -3483,9 +3868,10 @@ function dashboardHtml(basePath, title, evaluateEnabled = false, evaluateDefault
|
|
|
3483
3868
|
// has actually arrived in a poll (it may not be in the first batch).
|
|
3484
3869
|
if (!state.hashApplied) {
|
|
3485
3870
|
if (applyHash()) state.hashApplied = true;
|
|
3486
|
-
} else if (state.selectedId) {
|
|
3871
|
+
} else if (state.selectedId && openDetail() && state.loadingId === null) {
|
|
3872
|
+
// Re-fetch the open trace only when its summary changed.
|
|
3487
3873
|
var t = findTrace(state.selectedId);
|
|
3488
|
-
if (t
|
|
3874
|
+
if (t && traceSig(t) !== state.sig) loadDetail(state.selectedId);
|
|
3489
3875
|
}
|
|
3490
3876
|
}).catch(function (e) {
|
|
3491
3877
|
document.getElementById("meta").textContent = "disconnected";
|
|
@@ -3589,8 +3975,10 @@ function isAuthorized(req, url, token, allowQueryToken) {
|
|
|
3589
3975
|
*
|
|
3590
3976
|
* Routes (all under `config.basePath`):
|
|
3591
3977
|
*
|
|
3592
|
-
* - `GET api/traces` →
|
|
3593
|
-
*
|
|
3978
|
+
* - `GET api/traces` → the newest `?limit=` (default 200) matches of
|
|
3979
|
+
* `store.query(parseQuery(searchParams))`, as {@link TraceSummary}
|
|
3980
|
+
* entries (no span tree or captured content); `?full=1` returns full traces
|
|
3981
|
+
* - `GET api/traces/:id` → `store.get(id)` or `404` (`400` for a malformed id)
|
|
3594
3982
|
* - `GET api/aggregate` → `store.aggregate(parseQuery(searchParams))`
|
|
3595
3983
|
* - `GET {basePath}` → the self-contained HTML page
|
|
3596
3984
|
* - `POST api/traces/:traceId/spans/:spanId/evaluate` → ONLY when
|
|
@@ -3600,6 +3988,8 @@ function isAuthorized(req, url, token, allowQueryToken) {
|
|
|
3600
3988
|
* other route (the path is never even pattern-matched).
|
|
3601
3989
|
*
|
|
3602
3990
|
* Anything else → `404`. A method the matched route doesn't accept → `405`.
|
|
3991
|
+
* A handler failure answers `500` instead of escaping the server's
|
|
3992
|
+
* `request` listener, so one bad request can never take the app down.
|
|
3603
3993
|
* Host allowlist + bearer-token auth (S4) are checked for EVERY request,
|
|
3604
3994
|
* regardless of method, before any routing. The store shapes
|
|
3605
3995
|
* ({@link Trace}/{@link TraceSpan}) are already JSON-safe, so GET responses
|
|
@@ -3613,8 +4003,15 @@ function createRequestHandler(store, config) {
|
|
|
3613
4003
|
const base = config.basePath;
|
|
3614
4004
|
const apiPrefix = `${base}api`;
|
|
3615
4005
|
return function handle(req, res) {
|
|
3616
|
-
|
|
3617
|
-
|
|
4006
|
+
try {
|
|
4007
|
+
route(req, res);
|
|
4008
|
+
} catch {
|
|
4009
|
+
sendInternalError(res);
|
|
4010
|
+
}
|
|
4011
|
+
};
|
|
4012
|
+
function route(req, res) {
|
|
4013
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
4014
|
+
const pathname = url.pathname;
|
|
3618
4015
|
const host = hostHeaderName(req.headers.host);
|
|
3619
4016
|
if (!host || !config.allowedHosts.includes(host.toLowerCase())) {
|
|
3620
4017
|
sendJson(res, 403, { error: "host_not_allowed" });
|
|
@@ -3627,8 +4024,12 @@ function createRequestHandler(store, config) {
|
|
|
3627
4024
|
}
|
|
3628
4025
|
if (req.method === "POST" && config.evaluate) {
|
|
3629
4026
|
const match = matchEvaluatePath(pathname, apiPrefix);
|
|
4027
|
+
if (match === "malformed") {
|
|
4028
|
+
sendJson(res, 400, { error: "bad_trace_id" });
|
|
4029
|
+
return;
|
|
4030
|
+
}
|
|
3630
4031
|
if (match) {
|
|
3631
|
-
handleEvaluate(store, config.evaluate, match.traceId, match.spanId, req, res);
|
|
4032
|
+
handleEvaluate(store, config.evaluate, match.traceId, match.spanId, req, res).catch(() => sendInternalError(res));
|
|
3632
4033
|
return;
|
|
3633
4034
|
}
|
|
3634
4035
|
}
|
|
@@ -3637,11 +4038,17 @@ function createRequestHandler(store, config) {
|
|
|
3637
4038
|
return;
|
|
3638
4039
|
}
|
|
3639
4040
|
if (pathname === `${apiPrefix}/traces`) {
|
|
3640
|
-
|
|
4041
|
+
const { limit, full } = parseListOptions(url.searchParams);
|
|
4042
|
+
const traces = store.query(parseQuery(url.searchParams)).slice(0, limit);
|
|
4043
|
+
sendJson(res, 200, full ? traces : traces.map(toTraceSummary));
|
|
3641
4044
|
return;
|
|
3642
4045
|
}
|
|
3643
4046
|
if (pathname.startsWith(`${apiPrefix}/traces/`)) {
|
|
3644
|
-
const traceId =
|
|
4047
|
+
const traceId = safeDecode(pathname.slice(`${apiPrefix}/traces/`.length));
|
|
4048
|
+
if (traceId === void 0) {
|
|
4049
|
+
sendJson(res, 400, { error: "bad_trace_id" });
|
|
4050
|
+
return;
|
|
4051
|
+
}
|
|
3645
4052
|
const trace = traceId.length > 0 ? store.get(traceId) : void 0;
|
|
3646
4053
|
if (trace === void 0) {
|
|
3647
4054
|
sendJson(res, 404, {
|
|
@@ -3666,7 +4073,26 @@ function createRequestHandler(store, config) {
|
|
|
3666
4073
|
return;
|
|
3667
4074
|
}
|
|
3668
4075
|
sendJson(res, 404, { error: "not_found" });
|
|
3669
|
-
}
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
/**
|
|
4079
|
+
* `decodeURIComponent` that answers `undefined` for a malformed escape
|
|
4080
|
+
* (`%E0%A4%A`) instead of throwing a `URIError`.
|
|
4081
|
+
*/
|
|
4082
|
+
function safeDecode(value) {
|
|
4083
|
+
try {
|
|
4084
|
+
return decodeURIComponent(value);
|
|
4085
|
+
} catch {
|
|
4086
|
+
return;
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
/** Answer `500` unless a response is already on its way. */
|
|
4090
|
+
function sendInternalError(res) {
|
|
4091
|
+
if (res.headersSent) {
|
|
4092
|
+
res.end();
|
|
4093
|
+
return;
|
|
4094
|
+
}
|
|
4095
|
+
sendJson(res, 500, { error: "internal" });
|
|
3670
4096
|
}
|
|
3671
4097
|
/** Write a JSON response with the given status code and security headers. */
|
|
3672
4098
|
function sendJson(res, status, body) {
|
|
@@ -3680,16 +4106,20 @@ function sendJson(res, status, body) {
|
|
|
3680
4106
|
* Match `{apiPrefix}/traces/:traceId/spans/:spanId/evaluate` — the one
|
|
3681
4107
|
* write route. Returns `undefined` for anything else, including the plain
|
|
3682
4108
|
* `{apiPrefix}/traces/:id` read route (no `/spans/.../evaluate` suffix),
|
|
3683
|
-
* so the two never collide.
|
|
4109
|
+
* so the two never collide. `"malformed"` when an id is not valid
|
|
4110
|
+
* percent-encoding.
|
|
3684
4111
|
*/
|
|
3685
4112
|
function matchEvaluatePath(pathname, apiPrefix) {
|
|
3686
4113
|
const prefix = `${apiPrefix}/traces/`;
|
|
3687
4114
|
if (!pathname.startsWith(prefix)) return;
|
|
3688
4115
|
const match = /^([^/]+)\/spans\/([^/]+)\/evaluate$/.exec(pathname.slice(prefix.length));
|
|
3689
4116
|
if (!match) return;
|
|
4117
|
+
const traceId = safeDecode(match[1] ?? "");
|
|
4118
|
+
const spanId = safeDecode(match[2] ?? "");
|
|
4119
|
+
if (traceId === void 0 || spanId === void 0) return "malformed";
|
|
3690
4120
|
return {
|
|
3691
|
-
traceId
|
|
3692
|
-
spanId
|
|
4121
|
+
traceId,
|
|
4122
|
+
spanId
|
|
3693
4123
|
};
|
|
3694
4124
|
}
|
|
3695
4125
|
/**
|
|
@@ -3902,277 +4332,11 @@ function openBrowser(url) {
|
|
|
3902
4332
|
}).catch(() => {});
|
|
3903
4333
|
}
|
|
3904
4334
|
|
|
3905
|
-
//#endregion
|
|
3906
|
-
//#region ../../packages/ai-panoptic/src/dashboard/trace-filter.ts
|
|
3907
|
-
/** Statuses the errors-only toggle keeps. */
|
|
3908
|
-
const ERROR_STATUSES = ["failed", "cancelled"];
|
|
3909
|
-
/**
|
|
3910
|
-
* Span-attribute keys the collector stamps with prompt-version linkage when
|
|
3911
|
-
* an agent ran against a *named* `ai.prompts` builder. Read here (not
|
|
3912
|
-
* imported) so this pure module stays decoupled from the collector.
|
|
3913
|
-
*/
|
|
3914
|
-
const PROMPT_NAME_ATTR = "agent.promptName";
|
|
3915
|
-
const PROMPT_VERSION_ATTR = "agent.promptVersion";
|
|
3916
|
-
/**
|
|
3917
|
-
* The `name@version` prompt key a trace falls under, read from its root
|
|
3918
|
-
* span's prompt-version-linkage attributes (`agent.promptName` /
|
|
3919
|
-
* `agent.promptVersion`). Returns `undefined` when the run carried no named
|
|
3920
|
-
* prompt (raw-string / anonymous / no prompt), so callers can bucket those
|
|
3921
|
-
* under a synthetic "no prompt" key or skip them.
|
|
3922
|
-
*
|
|
3923
|
-
* The version is included so two runs of the same prompt name at different
|
|
3924
|
-
* versions are distinct keys — that is the whole point of the linkage: to
|
|
3925
|
-
* group / filter by the *exact* prompt revision that produced a run.
|
|
3926
|
-
*/
|
|
3927
|
-
function tracePromptKey(trace) {
|
|
3928
|
-
const attributes = trace.root.attributes;
|
|
3929
|
-
if (attributes === void 0) return;
|
|
3930
|
-
const name = attributes[PROMPT_NAME_ATTR];
|
|
3931
|
-
if (typeof name !== "string" || name.length === 0) return;
|
|
3932
|
-
const version = attributes[PROMPT_VERSION_ATTR];
|
|
3933
|
-
return `${name}@${typeof version === "string" && version.length > 0 ? version : "1"}`;
|
|
3934
|
-
}
|
|
3935
|
-
/**
|
|
3936
|
-
* Does a single trace pass the given filter? Pure predicate — all
|
|
3937
|
-
* conditions are ANDed; an unset field never excludes. Used by
|
|
3938
|
-
* {@link filterTraces} and mirrored by the dashboard's inlined JS.
|
|
3939
|
-
*/
|
|
3940
|
-
function matchesFilter(trace, filter) {
|
|
3941
|
-
const root = trace.root;
|
|
3942
|
-
if (filter.errorsOnly === true && !ERROR_STATUSES.includes(root.status)) return false;
|
|
3943
|
-
if (filter.statuses !== void 0 && filter.statuses.length > 0) {
|
|
3944
|
-
if (!filter.statuses.includes(root.status)) return false;
|
|
3945
|
-
}
|
|
3946
|
-
if (filter.types !== void 0 && filter.types.length > 0) {
|
|
3947
|
-
if (!filter.types.includes(root.type)) return false;
|
|
3948
|
-
}
|
|
3949
|
-
if (filter.sessionId !== void 0 && filter.sessionId.length > 0) {
|
|
3950
|
-
if (trace.sessionId !== filter.sessionId) return false;
|
|
3951
|
-
}
|
|
3952
|
-
if (filter.promptKey !== void 0 && filter.promptKey.length > 0) {
|
|
3953
|
-
if (tracePromptKey(trace) !== filter.promptKey) return false;
|
|
3954
|
-
}
|
|
3955
|
-
const text = filter.text?.trim().toLowerCase();
|
|
3956
|
-
if (text !== void 0 && text.length > 0) {
|
|
3957
|
-
if (!`${root.name} ${trace.sessionId ?? ""}`.toLowerCase().includes(text)) return false;
|
|
3958
|
-
}
|
|
3959
|
-
return true;
|
|
3960
|
-
}
|
|
3961
|
-
/** Narrow a trace list to those matching the filter, order preserved. */
|
|
3962
|
-
function filterTraces(traces, filter) {
|
|
3963
|
-
return traces.filter((trace) => matchesFilter(trace, filter));
|
|
3964
|
-
}
|
|
3965
|
-
/**
|
|
3966
|
-
* The grouping key a trace falls under when the list is grouped by
|
|
3967
|
-
* session. Traces without a `sessionId` collapse into one synthetic
|
|
3968
|
-
* "(no session)" bucket so they remain visible.
|
|
3969
|
-
*/
|
|
3970
|
-
const NO_SESSION_KEY = "(no session)";
|
|
3971
|
-
/**
|
|
3972
|
-
* Group an (already filtered, newest-first) trace list by session id,
|
|
3973
|
-
* preserving first-seen order of both the groups and the traces within
|
|
3974
|
-
* each. Sessionless traces bucket under {@link NO_SESSION_KEY}.
|
|
3975
|
-
*/
|
|
3976
|
-
function groupBySession(traces) {
|
|
3977
|
-
const order = [];
|
|
3978
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
3979
|
-
for (const trace of traces) {
|
|
3980
|
-
const key = trace.sessionId ?? "(no session)";
|
|
3981
|
-
let bucket = byKey.get(key);
|
|
3982
|
-
if (bucket === void 0) {
|
|
3983
|
-
bucket = [];
|
|
3984
|
-
byKey.set(key, bucket);
|
|
3985
|
-
order.push(key);
|
|
3986
|
-
}
|
|
3987
|
-
bucket.push(trace);
|
|
3988
|
-
}
|
|
3989
|
-
return order.map((sessionId) => ({
|
|
3990
|
-
sessionId,
|
|
3991
|
-
traces: byKey.get(sessionId) ?? []
|
|
3992
|
-
}));
|
|
3993
|
-
}
|
|
3994
|
-
/**
|
|
3995
|
-
* The grouping key a trace falls under when the list is grouped by prompt
|
|
3996
|
-
* version. Runs that resolved no named prompt collapse into one synthetic
|
|
3997
|
-
* "(no prompt)" bucket so they remain visible.
|
|
3998
|
-
*/
|
|
3999
|
-
const NO_PROMPT_KEY = "(no prompt)";
|
|
4000
|
-
/**
|
|
4001
|
-
* Group an (already filtered, newest-first) trace list by prompt version —
|
|
4002
|
-
* the `name@version` key {@link tracePromptKey} derives from each run's
|
|
4003
|
-
* prompt-version-linkage attributes. Preserves first-seen order of both the
|
|
4004
|
-
* groups and the traces within each. Runs with no named prompt bucket under
|
|
4005
|
-
* {@link NO_PROMPT_KEY}.
|
|
4006
|
-
*
|
|
4007
|
-
* The dashboard offers this as a second group-by dimension beside session,
|
|
4008
|
-
* so a reviewer can see every run of "support@2" together and compare its
|
|
4009
|
-
* cost / failure rate against "support@3".
|
|
4010
|
-
*/
|
|
4011
|
-
function groupByPrompt(traces) {
|
|
4012
|
-
const order = [];
|
|
4013
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
4014
|
-
for (const trace of traces) {
|
|
4015
|
-
const key = tracePromptKey(trace) ?? "(no prompt)";
|
|
4016
|
-
let bucket = byKey.get(key);
|
|
4017
|
-
if (bucket === void 0) {
|
|
4018
|
-
bucket = [];
|
|
4019
|
-
byKey.set(key, bucket);
|
|
4020
|
-
order.push(key);
|
|
4021
|
-
}
|
|
4022
|
-
bucket.push(trace);
|
|
4023
|
-
}
|
|
4024
|
-
return order.map((promptKey) => ({
|
|
4025
|
-
promptKey,
|
|
4026
|
-
traces: byKey.get(promptKey) ?? []
|
|
4027
|
-
}));
|
|
4028
|
-
}
|
|
4029
|
-
/**
|
|
4030
|
-
* The grouping key a trace falls under when the list is grouped by root
|
|
4031
|
-
* type. `root.type` is always present, so this is only a defensive
|
|
4032
|
-
* fallback for a malformed trace with no typed root.
|
|
4033
|
-
*/
|
|
4034
|
-
const NO_TYPE_KEY = "(no type)";
|
|
4035
|
-
/**
|
|
4036
|
-
* Group an (already filtered, newest-first) trace list by root type —
|
|
4037
|
-
* the `agent` / `workflow` / `supervisor` / `orchestrator` / `planner` /
|
|
4038
|
-
* `tool` / `batch` / `callback` discriminator on each trace's root span.
|
|
4039
|
-
* Preserves first-seen order of both the groups and the traces within each.
|
|
4040
|
-
*
|
|
4041
|
-
* The dashboard offers this as the coarsest group-by dimension beside
|
|
4042
|
-
* session and prompt: when a benchmark floods the flat list with hundreds
|
|
4043
|
-
* of one primitive (e.g. standalone `agent` runs), this collapses them
|
|
4044
|
-
* behind a per-type header so the structural primitives (the lone planner,
|
|
4045
|
-
* the team, the supervisors) are one click away instead of a scroll past.
|
|
4046
|
-
*/
|
|
4047
|
-
function groupByType(traces) {
|
|
4048
|
-
const order = [];
|
|
4049
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
4050
|
-
for (const trace of traces) {
|
|
4051
|
-
const key = trace.root.type || "(no type)";
|
|
4052
|
-
let bucket = byKey.get(key);
|
|
4053
|
-
if (bucket === void 0) {
|
|
4054
|
-
bucket = [];
|
|
4055
|
-
byKey.set(key, bucket);
|
|
4056
|
-
order.push(key);
|
|
4057
|
-
}
|
|
4058
|
-
bucket.push(trace);
|
|
4059
|
-
}
|
|
4060
|
-
return order.map((type) => ({
|
|
4061
|
-
type,
|
|
4062
|
-
traces: byKey.get(type) ?? []
|
|
4063
|
-
}));
|
|
4064
|
-
}
|
|
4065
|
-
/**
|
|
4066
|
-
* Nearest-rank percentile of `values` at `p` (0–100). Returns 0 for an
|
|
4067
|
-
* empty input and sorts a copy so the caller's array is left untouched.
|
|
4068
|
-
*/
|
|
4069
|
-
function percentile(values, p) {
|
|
4070
|
-
if (values.length === 0) return 0;
|
|
4071
|
-
const sorted = values.slice().sort((a, b) => a - b);
|
|
4072
|
-
const rank = Math.ceil(p / 100 * sorted.length) - 1;
|
|
4073
|
-
return sorted[Math.min(Math.max(rank, 0), sorted.length - 1)];
|
|
4074
|
-
}
|
|
4075
|
-
/**
|
|
4076
|
-
* One trace's total USD cost: its explicit root-usage cost when priced,
|
|
4077
|
-
* else the rollup of its subtree. Mirrors the dashboard's `traceCost` so the
|
|
4078
|
-
* stats panel and the trace rows agree to the cent.
|
|
4079
|
-
*/
|
|
4080
|
-
function traceCost(trace) {
|
|
4081
|
-
const own = costSumObj(trace.usage.cost);
|
|
4082
|
-
return own > 0 ? own : rollupCost(trace.root);
|
|
4083
|
-
}
|
|
4084
|
-
/**
|
|
4085
|
-
* Aggregate an (already filtered) trace list into one {@link TypeStat} row
|
|
4086
|
-
* per root type — count, failure rate, p50/p95 latency, total tokens, total
|
|
4087
|
-
* cost — preserving first-seen type order. Powers the dashboard's per-type
|
|
4088
|
-
* stats panel; computed over the same filtered list the trace view shows, so
|
|
4089
|
-
* the panel always reflects the active filters.
|
|
4090
|
-
*/
|
|
4091
|
-
function aggregateByType(traces) {
|
|
4092
|
-
const order = [];
|
|
4093
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
4094
|
-
for (const trace of traces) {
|
|
4095
|
-
const key = trace.root.type || "(no type)";
|
|
4096
|
-
let bucket = byKey.get(key);
|
|
4097
|
-
if (bucket === void 0) {
|
|
4098
|
-
bucket = [];
|
|
4099
|
-
byKey.set(key, bucket);
|
|
4100
|
-
order.push(key);
|
|
4101
|
-
}
|
|
4102
|
-
bucket.push(trace);
|
|
4103
|
-
}
|
|
4104
|
-
return order.map((type) => {
|
|
4105
|
-
const bucket = byKey.get(type) ?? [];
|
|
4106
|
-
const durations = bucket.map((trace) => trace.duration);
|
|
4107
|
-
let failed = 0;
|
|
4108
|
-
let tokens = 0;
|
|
4109
|
-
let cost = 0;
|
|
4110
|
-
for (const trace of bucket) {
|
|
4111
|
-
if (ERROR_STATUSES.includes(trace.root.status)) failed += 1;
|
|
4112
|
-
tokens += trace.usage.total ?? 0;
|
|
4113
|
-
cost += traceCost(trace);
|
|
4114
|
-
}
|
|
4115
|
-
return {
|
|
4116
|
-
type,
|
|
4117
|
-
count: bucket.length,
|
|
4118
|
-
failed,
|
|
4119
|
-
failRate: bucket.length > 0 ? failed / bucket.length : 0,
|
|
4120
|
-
p50: percentile(durations, 50),
|
|
4121
|
-
p95: percentile(durations, 95),
|
|
4122
|
-
tokens,
|
|
4123
|
-
cost
|
|
4124
|
-
};
|
|
4125
|
-
});
|
|
4126
|
-
}
|
|
4127
|
-
/**
|
|
4128
|
-
* Sum every priced lane of a usage cost object into one USD number.
|
|
4129
|
-
* Mirrors the dashboard's `costSumObj` so heatmap intensities computed
|
|
4130
|
-
* here match what the page renders.
|
|
4131
|
-
*/
|
|
4132
|
-
function costSumObj(cost) {
|
|
4133
|
-
if (cost === void 0) return 0;
|
|
4134
|
-
return (cost.input ?? 0) + (cost.output ?? 0) + (cost.cachedInput ?? 0) + (cost.cacheWrite ?? 0) + (cost.cachedOutput ?? 0) + (cost.reasoning ?? 0);
|
|
4135
|
-
}
|
|
4136
|
-
/**
|
|
4137
|
-
* Rollup-aware subtree cost: a node's own cost when it carries one
|
|
4138
|
-
* (it already rolls up its trips), otherwise the sum of its children.
|
|
4139
|
-
* Avoids double-counting wrapper nodes (workflow/supervisor roots carry
|
|
4140
|
-
* tokens but no cost). Mirrors the dashboard's `rollupCost`.
|
|
4141
|
-
*/
|
|
4142
|
-
function rollupCost(span) {
|
|
4143
|
-
const own = costSumObj(span.usage.cost);
|
|
4144
|
-
if (own > 0) return own;
|
|
4145
|
-
let sum = 0;
|
|
4146
|
-
for (const child of span.children) sum += rollupCost(child);
|
|
4147
|
-
return sum;
|
|
4148
|
-
}
|
|
4149
|
-
/**
|
|
4150
|
-
* Heatmap intensity in `[0, 1]` for a node's `rollupCost` relative to the
|
|
4151
|
-
* trace's most-expensive node. The dashboard tints each tree node's left
|
|
4152
|
-
* accent by this. `max <= 0` (a free trace) yields `0` for every node so
|
|
4153
|
-
* the heatmap simply stays cold rather than dividing by zero.
|
|
4154
|
-
*/
|
|
4155
|
-
function heatIntensity(nodeCost, maxCost) {
|
|
4156
|
-
if (maxCost <= 0 || nodeCost <= 0) return 0;
|
|
4157
|
-
const ratio = nodeCost / maxCost;
|
|
4158
|
-
return ratio > 1 ? 1 : ratio;
|
|
4159
|
-
}
|
|
4160
|
-
/**
|
|
4161
|
-
* The largest single-node {@link rollupCost} anywhere in a span tree —
|
|
4162
|
-
* the denominator for {@link heatIntensity}. Walks the whole subtree.
|
|
4163
|
-
*/
|
|
4164
|
-
function maxNodeCost(root) {
|
|
4165
|
-
let max = rollupCost(root);
|
|
4166
|
-
for (const child of root.children) {
|
|
4167
|
-
const childMax = maxNodeCost(child);
|
|
4168
|
-
if (childMax > max) max = childMax;
|
|
4169
|
-
}
|
|
4170
|
-
return max;
|
|
4171
|
-
}
|
|
4172
|
-
|
|
4173
4335
|
//#endregion
|
|
4174
4336
|
//#region ../../packages/ai-panoptic/src/config/apply-panoptic-config.ts
|
|
4175
4337
|
let applied;
|
|
4338
|
+
/** Traces kept by the store panoptic creates for the dashboard, unless `capacity` says otherwise. */
|
|
4339
|
+
const DEFAULT_DASHBOARD_STORE_CAPACITY = 1e3;
|
|
4176
4340
|
/**
|
|
4177
4341
|
* Read a {@link PanopticConfig} and wire panoptic onto the core observe
|
|
4178
4342
|
* seam — the bridge `ai.config({ panoptic })` resolves through. Builds a
|
|
@@ -4201,11 +4365,15 @@ function applyPanopticConfig(config) {
|
|
|
4201
4365
|
let store = findStore(exporters);
|
|
4202
4366
|
let cacheStore;
|
|
4203
4367
|
if (store === void 0 && config.dashboard) {
|
|
4368
|
+
const capacity = config.capacity ?? 1e3;
|
|
4204
4369
|
if (config.cache !== void 0) {
|
|
4205
4370
|
const onError = config.onError ?? ((error) => _warlock_js_logger.log.error("ai-panoptic", "cacheStore", error));
|
|
4206
|
-
cacheStore = createCacheTraceStore(config.cache, {
|
|
4371
|
+
cacheStore = createCacheTraceStore(config.cache, {
|
|
4372
|
+
onError,
|
|
4373
|
+
capacity
|
|
4374
|
+
});
|
|
4207
4375
|
store = cacheStore;
|
|
4208
|
-
} else store = createInMemoryTraceStore();
|
|
4376
|
+
} else store = createInMemoryTraceStore({ capacity });
|
|
4209
4377
|
exporters.push(store);
|
|
4210
4378
|
}
|
|
4211
4379
|
const panopticInstance = panoptic({
|