@@ -85,6 +85,7 @@ const Chat = () => {
8585 const [ showSpeechOutputBrowser , setShowSpeechOutputBrowser ] = useState < boolean > ( false ) ;
8686 const [ showSpeechOutputAzure , setShowSpeechOutputAzure ] = useState < boolean > ( false ) ;
8787 const [ showChatHistoryBrowser , setShowChatHistoryBrowser ] = useState < boolean > ( false ) ;
88+ const [ showChatHistoryCosmos , setShowChatHistoryCosmos ] = useState < boolean > ( false ) ;
8889 const audio = useRef ( new Audio ( ) ) . current ;
8990 const [ isPlaying , setIsPlaying ] = useState ( false ) ;
9091
@@ -111,6 +112,7 @@ const Chat = () => {
111112 setShowSpeechOutputBrowser ( config . showSpeechOutputBrowser ) ;
112113 setShowSpeechOutputAzure ( config . showSpeechOutputAzure ) ;
113114 setShowChatHistoryBrowser ( config . showChatHistoryBrowser ) ;
115+ setShowChatHistoryCosmos ( config . showChatHistoryCosmos ) ;
114116 } ) ;
115117 } ;
116118
@@ -160,7 +162,11 @@ const Chat = () => {
160162 const client = useLogin ? useMsal ( ) . instance : undefined ;
161163 const { loggedIn } = useContext ( LoginContext ) ;
162164
163- const historyProvider : HistoryProviderOptions = showChatHistoryBrowser ? HistoryProviderOptions . IndexedDB : HistoryProviderOptions . None ;
165+ const historyProvider : HistoryProviderOptions = ( ( ) => {
166+ if ( useLogin && showChatHistoryCosmos ) return HistoryProviderOptions . CosmosDB ;
167+ if ( showChatHistoryBrowser ) return HistoryProviderOptions . IndexedDB ;
168+ return HistoryProviderOptions . None ;
169+ } ) ( ) ;
164170 const historyManager = useHistoryManager ( historyProvider ) ;
165171
166172 const makeApiRequest = async ( question : string ) => {
@@ -217,7 +223,8 @@ const Chat = () => {
217223 const parsedResponse : ChatAppResponse = await handleAsyncRequest ( question , answers , response . body ) ;
218224 setAnswers ( [ ...answers , [ question , parsedResponse ] ] ) ;
219225 if ( typeof parsedResponse . session_state === "string" && parsedResponse . session_state !== "" ) {
220- historyManager . addItem ( parsedResponse . session_state , [ ...answers , [ question , parsedResponse ] ] ) ;
226+ const token = client ? await getToken ( client ) : undefined ;
227+ historyManager . addItem ( parsedResponse . session_state , [ ...answers , [ question , parsedResponse ] ] , token ) ;
221228 }
222229 } else {
223230 const parsedResponse : ChatAppResponseOrError = await response . json ( ) ;
@@ -226,7 +233,8 @@ const Chat = () => {
226233 }
227234 setAnswers ( [ ...answers , [ question , parsedResponse as ChatAppResponse ] ] ) ;
228235 if ( typeof parsedResponse . session_state === "string" && parsedResponse . session_state !== "" ) {
229- historyManager . addItem ( parsedResponse . session_state , [ ...answers , [ question , parsedResponse as ChatAppResponse ] ] ) ;
236+ const token = client ? await getToken ( client ) : undefined ;
237+ historyManager . addItem ( parsedResponse . session_state , [ ...answers , [ question , parsedResponse as ChatAppResponse ] ] , token ) ;
230238 }
231239 }
232240 setSpeechUrls ( [ ...speechUrls , null ] ) ;
@@ -369,7 +377,9 @@ const Chat = () => {
369377 </ Helmet >
370378 < div className = { styles . commandsSplitContainer } >
371379 < div className = { styles . commandsContainer } >
372- { showChatHistoryBrowser && < HistoryButton className = { styles . commandButton } onClick = { ( ) => setIsHistoryPanelOpen ( ! isHistoryPanelOpen ) } /> }
380+ { ( ( useLogin && showChatHistoryCosmos ) || showChatHistoryBrowser ) && (
381+ < HistoryButton className = { styles . commandButton } onClick = { ( ) => setIsHistoryPanelOpen ( ! isHistoryPanelOpen ) } />
382+ ) }
373383 </ div >
374384 < div className = { styles . commandsContainer } >
375385 < ClearChatButton className = { styles . commandButton } onClick = { clearChat } disabled = { ! lastQuestionRef . current || isLoading } />
@@ -478,7 +488,7 @@ const Chat = () => {
478488 />
479489 ) }
480490
481- { showChatHistoryBrowser && (
491+ { ( ( useLogin && showChatHistoryCosmos ) || showChatHistoryBrowser ) && (
482492 < HistoryPanel
483493 provider = { historyProvider }
484494 isOpen = { isHistoryPanelOpen }
0 commit comments