Skip to content

Commit 7b38f89

Browse files
authored
Update API client and condition for AI assistant (#3429)
1 parent 09b689b commit 7b38f89

File tree

8 files changed

+42
-8
lines changed

8 files changed

+42
-8
lines changed

.changeset/shiny-seahorses-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": minor
3+
---
4+
5+
Enable AI chat when AI mode is configured to assistant

bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
"react-dom": "^19.0.0",
248248
},
249249
"catalog": {
250-
"@gitbook/api": "^0.126.0",
250+
"@gitbook/api": "^0.128.0",
251251
},
252252
"packages": {
253253
"@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-0M+qjp+clUD0R1E5eWQFhxEvWLNaOtGQRUaBn8CUABnSKredagq92hUS9VjOzGsTm37xLfpaxl97AVtbeOsHew=="],
@@ -610,7 +610,7 @@
610610

611611
"@fortawesome/fontawesome-svg-core": ["@fortawesome/[email protected]", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],
612612

613-
"@gitbook/api": ["@gitbook/api@0.126.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-htDAGus+N+uSZZNHYP/My90EjaPMXaYXvwbnwOOFZqRUD5T6xsrMmUpMuNBF5KhdX/BBdwNKXUwt9Yeq7n80Bw=="],
613+
"@gitbook/api": ["@gitbook/api@0.128.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-VO98hRGfUcFdwMplvFW49jz72/ew2waE7RCu+URKAY2AyPHAduv2zgluF5gF1VcDyuJM9PKFtsdsMtpUjI5sYg=="],
614614

