From e60cb97ecc836dbedc7fdf02ddc286eda85294a0 Mon Sep 17 00:00:00 2001 From: Dylan Tientcheu Date: Wed, 18 Jun 2025 14:13:43 +0200 Subject: [PATCH] fix: make ask ai use config id --- examples/demo-askai/src/App.tsx | 2 +- packages/docsearch-react/src/DocSearch.tsx | 27 +++++++++++++++---- .../docsearch-react/src/DocSearchModal.tsx | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/examples/demo-askai/src/App.tsx b/examples/demo-askai/src/App.tsx index bcc1da74..c60ea00a 100644 --- a/examples/demo-askai/src/App.tsx +++ b/examples/demo-askai/src/App.tsx @@ -12,7 +12,7 @@ function App(): JSX.Element { indexName="beta-react" appId="betaHAXPMHIMMC" apiKey="8b00405cba281a7d800ccec393e9af24" - askAi={true} + askAi="askai-react-demo" insights={true} /> diff --git a/packages/docsearch-react/src/DocSearch.tsx b/packages/docsearch-react/src/DocSearch.tsx index b66b3060..d9466b7e 100644 --- a/packages/docsearch-react/src/DocSearch.tsx +++ b/packages/docsearch-react/src/DocSearch.tsx @@ -23,17 +23,32 @@ export type DocSearchTransformClient = { }; export type DocSearchAskAi = { - indexName: string; - apiKey: string; - appId: string; - promptId?: string | null; + /** + * The index name to use for the ask AI feature. Your assistant will search this index for relevant documents. + * If not provided, the index name will be used. + */ + indexName?: string; + /** + * The API key to use for the ask AI feature. Your assistant will use this API key to search the index. + * If not provided, the API key will be used. + */ + apiKey?: string; + /** + * The app ID to use for the ask AI feature. Your assistant will use this app ID to search the index. + * If not provided, the app ID will be used. + */ + appId?: string; + /** + * The assistant ID to use for the ask AI feature. + */ + assistantId: string | null; }; export interface DocSearchProps { appId: string; apiKey: string; indexName: string; - askAi?: DocSearchAskAi | boolean; + askAi?: DocSearchAskAi | string; placeholder?: string; searchParameters?: SearchParamsObject; maxResultsPerGroup?: number; @@ -60,6 +75,7 @@ export function DocSearch(props: DocSearchProps): JSX.Element { // check if the instance is configured to handle ask ai const canHandleAskAi = Boolean(props?.askAi); + const askAiConfigurationId = typeof props?.askAi === 'string' ? props?.askAi : props?.askAi?.assistantId || null; if (canHandleAskAi) { currentPlaceholder = props?.translations?.modal?.searchBox?.placeholderText || 'Search docs or ask AI a question'; @@ -117,6 +133,7 @@ export function DocSearch(props: DocSearchProps): JSX.Element { translations={props?.translations?.modal} isAskAiActive={isAskAiActive} canHandleAskAi={canHandleAskAi} + askAiConfigurationId={askAiConfigurationId} onAskAiToggle={onAskAiToggle} onClose={onClose} />, diff --git a/packages/docsearch-react/src/DocSearchModal.tsx b/packages/docsearch-react/src/DocSearchModal.tsx index 96339891..18c7a657 100644 --- a/packages/docsearch-react/src/DocSearchModal.tsx +++ b/packages/docsearch-react/src/DocSearchModal.tsx @@ -38,6 +38,7 @@ export type DocSearchModalProps = DocSearchProps & { onClose?: () => void; isAskAiActive?: boolean; canHandleAskAi?: boolean; + askAiConfigurationId: string | null; translations?: ModalTranslations; }; @@ -279,6 +280,7 @@ export function DocSearchModal({ onAskAiToggle, isAskAiActive = false, canHandleAskAi = false, + askAiConfigurationId, }: DocSearchModalProps): JSX.Element { const { footer: footerTranslations, searchBox: searchBoxTranslations, ...screenStateTranslations } = translations; const [state, setState] = React.useState>({