This repository was archived by the owner on Jun 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathruntime.ts
More file actions
68 lines (63 loc) · 1.74 KB
/
runtime.ts
File metadata and controls
68 lines (63 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import type { XMemClient } from "./client.ts"
type MemoryProviderStatus = {
backend: "builtin"
provider: string
model?: string
files?: number
chunks?: number
custom?: Record<string, unknown>
}
type RegisteredMemorySearchManager = {
status(): MemoryProviderStatus
probeEmbeddingAvailability(): Promise<{ ok: boolean; error?: string }>
probeVectorAvailability(): Promise<boolean>
sync?(): Promise<void>
close?(): Promise<void>
}
export function buildMemoryRuntime(client: XMemClient) {
const manager: RegisteredMemorySearchManager = {
status() {
return {
backend: "builtin",
provider: "xmem",
model: "xmem-remote",
files: 0,
chunks: 0,
custom: client.status(),
}
},
async probeEmbeddingAvailability() {
try {
await client.search("connection probe", 1)
return { ok: true }
} catch (err) {
return { ok: false, error: err instanceof Error ? err.message : "XMem unavailable" }
}
},
async probeVectorAvailability() {
return true
},
async sync() {},
async close() {},
}
return {
async getMemorySearchManager() {
return { manager }
},
resolveMemoryBackendConfig() {
return { backend: "builtin" as const }
},
}
}
export function buildPromptSection(params: { availableTools: Set<string> }): string[] {
const hasSearch = params.availableTools.has("xmem_search")
const hasStore = params.availableTools.has("xmem_store")
if (!hasSearch && !hasStore) return []
return [
"## Memory (XMem)",
"",
"Memory is managed by XMem remote APIs. Do not store secrets in memory.",
hasSearch ? "Use xmem_search to look up prior project context, decisions, and solved bugs." : "",
hasStore ? "Use xmem_store when the user asks you to remember something important." : "",
].filter(Boolean)
}