@mastra/mysql 0.8.2 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/mysql
2
2
 
3
+ ## 0.8.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Add an optional bounded description field to knowledge nodes across storage adapters, written through a dedicated curator tool. Part of an unreleased experimental memory feature. ([#21830](https://github.com/mastra-ai/mastra/pull/21830))
8
+
9
+ - Updated dependencies [[`bae1502`](https://github.com/mastra-ai/mastra/commit/bae150254b06a4da6964d7c137af97f336362359), [`0885364`](https://github.com/mastra-ai/mastra/commit/0885364c2fc7fa31febcfc444fc1ba5231ac1257), [`b8cb683`](https://github.com/mastra-ai/mastra/commit/b8cb683ba66499df254ddd1f7edd8cae3f89d2e7), [`078affd`](https://github.com/mastra-ai/mastra/commit/078affdaea57ac5e95a77e9e7b197d1878190684), [`9e3403e`](https://github.com/mastra-ai/mastra/commit/9e3403e9868240cb18841898e84cf008ebd7a87e), [`791bf5e`](https://github.com/mastra-ai/mastra/commit/791bf5e81cd27e2e1cff66122f1380ab8a3dda41)]:
10
+ - @mastra/core@1.63.1
11
+
12
+ ## 0.8.3-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Add an optional bounded description field to knowledge nodes across storage adapters, written through a dedicated curator tool. Part of an unreleased experimental memory feature. ([#21830](https://github.com/mastra-ai/mastra/pull/21830))
17
+
18
+ - Updated dependencies [[`0885364`](https://github.com/mastra-ai/mastra/commit/0885364c2fc7fa31febcfc444fc1ba5231ac1257)]:
19
+ - @mastra/core@1.63.1-alpha.2
20
+
3
21
  ## 0.8.2
4
22
 
5
23
  ### Patch Changes
package/LICENSE.md CHANGED
@@ -1,10 +1,12 @@
1
1
  Portions of this software are licensed as follows:
2
2
 
3
- - All content that resides under any directory named "ee/" within this
3
+ - All content that resides under any directory named `ee/` within this
4
4
  repository, including but not limited to:
5
- - `packages/core/src/auth/ee/`
6
- - `packages/server/src/server/auth/ee/`
7
- is licensed under the license defined in `ee/LICENSE`.
5
+ - `@mastra/core/auth/ee`
6
+ - `@mastra/core/agent-builder/ee`
7
+ - `@mastra/editor/ee`
8
+
9
+ is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
8
10
 
9
11
  - All third-party components incorporated into the Mastra Software are
10
12
  licensed under the original license provided by the owner of the
package/dist/index.cjs CHANGED
@@ -3954,6 +3954,7 @@ function parseNode(row) {
3954
3954
  name: String(row.name),
3955
3955
  kind: String(row.kind),
3956
3956
  content: row.content == null ? void 0 : String(row.content),
3957
+ description: row.description == null ? void 0 : String(row.description),
3957
3958
  scope: parseJson$1(row.scopeJson ?? row.scope),
3958
3959
  version: Number(row.version),
3959
3960
  mergedInto: row.mergedInto == null ? void 0 : String(row.mergedInto),
@@ -4053,6 +4054,11 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4053
4054
  tableName: _mastra_core_storage.TABLE_KNOWLEDGE_NODES,
4054
4055
  schema: _mastra_core_storage.KNOWLEDGE_NODES_SCHEMA
4055
4056
  });
4057
+ await this.#operations.alterTable({
4058
+ tableName: _mastra_core_storage.TABLE_KNOWLEDGE_NODES,
4059
+ schema: _mastra_core_storage.KNOWLEDGE_NODES_SCHEMA,
4060
+ ifNotExists: ["description"]
4061
+ });
4056
4062
  await this.#operations.createTable({
4057
4063
  tableName: _mastra_core_storage.TABLE_KNOWLEDGE_RECORDS,
4058
4064
  schema: _mastra_core_storage.KNOWLEDGE_RECORDS_SCHEMA
@@ -4092,6 +4098,7 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4092
4098
  });
