66} from '@algolia/autocomplete-core' ;
77import type { InitialAskAiMessage , OnAskAiToggle } from '@docsearch/core' ;
88import { useTheme } from '@docsearch/core/useTheme' ;
9- import type { ChatRequestOptions } from 'ai' ;
109import type { SearchResponse } from 'algoliasearch/lite' ;
1110import React , { type JSX } from 'react' ;
1211import type { MultiSearchRequestSchema } from 'typesense/lib/Typesense/Types' ;
@@ -34,7 +33,6 @@ import type {
3433import type { AIMessage , AskAiState } from './types/AskiAi' ;
3534import { useAskAi } from './useAskAi' ;
3635import { useSearchClient } from './useSearchClient' ;
37- import { useSuggestedQuestions } from './useSuggestedQuestions' ;
3836import { useTouchEvents } from './useTouchEvents' ;
3937import { useTrapFocus } from './useTrapFocus' ;
4038import { groupBy , identity , noop , removeHighlightTags , isModifierEvent , scrollTo as scrollToUtils } from './utils' ;
@@ -468,17 +466,8 @@ export function DocSearchModal({
468466
469467 const searchClient = useSearchClient ( transformSearchClient , typesenseServerConfig ) ;
470468
471- const askAiConfig = typeof askAi === 'object' ? askAi : null ;
472- const askAiConfigurationId = typeof askAi === 'string' ? askAi : askAiConfig ?. assistantId || null ;
473- const askAiSearchParameters = askAiConfig ?. searchParameters ;
474- const askAiUseStagingEnv = askAiConfig ?. useStagingEnv || false ;
469+ const askAiConfig = askAi ?? null ;
475470 const [ askAiState , setAskAiState ] = React . useState < AskAiState > ( 'initial' ) ;
476- const suggestedQuestions = useSuggestedQuestions ( {
477- assistantId : askAiConfigurationId ,
478- searchClient,
479- suggestedQuestionsEnabled : askAiConfig ?. suggestedQuestions ,
480- } ) ;
481- const agentStudio = askAiConfig ?. agentStudio ?? false ;
482471
483472 // Format the `indexes` to be used until `indexName` and `searchParameters` props are fully removed.
484473 const indexes : DocSearchIndex [ ] = [ ] ;
@@ -505,7 +494,7 @@ export function DocSearchModal({
505494 // storage
506495 const conversations = React . useRef (
507496 createStoredConversations < StoredAskAiState > ( {
508- key : `__DOCSEARCH_ASKAI_CONVERSATIONS__${ askAiConfig ?. indexName || defaultIndexName } ` ,
497+ key : `__DOCSEARCH_ASKAI_CONVERSATIONS__${ defaultIndexName } ` ,
509498 limit : 10 ,
510499 } ) ,
511500 ) . current ;
@@ -524,14 +513,14 @@ export function DocSearchModal({
524513
525514 const [ stoppedStream , setStoppedStream ] = React . useState ( false ) ;
526515
527- const { messages, status, setMessages, sendMessage, stopAskAiStreaming, askAiError, sendFeedback } = useAskAi ( {
528- assistantId : askAiConfigurationId ,
529- apiKey : askAiConfig ?. apiKey ?? 'testkey' ,
530- appId : askAiConfig ?. appId ?? 'testappid' ,
531- indexName : askAiConfig ?. indexName || defaultIndexName ,
532- searchParameters : askAiSearchParameters ,
533- useStagingEnv : askAiUseStagingEnv ,
534- agentStudio ,
516+ const { messages, status, setMessages, sendMessage, stopAskAiStreaming, askAiError } = useAskAi ( {
517+ typesenseServerConfig ,
518+ storageKey : `__DOCSEARCH_ASKAI_CONVERSATIONS__ ${ defaultIndexName } ` ,
519+ collection : askAiConfig ?. collection || defaultIndexName ,
520+ conversationModelId : askAiConfig ?. conversationModelId || '' ,
521+ queryBy : askAiConfig ?. queryBy || 'embedding' ,
522+ excludeFields : askAiConfig ?. excludeFields || 'embedding' ,
523+ searchParameters : askAiConfig ?. searchParameters ,
535524 } ) ;
536525
537526 const prevStatus = React . useRef ( status ) ;
@@ -544,13 +533,14 @@ export function DocSearchModal({
544533 // if we stopped the stream, store it on the most recent message
545534 if ( stoppedStream && messages . at ( - 1 ) ) {
546535 messages . at ( - 1 ) ! . metadata = {
536+ ...messages . at ( - 1 ) ! . metadata ,
547537 stopped : true ,
548538 } ;
549539 }
550540
551541 for ( const part of messages [ 0 ] . parts ) {
552542 if ( part . type === 'text' ) {
553- conversations . add ( buildDummyAskAiHit ( part . text , messages ) ) ;
543+ conversations . add ( buildDummyAskAiHit ( part . text , messages , messages . at ( - 1 ) ?. metadata ?. conversationId ) ) ;
554544 }
555545 }
556546 }
@@ -659,26 +649,9 @@ export function DocSearchModal({
659649
660650 setStoppedStream ( false ) ;
661651
662- const messageOptions : ChatRequestOptions = { } ;
663-
664- if ( suggestedQuestion ) {
665- messageOptions . body = {
666- suggestedQuestionId : suggestedQuestion . objectID ,
667- } ;
668- }
669-
670- sendMessage (
671- {
672- role : 'user' ,
673- parts : [
674- {
675- type : 'text' ,
676- text : query ,
677- } ,
678- ] ,
679- } ,
680- messageOptions ,
681- ) ;
652+ void sendMessage ( query , {
653+ suggestedQuestionId : suggestedQuestion ?. objectID ,
654+ } ) ;
682655
683656 if ( dropdownRef . current ) {
684657 // some test environments (like jsdom) don't implement element.scrollTo
@@ -700,13 +673,9 @@ export function DocSearchModal({
700673 ) ;
701674
702675 // feedback handler
703- const handleFeedbackSubmit = React . useCallback (
704- async ( messageId : string , thumbs : 0 | 1 ) : Promise < void > => {
705- if ( ! askAiConfigurationId ) return ;
706- await sendFeedback ( messageId , thumbs ) ;
707- } ,
708- [ askAiConfigurationId , sendFeedback ] ,
709- ) ;
676+ const handleFeedbackSubmit = React . useCallback ( async ( _messageId : string , _thumbs : 0 | 1 ) : Promise < void > => {
677+ return ;
678+ } , [ ] ) ;
710679
711680 if ( ! autocompleteRef . current ) {
712681 autocompleteRef . current = createAutocomplete ( {
@@ -1041,9 +1010,8 @@ export function DocSearchModal({
10411010 hasCollections = { hasCollections }
10421011 askAiState = { askAiState }
10431012 selectAskAiQuestion = { handleSelectAskAiQuestion }
1044- suggestedQuestions = { suggestedQuestions }
1013+ suggestedQuestions = { [ ] }
10451014 selectSuggestedQuestion = { selectSuggestedQuestion }
1046- agentStudio = { agentStudio }
10471015 onAskAiToggle = { onAskAiToggle }
10481016 onNewConversation = { handleNewConversation }
10491017 onItemClick = { ( item , event ) => {
0 commit comments