diff --git a/.changeset/ready-aliens-lose.md b/.changeset/ready-aliens-lose.md new file mode 100644 index 000000000..dcfcc6c5a --- /dev/null +++ b/.changeset/ready-aliens-lose.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Add customizable suggested questions diff --git a/bun.lock b/bun.lock index 5b9d520f0..eb9384a52 100644 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "gitbook", @@ -345,7 +346,7 @@ "react-dom": "catalog:", }, "catalog": { - "@gitbook/api": "0.153.0", + "@gitbook/api": "0.154.0", "@scalar/api-client-react": "^1.3.46", "@tsconfig/node20": "^20.1.6", "@tsconfig/strictest": "^2.0.6", @@ -726,7 +727,7 @@ "@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@6.6.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="], - "@gitbook/api": ["@gitbook/api@0.153.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-ArNPFoqwId4Flicz8xPEdGqXQkzxyxP7S8Uv3wIfCX2e4cLhpcS7xCJGEHOJrqe1tNs1ovT1N2MWfpdIqzXqig=="], + "@gitbook/api": ["@gitbook/api@0.154.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-huEgWWa2H+H4ofYEAQl9r49u0gVjDHHWVNJKhd6SgGCfefjNPHkQj9zaky/5DBQzlu/+SDmutWiOtYdrykQO8w=="], "@gitbook/browser-types": ["@gitbook/browser-types@workspace:packages/browser-types"], diff --git a/package.json b/package.json index 54ec8c2aa..b4860fd70 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "catalog": { "@tsconfig/strictest": "^2.0.6", "@tsconfig/node20": "^20.1.6", - "@gitbook/api": "0.153.0", + "@gitbook/api": "0.154.0", "@scalar/api-client-react": "^1.3.46", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", diff --git a/packages/gitbook/src/components/AI/useAI.tsx b/packages/gitbook/src/components/AI/useAI.tsx index d1b7c92fc..2a41b6134 100644 --- a/packages/gitbook/src/components/AI/useAI.tsx +++ b/packages/gitbook/src/components/AI/useAI.tsx @@ -15,6 +15,7 @@ import { useSearch } from '../Search/useSearch'; // Unify assistants configuration context with the assistants hook in one place export type AIConfig = { aiMode: CustomizationAIMode; + suggestions?: string[]; trademark: boolean; }; @@ -49,8 +50,11 @@ export type Assistant = Omit & { const AIContext = React.createContext(null); export function AIContextProvider(props: React.PropsWithChildren): React.ReactElement { - const { aiMode, trademark, children } = props; - const value = React.useMemo(() => ({ aiMode, trademark }), [aiMode, trademark]); + const { aiMode, trademark, suggestions, children } = props; + const value = React.useMemo( + () => ({ aiMode, trademark, suggestions }), + [aiMode, trademark, suggestions] + ); return {children}; } diff --git a/packages/gitbook/src/components/AIChat/AIChat.tsx b/packages/gitbook/src/components/AIChat/AIChat.tsx index de3b72a5e..d36ebe0e9 100644 --- a/packages/gitbook/src/components/AIChat/AIChat.tsx +++ b/packages/gitbook/src/components/AIChat/AIChat.tsx @@ -109,7 +109,11 @@ export function AIChat() { - + diff --git a/packages/gitbook/src/components/Embeddable/EmbeddableRootLayout.tsx b/packages/gitbook/src/components/Embeddable/EmbeddableRootLayout.tsx index 01d875c53..81477ab26 100644 --- a/packages/gitbook/src/components/Embeddable/EmbeddableRootLayout.tsx +++ b/packages/gitbook/src/components/Embeddable/EmbeddableRootLayout.tsx @@ -41,6 +41,7 @@ export async function EmbeddableRootLayout({ > (); const recommendedQuestions: ResultType[] = []; + if (suggestions && suggestions.length > 0) { + suggestions.forEach((question) => { + questions.add(question); + }); + setResultsState({ + results: suggestions.map((question, index) => ({ + type: 'recommended-question', + id: `recommended-question-${index}`, + question, + })), + fetching: false, + error: false, + }); + return; + } + const timeout = setTimeout(async () => { if (cancelled) { return; @@ -175,14 +192,14 @@ export function useSearchResults(props: { cancelled = true; clearTimeout(timeout); }; - }, [query, scope, trackEvent, withAI, siteSpaceId, siteSpaceIds, disabled]); + }, [query, scope, trackEvent, withAI, siteSpaceId, siteSpaceIds, disabled, suggestions]); const aiEnrichedResults: ResultType[] = React.useMemo(() => { if (!withAI) { return resultsState.results; } return withAskTriggers(resultsState.results, query, assistants); - }, [resultsState.results, query, withAI]); + }, [resultsState.results, query, withAI, assistants]); return { ...resultsState, results: aiEnrichedResults }; } diff --git a/packages/gitbook/src/components/SiteLayout/SiteLayout.tsx b/packages/gitbook/src/components/SiteLayout/SiteLayout.tsx index 117f4247e..e203751f6 100644 --- a/packages/gitbook/src/components/SiteLayout/SiteLayout.tsx +++ b/packages/gitbook/src/components/SiteLayout/SiteLayout.tsx @@ -56,6 +56,7 @@ export async function SiteLayout(props: { >