opencode-see-image 0.5.1 → 0.5.3

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 +51 -23
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -38,7 +38,10 @@ function opencodeDbPath(): string {
38
38
  return path.join(dataDir, "opencode.db")
39
39
  }
40
40
 
41
- function resolveFromDb(filename: string): ResolvedImage | null {
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
 
@@ -47,26 +50,50 @@ function resolveFromDb(filename: string): ResolvedImage | null {
47
50
  let rows: Array<{ data: string }>
48
51
 
49
52
  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 }>
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
+ }
61
76
  } 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 }>
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
+ }
70
97
  }
71
98
 
72
99
  db.close()
@@ -145,10 +172,11 @@ function resolveFromFilesystem(
145
172
  }
146
173
  }
147
174
 
148
- function resolveImage(name: string, cwd: string): ResolvedImage {
175
+ function resolveImage(name: string, cwd: string, sessionID?: string): ResolvedImage {
149
176
  // DB first: handles clipboard pastes, dragged files, screenshots.
150
177
  // For "clipboard" or empty name, gets the most recent file part.
151
- const fromDb = resolveFromDb(name)
178
+ // Scoped to the current session if known.
179
+ const fromDb = resolveFromDb(name, sessionID)
152
180
  if (fromDb) return fromDb
153
181
 
154
182
  // Filesystem fallback for files not yet in the DB.
@@ -419,7 +447,7 @@ const SeeImagePlugin: Plugin = async (ctx) => {
419
447
  ),
420
448
  },
421
449
  async execute(args, context) {
422
- const resolved = resolveImage(args.filePath, context.directory)
450
+ const resolved = resolveImage(args.filePath, context.directory, context.sessionID)
423
451
 
424
452
  const prompt =
425
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.1",
3
+ "version": "0.5.3",
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",