From 06fef43b581741fc9e9872a2512ef45e6394a6a5 Mon Sep 17 00:00:00 2001 From: Matias Benary Date: Wed, 25 Feb 2026 19:15:36 -0300 Subject: [PATCH 1/3] feat: update chatbot --- website/src/theme/DocItem/Layout/index.js | 2 + .../SearchBar/components/AIChatInSearch.tsx | 16 +- .../SearchBar/components/ChatbotTrigger.tsx | 59 ++++++ .../SearchBar/components/useStreamingChat.ts | 3 +- website/src/theme/SearchBar/index.tsx | 18 +- website/src/theme/SearchBar/styles.module.css | 184 +++++++++++++++++- 6 files changed, 276 insertions(+), 6 deletions(-) create mode 100644 website/src/theme/SearchBar/components/ChatbotTrigger.tsx diff --git a/website/src/theme/DocItem/Layout/index.js b/website/src/theme/DocItem/Layout/index.js index 873fecb1f36..489c6838da0 100644 --- a/website/src/theme/DocItem/Layout/index.js +++ b/website/src/theme/DocItem/Layout/index.js @@ -15,6 +15,7 @@ import styles from './styles.module.css'; import { FeedbackComponent } from '../../../components/FeedbackComponent'; +import ChatbotTrigger from '../../SearchBar/components/ChatbotTrigger'; /** * Decide if the toc should be rendered, on mobile or desktop viewports @@ -57,6 +58,7 @@ export default function DocItemLayout({ children }) { {children} {!isMain && <> + diff --git a/website/src/theme/SearchBar/components/AIChatInSearch.tsx b/website/src/theme/SearchBar/components/AIChatInSearch.tsx index 40769cf6eb4..1b0438d3642 100644 --- a/website/src/theme/SearchBar/components/AIChatInSearch.tsx +++ b/website/src/theme/SearchBar/components/AIChatInSearch.tsx @@ -15,6 +15,11 @@ interface AIChatInSearchProps { onSaveConversation?: (data: SavedConversation) => void; onClearConversation?: () => void; savedConversation?: SavedConversation | null; + initialMessage?: string | null; +} + +function getDisplayText(text: string): string { + return text.replace(/\n\n\[Page:[^\]]*\]$/, '').trim(); } const SUGGESTIONS = [ @@ -29,6 +34,7 @@ export default function AIChatInSearch({ onSaveConversation, onClearConversation, savedConversation, + initialMessage, }: AIChatInSearchProps) { const { colorMode } = useColorMode(); @@ -42,6 +48,14 @@ export default function AIChatInSearch({ const messagesEndRef = useRef(null); const inputRef = useRef(null); + const initialMessageSentRef = useRef(false); + + useEffect(() => { + if (initialMessage && !initialMessageSentRef.current) { + initialMessageSentRef.current = true; + sendMessage(initialMessage); + } + }, [initialMessage, sendMessage]); const prevIsLoadingRef = useRef(false); useEffect(() => { @@ -113,7 +127,7 @@ export default function AIChatInSearch({ {index > 0 &&
}
-

{turn.userText}

+

{getDisplayText(turn.userText)}


diff --git a/website/src/theme/SearchBar/components/ChatbotTrigger.tsx b/website/src/theme/SearchBar/components/ChatbotTrigger.tsx new file mode 100644 index 00000000000..5531d1065ad --- /dev/null +++ b/website/src/theme/SearchBar/components/ChatbotTrigger.tsx @@ -0,0 +1,59 @@ +import React, { useState, useRef } from 'react'; +import { ArrowUp } from 'lucide-react'; +import { useLocation } from '@docusaurus/router'; +import styles from '../styles.module.css'; + +export default function ChatbotTrigger() { + const [value, setValue] = useState(''); + const textareaRef = useRef(null); + const { pathname } = useLocation(); + + const getPageMdUrl = () => { + const clean = pathname.replace(/\/$/, ''); + return `${clean}.md`; + }; + + const submit = () => { + const text = value.trim(); + if (!text) return; + setValue(''); + const message = `${text}\n\n[Page: ${getPageMdUrl()}]`; + console.log(message); + + window.dispatchEvent(new CustomEvent('open-chatbot', { detail: { message } })); + }; + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + submit(); + } + }; + + return ( +
+