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.

✨ feat(hetero): add file/image upload to the heterogeneous agent `+` menu (#21794)

Arvin Xu442885976074
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 749019b4c6a..5b640c0b953 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -1604,7 +1604,7 @@
"input.costEstimate.tooltip": "Estimated from current context, tools, and model pricing. Actual cost may vary.",
"input.disclaimer": "Agents can make mistakes. Use your judgment for critical info.",
"input.errorMsg": "Send failed: {{errorMsg}}. Retry, or send again later.",
- "input.heteroPlus.tooltip": "Formatting and scheduling",
+ "input.heteroPlus.tooltip": "Attachments, formatting and scheduling",
"input.inputCompletionError.desc": "Input suggestions stopped after an error. Retry, or adjust the suggestion model in Settings.",
"input.inputCompletionError.retry": "Retry",
"input.inputCompletionError.settings": "Settings",
@@ -2894,6 +2894,7 @@
"upload.preview.status.processing": "Processing file...",
"upload.preview.status.success": "Upload complete",
"upload.preview.status.uploading": "Uploading file...",
+ "upload.validation.heteroImageNotSupported": "{{name}} can't read images, so {{file}} was not added. Use an agent that supports images instead.",
"upload.validation.mediaNotSupported": "The current model cannot read these media files, so they were not added: {{files}}. Switch to a model that supports them, or upload a different file type.",
"upload.validation.unsupportedFileType": "Unsupported file type: {{files}}. Supported images: JPG, PNG, GIF, WebP. Supported documents include PDF, Word, Excel, PowerPoint, Markdown, text, CSV, JSON, and code files.",
"upload.validation.videoSizeExceeded": "Video file size must not exceed {{maxSize}}. Current file size is {{actualSize}}.",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 4c5592a5868..224ca8731cf 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -1604,7 +1604,7 @@
"input.costEstimate.tooltip": "根据当前上下文、工具和模型定价估算。实际费用可能有所不同。",
"input.disclaimer": "助理也可能出错。关键信息请以你的判断为准",
"input.errorMsg": "发送遇到了问题:{{errorMsg}}。你可以重试,或稍后再发",
- "input.heteroPlus.tooltip": "格式工具与定时发送",
+ "input.heteroPlus.tooltip": "附件、格式工具与定时发送",
"input.inputCompletionError.desc": "输入补全遇到错误后已暂停。请重试,或到设置中调整补全模型。",
"input.inputCompletionError.retry": "重试",
"input.inputCompletionError.settings": "设置",
@@ -2894,6 +2894,7 @@
"upload.preview.status.processing": "文件处理中…",
"upload.preview.status.success": "上传完成",
"upload.preview.status.uploading": "正在上传文件…",
+ "upload.validation.heteroImageNotSupported": "{{name}} 无法读取图片,{{file}} 未添加。请改用支持图片的 Agent。",
"upload.validation.mediaNotSupported": "当前模型无法解析以下媒体文件,未添加:{{files}}。请切换到支持该媒体的模型,或改用其他文件类型。",
"upload.validation.unsupportedFileType": "不支持的文件类型:{{files}}。支持的图片格式:JPG、PNG、GIF、WebP。支持的文档包括PDF、Word、Excel、PowerPoint、Markdown、文本、CSV、JSON和代码文件。",
"upload.validation.videoSizeExceeded": "视频文件不能超过 {{maxSize}}。当前为 {{actualSize}}",
diff --git a/packages/heterogeneous-agents/src/imageInput.test.ts b/packages/heterogeneous-agents/src/imageInput.test.ts
new file mode 100644
index 00000000000..51a1c24c8b6
--- /dev/null
+++ b/packages/heterogeneous-agents/src/imageInput.test.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it } from 'vitest';
+
+import { heteroAgentSupportsImageInput } from './imageInput';
+
+describe('heteroAgentSupportsImageInput', () => {
+ it.each(['claude-code', 'codex', 'grok-build', 'opencode'])('accepts images for %s', (type) => {
+ expect(heteroAgentSupportsImageInput(type)).toBe(true);
+ });
+
+ it.each(['cursor', 'droid', 'devin', 'trae', 'deepseek-harness', 'openclaw', 'hermes'])(
+ 'rejects images for text-only %s',
+ (type) => {
+ expect(heteroAgentSupportsImageInput(type)).toBe(false);
+ },
+ );
+
+ it('rejects unknown or missing types', () => {
+ expect(heteroAgentSupportsImageInput('some-new-agent')).toBe(false);
+ expect(heteroAgentSupportsImageInput(undefined)).toBe(false);
+ });
+});
diff --git a/packages/heterogeneous-agents/src/imageInput.ts b/packages/heterogeneous-agents/src/imageInput.ts
new file mode 100644
index 00000000000..b4d2cad0c9f
--- /dev/null
+++ b/packages/heterogeneous-agents/src/imageInput.ts
@@ -0,0 +1,24 @@
+/**
+ * Agent types whose input builder turns image blocks into something the CLI
+ * reads (stream-json base64, `--image`, `--file`, ACP image parts, …). See
+ * `spawn/input/buildAgentInput.ts` and `spawn/grokAcpSession.ts`.
+ *
+ * Everything else is text-only: Cursor, Droid, Devin and TRAE throw on image
+ * blocks, DeepSeek Harness sends only the prompt text, and remote-task agents
+ * (OpenClaw, Hermes) have no image path. Unknown types default to unsupported,
+ * so a new adapter has to opt in here once it serialises images.
+ */
+const IMAGE_INPUT_AGENT_TYPES = new Set<string>([
+ 'amp',
+ 'claude-code',
+ 'codebuddy',
+ 'codex',
+ 'grok-build',
+ 'kimi-code',
+ 'opencode',
+ 'pi',
+ 'qoder',
+]);
+
+export const heteroAgentSupportsImageInput = (type?: string | null): boolean =>
+ !!type && IMAGE_INPUT_AGENT_TYPES.has(type);
diff --git a/packages/heterogeneous-agents/src/index.ts b/packages/heterogeneous-agents/src/index.ts
index 5a665ed0143..535bc69a9e4 100644
--- a/packages/heterogeneous-agents/src/index.ts
+++ b/packages/heterogeneous-agents/src/index.ts
@@ -74,6 +74,7 @@ export {
HETERO_ERROR_SPECS,
isUserSideHeteroError,
} from './errors';
+export { heteroAgentSupportsImageInput } from './imageInput';
export { getHeterogeneousTypeLabel, HETEROGENEOUS_TYPE_LABELS } from './labels';
export type {
CreateAssistantIntent,
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 7a601f0e736..49fe02082d8 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -973,7 +973,7 @@ export default {
'The current model is no longer available. Choose another model to continue.',
'input.viewOnlyAgent': 'You can only view this agent',
'input.viewOnlyGroup': 'You can only view this group',
- 'input.heteroPlus.tooltip': 'Formatting and scheduling',
+ 'input.heteroPlus.tooltip': 'Attachments, formatting and scheduling',
'input.more': 'More',
'input.notice.summary_one': '{{count}} input notice',
'input.notice.summary_other': '{{count}} input notices',
@@ -3317,6 +3317,8 @@ export default {
'upload.preview.status.processing': 'Processing file...',
'upload.preview.status.success': 'Upload complete',
'upload.preview.status.uploading': 'Uploading file...',
+ 'upload.validation.heteroImageNotSupported':
+ "{{name}} can't read images, so {{file}} was not added. Use an agent that supports images instead.",
'upload.validation.mediaNotSupported':
'The current model cannot read these media files, so they were not added: {{files}}. Switch to a model that supports them, or upload a different file type.',
'upload.validation.unsupportedFileType':
diff --git a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/HeteroPlus.tsx b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/HeteroPlus.tsx
index 807484f23fa..7665beec4e1 100644
--- a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/HeteroPlus.tsx
+++ b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/HeteroPlus.tsx
@@ -1,11 +1,13 @@
'use client';
-import { cssVar, Icon } from '@lobehub/ui';
+import { cssVar, Icon, Upload } from '@lobehub/ui';
+import * as stylex from '@stylexjs/stylex';
import dayjs from 'dayjs';
import {
CalendarClockIcon,
CheckIcon,
ChevronRight,
+ FileUp,
PlusIcon,
TargetIcon,
TypeIcon,
@@ -22,21 +24,41 @@ import { useUserStore } from '@/store/user';
import { labPreferSelectors } from '@/store/user/selectors';
import { OFFSETS_IN_HOURS, resolveScheduleTime } from './scheduleTime';
+import { useHeteroUpload } from './useHeteroUpload';
+
+const styles = stylex.create({
+ // Stretch the Upload trigger over the whole menu row, so clicking anywhere on
+ // it opens the file picker — same as the agent Plus.
+ hotArea: {
+ '::before': {
+ backgroundColor: 'transparent',
+ content: "''",
+ insetBlock: 0,
+ insetInline: 0,
+ position: 'absolute',
+ },
+ },
+});
/**
* The hetero action bar's `+` menu.
*
* Mirrors the agent composer's Plus, but carries only what a heterogeneous run
- * actually has: the formatting-toolbar toggle and "Send later". The agent Plus
- * is not reused — most of it (attachments, web search, skills, gateway mode) has
- * no meaning for a CLI agent, and a menu of mostly-inapplicable rows is worse
- * than a small one.
+ * actually has: file/image upload, the formatting-toolbar toggle and "Send
+ * later". The agent Plus is not reused — most of it (web search, skills,
+ * knowledge base, gateway mode) has no meaning for a CLI agent, and a menu of
+ * mostly-inapplicable rows is worse than a small one.
*
* Picking a time here only *arms* the send (`scheduledSendAt`); it creates
* nothing. The send button remains the single commit action, and the armed state
* is shown next to it by `ScheduledSendChip`.
*/
-const HeteroPlus = memo(() => {
+interface HeteroPlusProps {
+ /** The agent's CLI adapter type — decides whether picked images are accepted. */
+ providerType?: string;
+}
+
+const HeteroPlus = memo<HeteroPlusProps>(({ providerType }) => {
const { t } = useTranslation('chat');
const { t: tEditor } = useTranslation('editor');
const [open, setOpen] = useState(false);
@@ -51,6 +73,9 @@ const HeteroPlus = memo(() => {
const setScheduledSendAt = useConversationStore((s) => s.setScheduledSendAt);
const enableGoals = useUserStore(labPreferSelectors.enableGoals);
+ const closeMenu = useCallback(() => setOpen(false), []);
+ const { beforeUpload, onFiles } = useHeteroUpload(providerType, closeMenu);
+
const armSchedule = useCallback(
(hours: number) => {
setScheduledSendAt(resolveScheduleTime(hours).toISOString());
@@ -69,6 +94,17 @@ const HeteroPlus = memo(() => {
: undefined;
return [
+ {
+ closeOnClick: false,
+ icon: FileUp,
+ key: 'upload-file-or-image',
+ label: (
+ <Upload multiple beforeUpload={beforeUpload} onFiles={onFiles}>
+ <div {...stylex.props(styles.hotArea)}>{t('upload.action.fileOrImageUpload')}</div>
+ </Upload>
+ ),
+ },
+ { type: 'divider' },
{
children: OFFSETS_IN_HOURS.map((hours) => ({
extra:
@@ -117,15 +153,26 @@ const HeteroPlus = memo(() => {
] as ActionDropdownMenuItems)
: []),
];
- }, [t, tEditor, showTypoBar, setShowTypoBar, armSchedule, scheduledSendAt, enableGoals, editor]);
+ }, [
+ t,
+ tEditor,
+ showTypoBar,
+ setShowTypoBar,
+ armSchedule,
+ scheduledSendAt,
+ enableGoals,
+ editor,
+ beforeUpload,
+ onFiles,
+ ]);
return (
<ChatInputAction
icon={PlusIcon}
open={open}
size={{ blockSize: 32, borderRadius: 16, size: 18 }}
- // Not the agent Plus's tooltip — it promises files / skills / context, none
- // of which this menu has.
+ // Not the agent Plus's tooltip — it promises skills / context, which this
+ // menu does not have.
title={t('input.heteroPlus.tooltip')}
tooltipProps={{ placement: 'top' }}
dropdown={{
diff --git a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/index.tsx b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/index.tsx
index b7c39282bb7..78cb2f32221 100644
--- a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/index.tsx
+++ b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/index.tsx
@@ -33,7 +33,7 @@ import { shouldShowHeteroModelSelector } from './shouldShowHeteroModelSelector';
// Heterogeneous agents (e.g. Claude Code) bring their own toolchain and memory,
// so most LobeHub-side pickers don't apply — no built-in left action fits, and
// the bar is composed entirely from `extraActionItems`: a hetero-only `+` menu
-// (formatting toolbar + "Send later"), then the CLI model + thinking-effort
+// (uploads, formatting toolbar, "Send later"), then the CLI model + thinking-effort
// selector. Both sit in the input's bottom-left corner, where the agent composer
// puts its `+` and model picker, rather than off in the control-bar strip below.
const leftActions: ActionKeys[] = [];
@@ -77,8 +77,8 @@ GuardBanner.displayName = 'GuardBanner';
* HeterogeneousChatInput
*
* Simplified ChatInput for heterogeneous agents (Claude Code, etc.).
- * Keeps only: text input, typo toggle, send button, and a working-directory
- * picker — no model/tools/memory/KB/MCP/runtime-mode/upload.
+ * Keeps only: text input, attachments, typo toggle, send button, and a
+ * working-directory picker — no model/tools/memory/KB/MCP/runtime-mode.
*
* In cloud (web) mode, shows a configuration prompt and disables the input
* until the user sets up their cloud credentials in agent profile.
@@ -152,10 +152,14 @@ const HeterogeneousChatInput = memo(() => {
// state and the control that produced it read as one unit.
const extraActionItems = useMemo<ChatInputActionsProps['items']>(
() => [
- { alwaysDisplay: true, children: <HeteroPlus />, key: 'heteroPlus' },
+ {
+ alwaysDisplay: true,
+ children: <HeteroPlus providerType={providerType} />,
+ key: 'heteroPlus',
+ },
{ alwaysDisplay: true, children: <ScheduledSendChip />, key: 'scheduledSendChip' },
],
- [],
+ [providerType],
);
// The model selector rides in the send-area prefix rather than the
diff --git a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/useHeteroUpload.test.ts b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/useHeteroUpload.test.ts
new file mode 100644
index 00000000000..fa404b94fc2
--- /dev/null
+++ b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/useHeteroUpload.test.ts
@@ -0,0 +1,93 @@
+import { act, renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { useHeteroUpload } from './useHeteroUpload';
+
+const mocks = vi.hoisted(() => ({
+ editor: { focus: vi.fn() },
+ routeLargeFiles: vi.fn((files: File[]) => files),
+ toastError: vi.fn(),
+ upload: vi.fn(),
+ validateVideoFileSize: vi.fn(() => ({ isValid: true }) as Record<string, unknown>),
+}));
+
+vi.mock('@lobechat/utils/client', () => ({
+ validateVideoFileSize: mocks.validateVideoFileSize,
+}));
+
+vi.mock('@lobehub/ui', () => ({ toast: { error: mocks.toastError } }));
+
+vi.mock('@/features/ChatInput/hooks/useAgentId', () => ({ useAgentId: () => 'agt_hetero' }));
+
+vi.mock('@/features/ChatInput/hooks/useLargeFileLocalPath', () => ({
+ useLargeFileLocalPath: () => mocks.routeLargeFiles,
+}));
+
+vi.mock('@/features/ChatInput/store', () => ({
+ useChatInputStore: (selector: (s: any) => unknown) => selector({ editor: mocks.editor }),
+}));
+
+vi.mock('@/store/file', () => ({
+ useFileStore: (selector: (s: any) => unknown) => selector({ uploadChatFiles: mocks.upload }),
+}));
+
+describe('useHeteroUpload', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it('uploads picked files to the chat upload list for the hetero agent', async () => {
+ const onPicked = vi.fn();
+ const { result } = renderHook(() => useHeteroUpload('claude-code', onPicked));
+ const files = [new File(['x'], 'shot.png', { type: 'image/png' })];
+
+ await act(() => result.current.onFiles(files));
+
+ expect(onPicked).toHaveBeenCalled();
+ expect(mocks.editor.focus).toHaveBeenCalled();
+ expect(mocks.routeLargeFiles).toHaveBeenCalledWith(files);
+ expect(mocks.upload).toHaveBeenCalledWith(files, 'agt_hetero');
+ });
+
+ it('skips the upload when every picked file became a local-path reference', async () => {
+ mocks.routeLargeFiles.mockReturnValueOnce([]);
+ const { result } = renderHook(() => useHeteroUpload('claude-code', vi.fn()));
+
+ await act(() => result.current.onFiles([new File(['x'], 'big.csv', { type: 'text/csv' })]));
+
+ expect(mocks.upload).not.toHaveBeenCalled();
+ });
+
+ it('rejects images for a text-only adapter with a toast', () => {
+ const { result } = renderHook(() => useHeteroUpload('cursor', vi.fn()));
+
+ expect(result.current.beforeUpload(new File(['x'], 'a.png', { type: 'image/png' }))).toBe(
+ false,
+ );
+ expect(mocks.toastError).toHaveBeenCalled();
+ // Non-image files still go through as download links.
+ expect(result.current.beforeUpload(new File(['x'], 'a.txt', { type: 'text/plain' }))).toBe(
+ true,
+ );
+ });
+
+ it('accepts images for an adapter that reads them', () => {
+ const { result } = renderHook(() => useHeteroUpload('claude-code', vi.fn()));
+
+ expect(result.current.beforeUpload(new File(['x'], 'a.png', { type: 'image/png' }))).toBe(true);
+ });
+
+ it('rejects an oversized video with a toast', () => {
+ mocks.validateVideoFileSize.mockReturnValueOnce({
+ actualSize: '30 MB',
+ isValid: false,
+ maxSize: '20 MB',
+ });
+ const { result } = renderHook(() => useHeteroUpload('claude-code', vi.fn()));
+
+ expect(result.current.beforeUpload(new File(['x'], 'a.mp4', { type: 'video/mp4' }))).toBe(
+ false,
+ );
+ expect(mocks.toastError).toHaveBeenCalled();
+ });
+});
diff --git a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/useHeteroUpload.ts b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/useHeteroUpload.ts
new file mode 100644
index 00000000000..a2f8268390c
--- /dev/null
+++ b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/useHeteroUpload.ts
@@ -0,0 +1,71 @@
+'use client';
+
+import {
+ getHeterogeneousTypeLabel,
+ heteroAgentSupportsImageInput,
+} from '@lobechat/heterogeneous-agents';
+import { validateVideoFileSize } from '@lobechat/utils/client';
+import { toast } from '@lobehub/ui';
+import { useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useAgentId } from '@/features/ChatInput/hooks/useAgentId';
+import { useLargeFileLocalPath } from '@/features/ChatInput/hooks/useLargeFileLocalPath';
+import { useChatInputStore } from '@/features/ChatInput/store';
+import { useFileStore } from '@/store/file';
+
+/**
+ * File/image picking for the hetero `+` menu.
+ *
+ * Uploads land in the same chat upload list as the agent composer; the hetero
+ * send path forwards images as content blocks and other files as download links
+ * in the prompt. The gate is the adapter, not a LobeHub model: text-only CLIs
+ * (e.g. Cursor) fail the whole run on an image block, so images are refused at
+ * pick time for them.
+ */
+export const useHeteroUpload = (providerType: string | undefined, onPicked: () => void) => {
+ const { t } = useTranslation('chat');
+ const agentId = useAgentId();
+ const editor = useChatInputStore((s) => s.editor);
+ const upload = useFileStore((s) => s.uploadChatFiles);
+ // On desktop, big non-media files become local-path tags the CLI reads in place.
+ const routeLargeFilesToLocalPaths = useLargeFileLocalPath(agentId, editor);
+
+ const beforeUpload = useCallback(
+ (file: File) => {
+ if (file.type.startsWith('image') && !heteroAgentSupportsImageInput(providerType)) {
+ toast.error(
+ t('upload.validation.heteroImageNotSupported', {
+ file: file.name,
+ name: getHeterogeneousTypeLabel(providerType),
+ }),
+ );
+ return false;
+ }
+
+ const validation = validateVideoFileSize(file);
+ if (validation.isValid) return true;
+
+ toast.error(
+ t('upload.validation.videoSizeExceeded', {
+ actualSize: validation.actualSize,
+ maxSize: validation.maxSize,
+ }),
+ );
+ return false;
+ },
+ [providerType, t],
+ );
+
+ const onFiles = useCallback(
+ async (files: File[]) => {
+ onPicked();
+ editor?.focus();
+ const filesToUpload = routeLargeFilesToLocalPaths(files);
+ if (filesToUpload.length > 0) await upload(filesToUpload, agentId);
+ },
+ [onPicked, editor, routeLargeFilesToLocalPaths, upload, agentId],
+ );
+
+ return { beforeUpload, onFiles };
+};