opencode-see-image 0.5.2 → 0.5.4
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.
- package/index.ts +46 -6
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -346,14 +346,46 @@ const PKG_NAME = "opencode-see-image"
|
|
|
346
346
|
const REGISTRY_LATEST = `https://registry.npmjs.org/${PKG_NAME}/latest`
|
|
347
347
|
|
|
348
348
|
function currentVersion(): string | null {
|
|
349
|
+
// Try import.meta.url first (works when not bundled)
|
|
349
350
|
try {
|
|
350
351
|
const here = new URL(".", import.meta.url)
|
|
351
352
|
const pkgPath = new URL("package.json", here)
|
|
352
353
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
353
|
-
|
|
354
|
-
} catch {
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
if (pkg.version) return pkg.version
|
|
355
|
+
} catch {}
|
|
356
|
+
|
|
357
|
+
// Fallback: walk up from import.meta.url looking for package.json with our name
|
|
358
|
+
try {
|
|
359
|
+
let dir = new URL(".", import.meta.url)
|
|
360
|
+
for (let i = 0; i < 10; i++) {
|
|
361
|
+
const pkgPath = new URL("package.json", dir)
|
|
362
|
+
try {
|
|
363
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
364
|
+
if (pkg.name === PKG_NAME && pkg.version) return pkg.version
|
|
365
|
+
} catch {}
|
|
366
|
+
const parent = new URL("../", dir)
|
|
367
|
+
if (parent.href === dir.href) break
|
|
368
|
+
dir = parent
|
|
369
|
+
}
|
|
370
|
+
} catch {}
|
|
371
|
+
|
|
372
|
+
// Last resort: check the known opencode cache paths
|
|
373
|
+
try {
|
|
374
|
+
const cacheDir = path.join(os.homedir(), ".cache/opencode/packages")
|
|
375
|
+
if (fs.existsSync(cacheDir)) {
|
|
376
|
+
for (const sub of fs.readdirSync(cacheDir)) {
|
|
377
|
+
if (sub.startsWith(PKG_NAME)) {
|
|
378
|
+
const pkgPath = path.join(cacheDir, sub, "node_modules", PKG_NAME, "package.json")
|
|
379
|
+
try {
|
|
380
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
381
|
+
if (pkg.version) return pkg.version
|
|
382
|
+
} catch {}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
} catch {}
|
|
387
|
+
|
|
388
|
+
return null
|
|
357
389
|
}
|
|
358
390
|
|
|
359
391
|
function semverGt(a: string, b: string): boolean {
|
|
@@ -373,8 +405,13 @@ async function maybeAutoUpdate(
|
|
|
373
405
|
$: any,
|
|
374
406
|
log: (msg: string, level?: string) => void,
|
|
375
407
|
) {
|
|
408
|
+
log(`starting update check`, "debug")
|
|
376
409
|
const current = currentVersion()
|
|
377
|
-
if (!current)
|
|
410
|
+
if (!current) {
|
|
411
|
+
log(`could not determine current version`, "warn")
|
|
412
|
+
return
|
|
413
|
+
}
|
|
414
|
+
log(`current version: ${current}`, "debug")
|
|
378
415
|
|
|
379
416
|
let latest: string
|
|
380
417
|
try {
|
|
@@ -428,7 +465,10 @@ const SeeImagePlugin: Plugin = async (ctx) => {
|
|
|
428
465
|
} catch {}
|
|
429
466
|
}
|
|
430
467
|
|
|
431
|
-
|
|
468
|
+
log(`plugin initialized`, "info")
|
|
469
|
+
maybeAutoUpdate(client, $, log).catch((e) => {
|
|
470
|
+
log(`auto-update error: ${e?.message ?? e}`, "warn")
|
|
471
|
+
})
|
|
432
472
|
|
|
433
473
|
const seeImageTool = tool({
|
|
434
474
|
description:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-see-image",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
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",
|