diff --git a/surfsense_web/components/new-chat/document-mention-picker.tsx b/surfsense_web/components/new-chat/document-mention-picker.tsx index e89885b1d..8fbef9d15 100644 --- a/surfsense_web/components/new-chat/document-mention-picker.tsx +++ b/surfsense_web/components/new-chat/document-mention-picker.tsx @@ -1,7 +1,7 @@ "use client"; import { useQuery } from "@tanstack/react-query"; -import { FileText } from "lucide-react"; +import { BookOpen, FileText } from "lucide-react"; import { forwardRef, useCallback, @@ -215,6 +215,16 @@ export const DocumentMentionPicker = forwardRef< isSurfsenseDocsLoading) && currentPage === 0; + // Split documents into SurfSense docs and user docs for grouped rendering + const surfsenseDocsList = useMemo( + () => actualDocuments.filter((doc) => doc.document_type === "SURFSENSE_DOCS"), + [actualDocuments] + ); + const userDocsList = useMemo( + () => actualDocuments.filter((doc) => doc.document_type !== "SURFSENSE_DOCS"), + [actualDocuments] + ); + // Track already selected documents using unique key (document_type:id) to avoid ID collisions const selectedKeys = useMemo( () => new Set(initialSelectedDocuments.map((d) => `${d.document_type}:${d.id}`)), @@ -324,47 +334,104 @@ export const DocumentMentionPicker = forwardRef< ) : (
- {actualDocuments.map((doc) => { - const docKey = `${doc.document_type}:${doc.id}`; - const isAlreadySelected = selectedKeys.has(docKey); - const selectableIndex = selectableDocuments.findIndex( - (d) => d.document_type === doc.document_type && d.id === doc.id - ); - const isHighlighted = !isAlreadySelected && selectableIndex === highlightedIndex; + {/* SurfSense Documentation Section */} + {surfsenseDocsList.length > 0 && ( + <> +
+ + SurfSense Docs +
+ {surfsenseDocsList.map((doc) => { + const docKey = `${doc.document_type}:${doc.id}`; + const isAlreadySelected = selectedKeys.has(docKey); + const selectableIndex = selectableDocuments.findIndex( + (d) => d.document_type === doc.document_type && d.id === doc.id + ); + const isHighlighted = !isAlreadySelected && selectableIndex === highlightedIndex; + + return ( + + ); + })} + + )} + + {/* User Documents Section */} + {userDocsList.length > 0 && ( + <> +
+ + Your Documents +
+ {userDocsList.map((doc) => { + const docKey = `${doc.document_type}:${doc.id}`; + const isAlreadySelected = selectedKeys.has(docKey); + const selectableIndex = selectableDocuments.findIndex( + (d) => d.document_type === doc.document_type && d.id === doc.id + ); + const isHighlighted = !isAlreadySelected && selectableIndex === highlightedIndex; + + return ( + + ); + })} + + )} - return ( - - ); - })} {/* Loading indicator for additional pages */} {isLoadingMore && (