@koinzhang/paseo-plugin-activity 0.2.0 → 0.4.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 (55) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/README.md +26 -11
  3. package/client/attention-agents.test.ts +94 -0
  4. package/client/attention-agents.ts +67 -0
  5. package/client/attention-pill.tsx +254 -0
  6. package/client/attention-popover.tsx +161 -0
  7. package/client/attention-status-store.ts +47 -0
  8. package/client/formatted-time.tsx +23 -0
  9. package/client/global-surface.tsx +3 -1
  10. package/client/hidden-pill-recheck.test.ts +33 -0
  11. package/client/hidden-pill-recheck.ts +22 -0
  12. package/client/latest-user-message.test.ts +34 -0
  13. package/client/latest-user-message.ts +96 -0
  14. package/client/open-agent.ts +32 -0
  15. package/client/panel.tsx +117 -107
  16. package/client/pill-directory.test.ts +92 -0
  17. package/client/pill-directory.ts +79 -0
  18. package/client/pill.tsx +23 -23
  19. package/client/usage-popover.tsx +75 -84
  20. package/client/usage-query.tsx +8 -3
  21. package/client/usage-stats.tsx +2 -2
  22. package/client/use-agent-turn-end.ts +72 -0
  23. package/client/use-latest-user-message.ts +15 -0
  24. package/client/use-workspace-agent-statuses.ts +47 -0
  25. package/client/workspace/agent-live-status-sync.tsx +103 -0
  26. package/client/workspace/agent-row.tsx +105 -28
  27. package/client/workspace/agents-section.tsx +92 -17
  28. package/client/workspace/constants.test.ts +66 -0
  29. package/client/workspace/constants.ts +66 -4
  30. package/client/workspace/filters.test.ts +59 -0
  31. package/client/workspace/filters.ts +11 -2
  32. package/client/workspace/list-host-agents.test.ts +103 -0
  33. package/client/workspace/list-host-agents.ts +113 -23
  34. package/client/workspace/panel.tsx +192 -12
  35. package/client/workspace/rank-section.tsx +36 -26
  36. package/client/workspace/running-indicator.tsx +54 -0
  37. package/client/workspace/status-cache.test.ts +62 -0
  38. package/client/workspace/status-cache.ts +23 -0
  39. package/client/workspace/terminal-preview.test.ts +17 -0
  40. package/client/workspace/terminal-preview.ts +10 -0
  41. package/client/workspace/terminals-section.tsx +155 -0
  42. package/index.client.tsx +7 -1
  43. package/index.server.ts +2 -0
  44. package/package.json +3 -3
  45. package/server/agents.test.ts +16 -0
  46. package/server/agents.ts +7 -4
  47. package/server/handlers-query.test.ts +24 -3
  48. package/server/handlers.ts +17 -5
  49. package/server/skill-path.ts +3 -20
  50. package/shared/explorer-agent-display.ts +1 -1
  51. package/shared/format.test.ts +35 -31
  52. package/shared/format.ts +21 -36
  53. package/shared/home-path.ts +19 -0
  54. package/shared/usage.test.ts +8 -2
  55. package/shared/usage.ts +16 -0
