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..8fe7dea6a5 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} />