@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
package/client/panel.tsx
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { type PluginAgentPanelProps, useAgent, useRpc } from "@getpaseo/plugin/client";
|
|
2
2
|
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
3
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
-
import { useEffect, useMemo, useState
|
|
4
|
+
import { useEffect, useMemo, useState } from "react";
|
|
5
5
|
import { useRegisterOpenAgent } from "./open-agent.ts";
|
|
6
|
-
import {
|
|
7
|
-
ActivityIndicator,
|
|
8
|
-
Platform,
|
|
9
|
-
Pressable,
|
|
10
|
-
ScrollView,
|
|
11
|
-
Text,
|
|
12
|
-
View,
|
|
13
|
-
type TextStyle,
|
|
14
|
-
} from "react-native";
|
|
6
|
+
import { Pressable, ScrollView, Text, View } from "react-native";
|
|
15
7
|
import {
|
|
16
8
|
usageMcpByToolRpc,
|
|
17
9
|
usageReadSkillRpc,
|
|
@@ -28,6 +20,25 @@ import {
|
|
|
28
20
|
import { useAgentTurnEnd } from "./use-agent-turn-end.ts";
|
|
29
21
|
|
|
30
22
|
import { UsageStats } from "./usage-stats.tsx";
|
|
23
|
+
import { useAppLanguage, useMessages } from "./use-app-language.ts";
|
|
24
|
+
import {
|
|
25
|
+
CountText,
|
|
26
|
+
ErrorState,
|
|
27
|
+
IconButton,
|
|
28
|
+
InlineEmpty,
|
|
29
|
+
LoadingState,
|
|
30
|
+
Section,
|
|
31
|
+
SectionHeader,
|
|
32
|
+
} from "./ui.tsx";
|
|
33
|
+
import {
|
|
34
|
+
ICON_SIZE,
|
|
35
|
+
RADIUS,
|
|
36
|
+
ROW_PADDING,
|
|
37
|
+
TEXT,
|
|
38
|
+
iconButton,
|
|
39
|
+
pageLayout,
|
|
40
|
+
sectionTitle,
|
|
41
|
+
} from "./design-tokens.ts";
|
|
31
42
|
|
|
32
43
|
type TabId = "skills" | "mcp";
|
|
33
44
|
|
|
@@ -36,22 +47,13 @@ type SkillDetail = {
|
|
|
36
47
|
path: string;
|
|
37
48
|
};
|
|
38
49
|
|
|
39
|
-
const MONO = Platform.select({ ios: "Menlo", default: "monospace" });
|
|
40
|
-
|
|
41
|
-
function CountText({
|
|
42
|
-
value,
|
|
43
|
-
styles,
|
|
44
|
-
}: {
|
|
45
|
-
value: number | string;
|
|
46
|
-
styles: { countText: TextStyle };
|
|
47
|
-
}): ReactNode {
|
|
48
|
-
return <Text style={styles.countText}>{value}</Text>;
|
|
49
|
-
}
|
|
50
50
|
|
|
51
51
|
export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPanelProps) {
|
|
52
|
+
const locale = useAppLanguage();
|
|
53
|
+
const m = useMessages();
|
|
52
54
|
const [tab, setTab] = useState<TabId | null>(null);
|
|
53
55
|
const [skillDetail, setSkillDetail] = useState<SkillDetail | null>(null);
|
|
54
|
-
const
|
|
56
|
+
const page = pageLayout("panel", layout.compact);
|
|
55
57
|
const agentTitle = useAgent(agentId, (agent) => agent.title);
|
|
56
58
|
const openAgent = navigation?.openAgent;
|
|
57
59
|
useRegisterOpenAgent(openAgent);
|
|
@@ -135,10 +137,10 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
135
137
|
|
|
136
138
|
const tabs = useMemo(() => {
|
|
137
139
|
const next: Array<{ id: TabId; label: string }> = [];
|
|
138
|
-
if (skillItems.length > 0) next.push({ id: "skills", label:
|
|
139
|
-
if (mcpItems.length > 0) next.push({ id: "mcp", label:
|
|
140
|
+
if (skillItems.length > 0) next.push({ id: "skills", label: m.common.skills });
|
|
141
|
+
if (mcpItems.length > 0) next.push({ id: "mcp", label: m.common.mcp });
|
|
140
142
|
return next;
|
|
141
|
-
}, [skillItems.length, mcpItems.length]);
|
|
143
|
+
}, [skillItems.length, mcpItems.length, m]);
|
|
142
144
|
|
|
143
145
|
useEffect(() => {
|
|
144
146
|
if (tabs.length === 0) {
|
|
@@ -154,26 +156,17 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
154
156
|
() => ({
|
|
155
157
|
screen: { flex: 1, backgroundColor: theme.colors.surface0 },
|
|
156
158
|
content: {
|
|
157
|
-
padding,
|
|
158
|
-
paddingBottom: padding + 24,
|
|
159
|
-
gap:
|
|
159
|
+
padding: page.padding,
|
|
160
|
+
paddingBottom: page.padding + 24,
|
|
161
|
+
gap: page.gap,
|
|
160
162
|
maxWidth: 1000,
|
|
161
163
|
width: "100%" as const,
|
|
162
164
|
alignSelf: "center" as const,
|
|
163
165
|
},
|
|
164
166
|
sectionTitle: {
|
|
167
|
+
...sectionTitle(layout.compact),
|
|
165
168
|
color: theme.colors.foreground,
|
|
166
|
-
fontSize: 14,
|
|
167
|
-
fontWeight: "600" as const,
|
|
168
|
-
flexShrink: 1,
|
|
169
|
-
letterSpacing: -0.3,
|
|
170
|
-
},
|
|
171
|
-
listSectionTitle: {
|
|
172
|
-
color: theme.colors.foreground,
|
|
173
|
-
fontSize: 15,
|
|
174
|
-
fontWeight: "600" as const,
|
|
175
169
|
flexShrink: 1,
|
|
176
|
-
letterSpacing: -0.3,
|
|
177
170
|
},
|
|
178
171
|
sectionHeaderRow: {
|
|
179
172
|
flexDirection: "row" as const,
|
|
@@ -181,14 +174,7 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
181
174
|
justifyContent: "space-between" as const,
|
|
182
175
|
gap: 8,
|
|
183
176
|
},
|
|
184
|
-
titleAction:
|
|
185
|
-
width: 24,
|
|
186
|
-
height: 24,
|
|
187
|
-
alignItems: "center" as const,
|
|
188
|
-
justifyContent: "center" as const,
|
|
189
|
-
borderRadius: 6,
|
|
190
|
-
flexShrink: 0,
|
|
191
|
-
},
|
|
177
|
+
titleAction: iconButton,
|
|
192
178
|
panel: {
|
|
193
179
|
gap: 4,
|
|
194
180
|
overflow: "hidden" as const,
|
|
@@ -198,7 +184,7 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
198
184
|
alignItems: "center" as const,
|
|
199
185
|
gap: 12,
|
|
200
186
|
paddingHorizontal: 0,
|
|
201
|
-
paddingVertical:
|
|
187
|
+
paddingVertical: ROW_PADDING.regular,
|
|
202
188
|
borderTopWidth: 0,
|
|
203
189
|
borderTopColor: theme.colors.border,
|
|
204
190
|
},
|
|
@@ -211,33 +197,30 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
211
197
|
gap: 3,
|
|
212
198
|
},
|
|
213
199
|
listTitle: {
|
|
200
|
+
...TEXT.rowTitle,
|
|
214
201
|
color: theme.colors.foreground,
|
|
215
|
-
fontSize: 14,
|
|
216
|
-
fontWeight: "500" as const,
|
|
217
202
|
},
|
|
218
203
|
listLink: {
|
|
204
|
+
...TEXT.rowTitle,
|
|
219
205
|
color: theme.colors.foreground,
|
|
220
|
-
fontSize: 14,
|
|
221
|
-
fontWeight: "500" as const,
|
|
222
206
|
},
|
|
223
207
|
listMeta: {
|
|
208
|
+
...TEXT.meta,
|
|
224
209
|
color: theme.colors.foregroundMuted,
|
|
225
|
-
fontSize: 12,
|
|
226
210
|
},
|
|
227
211
|
conversationLink: {
|
|
212
|
+
...TEXT.meta,
|
|
228
213
|
color: theme.colors.accent,
|
|
229
|
-
fontSize: 12,
|
|
230
214
|
},
|
|
231
215
|
countText: {
|
|
216
|
+
...TEXT.count,
|
|
232
217
|
color: theme.colors.foregroundMuted,
|
|
233
|
-
fontSize: 13,
|
|
234
|
-
fontVariant: ["tabular-nums" as const],
|
|
235
218
|
minWidth: 24,
|
|
236
219
|
textAlign: "right" as const,
|
|
237
220
|
},
|
|
238
221
|
empty: {
|
|
222
|
+
...TEXT.small,
|
|
239
223
|
color: theme.colors.foregroundMuted,
|
|
240
|
-
fontSize: 13,
|
|
241
224
|
},
|
|
242
225
|
backRow: {
|
|
243
226
|
flexDirection: "row" as const,
|
|
@@ -246,21 +229,18 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
246
229
|
alignSelf: "flex-start" as const,
|
|
247
230
|
},
|
|
248
231
|
back: {
|
|
232
|
+
...TEXT.back,
|
|
249
233
|
color: theme.colors.foregroundMuted,
|
|
250
|
-
fontSize: 13,
|
|
251
|
-
fontWeight: "500" as const,
|
|
252
234
|
},
|
|
253
235
|
body: {
|
|
236
|
+
...TEXT.code,
|
|
254
237
|
color: theme.colors.foreground,
|
|
255
|
-
fontSize: 13,
|
|
256
|
-
fontFamily: MONO,
|
|
257
|
-
lineHeight: 22,
|
|
258
238
|
backgroundColor: theme.colors.surface1,
|
|
259
239
|
padding: 16,
|
|
260
|
-
borderRadius:
|
|
240
|
+
borderRadius: RADIUS.block,
|
|
261
241
|
},
|
|
262
242
|
}),
|
|
263
|
-
[theme, layout.compact, padding],
|
|
243
|
+
[theme, layout.compact, page.padding, page.gap],
|
|
264
244
|
);
|
|
265
245
|
|
|
266
246
|
const loading = skillsByName.isLoading || mcpByTool.isLoading;
|
|
@@ -268,8 +248,8 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
268
248
|
const showToggle = tabs.length > 1;
|
|
269
249
|
const toggleAction =
|
|
270
250
|
tab === "skills"
|
|
271
|
-
? { icon: "Plug" as const, accessibilityLabel:
|
|
272
|
-
: { icon: "Sparkles" as const, accessibilityLabel:
|
|
251
|
+
? { icon: "Plug" as const, accessibilityLabel: m.common.showMcp, next: "mcp" as const }
|
|
252
|
+
: { icon: "Sparkles" as const, accessibilityLabel: m.common.showSkills, next: "skills" as const };
|
|
273
253
|
|
|
274
254
|
if (skillDetail) {
|
|
275
255
|
return (
|
|
@@ -282,15 +262,13 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
282
262
|
}}
|
|
283
263
|
style={styles.backRow}
|
|
284
264
|
>
|
|
285
|
-
<Icon name="ChevronLeft" size={
|
|
286
|
-
<Text style={styles.back}>
|
|
265
|
+
<Icon name="ChevronLeft" size={ICON_SIZE.action} color={theme.colors.foregroundMuted} />
|
|
266
|
+
<Text style={styles.back}>{m.common.skills}</Text>
|
|
287
267
|
</Pressable>
|
|
288
268
|
<Text style={styles.sectionTitle}>{formatDisplayName(skillDetail.skillName)}</Text>
|
|
289
|
-
{skillFile.isLoading ? <
|
|
269
|
+
{skillFile.isLoading ? <LoadingState color={theme.colors.accent} /> : null}
|
|
290
270
|
{skillFile.error ? (
|
|
291
|
-
<
|
|
292
|
-
{skillFile.error instanceof Error ? skillFile.error.message : String(skillFile.error)}
|
|
293
|
-
</Text>
|
|
271
|
+
<ErrorState error={skillFile.error} onRetry={() => void skillFile.refetch()} colors={theme.colors} />
|
|
294
272
|
) : null}
|
|
295
273
|
{skillFile.data ? (
|
|
296
274
|
<Text style={styles.body} selectable>
|
|
@@ -307,7 +285,7 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
307
285
|
{openAgent ? (
|
|
308
286
|
<Text
|
|
309
287
|
accessibilityRole="link"
|
|
310
|
-
accessibilityLabel={
|
|
288
|
+
accessibilityLabel={m.common.openConversation(conversationLabel)}
|
|
311
289
|
style={styles.conversationLink}
|
|
312
290
|
onPress={() => openAgent({ agentId })}
|
|
313
291
|
>
|
|
@@ -318,46 +296,43 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
318
296
|
)}
|
|
319
297
|
</View>
|
|
320
298
|
{!loading && !error ? <UsageStats compact={layout.compact} dense colors={theme.colors} items={[
|
|
321
|
-
{ label:
|
|
322
|
-
{ label:
|
|
323
|
-
{ label:
|
|
324
|
-
{ label:
|
|
325
|
-
{ label:
|
|
326
|
-
{ label:
|
|
327
|
-
{ label:
|
|
299
|
+
{ label: m.kpi.skillCalls, value: skillItems.reduce((sum, item) => sum + item.total, 0).toLocaleString(locale) },
|
|
300
|
+
{ label: m.kpi.mcpCalls, value: mcpItems.reduce((sum, item) => sum + item.count, 0).toLocaleString(locale) },
|
|
301
|
+
{ label: m.kpi.shellCalls, value: (usageSummary.data?.shellCalls ?? 0).toLocaleString(locale) },
|
|
302
|
+
{ label: m.kpi.fileReads, value: (usageSummary.data?.fileReads ?? 0).toLocaleString(locale) },
|
|
303
|
+
{ label: m.kpi.fileWrites, value: (usageSummary.data?.fileWrites ?? 0).toLocaleString(locale) },
|
|
304
|
+
{ label: m.kpi.prompts, value: (usageSummary.data?.messageCount ?? 0).toLocaleString(locale) },
|
|
305
|
+
{ label: m.kpi.toolsExplored, value: String(skillItems.length + mcpItems.length) },
|
|
328
306
|
]} /> : null}
|
|
329
307
|
|
|
330
|
-
{loading ? <
|
|
308
|
+
{loading ? <LoadingState color={theme.colors.accent} /> : null}
|
|
331
309
|
{error ? (
|
|
332
|
-
<
|
|
333
|
-
{error
|
|
334
|
-
|
|
310
|
+
<ErrorState
|
|
311
|
+
error={error}
|
|
312
|
+
onRetry={() => {
|
|
313
|
+
void skillsByName.refetch();
|
|
314
|
+
void mcpByTool.refetch();
|
|
315
|
+
}}
|
|
316
|
+
colors={theme.colors}
|
|
317
|
+
/>
|
|
335
318
|
) : null}
|
|
336
319
|
|
|
337
320
|
{!loading && !error && tabs.length === 0 ? (
|
|
338
|
-
<
|
|
321
|
+
<InlineEmpty text={m.common.noSkillOrMcp} color={theme.colors.foregroundMuted} />
|
|
339
322
|
) : null}
|
|
340
323
|
|
|
341
324
|
{tab ? (
|
|
342
|
-
<
|
|
343
|
-
<
|
|
344
|
-
<Text style={styles.listSectionTitle}>{tab === "skills" ? "Skills" : "MCP"}</Text>
|
|
325
|
+
<Section compact={layout.compact}>
|
|
326
|
+
<SectionHeader title={tab === "skills" ? m.common.skills : m.common.mcp} colors={theme.colors} compact={layout.compact}>
|
|
345
327
|
{showToggle ? (
|
|
346
|
-
<
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
hitSlop={8}
|
|
328
|
+
<IconButton
|
|
329
|
+
icon={toggleAction.icon}
|
|
330
|
+
label={toggleAction.accessibilityLabel}
|
|
350
331
|
onPress={() => setTab(toggleAction.next)}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
<Icon
|
|
354
|
-
name={toggleAction.icon}
|
|
355
|
-
size={16}
|
|
356
|
-
color={theme.colors.foregroundMuted}
|
|
357
|
-
/>
|
|
358
|
-
</Pressable>
|
|
332
|
+
color={theme.colors.foregroundMuted}
|
|
333
|
+
/>
|
|
359
334
|
) : null}
|
|
360
|
-
</
|
|
335
|
+
</SectionHeader>
|
|
361
336
|
{tab === "skills" ? (
|
|
362
337
|
<View style={styles.panel}>
|
|
363
338
|
{skillItems.map((item, index) => {
|
|
@@ -384,16 +359,16 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
384
359
|
key={item.skillName}
|
|
385
360
|
style={[styles.listRow, index === 0 ? styles.listRowFirst : null]}
|
|
386
361
|
>
|
|
387
|
-
<Icon name="Sparkles" size={
|
|
362
|
+
<Icon name="Sparkles" size={ICON_SIZE.leading} color={theme.colors.foregroundMuted} />
|
|
388
363
|
<View style={styles.listMain}>
|
|
389
364
|
{title}
|
|
390
365
|
<FormattedTime
|
|
391
366
|
iso={item.lastUsedAt}
|
|
392
|
-
|
|
367
|
+
format={m.common.lastUsed}
|
|
393
368
|
style={styles.listMeta}
|
|
394
369
|
/>
|
|
395
370
|
</View>
|
|
396
|
-
<CountText value={item.total}
|
|
371
|
+
<CountText value={item.total} color={theme.colors.foregroundMuted} />
|
|
397
372
|
</View>
|
|
398
373
|
);
|
|
399
374
|
})}
|
|
@@ -405,29 +380,29 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
405
380
|
key={`${item.server}.${item.tool}`}
|
|
406
381
|
style={[styles.listRow, index === 0 ? styles.listRowFirst : null]}
|
|
407
382
|
>
|
|
408
|
-
<Icon name="Plug" size={
|
|
383
|
+
<Icon name="Plug" size={ICON_SIZE.leading} color={theme.colors.foregroundMuted} />
|
|
409
384
|
<View style={styles.listMain}>
|
|
410
385
|
<Text style={styles.listTitle} numberOfLines={1}>
|
|
411
386
|
{formatDisplayName(`${item.server}.${item.tool}`)}
|
|
412
387
|
</Text>
|
|
413
388
|
{item.failures > 0 ? (
|
|
414
|
-
<Text style={styles.listMeta}>{item.failures}
|
|
389
|
+
<Text style={styles.listMeta}>{m.common.failed(item.failures)}</Text>
|
|
415
390
|
) : item.lastUsedAt ? (
|
|
416
391
|
<FormattedTime
|
|
417
392
|
iso={item.lastUsedAt}
|
|
418
|
-
|
|
393
|
+
format={m.common.lastUsed}
|
|
419
394
|
style={styles.listMeta}
|
|
420
395
|
/>
|
|
421
396
|
) : (
|
|
422
397
|
<Text style={styles.listMeta}>—</Text>
|
|
423
398
|
)}
|
|
424
399
|
</View>
|
|
425
|
-
<CountText value={item.count}
|
|
400
|
+
<CountText value={item.count} color={theme.colors.foregroundMuted} />
|
|
426
401
|
</View>
|
|
427
402
|
))}
|
|
428
403
|
</View>
|
|
429
404
|
)}
|
|
430
|
-
</
|
|
405
|
+
</Section>
|
|
431
406
|
) : null}
|
|
432
407
|
</ScrollView>
|
|
433
408
|
);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import { Platform, Pressable, ScrollView, Text, View } from "react-native";
|
|
4
|
+
import { CONTROL, FONT_WEIGHT, ICON_SIZE, RADIUS, TEXT } from "./design-tokens.ts";
|
|
5
|
+
|
|
6
|
+
const MENU_MIN_WIDTH = 200;
|
|
7
|
+
const MENU_ROW_HEIGHT = 28;
|
|
8
|
+
/** Rows visible before the menu scrolls. */
|
|
9
|
+
const MENU_VISIBLE_ROWS = 10;
|
|
10
|
+
|
|
11
|
+
type Colors = {
|
|
12
|
+
border: string;
|
|
13
|
+
foreground: string;
|
|
14
|
+
foregroundMuted: string;
|
|
15
|
+
surface1: string;
|
|
16
|
+
surface2: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* `Provider: All ▾` filter (069). Lists every option; the menu floats under the
|
|
21
|
+
* right-aligned trigger (077) and a transparent backdrop closes it on outside
|
|
22
|
+
* press.
|
|
23
|
+
*/
|
|
24
|
+
export function ProviderDropdown({
|
|
25
|
+
label,
|
|
26
|
+
options,
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
colors,
|
|
30
|
+
triggerLabel,
|
|
31
|
+
closeLabel,
|
|
32
|
+
}: {
|
|
33
|
+
label: string;
|
|
34
|
+
options: ReadonlyArray<{ id: string; label: string }>;
|
|
35
|
+
value: string;
|
|
36
|
+
onChange: (id: string) => void;
|
|
37
|
+
colors: Colors;
|
|
38
|
+
triggerLabel: string;
|
|
39
|
+
closeLabel: string;
|
|
40
|
+
}): ReactNode {
|
|
41
|
+
const [open, setOpen] = useState(false);
|
|
42
|
+
const current = options.find((option) => option.id === value) ?? options[0];
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<View style={{ position: "relative", zIndex: 20, alignSelf: "flex-start" }}>
|
|
46
|
+
<Pressable
|
|
47
|
+
accessibilityRole="button"
|
|
48
|
+
accessibilityLabel={triggerLabel}
|
|
49
|
+
accessibilityState={{ expanded: open }}
|
|
50
|
+
hitSlop={CONTROL.hitSlop}
|
|
51
|
+
onPress={() => setOpen((prev) => !prev)}
|
|
52
|
+
style={{ flexDirection: "row", alignItems: "center", gap: 4, paddingVertical: 6 }}
|
|
53
|
+
>
|
|
54
|
+
<Text style={{ ...TEXT.body, color: colors.foregroundMuted }}>{label}:</Text>
|
|
55
|
+
<Text style={{ ...TEXT.body, fontWeight: FONT_WEIGHT.semibold, color: colors.foreground }} numberOfLines={1}>
|
|
56
|
+
{current?.label ?? ""}
|
|
57
|
+
</Text>
|
|
58
|
+
<Icon name="ChevronDown" size={ICON_SIZE.inline} color={colors.foregroundMuted} />
|
|
59
|
+
</Pressable>
|
|
60
|
+
|
|
61
|
+
{open ? (
|
|
62
|
+
<>
|
|
63
|
+
<Pressable
|
|
64
|
+
accessibilityRole="button"
|
|
65
|
+
accessibilityLabel={closeLabel}
|
|
66
|
+
onPress={() => setOpen(false)}
|
|
67
|
+
style={{
|
|
68
|
+
position: (Platform.OS === "web" ? "fixed" : "absolute") as "absolute",
|
|
69
|
+
top: 0,
|
|
70
|
+
left: 0,
|
|
71
|
+
right: 0,
|
|
72
|
+
bottom: 0,
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
<View
|
|
76
|
+
style={{
|
|
77
|
+
position: "absolute",
|
|
78
|
+
top: "100%",
|
|
79
|
+
right: 0,
|
|
80
|
+
marginTop: 4,
|
|
81
|
+
minWidth: MENU_MIN_WIDTH,
|
|
82
|
+
borderRadius: RADIUS.overlay,
|
|
83
|
+
borderWidth: 1,
|
|
84
|
+
borderColor: colors.border,
|
|
85
|
+
backgroundColor: colors.surface1,
|
|
86
|
+
shadowColor: "rgba(0, 0, 0, 0.04)",
|
|
87
|
+
shadowOffset: { width: 0, height: 4 },
|
|
88
|
+
shadowRadius: 16,
|
|
89
|
+
elevation: 4,
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
<ScrollView
|
|
93
|
+
style={{ maxHeight: MENU_VISIBLE_ROWS * MENU_ROW_HEIGHT + 8 }}
|
|
94
|
+
contentContainerStyle={{ paddingVertical: 4 }}
|
|
95
|
+
>
|
|
96
|
+
{options.map((option) => {
|
|
97
|
+
const selected = option.id === value;
|
|
98
|
+
return (
|
|
99
|
+
<Pressable
|
|
100
|
+
key={option.id}
|
|
101
|
+
accessibilityRole="button"
|
|
102
|
+
accessibilityState={{ selected }}
|
|
103
|
+
onPress={() => {
|
|
104
|
+
onChange(option.id);
|
|
105
|
+
setOpen(false);
|
|
106
|
+
}}
|
|
107
|
+
style={({ pressed, hovered }: { pressed: boolean; hovered?: boolean }) => ({
|
|
108
|
+
flexDirection: "row",
|
|
109
|
+
alignItems: "center",
|
|
110
|
+
minHeight: MENU_ROW_HEIGHT,
|
|
111
|
+
gap: 8,
|
|
112
|
+
marginHorizontal: 4,
|
|
113
|
+
paddingHorizontal: 8,
|
|
114
|
+
borderRadius: RADIUS.control,
|
|
115
|
+
backgroundColor: pressed || hovered ? colors.surface2 : "transparent",
|
|
116
|
+
})}
|
|
117
|
+
>
|
|
118
|
+
<Text style={{ ...TEXT.menu, color: colors.foreground, flex: 1, minWidth: 0 }} numberOfLines={1}>
|
|
119
|
+
{option.label}
|
|
120
|
+
</Text>
|
|
121
|
+
{selected ? <Icon name="Check" size={ICON_SIZE.action} color={colors.foreground} /> : null}
|
|
122
|
+
</Pressable>
|
|
123
|
+
);
|
|
124
|
+
})}
|
|
125
|
+
</ScrollView>
|
|
126
|
+
</View>
|
|
127
|
+
</>
|
|
128
|
+
) : null}
|
|
129
|
+
</View>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type ProviderFilterCandidate,
|
|
7
|
-
} from "./provider-filter.ts";
|
|
3
|
+
import { selectProviderOptions, type ProviderFilterCandidate } from "./provider-filter.ts";
|
|
4
|
+
|
|
5
|
+
const LIMIT = 5;
|
|
8
6
|
|
|
9
7
|
function candidate(
|
|
10
8
|
provider: string,
|
|
@@ -14,8 +12,14 @@ function candidate(
|
|
|
14
12
|
return { provider, label: provider.toUpperCase(), agentCount, messageCount };
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
test("
|
|
18
|
-
|
|
15
|
+
test("lists every provider by default (069)", () => {
|
|
16
|
+
const providers = ["a", "b", "c", "d", "e", "f", "g"].map((id, index) =>
|
|
17
|
+
candidate(id, 7 - index, 0),
|
|
18
|
+
);
|
|
19
|
+
assert.deepEqual(
|
|
20
|
+
selectProviderOptions(providers, "all").map((item) => item.id),
|
|
21
|
+
["a", "b", "c", "d", "e", "f", "g"],
|
|
22
|
+
);
|
|
19
23
|
});
|
|
20
24
|
|
|
21
25
|
test("ranks by agent count, then message count", () => {
|
|
@@ -40,12 +44,12 @@ test("breaks ties by provider id", () => {
|
|
|
40
44
|
);
|
|
41
45
|
});
|
|
42
46
|
|
|
43
|
-
test("caps the list at
|
|
47
|
+
test("caps the list at an explicit limit", () => {
|
|
44
48
|
const providers = ["a", "b", "c", "d", "e", "f", "g"].map((id, index) =>
|
|
45
49
|
candidate(id, 7 - index, 0),
|
|
46
50
|
);
|
|
47
|
-
const options = selectProviderOptions(providers, "all");
|
|
48
|
-
assert.equal(options.length,
|
|
51
|
+
const options = selectProviderOptions(providers, "all", LIMIT);
|
|
52
|
+
assert.equal(options.length, LIMIT);
|
|
49
53
|
assert.deepEqual(
|
|
50
54
|
options.map((item) => item.id),
|
|
51
55
|
["a", "b", "c", "d", "e"],
|
|
@@ -56,8 +60,8 @@ test("keeps a selected provider that fell out of the top list", () => {
|
|
|
56
60
|
const providers = ["a", "b", "c", "d", "e", "f"].map((id, index) =>
|
|
57
61
|
candidate(id, 6 - index, 0),
|
|
58
62
|
);
|
|
59
|
-
const options = selectProviderOptions(providers, "f");
|
|
60
|
-
assert.equal(options.length,
|
|
63
|
+
const options = selectProviderOptions(providers, "f", LIMIT);
|
|
64
|
+
assert.equal(options.length, LIMIT);
|
|
61
65
|
assert.deepEqual(
|
|
62
66
|
options.map((item) => item.id),
|
|
63
67
|
["a", "b", "c", "d", "f"],
|
|
@@ -68,7 +72,7 @@ test("keeps order when the selected provider is already in the top list", () =>
|
|
|
68
72
|
const providers = ["a", "b", "c", "d", "e", "f"].map((id, index) =>
|
|
69
73
|
candidate(id, 6 - index, 0),
|
|
70
74
|
);
|
|
71
|
-
const options = selectProviderOptions(providers, "b");
|
|
75
|
+
const options = selectProviderOptions(providers, "b", LIMIT);
|
|
72
76
|
assert.deepEqual(
|
|
73
77
|
options.map((item) => item.id),
|
|
74
78
|
["a", "b", "c", "d", "e"],
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/** Max provider chips shown in the global Activity filter bar (excludes All). */
|
|
2
|
-
export const PROVIDER_FILTER_LIMIT = 5;
|
|
3
|
-
|
|
4
1
|
export type ProviderFilterCandidate = {
|
|
5
2
|
provider: string;
|
|
6
3
|
label: string;
|
|
@@ -9,14 +6,15 @@ export type ProviderFilterCandidate = {
|
|
|
9
6
|
};
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
|
-
* Rank provider
|
|
13
|
-
* messages, then provider id.
|
|
14
|
-
* fell out of the top `limit` replaces the
|
|
9
|
+
* Rank provider options for the global filter dropdown: most sessions first,
|
|
10
|
+
* then most messages, then provider id. Uncapped by default (069); with a
|
|
11
|
+
* `limit`, a selected provider that fell out of the top `limit` replaces the
|
|
12
|
+
* last entry so the filter stays visible.
|
|
15
13
|
*/
|
|
16
14
|
export function selectProviderOptions(
|
|
17
15
|
providers: ReadonlyArray<ProviderFilterCandidate>,
|
|
18
16
|
selected: string,
|
|
19
|
-
limit =
|
|
17
|
+
limit = Number.POSITIVE_INFINITY,
|
|
20
18
|
): Array<{ id: string; label: string }> {
|
|
21
19
|
const capped = Math.max(0, limit);
|
|
22
20
|
const ranked = [...providers].sort(
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { fixedWindowFrom, rangeFrom } from "./range.ts";
|
|
4
|
+
|
|
5
|
+
describe("fixedWindowFrom", () => {
|
|
6
|
+
it("starts at local midnight so 30 days yield 30 buckets including today", () => {
|
|
7
|
+
const now = new Date(2026, 2, 10, 23, 30);
|
|
8
|
+
const start = new Date(fixedWindowFrom(30, now));
|
|
9
|
+
assert.equal(start.getFullYear(), 2026);
|
|
10
|
+
assert.equal(start.getMonth(), 1);
|
|
11
|
+
assert.equal(start.getDate(), 9); // Mar 10 minus 29 days
|
|
12
|
+
assert.equal(start.getHours(), 0);
|
|
13
|
+
assert.equal(start.getMinutes(), 0);
|
|
14
|
+
assert.equal(start.getSeconds(), 0);
|
|
15
|
+
assert.equal(start.getMilliseconds(), 0);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("keeps a single day for one-day and degenerate windows", () => {
|
|
19
|
+
const now = new Date(2026, 2, 10, 8, 0);
|
|
20
|
+
for (const days of [1, 0, -5]) {
|
|
21
|
+
const start = new Date(fixedWindowFrom(days, now));
|
|
22
|
+
assert.equal(start.getDate(), 10);
|
|
23
|
+
assert.equal(start.getHours(), 0);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("crosses month, year and DST boundaries without drifting", () => {
|
|
28
|
+
assert.equal(new Date(fixedWindowFrom(30, new Date(2026, 0, 5, 12))).getDate(), 7); // Dec 7
|
|
29
|
+
assert.equal(new Date(fixedWindowFrom(30, new Date(2026, 0, 5, 12))).getMonth(), 11);
|
|
30
|
+
const dst = new Date(fixedWindowFrom(30, new Date(2026, 2, 30, 12)));
|
|
31
|
+
assert.equal(dst.getDate(), 1); // Mar 1
|
|
32
|
+
assert.equal(dst.getHours(), 0);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("rangeFrom", () => {
|
|
37
|
+
it("returns no lower bound for all time and local midnight for today", () => {
|
|
38
|
+
assert.equal(rangeFrom("all"), undefined);
|
|
39
|
+
const today = new Date(rangeFrom("today")!);
|
|
40
|
+
const now = new Date();
|
|
41
|
+
assert.equal(today.getDate(), now.getDate());
|
|
42
|
+
assert.equal(today.getHours(), 0);
|
|
43
|
+
});
|
|
44
|
+
});
|
package/client/range.ts
CHANGED
|
@@ -18,3 +18,17 @@ export function rangeFrom(id: RangeId): string | undefined {
|
|
|
18
18
|
const days = id === "7d" ? 7 : 30;
|
|
19
19
|
return new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString();
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Local-midnight start of a fixed `days`-day window ending today (050).
|
|
24
|
+
* `days = 30` yields exactly 30 local-day buckets including today; the window
|
|
25
|
+
* does not follow the range chips.
|
|
26
|
+
*/
|
|
27
|
+
export function fixedWindowFrom(days: number, now: Date = new Date()): string {
|
|
28
|
+
const start = new Date(
|
|
29
|
+
now.getFullYear(),
|
|
30
|
+
now.getMonth(),
|
|
31
|
+
now.getDate() - (Math.max(1, Math.floor(days)) - 1),
|
|
32
|
+
);
|
|
33
|
+
return start.toISOString();
|
|
34
|
+
}
|