@linxiraos/pi-stats 1.5.14 → 1.5.16

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/src/aggregator.ts CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  getProviderTimeSeries,
35
35
  getProjectFolders,
36
36
  getStatsByAgentType,
37
+ getUsageAttribution,
37
38
  getStatsByFolder,
38
39
  getStatsByModel,
39
40
  getStatsByProvider,
@@ -506,7 +507,7 @@ async function syncAllSessionsLocked(
506
507
  const HOUR_MS = 60 * 60 * 1000;
507
508
  const DAY_MS = 24 * HOUR_MS;
508
509
 
509
- type TimeRange = "1h" | "24h" | "7d" | "30d" | "90d" | "all";
510
+ type TimeRange = "1h" | "24h" | "2d" | "3d" | "7d" | "30d" | "90d" | "all";
510
511
 
511
512
  const DEFAULT_TIME_RANGE: TimeRange = "24h";
512
513
 
@@ -514,6 +515,8 @@ const DEFAULT_TIME_RANGE: TimeRange = "24h";
514
515
  const TIME_RANGES: Record<TimeRange, { spanMs: number | null; bucketMs: number }> = {
515
516
  "1h": { spanMs: HOUR_MS, bucketMs: 5 * 60 * 1000 },
516
517
  "24h": { spanMs: DAY_MS, bucketMs: HOUR_MS },
518
+ "2d": { spanMs: 2 * DAY_MS, bucketMs: DAY_MS },
519
+ "3d": { spanMs: 3 * DAY_MS, bucketMs: DAY_MS },
517
520
  "7d": { spanMs: 7 * DAY_MS, bucketMs: DAY_MS },
518
521
  "30d": { spanMs: 30 * DAY_MS, bucketMs: DAY_MS },
519
522
  "90d": { spanMs: 90 * DAY_MS, bucketMs: DAY_MS },
@@ -539,11 +542,13 @@ export function getTimeRangeConfig(range?: string | null): RangeWindow {
539
542
  export async function getDashboardStats(range?: string | null): Promise<DashboardStats> {
540
543
  await initDb();
541
544
  const window = getTimeRangeConfig(range);
545
+ const usage = getUsageAttribution(window.cutoff);
542
546
  return {
543
547
  overall: getOverallStats(window.cutoff),
544
548
  byModel: getStatsByModel(window.cutoff),
549
+ bySideChannel: usage.bySideChannel,
545
550
  byFolder: getStatsByFolder(window.cutoff, FOLDER_LIMIT),
546
- byAgentType: getStatsByAgentType(window.cutoff),
551
+ byAgentType: usage.byAgentType,
547
552
  timeSeries: getTimeSeries(window),
548
553
  modelSeries: getModelTimeSeries(window),
549
554
  modelPerformanceSeries: getModelPerformanceSeries(window),
@@ -553,12 +558,14 @@ export async function getDashboardStats(range?: string | null): Promise<Dashboar
553
558
 
554
559
  export async function getOverviewStats(
555
560
  range?: string | null,
556
- ): Promise<Pick<DashboardStats, "overall" | "byAgentType" | "timeSeries">> {
561
+ ): Promise<Pick<DashboardStats, "overall" | "byAgentType" | "bySideChannel" | "timeSeries">> {
557
562
  await initDb();
558
563
  const window = getTimeRangeConfig(range);
564
+ const usage = getUsageAttribution(window.cutoff);
559
565
  return {
560
566
  overall: getOverallStats(window.cutoff),
561
- byAgentType: getStatsByAgentType(window.cutoff),
567
+ byAgentType: usage.byAgentType,
568
+ bySideChannel: usage.bySideChannel,
562
569
  timeSeries: getTimeSeries(window),
563
570
  };
564
571
  }
@@ -23,7 +23,7 @@ export interface ShellProps {
23
23
 
24
24
  /**
25
25
  * Fixed glass topbar + naked sidebar framing one inset content panel. Owns
26
- * the global keyboard shortcuts: `1`–`6` pick a range, `g` then a letter jumps
26
+ * the global keyboard shortcuts: `1`–`8` pick a range, `g` then a letter jumps
27
27
  * to a page.
28
28
  */
29
29
  export function Shell({ section, onSectionChange, range, onRangeChange, children }: ShellProps) {
@@ -1,6 +1,8 @@
1
1
  import { formatBucket, formatTick } from "../data/range";
2
2
  import { Chart, type ChartProps } from "./Chart";
3
3
 
4
+ const DAY_MS = 24 * 3_600_000;
5
+
4
6
  export interface TimeChartProps extends Omit<ChartProps, "slots" | "tickLabel" | "tooltipTitle" | "onSelect"> {
5
7
  /** Ascending bucket starts (see `bucketAxis`); series values align with them. */
6
8
  buckets: readonly number[];
@@ -14,7 +16,12 @@ export function TimeChart({ buckets, bucketMs, onSelectBucket, ...rest }: TimeCh
14
16
  <Chart
15
17
  {...rest}
16
18
  slots={buckets.length}
17
- tickLabel={i => formatTick(buckets[i], bucketMs)}
19
+ tickLabel={i =>
20
+ formatTick(
21
+ buckets[i],
22
+ buckets.length > 1 && buckets[buckets.length - 1] - buckets[0] > DAY_MS ? DAY_MS : bucketMs,
23
+ )
24
+ }
18
25
  tooltipTitle={i => formatBucket(buckets[i], bucketMs)}
19
26
  onSelect={onSelectBucket ? i => onSelectBucket(buckets[i]) : undefined}
20
27
  />
@@ -38,8 +38,14 @@ export function buildModelColorLookup(
38
38
  );
39
39
  }
40
40
 
41
- /** Generic form of {@link buildModelColorLookup} for any keyed, weighted series. */
42
- export function buildColorLookup(items: readonly { key: string; weight: number }[]): Map<string, string> {
41
+ /**
42
+ * Generic form of {@link buildModelColorLookup} for any keyed, weighted series.
43
+ * `palette` narrows the hues when some are spoken for on the same chart.
44
+ */
45
+ export function buildColorLookup(
46
+ items: readonly { key: string; weight: number }[],
47
+ palette: readonly string[] = SERIES_COLORS,
48
+ ): Map<string, string> {
43
49
  const ranked = [...items].sort((a, b) => b.weight - a.weight || a.key.localeCompare(b.key));
44
- return new Map(ranked.map((item, index) => [item.key, SERIES_COLORS[index % SERIES_COLORS.length]]));
50
+ return new Map(ranked.map((item, index) => [item.key, palette[index % palette.length]]));
45
51
  }
@@ -23,18 +23,55 @@ export interface RangeMeta {
23
23
  }
24
24
 
25
25
  const RANGE_META: Record<TimeRange, RangeMeta> = {
26
- "1h": { labelKey: "common.range-1h", windowKey: "common.window-1h", spanMs: HOUR_MS, bucketMs: 5 * MINUTE_MS },
27
- "24h": { labelKey: "common.range-24h", windowKey: "common.window-24h", spanMs: DAY_MS, bucketMs: HOUR_MS },
28
- "7d": { labelKey: "common.range-7d", windowKey: "common.window-7d", spanMs: 7 * DAY_MS, bucketMs: DAY_MS },
29
- "30d": { labelKey: "common.range-30d", windowKey: "common.window-30d", spanMs: 30 * DAY_MS, bucketMs: DAY_MS },
30
- "90d": { labelKey: "common.range-90d", windowKey: "common.window-90d", spanMs: 90 * DAY_MS, bucketMs: DAY_MS },
31
- all: { labelKey: "common.range-all", windowKey: "common.window-all", spanMs: null, bucketMs: DAY_MS },
26
+ "1h": {
27
+ labelKey: "common.range-1h" as any,
28
+ windowKey: "common.window-1h" as any,
29
+ spanMs: HOUR_MS,
30
+ bucketMs: 5 * MINUTE_MS,
31
+ },
32
+ "24h": {
33
+ labelKey: "common.range-24h" as any,
34
+ windowKey: "common.window-24h" as any,
35
+ spanMs: DAY_MS,
36
+ bucketMs: HOUR_MS,
37
+ },
38
+ "2d": {
39
+ labelKey: "common.range-2d" as any,
40
+ windowKey: "common.window-2d" as any,
41
+ spanMs: 2 * DAY_MS,
42
+ bucketMs: HOUR_MS,
43
+ },
44
+ "3d": {
45
+ labelKey: "common.range-3d" as any,
46
+ windowKey: "common.window-3d" as any,
47
+ spanMs: 3 * DAY_MS,
48
+ bucketMs: HOUR_MS,
49
+ },
50
+ "7d": {
51
+ labelKey: "common.range-7d" as any,
52
+ windowKey: "common.window-7d" as any,
53
+ spanMs: 7 * DAY_MS,
54
+ bucketMs: DAY_MS,
55
+ },
56
+ "30d": {
57
+ labelKey: "common.range-30d" as any,
58
+ windowKey: "common.window-30d" as any,
59
+ spanMs: 30 * DAY_MS,
60
+ bucketMs: DAY_MS,
61
+ },
62
+ "90d": {
63
+ labelKey: "common.range-90d" as any,
64
+ windowKey: "common.window-90d" as any,
65
+ spanMs: 90 * DAY_MS,
66
+ bucketMs: DAY_MS,
67
+ },
68
+ all: { labelKey: "common.range-all" as any, windowKey: "common.window-all" as any, spanMs: null, bucketMs: DAY_MS },
32
69
  };
33
70
 
34
71
  const MAX_BUCKETS = 1500;
35
72
 
36
73
  /** Ranges in selector order. */
37
- export const TIME_RANGES: readonly TimeRange[] = ["1h", "24h", "7d", "30d", "90d", "all"];
74
+ export const TIME_RANGES: readonly TimeRange[] = ["1h", "24h", "2d", "3d", "7d", "30d", "90d", "all"];
38
75
 
39
76
  export function rangeMeta(range: TimeRange): RangeMeta {
40
77
  return RANGE_META[range];
@@ -5,13 +5,17 @@ import type {
5
5
  FolderStats,
6
6
  MessageStats,
7
7
  ModelPerformancePoint,
8
+ SideChannelStats,
8
9
  ToolUsageStats,
10
+ UsageAttributionTotals,
9
11
  } from "../types";
10
- import { modelKey } from "./colors";
12
+ import { buildColorLookup, modelKey, SERIES_COLORS } from "./colors";
11
13
  import { isUnpricedMessage } from "./formatters";
12
14
 
13
- /** Fixed display order for the agent-token-share breakdown. */
15
+ /** Fixed display order of the agent types in a token share. */
14
16
  const AGENT_TYPE_ORDER: AgentType[] = ["main", "subagent", "advisor"];
17
+ /** Palette hues left to side-channel categories beside agent segments: the agent types wear the first three. */
18
+ const BESIDE_AGENT_COLORS = SERIES_COLORS.slice(3);
15
19
 
16
20
  export interface ConversationTokenStats {
17
21
  totalInputTokens: number;
@@ -25,50 +29,98 @@ export function sumConversationTokens(stats: ConversationTokenStats): number {
25
29
  return stats.totalInputTokens + stats.totalOutputTokens + stats.totalCacheReadTokens + stats.totalCacheWriteTokens;
26
30
  }
27
31
 
28
- export interface AgentTokenSegment {
29
- agentType: AgentType;
32
+ /** What a token-share segment counts: an agent type's conversation turns, or the calls of one side-channel category. */
33
+ export type TokenShareSource = { kind: "agent"; agentType: AgentType } | { kind: "sideChannel"; category: string };
34
+
35
+ export type TokenShareSegment = TokenShareSource & {
36
+ /** Unique within its view. */
37
+ key: string;
30
38
  /** input + output + cache read + cache write — the displayed denominator. */
31
39
  tokens: number;
32
40
  requests: number;
33
41
  cost: number;
34
- /** Fraction (0-1) of total tokens across all present agent types. */
42
+ /** Fraction (0-1) of the view's total tokens. */
35
43
  share: number;
36
- }
44
+ };
37
45
 
38
- export interface AgentTokenShareView {
46
+ export interface TokenShareView {
39
47
  totalTokens: number;
40
48
  totalCost: number;
41
- segments: AgentTokenSegment[];
49
+ segments: TokenShareSegment[];
50
+ /** Side-channel category -> color, ranked by tokens within this view so its largest categories never share a hue. */
51
+ categoryColors: Map<string, string>;
42
52
  }
43
53
 
44
- /**
45
- * Build the "token usage by agent" breakdown: one segment per agent type that
46
- * appears in the data, ordered main -> subagents -> advisor, each carrying its
47
- * token total and share of the grand total. Token counts use the same four
48
- * conversation-token buckets as the overview total so the two views reconcile.
49
- */
50
- export function buildAgentTokenShare(stats: AgentTypeStats[]): AgentTokenShareView {
54
+ /** A group's amounts; `share` is settled by {@link shareView} once the view's total is known. */
55
+ function segmentAmounts(stat: UsageAttributionTotals) {
56
+ return { tokens: sumConversationTokens(stat), requests: stat.totalRequests, cost: stat.totalCost, share: 0 };
57
+ }
58
+
59
+ /** One segment per agent type present in the data, ordered main -> subagents -> advisor. */
60
+ function agentSegments(stats: readonly AgentTypeStats[]): TokenShareSegment[] {
51
61
  const byType = new Map<AgentType, AgentTypeStats>();
52
62
  for (const stat of stats) byType.set(stat.agentType, stat);
63
+ const segments: TokenShareSegment[] = [];
64
+ for (const agentType of AGENT_TYPE_ORDER) {
65
+ const stat = byType.get(agentType);
66
+ if (stat) segments.push({ kind: "agent", agentType, key: `agent:${agentType}`, ...segmentAmounts(stat) });
67
+ }
68
+ return segments;
69
+ }
53
70
 
54
- const present = AGENT_TYPE_ORDER.map(type => byType.get(type)).filter(
55
- (stat): stat is AgentTypeStats => stat !== undefined,
56
- );
57
- const totalTokens = present.reduce((sum, stat) => sum + sumConversationTokens(stat), 0);
58
- const totalCost = present.reduce((sum, stat) => sum + stat.totalCost, 0);
71
+ /** One segment per category served by decision models (`decision`) or by language models, largest first. */
72
+ function sideChannelSegments(stats: readonly SideChannelStats[], decision: boolean): TokenShareSegment[] {
73
+ const segments: Extract<TokenShareSegment, { kind: "sideChannel" }>[] = [];
74
+ for (const stat of stats) {
75
+ if (stat.decision !== decision) continue;
76
+ segments.push({
77
+ kind: "sideChannel",
78
+ category: stat.category,
79
+ key: `side:${stat.category}`,
80
+ ...segmentAmounts(stat),
81
+ });
82
+ }
83
+ return segments.sort((a, b) => b.tokens - a.tokens || a.category.localeCompare(b.category));
84
+ }
59
85
 
60
- const segments = present.map(stat => {
61
- const tokens = sumConversationTokens(stat);
62
- return {
63
- agentType: stat.agentType,
64
- tokens,
65
- requests: stat.totalRequests,
66
- cost: stat.totalCost,
67
- share: totalTokens > 0 ? tokens / totalTokens : 0,
68
- };
69
- });
86
+ /** Settle each segment's share of the view's tokens and color the view's categories from `palette`. */
87
+ function shareView(segments: TokenShareSegment[], palette: readonly string[]): TokenShareView {
88
+ let totalTokens = 0;
89
+ let totalCost = 0;
90
+ const categories: { key: string; weight: number }[] = [];
91
+ for (const segment of segments) {
92
+ totalTokens += segment.tokens;
93
+ totalCost += segment.cost;
94
+ if (segment.kind === "sideChannel") categories.push({ key: segment.category, weight: segment.tokens });
95
+ }
96
+ if (totalTokens > 0) {
97
+ for (const segment of segments) segment.share = segment.tokens / totalTokens;
98
+ }
99
+ return { totalTokens, totalCost, segments, categoryColors: buildColorLookup(categories, palette) };
100
+ }
70
101
 
71
- return { totalTokens, totalCost, segments };
102
+ /**
103
+ * Build the "token usage by agent" breakdown: the conversation turns of each
104
+ * agent type present in the data, ordered main -> subagents -> advisor, then
105
+ * the side channels that ran on a language model, one segment per category,
106
+ * largest first. Shares are over all of them. Side channels served by decision
107
+ * models are left out: see {@link buildDecisionModelShare}. Token counts use
108
+ * the same four conversation-token buckets as the overview total.
109
+ */
110
+ export function buildUsageTokenShare(
111
+ byAgentType: readonly AgentTypeStats[],
112
+ bySideChannel: readonly SideChannelStats[],
113
+ ): TokenShareView {
114
+ return shareView([...agentSegments(byAgentType), ...sideChannelSegments(bySideChannel, false)], BESIDE_AGENT_COLORS);
115
+ }
116
+
117
+ /**
118
+ * Build the breakdown of decision-model usage: one segment per side-channel
119
+ * category served by a decision model, largest first, each with its share of
120
+ * all decision-model tokens. No segments when no decision model was called.
121
+ */
122
+ export function buildDecisionModelShare(bySideChannel: readonly SideChannelStats[]): TokenShareView {
123
+ return shareView(sideChannelSegments(bySideChannel, true), SERIES_COLORS);
72
124
  }
73
125
 
74
126
  /** API-equivalent cost split by billing component. */
@@ -27,7 +27,10 @@ export interface GainRouteProps {
27
27
 
28
28
  const DAY_MS = 86_400_000;
29
29
 
30
- const SOURCE_LABEL: Record<GainSource, string> = { snapcompact: "Snapcompact" };
30
+ const SOURCE_LABEL: Record<GainSource, string> = {
31
+ snapcompact: "Snapcompact imaged tool results",
32
+ compaction: "Snapcompact compaction (context freed)",
33
+ };
31
34
 
32
35
  /** The server buckets gain by local calendar day (`YYYY-MM-DD`). */
33
36
  interface SourceRow extends GainSourceTotals {
@@ -52,7 +55,7 @@ export function GainRoute({ active, range }: GainRouteProps) {
52
55
  points.map(p => p.timestamp),
53
56
  DAY_MS,
54
57
  );
55
- const daily = densify(points, buckets, p => p.snapcompact);
58
+ const daily = densify(points, buckets, p => p.total);
56
59
  let running = 0;
57
60
  const cumulative = daily.map(v => (running += v));
58
61
  return { buckets, daily, cumulative };
@@ -3,6 +3,7 @@ import { useMemo, useState } from "react";
3
3
  import { getOverviewStats, getRecentRequests } from "../api";
4
4
  import { t } from "../i18n";
5
5
  import { Legend, ShareBar, TimeChart } from "../charts";
6
+ import { OTHER_COLOR } from "../data/colors";
6
7
  import {
7
8
  formatCompact,
8
9
  formatDurationMs,
@@ -17,7 +18,13 @@ import {
17
18
  import { useQuery } from "../data/query";
18
19
  import { bucketAxis, rangeMeta } from "../data/range";
19
20
  import { densify } from "../data/series";
20
- import { buildAgentTokenShare, sumConversationTokens } from "../data/view-models";
21
+ import {
22
+ buildDecisionModelShare,
23
+ buildUsageTokenShare,
24
+ sumConversationTokens,
25
+ type TokenShareSegment,
26
+ type TokenShareView,
27
+ } from "../data/view-models";
21
28
  import type { AgentType, MessageStats, TimeRange } from "../types";
22
29
  import {
23
30
  Badge,
@@ -97,6 +104,15 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
97
104
  };
98
105
  }, [overview.data, range]);
99
106
 
107
+ const attribution = useMemo(() => {
108
+ const data = overview.data;
109
+ if (!data) return null;
110
+ return {
111
+ usage: buildUsageTokenShare(data.byAgentType, data.bySideChannel),
112
+ decisions: buildDecisionModelShare(data.bySideChannel),
113
+ };
114
+ }, [overview.data]);
115
+
100
116
  const chartSeries =
101
117
  metric === "requests"
102
118
  ? [
@@ -232,7 +248,7 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
232
248
  stale={overview.stale}
233
249
  >
234
250
  <QueryView query={overview} skeleton={<ChartSkeleton height={260} />}>
235
- {({ overall, byAgentType }) => {
251
+ {({ overall }) => {
236
252
  const mix = {
237
253
  input: overall.totalInputTokens,
238
254
  cacheRead: overall.totalCacheReadTokens,
@@ -240,7 +256,6 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
240
256
  output: overall.totalOutputTokens,
241
257
  };
242
258
  const total = sumConversationTokens(overall);
243
- const agents = buildAgentTokenShare(byAgentType);
244
259
  return (
245
260
  <div className="stack" style={{ gap: 18 }}>
246
261
  <div className="stack" style={{ gap: 10 }}>
@@ -261,36 +276,14 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
261
276
  }))}
262
277
  />
263
278
  </div>
264
- <div className="stack" style={{ gap: 10 }}>
265
- <div className="section-label" style={{ marginBottom: 0 }}>
266
- {t("overview.by-agent")}
267
- </div>
268
- <ShareBar
269
- segments={agents.segments.map(s => ({
270
- key: s.agentType,
271
- label: t(AGENT_LABEL_KEY[s.agentType]),
272
- value: s.tokens,
273
- color: AGENT_COLOR[s.agentType],
274
- }))}
275
- />
276
- {agents.segments.map(s => (
277
- <div key={s.agentType} className="row" style={{ justifyContent: "space-between" }}>
278
- <span className="row">
279
- <span className="swatch" style={{ background: AGENT_COLOR[s.agentType] }} />
280
- {t(AGENT_LABEL_KEY[s.agentType])}
281
- <span className="dim num">
282
- {t("overview.requests-short", { count: formatInteger(s.requests) })}
283
- </span>
284
- </span>
285
- <span className="row">
286
- <span className="dim num">{formatCompact(s.tokens)}</span>
287
- <span className="num" style={{ minWidth: 48, textAlign: "right" }}>
288
- {formatPercent(s.share)}
289
- </span>
290
- </span>
279
+ {attribution && (
280
+ <div className="stack" style={{ gap: 10 }}>
281
+ <div className="section-label" style={{ marginBottom: 0 }}>
282
+ By source
291
283
  </div>
292
- ))}
293
- </div>
284
+ <ShareBreakdown view={attribution.usage} />
285
+ </div>
286
+ )}
294
287
  </div>
295
288
  );
296
289
  }}
@@ -298,8 +291,19 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
298
291
  </Card>
299
292
  </div>
300
293
 
294
+ {attribution && attribution.decisions.segments.length > 0 && (
295
+ <Card
296
+ index={3}
297
+ title="Decision models"
298
+ description="Where decision-model tokens went, by use case"
299
+ stale={overview.stale}
300
+ >
301
+ <ShareBreakdown view={attribution.decisions} wide />
302
+ </Card>
303
+ )}
304
+
301
305
  <Card
302
- index={3}
306
+ index={4}
303
307
  title={
304
308
  <>
305
309
  <Dot tone="live" pulse /> {t("overview.latest-requests")}
@@ -329,6 +333,55 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
329
333
  );
330
334
  }
331
335
 
336
+ function segmentLabel(segment: TokenShareSegment): string {
337
+ if (segment.kind === "agent") return t(AGENT_LABEL_KEY[segment.agentType]);
338
+ return segment.category.charAt(0).toUpperCase() + segment.category.slice(1);
339
+ }
340
+
341
+ function segmentColor(segment: TokenShareSegment, colors: ReadonlyMap<string, string>): string {
342
+ if (segment.kind === "agent") return AGENT_COLOR[segment.agentType];
343
+ return colors.get(segment.category) ?? OTHER_COLOR;
344
+ }
345
+
346
+ /**
347
+ * A share bar over one row per segment: swatch, label, requests, tokens, percent of the bar.
348
+ * `wide` lays the rows out in columns, for a card that spans the page.
349
+ */
350
+ function ShareBreakdown({ view, wide = false }: { view: TokenShareView; wide?: boolean }) {
351
+ const { segments, categoryColors } = view;
352
+ return (
353
+ <div className="stack" style={{ gap: 10 }}>
354
+ <ShareBar
355
+ segments={segments.map(s => ({
356
+ key: s.key,
357
+ label: segmentLabel(s),
358
+ value: s.tokens,
359
+ color: segmentColor(s, categoryColors),
360
+ }))}
361
+ />
362
+ <div className={wide ? "grid grid-3" : "stack"} style={{ gap: wide ? "10px 28px" : 10 }}>
363
+ {segments.map(s => (
364
+ <div key={s.key} className="row" style={{ justifyContent: "space-between" }}>
365
+ <span className="row" style={{ minWidth: 0 }}>
366
+ <span className="swatch" style={{ background: segmentColor(s, categoryColors) }} />
367
+ <span className="truncate">{segmentLabel(s)}</span>
368
+ <span className="dim num" style={{ flexShrink: 0 }}>
369
+ {t("overview.requests-short", { count: formatInteger(s.requests) })}
370
+ </span>
371
+ </span>
372
+ <span className="row" style={{ flexShrink: 0 }}>
373
+ <span className="dim num">{formatCompact(s.tokens)}</span>
374
+ <span className="num" style={{ minWidth: 48, textAlign: "right" }}>
375
+ {formatPercent(s.share)}
376
+ </span>
377
+ </span>
378
+ </div>
379
+ ))}
380
+ </div>
381
+ </div>
382
+ );
383
+ }
384
+
332
385
  function requestColumns(): Column<MessageStats>[] {
333
386
  return [
334
387
  {
@@ -19,6 +19,7 @@ import type {
19
19
  ModelPerformancePoint,
20
20
  ModelStats,
21
21
  ModelTimeSeriesPoint,
22
+ SideChannelStats,
22
23
  TimeSeriesPoint,
23
24
  } from "../shared-types";
24
25
 
@@ -63,11 +64,12 @@ export interface RequestDetails extends MessageStats {
63
64
  output: unknown;
64
65
  }
65
66
 
66
- export type TimeRange = "1h" | "24h" | "7d" | "30d" | "90d" | "all";
67
+ export type TimeRange = "1h" | "24h" | "2d" | "3d" | "7d" | "30d" | "90d" | "all";
67
68
 
68
69
  export interface OverviewStats {
69
70
  overall: AggregatedStats;
70
71
  byAgentType: AgentTypeStats[];
72
+ bySideChannel: SideChannelStats[];
71
73
  timeSeries: TimeSeriesPoint[];
72
74
  }
73
75