()
| 72 | * with any custom assistants registered at runtime. |
| 73 | */ |
| 74 | export 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) { |
no test coverage detected