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