11import * as React from "react" ;
22import { 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" ;
47import type { UserProfileLookup } from "@/features/profile/lib/identity" ;
58import type { ManagedAgent } from "@/shared/api/types" ;
69import { cn } from "@/shared/lib/cn" ;
@@ -11,21 +14,38 @@ export type BotActivityAgent = Pick<ManagedAgent, "pubkey" | "name">;
1114
1215type 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
2025const HOVER_OPEN_DELAY_MS = 150 ;
2126const 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
2341export 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 }
0 commit comments