openclaw-memory-alibaba-mysql 0.2.2 → 0.2.4
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/config.ts +14 -36
- package/db.ts +1 -15
- package/index.ts +0 -4
- package/openclaw.plugin.json +2 -2
- package/package.json +1 -1
package/config.ts
CHANGED
|
@@ -59,7 +59,7 @@ export type { MemoryCategory };
|
|
|
59
59
|
const DEFAULT_MODEL = "text-embedding-v3";
|
|
60
60
|
const DEFAULT_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1";
|
|
61
61
|
const DEFAULT_TABLE_NAME = "openclaw_memories";
|
|
62
|
-
export const DEFAULT_CAPTURE_MAX_CHARS =
|
|
62
|
+
export const DEFAULT_CAPTURE_MAX_CHARS = 50000;
|
|
63
63
|
|
|
64
64
|
const EMBEDDING_DIMENSIONS: Record<string, number> = {
|
|
65
65
|
"text-embedding-v3": 1024,
|
|
@@ -114,66 +114,43 @@ function assertAllowedKeys(value: Record<string, unknown>, allowed: string[], la
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
function requireString(obj: Record<string, unknown>, key: string, label: string
|
|
117
|
+
function requireString(obj: Record<string, unknown>, key: string, label: string): string {
|
|
118
118
|
const v = obj[key];
|
|
119
|
-
if (typeof v !== "string") {
|
|
120
|
-
throw new Error(`${label}.${key} is required and must be a string`);
|
|
121
|
-
}
|
|
122
|
-
if (!allowEmpty && v.length === 0) {
|
|
119
|
+
if (typeof v !== "string" || v.length === 0) {
|
|
123
120
|
throw new Error(`${label}.${key} is required and must be a non-empty string`);
|
|
124
121
|
}
|
|
125
122
|
return v;
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
function parseMysqlConfig(raw: unknown): MysqlConnectionConfig {
|
|
129
|
-
// Allow empty mysql config - will be validated at connection time
|
|
130
126
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
131
|
-
|
|
132
|
-
host: "",
|
|
133
|
-
port: 3306,
|
|
134
|
-
user: "",
|
|
135
|
-
password: "",
|
|
136
|
-
database: "openclaw_memory",
|
|
137
|
-
ssl: false,
|
|
138
|
-
};
|
|
127
|
+
throw new Error("mysql config is required");
|
|
139
128
|
}
|
|
140
129
|
const m = raw as Record<string, unknown>;
|
|
141
130
|
assertAllowedKeys(m, ["host", "port", "user", "password", "database", "ssl"], "mysql");
|
|
142
131
|
|
|
143
|
-
const host = typeof m.host === "string" ? m.host : "";
|
|
144
|
-
const user = typeof m.user === "string" ? m.user : "";
|
|
145
|
-
const password = typeof m.password === "string" ? resolveEnvVars(m.password) : "";
|
|
146
|
-
const database = typeof m.database === "string" ? m.database : "openclaw_memory";
|
|
147
|
-
|
|
148
132
|
return {
|
|
149
|
-
host,
|
|
133
|
+
host: requireString(m, "host", "mysql"),
|
|
150
134
|
port: typeof m.port === "number" ? m.port : 3306,
|
|
151
|
-
user,
|
|
152
|
-
password,
|
|
153
|
-
database,
|
|
135
|
+
user: requireString(m, "user", "mysql"),
|
|
136
|
+
password: resolveEnvVars(requireString(m, "password", "mysql")),
|
|
137
|
+
database: requireString(m, "database", "mysql"),
|
|
154
138
|
ssl: m.ssl === true,
|
|
155
139
|
};
|
|
156
140
|
}
|
|
157
141
|
|
|
158
142
|
function parseEmbeddingConfig(raw: unknown): EmbeddingConfig {
|
|
159
|
-
// Allow empty embedding config - will be validated at connection time
|
|
160
143
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
161
|
-
|
|
162
|
-
apiKey: "",
|
|
163
|
-
model: DEFAULT_MODEL,
|
|
164
|
-
baseUrl: DEFAULT_BASE_URL,
|
|
165
|
-
dimensions: undefined,
|
|
166
|
-
};
|
|
144
|
+
throw new Error("embedding config is required");
|
|
167
145
|
}
|
|
168
146
|
const e = raw as Record<string, unknown>;
|
|
169
147
|
assertAllowedKeys(e, ["apiKey", "model", "baseUrl", "dimensions"], "embedding");
|
|
170
148
|
|
|
171
149
|
const model = typeof e.model === "string" ? e.model : DEFAULT_MODEL;
|
|
172
150
|
const explicitDims = typeof e.dimensions === "number" ? e.dimensions : undefined;
|
|
173
|
-
const apiKey = typeof e.apiKey === "string" ? resolveEnvVars(e.apiKey) : "";
|
|
174
151
|
|
|
175
152
|
return {
|
|
176
|
-
apiKey,
|
|
153
|
+
apiKey: resolveEnvVars(requireString(e, "apiKey", "embedding")),
|
|
177
154
|
model,
|
|
178
155
|
baseUrl: typeof e.baseUrl === "string" ? resolveEnvVars(e.baseUrl) : DEFAULT_BASE_URL,
|
|
179
156
|
dimensions: explicitDims,
|
|
@@ -197,8 +174,9 @@ function parseLLMConfig(raw: unknown): LLMConfig {
|
|
|
197
174
|
|
|
198
175
|
export const memoryConfigSchema = {
|
|
199
176
|
parse(value: unknown): MemoryConfig {
|
|
177
|
+
// Allow empty config during plugin registration
|
|
200
178
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
201
|
-
|
|
179
|
+
value = {};
|
|
202
180
|
}
|
|
203
181
|
const cfg = value as Record<string, unknown>;
|
|
204
182
|
|
|
@@ -264,8 +242,8 @@ export const memoryConfigSchema = {
|
|
|
264
242
|
|
|
265
243
|
const captureMaxChars =
|
|
266
244
|
typeof cfg.captureMaxChars === "number" ? Math.floor(cfg.captureMaxChars) : undefined;
|
|
267
|
-
if (typeof captureMaxChars === "number" && (captureMaxChars < 100 || captureMaxChars >
|
|
268
|
-
throw new Error("captureMaxChars must be between 100 and
|
|
245
|
+
if (typeof captureMaxChars === "number" && (captureMaxChars < 100 || captureMaxChars > 100_000)) {
|
|
246
|
+
throw new Error("captureMaxChars must be between 100 and 100000");
|
|
269
247
|
}
|
|
270
248
|
|
|
271
249
|
// --- Memory decay: only enableMemoryDecay is configurable; half-life and strategy use defaults ---
|
package/db.ts
CHANGED
|
@@ -51,20 +51,6 @@ export class MemoryDB {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
private async doInitialize(): Promise<void> {
|
|
54
|
-
// Validate MySQL config before connecting
|
|
55
|
-
if (!this.mysqlConfig.host || this.mysqlConfig.host.length === 0) {
|
|
56
|
-
throw new Error("MySQL host is not configured. Please set mysql.host in the plugin config.");
|
|
57
|
-
}
|
|
58
|
-
if (!this.mysqlConfig.user || this.mysqlConfig.user.length === 0) {
|
|
59
|
-
throw new Error("MySQL user is not configured. Please set mysql.user in the plugin config.");
|
|
60
|
-
}
|
|
61
|
-
if (!this.mysqlConfig.password || this.mysqlConfig.password.length === 0) {
|
|
62
|
-
throw new Error("MySQL password is not configured. Please set mysql.password in the plugin config.");
|
|
63
|
-
}
|
|
64
|
-
if (!this.mysqlConfig.database || this.mysqlConfig.database.length === 0) {
|
|
65
|
-
throw new Error("MySQL database is not configured. Please set mysql.database in the plugin config.");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
54
|
this.pool = mysql.createPool({
|
|
69
55
|
host: this.mysqlConfig.host,
|
|
70
56
|
port: this.mysqlConfig.port,
|
|
@@ -86,7 +72,7 @@ export class MemoryDB {
|
|
|
86
72
|
agent_id VARCHAR(128) NOT NULL,
|
|
87
73
|
user_id VARCHAR(128) NULL DEFAULT NULL,
|
|
88
74
|
session_id VARCHAR(128) NULL DEFAULT NULL,
|
|
89
|
-
text
|
|
75
|
+
text LONGTEXT NOT NULL,
|
|
90
76
|
embedding VECTOR(${this.vectorDim}) NOT NULL,
|
|
91
77
|
importance FLOAT DEFAULT 0,
|
|
92
78
|
category VARCHAR(64) DEFAULT '${USER_MEMORY_FACT}',
|
package/index.ts
CHANGED
|
@@ -81,10 +81,6 @@ class Embeddings {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
async embed(text: string): Promise<number[]> {
|
|
84
|
-
// Validate API key before making request
|
|
85
|
-
if (!this.client.apiKey || this.client.apiKey.length === 0) {
|
|
86
|
-
throw new Error("Embedding API key is not configured. Please set embedding.apiKey in the plugin config.");
|
|
87
|
-
}
|
|
88
84
|
const params: { model: string; input: string; dimensions?: number } = {
|
|
89
85
|
model: this.model,
|
|
90
86
|
input: text,
|
package/openclaw.plugin.json
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"autoRecall": { "type": "boolean", "default": true },
|
|
68
68
|
"autoCapture": { "type": "boolean", "default": true },
|
|
69
|
-
"captureMaxChars": { "type": "number", "default":
|
|
69
|
+
"captureMaxChars": { "type": "number", "default": 50000 },
|
|
70
70
|
"enableMemoryDecay": {
|
|
71
71
|
"type": "boolean",
|
|
72
72
|
"default": false,
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
"captureMaxChars": {
|
|
177
177
|
"label": "Capture Max Chars",
|
|
178
178
|
"placeholder": "500",
|
|
179
|
-
"help": "Max length per captured memory (100–
|
|
179
|
+
"help": "Max length per captured memory (100–100000)"
|
|
180
180
|
},
|
|
181
181
|
"enableMemoryDecay": {
|
|
182
182
|
"label": "Enable Memory Decay",
|