Skip to content

v1.3.0 — Fix Media.Asset prototype mismatch (OpenCode 2.0.18)

Latest

Choose a tag to compare

@TheCraftyCoder TheCraftyCoder released this 26 Sep 20:14

What's fixed

Pasted images now work reliably

When attaching an image to a prompt in OpenCode, the vision bridge was failing with a \Schema validation failed\ error because injected \media\ parts failed OpenCode's internal \instanceof Me\ (Media.Asset) check. The plugin imported the same Bun bundle chunk as OpenCode, but Bun created separate module instances — meaning the two \Me\ classes were different objects and \instanceof\ always returned \ alse.

How it was fixed

The fix uses a three-tier strategy to ensure every injected media part passes OpenCode's validator:

  1. Reuse the original — When the incoming context message already contains a real \Media.Asset\ (e.g. the user's own pasted image), that object is carried through to the internal vision session unchanged. No prototype games needed.
  2. Construct via the captured host — The first real \Media.Asset\ that passes through the context hook has its prototype/constructor captured. New objects are created with
    ew hostCtor(…)\ or stamped with \Object.setPrototypeOf(media, hostProto).
  3. Plain object fallback — If neither of the above is available yet, a raw object matching the expected shape is used (same as before).

Also improved


  • ead_image\ tool now also accepts paths inside the OS temp/opencode directory, so pasted session attachments can be analysed via the tool without triggering a path-escape error.

Compatibility

Tested against OpenCode 2.0.18. Compatible with the @opencode/plugin\ 2.0.x API.