@@ -85,6 +85,7 @@ const Chat = () => {
85
85
const [ showSpeechOutputBrowser , setShowSpeechOutputBrowser ] = useState < boolean > ( false ) ;
86
86
const [ showSpeechOutputAzure , setShowSpeechOutputAzure ] = useState < boolean > ( false ) ;
87
87
const [ showChatHistoryBrowser , setShowChatHistoryBrowser ] = useState < boolean > ( false ) ;
88
+ const [ showChatHistoryCosmos , setShowChatHistoryCosmos ] = useState < boolean > ( false ) ;
88
89
const audio = useRef ( new Audio ( ) ) . current ;
89
90
const [ isPlaying , setIsPlaying ] = useState ( false ) ;
90
91
@@ -111,6 +112,7 @@ const Chat = () => {
111
112
setShowSpeechOutputBrowser ( config . showSpeechOutputBrowser ) ;
112
113
setShowSpeechOutputAzure ( config . showSpeechOutputAzure ) ;
113
114
setShowChatHistoryBrowser ( config . showChatHistoryBrowser ) ;
115
+ setShowChatHistoryCosmos ( config . showChatHistoryCosmos ) ;
114
116
} ) ;
115
117
} ;
116
118
@@ -160,7 +162,11 @@ const Chat = () => {
160
162
const client = useLogin ? useMsal ( ) . instance : undefined ;
161
163
const { loggedIn } = useContext ( LoginContext ) ;
162
164
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
+ } ) ( ) ;
164
170
const historyManager = useHistoryManager ( historyProvider ) ;
165
171
166
172
const makeApiRequest = async ( question : string ) => {
@@ -217,7 +223,8 @@ const Chat = () => {
217
223
const parsedResponse : ChatAppResponse = await handleAsyncRequest ( question , answers , response . body ) ;
218
224
setAnswers ( [ ...answers , [ question , parsedResponse ] ] ) ;
219
225
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 ) ;
221
228
}
222
229
} else {
223
230
const parsedResponse : ChatAppResponseOrError = await response . json ( ) ;
@@ -226,7 +233,8 @@ const Chat = () => {
226
233
}
227
234
setAnswers ( [ ...answers , [ question , parsedResponse as ChatAppResponse ] ] ) ;
228
235
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 ) ;
230
238
}
231
239
}
232
240
setSpeechUrls ( [ ...speechUrls , null ] ) ;
@@ -369,7 +377,9 @@ const Chat = () => {
369
377
</ Helmet >
370
378
< div className = { styles . commandsSplitContainer } >
371
379
< 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
+ ) }
373
383
</ div >
374
384
< div className = { styles . commandsContainer } >
375
385
< ClearChatButton className = { styles . commandButton } onClick = { clearChat } disabled = { ! lastQuestionRef . current || isLoading } />
@@ -478,7 +488,7 @@ const Chat = () => {
478
488
/>
479
489
) }
480
490
481
- { showChatHistoryBrowser && (
491
+ { ( ( useLogin && showChatHistoryCosmos ) || showChatHistoryBrowser ) && (
482
492
< HistoryPanel
483
493
provider = { historyProvider }
484
494
isOpen = { isHistoryPanelOpen }
0 commit comments