4093
4099
  }
4094
4100
  async createNode(input) {
4101
+ (0, _mastra_core_storage.assertKnowledgeDescriptionWithinBound)(input.description);
4095
4102
  const scope = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(input.scope);
4096
4103
  return this.#transaction(async (tx) => {
4097
4104
  const existing = await this.#getNodeByName(tx, input.name, scope);
@@ -4107,13 +4114,14 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4107
4114
  name: input.name.trim(),
4108
4115
  kind: input.kind,
4109
4116
  content: input.content,
4117
+ description: input.description,
4110
4118
  scope,
4111
4119
  version: 1,
4112
4120
  createdAt: now,
4113
4121
  updatedAt: now
4114
4122
  };
4115
4123
  await tx.execute({
4116
- sql: `INSERT INTO "${_mastra_core_storage.TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
4124
+ sql: `INSERT INTO "${_mastra_core_storage.TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,description,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
4117
4125
  args: [
4118
4126
  node.id,
4119
4127
  "node",
@@ -4121,6 +4129,7 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4121
4129
  canonicalName(node.name),
4122
4130
  node.kind,
4123
4131
  node.content ?? null,
4132
+ node.description ?? null,
4124
4133
  JSON.stringify(scope),
4125
4134
  (0, _mastra_core_storage.knowledgeScopeKey)(scope),
4126
4135
  node.version,
@@ -4177,6 +4186,7 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4177
4186
  })).rows.map(parseNode);
4178
4187
  }
