Skip to content

Fix AI Actions dropdown and LLM integration #3464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-tigers-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gitbook': patch
---

Fix AI Actions dropdown and LLM integration
43 changes: 20 additions & 23 deletions packages/gitbook/src/components/AIActions/AIActionsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ import { DropdownMenu } from '@/components/primitives/DropdownMenu';
import { Icon } from '@gitbook/icons';
import { useRef } from 'react';

/**
* Dropdown menu for the AI Actions (Ask Docs Assistant, Copy page, View as Markdown, Open in LLM).
*/
export function AIActionsDropdown(props: {
interface AIActionsDropdownProps {
markdownPageUrl: string;
/**
* Whether to include the "Ask Docs Assistant" entry in the dropdown menu.
*/
withAIChat?: boolean;
pageURL: string;
trademark: boolean;
}) {
/**
* Whether to include the "Open in LLM" entries in the dropdown menu.
*/
withLLMActions?: boolean;
}

/**
* Dropdown menu for the AI Actions (Ask Docs Assistant, Copy page, View as Markdown, Open in LLM).
*/
export function AIActionsDropdown(props: AIActionsDropdownProps) {
const ref = useRef<HTMLDivElement>(null);

return (
Expand Down Expand Up @@ -56,13 +58,8 @@ export function AIActionsDropdown(props: {
/**
* The content of the dropdown menu.
*/
function AIActionsDropdownMenuContent(props: {
markdownPageUrl: string;
withAIChat?: boolean;
pageURL: string;
trademark: boolean;
}) {
const { markdownPageUrl, withAIChat, pageURL, trademark } = props;
function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
const { markdownPageUrl, withAIChat, trademark, withLLMActions } = props;

return (
<>
Expand All @@ -77,20 +74,20 @@ function AIActionsDropdownMenuContent(props: {
/>
<ViewAsMarkdown markdownPageUrl={markdownPageUrl} type="dropdown-menu-item" />

<OpenInLLM provider="chatgpt" url={pageURL} type="dropdown-menu-item" />
<OpenInLLM provider="claude" url={pageURL} type="dropdown-menu-item" />
{withLLMActions ? (
<>
<OpenInLLM provider="chatgpt" url={markdownPageUrl} type="dropdown-menu-item" />
<OpenInLLM provider="claude" url={markdownPageUrl} type="dropdown-menu-item" />
</>
) : null}
</>
);
}

/**
* A default action shown as a quick-access button beside the dropdown menu
*/
function DefaultAction(props: {
markdownPageUrl: string;
withAIChat?: boolean;
trademark: boolean;
}) {
function DefaultAction(props: AIActionsDropdownProps) {
const { markdownPageUrl, withAIChat, trademark } = props;

if (withAIChat) {
Expand Down
11 changes: 3 additions & 8 deletions packages/gitbook/src/components/PageBody/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isAIChatEnabled } from '@/components/utils/isAIChatEnabled';
import type { GitBookSiteContext } from '@/lib/context';
import type { AncestorRevisionPage } from '@/lib/pages';
import { tcls } from '@/lib/tailwind';
import type { RevisionPageDocument } from '@gitbook/api';
import { type RevisionPageDocument, SiteVisibility } from '@gitbook/api';
import { Icon } from '@gitbook/icons';
import { PageIcon } from '../PageIcon';
import { StyledLink } from '../primitives';
Expand Down Expand Up @@ -42,15 +42,10 @@ export async function PageHeader(props: {
)}
>
<AIActionsDropdown
markdownPageUrl={`${context.linker.toPathInSpace(page.path)}.md`}
pageURL={context.linker.toAbsoluteURL(
context.linker.toPathForPage({
pages: context.revision.pages,
page,
})
)}
markdownPageUrl={`${context.linker.toAbsoluteURL(context.linker.toPathInSpace(page.path))}.md`}
withAIChat={withAIChat}
trademark={context.customization.trademark.enabled}
withLLMActions={context.site.visibility === SiteVisibility.Public}
/>
</div>
) : null}
Expand Down