@openclaw/memory-lancedb 2026.5.1-beta.1

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.
@@ -0,0 +1,77 @@
1
+ type LanceDbModule = typeof import("@lancedb/lancedb");
2
+
3
+ export type LanceDbRuntimeLogger = {
4
+ info?: (message: string) => void;
5
+ warn?: (message: string) => void;
6
+ };
7
+
8
+ type LanceDbRuntimeLoaderDeps = {
9
+ platform: NodeJS.Platform;
10
+ arch: NodeJS.Architecture;
11
+ importBundled: () => Promise<LanceDbModule>;
12
+ };
13
+
14
+ function buildLoadFailureMessage(error: unknown): string {
15
+ return [
16
+ "memory-lancedb: bundled @lancedb/lancedb dependency is unavailable.",
17
+ "Install or repair the memory-lancedb plugin package dependencies, then restart OpenClaw.",
18
+ String(error),
19
+ ].join(" ");
20
+ }
21
+
22
+ function isUnsupportedNativePlatform(params: {
23
+ platform: NodeJS.Platform;
24
+ arch: NodeJS.Architecture;
25
+ }): boolean {
26
+ return params.platform === "darwin" && params.arch === "x64";
27
+ }
28
+
29
+ function buildUnsupportedNativePlatformMessage(params: {
30
+ platform: NodeJS.Platform;
31
+ arch: NodeJS.Architecture;
32
+ }): string {
33
+ return [
34
+ `memory-lancedb: LanceDB runtime is unavailable on ${params.platform}-${params.arch}.`,
35
+ "The bundled @lancedb/lancedb dependency does not publish a native package for this platform.",
36
+ "Disable memory-lancedb or switch to a supported memory backend/platform.",
37
+ ].join(" ");
38
+ }
39
+
40
+ export function createLanceDbRuntimeLoader(overrides: Partial<LanceDbRuntimeLoaderDeps> = {}): {
41
+ load: (_logger?: LanceDbRuntimeLogger) => Promise<LanceDbModule>;
42
+ } {
43
+ const deps: LanceDbRuntimeLoaderDeps = {
44
+ platform: overrides.platform ?? process.platform,
45
+ arch: overrides.arch ?? process.arch,
46
+ importBundled: overrides.importBundled ?? (() => import("@lancedb/lancedb")),
47
+ };
48
+
49
+ let loadPromise: Promise<LanceDbModule> | null = null;
50
+
51
+ return {
52
+ async load(_logger?: LanceDbRuntimeLogger): Promise<LanceDbModule> {
53
+ if (!loadPromise) {
54
+ loadPromise = deps.importBundled().catch((error) => {
55
+ loadPromise = null;
56
+ if (isUnsupportedNativePlatform({ platform: deps.platform, arch: deps.arch })) {
57
+ throw new Error(
58
+ buildUnsupportedNativePlatformMessage({
59
+ platform: deps.platform,
60
+ arch: deps.arch,
61
+ }),
62
+ { cause: error },
63
+ );
64
+ }
65
+ throw new Error(buildLoadFailureMessage(error), { cause: error });
66
+ });
67
+ }
68
+ return await loadPromise;
69
+ },
70
+ };
71
+ }
72
+
73
+ const defaultLoader = createLanceDbRuntimeLoader();
74
+
75
+ export async function loadLanceDbModule(logger?: LanceDbRuntimeLogger): Promise<LanceDbModule> {
76
+ return await defaultLoader.load(logger);
77
+ }
@@ -0,0 +1,121 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { installTmpDirHarness } from "./test-helpers.js";
3
+
4
+ const OPENAI_API_KEY = process.env.OPENAI_API_KEY ?? "";
5
+ const HAS_OPENAI_KEY = Boolean(process.env.OPENAI_API_KEY);
6
+ const liveEnabled = HAS_OPENAI_KEY && process.env.OPENCLAW_LIVE_TEST === "1";
7
+ const describeLive = liveEnabled ? describe : describe.skip;
8
+
9
+ // Live tests that require OpenAI API key and actually use LanceDB
10
+ describeLive("memory plugin live tests", () => {
11
+ const { getDbPath } = installTmpDirHarness({ prefix: "openclaw-memory-live-" });
12
+
13
+ test("memory tools work end-to-end", async () => {
14
+ const { default: memoryPlugin } = await import("./index.js");
15
+ const liveApiKey = OPENAI_API_KEY;
16
+
17
+ // Mock plugin API
18
+ const registeredTools: any[] = [];
19
+ const registeredClis: any[] = [];
20
+ const registeredServices: any[] = [];
21
+ const registeredHooks: Record<string, any[]> = {};
22
+ const logs: string[] = [];
23
+
24
+ const mockApi = {
25
+ id: "memory-lancedb",
26
+ name: "Memory (LanceDB)",
27
+ source: "test",
28
+ config: {},
29
+ pluginConfig: {
30
+ embedding: {
31
+ apiKey: liveApiKey,
32
+ model: "text-embedding-3-small",
33
+ },
34
+ dbPath: getDbPath(),
35
+ autoCapture: false,
36
+ autoRecall: false,
37
+ },
38
+ runtime: {},
39
+ logger: {
40
+ info: (msg: string) => logs.push(`[info] ${msg}`),
41
+ warn: (msg: string) => logs.push(`[warn] ${msg}`),
42
+ error: (msg: string) => logs.push(`[error] ${msg}`),
43
+ debug: (msg: string) => logs.push(`[debug] ${msg}`),
44
+ },
45
+ registerTool: (tool: any, opts: any) => {
46
+ registeredTools.push({ tool, opts });
47
+ },
48
+ registerCli: (registrar: any, opts: any) => {
49
+ registeredClis.push({ registrar, opts });
50
+ },
51
+ registerService: (service: any) => {
52
+ registeredServices.push(service);
53
+ },
54
+ on: (hookName: string, handler: any) => {
55
+ if (!registeredHooks[hookName]) {
56
+ registeredHooks[hookName] = [];
57
+ }
58
+ registeredHooks[hookName].push(handler);
59
+ },
60
+ resolvePath: (p: string) => p,
61
+ };
62
+
63
+ // Register plugin
64
+ memoryPlugin.register(mockApi as any);
65
+
66
+ // Check registration
67
+ expect(registeredTools.length).toBe(3);
68
+ expect(registeredTools.map((t) => t.opts?.name)).toContain("memory_recall");
69
+ expect(registeredTools.map((t) => t.opts?.name)).toContain("memory_store");
70
+ expect(registeredTools.map((t) => t.opts?.name)).toContain("memory_forget");
71
+ expect(registeredClis.length).toBe(1);
72
+ expect(registeredServices.length).toBe(1);
73
+
74
+ // Get tool functions
75
+ const storeTool = registeredTools.find((t) => t.opts?.name === "memory_store")?.tool;
76
+ const recallTool = registeredTools.find((t) => t.opts?.name === "memory_recall")?.tool;
77
+ const forgetTool = registeredTools.find((t) => t.opts?.name === "memory_forget")?.tool;
78
+
79
+ // Test store
80
+ const storeResult = await storeTool.execute("test-call-1", {
81
+ text: "The user prefers dark mode for all applications",
82
+ importance: 0.8,
83
+ category: "preference",
84
+ });
85
+
86
+ expect(storeResult.details?.action).toBe("created");
87
+ const storedId = storeResult.details?.id;
88
+ expect(storedId).toMatch(/.+/);
89
+
90
+ // Test recall
91
+ const recallResult = await recallTool.execute("test-call-2", {
92
+ query: "dark mode preference",
93
+ limit: 5,
94
+ });
95
+
96
+ expect(recallResult.details?.count).toBeGreaterThan(0);
97
+ expect(recallResult.details?.memories?.[0]?.text).toContain("dark mode");
98
+
99
+ // Test duplicate detection
100
+ const duplicateResult = await storeTool.execute("test-call-3", {
101
+ text: "The user prefers dark mode for all applications",
102
+ });
103
+
104
+ expect(duplicateResult.details?.action).toBe("duplicate");
105
+
106
+ // Test forget
107
+ const forgetResult = await forgetTool.execute("test-call-4", {
108
+ memoryId: storedId,
109
+ });
110
+
111
+ expect(forgetResult.details?.action).toBe("deleted");
112
+
113
+ // Verify it's gone
114
+ const recallAfterForget = await recallTool.execute("test-call-5", {
115
+ query: "dark mode preference",
116
+ limit: 5,
117
+ });
118
+
119
+ expect(recallAfterForget.details?.count).toBe(0);
120
+ }, 60000); // 60s timeout for live API calls
121
+ });
@@ -0,0 +1,129 @@
1
+ {
2
+ "id": "memory-lancedb",
3
+ "activation": {
4
+ "onStartup": false
5
+ },
6
+ "kind": "memory",
7
+ "uiHints": {
8
+ "embedding.apiKey": {
9
+ "label": "Embedding API Key",
10
+ "sensitive": true,
11
+ "placeholder": "sk-proj-...",
12
+ "help": "Optional API key override for OpenAI-compatible embeddings; omit to use configured provider auth"
13
+ },
14
+ "embedding.provider": {
15
+ "label": "Embedding Provider",
16
+ "placeholder": "openai",
17
+ "help": "Memory embedding provider adapter to use (for example openai, github-copilot, ollama)"
18
+ },
19
+ "embedding.model": {
20
+ "label": "Embedding Model",
21
+ "placeholder": "text-embedding-3-small",
22
+ "help": "OpenAI embedding model to use"
23
+ },
24
+ "embedding.baseUrl": {
25
+ "label": "Base URL",
26
+ "placeholder": "https://api.openai.com/v1",
27
+ "help": "Optional provider or OpenAI-compatible embedding endpoint base URL",
28
+ "advanced": true
29
+ },
30
+ "embedding.dimensions": {
31
+ "label": "Dimensions",
32
+ "placeholder": "1536",
33
+ "help": "Vector dimensions for custom models (required for non-standard models)",
34
+ "advanced": true
35
+ },
36
+ "dbPath": {
37
+ "label": "Database Path",
38
+ "placeholder": "~/.openclaw/memory/lancedb",
39
+ "advanced": true
40
+ },
41
+ "autoCapture": {
42
+ "label": "Auto-Capture",
43
+ "help": "Automatically capture important information from conversations"
44
+ },
45
+ "autoRecall": {
46
+ "label": "Auto-Recall",
47
+ "help": "Automatically inject relevant memories into context"
48
+ },
49
+ "dreaming": {
50
+ "label": "Dreaming",
51
+ "help": "Optional dreaming config consumed when this plugin owns the memory slot"
52
+ },
53
+ "captureMaxChars": {
54
+ "label": "Capture Max Chars",
55
+ "help": "Maximum message length eligible for auto-capture",
56
+ "advanced": true,
57
+ "placeholder": "500"
58
+ },
59
+ "recallMaxChars": {
60
+ "label": "Recall Query Max Chars",
61
+ "help": "Maximum prompt/query length embedded for memory recall. Lower for small local embedding models.",
62
+ "advanced": true,
63
+ "placeholder": "1000"
64
+ },
65
+ "storageOptions": {
66
+ "label": "Storage Options",
67
+ "advanced": true,
68
+ "help": "Storage configuration options (access_key, secret_key, endpoint, etc.); supports ${ENV_VAR} values"
69
+ }
70
+ },
71
+ "configSchema": {
72
+ "type": "object",
73
+ "additionalProperties": false,
74
+ "properties": {
75
+ "embedding": {
76
+ "type": "object",
77
+ "minProperties": 1,
78
+ "additionalProperties": false,
79
+ "minProperties": 1,
80
+ "properties": {
81
+ "apiKey": {
82
+ "type": "string"
83
+ },
84
+ "provider": {
85
+ "type": "string"
86
+ },
87
+ "model": {
88
+ "type": "string"
89
+ },
90
+ "baseUrl": {
91
+ "type": "string"
92
+ },
93
+ "dimensions": {
94
+ "type": "number"
95
+ }
96
+ }
97
+ },
98
+ "dbPath": {
99
+ "type": "string"
100
+ },
101
+ "autoCapture": {
102
+ "type": "boolean"
103
+ },
104
+ "autoRecall": {
105
+ "type": "boolean"
106
+ },
107
+ "dreaming": {
108
+ "type": "object"
109
+ },
110
+ "captureMaxChars": {
111
+ "type": "number",
112
+ "minimum": 100,
113
+ "maximum": 10000
114
+ },
115
+ "recallMaxChars": {
116
+ "type": "number",
117
+ "minimum": 100,
118
+ "maximum": 10000
119
+ },
120
+ "storageOptions": {
121
+ "type": "object",
122
+ "additionalProperties": {
123
+ "type": "string"
124
+ }
125
+ }
126
+ },
127
+ "required": ["embedding"]
128
+ }
129
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@openclaw/memory-lancedb",
3
+ "version": "2026.5.1-beta.1",
4
+ "description": "OpenClaw LanceDB-backed long-term memory plugin with auto-recall/capture",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/openclaw/openclaw"
8
+ },
9
+ "type": "module",
10
+ "dependencies": {
11
+ "@lancedb/lancedb": "^0.27.2",
12
+ "openai": "^6.35.0",
13
+ "typebox": "1.1.37"
14
+ },
15
+ "devDependencies": {
16
+ "@openclaw/plugin-sdk": "workspace:*"
17
+ },
18
+ "openclaw": {
19
+ "extensions": [
20
+ "./index.ts"
21
+ ],
22
+ "install": {
23
+ "npmSpec": "@openclaw/memory-lancedb",
24
+ "defaultChoice": "npm",
25
+ "minHostVersion": ">=2026.4.10"
26
+ },
27
+ "compat": {
28
+ "pluginApi": ">=2026.4.25"
29
+ },
30
+ "build": {
31
+ "openclawVersion": "2026.5.1-beta.1"
32
+ },
33
+ "release": {
34
+ "publishToClawHub": true,
35
+ "publishToNpm": true
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,25 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
4
+ import { afterEach, beforeEach } from "vitest";
5
+
6
+ export function installTmpDirHarness(params: { prefix: string }) {
7
+ let tmpDir = "";
8
+ let dbPath = "";
9
+
10
+ beforeEach(async () => {
11
+ tmpDir = await fs.mkdtemp(path.join(resolvePreferredOpenClawTmpDir(), params.prefix));
12
+ dbPath = path.join(tmpDir, "lancedb");
13
+ });
14
+
15
+ afterEach(async () => {
16
+ if (tmpDir) {
17
+ await fs.rm(tmpDir, { recursive: true, force: true });
18
+ }
19
+ });
20
+
21
+ return {
22
+ getTmpDir: () => tmpDir,
23
+ getDbPath: () => dbPath,
24
+ };
25
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../tsconfig.package-boundary.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "."
5
+ },
6
+ "include": ["./*.ts", "./src/**/*.ts"],
7
+ "exclude": [
8
+ "./**/*.test.ts",
9
+ "./dist/**",
10
+ "./node_modules/**",
11
+ "./src/test-support/**",
12
+ "./src/**/*test-helpers.ts",
13
+ "./src/**/*test-harness.ts",
14
+ "./src/**/*test-support.ts"
15
+ ]
16
+ }