opencode-see-image 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +24 -23
  2. package/index.ts +20 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,6 +6,14 @@ When a user attaches a screenshot to a text-only model, opencode rejects it with
6
6
 
7
7
  ## Install
8
8
 
9
+ **Option A, one command (recommended):**
10
+ ```bash
11
+ opencode plugin opencode-see-image --global
12
+ ```
13
+ This installs the package and adds it to your config. Then restart opencode.
14
+
15
+ **Option B, edit config manually:**
16
+
9
17
  Add the plugin to your opencode config:
10
18
 
11
19
  ```jsonc
@@ -17,20 +25,13 @@ Add the plugin to your opencode config:
17
25
  ```
18
26
  Then restart opencode.
19
27
 
28
+ ## Install via your agent
20
29
 
21
- ## Install via your agent (copy-paste this)
22
-
23
- Paste this prompt to your opencode agent, and it'll install the plugin for you.
24
-
30
+ Ask your agent:
25
31
  ```
26
- Install the opencode-see-image plugin so I can send you screenshots. Do this:
27
-
28
- 1. Edit ~/.config/opencode/opencode.jsonc (create it if missing). Preserve any existing fields and the $schema. Add "opencode-see-image" to the "plugin" array. If "plugin" doesn't exist, add it as ["opencode-see-image"].
29
- 2. Check that a vision-capable provider is connected by looking for ~/.local/share/opencode/auth.json with either an "opencode-go" entry (paid, fast) OR an "opencode" entry (free). If neither is present, tell me to run /connect and select either opencode-go or opencode (key from opencode.ai/auth).
30
- 3. Tell me to quit and restart opencode for the plugin to load.
31
-
32
- After I restart and attach a screenshot, you should call the see_image tool to view it.
32
+ install the opencode-see-image plugin
33
33
  ```
34
+ It'll run `opencode plugin opencode-see-image --global` and tell you to restart.
34
35
 
35
36
  ## Prerequisites
36
37
 
@@ -71,7 +72,7 @@ plugin's system-prompt instructions tell the model to call see_image
71
72
  see_image tool:
72
73
  1. locates the file (macOS screenshot temp dirs, ~/Desktop, ~/Downloads, cwd)
73
74
  2. base64-encodes it
74
- 3. sends it to the vision model via the Anthropic Messages API
75
+ 3. routes it to the vision model via opencode's SDK (or direct HTTP if SEE_IMAGE_API_KEY is set)
75
76
  4. returns the textual description
76
77
 
77
78
 
@@ -91,16 +92,16 @@ Your model calls this tool automatically when you attach a screenshot, you don't
91
92
 
92
93
  ## Configuration
93
94
 
94
- All settings are env-var overrides. Defaults work out-of-the-box for opencode-go + MiniMax M3.
95
+ All settings are env-var overrides. The plugin uses opencode's SDK client by default (handles auth automatically). Set `SEE_IMAGE_API_KEY` to bypass the SDK and call an HTTP endpoint directly.
95
96
 
96
97
  | Env var | Default | Description |
97
98
  |---|---|---|
98
- | `SEE_IMAGE_MODEL` | `minimax-m3` | Vision model ID to call |
99
- | `SEE_IMAGE_PROVIDER` | `opencode-go` | Provider key in opencode's `auth.json` |
100
- | `SEE_IMAGE_ENDPOINT` | `https://opencode.ai/zen/go/v1/messages` | Anthropic-Messages-compatible endpoint |
101
- | `SEE_IMAGE_API_KEY` | _(reads auth.json)_ | Bypass auth.json with an explicit key |
102
- | `SEE_IMAGE_API_VERSION` | `2023-06-01` | `anthropic-version` header value |
103
- | `SEE_IMAGE_USER_AGENT` | _(Chrome UA)_ | Override the User-Agent header |
99
+ | `SEE_IMAGE_MODEL` | `minimax-m3` | Vision model ID |
100
+ | `SEE_IMAGE_PROVIDER` | `opencode-go` | Provider ID for SDK routing |
101
+ | `SEE_IMAGE_API_KEY` | _(uses SDK)_ | Bypass SDK, call HTTP endpoint directly |
102
+ | `SEE_IMAGE_ENDPOINT` | `https://opencode.ai/zen/go/v1/messages` | HTTP endpoint (only used if `SEE_IMAGE_API_KEY` is set) |
103
+ | `SEE_IMAGE_API_VERSION` | `2023-06-01` | `anthropic-version` header (HTTP mode only) |
104
+ | `SEE_IMAGE_USER_AGENT` | _(Chrome UA)_ | User-Agent header (HTTP mode only) |
104
105
 
105
106
  ### Using a different vision model
106
107
 
@@ -137,17 +138,17 @@ export SEE_IMAGE_MODEL="kimi-k2.7-code"
137
138
 
