@bojackduy/opencode-telescope 0.1.25 → 0.1.26
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/package.json +1 -1
- package/search/embedding.ts +2 -1
- package/search/queries.ts +3 -16
- package/search/vector.ts +22 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@bojackduy/opencode-telescope",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.26",
|
|
5
5
|
"description": "OpenCode TUI plugin for fuzzy and semantic search across local conversation history, session transcripts, and AI coding chats",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
package/search/embedding.ts
CHANGED
|
@@ -19,7 +19,7 @@ export class LlamaEmbeddingClient {
|
|
|
19
19
|
async health() {
|
|
20
20
|
for (const endpoint of ["/health", "/v1/health"]) {
|
|
21
21
|
try {
|
|
22
|
-
const response = await fetch(new URL(endpoint, this.config.baseUrl))
|
|
22
|
+
const response = await fetch(new URL(endpoint, this.config.baseUrl), { signal: AbortSignal.timeout(1000) })
|
|
23
23
|
if (response.ok) return true
|
|
24
24
|
} catch {
|
|
25
25
|
continue
|
|
@@ -39,6 +39,7 @@ export class LlamaEmbeddingClient {
|
|
|
39
39
|
private async embed(inputs: string[]) {
|
|
40
40
|
const response = await fetch(new URL("/v1/embeddings", this.config.baseUrl), {
|
|
41
41
|
method: "POST",
|
|
42
|
+
signal: AbortSignal.timeout(15_000),
|
|
42
43
|
headers: { "content-type": "application/json" },
|
|
43
44
|
body: JSON.stringify({
|
|
44
45
|
model: this.config.model ?? "local-embedding",
|
package/search/queries.ts
CHANGED
|
@@ -270,22 +270,9 @@ export async function semanticSearchSessionMessages(query: string, options?: { l
|
|
|
270
270
|
const indexPath = searchIndexPath(dbPath)
|
|
271
271
|
const lastAttempt = lastVectorRebuildAttempt.get(indexPath)
|
|
272
272
|
if (!lastAttempt || Date.now() - lastAttempt > 30_000) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
documentPrefix: config.documentPrefix,
|
|
277
|
-
queryPrefix: config.queryPrefix,
|
|
278
|
-
})
|
|
279
|
-
try {
|
|
280
|
-
const healthy = await probeClient.health()
|
|
281
|
-
if (healthy) {
|
|
282
|
-
await setupVectorTable(index, config, indexPath)
|
|
283
|
-
lastVectorRebuildAttempt.set(indexPath, Date.now())
|
|
284
|
-
vecState = getMeta(index, "vector_state") ?? "stale"
|
|
285
|
-
}
|
|
286
|
-
} catch {
|
|
287
|
-
vecState = "unavailable"
|
|
288
|
-
}
|
|
273
|
+
setupVectorTable(index, config, indexPath)
|
|
274
|
+
lastVectorRebuildAttempt.set(indexPath, Date.now())
|
|
275
|
+
vecState = getMeta(index, "vector_state") ?? "stale"
|
|
289
276
|
}
|
|
290
277
|
}
|
|
291
278
|
if (vecState === "stale" && getMeta(index, "embedding_dimensions")) {
|
package/search/vector.ts
CHANGED
|
@@ -68,19 +68,35 @@ export function searchVector(index: Database, embedding: Float32Array, limit: nu
|
|
|
68
68
|
`).all(embedding, k)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
const vectorRebuilds = new Map<string, Promise<void>>()
|
|
72
|
+
|
|
73
|
+
export function setupVectorTable(index: Database, config: SemanticConfig, indexPath: string): void {
|
|
72
74
|
const dims = getMeta(index, "embedding_dimensions")
|
|
73
75
|
if (dims) {
|
|
74
76
|
setMeta(index, "vector_state", "enabled")
|
|
75
77
|
debug.log("vector:already-indexed", { dimensions: dims })
|
|
76
78
|
return
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
debug.log("vector:rebuild:error", err instanceof Error ? err.message : String(err))
|
|
80
|
+
if (vectorRebuilds.has(indexPath)) {
|
|
81
|
+
setMeta(index, "vector_state", "stale")
|
|
82
|
+
debug.log("vector:rebuild:already-running", { indexPath })
|
|
83
|
+
return
|
|
83
84
|
}
|
|
85
|
+
|
|
86
|
+
setMeta(index, "vector_state", "stale")
|
|
87
|
+
const rebuild = new Promise<void>((resolve) => {
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
rebuildVectorIndex(indexPath, config)
|
|
90
|
+
.catch((err) => {
|
|
91
|
+
debug.log("vector:rebuild:error", err instanceof Error ? err.message : String(err))
|
|
92
|
+
})
|
|
93
|
+
.finally(resolve)
|
|
94
|
+
}, 1)
|
|
95
|
+
;(timer as { unref?: () => void }).unref?.()
|
|
96
|
+
}).finally(() => {
|
|
97
|
+
vectorRebuilds.delete(indexPath)
|
|
98
|
+
})
|
|
99
|
+
vectorRebuilds.set(indexPath, rebuild)
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
let customSQLiteConfigured = false
|