@@ -23,11 +23,13 @@ import { ChatController } from './chat-controller.js';
2323import { ChatHistoryController } from './chat-history-controller.js' ;
2424import {
2525 lazyMultiInject ,
26- ComponentType ,
27- type ChatInputComponent ,
28- type ChatInputFooterComponent ,
29- type CitationActionComponent ,
26+ ControllerType ,
27+ type ChatInputController ,
28+ type ChatInputFooterController ,
29+ type CitationController ,
30+ type ChatSectionController ,
3031} from './composable.js' ;
32+ import { ChatContextController } from './chat-context.js' ;
3133
3234/**
3335 * A chat component that allows the user to ask questions and get answers from an API.
@@ -50,10 +52,22 @@ export class ChatComponent extends LitElement {
5052 inputPosition = 'sticky' ;
5153
5254 @property ( { type : String , attribute : 'data-interaction-model' } )
53- interactionModel : 'ask' | 'chat' = 'chat' ;
55+ set interactionModel ( value : 'ask' | 'chat' ) {
56+ this . chatContext . interactionModel = value || 'chat' ;
57+ }
58+
59+ get interactionModel ( ) : 'ask' | 'chat' {
60+ return this . chatContext . interactionModel ;
61+ }
5462
5563 @property ( { type : String , attribute : 'data-api-url' } )
56- apiUrl = chatHttpOptions . url ;
64+ set apiUrl ( value : string = chatHttpOptions . url ) {
65+ this . chatContext . apiUrl = value ;
66+ }
67+
68+ get apiUrl ( ) : string {
69+ return this . chatContext . apiUrl ;
70+ }
5771
5872 @property ( { type : String , attribute : 'data-custom-branding' , converter : ( value ) => value ?. toLowerCase ( ) === 'true' } )
5973 isCustomBranding : boolean = globalConfig . IS_CUSTOM_BRANDING ;
@@ -78,14 +92,20 @@ export class ChatComponent extends LitElement {
7892 @state ( )
7993 isDisabled = false ;
8094
81- @state ( )
82- isChatStarted = false ;
95+ set isChatStarted ( value : boolean ) {
96+ this . chatContext . isChatStarted = value ;
97+ }
98+
99+ get isChatStarted ( ) : boolean {
100+ return this . chatContext . isChatStarted ;
101+ }
83102
84103 @state ( )
85104 isResetInput = false ;
86105
87106 private chatController = new ChatController ( this ) ;
88107 private chatHistoryController = new ChatHistoryController ( this ) ;
108+ private chatContext = new ChatContextController ( this ) ;
89109
90110 // Is showing thought process panel
91111 @state ( )
@@ -104,14 +124,42 @@ export class ChatComponent extends LitElement {
104124
105125 static override styles = [ chatStyle ] ;
106126
107- @lazyMultiInject ( ComponentType . ChatInputComponent )
108- chatInputComponents : ChatInputComponent [ ] | undefined ;
127+ @lazyMultiInject ( ControllerType . ChatInput )
128+ chatInputComponents : ChatInputController [ ] | undefined ;
129+
130+ @lazyMultiInject ( ControllerType . ChatInputFooter )
131+ chatInputFooterComponets : ChatInputFooterController [ ] | undefined ;
109132
110- @lazyMultiInject ( ComponentType . ChatInputFooterComponent )
111- chatInputFooterComponets : ChatInputFooterComponent [ ] | undefined ;
133+ @lazyMultiInject ( ControllerType . Citation )
134+ citationControllers : CitationController [ ] | undefined ;
112135
113- @lazyMultiInject ( ComponentType . CitationActionComponent )
114- citationActionComponents : CitationActionComponent [ ] | undefined ;
136+ @lazyMultiInject ( ControllerType . ChatSection )
137+ chatFooterComponents : ChatSectionController [ ] | undefined ;
138+
139+ // Lifecycle method that runs when the component is first connected to the DOM
140+ override connectedCallback ( ) : void {
141+ super . connectedCallback ( ) ;
142+ if ( this . chatInputComponents ) {
143+ for ( const component of this . chatInputComponents ) {
144+ component . attach ( this , this . chatContext ) ;
145+ }
146+ }
147+ if ( this . chatInputFooterComponets ) {
148+ for ( const component of this . chatInputFooterComponets ) {
149+ component . attach ( this , this . chatContext ) ;
150+ }
151+ }
152+ if ( this . citationControllers ) {
153+ for ( const component of this . citationControllers ) {
154+ component . attach ( this , this . chatContext ) ;
155+ }
156+ }
157+ if ( this . chatFooterComponents ) {
158+ for ( const component of this . chatFooterComponents ) {
159+ component . attach ( this , this . chatContext ) ;
160+ }
161+ }
162+ }
115163
116164 override updated ( changedProperties : Map < string | number | symbol , unknown > ) {
117165 super . updated ( changedProperties ) ;
@@ -326,7 +374,7 @@ export class ChatComponent extends LitElement {
326374 @on-citation-click ="${ this . handleCitationClick } "
327375 > </ citation-list >
328376 ${ this . selectedCitation
329- ? this . citationActionComponents ?. map ( ( component ) =>
377+ ? this . citationControllers ?. map ( ( component ) =>
330378 component . render ( this . selectedCitation , `${ this . apiUrl } /content/${ this . selectedCitation . text } ` ) ,
331379 )
332380 : '' }
@@ -373,6 +421,7 @@ export class ChatComponent extends LitElement {
373421 .selectedCitation ="${ this . selectedCitation } "
374422 .isCustomBranding ="${ this . isCustomBranding } "
375423 .svgIcon ="${ iconLogo } "
424+ .context ="${ this . chatContext } "
376425 @on-action-button-click ="${ this . handleChatEntryActionButtonClick } "
377426 @on-citation-click ="${ this . handleCitationClick } "
378427 @on-followup-click ="${ this . handleInput } "
@@ -385,7 +434,7 @@ export class ChatComponent extends LitElement {
385434 ? ''
386435 : this . chatInputComponents
387436 . filter ( ( component ) => component . position === position )
388- . map ( ( component ) => component . render ( this . handleInput , this . isChatStarted , this . interactionModel ) ) ;
437+ . map ( ( component ) => component . render ( this . handleInput ) ) ;
389438 }
390439
391440 // Render the chat component as a web component
@@ -479,7 +528,7 @@ export class ChatComponent extends LitElement {
479528 ) }
480529 </ form >
481530 </ section >
482- ${ this . isShowingThoughtProcess
531+ <!-- ${ this . isShowingThoughtProcess
483532 ? html `
484533 <aside class="aside" data-testid="aside-thought-process">
485534 <div class="aside__header">
@@ -494,7 +543,8 @@ export class ChatComponent extends LitElement {
494543 ${ this . renderChatEntryTabContent ( this . selectedChatEntry as ChatThreadEntry ) }
495544 </aside>
496545 `
497- : '' }
546+ : '' } -->
547+ ${ this . chatFooterComponents ?. map ( ( component ) => component . render ( ) ) }
498548 </ section >
499549 ` ;
500550 }
0 commit comments