Skip to content

Commit a32681f

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
feat(profile): show active turn badges on agent profile panel and popover (#1026)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 65b6d79 commit a32681f

6 files changed

Lines changed: 275 additions & 1 deletion

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default defineConfig({
3232
"**/channel-controls-screenshots.spec.ts",
3333
"**/team-management-screenshots.spec.ts",
3434
"**/active-turn-screenshots.spec.ts",
35+
"**/profile-active-turn-screenshots.spec.ts",
3536
"**/file-attachment.spec.ts",
3637
"**/video-attachment.spec.ts",
3738
"**/mentions.spec.ts",

‎desktop/src/features/profile/ui/UserProfilePanel.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
useRelayAgentsQuery,
1212
useManagedAgentsQuery,
1313
} from "@/features/agents/hooks";
14+
import { useActiveAgentTurnsBridge } from "@/features/agents/activeAgentTurnsStore";
15+
import { useManagedAgentObserverBridge } from "@/features/agents/observerRelayStore";
1416
import { EditAgentDialog } from "@/features/agents/ui/EditAgentDialog";
1517
import { useChannelsQuery } from "@/features/channels/hooks";
1618
import { usePresenceQuery } from "@/features/presence/hooks";
@@ -176,6 +178,18 @@ export function UserProfilePanel({
176178
);
177179
const isBot = Boolean(relayAgent || managedAgent);
178180
const isOwner = useIsManagedAgent(isBot ? pubkey : null);
181+
182+
// Populate the active-turns store for this agent so useActiveAgentTurns works
183+
// even if the Agents page hasn't been visited yet.
184+
const bridgeAgents = React.useMemo(
185+
() =>
186+
managedAgent
187+
? [{ pubkey: managedAgent.pubkey, status: managedAgent.status }]
188+
: [],
189+
[managedAgent],
190+
);
191+
useActiveAgentTurnsBridge(bridgeAgents);
192+
useManagedAgentObserverBridge(bridgeAgents);
179193
const canEditAgent = isOwner === true && managedAgent !== undefined;
180194
const memoryQuery = useAgentMemoryQuery(pubkey, {
181195
enabled: isOwner === true,
@@ -201,6 +215,14 @@ export function UserProfilePanel({
201215
[pubkeyLower, relayAgent, managedAgent, channelsQuery.data],
202216
);
203217

218+
const channelIdToName = React.useMemo(() => {
219+
const map: Record<string, string> = {};
220+
for (const channel of channelsQuery.data ?? []) {
221+
map[channel.id] = channel.name;
222+
}
223+
return map;
224+
}, [channelsQuery.data]);
225+
204226
const prevPubkeyRef = React.useRef(pubkey);
205227
if (prevPubkeyRef.current !== pubkey) {
206228
prevPubkeyRef.current = pubkey;
@@ -297,6 +319,7 @@ export function UserProfilePanel({
297319
canEditAgent={canEditAgent}
298320
canViewActivity={canViewActivity}
299321
channelCount={profileChannels.length}
322+
channelIdToName={channelIdToName}
300323
channelsLoading={channelsQuery.isLoading}
301324
displayName={displayName}
302325
followMutation={followMutation}

‎desktop/src/features/profile/ui/UserProfilePanelSections.tsx‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import { toast } from "sonner";
2323

2424
import { MemorySection } from "@/features/agent-memory/ui/MemorySection";
2525
import { AgentStatusBadge } from "@/features/agents/ui/AgentStatusBadge";
26+
import { useActiveAgentTurns } from "@/features/agents/activeAgentTurnsStore";
27+
import { formatElapsed } from "@/features/agents/ui/agentSessionUtils";
28+
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
2629
import { getPresenceLabel } from "@/features/presence/lib/presence";
2730
import { PresenceDot } from "@/features/presence/ui/PresenceBadge";
2831
import type {
@@ -36,6 +39,8 @@ import { StatusEmoji } from "@/features/user-status/ui/StatusEmoji";
3639
import { BotIdenticon } from "@/features/messages/ui/BotIdenticon";
3740
import type { ManagedAgent, RelayAgent } from "@/shared/api/types";
3841
import { cn } from "@/shared/lib/cn";
42+
import { useNow } from "@/shared/lib/useNow";
43+
import { Badge } from "@/shared/ui/badge";
3944

4045
const RUNTIME_LABELS: Record<string, string> = {
4146
goose: "Goose",
@@ -59,6 +64,7 @@ export type ProfileSummaryViewProps = {
5964
canEditAgent: boolean;
6065
canViewActivity: boolean;
6166
channelCount: number;
67+
channelIdToName: Record<string, string>;
6268
channelsLoading: boolean;
6369
displayName: string;
6470
followMutation: ReturnType<typeof useFollowMutation>;
@@ -90,6 +96,7 @@ export function ProfileSummaryView({
9096
canEditAgent,
9197
canViewActivity,
9298
channelCount,
99+
channelIdToName,
93100
channelsLoading,
94101
displayName,
95102
followMutation,
@@ -116,6 +123,9 @@ export function ProfileSummaryView({
116123
unfollowMutation,
117124
userStatus,
118125
}: ProfileSummaryViewProps) {
126+
const { goChannel } = useAppNavigation();
127+
const activeTurns = useActiveAgentTurns(isBot ? pubkey : null);
128+
119129
const metadataFields = [
120130
...buildPublicFields({
121131
pubkey,
@@ -161,6 +171,20 @@ export function ProfileSummaryView({
161171
/>
162172
) : null}
163173

174+
{activeTurns.length > 0 ? (
175+
<div className="flex flex-wrap justify-center gap-1.5">
176+
{activeTurns.map(({ channelId, observedAt }) => (
177+
<ProfileWorkingBadge
178+
key={channelId}
179+
channelId={channelId}
180+
name={channelIdToName[channelId] ?? channelId}
181+
observedAt={observedAt}
182+
onNavigate={goChannel}
183+
/>
184+
))}
185+
</div>
186+
) : null}
187+
164188
{showMemoriesIngress || showChannelsIngress || canViewActivity ? (
165189
<section className="space-y-2">
166190
{showMemoriesIngress ? (
@@ -211,6 +235,30 @@ export function ProfileSummaryView({
211235
);
212236
}
213237

238+
function ProfileWorkingBadge({
239+
channelId,
240+
name,
241+
observedAt,
242+
onNavigate,
243+
}: {
244+
channelId: string;
245+
name: string;
246+
observedAt: number;
247+
onNavigate: (channelId: string) => void;
248+
}) {
249+
const now = useNow(1000);
250+
251+
return (
252+
<Badge
253+
className="cursor-pointer motion-safe:animate-pulse normal-case tracking-normal hover:opacity-80"
254+
variant="default"
255+
onClick={() => onNavigate(channelId)}
256+
>
257+
Working in #{name} · {formatElapsed(now - observedAt)}
258+
</Badge>
259+
);
260+
}
261+
214262
// ── Hero & metadata ──────────────────────────────────────────────────────────
215263

216264
function ProfileHero({

‎desktop/src/features/profile/ui/UserProfilePopover.tsx‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
useRelayAgentsQuery,
77
useManagedAgentsQuery,
88
} from "@/features/agents/hooks";
9+
import { useActiveAgentTurns } from "@/features/agents/activeAgentTurnsStore";
10+
import { formatElapsed } from "@/features/agents/ui/agentSessionUtils";
911
import { usePresenceQuery } from "@/features/presence/hooks";
1012
import { useUserStatusQuery } from "@/features/user-status/hooks";
13+
import { useChannelsQuery } from "@/features/channels/hooks";
1114
import { StatusEmoji } from "@/features/user-status/ui/StatusEmoji";
1215
import { PresenceBadge } from "@/features/presence/ui/PresenceBadge";
1316
import { rewriteRelayUrl } from "@/shared/lib/mediaUrl";
@@ -16,6 +19,7 @@ import { useProfilePanel } from "@/shared/context/ProfilePanelContext";
1619

1720
import { Popover, PopoverAnchor, PopoverContent } from "@/shared/ui/popover";
1821
import { BotIdenticon } from "@/features/messages/ui/BotIdenticon";
22+
import { useNow } from "@/shared/lib/useNow";
1923

2024
type UserProfilePopoverProps = {
2125
children: React.ReactNode;
@@ -90,6 +94,15 @@ export function UserProfilePopover({
9094
const profile = profileQuery.data;
9195
const presenceStatus = presenceQuery.data?.[pubkey.toLowerCase()];
9296
const userStatus = userStatusQuery.data?.[pubkey.toLowerCase()];
97+
const activeTurns = useActiveAgentTurns(role === "bot" ? pubkey : null);
98+
const channelsQuery = useChannelsQuery();
99+
const channelIdToName = React.useMemo(() => {
100+
const map: Record<string, string> = {};
101+
for (const channel of channelsQuery.data ?? []) {
102+
map[channel.id] = channel.name;
103+
}
104+
return map;
105+
}, [channelsQuery.data]);
93106

94107
const clearHoverTimer = React.useCallback(() => {
95108
if (hoverTimerRef.current !== null) {
@@ -243,6 +256,18 @@ export function UserProfilePopover({
243256
</div>
244257
) : null}
245258

259+
{activeTurns.length > 0 ? (
260+
<div className="flex flex-wrap gap-1.5">
261+
{activeTurns.map(({ channelId, observedAt }) => (
262+
<PopoverWorkingBadge
263+
key={channelId}
264+
name={channelIdToName[channelId] ?? channelId}
265+
observedAt={observedAt}
266+
/>
267+
))}
268+
</div>
269+
) : null}
270+
246271
{profile?.about ? (
247272
<p className="text-xs leading-relaxed text-muted-foreground">
248273
{profile.about}
@@ -268,3 +293,19 @@ export function UserProfilePopover({
268293
</Popover>
269294
);
270295
}
296+
297+
function PopoverWorkingBadge({
298+
name,
299+
observedAt,
300+
}: {
301+
name: string;
302+
observedAt: number;
303+
}) {
304+
const now = useNow(1000);
305+
306+
return (
307+
<span className="inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary motion-safe:animate-pulse">
308+
Working in #{name} · {formatElapsed(now - observedAt)}
309+
</span>
310+
);
311+
}

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,24 @@ function getMockMessageStore(channelId: string): RelayEvent[] {
21692169
sig: "mocksig".repeat(20).slice(0, 128),
21702170
},
21712171
]
2172-
: [];
2172+
: channelId === "94a444a4-c0a3-5966-ab05-530c6ddc2301"
2173+
? [
2174+
// Charlie is a `bot` member of #agents (see channel seed), so this
2175+
// message renders with role="bot" — the surface whose avatar opens
2176+
// a managed-agent profile panel / hover popover with active-turn
2177+
// badges. #agents has no message-row index assertions, so seeding
2178+
// here is safe for existing specs.
2179+
{
2180+
id: "mock-agents-charlie",
2181+
pubkey: CHARLIE_PUBKEY,
2182+
created_at: Math.floor(Date.now() / 1000) - 90,
2183+
kind: 9,
2184+
tags: [["h", channelId]],
2185+
content: "Indexing the channel catalog now.",
2186+
sig: "mocksig".repeat(20).slice(0, 128),
2187+
},
2188+
]
2189+
: [];
21732190

21742191
mockMessages.set(channelId, seeded);
21752192
return seeded;

0 commit comments

Comments
 (0)