@openclaw/memory-lancedb 2026.10.5-beta.4 → 2026.10.10-beta.2

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/dist/config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
2
2
  import { join } from "node:path";
3
3
  import { parseFiniteNumber, resolveOptionalIntegerOption } from "openclaw/plugin-sdk/number-runtime";
4
- import { homedir } from "node:os";
4
+ import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
5
5
  //#region extensions/memory-lancedb/config.ts
6
6
  const MEMORY_CATEGORIES = [
7
7
  "preference",
@@ -13,7 +13,9 @@ const MEMORY_CATEGORIES = [
13
13
  const DEFAULT_MODEL = "text-embedding-3-small";
14
14
  const DEFAULT_CAPTURE_MAX_CHARS = 500;
15
15
  const DEFAULT_RECALL_MAX_CHARS = 1e3;
16
- const DEFAULT_DB_PATH = join(homedir(), ".openclaw", "memory", "lancedb");
16
+ function resolveDefaultDbPath(stateDir = resolveStateDir()) {
17
+ return join(stateDir, "memory", "lancedb");
18
+ }
17
19
  const EMBEDDING_DIMENSIONS = {
18
20
  "text-embedding-3-small": 1536,
19
21
  "text-embedding-3-large": 3072
@@ -115,7 +117,7 @@ const memoryConfigSchema = { parse(value) {
115
117
  dimensions
116
118
  },
117
119
  dreaming,
118
- dbPath: typeof cfg.dbPath === "string" ? cfg.dbPath : DEFAULT_DB_PATH,
120
+ dbPath: typeof cfg.dbPath === "string" ? cfg.dbPath : resolveDefaultDbPath(),
119
121
  autoCapture: cfg.autoCapture === true,
120
122
  autoRecall: cfg.autoRecall !== false,
121
123
  captureMaxChars,
@@ -125,4 +127,4 @@ const memoryConfigSchema = { parse(value) {
125
127
  };
126
128
  } };
127
129
  //#endregion
128
- export { DEFAULT_CAPTURE_MAX_CHARS, DEFAULT_RECALL_MAX_CHARS, MEMORY_CATEGORIES, memoryConfigSchema, resolveEnvVars, vectorDimsForModel };
130
+ export { DEFAULT_CAPTURE_MAX_CHARS, DEFAULT_RECALL_MAX_CHARS, MEMORY_CATEGORIES, memoryConfigSchema, resolveDefaultDbPath, resolveEnvVars, vectorDimsForModel };
@@ -1,13 +1,13 @@
1
1
  import { o as __toESM } from "./.setup/rolldown-runtime-BMI-E3GI.mjs";
2
- import { resolveEnvVars } from "./config.js";
2
+ import { resolveDefaultDbPath, resolveEnvVars } from "./config.js";
3
3
  import { MEMORY_AGENT_ID_COLUMN, MEMORY_TABLE_NAME, hasAgentScopeColumn, memoryAgentPredicate, quoteLanceSqlString } from "./lancedb-schema.js";
4
4
  import { resolveDefaultAgentId } from "openclaw/plugin-sdk/agent-scope-runtime";
5
5
  import { normalizeAgentId } from "openclaw/plugin-sdk/routing";
6
6
  import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
7
7
  import { escapeRegExp } from "openclaw/plugin-sdk/text-utility-runtime";
8
8
  import path from "node:path";
9
- import os from "node:os";
10
9
  import fs from "node:fs";
10
+ import os from "node:os";
11
11
  import { fileURLToPath } from "node:url";
12
12
  //#region extensions/memory-lancedb/doctor-contract-api.ts
13
13
  const LEGACY_ENVELOPE_DELETE_BATCH_SIZE = 500;
@@ -55,10 +55,10 @@ const DEFAULT_PLUGIN_ROOT = resolveMemoryLanceDbPluginRoot(import.meta.url);
55
55
  function resolveHome(env) {
56
56
  return env.HOME?.trim() || os.homedir();
57
57
  }
58
- function resolveConfiguredDbPath(config, env, pluginRoot) {
58
+ function resolveConfiguredDbPath(config, env, pluginRoot, stateDir) {
59
59
  const pluginConfig = asOptionalRecord(config.plugins?.entries?.["memory-lancedb"]?.config);
60
60
  const configured = typeof pluginConfig?.dbPath === "string" ? pluginConfig.dbPath.trim() : "";
61
- if (!configured) return path.join(resolveHome(env), ".openclaw", "memory", "lancedb");
61
+ if (!configured) return resolveDefaultDbPath(stateDir);
62
62
  if (configured.includes("://")) return configured;
63
63
  if (configured.startsWith("~")) return path.resolve(configured.replace(/^~(?=$|[\\/])/, () => resolveHome(env)));
64
64
  return path.resolve(pluginRoot, configured);
@@ -73,7 +73,7 @@ function resolveStorageOptions(config, env) {
73
73
  }));
74
74
  }
75
75
  async function openMemoryTable(params) {
76
- const dbPath = resolveConfiguredDbPath(params.config, params.env, params.pluginRoot);
76
+ const dbPath = resolveConfiguredDbPath(params.config, params.env, params.pluginRoot, params.stateDir);
77
77
  if (!dbPath.includes("://") && !fs.existsSync(dbPath)) return {
78
78
  connection: null,
79
79
  table: null,
@@ -5,7 +5,6 @@ import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
5
5
  import { textResult } from "openclaw/plugin-sdk/tool-results";
6
6
  import { Buffer } from "node:buffer";
7
7
  import { resolve } from "node:path";
8
- import { resolveGlobalSingleton } from "openclaw/plugin-sdk/global-singleton";
9
8
  import { canonicalizeBase64 } from "openclaw/plugin-sdk/media-runtime";
10
9
  import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
11
10
  import { ensureGlobalUndiciEnvProxyDispatcher } from "openclaw/plugin-sdk/runtime-env";
@@ -13,27 +12,6 @@ import { raceWithTimeout } from "openclaw/plugin-sdk/time-runtime";
13
12
  //#region extensions/memory-lancedb/embeddings.ts
14
13
  const loadOpenAiModule = createLazyRuntimeModule(() => import("openai"));
15
14
  const loadMemoryEmbeddingProviderModule = createLazyRuntimeModule(() => import("openclaw/plugin-sdk/memory-core-host-engine-embeddings"));
16
- const PROVIDER_ADAPTER_LIFECYCLE = resolveGlobalSingleton(Symbol.for("openclaw.memoryLanceDbEmbeddingProviderLifecycle.v1"), () => ({
17
- retainedProviders: /* @__PURE__ */ new Set(),
18
- tail: Promise.resolve()
19
- }));
20
- function runProviderAdapterLifecycle(operation) {
21
- const result = PROVIDER_ADAPTER_LIFECYCLE.tail.then(operation, operation);
22
- PROVIDER_ADAPTER_LIFECYCLE.tail = result.then(() => void 0, () => void 0);
23
- return result;
24
- }
25
- async function drainRetainedProviders() {
26
- let firstError;
27
- let closeFailed = false;
28
- for (const provider of PROVIDER_ADAPTER_LIFECYCLE.retainedProviders) try {
29
- await provider.close?.();
30
- PROVIDER_ADAPTER_LIFECYCLE.retainedProviders.delete(provider);
31
- } catch (err) {
32
- if (!closeFailed) firstError = err;
33
- closeFailed = true;
34
- }
35
- if (closeFailed) throw toErrorObject(firstError, "memory-lancedb embedding provider retirement failed");
36
- }
37
15
  function embeddingConfigFingerprint(embedding) {
38
16
  const { provider, model, apiKey, baseUrl, dimensions } = embedding;
39
17
  return JSON.stringify([
@@ -120,6 +98,7 @@ var ProviderAdapterEmbeddings = class {
120
98
  this.api = api;
121
99
  this.providers = /* @__PURE__ */ new Map();
122
100
  this.closePromise = null;
101
+ this.retirement = Promise.resolve();
123
102
  this.closed = false;
124
103
  }
125
104
  getProvider(agentId, embedding) {
@@ -127,10 +106,7 @@ var ProviderAdapterEmbeddings = class {
127
106
  const agentDir = this.api.runtime.agent.resolveAgentDir(config, agentId);
128
107
  const existing = this.providers.get(agentId);
129
108
  if (existing?.config === config && existing.agentDir === agentDir) return existing;
130
- if (existing) {
131
- this.providers.delete(agentId);
132
- this.retireProviders([existing]).catch(() => void 0);
133
- }
109
+ if (existing) this.retireMatchingProviders((entry) => entry === existing);
134
110
  const entry = {
135
111
  config,
136
112
  agentDir,
@@ -155,48 +131,47 @@ var ProviderAdapterEmbeddings = class {
155
131
  entries.push(entry);
156
132
  }
157
133
  if (entries.length === 0) return;
158
- this.retireProviders(entries).catch(() => void 0);
134
+ this.retireProviders(entries).catch(() => {
135
+ this.api.logger.warn("memory-lancedb: embedding provider cleanup failed; restart the Gateway to reclaim resources");
136
+ });
159
137
  }
160
138
  invalidateProvidersForAuthMutation(event) {
161
139
  const changedAgentDir = event.agentDir ? resolve(event.agentDir) : void 0;
162
140
  this.retireMatchingProviders((entry) => event.affectsInheritedStores || resolve(entry.agentDir) === changedAgentDir);
163
141
  }
164
- async retireProviders(entries) {
165
- await runProviderAdapterLifecycle(async () => {
166
- for (const entry of entries) {
167
- if (entry.activeUses > 0) await new Promise((resolve) => {
168
- entry.idleResolver = resolve;
169
- });
170
- const provider = await entry.promise.catch(() => null);
171
- if (provider) PROVIDER_ADAPTER_LIFECYCLE.retainedProviders.add(provider);
172
- }
173
- await drainRetainedProviders();
142
+ retireProviders(entries) {
143
+ this.retirement = Promise.allSettled([this.retirement, ...entries.map(async (entry) => {
144
+ if (entry.activeUses > 0) await new Promise((resolve) => {
145
+ entry.idleResolver = resolve;
146
+ });
147
+ await (await entry.promise.catch(() => null))?.close?.();
148
+ })]).then((results) => {
149
+ const failure = results.find((result) => result.status === "rejected");
150
+ if (failure) throw toErrorObject(failure.reason, "memory-lancedb embedding provider retirement failed");
174
151
  });
152
+ return this.retirement;
175
153
  }
176
154
  async createProvider(config, agentDir, embedding) {
177
- return await runProviderAdapterLifecycle(async () => {
178
- await drainRetainedProviders();
179
- const providerId = embedding.provider;
180
- const { getMemoryEmbeddingProvider, registerRuntimeAuthProfileStoreMutationListener } = await loadMemoryEmbeddingProviderModule();
181
- if (!this.closed && !this.unregisterAuthMutationListener) this.unregisterAuthMutationListener = registerRuntimeAuthProfileStoreMutationListener((event) => this.invalidateProvidersForAuthMutation(event));
182
- const adapter = getMemoryEmbeddingProvider(providerId, config);
183
- if (!adapter) throw new Error(`Unknown memory embedding provider: ${providerId}`);
184
- const remote = embedding.apiKey || embedding.baseUrl ? {
185
- ...embedding.apiKey ? { apiKey: embedding.apiKey } : {},
186
- ...embedding.baseUrl ? { baseUrl: embedding.baseUrl } : {}
187
- } : void 0;
188
- const result = await adapter.create({
189
- config,
190
- agentDir,
191
- provider: providerId,
192
- fallback: "none",
193
- model: embedding.model,
194
- ...remote ? { remote } : {},
195
- ...typeof embedding.dimensions === "number" ? { dimensions: embedding.dimensions } : {}
196
- });
197
- if (!result.provider) throw new Error(`Memory embedding provider ${providerId} is unavailable.`);
198
- return result.provider;
155
+ const providerId = embedding.provider;
156
+ const { getMemoryEmbeddingProvider, registerRuntimeAuthProfileStoreMutationListener } = await loadMemoryEmbeddingProviderModule();
157
+ if (!this.closed && !this.unregisterAuthMutationListener) this.unregisterAuthMutationListener = registerRuntimeAuthProfileStoreMutationListener((event) => this.invalidateProvidersForAuthMutation(event));
158
+ const adapter = getMemoryEmbeddingProvider(providerId, config);
159
+ if (!adapter) throw new Error(`Unknown memory embedding provider: ${providerId}`);
160
+ const remote = embedding.apiKey || embedding.baseUrl ? {
161
+ ...embedding.apiKey ? { apiKey: embedding.apiKey } : {},
162
+ ...embedding.baseUrl ? { baseUrl: embedding.baseUrl } : {}
163
+ } : void 0;
164
+ const result = await adapter.create({
165
+ config,
166
+ agentDir,
167
+ provider: providerId,
168
+ fallback: "none",
169
+ model: embedding.model,
170
+ ...remote ? { remote } : {},
171
+ ...typeof embedding.dimensions === "number" ? { dimensions: embedding.dimensions } : {}
199
172
  });
173
+ if (!result.provider) throw new Error(`Memory embedding provider ${providerId} is unavailable.`);
174
+ return result.provider;
200
175
  }
201
176
  async embed(agentId, text, embeddingConfig, timeoutMs) {
202
177
  if (this.closed) throw new Error("memory-lancedb embeddings are closed");
@@ -229,20 +204,8 @@ var ProviderAdapterEmbeddings = class {
229
204
  }
230
205
  }
231
206
  }
232
- async close() {
233
- const existingClose = this.closePromise;
234
- if (existingClose) {
235
- await existingClose;
236
- return;
237
- }
238
- const closeOperation = this.closeOnce();
239
- this.closePromise = closeOperation;
240
- try {
241
- await closeOperation;
242
- } catch (err) {
243
- if (this.closePromise === closeOperation) this.closePromise = null;
244
- throw err;
245
- }
207
+ close() {
208
+ return this.closePromise ??= this.closeOnce();
246
209
  }
247
210
  async closeOnce() {
248
211
  this.closed = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/memory-lancedb",
3
- "version": "2026.10.5-beta.4",
3
+ "version": "2026.10.10-beta.2",
4
4
  "description": "OpenClaw LanceDB-backed long-term memory plugin with auto-recall, auto-capture, and vector search.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,8 +9,8 @@
9
9
  "type": "module",
10
10
  "dependencies": {
11
11
  "apache-arrow": "21.2.0",
12
- "openai": "7.27.0",
13
- "typebox": "1.3.34"
12
+ "openai": "7.28.0",
13
+ "typebox": "1.3.35"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@lancedb/lancedb": "0.39.0",
@@ -36,10 +36,10 @@
36
36
  "minHostVersion": ">=2026.5.31"
37
37
  },
38
38
  "compat": {
39
- "pluginApi": ">=2026.10.5-beta.4"
39
+ "pluginApi": ">=2026.10.10-beta.2"
40
40
  },
41
41
  "build": {
42
- "openclawVersion": "2026.10.5-beta.4",
42
+ "openclawVersion": "2026.10.10-beta.2",
43
43
  "workerEntries": [
44
44
  "./lancedb-runtime.ts"
45
45
  ]
@@ -62,7 +62,7 @@
62
62
  "assets/activity/*.svg"
63
63
  ],
64
64
  "peerDependencies": {
65
- "openclaw": ">=2026.10.5-beta.4"
65
+ "openclaw": ">=2026.10.10-beta.2"
66
66
  },
67
67
  "peerDependenciesMeta": {
68
68
  "openclaw": {