Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/image-format-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Guard against unsupported image formats to prevent crashes when processing WebP/GIF images.
16 changes: 16 additions & 0 deletions packages/agent-core/src/tools/builtin/file/read-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ export class ReadMediaFileTool implements BuiltinTool<ReadMediaFileInput> {
'Tell the user to use a model with image input capability.',
};
}
// Guard against image formats the model endpoint may reject.
// Some providers (e.g. kimi-for-coding) accept PNG/JPEG but reject
// WebP/GIF, causing a 400 that bricks the session because the failed
// image stays in history and is re-sent on every turn.
if (fileType.kind === 'image' && (fileType.mimeType === 'image/webp' || fileType.mimeType === 'image/gif')) {
const supported = this.capabilities.supportedImageMimes ?? ['image/png', 'image/jpeg'];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the MIME capability field before reading it

In the current @moonshot-ai/kosong contract, ModelCapability has no supportedImageMimes field, so this new access makes the package fail typechecking (Property 'supportedImageMimes' does not exist on type 'ModelCapability'). If the field is intended, it needs to be added to the shared capability type and populated by the capability providers; otherwise this guard cannot compile and release builds for agent-core are blocked.

Useful? React with 👍 / 👎.

if (!supported.includes(fileType.mimeType)) {
return {
isError: true,
output:
`The current model does not support ${fileType.mimeType} images. ` +
'Supported formats: ' + supported.join(', ') + '. ' +
'Convert the image to PNG or JPEG before reading it.',
};
}
}
if (fileType.kind === 'video' && !this.capabilities.video_in) {
return {
isError: true,
Expand Down