11import * as React from "react" ;
22import { CheckCheck } from "lucide-react" ;
33
4+ import { useAppNavigation } from "@/app/navigation/useAppNavigation" ;
45import { cn } from "@/shared/lib/cn" ;
6+ import { useProfilePanel } from "@/shared/context/ProfilePanelContext" ;
7+ import { Markdown } from "@/shared/ui/markdown" ;
58import { UserAvatar } from "@/shared/ui/UserAvatar" ;
9+ import { useAgentSessionTranscriptVariant } from "../agentSessionTranscriptContext" ;
10+ import { MessageLinkHoverCue } from "../activityRenderClasses/MessageLinkHoverCue" ;
611import { TranscriptTimestamp } from "../activityRenderClasses/TranscriptTimestamp" ;
12+ import { useTranscriptBubbleOverflow } from "../activityRenderClasses/useTranscriptBubbleOverflow" ;
713import { compactSummaryTone } from "./CompactToolSummaryRow" ;
814import type { SentMessageLink } from "./messageLinks" ;
915import { SentMessageContextDialog } from "./SentMessageContextDialog" ;
@@ -20,6 +26,7 @@ export function CompactMessageSummary({
2026 label,
2127 messageLink,
2228 preview,
29+ pubkey,
2330 result,
2431 timestamp,
2532} : {
@@ -34,34 +41,139 @@ export function CompactMessageSummary({
3441 label : string ;
3542 messageLink : SentMessageLink | null ;
3643 preview : string | null ;
44+ pubkey : string ;
3745 result : string ;
3846 timestamp : string ;
3947} ) {
4048 const [ detailsOpen , setDetailsOpen ] = React . useState ( false ) ;
49+ const variant = useAgentSessionTranscriptVariant ( ) ;
50+ const { goChannel } = useAppNavigation ( ) ;
51+ const { openProfilePanel } = useProfilePanel ( ) ;
52+ const isCompactPreview = variant === "compactPreview" ;
53+ const shouldClampBubble = ! isCompactPreview ;
54+ const [ bubbleRef , hasBubbleOverflow ] =
55+ useTranscriptBubbleOverflow ( shouldClampBubble ) ;
56+ const canOpenMessage = shouldClampBubble && messageLink !== null ;
4157 const mutedTone = compactSummaryTone ( ) ;
58+ const avatarClassName = cn (
59+ "mr-2 mt-1 shrink-0" ,
60+ isCompactPreview ? "size-5" : "size-7" ,
61+ ) ;
62+ const handleBubbleClick = React . useCallback (
63+ ( event : React . MouseEvent < HTMLDivElement > ) => {
64+ if ( ! messageLink || isNestedInteractiveTarget ( event ) ) return ;
65+ event . preventDefault ( ) ;
66+ event . stopPropagation ( ) ;
67+ void goChannel ( messageLink . channelId , {
68+ messageId : messageLink . messageId ,
69+ } ) ;
70+ } ,
71+ [ goChannel , messageLink ] ,
72+ ) ;
73+ const handleBubbleKeyDown = React . useCallback (
74+ ( event : React . KeyboardEvent < HTMLDivElement > ) => {
75+ if (
76+ ! messageLink ||
77+ isNestedInteractiveTarget ( event ) ||
78+ ( event . key !== "Enter" && event . key !== " " )
79+ ) {
80+ return ;
81+ }
82+
83+ event . preventDefault ( ) ;
84+ event . stopPropagation ( ) ;
85+ void goChannel ( messageLink . channelId , {
86+ messageId : messageLink . messageId ,
87+ } ) ;
88+ } ,
89+ [ goChannel , messageLink ] ,
90+ ) ;
91+ const bubbleLinkProps = canOpenMessage
92+ ? {
93+ onClick : handleBubbleClick ,
94+ onKeyDown : handleBubbleKeyDown ,
95+ role : "link" as const ,
96+ tabIndex : 0 ,
97+ }
98+ : { } ;
4299 return (
43100 < >
44101 < div className = "flex max-w-full flex-row items-start justify-start" >
45- < UserAvatar
46- avatarUrl = { avatarUrl }
47- className = "mr-2 mt-1 shrink-0"
48- displayName = { displayName }
49- size = "xs"
50- testId = "transcript-agent-sent-avatar"
51- />
52- < div className = "flex max-w-[85%] min-w-0 flex-col items-start gap-1" >
102+ { openProfilePanel && ! isCompactPreview ? (
103+ < button
104+ aria-label = { `Open ${ displayName } profile` }
105+ className = { cn (
106+ avatarClassName ,
107+ "pointer-events-auto rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" ,
108+ ) }
109+ onClick = { ( event ) => {
110+ event . preventDefault ( ) ;
111+ event . stopPropagation ( ) ;
112+ openProfilePanel ( pubkey ) ;
113+ } }
114+ type = "button"
115+ >
116+ < UserAvatar
117+ avatarUrl = { avatarUrl }
118+ className = "size-full text-xs"
119+ displayName = { displayName }
120+ size = "sm"
121+ testId = "transcript-agent-sent-avatar"
122+ />
123+ </ button >
124+ ) : (
125+ < UserAvatar
126+ avatarUrl = { avatarUrl }
127+ className = { cn (
128+ avatarClassName ,
129+ isCompactPreview ? "text-3xs" : "text-xs" ,
130+ ) }
131+ displayName = { displayName }
132+ size = "sm"
133+ testId = "transcript-agent-sent-avatar"
134+ />
135+ ) }
136+ < div className = "flex min-w-0 flex-1 flex-col items-start gap-1" >
53137 < div
54138 className = { cn (
55- "min-w-0 rounded-2xl border px-3 py-2 text-sm leading-relaxed shadow-sm" ,
56- isError
57- ? "border-destructive/25 bg-destructive/10 text-destructive"
58- : "border-primary/15 bg-primary/6 text-foreground" ,
139+ "w-full min-w-0 rounded-2xl border px-3 py-2 shadow-sm" ,
140+ isCompactPreview
141+ ? "text-xs leading-4"
142+ : "text-sm leading-relaxed" ,
143+ shouldClampBubble && "relative max-h-36 overflow-hidden" ,
144+ canOpenMessage &&
145+ "group/bubble cursor-pointer transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" ,
146+ isCompactPreview
147+ ? isError
148+ ? "border-destructive/25 bg-destructive/10 text-destructive"
149+ : "border-transparent bg-muted text-foreground"
150+ : isError
151+ ? "border-destructive/25 bg-destructive/10 text-destructive"
152+ : "border-transparent bg-muted text-foreground" ,
153+ canOpenMessage &&
154+ ( isError ? "hover:bg-destructive/15" : "hover:bg-muted/90" ) ,
59155 ) }
60156 data-testid = "transcript-tool-message-preview"
157+ ref = { bubbleRef }
158+ { ...bubbleLinkProps }
61159 >
62- < p className = "whitespace-pre-wrap wrap-break-word" >
63- { preview || "Message content unavailable." }
64- </ p >
160+ < Markdown
161+ className = { isCompactPreview ? "text-xs leading-4" : "leading-5" }
162+ content = { preview || "Message content unavailable." }
163+ />
164+ { hasBubbleOverflow ? (
165+ < span
166+ className = { cn (
167+ "pointer-events-none absolute inset-x-0 bottom-0 h-8 rounded-b-2xl bg-linear-to-b from-transparent" ,
168+ isError
169+ ? "to-destructive/10"
170+ : isCompactPreview
171+ ? "to-muted"
172+ : "to-muted" ,
173+ ) }
174+ />
175+ ) : null }
176+ { canOpenMessage ? < MessageLinkHoverCue /> : null }
65177 </ div >
66178 < div className = "inline-flex max-w-full items-center gap-1.5 px-1" >
67179 < TranscriptTimestamp
@@ -100,3 +212,16 @@ export function CompactMessageSummary({
100212 </ >
101213 ) ;
102214}
215+
216+ function isNestedInteractiveTarget (
217+ event : React . MouseEvent < HTMLElement > | React . KeyboardEvent < HTMLElement > ,
218+ ) {
219+ const target =
220+ event . target instanceof Element
221+ ? event . target . closest (
222+ "a,button,input,select,textarea,summary,[role='button'],[role='link']" ,
223+ )
224+ : null ;
225+
226+ return target !== null && target !== event . currentTarget ;
227+ }
0 commit comments