@koinzhang/paseo-plugin-activity 0.6.0 → 0.8.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 +50 -1
- package/README.md +18 -11
- package/client/activity-heatmap.tsx +115 -74
- package/client/agent-creations.tsx +100 -90
- package/client/attention-pill.tsx +17 -6
- package/client/attention-popover.tsx +19 -23
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +180 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +243 -268
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +153 -103
- package/client/panel-visibility.test.ts +25 -0
- package/client/panel-visibility.ts +45 -0
- package/client/panel.tsx +94 -111
- package/client/pill.tsx +1 -1
- package/client/provider-dropdown.tsx +134 -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 +294 -0
- package/client/sidebar-item.tsx +15 -0
- package/client/ui.tsx +351 -0
- package/client/usage-popover.tsx +72 -137
- 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 +28 -28
- package/client/workspace/agents-section.tsx +42 -57
- package/client/workspace/constants.ts +8 -6
- package/client/workspace/display-menu.tsx +6 -5
- package/client/workspace/filters.test.ts +1 -1
- package/client/workspace/filters.ts +4 -2
- package/client/workspace/panel.tsx +96 -104
- package/client/workspace/rank-section.tsx +40 -65
- package/client/workspace/running-indicator.tsx +1 -1
- package/client/workspace/terminals-section.tsx +24 -12
- package/index.client.tsx +53 -31
- package/index.server.ts +55 -73
- package/package.json +3 -3
- 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/host-types.ts +6 -6
- 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/server/turn-ingest.test.ts +180 -0
- package/server/turn-ingest.ts +71 -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 +125 -64
- package/shared/usage.test.ts +121 -0
- package/shared/usage.ts +191 -2
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/ui";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
3
|
+
import { Animated, Easing, Pressable, Text, View } from "react-native";
|
|
4
|
+
import { metricValue, type ActivityMetric } from "../shared/activity.ts";
|
|
5
|
+
import { messagesFor } from "../shared/i18n.ts";
|
|
6
|
+
import { CHART_MOTION, CONTROL, ICON_SIZE, PRESS, RADIUS, ROW_PADDING, TEXT, pillRadius, sectionTitle, titleGap } from "./design-tokens.ts";
|
|
7
|
+
import { InlineEmpty, MetricStepper } from "./ui.tsx";
|
|
8
|
+
|
|
9
|
+
const BAR_HEIGHT = 6;
|
|
10
|
+
const SWATCH_SIZE = 10;
|
|
11
|
+
const VISIBLE_ROWS = 5;
|
|
12
|
+
|
|
13
|
+
export type RankingEntry = {
|
|
14
|
+
key: string;
|
|
15
|
+
label: string;
|
|
16
|
+
/** Leading swatch colour. */
|
|
17
|
+
color: string;
|
|
18
|
+
agents: number;
|
|
19
|
+
messages: number;
|
|
20
|
+
skills: number;
|
|
21
|
+
mcp: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Ranked bars with a `‹ Sessions ›` metric switch (069 Providers, 070
|
|
26
|
+
* Projects). Shows the top five nonzero entries until expanded; `highlight`
|
|
27
|
+
* dims the others instead of hiding them. Bars use the top value for scale.
|
|
28
|
+
*/
|
|
29
|
+
export function RankingBars({ title, empty, entries, highlight, colors, compact, locale }: {
|
|
30
|
+
title: string;
|
|
31
|
+
empty: string;
|
|
32
|
+
entries: readonly RankingEntry[];
|
|
33
|
+
/** Entry key to keep at full opacity; omit to show all at full opacity. */
|
|
34
|
+
highlight?: string;
|
|
35
|
+
colors: { accent: string; foreground: string; foregroundMuted: string; surface2: string };
|
|
36
|
+
compact?: boolean;
|
|
37
|
+
locale: string;
|
|
38
|
+
}): ReactNode {
|
|
39
|
+
const [metric, setMetric] = useState<ActivityMetric>("sessions");
|
|
40
|
+
const [expanded, setExpanded] = useState(false);
|
|
41
|
+
/** Extra rows stay mounted until the collapse animation finishes. */
|
|
42
|
+
const [extrasMounted, setExtrasMounted] = useState(false);
|
|
43
|
+
const [disclosing, setDisclosing] = useState(false);
|
|
44
|
+
const [extrasHeight, setExtrasHeight] = useState(0);
|
|
45
|
+
const disclosure = useRef(new Animated.Value(0)).current;
|
|
46
|
+
const m = messagesFor(locale);
|
|
47
|
+
|
|
48
|
+
function toggle() {
|
|
49
|
+
const next = !expanded;
|
|
50
|
+
setExpanded(next);
|
|
51
|
+
setDisclosing(true);
|
|
52
|
+
if (next) setExtrasMounted(true);
|
|
53
|
+
discloseTiming(disclosure, next).start(({ finished }) => {
|
|
54
|
+
if (!finished) return;
|
|
55
|
+
setDisclosing(false);
|
|
56
|
+
if (!next) setExtrasMounted(false);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const rows = useMemo(
|
|
60
|
+
() =>
|
|
61
|
+
entries
|
|
62
|
+
.map((entry) => ({ ...entry, value: metricValue(entry, metric) }))
|
|
63
|
+
.filter((row) => row.value > 0)
|
|
64
|
+
.sort((a, b) => b.value - a.value || a.label.localeCompare(b.label)),
|
|
65
|
+
[entries, metric],
|
|
66
|
+
);
|
|
67
|
+
const max = rows[0]?.value ?? 0;
|
|
68
|
+
const hiddenCount = Math.max(0, rows.length - VISIBLE_ROWS);
|
|
69
|
+
const toggleLabel = expanded ? m.global.ranking.showLess : m.global.ranking.showMore(hiddenCount);
|
|
70
|
+
|
|
71
|
+
// Slots past `rows.length` linger until their exit animation reports back.
|
|
72
|
+
const [lingering, setLingering] = useState(0);
|
|
73
|
+
const slotCount = Math.max(lingering, rows.length);
|
|
74
|
+
const rowCountRef = useRef(rows.length);
|
|
75
|
+
rowCountRef.current = rows.length;
|
|
76
|
+
// Rows only animate in once the list has been shown; first paint and the
|
|
77
|
+
// Show more reveal already have their own motion.
|
|
78
|
+
const listShownRef = useRef(false);
|
|
79
|
+
const extrasShownRef = useRef(false);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
setLingering((prev) => (rows.length === 0 ? 0 : Math.max(prev, rows.length)));
|
|
82
|
+
listShownRef.current = rows.length > 0;
|
|
83
|
+
}, [rows.length]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
extrasShownRef.current = extrasMounted;
|
|
86
|
+
}, [extrasMounted]);
|
|
87
|
+
const dropExited = () => setLingering(rowCountRef.current);
|
|
88
|
+
const slots = (from: number, to: number, animateIn: boolean) =>
|
|
89
|
+
Array.from({ length: Math.max(0, to - from) }, (_, index) => {
|
|
90
|
+
const rank = from + index;
|
|
91
|
+
return (
|
|
92
|
+
<RankSlot key={rank} row={rows[rank]} animateIn={animateIn} onExited={dropExited}>
|
|
93
|
+
{renderRow}
|
|
94
|
+
</RankSlot>
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<View style={{ gap: titleGap(compact) - 2 }}>
|
|
100
|
+
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 8 }}>
|
|
101
|
+
<Text style={{ ...sectionTitle(compact), color: colors.foreground, flexShrink: 1 }} numberOfLines={1}>
|
|
102
|
+
{title}
|
|
103
|
+
</Text>
|
|
104
|
+
<MetricStepper value={metric} onChange={setMetric} colors={colors} />
|
|
105
|
+
</View>
|
|
106
|
+
{rows.length === 0 ? (
|
|
107
|
+
<InlineEmpty text={empty} color={colors.foregroundMuted} />
|
|
108
|
+
) : (
|
|
109
|
+
<View style={{ gap: 2 }}>
|
|
110
|
+
{slots(0, Math.min(VISIBLE_ROWS, slotCount), listShownRef.current)}
|
|
111
|
+
{extrasMounted && slotCount > VISIBLE_ROWS ? (
|
|
112
|
+
<Animated.View
|
|
113
|
+
style={{
|
|
114
|
+
height: disclosing
|
|
115
|
+
? disclosure.interpolate({ inputRange: [0, 1], outputRange: [0, extrasHeight] })
|
|
116
|
+
: undefined,
|
|
117
|
+
opacity: disclosure,
|
|
118
|
+
overflow: "hidden",
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<View
|
|
122
|
+
style={{ gap: 2 }}
|
|
123
|
+
onLayout={(event) => setExtrasHeight(event.nativeEvent.layout.height)}
|
|
124
|
+
>
|
|
125
|
+
{slots(VISIBLE_ROWS, slotCount, listShownRef.current && extrasShownRef.current)}
|
|
126
|
+
</View>
|
|
127
|
+
</Animated.View>
|
|
128
|
+
) : null}
|
|
129
|
+
{hiddenCount > 0 ? (
|
|
130
|
+
<Pressable
|
|
131
|
+
accessibilityRole="button"
|
|
132
|
+
accessibilityLabel={toggleLabel}
|
|
133
|
+
accessibilityState={{ expanded }}
|
|
134
|
+
hitSlop={CONTROL.hitSlop}
|
|
135
|
+
onPress={toggle}
|
|
136
|
+
style={({ pressed }) => [
|
|
137
|
+
{ alignSelf: "flex-end", flexDirection: "row", alignItems: "center", gap: 4, paddingVertical: ROW_PADDING.dense },
|
|
138
|
+
pressed ? { opacity: PRESS.textOpacity } : null,
|
|
139
|
+
]}
|
|
140
|
+
>
|
|
141
|
+
<Text style={{ ...TEXT.body, color: colors.foregroundMuted }}>{toggleLabel}</Text>
|
|
142
|
+
<Animated.View
|
|
143
|
+
style={{
|
|
144
|
+
transform: [{ rotate: disclosure.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "180deg"] }) }],
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
<Icon name="ChevronDown" size={ICON_SIZE.inline} color={colors.foregroundMuted} />
|
|
148
|
+
</Animated.View>
|
|
149
|
+
</Pressable>
|
|
150
|
+
) : null}
|
|
151
|
+
</View>
|
|
152
|
+
)}
|
|
153
|
+
</View>
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
function renderRow(row: RankedRow): ReactNode {
|
|
157
|
+
return (
|
|
158
|
+
<View
|
|
159
|
+
style={{
|
|
160
|
+
flexDirection: "row",
|
|
161
|
+
alignItems: "center",
|
|
162
|
+
gap: compact ? 10 : 16,
|
|
163
|
+
paddingVertical: ROW_PADDING.regular,
|
|
164
|
+
opacity: highlight == null || highlight === row.key ? 1 : 0.4,
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 10, width: compact ? 110 : 180 }}>
|
|
168
|
+
<View
|
|
169
|
+
style={{
|
|
170
|
+
width: SWATCH_SIZE,
|
|
171
|
+
height: SWATCH_SIZE,
|
|
172
|
+
borderRadius: RADIUS.swatch,
|
|
173
|
+
backgroundColor: row.color,
|
|
174
|
+
}}
|
|
175
|
+
/>
|
|
176
|
+
<Text style={{ ...TEXT.body, color: colors.foreground, flex: 1, minWidth: 0 }} numberOfLines={1}>
|
|
177
|
+
{row.label}
|
|
178
|
+
</Text>
|
|
179
|
+
</View>
|
|
180
|
+
<View
|
|
181
|
+
style={{
|
|
182
|
+
flex: 1,
|
|
183
|
+
height: BAR_HEIGHT,
|
|
184
|
+
borderRadius: pillRadius(BAR_HEIGHT),
|
|
185
|
+
backgroundColor: colors.surface2,
|
|
186
|
+
overflow: "hidden",
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
<AnimatedBar
|
|
190
|
+
percent={max > 0 ? Math.max(1, (row.value / max) * 100) : 0}
|
|
191
|
+
color={colors.accent}
|
|
192
|
+
/>
|
|
193
|
+
</View>
|
|
194
|
+
<Text
|
|
195
|
+
style={{ ...TEXT.body, color: colors.foregroundMuted, fontVariant: ["tabular-nums"], minWidth: 48, textAlign: "right" }}
|
|
196
|
+
>
|
|
197
|
+
{row.value.toLocaleString(locale)}
|
|
198
|
+
</Text>
|
|
199
|
+
</View>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
type RankedRow = RankingEntry & { value: number };
|
|
205
|
+
|
|
206
|
+
function discloseTiming(value: Animated.Value, open: boolean): Animated.CompositeAnimation {
|
|
207
|
+
return Animated.timing(value, {
|
|
208
|
+
toValue: open ? 1 : 0,
|
|
209
|
+
duration: open ? CHART_MOTION.disclose : CHART_MOTION.discloseClose,
|
|
210
|
+
easing: Easing.out(Easing.cubic),
|
|
211
|
+
useNativeDriver: false,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* One rank position. When its row appears or disappears (metric switch) it
|
|
217
|
+
* opens / closes with the same height + opacity motion as Show more; a
|
|
218
|
+
* departing row keeps rendering its last data until `onExited`.
|
|
219
|
+
*/
|
|
220
|
+
function RankSlot({ row, animateIn, onExited, children }: {
|
|
221
|
+
row: RankedRow | undefined;
|
|
222
|
+
animateIn: boolean;
|
|
223
|
+
onExited: () => void;
|
|
224
|
+
children: (row: RankedRow) => ReactNode;
|
|
225
|
+
}): ReactNode {
|
|
226
|
+
const lastRow = useRef(row);
|
|
227
|
+
if (row) lastRow.current = row;
|
|
228
|
+
const present = row != null;
|
|
229
|
+
const presence = useRef(new Animated.Value(animateIn ? 0 : 1)).current;
|
|
230
|
+
const [animating, setAnimating] = useState(animateIn);
|
|
231
|
+
const [height, setHeight] = useState(0);
|
|
232
|
+
const firstRun = useRef(true);
|
|
233
|
+
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
if (firstRun.current) {
|
|
236
|
+
firstRun.current = false;
|
|
237
|
+
if (!animateIn) return;
|
|
238
|
+
}
|
|
239
|
+
setAnimating(true);
|
|
240
|
+
const animation = discloseTiming(presence, present);
|
|
241
|
+
animation.start(({ finished }) => {
|
|
242
|
+
if (!finished) return;
|
|
243
|
+
// An exited slot stays clipped at 0 until the parent unmounts it.
|
|
244
|
+
if (present) setAnimating(false);
|
|
245
|
+
else onExited();
|
|
246
|
+
});
|
|
247
|
+
return () => animation.stop();
|
|
248
|
+
}, [present]);
|
|
249
|
+
|
|
250
|
+
const shown = lastRow.current;
|
|
251
|
+
if (!shown) return null;
|
|
252
|
+
return (
|
|
253
|
+
<Animated.View
|
|
254
|
+
style={{
|
|
255
|
+
opacity: presence,
|
|
256
|
+
height: animating ? presence.interpolate({ inputRange: [0, 1], outputRange: [0, height] }) : undefined,
|
|
257
|
+
overflow: animating ? "hidden" : "visible",
|
|
258
|
+
}}
|
|
259
|
+
>
|
|
260
|
+
<View onLayout={(event) => setHeight(event.nativeEvent.layout.height)}>{children(shown)}</View>
|
|
261
|
+
</Animated.View>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Bar fill that grows from 0 on mount and animates between widths on change.
|
|
267
|
+
* Slots are keyed by rank, so a bar only moves when its slot's percentage
|
|
268
|
+
* changes, not when entries reorder under it.
|
|
269
|
+
*/
|
|
270
|
+
function AnimatedBar({ percent, color }: { percent: number; color: string }): ReactNode {
|
|
271
|
+
const progress = useRef(new Animated.Value(0)).current;
|
|
272
|
+
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
const animation = Animated.timing(progress, {
|
|
275
|
+
toValue: percent,
|
|
276
|
+
duration: CHART_MOTION.grow,
|
|
277
|
+
easing: Easing.out(Easing.cubic),
|
|
278
|
+
useNativeDriver: false,
|
|
279
|
+
});
|
|
280
|
+
animation.start();
|
|
281
|
+
return () => animation.stop();
|
|
282
|
+
}, [percent, progress]);
|
|
283
|
+
|
|
284
|
+
return (
|
|
285
|
+
<Animated.View
|
|
286
|
+
style={{
|
|
287
|
+
width: progress.interpolate({ inputRange: [0, 100], outputRange: ["0%", "100%"] }),
|
|
288
|
+
height: BAR_HEIGHT,
|
|
289
|
+
borderRadius: pillRadius(BAR_HEIGHT),
|
|
290
|
+
backgroundColor: color,
|
|
291
|
+
}}
|
|
292
|
+
/>
|
|
293
|
+
);
|
|
294
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PluginSidebarItemProps } from "@getpaseo/plugin/client";
|
|
2
|
+
import { SidebarRow } from "@getpaseo/plugin/client/ui";
|
|
3
|
+
|
|
4
|
+
export const ACTIVITY_SCREEN_ID = "activity";
|
|
5
|
+
|
|
6
|
+
/** Sidebar header row for the global Activity screen (Paseo 0.11+ sidebar items). */
|
|
7
|
+
export function ActivitySidebarItem({ currentScreen, openScreen }: PluginSidebarItemProps) {
|
|
8
|
+
return (
|
|
9
|
+
<SidebarRow
|
|
10
|
+
icon="Activity"
|
|
11
|
+
active={currentScreen?.screenId === ACTIVITY_SCREEN_ID}
|
|
12
|
+
onPress={() => openScreen({ screenId: ACTIVITY_SCREEN_ID })}
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
}
|
package/client/ui.tsx
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/ui";
|
|
2
|
+
import { useRef, useState, type ReactNode } from "react";
|
|
3
|
+
import {
|
|
4
|
+
ActivityIndicator,
|
|
5
|
+
Animated,
|
|
6
|
+
Easing,
|
|
7
|
+
Pressable,
|
|
8
|
+
Text,
|
|
9
|
+
View,
|
|
10
|
+
type StyleProp,
|
|
11
|
+
type ViewStyle,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
import {
|
|
14
|
+
CHART_MOTION,
|
|
15
|
+
CONTROL,
|
|
16
|
+
FONT_WEIGHT,
|
|
17
|
+
ICON_SIZE,
|
|
18
|
+
PRESS,
|
|
19
|
+
RADIUS,
|
|
20
|
+
TEXT,
|
|
21
|
+
iconButton,
|
|
22
|
+
sectionTitle,
|
|
23
|
+
titleGap,
|
|
24
|
+
tooltipSurface,
|
|
25
|
+
} from "./design-tokens.ts";
|
|
26
|
+
import { useMessages } from "./use-app-language.ts";
|
|
27
|
+
import { stepMetric, type ActivityMetric } from "../shared/activity.ts";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Shared Activity UI building blocks (066). Styling comes from design tokens;
|
|
31
|
+
* copy comes from `useMessages()`. Rules: `docs/design-system.md`.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
type TextColors = { foreground: string; foregroundMuted: string };
|
|
35
|
+
|
|
36
|
+
export function IconButton({
|
|
37
|
+
icon,
|
|
38
|
+
label,
|
|
39
|
+
onPress,
|
|
40
|
+
color,
|
|
41
|
+
size = ICON_SIZE.action,
|
|
42
|
+
disabled,
|
|
43
|
+
expanded,
|
|
44
|
+
hidden,
|
|
45
|
+
busy,
|
|
46
|
+
style,
|
|
47
|
+
}: {
|
|
48
|
+
icon: string;
|
|
49
|
+
label: string;
|
|
50
|
+
onPress: () => void;
|
|
51
|
+
color: string;
|
|
52
|
+
size?: number;
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
expanded?: boolean;
|
|
55
|
+
/** Keeps layout but hides and disables the button (hover-reveal rows). */
|
|
56
|
+
hidden?: boolean;
|
|
57
|
+
busy?: boolean;
|
|
58
|
+
style?: StyleProp<ViewStyle>;
|
|
59
|
+
}): ReactNode {
|
|
60
|
+
return (
|
|
61
|
+
<Pressable
|
|
62
|
+
accessibilityRole="button"
|
|
63
|
+
accessibilityLabel={label}
|
|
64
|
+
accessibilityState={{ disabled: disabled === true, expanded }}
|
|
65
|
+
disabled={disabled || hidden}
|
|
66
|
+
hitSlop={CONTROL.hitSlop}
|
|
67
|
+
onPress={onPress}
|
|
68
|
+
pointerEvents={hidden ? "none" : "auto"}
|
|
69
|
+
style={({ pressed }) => [
|
|
70
|
+
iconButton,
|
|
71
|
+
hidden ? { opacity: 0 } : null,
|
|
72
|
+
pressed ? { opacity: PRESS.opacity, transform: [{ scale: PRESS.scale }] } : null,
|
|
73
|
+
style,
|
|
74
|
+
]}
|
|
75
|
+
>
|
|
76
|
+
{busy ? (
|
|
77
|
+
<ActivityIndicator size={size} color={color} style={{ width: size, height: size }} />
|
|
78
|
+
) : (
|
|
79
|
+
<Icon name={icon} size={size} color={color} />
|
|
80
|
+
)}
|
|
81
|
+
</Pressable>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Section title row; `children` are trailing actions (usually `IconButton`s). */
|
|
86
|
+
export function SectionHeader({
|
|
87
|
+
title,
|
|
88
|
+
colors,
|
|
89
|
+
compact,
|
|
90
|
+
children,
|
|
91
|
+
}: {
|
|
92
|
+
title: string;
|
|
93
|
+
colors: TextColors;
|
|
94
|
+
compact?: boolean;
|
|
95
|
+
children?: ReactNode;
|
|
96
|
+
}): ReactNode {
|
|
97
|
+
return (
|
|
98
|
+
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 8 }}>
|
|
99
|
+
<Text style={{ ...sectionTitle(compact), color: colors.foreground, flexShrink: 1 }} numberOfLines={1}>
|
|
100
|
+
{title}
|
|
101
|
+
</Text>
|
|
102
|
+
{children ? (
|
|
103
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 2, flexShrink: 0 }}>{children}</View>
|
|
104
|
+
) : null}
|
|
105
|
+
</View>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Section wrapper with the shared title → content gap. */
|
|
110
|
+
export function Section({ compact, children }: { compact?: boolean; children: ReactNode }): ReactNode {
|
|
111
|
+
return <View style={{ gap: titleGap(compact) }}>{children}</View>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function LoadingState({ color }: { color: string }): ReactNode {
|
|
115
|
+
return <ActivityIndicator color={color} />;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Error text plus Retry; `onRetry` should refetch every failed query. */
|
|
119
|
+
export function ErrorState({
|
|
120
|
+
error,
|
|
121
|
+
onRetry,
|
|
122
|
+
colors,
|
|
123
|
+
}: {
|
|
124
|
+
error: unknown;
|
|
125
|
+
onRetry?: () => void;
|
|
126
|
+
colors: { statusDanger: string; accent: string };
|
|
127
|
+
}): ReactNode {
|
|
128
|
+
const m = useMessages();
|
|
129
|
+
const detail = error instanceof Error ? error.message : error != null ? String(error) : "";
|
|
130
|
+
return (
|
|
131
|
+
<View style={{ gap: 4 }} accessibilityRole="alert">
|
|
132
|
+
<Text style={{ ...TEXT.small, color: colors.statusDanger }}>
|
|
133
|
+
{detail ? `${m.common.loadFailed}: ${detail}` : m.common.loadFailed}
|
|
134
|
+
</Text>
|
|
135
|
+
{onRetry ? (
|
|
136
|
+
<Pressable
|
|
137
|
+
accessibilityRole="button"
|
|
138
|
+
hitSlop={CONTROL.hitSlop}
|
|
139
|
+
onPress={onRetry}
|
|
140
|
+
style={({ pressed }) => [
|
|
141
|
+
{ alignSelf: "flex-start", paddingVertical: 2 },
|
|
142
|
+
pressed ? { opacity: PRESS.textOpacity } : null,
|
|
143
|
+
]}
|
|
144
|
+
>
|
|
145
|
+
<Text style={{ ...TEXT.small, fontWeight: FONT_WEIGHT.medium, color: colors.accent }}>
|
|
146
|
+
{m.common.retry}
|
|
147
|
+
</Text>
|
|
148
|
+
</Pressable>
|
|
149
|
+
) : null}
|
|
150
|
+
</View>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Empty text inside a section / list / chart. */
|
|
155
|
+
export function InlineEmpty({ text, color }: { text: string; color: string }): ReactNode {
|
|
156
|
+
return <Text style={{ ...TEXT.small, color }}>{text}</Text>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Whole-page empty state (no data at all). */
|
|
160
|
+
export function PageEmpty({ title, hint, colors }: { title: string; hint?: string; colors: TextColors }): ReactNode {
|
|
161
|
+
return (
|
|
162
|
+
<View style={{ paddingVertical: 48, alignItems: "center", gap: 6 }}>
|
|
163
|
+
<Text style={{ ...TEXT.display, color: colors.foreground }}>{title}</Text>
|
|
164
|
+
{hint ? <Text style={{ ...TEXT.body, color: colors.foregroundMuted, textAlign: "center" }}>{hint}</Text> : null}
|
|
165
|
+
</View>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Text tabs. `filter` = page filters (body 14, weight shift); `chart` = in-chart
|
|
171
|
+
* modes (label 12, color only — same level as axis labels).
|
|
172
|
+
*/
|
|
173
|
+
export function TextTabs<T extends string>({
|
|
174
|
+
options,
|
|
175
|
+
value,
|
|
176
|
+
onChange,
|
|
177
|
+
colors,
|
|
178
|
+
variant,
|
|
179
|
+
gap,
|
|
180
|
+
}: {
|
|
181
|
+
options: ReadonlyArray<{ id: T; label: string }>;
|
|
182
|
+
value: T;
|
|
183
|
+
onChange: (id: T) => void;
|
|
184
|
+
colors: TextColors;
|
|
185
|
+
variant: "filter" | "chart";
|
|
186
|
+
gap: number;
|
|
187
|
+
}): ReactNode {
|
|
188
|
+
return (
|
|
189
|
+
<View accessibilityRole="tablist" style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap }}>
|
|
190
|
+
{options.map((option) => {
|
|
191
|
+
const active = option.id === value;
|
|
192
|
+
const text =
|
|
193
|
+
variant === "filter"
|
|
194
|
+
? { ...TEXT.body, fontWeight: active ? FONT_WEIGHT.semibold : FONT_WEIGHT.medium }
|
|
195
|
+
: TEXT.meta;
|
|
196
|
+
return (
|
|
197
|
+
<Pressable
|
|
198
|
+
key={option.id}
|
|
199
|
+
accessibilityRole="tab"
|
|
200
|
+
accessibilityState={{ selected: active }}
|
|
201
|
+
onPress={() => onChange(option.id)}
|
|
202
|
+
style={({ pressed }) => [
|
|
203
|
+
{ paddingVertical: 6 },
|
|
204
|
+
pressed ? { opacity: PRESS.textOpacity } : null,
|
|
205
|
+
]}
|
|
206
|
+
>
|
|
207
|
+
<Text style={{ ...text, color: active ? colors.foreground : colors.foregroundMuted }}>{option.label}</Text>
|
|
208
|
+
</Pressable>
|
|
209
|
+
);
|
|
210
|
+
})}
|
|
211
|
+
</View>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* `‹ Sessions ›` metric switch for Global chart headers (070): cycles
|
|
217
|
+
* Sessions → Prompts → Skill calls → MCP calls.
|
|
218
|
+
*/
|
|
219
|
+
export function MetricStepper({
|
|
220
|
+
value,
|
|
221
|
+
onChange,
|
|
222
|
+
colors,
|
|
223
|
+
}: {
|
|
224
|
+
value: ActivityMetric;
|
|
225
|
+
onChange: (metric: ActivityMetric) => void;
|
|
226
|
+
colors: TextColors;
|
|
227
|
+
}): ReactNode {
|
|
228
|
+
const m = useMessages().global;
|
|
229
|
+
const slide = useRef(new Animated.Value(0)).current;
|
|
230
|
+
const step = (direction: 1 | -1) => {
|
|
231
|
+
onChange(stepMetric(value, direction));
|
|
232
|
+
// The new label enters from the side of the pressed arrow.
|
|
233
|
+
slide.setValue(direction);
|
|
234
|
+
Animated.timing(slide, {
|
|
235
|
+
toValue: 0,
|
|
236
|
+
duration: CHART_MOTION.step,
|
|
237
|
+
easing: Easing.out(Easing.cubic),
|
|
238
|
+
useNativeDriver: true,
|
|
239
|
+
}).start();
|
|
240
|
+
};
|
|
241
|
+
return (
|
|
242
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}>
|
|
243
|
+
<IconButton
|
|
244
|
+
icon="ChevronLeft"
|
|
245
|
+
label={m.previousMetric}
|
|
246
|
+
onPress={() => step(-1)}
|
|
247
|
+
color={colors.foregroundMuted}
|
|
248
|
+
/>
|
|
249
|
+
<View style={{ minWidth: 84, overflow: "hidden" }}>
|
|
250
|
+
<Animated.Text
|
|
251
|
+
accessibilityLiveRegion="polite"
|
|
252
|
+
style={{
|
|
253
|
+
...TEXT.body,
|
|
254
|
+
color: colors.foregroundMuted,
|
|
255
|
+
textAlign: "center",
|
|
256
|
+
opacity: slide.interpolate({ inputRange: [-1, 0, 1], outputRange: [0, 1, 0] }),
|
|
257
|
+
transform: [
|
|
258
|
+
{
|
|
259
|
+
translateX: slide.interpolate({
|
|
260
|
+
inputRange: [-1, 1],
|
|
261
|
+
outputRange: [-CHART_MOTION.stepOffset, CHART_MOTION.stepOffset],
|
|
262
|
+
}),
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
}}
|
|
266
|
+
numberOfLines={1}
|
|
267
|
+
>
|
|
268
|
+
{m.metrics[value]}
|
|
269
|
+
</Animated.Text>
|
|
270
|
+
</View>
|
|
271
|
+
<IconButton
|
|
272
|
+
icon="ChevronRight"
|
|
273
|
+
label={m.nextMetric}
|
|
274
|
+
onPress={() => step(1)}
|
|
275
|
+
color={colors.foregroundMuted}
|
|
276
|
+
/>
|
|
277
|
+
</View>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Trailing count in list rows. */
|
|
282
|
+
export function CountText({ value, color }: { value: number | string; color: string }): ReactNode {
|
|
283
|
+
return <Text style={{ ...TEXT.count, color, minWidth: 24, textAlign: "right" }}>{value}</Text>;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export type ChartTooltipRow = { label: string; value: string; color?: string };
|
|
287
|
+
|
|
288
|
+
const TOOLTIP_GAP = 8;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Floating chart tooltip, shared by the heatmap, creations histogram and
|
|
292
|
+
* timeline. Positioned in the chart root: centered on `anchorX`, above
|
|
293
|
+
* `anchorY`, clamped to `[0, containerWidth]`.
|
|
294
|
+
*/
|
|
295
|
+
export function ChartTooltip({
|
|
296
|
+
anchorX,
|
|
297
|
+
anchorY,
|
|
298
|
+
containerWidth,
|
|
299
|
+
title,
|
|
300
|
+
rows,
|
|
301
|
+
colors,
|
|
302
|
+
clampTop = true,
|
|
303
|
+
}: {
|
|
304
|
+
anchorX: number;
|
|
305
|
+
anchorY: number;
|
|
306
|
+
/** false = may rise above the chart root (over the section header). */
|
|
307
|
+
clampTop?: boolean;
|
|
308
|
+
containerWidth: number;
|
|
309
|
+
title: string;
|
|
310
|
+
rows: ReadonlyArray<ChartTooltipRow>;
|
|
311
|
+
colors: TextColors & { surface2: string; border: string };
|
|
312
|
+
}): ReactNode {
|
|
313
|
+
const [size, setSize] = useState({ width: 180, height: 60 });
|
|
314
|
+
const left = Math.max(0, Math.min(anchorX - size.width / 2, containerWidth - size.width));
|
|
315
|
+
const rawTop = anchorY - size.height - TOOLTIP_GAP;
|
|
316
|
+
const top = clampTop ? Math.max(0, rawTop) : rawTop;
|
|
317
|
+
return (
|
|
318
|
+
<View
|
|
319
|
+
pointerEvents="none"
|
|
320
|
+
onLayout={(event) => {
|
|
321
|
+
const { width, height } = event.nativeEvent.layout;
|
|
322
|
+
setSize((prev) => (prev.width === width && prev.height === height ? prev : { width, height }));
|
|
323
|
+
}}
|
|
324
|
+
style={{
|
|
325
|
+
position: "absolute",
|
|
326
|
+
left,
|
|
327
|
+
top,
|
|
328
|
+
zIndex: 10,
|
|
329
|
+
minWidth: 140,
|
|
330
|
+
maxWidth: containerWidth > 0 ? containerWidth : undefined,
|
|
331
|
+
gap: 4,
|
|
332
|
+
...tooltipSurface(colors),
|
|
333
|
+
}}
|
|
334
|
+
>
|
|
335
|
+
<Text accessibilityLiveRegion="polite" style={{ ...TEXT.tooltip, fontWeight: FONT_WEIGHT.medium, color: colors.foreground }}>
|
|
336
|
+
{title}
|
|
337
|
+
</Text>
|
|
338
|
+
{rows.map((row) => (
|
|
339
|
+
<View key={row.label} style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
|
340
|
+
{row.color ? (
|
|
341
|
+
<View style={{ width: 8, height: 8, borderRadius: RADIUS.swatch, backgroundColor: row.color }} />
|
|
342
|
+
) : null}
|
|
343
|
+
<Text style={{ ...TEXT.tooltip, color: colors.foregroundMuted, flex: 1 }} numberOfLines={1}>
|
|
344
|
+
{row.label}
|
|
345
|
+
</Text>
|
|
346
|
+
<Text style={{ ...TEXT.tooltip, color: colors.foreground, fontVariant: ["tabular-nums"] }}>{row.value}</Text>
|
|
347
|
+
</View>
|
|
348
|
+
))}
|
|
349
|
+
</View>
|
|
350
|
+
);
|
|
351
|
+
}
|