@linxiraos/pi-stats 1.5.14 → 1.5.15
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 +31 -16
- package/README.md +7 -1
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/dist/client/index.js +81 -81
- package/dist/types/aggregator.d.ts +1 -1
- package/dist/types/client/app/Shell.d.ts +1 -1
- package/dist/types/client/data/colors.d.ts +5 -2
- package/dist/types/client/data/view-models.d.ts +30 -11
- package/dist/types/client/types.d.ts +3 -2
- package/dist/types/db.d.ts +23 -2
- package/dist/types/gain-aggregator.d.ts +4 -4
- package/dist/types/parser.d.ts +2 -1
- package/dist/types/rollup.d.ts +12 -4
- package/dist/types/server.d.ts +2 -0
- package/dist/types/shared-types.d.ts +34 -9
- package/dist/types/side-channels.d.ts +28 -0
- package/dist/types/spotlight-ingest.d.ts +8 -5
- package/dist/types/types.d.ts +42 -1
- package/package.json +44 -44
- package/src/aggregator.ts +11 -4
- package/src/client/app/Shell.tsx +1 -1
- package/src/client/charts/TimeChart.tsx +8 -1
- package/src/client/data/colors.ts +9 -3
- package/src/client/data/range.ts +44 -7
- package/src/client/data/view-models.ts +83 -31
- package/src/client/routes/GainRoute.tsx +5 -2
- package/src/client/routes/OverviewRoute.tsx +86 -33
- package/src/client/types.ts +3 -1
- package/src/db.ts +150 -20
- package/src/gain-aggregator.ts +68 -32
- package/src/parser.ts +46 -1
- package/src/rollup.ts +112 -25
- package/src/server.ts +68 -0
- package/src/shared-types.ts +36 -9
- package/src/side-channels.ts +63 -0
- package/src/spotlight-ingest.ts +49 -23
- package/src/types.ts +36 -1
|
@@ -78,7 +78,7 @@ export declare function getTimeRangeConfig(range?: string | null): RangeWindow;
|
|
|
78
78
|
* Get all dashboard stats.
|
|
79
79
|
*/
|
|
80
80
|
export declare function getDashboardStats(range?: string | null): Promise<DashboardStats>;
|
|
81
|
-
export declare function getOverviewStats(range?: string | null): Promise<Pick<DashboardStats, "overall" | "byAgentType" | "timeSeries">>;
|
|
81
|
+
export declare function getOverviewStats(range?: string | null): Promise<Pick<DashboardStats, "overall" | "byAgentType" | "bySideChannel" | "timeSeries">>;
|
|
82
82
|
export declare function getModelDashboardStats(range?: string | null): Promise<Pick<DashboardStats, "byModel" | "modelSeries" | "modelPerformanceSeries">>;
|
|
83
83
|
export declare function getCostDashboardStats(range?: string | null): Promise<Pick<DashboardStats, "costSeries">>;
|
|
84
84
|
export declare function getFolderStats(range?: string | null): Promise<FolderStats[]>;
|
|
@@ -10,7 +10,7 @@ export interface ShellProps {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Fixed glass topbar + naked sidebar framing one inset content panel. Owns
|
|
13
|
-
* the global keyboard shortcuts: `1`–`
|
|
13
|
+
* the global keyboard shortcuts: `1`–`8` pick a range, `g` then a letter jumps
|
|
14
14
|
* to a page.
|
|
15
15
|
*/
|
|
16
16
|
export declare function Shell({ section, onSectionChange, range, onRangeChange, children }: ShellProps): import("react").JSX.Element;
|
|
@@ -18,8 +18,11 @@ export declare function buildModelColorLookup(records: readonly {
|
|
|
18
18
|
provider: string;
|
|
19
19
|
totalRequests: number;
|
|
20
20
|
}[]): Map<string, string>;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Generic form of {@link buildModelColorLookup} for any keyed, weighted series.
|
|
23
|
+
* `palette` narrows the hues when some are spoken for on the same chart.
|
|
24
|
+
*/
|
|
22
25
|
export declare function buildColorLookup(items: readonly {
|
|
23
26
|
key: string;
|
|
24
27
|
weight: number;
|
|
25
|
-
}[]): Map<string, string>;
|
|
28
|
+
}[], palette?: readonly string[]): Map<string, string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentType, AgentTypeStats, CostTimeSeriesPoint, FolderStats, MessageStats, ModelPerformancePoint, ToolUsageStats } from "../types.js";
|
|
1
|
+
import type { AgentType, AgentTypeStats, CostTimeSeriesPoint, FolderStats, MessageStats, ModelPerformancePoint, SideChannelStats, ToolUsageStats } from "../types.js";
|
|
2
2
|
export interface ConversationTokenStats {
|
|
3
3
|
totalInputTokens: number;
|
|
4
4
|
totalOutputTokens: number;
|
|
@@ -7,27 +7,46 @@ export interface ConversationTokenStats {
|
|
|
7
7
|
}
|
|
8
8
|
/** Sum every conversation-token bucket shown by the overview. */
|
|
9
9
|
export declare function sumConversationTokens(stats: ConversationTokenStats): number;
|
|
10
|
-
|
|
10
|
+
/** What a token-share segment counts: an agent type's conversation turns, or the calls of one side-channel category. */
|
|
11
|
+
export type TokenShareSource = {
|
|
12
|
+
kind: "agent";
|
|
11
13
|
agentType: AgentType;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "sideChannel";
|
|
16
|
+
category: string;
|
|
17
|
+
};
|
|
18
|
+
export type TokenShareSegment = TokenShareSource & {
|
|
19
|
+
/** Unique within its view. */
|
|
20
|
+
key: string;
|
|
12
21
|
/** input + output + cache read + cache write — the displayed denominator. */
|
|
13
22
|
tokens: number;
|
|
14
23
|
requests: number;
|
|
15
24
|
cost: number;
|
|
16
|
-
/** Fraction (0-1) of total tokens
|
|
25
|
+
/** Fraction (0-1) of the view's total tokens. */
|
|
17
26
|
share: number;
|
|
18
|
-
}
|
|
19
|
-
export interface
|
|
27
|
+
};
|
|
28
|
+
export interface TokenShareView {
|
|
20
29
|
totalTokens: number;
|
|
21
30
|
totalCost: number;
|
|
22
|
-
segments:
|
|
31
|
+
segments: TokenShareSegment[];
|
|
32
|
+
/** Side-channel category -> color, ranked by tokens within this view so its largest categories never share a hue. */
|
|
33
|
+
categoryColors: Map<string, string>;
|
|
23
34
|
}
|
|
24
35
|
/**
|
|
25
|
-
* Build the "token usage by agent" breakdown:
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
36
|
+
* Build the "token usage by agent" breakdown: the conversation turns of each
|
|
37
|
+
* agent type present in the data, ordered main -> subagents -> advisor, then
|
|
38
|
+
* the side channels that ran on a language model, one segment per category,
|
|
39
|
+
* largest first. Shares are over all of them. Side channels served by decision
|
|
40
|
+
* models are left out: see {@link buildDecisionModelShare}. Token counts use
|
|
41
|
+
* the same four conversation-token buckets as the overview total.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildUsageTokenShare(byAgentType: readonly AgentTypeStats[], bySideChannel: readonly SideChannelStats[]): TokenShareView;
|
|
44
|
+
/**
|
|
45
|
+
* Build the breakdown of decision-model usage: one segment per side-channel
|
|
46
|
+
* category served by a decision model, largest first, each with its share of
|
|
47
|
+
* all decision-model tokens. No segments when no decision model was called.
|
|
29
48
|
*/
|
|
30
|
-
export declare function
|
|
49
|
+
export declare function buildDecisionModelShare(bySideChannel: readonly SideChannelStats[]): TokenShareView;
|
|
31
50
|
/** API-equivalent cost split by billing component. */
|
|
32
51
|
export interface CostComponents {
|
|
33
52
|
costInput: number;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - `TimeRange`, `OverviewStats`, `ModelDashboardStats`,
|
|
12
12
|
* `CostDashboardStats` are UI-only view shapes the server never produces.
|
|
13
13
|
*/
|
|
14
|
-
import type { AgentTypeStats, AggregatedStats, CostTimeSeriesPoint, ModelPerformancePoint, ModelStats, ModelTimeSeriesPoint, TimeSeriesPoint } from "../shared-types.js";
|
|
14
|
+
import type { AgentTypeStats, AggregatedStats, CostTimeSeriesPoint, ModelPerformancePoint, ModelStats, ModelTimeSeriesPoint, SideChannelStats, TimeSeriesPoint } from "../shared-types.js";
|
|
15
15
|
export * from "../shared-types.js";
|
|
16
16
|
export interface Usage {
|
|
17
17
|
input: number;
|
|
@@ -49,10 +49,11 @@ export interface RequestDetails extends MessageStats {
|
|
|
49
49
|
messages: unknown[];
|
|
50
50
|
output: unknown;
|
|
51
51
|
}
|
|
52
|
-
export type TimeRange = "1h" | "24h" | "7d" | "30d" | "90d" | "all";
|
|
52
|
+
export type TimeRange = "1h" | "24h" | "2d" | "3d" | "7d" | "30d" | "90d" | "all";
|
|
53
53
|
export interface OverviewStats {
|
|
54
54
|
overall: AggregatedStats;
|
|
55
55
|
byAgentType: AgentTypeStats[];
|
|
56
|
+
bySideChannel: SideChannelStats[];
|
|
56
57
|
timeSeries: TimeSeriesPoint[];
|
|
57
58
|
}
|
|
58
59
|
export interface ModelDashboardStats {
|
package/dist/types/db.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Database } from "bun:sqlite";
|
|
2
2
|
import { type ParseSessionResult, type SessionParserState } from "./parser.js";
|
|
3
3
|
import { type SpotlightCallResultLink, type SpotlightCallRow, type SpotlightNeedRow, type SpotlightRequestRow, type SpotlightSessionRow, type SpotlightShapeRow } from "./spotlight-ingest.js";
|
|
4
|
-
import type { AssistantTextStats, DailyActivityPoint, FrustrationCounts, MessageStats, MessageStatsInput, ModelDailyActivityPoint, ModelHourlyActivityPoint, ModelSideCounts, ModelSideTimeSeriesPoint, ToolCallStats, ToolResultLink, UserMessageLink, UserMessageStats } from "./types.js";
|
|
4
|
+
import type { AssistantTextStats, DailyActivityPoint, FrustrationCounts, MessageStats, MessageStatsInput, ModelDailyActivityPoint, ModelHourlyActivityPoint, ModelSideCounts, ModelSideTimeSeriesPoint, SnapcompactCompactionStats, ToolCallStats, ToolResultLink, UserMessageLink, UserMessageStats } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Predicate counting one stored request as "unpriced" — the public rate card
|
|
7
7
|
* has no charge for it, so its zero is unknown spend rather than free usage.
|
|
@@ -22,6 +22,11 @@ import type { AssistantTextStats, DailyActivityPoint, FrustrationCounts, Message
|
|
|
22
22
|
export declare function unpricedRequestSql(prefix?: string): string;
|
|
23
23
|
/** The open stats database, or null before {@link initDb}. Used by the rollup query layer. */
|
|
24
24
|
export declare function currentDb(): Database | null;
|
|
25
|
+
/**
|
|
26
|
+
* Env var overriding {@link BUSY_TIMEOUT_MS} (positive milliseconds) for the
|
|
27
|
+
* stats database's busy handler.
|
|
28
|
+
*/
|
|
29
|
+
export declare const STATS_BUSY_TIMEOUT_MS_ENV = "ZETA_STATS_BUSY_TIMEOUT_MS";
|
|
25
30
|
/**
|
|
26
31
|
* Initialize the database and create tables.
|
|
27
32
|
*/
|
|
@@ -83,7 +88,10 @@ export declare function completeSessionSync(reconcile: boolean): void;
|
|
|
83
88
|
* first-write-wins across the lineage. Same-file re-syncs still hit the
|
|
84
89
|
* `ON CONFLICT(session_file, entry_id)` upsert below, which re-derives the
|
|
85
90
|
* stored cost (orchestration-aware) and keeps `premium_requests` monotonic, so
|
|
86
|
-
* a forced re-parse repairs historical `premium_requests` and cost fix-ups.
|
|
91
|
+
* a forced re-parse repairs historical `premium_requests` and cost fix-ups. It
|
|
92
|
+
* also rewrites the parser-derived `purpose`, `duration` and `ttft`, so a row
|
|
93
|
+
* stored by a build that did not read them from `model_usage` entries is
|
|
94
|
+
* repaired by the same re-parse.
|
|
87
95
|
*/
|
|
88
96
|
export declare function insertMessageStats(stats: Iterable<MessageStatsInput>): number;
|
|
89
97
|
/**
|
|
@@ -106,6 +114,14 @@ export declare function getMessageById(id: number): MessageStats | null;
|
|
|
106
114
|
* raw rows while its rebuild backlog is too large for exact reads.
|
|
107
115
|
*/
|
|
108
116
|
export declare function getDailyActivity(days?: number, now?: number): Promise<DailyActivityPoint[]>;
|
|
117
|
+
/**
|
|
118
|
+
* {@link getDailyActivity} from the stored rows through a connection of its
|
|
119
|
+
* own that never writes: no schema setup or one-time pass runs first, so
|
|
120
|
+
* another process holding the write lock never delays or fails it (WAL
|
|
121
|
+
* readers do not wait for writers). Returns null when the stats database
|
|
122
|
+
* cannot be opened, as before one exists.
|
|
123
|
+
*/
|
|
124
|
+
export declare function readDailyActivity(days?: number): DailyActivityPoint[] | null;
|
|
109
125
|
/**
|
|
110
126
|
* Lookback for the Studio home usage card. It renders a calendar-year heatmap
|
|
111
127
|
* plus a year-to-date model legend, so the window has to reach back past
|
|
@@ -270,6 +286,11 @@ export declare function insertToolCalls(calls: Iterable<ToolCallStats>): number;
|
|
|
270
286
|
* never match.
|
|
271
287
|
*/
|
|
272
288
|
export declare function updateToolResults(links: Iterable<ToolResultLink>): number;
|
|
289
|
+
/**
|
|
290
|
+
* Insert snapcompact compaction rows. Forked transcripts copy compaction
|
|
291
|
+
* entries verbatim, so the fork guard keeps one row per entry across the lineage.
|
|
292
|
+
*/
|
|
293
|
+
export declare function insertSnapcompactCompactions(rows: Iterable<SnapcompactCompactionStats>): number;
|
|
273
294
|
/** Record each experiment session's first Spotlight marker; a later one (a resumed session) never replaces it. */
|
|
274
295
|
export declare function insertSpotlightSessions(rows: Iterable<SpotlightSessionRow>): number;
|
|
275
296
|
export declare function updateSpotlightTitles(rows: Iterable<{
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Aggregates token-savings data for the Gain dashboard.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 1.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Sources:
|
|
5
|
+
* 1. Imaged tool results: colocated with stats.db as snapcompact-savings.jsonl
|
|
6
|
+
* (a missing file is zero records, never an error)
|
|
7
|
+
* 2. Snapcompact compactions: the `snapcompact_compactions` table the session sync fills
|
|
8
8
|
*/
|
|
9
9
|
import type { GainDashboardStats } from "./shared-types.js";
|
|
10
10
|
/**
|
package/dist/types/parser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as nodeFs from "node:fs";
|
|
2
2
|
import { type ServiceTierByFamily } from "@linxiraos/pi-ai";
|
|
3
|
-
import type { AgentType, AssistantTextStats, MessageStatsInput, SessionEntry, ToolCallStats, ToolResultLink, UserMessageLink, UserMessageStats } from "./types.js";
|
|
3
|
+
import type { AgentType, AssistantTextStats, MessageStatsInput, SessionEntry, SnapcompactCompactionStats, ToolCallStats, ToolResultLink, UserMessageLink, UserMessageStats } from "./types.js";
|
|
4
4
|
import { type SpotlightParseRows, type SpotlightParserState } from "./spotlight-ingest.js";
|
|
5
5
|
/**
|
|
6
6
|
* Classify which agent produced a transcript from its path within the sessions
|
|
@@ -68,6 +68,7 @@ export interface ParseSessionResult {
|
|
|
68
68
|
userLinks: UserMessageLink[];
|
|
69
69
|
toolCalls: ToolCallStats[];
|
|
70
70
|
toolResults: ToolResultLink[];
|
|
71
|
+
snapcompactCompactions: SnapcompactCompactionStats[];
|
|
71
72
|
spotlight: SpotlightParseRows;
|
|
72
73
|
newOffset: number;
|
|
73
74
|
parserState?: SessionParserState;
|
package/dist/types/rollup.d.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* (an hour of data is small and indexed by timestamp).
|
|
26
26
|
*/
|
|
27
27
|
import type { Database } from "bun:sqlite";
|
|
28
|
-
import type { AgentType, AgentTypeStats, AggregatedStats, CostTimeSeriesPoint, DailyActivityPoint, FolderStats, ModelDailyActivityPoint, ModelHourlyActivityPoint, ModelPerformancePoint, ModelStats, ModelTimeSeriesPoint, ProviderAggregate, ProviderHourlyPoint, ProviderTimeSeriesPoint, TimeSeriesPoint, ToolModelStats, ToolTimeSeriesPoint, ToolUsageStats } from "./types.js";
|
|
28
|
+
import type { AgentType, AgentTypeStats, AggregatedStats, CostTimeSeriesPoint, DailyActivityPoint, DashboardStats, FolderStats, ModelDailyActivityPoint, ModelHourlyActivityPoint, ModelPerformancePoint, ModelStats, ModelTimeSeriesPoint, ProviderAggregate, ProviderHourlyPoint, ProviderTimeSeriesPoint, TimeSeriesPoint, ToolModelStats, ToolTimeSeriesPoint, ToolUsageStats } from "./types.js";
|
|
29
29
|
/**
|
|
30
30
|
* Create (or rebuild after a version bump) the rollup tables and the triggers
|
|
31
31
|
* that mark hours dirty. Called from `initDb` after the raw tables exist.
|
|
@@ -72,6 +72,13 @@ export declare function getStatsByFolder(cutoff?: number | null, limit?: number)
|
|
|
72
72
|
export declare function getProjectFolders(limit?: number): string[];
|
|
73
73
|
/** Newest session file registered for a project folder, used to resolve its real cwd. */
|
|
74
74
|
export declare function getProjectSessionFile(folder: string): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Usage attributed to what spent it: conversation turns per agent type (main,
|
|
77
|
+
* subagent, advisor) and side channels per category, apart for decision models.
|
|
78
|
+
* Rows are grouped by their raw dimensions and classified here (see
|
|
79
|
+
* `side-channels.ts`), so every row lands in exactly one group.
|
|
80
|
+
*/
|
|
81
|
+
export declare function getUsageAttribution(cutoff?: number | null): Pick<DashboardStats, "byAgentType" | "bySideChannel">;
|
|
75
82
|
/** Token usage per agent type (main, subagent, advisor). */
|
|
76
83
|
export declare function getStatsByAgentType(cutoff?: number | null): AgentTypeStats[];
|
|
77
84
|
/** Requests, errors, tokens and cost per bucket. */
|
|
@@ -95,10 +102,11 @@ export declare function getProviderHourlyBurn(cutoff?: number | null): ProviderH
|
|
|
95
102
|
* Per-local-day request/token/cost totals since `cutoff`, oldest first, read
|
|
96
103
|
* from the hourly rollup. Returns null when the local UTC offset is not a whole
|
|
97
104
|
* hour (now or at `cutoff`), since hourly buckets then straddle local midnight,
|
|
98
|
-
*
|
|
99
|
-
*
|
|
105
|
+
* when the stored rollup is missing or was built under another version, or
|
|
106
|
+
* while the dirty backlog is too large for exact reads; callers then aggregate
|
|
107
|
+
* the raw rows instead.
|
|
100
108
|
*/
|
|
101
|
-
export declare function getDailyActivityFromRollup(cutoff: number): DailyActivityPoint[] | null;
|
|
109
|
+
export declare function getDailyActivityFromRollup(cutoff: number, database?: Database | null): DailyActivityPoint[] | null;
|
|
102
110
|
/**
|
|
103
111
|
* Per-model token totals per local day since `cutoff`, oldest day first. Same
|
|
104
112
|
* exactness rules as every range read (clean rollup hours plus raw rows for the
|
package/dist/types/server.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare function setStatsCloseHandler(close: (() => void) | undefined): v
|
|
|
12
12
|
export declare function handleApi(req: Request): Promise<Response>;
|
|
13
13
|
/** Format a dashboard origin, including brackets required by IPv6 literals. */
|
|
14
14
|
export declare function formatStatsDashboardUrl(hostname: string, port: number): string;
|
|
15
|
+
/** Extra Host names (comma-separated) the dashboard answers to; `*.example.com` allows its subdomains. */
|
|
16
|
+
export declare const STATS_ALLOWED_HOSTS_ENV = "OMP_STATS_ALLOWED_HOSTS";
|
|
15
17
|
/** A dashboard this process started or found; `reused` distinguishes another process's server from one we own. */
|
|
16
18
|
export interface StatsServerHandle {
|
|
17
19
|
hostname: string;
|
|
@@ -173,6 +173,7 @@ export interface DashboardStats {
|
|
|
173
173
|
byModel: ModelStats[];
|
|
174
174
|
byFolder: FolderStats[];
|
|
175
175
|
byAgentType: AgentTypeStats[];
|
|
176
|
+
bySideChannel: SideChannelStats[];
|
|
176
177
|
timeSeries: TimeSeriesPoint[];
|
|
177
178
|
modelSeries: ModelTimeSeriesPoint[];
|
|
178
179
|
modelPerformanceSeries: ModelPerformancePoint[];
|
|
@@ -186,12 +187,12 @@ export interface DashboardStats {
|
|
|
186
187
|
*/
|
|
187
188
|
export type AgentType = "main" | "subagent" | "advisor";
|
|
188
189
|
/**
|
|
189
|
-
*
|
|
190
|
-
* columns are explicit so the dashboard's share
|
|
191
|
-
* counts it renders (input + output + cache read +
|
|
190
|
+
* Request, token and cost totals of one usage-attribution group over the
|
|
191
|
+
* active range. Token columns are explicit so the dashboard's share
|
|
192
|
+
* denominator matches the counts it renders (input + output + cache read +
|
|
193
|
+
* cache write).
|
|
192
194
|
*/
|
|
193
|
-
export interface
|
|
194
|
-
agentType: AgentType;
|
|
195
|
+
export interface UsageAttributionTotals {
|
|
195
196
|
/** Total number of requests */
|
|
196
197
|
totalRequests: number;
|
|
197
198
|
/** Total input tokens */
|
|
@@ -205,6 +206,26 @@ export interface AgentTypeStats {
|
|
|
205
206
|
/** Total cost */
|
|
206
207
|
totalCost: number;
|
|
207
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Usage of conversation turns (assistant messages, discarded ones included)
|
|
211
|
+
* aggregated by {@link AgentType}. Off-transcript model calls are not in here:
|
|
212
|
+
* see {@link SideChannelStats}.
|
|
213
|
+
*/
|
|
214
|
+
export interface AgentTypeStats extends UsageAttributionTotals {
|
|
215
|
+
agentType: AgentType;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Usage of side channels (model calls that are not conversation turns: title
|
|
219
|
+
* generation, job captions, judge queries, …) aggregated per use case, apart
|
|
220
|
+
* for calls served by a decision model and calls served by a language model.
|
|
221
|
+
* Busiest group first.
|
|
222
|
+
*/
|
|
223
|
+
export interface SideChannelStats extends UsageAttributionTotals {
|
|
224
|
+
/** Use case, such as `title` or `progress`; a purpose without a known category is its own. */
|
|
225
|
+
category: string;
|
|
226
|
+
/** Whether the calls ran on a decision model (an api that answers judgments natively). */
|
|
227
|
+
decision: boolean;
|
|
228
|
+
}
|
|
208
229
|
/**
|
|
209
230
|
* Model-side tallies over assistant turns. Every field except `messages`,
|
|
210
231
|
* `collapse`, `words` and `toolErrors` counts turns carrying the signal, so
|
|
@@ -365,7 +386,7 @@ export interface FrustrationDashboardStats {
|
|
|
365
386
|
byModel: FrustrationModelStats[];
|
|
366
387
|
/** Model-side (AI breakdown) analysis alongside the user-side tallies. */
|
|
367
388
|
modelSide: ModelSideDashboardStats;
|
|
368
|
-
/** Whether this dashboard host can run the judge (standalone `
|
|
389
|
+
/** Whether this dashboard host can run the judge (standalone `pi-stats` cannot). */
|
|
369
390
|
judgeAvailable: boolean;
|
|
370
391
|
job: FrustrationJobStatus;
|
|
371
392
|
}
|
|
@@ -398,12 +419,16 @@ export interface GainSourceTotals {
|
|
|
398
419
|
/** savedBytes / originalBytes when both are known, else null */
|
|
399
420
|
reductionPercent: number | null;
|
|
400
421
|
}
|
|
401
|
-
/**
|
|
402
|
-
|
|
422
|
+
/**
|
|
423
|
+
* Per-source breakdown: `snapcompact` is tool results snapcompact sent as images,
|
|
424
|
+
* `compaction` is the context snapcompact compactions freed.
|
|
425
|
+
*/
|
|
426
|
+
export type GainSource = "snapcompact" | "compaction";
|
|
403
427
|
/** Time-series point for gain (daily bucket). */
|
|
404
428
|
export interface GainTimeSeriesPoint {
|
|
405
429
|
date: string;
|
|
406
430
|
snapcompact: number;
|
|
431
|
+
compaction?: number;
|
|
407
432
|
total: number;
|
|
408
433
|
}
|
|
409
434
|
/** Complete gain dashboard payload. */
|
|
@@ -431,7 +456,7 @@ export interface SpotlightToolRow extends SpotlightToolTotals {
|
|
|
431
456
|
}
|
|
432
457
|
/**
|
|
433
458
|
* How the model got back output a shortened result hid:
|
|
434
|
-
* - `artifact`: a later call read or searched
|
|
459
|
+
* - `artifact`: a later call read or searched a spill the shortened result named (`local://N.log`, or `artifact://N` in older transcripts);
|
|
435
460
|
* - `reread`: a later `read` of the same file whose selection overlaps the hidden lines, or the whole file again;
|
|
436
461
|
* - `rerun`: a later call of the same tool repeating the shortened one: a bash command with a pipe, redirect or
|
|
437
462
|
* changed flags; any other tool with near-identical arguments (same tool, argument tokens' Jaccard ≥ 0.6).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classification of the model calls stored in `messages`, for attributing usage.
|
|
3
|
+
*
|
|
4
|
+
* - A **turn** is an assistant message (stored with a NULL purpose), or the
|
|
5
|
+
* billed usage of a discarded assistant turn, which the session journals as
|
|
6
|
+
* a `model_usage` entry with purpose `discarded-turn`.
|
|
7
|
+
* - A **side channel** is every other `model_usage` entry: a model call that
|
|
8
|
+
* is not part of the conversation (title generation, job captions, judge
|
|
9
|
+
* queries, …). Its category groups the purposes of one use case.
|
|
10
|
+
* - A side channel runs on a **decision model** when its api answers
|
|
11
|
+
* judgments natively instead of generating text.
|
|
12
|
+
*
|
|
13
|
+
* The purposes are written by the coding agent, which stats never imports, so
|
|
14
|
+
* the table lives here. Rows and rollups store the raw purpose and api and
|
|
15
|
+
* everything below is derived at read time: the table applies to entries
|
|
16
|
+
* already ingested and can be re-cut without re-ingesting.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Side-channel category of a row from its stored `purpose`, or `null` when the
|
|
20
|
+
* row is a turn. A `:detail` suffix belongs to its base purpose
|
|
21
|
+
* (`cache-warm:extension-override` is `cache-warm`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function sideChannelCategory(purpose: string | null): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Whether a side-channel row with this stored `api` ran on a decision model.
|
|
26
|
+
* Decided by the api alone, never by model or provider ids.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isDecisionModelApi(api: string): boolean;
|
|
@@ -94,7 +94,10 @@ export interface SpotlightShapeRow {
|
|
|
94
94
|
gated: boolean;
|
|
95
95
|
/** `details.spotlight.original` (present only when shaping changed the text). */
|
|
96
96
|
original: SpotlightOriginalFacts | null;
|
|
97
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Artifact ids the result names (its text's spill URLs, `local://N.log` or legacy `artifact://N`, plus
|
|
99
|
+
* `original.url`); null before the result lands.
|
|
100
|
+
*/
|
|
98
101
|
artifacts: number[] | null;
|
|
99
102
|
/**
|
|
100
103
|
* Spotlight's own usage, from the shape entry; null before it lands. `failureCauses` counts failed calls by cause
|
|
@@ -206,7 +209,7 @@ export interface SpotlightParseRows {
|
|
|
206
209
|
}
|
|
207
210
|
export declare function emptySpotlightRows(): SpotlightParseRows;
|
|
208
211
|
export declare function spotlightRowCount(rows: SpotlightParseRows): number;
|
|
209
|
-
/** Distinct `artifact://N`
|
|
212
|
+
/** Distinct spill ids a text names (`local://N.log`, or `artifact://N` in older transcripts), ascending. */
|
|
210
213
|
export declare function artifactIds(text: string): number[];
|
|
211
214
|
/**
|
|
212
215
|
* What a call asked for, as recovery detection compares it: a read's path with its selector, a bash command, a
|
|
@@ -223,8 +226,8 @@ export declare function callTarget(toolName: string, args: unknown): string;
|
|
|
223
226
|
export declare function argumentTokens(args: unknown): string[];
|
|
224
227
|
/**
|
|
225
228
|
* Files a call changes: an `edit`'s patch headers (or its `path`), a `write`'s `path`, an `ast_edit`'s `paths`
|
|
226
|
-
* (globs kept as written)
|
|
227
|
-
*
|
|
229
|
+
* (globs kept as written). Null when the call is no file edit (other tools, or a write to an internal URL such as
|
|
230
|
+
* `proc://…/kill`).
|
|
228
231
|
*/
|
|
229
232
|
export declare function editedPaths(toolName: string, args: unknown): string[] | null;
|
|
230
233
|
/** A read target split into its path and selected lines. */
|
|
@@ -239,7 +242,7 @@ export interface ReadSelection {
|
|
|
239
242
|
export declare function parseReadSelection(target: string): ReadSelection;
|
|
240
243
|
/** A read selection's lines; null for the whole file. */
|
|
241
244
|
export declare function selectedLines(selection: ReadSelection): [number, number][] | null;
|
|
242
|
-
/** A path as written, resolved
|
|
245
|
+
/** A path as written, resolved against the session's working directory (URLs and absolute paths kept). */
|
|
243
246
|
export declare function resolveReadPath(target: string, cwd: string | null): string;
|
|
244
247
|
/** One `*** Find` block of an `edit` input and the file its section edits (null: the call's `path`). */
|
|
245
248
|
export interface EditFindBlock {
|
package/dist/types/types.d.ts
CHANGED
|
@@ -33,6 +33,16 @@ export interface MessageStats {
|
|
|
33
33
|
usage: Usage;
|
|
34
34
|
/** Which agent produced this message (main agent, task subagent, advisor) */
|
|
35
35
|
agentType: AgentType;
|
|
36
|
+
/**
|
|
37
|
+
* Raw `purpose` of the `model_usage` entry this row was journaled from (a
|
|
38
|
+
* model call that is not a conversation turn: title generation, judge
|
|
39
|
+
* queries, …), `:detail` suffix included; `null` for an assistant message.
|
|
40
|
+
* Non-null is what marks a row as off-transcript, so the parser always gives
|
|
41
|
+
* such a row a value. Always written by `rowToMessageStats`; optional because
|
|
42
|
+
* the parser omits it for assistant messages and session fixtures that stand
|
|
43
|
+
* in for ingest input are typed as `MessageStats` too.
|
|
44
|
+
*/
|
|
45
|
+
purpose?: string | null;
|
|
36
46
|
/**
|
|
37
47
|
* Service tier the provider reported serving this turn, or `null` when the
|
|
38
48
|
* provider reported none. Lets consumers separate a fast serving path's
|
|
@@ -69,7 +79,11 @@ export interface MessageStatsInput extends Omit<MessageStats, "usage" | "costUnp
|
|
|
69
79
|
export interface RequestDetails extends MessageStats {
|
|
70
80
|
/** The full conversation history or just the last turn. */
|
|
71
81
|
messages: unknown[];
|
|
72
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* The model's response. For a `model_usage` entry, the payload it journaled:
|
|
84
|
+
* the reply text of a completion, else a judgment's answers by question id,
|
|
85
|
+
* else `null`.
|
|
86
|
+
*/
|
|
73
87
|
output: unknown;
|
|
74
88
|
}
|
|
75
89
|
/**
|
|
@@ -112,6 +126,21 @@ export interface SessionModelUsageEntry {
|
|
|
112
126
|
usage: Usage;
|
|
113
127
|
stopReason?: StopReason;
|
|
114
128
|
errorMessage?: string;
|
|
129
|
+
/** Wall time of the request in milliseconds; absent on older entries. */
|
|
130
|
+
duration?: number;
|
|
131
|
+
/** Milliseconds until the first token; absent on older entries. */
|
|
132
|
+
ttft?: number;
|
|
133
|
+
/** What a native judge query answered, by question id; absent on older entries. */
|
|
134
|
+
judgment?: {
|
|
135
|
+
state: string;
|
|
136
|
+
answers: Record<string, number | [string | number, number]>;
|
|
137
|
+
cached?: number;
|
|
138
|
+
};
|
|
139
|
+
/** What a text side channel (title generation) was sent and replied; absent on older entries. */
|
|
140
|
+
completion?: {
|
|
141
|
+
prompt?: string;
|
|
142
|
+
reply?: string;
|
|
143
|
+
};
|
|
115
144
|
}
|
|
116
145
|
/**
|
|
117
146
|
* Custom journal entry (`tool_execution_start`, `session_exit`, …). Mirrors
|
|
@@ -284,3 +313,15 @@ export interface ToolResultLink {
|
|
|
284
313
|
resultChars: number;
|
|
285
314
|
isError: boolean;
|
|
286
315
|
}
|
|
316
|
+
/** One snapcompact compaction entry: the context size the session's estimate measured before and after it. */
|
|
317
|
+
export interface SnapcompactCompactionStats {
|
|
318
|
+
sessionFile: string;
|
|
319
|
+
/** Compaction entry ID */
|
|
320
|
+
entryId: string;
|
|
321
|
+
/** Folder/project path (extracted from session filename) */
|
|
322
|
+
folder: string;
|
|
323
|
+
/** Compaction timestamp (Unix ms) */
|
|
324
|
+
timestamp: number;
|
|
325
|
+
tokensBefore: number;
|
|
326
|
+
tokensAfter: number;
|
|
327
|
+
}
|
package/package.json
CHANGED
|
@@ -1,58 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@linxiraos/pi-stats",
|
|
4
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.15",
|
|
5
4
|
"description": "Local observability dashboard for omp AI usage statistics",
|
|
6
|
-
"homepage": "https://linxira-os.github.io/zeta/",
|
|
7
|
-
"author": "Linxira-OS",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"repository": {
|
|
10
|
-
"directory": "packages/stats",
|
|
11
|
-
"url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
|
|
12
|
-
"type": "git"
|
|
13
|
-
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/Linxira-OS/linxira-zeta/issues"
|
|
16
|
-
},
|
|
17
5
|
"keywords": [
|
|
18
6
|
"ai",
|
|
19
|
-
"observability",
|
|
20
|
-
"metrics",
|
|
21
7
|
"dashboard",
|
|
22
8
|
"llm",
|
|
9
|
+
"metrics",
|
|
10
|
+
"observability",
|
|
23
11
|
"statistics"
|
|
24
12
|
],
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"zeta-stats": "./src/index.ts"
|
|
29
|
-
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"gen:stats": "bun scripts/generate-client-bundle.ts --generate",
|
|
32
|
-
"gen:stats:reset": "bun scripts/generate-client-bundle.ts --reset",
|
|
33
|
-
"build": "bun run build.ts",
|
|
34
|
-
"dev": "bun run src/index.ts",
|
|
35
|
-
"check": "oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types",
|
|
36
|
-
"check:types": "bun check --no-script -p tsconfig.json && bun check --no-script -p tsconfig.client.json",
|
|
37
|
-
"lint": "oxlint .",
|
|
38
|
-
"fix": "oxlint --fix --fix-suggestions . && bun run fmt",
|
|
39
|
-
"fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
|
|
40
|
-
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@linxiraos/pi-ai": "1.5.14",
|
|
43
|
-
"@linxiraos/pi-catalog": "1.5.14",
|
|
44
|
-
"@linxiraos/pi-utils": "1.5.14",
|
|
45
|
-
"lucide-react": "^1.24.0",
|
|
46
|
-
"react": "19.2.7",
|
|
47
|
-
"react-dom": "19.2.7"
|
|
13
|
+
"homepage": "https://linxira-os.github.io/zeta/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Linxira-OS/linxira-zeta/issues"
|
|
48
16
|
},
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Linxira-OS",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
|
|
22
|
+
"directory": "packages/stats"
|
|
53
23
|
},
|
|
54
|
-
"
|
|
55
|
-
"
|
|
24
|
+
"bin": {
|
|
25
|
+
"zeta-stats": "./src/index.ts"
|
|
56
26
|
},
|
|
57
27
|
"files": [
|
|
58
28
|
"src",
|
|
@@ -64,6 +34,9 @@
|
|
|
64
34
|
"dist/types",
|
|
65
35
|
"dist/client"
|
|
66
36
|
],
|
|
37
|
+
"type": "module",
|
|
38
|
+
"main": "./src/index.ts",
|
|
39
|
+
"types": "./dist/types/index.d.ts",
|
|
67
40
|
"exports": {
|
|
68
41
|
".": {
|
|
69
42
|
"types": "./dist/types/index.d.ts",
|
|
@@ -88,5 +61,32 @@
|
|
|
88
61
|
},
|
|
89
62
|
"./client/styles.css": "./src/client/styles.css",
|
|
90
63
|
"./client/traces/traces.css": "./src/client/traces/traces.css"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"gen:stats": "bun scripts/generate-client-bundle.ts --generate",
|
|
67
|
+
"gen:stats:reset": "bun scripts/generate-client-bundle.ts --reset",
|
|
68
|
+
"build": "bun run build.ts",
|
|
69
|
+
"dev": "bun run src/index.ts",
|
|
70
|
+
"check": "oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types",
|
|
71
|
+
"check:types": "bun check --no-script -p tsconfig.json && bun check --no-script -p tsconfig.client.json",
|
|
72
|
+
"lint": "oxlint .",
|
|
73
|
+
"fix": "oxlint --fix --fix-suggestions . && bun run fmt",
|
|
74
|
+
"fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"@linxiraos/pi-ai": "1.5.15",
|
|
78
|
+
"@linxiraos/pi-catalog": "1.5.15",
|
|
79
|
+
"@linxiraos/pi-utils": "1.5.15",
|
|
80
|
+
"lucide-react": "^1.24.0",
|
|
81
|
+
"react": "19.2.7",
|
|
82
|
+
"react-dom": "19.2.7"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@types/bun": "1.4.4",
|
|
86
|
+
"@types/react": "19.3.0",
|
|
87
|
+
"@types/react-dom": "19.3.0"
|
|
88
|
+
},
|
|
89
|
+
"engines": {
|
|
90
|
+
"bun": ">=1.4.4"
|
|
91
91
|
}
|
|
92
92
|
}
|