@koinzhang/paseo-plugin-activity 0.5.0 → 0.7.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 +78 -1
- package/README.md +15 -8
- package/client/activity-heatmap.tsx +126 -93
- package/client/agent-creations.tsx +216 -0
- package/client/attention-pill.tsx +16 -5
- package/client/attention-popover.tsx +19 -23
- package/client/color-mix.test.ts +27 -0
- package/client/color-mix.ts +38 -0
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +168 -0
- package/client/fit-text.test.ts +41 -0
- package/client/fit-text.ts +33 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +316 -275
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +425 -0
- package/client/measured-width.ts +72 -0
- package/client/panel-visibility.test.ts +25 -0
- package/client/panel-visibility.ts +45 -0
- package/client/panel.tsx +83 -108
- package/client/provider-dropdown.tsx +131 -0
- package/client/provider-filter.test.ts +17 -13
- package/client/provider-filter.ts +5 -7
- package/client/range.test.ts +44 -0
- package/client/range.ts +14 -0
- package/client/rank-color.test.ts +108 -14
- package/client/rank-color.ts +261 -48
- package/client/ranking-bars.tsx +291 -0
- package/client/ui.tsx +339 -0
- package/client/usage-popover.tsx +62 -134
- package/client/usage-stats.tsx +137 -8
- package/client/use-agent-turn-end.ts +2 -1
- package/client/use-app-language.ts +17 -0
- package/client/web.ts +73 -18
- package/client/workspace/agent-row.tsx +18 -25
- package/client/workspace/agents-section.tsx +23 -20
- package/client/workspace/constants.ts +6 -6
- package/client/workspace/display-menu.tsx +5 -4
- package/client/workspace/filters.test.ts +1 -1
- package/client/workspace/filters.ts +4 -2
- package/client/workspace/panel.tsx +176 -104
- package/client/workspace/rank-section.tsx +157 -44
- package/client/workspace/terminals-section.tsx +13 -9
- package/index.client.tsx +40 -20
- package/index.server.ts +63 -31
- package/package.json +2 -2
- package/paseo-plugin.json +2 -1
- package/server/agents.ts +20 -2
- package/server/background-sync.test.ts +43 -0
- package/server/background-sync.ts +43 -4
- package/server/handlers-query.test.ts +252 -1
- package/server/handlers.ts +174 -13
- package/server/ingest.test.ts +8 -0
- package/server/messages.test.ts +96 -1
- package/server/prompt-dedupe.ts +52 -0
- package/server/rpc-cache.test.ts +74 -0
- package/server/rpc-cache.ts +48 -0
- package/server/store.test.ts +122 -0
- package/server/store.ts +313 -19
- package/server/ttl-cache.ts +3 -0
- package/shared/activity.test.ts +159 -6
- package/shared/activity.ts +140 -5
- package/shared/classify.test.ts +1 -0
- package/shared/classify.ts +4 -1
- package/shared/explorer-agent-display.test.ts +61 -0
- package/shared/explorer-agent-display.ts +21 -2
- package/shared/format.test.ts +28 -3
- package/shared/format.ts +25 -2
- package/shared/i18n.test.ts +34 -0
- package/shared/i18n.ts +363 -0
- package/shared/insights.test.ts +162 -80
- package/shared/insights.ts +136 -61
- package/shared/usage.test.ts +330 -0
- package/shared/usage.ts +471 -0
|
@@ -3,8 +3,6 @@ import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
|
3
3
|
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
|
4
4
|
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
5
5
|
import {
|
|
6
|
-
ActivityIndicator,
|
|
7
|
-
Pressable,
|
|
8
6
|
ScrollView,
|
|
9
7
|
Text,
|
|
10
8
|
View,
|
|
@@ -12,30 +10,45 @@ import {
|
|
|
12
10
|
type ViewStyle,
|
|
13
11
|
} from "react-native";
|
|
14
12
|
import {
|
|
13
|
+
usageActivityByHourRpc,
|
|
15
14
|
providerLabel,
|
|
16
15
|
usageActivityByDayRpc,
|
|
16
|
+
usageAgentCreationsRpc,
|
|
17
|
+
usageAgentLifetimeRpc,
|
|
18
|
+
usageByProjectRpc,
|
|
17
19
|
usageByProviderRpc,
|
|
20
|
+
OTHER_PROJECT_KEY,
|
|
18
21
|
type ProviderUsageItem,
|
|
19
22
|
} from "../shared/usage.ts";
|
|
20
23
|
import { formatDisplayName } from "../shared/format.ts";
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} from "./
|
|
26
|
-
|
|
24
|
+
import { ActivityHeatmap } from "./activity-heatmap.tsx";
|
|
25
|
+
import { AgentCreations } from "./agent-creations.tsx";
|
|
26
|
+
import { HourlyActivityTimeline } from "./hourly-activity-timeline.tsx";
|
|
27
|
+
import { ProviderDropdown } from "./provider-dropdown.tsx";
|
|
28
|
+
import { RankingBars, type RankingEntry } from "./ranking-bars.tsx";
|
|
27
29
|
import { UsageStats } from "./usage-stats.tsx";
|
|
28
|
-
import {
|
|
30
|
+
import { chartColorScheme, entityColor, providerColor } from "./rank-color.ts";
|
|
29
31
|
import { selectProviderOptions } from "./provider-filter.ts";
|
|
30
32
|
import { useAppLanguage } from "./use-app-language.ts";
|
|
31
|
-
import { buildActivityInsights,
|
|
32
|
-
import {
|
|
33
|
+
import { buildActivityInsights, buildActivityKpi } from "../shared/insights.ts";
|
|
34
|
+
import { fixedWindowFrom } from "./range.ts";
|
|
33
35
|
import { useRegisterOpenAgent } from "./open-agent.ts";
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
import { ICON_SIZE, ROW_PADDING, TEXT, pageLayout, titleGap } from "./design-tokens.ts";
|
|
37
|
+
import { messagesFor, type Messages } from "../shared/i18n.ts";
|
|
38
|
+
import {
|
|
39
|
+
ErrorState,
|
|
40
|
+
IconButton,
|
|
41
|
+
InlineEmpty,
|
|
42
|
+
LoadingState,
|
|
43
|
+
PageEmpty,
|
|
44
|
+
SectionHeader,
|
|
45
|
+
} from "./ui.tsx";
|
|
46
|
+
|
|
47
|
+
/** Fixed width of the creations histogram (050). */
|
|
48
|
+
const CREATIONS_WINDOW_DAYS = 30;
|
|
49
|
+
const HOURLY_WINDOW_HOURS = 7 * 24;
|
|
50
|
+
|
|
51
|
+
/** Zeroed provider row when a selected provider has no usage row. */
|
|
39
52
|
function emptyProviderUsage(provider: string, label?: string): ProviderUsageItem {
|
|
40
53
|
return {
|
|
41
54
|
provider,
|
|
@@ -62,37 +75,6 @@ function emptyProviderUsage(provider: string, label?: string): ProviderUsageItem
|
|
|
62
75
|
|
|
63
76
|
|
|
64
77
|
|
|
65
|
-
function formatCount(value: number): string {
|
|
66
|
-
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
|
|
67
|
-
if (value >= 10_000) return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;
|
|
68
|
-
return String(value);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function TextTabs({
|
|
72
|
-
options,
|
|
73
|
-
value,
|
|
74
|
-
onChange,
|
|
75
|
-
styles,
|
|
76
|
-
}: {
|
|
77
|
-
options: ReadonlyArray<{ id: string; label: string }>;
|
|
78
|
-
value: string;
|
|
79
|
-
onChange: (id: string) => void;
|
|
80
|
-
styles: { tabRow: ViewStyle; tab: TextStyle; tabActive: TextStyle };
|
|
81
|
-
}): ReactNode {
|
|
82
|
-
return (
|
|
83
|
-
<View style={styles.tabRow}>
|
|
84
|
-
{options.map((option) => {
|
|
85
|
-
const active = option.id === value;
|
|
86
|
-
return (
|
|
87
|
-
<Pressable key={option.id} accessibilityRole="tab" accessibilityState={{ selected: active }} style={{ paddingVertical: 6 }} onPress={() => onChange(option.id)}>
|
|
88
|
-
<Text style={active ? styles.tabActive : styles.tab}>{option.label}</Text>
|
|
89
|
-
</Pressable>
|
|
90
|
-
);
|
|
91
|
-
})}
|
|
92
|
-
</View>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
78
|
type RankKind = "skills" | "mcp" | "models";
|
|
97
79
|
|
|
98
80
|
type RankItem = {
|
|
@@ -101,7 +83,7 @@ type RankItem = {
|
|
|
101
83
|
count: number;
|
|
102
84
|
kind: RankKind;
|
|
103
85
|
server?: string;
|
|
104
|
-
|
|
86
|
+
unit?: "prompts";
|
|
105
87
|
};
|
|
106
88
|
|
|
107
89
|
const RANK_CYCLE: RankKind[] = ["skills", "mcp", "models"];
|
|
@@ -110,29 +92,10 @@ function nextRankKind(kind: RankKind): RankKind {
|
|
|
110
92
|
return RANK_CYCLE[(RANK_CYCLE.indexOf(kind) + 1) % RANK_CYCLE.length] ?? "skills";
|
|
111
93
|
}
|
|
112
94
|
|
|
113
|
-
function
|
|
114
|
-
if (kind === "skills") return "
|
|
115
|
-
if (kind === "mcp") return "
|
|
116
|
-
return "
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function rankEmpty(kind: RankKind): string {
|
|
120
|
-
if (kind === "skills") return "No skills yet";
|
|
121
|
-
if (kind === "mcp") return "No MCP yet";
|
|
122
|
-
return "No models yet";
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function rankHeaderAction(kind: RankKind): {
|
|
126
|
-
icon: "Sparkles" | "Plug" | "Bot";
|
|
127
|
-
accessibilityLabel: string;
|
|
128
|
-
} {
|
|
129
|
-
if (kind === "skills") {
|
|
130
|
-
return { icon: "Plug", accessibilityLabel: "Show most used MCP" };
|
|
131
|
-
}
|
|
132
|
-
if (kind === "mcp") {
|
|
133
|
-
return { icon: "Bot", accessibilityLabel: "Show most used models" };
|
|
134
|
-
}
|
|
135
|
-
return { icon: "Sparkles", accessibilityLabel: "Show most used skills" };
|
|
95
|
+
function rankShowIcon(kind: RankKind): "Sparkles" | "Plug" | "Bot" {
|
|
96
|
+
if (kind === "skills") return "Plug";
|
|
97
|
+
if (kind === "mcp") return "Bot";
|
|
98
|
+
return "Sparkles";
|
|
136
99
|
}
|
|
137
100
|
|
|
138
101
|
function rankIconName(kind: RankKind): "Sparkles" | "Plug" | "Bot" {
|
|
@@ -141,72 +104,92 @@ function rankIconName(kind: RankKind): "Sparkles" | "Plug" | "Bot" {
|
|
|
141
104
|
return "Bot";
|
|
142
105
|
}
|
|
143
106
|
|
|
107
|
+
const ROW_GAP = 2;
|
|
108
|
+
|
|
144
109
|
function RankList({
|
|
145
110
|
title,
|
|
146
111
|
items,
|
|
147
112
|
empty,
|
|
148
113
|
styles,
|
|
149
114
|
colors,
|
|
115
|
+
compact,
|
|
116
|
+
units,
|
|
117
|
+
visibleRows,
|
|
150
118
|
headerAction,
|
|
151
119
|
}: {
|
|
152
120
|
title: string;
|
|
153
121
|
items: RankItem[];
|
|
154
122
|
empty: string;
|
|
155
123
|
styles: {
|
|
156
|
-
block: ViewStyle;
|
|
157
|
-
blockTitle: TextStyle;
|
|
158
|
-
titleRow: ViewStyle;
|
|
159
|
-
titleAction: ViewStyle;
|
|
160
124
|
rankRow: ViewStyle;
|
|
161
125
|
rankName: TextStyle;
|
|
162
126
|
rankMeta: TextStyle;
|
|
163
|
-
emptyHint: TextStyle;
|
|
164
127
|
};
|
|
165
|
-
colors: { accent: string; foregroundMuted: string };
|
|
128
|
+
colors: { accent: string; foreground: string; foregroundMuted: string; surface0: string };
|
|
129
|
+
compact: boolean;
|
|
130
|
+
units: Messages["units"];
|
|
131
|
+
/** Rows shown before the list scrolls (matches the Insights column). */
|
|
132
|
+
visibleRows: number;
|
|
166
133
|
headerAction?: {
|
|
167
134
|
icon: "Sparkles" | "Plug" | "Bot";
|
|
168
135
|
accessibilityLabel: string;
|
|
169
136
|
onPress: () => void;
|
|
170
137
|
};
|
|
171
138
|
}): ReactNode {
|
|
139
|
+
const [rowHeight, setRowHeight] = useState(0);
|
|
172
140
|
return (
|
|
173
|
-
<View style={
|
|
174
|
-
<View style={
|
|
175
|
-
<
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
</Pressable>
|
|
186
|
-
) : null}
|
|
141
|
+
<View style={{ gap: ROW_GAP }}>
|
|
142
|
+
<View style={{ marginBottom: titleGap(compact) - 2 }}>
|
|
143
|
+
<SectionHeader title={title} colors={colors} compact={compact}>
|
|
144
|
+
{headerAction ? (
|
|
145
|
+
<IconButton
|
|
146
|
+
icon={headerAction.icon}
|
|
147
|
+
label={headerAction.accessibilityLabel}
|
|
148
|
+
onPress={headerAction.onPress}
|
|
149
|
+
color={colors.foregroundMuted}
|
|
150
|
+
/>
|
|
151
|
+
) : null}
|
|
152
|
+
</SectionHeader>
|
|
187
153
|
</View>
|
|
188
154
|
{items.length === 0 ? (
|
|
189
|
-
<
|
|
155
|
+
<InlineEmpty text={empty} color={colors.foregroundMuted} />
|
|
190
156
|
) : (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
{
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
157
|
+
<ScrollView
|
|
158
|
+
key={items[0]?.kind}
|
|
159
|
+
style={{
|
|
160
|
+
maxHeight:
|
|
161
|
+
items.length > visibleRows && rowHeight > 0
|
|
162
|
+
? visibleRows * rowHeight + (visibleRows - 1) * ROW_GAP
|
|
163
|
+
: undefined,
|
|
164
|
+
}}
|
|
165
|
+
contentContainerStyle={{ gap: ROW_GAP }}
|
|
166
|
+
showsVerticalScrollIndicator={false}
|
|
167
|
+
nestedScrollEnabled
|
|
168
|
+
>
|
|
169
|
+
{items.map((item, index) => (
|
|
170
|
+
<View
|
|
171
|
+
key={item.key}
|
|
172
|
+
style={styles.rankRow}
|
|
173
|
+
onLayout={index === 0 ? (event) => setRowHeight(event.nativeEvent.layout.height) : undefined}
|
|
174
|
+
>
|
|
175
|
+
<Icon
|
|
176
|
+
name={rankIconName(item.kind)}
|
|
177
|
+
size={ICON_SIZE.inline}
|
|
178
|
+
color={
|
|
179
|
+
item.kind === "mcp"
|
|
180
|
+
? entityColor(item.server ?? "", chartColorScheme(colors.surface0))
|
|
181
|
+
: colors.accent
|
|
182
|
+
}
|
|
183
|
+
/>
|
|
184
|
+
<Text style={styles.rankName} numberOfLines={1}>
|
|
185
|
+
{item.label}
|
|
186
|
+
</Text>
|
|
187
|
+
<Text style={styles.rankMeta}>
|
|
188
|
+
{item.unit === "prompts" ? units.prompts(item.count) : units.calls(item.count)}
|
|
189
|
+
</Text>
|
|
190
|
+
</View>
|
|
191
|
+
))}
|
|
192
|
+
</ScrollView>
|
|
210
193
|
)}
|
|
211
194
|
</View>
|
|
212
195
|
);
|
|
@@ -214,77 +197,124 @@ function RankList({
|
|
|
214
197
|
|
|
215
198
|
export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceProps) {
|
|
216
199
|
useRegisterOpenAgent(navigation?.openAgent);
|
|
217
|
-
const [range, setRange] = useState<RangeId>("all");
|
|
218
200
|
const [providerFilter, setProviderFilter] = useState<string>("all");
|
|
219
|
-
const [heatmapMode, setHeatmapMode] = useState<HeatmapMode>("daily");
|
|
220
201
|
const [rankKind, setRankKind] = useState<RankKind>("skills");
|
|
221
202
|
const locale = useAppLanguage();
|
|
222
|
-
|
|
223
|
-
const from = rangeFrom(range);
|
|
203
|
+
const m = messagesFor(locale);
|
|
224
204
|
|
|
225
|
-
const
|
|
205
|
+
const page = pageLayout("surface", layout.compact);
|
|
226
206
|
const byProvider = useRpc(usageByProviderRpc);
|
|
207
|
+
const byProject = useRpc(usageByProjectRpc);
|
|
227
208
|
const activityByDay = useRpc(usageActivityByDayRpc);
|
|
209
|
+
const activityByHour = useRpc(usageActivityByHourRpc);
|
|
210
|
+
const agentLifetime = useRpc(usageAgentLifetimeRpc);
|
|
211
|
+
const agentCreations = useRpc(usageAgentCreationsRpc);
|
|
228
212
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const catalogQuery = useQuery({
|
|
213
|
+
// The page is all-time (069): one by-provider query feeds the dropdown, KPI,
|
|
214
|
+
// lists and the provider ranking.
|
|
215
|
+
const query = useQuery({
|
|
233
216
|
refetchInterval: 15_000,
|
|
234
217
|
retry: false,
|
|
235
218
|
queryKey: ["activity", "by-provider", "all"],
|
|
236
219
|
queryFn: () => byProvider({}),
|
|
237
220
|
});
|
|
238
221
|
|
|
239
|
-
const
|
|
222
|
+
const currentWindowStart = fixedWindowFrom(7);
|
|
223
|
+
const previousWindowStart = fixedWindowFrom(14);
|
|
224
|
+
// The RPC's `to` is inclusive; end the previous window just before this one.
|
|
225
|
+
const previousWindowEnd = new Date(Date.parse(currentWindowStart) - 1).toISOString();
|
|
226
|
+
const comparisonQuery = useQuery({
|
|
240
227
|
refetchInterval: 15_000,
|
|
241
228
|
retry: false,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
229
|
+
queryKey: ["activity", "kpi-comparison", currentWindowStart],
|
|
230
|
+
queryFn: async () => {
|
|
231
|
+
const [current, previous] = await Promise.all([
|
|
232
|
+
byProvider({ from: currentWindowStart }),
|
|
233
|
+
byProvider({ from: previousWindowStart, to: previousWindowEnd }),
|
|
234
|
+
]);
|
|
235
|
+
return { current: current.providers, previous: previous.providers };
|
|
236
|
+
},
|
|
247
237
|
});
|
|
248
238
|
|
|
249
239
|
const activityQuery = useQuery({
|
|
250
240
|
refetchInterval: 15_000,
|
|
251
241
|
retry: false,
|
|
252
|
-
queryKey: ["activity", "activity-by-day",
|
|
242
|
+
queryKey: ["activity", "activity-by-day", "all", providerFilter],
|
|
253
243
|
queryFn: () =>
|
|
254
244
|
activityByDay({
|
|
255
|
-
...filter,
|
|
256
245
|
provider: providerFilter === "all" ? undefined : providerFilter,
|
|
257
246
|
}),
|
|
258
|
-
// Keep prior heatmap while provider
|
|
247
|
+
// Keep prior heatmap while the provider switches — avoids spinner pushing layout.
|
|
248
|
+
placeholderData: keepPreviousData,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const lifetimeQuery = useQuery({
|
|
252
|
+
refetchInterval: 15_000,
|
|
253
|
+
retry: false,
|
|
254
|
+
// Lifetime is all-time by design (049): only the provider filter applies.
|
|
255
|
+
queryKey: ["activity", "agent-lifetime", providerFilter],
|
|
256
|
+
queryFn: () =>
|
|
257
|
+
agentLifetime({ provider: providerFilter === "all" ? undefined : providerFilter }),
|
|
258
|
+
placeholderData: keepPreviousData,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const histogramQuery = useQuery({
|
|
262
|
+
refetchInterval: 15_000,
|
|
263
|
+
retry: false,
|
|
264
|
+
// Fixed 30-day window (050).
|
|
265
|
+
queryKey: ["activity", "agent-creations", "last30", providerFilter],
|
|
266
|
+
queryFn: () =>
|
|
267
|
+
agentCreations({
|
|
268
|
+
from: fixedWindowFrom(CREATIONS_WINDOW_DAYS),
|
|
269
|
+
provider: providerFilter === "all" ? undefined : providerFilter,
|
|
270
|
+
}),
|
|
259
271
|
placeholderData: keepPreviousData,
|
|
260
272
|
});
|
|
261
273
|
|
|
262
|
-
const
|
|
263
|
-
|
|
274
|
+
const projectQuery = useQuery({
|
|
275
|
+
refetchInterval: 15_000,
|
|
276
|
+
retry: false,
|
|
277
|
+
queryKey: ["activity", "by-project", providerFilter],
|
|
278
|
+
queryFn: () =>
|
|
279
|
+
byProject({ provider: providerFilter === "all" ? undefined : providerFilter }),
|
|
280
|
+
placeholderData: keepPreviousData,
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const hourlyQuery = useQuery({
|
|
284
|
+
refetchInterval: 15_000,
|
|
285
|
+
retry: false,
|
|
286
|
+
// Fixed 168-hour window (059).
|
|
287
|
+
queryKey: ["activity", "activity-by-hour", "last168", providerFilter],
|
|
288
|
+
queryFn: () =>
|
|
289
|
+
activityByHour({
|
|
290
|
+
hours: HOURLY_WINDOW_HOURS,
|
|
291
|
+
provider: providerFilter === "all" ? undefined : providerFilter,
|
|
292
|
+
}),
|
|
293
|
+
placeholderData: keepPreviousData,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const providers = useMemo(() => query.data?.providers ?? [], [query.data]);
|
|
264
297
|
|
|
265
298
|
const providerOptions = useMemo(
|
|
266
299
|
() => [
|
|
267
|
-
{ id: "all", label:
|
|
268
|
-
...selectProviderOptions(
|
|
300
|
+
{ id: "all", label: m.global.allProviders },
|
|
301
|
+
...selectProviderOptions(providers, providerFilter),
|
|
269
302
|
],
|
|
270
|
-
[
|
|
303
|
+
[providers, providerFilter, m],
|
|
271
304
|
);
|
|
272
305
|
|
|
273
306
|
useEffect(() => {
|
|
274
|
-
if (providerFilter === "all") return;
|
|
275
|
-
if (!
|
|
307
|
+
if (providerFilter === "all" || !query.data) return;
|
|
308
|
+
if (!providers.some((item) => item.provider === providerFilter)) {
|
|
276
309
|
setProviderFilter("all");
|
|
277
310
|
}
|
|
278
|
-
}, [
|
|
311
|
+
}, [providers, providerFilter, query.data]);
|
|
279
312
|
|
|
280
313
|
const filteredProviders = useMemo(() => {
|
|
281
314
|
if (providerFilter === "all") return providers;
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (!catalog) return [];
|
|
286
|
-
return [emptyProviderUsage(catalog.provider, catalog.label)];
|
|
287
|
-
}, [catalogProviders, providerFilter, providers]);
|
|
315
|
+
const selected = providers.find((item) => item.provider === providerFilter);
|
|
316
|
+
return selected ? [selected] : [emptyProviderUsage(providerFilter)];
|
|
317
|
+
}, [providerFilter, providers]);
|
|
288
318
|
|
|
289
319
|
const lists = useMemo(() => {
|
|
290
320
|
if (providerFilter === "all") {
|
|
@@ -346,7 +376,7 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
346
376
|
label: formatDisplayName(model),
|
|
347
377
|
count,
|
|
348
378
|
kind: "models" as const,
|
|
349
|
-
|
|
379
|
+
unit: "prompts" as const,
|
|
350
380
|
}))
|
|
351
381
|
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
352
382
|
|
|
@@ -383,7 +413,7 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
383
413
|
label: formatDisplayName(item.model),
|
|
384
414
|
count: item.count,
|
|
385
415
|
kind: "models" as const,
|
|
386
|
-
|
|
416
|
+
unit: "prompts" as const,
|
|
387
417
|
}))
|
|
388
418
|
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
389
419
|
|
|
@@ -429,11 +459,6 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
429
459
|
};
|
|
430
460
|
}, [filteredProviders, providerFilter, query.data?.totals.workspaceCount]);
|
|
431
461
|
|
|
432
|
-
const streaks = useMemo(
|
|
433
|
-
() => computeStreaks(activityQuery.data?.days ?? []),
|
|
434
|
-
[activityQuery.data],
|
|
435
|
-
);
|
|
436
|
-
|
|
437
462
|
const insights = useMemo(() => {
|
|
438
463
|
return buildActivityInsights({
|
|
439
464
|
days: activityQuery.data?.days ?? [],
|
|
@@ -444,63 +469,82 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
444
469
|
messages: summary.messages,
|
|
445
470
|
codingAgents: summary.codingAgents,
|
|
446
471
|
chatAgents: summary.chatAgents,
|
|
447
|
-
longestStreak: streaks.longest,
|
|
448
472
|
},
|
|
449
|
-
|
|
450
|
-
|
|
473
|
+
workspaces: summary.workspaces,
|
|
474
|
+
averageSessionMs: lifetimeQuery.data?.averageEngagedMs,
|
|
475
|
+
multiTurn: lifetimeQuery.data,
|
|
451
476
|
locale,
|
|
452
|
-
limit: LIST_LIMIT,
|
|
453
477
|
});
|
|
454
|
-
}, [activityQuery.data?.days,
|
|
478
|
+
}, [activityQuery.data?.days, lifetimeQuery.data, locale, summary]);
|
|
455
479
|
|
|
456
480
|
const kpi = useMemo(
|
|
457
|
-
() =>
|
|
458
|
-
{
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
},
|
|
481
|
+
() =>
|
|
482
|
+
buildActivityKpi({
|
|
483
|
+
sessions: summary.agents,
|
|
484
|
+
messages: summary.messages,
|
|
485
|
+
locale,
|
|
486
|
+
providers: filteredProviders,
|
|
487
|
+
allProviders: providers,
|
|
488
|
+
providerFilter,
|
|
489
|
+
comparison: comparisonQuery.data,
|
|
490
|
+
}),
|
|
491
|
+
[
|
|
492
|
+
comparisonQuery.data,
|
|
493
|
+
filteredProviders,
|
|
494
|
+
locale,
|
|
495
|
+
providerFilter,
|
|
496
|
+
providers,
|
|
497
|
+
summary.agents,
|
|
498
|
+
summary.messages,
|
|
467
499
|
],
|
|
468
|
-
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
const scheme = chartColorScheme(theme.colors.surface0);
|
|
503
|
+
const providerEntries = useMemo<RankingEntry[]>(
|
|
504
|
+
() =>
|
|
505
|
+
providers.map((item) => ({
|
|
506
|
+
key: item.provider,
|
|
507
|
+
label: item.label,
|
|
508
|
+
color: providerColor(item.provider, scheme),
|
|
509
|
+
agents: item.agentCount,
|
|
510
|
+
messages: item.messageCount,
|
|
511
|
+
skills: item.skillCalls.exact + item.skillCalls.inferred,
|
|
512
|
+
mcp: item.mcpCalls,
|
|
513
|
+
})),
|
|
514
|
+
[providers, scheme],
|
|
515
|
+
);
|
|
516
|
+
const projectEntries = useMemo<RankingEntry[]>(
|
|
517
|
+
() =>
|
|
518
|
+
(projectQuery.data?.projects ?? []).map((item) => ({
|
|
519
|
+
key: item.key,
|
|
520
|
+
label: item.key === OTHER_PROJECT_KEY ? m.global.projectRanking.other : item.label,
|
|
521
|
+
color:
|
|
522
|
+
item.key === OTHER_PROJECT_KEY ? theme.colors.foregroundMuted : entityColor(item.key, scheme),
|
|
523
|
+
agents: item.agentCount,
|
|
524
|
+
messages: item.messageCount,
|
|
525
|
+
skills: item.skillCalls,
|
|
526
|
+
mcp: item.mcpCalls,
|
|
527
|
+
})),
|
|
528
|
+
[projectQuery.data, scheme, m, theme.colors.foregroundMuted],
|
|
469
529
|
);
|
|
470
530
|
|
|
471
531
|
const styles = useMemo(
|
|
472
532
|
() => ({
|
|
473
533
|
screen: { flex: 1, backgroundColor: theme.colors.surface0 },
|
|
474
534
|
content: {
|
|
475
|
-
padding,
|
|
476
|
-
paddingBottom: padding + 32,
|
|
477
|
-
gap:
|
|
535
|
+
padding: page.padding,
|
|
536
|
+
paddingBottom: page.padding + 32,
|
|
537
|
+
gap: page.gap,
|
|
478
538
|
maxWidth: 780,
|
|
479
539
|
width: "100%" as const,
|
|
480
540
|
alignSelf: "center" as const,
|
|
481
541
|
},
|
|
482
542
|
filterRow: {
|
|
483
543
|
flexDirection: "row" as const,
|
|
484
|
-
flexWrap: "wrap" as const,
|
|
485
|
-
alignItems: "center" as const,
|
|
486
|
-
justifyContent: "space-between" as const,
|
|
487
|
-
gap: layout.compact ? 12 : 16,
|
|
488
|
-
},
|
|
489
|
-
tabRow: {
|
|
490
|
-
flexDirection: "row" as const,
|
|
491
|
-
flexWrap: "wrap" as const,
|
|
492
544
|
alignItems: "center" as const,
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
color: theme.colors.foregroundMuted,
|
|
497
|
-
fontSize: 14,
|
|
498
|
-
fontWeight: "500" as const,
|
|
499
|
-
},
|
|
500
|
-
tabActive: {
|
|
501
|
-
color: theme.colors.foreground,
|
|
502
|
-
fontSize: 14,
|
|
503
|
-
fontWeight: "600" as const,
|
|
545
|
+
justifyContent: "flex-end" as const,
|
|
546
|
+
position: "relative" as const,
|
|
547
|
+
zIndex: 20,
|
|
504
548
|
},
|
|
505
549
|
columns: {
|
|
506
550
|
flexDirection: layout.compact ? ("column" as const) : ("row" as const),
|
|
@@ -512,42 +556,21 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
512
556
|
minWidth: 0,
|
|
513
557
|
width: layout.compact ? ("100%" as const) : undefined,
|
|
514
558
|
},
|
|
515
|
-
block: {
|
|
516
|
-
gap: 2,
|
|
517
|
-
},
|
|
518
|
-
titleRow: {
|
|
519
|
-
flexDirection: "row" as const,
|
|
520
|
-
alignItems: "center" as const,
|
|
521
|
-
justifyContent: "space-between" as const,
|
|
522
|
-
gap: 8,
|
|
523
|
-
marginBottom: 10,
|
|
524
|
-
},
|
|
525
|
-
blockTitle: {
|
|
526
|
-
color: theme.colors.foreground,
|
|
527
|
-
fontSize: layout.compact ? 13 : 15,
|
|
528
|
-
fontWeight: "500" as const,
|
|
529
|
-
flexShrink: 1,
|
|
530
|
-
marginBottom: 0,
|
|
531
|
-
},
|
|
532
|
-
titleAction: {
|
|
533
|
-
padding: 4,
|
|
534
|
-
borderRadius: 6,
|
|
535
|
-
},
|
|
536
559
|
insightRow: {
|
|
537
560
|
flexDirection: "row" as const,
|
|
538
561
|
alignItems: "baseline" as const,
|
|
539
562
|
justifyContent: "space-between" as const,
|
|
540
563
|
gap: 8,
|
|
541
|
-
paddingVertical:
|
|
564
|
+
paddingVertical: ROW_PADDING.regular,
|
|
542
565
|
},
|
|
543
566
|
insightLabel: {
|
|
567
|
+
...TEXT.body,
|
|
544
568
|
color: theme.colors.foregroundMuted,
|
|
545
|
-
fontSize: 14,
|
|
546
569
|
flexShrink: 0,
|
|
547
570
|
},
|
|
548
571
|
insightValue: {
|
|
572
|
+
...TEXT.body,
|
|
549
573
|
color: theme.colors.foreground,
|
|
550
|
-
fontSize: 14,
|
|
551
574
|
textAlign: "right" as const,
|
|
552
575
|
flex: 1,
|
|
553
576
|
minWidth: 0,
|
|
@@ -556,76 +579,57 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
556
579
|
flexDirection: "row" as const,
|
|
557
580
|
alignItems: "center" as const,
|
|
558
581
|
gap: 10,
|
|
559
|
-
paddingVertical:
|
|
582
|
+
paddingVertical: ROW_PADDING.regular,
|
|
560
583
|
},
|
|
561
584
|
rankName: {
|
|
585
|
+
...TEXT.body,
|
|
562
586
|
color: theme.colors.foreground,
|
|
563
|
-
fontSize: 14,
|
|
564
587
|
flex: 1,
|
|
565
588
|
minWidth: 0,
|
|
566
|
-
|
|
567
589
|
},
|
|
568
590
|
rankMeta: {
|
|
591
|
+
...TEXT.body,
|
|
569
592
|
color: theme.colors.foregroundMuted,
|
|
570
|
-
fontSize: 14,
|
|
571
593
|
fontVariant: ["tabular-nums" as const],
|
|
572
594
|
},
|
|
573
|
-
emptyState: {
|
|
574
|
-
paddingVertical: 48,
|
|
575
|
-
alignItems: "center" as const,
|
|
576
|
-
gap: 6,
|
|
577
|
-
},
|
|
578
|
-
emptyTitle: {
|
|
579
|
-
color: theme.colors.foreground,
|
|
580
|
-
fontSize: 19,
|
|
581
|
-
fontWeight: "500" as const,
|
|
582
|
-
},
|
|
583
|
-
emptyHint: {
|
|
584
|
-
color: theme.colors.foregroundMuted,
|
|
585
|
-
fontSize: 14,
|
|
586
|
-
},
|
|
587
595
|
}),
|
|
588
|
-
[theme, layout.compact, padding],
|
|
596
|
+
[theme, layout.compact, page.padding, page.gap],
|
|
589
597
|
);
|
|
590
598
|
|
|
591
599
|
// Keep prior results visible while refetching; spinner only on cold start.
|
|
592
600
|
const loading =
|
|
593
601
|
(!query.data && query.isLoading) ||
|
|
594
|
-
(!activityQuery.data && activityQuery.isLoading)
|
|
595
|
-
|
|
602
|
+
(!activityQuery.data && activityQuery.isLoading) ||
|
|
603
|
+
(!hourlyQuery.data && hourlyQuery.isLoading);
|
|
604
|
+
const error = query.error ?? activityQuery.error ?? hourlyQuery.error;
|
|
605
|
+
const retry = () => {
|
|
606
|
+
void query.refetch();
|
|
607
|
+
void activityQuery.refetch();
|
|
608
|
+
void hourlyQuery.refetch();
|
|
609
|
+
};
|
|
596
610
|
const showContent = filteredProviders.length > 0;
|
|
597
611
|
|
|
598
612
|
return (
|
|
599
613
|
<ScrollView style={styles.screen} contentContainerStyle={styles.content}>
|
|
600
|
-
|
|
601
|
-
<
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
onChange={(id) => setRange(id as RangeId)}
|
|
605
|
-
styles={styles}
|
|
606
|
-
/>
|
|
607
|
-
{providerOptions.length > 1 ? (
|
|
608
|
-
<TextTabs
|
|
614
|
+
{providerOptions.length > 1 ? (
|
|
615
|
+
<View style={styles.filterRow}>
|
|
616
|
+
<ProviderDropdown
|
|
617
|
+
label={m.global.providerLabel}
|
|
609
618
|
options={providerOptions}
|
|
610
619
|
value={providerFilter}
|
|
611
620
|
onChange={setProviderFilter}
|
|
612
|
-
|
|
621
|
+
colors={theme.colors}
|
|
622
|
+
triggerLabel={m.global.selectProvider}
|
|
623
|
+
closeLabel={m.global.closeProviderMenu}
|
|
613
624
|
/>
|
|
614
|
-
|
|
615
|
-
</View>
|
|
616
|
-
|
|
617
|
-
{loading ? <ActivityIndicator color={theme.colors.accent} /> : null}
|
|
618
|
-
{error ? (
|
|
619
|
-
<Text style={{ color: theme.colors.statusDanger }}>
|
|
620
|
-
{error instanceof Error ? error.message : String(error)}
|
|
621
|
-
</Text>
|
|
625
|
+
</View>
|
|
622
626
|
) : null}
|
|
623
627
|
|
|
628
|
+
{loading ? <LoadingState color={theme.colors.accent} /> : null}
|
|
629
|
+
{error ? <ErrorState error={error} onRetry={retry} colors={theme.colors} /> : null}
|
|
630
|
+
|
|
624
631
|
{filteredProviders.length === 0 && !loading && !error ? (
|
|
625
|
-
<
|
|
626
|
-
<Text style={styles.emptyTitle}>No usage yet</Text>
|
|
627
|
-
<Text style={styles.emptyHint}>Agents, messages, skill and MCP calls will show up here</Text>
|
|
628
|
-
</View>
|
|
632
|
+
<PageEmpty title={m.global.emptyTitle} hint={m.global.emptyHint} colors={theme.colors} />
|
|
629
633
|
) : null}
|
|
630
634
|
|
|
631
635
|
{showContent ? (
|
|
@@ -635,24 +639,63 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
635
639
|
{showContent ? (
|
|
636
640
|
<ActivityHeatmap
|
|
637
641
|
days={activityQuery.data?.days ?? []}
|
|
638
|
-
from={from}
|
|
639
642
|
colors={theme.colors}
|
|
640
643
|
compact={layout.compact}
|
|
641
|
-
mode=
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
]}
|
|
644
|
+
mode="daily"
|
|
645
|
+
/>
|
|
646
|
+
) : null}
|
|
647
|
+
|
|
648
|
+
{showContent ? (
|
|
649
|
+
<AgentCreations
|
|
650
|
+
days={histogramQuery.data?.days ?? []}
|
|
651
|
+
activityDays={activityQuery.data?.days ?? []}
|
|
652
|
+
windowDays={CREATIONS_WINDOW_DAYS}
|
|
653
|
+
colors={theme.colors}
|
|
654
|
+
compact={layout.compact}
|
|
655
|
+
locale={locale}
|
|
656
|
+
/>
|
|
657
|
+
) : null}
|
|
658
|
+
|
|
659
|
+
{showContent ? (
|
|
660
|
+
<HourlyActivityTimeline
|
|
661
|
+
hours={hourlyQuery.data?.hours ?? []}
|
|
662
|
+
colors={theme.colors}
|
|
663
|
+
compact={layout.compact}
|
|
664
|
+
locale={locale}
|
|
665
|
+
resetKey={providerFilter}
|
|
666
|
+
/>
|
|
667
|
+
) : null}
|
|
668
|
+
|
|
669
|
+
{showContent ? (
|
|
670
|
+
<RankingBars
|
|
671
|
+
title={m.global.providerRanking.title}
|
|
672
|
+
empty={m.global.providerRanking.empty}
|
|
673
|
+
entries={providerEntries}
|
|
674
|
+
highlight={providerFilter === "all" ? undefined : providerFilter}
|
|
675
|
+
colors={theme.colors}
|
|
676
|
+
compact={layout.compact}
|
|
677
|
+
locale={locale}
|
|
678
|
+
/>
|
|
679
|
+
) : null}
|
|
680
|
+
|
|
681
|
+
{showContent ? (
|
|
682
|
+
<RankingBars
|
|
683
|
+
title={m.global.projectRanking.title}
|
|
684
|
+
empty={m.global.projectRanking.empty}
|
|
685
|
+
entries={projectEntries}
|
|
686
|
+
colors={theme.colors}
|
|
687
|
+
compact={layout.compact}
|
|
688
|
+
locale={locale}
|
|
648
689
|
/>
|
|
649
690
|
) : null}
|
|
650
691
|
|
|
651
692
|
{showContent ? (
|
|
652
693
|
<View style={styles.columns}>
|
|
653
694
|
<View style={styles.column}>
|
|
654
|
-
<View style={
|
|
655
|
-
<
|
|
695
|
+
<View style={{ gap: 2 }}>
|
|
696
|
+
<View style={{ marginBottom: titleGap(layout.compact) - 2 }}>
|
|
697
|
+
<SectionHeader title={m.insights.title} colors={theme.colors} compact={layout.compact} />
|
|
698
|
+
</View>
|
|
656
699
|
{insights.map((row) => (
|
|
657
700
|
<View key={row.label} style={styles.insightRow}>
|
|
658
701
|
<Text style={styles.insightLabel}>{row.label}</Text>
|
|
@@ -666,19 +709,17 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
|
|
|
666
709
|
|
|
667
710
|
<View style={styles.column}>
|
|
668
711
|
<RankList
|
|
669
|
-
title={rankTitle
|
|
670
|
-
items={
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
: rankKind === "mcp"
|
|
674
|
-
? lists.mcp
|
|
675
|
-
: lists.models
|
|
676
|
-
).slice(0, LIST_LIMIT)}
|
|
677
|
-
empty={rankEmpty(rankKind)}
|
|
712
|
+
title={m.global.rankTitle[rankKind]}
|
|
713
|
+
items={lists[rankKind]}
|
|
714
|
+
visibleRows={insights.length}
|
|
715
|
+
empty={m.global.rankEmpty[rankKind]}
|
|
678
716
|
styles={styles}
|
|
679
717
|
colors={theme.colors}
|
|
718
|
+
compact={layout.compact}
|
|
719
|
+
units={m.units}
|
|
680
720
|
headerAction={{
|
|
681
|
-
|
|
721
|
+
icon: rankShowIcon(rankKind),
|
|
722
|
+
accessibilityLabel: m.global.rankShow[nextRankKind(rankKind)],
|
|
682
723
|
onPress: () => setRankKind((prev) => nextRankKind(prev)),
|
|
683
724
|
}}
|
|
684
725
|
/>
|