From 463b9f0948abc38e1875e1cd2342d9c74b0b08bb Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Tue, 9 Dec 2025 10:02:07 +0100 Subject: [PATCH 1/2] Support `greeting` and fix suggested questions if there are no custom questions defined --- .changeset/social-moles-film.md | 5 +++++ packages/gitbook/src/components/AI/useAI.tsx | 10 +++++++--- .../gitbook/src/components/AIChat/AIChat.tsx | 17 +++++++++++------ .../AIChat/AIChatSuggestedQuestions.tsx | 18 ++++++++++-------- .../components/Embeddable/EmbeddableAIChat.tsx | 1 + 5 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 .changeset/social-moles-film.md diff --git a/.changeset/social-moles-film.md b/.changeset/social-moles-film.md new file mode 100644 index 0000000000..06853b9a06 --- /dev/null +++ b/.changeset/social-moles-film.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Support `greeting` and fix suggested questions if there are no custom ones defined diff --git a/packages/gitbook/src/components/AI/useAI.tsx b/packages/gitbook/src/components/AI/useAI.tsx index 2a41b61342..677139979d 100644 --- a/packages/gitbook/src/components/AI/useAI.tsx +++ b/packages/gitbook/src/components/AI/useAI.tsx @@ -17,6 +17,10 @@ export type AIConfig = { aiMode: CustomizationAIMode; suggestions?: string[]; trademark: boolean; + greeting?: { + title: string; + subtitle: string; + }; }; export type Assistant = Omit & { @@ -50,10 +54,10 @@ export type Assistant = Omit & { const AIContext = React.createContext(null); export function AIContextProvider(props: React.PropsWithChildren): React.ReactElement { - const { aiMode, trademark, suggestions, children } = props; + const { aiMode, trademark, suggestions, greeting, children } = props; const value = React.useMemo( - () => ({ aiMode, trademark, suggestions }), - [aiMode, trademark, suggestions] + () => ({ aiMode, trademark, suggestions, greeting }), + [aiMode, trademark, suggestions, greeting] ); return {children}; } diff --git a/packages/gitbook/src/components/AIChat/AIChat.tsx b/packages/gitbook/src/components/AIChat/AIChat.tsx index 6bc5304811..1363e3d0e5 100644 --- a/packages/gitbook/src/components/AIChat/AIChat.tsx +++ b/packages/gitbook/src/components/AIChat/AIChat.tsx @@ -193,8 +193,12 @@ export function AIChatBody(props: { chat: AIChatState; welcomeMessage?: string; suggestions?: string[]; + greeting?: { + title: string; + subtitle: string; + }; }) { - const { chatController, chat, suggestions } = props; + const { chatController, chat, suggestions, greeting } = props; const { trademark } = useAI().config; const [input, setInput] = React.useState(''); @@ -233,19 +237,20 @@ export function AIChatBody(props: { className="size-8 text-primary [@container(min-height:400px)]:size-16" /> -
+
- {timeGreeting} + {greeting?.title ?? timeGreeting}

- {t(language, 'ai_chat_assistant_description')} + {greeting?.subtitle ?? + t(language, 'ai_chat_assistant_description')}

diff --git a/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx b/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx index cbc31bff64..c4dca65dbf 100644 --- a/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx +++ b/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx @@ -7,14 +7,16 @@ export default function AIChatSuggestedQuestions(props: { suggestions?: string[]; }) { const language = useLanguage(); - const { - chatController, - suggestions = [ - tString(language, 'ai_chat_suggested_questions_about_this_page'), - tString(language, 'ai_chat_suggested_questions_read_next'), - tString(language, 'ai_chat_suggested_questions_example'), - ], - } = props; + const { chatController, suggestions: _suggestions } = props; + + const suggestions = + _suggestions && _suggestions.length > 0 + ? _suggestions + : [ + tString(language, 'ai_chat_suggested_questions_about_this_page'), + tString(language, 'ai_chat_suggested_questions_read_next'), + tString(language, 'ai_chat_suggested_questions_example'), + ]; return (
diff --git a/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx b/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx index 09fde03a02..54f63b08a6 100644 --- a/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx +++ b/packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx @@ -98,6 +98,7 @@ export function EmbeddableAIChat(props: EmbeddableAIChatProps) { chatController={chatController} chat={chat} suggestions={configuration.suggestions} + greeting={configuration.greeting} /> From d795c34482142cd18e4811164f21e08bb7af3b1f Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Tue, 9 Dec 2025 12:46:41 +0100 Subject: [PATCH 2/2] GPT review --- packages/gitbook/src/components/AIChat/AIChat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gitbook/src/components/AIChat/AIChat.tsx b/packages/gitbook/src/components/AIChat/AIChat.tsx index 1363e3d0e5..8fe7dea6a5 100644 --- a/packages/gitbook/src/components/AIChat/AIChat.tsx +++ b/packages/gitbook/src/components/AIChat/AIChat.tsx @@ -243,13 +243,13 @@ export function AIChatBody(props: { style={{ animationDelay: '.5s' }} data-testid="ai-chat-time-greeting" > - {greeting?.title ?? timeGreeting} + {greeting?.title || timeGreeting}

- {greeting?.subtitle ?? + {greeting?.subtitle || t(language, 'ai_chat_assistant_description')}