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..7f4638bd54 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'; @@ -13,7 +14,7 @@ import { } from '../AI'; import { EmbeddableFrame } from '../Embeddable/EmbeddableFrame'; import { useNow } from '../hooks'; -import { Button } from '../primitives'; +import { Button, DropdownMenuSeparator } from '../primitives'; import { DropdownMenu, DropdownMenuItem } from '../primitives'; import { AIChatIcon } from './AIChatIcon'; import { AIChatInput } from './AIChatInput'; @@ -64,7 +65,10 @@ export function AIChat(props: { trademark: boolean }) { return (
} > + { + chatController.setSize( + chat.size === 'default' ? 'large' : 'default' + ); + }} + > + +
+

+ {chat.size === 'default' ? 'Maximize' : 'Minimize'} +

+

+ {chat.size === 'default' + ? 'Longer, more detailed answers' + : 'Shorter, more concise answers'} +

+
+
+ { chatController.clear(); @@ -223,27 +254,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) => (