Skip to content

🤯 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.

🐛 fix: slove input editor on pause emit (#11051)

Shinji-Lid102d47577aa
diff --git a/packages/builtin-tool-gtd/package.json b/packages/builtin-tool-gtd/package.json
index c49ddcf4f42..70ff28b08cf 100644
--- a/packages/builtin-tool-gtd/package.json
+++ b/packages/builtin-tool-gtd/package.json
@@ -13,11 +13,11 @@
},
"devDependencies": {
"@lobechat/types": "workspace:*",
- "@lobehub/editor": "^1",
+ "@lobehub/editor": "^3",
"@lobehub/ui": "^4.3.1"
},
"peerDependencies": {
- "@lobehub/editor": "^1",
+ "@lobehub/editor": "^3",
"@lobehub/ui": "^4",
"antd": "^6",
"antd-style": "*",
diff --git a/src/components/DragUploadZone/index.tsx b/src/components/DragUploadZone/index.tsx
index 0723eaee8d4..c114173d1dd 100644
--- a/src/components/DragUploadZone/index.tsx
+++ b/src/components/DragUploadZone/index.tsx
@@ -182,5 +182,6 @@ const DragUploadZone = memo<DragUploadZoneProps>(
DragUploadZone.displayName = 'DragUploadZone';
+export { usePasteFile } from './usePasteFile';
export { useUploadFiles } from './useUploadFiles';
export default DragUploadZone;
diff --git a/src/components/DragUploadZone/usePasteFile.ts b/src/components/DragUploadZone/usePasteFile.ts
new file mode 100644
index 00000000000..872f8d93351
--- /dev/null
+++ b/src/components/DragUploadZone/usePasteFile.ts
@@ -0,0 +1,40 @@
+import { type IEditor } from '@lobehub/editor';
+import { useCallback, useEffect } from 'react';
+
+import { getFileListFromDataTransferItems } from './useLocalDragUpload';
+
+/**
+ * Hook for handling paste file uploads via @lobehub/editor.
+ * Listens to editor's onPaste event and extracts files from clipboard.
+ *
+ * @param editor - The editor instance from @lobehub/editor
+ * @param onUploadFiles - Callback when files are pasted
+ */
+export const usePasteFile = (
+ editor: IEditor | undefined,
+ onUploadFiles: (files: File[]) => void | Promise<void>,
+) => {
+ const handlePaste = useCallback(
+ async (event: ClipboardEvent) => {
+ if (!event.clipboardData) return;
+
+ const items = Array.from(event.clipboardData.items);
+ const files = await getFileListFromDataTransferItems(items);
+
+ if (files.length === 0) return;
+
+ onUploadFiles(files);
+ },
+ [onUploadFiles],
+ );
+
+ useEffect(() => {
+ if (!editor) return;
+
+ editor.on('onPaste', handlePaste);
+
+ return () => {
+ editor.off('onPaste', handlePaste);
+ };
+ }, [editor, handlePaste]);
+};
diff --git a/src/features/ChatInput/InputEditor/index.tsx b/src/features/ChatInput/InputEditor/index.tsx
index ff6dab70b6e..960091511a5 100644
--- a/src/features/ChatInput/InputEditor/index.tsx
+++ b/src/features/ChatInput/InputEditor/index.tsx
@@ -20,9 +20,13 @@ import { memo, useEffect, useMemo, useRef } from 'react';
import { useHotkeysContext } from 'react-hotkeys-hook';
import { useTranslation } from 'react-i18next';
+import { usePasteFile, useUploadFiles } from '@/components/DragUploadZone';
+import { useAgentStore } from '@/store/agent';
+import { agentByIdSelectors } from '@/store/agent/selectors';
import { useUserStore } from '@/store/user';
import { labPreferSelectors, preferenceSelectors, settingsSelectors } from '@/store/user/selectors';
+import { useAgentId } from '../hooks/useAgentId';
import { useChatInputStore, useStoreApi } from '../store';
import Placeholder from './Placeholder';
@@ -55,6 +59,15 @@ const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {
const enableMention = !!mentionItems && mentionItems.length > 0;
+ // Get agent's model info for vision support check and handle paste upload
+ const agentId = useAgentId();
+ const model = useAgentStore((s) => agentByIdSelectors.getAgentModelById(agentId)(s));
+ const provider = useAgentStore((s) => agentByIdSelectors.getAgentModelProviderById(agentId)(s));
+ const { handleUploadFiles } = useUploadFiles({ model, provider });
+
+ // Listen to editor's paste event for file uploads
+ usePasteFile(editor, handleUploadFiles);
+
useEffect(() => {
const fn = (e: BeforeUnloadEvent) => {
if (!state.isEmpty) {