Skip to content

Commit a77d854

Browse files
feat(desktop): move agent activity below composer
Co-authored-by: Cursor <[email protected]>
1 parent 04c6b99 commit a77d854

5 files changed

Lines changed: 230 additions & 47 deletions

File tree

‎desktop/src/features/channels/ui/BotActivityBar.tsx‎

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as React from "react";
22
import { Loader2 } from "lucide-react";
33

4+
import { useAgentTranscript } from "@/features/agents/ui/useObserverEvents";
5+
import type { TranscriptItem } from "@/features/agents/ui/agentSessionTypes";
6+
import { formatToolTitle } from "@/features/agents/ui/agentSessionToolCatalog";
47
import type { UserProfileLookup } from "@/features/profile/lib/identity";
58
import type { ManagedAgent } from "@/shared/api/types";
69
import { cn } from "@/shared/lib/cn";
@@ -11,21 +14,38 @@ export type BotActivityAgent = Pick<ManagedAgent, "pubkey" | "name">;
1114

1215
type BotActivityBarProps = {
1316
agents: BotActivityAgent[];
17+
channelId?: string | null;
1418
onOpenAgentSession: (pubkey: string) => void;
1519
openAgentSessionPubkey: string | null;
1620
profiles?: UserProfileLookup;
1721
typingBotPubkeys: string[];
22+
variant?: "toolbar" | "inline";
1823
};
1924

2025
const HOVER_OPEN_DELAY_MS = 150;
2126
const HOVER_CLOSE_DELAY_MS = 180;
27+
const HEADLINE_ROTATION_MS = 2200;
28+
29+
function getActivityHeadline(item: TranscriptItem): string | null {
30+
if (item.type === "tool") {
31+
return formatToolTitle(item.sproutToolName ?? item.toolName, item.title);
32+
}
33+
34+
if (item.type === "message") {
35+
return item.role === "assistant" ? "Responding" : item.title;
36+
}
37+
38+
return item.title;
39+
}
2240

2341
export function BotActivityComposerAction({
2442
agents,
43+
channelId = null,
2544
onOpenAgentSession,
2645
openAgentSessionPubkey,
2746
profiles,
2847
typingBotPubkeys,
48+
variant = "toolbar",
2949
}: BotActivityBarProps) {
3050
const [open, setOpen] = React.useState(false);
3151
const hoverTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(
@@ -39,6 +59,39 @@ export function BotActivityComposerAction({
3959

4060
return agents.filter((agent) => typingSet.has(agent.pubkey.toLowerCase()));
4161
}, [agents, typingBotPubkeys]);
62+
const singleTypingAgent =
63+
typingAgents.length === 1 ? (typingAgents[0] ?? null) : null;
64+
const transcript = useAgentTranscript(
65+
Boolean(singleTypingAgent),
66+
singleTypingAgent?.pubkey,
67+
);
68+
const activityHeadlines = React.useMemo(() => {
69+
if (!singleTypingAgent) {
70+
return [];
71+
}
72+
73+
const seen = new Set<string>();
74+
const headlines: string[] = [];
75+
const scopedTranscript = channelId
76+
? transcript.filter((item) => item.channelId === channelId)
77+
: transcript;
78+
79+
for (let i = scopedTranscript.length - 1; i >= 0; i--) {
80+
const headline = getActivityHeadline(scopedTranscript[i]);
81+
if (!headline || seen.has(headline)) {
82+
continue;
83+
}
84+
85+
seen.add(headline);
86+
headlines.unshift(headline);
87+
if (headlines.length >= 5) {
88+
break;
89+
}
90+
}
91+
92+
return headlines;
93+
}, [channelId, singleTypingAgent, transcript]);
94+
const [headlineIndex, setHeadlineIndex] = React.useState(0);
4295

4396
const clearHoverTimer = React.useCallback(() => {
4497
if (hoverTimerRef.current !== null) {
@@ -69,6 +122,18 @@ export function BotActivityComposerAction({
69122
return () => clearHoverTimer();
70123
}, [clearHoverTimer]);
71124

125+
React.useEffect(() => {
126+
if (activityHeadlines.length <= 1) {
127+
return;
128+
}
129+
130+
const interval = window.setInterval(() => {
131+
setHeadlineIndex((current) => (current + 1) % activityHeadlines.length);
132+
}, HEADLINE_ROTATION_MS);
133+
134+
return () => window.clearInterval(interval);
135+
}, [activityHeadlines.length]);
136+
72137
if (typingAgents.length === 0) {
73138
return null;
74139
}
@@ -80,13 +145,26 @@ export function BotActivityComposerAction({
80145
typingAgents.length === 1
81146
? `${typingAgents[0]?.name ?? "Agent"} is working`
82147
: `${typingAgents.length} agents working`;
148+
const isInline = variant === "inline";
149+
const visibleStatusLabel =
150+
typingAgents.length === 1
151+
? `${typingAgents[0]?.name ?? "Agent"}: ${
152+
activityHeadlines[headlineIndex % activityHeadlines.length] ??
153+
"Working"
154+
}`
155+
: `${typingAgents[0]?.name ?? "Agent"} +${typingAgents.length - 1}`;
83156

84157
return (
85158
<Popover onOpenChange={setOpen} open={open}>
86159
<PopoverTrigger asChild>
87160
<button
88161
aria-label={`${triggerLabel}. View activity.`}
89-
className="inline-flex h-9 min-w-9 items-center justify-center gap-1.5 rounded-full border border-border/60 bg-background px-2 text-xs font-medium text-muted-foreground transition-colors hover:border-primary/30 hover:bg-primary/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring data-[state=open]:border-primary/40 data-[state=open]:bg-primary/10 data-[state=open]:text-primary"
162+
className={cn(
163+
"inline-flex items-center justify-center rounded-full border border-border/60 bg-background font-medium text-muted-foreground transition-colors hover:border-primary/30 hover:bg-primary/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring data-[state=open]:border-primary/40 data-[state=open]:bg-primary/10 data-[state=open]:text-primary",
164+
isInline
165+
? "h-7 min-w-0 gap-2 border-transparent bg-transparent px-0 text-xs font-semibold leading-none shadow-none hover:border-transparent hover:bg-transparent data-[state=open]:border-transparent data-[state=open]:bg-transparent"
166+
: "h-9 min-w-9 gap-1.5 px-2 text-xs",
167+
)}
90168
data-testid="bot-activity-composer-trigger"
91169
onBlur={closeWithDelay}
92170
onClick={() => {
@@ -102,7 +180,12 @@ export function BotActivityComposerAction({
102180
{typingAgents.slice(0, 2).map((agent) => (
103181
<UserAvatar
104182
avatarUrl={agentAvatarUrl(agent)}
105-
className="!h-5 !w-5 rounded-full border border-background text-[8px]"
183+
className={cn(
184+
"rounded-full border border-background",
185+
isInline
186+
? "!h-[18px] !w-[18px] shadow-sm ring-1 ring-primary/25 text-[7px]"
187+
: "!h-5 !w-5 text-[8px]",
188+
)}
106189
displayName={agent.name}
107190
key={agent.pubkey}
108191
/>
@@ -113,11 +196,20 @@ export function BotActivityComposerAction({
113196
+{typingAgents.length - 2}
114197
</span>
115198
) : null}
116-
<Loader2 className="h-3.5 w-3.5 shrink-0 animate-spin opacity-70" />
199+
<span
200+
className={cn(
201+
isInline ? "agent-activity-shimmer max-w-40 truncate" : "sr-only",
202+
)}
203+
>
204+
{isInline ? visibleStatusLabel : "working"}
205+
</span>
206+
{isInline ? null : (
207+
<Loader2 className="h-3.5 w-3.5 shrink-0 animate-spin opacity-70" />
208+
)}
117209
</button>
118210
</PopoverTrigger>
119211
<PopoverContent
120-
align="end"
212+
align={isInline ? "start" : "end"}
121213
className="w-64 p-2"
122214
onMouseEnter={keepOpen}
123215
onMouseLeave={closeWithDelay}

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export const ChannelPane = React.memo(function ChannelPane({
260260
}
261261
return pubkeys;
262262
}, [botTypingEntries]);
263+
const hasComposerBotActivity = composerBotTypingPubkeys.length > 0;
263264
const threadComposerBotTypingPubkeys = React.useMemo(() => {
264265
if (!openThreadHeadId) {
265266
return [];
@@ -281,6 +282,8 @@ export const ChannelPane = React.memo(function ChannelPane({
281282
}
282283
return pubkeys;
283284
}, [botTypingEntries, openThreadHeadId]);
285+
const hasThreadComposerBotActivity =
286+
threadComposerBotTypingPubkeys.length > 0;
284287

285288
const selectedAgent = React.useMemo(
286289
() =>
@@ -378,15 +381,6 @@ export const ChannelPane = React.memo(function ChannelPane({
378381
onEditSave={onEditSave}
379382
onSend={onSendMessage}
380383
profiles={profiles}
381-
toolbarExtraActions={
382-
<BotActivityComposerAction
383-
agents={activityAgents}
384-
onOpenAgentSession={onOpenAgentSession}
385-
openAgentSessionPubkey={openAgentSessionPubkey}
386-
profiles={profiles}
387-
typingBotPubkeys={composerBotTypingPubkeys}
388-
/>
389-
}
390384
placeholder={
391385
activeChannel?.archivedAt
392386
? "Archived channels are read-only."
@@ -398,16 +392,32 @@ export const ChannelPane = React.memo(function ChannelPane({
398392
}
399393
showTopBorder={false}
400394
/>
401-
<div className="h-6 bg-background">
402-
{hasTypingActivity ? (
403-
<TypingIndicatorRow
404-
channel={activeChannel}
405-
className="px-4 pb-1 pt-0 sm:px-6"
406-
currentPubkey={currentPubkey}
407-
profiles={profiles}
408-
typingPubkeys={typingPubkeys}
409-
/>
410-
) : null}
395+
<div className="h-7 bg-background px-4 pb-1 pt-0 sm:px-6 -mt-1">
396+
<div className="mx-auto flex h-full w-full max-w-4xl items-center gap-2">
397+
{hasComposerBotActivity ? (
398+
<div className="shrink-0">
399+
<BotActivityComposerAction
400+
agents={activityAgents}
401+
channelId={activeChannel?.id ?? null}
402+
onOpenAgentSession={onOpenAgentSession}
403+
openAgentSessionPubkey={openAgentSessionPubkey}
404+
profiles={profiles}
405+
typingBotPubkeys={composerBotTypingPubkeys}
406+
variant="inline"
407+
/>
408+
</div>
409+
) : null}
410+
{hasTypingActivity ? (
411+
<TypingIndicatorRow
412+
channel={activeChannel}
413+
className="min-w-0 flex-1 px-0 py-0"
414+
currentPubkey={currentPubkey}
415+
profiles={profiles}
416+
typingPubkeys={typingPubkeys}
417+
variant="activity"
418+
/>
419+
) : null}
420+
</div>
411421
</div>
412422
</div>
413423
</div>
@@ -446,13 +456,17 @@ export const ChannelPane = React.memo(function ChannelPane({
446456
threadReplies={threadMessages}
447457
threadTypingPubkeys={threadTypingPubkeys}
448458
toolbarExtraActions={
449-
<BotActivityComposerAction
450-
agents={activityAgents}
451-
onOpenAgentSession={onOpenAgentSession}
452-
openAgentSessionPubkey={openAgentSessionPubkey}
453-
profiles={profiles}
454-
typingBotPubkeys={threadComposerBotTypingPubkeys}
455-
/>
459+
hasThreadComposerBotActivity ? (
460+
<BotActivityComposerAction
461+
agents={activityAgents}
462+
channelId={activeChannel?.id ?? null}
463+
onOpenAgentSession={onOpenAgentSession}
464+
openAgentSessionPubkey={openAgentSessionPubkey}
465+
profiles={profiles}
466+
typingBotPubkeys={threadComposerBotTypingPubkeys}
467+
variant="inline"
468+
/>
469+
) : null
456470
}
457471
/>
458472
) : activeChannel && selectedAgent ? (

‎desktop/src/features/messages/ui/MessageThreadPanel.tsx‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,25 @@ export function MessageThreadPanel({
310310
placeholder={`Reply in thread to ${threadHead.author}`}
311311
profiles={profiles}
312312
replyTarget={composerReplyTarget}
313-
toolbarExtraActions={toolbarExtraActions}
314313
typingParentEventId={threadHead.id}
315314
typingRootEventId={threadHead.rootId}
316315
/>
317-
<div className="h-6 bg-background">
318-
{threadTypingPubkeys.length > 0 ? (
319-
<TypingIndicatorRow
320-
channel={channel}
321-
className="px-4 pb-1 pt-0 sm:px-6"
322-
currentPubkey={currentPubkey}
323-
profiles={profiles}
324-
typingPubkeys={threadTypingPubkeys}
325-
/>
326-
) : null}
316+
<div className="h-7 bg-background px-4 pb-1 pt-0 sm:px-6 -mt-1">
317+
<div className="mx-auto flex h-full w-full max-w-4xl items-center gap-2">
318+
{toolbarExtraActions ? (
319+
<div className="shrink-0">{toolbarExtraActions}</div>
320+
) : null}
321+
{threadTypingPubkeys.length > 0 ? (
322+
<TypingIndicatorRow
323+
channel={channel}
324+
className="min-w-0 flex-1 px-0 py-0"
325+
currentPubkey={currentPubkey}
326+
profiles={profiles}
327+
typingPubkeys={threadTypingPubkeys}
328+
variant="activity"
329+
/>
330+
) : null}
331+
</div>
327332
</div>
328333
</div>
329334
</div>

‎desktop/src/features/messages/ui/TypingIndicatorRow.tsx‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type TypingIndicatorRowProps = {
1414
currentPubkey?: string;
1515
profiles?: UserProfileLookup;
1616
typingPubkeys: string[];
17+
variant?: "default" | "activity";
1718
};
1819

1920
function resolveFallbackName(channel: Channel | null, pubkey: string) {
@@ -54,7 +55,9 @@ export function TypingIndicatorRow({
5455
currentPubkey,
5556
profiles,
5657
typingPubkeys,
58+
variant = "default",
5759
}: TypingIndicatorRowProps) {
60+
const isActivityVariant = variant === "activity";
5861
const labels = React.useMemo(
5962
() =>
6063
typingPubkeys.map((pubkey) =>
@@ -72,35 +75,63 @@ export function TypingIndicatorRow({
7275
return (
7376
<div
7477
aria-live="polite"
75-
className={cn("shrink-0 bg-transparent px-4 py-2 sm:px-6", className)}
78+
className={cn(
79+
"shrink-0 bg-transparent",
80+
isActivityVariant
81+
? "flex h-7 items-center px-0 py-0"
82+
: "px-4 py-2 sm:px-6",
83+
className,
84+
)}
7685
{...(labels.length > 0
7786
? { "data-testid": "message-typing-indicator" }
7887
: {})}
7988
>
8089
{labels.length > 0 && (
81-
<div className="mx-auto flex w-full max-w-4xl items-center gap-2">
90+
<div
91+
className={cn(
92+
"flex w-full items-center gap-2",
93+
isActivityVariant && "h-full",
94+
!isActivityVariant && "mx-auto max-w-4xl",
95+
)}
96+
>
8297
<div className="flex shrink-0 items-center">
8398
{typingPubkeys.map((pubkey, index) => {
8499
const profile = profiles?.[pubkey.toLowerCase()];
85100
const label = labels[index] ?? pubkey.slice(0, 8);
86101
return (
87102
<div
88103
key={pubkey}
89-
className={`relative h-5 w-5 shrink-0 rounded-full ring-1 ring-background${index > 0 ? " -ml-1.5" : ""}`}
104+
className={cn(
105+
"relative shrink-0 rounded-full ring-1 ring-background",
106+
isActivityVariant ? "h-[18px] w-[18px]" : "h-5 w-5",
107+
index > 0 && "-ml-1.5",
108+
)}
90109
data-testid="message-typing-avatar"
91110
>
92111
<ProfileAvatar
93112
avatarUrl={profile?.avatarUrl ?? null}
94113
label={label}
95-
className="h-5 w-5 rounded-full text-[8px]"
96-
iconClassName="h-3 w-3"
114+
className={cn(
115+
"rounded-full",
116+
isActivityVariant
117+
? "h-[18px] w-[18px] text-[7px]"
118+
: "h-5 w-5 text-[8px]",
119+
)}
120+
iconClassName={
121+
isActivityVariant ? "h-2.5 w-2.5" : "h-3 w-3"
122+
}
97123
/>
98124
</div>
99125
);
100126
})}
101127
</div>
102128
<p
103-
className="truncate text-sm text-muted-foreground"
129+
className={cn(
130+
"truncate text-muted-foreground",
131+
isActivityVariant
132+
? "agent-activity-shimmer text-xs font-semibold leading-none"
133+
: "text-sm",
134+
)}
104135
data-testid="message-typing-indicator-label"
105136
>
106137
{formatTypingLabel(labels)}

0 commit comments

Comments
 (0)