🤯 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(kimi-code): support image attachments for Kimi Code agents (#19767)
Arvin Xu5221d0934404
diff --git a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.ts b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.tsindex 3397fdad70d..634e0488076 100644--- a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.ts+++ b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.test.ts@@ -9,17 +9,6 @@ import { buildAgentInput } from './buildAgentInput';const PNG_BYTES = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x10]);describe('buildAgentInput', () => {- it('puts Kimi Code text in argv and rejects images', async () => {- await expect(buildAgentInput('kimi-code', 'hello')).resolves.toEqual({- args: ['--prompt', 'hello'],- stdin: '',- });- await expect(- buildAgentInput('kimi-code', [- { source: { type: 'url', url: 'https://example.com/a.png' }, type: 'image' },- ]),- ).rejects.toThrow(/Kimi Code does not support image attachments/);- });let tmp: string;beforeEach(async () => {@@ -329,6 +318,56 @@ describe('buildAgentInput', () => {});});+ describe('kimi-code', () => {+ it('puts text in the --prompt argv with no stdin', async () => {+ await expect(buildAgentInput('kimi-code', 'hello')).resolves.toEqual({+ args: ['--prompt', 'hello'],+ stdin: '',+ });+ });++ it('references a path-source image in the prompt without re-materializing', async () => {+ const filePath = path.join(tmp, 'on-disk.png');+ await writeFile(filePath, PNG_BYTES);++ const plan = await buildAgentInput(+ 'kimi-code',+ [+ { text: 'what color is this?', type: 'text' },+ { source: { path: filePath, type: 'path' }, type: 'image' },+ ],+ { cacheDir: tmp },+ );++ expect(plan.stdin).toBe('');+ expect(plan.args[0]).toBe('--prompt');+ expect(plan.args[1]).toBe(+ `what color is this?\n\n[Image attached: ${filePath}] Use the ReadMediaFile tool to view this image.`,+ );+ });++ it('materializes base64 images into cacheDir and references the path in the prompt', async () => {+ const plan = await buildAgentInput(+ 'kimi-code',+ [+ {+ source: { data: PNG_BYTES.toString('base64'), mediaType: 'image/png', type: 'base64' },+ type: 'image',+ },+ ],+ { cacheDir: tmp },+ );++ expect(plan.args[0]).toBe('--prompt');+ const prompt = plan.args[1]!;+ const match = prompt.match(/^\[Image attached: (.+\.png)\]/);+ expect(match).not.toBeNull();+ expect(match![1]!.startsWith(tmp)).toBe(true);+ const written = await readFile(match![1]!);+ expect(written.equals(PNG_BYTES)).toBe(true);+ });+ });+it('throws on unknown agent types', async () => {await expect(buildAgentInput('kimi-cli', 'hi')).rejects.toThrow(/unsupported agent type/);});diff --git a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.ts b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.tsindex 62e8e0e3be8..69b6af4621d 100644--- a/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.ts+++ b/packages/heterogeneous-agents/src/spawn/input/buildAgentInput.ts@@ -140,11 +140,21 @@ const buildPiInput = async (): Promise<AgentInputPlan> => {);};-const buildKimiCodeInput = (blocks: AgentContentBlock[]): AgentInputPlan => {- if (blocks.some(isImageBlock)) {- throw new Error('Kimi Code does not support image attachments in one-shot prompt mode.');- }- return { args: ['--prompt', collectText(blocks)], stdin: '' };+const buildKimiCodeInput = async (+ blocks: AgentContentBlock[],+ options: BuildAgentInputOptions,+): Promise<AgentInputPlan> => {+ const imagePaths = await resolvePathInputImagePaths(blocks, options);+ const text = collectText(blocks);++ // One-shot `--prompt` mode has no attachment flag, but the model reads local+ // images via its builtin ReadMediaFile tool when the prompt references a path.+ const imageSection = imagePaths+ .map((p) => `[Image attached: ${p}] Use the ReadMediaFile tool to view this image.`)+ .join('\n');+ const prompt = [text, imageSection].filter(Boolean).join('\n\n');++ return { args: ['--prompt', prompt], stdin: '' };};const buildQoderInput = async (@@ -174,6 +184,7 @@ const buildQoderInput = async (** - `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* - `opencode`: raw text on stdin + repeatable `--file <path>` flags* - `pi`: raw text on stdin + repeatable `@<path>` arguments* - `qoder`: stream-json text on stdin + repeatable `--attachment <path>` flags@@ -198,7 +209,7 @@ export const buildAgentInput = async (return buildCodexInput(blocks, options);}case 'kimi-code': {- return buildKimiCodeInput(blocks);+ return buildKimiCodeInput(blocks, options);}case 'opencode': {return buildOpenCodeInput(blocks, options);diff --git a/src/hooks/useMediaUploadAbility.test.ts b/src/hooks/useMediaUploadAbility.test.tsindex b532e7e2b3e..5ea9de48660 100644--- a/src/hooks/useMediaUploadAbility.test.ts+++ b/src/hooks/useMediaUploadAbility.test.ts@@ -208,7 +208,7 @@ describe('useMediaUploadAbility', () => {expect(result.current.canUploadVideo).toBe(true);});- it('should reject image uploads for Kimi Code agents', () => {+ it('should bypass the media gate for Kimi Code agents', () => {mockedUseAgentStore.mockImplementation((selector: any) =>selector({ enableMode: false, heterogeneous: true, heterogeneousType: 'kimi-code' } as any),);@@ -216,7 +216,7 @@ describe('useMediaUploadAbility', () => {const { result } = renderHook(() => useMediaUploadAbility('model', 'provider', 'agent-1'));expect(result.current.canUploadAudio).toBe(true);- expect(result.current.canUploadImage).toBe(false);+ expect(result.current.canUploadImage).toBe(true);expect(result.current.canUploadVideo).toBe(true);});diff --git a/src/hooks/useMediaUploadAbility.ts b/src/hooks/useMediaUploadAbility.tsindex 4a4d0ba790b..f2db0f51caf 100644--- a/src/hooks/useMediaUploadAbility.ts+++ b/src/hooks/useMediaUploadAbility.ts@@ -59,12 +59,6 @@ export const useMediaUploadAbility = (model: string, provider: string, agentId?:supportToolUse,});- const heterogeneousAgentType = useAgentStore((s) =>- agentId- ? agentByIdSelectors.getAgencyConfigById(agentId)(s)?.heterogeneousProvider?.type- : undefined,- );-// In agent mode (tool calls) or heterogeneous agents (Claude Code / Codex, etc.) the agent// can parse any file via scripts/terminal, so the upload should not be gated on the model's// own multimodal ability. Mirror the store's `enforceFileTypeWhitelist` bypass in@@ -80,9 +74,7 @@ export const useMediaUploadAbility = (model: string, provider: string, agentId?:if (bypassMediaGate) {return {canUploadAudio: true,- // Kimi's one-shot `--prompt` mode has no attachment argument, and ReadMediaFile is only- // registered for vision-capable local models, which LobeHub cannot determine beforehand.- canUploadImage: heterogeneousAgentType !== 'kimi-code',+ canUploadImage: true,canUploadVideo: true,};}