Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-search-algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
},
"dependencies": {
"@docsearch/react": "^3.9.0 || ^4.1.0",
"@docsearch/react": "^3.9.0 || ^4.3.2",
"@docusaurus/core": "3.9.2",
"@docusaurus/logger": "3.9.2",
"@docusaurus/plugin-content-docs": "3.9.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,5 +436,95 @@ describe('validateThemeConfig', () => {
});
});
});

describe('Ask AI suggestedQuestions', () => {
it('accepts suggestedQuestions as true', () => {
const algolia = {
appId: 'BH4D9OD16A',
indexName: 'index',
apiKey: 'apiKey',
askAi: {
assistantId: 'my-assistant-id',
suggestedQuestions: true,
},
} satisfies AlgoliaInput;

expect(testValidateThemeConfig(algolia)).toEqual({
algolia: {
...DEFAULT_CONFIG,
...algolia,
askAi: {
indexName: algolia.indexName,
apiKey: algolia.apiKey,
appId: algolia.appId,
assistantId: 'my-assistant-id',
suggestedQuestions: true,
},
},
});
});

it('accepts suggestedQuestions as false', () => {
const algolia = {
appId: 'BH4D9OD16A',
indexName: 'index',
apiKey: 'apiKey',
askAi: {
assistantId: 'my-assistant-id',
suggestedQuestions: false,
},
} satisfies AlgoliaInput;

expect(testValidateThemeConfig(algolia)).toEqual({
algolia: {
...DEFAULT_CONFIG,
...algolia,
askAi: {
indexName: algolia.indexName,
apiKey: algolia.apiKey,
appId: algolia.appId,
assistantId: 'my-assistant-id',
suggestedQuestions: false,
},
},
});
});

it('rejects invalid suggestedQuestions type', () => {
const algolia: AlgoliaInput = {
appId: 'BH4D9OD16A',
indexName: 'index',
apiKey: 'apiKey',
askAi: {
assistantId: 'my-assistant-id',
// @ts-expect-error: expected type error
suggestedQuestions: 'invalid-string',
},
};
expect(() =>
testValidateThemeConfig(algolia),
).toThrowErrorMatchingInlineSnapshot(
`""algolia.askAi.suggestedQuestions" must be a boolean"`,
);
});

it('rejects suggestedQuestions as number', () => {
const algolia: AlgoliaInput = {
appId: 'BH4D9OD16A',
indexName: 'index',
apiKey: 'apiKey',
askAi: {
assistantId: 'my-assistant-id',
// @ts-expect-error: expected type error
suggestedQuestions: 123,
},
};
expect(() =>
testValidateThemeConfig(algolia),
).toThrowErrorMatchingInlineSnapshot(
`""algolia.askAi.suggestedQuestions" must be a boolean"`,
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function useAlgoliaAskAi(props: DocSearchV4PropsLite): UseAskAiResult {
}, []);

const extraAskAiProps: UseAskAiResult['extraAskAiProps'] = {
askAi,
askAi: askAi as any,
canHandleAskAi,
isAskAiActive,
onAskAiToggle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare module '@docusaurus/theme-search-algolia' {
import type {FacetFilters} from 'algoliasearch/lite';

// The config after normalization (e.g. AskAI string -> object)
// This matches DocSearch v4.3+ AskAi configuration
export type AskAiConfig = {
indexName: string;
apiKey: string;
Expand All @@ -25,6 +26,7 @@ declare module '@docusaurus/theme-search-algolia' {
searchParameters?: {
facetFilters?: FacetFilters;
};
suggestedQuestions?: boolean;
};

// DocSearch props that Docusaurus exposes directly through props forwarding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type DocSearchProps = Omit<

// extend DocSearchProps for v4 features
// TODO Docusaurus v4: cleanup after we drop support for DocSearch v3
interface DocSearchV4Props extends DocSearchProps {
interface DocSearchV4Props extends Omit<DocSearchProps, 'askAi'> {
indexName: string;
askAi?: ThemeConfigAlgolia['askAi'];
translations?: DocSearchTranslations;
Expand Down Expand Up @@ -199,7 +199,7 @@ function useSearchParameters({

function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
const navigator = useNavigator({externalUrlRegex});
const searchParameters = useSearchParameters({...props});
const searchParameters = useSearchParameters({...props} as DocSearchProps);
const transformItems = useTransformItems(props);
const transformSearchClient = useTransformSearchClient();

Expand Down Expand Up @@ -301,7 +301,7 @@ function DocSearch({externalUrlRegex, ...props}: DocSearchV4Props) {
resultsFooterComponent,
})}
placeholder={currentPlaceholder}
{...props}
{...(props as any)}
translations={props.translations?.modal ?? translations.modal}
searchParameters={searchParameters}
{...extraAskAiProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const Schema = Joi.object<ThemeConfig>({
searchParameters: Joi.object({
facetFilters: FacetFiltersSchema.optional(),
}).optional(),
suggestedQuestions: Joi.boolean().optional(),
}),
)
.custom(
Expand Down
1 change: 1 addition & 0 deletions website/docs/search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export default {
indexName: 'YOUR_ALGOLIA_INDEX_NAME',
apiKey: 'YOUR_ALGOLIA_API_KEY',
appId: 'YOUR_ALGOLIA_APP_ID',
suggestedQuestions: true, // Optional: enable suggested questions (default: false)
},
// highlight-end

Expand Down
1 change: 1 addition & 0 deletions website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ export default async function createConfigAsync() {
// cSpell:ignore IMYF
assistantId: 'RgIMYFUmTfrN',
indexName: 'docusaurus-markdown',
suggestedQuestions: true,
},
}
: {}),
Expand Down
1 change: 1 addition & 0 deletions website/versioned_docs/version-3.9.2/search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export default {
indexName: 'YOUR_ALGOLIA_INDEX_NAME',
apiKey: 'YOUR_ALGOLIA_API_KEY',
appId: 'YOUR_ALGOLIA_APP_ID',
suggestedQuestions: true, // Optional: enable suggested questions (default: false)
},
// highlight-end

Expand Down
24 changes: 15 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2077,19 +2077,25 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@docsearch/css@4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-4.1.0.tgz#e156e011539d73624b2354dc8be8e96ac9be9ddc"
integrity sha512-nuNKGjHj/FQeWgE9t+i83QD/V67QiaAmGY7xS9TVCRUiCqSljOgIKlsLoQZKKVwEG8f+OWKdznzZkJxGZ7d06A==
"@docsearch/core@4.3.1":
version "4.3.1"
resolved "https://registry.yarnpkg.com/@docsearch/core/-/core-4.3.1.tgz#88a97a6fe4d4025269b6dee8b9d070b76758ad82"
integrity sha512-ktVbkePE+2h9RwqCUMbWXOoebFyDOxHqImAqfs+lC8yOU+XwEW4jgvHGJK079deTeHtdhUNj0PXHSnhJINvHzQ==

"@docsearch/react@^3.9.0 || ^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-4.1.0.tgz#a04f22324067f2e39dbe12f0e1247e7e0341d26d"
integrity sha512-4GHI7TT3sJZ2Vs4Kjadv7vAkMrTsJqHvzvxO3JA7UT8iPRKaDottG5o5uNshPWhVVaBYPC35Ukf8bfCotGpjSg==
"@docsearch/css@4.3.2":
version "4.3.2"
resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-4.3.2.tgz#d47d25336c9516b419245fa74e8dd5ae84a17492"
integrity sha512-K3Yhay9MgkBjJJ0WEL5MxnACModX9xuNt3UlQQkDEDZJZ0+aeWKtOkxHNndMRkMBnHdYvQjxkm6mdlneOtU1IQ==

"@docsearch/react@^3.9.0 || ^4.3.2":
version "4.3.2"
resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-4.3.2.tgz#450b8341cb5cca03737a00075d4dfd3a904a3e3e"
integrity sha512-74SFD6WluwvgsOPqifYOviEEVwDxslxfhakTlra+JviaNcs7KK/rjsPj89kVEoQc9FUxRkAofaJnHIR7pb4TSQ==
dependencies:
"@ai-sdk/react" "^2.0.30"
"@algolia/autocomplete-core" "1.19.2"
"@docsearch/css" "4.1.0"
"@docsearch/core" "4.3.1"
"@docsearch/css" "4.3.2"
ai "^5.0.30"
algoliasearch "^5.28.0"
marked "^16.3.0"
Expand Down
Loading