@koinzhang/paseo-plugin-activity 0.1.0 → 0.3.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 +81 -0
- package/README.md +85 -0
- package/client/activity-heatmap.tsx +72 -14
- package/client/formatted-time.tsx +23 -0
- package/client/global-surface.tsx +24 -25
- package/client/hidden-pill-recheck.test.ts +33 -0
- package/client/hidden-pill-recheck.ts +22 -0
- package/client/panel.tsx +116 -107
- package/client/pill-directory.test.ts +92 -0
- package/client/pill-directory.ts +79 -0
- package/client/pill.tsx +23 -23
- package/client/range.ts +20 -0
- package/client/usage-popover.tsx +75 -84
- package/client/usage-query.tsx +8 -3
- package/client/usage-stats.tsx +7 -5
- package/client/use-agent-turn-end.ts +69 -0
- package/client/workspace/agent-row.tsx +167 -0
- package/client/workspace/agents-section.tsx +330 -0
- package/client/workspace/constants.ts +147 -0
- package/client/workspace/display-menu.tsx +116 -0
- package/client/workspace/filters.ts +30 -0
- package/client/workspace/list-host-agents.test.ts +45 -0
- package/client/workspace/list-host-agents.ts +90 -0
- package/client/workspace/panel.tsx +964 -0
- package/client/workspace/rank-section.tsx +131 -0
- package/client/workspace/running-indicator.tsx +54 -0
- package/client/workspace/status-cache.test.ts +62 -0
- package/client/workspace/status-cache.ts +19 -0
- package/client/workspace/terminal-preview.test.ts +17 -0
- package/client/workspace/terminal-preview.ts +10 -0
- package/client/workspace/terminals-section.tsx +155 -0
- package/client/workspace-panel.tsx +2 -0
- package/index.client.tsx +20 -13
- package/index.server.ts +13 -0
- package/package.json +9 -3
- package/server/agents.test.ts +36 -1
- package/server/agents.ts +9 -5
- package/server/background-sync.test.ts +14 -3
- package/server/background-sync.ts +16 -5
- package/server/handlers-query.test.ts +82 -3
- package/server/handlers.ts +89 -6
- package/server/messages.test.ts +8 -2
- package/server/skill-path.ts +3 -20
- package/server/store.test.ts +13 -0
- package/server/store.ts +2 -2
- package/shared/activity.test.ts +22 -12
- package/shared/activity.ts +8 -13
- package/shared/agent-page-size.test.ts +11 -0
- package/shared/agent-title-search.test.ts +28 -0
- package/shared/agent-title-search.ts +12 -0
- package/shared/explorer-agent-display.ts +30 -0
- package/shared/format.test.ts +41 -16
- package/shared/format.ts +26 -17
- package/shared/home-path.ts +19 -0
- package/shared/insights.test.ts +38 -18
- package/shared/insights.ts +38 -19
- package/shared/list-agent-pages.test.ts +51 -0
- package/shared/list-agent-pages.ts +31 -0
- package/shared/usage.test.ts +248 -0
- package/shared/usage.ts +336 -11
package/client/usage-popover.tsx
CHANGED
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
usageReadSkillRpc,
|
|
19
19
|
} from "../shared/usage.ts";
|
|
20
|
-
import {
|
|
20
|
+
import { formatDisplayName } from "../shared/format.ts";
|
|
21
|
+
import { FormattedTime } from "./formatted-time.tsx";
|
|
21
22
|
import { useUsagePillData } from "./usage-query.tsx";
|
|
22
23
|
|
|
23
24
|
const MONO = Platform.select({ ios: "Menlo", default: "monospace" });
|
|
@@ -111,28 +112,25 @@ function UsagePopoverAgent(
|
|
|
111
112
|
minWidth: compact ? undefined : 300,
|
|
112
113
|
maxWidth: compact ? undefined : 380,
|
|
113
114
|
},
|
|
114
|
-
|
|
115
|
+
sectionHeaderRow: {
|
|
115
116
|
flexDirection: "row" as const,
|
|
116
117
|
alignItems: "center" as const,
|
|
117
|
-
|
|
118
|
-
gap:
|
|
119
|
-
},
|
|
120
|
-
rangeSegment: {
|
|
121
|
-
paddingVertical: 8,
|
|
122
|
-
},
|
|
123
|
-
rangeSegmentActive: {
|
|
124
|
-
borderBottomWidth: 1,
|
|
125
|
-
borderBottomColor: theme.colors.foreground,
|
|
126
|
-
},
|
|
127
|
-
chipText: {
|
|
128
|
-
color: theme.colors.foregroundMuted,
|
|
129
|
-
fontSize: 12,
|
|
130
|
-
fontWeight: "500" as const,
|
|
118
|
+
justifyContent: "space-between" as const,
|
|
119
|
+
gap: 8,
|
|
131
120
|
},
|
|
132
|
-
|
|
121
|
+
sectionTitle: {
|
|
133
122
|
color: theme.colors.foreground,
|
|
134
|
-
fontSize:
|
|
123
|
+
fontSize: 14,
|
|
135
124
|
fontWeight: "600" as const,
|
|
125
|
+
flexShrink: 1,
|
|
126
|
+
},
|
|
127
|
+
titleAction: {
|
|
128
|
+
width: 24,
|
|
129
|
+
height: 24,
|
|
130
|
+
alignItems: "center" as const,
|
|
131
|
+
justifyContent: "center" as const,
|
|
132
|
+
borderRadius: 6,
|
|
133
|
+
flexShrink: 0,
|
|
136
134
|
},
|
|
137
135
|
list: {
|
|
138
136
|
gap: 0,
|
|
@@ -159,11 +157,6 @@ function UsagePopoverAgent(
|
|
|
159
157
|
fontSize: 13,
|
|
160
158
|
fontWeight: "500" as const,
|
|
161
159
|
},
|
|
162
|
-
rowLink: {
|
|
163
|
-
color: theme.colors.foreground,
|
|
164
|
-
fontSize: 13,
|
|
165
|
-
fontWeight: "500" as const,
|
|
166
|
-
},
|
|
167
160
|
rowMeta: {
|
|
168
161
|
color: theme.colors.foregroundMuted,
|
|
169
162
|
fontSize: 11,
|
|
@@ -199,17 +192,16 @@ function UsagePopoverAgent(
|
|
|
199
192
|
fontWeight: "500" as const,
|
|
200
193
|
},
|
|
201
194
|
panelButton: {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
borderRadius: 8,
|
|
205
|
-
backgroundColor: theme.colors.surface2,
|
|
206
|
-
flexDirection: "row" as const,
|
|
195
|
+
width: 24,
|
|
196
|
+
height: 24,
|
|
207
197
|
alignItems: "center" as const,
|
|
208
|
-
|
|
198
|
+
justifyContent: "center" as const,
|
|
199
|
+
borderRadius: 6,
|
|
200
|
+
flexShrink: 0,
|
|
209
201
|
},
|
|
210
202
|
title: {
|
|
211
203
|
color: theme.colors.foreground,
|
|
212
|
-
fontSize:
|
|
204
|
+
fontSize: 14,
|
|
213
205
|
fontWeight: "600" as const,
|
|
214
206
|
flexShrink: 1,
|
|
215
207
|
},
|
|
@@ -226,11 +218,13 @@ function UsagePopoverAgent(
|
|
|
226
218
|
[theme, compact],
|
|
227
219
|
);
|
|
228
220
|
|
|
229
|
-
// Cached pill data (QueryClient or module cache) must paint immediately; only
|
|
230
|
-
// spin when we have nothing to show yet.
|
|
231
221
|
const loading = !usage.data && usage.isLoading;
|
|
232
222
|
const error = usage.error;
|
|
233
|
-
const
|
|
223
|
+
const showToggle = skillItems.length > 0 && mcpItems.length > 0;
|
|
224
|
+
const toggleAction =
|
|
225
|
+
tab === "skills"
|
|
226
|
+
? { icon: "Plug" as const, accessibilityLabel: "Show MCP", next: "mcp" as const }
|
|
227
|
+
: { icon: "Sparkles" as const, accessibilityLabel: "Show skills", next: "skills" as const };
|
|
234
228
|
|
|
235
229
|
if (skillDetail) {
|
|
236
230
|
return (
|
|
@@ -248,14 +242,14 @@ function UsagePopoverAgent(
|
|
|
248
242
|
<Pressable
|
|
249
243
|
accessibilityRole="button"
|
|
250
244
|
accessibilityLabel="Open SKILL.md in panel"
|
|
245
|
+
hitSlop={8}
|
|
251
246
|
style={styles.panelButton}
|
|
252
247
|
onPress={() => {
|
|
253
248
|
openSkillInPanel(skillDetail);
|
|
254
249
|
close();
|
|
255
250
|
}}
|
|
256
251
|
>
|
|
257
|
-
<Icon name="ArrowUpRight" size={
|
|
258
|
-
<Text style={styles.back}>Open in tab</Text>
|
|
252
|
+
<Icon name="ArrowUpRight" size={16} color={theme.colors.foregroundMuted} />
|
|
259
253
|
</Pressable>
|
|
260
254
|
) : null}
|
|
261
255
|
</View>
|
|
@@ -277,33 +271,24 @@ function UsagePopoverAgent(
|
|
|
277
271
|
|
|
278
272
|
return (
|
|
279
273
|
<View style={styles.root}>
|
|
280
|
-
{
|
|
281
|
-
<View style={
|
|
282
|
-
<Text style={styles.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
accessibilityRole="tab"
|
|
299
|
-
accessibilityState={{ selected: active }}
|
|
300
|
-
onPress={() => setTab(id)}
|
|
301
|
-
style={[styles.rangeSegment, active ? styles.rangeSegmentActive : null]}
|
|
302
|
-
>
|
|
303
|
-
<Text style={active ? styles.chipTextActive : styles.chipText}>{label}</Text>
|
|
304
|
-
</Pressable>
|
|
305
|
-
);
|
|
306
|
-
})}
|
|
274
|
+
{tab && (skillItems.length > 0 || mcpItems.length > 0) ? (
|
|
275
|
+
<View style={styles.sectionHeaderRow}>
|
|
276
|
+
<Text style={styles.sectionTitle}>{tab === "skills" ? "Skills" : "MCP"}</Text>
|
|
277
|
+
{showToggle ? (
|
|
278
|
+
<Pressable
|
|
279
|
+
accessibilityRole="button"
|
|
280
|
+
accessibilityLabel={toggleAction.accessibilityLabel}
|
|
281
|
+
hitSlop={8}
|
|
282
|
+
onPress={() => setTab(toggleAction.next)}
|
|
283
|
+
style={styles.titleAction}
|
|
284
|
+
>
|
|
285
|
+
<Icon
|
|
286
|
+
name={toggleAction.icon}
|
|
287
|
+
size={16}
|
|
288
|
+
color={theme.colors.foregroundMuted}
|
|
289
|
+
/>
|
|
290
|
+
</Pressable>
|
|
291
|
+
) : null}
|
|
307
292
|
</View>
|
|
308
293
|
) : null}
|
|
309
294
|
|
|
@@ -322,33 +307,39 @@ function UsagePopoverAgent(
|
|
|
322
307
|
<View style={styles.list}>
|
|
323
308
|
{skillItems.map((item, index) => {
|
|
324
309
|
const name = formatDisplayName(item.skillName);
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
accessibilityLabel={`Open ${name} SKILL.md`}
|
|
329
|
-
onPress={() =>
|
|
330
|
-
setSkillDetail({ skillName: item.skillName, path: item.skillPath! })
|
|
331
|
-
}
|
|
332
|
-
>
|
|
333
|
-
<Text style={styles.rowLink} numberOfLines={1}>
|
|
334
|
-
{name}
|
|
335
|
-
</Text>
|
|
336
|
-
</Pressable>
|
|
337
|
-
) : (
|
|
338
|
-
<Text style={styles.rowTitle} numberOfLines={1}>
|
|
339
|
-
{name}
|
|
340
|
-
</Text>
|
|
341
|
-
);
|
|
342
|
-
return (
|
|
343
|
-
<View key={item.skillName} style={[styles.row, index === 0 ? styles.rowFirst : null]}>
|
|
310
|
+
const rowStyle = [styles.row, index === 0 ? styles.rowFirst : null];
|
|
311
|
+
const content = (
|
|
312
|
+
<>
|
|
344
313
|
<Icon name="Sparkles" size={16} color={theme.colors.foregroundMuted} />
|
|
345
314
|
<View style={styles.rowMain}>
|
|
346
|
-
{
|
|
315
|
+
<Text style={styles.rowTitle} numberOfLines={1}>
|
|
316
|
+
{name}
|
|
317
|
+
</Text>
|
|
347
318
|
{item.lastUsedAt ? (
|
|
348
|
-
<
|
|
319
|
+
<FormattedTime iso={item.lastUsedAt} style={styles.rowMeta} />
|
|
349
320
|
) : null}
|
|
350
321
|
</View>
|
|
351
322
|
<CountBadge value={item.total} styles={styles} />
|
|
323
|
+
</>
|
|
324
|
+
);
|
|
325
|
+
if (item.skillPath) {
|
|
326
|
+
return (
|
|
327
|
+
<Pressable
|
|
328
|
+
key={item.skillName}
|
|
329
|
+
accessibilityRole="link"
|
|
330
|
+
accessibilityLabel={`Open ${name} SKILL.md`}
|
|
331
|
+
onPress={() =>
|
|
332
|
+
setSkillDetail({ skillName: item.skillName, path: item.skillPath! })
|
|
333
|
+
}
|
|
334
|
+
style={rowStyle}
|
|
335
|
+
>
|
|
336
|
+
{content}
|
|
337
|
+
</Pressable>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
return (
|
|
341
|
+
<View key={item.skillName} style={rowStyle}>
|
|
342
|
+
{content}
|
|
352
343
|
</View>
|
|
353
344
|
);
|
|
354
345
|
})}
|
|
@@ -370,7 +361,7 @@ function UsagePopoverAgent(
|
|
|
370
361
|
{item.failures > 0 ? (
|
|
371
362
|
<Text style={styles.rowMeta}>{item.failures} failed</Text>
|
|
372
363
|
) : item.lastUsedAt ? (
|
|
373
|
-
<
|
|
364
|
+
<FormattedTime iso={item.lastUsedAt} style={styles.rowMeta} />
|
|
374
365
|
) : null}
|
|
375
366
|
</View>
|
|
376
367
|
<CountBadge value={item.count} styles={styles} />
|
package/client/usage-query.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRpc } from "@getpaseo/plugin/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import {
|
|
4
4
|
usageMcpByToolRpc,
|
|
5
5
|
usageSkillsByNameRpc,
|
|
@@ -10,17 +10,22 @@ import {
|
|
|
10
10
|
writePillDataCache,
|
|
11
11
|
type UsagePillData,
|
|
12
12
|
} from "./pill-data-cache.ts";
|
|
13
|
+
import { useAgentTurnEnd } from "./use-agent-turn-end.ts";
|
|
13
14
|
|
|
14
15
|
export type { UsagePillData } from "./pill-data-cache.ts";
|
|
15
16
|
export { __setPillDataCacheForTests, clearPillDataCache } from "./pill-data-cache.ts";
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
const EMPTY_REFETCH_MS =
|
|
18
|
+
/** Fallback poll while empty; host turn-end events drive the fast path. */
|
|
19
|
+
const EMPTY_REFETCH_MS = 5_000;
|
|
19
20
|
|
|
20
21
|
/** Current-agent skills/mcp breakdown for the composer pill (no summary — unused in UI). */
|
|
21
22
|
export function useUsagePillData(agentId: string) {
|
|
22
23
|
const skillsRpc = useRpc(usageSkillsByNameRpc);
|
|
23
24
|
const mcpRpc = useRpc(usageMcpByToolRpc);
|
|
25
|
+
const queryClient = useQueryClient();
|
|
26
|
+
useAgentTurnEnd({ agentId }, () => {
|
|
27
|
+
void queryClient.invalidateQueries({ queryKey: ["activity", "pill", "agent", agentId] });
|
|
28
|
+
});
|
|
24
29
|
return useQuery({
|
|
25
30
|
queryKey: ["activity", "pill", "agent", agentId],
|
|
26
31
|
queryFn: async () => {
|
package/client/usage-stats.tsx
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { Text, View } from "react-native";
|
|
2
2
|
|
|
3
|
-
export function UsageStats({ items, colors, compact }: {
|
|
3
|
+
export function UsageStats({ items, colors, compact, dense }: {
|
|
4
4
|
items: ReadonlyArray<{ label: string; value: string }>;
|
|
5
5
|
colors: { border: string; foreground: string; foregroundMuted: string };
|
|
6
6
|
compact: boolean;
|
|
7
|
+
/** Smaller numbers / labels / padding (025). */
|
|
8
|
+
dense?: boolean;
|
|
7
9
|
}) {
|
|
8
10
|
return (
|
|
9
|
-
<View style={{ flexDirection: "row", flexWrap: "wrap", borderWidth: 1, borderColor: colors.border, borderRadius: 20, paddingVertical: compact ? 8 : 18, rowGap: 16 }}>
|
|
11
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", borderWidth: 1, borderColor: colors.border, borderRadius: 20, paddingVertical: dense ? 6 : compact ? 8 : 18, rowGap: dense ? 10 : 16 }}>
|
|
10
12
|
{items.map((item, index) => (
|
|
11
|
-
<View key={item.label} style={{ flexGrow: 1, flexBasis: compact ? 100 : 120, minWidth: 0, alignItems: "center", paddingHorizontal: 12, paddingVertical: 4, gap: 6, borderLeftWidth: index === 0 || compact ? 0 : 1, borderLeftColor: colors.border }}>
|
|
12
|
-
<Text style={{ color: colors.foreground, fontSize:
|
|
13
|
-
<Text style={{ color: colors.foregroundMuted, fontSize:
|
|
13
|
+
<View key={item.label} style={{ flexGrow: 1, flexBasis: dense ? 84 : compact ? 100 : 120, minWidth: 0, alignItems: "center", paddingHorizontal: dense ? 8 : 12, paddingVertical: dense ? 2 : 4, gap: dense ? 4 : 6, borderLeftWidth: index === 0 || compact ? 0 : 1, borderLeftColor: colors.border }}>
|
|
14
|
+
<Text style={{ color: colors.foreground, fontSize: 18, fontWeight: "500", fontVariant: ["tabular-nums"] }}>{item.value}</Text>
|
|
15
|
+
<Text style={{ color: colors.foregroundMuted, fontSize: 12 }}>{item.label}</Text>
|
|
14
16
|
</View>
|
|
15
17
|
))}
|
|
16
18
|
</View>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { usePaseo } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
|
|
4
|
+
const TURN_END_DEBOUNCE_MS = 300;
|
|
5
|
+
const INGEST_SETTLE_MS = 2_000;
|
|
6
|
+
|
|
7
|
+
type AgentTurnEndScope = {
|
|
8
|
+
agentId?: string;
|
|
9
|
+
workspaceId?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Shared debounce/ingest settle scheduling; callers choose the signal explicitly. */
|
|
13
|
+
function useActivityRefresh(scope: AgentTurnEndScope, onTurnEnd: () => void): void {
|
|
14
|
+
const paseo = usePaseo();
|
|
15
|
+
const { agentId, workspaceId } = scope;
|
|
16
|
+
const callbackRef = useRef(onTurnEnd);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
callbackRef.current = onTurnEnd;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
let debounce: ReturnType<typeof setTimeout> | null = null;
|
|
24
|
+
let settle: ReturnType<typeof setTimeout> | null = null;
|
|
25
|
+
const schedule = () => {
|
|
26
|
+
if (debounce != null) clearTimeout(debounce);
|
|
27
|
+
if (settle != null) clearTimeout(settle);
|
|
28
|
+
debounce = setTimeout(() => {
|
|
29
|
+
debounce = null;
|
|
30
|
+
callbackRef.current();
|
|
31
|
+
}, TURN_END_DEBOUNCE_MS);
|
|
32
|
+
settle = setTimeout(() => {
|
|
33
|
+
settle = null;
|
|
34
|
+
callbackRef.current();
|
|
35
|
+
}, INGEST_SETTLE_MS);
|
|
36
|
+
};
|
|
37
|
+
const unsubscribe = agentId != null
|
|
38
|
+
? paseo.agents.ref(agentId).timeline.subscribe(({ event }) => {
|
|
39
|
+
if (["turn_completed", "turn_failed", "turn_canceled", "replacement"].includes(event.type)) schedule();
|
|
40
|
+
})
|
|
41
|
+
: paseo.agents.subscribe((update) => {
|
|
42
|
+
// Workspace-wide hint only. The 15s query poll owns completeness.
|
|
43
|
+
if (update.kind !== "upsert") return;
|
|
44
|
+
const agent = update.agent;
|
|
45
|
+
if (agent.workspaceId !== workspaceId) return;
|
|
46
|
+
if (agent.status !== "running" && agent.status !== "initializing") schedule();
|
|
47
|
+
});
|
|
48
|
+
if ("ready" in unsubscribe) {
|
|
49
|
+
void (unsubscribe.ready as Promise<void>).catch((error: unknown) => {
|
|
50
|
+
console.error("[activity] timeline observation failed; polling remains active", error);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return () => {
|
|
54
|
+
unsubscribe();
|
|
55
|
+
if (debounce != null) clearTimeout(debounce);
|
|
56
|
+
if (settle != null) clearTimeout(settle);
|
|
57
|
+
};
|
|
58
|
+
}, [paseo, agentId, workspaceId]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Actual turn terminal events; directory status does not imply completion. */
|
|
62
|
+
export function useAgentTurnEnd(scope: { agentId: string }, onTurnEnd: () => void): void {
|
|
63
|
+
useActivityRefresh(scope, onTurnEnd);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Best-effort directory hint, never a turn-end signal. */
|
|
67
|
+
export function useWorkspaceActivityRefresh(workspaceId: string, refresh: () => void): void {
|
|
68
|
+
useActivityRefresh({ workspaceId }, refresh);
|
|
69
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import {
|
|
4
|
+
ActivityIndicator,
|
|
5
|
+
Platform,
|
|
6
|
+
Pressable,
|
|
7
|
+
Text,
|
|
8
|
+
View,
|
|
9
|
+
type TextStyle,
|
|
10
|
+
type ViewStyle,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import type { AgentAttentionKind, WorkspaceTheme } from "./constants.ts";
|
|
13
|
+
import { RunningIndicator } from "./running-indicator.tsx";
|
|
14
|
+
|
|
15
|
+
export type AgentRowStyles = {
|
|
16
|
+
agentListRow: ViewStyle;
|
|
17
|
+
agentIconWrap: ViewStyle;
|
|
18
|
+
runningBadge: ViewStyle;
|
|
19
|
+
listMain: ViewStyle;
|
|
20
|
+
listLink: TextStyle;
|
|
21
|
+
listTitle: TextStyle;
|
|
22
|
+
listMeta: TextStyle;
|
|
23
|
+
titleAction: ViewStyle;
|
|
24
|
+
permissionBadge: ViewStyle;
|
|
25
|
+
permissionBadgeText: TextStyle;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function AgentRow({
|
|
29
|
+
label,
|
|
30
|
+
archived,
|
|
31
|
+
canOpen,
|
|
32
|
+
meta,
|
|
33
|
+
permissionCount,
|
|
34
|
+
attentionKind,
|
|
35
|
+
running,
|
|
36
|
+
busy,
|
|
37
|
+
actionDisabled,
|
|
38
|
+
theme,
|
|
39
|
+
styles,
|
|
40
|
+
onOpen,
|
|
41
|
+
onArchiveToggle,
|
|
42
|
+
}: {
|
|
43
|
+
label: string;
|
|
44
|
+
archived: boolean;
|
|
45
|
+
canOpen: boolean;
|
|
46
|
+
meta: string | null;
|
|
47
|
+
permissionCount: number;
|
|
48
|
+
attentionKind: AgentAttentionKind;
|
|
49
|
+
running: boolean;
|
|
50
|
+
busy: boolean;
|
|
51
|
+
actionDisabled: boolean;
|
|
52
|
+
theme: WorkspaceTheme;
|
|
53
|
+
styles: AgentRowStyles;
|
|
54
|
+
onOpen: () => void;
|
|
55
|
+
onArchiveToggle: () => void;
|
|
56
|
+
}): ReactNode {
|
|
57
|
+
const [hovered, setHovered] = useState(false);
|
|
58
|
+
// Web: hover-reveal. Native has no hover — keep the action visible.
|
|
59
|
+
// mouseenter/leave (not nested Pressable hover) so title/action don't flicker.
|
|
60
|
+
const showAction = Platform.OS !== "web" || hovered || busy;
|
|
61
|
+
const hoverProps =
|
|
62
|
+
Platform.OS === "web"
|
|
63
|
+
? ({
|
|
64
|
+
onMouseEnter: () => setHovered(true),
|
|
65
|
+
onMouseLeave: () => setHovered(false),
|
|
66
|
+
} as object)
|
|
67
|
+
: null;
|
|
68
|
+
|
|
69
|
+
const botColor =
|
|
70
|
+
!archived && attentionKind === "error"
|
|
71
|
+
? theme.colors.statusDanger
|
|
72
|
+
: !archived && attentionKind === "permission"
|
|
73
|
+
? theme.colors.statusWarning
|
|
74
|
+
: !archived && attentionKind === "finished"
|
|
75
|
+
? theme.colors.statusSuccess
|
|
76
|
+
: theme.colors.foregroundMuted;
|
|
77
|
+
const stateLabels: string[] = [];
|
|
78
|
+
if (!archived && running) stateLabels.push("running");
|
|
79
|
+
if (permissionCount > 0) {
|
|
80
|
+
stateLabels.push(
|
|
81
|
+
permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (!archived && attentionKind === "error") stateLabels.push("failed");
|
|
85
|
+
if (!archived && attentionKind === "finished") stateLabels.push("turn finished, unread");
|
|
86
|
+
const stateSuffix = stateLabels.length > 0 ? `, ${stateLabels.join(", ")}` : "";
|
|
87
|
+
|
|
88
|
+
const body = (
|
|
89
|
+
<>
|
|
90
|
+
<View style={styles.agentIconWrap}>
|
|
91
|
+
<Icon
|
|
92
|
+
name={archived ? "BotOff" : "Bot"}
|
|
93
|
+
size={18}
|
|
94
|
+
color={botColor}
|
|
95
|
+
/>
|
|
96
|
+
{running && !archived ? (
|
|
97
|
+
<View style={styles.runningBadge}>
|
|
98
|
+
<RunningIndicator theme={theme} />
|
|
99
|
+
</View>
|
|
100
|
+
) : null}
|
|
101
|
+
</View>
|
|
102
|
+
<View style={styles.listMain}>
|
|
103
|
+
<Text style={canOpen ? styles.listLink : styles.listTitle} numberOfLines={1}>
|
|
104
|
+
{label}
|
|
105
|
+
</Text>
|
|
106
|
+
{meta ? (
|
|
107
|
+
<Text style={styles.listMeta} numberOfLines={1}>
|
|
108
|
+
{meta}
|
|
109
|
+
</Text>
|
|
110
|
+
) : null}
|
|
111
|
+
</View>
|
|
112
|
+
{permissionCount > 0 ? (
|
|
113
|
+
<View
|
|
114
|
+
accessibilityLabel={
|
|
115
|
+
permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`
|
|
116
|
+
}
|
|
117
|
+
style={styles.permissionBadge}
|
|
118
|
+
>
|
|
119
|
+
<Icon name="ShieldAlert" size={12} color={theme.colors.statusWarning} />
|
|
120
|
+
{permissionCount > 1 ? (
|
|
121
|
+
<Text style={styles.permissionBadgeText}>{permissionCount}</Text>
|
|
122
|
+
) : null}
|
|
123
|
+
</View>
|
|
124
|
+
) : null}
|
|
125
|
+
<Pressable
|
|
126
|
+
accessibilityRole="button"
|
|
127
|
+
accessibilityLabel={archived ? `Unarchive ${label}` : `Archive ${label}`}
|
|
128
|
+
accessibilityState={{ disabled: actionDisabled }}
|
|
129
|
+
disabled={actionDisabled || !showAction}
|
|
130
|
+
hitSlop={8}
|
|
131
|
+
onPress={onArchiveToggle}
|
|
132
|
+
pointerEvents={showAction ? "auto" : "none"}
|
|
133
|
+
style={[styles.titleAction, { opacity: showAction ? 1 : 0 }]}
|
|
134
|
+
>
|
|
135
|
+
{busy ? (
|
|
136
|
+
<ActivityIndicator size="small" color={theme.colors.foregroundMuted} />
|
|
137
|
+
) : (
|
|
138
|
+
<Icon
|
|
139
|
+
name={archived ? "ArchiveRestore" : "Archive"}
|
|
140
|
+
size={14}
|
|
141
|
+
color={theme.colors.foregroundMuted}
|
|
142
|
+
/>
|
|
143
|
+
)}
|
|
144
|
+
</Pressable>
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (canOpen) {
|
|
149
|
+
return (
|
|
150
|
+
<Pressable
|
|
151
|
+
accessibilityRole="link"
|
|
152
|
+
accessibilityLabel={`Open conversation ${label}${stateSuffix}`}
|
|
153
|
+
onPress={onOpen}
|
|
154
|
+
style={styles.agentListRow}
|
|
155
|
+
{...hoverProps}
|
|
156
|
+
>
|
|
157
|
+
{body}
|
|
158
|
+
</Pressable>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<View style={styles.agentListRow} {...hoverProps}>
|
|
164
|
+
{body}
|
|
165
|
+
</View>
|
|
166
|
+
);
|
|
167
|
+
}
|