diff --git a/apps/masterbots.ai/app/c/[category]/[chatbot]/page.tsx b/apps/masterbots.ai/app/c/[category]/[chatbot]/page.tsx index 70dc97f1..4aa16387 100644 --- a/apps/masterbots.ai/app/c/[category]/[chatbot]/page.tsx +++ b/apps/masterbots.ai/app/c/[category]/[chatbot]/page.tsx @@ -2,7 +2,7 @@ import { authOptions } from "@/auth"; import { ChatChatbot } from "@/components/routes/chat/chat-chatbot"; import ThreadPanel from "@/components/routes/thread/thread-panel"; import { botNames } from "@/lib/constants/bots-names"; -import { PAGE_SM_SIZE } from "@/lib/constants/hasura"; +import { PAGE_SIZE } from "@/lib/constants/hasura"; import { generateMetadataFromSEO } from "@/lib/metadata"; import { getChatbot, getThreads } from "@/services/hasura"; import { isTokenExpired } from "mb-lib"; @@ -43,8 +43,9 @@ export default async function BotThreadsPage({ throw new Error("User ID is missing."); } - const threads = await getThreads({ chatbotName, jwt: jwt as string, userId, limit: PAGE_SM_SIZE }); - + const threads = await getThreads({ chatbotName, jwt: jwt as string, userId, limit: PAGE_SIZE }); + console.log('threads::[chatbots] page --> ', threads.length) + console.log('threads::[chatbots] page::chatbotName --> ', chatbotName) return ( <> li::before { - content: "•"; + content: '•'; @apply absolute left-0 text-muted-foreground; } @@ -186,7 +216,7 @@ } .nested-list.list-decimal > li::before { - content: counter(list-counter) "."; + content: counter(list-counter) '.'; @apply absolute left-0 text-muted-foreground; } @@ -265,16 +295,16 @@ button.text-link { } .scrollbar::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); - border-radius: 2px; + border-radius: 3px; +} +.scrollbar::-webkit-scrollbar-thumb:hover { + background: hsla(var(--accent)); } -/* .scrollbar::-webkit-scrollbar-thumb:hover { - background: var(--scrollbar-thumb-hover); -} */ @media screen and (min-width: 1024px) { .scrollbar::-webkit-scrollbar { - width: 8px; - height: 8px; + width: 6px; + height: 6px; } } @@ -438,52 +468,52 @@ button.text-link { stroke-width: 1.25px; } -/* Base sidebar gradient styles *//* Chat route styles */ +/* Base sidebar gradient styles */ /* Chat route styles */ .sidebar-gradient { transition: background-image 0.3s ease; } /* Chat route styles */ -[data-route="chat"] .sidebar-gradient:hover:not(.selected) { +[data-route='chat'] .sidebar-gradient:hover:not(.selected) { background-image: var(--background-chat-hover-gradient); } -[data-route="chat"] .sidebar-gradient.selected { +[data-route='chat'] .sidebar-gradient.selected { background-image: var(--background-chat-gradient); } /* Public route styles */ -[data-route="public"] .sidebar-gradient:hover:not(.selected) { +[data-route='public'] .sidebar-gradient:hover:not(.selected) { background-image: var(--background-public-hover-gradient); } -[data-route="public"] .sidebar-gradient.selected { +[data-route='public'] .sidebar-gradient.selected { background-image: var(--background-public-gradient); } /* Component route styles */ - /* Avatar ring colors */ - [data-route="chat"] .selected-bot-avatar { - @apply ring-purple-500; - } - [data-route="public"] .selected-bot-avatar { - @apply ring-green-500; - } +/* Avatar ring colors */ +[data-route='chat'] .selected-bot-avatar { + @apply ring-purple-500; +} +[data-route='public'] .selected-bot-avatar { + @apply ring-green-500; +} - /* Text colors */ - [data-route="chat"] .selected-bot-text { - @apply text-purple-500; - } - [data-route="public"] .selected-bot-text { - @apply text-green-500; - } +/* Text colors */ +[data-route='chat'] .selected-bot-text { + @apply text-purple-500; +} +[data-route='public'] .selected-bot-text { + @apply text-green-500; +} - /* Icon fill colors */ - [data-route="chat"] .selected-bot-icon { - @apply fill-purple-500; - } - [data-route="public"] .selected-bot-icon { - @apply fill-green-500; - } +/* Icon fill colors */ +[data-route='chat'] .selected-bot-icon { + @apply fill-purple-500; +} +[data-route='public'] .selected-bot-icon { + @apply fill-green-500; +} diff --git a/apps/masterbots.ai/components/layout/sidebar/sidebar-link.tsx b/apps/masterbots.ai/components/layout/sidebar/sidebar-link.tsx index 90c8e399..c3f1c19e 100755 --- a/apps/masterbots.ai/components/layout/sidebar/sidebar-link.tsx +++ b/apps/masterbots.ai/components/layout/sidebar/sidebar-link.tsx @@ -290,6 +290,7 @@ const ChatbotComponent: React.FC = React.memo( )} onClick={handleChatbotClick} data-route={routeType} + prefetch > index - }`} + }`} className={cn( 'cursor-pointer hover:underline', isListItem ? 'text-blue-500' : 'text-link' @@ -153,8 +153,8 @@ export function ClickableText({ typeof item === 'string' ? item : extractTextFromReactNodeNormal( - (item.props as { children: React.ReactNode }).children - ) + (item.props as { children: React.ReactNode }).children + ) ) .join(' ') return transformLink(content, parentContext) @@ -174,7 +174,7 @@ export function ClickableText({ key={`clickable-${ // biome-ignore lint/suspicious/noArrayIndexKey: index - }`} + }`} > {renderClickableContent(clickableText, restText)} diff --git a/apps/masterbots.ai/components/routes/chat/chat-layout-section.tsx b/apps/masterbots.ai/components/routes/chat/chat-layout-section.tsx index 1318af87..d283fd5a 100644 --- a/apps/masterbots.ai/components/routes/chat/chat-layout-section.tsx +++ b/apps/masterbots.ai/components/routes/chat/chat-layout-section.tsx @@ -15,7 +15,7 @@ export function ChatLayoutSection({ children }: { children: React.ReactNode }) {
} className={cn( - 'flex h-[calc(100vh-4rem)] group w-full overflow-auto animate-in duration-300 ease-in-out relative', + 'flex h-full max-h-[calc(100vh-219px)] group w-full overflow-auto animate-in duration-300 ease-in-out relative', 'lg:w-[calc(100%-250px)] xl:w-[calc(100%-300px)] lg:ml-[250px] xl:ml-[300px]', 'scrollbar' )} diff --git a/apps/masterbots.ai/components/routes/chat/chat-list.tsx b/apps/masterbots.ai/components/routes/chat/chat-list.tsx index a2ed2268..a3e498c6 100644 --- a/apps/masterbots.ai/components/routes/chat/chat-list.tsx +++ b/apps/masterbots.ai/components/routes/chat/chat-list.tsx @@ -47,7 +47,7 @@ export function ChatList({ const localContainerRef = useRef(null) const effectiveContainerRef = containerRef || localContainerRef const chatMessages = (messages || activeThread?.messages || []) - // .sort((a, b) => a.createdAt - b.createdAt) + .sort((a, b) => a.createdAt - b.createdAt) useScroll({ containerRef: effectiveContainerRef, diff --git a/apps/masterbots.ai/components/routes/chat/chat-message.tsx b/apps/masterbots.ai/components/routes/chat/chat-message.tsx index 781e9491..ad41ea3f 100644 --- a/apps/masterbots.ai/components/routes/chat/chat-message.tsx +++ b/apps/masterbots.ai/components/routes/chat/chat-message.tsx @@ -17,7 +17,8 @@ export function ChatMessage({ webSearchResults = [], ...props }: ChatMessageProps) { - const cleanMessage = { ...message, content: cleanPrompt(message.content) } + const content = cleanPrompt(message.content) + const cleanMessage = { ...message, content } const [references, setReferences] = useState([]) const ReferencesSection = () => { @@ -28,8 +29,8 @@ export function ChatMessage({

References

{references.map((ref) => ( -
{ref.thumbnail?.src && ( @@ -107,7 +108,7 @@ export function ChatMessage({ ) return ( -
  • -
    +
    - + handleKeywordChange(e.target.value)} diff --git a/apps/masterbots.ai/components/routes/profile/user-thread-list.tsx b/apps/masterbots.ai/components/routes/profile/user-thread-list.tsx index 411aa29f..ed5c45c8 100644 --- a/apps/masterbots.ai/components/routes/profile/user-thread-list.tsx +++ b/apps/masterbots.ai/components/routes/profile/user-thread-list.tsx @@ -1,10 +1,10 @@ 'use client' -import { Thread, User } from 'mb-genql' +import type { Thread, User } from 'mb-genql' import UserThreadPanel from '../thread/user-thread-panel' export function UserThreadList({ user, - threads + threads, }: { user: User threads: Thread[] diff --git a/apps/masterbots.ai/components/routes/thread/thread-popup.tsx b/apps/masterbots.ai/components/routes/thread/thread-popup.tsx index 360b4f72..9bf51186 100644 --- a/apps/masterbots.ai/components/routes/thread/thread-popup.tsx +++ b/apps/masterbots.ai/components/routes/thread/thread-popup.tsx @@ -95,7 +95,7 @@ export function ThreadPopup({ className }: { className?: string }) { className={cn( 'flex flex-col dark:bg-[#18181b] bg-white grow rounded-b-[8px] scrollbar h-full', 'pb-[120px] md:pb-[180px]', - 'max-h-[calc(100vh-240px)] md:max-h-[calc(100vh-220px)]', + 'max-h-[calc(100%-240px)] md:max-h-[calc(100%-220px)]', className )} ref={popupContentRef as React.Ref} diff --git a/apps/masterbots.ai/components/routes/thread/user-thread-panel.tsx b/apps/masterbots.ai/components/routes/thread/user-thread-panel.tsx index b2cc553c..bc8b1506 100755 --- a/apps/masterbots.ai/components/routes/thread/user-thread-panel.tsx +++ b/apps/masterbots.ai/components/routes/thread/user-thread-panel.tsx @@ -33,13 +33,13 @@ import { ChatSearchInput } from '@/components/routes/chat/chat-search-input' import ThreadList from '@/components/routes/thread/thread-list' import { NoResults } from '@/components/shared/no-results-card' import { ThreadItemSkeleton } from '@/components/shared/skeletons/browse-skeletons' +import { Skeleton } from '@/components/ui/skeleton' import { PAGE_SIZE, PAGE_SM_SIZE } from '@/lib/constants/hasura' import { useSidebar } from '@/lib/hooks/use-sidebar' import { useThread } from '@/lib/hooks/use-thread' import { useThreadVisibility } from '@/lib/hooks/use-thread-visibility' import { cn } from '@/lib/utils' import { getBrowseThreads, getThread, getThreads, getUserBySlug } from '@/services/hasura' -import { isEqual } from 'lodash' import type { Thread } from 'mb-genql' import type { Session } from 'next-auth' import { useSession } from 'next-auth/react' @@ -59,10 +59,10 @@ export default function UserThreadPanel({ }) { const params = useParams<{ chatbot: string; threadId: string; slug?: string }>() const { data: session } = useSession() - const { activeCategory, activeChatbot, selectedChatbots, selectedCategories } = useSidebar() + const { activeCategory, activeChatbot } = useSidebar() const { isOpenPopup, activeThread, setActiveThread, setIsOpenPopup } = useThread() - const [loading, setLoading] = useState(false) - const { threads: hookThreads, isContinuousThread, setIsContinuousThread } = useThreadVisibility() + const [loading, setLoading] = useState(true) + const { isContinuousThread, setIsContinuousThread } = useThreadVisibility() const [searchTerm, setSearchTerm] = useState('') const searchParams = useSearchParams() const { slug, threadId } = params @@ -77,10 +77,7 @@ export default function UserThreadPanel({ return result }, [slug]) - const prevCategoryRef = useRef(activeCategory) - const prevChatbotRef = useRef(activeChatbot) - const prevPathRef = useRef(usePathname()) - const fetchIdRef = useRef(0) // Store the fetchId in a ref + const prevPathRef = useRef('') const pathname = usePathname() const [state, setState] = useSetState<{ threads: Thread[] @@ -137,44 +134,6 @@ export default function UserThreadPanel({ setLoading(false) } - const handleThreadsChange = async () => { - setLoading(true) - const userOnSlug = userWithSlug.value?.user - const isOwnProfile = session?.user?.id === userOnSlug?.userId - if (!session?.user || (!isOwnProfile && page === 'profile')) { - const newThreads = await fetchBrowseThreads() - - setState({ - threads: newThreads, - totalThreads: threads?.length, - count: threads?.length, - }) - setLoading(false) - return - } - - const currentFetchId = Date.now() // Generate a unique identifier for the current fetch - fetchIdRef.current = currentFetchId - const newThreads = await getThreads({ - jwt: session?.user?.hasuraJwt, - userId: session?.user.id, - limit: PAGE_SIZE, - categoryId: activeCategory, - chatbotName: activeChatbot?.name - }) - - // Check if the fetchId matches the current fetchId stored in the ref - if (fetchIdRef.current === currentFetchId) { - // If it matches, update the threads state - setState({ - threads: newThreads, - totalThreads: threads?.length, - count: threads?.length, - }) - } - setLoading(false) - } - const getThreadByContinuousThreadId = async (continuousThreadId: string, session: Session) => { const thread = await getThread({ threadId: continuousThreadId, @@ -200,29 +159,21 @@ export default function UserThreadPanel({ } }, [continuousThreadId, session]) - const threads = state.threads.length ? state.threads : initialThreads + const threads = state.threads.length > initialThreads.length ? state.threads : initialThreads - // biome-ignore lint/correctness/useExhaustiveDependencies: This effect should run only when the active category or chatbot changes + const completeLoading = (load: boolean) => { + setLoading(load) + } + + // biome-ignore lint/correctness/useExhaustiveDependencies: This effect should run only when the pathname changes useEffect(() => { - // Skip if popup is open + // Skip if popup is open or there is initial threads if (isOpenPopup) return - const shouldFetch = - activeCategory || - activeChatbot || - !isEqual(prevCategoryRef.current, activeCategory) || - !isEqual(prevChatbotRef.current, activeChatbot) || - pathname !== prevPathRef.current // Add pathname check - - // Update refs - prevCategoryRef.current = activeCategory - prevChatbotRef.current = activeChatbot prevPathRef.current = pathname - if (shouldFetch) { - handleThreadsChange() - } - }, [activeCategory, activeChatbot, isOpenPopup, pathname]) + completeLoading(prevPathRef.current !== pathname) + }, [initialThreads, pathname, activeChatbot, activeCategory]) // biome-ignore lint/correctness/useExhaustiveDependencies: This effect should run only when the active thread changes useEffect(() => { @@ -239,15 +190,24 @@ export default function UserThreadPanel({ ? 'No threads available in the selected category' : 'Start a conversation to create your first thread' const showNoResults = !loading && searchTerm && threads.length === 0 - const showChatbotDetails = !loading && !searchTerm && !threads.length + const showChatbotDetails = !loading && !searchTerm && !threads.length && activeChatbot + const searchInputContainerClassName = 'flex justify-between px-4 py-5 md:px-10 lg:max-w-full' return ( <> - {(page !== 'profile' || (page !== 'profile' && !isContinuousThread)) && ( -
    + {!loading && (threads.length !== 0 && (page !== 'profile' || (page !== 'profile' && !isContinuousThread))) && ( +
    )} + {loading && ( +
    +
    + + +
    +
    + )}
      { + let markerFound = false for (const marker of markers) { const index = extracted.indexOf(marker) if (index !== -1) { extracted = extracted.substring(index + marker.length) + markerFound = true } } + return markerFound } - if (markers.some((marker) => extracted.includes(marker))) runExtraction() + while (runExtraction()) {} return extracted } diff --git a/apps/masterbots.ai/lib/hooks/use-mb-chat.tsx b/apps/masterbots.ai/lib/hooks/use-mb-chat.tsx index ce0fe468..6a7ab4da 100644 --- a/apps/masterbots.ai/lib/hooks/use-mb-chat.tsx +++ b/apps/masterbots.ai/lib/hooks/use-mb-chat.tsx @@ -8,7 +8,7 @@ import { setDefaultUserPreferencesPrompt, } from '@/lib/constants/prompts' import { useModel } from '@/lib/hooks/use-model' -import { useSidebar } from '@/lib/hooks/use-sidebar' +import { type NavigationParams, useSidebar } from '@/lib/hooks/use-sidebar' import { useThread } from '@/lib/hooks/use-thread' import { useThreadVisibility } from '@/lib/hooks/use-thread-visibility' import { @@ -16,7 +16,7 @@ import { deleteThread, getMessages, getThread, - saveNewMessage + saveNewMessage, } from '@/services/hasura' import type { AiClientType, @@ -35,7 +35,7 @@ import type { SaveNewMessageParams } from '@/services/hasura/hasura.service.type import { appConfig } from 'mb-env' import { nanoid } from 'nanoid' import { useSession } from 'next-auth/react' -import { useParams, useRouter } from 'next/navigation' +import { useParams } from 'next/navigation' import { createContext, useContext, useEffect, useRef } from 'react' import { useAsync, useSetState } from 'react-use' import { useSonner } from './useSonner' @@ -62,11 +62,10 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { setActiveTool, setLoadingState, } = useThread() - const { activeChatbot } = useSidebar() - const router = useRouter() + const { activeChatbot, navigateTo } = useSidebar() const userContentRef = useRef('') const randomThreadId = useRef(crypto.randomUUID()) - const [{ messagesFromDB, isInitLoaded, /* isNewChat */ }, setState] = useSetState<{ + const [{ messagesFromDB, isInitLoaded /* isNewChat */ }, setState] = useSetState<{ isInitLoaded: boolean webSearch: boolean messagesFromDB: Message[] @@ -78,6 +77,7 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { // isNewChat: Boolean(!activeThread || activeThread && activeThread.messages.length <= 1), }) const isNewChat = Boolean(!activeThread || (activeThread && activeThread.messages.length <= 1)) + const { customSonner } = useSonner() const { isContinuousThread } = useThreadVisibility() // console.log('[HOOK] webSearch', webSearch) @@ -102,6 +102,7 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { createdAt: m.createdAt, })) : [] + const systemPrompts: AiMessage[] = userPreferencesPrompts.concat(chatbotSystemPrompts) /** * @description * Concatenate all message to pass it to chat component. @@ -112,9 +113,7 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { * 2. Chatbot System Prompts (IQ, Expertise). * 3. Conversation between user and assistant. * */ - const initialMessages: AiMessage[] = userPreferencesPrompts - .concat(chatbotSystemPrompts) - .concat(userAndAssistantMessages) + const initialMessages: AiMessage[] = systemPrompts.concat(userAndAssistantMessages) const threadId = activeThread?.threadId || randomThreadId.current const chatbot = activeThread?.chatbot || activeChatbot @@ -209,6 +208,17 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { // fetchMessages(), ]) + // ? This is when we want to reflect the whole conversation and serves as a fallback + // ? whenever the conversation glitches due the bug with the "isNewChat" boolean. + // ! Logic has to improve... + const transformedMessages = [newUserMessage, newAssistantMessage].map((msg) => ({ + id: nanoid(), + role: msg.role as AiMessage['role'], + content: msg.content, + createdAt: msg.createdAt, + } as AiMessage)) + setMessages(allMessages.concat(transformedMessages)) + // router.push( // `/c/${toSlug(activeThread?.chatbot.categories[0].category.name as string)}/${toSlug(activeThread?.chatbot.name as string)}/${activeThread?.threadId}`, // { @@ -266,7 +276,6 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { // eslint-disable-next-line react-hooks/exhaustive-deps }, [isOpenPopup]) - // * Loading: getting the the information right... 'digesting' // ? fetch messages from db on active thread change const { loading } = useAsync(async () => { if ( @@ -283,6 +292,7 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { useEffect(() => { if (!activeThread && !isOpenPopup) { setState({ messagesFromDB: [], isInitLoaded: false }) + setLoadingState() } }, [activeThread, isOpenPopup]) @@ -325,21 +335,6 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { threadId, jwt: session?.user?.hasuraJwt, }) - } else { - const newAllMessages = uniqBy( - allMessages?.concat( - (newThread?.messages || []).map((m) => ({ - id: m.messageId, - role: m.role as AiMessage['role'], - content: m.content, - createdAt: m.createdAt || new Date().toISOString(), - })), - ), - 'content', - ) - // .filter((m) => m.role !== 'system') - // console.log('newAllMessages ---> ', newAllMessages) - setMessages(newAllMessages) } if (thread) { @@ -363,10 +358,13 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { // console.log('thread::tunninUserContent --> ', thread) if (thread) { - updateActiveThread({ - ...thread, - messages: thread.messages.filter((m) => m.content !== userMessage.content) - }, true) + updateActiveThread( + { + ...thread, + messages: thread.messages.filter((m) => m.content !== userMessage.content), + }, + true, + ) } userContentRef.current = content @@ -411,7 +409,11 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { userId: session?.user.id, } - const thread = await updateActiveThread(!activeThread || isNewChat ? optimisticThread : undefined) + console.log('appendWithMbContextPrompts::activeThread', activeThread) + console.log('appendWithMbContextPrompts::isNewChat', isNewChat) + const thread = await updateActiveThread( + isNewChat && !activeThread ? optimisticThread : activeThread || undefined, + ) if (!isOpenPopup) { setIsOpenPopup(true) @@ -483,11 +485,11 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { content: message, }) - router.push(`/${chatbot?.name?.trim().toLowerCase()}/${randomThreadId.current}`, { - scroll: false, - }) - - router.refresh() + navigateTo({ + categoryName: activeChatbot?.categories[0].category.name, + chatbotName: activeChatbot?.name, + page: 'personal', + } as NavigationParams) } return null @@ -508,38 +510,10 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { } const appendNewMessage = async (userMessage: AiMessage | CreateMessage, thread: Thread) => { - try { const chatbotMetadata = await getMetadataLabels() const isUpdatedThreadNewChat = Boolean(!thread || (thread && thread.messages.length <= 1)) - if (isUpdatedThreadNewChat) { - const newChatMessages = uniqBy( - [ - { - id: 'examples-' + nanoid(10), - role: 'system' as 'data' | 'system' | 'user' | 'assistant', - content: examplesPrompt(chatbotMetadata), - }, - ...initialMessages, - ...allMessages, - ], - 'content', - ) - setMessages(newChatMessages) - - if (appConfig.features.devMode) { - console.log('newChatMessages --> ', newChatMessages) - console.log('Chatbot metadata --> ', chatbotMetadata) - } - } - // What remedies are good for stress relieve? - if (appConfig.features.devMode && !isUpdatedThreadNewChat) { - console.log('allMessages --> ', allMessages) - console.log('Chatbot metadata --> ', chatbotMetadata) - } - - if (isUpdatedThreadNewChat && chatbot) { await createThread({ threadId: threadId as string, @@ -550,12 +524,35 @@ export function MBChatProvider({ children }: { children: React.ReactNode }) { } setLoadingState('generating') + + const chatMessagesToAppend = uniqBy( + [ + { + id: 'examples-' + nanoid(10), + role: 'system' as 'data' | 'system' | 'user' | 'assistant', + content: examplesPrompt(chatbotMetadata), + }, + ...systemPrompts, + ], + 'content', + ) + setMessages(chatMessagesToAppend) + + // What remedies are good for stress relieve? + if (appConfig.features.devMode) { + console.log('chatMessagesToAppend --> ', chatMessagesToAppend) + console.log('Chatbot metadata --> ', chatbotMetadata) + } + const appendResponse = await append( { ...userMessage, - content: isNewChat + content: isUpdatedThreadNewChat ? userContentRef.current - : followingQuestionsPrompt(userContentRef.current, messages), + : followingQuestionsPrompt( + userContentRef.current, + allMessages.filter((msg) => msg.role === 'user'), + ), }, // ? Provide chat attachments here... // { diff --git a/apps/masterbots.ai/lib/hooks/use-sidebar.tsx b/apps/masterbots.ai/lib/hooks/use-sidebar.tsx index 87f2f901..cbe2b87c 100644 --- a/apps/masterbots.ai/lib/hooks/use-sidebar.tsx +++ b/apps/masterbots.ai/lib/hooks/use-sidebar.tsx @@ -4,13 +4,13 @@ import { getCategories, getUserBySlug } from '@/services/hasura' import type { Category, Chatbot } from 'mb-genql' import { toSlug } from 'mb-lib' import { useSession } from 'next-auth/react' -import { useParams, usePathname } from 'next/navigation' +import { useParams, usePathname, useRouter } from 'next/navigation' import * as React from 'react' import { useAsync } from 'react-use' const LOCAL_STORAGE_KEY = 'sidebar' -interface NavigationParams { +export interface NavigationParams { page: string | undefined slug: string | undefined categoryName?: string @@ -65,6 +65,7 @@ export function SidebarProvider({ children }: SidebarProviderProps) { const { data: session } = useSession() const { slug } = useParams() const pathname = usePathname() + const router = useRouter() const prevPath = React.useRef(null) const { @@ -271,7 +272,15 @@ export function SidebarProvider({ children }: SidebarProviderProps) { isBrowse, }: NavigationParams): void => { const url = buildNavigationUrl({ page, slug, categoryName, chatbotName, isBrowse }) - window.history.pushState({}, '', url) + + if (url.startsWith('/c')) { + router.push(url, { scroll: false }) + } else { + window.history.pushState({ + category: categoryName, + chatbot: chatbotName, + }, '', url) + } } if (isLoading) { diff --git a/apps/masterbots.ai/lib/threads.ts b/apps/masterbots.ai/lib/threads.ts index a56bfab8..8a94ab06 100644 --- a/apps/masterbots.ai/lib/threads.ts +++ b/apps/masterbots.ai/lib/threads.ts @@ -22,7 +22,8 @@ export function getAllUserMessagesAsStringArray(allMessages: Message[] | AI.Mess const cleanMessages = userMessages.map((m) => extractBetweenMarkers( m.content, - 'OK, so following the same pattern, how would you answer the question:', + // 'OK, so following the same pattern, how would you answer the question:', + 'First, think about the following questions and requests: [', ), ) return cleanMessages.join(', ') diff --git a/bun.lockb b/bun.lockb index a7ca733f..b24a1c6e 100755 Binary files a/bun.lockb and b/bun.lockb differ