openclaw-memory-alibaba-mysql 0.2.2 → 0.2.3
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 +11 -33
- package/db.ts +0 -14
- package/index.ts +0 -4
- package/package.json +1 -1
package/config.ts
CHANGED
|
@@ -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
|
|
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,
|
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,
|