mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
refactor: improve message content filtering and update dependencies in new chat
- Enhanced the message content filtering logic to exclude both "thinking-steps" and "mentioned-documents" for better clarity in chat messages. - Updated the dependency imports in the thread component for improved organization and consistency. - Adjusted the effect dependencies in the NewChatPage component to include the message documents map for better state management.
This commit is contained in:
parent
6f330e7b8d
commit
1d646d3b5f
2 changed files with 14 additions and 39 deletions
|
|
@ -77,15 +77,12 @@ function convertToThreadMessage(msg: MessageRecord): ThreadMessageLike {
|
||||||
content = [{ type: "text", text: msg.content }];
|
content = [{ type: "text", text: msg.content }];
|
||||||
} else if (Array.isArray(msg.content)) {
|
} else if (Array.isArray(msg.content)) {
|
||||||
// Filter out custom metadata parts - they're handled separately
|
// Filter out custom metadata parts - they're handled separately
|
||||||
const filteredContent = msg.content.filter(
|
const filteredContent = msg.content.filter((part: unknown) => {
|
||||||
(part: unknown) =>
|
if (typeof part !== "object" || part === null || !("type" in part)) return true;
|
||||||
!(
|
const partType = (part as { type: string }).type;
|
||||||
typeof part === "object" &&
|
// Filter out thinking-steps and mentioned-documents
|
||||||
part !== null &&
|
return partType !== "thinking-steps" && partType !== "mentioned-documents";
|
||||||
"type" in part &&
|
});
|
||||||
(part as { type: string }).type === "thinking-steps"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
content =
|
content =
|
||||||
filteredContent.length > 0
|
filteredContent.length > 0
|
||||||
? (filteredContent as ThreadMessageLike["content"])
|
? (filteredContent as ThreadMessageLike["content"])
|
||||||
|
|
@ -219,7 +216,7 @@ export default function NewChatPage() {
|
||||||
} finally {
|
} finally {
|
||||||
setIsInitializing(false);
|
setIsInitializing(false);
|
||||||
}
|
}
|
||||||
}, [urlChatId, searchSpaceId, router]);
|
}, [urlChatId, searchSpaceId, router, setMessageDocumentsMap]);
|
||||||
|
|
||||||
// Initialize on mount
|
// Initialize on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import {
|
||||||
useAssistantState,
|
useAssistantState,
|
||||||
useThreadViewport,
|
useThreadViewport,
|
||||||
} from "@assistant-ui/react";
|
} from "@assistant-ui/react";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
||||||
import {
|
import {
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
ArrowDownIcon,
|
ArrowDownIcon,
|
||||||
|
|
@ -32,17 +32,11 @@ import {
|
||||||
SquareIcon,
|
SquareIcon,
|
||||||
X,
|
X,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useParams } from "next/navigation";
|
|
||||||
import Link from "next/link";
|
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 { createPortal } from "react-dom";
|
||||||
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
||||||
import { mentionedDocumentIdsAtom, mentionedDocumentsAtom, messageDocumentsMapAtom } from "@/atoms/chat/mentioned-documents.atom";
|
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 { documentTypeCountsAtom } from "@/atoms/documents/document-query.atoms";
|
||||||
import {
|
import {
|
||||||
globalNewLLMConfigsAtom,
|
globalNewLLMConfigsAtom,
|
||||||
|
|
@ -59,6 +53,7 @@ import {
|
||||||
import { MarkdownText } from "@/components/assistant-ui/markdown-text";
|
import { MarkdownText } from "@/components/assistant-ui/markdown-text";
|
||||||
import { ToolFallback } from "@/components/assistant-ui/tool-fallback";
|
import { ToolFallback } from "@/components/assistant-ui/tool-fallback";
|
||||||
import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
|
import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
|
||||||
|
import { DocumentsDataTable, type DocumentsDataTableRef } from "@/components/new-chat/DocumentsDataTable";
|
||||||
import {
|
import {
|
||||||
ChainOfThought,
|
ChainOfThought,
|
||||||
ChainOfThoughtContent,
|
ChainOfThoughtContent,
|
||||||
|
|
@ -66,12 +61,12 @@ import {
|
||||||
ChainOfThoughtStep,
|
ChainOfThoughtStep,
|
||||||
ChainOfThoughtTrigger,
|
ChainOfThoughtTrigger,
|
||||||
} from "@/components/prompt-kit/chain-of-thought";
|
} 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 type { ThinkingStep } from "@/components/tool-ui/deepagent-thinking";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import type { Document } from "@/contracts/types/document.types";
|
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||||
import { getConnectorIcon } from "@/contracts/enums/connectorIcons";
|
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 { useSearchSourceConnectors } from "@/hooks/use-search-source-connectors";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
|
@ -257,7 +252,7 @@ const ThinkingStepsScrollHandler: FC = () => {
|
||||||
const scrollAttempt = () => {
|
const scrollAttempt = () => {
|
||||||
try {
|
try {
|
||||||
viewport.scrollToBottom();
|
viewport.scrollToBottom();
|
||||||
} catch (e) {
|
} catch {
|
||||||
// Ignore errors - viewport might not be ready
|
// Ignore errors - viewport might not be ready
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -531,23 +526,6 @@ const Composer: FC = () => {
|
||||||
setMentionedDocuments((prev) => prev.filter((doc) => doc.id !== docId));
|
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 (
|
return (
|
||||||
<ComposerPrimitive.Root className="aui-composer-root relative flex w-full flex-col">
|
<ComposerPrimitive.Root className="aui-composer-root relative flex w-full flex-col">
|
||||||
<ComposerPrimitive.AttachmentDropzone className="aui-composer-attachment-dropzone flex w-full flex-col rounded-2xl border-input bg-muted px-1 pt-2 outline-none transition-shadow data-[dragging=true]:border-ring data-[dragging=true]:border-dashed data-[dragging=true]:bg-accent/50">
|
<ComposerPrimitive.AttachmentDropzone className="aui-composer-attachment-dropzone flex w-full flex-col rounded-2xl border-input bg-muted px-1 pt-2 outline-none transition-shadow data-[dragging=true]:border-ring data-[dragging=true]:border-dashed data-[dragging=true]:bg-accent/50">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue