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 pathindex.ts
More file actions
78 lines (68 loc) · 2.45 KB
/
index.ts
File metadata and controls
78 lines (68 loc) · 2.45 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
69
70
71
72
73
74
75
76
77
78
import fs from "node:fs"
import os from "node:os"
import path from "node:path"
import type { OpenClawPluginApi } from "openclaw/plugin-sdk"
import { XMemClient } from "./client.ts"
import { registerCli } from "./commands/cli.ts"
import { registerCommands, registerStubCommands } from "./commands/slash.ts"
import { parseConfig, xmemOpenClawConfigSchema } from "./config.ts"
import { buildCaptureHandler } from "./hooks/capture.ts"
import { buildRecallHandler } from "./hooks/recall.ts"
import { initLogger } from "./logger.ts"
import { buildMemoryRuntime, buildPromptSection } from "./runtime.ts"
import { registerSearchTool } from "./tools/search.ts"
import { registerStatusTool } from "./tools/status.ts"
import { registerStoreTool } from "./tools/store.ts"
function ensureOpenClawMemoryStore(): void {
try {
const stateDir = process.env.OPENCLAW_STATE_DIR || path.join(os.homedir(), ".openclaw")
const storePath = path.join(stateDir, "memory", "main.sqlite")
if (!fs.existsSync(storePath)) {
fs.mkdirSync(path.dirname(storePath), { recursive: true })
fs.writeFileSync(storePath, "")
}
} catch {}
}
export default {
id: "xmem-openclaw",
name: "XMem",
description: "OpenClaw powered by XMem memory",
kind: "memory" as const,
configSchema: xmemOpenClawConfigSchema,
register(api: OpenClawPluginApi) {
const cfg = parseConfig(api.pluginConfig)
initLogger(api.logger, cfg.debug)
ensureOpenClawMemoryStore()
if (!cfg.apiKey) {
registerCli(api)
api.logger.info("xmem: not configured - set XMEM_API_KEY or plugin apiKey")
registerStubCommands(api)
return
}
const client = new XMemClient(cfg)
registerCli(api, client)
const runtime = buildMemoryRuntime(client)
if (typeof api.registerMemoryCapability === "function") {
api.registerMemoryCapability({
runtime,
promptBuilder: buildPromptSection,
flushPlanResolver: () => null,
})
} else {
api.registerMemoryRuntime?.(runtime)
api.registerMemoryPromptSection?.(buildPromptSection)
api.registerMemoryFlushPlan?.(() => null)
}
registerSearchTool(api, client)
registerStoreTool(api, client)
registerStatusTool(api, client)
if (cfg.autoRecall) api.on("before_prompt_build", buildRecallHandler(client, cfg))
if (cfg.autoCapture) api.on("agent_end", buildCaptureHandler(client))
registerCommands(api, client)
api.registerService({
id: "xmem-openclaw",
start: () => api.logger.info("xmem: connected"),
stop: () => api.logger.info("xmem: stopped"),
})
},
}