@linxiraos/pi-stats 1.4.12 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -5
- package/dist/client/index.js +86 -86
- package/dist/types/client/data/formatters.d.ts +9 -0
- package/dist/types/client/i18n/messages/common.d.ts +2 -2
- package/dist/types/client/i18n/messages/en.d.ts +2 -2
- package/dist/types/client/i18n/messages/models.d.ts +2 -2
- package/dist/types/client/i18n/messages/overview.d.ts +1 -1
- package/dist/types/client/ui/RequestDrawer.d.ts +2 -2
- package/dist/types/server.d.ts +3 -1
- package/dist/types/shared-types.d.ts +4 -3
- package/dist/types/trace.d.ts +8 -5
- package/package.json +4 -4
- package/src/client/data/formatters.ts +47 -6
- package/src/client/i18n/messages/common.ts +2 -2
- package/src/client/i18n/messages/models.ts +2 -2
- package/src/client/i18n/messages/overview.ts +1 -1
- package/src/client/routes/CostsRoute.tsx +24 -28
- package/src/client/routes/ErrorsRoute.tsx +57 -55
- package/src/client/routes/GainRoute.tsx +54 -54
- package/src/client/routes/ModelsRoute.tsx +7 -5
- package/src/client/routes/OverviewRoute.tsx +73 -62
- package/src/client/routes/ProvidersRoute.tsx +188 -176
- package/src/client/routes/RequestsRoute.tsx +98 -96
- package/src/client/routes/ToolsRoute.tsx +11 -10
- package/src/client/routes/TracesRoute.tsx +2 -1
- package/src/client/traces/SpanDrawer.tsx +2 -2
- package/src/client/traces/TimelineCanvas.tsx +16 -12
- package/src/client/traces/TraceView.tsx +18 -14
- package/src/client/ui/RequestDrawer.tsx +16 -6
- package/src/server.ts +7 -3
- package/src/shared-types.ts +4 -3
- package/src/trace.ts +43 -13
|
@@ -2,7 +2,7 @@ import { useMemo, useState } from "react";
|
|
|
2
2
|
import { getGainDashboardStats } from "../api";
|
|
3
3
|
import { t } from "../i18n";
|
|
4
4
|
import { Chart, type ChartSeries, Legend } from "../charts";
|
|
5
|
-
import { formatBytes, formatCompact, formatInteger, formatPercent } from "../data/formatters";
|
|
5
|
+
import { formatBytes, formatCompact, formatInteger, formatPercent, formatUtcDay } from "../data/formatters";
|
|
6
6
|
import { useQuery } from "../data/query";
|
|
7
7
|
import { bucketAxis, rangeMeta } from "../data/range";
|
|
8
8
|
import { densify } from "../data/series";
|
|
@@ -30,8 +30,6 @@ const DAY_MS = 86_400_000;
|
|
|
30
30
|
const SOURCE_LABEL: Record<GainSource, string> = { snapcompact: "Snapcompact" };
|
|
31
31
|
|
|
32
32
|
/** The server buckets gain by UTC calendar day (`YYYY-MM-DD`). */
|
|
33
|
-
const DAY_LABEL = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", timeZone: "UTC" });
|
|
34
|
-
|
|
35
33
|
interface SourceRow extends GainSourceTotals {
|
|
36
34
|
source: GainSource;
|
|
37
35
|
/** Share of all saved tokens (0-1). */
|
|
@@ -166,7 +164,7 @@ export function GainRoute({ active, range }: GainRouteProps) {
|
|
|
166
164
|
>
|
|
167
165
|
<Chart
|
|
168
166
|
slots={series.buckets.length}
|
|
169
|
-
tickLabel={i =>
|
|
167
|
+
tickLabel={i => formatUtcDay(series.buckets[i])}
|
|
170
168
|
series={chartSeries}
|
|
171
169
|
height={260}
|
|
172
170
|
formatTooltip={formatInteger}
|
|
@@ -181,7 +179,7 @@ export function GainRoute({ active, range }: GainRouteProps) {
|
|
|
181
179
|
flush
|
|
182
180
|
stale={gain.stale}
|
|
183
181
|
>
|
|
184
|
-
<Table rows={sourceRows} rowKey={row => row.source} columns={
|
|
182
|
+
<Table rows={sourceRows} rowKey={row => row.source} columns={sourceColumns()} />
|
|
185
183
|
</Card>
|
|
186
184
|
</>
|
|
187
185
|
)}
|
|
@@ -190,52 +188,54 @@ export function GainRoute({ active, range }: GainRouteProps) {
|
|
|
190
188
|
);
|
|
191
189
|
}
|
|
192
190
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
<
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
191
|
+
function sourceColumns(): Column<SourceRow>[] {
|
|
192
|
+
return [
|
|
193
|
+
{
|
|
194
|
+
key: "source",
|
|
195
|
+
header: t("gain.source"),
|
|
196
|
+
sort: row => row.source,
|
|
197
|
+
render: row => <span className="cell-primary">{SOURCE_LABEL[row.source]}</span>,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
key: "tokens",
|
|
201
|
+
header: t("gain.saved-tokens"),
|
|
202
|
+
align: "right",
|
|
203
|
+
sort: row => row.savedTokens,
|
|
204
|
+
render: row => (
|
|
205
|
+
<span title={formatInteger(row.savedTokens)}>
|
|
206
|
+
<MeterCell value={row.share} max={1} display={formatCompact(row.savedTokens)} />
|
|
207
|
+
</span>
|
|
208
|
+
),
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
key: "share",
|
|
212
|
+
header: t("common.share"),
|
|
213
|
+
align: "right",
|
|
214
|
+
sort: row => row.share,
|
|
215
|
+
render: row => <span className="num muted">{formatPercent(row.share)}</span>,
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
key: "bytes",
|
|
219
|
+
header: t("gain.saved-bytes"),
|
|
220
|
+
align: "right",
|
|
221
|
+
sort: row => row.savedBytes,
|
|
222
|
+
render: row => <span className="num">{formatBytes(row.savedBytes)}</span>,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
key: "hits",
|
|
226
|
+
header: t("gain.hits"),
|
|
227
|
+
align: "right",
|
|
228
|
+
sort: row => row.hits,
|
|
229
|
+
render: row => <span className="num">{formatInteger(row.hits)}</span>,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
key: "reduction",
|
|
233
|
+
header: t("gain.reduction"),
|
|
234
|
+
align: "right",
|
|
235
|
+
sort: row => row.reductionPercent ?? -1,
|
|
236
|
+
render: row => (
|
|
237
|
+
<span className="num">{row.reductionPercent !== null ? formatPercent(row.reductionPercent) : "–"}</span>
|
|
238
|
+
),
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
}
|
|
@@ -52,10 +52,12 @@ export interface ModelsRouteProps {
|
|
|
52
52
|
|
|
53
53
|
type ShareMode = "share" | "requests";
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
function shareOptions() {
|
|
56
|
+
return [
|
|
57
|
+
{ value: "share" as const, label: t("common.share") },
|
|
58
|
+
{ value: "requests" as const, label: t("common.requests") },
|
|
59
|
+
];
|
|
60
|
+
}
|
|
59
61
|
|
|
60
62
|
/** Models plotted individually in the share chart; the rest fold into "Other". */
|
|
61
63
|
const SHARE_LIMIT = 6;
|
|
@@ -147,7 +149,7 @@ export function ModelsRoute({ active, range }: ModelsRouteProps) {
|
|
|
147
149
|
actions={
|
|
148
150
|
<Segmented
|
|
149
151
|
size="sm"
|
|
150
|
-
options={
|
|
152
|
+
options={shareOptions()}
|
|
151
153
|
value={mode}
|
|
152
154
|
onChange={setMode}
|
|
153
155
|
aria-label={t("models.share-mode-aria")}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
Badge,
|
|
24
24
|
Card,
|
|
25
25
|
ChartSkeleton,
|
|
26
|
+
type Column,
|
|
26
27
|
Dot,
|
|
27
28
|
LabelCell,
|
|
28
29
|
PageHeader,
|
|
@@ -42,29 +43,37 @@ export interface OverviewRouteProps {
|
|
|
42
43
|
|
|
43
44
|
type ActivityMetric = "requests" | "tokens" | "cost";
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
// Translated labels are functions, not module-level constants: `t()` reads the
|
|
47
|
+
// active locale, so a table built at import time would keep the boot language
|
|
48
|
+
// after the topbar switch (the Chinese labels in an English dashboard bug).
|
|
49
|
+
function activityOptions() {
|
|
50
|
+
return [
|
|
51
|
+
{ value: "requests" as const, label: t("common.requests") },
|
|
52
|
+
{ value: "tokens" as const, label: t("common.tokens") },
|
|
53
|
+
{ value: "cost" as const, label: t("common.cost") },
|
|
54
|
+
];
|
|
55
|
+
}
|
|
50
56
|
|
|
51
|
-
const
|
|
52
|
-
main:
|
|
53
|
-
subagent:
|
|
54
|
-
advisor:
|
|
57
|
+
const AGENT_LABEL_KEY: Record<AgentType, "overview.main-agent" | "overview.subagents" | "overview.advisor"> = {
|
|
58
|
+
main: "overview.main-agent",
|
|
59
|
+
subagent: "overview.subagents",
|
|
60
|
+
advisor: "overview.advisor",
|
|
55
61
|
};
|
|
62
|
+
|
|
56
63
|
const AGENT_COLOR: Record<AgentType, string> = {
|
|
57
64
|
main: "var(--chart-primary)",
|
|
58
65
|
subagent: "var(--chart-secondary)",
|
|
59
66
|
advisor: "#9d7bff",
|
|
60
67
|
};
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
function tokenMix() {
|
|
70
|
+
return [
|
|
71
|
+
{ key: "input", label: t("overview.uncached-input"), color: "#5b8cff" },
|
|
72
|
+
{ key: "cacheRead", label: t("common.cache-read"), color: "var(--chart-primary)" },
|
|
73
|
+
{ key: "cacheWrite", label: t("common.cache-write"), color: "#f5b54a" },
|
|
74
|
+
{ key: "output", label: t("common.output"), color: "var(--chart-secondary)" },
|
|
75
|
+
] as const;
|
|
76
|
+
}
|
|
68
77
|
|
|
69
78
|
export function OverviewRoute({ active, range, onRequestClick }: OverviewRouteProps) {
|
|
70
79
|
const overview = useQuery(["overview", range], ({ signal }) => getOverviewStats(range, signal), { enabled: active });
|
|
@@ -200,7 +209,7 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
|
|
|
200
209
|
? t("overview.per-hour")
|
|
201
210
|
: t("overview.per-day")
|
|
202
211
|
}
|
|
203
|
-
actions={<Segmented size="sm" options={
|
|
212
|
+
actions={<Segmented size="sm" options={activityOptions()} value={metric} onChange={setMetric} />}
|
|
204
213
|
stale={overview.stale}
|
|
205
214
|
>
|
|
206
215
|
<QueryView query={overview} skeleton={<ChartSkeleton height={260} />}>
|
|
@@ -236,7 +245,7 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
|
|
|
236
245
|
<div className="stack" style={{ gap: 18 }}>
|
|
237
246
|
<div className="stack" style={{ gap: 10 }}>
|
|
238
247
|
<ShareBar
|
|
239
|
-
segments={
|
|
248
|
+
segments={tokenMix().map(slice => ({
|
|
240
249
|
key: slice.key,
|
|
241
250
|
label: slice.label,
|
|
242
251
|
value: mix[slice.key],
|
|
@@ -244,7 +253,7 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
|
|
|
244
253
|
}))}
|
|
245
254
|
/>
|
|
246
255
|
<Legend
|
|
247
|
-
items={
|
|
256
|
+
items={tokenMix().map(slice => ({
|
|
248
257
|
key: slice.key,
|
|
249
258
|
label: slice.label,
|
|
250
259
|
color: slice.color,
|
|
@@ -259,7 +268,7 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
|
|
|
259
268
|
<ShareBar
|
|
260
269
|
segments={agents.segments.map(s => ({
|
|
261
270
|
key: s.agentType,
|
|
262
|
-
label:
|
|
271
|
+
label: t(AGENT_LABEL_KEY[s.agentType]),
|
|
263
272
|
value: s.tokens,
|
|
264
273
|
color: AGENT_COLOR[s.agentType],
|
|
265
274
|
}))}
|
|
@@ -268,7 +277,7 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
|
|
|
268
277
|
<div key={s.agentType} className="row" style={{ justifyContent: "space-between" }}>
|
|
269
278
|
<span className="row">
|
|
270
279
|
<span className="swatch" style={{ background: AGENT_COLOR[s.agentType] }} />
|
|
271
|
-
{
|
|
280
|
+
{t(AGENT_LABEL_KEY[s.agentType])}
|
|
272
281
|
<span className="dim num">
|
|
273
282
|
{t("overview.requests-short", { count: formatInteger(s.requests) })}
|
|
274
283
|
</span>
|
|
@@ -310,7 +319,7 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
|
|
|
310
319
|
rows={rows}
|
|
311
320
|
rowKey={row => row.id ?? `${row.sessionFile}:${row.entryId}`}
|
|
312
321
|
onRowClick={row => row.id !== undefined && onRequestClick(row.id)}
|
|
313
|
-
columns={
|
|
322
|
+
columns={requestColumns()}
|
|
314
323
|
dense
|
|
315
324
|
/>
|
|
316
325
|
)}
|
|
@@ -320,44 +329,46 @@ export function OverviewRoute({ active, range, onRequestClick }: OverviewRoutePr
|
|
|
320
329
|
);
|
|
321
330
|
}
|
|
322
331
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
row
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
332
|
+
function requestColumns(): Column<MessageStats>[] {
|
|
333
|
+
return [
|
|
334
|
+
{
|
|
335
|
+
key: "model",
|
|
336
|
+
header: t("common.model"),
|
|
337
|
+
render: (row: MessageStats) => <LabelCell primary={row.model} secondary={row.provider} />,
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
key: "time",
|
|
341
|
+
header: t("overview.when"),
|
|
342
|
+
render: (row: MessageStats) => <span className="muted">{formatRelativeTime(row.timestamp)}</span>,
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
key: "tokens",
|
|
346
|
+
header: t("common.tokens"),
|
|
347
|
+
align: "right" as const,
|
|
348
|
+
render: (row: MessageStats) => <span className="num">{formatInteger(row.usage.totalTokens)}</span>,
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
key: "cost",
|
|
352
|
+
header: t("common.cost"),
|
|
353
|
+
align: "right" as const,
|
|
354
|
+
render: (row: MessageStats) => <span className="num">{formatMessageCost(row, 4)}</span>,
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
key: "duration",
|
|
358
|
+
header: t("common.duration"),
|
|
359
|
+
align: "right" as const,
|
|
360
|
+
render: (row: MessageStats) => <span className="num">{formatDurationMs(row.duration)}</span>,
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
key: "status",
|
|
364
|
+
header: t("overview.status"),
|
|
365
|
+
align: "right" as const,
|
|
366
|
+
render: (row: MessageStats) =>
|
|
367
|
+
row.errorMessage ? (
|
|
368
|
+
<Badge tone="bad">{t("common.failed")}</Badge>
|
|
369
|
+
) : (
|
|
370
|
+
<Badge tone="ok">{t("overview.ok")}</Badge>
|
|
371
|
+
),
|
|
372
|
+
},
|
|
373
|
+
];
|
|
374
|
+
}
|