From 38226b9413095be2fccdf84853f10ee041e3af6d Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Tue, 16 Sep 2025 16:29:10 +0200 Subject: [PATCH] Simplify AI Chat - Add new `note` field - Always clear `messages` when posting a message - Remove follow-up questions --- .changeset/bright-ladybugs-march.md | 5 + .../gitbook/src/components/AI/useAIChat.tsx | 3 +- .../src/components/AIChat/AIChatMessages.tsx | 105 +++++++++--------- 3 files changed, 62 insertions(+), 51 deletions(-) create mode 100644 .changeset/bright-ladybugs-march.md diff --git a/.changeset/bright-ladybugs-march.md b/.changeset/bright-ladybugs-march.md new file mode 100644 index 0000000000..11f17a44b6 --- /dev/null +++ b/.changeset/bright-ladybugs-march.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Simplify AI Chat diff --git a/packages/gitbook/src/components/AI/useAIChat.tsx b/packages/gitbook/src/components/AI/useAIChat.tsx index 55317f8d76..999a3fe002 100644 --- a/packages/gitbook/src/components/AI/useAIChat.tsx +++ b/packages/gitbook/src/components/AI/useAIChat.tsx @@ -21,6 +21,7 @@ export type AIChatMessage = { role: AIMessageRole; content: React.ReactNode; query?: string; + note?: string; }; export type AIChatPendingTool = { @@ -391,11 +392,11 @@ export function AIChatProvider(props: { return { ...state, messages: [ - ...state.messages, { role: AIMessageRole.User, content: input.message, query: input.message, + note: state.messages.length > 0 ? 'Starting a new chat' : undefined, }, ], query: input.message, diff --git a/packages/gitbook/src/components/AIChat/AIChatMessages.tsx b/packages/gitbook/src/components/AIChat/AIChatMessages.tsx index 35ee7846c8..74790ad449 100644 --- a/packages/gitbook/src/components/AIChat/AIChatMessages.tsx +++ b/packages/gitbook/src/components/AIChat/AIChatMessages.tsx @@ -6,14 +6,13 @@ import type React from 'react'; import type { AIChatController, AIChatState } from '../AI'; import { AIChatToolConfirmations } from './AIChatToolConfirmations'; import { AIResponseFeedback } from './AIResponseFeedback'; -import { AIChatFollowupSuggestions } from './AiChatFollowupSuggestions'; export function AIChatMessages(props: { chat: AIChatState; chatController: AIChatController; lastUserMessageRef?: React.RefObject; }) { - const { chat, chatController, lastUserMessageRef } = props; + const { chat, lastUserMessageRef } = props; return ( <> @@ -24,57 +23,63 @@ export function AIChatMessages(props: { index === chat.messages.map((m) => m.role).lastIndexOf(AIMessageRole.User); return ( -
- {message.content ? message.content : null} - - {isLastMessage && chat.loading ? ( -
- {!message.content ? : null} - + <> + {message.note ? ( +
+ {message.note}
) : null} +
+ {message.content ? message.content : null} - {isLastMessage ? ( - <> - {!chat.loading && - !chat.error && - chat.query && - chat.responseId && - chat.pendingTools.length === 0 ? ( - - ) : null} - - - - ) : null} -
+ {isLastMessage && chat.loading ? ( +
+ {!message.content ? : null} + +
+ ) : null} + + {isLastMessage ? ( + <> + {!chat.loading && + !chat.error && + chat.query && + chat.responseId && + chat.pendingTools.length === 0 ? ( + + ) : null} + + + ) : null} +
+ ); })}