Repository navigation
[Bug] dsh-llm-pi-ai sends non png/jpeg/gif images as-is; LM Studio rejects webp with 400 "'url' field must be a base64 encoded image." #4615
Replies: 5 comments
|
Hit the same thing on Since DSH treats everything as a plugin, I vibe a small plugin for a temporary fix to unblock LM Studio users now: |
|
你的报告与源码一致:pi-ai 出站路径没有格式白名单。packages/llm/llm-pi-ai/src/context.ts:60-70 把图片块原样转成 { data: base64, mimeType: version.mediaType } —— mediaType 直接透传附件声明的类型;整条路径里唯一的检查是 adapter.ts:359-364 的「模型是否声明 image 输入」,没有任何 png/jpeg/gif 校验。 补充一个非对称事实:入站侧(read_image 工具)只接受 PNG/JPEG/WebP/GIF(tool-fs 的稳定错误信息里写明),所以正常流进的图都是合法格式;但若有别的路径(网关/插件)塞进其他 mediaType 的图片块,出站会原样送出。修复点就在 context.ts:60-72 这段转换里加类型闸,或在上游附件准入处统一。(基于 0.1.5-rc.2 源码核对。) |
中文 (CN)状态更新(v0.2.0-rc.2,2026-10-02):上游仍未修复;下面给出已验证的补丁与端到端复现。 现状
修复补丁将 alpha 编码从 WebP 切换为 PNG(保留透明通道、所有 OpenAI 兼容视觉服务端均可解码),并在 diff --git a/@deepseek-ai/dsh-attachment-local/lib/index.js b/@deepseek-ai/dsh-attachment-local/lib/index.js
index 882005f..2b74629 100644
--- a/@deepseek-ai/dsh-attachment-local/lib/index.js
+++ b/@deepseek-ai/dsh-attachment-local/lib/index.js
@@ -63,10 +63,14 @@ const IMAGE_ENCODING_QUALITIES = [
60
];
async function encode(pipeline, mediaType, quality) {
- const { data, info } = await (mediaType === "image/webp" ? pipeline.webp({
+ // PNG is offered as an alpha codec: it preserves transparency and is decodable
+ // by every OpenAI-compatible vision server, including LM Studio, which rejects
+ // WebP input. WebP remains available to callers that explicitly request it.
+ const encoder = mediaType === "image/webp" ? pipeline.webp({
quality,
effort: 0
- }) : pipeline.jpeg({ quality })).toBuffer({ resolveWithObject: true });
+ }) : mediaType === "image/png" ? pipeline.png() : pipeline.jpeg({ quality });
+ const { data, info } = await encoder.toBuffer({ resolveWithObject: true });
return {
data: new Uint8Array(data),
mediaType,
@@ -75,14 +79,16 @@ async function encode(pipeline, mediaType, quality) {
};
}
/**
-* Build the lazy quality ladder for one prepared pipeline: WebP keeps a source
-* alpha channel, everything else is JPEG.
+* Build the lazy quality ladder for one prepared pipeline: PNG keeps a source
+* alpha channel, everything else is JPEG (PNG/JPEG stay OpenAI-compatible).
* @param prepared - sized sRGB pipeline; cloned per candidate.
* @param hasAlpha - decoded source alpha fact selecting the codec.
* @returns encoders ordered from highest to lowest ladder quality.
*/
function encodingLadder(prepared, hasAlpha) {
- const mediaType = hasAlpha ? "image/webp" : "image/jpeg";
+ // PNG for alpha (not WebP): universally decodable by OpenAI-compatible vision
+ // servers such as LM Studio, which reject WebP input. JPEG for opaque.
+ const mediaType = hasAlpha ? "image/png" : "image/jpeg";
return IMAGE_ENCODING_QUALITIES.map((quality) => (() => encode(prepared.clone(), mediaType, quality)));
}
/**
@@ -800,7 +806,12 @@ function sourcePipeline(attachment) {
}).toColourspace("srgb");
}
async function createRequestImage(attachment, target, hasAlpha) {
- if (target.width >= attachment.ref.width && target.height >= attachment.ref.height && attachment.data.byteLength <= target.maxBytes) return {
+ // Pass a stored source through only when its format is guaranteed decodable by
+ // OpenAI-compatible vision servers (PNG/JPEG). Sources stored as WebP or GIF are
+ // re-encoded to a compatible codec so the request image never rides a format the
+ // target may reject (LM Studio does not decode WebP input).
+ const passthroughSafe = attachment.ref.mediaType === "image/png" || attachment.ref.mediaType === "image/jpeg";
+ if (passthroughSafe && target.width >= attachment.ref.width && target.height >= attachment.ref.height && attachment.data.byteLength <= target.maxBytes) return {
data: attachment.data,
mediaType: attachment.ref.mediaType,
width: attachment.ref.width,
端到端验证(v0.2.0-rc.2 + 上述补丁)向本地 VLM(qwen2.5-vl-7b-instruct,OpenAI 兼容端点)同时附加 相关:模态声明侧的问题见 #5837。 English (EN)Status update (v0.2.0-rc.2, 2026-10-02): still unfixed upstream; verified patch and end-to-end repro below. Current state
Fix patchSwitch the alpha codec from WebP to PNG (preserves transparency; decodable by every OpenAI-compatible vision server), and add a passthrough guard in diff --git a/@deepseek-ai/dsh-attachment-local/lib/index.js b/@deepseek-ai/dsh-attachment-local/lib/index.js
index 882005f..2b74629 100644
--- a/@deepseek-ai/dsh-attachment-local/lib/index.js
+++ b/@deepseek-ai/dsh-attachment-local/lib/index.js
@@ -63,10 +63,14 @@ const IMAGE_ENCODING_QUALITIES = [
60
];
async function encode(pipeline, mediaType, quality) {
- const { data, info } = await (mediaType === "image/webp" ? pipeline.webp({
+ // PNG is offered as an alpha codec: it preserves transparency and is decodable
+ // by every OpenAI-compatible vision server, including LM Studio, which rejects
+ // WebP input. WebP remains available to callers that explicitly request it.
+ const encoder = mediaType === "image/webp" ? pipeline.webp({
quality,
effort: 0
- }) : pipeline.jpeg({ quality })).toBuffer({ resolveWithObject: true });
+ }) : mediaType === "image/png" ? pipeline.png() : pipeline.jpeg({ quality });
+ const { data, info } = await encoder.toBuffer({ resolveWithObject: true });
return {
data: new Uint8Array(data),
mediaType,
@@ -75,14 +79,16 @@ async function encode(pipeline, mediaType, quality) {
};
}
/**
-* Build the lazy quality ladder for one prepared pipeline: WebP keeps a source
-* alpha channel, everything else is JPEG.
+* Build the lazy quality ladder for one prepared pipeline: PNG keeps a source
+* alpha channel, everything else is JPEG (PNG/JPEG stay OpenAI-compatible).
* @param prepared - sized sRGB pipeline; cloned per candidate.
* @param hasAlpha - decoded source alpha fact selecting the codec.
* @returns encoders ordered from highest to lowest ladder quality.
*/
function encodingLadder(prepared, hasAlpha) {
- const mediaType = hasAlpha ? "image/webp" : "image/jpeg";
+ // PNG for alpha (not WebP): universally decodable by OpenAI-compatible vision
+ // servers such as LM Studio, which reject WebP input. JPEG for opaque.
+ const mediaType = hasAlpha ? "image/png" : "image/jpeg";
return IMAGE_ENCODING_QUALITIES.map((quality) => (() => encode(prepared.clone(), mediaType, quality)));
}
/**
@@ -800,7 +806,12 @@ function sourcePipeline(attachment) {
}).toColourspace("srgb");
}
async function createRequestImage(attachment, target, hasAlpha) {
- if (target.width >= attachment.ref.width && target.height >= attachment.ref.height && attachment.data.byteLength <= target.maxBytes) return {
+ // Pass a stored source through only when its format is guaranteed decodable by
+ // OpenAI-compatible vision servers (PNG/JPEG). Sources stored as WebP or GIF are
+ // re-encoded to a compatible codec so the request image never rides a format the
+ // target may reject (LM Studio does not decode WebP input).
+ const passthroughSafe = attachment.ref.mediaType === "image/png" || attachment.ref.mediaType === "image/jpeg";
+ if (passthroughSafe && target.width >= attachment.ref.width && target.height >= attachment.ref.height && attachment.data.byteLength <= target.maxBytes) return {
data: attachment.data,
mediaType: attachment.ref.mediaType,
width: attachment.ref.width,
End-to-end verification (v0.2.0-rc.2 + patch above)Attached Related: the modality-declaration side of this issue is tracked in #5837. |
|
Same failure with another OpenAI-compatible local server, still present in dsh 0.2.2-rc.1.
Direct tests against the server: JPEG and PNG up to 8.9 MB return 200. Every WebP variant (lossy and lossless, 372 bytes to 81 KB) returns 400. Workaround: instruct the agent to render and view JPEG only, so no image carries an alpha channel. A per-provider list of accepted image media types would fix this for all local servers. |
|
I'm researching how people run DeepSeek Harness on media in paid work — not selling anything. You asked for webp and images being rejected by local model backends. Two questions if you have a minute: what do you use today for that, and what would have to be true for it to be worth paying for? I'll share what I learn from everyone I ask. samora@itikia.co.ke |

Uh oh!
There was an error while loading. Please reload this page.
Summary
When a user pastes an image into the GUI,
dsh-llm-pi-aiserializes it asdata:<mimeType>;base64,<data>and sends it to the configured backend.Strict OpenAI-compatible backends (LM Studio) only accept
image/png | jpeg | gifdata URIs; webp, bmp, heic, etc. are rejected atthe protocol layer with HTTP 400
"'url' field must be a base64 encoded image.".Environment
0.1.1-rc.2llm-pi-ai,api: openai-completions, baseURL → LM Studioqwen/qwen3.8-27bwithinput: [text, image]Steps to reproduce
page screenshot — very common).
Root cause
Verified directly against the backend — the rejection is a mime whitelist
check, not a base64 validity check:
data:image/png;base64,…data:image/jpeg;base64,…data:image/gif;base64,…data:image/webp;base64,…data:image/bmp;base64,…data:image/heic;base64,…DSH correctly provides base64 bytes; the problem is only the mime type.
dsh-llm-pi-aiuserContent()pushes{ type: "image", data: <base64>, mimeType: <original> }, which pi-ai thenserializes to
data:<original>;base64,…— so any format outside the whitelistfails on every request.
Suggested fix
In the pi-ai adapter (or in
dsh-llm-pi-aiconversion), transcode imagecontent that is not
image/png|jpeg|gifto PNG before sending.sharpisalready available in the profile dependency tree (verified:
sharp(webpBuf).png().toBuffer()round-trips correctly).At minimum, document this backend limitation.
Workaround (local)
We transcode in
userContent()before pushing the image block (sharp, with abest-effort fallback that keeps original bytes); happy to PR this if useful.
All reactions