opencode-see-image 0.5.0 → 0.5.1
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 +28 -14
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -44,14 +44,30 @@ function resolveFromDb(filename: string): ResolvedImage | null {
|
|
|
44
44
|
|
|
45
45
|
try {
|
|
46
46
|
const db = new Database(dbPath, { readonly: true })
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
let rows: Array<{ data: string }>
|
|
48
|
+
|
|
49
|
+
if (!filename || filename === "clipboard") {
|
|
50
|
+
// No filename: get the most recent file part (handles clipboard pastes
|
|
51
|
+
// where opencode labels the error as "clipboard" but the DB part has
|
|
52
|
+
// the original filename).
|
|
53
|
+
rows = db
|
|
54
|
+
.query(
|
|
55
|
+
`SELECT data FROM part
|
|
56
|
+
WHERE json_extract(data, '$.type') = 'file'
|
|
57
|
+
AND json_extract(data, '$.url') LIKE 'data:%'
|
|
58
|
+
ORDER BY time_created DESC LIMIT 1`,
|
|
59
|
+
)
|
|
60
|
+
.all() as Array<{ data: string }>
|
|
61
|
+
} else {
|
|
62
|
+
rows = db
|
|
63
|
+
.query(
|
|
64
|
+
`SELECT data FROM part
|
|
65
|
+
WHERE json_extract(data, '$.type') = 'file'
|
|
66
|
+
AND json_extract(data, '$.filename') = ?
|
|
67
|
+
ORDER BY time_created DESC LIMIT 1`,
|
|
68
|
+
)
|
|
69
|
+
.all(filename) as Array<{ data: string }>
|
|
70
|
+
}
|
|
55
71
|
|
|
56
72
|
db.close()
|
|
57
73
|
|
|
@@ -130,19 +146,17 @@ function resolveFromFilesystem(
|
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
function resolveImage(name: string, cwd: string): ResolvedImage {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (fromDb) return fromDb
|
|
136
|
-
}
|
|
137
|
-
|
|
149
|
+
// DB first: handles clipboard pastes, dragged files, screenshots.
|
|
150
|
+
// For "clipboard" or empty name, gets the most recent file part.
|
|
138
151
|
const fromDb = resolveFromDb(name)
|
|
139
152
|
if (fromDb) return fromDb
|
|
140
153
|
|
|
154
|
+
// Filesystem fallback for files not yet in the DB.
|
|
141
155
|
const fromFs = resolveFromFilesystem(name, cwd)
|
|
142
156
|
if (fromFs) return fromFs
|
|
143
157
|
|
|
144
158
|
throw new Error(
|
|
145
|
-
`see_image: could not find "${name}". Searched opencode DB and filesystem
|
|
159
|
+
`see_image: could not find "${name}". Searched opencode DB and filesystem. Pass an absolute filePath instead.`,
|
|
146
160
|
)
|
|
147
161
|
}
|
|
148
162
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-see-image",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|