Skip to content

Commit 463b9f0

Browse files
committed
Support greeting and fix suggested questions if there are no custom questions defined
1 parent 6b43773 commit 463b9f0

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

.changeset/social-moles-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Support `greeting` and fix suggested questions if there are no custom ones defined

packages/gitbook/src/components/AI/useAI.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export type AIConfig = {
1717
aiMode: CustomizationAIMode;
1818
suggestions?: string[];
1919
trademark: boolean;
20+
greeting?: {
21+
title: string;
22+
subtitle: string;
23+
};
2024
};
2125

2226
export type Assistant = Omit<GitBookAssistant, 'icon'> & {
@@ -50,10 +54,10 @@ export type Assistant = Omit<GitBookAssistant, 'icon'> & {
5054
const AIContext = React.createContext<AIConfig | null>(null);
5155

5256
export function AIContextProvider(props: React.PropsWithChildren<AIConfig>): React.ReactElement {
53-
const { aiMode, trademark, suggestions, children } = props;
57+
const { aiMode, trademark, suggestions, greeting, children } = props;
5458
const value = React.useMemo(
55-
() => ({ aiMode, trademark, suggestions }),
56-
[aiMode, trademark, suggestions]
59+
() => ({ aiMode, trademark, suggestions, greeting }),
60+
[aiMode, trademark, suggestions, greeting]
5761
);
5862
return <AIContext.Provider value={value}>{children}</AIContext.Provider>;
5963
}

packages/gitbook/src/components/AIChat/AIChat.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,12 @@ export function AIChatBody(props: {
193193
chat: AIChatState;
194194
welcomeMessage?: string;
195195
suggestions?: string[];
196+
greeting?: {
197+
title: string;
198+
subtitle: string;
199+
};
196200
}) {
197-
const { chatController, chat, suggestions } = props;
201+
const { chatController, chat, suggestions, greeting } = props;
198202
const { trademark } = useAI().config;
199203

200204
const [input, setInput] = React.useState('');
@@ -233,19 +237,20 @@ export function AIChatBody(props: {
233237
className="size-8 text-primary [@container(min-height:400px)]:size-16"
234238
/>
235239
</div>
236-
<div className="flex flex-col items-start [@container(min-height:400px)]:items-center">
240+
<div className="flex flex-col items-start gap-1 [@container(min-height:400px)]:items-center">
237241
<h5
238-
className="animate-blur-in-slow font-bold text-lg text-tint-strong [@container(min-height:400px)]:text-center"
242+
className="animate-blur-in-slow font-bold text-lg text-tint-strong leading-tight [@container(min-height:400px)]:text-center"
239243
style={{ animationDelay: '.5s' }}
240244
data-testid="ai-chat-time-greeting"
241245
>
242-
{timeGreeting}
246+
{greeting?.title ?? timeGreeting}
243247
</h5>
244248
<p
245-
className="animate-blur-in-slow text-tint [@container(min-height:400px)]:text-center"
249+
className="animate-blur-in-slow text-tint leading-tight [@container(min-height:400px)]:text-center"
246250
style={{ animationDelay: '.6s' }}
247251
>
248-
{t(language, 'ai_chat_assistant_description')}
252+
{greeting?.subtitle ??
253+
t(language, 'ai_chat_assistant_description')}
249254
</p>
250255
</div>
251256
</div>

packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ export default function AIChatSuggestedQuestions(props: {
77
suggestions?: string[];
88
}) {
99
const language = useLanguage();
10-
const {
11-
chatController,
12-
suggestions = [
13-
tString(language, 'ai_chat_suggested_questions_about_this_page'),
14-
tString(language, 'ai_chat_suggested_questions_read_next'),
15-
tString(language, 'ai_chat_suggested_questions_example'),
16-
],
17-
} = props;
10+
const { chatController, suggestions: _suggestions } = props;
11+
12+
const suggestions =
13+
_suggestions && _suggestions.length > 0
14+
? _suggestions
15+
: [
16+
tString(language, 'ai_chat_suggested_questions_about_this_page'),
17+
tString(language, 'ai_chat_suggested_questions_read_next'),
18+
tString(language, 'ai_chat_suggested_questions_example'),
19+
];
1820

1921
return (
2022
<div className="flex flex-col items-start gap-2 self-start">

packages/gitbook/src/components/Embeddable/EmbeddableAIChat.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export function EmbeddableAIChat(props: EmbeddableAIChatProps) {
9898
chatController={chatController}
9999
chat={chat}
100100
suggestions={configuration.suggestions}
101+
greeting={configuration.greeting}
101102
/>
102103
</EmbeddableFrameBody>
103104
</EmbeddableFrameMain>

0 commit comments

Comments
 (0)