@koinzhang/paseo-plugin-activity 0.3.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 +25 -1
- package/README.md +6 -5
- 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/global-surface.tsx +3 -1
- 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 +2 -0
- package/client/use-agent-turn-end.ts +4 -1
- 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 +49 -22
- package/client/workspace/agents-section.tsx +90 -22
- package/client/workspace/constants.test.ts +66 -0
- package/client/workspace/constants.ts +37 -1
- package/client/workspace/filters.test.ts +59 -0
- package/client/workspace/filters.ts +9 -0
- package/client/workspace/list-host-agents.test.ts +59 -1
- package/client/workspace/list-host-agents.ts +66 -9
- package/client/workspace/panel.tsx +39 -23
- package/client/workspace/status-cache.test.ts +5 -5
- package/client/workspace/status-cache.ts +5 -1
- package/index.client.tsx +7 -1
- package/package.json +2 -2
- package/shared/explorer-agent-display.ts +1 -1
- package/shared/usage.test.ts +8 -2
- package/shared/usage.ts +7 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import type { AgentStatusInfo } from "./workspace/constants.ts";
|
|
3
|
+
|
|
4
|
+
const byWorkspace = new Map<string, Record<string, AgentStatusInfo>>();
|
|
5
|
+
const listeners = new Set<() => void>();
|
|
6
|
+
|
|
7
|
+
function emit(): void {
|
|
8
|
+
for (const listener of listeners) listener();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function subscribe(listener: () => void): () => void {
|
|
12
|
+
listeners.add(listener);
|
|
13
|
+
return () => {
|
|
14
|
+
listeners.delete(listener);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Publish push/poll status for a workspace; icon + popover read this immediately. */
|
|
19
|
+
export function publishAttentionStatuses(
|
|
20
|
+
workspaceId: string,
|
|
21
|
+
statuses: Record<string, AgentStatusInfo>,
|
|
22
|
+
): void {
|
|
23
|
+
byWorkspace.set(workspaceId, statuses);
|
|
24
|
+
emit();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getAttentionStatuses(
|
|
28
|
+
workspaceId: string,
|
|
29
|
+
): Record<string, AgentStatusInfo> | undefined {
|
|
30
|
+
return byWorkspace.get(workspaceId);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function clearAttentionStatuses(): void {
|
|
34
|
+
byWorkspace.clear();
|
|
35
|
+
emit();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Re-renders when contribute-layer status for this workspace is republished. */
|
|
39
|
+
export function useAttentionStatuses(
|
|
40
|
+
workspaceId: string,
|
|
41
|
+
): Record<string, AgentStatusInfo> | undefined {
|
|
42
|
+
return useSyncExternalStore(
|
|
43
|
+
subscribe,
|
|
44
|
+
() => byWorkspace.get(workspaceId),
|
|
45
|
+
() => undefined,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -30,6 +30,7 @@ import { selectProviderOptions } from "./provider-filter.ts";
|
|
|
30
30
|
import { useAppLanguage } from "./use-app-language.ts";
|
|
31
31
|
import { buildActivityInsights, ACTIVITY_LIST_LIMIT } from "../shared/insights.ts";
|
|
32
32
|
import { rangeFrom, RANGE_OPTIONS, type RangeId } from "./range.ts";
|
|
33
|
+
import { useRegisterOpenAgent } from "./open-agent.ts";
|
|
33
34
|
|
|
34
35
|
/** Max rows for Activity insights and Most used skills / MCP. */
|
|
35
36
|
const LIST_LIMIT = ACTIVITY_LIST_LIMIT;
|
|
@@ -211,7 +212,8 @@ function RankList({
|
|
|
211
212
|
);
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
|
|
215
|
+
export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceProps) {
|
|
216
|
+
useRegisterOpenAgent(navigation?.openAgent);
|
|
215
217
|
const [range, setRange] = useState<RangeId>("all");
|
|
216
218
|
const [providerFilter, setProviderFilter] = useState<string>("all");
|
|
217
219
|
const [heatmapMode, setHeatmapMode] = useState<HeatmapMode>("daily");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
formatMessagePreview,
|
|
5
|
+
pickLatestUserMessageText,
|
|
6
|
+
} from "./latest-user-message.ts";
|
|
7
|
+
|
|
8
|
+
describe("pickLatestUserMessageText", () => {
|
|
9
|
+
it("picks the highest-seq non-empty user_message", () => {
|
|
10
|
+
const text = pickLatestUserMessageText([
|
|
11
|
+
{ item: { type: "user_message", text: "first" }, seqStart: 1, timestamp: "a" },
|
|
12
|
+
{ item: { type: "assistant_message", text: "reply" }, seqStart: 2, timestamp: "b" },
|
|
13
|
+
{ item: { type: "user_message", text: " " }, seqStart: 3, timestamp: "c" },
|
|
14
|
+
{ item: { type: "user_message", text: "latest" }, seqStart: 4, timestamp: "d" },
|
|
15
|
+
]);
|
|
16
|
+
assert.equal(text, "latest");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("when seq missing, prefers later list entry", () => {
|
|
20
|
+
const text = pickLatestUserMessageText([
|
|
21
|
+
{ item: { type: "user_message", text: "older" } },
|
|
22
|
+
{ item: { type: "assistant_message", text: "reply" } },
|
|
23
|
+
{ item: { type: "user_message", text: "newer" } },
|
|
24
|
+
]);
|
|
25
|
+
assert.equal(text, "newer");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("formatMessagePreview", () => {
|
|
30
|
+
it("collapses whitespace and truncates", () => {
|
|
31
|
+
assert.equal(formatMessagePreview("hello\n world"), "hello world");
|
|
32
|
+
assert.equal(formatMessagePreview("abcdefghij", 6), "abcde…");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural timeline entry shape for user-message previews.
|
|
3
|
+
*
|
|
4
|
+
* Do not import `@getpaseo/protocol/*` from client/: Paseo compiles plugins
|
|
5
|
+
* without installing that package, and type-only imports still fail the
|
|
6
|
+
* `paseo-plugin-client-runtime-boundary` build (see server/host-types.ts).
|
|
7
|
+
*/
|
|
8
|
+
export type TimelineTailEntry = {
|
|
9
|
+
item: {
|
|
10
|
+
type: string;
|
|
11
|
+
text?: string | null;
|
|
12
|
+
};
|
|
13
|
+
seqStart?: number;
|
|
14
|
+
timestamp?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type TimelineApi = {
|
|
18
|
+
agents: {
|
|
19
|
+
ref: (agentId: string) => {
|
|
20
|
+
timeline: {
|
|
21
|
+
refetch: (options: {
|
|
22
|
+
projection?: "canonical" | "projected";
|
|
23
|
+
direction?: "tail" | "before" | "after";
|
|
24
|
+
limit?: number;
|
|
25
|
+
}) => Promise<{
|
|
26
|
+
error?: string | null;
|
|
27
|
+
entries?: ReadonlyArray<TimelineTailEntry> | null;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Newest non-empty user_message; prefers higher seq/ts, else later list index (tail order). */
|
|
35
|
+
export function pickLatestUserMessageText(
|
|
36
|
+
entries: ReadonlyArray<TimelineTailEntry>,
|
|
37
|
+
): string | null {
|
|
38
|
+
let best: { text: string; seq: number; ts: string; index: number } | null = null;
|
|
39
|
+
for (let index = 0; index < entries.length; index++) {
|
|
40
|
+
const entry = entries[index]!;
|
|
41
|
+
if (entry.item.type !== "user_message") continue;
|
|
42
|
+
const text = entry.item.text?.trim();
|
|
43
|
+
if (!text) continue;
|
|
44
|
+
const seq = entry.seqStart ?? -1;
|
|
45
|
+
const ts = entry.timestamp ?? "";
|
|
46
|
+
if (
|
|
47
|
+
!best ||
|
|
48
|
+
seq > best.seq ||
|
|
49
|
+
(seq === best.seq && ts > best.ts) ||
|
|
50
|
+
(seq === best.seq && ts === best.ts && index > best.index)
|
|
51
|
+
) {
|
|
52
|
+
best = { text, seq, ts, index };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return best?.text ?? null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Single-line preview for list meta; collapses whitespace. */
|
|
59
|
+
export function formatMessagePreview(text: string, maxChars = 72): string {
|
|
60
|
+
const oneLine = text.replace(/\s+/g, " ").trim();
|
|
61
|
+
if (oneLine.length <= maxChars) return oneLine;
|
|
62
|
+
return `${oneLine.slice(0, Math.max(1, maxChars - 1)).trimEnd()}…`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function refetchPreview(
|
|
66
|
+
paseo: TimelineApi,
|
|
67
|
+
agentId: string,
|
|
68
|
+
projection: "projected" | "canonical",
|
|
69
|
+
): Promise<string | null> {
|
|
70
|
+
const page = await paseo.agents.ref(agentId).timeline.refetch({
|
|
71
|
+
projection,
|
|
72
|
+
direction: "tail",
|
|
73
|
+
limit: 80,
|
|
74
|
+
});
|
|
75
|
+
if (page.error) throw new Error(page.error);
|
|
76
|
+
const text = pickLatestUserMessageText(page.entries ?? []);
|
|
77
|
+
return text ? formatMessagePreview(text) : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Read the newest user prompt from the host timeline (not local SQLite —
|
|
82
|
+
* message bodies are intentionally not stored in usage.db).
|
|
83
|
+
* Prefer projected (UI text), then canonical.
|
|
84
|
+
*/
|
|
85
|
+
export async function fetchLatestUserMessagePreview(
|
|
86
|
+
paseo: TimelineApi,
|
|
87
|
+
agentId: string,
|
|
88
|
+
): Promise<string | null> {
|
|
89
|
+
try {
|
|
90
|
+
const projected = await refetchPreview(paseo, agentId, "projected");
|
|
91
|
+
if (projected) return projected;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.warn("[activity] projected timeline preview failed", agentId, error);
|
|
94
|
+
}
|
|
95
|
+
return refetchPreview(paseo, agentId, "canonical");
|
|
96
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
type OpenAgent = (input: { agentId: string }) => void;
|
|
4
|
+
|
|
5
|
+
/** Last-registered wins; cleanup pops this registration only. */
|
|
6
|
+
const stack: OpenAgent[] = [];
|
|
7
|
+
|
|
8
|
+
export function setOpenAgent(open: OpenAgent | null | undefined): () => void {
|
|
9
|
+
if (!open) return () => {};
|
|
10
|
+
stack.push(open);
|
|
11
|
+
return () => {
|
|
12
|
+
const index = stack.lastIndexOf(open);
|
|
13
|
+
if (index >= 0) stack.splice(index, 1);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Register host `navigation.openAgent` while a navigable surface/panel is mounted. */
|
|
18
|
+
export function useRegisterOpenAgent(open: OpenAgent | null | undefined): void {
|
|
19
|
+
useEffect(() => setOpenAgent(open), [open]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function tryOpenAgent(agentId: string): boolean {
|
|
23
|
+
const open = stack[stack.length - 1];
|
|
24
|
+
if (!open) return false;
|
|
25
|
+
open({ agentId });
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Focus another agent conversation via the registered host navigation bridge. */
|
|
30
|
+
export function openAttentionAgent(agentId: string): void {
|
|
31
|
+
tryOpenAgent(agentId);
|
|
32
|
+
}
|
package/client/panel.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { type PluginAgentPanelProps, useAgent, useRpc } from "@getpaseo/plugin/c
|
|
|
2
2
|
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
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,
|
|
@@ -53,6 +54,7 @@ export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPa
|
|
|
53
54
|
const padding = layout.compact ? 16 : 28;
|
|
54
55
|
const agentTitle = useAgent(agentId, (agent) => agent.title);
|
|
55
56
|
const openAgent = navigation?.openAgent;
|
|
57
|
+
useRegisterOpenAgent(openAgent);
|
|
56
58
|
const conversationLabel = agentTitle ?? agentId;
|
|
57
59
|
|
|
58
60
|
const skillsByNameRpc = useRpc(usageSkillsByNameRpc);
|
|
@@ -40,7 +40,10 @@ function useActivityRefresh(scope: AgentTurnEndScope, onTurnEnd: () => void): vo
|
|
|
40
40
|
})
|
|
41
41
|
: paseo.agents.subscribe((update) => {
|
|
42
42
|
// Workspace-wide hint only. The 15s query poll owns completeness.
|
|
43
|
-
if (update.kind
|
|
43
|
+
if (update.kind === "remove") {
|
|
44
|
+
schedule();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
44
47
|
const agent = update.agent;
|
|
45
48
|
if (agent.workspaceId !== workspaceId) return;
|
|
46
49
|
if (agent.status !== "running" && agent.status !== "initializing") schedule();
|
|
@@ -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
|
+
}
|
|
@@ -16,6 +16,8 @@ export type AgentRowStyles = {
|
|
|
16
16
|
agentListRow: ViewStyle;
|
|
17
17
|
agentIconWrap: ViewStyle;
|
|
18
18
|
runningBadge: ViewStyle;
|
|
19
|
+
subAgentBadge: ViewStyle;
|
|
20
|
+
subAgentBadgeText: TextStyle;
|
|
19
21
|
listMain: ViewStyle;
|
|
20
22
|
listLink: TextStyle;
|
|
21
23
|
listTitle: TextStyle;
|
|
@@ -33,6 +35,7 @@ export function AgentRow({
|
|
|
33
35
|
permissionCount,
|
|
34
36
|
attentionKind,
|
|
35
37
|
running,
|
|
38
|
+
subAgentCount = 0,
|
|
36
39
|
busy,
|
|
37
40
|
actionDisabled,
|
|
38
41
|
theme,
|
|
@@ -47,12 +50,15 @@ export function AgentRow({
|
|
|
47
50
|
permissionCount: number;
|
|
48
51
|
attentionKind: AgentAttentionKind;
|
|
49
52
|
running: boolean;
|
|
53
|
+
/** Direct child sessions; corner badge yields to running spinner. */
|
|
54
|
+
subAgentCount?: number;
|
|
50
55
|
busy: boolean;
|
|
51
56
|
actionDisabled: boolean;
|
|
52
57
|
theme: WorkspaceTheme;
|
|
53
58
|
styles: AgentRowStyles;
|
|
54
59
|
onOpen: () => void;
|
|
55
|
-
|
|
60
|
+
/** Omit to hide the archive control (attention popover). */
|
|
61
|
+
onArchiveToggle?: () => void;
|
|
56
62
|
}): ReactNode {
|
|
57
63
|
const [hovered, setHovered] = useState(false);
|
|
58
64
|
// Web: hover-reveal. Native has no hover — keep the action visible.
|
|
@@ -76,6 +82,9 @@ export function AgentRow({
|
|
|
76
82
|
: theme.colors.foregroundMuted;
|
|
77
83
|
const stateLabels: string[] = [];
|
|
78
84
|
if (!archived && running) stateLabels.push("running");
|
|
85
|
+
if (subAgentCount > 0) {
|
|
86
|
+
stateLabels.push(subAgentCount === 1 ? "1 subagent" : `${subAgentCount} subagents`);
|
|
87
|
+
}
|
|
79
88
|
if (permissionCount > 0) {
|
|
80
89
|
stateLabels.push(
|
|
81
90
|
permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`,
|
|
@@ -84,6 +93,9 @@ export function AgentRow({
|
|
|
84
93
|
if (!archived && attentionKind === "error") stateLabels.push("failed");
|
|
85
94
|
if (!archived && attentionKind === "finished") stateLabels.push("turn finished, unread");
|
|
86
95
|
const stateSuffix = stateLabels.length > 0 ? `, ${stateLabels.join(", ")}` : "";
|
|
96
|
+
const showRunning = running && !archived;
|
|
97
|
+
const showSubAgentCount = !showRunning && subAgentCount > 0;
|
|
98
|
+
const subAgentLabel = subAgentCount > 99 ? "99+" : String(subAgentCount);
|
|
87
99
|
|
|
88
100
|
const body = (
|
|
89
101
|
<>
|
|
@@ -93,10 +105,19 @@ export function AgentRow({
|
|
|
93
105
|
size={18}
|
|
94
106
|
color={botColor}
|
|
95
107
|
/>
|
|
96
|
-
{
|
|
108
|
+
{showRunning ? (
|
|
97
109
|
<View style={styles.runningBadge}>
|
|
98
110
|
<RunningIndicator theme={theme} />
|
|
99
111
|
</View>
|
|
112
|
+
) : showSubAgentCount ? (
|
|
113
|
+
<View
|
|
114
|
+
accessibilityLabel={
|
|
115
|
+
subAgentCount === 1 ? "1 subagent" : `${subAgentCount} subagents`
|
|
116
|
+
}
|
|
117
|
+
style={styles.subAgentBadge}
|
|
118
|
+
>
|
|
119
|
+
<Text style={styles.subAgentBadgeText}>{subAgentLabel}</Text>
|
|
120
|
+
</View>
|
|
100
121
|
) : null}
|
|
101
122
|
</View>
|
|
102
123
|
<View style={styles.listMain}>
|
|
@@ -122,26 +143,32 @@ export function AgentRow({
|
|
|
122
143
|
) : null}
|
|
123
144
|
</View>
|
|
124
145
|
) : null}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
{onArchiveToggle ? (
|
|
147
|
+
<Pressable
|
|
148
|
+
accessibilityRole="button"
|
|
149
|
+
accessibilityLabel={archived ? `Unarchive ${label}` : `Archive ${label}`}
|
|
150
|
+
accessibilityState={{ disabled: actionDisabled }}
|
|
151
|
+
disabled={actionDisabled || !showAction}
|
|
152
|
+
hitSlop={8}
|
|
153
|
+
onPress={onArchiveToggle}
|
|
154
|
+
pointerEvents={showAction ? "auto" : "none"}
|
|
155
|
+
style={[styles.titleAction, { opacity: showAction ? 1 : 0 }]}
|
|
156
|
+
>
|
|
157
|
+
{busy ? (
|
|
158
|
+
<ActivityIndicator
|
|
159
|
+
size={14}
|
|
160
|
+
color={theme.colors.foregroundMuted}
|
|
161
|
+
style={{ width: 14, height: 14 }}
|
|
162
|
+
/>
|
|
163
|
+
) : (
|
|
164
|
+
<Icon
|
|
165
|
+
name={archived ? "ArchiveRestore" : "Archive"}
|
|
166
|
+
size={14}
|
|
167
|
+
color={theme.colors.foregroundMuted}
|
|
168
|
+
/>
|
|
169
|
+
)}
|
|
170
|
+
</Pressable>
|
|
171
|
+
) : null}
|
|
145
172
|
</>
|
|
146
173
|
);
|
|
147
174
|
|