@koinzhang/paseo-plugin-activity 0.1.0 → 0.2.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +71 -0
  3. package/client/activity-heatmap.tsx +72 -14
  4. package/client/global-surface.tsx +24 -25
  5. package/client/panel.tsx +1 -0
  6. package/client/range.ts +20 -0
  7. package/client/usage-stats.tsx +7 -5
  8. package/client/workspace/agent-row.tsx +117 -0
  9. package/client/workspace/agents-section.tsx +323 -0
  10. package/client/workspace/constants.ts +121 -0
  11. package/client/workspace/display-menu.tsx +116 -0
  12. package/client/workspace/filters.ts +30 -0
  13. package/client/workspace/list-host-agents.ts +57 -0
  14. package/client/workspace/panel.tsx +800 -0
  15. package/client/workspace/rank-section.tsx +121 -0
  16. package/client/workspace-panel.tsx +2 -0
  17. package/index.client.tsx +20 -13
  18. package/index.server.ts +11 -0
  19. package/package.json +8 -2
  20. package/server/agents.test.ts +20 -1
  21. package/server/agents.ts +2 -1
  22. package/server/background-sync.test.ts +14 -3
  23. package/server/background-sync.ts +16 -5
  24. package/server/handlers-query.test.ts +58 -0
  25. package/server/handlers.ts +73 -2
  26. package/server/messages.test.ts +8 -2
  27. package/server/store.test.ts +13 -0
  28. package/server/store.ts +2 -2
  29. package/shared/activity.test.ts +22 -12
  30. package/shared/activity.ts +8 -13
  31. package/shared/agent-page-size.test.ts +11 -0
  32. package/shared/agent-title-search.test.ts +28 -0
  33. package/shared/agent-title-search.ts +12 -0
  34. package/shared/explorer-agent-display.ts +30 -0
  35. package/shared/format.test.ts +22 -1
  36. package/shared/format.ts +24 -0
  37. package/shared/insights.test.ts +38 -18
  38. package/shared/insights.ts +38 -19
  39. package/shared/list-agent-pages.test.ts +51 -0
  40. package/shared/list-agent-pages.ts +31 -0
  41. package/shared/usage.test.ts +248 -0
  42. package/shared/usage.ts +327 -11
