opencode-see-image 0.8.5 → 0.9.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
@@ -217,6 +217,7 @@ function readProviderKey(providerID: string): string | null {
217
217
 
218
218
  async function seeImageViaSDK(
219
219
  client: any,
220
+ $: any,
220
221
  dataUrl: string,
221
222
  mediaType: string,
222
223
  prompt: string,
@@ -231,7 +232,27 @@ async function seeImageViaSDK(
231
232
  fs.writeFileSync(tmpPath, Buffer.from(b64, "base64"))
232
233
  } catch {}
233
234
 
234
- const fileUrl = `file://${tmpPath}`
235
+ // For free opencode models, use CLI instead of SDK (SDK returns empty)
236
+ const freeFallback = async (modelID: string, userPrompt: string): Promise<string | null> => {
237
+ try {
238
+ const controller = new AbortController()
239
+ const timer = setTimeout(() => controller.abort(), TIMEOUT)
240
+ const proc = $`opencode run -f ${tmpPath} -m opencode/${modelID} ${userPrompt} --format json --dangerously-skip-permissions`
241
+ const out = await proc.text()
242
+ clearTimeout(timer)
243
+ for (const line of out.split("\n").filter(Boolean)) {
244
+ try {
245
+ const parsed = JSON.parse(line)
246
+ if (parsed?.part?.type === "text" && parsed?.part?.text) {
247
+ return parsed.part.text
248
+ }
249
+ } catch {}
250
+ }
251
+ } catch {}
252
+ return null
253
+ }
254
+
255
+ const fileUrl = tmpPath
235
256
  let result: { text: string; model: string; provider: string } | undefined
236
257
 
237
258
  try {
@@ -245,6 +266,17 @@ async function seeImageViaSDK(
245
266
  candidates.push({ providerID: "opencode", modelID: "mimo-v2.5-free" })
246
267
 
247
268
  for (const { providerID, modelID } of candidates) {
269
+ if (providerID === "opencode") {
270
+ // SDK session.prompt returns empty for free models; use CLI instead
271
+ const text = await freeFallback(modelID, prompt)
272
+ if (text) {
273
+ result = { text, model: modelID, provider: providerID }
274
+ break
275
+ }
276
+ errors.push(`${providerID}/${modelID}: no text from CLI fallback`)
277
+ continue
278
+ }
279
+
248
280
  let sessionID: string | undefined
249
281
  try {
250
282
  const sessionRes = await client.session.create({ body: {} })
@@ -454,6 +486,7 @@ const SeeImagePlugin: Plugin = async (ctx) => {
454
486
  } else {
455
487
  result = await seeImageViaSDK(
456
488
  client,
489
+ $,
457
490
  resolved.dataUrl,
458
491
  resolved.mediaType,
459
492
  prompt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-see-image",
3
- "version": "0.8.5",
3
+ "version": "0.9.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",