615615
"@gitbook/cache-tags": ["@gitbook/cache-tags@workspace:packages/cache-tags"],
616616

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"workspaces": {
3535
"packages": ["packages/*"],
3636
"catalog": {
37-
"@gitbook/api": "^0.126.0"
37+
"@gitbook/api": "^0.128.0"
3838
}
3939
},
4040
"patchedDependencies": {

packages/gitbook/e2e/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { argosScreenshot } from '@argos-ci/playwright';
22
import {
3+
CustomizationAIMode,
34
CustomizationBackground,
45
CustomizationCorners,
56
CustomizationDefaultFont,
7+
CustomizationDefaultMonospaceFont,
68
CustomizationDepth,
79
type CustomizationHeaderItem,
810
CustomizationHeaderPreset,
@@ -282,6 +284,7 @@ export function getCustomizationURL(partial: DeepPartial<SiteCustomizationSettin
282284
corners: CustomizationCorners.Rounded,
283285
depth: CustomizationDepth.Subtle,
284286
font: CustomizationDefaultFont.Inter,
287+
monospaceFont: CustomizationDefaultMonospaceFont.IBMPlexMono,
285288
background: CustomizationBackground.Plain,
286289
icons: CustomizationIconsStyle.Regular,
287290
links: CustomizationLinksStyle.Default,
@@ -315,9 +318,13 @@ export function getCustomizationURL(partial: DeepPartial<SiteCustomizationSettin
315318
feedback: {
316319
enabled: false,
317320
},
321+
// TODO: remove aiSearch once the cache has been fully updated (after 11/07/2025)
318322
aiSearch: {
319323
enabled: true,
320324
},
325+
ai: {
326+
mode: CustomizationAIMode.None,
327+
},
321328
externalLinks: {
322329
target: SiteExternalLinksTarget.Self,
323330
},

packages/gitbook/src/components/DocumentView/Block.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
105105
return <Stepper {...props} block={block} />;
106106
case 'stepper-step':
107107
return <StepperStep {...props} block={block} />;
108+
case 'if':
109+
// If block should be processed by the API.
110+
return null;
108111
case 'image':
109112
case 'code-line':
110113
case 'tabs-item':
@@ -142,6 +145,7 @@ export function BlockSkeleton(props: { block: DocumentBlock; style: ClassValue }
142145
case 'hint':
143146
case 'tabs':
144147
case 'stepper-step':
148+
case 'if':
145149
return <SkeletonParagraph id={id} style={style} />;
146150
case 'expandable':
147151
case 'table':

packages/gitbook/src/components/Header/Header.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CONTAINER_STYLE, HEADER_HEIGHT_DESKTOP } from '@/components/layout';
55
import { getSpaceLanguage, t } from '@/intl/server';
66
import { tcls } from '@/lib/tailwind';
77

8+
import { CustomizationAIMode } from '@gitbook/api';
89
import { AIChatButton } from '../AIChat/AIChatButton';
910
import { SearchButton } from '../Search';
1011
import { SiteSectionTabs, encodeClientSiteSections } from '../SiteSections';
@@ -154,7 +155,10 @@ export function Header(props: {
154155
<span className={tcls('flex-1')}>
155156
{t(
156157
getSpaceLanguage(customization),
157-
customization.aiSearch.enabled
158+
// TODO: remove aiSearch and optional chain once the cache has been fully updated (after 11/07/2025)
159+
customization.aiSearch?.enabled ||
160+
customization.ai?.mode !==
161+
CustomizationAIMode.None
158162
? 'search_or_ask'
159163
: 'search'
160164
)}

packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { GitBookSiteContext } from '@/lib/context';
2-
import { CustomizationHeaderPreset } from '@gitbook/api';
2+
import { CustomizationAIMode, CustomizationHeaderPreset } from '@gitbook/api';
33
import React from 'react';
44

55
import { Footer } from '@/components/Footer';
@@ -50,8 +50,9 @@ export function SpaceLayout(props: {
5050
customization.footer.logo ||
5151
customization.footer.groups?.length;
5252

53+
// TODO: remove aiSearch and optional chain once the cache has been fully updated (after 11/07/2025)
5354
const withAIChat =
54-
context.customization.aiSearch.enabled &&
55+
context.customization.ai?.mode === CustomizationAIMode.Assistant &&
5556
(context.site.id === 'site_p4Xo4' || context.site.id === 'site_JOVzv');
5657

5758
return (
@@ -123,7 +124,11 @@ export function SpaceLayout(props: {
123124
<span className={tcls('flex-1')}>
124125
{t(
125126
getSpaceLanguage(customization),
126-
customization.aiSearch.enabled
127+
// TODO: remove aiSearch and optional chain once the cache has been fully updated (after 11/07/2025)
128+
customization.aiSearch
129+
?.enabled ||
130+
customization.ai?.mode !==
131+
CustomizationAIMode.None
127132
? 'search_or_ask'
128133
: 'search'
129134
)}
@@ -167,7 +172,11 @@ export function SpaceLayout(props: {
167172
<React.Suspense fallback={null}>
168173
<SearchModal
169174
spaceTitle={siteSpace.title}
170-
withAsk={customization.aiSearch.enabled}
175+
// TODO: remove aiSearch and optional chain once the cache has been fully updated (after 11/07/2025)
176+
withAsk={
177+
customization.aiSearch?.enabled ||
178+
customization.ai?.mode !== CustomizationAIMode.None
179+
}
171180
withAIChat={withAIChat}
172181
isMultiVariants={isMultiVariants}
173182
/>

packages/gitbook/src/lib/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function defaultCustomization(): api.SiteCustomizationSettings {
1414
successColor: { light: '#00C950', dark: '#00C950' },
1515
corners: api.CustomizationCorners.Rounded,
1616
font: api.CustomizationDefaultFont.Inter,
17+
monospaceFont: api.CustomizationDefaultMonospaceFont.IBMPlexMono,
1718
background: api.CustomizationBackground.Plain,
1819
icons: api.CustomizationIconsStyle.Regular,
1920
links: api.CustomizationLinksStyle.Default,
@@ -48,9 +49,13 @@ export function defaultCustomization(): api.SiteCustomizationSettings {
4849
feedback: {
4950
enabled: false,
5051
},
52+
// TODO: remove aiSearch once the cache has been fully updated (after 11/07/2025)
5153
aiSearch: {
5254
enabled: true,
5355
},
56+
ai: {
57+
mode: api.CustomizationAIMode.None,
58+
},
5459
externalLinks: {
5560
target: api.SiteExternalLinksTarget.Self,
5661
},

0 commit comments

Comments
 (0)