@@ -0,0 +1,323 @@
1
+ import { Icon, TextInput } from "@getpaseo/plugin/client/react-native";
2
+ import { useEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";
3
+ import {
4
+ Animated,
5
+ Easing,
6
+ Pressable,
7
+ Text,
8
+ View,
9
+ type TextStyle,
10
+ type ViewStyle,
11
+ } from "react-native";
12
+ import { providerLabel, type AgentUsageItem } from "../../shared/usage.ts";
13
+ import { AgentRow, type AgentRowStyles } from "./agent-row.tsx";
14
+ import {
15
+ AGENT_PAGE_SIZE,
16
+ SEARCH_ANIM_MS,
17
+ SEARCH_TITLE_GAP,
18
+ type AgentGroup,
19
+ type AgentShowField,
20
+ type AgentStatusInfo,
21
+ } from "./constants.ts";
22
+ import { formatAgentMeta } from "./filters.ts";
23
+ import type { WorkspaceTheme } from "./constants.ts";
24
+
25
+ export type AgentsSectionStyles = AgentRowStyles & {
26
+ agentsSection: ViewStyle;
27
+ agentsHeaderWrap: ViewStyle;
28
+ agentsHeaderRow: ViewStyle;
29
+ agentsHeaderSearchSlot: ViewStyle;
30
+ searchField: ViewStyle;
31
+ searchInput: TextStyle;
32
+ headerActions: ViewStyle;
33
+ sectionTitle: TextStyle;
34
+ titleAction: ViewStyle;
35
+ panel: ViewStyle;
36
+ agentGroup: ViewStyle;
37
+ groupLabel: TextStyle;
38
+ empty: TextStyle;
39
+ pagerRow: ViewStyle;
40
+ pagerButton: ViewStyle;
41
+ pagerButtonDisabled: ViewStyle;
42
+ pagerLabel: TextStyle;
43
+ };
44
+
45
+ export function AgentsSection({
46
+ theme,
47
+ styles,
48
+ locale,
49
+ agentGroup,
50
+ agentShowFields,
51
+ statuses,
52
+ visibleAgentItems,
53
+ statusFiltersEmpty,
54
+ busyAgentId,
55
+ openAgent,
56
+ menuOpen,
57
+ onToggleMenu,
58
+ triggerRef,
59
+ searchQuery,
60
+ onSearchQueryChange,
61
+ onArchive,
62
+ onUnarchive,
63
+ resetKey,
64
+ }: {
65
+ theme: WorkspaceTheme;
66
+ styles: AgentsSectionStyles;
67
+ locale: string;
68
+ agentGroup: AgentGroup;
69
+ agentShowFields: ReadonlySet<AgentShowField>;
70
+ statuses: Record<string, AgentStatusInfo> | undefined;
71
+ /** Already filtered / sorted / search-matched. */
72
+ visibleAgentItems: ReadonlyArray<AgentUsageItem>;
73
+ statusFiltersEmpty: boolean;
74
+ busyAgentId: string | null;
75
+ openAgent?: (opts: { agentId: string }) => void;
76
+ menuOpen: boolean;
77
+ onToggleMenu: () => void;
78
+ triggerRef: RefObject<View | null>;
79
+ searchQuery: string;
80
+ onSearchQueryChange: (query: string) => void;
81
+ onArchive: (item: AgentUsageItem) => void;
82
+ onUnarchive: (item: AgentUsageItem) => void;
83
+ /** Bump when workspace changes to collapse search. */
84
+ resetKey: string;
85
+ }): ReactNode {
86
+ const [agentSearchOpen, setAgentSearchOpen] = useState(false);
87
+ const [searchSlotWidth, setSearchSlotWidth] = useState(0);
88
+ const [pageIndex, setPageIndex] = useState(0);
89
+ const searchProgress = useRef(new Animated.Value(0)).current;
90
+ const searchInputRef = useRef<{ focus?: () => void } | null>(null);
91
+
92
+ useEffect(() => {
93
+ searchProgress.stopAnimation();
94
+ searchProgress.setValue(0);
95
+ setAgentSearchOpen(false);
96
+ setPageIndex(0);
97
+ }, [resetKey, searchProgress]);
98
+
99
+ useEffect(() => {
100
+ if (!agentSearchOpen) return;
101
+ const id = setTimeout(() => searchInputRef.current?.focus?.(), SEARCH_ANIM_MS);
102
+ return () => clearTimeout(id);
103
+ }, [agentSearchOpen]);
104
+
105
+ useEffect(() => {
106
+ setPageIndex(0);
107
+ }, [visibleAgentItems]);
108
+
109
+ function openAgentSearch() {
110
+ if (agentSearchOpen) return;
111
+ setAgentSearchOpen(true);
112
+ Animated.timing(searchProgress, {
113
+ toValue: 1,
114
+ duration: SEARCH_ANIM_MS,
115
+ easing: Easing.out(Easing.cubic),
116
+ useNativeDriver: false,
117
+ }).start();
118
+ }
119
+
120
+ function closeAgentSearch() {
121
+ if (!agentSearchOpen) return;
122
+ Animated.timing(searchProgress, {
123
+ toValue: 0,
124
+ duration: SEARCH_ANIM_MS,
125
+ easing: Easing.in(Easing.cubic),
126
+ useNativeDriver: false,
127
+ }).start(({ finished }) => {
128
+ if (!finished) return;
129
+ setAgentSearchOpen(false);
130
+ onSearchQueryChange("");
131
+ });
132
+ }
133
+
134
+ const pageCount = Math.max(1, Math.ceil(visibleAgentItems.length / AGENT_PAGE_SIZE));
135
+ const safePage = Math.min(pageIndex, pageCount - 1);
136
+ const pageItems = useMemo(() => {
137
+ const start = safePage * AGENT_PAGE_SIZE;
138
+ return visibleAgentItems.slice(start, start + AGENT_PAGE_SIZE);
139
+ }, [visibleAgentItems, safePage]);
140
+
141
+ const pageGroups = useMemo(() => {
142
+ if (agentGroup === "none") return null;
143
+ if (agentGroup === "status") {
144
+ const active: AgentUsageItem[] = [];
145
+ const archived: AgentUsageItem[] = [];
146
+ for (const item of pageItems) {
147
+ if (item.archivedAt != null) archived.push(item);
148
+ else active.push(item);
149
+ }
150
+ const groups: Array<[string, AgentUsageItem[]]> = [];
151
+ if (active.length > 0) groups.push(["Active", active]);
152
+ if (archived.length > 0) groups.push(["Archived", archived]);
153
+ return groups;
154
+ }
155
+ const map = new Map<string, AgentUsageItem[]>();
156
+ for (const item of pageItems) {
157
+ const list = map.get(item.provider);
158
+ if (list) list.push(item);
159
+ else map.set(item.provider, [item]);
160
+ }
161
+ return [...map.entries()].sort((a, b) =>
162
+ providerLabel(a[0]).localeCompare(providerLabel(b[0])),
163
+ );
164
+ }, [agentGroup, pageItems]);
165
+
166
+ function renderAgentRow(item: AgentUsageItem): ReactNode {
167
+ const label = item.title ?? item.agentId;
168
+ const archived = item.archivedAt != null;
169
+ const canOpen = openAgent != null && !archived;
170
+ const meta = formatAgentMeta(item, agentShowFields, statuses, locale);
171
+ const busy = busyAgentId === item.agentId;
172
+ return (
173
+ <AgentRow
174
+ key={item.agentId}
175
+ label={label}
176
+ archived={archived}
177
+ canOpen={canOpen}
178
+ meta={meta}
179
+ busy={busy}
180
+ actionDisabled={busy || busyAgentId != null}
181
+ theme={theme}
182
+ styles={styles}
183
+ onOpen={() => openAgent?.({ agentId: item.agentId })}
184
+ onArchiveToggle={() => {
185
+ if (archived) onUnarchive(item);
186
+ else onArchive(item);
187
+ }}
188
+ />
189
+ );
190
+ }
191
+
192
+ const showPager = pageCount > 1;
193
+
194
+ return (
195
+ <View style={styles.agentsSection}>
196
+ <View style={styles.agentsHeaderWrap}>
197
+ <View style={styles.agentsHeaderRow}>
198
+ <Text style={styles.sectionTitle}>Agents</Text>
199
+ <View
200
+ style={styles.agentsHeaderSearchSlot}
201
+ onLayout={(event) => {
202
+ const next = event.nativeEvent.layout.width;
203
+ setSearchSlotWidth((prev) => (prev === next ? prev : next));
204
+ }}
205
+ >
206
+ <Animated.View
207
+ pointerEvents={agentSearchOpen ? "auto" : "none"}
208
+ style={[
209
+ styles.searchField,
210
+ {
211
+ width: searchProgress.interpolate({
212
+ inputRange: [0, 1],
213
+ outputRange: [0, Math.max(0, searchSlotWidth - SEARCH_TITLE_GAP)],
214
+ }),
215
+ opacity: searchProgress,
216
+ marginLeft: searchProgress.interpolate({
217
+ inputRange: [0, 1],
218
+ outputRange: [0, SEARCH_TITLE_GAP],
219
+ }),
220
+ },
221
+ ]}
222
+ >
223
+ <Icon name="Search" size={14} color={theme.colors.foregroundMuted} />
224
+ <TextInput
225
+ ref={searchInputRef as never}
226
+ value={searchQuery}
227
+ onChangeText={onSearchQueryChange}
228
+ placeholder="Search agents"
229
+ placeholderTextColor={theme.colors.foregroundMuted}
230
+ autoCapitalize="none"
231
+ autoCorrect={false}
232
+ returnKeyType="search"
233
+ editable={agentSearchOpen}
234
+ style={styles.searchInput}
235
+ accessibilityLabel="Search agents by title"
236
+ />
237
+ </Animated.View>
238
+ </View>
239
+ <View style={styles.headerActions}>
240
+ <Pressable
241
+ accessibilityRole="button"
242
+ accessibilityLabel={agentSearchOpen ? "Close agent search" : "Search agents"}
243
+ accessibilityState={{ expanded: agentSearchOpen }}
244
+ hitSlop={8}
245
+ onPress={() => {
246
+ if (agentSearchOpen) closeAgentSearch();
247
+ else openAgentSearch();
248
+ }}
249
+ style={styles.titleAction}
250
+ >
251
+ <Icon
252
+ name={agentSearchOpen ? "X" : "Search"}
253
+ size={14}
254
+ color={theme.colors.foregroundMuted}
255
+ />
256
+ </Pressable>
257
+ <View ref={triggerRef} collapsable={false}>
258
+ <Pressable
259
+ accessibilityRole="button"
260
+ accessibilityLabel="Agent display options"
261
+ accessibilityState={{ expanded: menuOpen }}
262
+ hitSlop={8}
263
+ onPress={onToggleMenu}
264
+ style={styles.titleAction}
265
+ >
266
+ <Icon name="Settings2" size={14} color={theme.colors.foregroundMuted} />
267
+ </Pressable>
268
+ </View>
269
+ </View>
270
+ </View>
271
+ </View>
272
+ <View style={styles.panel}>
273
+ {pageGroups
274
+ ? pageGroups.map(([groupKey, items]) => (
275
+ <View key={groupKey} style={styles.agentGroup}>
276
+ <Text style={styles.groupLabel}>
277
+ {agentGroup === "provider" ? providerLabel(groupKey) : groupKey}
278
+ </Text>
279
+ {items.map(renderAgentRow)}
280
+ </View>
281
+ ))
282
+ : pageItems.map(renderAgentRow)}
283
+ {visibleAgentItems.length === 0 ? (
284
+ <Text style={styles.empty}>
285
+ {statusFiltersEmpty ? "No filters selected" : "No matching agents"}
286
+ </Text>
287
+ ) : null}
288
+ {showPager ? (
289
+ <View style={styles.pagerRow}>
290
+ <Pressable
291
+ accessibilityRole="button"
292
+ accessibilityLabel="Previous agents page"
293
+ accessibilityState={{ disabled: safePage === 0 }}
294
+ disabled={safePage === 0}
295
+ hitSlop={8}
296
+ onPress={() => setPageIndex((p) => Math.max(0, p - 1))}
297
+ style={[styles.pagerButton, safePage === 0 ? styles.pagerButtonDisabled : null]}
298
+ >
299
+ <Icon name="ChevronLeft" size={14} color={theme.colors.foregroundMuted} />
300
+ </Pressable>
301
+ <Text style={styles.pagerLabel}>
302
+ {safePage + 1} / {pageCount}
303
+ </Text>
304
+ <Pressable
305
+ accessibilityRole="button"
306
+ accessibilityLabel="Next agents page"
307
+ accessibilityState={{ disabled: safePage >= pageCount - 1 }}
308
+ disabled={safePage >= pageCount - 1}
309
+ hitSlop={8}
310
+ onPress={() => setPageIndex((p) => Math.min(pageCount - 1, p + 1))}
311
+ style={[
312
+ styles.pagerButton,
313
+ safePage >= pageCount - 1 ? styles.pagerButtonDisabled : null,
314
+ ]}
315
+ >
316
+ <Icon name="ChevronRight" size={14} color={theme.colors.foregroundMuted} />
317
+ </Pressable>
318
+ </View>
319
+ ) : null}
320
+ </View>
321
+ </View>
322
+ );
323
+ }
@@ -0,0 +1,121 @@
1
+ import type { PluginWorkspacePanelProps } from "@getpaseo/plugin/client";
2
+ import type { AgentUsageItem } from "../../shared/usage.ts";
3
+
4
+ export type WorkspaceTheme = PluginWorkspacePanelProps["theme"];
5
+
6
+ export type AgentSort = "created" | "updated" | "name" | "messages" | "status";
7
+ export type AgentGroup = "none" | "provider" | "status";
8
+ export type AgentShowField = "provider" | "calls" | "messages" | "updated";
9
+ /** Archive scope: Active / Archived. */
10
+ export type AgentStatusFilter = "active" | "archived";
11
+ /** Lifecycle for non-archived agents: Idle / Running / Error / Closed. */
12
+ export type AgentLifecycleFilter = "idle" | "running" | "error" | "closed";
13
+ export type MenuFlyout = "sort" | "group" | "show" | "status" | "lifecycle";
14
+
15
+ export type AgentStatusInfo = {
16
+ rank: number;
17
+ updatedAt: string | null;
18
+ status: string | null;
19
+ };
20
+
21
+ export type MenuOption = { id: string; label: string; icon: string };
22
+
23
+ /** Agents header row / search pill height — keep fixed to avoid layout jump. */
24
+ export const AGENT_HEADER_HEIGHT = 28;
25
+ export const SEARCH_ANIM_MS = 220;
26
+ export const SEARCH_TITLE_GAP = 8;
27
+ /** Host MenuFlyout overlap between root surface and submenu (`SUBMENU_OVERLAP`). */
28
+ export const MENU_SUBMENU_OVERLAP = 5;
29
+ export const MENU_WIDTH = 232;
30
+ export const MENU_OPTION_ICON_SIZE = 14;
31
+ /** Approx list-row height (padding + title/meta) for stable Skills/MCP section size. */
32
+ export const RANK_ROW_ESTIMATE = 54;
33
+ /** Visible agents per page in Explorer; pager hidden when pageCount ≤ 1. */
34
+ export const AGENT_PAGE_SIZE = 40;
35
+ export const HOST_AGENT_PAGE_LIMIT = 200;
36
+
37
+ export const SORT_OPTIONS: ReadonlyArray<MenuOption & { id: AgentSort }> = [
38
+ { id: "updated", label: "Updated", icon: "Clock" },
39
+ { id: "created", label: "Created", icon: "CalendarPlus" },
40
+ { id: "name", label: "Name", icon: "Type" },
41
+ { id: "messages", label: "Messages", icon: "MessageSquare" },
42
+ { id: "status", label: "Status", icon: "CircleDashed" },
43
+ ];
44
+
45
+ export const GROUP_OPTIONS: ReadonlyArray<MenuOption & { id: AgentGroup }> = [
46
+ { id: "none", label: "None", icon: "Minus" },
47
+ { id: "provider", label: "Provider", icon: "Server" },
48
+ { id: "status", label: "Status", icon: "CircleDashed" },
49
+ ];
50
+
51
+ export const SHOW_FIELD_OPTIONS: ReadonlyArray<MenuOption & { id: AgentShowField }> = [
52
+ { id: "provider", label: "Provider", icon: "Server" },
53
+ { id: "calls", label: "Calls", icon: "Terminal" },
54
+ { id: "messages", label: "Messages", icon: "MessageSquare" },
55
+ { id: "updated", label: "Updated", icon: "Clock" },
56
+ ];
57
+
58
+ export const STATUS_FILTER_OPTIONS: ReadonlyArray<MenuOption & { id: AgentStatusFilter }> = [
59
+ { id: "active", label: "Active", icon: "CircleCheck" },
60
+ { id: "archived", label: "Archived", icon: "Archive" },
61
+ ];
62
+
63
+ export const LIFECYCLE_FILTER_OPTIONS: ReadonlyArray<
64
+ MenuOption & { id: AgentLifecycleFilter }
65
+ > = [
66
+ { id: "idle", label: "Idle", icon: "Circle" },
67
+ { id: "running", label: "Running", icon: "Play" },
68
+ { id: "error", label: "Error", icon: "CircleAlert" },
69
+ { id: "closed", label: "Closed", icon: "CircleOff" },
70
+ ];
71
+
72
+ export function optionLabel<T extends string>(
73
+ options: ReadonlyArray<{ id: T; label: string }>,
74
+ id: T,
75
+ ): string {
76
+ return options.find((option) => option.id === id)?.label ?? id;
77
+ }
78
+
79
+ /** 0 = attention-worthy, then running / idle / initializing / closed (unknown). */
80
+ export function attentionRank(agent: {
81
+ status?: string;
82
+ requiresAttention?: boolean;
83
+ attentionReason?: string | null;
84
+ }): number {
85
+ if (
86
+ agent.requiresAttention === true ||
87
+ agent.attentionReason === "permission" ||
88
+ agent.attentionReason === "error" ||
89
+ agent.status === "error"
90
+ ) {
91
+ return 0;
92
+ }
93
+ if (agent.status === "running") return 1;
94
+ if (agent.status === "idle") return 2;
95
+ if (agent.status === "initializing") return 3;
96
+ return 4;
97
+ }
98
+
99
+ export function matchesAgentFilters(
100
+ item: AgentUsageItem,
101
+ statusFilters: ReadonlySet<AgentStatusFilter>,
102
+ lifecycleFilters: ReadonlySet<AgentLifecycleFilter>,
103
+ byId: Record<string, AgentStatusInfo> | undefined,
104
+ ): boolean {
105
+ if (item.archivedAt != null) return statusFilters.has("archived");
106
+ if (!statusFilters.has("active")) return false;
107
+ if (lifecycleFilters.size === 0) return false;
108
+ const status = byId?.[item.agentId]?.status;
109
+ if (status === "idle" || status === "running" || status === "error" || status === "closed") {
110
+ return lifecycleFilters.has(status);
111
+ }
112
+ // initializing / unknown: visible when Active is on and any lifecycle is selected
113
+ return true;
114
+ }
115
+
116
+ export function agentUpdatedAt(
117
+ item: AgentUsageItem,
118
+ byId: Record<string, AgentStatusInfo> | undefined,
119
+ ): string | null {
120
+ return item.updatedAt ?? byId?.[item.agentId]?.updatedAt ?? item.lastActivityAt ?? null;
121
+ }
@@ -0,0 +1,116 @@
1
+ import { Icon } from "@getpaseo/plugin/client/react-native";
2
+ import type { ReactNode } from "react";
3
+ import { Pressable, Text, View, type TextStyle, type ViewStyle } from "react-native";
4
+ import { MENU_OPTION_ICON_SIZE, type MenuOption } from "./constants.ts";
5
+
6
+ export type MenuStyles = {
7
+ menuPage: ViewStyle;
8
+ menuRow: ViewStyle;
9
+ menuRowHighlighted: ViewStyle;
10
+ menuLabel: TextStyle;
11
+ menuValue: TextStyle;
12
+ menuTrailing: ViewStyle;
13
+ menuOption: ViewStyle;
14
+ menuOptionLabel: TextStyle;
15
+ menuLeadingSlot: ViewStyle;
16
+ menuSurface: ViewStyle;
17
+ menuRootWrap: ViewStyle;
18
+ menuFlyout: ViewStyle;
19
+ menuSeparator: ViewStyle;
20
+ };
21
+
22
+ export function MenuSubTrigger({
23
+ label,
24
+ value,
25
+ active,
26
+ onOpen,
27
+ styles,
28
+ chevronColor,
29
+ }: {
30
+ label: string;
31
+ value?: string;
32
+ active: boolean;
33
+ onOpen: () => void;
34
+ styles: MenuStyles;
35
+ chevronColor: string;
36
+ }): ReactNode {
37
+ return (
38
+ <View
39
+ // Web: open flyout on hover like host MenuSubTrigger.
40
+ {...({ onPointerEnter: onOpen } as object)}
41
+ >
42
+ <Pressable
43
+ accessibilityRole="button"
44
+ accessibilityState={{ expanded: active }}
45
+ onPress={onOpen}
46
+ style={({ pressed, hovered }: { pressed: boolean; hovered?: boolean }) => [
47
+ styles.menuRow,
48
+ active || pressed || hovered ? styles.menuRowHighlighted : null,
49
+ ]}
50
+ >
51
+ <Text style={styles.menuLabel} numberOfLines={1}>
52
+ {label}
53
+ </Text>
54
+ <View style={styles.menuTrailing}>
55
+ {value ? (
56
+ <Text style={styles.menuValue} numberOfLines={1}>
57
+ {value}
58
+ </Text>
59
+ ) : null}
60
+ <Icon name="ChevronRight" size={14} color={chevronColor} />
61
+ </View>
62
+ </Pressable>
63
+ </View>
64
+ );
65
+ }
66
+
67
+ export function MenuOptionList({
68
+ options,
69
+ selectedId,
70
+ selectedIds,
71
+ onSelect,
72
+ styles,
73
+ checkColor,
74
+ iconColor,
75
+ }: {
76
+ options: ReadonlyArray<MenuOption>;
77
+ selectedId?: string;
78
+ selectedIds?: ReadonlySet<string>;
79
+ onSelect: (id: string) => void;
80
+ styles: MenuStyles;
81
+ checkColor: string;
82
+ iconColor: string;
83
+ }): ReactNode {
84
+ return (
85
+ <View style={styles.menuPage}>
86
+ {options.map((option) => {
87
+ const selected =
88
+ selectedIds != null ? selectedIds.has(option.id) : selectedId === option.id;
89
+ return (
90
+ <Pressable
91
+ key={option.id}
92
+ accessibilityRole="button"
93
+ accessibilityState={{ selected }}
94
+ onPress={() => onSelect(option.id)}
95
+ style={({ pressed, hovered }: { pressed: boolean; hovered?: boolean }) => [
96
+ styles.menuOption,
97
+ pressed || hovered ? styles.menuRowHighlighted : null,
98
+ ]}
99
+ >
100
+ <View style={styles.menuLeadingSlot}>
101
+ <Icon name={option.icon} size={MENU_OPTION_ICON_SIZE} color={iconColor} />
102
+ </View>
103
+ <Text style={styles.menuOptionLabel} numberOfLines={1}>
104
+ {option.label}
105
+ </Text>
106
+ {selected ? (
107
+ <View style={styles.menuTrailing}>
108
+ <Icon name="Check" size={16} color={checkColor} />
109
+ </View>
110
+ ) : null}
111
+ </Pressable>
112
+ );
113
+ })}
114
+ </View>
115
+ );
116
+ }
@@ -0,0 +1,30 @@
1
+ import { matchesAgentTitleSearch } from "../../shared/agent-title-search.ts";
2
+ import { formatUpdatedAt } from "../../shared/format.ts";
3
+ import { providerLabel, type AgentUsageItem } from "../../shared/usage.ts";
4
+ import {
5
+ type AgentShowField,
6
+ type AgentStatusInfo,
7
+ agentUpdatedAt,
8
+ } from "./constants.ts";
9
+
10
+ export function matchesAgentTitle(item: AgentUsageItem, query: string): boolean {
11
+ return matchesAgentTitleSearch(item.title ?? item.agentId, query);
12
+ }
13
+
14
+ export function formatAgentMeta(
15
+ item: AgentUsageItem,
16
+ showFields: ReadonlySet<AgentShowField>,
17
+ byId: Record<string, AgentStatusInfo> | undefined,
18
+ locale: string,
19
+ ): string | null {
20
+ const parts: string[] = [];
21
+ if (showFields.has("provider")) parts.push(providerLabel(item.provider));
22
+ if (showFields.has("calls")) parts.push(`${item.callCount} calls`);
23
+ if (showFields.has("messages")) parts.push(`${item.messageCount} messages`);
24
+ if (showFields.has("updated")) {
25
+ const at = agentUpdatedAt(item, byId);
26
+ if (at) parts.push(formatUpdatedAt(at, locale));
27
+ }
28
+ if (parts.length === 0) return null;
29
+ return parts.join(" · ");
30
+ }
@@ -0,0 +1,57 @@
1
+ import { listAllAgentPages } from "../../shared/list-agent-pages.ts";
2
+ import {
3
+ attentionRank,
4
+ HOST_AGENT_PAGE_LIMIT,
5
+ type AgentStatusInfo,
6
+ } from "./constants.ts";
7
+
8
+ type HostAgentEntry = {
9
+ agent: {
10
+ id: string;
11
+ workspaceId?: string;
12
+ status?: string;
13
+ updatedAt?: string;
14
+ requiresAttention?: boolean;
15
+ attentionReason?: string | null;
16
+ };
17
+ };
18
+
19
+ type HostAgentsApi = {
20
+ agents: {
21
+ list: (options: {
22
+ filter?: { includeArchived?: boolean };
23
+ page?: { limit: number; cursor?: string };
24
+ }) => Promise<{
25
+ entries: ReadonlyArray<HostAgentEntry>;
26
+ pageInfo: { hasMore: boolean; nextCursor: string | null };
27
+ }>;
28
+ };
29
+ };
30
+
31
+ /** Fetch all host agents (paged) and build workspace-scoped status enrichment. */
32
+ export async function loadWorkspaceAgentStatuses(
33
+ paseo: HostAgentsApi,
34
+ workspaceId: string,
35
+ ): Promise<Record<string, AgentStatusInfo>> {
36
+ const entries = await listAllAgentPages(
37
+ async (cursor) => {
38
+ const result = await paseo.agents.list({
39
+ filter: { includeArchived: true },
40
+ page: { limit: HOST_AGENT_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
41
+ });
42
+ return { entries: result.entries, pageInfo: result.pageInfo };
43
+ },
44
+ );
45
+
46
+ const map: Record<string, AgentStatusInfo> = {};
47
+ for (const entry of entries) {
48
+ const agent = entry.agent;
49
+ if (agent.workspaceId && agent.workspaceId !== workspaceId) continue;
50
+ map[agent.id] = {
51
+ rank: attentionRank(agent),
52
+ updatedAt: agent.updatedAt ?? null,
53
+ status: agent.status ?? null,
54
+ };
55
+ }
56
+ return map;
57
+ }