@linxiraos/pi-stats 1.1.8 → 1.1.9
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 +4 -0
- package/package.json +87 -94
- package/src/gain-aggregator.ts +1 -1
- package/src/index.ts +0 -0
- package/THIRD-PARTY-NOTICES.txt +0 -22909
- package/dist/client/index.css +0 -1
- package/dist/client/index.html +0 -24
- package/dist/client/index.js +0 -257
- package/dist/client/styles.css +0 -1956
- package/dist/types/aggregator.d.ts +0 -103
- package/dist/types/client/App.d.ts +0 -1
- package/dist/types/client/api.d.ts +0 -28
- package/dist/types/client/app/AppLayout.d.ts +0 -16
- package/dist/types/client/app/NavRail.d.ts +0 -7
- package/dist/types/client/app/RangeControl.d.ts +0 -7
- package/dist/types/client/app/SyncButton.d.ts +0 -14
- package/dist/types/client/app/ThemeToggle.d.ts +0 -1
- package/dist/types/client/app/TopBar.d.ts +0 -15
- package/dist/types/client/app/routes.d.ts +0 -12
- package/dist/types/client/components/AgentTokenShare.d.ts +0 -5
- package/dist/types/client/components/chart-shared.d.ts +0 -178
- package/dist/types/client/components/models-table-shared.d.ts +0 -175
- package/dist/types/client/components/range-meta.d.ts +0 -21
- package/dist/types/client/data/charts.d.ts +0 -1
- package/dist/types/client/data/formatters.d.ts +0 -13
- package/dist/types/client/data/useHashRoute.d.ts +0 -10
- package/dist/types/client/data/useResource.d.ts +0 -13
- package/dist/types/client/data/view-models.d.ts +0 -75
- package/dist/types/client/index.d.ts +0 -2
- package/dist/types/client/routes/BehaviorRoute.d.ts +0 -7
- package/dist/types/client/routes/CostsRoute.d.ts +0 -7
- package/dist/types/client/routes/ErrorsRoute.d.ts +0 -8
- package/dist/types/client/routes/GainRoute.d.ts +0 -7
- package/dist/types/client/routes/ModelsRoute.d.ts +0 -7
- package/dist/types/client/routes/OverviewRoute.d.ts +0 -8
- package/dist/types/client/routes/ProjectsRoute.d.ts +0 -7
- package/dist/types/client/routes/ProvidersRoute.d.ts +0 -7
- package/dist/types/client/routes/RequestsRoute.d.ts +0 -8
- package/dist/types/client/routes/ToolsRoute.d.ts +0 -7
- package/dist/types/client/routes/TracesRoute.d.ts +0 -11
- package/dist/types/client/routes/index.d.ts +0 -11
- package/dist/types/client/traces/AggregatesPanel.d.ts +0 -9
- package/dist/types/client/traces/Minimap.d.ts +0 -14
- package/dist/types/client/traces/SpanDrawer.d.ts +0 -14
- package/dist/types/client/traces/SummaryStrip.d.ts +0 -9
- package/dist/types/client/traces/TimelineCanvas.d.ts +0 -25
- package/dist/types/client/traces/TraceView.d.ts +0 -11
- package/dist/types/client/traces/TranscriptList.d.ts +0 -24
- package/dist/types/client/traces/time-scale.d.ts +0 -40
- package/dist/types/client/traces/trace-colors.d.ts +0 -31
- package/dist/types/client/types.d.ts +0 -63
- package/dist/types/client/ui/AsyncBoundary.d.ts +0 -12
- package/dist/types/client/ui/DataTable.d.ts +0 -17
- package/dist/types/client/ui/EmptyState.d.ts +0 -7
- package/dist/types/client/ui/ErrorState.d.ts +0 -6
- package/dist/types/client/ui/JsonBlock.d.ts +0 -7
- package/dist/types/client/ui/MetricCluster.d.ts +0 -5
- package/dist/types/client/ui/Panel.d.ts +0 -7
- package/dist/types/client/ui/RequestDrawer.d.ts +0 -5
- package/dist/types/client/ui/SegmentedControl.d.ts +0 -12
- package/dist/types/client/ui/Skeleton.d.ts +0 -8
- package/dist/types/client/ui/StatusPill.d.ts +0 -7
- package/dist/types/client/ui/index.d.ts +0 -11
- package/dist/types/client/useSystemTheme.d.ts +0 -11
- package/dist/types/db.d.ts +0 -183
- package/dist/types/embedded-client.d.ts +0 -18
- package/dist/types/gain-aggregator.d.ts +0 -26
- package/dist/types/index.d.ts +0 -17
- package/dist/types/parser.d.ts +0 -61
- package/dist/types/port-conflict.d.ts +0 -16
- package/dist/types/server.d.ts +0 -15
- package/dist/types/shared-types.d.ts +0 -551
- package/dist/types/sync-worker.d.ts +0 -31
- package/dist/types/trace.d.ts +0 -33
- package/dist/types/types.d.ts +0 -198
- package/dist/types/usage-windows.d.ts +0 -72
- package/dist/types/user-metrics.d.ts +0 -81
|
@@ -1,551 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared type definitions consumed by both the server-side stats code and the
|
|
3
|
-
* standalone client bundle. Keep this file free of any imports from server-only
|
|
4
|
-
* packages (e.g. `@linxiraos/pi-ai`, `bun:sqlite`) so the client can import it
|
|
5
|
-
* without dragging server dependencies into its bundle.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Aggregated stats for a model or folder.
|
|
9
|
-
*/
|
|
10
|
-
export interface AggregatedStats {
|
|
11
|
-
/** Total number of requests */
|
|
12
|
-
totalRequests: number;
|
|
13
|
-
/** Number of successful requests */
|
|
14
|
-
successfulRequests: number;
|
|
15
|
-
/** Number of failed requests */
|
|
16
|
-
failedRequests: number;
|
|
17
|
-
/** Error rate (0-1) */
|
|
18
|
-
errorRate: number;
|
|
19
|
-
/** Total input tokens */
|
|
20
|
-
totalInputTokens: number;
|
|
21
|
-
/** Total output tokens */
|
|
22
|
-
totalOutputTokens: number;
|
|
23
|
-
/** Total cache read tokens */
|
|
24
|
-
totalCacheReadTokens: number;
|
|
25
|
-
/** Total cache write tokens */
|
|
26
|
-
totalCacheWriteTokens: number;
|
|
27
|
-
/** Percentage of prompt input tokens served from cache (0-1). */
|
|
28
|
-
cacheRate: number;
|
|
29
|
-
/**
|
|
30
|
-
* Prompt-input cost saved relative to billing the same tokens uncached
|
|
31
|
-
* (0-1; negative when cache writes cost more than reads save).
|
|
32
|
-
*/
|
|
33
|
-
cacheSavings: number;
|
|
34
|
-
/** Total cost */
|
|
35
|
-
totalCost: number;
|
|
36
|
-
/** Requests with token usage but no public-equivalent subscription price. */
|
|
37
|
-
unpricedRequests: number;
|
|
38
|
-
/** Total premium requests */
|
|
39
|
-
totalPremiumRequests: number;
|
|
40
|
-
/** Average duration in ms */
|
|
41
|
-
avgDuration: number | null;
|
|
42
|
-
/** Average TTFT in ms */
|
|
43
|
-
avgTtft: number | null;
|
|
44
|
-
/** Average tokens per second (output tokens / duration) */
|
|
45
|
-
avgTokensPerSecond: number | null;
|
|
46
|
-
/** Time range */
|
|
47
|
-
firstTimestamp: number;
|
|
48
|
-
lastTimestamp: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Stats grouped by model.
|
|
52
|
-
*/
|
|
53
|
-
export interface ModelStats extends AggregatedStats {
|
|
54
|
-
model: string;
|
|
55
|
-
provider: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Stats grouped by folder.
|
|
59
|
-
*/
|
|
60
|
-
export interface FolderStats extends AggregatedStats {
|
|
61
|
-
folder: string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Time series data point.
|
|
65
|
-
*/
|
|
66
|
-
export interface TimeSeriesPoint {
|
|
67
|
-
/** Bucket timestamp (start of hour/day) */
|
|
68
|
-
timestamp: number;
|
|
69
|
-
/** Request count */
|
|
70
|
-
requests: number;
|
|
71
|
-
/** Error count */
|
|
72
|
-
errors: number;
|
|
73
|
-
/** Total tokens */
|
|
74
|
-
tokens: number;
|
|
75
|
-
/** Total cost */
|
|
76
|
-
cost: number;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Model usage time series data point (daily buckets).
|
|
80
|
-
*/
|
|
81
|
-
export interface ModelTimeSeriesPoint {
|
|
82
|
-
/** Bucket timestamp (start of day) */
|
|
83
|
-
timestamp: number;
|
|
84
|
-
/** Model name */
|
|
85
|
-
model: string;
|
|
86
|
-
/** Provider name */
|
|
87
|
-
provider: string;
|
|
88
|
-
/** Request count */
|
|
89
|
-
requests: number;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Model performance time series data point (daily buckets).
|
|
93
|
-
*/
|
|
94
|
-
export interface ModelPerformancePoint {
|
|
95
|
-
/** Bucket timestamp (start of day) */
|
|
96
|
-
timestamp: number;
|
|
97
|
-
/** Model name */
|
|
98
|
-
model: string;
|
|
99
|
-
/** Provider name */
|
|
100
|
-
provider: string;
|
|
101
|
-
/** Request count */
|
|
102
|
-
requests: number;
|
|
103
|
-
/** Average TTFT in ms */
|
|
104
|
-
avgTtft: number | null;
|
|
105
|
-
/** Average tokens per second */
|
|
106
|
-
avgTokensPerSecond: number | null;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Cost time series data point (daily buckets).
|
|
110
|
-
*/
|
|
111
|
-
export interface CostTimeSeriesPoint {
|
|
112
|
-
/** Bucket timestamp (start of day) */
|
|
113
|
-
timestamp: number;
|
|
114
|
-
/** Model name */
|
|
115
|
-
model: string;
|
|
116
|
-
/** Provider name */
|
|
117
|
-
provider: string;
|
|
118
|
-
/** Total cost for this bucket */
|
|
119
|
-
cost: number;
|
|
120
|
-
/** Requests excluded because no public-equivalent subscription price exists. */
|
|
121
|
-
unpricedRequests: number;
|
|
122
|
-
/** Cost breakdown */
|
|
123
|
-
costInput: number;
|
|
124
|
-
costOutput: number;
|
|
125
|
-
costCacheRead: number;
|
|
126
|
-
costCacheWrite: number;
|
|
127
|
-
/** Request count */
|
|
128
|
-
requests: number;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* One local calendar day of aggregate request activity, for the `/usage`
|
|
132
|
-
* activity heatmap in the coding-agent TUI.
|
|
133
|
-
*/
|
|
134
|
-
export interface DailyActivityPoint {
|
|
135
|
-
/** Local calendar date, `YYYY-MM-DD`. */
|
|
136
|
-
day: string;
|
|
137
|
-
/** Summed API-equivalent cost for the day. */
|
|
138
|
-
cost: number;
|
|
139
|
-
/** Request count for the day. */
|
|
140
|
-
requests: number;
|
|
141
|
-
/** Total tokens (input + output + cache) for the day. */
|
|
142
|
-
totalTokens: number;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Overall dashboard stats.
|
|
146
|
-
*/
|
|
147
|
-
export interface DashboardStats {
|
|
148
|
-
overall: AggregatedStats;
|
|
149
|
-
byModel: ModelStats[];
|
|
150
|
-
byFolder: FolderStats[];
|
|
151
|
-
byAgentType: AgentTypeStats[];
|
|
152
|
-
timeSeries: TimeSeriesPoint[];
|
|
153
|
-
modelSeries: ModelTimeSeriesPoint[];
|
|
154
|
-
modelPerformanceSeries: ModelPerformancePoint[];
|
|
155
|
-
costSeries: CostTimeSeriesPoint[];
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Which agent produced a message, derived from its transcript file location
|
|
159
|
-
* inside the session directory: the top-level `<project>/<file>.jsonl` is the
|
|
160
|
-
* `main` agent, an `__advisor.jsonl` is the passive `advisor`, and any other
|
|
161
|
-
* nested transcript is a task `subagent`.
|
|
162
|
-
*/
|
|
163
|
-
export type AgentType = "main" | "subagent" | "advisor";
|
|
164
|
-
/**
|
|
165
|
-
* Token usage aggregated by {@link AgentType} over the active range. Token
|
|
166
|
-
* columns are explicit so the dashboard's share denominator matches the
|
|
167
|
-
* counts it renders (input + output + cache read + cache write).
|
|
168
|
-
*/
|
|
169
|
-
export interface AgentTypeStats {
|
|
170
|
-
agentType: AgentType;
|
|
171
|
-
/** Total number of requests */
|
|
172
|
-
totalRequests: number;
|
|
173
|
-
/** Total input tokens */
|
|
174
|
-
totalInputTokens: number;
|
|
175
|
-
/** Total output tokens */
|
|
176
|
-
totalOutputTokens: number;
|
|
177
|
-
/** Total cache read tokens */
|
|
178
|
-
totalCacheReadTokens: number;
|
|
179
|
-
/** Total cache write tokens */
|
|
180
|
-
totalCacheWriteTokens: number;
|
|
181
|
-
/** Total cost */
|
|
182
|
-
totalCost: number;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Behavior time-series point (daily bucket, per responding model).
|
|
186
|
-
*/
|
|
187
|
-
export interface BehaviorTimeSeriesPoint {
|
|
188
|
-
/** Bucket timestamp (start of day) */
|
|
189
|
-
timestamp: number;
|
|
190
|
-
/** Responding model ("unknown" if user msg never got a reply) */
|
|
191
|
-
model: string;
|
|
192
|
-
/** Responding provider */
|
|
193
|
-
provider: string;
|
|
194
|
-
/** Number of user messages in bucket */
|
|
195
|
-
messages: number;
|
|
196
|
-
/** Total yelling sentences in bucket */
|
|
197
|
-
yelling: number;
|
|
198
|
-
/** Total profanity hits in bucket */
|
|
199
|
-
profanity: number;
|
|
200
|
-
/** Total anguish signal in bucket */
|
|
201
|
-
anguish: number;
|
|
202
|
-
/** Total corrective-negation hits in bucket */
|
|
203
|
-
negation: number;
|
|
204
|
-
/** Total user-repeating-themselves hits in bucket */
|
|
205
|
-
repetition: number;
|
|
206
|
-
/** Total second-person blame hits in bucket */
|
|
207
|
-
blame: number;
|
|
208
|
-
/** Total characters in bucket */
|
|
209
|
-
chars: number;
|
|
210
|
-
}
|
|
211
|
-
export interface BehaviorOverallStats {
|
|
212
|
-
totalMessages: number;
|
|
213
|
-
totalYelling: number;
|
|
214
|
-
totalProfanity: number;
|
|
215
|
-
totalAnguish: number;
|
|
216
|
-
totalNegation: number;
|
|
217
|
-
totalRepetition: number;
|
|
218
|
-
totalBlame: number;
|
|
219
|
-
totalChars: number;
|
|
220
|
-
firstTimestamp: number;
|
|
221
|
-
lastTimestamp: number;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Per-model behavioral aggregate over the active range.
|
|
225
|
-
*/
|
|
226
|
-
export interface BehaviorModelStats {
|
|
227
|
-
model: string;
|
|
228
|
-
provider: string;
|
|
229
|
-
totalMessages: number;
|
|
230
|
-
totalYelling: number;
|
|
231
|
-
totalProfanity: number;
|
|
232
|
-
totalAnguish: number;
|
|
233
|
-
totalNegation: number;
|
|
234
|
-
totalRepetition: number;
|
|
235
|
-
totalBlame: number;
|
|
236
|
-
totalChars: number;
|
|
237
|
-
lastTimestamp: number;
|
|
238
|
-
}
|
|
239
|
-
export interface BehaviorDashboardStats {
|
|
240
|
-
overall: BehaviorOverallStats;
|
|
241
|
-
byModel: BehaviorModelStats[];
|
|
242
|
-
behaviorSeries: BehaviorTimeSeriesPoint[];
|
|
243
|
-
}
|
|
244
|
-
/** Token savings from a single source type. */
|
|
245
|
-
export interface GainSourceTotals {
|
|
246
|
-
savedTokens: number;
|
|
247
|
-
savedBytes: number;
|
|
248
|
-
hits: number;
|
|
249
|
-
/** originalBytes - savedBytes, when original is known */
|
|
250
|
-
outputBytes: number;
|
|
251
|
-
/** Total original bytes before compression, when known */
|
|
252
|
-
originalBytes: number;
|
|
253
|
-
/** savedBytes / originalBytes when both are known, else null */
|
|
254
|
-
reductionPercent: number | null;
|
|
255
|
-
}
|
|
256
|
-
/** Per-source breakdown. */
|
|
257
|
-
export type GainSource = "snapcompact";
|
|
258
|
-
/** Time-series point for gain (daily bucket). */
|
|
259
|
-
export interface GainTimeSeriesPoint {
|
|
260
|
-
date: string;
|
|
261
|
-
snapcompact: number;
|
|
262
|
-
total: number;
|
|
263
|
-
}
|
|
264
|
-
/** Complete gain dashboard payload. */
|
|
265
|
-
export interface GainDashboardStats {
|
|
266
|
-
/** Aggregate across all sources for the active range. */
|
|
267
|
-
overall: GainSourceTotals;
|
|
268
|
-
/** Per-source breakdown. */
|
|
269
|
-
bySource: Record<GainSource, GainSourceTotals>;
|
|
270
|
-
/** Daily time series. */
|
|
271
|
-
timeSeries: GainTimeSeriesPoint[];
|
|
272
|
-
/** Active project filter (cwd prefix), or null for all projects. */
|
|
273
|
-
project: string | null;
|
|
274
|
-
/** All distinct projects seen in the data, for the selector. */
|
|
275
|
-
projects: string[];
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Aggregated usage for a single tool over the active range.
|
|
279
|
-
*
|
|
280
|
-
* Token/cost fields are the *real* provider usage of the assistant turns that
|
|
281
|
-
* invoked the tool, split evenly across that turn's tool calls so the numbers
|
|
282
|
-
* stay additive (a turn with 3 calls contributes a third of its usage to each
|
|
283
|
-
* tool). Payload fields (`argsChars`/`resultChars`) are raw character counts
|
|
284
|
-
* of the serialized arguments and the text fed back into context — a size
|
|
285
|
-
* proxy, not provider-counted tokens.
|
|
286
|
-
*/
|
|
287
|
-
export interface ToolUsageStats {
|
|
288
|
-
/** Tool name as recorded on the tool call. */
|
|
289
|
-
tool: string;
|
|
290
|
-
/** Number of tool calls. */
|
|
291
|
-
calls: number;
|
|
292
|
-
/** Calls whose result came back with `isError`. */
|
|
293
|
-
errors: number;
|
|
294
|
-
/** Serialized tool-call argument characters. */
|
|
295
|
-
argsChars: number;
|
|
296
|
-
/** Text characters of tool results fed back into context. */
|
|
297
|
-
resultChars: number;
|
|
298
|
-
/** Total provider tokens of invoking turns, attributed per call share. */
|
|
299
|
-
totalTokensShare: number;
|
|
300
|
-
/** Output tokens of invoking turns, attributed per call share. */
|
|
301
|
-
outputTokensShare: number;
|
|
302
|
-
/** Cost (USD) of invoking turns, attributed per call share. */
|
|
303
|
-
costShare: number;
|
|
304
|
-
/** Share of unpriced subscription requests attributed to this tool. */
|
|
305
|
-
unpricedRequestsShare: number;
|
|
306
|
-
/** Unix ms of the most recent call in range. */
|
|
307
|
-
lastUsed: number;
|
|
308
|
-
}
|
|
309
|
-
/** Per-(tool, model) breakdown with the same attribution as {@link ToolUsageStats}. */
|
|
310
|
-
export interface ToolModelStats extends ToolUsageStats {
|
|
311
|
-
model: string;
|
|
312
|
-
provider: string;
|
|
313
|
-
}
|
|
314
|
-
/** Tool-call time-series point (one bucket per tool). */
|
|
315
|
-
export interface ToolTimeSeriesPoint {
|
|
316
|
-
timestamp: number;
|
|
317
|
-
tool: string;
|
|
318
|
-
calls: number;
|
|
319
|
-
errors: number;
|
|
320
|
-
}
|
|
321
|
-
/** Complete tools dashboard payload. */
|
|
322
|
-
export interface ToolDashboardStats {
|
|
323
|
-
byTool: ToolUsageStats[];
|
|
324
|
-
byToolModel: ToolModelStats[];
|
|
325
|
-
series: ToolTimeSeriesPoint[];
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Aggregated request/token/cost totals for one provider over the active range.
|
|
329
|
-
*/
|
|
330
|
-
export interface ProviderAggregate {
|
|
331
|
-
provider: string;
|
|
332
|
-
totalRequests: number;
|
|
333
|
-
failedRequests: number;
|
|
334
|
-
/** Distinct models used through this provider in the range. */
|
|
335
|
-
models: number;
|
|
336
|
-
totalInputTokens: number;
|
|
337
|
-
totalOutputTokens: number;
|
|
338
|
-
totalCacheReadTokens: number;
|
|
339
|
-
totalCacheWriteTokens: number;
|
|
340
|
-
/** Uncached input + cache reads + cache writes + output. */
|
|
341
|
-
totalTokens: number;
|
|
342
|
-
totalCost: number;
|
|
343
|
-
/** Requests excluded because no public-equivalent subscription price exists. */
|
|
344
|
-
unpricedRequests: number;
|
|
345
|
-
totalPremiumRequests: number;
|
|
346
|
-
avgTokensPerSecond: number | null;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Token burn attributed to one local hour-of-day (0-23) for one provider.
|
|
350
|
-
* Powers the "peak burn hours" histogram.
|
|
351
|
-
*/
|
|
352
|
-
export interface ProviderHourlyPoint {
|
|
353
|
-
provider: string;
|
|
354
|
-
/** Local hour of day, 0-23. */
|
|
355
|
-
hour: number;
|
|
356
|
-
totalTokens: number;
|
|
357
|
-
outputTokens: number;
|
|
358
|
-
requests: number;
|
|
359
|
-
}
|
|
360
|
-
/** Provider token/cost time-series point (bucketed like the model series). */
|
|
361
|
-
export interface ProviderTimeSeriesPoint {
|
|
362
|
-
timestamp: number;
|
|
363
|
-
provider: string;
|
|
364
|
-
totalTokens: number;
|
|
365
|
-
cost: number;
|
|
366
|
-
/** Requests excluded because no public-equivalent subscription price exists. */
|
|
367
|
-
unpricedRequests: number;
|
|
368
|
-
requests: number;
|
|
369
|
-
}
|
|
370
|
-
/** One recorded usage-limit snapshot for an (account, window) series. */
|
|
371
|
-
export interface UsageWindowPoint {
|
|
372
|
-
timestamp: number;
|
|
373
|
-
/** Used fraction 0..1 (>1 = overage) when the provider reported one. */
|
|
374
|
-
usedFraction: number | null;
|
|
375
|
-
exhausted: boolean;
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Utilization history for one (account, limit window) pair of a provider,
|
|
379
|
-
* sourced from the auth store's recorded usage-limit snapshots.
|
|
380
|
-
*/
|
|
381
|
-
export interface UsageWindowSeries {
|
|
382
|
-
provider: string;
|
|
383
|
-
accountKey: string;
|
|
384
|
-
/** Email/account id when known, else the stable account key. */
|
|
385
|
-
accountLabel: string;
|
|
386
|
-
/** Groups the same limit window across accounts (the provider limit id). */
|
|
387
|
-
windowKey: string;
|
|
388
|
-
/** Human label of the limit (distinguishes same-duration windows). */
|
|
389
|
-
windowLabel: string;
|
|
390
|
-
points: UsageWindowPoint[];
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Derived subscription insight for one provider limit window across all
|
|
394
|
-
* accounts: how much of the window was consumed, what one window is worth in
|
|
395
|
-
* tokens, and how many accounts peak demand would have needed.
|
|
396
|
-
*/
|
|
397
|
-
export interface ProviderWindowInsight {
|
|
398
|
-
provider: string;
|
|
399
|
-
/** Groups the same limit window across accounts (the provider limit id). */
|
|
400
|
-
windowKey: string;
|
|
401
|
-
/** Human label of the limit (distinguishes same-duration windows). */
|
|
402
|
-
windowLabel: string;
|
|
403
|
-
/** Accounts with at least one snapshot for this window in range. */
|
|
404
|
-
accounts: number;
|
|
405
|
-
/** Window resets observed (drops in used fraction). */
|
|
406
|
-
cycles: number;
|
|
407
|
-
/**
|
|
408
|
-
* Subscription-window equivalents consumed in range: sum of positive
|
|
409
|
-
* used-fraction deltas across accounts (1.0 = one full window burned).
|
|
410
|
-
*/
|
|
411
|
-
fractionConsumed: number;
|
|
412
|
-
/**
|
|
413
|
-
* Estimated tokens one full window buys: provider tokens burned in range
|
|
414
|
-
* divided by {@link fractionConsumed}. Null when too little of the window
|
|
415
|
-
* was consumed to extrapolate.
|
|
416
|
-
*/
|
|
417
|
-
estTokensPerWindow: number | null;
|
|
418
|
-
/** Peak of sum-across-accounts used fraction at any sampled instant. */
|
|
419
|
-
peakConcurrentFraction: number;
|
|
420
|
-
/**
|
|
421
|
-
* Accounts needed to keep peak demand under 90% of fleet capacity:
|
|
422
|
-
* max(1, ceil(peakConcurrentFraction / 0.9)).
|
|
423
|
-
*/
|
|
424
|
-
idealAccounts: number;
|
|
425
|
-
/** Transitions into an exhausted state observed in range. */
|
|
426
|
-
exhaustedEvents: number;
|
|
427
|
-
}
|
|
428
|
-
/** Complete providers dashboard payload. */
|
|
429
|
-
export interface ProviderDashboardStats {
|
|
430
|
-
providers: ProviderAggregate[];
|
|
431
|
-
hourly: ProviderHourlyPoint[];
|
|
432
|
-
series: ProviderTimeSeriesPoint[];
|
|
433
|
-
usageSeries: UsageWindowSeries[];
|
|
434
|
-
windowInsights: ProviderWindowInsight[];
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* One row of the Traces session list: a root session with every child
|
|
438
|
-
* transcript (task subagents, advisors) folded in.
|
|
439
|
-
*/
|
|
440
|
-
export interface SessionSummary {
|
|
441
|
-
/** Absolute root session file path (trace key). */
|
|
442
|
-
file: string;
|
|
443
|
-
/** Decoded project path (e.g. `/work/pi`). */
|
|
444
|
-
folder: string;
|
|
445
|
-
title: string | null;
|
|
446
|
-
/** ms epoch of first activity. */
|
|
447
|
-
startedAt: number;
|
|
448
|
-
/** ms epoch of last activity, children included. */
|
|
449
|
-
endedAt: number;
|
|
450
|
-
/** Assistant messages, children folded in. */
|
|
451
|
-
requests: number;
|
|
452
|
-
toolCalls: number;
|
|
453
|
-
/** Child transcript count. */
|
|
454
|
-
subagents: number;
|
|
455
|
-
totalTokens: number;
|
|
456
|
-
costTotal: number;
|
|
457
|
-
models: string[];
|
|
458
|
-
}
|
|
459
|
-
export type TraceSpanKind = "turn" | "model" | "tool" | "subagent" | "background";
|
|
460
|
-
/** One rendered block on a trace track lane. */
|
|
461
|
-
export interface TraceSpan {
|
|
462
|
-
/** `${track.id}:${entryId}` (+`:${toolCallId}` for tool spans); stable across refetch. */
|
|
463
|
-
id: string;
|
|
464
|
-
kind: TraceSpanKind;
|
|
465
|
-
/** ms epoch. */
|
|
466
|
-
start: number;
|
|
467
|
-
/** ms epoch, >= start. */
|
|
468
|
-
end: number;
|
|
469
|
-
/** ≤80 chars: tool name / model id / user-text head / agent name. */
|
|
470
|
-
label: string;
|
|
471
|
-
/** ≤160 chars: args projection / result head / task text. */
|
|
472
|
-
detail?: string;
|
|
473
|
-
/** Journal entry id for /api/session/entry. */
|
|
474
|
-
entryId?: string;
|
|
475
|
-
toolCallId?: string;
|
|
476
|
-
model?: string;
|
|
477
|
-
/** usage.totalTokens (model spans). */
|
|
478
|
-
tokens?: number;
|
|
479
|
-
/** usage.cost.total (model spans). */
|
|
480
|
-
cost?: number;
|
|
481
|
-
/** Time to first token, ms offset from start. */
|
|
482
|
-
ttft?: number;
|
|
483
|
-
isError?: boolean;
|
|
484
|
-
/** End synthesized (no result / pending at session exit). */
|
|
485
|
-
unterminated?: boolean;
|
|
486
|
-
/** Set on `subagent` spans whose child transcript became a track. */
|
|
487
|
-
childTrackId?: string;
|
|
488
|
-
}
|
|
489
|
-
/** Point event drawn on a track header row. */
|
|
490
|
-
export interface TraceMarker {
|
|
491
|
-
/** ms epoch. */
|
|
492
|
-
time: number;
|
|
493
|
-
kind: "compaction" | "model_change" | "mode_change" | "reset" | "session_exit";
|
|
494
|
-
/** e.g. "compaction 142k→38k", model id, mode name, exit kind. */
|
|
495
|
-
label: string;
|
|
496
|
-
}
|
|
497
|
-
/** One transcript (main session, subagent, advisor) in a trace. */
|
|
498
|
-
export interface TraceTrack {
|
|
499
|
-
/** "main" or slash-joined child key: "Scout1", "Scout1/Nested2", "__advisor". */
|
|
500
|
-
id: string;
|
|
501
|
-
parentId: string | null;
|
|
502
|
-
label: string;
|
|
503
|
-
/** session_init.agent when recorded. */
|
|
504
|
-
agent: string | null;
|
|
505
|
-
/** session_init.resolvedModel ?? first assistant model. */
|
|
506
|
-
model: string | null;
|
|
507
|
-
/** Absolute transcript path (for entry fetch). */
|
|
508
|
-
file: string;
|
|
509
|
-
/** Sorted by start. */
|
|
510
|
-
spans: TraceSpan[];
|
|
511
|
-
markers: TraceMarker[];
|
|
512
|
-
}
|
|
513
|
-
/** Per-tool duration aggregate across all tracks of one trace. */
|
|
514
|
-
export interface TraceToolStat {
|
|
515
|
-
tool: string;
|
|
516
|
-
calls: number;
|
|
517
|
-
errors: number;
|
|
518
|
-
totalMs: number;
|
|
519
|
-
maxMs: number;
|
|
520
|
-
}
|
|
521
|
-
/** Headline aggregates for one trace. */
|
|
522
|
-
export interface TraceSummary {
|
|
523
|
-
wallMs: number;
|
|
524
|
-
/** Summed model-span duration on the main track. */
|
|
525
|
-
modelMs: number;
|
|
526
|
-
/** Summed tool-span duration on the main track. */
|
|
527
|
-
toolMs: number;
|
|
528
|
-
/** Wall time not covered by any span on any track. */
|
|
529
|
-
idleMs: number;
|
|
530
|
-
turns: number;
|
|
531
|
-
requests: number;
|
|
532
|
-
toolCalls: number;
|
|
533
|
-
subagents: number;
|
|
534
|
-
totalTokens: number;
|
|
535
|
-
costTotal: number;
|
|
536
|
-
/** Sorted totalMs desc. */
|
|
537
|
-
toolStats: TraceToolStat[];
|
|
538
|
-
}
|
|
539
|
-
/** Complete span tree for one session, `/api/session/trace` payload. */
|
|
540
|
-
export interface SessionTrace {
|
|
541
|
-
file: string;
|
|
542
|
-
title: string | null;
|
|
543
|
-
cwd: string | null;
|
|
544
|
-
startedAt: number;
|
|
545
|
-
endedAt: number;
|
|
546
|
-
/** Root transcript mtime; doubles as the ETag. */
|
|
547
|
-
mtimeMs: number;
|
|
548
|
-
/** DFS order, main first. */
|
|
549
|
-
tracks: TraceTrack[];
|
|
550
|
-
summary: TraceSummary;
|
|
551
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stateless parse worker for `syncAllSessions`. The main thread owns the
|
|
3
|
-
* SQLite handle; workers receive `{ sessionFile, fromOffset }`, run
|
|
4
|
-
* `parseSessionFile` (which is pure I/O + CPU, no DB), and post the
|
|
5
|
-
* structured-clone-safe result back. One in-flight request per worker so
|
|
6
|
-
* the main thread can fan jobs out 1:1 with the pool size.
|
|
7
|
-
*
|
|
8
|
-
* A `{ kind: "ping" }` request is also accepted and replies with
|
|
9
|
-
* `{ ok: true, kind: "pong" }` — used by `smokeTestSyncWorker` to prove the
|
|
10
|
-
* worker actually spawns and runs in compiled binaries (regression coverage
|
|
11
|
-
* for issue #1011 / PR #1027, where the worker silently failed to load).
|
|
12
|
-
*/
|
|
13
|
-
import { type ParseSessionResult } from "./parser.js";
|
|
14
|
-
export type SyncWorkerRequest = {
|
|
15
|
-
kind?: "parse";
|
|
16
|
-
sessionFile: string;
|
|
17
|
-
fromOffset: number;
|
|
18
|
-
} | {
|
|
19
|
-
kind: "ping";
|
|
20
|
-
};
|
|
21
|
-
export type SyncWorkerResponse = {
|
|
22
|
-
ok: true;
|
|
23
|
-
kind?: "parse";
|
|
24
|
-
result: ParseSessionResult;
|
|
25
|
-
} | {
|
|
26
|
-
ok: true;
|
|
27
|
-
kind: "pong";
|
|
28
|
-
} | {
|
|
29
|
-
ok: false;
|
|
30
|
-
error: string;
|
|
31
|
-
};
|
package/dist/types/trace.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session trace assembly for the Traces dashboard section.
|
|
3
|
-
*
|
|
4
|
-
* Builds a span tree (turns, model calls, tool calls, subagents, background
|
|
5
|
-
* jobs) directly from raw session JSONL — the only source with tool start/end
|
|
6
|
-
* times — while stats.db supplies the session-list rollups. Entry shapes are
|
|
7
|
-
* mirrored structurally from the coding-agent journal (`tool_execution_start`,
|
|
8
|
-
* `session_exit`, task results, async-result batches); stats never imports
|
|
9
|
-
* coding-agent.
|
|
10
|
-
*/
|
|
11
|
-
import type { SessionEntry, SessionSummary, SessionTrace } from "./types.js";
|
|
12
|
-
/** Client-supplied path escaped the sessions root or is not a transcript. Maps to HTTP 400. */
|
|
13
|
-
export declare class TracePathError extends Error {
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Trace payload schema/assembly revision, folded into the HTTP ETag. Bump when
|
|
17
|
-
* span assembly changes so browsers don't revalidate stale cached bodies
|
|
18
|
-
* against an unchanged transcript mtime.
|
|
19
|
-
*/
|
|
20
|
-
export declare const TRACE_ETAG_VERSION = 2;
|
|
21
|
-
/**
|
|
22
|
-
* Assemble the full span tree for one root session transcript.
|
|
23
|
-
* Throws {@link TracePathError} for paths outside the sessions root; ENOENT
|
|
24
|
-
* passes through for the caller's 404 mapping.
|
|
25
|
-
*/
|
|
26
|
-
export declare function buildSessionTrace(fileParam: string): Promise<SessionTrace>;
|
|
27
|
-
/** Fetch one full journal entry by id from a transcript, for the span drawer. */
|
|
28
|
-
export declare function getTraceEntry(fileParam: string, entryId: string): Promise<SessionEntry | null>;
|
|
29
|
-
/**
|
|
30
|
-
* List root sessions for the Traces section, folding every synced child
|
|
31
|
-
* transcript (subagents, advisors) into its root row.
|
|
32
|
-
*/
|
|
33
|
-
export declare function listSessionSummaries(limit?: number, q?: string): Promise<SessionSummary[]>;
|