Skip to content

Commit 854c448

Browse files
authored
Custom assistants followup (#3584)
1 parent 64a0b0f commit 854c448

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

.changeset/weak-kiwis-type.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@gitbook/browser-types": patch
3+
"gitbook": patch
4+
---
5+
6+
Custom assistants followup

packages/gitbook/src/components/AI/useAI.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export type Assistant = Omit<GitBookAssistant, 'icon'> & {
3434
*/
3535
mode?: 'overlay' | 'sidebar' | 'search';
3636

37+
/**
38+
* Whether the assistant is displayed in the page action menu.
39+
* @default false
40+
*/
41+
pageAction: boolean;
42+
3743
/**
3844
* Icon of the assistant displayed in the UI.
3945
*/
@@ -90,6 +96,7 @@ export function useAI(): AIContext {
9096
chatController.postMessage({ message: query });
9197
}
9298
},
99+
pageAction: true,
93100
ui: true,
94101
mode: 'sidebar',
95102
});
@@ -114,6 +121,7 @@ export function useAI(): AIContext {
114121
);
115122
}
116123
},
124+
pageAction: false,
117125
ui: false,
118126
mode: 'search',
119127
});
@@ -125,6 +133,15 @@ export function useAI(): AIContext {
125133
...integrationAssistants.map((assistant) => ({
126134
...assistant,
127135
icon: <Icon icon={assistant.icon as IconName} className="size-4" />,
136+
open: (query?: string) => {
137+
setSearchState((prev) => ({
138+
ask: null, // Reset ask as we assume the assistant will handle it
139+
query: prev?.query ?? null,
140+
global: prev?.global ?? false,
141+
open: false,
142+
}));
143+
assistant.open(query);
144+
},
128145
}))
129146
);
130147
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ interface AIActionsDropdownProps {
2525
*/
2626
export function AIActionsDropdown(props: AIActionsDropdownProps) {
2727
const ref = useRef<HTMLDivElement>(null);
28-
const assistants = useAI().assistants.filter((assistant) => assistant.ui === true);
28+
const assistants = useAI().assistants.filter(
29+
(assistant) => assistant.ui === true && assistant.pageAction
30+
);
2931
const language = useLanguage();
3032

3133
return assistants.length > 0 || props.actions.markdown || props.actions.externalAI ? (
@@ -63,7 +65,9 @@ export function AIActionsDropdown(props: AIActionsDropdownProps) {
6365
*/
6466
function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
6567
const { markdownPageUrl, actions } = props;
66-
const assistants = useAI().assistants.filter((assistant) => assistant.ui === true);
68+
const assistants = useAI().assistants.filter(
69+
(assistant) => assistant.ui === true && assistant.pageAction
70+
);
6771

6872
return (
6973
<>
@@ -103,7 +107,9 @@ function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
103107
*/
104108
function DefaultAction(props: AIActionsDropdownProps) {
105109
const { markdownPageUrl, actions } = props;
106-
const assistants = useAI().assistants.filter((assistant) => assistant.ui === true);
110+
const assistants = useAI().assistants.filter(
111+
(assistant) => assistant.ui === true && assistant.pageAction
112+
);
107113

108114
if (assistants.length) {
109115
return <OpenAIAssistant assistant={assistants[0]} type="button" />;

packages/gitbook/src/components/Integrations/LoadIntegrations.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ if (typeof window !== 'undefined') {
5050
integrationAssistants.setState(
5151
(state) => [
5252
...state,
53-
{ ...assistant, id, ui: assistant.ui ?? true, mode: 'overlay' },
53+
{
54+
...assistant,
55+
id,
56+
ui: assistant.ui ?? true,
57+
mode: 'overlay',
58+
pageAction: false,
59+
},
5460
],
5561
true
5662
);

0 commit comments

Comments
 (0)