Skip to content

Commit 7212345

Browse files
authored
Fix AI Actions dropdown and LLM integration (#3464)
1 parent e38caf7 commit 7212345

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

.changeset/lucky-tigers-drive.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+
Fix AI Actions dropdown and LLM integration

packages/gitbook/src/components/AIActions/AIActionsDropdown.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ import { DropdownMenu } from '@/components/primitives/DropdownMenu';
1212
import { Icon } from '@gitbook/icons';
1313
import { useRef } from 'react';
1414

15-
/**
16-
* Dropdown menu for the AI Actions (Ask Docs Assistant, Copy page, View as Markdown, Open in LLM).
17-
*/
18-
export function AIActionsDropdown(props: {
15+
interface AIActionsDropdownProps {
1916
markdownPageUrl: string;
20-
/**
21-
* Whether to include the "Ask Docs Assistant" entry in the dropdown menu.
22-
*/
2317
withAIChat?: boolean;
24-
pageURL: string;
2518
trademark: boolean;
26-
}) {
19+
/**
20+
* Whether to include the "Open in LLM" entries in the dropdown menu.
21+
*/
22+
withLLMActions?: boolean;
23+
}
24+
25+
/**
26+
* Dropdown menu for the AI Actions (Ask Docs Assistant, Copy page, View as Markdown, Open in LLM).
27+
*/
28+
export function AIActionsDropdown(props: AIActionsDropdownProps) {
2729
const ref = useRef<HTMLDivElement>(null);
2830

2931
return (
@@ -56,13 +58,8 @@ export function AIActionsDropdown(props: {
5658
/**
5759
* The content of the dropdown menu.
5860
*/
59-
function AIActionsDropdownMenuContent(props: {
60-
markdownPageUrl: string;
61-
withAIChat?: boolean;
62-
pageURL: string;
63-
trademark: boolean;
64-
}) {
65-
const { markdownPageUrl, withAIChat, pageURL, trademark } = props;
61+
function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
62+
const { markdownPageUrl, withAIChat, trademark, withLLMActions } = props;
6663

6764
return (
6865
<>
@@ -77,20 +74,20 @@ function AIActionsDropdownMenuContent(props: {
7774
/>
7875
<ViewAsMarkdown markdownPageUrl={markdownPageUrl} type="dropdown-menu-item" />
7976

80-
<OpenInLLM provider="chatgpt" url={pageURL} type="dropdown-menu-item" />
81-
<OpenInLLM provider="claude" url={pageURL} type="dropdown-menu-item" />
77+
{withLLMActions ? (
78+
<>
79+
<OpenInLLM provider="chatgpt" url={markdownPageUrl} type="dropdown-menu-item" />
80+
<OpenInLLM provider="claude" url={markdownPageUrl} type="dropdown-menu-item" />
81+
</>
82+
) : null}
8283
</>
8384
);
8485
}
8586

8687
/**
8788
* A default action shown as a quick-access button beside the dropdown menu
8889
*/
89-
function DefaultAction(props: {
90-
markdownPageUrl: string;
91-
withAIChat?: boolean;
92-
trademark: boolean;
93-
}) {
90+
function DefaultAction(props: AIActionsDropdownProps) {
9491
const { markdownPageUrl, withAIChat, trademark } = props;
9592

9693
if (withAIChat) {

packages/gitbook/src/components/PageBody/PageHeader.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isAIChatEnabled } from '@/components/utils/isAIChatEnabled';
33
import type { GitBookSiteContext } from '@/lib/context';
44
import type { AncestorRevisionPage } from '@/lib/pages';
55
import { tcls } from '@/lib/tailwind';
6-
import type { RevisionPageDocument } from '@gitbook/api';
6+
import { type RevisionPageDocument, SiteVisibility } from '@gitbook/api';
77
import { Icon } from '@gitbook/icons';
88
import { PageIcon } from '../PageIcon';
99
import { StyledLink } from '../primitives';
@@ -42,15 +42,10 @@ export async function PageHeader(props: {
4242
)}
4343
>
4444
<AIActionsDropdown
45-
markdownPageUrl={`${context.linker.toPathInSpace(page.path)}.md`}
46-
pageURL={context.linker.toAbsoluteURL(
47-
context.linker.toPathForPage({
48-
pages: context.revision.pages,
49-
page,
50-
})
51-
)}
45+
markdownPageUrl={`${context.linker.toAbsoluteURL(context.linker.toPathInSpace(page.path))}.md`}
5246
withAIChat={withAIChat}
5347
trademark={context.customization.trademark.enabled}
48+
withLLMActions={context.site.visibility === SiteVisibility.Public}
5449
/>
5550
</div>
5651
) : null}

0 commit comments

Comments
 (0)