From 8e4c94a4e5871891c55fd059adc6aa003b0793b6 Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Fri, 22 Aug 2025 19:00:09 +0200 Subject: [PATCH 1/2] First test --- .../gitbook/src/components/AI/useAIChat.tsx | 19 +++++- .../gitbook/src/components/AIChat/AIChat.tsx | 58 ++++++++++++++----- .../src/components/AIChat/AIChatInput.tsx | 2 +- .../AIChat/AIChatSuggestedQuestions.tsx | 4 +- .../Integrations/LoadIntegrations.tsx | 20 ++++++- 5 files changed, 81 insertions(+), 22 deletions(-) diff --git a/packages/gitbook/src/components/AI/useAIChat.tsx b/packages/gitbook/src/components/AI/useAIChat.tsx index 43238e21a1..9d925d5a94 100644 --- a/packages/gitbook/src/components/AI/useAIChat.tsx +++ b/packages/gitbook/src/components/AI/useAIChat.tsx @@ -23,6 +23,8 @@ export type AIChatMessage = { query?: string; }; +export type AIChatSize = 'default' | 'large'; + export type AIChatPendingTool = { icon?: IconName; label: string; @@ -85,6 +87,11 @@ export type AIChatState = { * display an error alert. Clearing the conversation will reset this flag. */ error: boolean; + + /** + * The size of the chat window. + */ + size: AIChatSize; }; export type AIChatController = { @@ -96,12 +103,14 @@ export type AIChatController = { postMessage: (input: { message: string }) => void; /** Clear the conversation */ clear: () => void; + /** Toggle the size of the chat window */ + setSize: (size: AIChatSize) => void; }; const AIChatControllerContext = React.createContext(null); // Global state store for AI chat -const globalState = zustand.create(() => { +export const globalState = zustand.create(() => { return { opened: false, responseId: null, @@ -112,6 +121,7 @@ const globalState = zustand.create(() => { loading: false, error: false, initialQuery: null, + size: 'default', }; }); @@ -438,14 +448,19 @@ export function AIChatProvider(props: { })); }, [setSearchState]); + const onSetSize = React.useCallback((size: AIChatSize) => { + globalState.setState((state) => ({ ...state, size })); + }, []); + const controller = React.useMemo(() => { return { open: onOpen, close: onClose, clear: onClear, postMessage: onPostMessage, + setSize: onSetSize, }; - }, [onOpen, onClose, onClear, onPostMessage]); + }, [onOpen, onClose, onClear, onPostMessage, onSetSize]); return ( diff --git a/packages/gitbook/src/components/AIChat/AIChat.tsx b/packages/gitbook/src/components/AIChat/AIChat.tsx index b1b00c449b..51994eb781 100644 --- a/packages/gitbook/src/components/AIChat/AIChat.tsx +++ b/packages/gitbook/src/components/AIChat/AIChat.tsx @@ -2,6 +2,7 @@ import { t, tString, useLanguage } from '@/intl/client'; import type { TranslationLanguage } from '@/intl/translations'; +import { tcls } from '@/lib/tailwind'; import { Icon } from '@gitbook/icons'; import React from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; @@ -64,7 +65,10 @@ export function AIChat(props: { trademark: boolean }) { return (
} > + { + chatController.setSize( + chat.size === 'default' ? 'large' : 'default' + ); + }} + > + + {chat.size === 'default' ? 'Maximize' : 'Minimize'} + { chatController.clear(); @@ -223,27 +244,32 @@ export function AIChatBody(props: { <>
{isEmpty ? (
-
- -
-
-
- {timeGreeting} -
-

- {t(language, 'ai_chat_assistant_description')} -

+
+
+ +
+
+
+ {timeGreeting} +
+

+ {t(language, 'ai_chat_assistant_description')} +

+
{!chat.error ? ( diff --git a/packages/gitbook/src/components/AIChat/AIChatInput.tsx b/packages/gitbook/src/components/AIChat/AIChatInput.tsx index 8cbaed3ab3..437291d12a 100644 --- a/packages/gitbook/src/components/AIChat/AIChatInput.tsx +++ b/packages/gitbook/src/components/AIChat/AIChatInput.tsx @@ -140,7 +140,7 @@ export function AIChatInput(props: { {t(language, 'ai_chat_context_title')} - +
diff --git a/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx b/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx index 5f0089ebdf..837c402520 100644 --- a/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx +++ b/packages/gitbook/src/components/AIChat/AIChatSuggestedQuestions.tsx @@ -13,13 +13,13 @@ export default function AIChatSuggestedQuestions(props: { chatController: AIChat ]; return ( -
+
{DEFAULT_SUGGESTED_QUESTIONS.map((question, index) => (