🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat: support files upload in chat input (#10967)
Shinji-Li60eba456ed04
diff --git a/src/app/[variants]/(main)/chat/features/Conversation/index.tsx b/src/app/[variants]/(main)/chat/features/Conversation/index.tsxindex 5a83f8b5162..9ed2661c914 100644--- a/src/app/[variants]/(main)/chat/features/Conversation/index.tsx+++ b/src/app/[variants]/(main)/chat/features/Conversation/index.tsx@@ -1,6 +1,9 @@import { Flexbox, TooltipGroup } from '@lobehub/ui';import { memo } from 'react';+import DragUploadZone, { useUploadFiles } from '@/components/DragUploadZone';+import { useAgentStore } from '@/store/agent';+import { agentSelectors } from '@/store/agent/selectors';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';@@ -9,13 +12,21 @@ import ChatHeader from './Header';const ChatConversation = memo(() => {const showHeader = useGlobalStore(systemStatusSelectors.showChatHeader);++ // Get current agent's model info for vision support check+ const model = useAgentStore(agentSelectors.currentAgentModel);+ const provider = useAgentStore(agentSelectors.currentAgentModelProvider);+ const { handleUploadFiles } = useUploadFiles({ model, provider });+return (- <Flexbox height={'100%'} style={{ overflow: 'hidden', position: 'relative' }} width={'100%'}>- {showHeader && <ChatHeader />}- <TooltipGroup>- <ConversationArea />- </TooltipGroup>- </Flexbox>+ <DragUploadZone onUploadFiles={handleUploadFiles} style={{ height: '100%', width: '100%' }}>+ <Flexbox height={'100%'} style={{ overflow: 'hidden', position: 'relative' }} width={'100%'}>+ {showHeader && <ChatHeader />}+ <TooltipGroup>+ <ConversationArea />+ </TooltipGroup>+ </Flexbox>+ </DragUploadZone>);});diff --git a/src/app/[variants]/(main)/group/features/Conversation/index.tsx b/src/app/[variants]/(main)/group/features/Conversation/index.tsxindex 5551ce80ddf..7134eb6350d 100644--- a/src/app/[variants]/(main)/group/features/Conversation/index.tsx+++ b/src/app/[variants]/(main)/group/features/Conversation/index.tsx@@ -1,6 +1,9 @@import { Flexbox } from '@lobehub/ui';import { memo } from 'react';+import DragUploadZone, { useUploadFiles } from '@/components/DragUploadZone';+import { useAgentStore } from '@/store/agent';+import { agentSelectors } from '@/store/agent/selectors';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';@@ -9,11 +12,19 @@ import ChatHeader from './Header';const ChatConversation = memo(() => {const showHeader = useGlobalStore(systemStatusSelectors.showChatHeader);++ // Get current agent's model info for vision support check+ const model = useAgentStore(agentSelectors.currentAgentModel);+ const provider = useAgentStore(agentSelectors.currentAgentModelProvider);+ const { handleUploadFiles } = useUploadFiles({ model, provider });+return (- <Flexbox height={'100%'} style={{ overflow: 'hidden', position: 'relative' }} width={'100%'}>- {showHeader && <ChatHeader />}- <ConversationArea />- </Flexbox>+ <DragUploadZone onUploadFiles={handleUploadFiles} style={{ height: '100%', width: '100%' }}>+ <Flexbox height={'100%'} style={{ overflow: 'hidden', position: 'relative' }} width={'100%'}>+ {showHeader && <ChatHeader />}+ <ConversationArea />+ </Flexbox>+ </DragUploadZone>);});diff --git a/src/app/[variants]/(main)/home/features/InputArea/index.tsx b/src/app/[variants]/(main)/home/features/InputArea/index.tsxindex 2777cd9a44d..a7cbd36d016 100644--- a/src/app/[variants]/(main)/home/features/InputArea/index.tsx+++ b/src/app/[variants]/(main)/home/features/InputArea/index.tsx@@ -1,7 +1,10 @@import { Flexbox } from '@lobehub/ui';import { memo, useMemo } from 'react';+import DragUploadZone, { useUploadFiles } from '@/components/DragUploadZone';import { type ActionKeys, ChatInputProvider, DesktopChatInput } from '@/features/ChatInput';+import { useAgentStore } from '@/store/agent';+import { agentByIdSelectors } from '@/store/agent/selectors';import { useChatStore } from '@/store/chat';import { useHomeStore } from '@/store/home';@@ -15,6 +18,13 @@ const InputArea = memo(() => {const { loading, send, inboxAgentId } = useSend();const inputActiveMode = useHomeStore((s) => s.inputActiveMode);+ // Get agent's model info for vision support check+ const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(inboxAgentId)(s));+ const provider = useAgentStore((s) =>+ agentByIdSelectors.getAgentModelProviderById(inboxAgentId)(s),+ );+ const { handleUploadFiles } = useUploadFiles({ model, provider });+// A slot to insert content above the chat input// Override some default behavior of the chat inputconst inputContainerProps = useMemo(@@ -31,30 +41,32 @@ const InputArea = memo(() => {return (<Flexbox gap={16} style={{ marginBottom: 16 }}>- <ChatInputProvider- agentId={inboxAgentId}- chatInputEditorRef={(instance) => {- if (!instance) return;- useChatStore.setState({ mainInputEditor: instance });- }}- leftActions={leftActions}- onMarkdownContentChange={(content) => {- useChatStore.setState({ inputMessage: content });- }}- onSend={send}- sendButtonProps={{- disabled: loading,- generating: loading,- onStop: () => {},- shape: 'round',- }}- >- <DesktopChatInput- dropdownPlacement="bottomLeft"- extenHeaderContent={inputActiveMode ? <ModeHeader /> : undefined}- inputContainerProps={inputContainerProps}- />- </ChatInputProvider>+ <DragUploadZone onUploadFiles={handleUploadFiles}>+ <ChatInputProvider+ agentId={inboxAgentId}+ chatInputEditorRef={(instance) => {+ if (!instance) return;+ useChatStore.setState({ mainInputEditor: instance });+ }}+ leftActions={leftActions}+ onMarkdownContentChange={(content) => {+ useChatStore.setState({ inputMessage: content });+ }}+ onSend={send}+ sendButtonProps={{+ disabled: loading,+ generating: loading,+ onStop: () => {},+ shape: 'round',+ }}+ >+ <DesktopChatInput+ dropdownPlacement="bottomLeft"+ extenHeaderContent={inputActiveMode ? <ModeHeader /> : undefined}+ inputContainerProps={inputContainerProps}+ />+ </ChatInputProvider>+ </DragUploadZone><StarterList /></Flexbox>diff --git a/src/components/DragUploadZone/DragUploadProvider.tsx b/src/components/DragUploadZone/DragUploadProvider.tsxnew file mode 100644index 00000000000..96cb4d313f1--- /dev/null+++ b/src/components/DragUploadZone/DragUploadProvider.tsx@@ -0,0 +1,98 @@+'use client';++import {+ type ReactNode,+ createContext,+ memo,+ useCallback,+ useContext,+ useEffect,+ useRef,+ useState,+} from 'react';++interface DragUploadContextValue {+ /**+ * Whether files are being dragged anywhere on the page+ */+ isDraggingGlobally: boolean;+}++const DragUploadContext = createContext<DragUploadContextValue>({+ isDraggingGlobally: false,+});++/**+ * Hook to access global drag state+ */+export const useDragUploadContext = () => useContext(DragUploadContext);++interface DragUploadProviderProps {+ children: ReactNode;+}++/**+ * Provider that tracks global drag state across the entire page.+ * When files are dragged anywhere on the page, all DragUploadZone components+ * can highlight to show they are drop targets.+ */+export const DragUploadProvider = memo<DragUploadProviderProps>(({ children }) => {+ const [isDraggingGlobally, setIsDraggingGlobally] = useState(false);+ const dragCounter = useRef(0);++ const handleDragEnter = useCallback((e: DragEvent) => {+ if (!e.dataTransfer?.types.includes('Files')) return;++ e.preventDefault();+ dragCounter.current += 1;++ if (dragCounter.current === 1) {+ setIsDraggingGlobally(true);+ }+ }, []);++ const handleDragOver = useCallback((e: DragEvent) => {+ if (!e.dataTransfer?.types.includes('Files')) return;+ e.preventDefault();+ }, []);++ const handleDragLeave = useCallback((e: DragEvent) => {+ if (!e.dataTransfer?.types.includes('Files')) return;++ e.preventDefault();+ dragCounter.current -= 1;++ if (dragCounter.current === 0) {+ setIsDraggingGlobally(false);+ }+ }, []);++ const handleDrop = useCallback((e: DragEvent) => {+ // Prevent browser from opening the file if dropped outside a zone+ e.preventDefault();+ dragCounter.current = 0;+ setIsDraggingGlobally(false);+ }, []);++ useEffect(() => {+ window.addEventListener('dragenter', handleDragEnter);+ window.addEventListener('dragover', handleDragOver);+ window.addEventListener('dragleave', handleDragLeave);+ window.addEventListener('drop', handleDrop);++ return () => {+ window.removeEventListener('dragenter', handleDragEnter);+ window.removeEventListener('dragover', handleDragOver);+ window.removeEventListener('dragleave', handleDragLeave);+ window.removeEventListener('drop', handleDrop);+ };+ }, [handleDragEnter, handleDragOver, handleDragLeave, handleDrop]);++ return (+ <DragUploadContext.Provider value={{ isDraggingGlobally }}>+ {children}+ </DragUploadContext.Provider>+ );+});++DragUploadProvider.displayName = 'DragUploadProvider';diff --git a/src/components/DragUploadZone/index.tsx b/src/components/DragUploadZone/index.tsxnew file mode 100644index 00000000000..7ca3449c2bb--- /dev/null+++ b/src/components/DragUploadZone/index.tsx@@ -0,0 +1,189 @@+'use client';++import { Center, Flexbox, Icon } from '@lobehub/ui';+import { createStyles } from 'antd-style';+import { FileImage, FileText, FileUpIcon } from 'lucide-react';+import { darken, lighten } from 'polished';+import { type CSSProperties, type ReactNode, memo } from 'react';+import { useTranslation } from 'react-i18next';++import { useDragUploadContext } from './DragUploadProvider';+import { useLocalDragUpload } from './useLocalDragUpload';++const BLOCK_SIZE = 48;+const ICON_SIZE = { size: 28, strokeWidth: 1.5 };++const useStyles = createStyles(({ css, token }) => ({+ container: css`+ position: relative;+ `,+ content: css`+ width: 100%;+ height: 100%;+ padding: 12px;+ border: 1.5px dashed #fff;+ border-radius: ${token.borderRadiusLG}px;+ `,+ desc: css`+ font-size: 12px;+ line-height: 18px;+ color: #fff;+ `,+ icon: css`+ border-radius: ${token.borderRadiusSM}px;+ color: ${darken(0.05, token.geekblue)};+ background: ${lighten(0.38, token.geekblue)};+ `,+ iconGroup: css`+ margin-block-start: -32px;+ `,+ overlay: css`+ pointer-events: none;++ position: absolute;+ z-index: 100;+ inset: 0;++ display: flex;+ align-items: center;+ justify-content: center;++ border-radius: ${token.borderRadiusLG}px;++ background: ${token.colorBgMask};++ transition: all 0.2s ease-in-out;+ `,+ overlayContent: css`+ padding: ${token.borderRadiusLG}px;+ border-radius: 12px;++ background: ${token.geekblue};+ `,+ title: css`+ font-size: 16px;+ font-weight: bold;+ color: #fff;+ `,+}));++export interface DragUploadZoneProps {+ /**+ * The content to render inside the drop zone+ */+ children: ReactNode;+ /**+ * Custom class name for the container+ */+ className?: string;+ /**+ * Whether the drop zone is disabled+ */+ disabled?: boolean;+ /**+ * Whether to show file types (images + documents) or just images+ * @default true+ */+ enabledFiles?: boolean;+ /**+ * Callback when files are dropped+ */+ onUploadFiles: (files: File[]) => void | Promise<void>;+ /**+ * Minimum height of the overlay content+ */+ overlayMinHeight?: number;+ /**+ * Custom style for the container+ */+ style?: CSSProperties;+}++const DragUploadZone = memo<DragUploadZoneProps>(+ ({+ children,+ className,+ disabled = false,+ enabledFiles = true,+ overlayMinHeight = 160,+ onUploadFiles,+ style,+ }) => {+ const { styles, cx, theme } = useStyles();+ const { t } = useTranslation('components');++ // Global drag state - shows overlay when dragging anywhere on page+ const { isDraggingGlobally } = useDragUploadContext();++ // Local drop handler - only handles drop events+ const { getContainerProps } = useLocalDragUpload({+ disabled,+ onUploadFiles,+ });++ // Show overlay when files are being dragged anywhere on the page+ const showOverlay = isDraggingGlobally && !disabled;++ return (+ <div className={cx(styles.container, className)} style={style} {...getContainerProps()}>+ {children}+ {showOverlay && (+ <div className={styles.overlay}>+ <div className={styles.overlayContent} style={{ minHeight: overlayMinHeight }}>+ <Center className={styles.content} gap={8}>+ <Flexbox className={styles.iconGroup} horizontal>+ <Center+ className={styles.icon}+ height={BLOCK_SIZE * 1.2}+ style={{+ background: lighten(0.32, theme.geekblue),+ transform: 'rotateZ(-20deg) translateX(8px)',+ }}+ width={BLOCK_SIZE}+ >+ <Icon icon={FileImage} size={ICON_SIZE} />+ </Center>+ <Center+ className={styles.icon}+ height={BLOCK_SIZE * 1.2}+ style={{+ transform: 'translateY(-10px)',+ zIndex: 1,+ }}+ width={BLOCK_SIZE}+ >+ <Icon icon={FileUpIcon} size={ICON_SIZE} />+ </Center>+ <Center+ className={styles.icon}+ height={BLOCK_SIZE * 1.2}+ style={{+ background: lighten(0.32, theme.geekblue),+ transform: 'rotateZ(20deg) translateX(-8px)',+ }}+ width={BLOCK_SIZE}+ >+ <Icon icon={FileText} size={ICON_SIZE} />+ </Center>+ </Flexbox>+ <Flexbox align={'center'} gap={4} style={{ textAlign: 'center' }}>+ <Flexbox className={styles.title}>+ {t(enabledFiles ? 'DragUpload.dragFileTitle' : 'DragUpload.dragTitle')}+ </Flexbox>+ <Flexbox className={styles.desc}>+ {t(enabledFiles ? 'DragUpload.dragFileDesc' : 'DragUpload.dragDesc')}+ </Flexbox>+ </Flexbox>+ </Center>+ </div>+ </div>+ )}+ </div>+ );+ },+);++DragUploadZone.displayName = 'DragUploadZone';++export { useUploadFiles } from './useUploadFiles';+export default DragUploadZone;diff --git a/src/components/DragUploadZone/useLocalDragUpload.ts b/src/components/DragUploadZone/useLocalDragUpload.tsnew file mode 100644index 00000000000..3832c59513c--- /dev/null+++ b/src/components/DragUploadZone/useLocalDragUpload.ts@@ -0,0 +1,134 @@+/* eslint-disable no-undef */+import { useCallback } from 'react';++/**+ * Process a FileSystemEntry recursively to extract all files+ */+const processEntry = async (entry: FileSystemEntry): Promise<File[]> => {+ return new Promise((resolve) => {+ if (entry.isFile) {+ (entry as FileSystemFileEntry).file((file) => {+ resolve([file]);+ });+ } else if (entry.isDirectory) {+ const dirReader = (entry as FileSystemDirectoryEntry).createReader();+ dirReader.readEntries(async (entries) => {+ const filesPromises = entries.map((element) => processEntry(element));+ const fileArrays = await Promise.all(filesPromises);+ resolve(fileArrays.flat());+ });+ } else {+ resolve([]);+ }+ });+};++/**+ * Extract files from DataTransferItems, supporting both files and directories+ */+export const getFileListFromDataTransferItems = async (+ items: DataTransferItem[],+): Promise<File[]> => {+ const filePromises: Promise<File[]>[] = [];++ for (const item of items) {+ if (item.kind === 'file') {+ // Safari browser may throw error when using FileSystemFileEntry.file()+ // So we prioritize using getAsFile() method first for better browser compatibility+ const file = item.getAsFile();++ if (file) {+ filePromises.push(Promise.resolve([file]));+ } else {+ const entry = item.webkitGetAsEntry();+ if (entry) {+ filePromises.push(processEntry(entry));+ }+ }+ }+ }++ const fileArrays = await Promise.all(filePromises);+ return fileArrays.flat();+};++export interface UseLocalDragUploadOptions {+ /**+ * Whether the drag upload is disabled+ */+ disabled?: boolean;+ /**+ * Callback when files are dropped+ */+ onUploadFiles: (files: File[]) => void | Promise<void>;+}++export interface UseLocalDragUploadResult {+ /**+ * Props to spread on the container element+ */+ getContainerProps: () => {+ onDragOver: (e: React.DragEvent) => void;+ onDrop: (e: React.DragEvent) => void;+ };+}++/**+ * Hook for handling local (container-scoped) drag and drop file uploads.+ *+ * This hook only handles dragOver (to allow drop) and drop events.+ * The global drag state is managed by DragUploadProvider.+ *+ * IMPORTANT: We intentionally do NOT call stopPropagation() to allow+ * events to bubble up to the window where DragUploadProvider listens.+ */+export const useLocalDragUpload = (+ options: UseLocalDragUploadOptions,+): UseLocalDragUploadResult => {+ const { onUploadFiles, disabled = false } = options;++ // Only preventDefault to allow drop, do NOT stopPropagation+ const handleDragOver = useCallback(+ (e: React.DragEvent) => {+ if (disabled) return;+ if (!e.dataTransfer?.types.includes('Files')) return;++ e.preventDefault();+ // Do NOT call stopPropagation - let event bubble to Provider+ },+ [disabled],+ );++ const handleDrop = useCallback(+ async (e: React.DragEvent) => {+ if (disabled) return;+ if (!e.dataTransfer?.items || e.dataTransfer.items.length === 0) return;++ const isFile = e.dataTransfer.types.includes('Files');+ if (!isFile) return;++ e.preventDefault();+ // Do NOT call stopPropagation - let event bubble to Provider++ const items = Array.from(e.dataTransfer.items);+ const files = await getFileListFromDataTransferItems(items);++ if (files.length === 0) return;++ onUploadFiles(files);+ },+ [disabled, onUploadFiles],+ );++ const getContainerProps = useCallback(+ () => ({+ onDragOver: handleDragOver,+ onDrop: handleDrop,+ }),+ [handleDragOver, handleDrop],+ );++ return {+ getContainerProps,+ };+};diff --git a/src/components/DragUploadZone/useUploadFiles.ts b/src/components/DragUploadZone/useUploadFiles.tsnew file mode 100644index 00000000000..aa30c42f060--- /dev/null+++ b/src/components/DragUploadZone/useUploadFiles.ts@@ -0,0 +1,40 @@+import { useCallback } from 'react';++import { useModelSupportVision } from '@/hooks/useModelSupportVision';+import { useFileStore } from '@/store/file';++interface UseUploadFilesOptions {+ model?: string;+ provider?: string;+}++/**+ * Hook to handle file uploads with vision support filtering.+ * Filters out image files if the model does not support vision.+ *+ * @param options - The model and provider to check for vision support+ * @returns handleUploadFiles - Callback to handle file uploads+ */+export const useUploadFiles = (options: UseUploadFilesOptions = {}) => {+ const { model = '', provider = '' } = options;++ const canUploadImage = useModelSupportVision(model, provider);+ const uploadFiles = useFileStore((s) => s.uploadChatFiles);++ const handleUploadFiles = useCallback(+ async (files: File[]) => {+ // Filter out image files if the model does not support vision+ const filteredFiles = files.filter((file) => {+ if (canUploadImage) return true;+ return !file.type.startsWith('image');+ });++ if (filteredFiles.length > 0) {+ uploadFiles(filteredFiles);+ }+ },+ [canUploadImage, uploadFiles],+ );++ return { canUploadImage, handleUploadFiles };+};diff --git a/src/features/AgentBuilder/AgentBuilderConversation.tsx b/src/features/AgentBuilder/AgentBuilderConversation.tsxindex ee26d7541a6..4a588add02f 100644--- a/src/features/AgentBuilder/AgentBuilderConversation.tsx+++ b/src/features/AgentBuilder/AgentBuilderConversation.tsx@@ -1,8 +1,11 @@import { Flexbox } from '@lobehub/ui';import { memo } from 'react';+import DragUploadZone, { useUploadFiles } from '@/components/DragUploadZone';import type { ActionKeys } from '@/features/ChatInput';import { ChatInput, ChatList } from '@/features/Conversation';+import { useAgentStore } from '@/store/agent';+import { agentByIdSelectors } from '@/store/agent/selectors';import AgentBuilderWelcome from './AgentBuilderWelcome';import TopicSelector from './TopicSelector';@@ -17,14 +20,21 @@ const actions: ActionKeys[] = ['model'];* Displays the chat interface for configuring the agent via conversation*/const AgentBuilderConversation = memo<AgentBuilderConversationProps>(({ agentId }) => {+ // Get agent's model info for vision support check+ const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(agentId)(s));+ const provider = useAgentStore((s) => agentByIdSelectors.getAgentModelProviderById(agentId)(s));+ const { handleUploadFiles } = useUploadFiles({ model, provider });+return (- <Flexbox flex={1} height={'100%'}>- <TopicSelector agentId={agentId} />- <Flexbox flex={1} style={{ overflow: 'hidden' }}>- <ChatList welcome={<AgentBuilderWelcome />} />+ <DragUploadZone onUploadFiles={handleUploadFiles} style={{ flex: 1, height: '100%' }}>+ <Flexbox flex={1} height={'100%'}>+ <TopicSelector agentId={agentId} />+ <Flexbox flex={1} style={{ overflow: 'hidden' }}>+ <ChatList welcome={<AgentBuilderWelcome />} />+ </Flexbox>+ <ChatInput leftActions={actions} /></Flexbox>- <ChatInput leftActions={actions} />- </Flexbox>+ </DragUploadZone>);});diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/FilePreviewModal.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/FilePreviewModal.tsxnew file mode 100644index 00000000000..c5758934ad3--- /dev/null+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/FilePreviewModal.tsx@@ -0,0 +1,58 @@+'use client';++import { Modal } from '@lobehub/ui';+import { memo } from 'react';+import FileViewer from '@/features/FileViewer';+import { UploadFileItem } from '@/types/files/upload';++interface FilePreviewModalProps {+ file: UploadFileItem;+ onClose: () => void;+ open: boolean;+}++const FilePreviewModal = memo<FilePreviewModalProps>(({ file, open, onClose }) => {++ // Get the best available URL for preview+ const previewUrl = file.previewUrl || file.fileUrl || file.base64Url || '';++ return (+ <Modal+ allowFullscreen+ centered+ destroyOnHidden+ footer={null}+ height={'80vh'}+ onCancel={onClose}+ open={open}+ styles={{+ body: {+ height: '80vh',+ overflow: 'auto',+ padding: 0,+ },+ }}+ title={file.file.name}+ width={'min(90vw, 1024px)'}+ >+ <FileViewer+ chunkCount={null}+ chunkingError={null}+ createdAt={new Date()}+ embeddingError={null}+ fileType={file.file.type}+ finishEmbedding={false}+ id={file.id}+ name={file.file.name}+ size={file.file.size}+ sourceType="upload"+ updatedAt={new Date()}+ url={previewUrl}+ />+ </Modal>+ );+});++FilePreviewModal.displayName = 'FilePreviewModal';++export default FilePreviewModal;diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsxindex 103a9ceab83..eea1208b199 100644--- a/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsx+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextItem/index.tsx@@ -1,11 +1,13 @@import { Flexbox, Tag, Tooltip } from '@lobehub/ui';+import { Progress } from 'antd';import { createStyles } from 'antd-style';-import { memo } from 'react';+import { memo, useState } from 'react';import { useFileStore } from '@/store/file';-import { UploadFileItem } from '@/types/files/upload';+import { UPLOAD_STATUS_SET, UploadFileItem } from '@/types/files/upload';import Content from './Content';+import FilePreviewModal from './FilePreviewModal';import { getFileBasename } from './utils';const useStyles = createStyles(({ css, token }) => ({@@ -19,6 +21,7 @@ const useStyles = createStyles(({ css, token }) => ({}`,icon: css`+ position: relative;flex-shrink: 0;width: 18px;height: 18px;@@ -41,26 +44,58 @@ const useStyles = createStyles(({ css, token }) => ({text-overflow: ellipsis;white-space: nowrap;`,+ progress: css`+ position: absolute;+ inset: -3px;++ display: flex;+ align-items: center;+ justify-content: center;++ background: ${token.colorBgMask};+ border-radius: 4px;+ `,}));type FileItemProps = UploadFileItem;const ContextItem = memo<FileItemProps>((props) => {- const { file, id } = props;+ const { file, id, status, uploadState } = props;const { styles } = useStyles();const [removeChatUploadFile] = useFileStore((s) => [s.removeChatUploadFile]);+ const [previewOpen, setPreviewOpen] = useState(false);const basename = getFileBasename(file.name);+ const isUploading = UPLOAD_STATUS_SET.has(status);+ const progress = uploadState?.progress ?? 0;++ const handleClick = () => {+ setPreviewOpen(true);+ };return (- <Tag closable onClose={() => removeChatUploadFile(id)} size={'large'}>- <Flexbox className={styles.icon}>- <Content {...props} />- </Flexbox>- <Tooltip title={file.name}>- <span className={styles.name}>{basename}</span>- </Tooltip>- </Tag>+ <>+ <Tag closable onClick={handleClick} onClose={() => removeChatUploadFile(id)} size={'large'}>+ <Flexbox className={styles.icon}>+ <Content {...props} />+ {isUploading && (+ <div className={styles.progress}>+ <Progress+ percent={progress}+ showInfo={false}+ size={14}+ strokeWidth={2}+ type="circle"+ />+ </div>+ )}+ </Flexbox>+ <Tooltip title={file.name}>+ <span className={styles.name}>{basename}</span>+ </Tooltip>+ </Tag>+ <FilePreviewModal file={props} onClose={() => setPreviewOpen(false)} open={previewOpen} />+ </>);});diff --git a/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsx b/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsxindex 73d5ecc0d14..09d8956daa9 100644--- a/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsx+++ b/src/features/ChatInput/Desktop/ContextContainer/ContextList.tsx@@ -1,9 +1,11 @@import { Flexbox, ScrollShadow } from '@lobehub/ui';import { createStyles } from 'antd-style';-import { memo, useEffect, useRef } from 'react';+import { memo, useEffect, useMemo, useRef } from 'react';import { fileChatSelectors, useFileStore } from '@/store/file';+import { UPLOAD_STATUS_SET } from '@/types/files/upload';+import FileItem from '../FilePreview/FileItem';import { useAgentId } from '../../hooks/useAgentId';import ContextItem from './ContextItem';import SelectionItem from './SelectionItem';@@ -13,6 +15,11 @@ const useStyles = createStyles(({ css }) => ({overflow-x: scroll;width: 100%;`,+ uploadingContainer: css`+ overflow-x: auto;+ width: 100%;+ padding-block: 8px;+ `,}));const ContextList = memo(() => {@@ -38,25 +45,69 @@ const ContextList = memo(() => {(item, index, self) => index === self.findIndex((t) => t.preview === item.preview),);- if ((!inputFilesList.length || !showFileList) && !showSelectionList) return null;+ // Separate files into uploading/error and completed+ const { uploadingFiles, completedFiles } = useMemo(() => {+ const uploading = inputFilesList.filter(+ (file) => UPLOAD_STATUS_SET.has(file.status) || file.status === 'error',+ );+ const completed = inputFilesList.filter(+ (file) => !UPLOAD_STATUS_SET.has(file.status) && file.status !== 'error',+ );+ return { completedFiles: completed, uploadingFiles: uploading };+ }, [inputFilesList]);++ const hasUploadingFiles = uploadingFiles.length > 0;+ const hasCompletedFiles = completedFiles.length > 0;+ const hasSelections = showSelectionList && selectionList.length > 0;++ if (!showFileList && !showSelectionList) return null;+ if (!hasUploadingFiles && !hasCompletedFiles && !hasSelections) return null;return (- <ScrollShadow- className={styles.container}- hideScrollBar- horizontal- orientation={'horizontal'}- size={8}- >- <Flexbox gap={4} horizontal paddingInline={0} style={{ paddingBlockStart: 8 }} wrap={'wrap'}>- {selectionList.map((item) => (- <SelectionItem key={item.id} {...item} />- ))}- {inputFilesList.map((item) => (- <ContextItem key={item.id} {...item} />- ))}- </Flexbox>- </ScrollShadow>+ <Flexbox gap={0}>+ {/* Uploading/Error files - show with detailed FileItem */}+ {hasUploadingFiles && (+ <ScrollShadow+ className={styles.uploadingContainer}+ hideScrollBar+ horizontal+ orientation={'horizontal'}+ size={8}+ >+ <Flexbox gap={8} horizontal>+ {uploadingFiles.map((item) => (+ <FileItem key={item.id} {...item} />+ ))}+ </Flexbox>+ </ScrollShadow>+ )}++ {/* Completed files and selections - show with compact Tag */}+ {(hasCompletedFiles || hasSelections) && (+ <ScrollShadow+ className={styles.container}+ hideScrollBar+ horizontal+ orientation={'horizontal'}+ size={8}+ >+ <Flexbox+ gap={4}+ horizontal+ paddingInline={0}+ style={{ paddingBlockStart: 8 }}+ wrap={'wrap'}+ >+ {selectionList.map((item) => (+ <SelectionItem key={item.id} {...item} />+ ))}+ {completedFiles.map((item) => (+ <ContextItem key={item.id} {...item} />+ ))}+ </Flexbox>+ </ScrollShadow>+ )}+ </Flexbox>);});diff --git a/src/features/ChatInput/Desktop/ContextContainer/index.tsx b/src/features/ChatInput/Desktop/ContextContainer/index.tsxindex d4e9eebf866..e89c47528dd 100644--- a/src/features/ChatInput/Desktop/ContextContainer/index.tsx+++ b/src/features/ChatInput/Desktop/ContextContainer/index.tsx@@ -1,43 +1,15 @@import { Flexbox } from '@lobehub/ui';import { memo } from 'react';-import DragUpload from '@/components/DragUpload';-import { useModelSupportVision } from '@/hooks/useModelSupportVision';-import { useAgentStore } from '@/store/agent';-import { agentByIdSelectors } from '@/store/agent/selectors';-import { useFileStore } from '@/store/file';--import { useAgentId } from '../../hooks/useAgentId';import ContextList from './ContextList';/*** Contains the context item to be attached, such as file, image, text, etc.+ * Note: Drag upload is now handled by DragUploadZone in the parent Desktop component.*/const ContextContainer = memo(() => {- const agentId = useAgentId();- const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(agentId)(s));- const provider = useAgentStore((s) => agentByIdSelectors.getAgentModelProviderById(agentId)(s));-- const canUploadImage = useModelSupportVision(model, provider);-- const [uploadFiles] = useFileStore((s) => [s.uploadChatFiles]);-- const upload = async (fileList: FileList | File[] | undefined) => {- if (!fileList || fileList.length === 0) return;-- // Filter out files that are not images if the model does not support image uploads- const files = Array.from(fileList).filter((file) => {- if (canUploadImage) return true;-- return !file.type.startsWith('image');- });-- uploadFiles(files);- };-return (<Flexbox paddingInline={8}>- <DragUpload onUploadFiles={upload} /><ContextList /></Flexbox>);diff --git a/src/features/ChatInput/Desktop/FilePreview/index.tsx b/src/features/ChatInput/Desktop/FilePreview/index.tsxindex 9ec4a2d6126..3b8c39c3853 100644--- a/src/features/ChatInput/Desktop/FilePreview/index.tsx+++ b/src/features/ChatInput/Desktop/FilePreview/index.tsx@@ -1,42 +1,12 @@import { memo } from 'react';-import DragUpload from '@/components/DragUpload';-import { useModelSupportVision } from '@/hooks/useModelSupportVision';-import { useAgentStore } from '@/store/agent';-import { agentByIdSelectors } from '@/store/agent/selectors';-import { useFileStore } from '@/store/file';--import { useAgentId } from '../../hooks/useAgentId';import FileItemList from './FileList';+/**+ * Note: Drag upload is now handled by DragUploadZone in the parent Desktop component.+ */const FilePreview = memo(() => {- const agentId = useAgentId();- const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(agentId)(s));- const provider = useAgentStore((s) => agentByIdSelectors.getAgentModelProviderById(agentId)(s));-- const canUploadImage = useModelSupportVision(model, provider);-- const [uploadFiles] = useFileStore((s) => [s.uploadChatFiles]);-- const upload = async (fileList: FileList | File[] | undefined) => {- if (!fileList || fileList.length === 0) return;-- // Filter out files that are not images if the model does not support image uploads- const files = Array.from(fileList).filter((file) => {- if (canUploadImage) return true;-- return !file.type.startsWith('image');- });-- uploadFiles(files);- };-- return (- <>- <DragUpload onUploadFiles={upload} />- <FileItemList />- </>- );+ return <FileItemList />;});export default FilePreview;diff --git a/src/features/ChatInput/Mobile/FilePreview/FileItem/index.tsx b/src/features/ChatInput/Mobile/FilePreview/FileItem/index.tsxindex fee79d36378..e70a952ba3d 100644--- a/src/features/ChatInput/Mobile/FilePreview/FileItem/index.tsx+++ b/src/features/ChatInput/Mobile/FilePreview/FileItem/index.tsx@@ -20,6 +20,8 @@ const FileItem = memo<FileItemProps>((props) => {const { file, id, previewUrl, status } = props;const [removeFile] = useFileStore((s) => [s.removeChatUploadFile]);+ console.log('file', file)+if (file.type.startsWith('image')) {return (<Imagediff --git a/src/features/PageEditor/Copilot/Conversation.tsx b/src/features/PageEditor/Copilot/Conversation.tsxindex 1837f19fcd9..632fef31992 100644--- a/src/features/PageEditor/Copilot/Conversation.tsx+++ b/src/features/PageEditor/Copilot/Conversation.tsx@@ -1,9 +1,11 @@import { Flexbox } from '@lobehub/ui';import { memo, useEffect, useState } from 'react';+import DragUploadZone, { useUploadFiles } from '@/components/DragUploadZone';import type { ActionKeys } from '@/features/ChatInput';import { ChatInput, ChatList } from '@/features/Conversation';import { useAgentStore } from '@/store/agent';+import { agentByIdSelectors } from '@/store/agent/selectors';import { useChatStore } from '@/store/chat';import CopilotToolbar from './Toolbar';@@ -29,20 +31,31 @@ const Conversation = memo<ConversationProps>(({ agentId }) => {const currentAgentId = activeAgentId || agentId;+ // Get agent's model info for vision support check+ const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(currentAgentId)(s));+ const provider = useAgentStore((s) =>+ agentByIdSelectors.getAgentModelProviderById(currentAgentId)(s),+ );+ const { handleUploadFiles } = useUploadFiles({ model, provider });+return (- <Flexbox- flex={1}- height={'100%'}- onMouseEnter={() => setIsHovered(true)}- onMouseLeave={() => setIsHovered(false)}- style={{ minWidth: 300 }}+ <DragUploadZone+ onUploadFiles={handleUploadFiles}+ style={{ flex: 1, height: '100%', minWidth: 300 }}>- <CopilotToolbar agentId={currentAgentId} isHovered={isHovered} />- <Flexbox flex={1} style={{ overflow: 'hidden' }}>- <ChatList welcome={<Welcome />} />+ <Flexbox+ flex={1}+ height={'100%'}+ onMouseEnter={() => setIsHovered(true)}+ onMouseLeave={() => setIsHovered(false)}+ >+ <CopilotToolbar agentId={currentAgentId} isHovered={isHovered} />+ <Flexbox flex={1} style={{ overflow: 'hidden' }}>+ <ChatList welcome={<Welcome />} />+ </Flexbox>+ <ChatInput leftActions={actions} /></Flexbox>- <ChatInput leftActions={actions} />- </Flexbox>+ </DragUploadZone>);});diff --git a/src/layout/GlobalProvider/index.tsx b/src/layout/GlobalProvider/index.tsxindex 532e9faf3cd..be4d5bf575a 100644--- a/src/layout/GlobalProvider/index.tsx+++ b/src/layout/GlobalProvider/index.tsx@@ -2,6 +2,7 @@ import { LazyMotion, domMax } from 'motion/react';import { ReactNode, Suspense } from 'react';import { LobeAnalyticsProviderWrapper } from '@/components/Analytics/LobeAnalyticsProviderWrapper';+import { DragUploadProvider } from '@/components/DragUploadZone/DragUploadProvider';import { getServerFeatureFlagsValue } from '@/config/featureFlags';import { appEnv } from '@/envs/app';import DevPanel from '@/features/DevPanel';@@ -60,9 +61,11 @@ const GlobalLayout = async ({><QueryProvider><GroupWizardProvider>- <LazyMotion features={domMax}>- <LobeAnalyticsProviderWrapper>{children}</LobeAnalyticsProviderWrapper>- </LazyMotion>+ <DragUploadProvider>+ <LazyMotion features={domMax}>+ <LobeAnalyticsProviderWrapper>{children}</LobeAnalyticsProviderWrapper>+ </LazyMotion>+ </DragUploadProvider></GroupWizardProvider></QueryProvider><StoreInitialization />