MCPcopy
hub / github.com/GitbookIO/gitbook / useAI

Function useAI

packages/gitbook/src/components/AI/useAI.tsx:74–153  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72 * with any custom assistants registered at runtime.
73 */
74export function useAI(): AIContext {
75 const config = useAIConfig();
76 const chat = useAIChatState();
77 const chatController = useAIChatController();
78 const language = useLanguage();
79 const [, setSearchState] = useSearch();
80
81 const assistants: Assistant[] = [];
82
83 if (config.aiMode === CustomizationAIMode.Assistant) {
84 assistants.push({
85 id: 'gitbook-assistant',
86 label: getAIChatName(language, config.trademark),
87 icon: (
88 <AIChatIcon
89 state={chat.loading ? 'thinking' : 'default'}
90 trademark={config.trademark}
91 />
92 ),
93 open: (query?: string) => {
94 chatController.open();
95 if (query) {
96 chatController.postMessage({ message: query });
97 }
98 },
99 pageAction: true,
100 ui: true,
101 mode: 'sidebar',
102 });
103 } else if (config.aiMode === CustomizationAIMode.Search) {
104 assistants.push({
105 id: 'gitbook-ai-search',
106 label: tString(language, 'ai_chat_context_badge'),
107 icon: (
108 <div className="relative">
109 <Icon icon="search" className="size-4" />
110 <Icon
111 icon="sparkle"
112 iconStyle={IconStyle.Solid}
113 className="absolute top-[2.5px] left-[2.6px] size-2"
114 />
115 </div>
116 ),
117 open: (query?: string) => {
118 if (query) {
119 setSearchState((prev) =>
120 prev ? { ...prev, query: null, ask: query, open: true } : null
121 );
122 }
123 },
124 pageAction: false,
125 ui: false,
126 mode: 'search',
127 });
128 }
129
130 const integrationAssistants = useIntegrationAssistants();
131 if (integrationAssistants.length > 0) {

Callers 5

getPageDropdownActionsFunction · 0.90
getPageDefaultActionFunction · 0.90
useSearchResultsFunction · 0.90
SearchResults.tsxFile · 0.90
SearchContainerFunction · 0.90

Calls 8

useLanguageFunction · 0.90
useSearchFunction · 0.90
getAIChatNameFunction · 0.90
useIntegrationAssistantsFunction · 0.90
useAIConfigFunction · 0.85
useAIChatStateFunction · 0.85
useAIChatControllerFunction · 0.85
tStringFunction · 0.50

Tested by

no test coverage detected