@openclaw/memory-lancedb 2026.9.6 → 2026.9.7

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.
@@ -1,7 +1,8 @@
1
1
  import { looksLikeEnvelopeSludge } from "./memory-capture-sanitization.js";
2
2
  import { DEFAULT_RECALL_MAX_CHARS } from "./config.js";
3
3
  import { asOptionalRecord, normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
4
- import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
4
+ import { escapeHtml as escapeMemoryForPrompt, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
5
+ import { resolveNonNegativeIntegerOption } from "openclaw/plugin-sdk/number-runtime";
5
6
  import { createHash } from "node:crypto";
6
7
  //#region extensions/memory-lancedb/memory-policy.ts
7
8
  function extractUserTextContent(message) {
@@ -19,12 +20,9 @@ function extractUserTextContent(message) {
19
20
  }
20
21
  function normalizeRecallQuery(text, maxChars = DEFAULT_RECALL_MAX_CHARS) {
21
22
  const normalized = text.replace(/\s+/g, " ").trim();
22
- const limit = normalizeMaxChars(maxChars, DEFAULT_RECALL_MAX_CHARS);
23
+ const limit = resolveNonNegativeIntegerOption(maxChars, DEFAULT_RECALL_MAX_CHARS);
23
24
  return normalized.length > limit ? truncateUtf16Safe(normalized, limit).trimEnd() : normalized;
24
25
  }
25
- function normalizeMaxChars(value, fallback) {
26
- return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : fallback;
27
- }
28
26
  function captureFingerprint(text) {
29
27
  return createHash("sha256").update(text).digest("hex");
30
28
  }
@@ -102,21 +100,11 @@ const PROMPT_INJECTION_PATTERNS = [
102
100
  /<\s*(system|assistant|developer|tool|function|relevant-memories)\b/i,
103
101
  /\b(run|execute|call|invoke)\b.{0,40}\b(tool|command)\b/i
104
102
  ];
105
- const PROMPT_ESCAPE_MAP = {
106
- "&": "&amp;",
107
- "<": "&lt;",
108
- ">": "&gt;",
109
- "\"": "&quot;",
110
- "'": "&#39;"
111
- };
112
103
  function looksLikePromptInjection(text) {
113
104
  const normalized = text.replace(/\s+/g, " ").trim();
114
105
  if (!normalized) return false;
115
106
  return PROMPT_INJECTION_PATTERNS.some((pattern) => pattern.test(normalized));
116
107
  }
117
- function escapeMemoryForPrompt(text) {
118
- return text.replace(/[&<>"']/g, (char) => PROMPT_ESCAPE_MAP[char] ?? char);
119
- }
120
108
  function isRecallableMemoryText(text) {
121
109
  return text.trim().length > 0 && !looksLikeEnvelopeSludge(text);
122
110
  }
@@ -132,7 +120,7 @@ function cleanMemorySearchResults(results) {
132
120
  return results.filter(({ entry }) => isRecallableMemoryText(entry.text));
133
121
  }
134
122
  function formatRecalledMemoryForModel(text, maxChars = DEFAULT_RECALL_MAX_CHARS) {
135
- const limit = normalizeMaxChars(maxChars, DEFAULT_RECALL_MAX_CHARS);
123
+ const limit = resolveNonNegativeIntegerOption(maxChars, DEFAULT_RECALL_MAX_CHARS);
136
124
  return truncateUtf16Safe(escapeMemoryForPrompt(text), limit);
137
125
  }
138
126
  function formatRelevantMemoriesContext(memories, maxChars = DEFAULT_RECALL_MAX_CHARS) {
@@ -147,7 +135,7 @@ function matchesCustomTrigger(text, customTriggers) {
147
135
  }
148
136
  function shouldCapture(text, options) {
149
137
  if (looksLikeEnvelopeSludge(text)) return false;
150
- const maxChars = normalizeMaxChars(options?.maxChars, 500);
138
+ const maxChars = resolveNonNegativeIntegerOption(options?.maxChars, 500);
151
139
  if (text.length > maxChars) return false;
152
140
  if (text.includes("<relevant-memories>")) return false;
153
141
  if (text.startsWith("<") && text.includes("</")) return false;
@@ -0,0 +1,12 @@
1
+ //#region extensions/memory-lancedb/memory-stats-entrypoint.ts
2
+ const memoryStatsRuntimeEntrypoint = {
3
+ currentModuleUrl: import.meta.url,
4
+ sourceWorkerName: "lancedb-runtime",
5
+ package: {
6
+ name: "@openclaw/memory-lancedb",
7
+ distWorkerPath: "lancedb-runtime.js"
8
+ },
9
+ distWorkerPath: "extensions/memory-lancedb/lancedb-runtime.js"
10
+ };
11
+ //#endregion
12
+ export { memoryStatsRuntimeEntrypoint };
@@ -0,0 +1,63 @@
1
+ import { MEMORY_TABLE_NAME, hasAgentScopeColumn, legacyMemorySchemaError, memoryAgentPredicate } from "./lancedb-schema.js";
2
+ import { memoryStatsRuntimeEntrypoint } from "./memory-stats-entrypoint.js";
3
+ import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
+ import { resolveRuntimeWorkerArgv, resolveRuntimeWorkerUrl, runUtf8CommandWithTimeout } from "openclaw/plugin-sdk/process-runtime";
5
+ //#region extensions/memory-lancedb/memory-stats.ts
6
+ const STATS_READER = `
7
+ import { readFileSync } from "node:fs";
8
+ const input = JSON.parse(readFileSync(0, "utf8"));
9
+ let db;
10
+ let table;
11
+ const result = {};
12
+ try {
13
+ const { loadLanceDbModule } = await import(input.moduleUrl);
14
+ const lancedb = await loadLanceDbModule();
15
+ db = await lancedb.connect(input.dbPath, { storageOptions: input.storageOptions });
16
+ if ((await db.tableNames()).includes(input.tableName)) {
17
+ table = await db.openTable(input.tableName);
18
+ result.columns = (await table.schema()).fields.map((field) => field.name);
19
+ result.count = await table.countRows(input.predicate);
20
+ } else {
21
+ result.count = 0;
22
+ }
23
+ } catch (error) {
24
+ result.error = String(error);
25
+ } finally {
26
+ table?.close();
27
+ db?.close();
28
+ }
29
+ process.stdout.write(JSON.stringify(result));
30
+ `;
31
+ async function readMemoryStats(source, agentId) {
32
+ const moduleUrl = resolveRuntimeWorkerUrl(memoryStatsRuntimeEntrypoint);
33
+ const preload = resolveRuntimeWorkerArgv(moduleUrl).slice(0, -1);
34
+ const result = await runUtf8CommandWithTimeout([
35
+ process.execPath,
36
+ ...preload,
37
+ "--input-type=module",
38
+ "--eval",
39
+ STATS_READER
40
+ ], {
41
+ input: JSON.stringify({
42
+ ...source,
43
+ moduleUrl: moduleUrl.href,
44
+ tableName: MEMORY_TABLE_NAME,
45
+ predicate: memoryAgentPredicate(agentId)
46
+ }),
47
+ timeoutMs: 6e4,
48
+ killProcessTree: true,
49
+ requireProcessTreeExtinction: true,
50
+ maxOutputBytes: 65536
51
+ });
52
+ if (result.cleanup === "uncertain") throw new Error("memory-lancedb: statistics reader stopped responding; process cleanup could not be confirmed. Check the local process before retrying.");
53
+ if (result.termination === "timeout") throw new Error("memory-lancedb: statistics timed out after 60 seconds; the reader was stopped. Check database availability, then retry.");
54
+ if (result.code !== 0 || result.termination !== "exit") throw new Error(`memory-lancedb: statistics reader failed (${result.termination}, exit ${result.code}). ${result.stderr.trim()}`);
55
+ const reply = asOptionalRecord(JSON.parse(result.stdout));
56
+ const columns = reply?.columns;
57
+ if (Array.isArray(columns) && columns.every((column) => typeof column === "string") && !hasAgentScopeColumn({ fields: columns.map((name) => ({ name })) })) throw legacyMemorySchemaError();
58
+ if (typeof reply?.error === "string") throw new Error(`memory-lancedb: statistics failed: ${reply.error}`);
59
+ if (typeof reply?.count !== "number" || !Number.isSafeInteger(reply.count) || reply.count < 0) throw new Error("memory-lancedb: statistics reader returned an invalid count.");
60
+ return reply.count;
61
+ }
62
+ //#endregion
63
+ export { readMemoryStats };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/memory-lancedb",
3
- "version": "2026.9.6",
3
+ "version": "2026.9.7",
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",
@@ -8,22 +8,22 @@
8
8
  },
9
9
  "type": "module",
10
10
  "dependencies": {
11
- "apache-arrow": "18.1.0",
12
- "openai": "7.15.0",
13
- "typebox": "1.3.30"
11
+ "apache-arrow": "21.2.0",
12
+ "openai": "7.20.0",
13
+ "typebox": "1.3.34"
14
14
  },
15
15
  "devDependencies": {
16
- "@lancedb/lancedb": "0.38.0",
16
+ "@lancedb/lancedb": "0.39.0",
17
17
  "@openclaw/plugin-sdk": "workspace:*"
18
18
  },
19
19
  "optionalDependencies": {
20
- "@lancedb/lancedb-darwin-arm64": "0.38.0",
21
- "@lancedb/lancedb-linux-arm64-gnu": "0.38.0",
22
- "@lancedb/lancedb-linux-arm64-musl": "0.38.0",
23
- "@lancedb/lancedb-linux-x64-gnu": "0.38.0",
24
- "@lancedb/lancedb-linux-x64-musl": "0.38.0",
25
- "@lancedb/lancedb-win32-arm64-msvc": "0.38.0",
26
- "@lancedb/lancedb-win32-x64-msvc": "0.38.0"
20
+ "@lancedb/lancedb-darwin-arm64": "0.39.0",
21
+ "@lancedb/lancedb-linux-arm64-gnu": "0.39.0",
22
+ "@lancedb/lancedb-linux-arm64-musl": "0.39.0",
23
+ "@lancedb/lancedb-linux-x64-gnu": "0.39.0",
24
+ "@lancedb/lancedb-linux-x64-musl": "0.39.0",
25
+ "@lancedb/lancedb-win32-arm64-msvc": "0.39.0",
26
+ "@lancedb/lancedb-win32-x64-msvc": "0.39.0"
27
27
  },
28
28
  "openclaw": {
29
29
  "extensions": [
@@ -36,10 +36,13 @@
36
36
  "minHostVersion": ">=2026.5.31"
37
37
  },
38
38
  "compat": {
39
- "pluginApi": ">=2026.9.6"
39
+ "pluginApi": ">=2026.9.7"
40
40
  },
41
41
  "build": {
42
- "openclawVersion": "2026.9.6"
42
+ "openclawVersion": "2026.9.7",
43
+ "workerEntries": [
44
+ "./lancedb-runtime.ts"
45
+ ]
43
46
  },
44
47
  "release": {
45
48
  "bundleRuntimeDependencies": false,
@@ -59,7 +62,7 @@
59
62
  "assets/activity/*.svg"
60
63
  ],
61
64
  "peerDependencies": {
62
- "openclaw": ">=2026.9.6"
65
+ "openclaw": ">=2026.9.7"
63
66
  },
64
67
  "peerDependenciesMeta": {
65
68
  "openclaw": {
package/dist/api.js DELETED
@@ -1,3 +0,0 @@
1
- import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
2
- import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
3
- export { definePluginEntry, resolveStateDir };