File tree Expand file tree Collapse file tree
packages/docsearch-react/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ export type DocSearchAskAi = {
6060 * Typesense conversational model id.
6161 */
6262 conversationModelId : string ;
63+ /**
64+ * Static suggested questions shown in Ask AI entry points.
65+ *
66+ * TODO: Replace this with a Typesense-backed suggestions source instead of
67+ * shipping questions directly in frontend config.
68+ */
69+ suggestedQuestions ?: string [ ] ;
6370 /**
6471 * Collection to query for conversational retrieval.
6572 * Defaults to `typesenseCollectionName`.
Original file line number Diff line number Diff line change @@ -468,6 +468,14 @@ export function DocSearchModal({
468468
469469 const askAiConfig = askAi ?? null ;
470470 const [ askAiState , setAskAiState ] = React . useState < AskAiState > ( 'initial' ) ;
471+ const suggestedQuestions = React . useMemo < SuggestedQuestionHit [ ] > ( ( ) => {
472+ const staticQuestions = askAiConfig ?. suggestedQuestions ?? [ ] ;
473+
474+ return staticQuestions . map ( ( question , index ) => ( {
475+ objectID : `suggested-question-${ index } ` ,
476+ question,
477+ } ) ) as SuggestedQuestionHit [ ] ;
478+ } , [ askAiConfig ?. suggestedQuestions ] ) ;
471479
472480 // Format the `indexes` to be used until `indexName` and `searchParameters` props are fully removed.
473481 const indexes : DocSearchIndex [ ] = [ ] ;
@@ -1010,7 +1018,7 @@ export function DocSearchModal({
10101018 hasCollections = { hasCollections }
10111019 askAiState = { askAiState }
10121020 selectAskAiQuestion = { handleSelectAskAiQuestion }
1013- suggestedQuestions = { [ ] }
1021+ suggestedQuestions = { suggestedQuestions }
10141022 selectSuggestedQuestion = { selectSuggestedQuestion }
10151023 onAskAiToggle = { onAskAiToggle }
10161024 onNewConversation = { handleNewConversation }
Original file line number Diff line number Diff line change @@ -101,9 +101,11 @@ export type SidepanelProps = {
101101 portalContainer ?: DocumentFragment | Element | null ;
102102 /**
103103 * Enables displaying suggested questions on new conversation screen.
104- * Reserved for a future Typesense-native suggestions source.
104+ *
105+ * TODO: Replace this with a Typesense-backed suggestions source instead of
106+ * shipping questions directly in frontend config.
105107 */
106- suggestedQuestions ?: boolean ;
108+ suggestedQuestions ?: string [ ] ;
107109 /**
108110 * Translations specific to the Sidepanel panel.
109111 **/
@@ -181,7 +183,14 @@ function SidepanelInner(
181183 excludeFields : askAi . excludeFields || 'embedding' ,
182184 searchParameters : askAi . searchParameters ,
183185 } ) ;
184- const suggestedQuestions : SuggestedQuestionHit [ ] = [ ] ;
186+ const suggestedQuestions : SuggestedQuestionHit [ ] = React . useMemo ( ( ) => {
187+ const staticQuestions = askAi . suggestedQuestions ?? [ ] ;
188+
189+ return staticQuestions . map ( ( question , index ) => ( {
190+ objectID : `suggested-question-${ index } ` ,
191+ question,
192+ } ) ) as SuggestedQuestionHit [ ] ;
193+ } , [ askAi . suggestedQuestions ] ) ;
185194
186195 const prevStatus = React . useRef ( status ) ;
187196
You can’t perform that action at this time.
0 commit comments