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(chat): support Antigravity images and restore image copying (#23652)

Mocha236e7c8a253e
diff --git a/apps/desktop/src/main/controllers/__tests__/heterogeneousAgentSteer.test.ts b/apps/desktop/src/main/controllers/__tests__/heterogeneousAgentSteer.test.ts
index dea6b8bfa18..8c789e4bec3 100644
--- a/apps/desktop/src/main/controllers/__tests__/heterogeneousAgentSteer.test.ts
+++ b/apps/desktop/src/main/controllers/__tests__/heterogeneousAgentSteer.test.ts
@@ -1,3 +1,6 @@
+import { mkdtemp, readFile, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
import { PassThrough } from 'node:stream';
import { AntigravityLiveInput, ClaudeCodeLiveInput } from '@lobechat/heterogeneous-agents/spawn';
@@ -75,7 +78,7 @@ describe('steerAgentSession', () => {
);
});
- it('steers a live Antigravity CLI with text and rejects image attachments', async () => {
+ it('steers a live Antigravity CLI with text and image attachments', async () => {
const stdin = new PassThrough();
const written = readLines(stdin);
const liveInput = new AntigravityLiveInput(stdin);
@@ -92,13 +95,26 @@ describe('steerAgentSession', () => {
});
expect(liveInput.takeSteerUuid()).toBe('steer-1');
- await expect(
- steerAgentSession(
- agy,
- { ...params, imageList: [{ id: 'img-1', url: 'https://example.com/a.png' }] },
- '/tmp',
- ),
- ).resolves.toEqual({ status: 'rejected' });
+ const cacheDir = await mkdtemp(path.join(tmpdir(), 'agy-desktop-steer-test-'));
+ const image = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ';
+ try {
+ await expect(
+ steerAgentSession(
+ agy,
+ {
+ ...params,
+ imageList: [{ id: 'img-1', url: `data:image/png;base64,${image}` }],
+ messageId: 'steer-image',
+ },
+ cacheDir,
+ ),
+ ).resolves.toEqual({ status: 'accepted' });
+ const filePath = JSON.parse(written[1].message.content.match(/^- (".+")$/m)![1]);
+ expect(await readFile(filePath)).toEqual(Buffer.from(image, 'base64'));
+ expect(liveInput.takeSteerUuid()).toBe('steer-image');
+ } finally {
+ await rm(cacheDir, { force: true, recursive: true });
+ }
});
it('steers a Pi run', async () => {
diff --git a/apps/desktop/src/main/controllers/heterogeneousAgentSteer.ts b/apps/desktop/src/main/controllers/heterogeneousAgentSteer.ts
index 4411b6f7701..bbfb6c8deba 100644
--- a/apps/desktop/src/main/controllers/heterogeneousAgentSteer.ts
+++ b/apps/desktop/src/main/controllers/heterogeneousAgentSteer.ts
@@ -85,9 +85,7 @@ export const steerAgentSession = async (
if (session.agentType === 'antigravity') {
const live = session.liveInput;
if (!live) return session.process ? unsupported : rejected;
- // Antigravity stream-json input accepts text only; reject image steers so
- // they fall back to the next turn instead of terminating the session.
- if (params.imageList?.length) return rejected;
+ if (!live.isOpen) return rejected;
const plan = await buildAgentInput('antigravity', promptInput, { cacheDir });
return live.send(plan.stdin, params.messageId) ? accepted : rejected;
}
diff --git a/packages/heterogeneous-agents/src/imageInput.test.ts b/packages/heterogeneous-agents/src/imageInput.test.ts
index 6fc27699298..15c7e202060 100644
--- a/packages/heterogeneous-agents/src/imageInput.test.ts
+++ b/packages/heterogeneous-agents/src/imageInput.test.ts
@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest';
import { heteroAgentSupportsImageInput } from './imageInput';
describe('heteroAgentSupportsImageInput', () => {
- it.each(['claude-code', 'codex', 'copilot', 'grok-build', 'opencode'])(
+ it.each(['antigravity', 'claude-code', 'codex', 'copilot', 'grok-build', 'opencode'])(
'accepts images for %s',
(type) => {
expect(heteroAgentSupportsImageInput(type)).toBe(true);
diff --git a/packages/heterogeneous-agents/src/imageInput.ts b/packages/heterogeneous-agents/src/imageInput.ts
index 9772f603670..7eebb32c2a6 100644
--- a/packages/heterogeneous-agents/src/imageInput.ts
+++ b/packages/heterogeneous-agents/src/imageInput.ts
@@ -10,6 +10,7 @@
*/
const IMAGE_INPUT_AGENT_TYPES = new Set<string>([
'amp',
+ 'antigravity',
'claude-code',
'codebuddy',
'codex',
diff --git a/packages/heterogeneous-agents/src/spawn/antigravity.test.ts b/packages/heterogeneous-agents/src/spawn/antigravity.test.ts
index a44e690f534..dbdaf5f7cb2 100644
--- a/packages/heterogeneous-agents/src/spawn/antigravity.test.ts
+++ b/packages/heterogeneous-agents/src/spawn/antigravity.test.ts
@@ -49,12 +49,4 @@ describe('Antigravity process input', () => {
])('rejects custom %s that breaks protocol or session ownership', (flag) => {
expect(() => buildAntigravityArgs({ extraArgs: [flag] })).toThrow('LobeHub manages');
});
-
- it('rejects image attachments instead of silently dropping them', async () => {
- await expect(
- buildAgentInput('antigravity', [
- { type: 'image', source: { type: 'path', path: '/tmp/image.png' } },
- ]),
- ).rejects.toThrow('does not support image attachments');
- });
});
diff --git a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.ts b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.ts
index 634e0488076..c26589bab64 100644
--- a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.ts
+++ b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.ts
@@ -192,6 +192,51 @@ describe('buildAgentInput', () => {
});
});
+ describe('antigravity', () => {
+ it('references every attached image in the text stream and materializes distinct bytes', async () => {
+ const header = Buffer.concat([PNG_BYTES, Buffer.alloc(64)]);
+ const images = [
+ Buffer.concat([header, Buffer.from('a')]),
+ Buffer.concat([header, Buffer.from('b')]),
+ ];
+
+ const plan = await buildAgentInput(
+ 'antigravity',
+ [
+ { text: 'Compare the two images', type: 'text' },
+ ...images.map((image) => ({
+ source: {
+ data: image.toString('base64'),
+ mediaType: 'image/png',
+ type: 'base64' as const,
+ },
+ type: 'image' as const,
+ })),
+ ],
+ { cacheDir: tmp },
+ );
+
+ const {
+ event,
+ message: { content },
+ } = JSON.parse(plan.stdin);
+ expect(event).toBe('user');
+ expect(content).toContain('Compare the two images');
+ const paths = [...content.matchAll(/^- (".+")$/gm)].map(([, value]) => JSON.parse(value));
+ expect(paths).toHaveLength(2);
+ expect(await Promise.all(paths.map((filePath) => readFile(filePath)))).toEqual(images);
+ });
+
+ it('reports a missing attachment instead of sending a prompt without the image', async () => {
+ const filePath = path.join(tmp, 'missing.png');
+ await expect(
+ buildAgentInput('antigravity', [
+ { source: { path: filePath, type: 'path' }, type: 'image' },
+ ]),
+ ).rejects.toMatchObject({ code: 'ENOENT', path: filePath });
+ });
+ });
+
describe('codex', () => {
it('puts text on stdin and emits no --image flags when there are no images', async () => {
const plan = await buildAgentInput('codex', 'just text');
diff --git a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.ts b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.ts
index dd303f6087b..f2e35b3f03d 100644
--- a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.ts
+++ b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.ts
@@ -182,6 +182,7 @@ const buildQoderInput = async (
* extra CLI args required to attach images. The single source of truth for
* how each external agent CLI receives multimodal input.
*
+ * - `antigravity`: stream-json text on stdin with local paths for the built-in image reader
* - `amp` / `claude-code` / `codebuddy`: stream-json on stdin with text + base64 image content blocks
* - `codex`: raw text on stdin + repeatable `--image <path>` flags
* - `kimi-code`: `--prompt <text>` with materialized image paths referenced in the text
@@ -201,14 +202,18 @@ export const buildAgentInput = async (
switch (agentType) {
case 'antigravity': {
- // agy's stream input currently accepts text only. Never silently discard
- // attachments or send unsupported blocks that terminate its session.
- if (blocks.some(isImageBlock)) {
- throw new Error('Antigravity CLI stream input does not support image attachments.');
- }
+ // agy rejects image blocks in stream-json, but its built-in file reader accepts images.
+ const imagePaths = await resolvePathInputImagePaths(blocks, options);
+ const attachments = imagePaths.length
+ ? [
+ 'Use your built-in image-reading tool to inspect the attached images before answering:',
+ ...imagePaths.map((imagePath) => `- ${JSON.stringify(path.resolve(imagePath))}`),
+ ].join('\n')
+ : '';
+ const content = [collectText(blocks), attachments].filter(Boolean).join('\n\n');
return {
args: [],
- stdin: `${JSON.stringify({ event: 'user', message: { content: collectText(blocks) } })}\n`,
+ stdin: `${JSON.stringify({ event: 'user', message: { content } })}\n`,
};
}
case 'amp':
diff --git a/packages/heterogeneous-agents/src/spawn/input/normalizeImage.ts b/packages/heterogeneous-agents/src/spawn/input/normalizeImage.ts
index 7c417465514..46cd227111b 100644
--- a/packages/heterogeneous-agents/src/spawn/input/normalizeImage.ts
+++ b/packages/heterogeneous-agents/src/spawn/input/normalizeImage.ts
@@ -45,7 +45,8 @@ const MEDIA_TYPE_BY_EXT: Record<string, string> = {
'.webp': 'image/webp',
};
-const sha256Hex = (input: string): string => createHash('sha256').update(input).digest('hex');
+const sha256Hex = (input: string | Buffer): string =>
+ createHash('sha256').update(input).digest('hex');
const normalizeMediaType = (raw: string | undefined | null): string => {
if (!raw) return '';
@@ -226,9 +227,7 @@ export const materializeImageToPath = async (
throw new Error(`Unsupported image media type for path materialization: ${image.mediaType}`);
}
- const key = sha256Hex(
- `${image.mediaType}:${image.buffer.length}:${image.buffer.subarray(0, 64).toString('hex')}`,
- );
+ const key = sha256Hex(image.buffer);
const filePath = path.join(cacheDir, `${key}${ext}`);
try {
diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.antigravity.test.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.antigravity.test.ts
index cd8073c8e9b..b5852d092f5 100644
--- a/packages/heterogeneous-agents/src/spawn/spawnAgent.antigravity.test.ts
+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.antigravity.test.ts
@@ -1,6 +1,9 @@
import type * as childProcess from 'node:child_process';
import { EventEmitter } from 'node:events';
+import { mkdtemp, readFile, rm } from 'node:fs/promises';
import type * as os from 'node:os';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
import { PassThrough } from 'node:stream';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -130,7 +133,9 @@ describe('spawnAgent β€” Antigravity', () => {
expect(events.some((event) => event.type === 'error')).toBe(false);
});
- it('keeps stdin open in liveInput mode and steers follow-up messages into the session', async () => {
+ it('steers a follow-up with an image without closing the live session', async ({
+ onTestFinished,
+ }) => {
const fake = createFakeProc({
stdoutChunks: [
JSON.stringify({ event: 'init', conversation_id: 'agy-live', init: {} }) + '\n',
@@ -155,7 +160,12 @@ describe('spawnAgent β€” Antigravity', () => {
}) + '\n',
JSON.stringify({
event: 'result',
- result: { conversation_id: 'agy-live', num_turns: 1, response: 'first', status: 'SUCCESS' },
+ result: {
+ conversation_id: 'agy-live',
+ num_turns: 1,
+ response: 'first',
+ status: 'SUCCESS',
+ },
}) + '\n',
JSON.stringify({
event: 'step_update',
@@ -189,22 +199,41 @@ describe('spawnAgent β€” Antigravity', () => {
});
nextFakeProc = fake.proc;
const { spawnAgent } = await import('./spawnAgent');
+ const cacheDir = await mkdtemp(path.join(tmpdir(), 'agy-steer-test-'));
+ onTestFinished(() => rm(cacheDir, { force: true, recursive: true }));
+ const image = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ', 'base64');
const handle = await spawnAgent({
agentType: 'antigravity',
+ inputOptions: { cacheDir },
liveInput: true,
operationId: 'op-agy-live',
prompt: 'initial',
});
expect(handle.sendUserMessage).toBeDefined();
- expect(handle.supportsSteerImages).toBe(false);
+ expect(handle.supportsSteerImages).not.toBe(false);
expect(fake.proc.stdin.end).not.toHaveBeenCalled();
- await expect(handle.sendUserMessage!('follow up', { uuid: 'steer-1' })).resolves.toBe(true);
- expect(JSON.parse(fake.stdinWrites[1])).toEqual({
- event: 'user',
- message: { content: 'follow up' },
- });
+ await expect(
+ handle.sendUserMessage!(
+ [
+ { text: 'follow up', type: 'text' },
+ {
+ source: { data: image.toString('base64'), mediaType: 'image/png', type: 'base64' },
+ type: 'image',
+ },
+ ],
+ { uuid: 'steer-1' },
+ ),
+ ).resolves.toBe(true);
+ const {
+ event,
+ message: { content },
+ } = JSON.parse(fake.stdinWrites[1]);
+ expect(event).toBe('user');
+ expect(content).toContain('follow up');
+ const filePath = JSON.parse(content.match(/^- (".+")$/m)![1]);
+ expect(await readFile(filePath)).toEqual(image);
fake.start();
const events = [];
diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.ts
index a819e41ca1b..723e35d9838 100644
--- a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts
+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.ts
@@ -855,8 +855,6 @@ const spawnCliAgent = async (
const plan = await buildAgentInput('antigravity', prompt, options.inputOptions);
return antigravityLive.send(plan.stdin, sendOptions?.uuid);
},
- // Antigravity stream-json input only supports text content blocks.
- supportsSteerImages: false,
}),
kill: (signal: NodeJS.Signals = 'SIGINT') => {
killedByUs = true;
diff --git a/src/features/Conversation/Messages/index.tsx b/src/features/Conversation/Messages/index.tsx
index e4eb1bcfbed..cc4ea4c3090 100644
--- a/src/features/Conversation/Messages/index.tsx
+++ b/src/features/Conversation/Messages/index.tsx
@@ -30,7 +30,7 @@ import PendingRetryTurn from './components/PendingRetryTurn';
import TextSelectionActionLayer from './components/TextSelectionActionLayer';
import CompressedGroupMessage from './CompressedGroup';
import GroupTasksMessage from './GroupTasks';
-import { getMessageInteractionState } from './messageInteraction';
+import { getMessageContextMenuAction, getMessageInteractionState } from './messageInteraction';
import TaskMessage from './Task';
import TaskCallbackMessage from './TaskCallback';
import TasksMessage from './Tasks';
@@ -115,7 +115,10 @@ const MessageItem = memo<MessageItemProps>(
const onContextMenu = useCallback(
async (event: MouseEvent<HTMLDivElement>) => {
- if (shouldSuppressContextMenu) {
+ const action = getMessageContextMenuAction(event.target, shouldSuppressContextMenu);
+ if (action === 'native') return;
+
+ if (action === 'suppress') {
event.preventDefault();
return;
}
diff --git a/src/features/Conversation/Messages/messageInteraction.test.ts b/src/features/Conversation/Messages/messageInteraction.test.ts
index 02d495c8e83..cb07f51fa85 100644
--- a/src/features/Conversation/Messages/messageInteraction.test.ts
+++ b/src/features/Conversation/Messages/messageInteraction.test.ts
@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest';
import { LOCAL_MESSAGE_SCOPE } from '@/store/chat/utils/localMessages';
-import { getMessageInteractionState } from './messageInteraction';
+import { getMessageContextMenuAction, getMessageInteractionState } from './messageInteraction';
const createMessage = (metadata?: UIChatMessage['metadata']) =>
({ id: 'message-1', metadata, role: 'user' }) as UIChatMessage;
@@ -30,3 +30,17 @@ describe('getMessageInteractionState', () => {
});
});
});
+
+describe('getMessageContextMenuAction', () => {
+ it('leaves message images to the platform menu even on a local-only message', () => {
+ const image = document.createElement('img');
+ expect(getMessageContextMenuAction(image, false)).toBe('native');
+ expect(getMessageContextMenuAction(image, true)).toBe('native');
+ });
+
+ it('keeps the usual message menu and local-only restriction for non-image targets', () => {
+ const text = document.createElement('span');
+ expect(getMessageContextMenuAction(text, false)).toBe('message');
+ expect(getMessageContextMenuAction(text, true)).toBe('suppress');
+ });
+});
diff --git a/src/features/Conversation/Messages/messageInteraction.ts b/src/features/Conversation/Messages/messageInteraction.ts
index 039a4249f2a..cd53224674a 100644
--- a/src/features/Conversation/Messages/messageInteraction.ts
+++ b/src/features/Conversation/Messages/messageInteraction.ts
@@ -13,3 +13,9 @@ export const getMessageInteractionState = (
shouldSuppressContextMenu: isLocalOnly,
};
};
+
+export const getMessageContextMenuAction = (target: EventTarget, suppress: boolean) => {
+ // Let the platform hit-test the actual image for its Copy Image command.
+ if (target instanceof HTMLImageElement) return 'native';
+ return suppress ? 'suppress' : 'message';
+};