opencode-see-image 0.6.2 → 0.7.0

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 (2) hide show
  1. package/index.ts +34 -1
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -195,6 +195,26 @@ function resolveImage(name: string, cwd: string, sessionID?: string): ResolvedIm
195
195
  )
196
196
  }
197
197
 
198
+ function readProviderKey(providerID: string): string | null {
199
+ try {
200
+ const xdgDataHome = process.env.XDG_DATA_HOME
201
+ ? path.join(process.env.XDG_DATA_HOME, "opencode")
202
+ : ""
203
+ const dataDir =
204
+ process.env.OPENCODE_DATA_DIR ||
205
+ xdgDataHome ||
206
+ path.join(os.homedir(), ".local/share/opencode")
207
+ const authPath = path.join(dataDir, "auth.json")
208
+ if (!fs.existsSync(authPath)) return null
209
+ const auth = JSON.parse(fs.readFileSync(authPath, "utf8"))
210
+ const entry = auth[providerID]
211
+ if (entry?.type === "api" && entry?.key) return entry.key
212
+ return null
213
+ } catch {
214
+ return null
215
+ }
216
+ }
217
+
198
218
  async function seeImageViaSDK(
199
219
  client: any,
200
220
  dataUrl: string,
@@ -266,6 +286,18 @@ async function seeImageViaSDK(
266
286
  }
267
287
  }
268
288
 
289
+ // If user has an API key configured (from auth.json or env), try HTTP fallback
290
+ const b64 = dataUrl.split(",")[1] || ""
291
+ const apiKey =
292
+ process.env.SEE_IMAGE_API_KEY || readProviderKey("opencode-go")
293
+ if (apiKey) {
294
+ try {
295
+ return await seeImageViaHTTP(b64, mediaType, prompt, abort, apiKey)
296
+ } catch (e: any) {
297
+ errors.push(`http-fallback: ${e?.message ?? e}`)
298
+ }
299
+ }
300
+
269
301
  throw new Error(
270
302
  `see_image: SDK vision call failed for all candidates. ${errors.join("; ")}`,
271
303
  )
@@ -276,8 +308,9 @@ async function seeImageViaHTTP(
276
308
  mediaType: string,
277
309
  prompt: string,
278
310
  abort?: AbortSignal,
311
+ keyOverride?: string,
279
312
  ): Promise<{ text: string; model: string; provider: string }> {
280
- const key = process.env.SEE_IMAGE_API_KEY!
313
+ const key = keyOverride || process.env.SEE_IMAGE_API_KEY!
281
314
  const body = {
282
315
  model: MODEL,
283
316
  max_tokens: 2048,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-see-image",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
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",