138
139
  ## Updating
139
140
 
140
- **Auto-update (built in):** the plugin checks npm for a newer version on every opencode startup. If one exists, it runs `bun update` automatically and shows a toast: *"opencode-see-image updated to X.Y.Z, restart opencode to apply"*. You just need to restart opencode to load the new version. Nothing to configure.
141
+ **Auto-update (built in):** the plugin checks npm for a newer version on every opencode startup. If one exists, it updates itself via `opencode plugin --force` (uses opencode's bundled bun, no global bun needed) and shows a toast: *"opencode-see-image updated to X.Y.Z, restart opencode to apply"*. You just need to restart opencode to load the new version. Nothing to configure.
141
142
 
142
143
  **Manual update** (if you want to force it now):
143
144
  ```bash
144
- cd ~/.cache/opencode && bun update opencode-see-image
145
+ opencode plugin opencode-see-image --force --global
145
146
  ```
146
- Then restart opencode.
147
+ Then restart opencode. (No bun required, this uses opencode's own bun.)
147
148
 
148
149
  **Pin a version** in your config to opt out of auto-updates:
149
150
  ```jsonc
150
- "plugin": ["opencode-see-image@0.3.0"]
151
+ "plugin": ["opencode-see-image@0.4.2"]
151
152
  ```
152
153
 
153
154
  ## File search locations
package/index.ts CHANGED
@@ -76,6 +76,7 @@ async function seeImageViaSDK(
76
76
  dataUrl: string,
77
77
  mediaType: string,
78
78
  prompt: string,
79
+ abort?: AbortSignal,
79
80
  ): Promise<{ text: string; model: string; provider: string }> {
80
81
  const envProvider = process.env.SEE_IMAGE_PROVIDER
81
82
  const envModel = process.env.SEE_IMAGE_MODEL
@@ -144,6 +145,7 @@ async function seeImageViaHTTP(
144
145
  b64: string,
145
146
  mediaType: string,
146
147
  prompt: string,
148
+ abort?: AbortSignal,
147
149
  ): Promise<{ text: string; model: string; provider: string }> {
148
150
  const key = process.env.SEE_IMAGE_API_KEY!
149
151
  const body = {
@@ -172,6 +174,7 @@ async function seeImageViaHTTP(
172
174
  "user-agent": USER_AGENT,
173
175
  },
174
176
  body: JSON.stringify(body),
177
+ signal: abort,
175
178
  })
176
179
 
177
180
  if (!res.ok) {
@@ -271,14 +274,24 @@ async function maybeAutoUpdate(
271
274
 
272
275
  if (!semverGt(latest, current)) return
273
276
 
274
- log(`update available: ${current} -> ${latest}; running bun update`, "info")
277
+ log(`update available: ${current} -> ${latest}; updating`, "info")
275
278
 
276
- const cacheDir = path.join(os.homedir(), ".cache/opencode")
279
+ // Use opencode's own plugin command to re-resolve from npm. This uses
280
+ // opencode's bundled bun, so it works even when bun isn't installed
281
+ // globally on the user's PATH.
282
+ const opencodeBin =
283
+ process.env.OPENCODE_BIN ||
284
+ path.join(os.homedir(), ".opencode/bin/opencode")
277
285
  try {
278
- await $`cd ${cacheDir} && bun update ${PKG_NAME} --no-save`.quiet()
286
+ await $`${opencodeBin} plugin ${PKG_NAME} --force --global`.quiet()
279
287
  } catch (e: any) {
280
- log(`bun update failed: ${e?.message ?? e}`, "warn")
281
- return
288
+ // Fallback: try bare `opencode` on PATH
289
+ try {
290
+ await $`opencode plugin ${PKG_NAME} --force --global`.quiet()
291
+ } catch (e2: any) {
292
+ log(`plugin update failed: ${e2?.message ?? e2}`, "warn")
293
+ return
294
+ }
282
295
  }
283
296
 
284
297
  try {
@@ -337,9 +350,9 @@ const SeeImagePlugin: Plugin = async (ctx) => {
337
350
  let result: { text: string; model: string; provider: string }
338
351
 
339
352
  if (process.env.SEE_IMAGE_API_KEY) {
340
- result = await seeImageViaHTTP(b64, mediaType, prompt)
353
+ result = await seeImageViaHTTP(b64, mediaType, prompt, context.abort)
341
354
  } else {
342
- result = await seeImageViaSDK(client, dataUrl, mediaType, prompt)
355
+ result = await seeImageViaSDK(client, dataUrl, mediaType, prompt, context.abort)
343
356
  }
344
357
 
345
358
  context.metadata({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-see-image",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Give non-vision opencode models the ability to see images/screenshots by routing them to a vision-capable model (MiniMax M3 via opencode-go by default).",
5
5
  "type": "module",
6
6
  "main": "index.ts",