@@ -17,7 +17,8 @@ import {
17
17
  import {
18
18
  usageReadSkillRpc,
19
19
  } from "../shared/usage.ts";
20
- import { formatDayTime, formatDisplayName } from "../shared/format.ts";
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
- rangeBar: {
115
+ sectionHeaderRow: {
115
116
  flexDirection: "row" as const,
116
117
  alignItems: "center" as const,
117
- alignSelf: "flex-start" as const,
118
- gap: 20,
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
- chipTextActive: {
121
+ sectionTitle: {
133
122
  color: theme.colors.foreground,
134
- fontSize: 12,
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
- paddingHorizontal: 10,
203
- paddingVertical: 8,
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
- gap: 6,
198
+ justifyContent: "center" as const,
199
+ borderRadius: 6,
200
+ flexShrink: 0,
209
201
  },
210
202
  title: {
211
203
  color: theme.colors.foreground,
212
- fontSize: compact ? 15 : 16,
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 showTabs = skillItems.length > 0 && mcpItems.length > 0;
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={14} color={theme.colors.foregroundMuted} />
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
- {!compact ? (
281
- <View style={{ gap: 4 }}>
282
- <Text style={styles.title}>Activity</Text>
283
- <Text style={styles.rowMeta}>Current conversation</Text>
284
- </View>
285
- ) : null}
286
- {showTabs ? (
287
- <View style={styles.rangeBar}>
288
- {(
289
- [
290
- ["skills", "Skills"],
291
- ["mcp", "MCP"],
292
- ] as const
293
- ).map(([id, label]) => {
294
- const active = tab === id;
295
- return (
296
- <Pressable
297
- key={id}
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 title = item.skillPath ? (
326
- <Pressable
327
- accessibilityRole="link"
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
- {title}
315
+ <Text style={styles.rowTitle} numberOfLines={1}>
316
+ {name}
317
+ </Text>
347
318
  {item.lastUsedAt ? (
348
- <Text style={styles.rowMeta}>{formatDayTime(item.lastUsedAt)}</Text>
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
- <Text style={styles.rowMeta}>{formatDayTime(item.lastUsedAt)}</Text>
364
+ <FormattedTime iso={item.lastUsedAt} style={styles.rowMeta} />
374
365
  ) : null}
375
366
  </View>
376
367
  <CountBadge value={item.count} styles={styles} />
@@ -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
- /** Poll while empty so mid-turn mount can see post-turn_ended rows before hide. */
18
- const EMPTY_REFETCH_MS = 1_500;
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 () => {
@@ -11,8 +11,8 @@ export function UsageStats({ items, colors, compact, dense }: {
11
11
  <View style={{ flexDirection: "row", flexWrap: "wrap", borderWidth: 1, borderColor: colors.border, borderRadius: 20, paddingVertical: dense ? 6 : compact ? 8 : 18, rowGap: dense ? 10 : 16 }}>
12
12
  {items.map((item, index) => (
13
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: dense ? 17 : compact ? 20 : 24, fontWeight: "500", fontVariant: ["tabular-nums"] }}>{item.value}</Text>
15
- <Text style={{ color: colors.foregroundMuted, fontSize: dense ? 11 : compact ? 12 : 14 }}>{item.label}</Text>
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>
16
16
  </View>
17
17
  ))}
18
18
  </View>
@@ -0,0 +1,72 @@
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 === "remove") {
44
+ schedule();
45
+ return;
46
+ }
47
+ const agent = update.agent;
48
+ if (agent.workspaceId !== workspaceId) return;
49
+ if (agent.status !== "running" && agent.status !== "initializing") schedule();
50
+ });
51
+ if ("ready" in unsubscribe) {
52
+ void (unsubscribe.ready as Promise<void>).catch((error: unknown) => {
53
+ console.error("[activity] timeline observation failed; polling remains active", error);
54
+ });
55
+ }
56
+ return () => {
57
+ unsubscribe();
58
+ if (debounce != null) clearTimeout(debounce);
59
+ if (settle != null) clearTimeout(settle);
60
+ };
61
+ }, [paseo, agentId, workspaceId]);
62
+ }
63
+
64
+ /** Actual turn terminal events; directory status does not imply completion. */
65
+ export function useAgentTurnEnd(scope: { agentId: string }, onTurnEnd: () => void): void {
66
+ useActivityRefresh(scope, onTurnEnd);
67
+ }
68
+
69
+ /** Best-effort directory hint, never a turn-end signal. */
70
+ export function useWorkspaceActivityRefresh(workspaceId: string, refresh: () => void): void {
71
+ useActivityRefresh({ workspaceId }, refresh);
72
+ }
@@ -0,0 +1,15 @@
1
+ import { usePaseo } from "@getpaseo/plugin/client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { fetchLatestUserMessagePreview } from "./latest-user-message.ts";
4
+
5
+ /** Latest user prompt preview for an agent (host timeline tail; ephemeral). */
6
+ export function useLatestUserMessagePreview(agentId: string, enabled = true) {
7
+ const paseo = usePaseo();
8
+ return useQuery({
9
+ queryKey: ["activity", "latest-user-message", agentId],
10
+ queryFn: () => fetchLatestUserMessagePreview(paseo, agentId),
11
+ enabled: enabled && agentId.length > 0,
12
+ staleTime: 30_000,
13
+ retry: false,
14
+ });
15
+ }
@@ -0,0 +1,47 @@
1
+ import {
2
+ usePaseo,
3
+ useWorkspace,
4
+ } from "@getpaseo/plugin/client";
5
+ import { useQuery, useQueryClient } from "@tanstack/react-query";
6
+ import { useEffect, useMemo } from "react";
7
+ import type { AgentStatusInfo } from "./workspace/constants.ts";
8
+ import { loadWorkspaceAgentStatuses } from "./workspace/list-host-agents.ts";
9
+ import { updateWorkspaceStatusCache } from "./workspace/status-cache.ts";
10
+
11
+ export function workspaceAgentStatusQueryKey(
12
+ workspaceId: string,
13
+ projectId: string | null | undefined,
14
+ ) {
15
+ return ["activity", "workspace-agent-status", workspaceId, projectId ?? null] as const;
16
+ }
17
+
18
+ /**
19
+ * Shared host agent status map for a workspace (Explorer + attention pill).
20
+ * 15s poll owns completeness; subscribe accelerates without list({ subscribe }).
21
+ */
22
+ export function useWorkspaceAgentStatuses(workspaceId: string) {
23
+ const paseo = usePaseo();
24
+ const queryClient = useQueryClient();
25
+ const projectId = useWorkspace(workspaceId, (workspace) => workspace.projectId);
26
+ const queryKey = useMemo(
27
+ () => workspaceAgentStatusQueryKey(workspaceId, projectId),
28
+ [workspaceId, projectId],
29
+ );
30
+
31
+ const query = useQuery({
32
+ refetchInterval: 15_000,
33
+ retry: false,
34
+ queryKey,
35
+ queryFn: () => loadWorkspaceAgentStatuses(paseo, workspaceId, projectId),
36
+ });
37
+
38
+ useEffect(
39
+ () =>
40
+ paseo.agents.subscribe((update) => {
41
+ updateWorkspaceStatusCache(queryClient, queryKey, workspaceId, update);
42
+ }),
43
+ [paseo, queryClient, workspaceId, queryKey],
44
+ );
45
+
46
+ return query as typeof query & { data: Record<string, AgentStatusInfo> | undefined };
47
+ }
@@ -0,0 +1,103 @@
1
+ import { useAgent, useWorkspace } from "@getpaseo/plugin/client";
2
+ import { useQueryClient } from "@tanstack/react-query";
3
+ import { useEffect, type ReactNode } from "react";
4
+ import { workspaceAgentStatusQueryKey } from "../use-workspace-agent-statuses.ts";
5
+ import type { AgentStatusInfo } from "./constants.ts";
6
+ import { updateWorkspaceStatusCache } from "./status-cache.ts";
7
+
8
+ type LiveFields = {
9
+ status: AgentStatusInfo["status"];
10
+ updatedAt: string | null;
11
+ requiresAttention: boolean;
12
+ attentionReason: AgentStatusInfo["attentionReason"];
13
+ parentAgentId: string | null;
14
+ };
15
+
16
+ function sameLiveFields(current: AgentStatusInfo | undefined, next: LiveFields): boolean {
17
+ if (!current) return false;
18
+ return (
19
+ current.status === next.status &&
20
+ current.updatedAt === next.updatedAt &&
21
+ current.requiresAttention === next.requiresAttention &&
22
+ current.attentionReason === next.attentionReason &&
23
+ current.parentAgentId === next.parentAgentId
24
+ );
25
+ }
26
+
27
+ /** Push one host-normalized snapshot into the workspace status query cache (043). */
28
+ function AgentLiveStatusSync({
29
+ agentId,
30
+ workspaceId,
31
+ }: {
32
+ agentId: string;
33
+ workspaceId: string;
34
+ }): null {
35
+ const queryClient = useQueryClient();
36
+ const projectId = useWorkspace(workspaceId, (workspace) => workspace.projectId);
37
+ const queryKey = workspaceAgentStatusQueryKey(workspaceId, projectId);
38
+ const live = useAgent(agentId, (agent) => ({
39
+ status: agent.status,
40
+ updatedAt: agent.updatedAt,
41
+ requiresAttention: agent.requiresAttention,
42
+ attentionReason: agent.attentionReason,
43
+ parentAgentId: agent.parentAgentId,
44
+ }));
45
+
46
+ useEffect(() => {
47
+ const previous = queryClient.getQueryData<Record<string, AgentStatusInfo>>(queryKey);
48
+ if (!previous) return;
49
+
50
+ if (live == null) {
51
+ if (!(agentId in previous) || previous[agentId]?.status === "closed") return;
52
+ updateWorkspaceStatusCache(queryClient, queryKey, workspaceId, {
53
+ kind: "upsert",
54
+ agent: { id: agentId, workspaceId, status: "closed" },
55
+ });
56
+ return;
57
+ }
58
+
59
+ const next: LiveFields = {
60
+ status: live.status,
61
+ updatedAt: live.updatedAt,
62
+ requiresAttention: live.requiresAttention,
63
+ attentionReason: live.attentionReason,
64
+ parentAgentId: live.parentAgentId,
65
+ };
66
+ if (sameLiveFields(previous[agentId], next)) return;
67
+
68
+ updateWorkspaceStatusCache(queryClient, queryKey, workspaceId, {
69
+ kind: "upsert",
70
+ agent: {
71
+ id: agentId,
72
+ workspaceId,
73
+ status: live.status,
74
+ updatedAt: live.updatedAt,
75
+ requiresAttention: live.requiresAttention,
76
+ attentionReason: live.attentionReason,
77
+ parentAgentId: live.parentAgentId,
78
+ },
79
+ });
80
+ }, [agentId, live, queryClient, queryKey, workspaceId]);
81
+
82
+ return null;
83
+ }
84
+
85
+ /**
86
+ * Official real-time path for lifecycle / attention fields without owning
87
+ * `agents.list({ subscribe })`. pendingPermissions still come from list polls.
88
+ */
89
+ export function WorkspaceAgentLiveStatusSync({
90
+ agentIds,
91
+ workspaceId,
92
+ }: {
93
+ agentIds: ReadonlyArray<string>;
94
+ workspaceId: string;
95
+ }): ReactNode {
96
+ return (
97
+ <>
98
+ {agentIds.map((agentId) => (
99
+ <AgentLiveStatusSync key={agentId} agentId={agentId} workspaceId={workspaceId} />
100
+ ))}
101
+ </>
102
+ );
103
+ }