mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Custom assistants followup (#3584)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gitbook/browser-types": patch
|
||||
"gitbook": patch
|
||||
---
|
||||
|
||||
Custom assistants followup
|
||||
@@ -34,6 +34,12 @@ export type Assistant = Omit<GitBookAssistant, 'icon'> & {
|
||||
*/
|
||||
mode?: 'overlay' | 'sidebar' | 'search';
|
||||
|
||||
/**
|
||||
* Whether the assistant is displayed in the page action menu.
|
||||
* @default false
|
||||
*/
|
||||
pageAction: boolean;
|
||||
|
||||
/**
|
||||
* Icon of the assistant displayed in the UI.
|
||||
*/
|
||||
@@ -90,6 +96,7 @@ export function useAI(): AIContext {
|
||||
chatController.postMessage({ message: query });
|
||||
}
|
||||
},
|
||||
pageAction: true,
|
||||
ui: true,
|
||||
mode: 'sidebar',
|
||||
});
|
||||
@@ -114,6 +121,7 @@ export function useAI(): AIContext {
|
||||
);
|
||||
}
|
||||
},
|
||||
pageAction: false,
|
||||
ui: false,
|
||||
mode: 'search',
|
||||
});
|
||||
@@ -125,6 +133,15 @@ export function useAI(): AIContext {
|
||||
...integrationAssistants.map((assistant) => ({
|
||||
...assistant,
|
||||
icon: <Icon icon={assistant.icon as IconName} className="size-4" />,
|
||||
open: (query?: string) => {
|
||||
setSearchState((prev) => ({
|
||||
ask: null, // Reset ask as we assume the assistant will handle it
|
||||
query: prev?.query ?? null,
|
||||
global: prev?.global ?? false,
|
||||
open: false,
|
||||
}));
|
||||
assistant.open(query);
|
||||
},
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ interface AIActionsDropdownProps {
|
||||
*/
|
||||
export function AIActionsDropdown(props: AIActionsDropdownProps) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const assistants = useAI().assistants.filter((assistant) => assistant.ui === true);
|
||||
const assistants = useAI().assistants.filter(
|
||||
(assistant) => assistant.ui === true && assistant.pageAction
|
||||
);
|
||||
const language = useLanguage();
|
||||
|
||||
return assistants.length > 0 || props.actions.markdown || props.actions.externalAI ? (
|
||||
@@ -63,7 +65,9 @@ export function AIActionsDropdown(props: AIActionsDropdownProps) {
|
||||
*/
|
||||
function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
|
||||
const { markdownPageUrl, actions } = props;
|
||||
const assistants = useAI().assistants.filter((assistant) => assistant.ui === true);
|
||||
const assistants = useAI().assistants.filter(
|
||||
(assistant) => assistant.ui === true && assistant.pageAction
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -103,7 +107,9 @@ function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
|
||||
*/
|
||||
function DefaultAction(props: AIActionsDropdownProps) {
|
||||
const { markdownPageUrl, actions } = props;
|
||||
const assistants = useAI().assistants.filter((assistant) => assistant.ui === true);
|
||||
const assistants = useAI().assistants.filter(
|
||||
(assistant) => assistant.ui === true && assistant.pageAction
|
||||
);
|
||||
|
||||
if (assistants.length) {
|
||||
return <OpenAIAssistant assistant={assistants[0]} type="button" />;
|
||||
|
||||
@@ -50,7 +50,13 @@ if (typeof window !== 'undefined') {
|
||||
integrationAssistants.setState(
|
||||
(state) => [
|
||||
...state,
|
||||
{ ...assistant, id, ui: assistant.ui ?? true, mode: 'overlay' },
|
||||
{
|
||||
...assistant,
|
||||
id,
|
||||
ui: assistant.ui ?? true,
|
||||
mode: 'overlay',
|
||||
pageAction: false,
|
||||
},
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user