@@ -31,7 +31,11 @@ type SidebarPanelDefinitionParams = {
3131 onCompanionSubmit : ( question : string ) => void ;
3232 onCompanionDraftChange : ( draft : string ) => void ;
3333 onCompanionVisibilityChange : ( visible : boolean ) => void ;
34+ connected : boolean ;
35+ pendingQuestion : string | null ;
36+ onClearCompanion : ( ) => void ;
3437 discussion : SessionDiscussionPanelConfig | null ;
38+ discussionOpenUrl : string | null ;
3539 discussionSourceGeneration : number ;
3640} ;
3741
@@ -46,66 +50,13 @@ type SidebarPanelTextKey =
4650 | "tasks"
4751 | "terminal" ;
4852
49- /**
50- * Header actions contributed by the panels that own content actions. Panels
51- * have no header of their own in the tabbed model, so anything acting on the
52- * active panel — the destructive side-chat clear, the discussion's external
53- * link — is only reachable through the shared side-panel header.
54- */
55- export function sidePanelHeaderActions ( params : {
56- connected : boolean ;
57- pendingQuestion : string | null ;
58- discussionOpenUrl : string | null ;
59- onClearCompanion : ( ) => void ;
60- } ) : SidebarPanelTemplates {
61- return {
62- ...( params . discussionOpenUrl
63- ? {
64- discussion : html `< a
65- class ="rail-header__action "
66- href =${ params . discussionOpenUrl }
67- target ="_blank"
68- rel="noopener"
69- aria-label=${ t ( "chat.sessionDiscussion.openExternal" ) }
70- title=${ t ( "chat.sessionDiscussion.openExternal" ) }
71- > ${ icons . externalLink } </ a
72- > ` ,
73- }
74- : { } ) ,
75- companion : html `< wa-dropdown
76- class ="chat-session-rail__menu "
77- placement ="bottom-end "
78- @wa-select =${ ( event : CustomEvent < { item : { value ?: string } } > ) => {
79- if ( event . detail . item . value === "clear" ) {
80- params . onClearCompanion ( ) ;
81- }
82- } }
83- >
84- < button
85- slot ="trigger "
86- class ="rail-header__action "
87- type ="button "
88- aria-label =${ t ( "chat.rail.moreActions" ) }
89- aria-haspopup ="menu"
90- aria-expanded="false"
91- >
92- ${ icons . moreHorizontal }
93- </ button >
94- < wa-dropdown-item
95- value ="clear "
96- ?disabled =${ ! params . connected || params . pendingQuestion !== null }
97- >
98- ${ t ( "chat.rail.clear" ) }
99- </ wa-dropdown-item >
100- </ wa-dropdown > ` ,
101- } ;
102- }
103-
10453/** One ordered declaration for every chat side-panel slot. */
10554export function sidebarPanelDefinitions (
10655 params ?: SidebarPanelDefinitionParams ,
10756) : SidebarPanelDefinition [ ] {
10857 const state = params ?. state ;
58+ // Metadata-only definitions have no pane context, so they describe types without offering tabs.
59+ const hasPaneContext = params !== undefined ;
10960 const terminalAvailable = state ?. terminalAvailable === true ;
11061 const browserAvailable = state ?. browserPanelAvailable === true ;
11162 const desktopAvailable = params ?. desktopAvailable === true ;
@@ -114,14 +65,15 @@ export function sidebarPanelDefinitions(
11465 textKey : SidebarPanelTextKey ,
11566 icon : TemplateResult ,
11667 content : TemplateResult | typeof nothing | null ,
117- options ?: { available ?: boolean ; shortcut ?: string } ,
68+ options ?: { available ?: boolean ; headerAction ?: TemplateResult ; shortcut ?: string } ,
11869 ) : SidebarPanelDefinition => ( {
11970 slot,
12071 label : t ( `chat.sidePanel.${ textKey } ` ) ,
12172 icon,
122- available : options ?. available ?? params !== undefined ,
73+ available : options ?. available ?? hasPaneContext ,
12374 content,
12475 empty : { description : t ( `chat.sidePanel.${ textKey } Empty` ) } ,
76+ ...( options ?. headerAction ? { headerAction : options . headerAction } : { } ) ,
12577 ...( options ?. shortcut ? { shortcut : options . shortcut } : { } ) ,
12678 } ) ;
12779 const terminal =
@@ -193,11 +145,59 @@ export function sidebarPanelDefinitions(
193145 definePanel ( "workspace" , "files" , icons . fileText , params ?. workspace ?? null , {
194146 shortcut : "⇧⌘B" ,
195147 } ) ,
196- definePanel ( "companion" , "companion" , icons . bot , companion ) ,
148+ definePanel (
149+ "companion" ,
150+ "companion" ,
151+ icons . bot ,
152+ companion ,
153+ params
154+ ? {
155+ headerAction : html `< wa-dropdown
156+ class ="chat-session-rail__menu "
157+ placement ="bottom-end "
158+ @wa-select =${ ( event : CustomEvent < { item : { value ?: string } } > ) => {
159+ if ( event . detail . item . value === "clear" ) {
160+ params . onClearCompanion ( ) ;
161+ }
162+ } }
163+ >
164+ < button
165+ slot ="trigger "
166+ class ="rail-header__action "
167+ type ="button "
168+ aria-label =${ t ( "chat.rail.moreActions" ) }
169+ aria-haspopup ="menu"
170+ aria-expanded="false"
171+ >
172+ ${ icons . moreHorizontal }
173+ </ button >
174+ < wa-dropdown-item
175+ value ="clear "
176+ ?disabled =${ ! params . connected || params . pendingQuestion !== null }
177+ >
178+ ${ t ( "chat.rail.clear" ) }
179+ </ wa-dropdown-item >
180+ </ wa-dropdown > ` ,
181+ }
182+ : undefined ,
183+ ) ,
197184 definePanel ( "tasks" , "tasks" , icons . listChecks , params ?. tasks ?? null ) ,
198185 definePanel ( "desktop" , "desktop" , icons . monitor , desktop , { available : desktopAvailable } ) ,
199186 definePanel ( "discussion" , "discussion" , icons . messageSquare , discussion , {
200187 available : discussion !== null ,
188+ ...( params ?. discussionOpenUrl
189+ ? {
190+ headerAction : html `< a
191+ class ="rail-header__action "
192+ href =${ params . discussionOpenUrl }
193+ target ="_blank"
194+ rel="noopener"
195+ aria-label=${ t ( "chat.sessionDiscussion.openExternal" ) }
196+ title=${ t ( "chat.sessionDiscussion.openExternal" ) }
197+ > ${ icons . externalLink } </ a
198+ > ` ,
199+ }
200+ : { } ) ,
201201 } ) ,
202202 definePanel ( "chat" , "boardChat" , icons . messageSquare , params ?. chat ?? null , {
203203 available : params ?. hasBoard === true ,
@@ -222,3 +222,13 @@ export function sidebarPanelTemplates(
222222 }
223223 return templates ;
224224}
225+
226+ export function sidebarPanelActions ( definitions : SidebarPanelDefinition [ ] ) : SidebarPanelTemplates {
227+ const actions : SidebarPanelTemplates = { } ;
228+ for ( const definition of definitions ) {
229+ if ( definition . headerAction ) {
230+ actions [ definition . slot ] = definition . headerAction ;
231+ }
232+ }
233+ return actions ;
234+ }
0 commit comments