4179
4188
  async updateNode(input) {
4189
+ (0, _mastra_core_storage.assertKnowledgeDescriptionWithinBound)(input.description);
4180
4190
  return this.#transaction(async (tx) => {
4181
4191
  const existing = await this.#getNode(tx, input.id);
4182
4192
  if (!existing) throw new _mastra_core_storage.KnowledgeNotFoundError("node", input.id);
@@ -4184,14 +4194,16 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4184
4194
  const scope = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(input.scope ?? existing.scope);
4185
4195
  const name = (input.name ?? existing.name).trim();
4186
4196
  const content = input.content ?? existing.content;
4197
+ const description = input.description ?? existing.description;
4187
4198
  const now = /* @__PURE__ */ new Date();
4188
4199
  if ((await tx.execute({
4189
- sql: `UPDATE "${_mastra_core_storage.TABLE_KNOWLEDGE_NODES}" SET name=?,canonicalName=?,kind=?,content=?,scope=jsonb(?),scopeKey=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=?`,
4200
+ sql: `UPDATE "${_mastra_core_storage.TABLE_KNOWLEDGE_NODES}" SET name=?,canonicalName=?,kind=?,content=?,description=?,scope=jsonb(?),scopeKey=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=?`,
4190
4201
  args: [
4191
4202
  name,
4192
4203
  canonicalName(name),
4193
4204
  input.kind ?? existing.kind,
4194
4205
  content ?? null,
4206
+ description ?? null,
4195
4207
  JSON.stringify(scope),
4196
4208
  (0, _mastra_core_storage.knowledgeScopeKey)(scope),
4197
4209
  now.toISOString(),
@@ -4219,6 +4231,7 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4219
4231
  name,
4220
4232
  kind: input.kind ?? existing.kind,
4221
4233
  content,
4234
+ description,
4222
4235
  scope,
4223
4236
  version: input.version + 1,
4224
4237
  updatedAt: now
@@ -4265,10 +4278,31 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4265
4278
  });
4266
4279
  for (const row of movedFacts.rows) await this.#outbox(tx, "record", String(row.id), row.deletedAt == null ? "upsert" : "delete", (0, _mastra_core_storage.createKnowledgeUlid)(), parseJson$1(row.scopeJson));
4267
4280
  for (const row of affected.rows) await this.#outbox(tx, String(row.sourceType), String(row.sourceId), Number(row.deleted) ? "delete" : "upsert", (0, _mastra_core_storage.createKnowledgeUlid)(), parseJson$1(row.scopeJson));
4281
+ let mergedTarget = target;
4282
+ if (target.description === void 0 && source.description) {
4283
+ const adoptedAt = /* @__PURE__ */ new Date();
4284
+ if ((await tx.execute({
4285
+ sql: `UPDATE "${_mastra_core_storage.TABLE_KNOWLEDGE_NODES}" SET description=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=? AND description IS NULL`,
4286
+ args: [
4287
+ source.description,
4288
+ adoptedAt.toISOString(),
4289
+ target.id,
4290
+ target.version
4291
+ ]
4292
+ })).rowsAffected > 0) {
4293
+ mergedTarget = {
4294
+ ...target,
4295
+ description: source.description,
4296
+ version: target.version + 1,
4297
+ updatedAt: adoptedAt
4298
+ };
4299
+ await this.#activity(tx, "node-updated", "node", target.id, target.scope);
4300
+ }
4301
+ }
4268
4302
  await this.#activity(tx, "node-merged", "node", source.id, source.scope);
4269
4303
  await this.#outbox(tx, "node", source.id, "delete", input.sourceVersion + 1, source.scope);
4270
- await this.#outbox(tx, "node", target.id, "upsert", (0, _mastra_core_storage.createKnowledgeUlid)(), target.scope);
4271
- return target;
4304
+ await this.#outbox(tx, "node", target.id, "upsert", (0, _mastra_core_storage.createKnowledgeUlid)(), mergedTarget.scope);
4305
+ return mergedTarget;
4272
4306
  });
4273
4307
  }
4274
4308
  async appendKnowledge(input) {
@@ -4433,13 +4467,14 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4433
4467
  if (!normalizedQuery) return [];
4434
4468
  const query = `%${escapeLikePattern(normalizedQuery)}%`;
4435
4469
  const results = (await this.#client.execute({
4436
- sql: `SELECT *,scope AS scopeJson FROM "${_mastra_core_storage.TABLE_KNOWLEDGE_NODES}" WHERE mergedInto IS NULL AND ${visibleSql} AND (canonicalName LIKE ? ESCAPE '=' OR lower(COALESCE(kind,'')) LIKE ? ESCAPE '=' OR lower(COALESCE(content,'')) LIKE ? ESCAPE '=') ORDER BY updatedAt DESC LIMIT ?`,
4470
+ sql: `SELECT *,scope AS scopeJson FROM "${_mastra_core_storage.TABLE_KNOWLEDGE_NODES}" WHERE mergedInto IS NULL AND ${visibleSql} AND (canonicalName LIKE ? ESCAPE '=' OR lower(COALESCE(kind,'')) LIKE ? ESCAPE '=' OR lower(COALESCE(content,'')) LIKE ? ESCAPE '=' OR lower(COALESCE(description,'')) LIKE ? ESCAPE '=') ORDER BY updatedAt DESC LIMIT ?`,
4437
4471
  args: [
4438
4472
  key,
4439
4473
  key,
4440
4474
  query,
4441
4475
  query,
4442
4476
  query,
4477
+ query,
4443
4478
  input.limit ?? 20
4444
4479
  ]
4445
4480
  })).rows.map((row) => ({
@@ -4447,7 +4482,11 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
4447
4482
  id: String(row.id),
4448
4483
  recordId: String(row.id),
4449
4484
  name: String(row.name),
4450
- text: row.content ? `${String(row.name)}\n${String(row.content)}` : String(row.name),
4485
+ text: [
4486
+ String(row.name),
4487
+ ...row.description ? [String(row.description)] : [],
4488
+ ...row.content ? [String(row.content)] : []
4489
+ ].join("\n"),
4451
4490
  scope: parseJson$1(row.scopeJson)
4452
4491
  }));
4453
4492
  if (results.length < (input.limit ?? 20)) {