@openclaw/memory-lancedb 2026.7.2-beta.7 → 2026.8.1-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 +76 -145
- package/dist/doctor-contract-api.js +4 -6
- package/dist/embeddings.js +81 -37
- package/dist/index.js +9 -8
- package/dist/memory-cli.js +1 -1
- package/openclaw.plugin.json +3 -0
- package/package.json +4 -4
package/dist/config.js
CHANGED
|
@@ -62,153 +62,84 @@ function resolveEmbeddingDimensions(embedding) {
|
|
|
62
62
|
if (dimensions === void 0 || !Number.isInteger(dimensions) || dimensions < 1) throw new Error("embedding.dimensions must be a positive integer");
|
|
63
63
|
return dimensions;
|
|
64
64
|
}
|
|
65
|
-
const memoryConfigSchema = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
65
|
+
const memoryConfigSchema = { parse(value) {
|
|
66
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("memory config required");
|
|
67
|
+
const cfg = value;
|
|
68
|
+
assertAllowedKeys(cfg, [
|
|
69
|
+
"embedding",
|
|
70
|
+
"dreaming",
|
|
71
|
+
"dbPath",
|
|
72
|
+
"autoCapture",
|
|
73
|
+
"autoRecall",
|
|
74
|
+
"captureMaxChars",
|
|
75
|
+
"customTriggers",
|
|
76
|
+
"recallMaxChars",
|
|
77
|
+
"storageOptions"
|
|
78
|
+
], "memory config");
|
|
79
|
+
const embedding = cfg.embedding;
|
|
80
|
+
if (!embedding || typeof embedding !== "object" || Array.isArray(embedding)) throw new Error("embedding config required");
|
|
81
|
+
assertAllowedKeys(embedding, [...EMBEDDING_CONFIG_KEYS], "embedding config");
|
|
82
|
+
if (Object.keys(embedding).length === 0) throw new Error("embedding config must include at least one setting");
|
|
83
|
+
const dimensions = resolveEmbeddingDimensions(embedding);
|
|
84
|
+
const model = resolveEmbeddingModel(embedding, dimensions);
|
|
85
|
+
const provider = typeof embedding.provider === "string" ? embedding.provider.trim() : "openai";
|
|
86
|
+
if (!provider) throw new Error("embedding.provider must not be empty");
|
|
87
|
+
const captureMaxChars = resolveBoundedIntegerConfig({
|
|
88
|
+
value: cfg.captureMaxChars,
|
|
89
|
+
fallback: 500,
|
|
90
|
+
min: 100,
|
|
91
|
+
max: 1e4,
|
|
92
|
+
label: "captureMaxChars"
|
|
93
|
+
});
|
|
94
|
+
const recallMaxChars = resolveBoundedIntegerConfig({
|
|
95
|
+
value: cfg.recallMaxChars,
|
|
96
|
+
fallback: DEFAULT_RECALL_MAX_CHARS,
|
|
97
|
+
min: 100,
|
|
98
|
+
max: 1e4,
|
|
99
|
+
label: "recallMaxChars"
|
|
100
|
+
});
|
|
101
|
+
let customTriggers;
|
|
102
|
+
if (cfg.customTriggers !== void 0) {
|
|
103
|
+
if (!Array.isArray(cfg.customTriggers)) throw new Error("customTriggers must be an array of strings");
|
|
104
|
+
customTriggers = cfg.customTriggers.map((trigger, index) => {
|
|
105
|
+
if (typeof trigger !== "string") throw new Error(`customTriggers.${index} must be a string`);
|
|
106
|
+
const normalized = trigger.trim();
|
|
107
|
+
if (!normalized) throw new Error(`customTriggers.${index} must not be empty`);
|
|
108
|
+
if (normalized.length > 100) throw new Error(`customTriggers.${index} must be at most 100 characters`);
|
|
109
|
+
return normalized;
|
|
101
110
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
throw new Error("dreaming config must be an object");
|
|
116
|
-
})();
|
|
117
|
-
let storageOptions;
|
|
118
|
-
const storageOpts = cfg.storageOptions;
|
|
119
|
-
if (storageOpts !== void 0 && storageOpts !== null) {
|
|
120
|
-
if (!storageOpts || typeof storageOpts !== "object" || Array.isArray(storageOpts)) throw new Error("storageOptions must be an object");
|
|
121
|
-
storageOptions = {};
|
|
122
|
-
for (const [key, valueLocal] of Object.entries(storageOpts)) {
|
|
123
|
-
if (typeof valueLocal !== "string") throw new Error(`storageOptions.${key} must be a string`);
|
|
124
|
-
storageOptions[key] = resolveEnvVars(valueLocal);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
embedding: {
|
|
129
|
-
provider,
|
|
130
|
-
model,
|
|
131
|
-
apiKey: typeof embedding.apiKey === "string" ? resolveEnvVars(embedding.apiKey) : void 0,
|
|
132
|
-
baseUrl: typeof embedding.baseUrl === "string" ? resolveEnvVars(embedding.baseUrl) : void 0,
|
|
133
|
-
dimensions
|
|
134
|
-
},
|
|
135
|
-
dreaming,
|
|
136
|
-
dbPath: typeof cfg.dbPath === "string" ? cfg.dbPath : DEFAULT_DB_PATH,
|
|
137
|
-
autoCapture: cfg.autoCapture === true,
|
|
138
|
-
autoRecall: cfg.autoRecall !== false,
|
|
139
|
-
captureMaxChars,
|
|
140
|
-
...customTriggers ? { customTriggers } : {},
|
|
141
|
-
recallMaxChars,
|
|
142
|
-
...storageOptions ? { storageOptions } : {}
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
uiHints: {
|
|
146
|
-
"embedding.provider": {
|
|
147
|
-
label: "Embedding Provider",
|
|
148
|
-
placeholder: "openai",
|
|
149
|
-
help: "Memory embedding provider adapter to use (for example openai, github-copilot, ollama)"
|
|
150
|
-
},
|
|
151
|
-
"embedding.apiKey": {
|
|
152
|
-
label: "OpenAI API Key",
|
|
153
|
-
sensitive: true,
|
|
154
|
-
placeholder: "sk-proj-...",
|
|
155
|
-
help: "Optional API key override for OpenAI-compatible embeddings; omit to use configured provider auth"
|
|
156
|
-
},
|
|
157
|
-
"embedding.baseUrl": {
|
|
158
|
-
label: "Base URL",
|
|
159
|
-
placeholder: "https://api.openai.com/v1",
|
|
160
|
-
help: "Optional provider or OpenAI-compatible embedding endpoint base URL",
|
|
161
|
-
advanced: true
|
|
162
|
-
},
|
|
163
|
-
"embedding.dimensions": {
|
|
164
|
-
label: "Dimensions",
|
|
165
|
-
placeholder: "1536",
|
|
166
|
-
help: "Vector dimensions for custom models (required for non-standard models)",
|
|
167
|
-
advanced: true
|
|
168
|
-
},
|
|
169
|
-
"embedding.model": {
|
|
170
|
-
label: "Embedding Model",
|
|
171
|
-
placeholder: DEFAULT_MODEL,
|
|
172
|
-
help: "OpenAI embedding model to use"
|
|
173
|
-
},
|
|
174
|
-
dbPath: {
|
|
175
|
-
label: "Database Path",
|
|
176
|
-
placeholder: "~/.openclaw/memory/lancedb",
|
|
177
|
-
advanced: true,
|
|
178
|
-
help: "Local filesystem path or cloud storage URI (s3://, gs://) for LanceDB database"
|
|
179
|
-
},
|
|
180
|
-
autoCapture: {
|
|
181
|
-
label: "Auto-Capture",
|
|
182
|
-
help: "Automatically capture important information from conversations"
|
|
183
|
-
},
|
|
184
|
-
autoRecall: {
|
|
185
|
-
label: "Auto-Recall",
|
|
186
|
-
help: "Automatically inject relevant memories into context"
|
|
187
|
-
},
|
|
188
|
-
captureMaxChars: {
|
|
189
|
-
label: "Capture Max Chars",
|
|
190
|
-
help: "Maximum message length eligible for auto-capture",
|
|
191
|
-
advanced: true,
|
|
192
|
-
placeholder: String(500)
|
|
193
|
-
},
|
|
194
|
-
customTriggers: {
|
|
195
|
-
label: "Custom Triggers",
|
|
196
|
-
help: "Literal phrases that should make auto-capture consider a message memory-worthy",
|
|
197
|
-
advanced: true
|
|
198
|
-
},
|
|
199
|
-
recallMaxChars: {
|
|
200
|
-
label: "Recall Query Max Chars",
|
|
201
|
-
help: "Maximum prompt/query length embedded for memory recall. Lower for small local embedding models.",
|
|
202
|
-
advanced: true,
|
|
203
|
-
placeholder: String(DEFAULT_RECALL_MAX_CHARS)
|
|
204
|
-
},
|
|
205
|
-
storageOptions: {
|
|
206
|
-
label: "Storage Options",
|
|
207
|
-
sensitive: true,
|
|
208
|
-
advanced: true,
|
|
209
|
-
help: "Storage configuration options (access_key, secret_key, endpoint, etc.); supports ${ENV_VAR} values"
|
|
111
|
+
if (customTriggers.length > 50) throw new Error("customTriggers must include at most 50 entries");
|
|
112
|
+
}
|
|
113
|
+
const dreaming = cfg.dreaming === void 0 ? void 0 : cfg.dreaming && typeof cfg.dreaming === "object" && !Array.isArray(cfg.dreaming) ? cfg.dreaming : (() => {
|
|
114
|
+
throw new Error("dreaming config must be an object");
|
|
115
|
+
})();
|
|
116
|
+
let storageOptions;
|
|
117
|
+
const storageOpts = cfg.storageOptions;
|
|
118
|
+
if (storageOpts !== void 0 && storageOpts !== null) {
|
|
119
|
+
if (!storageOpts || typeof storageOpts !== "object" || Array.isArray(storageOpts)) throw new Error("storageOptions must be an object");
|
|
120
|
+
storageOptions = {};
|
|
121
|
+
for (const [key, valueLocal] of Object.entries(storageOpts)) {
|
|
122
|
+
if (typeof valueLocal !== "string") throw new Error(`storageOptions.${key} must be a string`);
|
|
123
|
+
storageOptions[key] = resolveEnvVars(valueLocal);
|
|
210
124
|
}
|
|
211
125
|
}
|
|
212
|
-
|
|
126
|
+
return {
|
|
127
|
+
embedding: {
|
|
128
|
+
provider,
|
|
129
|
+
model,
|
|
130
|
+
apiKey: typeof embedding.apiKey === "string" ? resolveEnvVars(embedding.apiKey) : void 0,
|
|
131
|
+
baseUrl: typeof embedding.baseUrl === "string" ? resolveEnvVars(embedding.baseUrl) : void 0,
|
|
132
|
+
dimensions
|
|
133
|
+
},
|
|
134
|
+
dreaming,
|
|
135
|
+
dbPath: typeof cfg.dbPath === "string" ? cfg.dbPath : DEFAULT_DB_PATH,
|
|
136
|
+
autoCapture: cfg.autoCapture === true,
|
|
137
|
+
autoRecall: cfg.autoRecall !== false,
|
|
138
|
+
captureMaxChars,
|
|
139
|
+
...customTriggers ? { customTriggers } : {},
|
|
140
|
+
recallMaxChars,
|
|
141
|
+
...storageOptions ? { storageOptions } : {}
|
|
142
|
+
};
|
|
143
|
+
} };
|
|
213
144
|
//#endregion
|
|
214
145
|
export { DEFAULT_CAPTURE_MAX_CHARS, DEFAULT_RECALL_MAX_CHARS, MEMORY_CATEGORIES, memoryConfigSchema, vectorDimsForModel };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MEMORY_AGENT_ID_COLUMN, MEMORY_TABLE_NAME, hasAgentScopeColumn, memoryAgentPredicate, quoteLanceSqlString } from "./lancedb-schema.js";
|
|
2
|
-
import {
|
|
2
|
+
import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { resolveDefaultAgentId } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
7
8
|
//#region extensions/memory-lancedb/doctor-contract-api.ts
|
|
8
9
|
const LEGACY_ENVELOPE_DELETE_BATCH_SIZE = 500;
|
|
9
10
|
const LEGACY_ENVELOPE_SENTINEL_LINE_RE = new RegExp(`^(?:${[
|
|
@@ -37,14 +38,11 @@ function resolveMemoryLanceDbPluginRoot(moduleUrl) {
|
|
|
37
38
|
return path.basename(artifactDir) === "dist" ? path.dirname(artifactDir) : artifactDir;
|
|
38
39
|
}
|
|
39
40
|
const DEFAULT_PLUGIN_ROOT = resolveMemoryLanceDbPluginRoot(import.meta.url);
|
|
40
|
-
function asRecord(value) {
|
|
41
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
42
|
-
}
|
|
43
41
|
function resolveHome(env) {
|
|
44
42
|
return env.HOME?.trim() || os.homedir();
|
|
45
43
|
}
|
|
46
44
|
function resolveConfiguredDbPath(config, env, pluginRoot) {
|
|
47
|
-
const pluginConfig =
|
|
45
|
+
const pluginConfig = asOptionalRecord(config.plugins?.entries?.["memory-lancedb"]?.config);
|
|
48
46
|
const configured = typeof pluginConfig?.dbPath === "string" ? pluginConfig.dbPath.trim() : "";
|
|
49
47
|
if (!configured) return path.join(resolveHome(env), ".openclaw", "memory", "lancedb");
|
|
50
48
|
if (configured.includes("://")) return configured;
|
|
@@ -52,7 +50,7 @@ function resolveConfiguredDbPath(config, env, pluginRoot) {
|
|
|
52
50
|
return path.resolve(pluginRoot, configured);
|
|
53
51
|
}
|
|
54
52
|
function resolveStorageOptions(config, env) {
|
|
55
|
-
const rawOptions =
|
|
53
|
+
const rawOptions = asOptionalRecord(asOptionalRecord(config.plugins?.entries?.["memory-lancedb"]?.config)?.storageOptions);
|
|
56
54
|
if (!rawOptions) return;
|
|
57
55
|
return Object.fromEntries(Object.entries(rawOptions).map(([key, value]) => {
|
|
58
56
|
if (typeof value !== "string") throw new Error(`memory-lancedb storageOptions.${key} must be a string`);
|
package/dist/embeddings.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import { formatErrorMessage, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
1
2
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
3
|
+
import { normalizeAgentId } from "openclaw/plugin-sdk/routing";
|
|
2
4
|
import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
5
|
+
import { resolve } from "node:path";
|
|
3
6
|
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
|
|
4
7
|
import { Buffer } from "node:buffer";
|
|
5
|
-
import { toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
6
8
|
import { resolveGlobalSingleton } from "openclaw/plugin-sdk/global-singleton";
|
|
7
9
|
import { canonicalizeBase64 } from "openclaw/plugin-sdk/media-runtime";
|
|
8
10
|
import { ensureGlobalUndiciEnvProxyDispatcher } from "openclaw/plugin-sdk/runtime-env";
|
|
9
11
|
//#region extensions/memory-lancedb/embeddings.ts
|
|
10
12
|
const loadOpenAiModule = createLazyRuntimeModule(() => import("openai"));
|
|
11
13
|
const loadMemoryEmbeddingProviderModule = createLazyRuntimeModule(() => import("openclaw/plugin-sdk/memory-core-host-engine-embeddings"));
|
|
12
|
-
const loadMemoryHostCoreModule = createLazyRuntimeModule(() => import("openclaw/plugin-sdk/memory-host-core"));
|
|
13
14
|
const PROVIDER_ADAPTER_LIFECYCLE = resolveGlobalSingleton(Symbol.for("openclaw.memoryLanceDbEmbeddingProviderLifecycle.v1"), () => ({
|
|
14
15
|
retainedProviders: /* @__PURE__ */ new Set(),
|
|
15
16
|
tail: Promise.resolve()
|
|
@@ -40,7 +41,7 @@ var OpenAiCompatibleEmbeddings = class {
|
|
|
40
41
|
baseURL: baseUrl
|
|
41
42
|
}));
|
|
42
43
|
}
|
|
43
|
-
async embed(text, options) {
|
|
44
|
+
async embed(_agentId, text, options) {
|
|
44
45
|
const dimensions = this.dimensions;
|
|
45
46
|
const startedAtMs = options?.timeoutMs && Number.isFinite(options.timeoutMs) ? Date.now() : null;
|
|
46
47
|
try {
|
|
@@ -112,17 +113,51 @@ var ProviderAdapterEmbeddings = class {
|
|
|
112
113
|
constructor(api, embedding) {
|
|
113
114
|
this.api = api;
|
|
114
115
|
this.embedding = embedding;
|
|
116
|
+
this.providers = /* @__PURE__ */ new Map();
|
|
115
117
|
this.closePromise = null;
|
|
116
118
|
this.closed = false;
|
|
117
119
|
this.activeUses = 0;
|
|
118
120
|
this.idleWaiters = /* @__PURE__ */ new Set();
|
|
119
121
|
}
|
|
120
|
-
getProvider() {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
getProvider(agentId) {
|
|
123
|
+
const config = this.api.runtime.config?.current?.() ?? this.api.config;
|
|
124
|
+
const agentDir = this.api.runtime.agent.resolveAgentDir(config, agentId);
|
|
125
|
+
const existing = this.providers.get(agentId);
|
|
126
|
+
if (existing?.config === config && existing.agentDir === agentDir) return existing;
|
|
127
|
+
if (existing) {
|
|
128
|
+
this.providers.delete(agentId);
|
|
129
|
+
this.retireProvider(existing);
|
|
130
|
+
}
|
|
131
|
+
const entry = {
|
|
132
|
+
config,
|
|
133
|
+
agentDir,
|
|
134
|
+
promise: this.createProvider(config, agentDir).catch((err) => {
|
|
135
|
+
if (this.providers.get(agentId) === entry) this.providers.delete(agentId);
|
|
136
|
+
throw err;
|
|
137
|
+
}),
|
|
138
|
+
activeUses: 0,
|
|
139
|
+
idleWaiters: /* @__PURE__ */ new Set()
|
|
140
|
+
};
|
|
141
|
+
this.providers.set(agentId, entry);
|
|
142
|
+
return entry;
|
|
143
|
+
}
|
|
144
|
+
retireProvider(entry) {
|
|
145
|
+
runProviderAdapterLifecycle(async () => {
|
|
146
|
+
if (entry.activeUses > 0) await new Promise((resolve) => {
|
|
147
|
+
entry.idleWaiters.add(resolve);
|
|
148
|
+
});
|
|
149
|
+
const provider = await entry.promise.catch(() => null);
|
|
150
|
+
if (provider) PROVIDER_ADAPTER_LIFECYCLE.retainedProviders.add(provider);
|
|
151
|
+
await drainRetainedProviders();
|
|
152
|
+
}).catch(() => void 0);
|
|
153
|
+
}
|
|
154
|
+
invalidateProvidersForAuthMutation(event) {
|
|
155
|
+
const changedAgentDir = event.agentDir ? resolve(event.agentDir) : void 0;
|
|
156
|
+
for (const [agentId, entry] of this.providers) {
|
|
157
|
+
if (!event.affectsInheritedStores && resolve(entry.agentDir) !== changedAgentDir) continue;
|
|
158
|
+
this.providers.delete(agentId);
|
|
159
|
+
this.retireProvider(entry);
|
|
160
|
+
}
|
|
126
161
|
}
|
|
127
162
|
acquireUse() {
|
|
128
163
|
if (this.closed) throw new Error("memory-lancedb embeddings are closed");
|
|
@@ -145,27 +180,24 @@ var ProviderAdapterEmbeddings = class {
|
|
|
145
180
|
this.idleWaiters.add(resolve);
|
|
146
181
|
});
|
|
147
182
|
}
|
|
148
|
-
async createProvider() {
|
|
183
|
+
async createProvider(config, agentDir) {
|
|
149
184
|
return await runProviderAdapterLifecycle(async () => {
|
|
150
185
|
await drainRetainedProviders();
|
|
151
|
-
return await this.createProviderAfterRetirement();
|
|
186
|
+
return await this.createProviderAfterRetirement(config, agentDir);
|
|
152
187
|
});
|
|
153
188
|
}
|
|
154
|
-
async createProviderAfterRetirement() {
|
|
155
|
-
const cfg = this.api.runtime.config?.current?.() ?? this.api.config;
|
|
189
|
+
async createProviderAfterRetirement(config, agentDir) {
|
|
156
190
|
const providerId = this.embedding.provider;
|
|
157
|
-
const { getMemoryEmbeddingProvider } = await loadMemoryEmbeddingProviderModule();
|
|
158
|
-
|
|
191
|
+
const { getMemoryEmbeddingProvider, registerRuntimeAuthProfileStoreMutationListener } = await loadMemoryEmbeddingProviderModule();
|
|
192
|
+
if (!this.closed && !this.unregisterAuthMutationListener) this.unregisterAuthMutationListener = registerRuntimeAuthProfileStoreMutationListener((event) => this.invalidateProvidersForAuthMutation(event));
|
|
193
|
+
const adapter = getMemoryEmbeddingProvider(providerId, config);
|
|
159
194
|
if (!adapter) throw new Error(`Unknown memory embedding provider: ${providerId}`);
|
|
160
|
-
const { resolveDefaultAgentId } = await loadMemoryHostCoreModule();
|
|
161
|
-
const defaultAgentId = resolveDefaultAgentId(cfg);
|
|
162
|
-
const agentDir = this.api.runtime.agent.resolveAgentDir(cfg, defaultAgentId);
|
|
163
195
|
const remote = this.embedding.apiKey || this.embedding.baseUrl ? {
|
|
164
196
|
...this.embedding.apiKey ? { apiKey: this.embedding.apiKey } : {},
|
|
165
197
|
...this.embedding.baseUrl ? { baseUrl: this.embedding.baseUrl } : {}
|
|
166
198
|
} : void 0;
|
|
167
199
|
const result = await adapter.create({
|
|
168
|
-
config
|
|
200
|
+
config,
|
|
169
201
|
agentDir,
|
|
170
202
|
provider: providerId,
|
|
171
203
|
fallback: "none",
|
|
@@ -176,19 +208,30 @@ var ProviderAdapterEmbeddings = class {
|
|
|
176
208
|
if (!result.provider) throw new Error(`Memory embedding provider ${providerId} is unavailable.`);
|
|
177
209
|
return result.provider;
|
|
178
210
|
}
|
|
179
|
-
async embed(text, options) {
|
|
211
|
+
async embed(agentId, text, options) {
|
|
180
212
|
const releaseUse = this.acquireUse();
|
|
181
213
|
try {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
const controller = new AbortController();
|
|
185
|
-
let timer;
|
|
214
|
+
const entry = this.getProvider(normalizeAgentId(agentId));
|
|
215
|
+
entry.activeUses += 1;
|
|
186
216
|
try {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
217
|
+
const provider = await entry.promise;
|
|
218
|
+
if (!options?.timeoutMs) return await provider.embedQuery(text);
|
|
219
|
+
const controller = new AbortController();
|
|
220
|
+
let timer;
|
|
221
|
+
try {
|
|
222
|
+
timer = setTimeout(() => controller.abort(/* @__PURE__ */ new Error("memory-lancedb embedding timed out")), resolveTimerTimeoutMs(options.timeoutMs, 1));
|
|
223
|
+
timer.unref?.();
|
|
224
|
+
return await provider.embedQuery(text, { signal: controller.signal });
|
|
225
|
+
} finally {
|
|
226
|
+
if (timer) clearTimeout(timer);
|
|
227
|
+
}
|
|
190
228
|
} finally {
|
|
191
|
-
|
|
229
|
+
entry.activeUses -= 1;
|
|
230
|
+
if (entry.activeUses === 0) {
|
|
231
|
+
const waiters = Array.from(entry.idleWaiters);
|
|
232
|
+
entry.idleWaiters.clear();
|
|
233
|
+
for (const resolve of waiters) resolve();
|
|
234
|
+
}
|
|
192
235
|
}
|
|
193
236
|
} finally {
|
|
194
237
|
releaseUse();
|
|
@@ -211,15 +254,19 @@ var ProviderAdapterEmbeddings = class {
|
|
|
211
254
|
}
|
|
212
255
|
async closeOnce() {
|
|
213
256
|
this.closed = true;
|
|
214
|
-
|
|
257
|
+
this.unregisterAuthMutationListener?.();
|
|
258
|
+
this.unregisterAuthMutationListener = void 0;
|
|
259
|
+
const providers = Array.from(this.providers.entries());
|
|
215
260
|
await runProviderAdapterLifecycle(async () => {
|
|
216
261
|
await this.awaitIdle();
|
|
217
|
-
const
|
|
218
|
-
|
|
262
|
+
for (const [, entry] of providers) {
|
|
263
|
+
const provider = await entry.promise.catch(() => null);
|
|
264
|
+
if (provider) PROVIDER_ADAPTER_LIFECYCLE.retainedProviders.add(provider);
|
|
265
|
+
}
|
|
219
266
|
try {
|
|
220
267
|
await drainRetainedProviders();
|
|
221
268
|
} finally {
|
|
222
|
-
if (this.
|
|
269
|
+
for (const [agentId, entry] of providers) if (this.providers.get(agentId) === entry) this.providers.delete(agentId);
|
|
223
270
|
}
|
|
224
271
|
});
|
|
225
272
|
}
|
|
@@ -244,9 +291,6 @@ async function runWithTimeout(params) {
|
|
|
244
291
|
if (timeout) clearTimeout(timeout);
|
|
245
292
|
}
|
|
246
293
|
}
|
|
247
|
-
function formatMemoryRecallError(error) {
|
|
248
|
-
return error instanceof Error ? error.message : String(error);
|
|
249
|
-
}
|
|
250
294
|
function isMemoryRecallTimeoutError(error) {
|
|
251
295
|
let current = error;
|
|
252
296
|
for (let depth = 0; depth < 3 && current !== void 0; depth += 1) {
|
|
@@ -275,7 +319,7 @@ function buildMemoryRecallUnavailableResult(error) {
|
|
|
275
319
|
}
|
|
276
320
|
var MemoryRecallEmbeddingError = class extends Error {
|
|
277
321
|
constructor(originalError) {
|
|
278
|
-
super(
|
|
322
|
+
super(formatErrorMessage(originalError));
|
|
279
323
|
this.originalError = originalError;
|
|
280
324
|
this.name = "MemoryRecallEmbeddingError";
|
|
281
325
|
}
|
|
@@ -309,4 +353,4 @@ function normalizeEmbeddingVector(value) {
|
|
|
309
353
|
throw new Error("Embedding response is missing a vector");
|
|
310
354
|
}
|
|
311
355
|
//#endregion
|
|
312
|
-
export { MemoryRecallEmbeddingError, buildMemoryRecallUnavailableResult, createEmbeddings,
|
|
356
|
+
export { MemoryRecallEmbeddingError, buildMemoryRecallUnavailableResult, createEmbeddings, isMemoryRecallTimeoutError, normalizeEmbeddingVector, runWithTimeout, testing };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { definePluginEntry } from "./api.js";
|
|
2
2
|
import { MEMORY_CATEGORIES, memoryConfigSchema, vectorDimsForModel } from "./config.js";
|
|
3
|
-
import { MemoryRecallEmbeddingError, buildMemoryRecallUnavailableResult, createEmbeddings,
|
|
3
|
+
import { MemoryRecallEmbeddingError, buildMemoryRecallUnavailableResult, createEmbeddings, isMemoryRecallTimeoutError, normalizeEmbeddingVector, runWithTimeout, testing } from "./embeddings.js";
|
|
4
4
|
import { MemoryDB } from "./lancedb-store.js";
|
|
5
5
|
import { dropMediaNoteLines, looksLikeEnvelopeSludge, sanitizeForMemoryCapture } from "./memory-capture-sanitization.js";
|
|
6
6
|
import { cleanMemorySearchResults, detectCategory, escapeMemoryForPrompt, extractLatestUserText, extractUserTextContent, findCleanDuplicateMemory, formatRelevantMemoriesContext, looksLikePromptInjection, messageFingerprint, normalizeRecallQuery, resolveAutoCaptureStartIndex, shouldCapture } from "./memory-policy.js";
|
|
7
7
|
import { parseMemoryCliFilter, registerMemoryCli } from "./memory-cli.js";
|
|
8
8
|
import { resolveAgentConfig, resolveDefaultAgentId } from "openclaw/plugin-sdk/agent-runtime";
|
|
9
9
|
import { optionalFiniteNumberSchema, optionalPositiveIntegerSchema } from "openclaw/plugin-sdk/channel-actions";
|
|
10
|
+
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
10
11
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
11
12
|
import { readFiniteNumberParam, readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
|
|
12
13
|
import { resolveLivePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime";
|
|
@@ -132,7 +133,7 @@ var memory_lancedb_default = definePluginEntry({
|
|
|
132
133
|
task: async () => {
|
|
133
134
|
let vector;
|
|
134
135
|
try {
|
|
135
|
-
vector = await embeddings.embed(normalizeRecallQuery(query, currentCfg.recallMaxChars), { timeoutMs: DEFAULT_TOOL_RECALL_TIMEOUT_MS });
|
|
136
|
+
vector = await embeddings.embed(agentId, normalizeRecallQuery(query, currentCfg.recallMaxChars), { timeoutMs: DEFAULT_TOOL_RECALL_TIMEOUT_MS });
|
|
136
137
|
} catch (error) {
|
|
137
138
|
throw new MemoryRecallEmbeddingError(error);
|
|
138
139
|
}
|
|
@@ -142,7 +143,7 @@ var memory_lancedb_default = definePluginEntry({
|
|
|
142
143
|
});
|
|
143
144
|
} catch (error) {
|
|
144
145
|
if (!(error instanceof MemoryRecallEmbeddingError)) throw error;
|
|
145
|
-
const message =
|
|
146
|
+
const message = formatErrorMessage(error.originalError);
|
|
146
147
|
if (isMemoryRecallTimeoutError(error.originalError)) recordMemoryRecallCooldown(agentId, message);
|
|
147
148
|
api.logger.warn?.(`memory-lancedb: memory_recall failed: ${message}; returning unavailable memory result`);
|
|
148
149
|
return buildMemoryRecallUnavailableResult(message);
|
|
@@ -227,7 +228,7 @@ var memory_lancedb_default = definePluginEntry({
|
|
|
227
228
|
reason: "prompt_injection_detected"
|
|
228
229
|
}
|
|
229
230
|
};
|
|
230
|
-
const vector = await embeddings.embed(text);
|
|
231
|
+
const vector = await embeddings.embed(agentId, text);
|
|
231
232
|
const existing = await findCleanDuplicateMemory(db, agentId, vector);
|
|
232
233
|
if (existing) return {
|
|
233
234
|
content: [{
|
|
@@ -296,7 +297,7 @@ var memory_lancedb_default = definePluginEntry({
|
|
|
296
297
|
}
|
|
297
298
|
if (query) {
|
|
298
299
|
const currentCfg = resolveCurrentHookConfig();
|
|
299
|
-
const vector = await embeddings.embed(normalizeRecallQuery(query, currentCfg.recallMaxChars));
|
|
300
|
+
const vector = await embeddings.embed(agentId, normalizeRecallQuery(query, currentCfg.recallMaxChars));
|
|
300
301
|
const results = await db.search(agentId, vector, 5, .7);
|
|
301
302
|
if (results.length === 0) return {
|
|
302
303
|
content: [{
|
|
@@ -368,7 +369,7 @@ var memory_lancedb_default = definePluginEntry({
|
|
|
368
369
|
task: async () => {
|
|
369
370
|
let vector;
|
|
370
371
|
try {
|
|
371
|
-
vector = await embeddings.embed(recallQuery, { timeoutMs: DEFAULT_AUTO_RECALL_TIMEOUT_MS });
|
|
372
|
+
vector = await embeddings.embed(agentId, recallQuery, { timeoutMs: DEFAULT_AUTO_RECALL_TIMEOUT_MS });
|
|
372
373
|
} catch (error) {
|
|
373
374
|
throw new MemoryRecallEmbeddingError(error);
|
|
374
375
|
}
|
|
@@ -391,7 +392,7 @@ var memory_lancedb_default = definePluginEntry({
|
|
|
391
392
|
if (!context) return;
|
|
392
393
|
return { prependContext: context };
|
|
393
394
|
} catch (err) {
|
|
394
|
-
if (err instanceof MemoryRecallEmbeddingError && isMemoryRecallTimeoutError(err.originalError)) recordMemoryRecallCooldown(agentId,
|
|
395
|
+
if (err instanceof MemoryRecallEmbeddingError && isMemoryRecallTimeoutError(err.originalError)) recordMemoryRecallCooldown(agentId, formatErrorMessage(err.originalError));
|
|
395
396
|
api.logger.warn(`memory-lancedb: recall failed: ${String(err)}`);
|
|
396
397
|
}
|
|
397
398
|
});
|
|
@@ -420,7 +421,7 @@ var memory_lancedb_default = definePluginEntry({
|
|
|
420
421
|
capturableSeen++;
|
|
421
422
|
if (capturableSeen > 3) continue;
|
|
422
423
|
const category = detectCategory(sanitized);
|
|
423
|
-
const vector = await embeddings.embed(sanitized);
|
|
424
|
+
const vector = await embeddings.embed(agentId, sanitized);
|
|
424
425
|
if (await findCleanDuplicateMemory(db, agentId, vector)) continue;
|
|
425
426
|
await db.store(agentId, {
|
|
426
427
|
text: sanitized,
|
package/dist/memory-cli.js
CHANGED
|
@@ -65,8 +65,8 @@ function registerMemoryCli(api, db, embeddings, resolveCliAgentId, recallMaxChar
|
|
|
65
65
|
let operationFailed = false;
|
|
66
66
|
try {
|
|
67
67
|
const agentId = resolveCliAgentId(opts.agent);
|
|
68
|
-
const vector = await embeddings.embed(normalizeRecallQuery(query, recallMaxChars));
|
|
69
68
|
const limit = parsePositiveIntegerOption(opts.limit, "--limit");
|
|
69
|
+
const vector = await embeddings.embed(agentId, normalizeRecallQuery(query, recallMaxChars));
|
|
70
70
|
const output = (await db.search(agentId, vector, limit, .3)).map((r) => ({
|
|
71
71
|
id: r.entry.id,
|
|
72
72
|
text: r.entry.text,
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "memory-lancedb",
|
|
3
|
+
"doctorContract": {
|
|
4
|
+
"stateMigrations": true
|
|
5
|
+
},
|
|
3
6
|
"name": "Memory LanceDB",
|
|
4
7
|
"description": "OpenClaw LanceDB-backed long-term memory plugin with auto-recall, auto-capture, and vector search.",
|
|
5
8
|
"catalog": { "featured": true, "order": 70 },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/memory-lancedb",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.8.1-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",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"minHostVersion": ">=2026.5.31"
|
|
27
27
|
},
|
|
28
28
|
"compat": {
|
|
29
|
-
"pluginApi": ">=2026.
|
|
29
|
+
"pluginApi": ">=2026.8.1-beta.2"
|
|
30
30
|
},
|
|
31
31
|
"build": {
|
|
32
|
-
"openclawVersion": "2026.
|
|
32
|
+
"openclawVersion": "2026.8.1-beta.2"
|
|
33
33
|
},
|
|
34
34
|
"release": {
|
|
35
35
|
"bundleRuntimeDependencies": false,
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"README.md"
|
|
47
47
|
],
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"openclaw": ">=2026.
|
|
49
|
+
"openclaw": ">=2026.8.1-beta.2"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"openclaw": {
|