@koinzhang/paseo-plugin-activity 0.1.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/client/activity-heatmap.tsx +138 -0
- package/client/global-surface.tsx +689 -0
- package/client/panel.tsx +423 -0
- package/client/pending-skill.ts +50 -0
- package/client/pill-data-cache.test.ts +68 -0
- package/client/pill-data-cache.ts +37 -0
- package/client/pill.tsx +211 -0
- package/client/provider-filter.test.ts +95 -0
- package/client/provider-filter.ts +44 -0
- package/client/rank-color.test.ts +35 -0
- package/client/rank-color.ts +69 -0
- package/client/usage-popover.tsx +383 -0
- package/client/usage-query.tsx +54 -0
- package/client/usage-stats.tsx +18 -0
- package/client/use-app-language.ts +14 -0
- package/client/web.ts +28 -0
- package/index.client.tsx +62 -0
- package/index.server.ts +128 -0
- package/package.json +31 -0
- package/paseo-plugin.json +6 -0
- package/server/agents.test.ts +67 -0
- package/server/agents.ts +75 -0
- package/server/background-sync.test.ts +143 -0
- package/server/background-sync.ts +105 -0
- package/server/handlers-query.test.ts +91 -0
- package/server/handlers.ts +531 -0
- package/server/host-types.ts +14 -0
- package/server/ingest.test.ts +233 -0
- package/server/ingest.ts +277 -0
- package/server/mcp-servers.test.ts +70 -0
- package/server/mcp-servers.ts +212 -0
- package/server/messages.test.ts +150 -0
- package/server/migrate-data.test.ts +65 -0
- package/server/migrate-data.ts +54 -0
- package/server/resolve-model.test.ts +11 -0
- package/server/resolve-model.ts +30 -0
- package/server/skill-path.test.ts +56 -0
- package/server/skill-path.ts +85 -0
- package/server/store.test.ts +221 -0
- package/server/store.ts +909 -0
- package/server/ttl-cache.ts +34 -0
- package/shared/activity.test.ts +86 -0
- package/shared/activity.ts +185 -0
- package/shared/classify.test.ts +306 -0
- package/shared/classify.ts +378 -0
- package/shared/format.test.ts +48 -0
- package/shared/format.ts +45 -0
- package/shared/insights.test.ts +122 -0
- package/shared/insights.ts +188 -0
- package/shared/plugin-id.ts +7 -0
- package/shared/usage.test.ts +668 -0
- package/shared/usage.ts +726 -0
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import { type PluginSurfaceProps, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
5
|
+
import {
|
|
6
|
+
ActivityIndicator,
|
|
7
|
+
Pressable,
|
|
8
|
+
ScrollView,
|
|
9
|
+
Text,
|
|
10
|
+
View,
|
|
11
|
+
type TextStyle,
|
|
12
|
+
type ViewStyle,
|
|
13
|
+
} from "react-native";
|
|
14
|
+
import {
|
|
15
|
+
providerLabel,
|
|
16
|
+
usageActivityByDayRpc,
|
|
17
|
+
usageByProviderRpc,
|
|
18
|
+
type ProviderUsageItem,
|
|
19
|
+
} from "../shared/usage.ts";
|
|
20
|
+
import { formatDisplayName } from "../shared/format.ts";
|
|
21
|
+
import {
|
|
22
|
+
ActivityHeatmap,
|
|
23
|
+
computeStreaks,
|
|
24
|
+
type HeatmapMode,
|
|
25
|
+
} from "./activity-heatmap.tsx";
|
|
26
|
+
|
|
27
|
+
import { UsageStats } from "./usage-stats.tsx";
|
|
28
|
+
import { mcpServerColor } from "./rank-color.ts";
|
|
29
|
+
import { selectProviderOptions } from "./provider-filter.ts";
|
|
30
|
+
import { useAppLanguage } from "./use-app-language.ts";
|
|
31
|
+
import { buildActivityInsights, ACTIVITY_LIST_LIMIT } from "../shared/insights.ts";
|
|
32
|
+
|
|
33
|
+
type RangeId = "all" | "7d" | "30d" | "today";
|
|
34
|
+
|
|
35
|
+
/** Max rows for Activity insights and Most used skills / MCP. */
|
|
36
|
+
const LIST_LIMIT = ACTIVITY_LIST_LIMIT;
|
|
37
|
+
|
|
38
|
+
/** Zeroed provider row when the chip exists all-time but the time window has no rows. */
|
|
39
|
+
function emptyProviderUsage(provider: string, label?: string): ProviderUsageItem {
|
|
40
|
+
return {
|
|
41
|
+
provider,
|
|
42
|
+
label: label ?? providerLabel(provider),
|
|
43
|
+
shellCalls: 0,
|
|
44
|
+
shellFailures: 0,
|
|
45
|
+
fileReads: 0,
|
|
46
|
+
fileWrites: 0,
|
|
47
|
+
skillCalls: { exact: 0, inferred: 0, low: 0 },
|
|
48
|
+
skills: [],
|
|
49
|
+
mcpCalls: 0,
|
|
50
|
+
mcpFailures: 0,
|
|
51
|
+
mcpTools: [],
|
|
52
|
+
shellTop: [],
|
|
53
|
+
models: [],
|
|
54
|
+
agentCount: 0,
|
|
55
|
+
workspaceCount: 0,
|
|
56
|
+
messageCount: 0,
|
|
57
|
+
callCount: 0,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function rangeFrom(id: RangeId): string | undefined {
|
|
64
|
+
if (id === "all") return undefined;
|
|
65
|
+
if (id === "today") {
|
|
66
|
+
const d = new Date();
|
|
67
|
+
d.setHours(0, 0, 0, 0);
|
|
68
|
+
return d.toISOString();
|
|
69
|
+
}
|
|
70
|
+
const days = id === "7d" ? 7 : 30;
|
|
71
|
+
return new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function formatCount(value: number): string {
|
|
75
|
+
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
|
|
76
|
+
if (value >= 10_000) return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;
|
|
77
|
+
return String(value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function TextTabs({
|
|
81
|
+
options,
|
|
82
|
+
value,
|
|
83
|
+
onChange,
|
|
84
|
+
styles,
|
|
85
|
+
}: {
|
|
86
|
+
options: ReadonlyArray<{ id: string; label: string }>;
|
|
87
|
+
value: string;
|
|
88
|
+
onChange: (id: string) => void;
|
|
89
|
+
styles: { tabRow: ViewStyle; tab: TextStyle; tabActive: TextStyle };
|
|
90
|
+
}): ReactNode {
|
|
91
|
+
return (
|
|
92
|
+
<View style={styles.tabRow}>
|
|
93
|
+
{options.map((option) => {
|
|
94
|
+
const active = option.id === value;
|
|
95
|
+
return (
|
|
96
|
+
<Pressable key={option.id} accessibilityRole="tab" accessibilityState={{ selected: active }} style={{ paddingVertical: 6 }} onPress={() => onChange(option.id)}>
|
|
97
|
+
<Text style={active ? styles.tabActive : styles.tab}>{option.label}</Text>
|
|
98
|
+
</Pressable>
|
|
99
|
+
);
|
|
100
|
+
})}
|
|
101
|
+
</View>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type RankKind = "skills" | "mcp" | "models";
|
|
106
|
+
|
|
107
|
+
type RankItem = {
|
|
108
|
+
key: string;
|
|
109
|
+
label: string;
|
|
110
|
+
count: number;
|
|
111
|
+
kind: RankKind;
|
|
112
|
+
server?: string;
|
|
113
|
+
countLabel?: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const RANK_CYCLE: RankKind[] = ["skills", "mcp", "models"];
|
|
117
|
+
|
|
118
|
+
function nextRankKind(kind: RankKind): RankKind {
|
|
119
|
+
return RANK_CYCLE[(RANK_CYCLE.indexOf(kind) + 1) % RANK_CYCLE.length] ?? "skills";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function rankTitle(kind: RankKind): string {
|
|
123
|
+
if (kind === "skills") return "Most used skills";
|
|
124
|
+
if (kind === "mcp") return "Most used MCP";
|
|
125
|
+
return "Most used models";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function rankEmpty(kind: RankKind): string {
|
|
129
|
+
if (kind === "skills") return "No skills yet";
|
|
130
|
+
if (kind === "mcp") return "No MCP yet";
|
|
131
|
+
return "No models yet";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function rankHeaderAction(kind: RankKind): {
|
|
135
|
+
icon: "Sparkles" | "Plug" | "Bot";
|
|
136
|
+
accessibilityLabel: string;
|
|
137
|
+
} {
|
|
138
|
+
if (kind === "skills") {
|
|
139
|
+
return { icon: "Plug", accessibilityLabel: "Show most used MCP" };
|
|
140
|
+
}
|
|
141
|
+
if (kind === "mcp") {
|
|
142
|
+
return { icon: "Bot", accessibilityLabel: "Show most used models" };
|
|
143
|
+
}
|
|
144
|
+
return { icon: "Sparkles", accessibilityLabel: "Show most used skills" };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function rankIconName(kind: RankKind): "Sparkles" | "Plug" | "Bot" {
|
|
148
|
+
if (kind === "skills") return "Sparkles";
|
|
149
|
+
if (kind === "mcp") return "Plug";
|
|
150
|
+
return "Bot";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function RankList({
|
|
154
|
+
title,
|
|
155
|
+
items,
|
|
156
|
+
empty,
|
|
157
|
+
styles,
|
|
158
|
+
colors,
|
|
159
|
+
headerAction,
|
|
160
|
+
}: {
|
|
161
|
+
title: string;
|
|
162
|
+
items: RankItem[];
|
|
163
|
+
empty: string;
|
|
164
|
+
styles: {
|
|
165
|
+
block: ViewStyle;
|
|
166
|
+
blockTitle: TextStyle;
|
|
167
|
+
titleRow: ViewStyle;
|
|
168
|
+
titleAction: ViewStyle;
|
|
169
|
+
rankRow: ViewStyle;
|
|
170
|
+
rankName: TextStyle;
|
|
171
|
+
rankMeta: TextStyle;
|
|
172
|
+
emptyHint: TextStyle;
|
|
173
|
+
};
|
|
174
|
+
colors: { accent: string; foregroundMuted: string };
|
|
175
|
+
headerAction?: {
|
|
176
|
+
icon: "Sparkles" | "Plug" | "Bot";
|
|
177
|
+
accessibilityLabel: string;
|
|
178
|
+
onPress: () => void;
|
|
179
|
+
};
|
|
180
|
+
}): ReactNode {
|
|
181
|
+
return (
|
|
182
|
+
<View style={styles.block}>
|
|
183
|
+
<View style={styles.titleRow}>
|
|
184
|
+
<Text style={styles.blockTitle}>{title}</Text>
|
|
185
|
+
{headerAction ? (
|
|
186
|
+
<Pressable
|
|
187
|
+
accessibilityRole="button"
|
|
188
|
+
accessibilityLabel={headerAction.accessibilityLabel}
|
|
189
|
+
hitSlop={8}
|
|
190
|
+
onPress={headerAction.onPress}
|
|
191
|
+
style={styles.titleAction}
|
|
192
|
+
>
|
|
193
|
+
<Icon name={headerAction.icon} size={16} color={colors.foregroundMuted} />
|
|
194
|
+
</Pressable>
|
|
195
|
+
) : null}
|
|
196
|
+
</View>
|
|
197
|
+
{items.length === 0 ? (
|
|
198
|
+
<Text style={styles.emptyHint}>{empty}</Text>
|
|
199
|
+
) : (
|
|
200
|
+
items.map((item) => (
|
|
201
|
+
<View key={item.key} style={styles.rankRow}>
|
|
202
|
+
<Icon
|
|
203
|
+
name={rankIconName(item.kind)}
|
|
204
|
+
size={14}
|
|
205
|
+
color={
|
|
206
|
+
item.kind === "mcp"
|
|
207
|
+
? mcpServerColor(item.server ?? "", colors.accent)
|
|
208
|
+
: colors.accent
|
|
209
|
+
}
|
|
210
|
+
/>
|
|
211
|
+
<Text style={styles.rankName} numberOfLines={1}>
|
|
212
|
+
{item.label}
|
|
213
|
+
</Text>
|
|
214
|
+
<Text style={styles.rankMeta}>
|
|
215
|
+
{item.count} {item.countLabel ?? "calls"}
|
|
216
|
+
</Text>
|
|
217
|
+
</View>
|
|
218
|
+
))
|
|
219
|
+
)}
|
|
220
|
+
</View>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
|
|
225
|
+
const [range, setRange] = useState<RangeId>("all");
|
|
226
|
+
const [providerFilter, setProviderFilter] = useState<string>("all");
|
|
227
|
+
const [heatmapMode, setHeatmapMode] = useState<HeatmapMode>("daily");
|
|
228
|
+
const [rankKind, setRankKind] = useState<RankKind>("skills");
|
|
229
|
+
const locale = useAppLanguage();
|
|
230
|
+
// Recompute on each render so today / rolling windows refresh after midnight (poll-driven).
|
|
231
|
+
const from = rangeFrom(range);
|
|
232
|
+
|
|
233
|
+
const padding = layout.compact ? 16 : 20;
|
|
234
|
+
const byProvider = useRpc(usageByProviderRpc);
|
|
235
|
+
const activityByDay = useRpc(usageActivityByDayRpc);
|
|
236
|
+
|
|
237
|
+
const filter = from ? { from } : {};
|
|
238
|
+
|
|
239
|
+
/** All-time providers for filter chips (agents / skills / messages / …). */
|
|
240
|
+
const catalogQuery = useQuery({
|
|
241
|
+
refetchInterval: 15_000,
|
|
242
|
+
retry: false,
|
|
243
|
+
queryKey: ["activity", "by-provider", "all"],
|
|
244
|
+
queryFn: () => byProvider({}),
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const query = useQuery({
|
|
248
|
+
refetchInterval: 15_000,
|
|
249
|
+
retry: false,
|
|
250
|
+
// Shares cache with catalogQuery when range === "all".
|
|
251
|
+
queryKey: ["activity", "by-provider", from ?? "all"],
|
|
252
|
+
queryFn: () => byProvider(filter),
|
|
253
|
+
// Keep prior window while range chips change so KPI/lists do not collapse.
|
|
254
|
+
placeholderData: keepPreviousData,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const activityQuery = useQuery({
|
|
258
|
+
refetchInterval: 15_000,
|
|
259
|
+
retry: false,
|
|
260
|
+
queryKey: ["activity", "activity-by-day", range, from ?? "all", providerFilter],
|
|
261
|
+
queryFn: () =>
|
|
262
|
+
activityByDay({
|
|
263
|
+
...filter,
|
|
264
|
+
provider: providerFilter === "all" ? undefined : providerFilter,
|
|
265
|
+
}),
|
|
266
|
+
// Keep prior heatmap while provider / range switches — avoids spinner pushing layout.
|
|
267
|
+
placeholderData: keepPreviousData,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const providers = query.data?.providers ?? [];
|
|
271
|
+
const catalogProviders = catalogQuery.data?.providers ?? providers;
|
|
272
|
+
|
|
273
|
+
const providerOptions = useMemo(
|
|
274
|
+
() => [
|
|
275
|
+
{ id: "all", label: "All" },
|
|
276
|
+
...selectProviderOptions(catalogProviders, providerFilter),
|
|
277
|
+
],
|
|
278
|
+
[catalogProviders, providerFilter],
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
if (providerFilter === "all") return;
|
|
283
|
+
if (!catalogProviders.some((item) => item.provider === providerFilter)) {
|
|
284
|
+
setProviderFilter("all");
|
|
285
|
+
}
|
|
286
|
+
}, [catalogProviders, providerFilter]);
|
|
287
|
+
|
|
288
|
+
const filteredProviders = useMemo(() => {
|
|
289
|
+
if (providerFilter === "all") return providers;
|
|
290
|
+
const inWindow = providers.filter((item) => item.provider === providerFilter);
|
|
291
|
+
if (inWindow.length > 0) return inWindow;
|
|
292
|
+
const catalog = catalogProviders.find((item) => item.provider === providerFilter);
|
|
293
|
+
if (!catalog) return [];
|
|
294
|
+
return [emptyProviderUsage(catalog.provider, catalog.label)];
|
|
295
|
+
}, [catalogProviders, providerFilter, providers]);
|
|
296
|
+
|
|
297
|
+
const lists = useMemo(() => {
|
|
298
|
+
if (providerFilter === "all") {
|
|
299
|
+
const mcpMap = new Map<
|
|
300
|
+
string,
|
|
301
|
+
{ server: string; tool: string; count: number; failures: number }
|
|
302
|
+
>();
|
|
303
|
+
const skillMap = new Map<string, number>();
|
|
304
|
+
const modelMap = new Map<string, number>();
|
|
305
|
+
|
|
306
|
+
for (const item of providers) {
|
|
307
|
+
for (const mcp of item.mcpTools) {
|
|
308
|
+
const key = `${mcp.server}.${mcp.tool}`;
|
|
309
|
+
const prev = mcpMap.get(key);
|
|
310
|
+
if (prev) {
|
|
311
|
+
prev.count += mcp.count;
|
|
312
|
+
prev.failures += mcp.failures;
|
|
313
|
+
} else {
|
|
314
|
+
mcpMap.set(key, {
|
|
315
|
+
server: mcp.server,
|
|
316
|
+
tool: mcp.tool,
|
|
317
|
+
count: mcp.count,
|
|
318
|
+
failures: mcp.failures,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
for (const skill of item.skills) {
|
|
323
|
+
if (skill.total <= 0) continue;
|
|
324
|
+
skillMap.set(skill.skillName, (skillMap.get(skill.skillName) ?? 0) + skill.total);
|
|
325
|
+
}
|
|
326
|
+
for (const model of item.models) {
|
|
327
|
+
if (model.count <= 0) continue;
|
|
328
|
+
modelMap.set(model.model, (modelMap.get(model.model) ?? 0) + model.count);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const skills: RankItem[] = [...skillMap.entries()]
|
|
333
|
+
.map(([skillName, count]) => ({
|
|
334
|
+
key: skillName,
|
|
335
|
+
label: formatDisplayName(skillName),
|
|
336
|
+
count,
|
|
337
|
+
kind: "skills" as const,
|
|
338
|
+
}))
|
|
339
|
+
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
340
|
+
|
|
341
|
+
const mcp: RankItem[] = [...mcpMap.entries()]
|
|
342
|
+
.map(([key, item]) => ({
|
|
343
|
+
key,
|
|
344
|
+
label: formatDisplayName(`${item.server}.${item.tool}`),
|
|
345
|
+
count: item.count,
|
|
346
|
+
kind: "mcp" as const,
|
|
347
|
+
server: item.server,
|
|
348
|
+
}))
|
|
349
|
+
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
350
|
+
|
|
351
|
+
const models: RankItem[] = [...modelMap.entries()]
|
|
352
|
+
.map(([model, count]) => ({
|
|
353
|
+
key: model,
|
|
354
|
+
label: formatDisplayName(model),
|
|
355
|
+
count,
|
|
356
|
+
kind: "models" as const,
|
|
357
|
+
countLabel: "messages",
|
|
358
|
+
}))
|
|
359
|
+
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
360
|
+
|
|
361
|
+
return { skills, mcp, models };
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const selected = filteredProviders[0];
|
|
365
|
+
if (!selected) return { skills: [], mcp: [], models: [] };
|
|
366
|
+
|
|
367
|
+
const skills: RankItem[] = selected.skills
|
|
368
|
+
.filter((skill) => skill.total > 0)
|
|
369
|
+
.map((skill) => ({
|
|
370
|
+
key: skill.skillName,
|
|
371
|
+
label: formatDisplayName(skill.skillName),
|
|
372
|
+
count: skill.total,
|
|
373
|
+
kind: "skills" as const,
|
|
374
|
+
}))
|
|
375
|
+
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
376
|
+
|
|
377
|
+
const mcp: RankItem[] = selected.mcpTools
|
|
378
|
+
.map((item) => ({
|
|
379
|
+
key: `${item.server}.${item.tool}`,
|
|
380
|
+
label: formatDisplayName(`${item.server}.${item.tool}`),
|
|
381
|
+
count: item.count,
|
|
382
|
+
kind: "mcp" as const,
|
|
383
|
+
server: item.server,
|
|
384
|
+
}))
|
|
385
|
+
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
386
|
+
|
|
387
|
+
const models: RankItem[] = selected.models
|
|
388
|
+
.filter((item) => item.count > 0)
|
|
389
|
+
.map((item) => ({
|
|
390
|
+
key: item.model,
|
|
391
|
+
label: formatDisplayName(item.model),
|
|
392
|
+
count: item.count,
|
|
393
|
+
kind: "models" as const,
|
|
394
|
+
countLabel: "messages",
|
|
395
|
+
}))
|
|
396
|
+
.sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
397
|
+
|
|
398
|
+
return { skills, mcp, models };
|
|
399
|
+
}, [filteredProviders, providerFilter, providers]);
|
|
400
|
+
|
|
401
|
+
const summary = useMemo(() => {
|
|
402
|
+
let skills = 0;
|
|
403
|
+
let mcp = 0;
|
|
404
|
+
let shell = 0;
|
|
405
|
+
let fileReads = 0;
|
|
406
|
+
let fileWrites = 0;
|
|
407
|
+
let agents = 0;
|
|
408
|
+
let messages = 0;
|
|
409
|
+
for (const item of filteredProviders) {
|
|
410
|
+
skills += item.skillCalls.exact + item.skillCalls.inferred;
|
|
411
|
+
mcp += item.mcpCalls;
|
|
412
|
+
shell += item.shellCalls;
|
|
413
|
+
fileReads += item.fileReads;
|
|
414
|
+
fileWrites += item.fileWrites;
|
|
415
|
+
agents += item.agentCount;
|
|
416
|
+
messages += item.messageCount;
|
|
417
|
+
}
|
|
418
|
+
const workspaces =
|
|
419
|
+
providerFilter === "all"
|
|
420
|
+
? (query.data?.totals.workspaceCount ?? 0)
|
|
421
|
+
: (filteredProviders[0]?.workspaceCount ?? 0);
|
|
422
|
+
return { skills, mcp, shell, fileReads, fileWrites, agents, messages, workspaces };
|
|
423
|
+
}, [filteredProviders, providerFilter, query.data?.totals.workspaceCount]);
|
|
424
|
+
|
|
425
|
+
const streaks = useMemo(
|
|
426
|
+
() => computeStreaks(activityQuery.data?.days ?? []),
|
|
427
|
+
[activityQuery.data],
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const insights = useMemo(() => {
|
|
431
|
+
return buildActivityInsights({
|
|
432
|
+
days: activityQuery.data?.days ?? [],
|
|
433
|
+
summary: {
|
|
434
|
+
skills: summary.skills,
|
|
435
|
+
mcp: summary.mcp,
|
|
436
|
+
agents: summary.agents,
|
|
437
|
+
messages: summary.messages,
|
|
438
|
+
shell: summary.shell,
|
|
439
|
+
fileReads: summary.fileReads,
|
|
440
|
+
fileWrites: summary.fileWrites,
|
|
441
|
+
longestStreak: streaks.longest,
|
|
442
|
+
},
|
|
443
|
+
providers: filteredProviders,
|
|
444
|
+
providerFilter,
|
|
445
|
+
locale,
|
|
446
|
+
limit: LIST_LIMIT,
|
|
447
|
+
});
|
|
448
|
+
}, [activityQuery.data?.days, filteredProviders, locale, providerFilter, streaks.longest, summary]);
|
|
449
|
+
|
|
450
|
+
const kpi = useMemo(
|
|
451
|
+
() => [
|
|
452
|
+
{ value: formatCount(summary.messages), label: "Messages" },
|
|
453
|
+
{ value: formatCount(summary.agents), label: "Agents" },
|
|
454
|
+
{ value: formatCount(summary.workspaces), label: "Workspaces" },
|
|
455
|
+
{ value: formatCount(summary.skills), label: "Skill calls" },
|
|
456
|
+
{ value: formatCount(summary.mcp), label: "MCP calls" },
|
|
457
|
+
{
|
|
458
|
+
value: `${streaks.current} day${streaks.current === 1 ? "" : "s"}`,
|
|
459
|
+
label: "Current streak",
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
[summary, streaks],
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
const styles = useMemo(
|
|
466
|
+
() => ({
|
|
467
|
+
screen: { flex: 1, backgroundColor: theme.colors.surface0 },
|
|
468
|
+
content: {
|
|
469
|
+
padding,
|
|
470
|
+
paddingBottom: padding + 32,
|
|
471
|
+
gap: layout.compact ? 28 : 40,
|
|
472
|
+
maxWidth: 780,
|
|
473
|
+
width: "100%" as const,
|
|
474
|
+
alignSelf: "center" as const,
|
|
475
|
+
},
|
|
476
|
+
filterRow: {
|
|
477
|
+
flexDirection: "row" as const,
|
|
478
|
+
flexWrap: "wrap" as const,
|
|
479
|
+
alignItems: "center" as const,
|
|
480
|
+
justifyContent: "space-between" as const,
|
|
481
|
+
gap: layout.compact ? 12 : 16,
|
|
482
|
+
},
|
|
483
|
+
tabRow: {
|
|
484
|
+
flexDirection: "row" as const,
|
|
485
|
+
flexWrap: "wrap" as const,
|
|
486
|
+
alignItems: "center" as const,
|
|
487
|
+
gap: layout.compact ? 12 : 16,
|
|
488
|
+
},
|
|
489
|
+
tab: {
|
|
490
|
+
color: theme.colors.foregroundMuted,
|
|
491
|
+
fontSize: 14,
|
|
492
|
+
fontWeight: "500" as const,
|
|
493
|
+
},
|
|
494
|
+
tabActive: {
|
|
495
|
+
color: theme.colors.foreground,
|
|
496
|
+
fontSize: 14,
|
|
497
|
+
fontWeight: "600" as const,
|
|
498
|
+
},
|
|
499
|
+
columns: {
|
|
500
|
+
flexDirection: layout.compact ? ("column" as const) : ("row" as const),
|
|
501
|
+
alignItems: "flex-start" as const,
|
|
502
|
+
gap: layout.compact ? 24 : 28,
|
|
503
|
+
},
|
|
504
|
+
column: {
|
|
505
|
+
flex: 1,
|
|
506
|
+
minWidth: 0,
|
|
507
|
+
width: layout.compact ? ("100%" as const) : undefined,
|
|
508
|
+
},
|
|
509
|
+
block: {
|
|
510
|
+
gap: 2,
|
|
511
|
+
},
|
|
512
|
+
titleRow: {
|
|
513
|
+
flexDirection: "row" as const,
|
|
514
|
+
alignItems: "center" as const,
|
|
515
|
+
justifyContent: "space-between" as const,
|
|
516
|
+
gap: 8,
|
|
517
|
+
marginBottom: 10,
|
|
518
|
+
},
|
|
519
|
+
blockTitle: {
|
|
520
|
+
color: theme.colors.foreground,
|
|
521
|
+
fontSize: 19,
|
|
522
|
+
fontWeight: "500" as const,
|
|
523
|
+
flexShrink: 1,
|
|
524
|
+
marginBottom: 0,
|
|
525
|
+
},
|
|
526
|
+
titleAction: {
|
|
527
|
+
padding: 4,
|
|
528
|
+
borderRadius: 6,
|
|
529
|
+
},
|
|
530
|
+
insightRow: {
|
|
531
|
+
flexDirection: "row" as const,
|
|
532
|
+
alignItems: "baseline" as const,
|
|
533
|
+
justifyContent: "space-between" as const,
|
|
534
|
+
gap: 8,
|
|
535
|
+
paddingVertical: 9,
|
|
536
|
+
},
|
|
537
|
+
insightLabel: {
|
|
538
|
+
color: theme.colors.foregroundMuted,
|
|
539
|
+
fontSize: 14,
|
|
540
|
+
flexShrink: 0,
|
|
541
|
+
},
|
|
542
|
+
insightValue: {
|
|
543
|
+
color: theme.colors.foreground,
|
|
544
|
+
fontSize: 14,
|
|
545
|
+
textAlign: "right" as const,
|
|
546
|
+
flex: 1,
|
|
547
|
+
minWidth: 0,
|
|
548
|
+
},
|
|
549
|
+
rankRow: {
|
|
550
|
+
flexDirection: "row" as const,
|
|
551
|
+
alignItems: "center" as const,
|
|
552
|
+
gap: 10,
|
|
553
|
+
paddingVertical: 9,
|
|
554
|
+
},
|
|
555
|
+
rankName: {
|
|
556
|
+
color: theme.colors.foreground,
|
|
557
|
+
fontSize: 14,
|
|
558
|
+
flex: 1,
|
|
559
|
+
minWidth: 0,
|
|
560
|
+
|
|
561
|
+
},
|
|
562
|
+
rankMeta: {
|
|
563
|
+
color: theme.colors.foregroundMuted,
|
|
564
|
+
fontSize: 14,
|
|
565
|
+
fontVariant: ["tabular-nums" as const],
|
|
566
|
+
},
|
|
567
|
+
emptyState: {
|
|
568
|
+
paddingVertical: 48,
|
|
569
|
+
alignItems: "center" as const,
|
|
570
|
+
gap: 6,
|
|
571
|
+
},
|
|
572
|
+
emptyTitle: {
|
|
573
|
+
color: theme.colors.foreground,
|
|
574
|
+
fontSize: 19,
|
|
575
|
+
fontWeight: "500" as const,
|
|
576
|
+
},
|
|
577
|
+
emptyHint: {
|
|
578
|
+
color: theme.colors.foregroundMuted,
|
|
579
|
+
fontSize: 14,
|
|
580
|
+
},
|
|
581
|
+
}),
|
|
582
|
+
[theme, layout.compact, padding],
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
// Keep prior results visible while refetching; spinner only on cold start.
|
|
586
|
+
const loading =
|
|
587
|
+
(!query.data && query.isLoading) ||
|
|
588
|
+
(!activityQuery.data && activityQuery.isLoading);
|
|
589
|
+
const error = query.error ?? activityQuery.error;
|
|
590
|
+
const showContent = filteredProviders.length > 0;
|
|
591
|
+
|
|
592
|
+
return (
|
|
593
|
+
<ScrollView style={styles.screen} contentContainerStyle={styles.content}>
|
|
594
|
+
<View style={styles.filterRow}>
|
|
595
|
+
<TextTabs
|
|
596
|
+
options={[
|
|
597
|
+
{ id: "all", label: "All time" },
|
|
598
|
+
{ id: "today", label: "Today" },
|
|
599
|
+
{ id: "7d", label: "7 days" },
|
|
600
|
+
{ id: "30d", label: "30 days" },
|
|
601
|
+
]}
|
|
602
|
+
value={range}
|
|
603
|
+
onChange={(id) => setRange(id as RangeId)}
|
|
604
|
+
styles={styles}
|
|
605
|
+
/>
|
|
606
|
+
{providerOptions.length > 1 ? (
|
|
607
|
+
<TextTabs
|
|
608
|
+
options={providerOptions}
|
|
609
|
+
value={providerFilter}
|
|
610
|
+
onChange={setProviderFilter}
|
|
611
|
+
styles={styles}
|
|
612
|
+
/>
|
|
613
|
+
) : null}
|
|
614
|
+
</View>
|
|
615
|
+
|
|
616
|
+
{loading ? <ActivityIndicator color={theme.colors.accent} /> : null}
|
|
617
|
+
{error ? (
|
|
618
|
+
<Text style={{ color: theme.colors.statusDanger }}>
|
|
619
|
+
{error instanceof Error ? error.message : String(error)}
|
|
620
|
+
</Text>
|
|
621
|
+
) : null}
|
|
622
|
+
|
|
623
|
+
{filteredProviders.length === 0 && !loading && !error ? (
|
|
624
|
+
<View style={styles.emptyState}>
|
|
625
|
+
<Text style={styles.emptyTitle}>No usage yet</Text>
|
|
626
|
+
<Text style={styles.emptyHint}>Agents, messages, skill and MCP calls will show up here</Text>
|
|
627
|
+
</View>
|
|
628
|
+
) : null}
|
|
629
|
+
|
|
630
|
+
{showContent ? (
|
|
631
|
+
<UsageStats items={kpi} colors={theme.colors} compact={layout.compact} />
|
|
632
|
+
) : null}
|
|
633
|
+
|
|
634
|
+
{showContent ? (
|
|
635
|
+
<ActivityHeatmap
|
|
636
|
+
days={activityQuery.data?.days ?? []}
|
|
637
|
+
from={from}
|
|
638
|
+
colors={theme.colors}
|
|
639
|
+
compact={layout.compact}
|
|
640
|
+
mode={heatmapMode}
|
|
641
|
+
onModeChange={setHeatmapMode}
|
|
642
|
+
modeOptions={[
|
|
643
|
+
{ id: "daily", label: "Daily" },
|
|
644
|
+
{ id: "weekly", label: "Weekly" },
|
|
645
|
+
{ id: "cumulative", label: "Cumulative" },
|
|
646
|
+
]}
|
|
647
|
+
/>
|
|
648
|
+
) : null}
|
|
649
|
+
|
|
650
|
+
{showContent ? (
|
|
651
|
+
<View style={styles.columns}>
|
|
652
|
+
<View style={styles.column}>
|
|
653
|
+
<View style={styles.block}>
|
|
654
|
+
<Text style={[styles.blockTitle, { marginBottom: 10 }]}>Activity insights</Text>
|
|
655
|
+
{insights.map((row) => (
|
|
656
|
+
<View key={row.label} style={styles.insightRow}>
|
|
657
|
+
<Text style={styles.insightLabel}>{row.label}</Text>
|
|
658
|
+
<Text style={styles.insightValue} numberOfLines={1}>
|
|
659
|
+
{row.value}
|
|
660
|
+
</Text>
|
|
661
|
+
</View>
|
|
662
|
+
))}
|
|
663
|
+
</View>
|
|
664
|
+
</View>
|
|
665
|
+
|
|
666
|
+
<View style={styles.column}>
|
|
667
|
+
<RankList
|
|
668
|
+
title={rankTitle(rankKind)}
|
|
669
|
+
items={(
|
|
670
|
+
rankKind === "skills"
|
|
671
|
+
? lists.skills
|
|
672
|
+
: rankKind === "mcp"
|
|
673
|
+
? lists.mcp
|
|
674
|
+
: lists.models
|
|
675
|
+
).slice(0, LIST_LIMIT)}
|
|
676
|
+
empty={rankEmpty(rankKind)}
|
|
677
|
+
styles={styles}
|
|
678
|
+
colors={theme.colors}
|
|
679
|
+
headerAction={{
|
|
680
|
+
...rankHeaderAction(rankKind),
|
|
681
|
+
onPress: () => setRankKind((prev) => nextRankKind(prev)),
|
|
682
|
+
}}
|
|
683
|
+
/>
|
|
684
|
+
</View>
|
|
685
|
+
</View>
|
|
686
|
+
) : null}
|
|
687
|
+
</ScrollView>
|
|
688
|
+
);
|
|
689
|
+
}
|