openclaw-memory-alibaba-mysql 0.2.1 → 0.2.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.
Files changed (4) hide show
  1. package/config.ts +32 -9
  2. package/db.ts +14 -0
  3. package/index.ts +4 -0
  4. package/package.json +1 -1
package/config.ts CHANGED
@@ -114,43 +114,66 @@ 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): string {
117
+ function requireString(obj: Record<string, unknown>, key: string, label: string, allowEmpty = false): string {
118
118
  const v = obj[key];
119
- if (typeof v !== "string" || v.length === 0) {
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) {
120
123
  throw new Error(`${label}.${key} is required and must be a non-empty string`);
121
124
  }
122
125
  return v;
123
126
  }
124
127
 
125
128
  function parseMysqlConfig(raw: unknown): MysqlConnectionConfig {
129
+ // Allow empty mysql config - will be validated at connection time
126
130
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
127
- throw new Error("mysql config is required");
131
+ return {
132
+ host: "",
133
+ port: 3306,
134
+ user: "",
135
+ password: "",
136
+ database: "openclaw_memory",
137
+ ssl: false,
138
+ };
128
139
  }
129
140
  const m = raw as Record<string, unknown>;
130
141
  assertAllowedKeys(m, ["host", "port", "user", "password", "database", "ssl"], "mysql");
131
142
 
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
+
132
148
  return {
133
- host: requireString(m, "host", "mysql"),
149
+ host,
134
150
  port: typeof m.port === "number" ? m.port : 3306,
135
- user: requireString(m, "user", "mysql"),
136
- password: resolveEnvVars(requireString(m, "password", "mysql")),
137
- database: requireString(m, "database", "mysql"),
151
+ user,
152
+ password,
153
+ database,
138
154
  ssl: m.ssl === true,
139
155
  };
140
156
  }
141
157
 
142
158
  function parseEmbeddingConfig(raw: unknown): EmbeddingConfig {
159
+ // Allow empty embedding config - will be validated at connection time
143
160
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
144
- throw new Error("embedding config is required");
161
+ return {
162
+ apiKey: "",
163
+ model: DEFAULT_MODEL,
164
+ baseUrl: DEFAULT_BASE_URL,
165
+ dimensions: undefined,
166
+ };
145
167
  }
146
168
  const e = raw as Record<string, unknown>;
147
169
  assertAllowedKeys(e, ["apiKey", "model", "baseUrl", "dimensions"], "embedding");
148
170
 
149
171
  const model = typeof e.model === "string" ? e.model : DEFAULT_MODEL;
150
172
  const explicitDims = typeof e.dimensions === "number" ? e.dimensions : undefined;
173
+ const apiKey = typeof e.apiKey === "string" ? resolveEnvVars(e.apiKey) : "";
151
174
 
152
175
  return {
153
- apiKey: resolveEnvVars(requireString(e, "apiKey", "embedding")),
176
+ apiKey,
154
177
  model,
155
178
  baseUrl: typeof e.baseUrl === "string" ? resolveEnvVars(e.baseUrl) : DEFAULT_BASE_URL,
156
179
  dimensions: explicitDims,
package/db.ts CHANGED
@@ -51,6 +51,20 @@ 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
+
54
68
  this.pool = mysql.createPool({
55
69
  host: this.mysqlConfig.host,
56
70
  port: this.mysqlConfig.port,
package/index.ts CHANGED
@@ -81,6 +81,10 @@ 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
+ }
84
88
  const params: { model: string; input: string; dimensions?: number } = {
85
89
  model: this.model,
86
90
  input: text,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-memory-alibaba-mysql",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "OpenClaw memory plugin using Alibaba Cloud RDS MySQL vector storage",
5
5
  "type": "module",
6
6
  "license": "MIT",