diff --git a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx index 6da678d7c..d50db6d9f 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx @@ -77,15 +77,12 @@ function convertToThreadMessage(msg: MessageRecord): ThreadMessageLike { content = [{ type: "text", text: msg.content }]; } else if (Array.isArray(msg.content)) { // Filter out custom metadata parts - they're handled separately - const filteredContent = msg.content.filter( - (part: unknown) => - !( - typeof part === "object" && - part !== null && - "type" in part && - (part as { type: string }).type === "thinking-steps" - ) - ); + const filteredContent = msg.content.filter((part: unknown) => { + if (typeof part !== "object" || part === null || !("type" in part)) return true; + const partType = (part as { type: string }).type; + // Filter out thinking-steps and mentioned-documents + return partType !== "thinking-steps" && partType !== "mentioned-documents"; + }); content = filteredContent.length > 0 ? (filteredContent as ThreadMessageLike["content"]) @@ -219,7 +216,7 @@ export default function NewChatPage() { } finally { setIsInitializing(false); } - }, [urlChatId, searchSpaceId, router]); + }, [urlChatId, searchSpaceId, router, setMessageDocumentsMap]); // Initialize on mount useEffect(() => { diff --git a/surfsense_web/components/assistant-ui/thread.tsx b/surfsense_web/components/assistant-ui/thread.tsx index 98f5539a1..5c80842ef 100644 --- a/surfsense_web/components/assistant-ui/thread.tsx +++ b/surfsense_web/components/assistant-ui/thread.tsx @@ -9,7 +9,7 @@ import { useAssistantState, useThreadViewport, } from "@assistant-ui/react"; -import { useAtomValue } from "jotai"; +import { useAtom, useAtomValue, useSetAtom } from "jotai"; import { AlertCircle, ArrowDownIcon, @@ -32,17 +32,11 @@ import { SquareIcon, X, } from "lucide-react"; -import { useParams } from "next/navigation"; import Link from "next/link"; -import { type FC, useState, useRef, useCallback, useEffect, createContext, useContext, useMemo } from "react"; +import { useParams } from "next/navigation"; +import { type FC, createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react"; import { createPortal } from "react-dom"; -import { useAtom, useAtomValue, useSetAtom } from "jotai"; import { mentionedDocumentIdsAtom, mentionedDocumentsAtom, messageDocumentsMapAtom } from "@/atoms/chat/mentioned-documents.atom"; -import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms"; -import { documentTypeCountsAtom } from "@/atoms/documents/document-query.atoms"; -import { useSearchSourceConnectors } from "@/hooks/use-search-source-connectors"; -import { getConnectorIcon } from "@/contracts/enums/connectorIcons"; -import { getDocumentTypeLabel } from "@/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentTypeIcon"; import { documentTypeCountsAtom } from "@/atoms/documents/document-query.atoms"; import { globalNewLLMConfigsAtom, @@ -59,6 +53,7 @@ import { import { MarkdownText } from "@/components/assistant-ui/markdown-text"; import { ToolFallback } from "@/components/assistant-ui/tool-fallback"; import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button"; +import { DocumentsDataTable, type DocumentsDataTableRef } from "@/components/new-chat/DocumentsDataTable"; import { ChainOfThought, ChainOfThoughtContent, @@ -66,12 +61,12 @@ import { ChainOfThoughtStep, ChainOfThoughtTrigger, } from "@/components/prompt-kit/chain-of-thought"; -import { DocumentsDataTable, type DocumentsDataTableRef } from "@/components/new-chat/DocumentsDataTable"; import type { ThinkingStep } from "@/components/tool-ui/deepagent-thinking"; import { Button } from "@/components/ui/button"; -import type { Document } from "@/contracts/types/document.types"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { getConnectorIcon } from "@/contracts/enums/connectorIcons"; +import type { Document } from "@/contracts/types/document.types"; +import { getDocumentTypeLabel } from "@/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentTypeIcon"; import { useSearchSourceConnectors } from "@/hooks/use-search-source-connectors"; import { cn } from "@/lib/utils"; @@ -257,7 +252,7 @@ const ThinkingStepsScrollHandler: FC = () => { const scrollAttempt = () => { try { viewport.scrollToBottom(); - } catch (e) { + } catch { // Ignore errors - viewport might not be ready } }; @@ -531,23 +526,6 @@ const Composer: FC = () => { setMentionedDocuments((prev) => prev.filter((doc) => doc.id !== docId)); }; - // Check if a model is configured - needed to disable input - const { data: userConfigs } = useAtomValue(newLLMConfigsAtom); - const { data: globalConfigs } = useAtomValue(globalNewLLMConfigsAtom); - const { data: preferences } = useAtomValue(llmPreferencesAtom); - - const hasModelConfigured = useMemo(() => { - if (!preferences) return false; - const agentLlmId = preferences.agent_llm_id; - if (agentLlmId === null || agentLlmId === undefined) return false; - - // Check if the configured model actually exists - if (agentLlmId < 0) { - return globalConfigs?.some((c) => c.id === agentLlmId) ?? false; - } - return userConfigs?.some((c) => c.id === agentLlmId) ?? false; - }, [preferences, globalConfigs, userConfigs]); - return (