dsh-image-formats: Enable AVIF/TIFF/SVG Support in DSH

Introduction

DeepSeek Harness (DSH) native read_image and the input box only support PNG, JPEG, WebP, and GIF. When you paste or drag in formats like AVIF, they are rejected before upload; read_image also rejects these formats based on extension or byte sniffing. This adds extra steps for developers who need to handle non-native formats.

dsh-image-formats is a DSH plugin that adds AVIF/TIFF/SVG support to read_image and the input box: it automatically converts them to PNG when needed, then hands them off to the existing attachment and upload pipeline. It does not modify app.asar nor introduce new runtime dependencies; on the host side it reuses the Sharp/libvips bundled with DSH Desktop, and on the client side it reuses the browser’s built-in decoders and canvas.

How It Works

The plugin does half the work on the host side and half on the client side.

Host Side: Shadowing the read_image Tool

When an agent is created, the plugin registers a same-named read_image tool scoped per agent via agent.ctx.tools.register. The model still sees the familiar single read_image tool, but its implementation is replaced by this plugin. The execution order matches the official tool:

  1. Validate file_path and classify by extension;
  2. Check the deployment’s attachment whitelist and whether the call route declares image input;
  3. Resolve and read the file via ctx.fs, with the byte cap set to the smaller of maxImageBytes and maxMessageImageBytes;
  4. Native formats (PNG/JPEG/WebP/GIF) are saved as-is; AVIF/TIFF/SVG are first converted to PNG via Sharp;
  5. Call attachments.saveImage, returning the same { path, image } shape as the official tool, and emit fs/observed.

Conversion parameters:
- Input limit limitInputPixels: 268435456, failOn: 'none', only the first frame is taken;
- SVG is rendered with density: 144; other formats are auto-rotated according to EXIF orientation;
- Output PNG uses compressionLevel: 9; the filename changes from photo.avif to photo.png.

Sharp candidate paths are tried in this order:
- The DSH_IMAGE_FORMATS_SHARP environment variable;
- app.asar/dsh/node_modules/sharp and app.asar/node_modules/sharp under process.resourcesPath;
- resources/... at the same level as the executable;
- <DSH_HOME>/profiles/<profile>/node_modules/sharp (current profile first, then other profiles; ~/.dsh is used if DSH_HOME is not set);
- Finally, the regular sharp package.

If Sharp cannot be found, a diagnosable IMAGE_CONVERTER_UNAVAILABLE error is thrown; it will not fall back to “guessing a format.”

Client Side: Replacing Files Before They Enter the Composer

The client plugin listens for paste, drop, and change events during the capture phase of the document:

  1. Only AVIF files are picked up (MIME type image/avif, or extension .avif with no other declared type);
  2. Decoded via createImageBitmap, with a fallback to <img> + object URL on failure;
  3. Drawn to a canvas with the long edge capped at 2048, encoded with canvas.toBlob('image/png'); if the result exceeds 6 MB, it is progressively scaled down to 1024 and retried;
  4. The PNG is passed to the host’s public slot conversation.input.attachments via onAddFiles (owner props), and the official intakeFiles handles the original upload pipeline; only when the host does not have this slot does it fall back to the legacy DOM path—writing into the hidden input[type=file][hidden] inside the composer via DataTransfer and dispatching a bubbling change event.

This slot is single-slot: registering into it shadows the host’s built-in attachment bar, which has no public rebuild entry point. So the bridge component only mounts when the slot is empty, and immediately unregisters if another registrant appears, reverting to the DOM backfill. If the slot service becomes available after the plugin is ready, the plugin waits for internal/service and re-mounts.

This way the official InputBar’s onPickFiles / intakeFiles handle the PNG through the original path, and the plugin does not need to call any private upload functions. Conversion is done in memory—no temp files, no network requests. If the clipboard also carries non-empty text/plain during a paste, the plugin yields to the native logic to avoid swallowing the text.

Installation & Activation

Requirements:
- DSH 0.2.1-rc.5 or later, and earlier than 0.3.0;
- Node.js 20 or later (the plugin itself adds no dependencies; the DSH CLI requires Sharp to be available in some profile or environment—bundled with the Desktop edition).

Install from npm (after publication):

In the sidebar go to Plugins → Install Plugin, and enter:

dsh-image-formats

Or:

dsh plugin --profile desktop add dsh-image-formats

Install from GitHub:

https://github.com/TLEWA/dsh-image-formats

Pin to a tag:

dsh plugin --profile desktop add github:TLEWA/dsh-image-formats#v0.1.0

Install from source:

git clone https://github.com/TLEWA/dsh-image-formats.git
cd dsh-image-formats
npm test
dsh plugin --profile desktop add .

After installation, restart DSH: host-side plugins are loaded when the profile starts, and client-side plugins take effect after the Web UI is refreshed.

Compatibility & Limitations

  • HEIC/HEIF is not supported: the Sharp/libvips bundled with DSH Desktop lacks a HEVC decoder (requires libde265), so even if you convert to HEIC it still cannot be read. The plugin explicitly reports HEIC/HEIF (HEVC) and suggests converting to AVIF/PNG/JPEG/WebP first;
  • JPEG XL, PSD, and camera RAW are not supported: Sharp has no decoders for these;
  • The client only auto-converts AVIF. Browsers have no stable TIFF decoder, and SVG via canvas involves cross-origin/security boundaries, so dragging TIFF/SVG files is still rejected by the official upload pipeline; reading them via read_image by path is unaffected;
  • The client prefers the host’s public slot conversation.input.attachments; when that slot is occupied (which is the case with DSH’s default installation), it falls back to the composer’s hidden file input and the data-composer-card marker. If DSH changes the structure of either of these in a future release, the plugin will need to be updated accordingly;
  • Conversion only preserves the first frame: animated AVIF or multi-page TIFF content will not be carried over;
  • Conversion re-encodes: EXIF, ICC/HDR, 10-bit information may be lost or altered, and the PNG file size may be larger than the original AVIF;
  • The original file is never modified; what is added to the session is a PNG attachment;
  • The host’s image capability gate is identical to the official one: the call route must declare image input, otherwise it reports IMAGE_UNSUPPORTED_MODEL first without reading the file in vain. In 0.2.3-alpha.1 the error code for the same semantics was renamed to MODEL_DOES_NOT_SUPPORT_IMAGES; the plugin recognizes both spellings via IMAGE_MODEL_UNSUPPORTED_CODES and isImageModelUnsupportedCode(), still reporting IMAGE_UNSUPPORTED_MODEL externally, and passing through other error codes as-is;
  • The first conversion reads the entire image into memory; very large images are subject to DSH’s attachment byte cap.

Summary

dsh-image-formats enables DSH’s read_image and the input box to automatically convert AVIF/TIFF/SVG to PNG, so the model can read images without any extra steps. By shadowing the read_image tool on the host side and intercepting files before they enter the composer on the client side, it extends native format support without modifying app.asar or adding runtime dependencies. It is ideal for developers who need to handle these non-native image formats. Source code and further details: https://github.com/TLEWA/dsh-image-formats

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye