Fix AI Actions dropdown and LLM integration (#3464)

This commit is contained in:
Nolann B.
2025-07-11 12:14:06 +02:00
committed by GitHub
parent e38caf78ff
commit 7212345466
3 changed files with 28 additions and 31 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'gitbook': patch
---
Fix AI Actions dropdown and LLM integration
@@ -12,18 +12,20 @@ import { DropdownMenu } from '@/components/primitives/DropdownMenu';
import { Icon } from '@gitbook/icons';
import { useRef } from 'react';
interface AIActionsDropdownProps {
markdownPageUrl: string;
withAIChat?: boolean;
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: {
markdownPageUrl: string;
/**
* Whether to include the "Ask Docs Assistant" entry in the dropdown menu.
*/
withAIChat?: boolean;
pageURL: string;
trademark: boolean;
}) {
export function AIActionsDropdown(props: AIActionsDropdownProps) {
const ref = useRef<HTMLDivElement>(null);
return (
@@ -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 (
<>
@@ -77,8 +74,12 @@ 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}
</>
);
}
@@ -86,11 +87,7 @@ function AIActionsDropdownMenuContent(props: {
/**
* 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) {
@@ -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';
@@ -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}