forked from supermemoryai/openclaw-supermemory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
74 lines (62 loc) · 2.15 KB
/
index.ts
File metadata and controls
74 lines (62 loc) · 2.15 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
import type { OpenClawPluginApi } from "openclaw/plugin-sdk"
import { SupermemoryClient } from "./client.ts"
import { registerCli, registerCliSetup } from "./commands/cli.ts"
import { registerCommands, registerStubCommands } from "./commands/slash.ts"
import { parseConfig, supermemoryConfigSchema } from "./config.ts"
import { buildCaptureHandler } from "./hooks/capture.ts"
import { buildRecallHandler } from "./hooks/recall.ts"
import { initLogger } from "./logger.ts"
import { registerForgetTool } from "./tools/forget.ts"
import { registerProfileTool } from "./tools/profile.ts"
import { registerSearchTool } from "./tools/search.ts"
import { registerStoreTool } from "./tools/store.ts"
export default {
id: "openclaw-supermemory",
name: "Supermemory",
description: "OpenClaw powered by Supermemory plugin",
kind: "memory" as const,
configSchema: supermemoryConfigSchema,
register(api: OpenClawPluginApi) {
const cfg = parseConfig(api.pluginConfig)
initLogger(api.logger, cfg.debug)
registerCliSetup(api)
if (!cfg.apiKey) {
api.logger.info(
"supermemory: not configured - run 'openclaw supermemory setup'",
)
registerStubCommands(api)
return
}
const client = new SupermemoryClient(cfg.apiKey, cfg.containerTag)
let sessionKey: string | undefined
const getSessionKey = () => sessionKey
registerSearchTool(api, client, cfg)
registerStoreTool(api, client, cfg, getSessionKey)
registerForgetTool(api, client, cfg)
registerProfileTool(api, client, cfg)
if (cfg.autoRecall) {
const recallHandler = buildRecallHandler(client, cfg)
api.on(
"before_agent_start",
(event: Record<string, unknown>, ctx: Record<string, unknown>) => {
if (ctx.sessionKey) sessionKey = ctx.sessionKey as string
return recallHandler(event, ctx)
},
)
}
if (cfg.autoCapture) {
api.on("agent_end", buildCaptureHandler(client, cfg, getSessionKey))
}
registerCommands(api, client, cfg, getSessionKey)
registerCli(api, client, cfg)
api.registerService({
id: "openclaw-supermemory",
start: () => {
api.logger.info("supermemory: connected")
},
stop: () => {
api.logger.info("supermemory: stopped")
},
})
},
}