@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.
- package/CHANGELOG.md +50 -1
- package/README.md +26 -11
- package/client/attention-agents.test.ts +94 -0
- package/client/attention-agents.ts +67 -0
- package/client/attention-pill.tsx +254 -0
- package/client/attention-popover.tsx +161 -0
- package/client/attention-status-store.ts +47 -0
- package/client/formatted-time.tsx +23 -0
- package/client/global-surface.tsx +3 -1
- package/client/hidden-pill-recheck.test.ts +33 -0
- package/client/hidden-pill-recheck.ts +22 -0
- package/client/latest-user-message.test.ts +34 -0
- package/client/latest-user-message.ts +96 -0
- package/client/open-agent.ts +32 -0
- package/client/panel.tsx +117 -107
- package/client/pill-directory.test.ts +92 -0
- package/client/pill-directory.ts +79 -0
- package/client/pill.tsx +23 -23
- package/client/usage-popover.tsx +75 -84
- package/client/usage-query.tsx +8 -3
- package/client/usage-stats.tsx +2 -2
- package/client/use-agent-turn-end.ts +72 -0
- package/client/use-latest-user-message.ts +15 -0
- package/client/use-workspace-agent-statuses.ts +47 -0
- package/client/workspace/agent-live-status-sync.tsx +103 -0
- package/client/workspace/agent-row.tsx +105 -28
- package/client/workspace/agents-section.tsx +92 -17
- package/client/workspace/constants.test.ts +66 -0
- package/client/workspace/constants.ts +66 -4
- package/client/workspace/filters.test.ts +59 -0
- package/client/workspace/filters.ts +11 -2
- package/client/workspace/list-host-agents.test.ts +103 -0
- package/client/workspace/list-host-agents.ts +113 -23
- package/client/workspace/panel.tsx +192 -12
- package/client/workspace/rank-section.tsx +36 -26
- package/client/workspace/running-indicator.tsx +54 -0
- package/client/workspace/status-cache.test.ts +62 -0
- package/client/workspace/status-cache.ts +23 -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/index.client.tsx +7 -1
- package/index.server.ts +2 -0
- package/package.json +3 -3
- package/server/agents.test.ts +16 -0
- package/server/agents.ts +7 -4
- package/server/handlers-query.test.ts +24 -3
- package/server/handlers.ts +17 -5
- package/server/skill-path.ts +3 -20
- package/shared/explorer-agent-display.ts +1 -1
- package/shared/format.test.ts +35 -31
- package/shared/format.ts +21 -36
- package/shared/home-path.ts +19 -0
- package/shared/usage.test.ts +8 -2
- package/shared/usage.ts +16 -0
package/client/panel.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type PluginAgentPanelProps, useAgent, useRpc } from "@getpaseo/plugin/client";
|
|
2
2
|
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
5
|
+
import { useRegisterOpenAgent } from "./open-agent.ts";
|
|
5
6
|
import {
|
|
6
7
|
ActivityIndicator,
|
|
7
8
|
Platform,
|
|
@@ -17,12 +18,14 @@ import {
|
|
|
17
18
|
usageSkillsByNameRpc,
|
|
18
19
|
usageSummaryRpc,
|
|
19
20
|
} from "../shared/usage.ts";
|
|
20
|
-
import { formatDisplayName
|
|
21
|
+
import { formatDisplayName } from "../shared/format.ts";
|
|
22
|
+
import { FormattedTime } from "./formatted-time.tsx";
|
|
21
23
|
import {
|
|
22
24
|
clearPendingSkillOpen,
|
|
23
25
|
consumePendingSkillOpen,
|
|
24
26
|
subscribePendingSkillOpen,
|
|
25
27
|
} from "./pending-skill.ts";
|
|
28
|
+
import { useAgentTurnEnd } from "./use-agent-turn-end.ts";
|
|
26
29
|
|
|
27
30
|
import { UsageStats } from "./usage-stats.tsx";
|
|
28
31
|
|
|
@@ -51,6 +54,7 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
51
54
|
const padding = layout.compact ? 16 : 28;
|
|
52
55
|
const agentTitle = useAgent(agentId, (agent) => agent.title);
|
|
53
56
|
const openAgent = navigation?.openAgent;
|
|
57
|
+
useRegisterOpenAgent(openAgent);
|
|
54
58
|
const conversationLabel = agentTitle ?? agentId;
|
|
55
59
|
|
|
56
60
|
const skillsByNameRpc = useRpc(usageSkillsByNameRpc);
|
|
@@ -99,6 +103,13 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
99
103
|
retry: false,
|
|
100
104
|
});
|
|
101
105
|
|
|
106
|
+
const queryClient = useQueryClient();
|
|
107
|
+
useAgentTurnEnd({ agentId }, () => {
|
|
108
|
+
void queryClient.invalidateQueries({ queryKey: ["activity", "skills-by-name", agentId] });
|
|
109
|
+
void queryClient.invalidateQueries({ queryKey: ["activity", "mcp-by-tool", agentId] });
|
|
110
|
+
void queryClient.invalidateQueries({ queryKey: ["activity", "summary", agentId] });
|
|
111
|
+
});
|
|
112
|
+
|
|
102
113
|
const skillItems = useMemo(() => {
|
|
103
114
|
return (skillsByName.data?.items ?? [])
|
|
104
115
|
.filter((item) => item.total > 0)
|
|
@@ -152,33 +163,31 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
152
163
|
},
|
|
153
164
|
sectionTitle: {
|
|
154
165
|
color: theme.colors.foreground,
|
|
155
|
-
fontSize:
|
|
166
|
+
fontSize: 14,
|
|
167
|
+
fontWeight: "600" as const,
|
|
168
|
+
flexShrink: 1,
|
|
169
|
+
letterSpacing: -0.3,
|
|
170
|
+
},
|
|
171
|
+
listSectionTitle: {
|
|
172
|
+
color: theme.colors.foreground,
|
|
173
|
+
fontSize: 15,
|
|
156
174
|
fontWeight: "600" as const,
|
|
157
175
|
flexShrink: 1,
|
|
158
176
|
letterSpacing: -0.3,
|
|
159
177
|
},
|
|
160
|
-
|
|
178
|
+
sectionHeaderRow: {
|
|
161
179
|
flexDirection: "row" as const,
|
|
162
180
|
alignItems: "center" as const,
|
|
163
|
-
|
|
164
|
-
gap:
|
|
165
|
-
},
|
|
166
|
-
rangeSegment: {
|
|
167
|
-
paddingVertical: 8,
|
|
168
|
-
},
|
|
169
|
-
rangeSegmentActive: {
|
|
170
|
-
borderBottomWidth: 1,
|
|
171
|
-
borderBottomColor: theme.colors.foreground,
|
|
172
|
-
},
|
|
173
|
-
chipText: {
|
|
174
|
-
color: theme.colors.foregroundMuted,
|
|
175
|
-
fontSize: 13,
|
|
176
|
-
fontWeight: "500" as const,
|
|
181
|
+
justifyContent: "space-between" as const,
|
|
182
|
+
gap: 8,
|
|
177
183
|
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
titleAction: {
|
|
185
|
+
width: 24,
|
|
186
|
+
height: 24,
|
|
187
|
+
alignItems: "center" as const,
|
|
188
|
+
justifyContent: "center" as const,
|
|
189
|
+
borderRadius: 6,
|
|
190
|
+
flexShrink: 0,
|
|
182
191
|
},
|
|
183
192
|
panel: {
|
|
184
193
|
gap: 4,
|
|
@@ -256,6 +265,11 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
256
265
|
|
|
257
266
|
const loading = skillsByName.isLoading || mcpByTool.isLoading;
|
|
258
267
|
const error = skillsByName.error ?? mcpByTool.error;
|
|
268
|
+
const showToggle = tabs.length > 1;
|
|
269
|
+
const toggleAction =
|
|
270
|
+
tab === "skills"
|
|
271
|
+
? { icon: "Plug" as const, accessibilityLabel: "Show MCP", next: "mcp" as const }
|
|
272
|
+
: { icon: "Sparkles" as const, accessibilityLabel: "Show skills", next: "skills" as const };
|
|
259
273
|
|
|
260
274
|
if (skillDetail) {
|
|
261
275
|
return (
|
|
@@ -287,12 +301,9 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
287
301
|
);
|
|
288
302
|
}
|
|
289
303
|
|
|
290
|
-
const compact = layout.compact;
|
|
291
|
-
|
|
292
304
|
return (
|
|
293
305
|
<ScrollView style={styles.screen} contentContainerStyle={styles.content}>
|
|
294
306
|
<View style={{ gap: 6 }}>
|
|
295
|
-
{!compact ? <Text style={styles.sectionTitle}>Activity</Text> : null}
|
|
296
307
|
{openAgent ? (
|
|
297
308
|
<Text
|
|
298
309
|
accessibilityRole="link"
|
|
@@ -306,7 +317,7 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
306
317
|
<Text style={styles.listMeta}>{conversationLabel}</Text>
|
|
307
318
|
)}
|
|
308
319
|
</View>
|
|
309
|
-
{!loading && !error ? <UsageStats compact={layout.compact} colors={theme.colors} items={[
|
|
320
|
+
{!loading && !error ? <UsageStats compact={layout.compact} dense colors={theme.colors} items={[
|
|
310
321
|
{ label: "Skill calls", value: skillItems.reduce((sum, item) => sum + item.total, 0).toLocaleString() },
|
|
311
322
|
{ label: "MCP calls", value: mcpItems.reduce((sum, item) => sum + item.count, 0).toLocaleString() },
|
|
312
323
|
{ label: "Shell calls", value: (usageSummary.data?.shellCalls ?? 0).toLocaleString() },
|
|
@@ -315,24 +326,6 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
315
326
|
{ label: "Messages", value: (usageSummary.data?.messageCount ?? 0).toLocaleString() },
|
|
316
327
|
{ label: "Tools explored", value: String(skillItems.length + mcpItems.length) },
|
|
317
328
|
]} /> : null}
|
|
318
|
-
{tabs.length > 1 ? (
|
|
319
|
-
<View style={styles.rangeBar}>
|
|
320
|
-
{tabs.map((item) => {
|
|
321
|
-
const active = tab === item.id;
|
|
322
|
-
return (
|
|
323
|
-
<Pressable
|
|
324
|
-
key={item.id}
|
|
325
|
-
accessibilityRole="tab"
|
|
326
|
-
accessibilityState={{ selected: active }}
|
|
327
|
-
onPress={() => setTab(item.id)}
|
|
328
|
-
style={[styles.rangeSegment, active ? styles.rangeSegmentActive : null]}
|
|
329
|
-
>
|
|
330
|
-
<Text style={active ? styles.chipTextActive : styles.chipText}>{item.label}</Text>
|
|
331
|
-
</Pressable>
|
|
332
|
-
);
|
|
333
|
-
})}
|
|
334
|
-
</View>
|
|
335
|
-
) : null}
|
|
336
329
|
|
|
337
330
|
{loading ? <ActivityIndicator color={theme.colors.accent} /> : null}
|
|
338
331
|
{error ? (
|
|
@@ -342,81 +335,98 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
342
335
|
) : null}
|
|
343
336
|
|
|
344
337
|
{!loading && !error && tabs.length === 0 ? (
|
|
345
|
-
<
|
|
346
|
-
{!compact ? <Text style={styles.sectionTitle}>Activity</Text> : null}
|
|
347
|
-
<Text style={styles.empty}>No skill or MCP calls yet</Text>
|
|
348
|
-
</View>
|
|
338
|
+
<Text style={styles.empty}>No skill or MCP calls yet</Text>
|
|
349
339
|
) : null}
|
|
350
340
|
|
|
351
|
-
{tab
|
|
341
|
+
{tab ? (
|
|
352
342
|
<View style={{ gap: 12 }}>
|
|
353
|
-
<
|
|
354
|
-
|
|
355
|
-
{
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
343
|
+
<View style={styles.sectionHeaderRow}>
|
|
344
|
+
<Text style={styles.listSectionTitle}>{tab === "skills" ? "Skills" : "MCP"}</Text>
|
|
345
|
+
{showToggle ? (
|
|
346
|
+
<Pressable
|
|
347
|
+
accessibilityRole="button"
|
|
348
|
+
accessibilityLabel={toggleAction.accessibilityLabel}
|
|
349
|
+
hitSlop={8}
|
|
350
|
+
onPress={() => setTab(toggleAction.next)}
|
|
351
|
+
style={styles.titleAction}
|
|
352
|
+
>
|
|
353
|
+
<Icon
|
|
354
|
+
name={toggleAction.icon}
|
|
355
|
+
size={16}
|
|
356
|
+
color={theme.colors.foregroundMuted}
|
|
357
|
+
/>
|
|
358
|
+
</Pressable>
|
|
359
|
+
) : null}
|
|
360
|
+
</View>
|
|
361
|
+
{tab === "skills" ? (
|
|
362
|
+
<View style={styles.panel}>
|
|
363
|
+
{skillItems.map((item, index) => {
|
|
364
|
+
const name = formatDisplayName(item.skillName);
|
|
365
|
+
const title = item.skillPath ? (
|
|
366
|
+
<Pressable
|
|
367
|
+
accessibilityRole="link"
|
|
368
|
+
accessibilityLabel={`Open ${name} SKILL.md`}
|
|
369
|
+
onPress={() =>
|
|
370
|
+
setSkillDetail({ skillName: item.skillName, path: item.skillPath! })
|
|
371
|
+
}
|
|
372
|
+
>
|
|
373
|
+
<Text style={styles.listLink} numberOfLines={1}>
|
|
374
|
+
{name}
|
|
375
|
+
</Text>
|
|
376
|
+
</Pressable>
|
|
377
|
+
) : (
|
|
378
|
+
<Text style={styles.listTitle} numberOfLines={1}>
|
|
366
379
|
{name}
|
|
367
380
|
</Text>
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
381
|
+
);
|
|
382
|
+
return (
|
|
383
|
+
<View
|
|
384
|
+
key={item.skillName}
|
|
385
|
+
style={[styles.listRow, index === 0 ? styles.listRowFirst : null]}
|
|
386
|
+
>
|
|
387
|
+
<Icon name="Sparkles" size={18} color={theme.colors.foregroundMuted} />
|
|
388
|
+
<View style={styles.listMain}>
|
|
389
|
+
{title}
|
|
390
|
+
<FormattedTime
|
|
391
|
+
iso={item.lastUsedAt}
|
|
392
|
+
prefix="Last "
|
|
393
|
+
style={styles.listMeta}
|
|
394
|
+
/>
|
|
395
|
+
</View>
|
|
396
|
+
<CountText value={item.total} styles={styles} />
|
|
397
|
+
</View>
|
|
398
|
+
);
|
|
399
|
+
})}
|
|
400
|
+
</View>
|
|
401
|
+
) : (
|
|
402
|
+
<View style={styles.panel}>
|
|
403
|
+
{mcpItems.map((item, index) => (
|
|
375
404
|
<View
|
|
376
|
-
key={item.
|
|
405
|
+
key={`${item.server}.${item.tool}`}
|
|
377
406
|
style={[styles.listRow, index === 0 ? styles.listRowFirst : null]}
|
|
378
407
|
>
|
|
379
|
-
<Icon name="
|
|
408
|
+
<Icon name="Plug" size={18} color={theme.colors.foregroundMuted} />
|
|
380
409
|
<View style={styles.listMain}>
|
|
381
|
-
{
|
|
382
|
-
|
|
383
|
-
Last {formatLocalDateTime(item.lastUsedAt)}
|
|
410
|
+
<Text style={styles.listTitle} numberOfLines={1}>
|
|
411
|
+
{formatDisplayName(`${item.server}.${item.tool}`)}
|
|
384
412
|
</Text>
|
|
413
|
+
{item.failures > 0 ? (
|
|
414
|
+
<Text style={styles.listMeta}>{item.failures} failed</Text>
|
|
415
|
+
) : item.lastUsedAt ? (
|
|
416
|
+
<FormattedTime
|
|
417
|
+
iso={item.lastUsedAt}
|
|
418
|
+
prefix="Last "
|
|
419
|
+
style={styles.listMeta}
|
|
420
|
+
/>
|
|
421
|
+
) : (
|
|
422
|
+
<Text style={styles.listMeta}>—</Text>
|
|
423
|
+
)}
|
|
385
424
|
</View>
|
|
386
|
-
<CountText value={item.
|
|
425
|
+
<CountText value={item.count} styles={styles} />
|
|
387
426
|
</View>
|
|
388
|
-
)
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
</View>
|
|
392
|
-
) : null}
|
|
393
|
-
|
|
394
|
-
{tab === "mcp" ? (
|
|
395
|
-
<View style={{ gap: 12 }}>
|
|
396
|
-
<Text style={styles.sectionTitle}>MCP</Text>
|
|
397
|
-
<View style={styles.panel}>
|
|
398
|
-
{mcpItems.map((item, index) => (
|
|
399
|
-
<View
|
|
400
|
-
key={`${item.server}.${item.tool}`}
|
|
401
|
-
style={[styles.listRow, index === 0 ? styles.listRowFirst : null]}
|
|
402
|
-
>
|
|
403
|
-
<Icon name="Plug" size={18} color={theme.colors.foregroundMuted} />
|
|
404
|
-
<View style={styles.listMain}>
|
|
405
|
-
<Text style={styles.listTitle} numberOfLines={1}>
|
|
406
|
-
{formatDisplayName(`${item.server}.${item.tool}`)}
|
|
407
|
-
</Text>
|
|
408
|
-
<Text style={styles.listMeta}>
|
|
409
|
-
{item.failures > 0
|
|
410
|
-
? `${item.failures} failed`
|
|
411
|
-
: item.lastUsedAt
|
|
412
|
-
? `Last ${formatLocalDateTime(item.lastUsedAt)}`
|
|
413
|
-
: "—"}
|
|
414
|
-
</Text>
|
|
415
|
-
</View>
|
|
416
|
-
<CountText value={item.count} styles={styles} />
|
|
417
|
-
</View>
|
|
418
|
-
))}
|
|
419
|
-
</View>
|
|
427
|
+
))}
|
|
428
|
+
</View>
|
|
429
|
+
)}
|
|
420
430
|
</View>
|
|
421
431
|
) : null}
|
|
422
432
|
</ScrollView>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { setImmediate } from "node:timers/promises";
|
|
4
|
+
import { watchPillDirectory } from "./pill-directory.ts";
|
|
5
|
+
|
|
6
|
+
type Api = Parameters<typeof watchPillDirectory>[0];
|
|
7
|
+
type Update = Parameters<Parameters<Api["subscribe"]>[0]>[0];
|
|
8
|
+
|
|
9
|
+
test("pill directory pages without observation and replays concurrent removal", async () => {
|
|
10
|
+
let listener!: (update: Update) => void;
|
|
11
|
+
const seen = new Set<string>();
|
|
12
|
+
const cursors: unknown[] = [];
|
|
13
|
+
let unsubscribed = false;
|
|
14
|
+
const api = {
|
|
15
|
+
subscribe: (handler: typeof listener) => { listener = handler; return () => { unsubscribed = true; }; },
|
|
16
|
+
list: async (options: { page: { cursor?: string }; subscribe?: unknown }) => {
|
|
17
|
+
assert.equal(options.subscribe, undefined);
|
|
18
|
+
cursors.push(options.page.cursor);
|
|
19
|
+
if (!options.page.cursor) return {
|
|
20
|
+
entries: [{ agent: { id: "first", workspaceId: "w" } }],
|
|
21
|
+
pageInfo: { hasMore: true, nextCursor: "next" },
|
|
22
|
+
};
|
|
23
|
+
listener({ kind: "remove", agentId: "first" } as Update);
|
|
24
|
+
return { entries: [{ agent: { id: "second", workspaceId: "w" } }], pageInfo: { hasMore: false, nextCursor: null } };
|
|
25
|
+
},
|
|
26
|
+
} as unknown as Api;
|
|
27
|
+
const stop = watchPillDirectory(api, (agent) => seen.add(agent.id), (id) => seen.delete(id));
|
|
28
|
+
try {
|
|
29
|
+
await setImmediate();
|
|
30
|
+
assert.deepEqual(cursors, [undefined, "next"]);
|
|
31
|
+
assert.deepEqual([...seen], ["second"]);
|
|
32
|
+
} finally { stop(); }
|
|
33
|
+
assert.equal(unsubscribed, true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("unload while a directory request is pending cannot register pills", async () => {
|
|
37
|
+
let finish!: (result: unknown) => void;
|
|
38
|
+
let calls = 0;
|
|
39
|
+
const api = {
|
|
40
|
+
subscribe: () => () => {},
|
|
41
|
+
list: () => new Promise((resolve) => { finish = resolve; }),
|
|
42
|
+
} as unknown as Api;
|
|
43
|
+
const stop = watchPillDirectory(api, () => { calls++; }, () => { calls++; });
|
|
44
|
+
stop();
|
|
45
|
+
finish({ entries: [{ agent: { id: "late" } }], pageInfo: { hasMore: false, nextCursor: null } });
|
|
46
|
+
await setImmediate();
|
|
47
|
+
assert.equal(calls, 0);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("polling discovers agents without any directory push", async () => {
|
|
51
|
+
let reads = 0;
|
|
52
|
+
let found!: () => void;
|
|
53
|
+
const discovery = new Promise<void>((resolve) => { found = resolve; });
|
|
54
|
+
const api = {
|
|
55
|
+
subscribe: () => () => {},
|
|
56
|
+
list: async () => ({
|
|
57
|
+
entries: ++reads === 1 ? [] : [{ agent: { id: "new", workspaceId: "w" } }],
|
|
58
|
+
pageInfo: { hasMore: false, nextCursor: null },
|
|
59
|
+
}),
|
|
60
|
+
} as unknown as Api;
|
|
61
|
+
const stop = watchPillDirectory(api, () => found(), () => {}, 1);
|
|
62
|
+
try { await discovery; assert.equal(reads, 2); } finally { stop(); }
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("unchanged idle polls do not revive a pill; new activity and re-add still notify", async () => {
|
|
66
|
+
let listener!: (update: Update) => void;
|
|
67
|
+
let reads = 0;
|
|
68
|
+
let thirdRead!: () => void;
|
|
69
|
+
const polled = new Promise<void>(resolve => { thirdRead = resolve; });
|
|
70
|
+
const agent = { id: "a", workspaceId: "w", status: "idle", updatedAt: "old" };
|
|
71
|
+
let callbacks = 0;
|
|
72
|
+
const stop = watchPillDirectory({
|
|
73
|
+
subscribe: (handler: typeof listener) => { listener = handler; return () => {}; },
|
|
74
|
+
list: async () => {
|
|
75
|
+
if (++reads === 3) thirdRead();
|
|
76
|
+
return { entries: [{ agent }], pageInfo: { hasMore: false, nextCursor: null } };
|
|
77
|
+
},
|
|
78
|
+
} as unknown as Api, () => { callbacks++; }, () => {}, 1);
|
|
79
|
+
try {
|
|
80
|
+
await polled;
|
|
81
|
+
await setImmediate();
|
|
82
|
+
assert.equal(callbacks, 1);
|
|
83
|
+
listener({ kind: "upsert", agent } as Update);
|
|
84
|
+
assert.equal(callbacks, 1);
|
|
85
|
+
// Polling can miss the running transition: newer idle timestamp must revive.
|
|
86
|
+
listener({ kind: "upsert", agent: { ...agent, updatedAt: "new" } } as Update);
|
|
87
|
+
assert.equal(callbacks, 2);
|
|
88
|
+
listener({ kind: "remove", agentId: "a" } as Update);
|
|
89
|
+
listener({ kind: "upsert", agent: { ...agent, updatedAt: "new" } } as Update);
|
|
90
|
+
assert.equal(callbacks, 3);
|
|
91
|
+
} finally { stop(); }
|
|
92
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import { listAllAgentPages } from "../shared/list-agent-pages.ts";
|
|
3
|
+
|
|
4
|
+
type AgentsApi = PluginClientContext["paseo"]["agents"];
|
|
5
|
+
type Update = Parameters<Parameters<AgentsApi["subscribe"]>[0]>[0];
|
|
6
|
+
type Agent = Extract<Update, { kind: "upsert" }>["agent"];
|
|
7
|
+
|
|
8
|
+
/** 0.8 has one shared directory slot. Plain paged reads own our fallback, never that slot. */
|
|
9
|
+
export function watchPillDirectory(
|
|
10
|
+
agents: AgentsApi,
|
|
11
|
+
onAgent: (agent: Agent) => void,
|
|
12
|
+
onRemove: (agentId: string) => void,
|
|
13
|
+
intervalMs = 15_000,
|
|
14
|
+
onPolled?: (agent: Agent) => void,
|
|
15
|
+
): () => void {
|
|
16
|
+
let disposed = false;
|
|
17
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
18
|
+
let pending: Update[] | null = null;
|
|
19
|
+
let known = new Set<string>();
|
|
20
|
+
const versions = new Map<string, string>();
|
|
21
|
+
function publish(agent: Agent) {
|
|
22
|
+
const version = JSON.stringify([agent.workspaceId, agent.status, agent.updatedAt,
|
|
23
|
+
agent.lastUserMessageAt, agent.activeTurn?.turnId]);
|
|
24
|
+
if (versions.get(agent.id) === version) return;
|
|
25
|
+
versions.set(agent.id, version);
|
|
26
|
+
onAgent(agent);
|
|
27
|
+
}
|
|
28
|
+
function remove(id: string) {
|
|
29
|
+
versions.delete(id);
|
|
30
|
+
onRemove(id);
|
|
31
|
+
}
|
|
32
|
+
function apply(update: Update) {
|
|
33
|
+
if (update.kind === "remove") {
|
|
34
|
+
known.delete(update.agentId);
|
|
35
|
+
remove(update.agentId);
|
|
36
|
+
} else {
|
|
37
|
+
known.add(update.agent.id);
|
|
38
|
+
publish(update.agent);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Opportunistic acceleration only; correctness does not depend on host observation.
|
|
42
|
+
const unsubscribe = agents.subscribe((update) => {
|
|
43
|
+
if (disposed) return;
|
|
44
|
+
pending?.push(update);
|
|
45
|
+
apply(update);
|
|
46
|
+
});
|
|
47
|
+
async function sync() {
|
|
48
|
+
pending = [];
|
|
49
|
+
try {
|
|
50
|
+
const entries = await listAllAgentPages((cursor) => agents.list({
|
|
51
|
+
page: { limit: 200, ...(cursor ? { cursor } : {}) },
|
|
52
|
+
}));
|
|
53
|
+
if (disposed) return;
|
|
54
|
+
const snapshot = new Map(entries.map(({ agent }) => [agent.id, agent]));
|
|
55
|
+
// Pushes received during pagination are newer than its snapshot.
|
|
56
|
+
for (const update of pending) {
|
|
57
|
+
if (update.kind === "remove") snapshot.delete(update.agentId);
|
|
58
|
+
else snapshot.set(update.agent.id, update.agent);
|
|
59
|
+
}
|
|
60
|
+
for (const id of known) if (!snapshot.has(id)) remove(id);
|
|
61
|
+
known = new Set(snapshot.keys());
|
|
62
|
+
for (const agent of snapshot.values()) {
|
|
63
|
+
publish(agent);
|
|
64
|
+
onPolled?.(agent);
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (!disposed) console.error("[activity] could not sync composer pills", error);
|
|
68
|
+
} finally {
|
|
69
|
+
pending = null;
|
|
70
|
+
if (!disposed) timer = setTimeout(() => void sync(), intervalMs);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
void sync();
|
|
74
|
+
return () => {
|
|
75
|
+
disposed = true;
|
|
76
|
+
unsubscribe();
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
};
|
|
79
|
+
}
|
package/client/pill.tsx
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { createHiddenPillRecheck } from "./hidden-pill-recheck.ts";
|
|
2
|
+
import { writePillDataCache } from "./pill-data-cache.ts";
|
|
3
|
+
import { watchPillDirectory } from "./pill-directory.ts";
|
|
1
4
|
import {
|
|
2
5
|
type PluginButtonContentProps,
|
|
3
6
|
type PluginButtonIconProps,
|
|
@@ -6,7 +9,7 @@ import {
|
|
|
6
9
|
} from "@getpaseo/plugin/client";
|
|
7
10
|
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
8
11
|
import { useEffect, useRef } from "react";
|
|
9
|
-
import { formatUsagePillLabel } from "../shared/usage.ts";
|
|
12
|
+
import { formatUsagePillLabel, usageSkillsByNameRpc, usageMcpByToolRpc } from "../shared/usage.ts";
|
|
10
13
|
import { useUsagePillData, clearPillDataCache } from "./usage-query.tsx";
|
|
11
14
|
import { UsagePopover, type SkillDetail } from "./usage-popover.tsx";
|
|
12
15
|
import { requestOpenSkillInPanel } from "./pending-skill.ts";
|
|
@@ -23,6 +26,7 @@ const EMPTY_GRACE_MS_RECHECK = 4_000;
|
|
|
23
26
|
|
|
24
27
|
type PillEntry = {
|
|
25
28
|
registration?: PluginButtonRegistration;
|
|
29
|
+
recheck?: () => Promise<void>;
|
|
26
30
|
/** Host unmounted the icon after a settled empty hide. */
|
|
27
31
|
hidden: boolean;
|
|
28
32
|
/** Already completed one empty grace → hide cycle for this agent. */
|
|
@@ -161,6 +165,16 @@ export function contributePills(client: PluginClientContext) {
|
|
|
161
165
|
},
|
|
162
166
|
});
|
|
163
167
|
pills.set(agentId, entry);
|
|
168
|
+
entry.recheck = createHiddenPillRecheck(async () => {
|
|
169
|
+
const [skills, mcp] = await Promise.all([
|
|
170
|
+
client.rpc(usageSkillsByNameRpc, { agentId }),
|
|
171
|
+
client.rpc(usageMcpByToolRpc, { agentId }),
|
|
172
|
+
]);
|
|
173
|
+
return { skills: skills.items, mcpTools: mcp.items };
|
|
174
|
+
}, () => pills.get(agentId) === entry && entry.hidden, (data) => {
|
|
175
|
+
writePillDataCache(agentId, data);
|
|
176
|
+
reviveHiddenPill(agentId);
|
|
177
|
+
});
|
|
164
178
|
}
|
|
165
179
|
|
|
166
180
|
function removePill(agentId: string) {
|
|
@@ -177,32 +191,18 @@ export function contributePills(client: PluginClientContext) {
|
|
|
177
191
|
entry.registration.update({ label: TITLE, visible: true });
|
|
178
192
|
}
|
|
179
193
|
|
|
180
|
-
const unsubscribe = client.paseo.agents
|
|
181
|
-
|
|
182
|
-
removePill(update.agentId);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const { id, workspaceId, status } = update.agent;
|
|
194
|
+
const unsubscribe = watchPillDirectory(client.paseo.agents, (agent) => {
|
|
195
|
+
const { id, workspaceId, status } = agent;
|
|
186
196
|
if (!workspaceId) return;
|
|
187
|
-
if (pills.has(id)) {
|
|
188
|
-
// turn_ended ingest races with idle; remount hidden pills so they can catch up.
|
|
189
|
-
if (status === "idle") reviveHiddenPill(id);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
197
|
addPill(id, workspaceId);
|
|
198
|
+
// A read/push is a refresh hint, not proof of turn completion.
|
|
199
|
+
if (status === "idle") reviveHiddenPill(id);
|
|
200
|
+
}, removePill, 15_000, (agent) => {
|
|
201
|
+
// Ingest can finish after the empty grace period without another agent update.
|
|
202
|
+
// Keep the fallback query, but only make the pill visible when data exists.
|
|
203
|
+
if (agent.status === "idle") void pills.get(agent.id)?.recheck?.();
|
|
193
204
|
});
|
|
194
205
|
|
|
195
|
-
client.paseo.agents
|
|
196
|
-
.list()
|
|
197
|
-
.then((result) => {
|
|
198
|
-
result.entries.forEach(({ agent }) => {
|
|
199
|
-
if (agent.workspaceId) addPill(agent.id, agent.workspaceId);
|
|
200
|
-
});
|
|
201
|
-
})
|
|
202
|
-
.catch((error: unknown) => {
|
|
203
|
-
console.error("[activity] could not seed composer pills", error);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
206
|
return () => {
|
|
207
207
|
unsubscribe();
|
|
208
208
|
pills.forEach((entry) => entry.registration?.remove());
|