opencode-see-image 0.5.0 → 0.5.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.
- package/index.ts +60 -18
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -38,20 +38,63 @@ function opencodeDbPath(): string {
|
|
|
38
38
|
return path.join(dataDir, "opencode.db")
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function resolveFromDb(
|
|
41
|
+
function resolveFromDb(
|
|
42
|
+
filename: string,
|
|
43
|
+
sessionID?: string,
|
|
44
|
+
): ResolvedImage | null {
|
|
42
45
|
const dbPath = opencodeDbPath()
|
|
43
46
|
if (!fs.existsSync(dbPath)) return null
|
|
44
47
|
|
|
45
48
|
try {
|
|
46
49
|
const db = new Database(dbPath, { readonly: true })
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
|
|
50
|
+
let rows: Array<{ data: string }>
|
|
51
|
+
|
|
52
|
+
if (!filename || filename === "clipboard") {
|
|
53
|
+
// No filename: get the most recent file part, scoped to the current
|
|
54
|
+
// session if known so we don't grab an image pasted into a different
|
|
55
|
+
// conversation.
|
|
56
|
+
if (sessionID) {
|
|
57
|
+
rows = db
|
|
58
|
+
.query(
|
|
59
|
+
`SELECT data FROM part
|
|
60
|
+
WHERE session_id = ?
|
|
61
|
+
AND json_extract(data, '$.type') = 'file'
|
|
62
|
+
AND json_extract(data, '$.url') LIKE 'data:%'
|
|
63
|
+
ORDER BY time_created DESC LIMIT 1`,
|
|
64
|
+
)
|
|
65
|
+
.all(sessionID) as Array<{ data: string }>
|
|
66
|
+
} else {
|
|
67
|
+
rows = db
|
|
68
|
+
.query(
|
|
69
|
+
`SELECT data FROM part
|
|
70
|
+
WHERE json_extract(data, '$.type') = 'file'
|
|
71
|
+
AND json_extract(data, '$.url') LIKE 'data:%'
|
|
72
|
+
ORDER BY time_created DESC LIMIT 1`,
|
|
73
|
+
)
|
|
74
|
+
.all() as Array<{ data: string }>
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
if (sessionID) {
|
|
78
|
+
rows = db
|
|
79
|
+
.query(
|
|
80
|
+
`SELECT data FROM part
|
|
81
|
+
WHERE session_id = ?
|
|
82
|
+
AND json_extract(data, '$.type') = 'file'
|
|
83
|
+
AND json_extract(data, '$.filename') = ?
|
|
84
|
+
ORDER BY time_created DESC LIMIT 1`,
|
|
85
|
+
)
|
|
86
|
+
.all(sessionID, filename) as Array<{ data: string }>
|
|
87
|
+
} else {
|
|
88
|
+
rows = db
|
|
89
|
+
.query(
|
|
90
|
+
`SELECT data FROM part
|
|
91
|
+
WHERE json_extract(data, '$.type') = 'file'
|
|
92
|
+
AND json_extract(data, '$.filename') = ?
|
|
93
|
+
ORDER BY time_created DESC LIMIT 1`,
|
|
94
|
+
)
|
|
95
|
+
.all(filename) as Array<{ data: string }>
|
|
96
|
+
}
|
|
97
|
+
}
|
|
55
98
|
|
|
56
99
|
db.close()
|
|
57
100
|
|
|
@@ -129,20 +172,19 @@ function resolveFromFilesystem(
|
|
|
129
172
|
}
|
|
130
173
|
}
|
|
131
174
|
|
|
132
|
-
function resolveImage(name: string, cwd: string): ResolvedImage {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const fromDb = resolveFromDb(name)
|
|
175
|
+
function resolveImage(name: string, cwd: string, sessionID?: string): ResolvedImage {
|
|
176
|
+
// DB first: handles clipboard pastes, dragged files, screenshots.
|
|
177
|
+
// For "clipboard" or empty name, gets the most recent file part.
|
|
178
|
+
// Scoped to the current session if known.
|
|
179
|
+
const fromDb = resolveFromDb(name, sessionID)
|
|
139
180
|
if (fromDb) return fromDb
|
|
140
181
|
|
|
182
|
+
// Filesystem fallback for files not yet in the DB.
|
|
141
183
|
const fromFs = resolveFromFilesystem(name, cwd)
|
|
142
184
|
if (fromFs) return fromFs
|
|
143
185
|
|
|
144
186
|
throw new Error(
|
|
145
|
-
`see_image: could not find "${name}". Searched opencode DB and filesystem
|
|
187
|
+
`see_image: could not find "${name}". Searched opencode DB and filesystem. Pass an absolute filePath instead.`,
|
|
146
188
|
)
|
|
147
189
|
}
|
|
148
190
|
|
|
@@ -405,7 +447,7 @@ const SeeImagePlugin: Plugin = async (ctx) => {
|
|
|
405
447
|
),
|
|
406
448
|
},
|
|
407
449
|
async execute(args, context) {
|
|
408
|
-
const resolved = resolveImage(args.filePath, context.directory)
|
|
450
|
+
const resolved = resolveImage(args.filePath, context.directory, context.sessionID)
|
|
409
451
|
|
|
410
452
|
const prompt =
|
|
411
453
|
args.question && args.question.trim().length > 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-see-image",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.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",
|