mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-11-19 06:42:16 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 447bee1fb9 | |||
| b633fffc6f |
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gitbook/embed": minor
|
||||
"gitbook": patch
|
||||
---
|
||||
|
||||
Use the site's suggested questions when the embedded Assistant receives an empty or omitted list, including from older SDKs.
|
||||
@@ -394,6 +394,8 @@ Available in: Standalone script, NPM package, React components
|
||||
|
||||
Suggested questions displayed in the [Assistant](https://gitbook.com/docs/publishing-documentation/gitbook-ai-assistant) welcome screen.
|
||||
|
||||
Omit `suggestions` when creating the embed or pass an empty array to use the site's suggested questions. If the site has no suggested questions, the Assistant shows generic questions. Later `configure` calls keep the current setting unless you pass `suggestions`. To restore the site's questions, remove the React prop or pass `{ suggestions: [] }` or `{ suggestions: undefined }` to `configure`.
|
||||
|
||||
- **Type**: `string[]`
|
||||
|
||||
```javascript
|
||||
|
||||
@@ -83,7 +83,7 @@ export function createGitBookFrame(iframe: HTMLIFrameElement): GitBookFrameClien
|
||||
tabs: ['assistant', 'search', 'docs'],
|
||||
actions: [],
|
||||
greeting: { title: '', subtitle: '' },
|
||||
suggestions: [],
|
||||
suggestions: undefined,
|
||||
tools: [],
|
||||
trademark: true,
|
||||
};
|
||||
|
||||
@@ -94,8 +94,8 @@ export type GitBookEmbeddableConfiguration = {
|
||||
*/
|
||||
assistantName?: string;
|
||||
|
||||
/** Suggestions of questions to be displayed in the welcome page. */
|
||||
suggestions: string[];
|
||||
/** Welcome questions. Omit or pass [] to inherit the site's questions. */
|
||||
suggestions?: string[] | undefined;
|
||||
|
||||
/** Tools to be provided to the assistant. */
|
||||
tools: GitBookToolDefinition[];
|
||||
|
||||
@@ -24,7 +24,7 @@ export function GitBookFrame(props: GitBookFrameProps) {
|
||||
visitor,
|
||||
actions = [],
|
||||
greeting,
|
||||
suggestions = [],
|
||||
suggestions,
|
||||
tools = [],
|
||||
tabs = ['assistant', 'search', 'docs'],
|
||||
defaultTab,
|
||||
|
||||
@@ -63,7 +63,6 @@ let frameConfiguration: GitBookEmbeddableConfiguration & StandaloneConfiguration
|
||||
},
|
||||
actions: [],
|
||||
greeting: { title: '', subtitle: '' },
|
||||
suggestions: [],
|
||||
tools: [],
|
||||
tabs: ['assistant', 'search', 'docs'],
|
||||
trademark: true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type Page, type Request, type Route, expect } from '@playwright/test';
|
||||
import { type Page, type Request, type Route, expect, test } from '@playwright/test';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
import {
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
CustomizationIconsStyle,
|
||||
CustomizationPageActionType,
|
||||
CustomizationSidebarListStyle,
|
||||
GitBookAPI,
|
||||
SiteSocialAccountPlatform,
|
||||
} from '@gitbook/api';
|
||||
import type { GitBookStandalone } from '@gitbook/embed';
|
||||
@@ -3799,3 +3800,47 @@ const testCases: TestsCase[] = [
|
||||
];
|
||||
|
||||
runTestCases(testCases);
|
||||
|
||||
test('Docs Embed inherits the site questions unless the host supplies questions', async ({
|
||||
page,
|
||||
}) => {
|
||||
const docsURL = 'https://gitbook.com/docs/';
|
||||
const { apiToken, organization, site, siteSpace } = await getSiteAPIToken(docsURL);
|
||||
const api = new GitBookAPI({ endpoint: 'https://api.gitbook.com/cache', authToken: apiToken });
|
||||
const { data } = await api.orgs.getPublishedContentSite(organization, site, {});
|
||||
const customization = data.customizations.siteSpaces[siteSpace] ?? data.customizations.site;
|
||||
const siteQuestions = [...new Set(customization.ai?.suggestions)];
|
||||
expect(siteQuestions.length).toBeGreaterThan(0);
|
||||
|
||||
const hostURL = getContentTestURL(new URL('~gitbook/embed/demo/', docsURL).href);
|
||||
const loaderURL = getContentTestURL(new URL('~gitbook/embed/script.js', docsURL).href);
|
||||
const hostQuestions = ['Where should I start?'];
|
||||
await page.route(hostURL, (route) =>
|
||||
route.fulfill({
|
||||
contentType: 'text/html',
|
||||
body: `<!doctype html>
|
||||
<button id="override">Use host questions</button>
|
||||
<script src="${loaderURL}"></script>
|
||||
<script>
|
||||
GitBook('configure', {
|
||||
tabs: ['assistant'],
|
||||
assistantName: 'Docs Assistant',
|
||||
suggestions: [],
|
||||
});
|
||||
GitBook('open');
|
||||
document.getElementById('override').onclick = () => {
|
||||
GitBook('configure', { suggestions: ${JSON.stringify(hostQuestions)} });
|
||||
};
|
||||
</script>`,
|
||||
})
|
||||
);
|
||||
|
||||
await page.goto(hostURL, { waitUntil: 'domcontentloaded' });
|
||||
const frame = page.frameLocator('#gitbook-widget-iframe');
|
||||
await expect(frame.getByText('Docs Assistant', { exact: true })).toBeVisible();
|
||||
const questions = frame.getByTestId('ai-chat-suggested-question');
|
||||
await expect(questions).toHaveText(siteQuestions);
|
||||
|
||||
await page.getByRole('button', { name: 'Use host questions' }).click();
|
||||
await expect(questions).toHaveText(hostQuestions);
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ export function EmbeddableAIContextProvider(props: EmbeddableAIContextProviderPr
|
||||
return (
|
||||
<AIContextProvider
|
||||
aiMode={aiMode}
|
||||
suggestions={embedConfig.suggestions ?? suggestions}
|
||||
suggestions={embedConfig.suggestions?.length ? embedConfig.suggestions : suggestions}
|
||||
greeting={embedConfig.greeting ?? greeting}
|
||||
trademark={trademark && (embedConfig.trademark ?? true)}
|
||||
assistantName={embedConfig.assistantName?.substring(0, 32)} // Limit to 32 characters
|
||||
|
||||
@@ -20,7 +20,6 @@ const embeddableConfiguration = createStore<GitBookEmbeddableConfiguration>(() =
|
||||
tabs: [],
|
||||
actions: [],
|
||||
greeting: { title: '', subtitle: '' },
|
||||
suggestions: [],
|
||||
tools: [],
|
||||
trademark: true,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user