@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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
2
- import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, ExperimentsStorage, FAVORITES_SCHEMA, FavoritesStorage, KNOWLEDGE_ACTIVITY_SCHEMA, KNOWLEDGE_CURSORS_SCHEMA, KNOWLEDGE_MENTIONS_SCHEMA, KNOWLEDGE_NODES_SCHEMA, KNOWLEDGE_RECORDS_SCHEMA, KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, MCPClientsStorage, MCPServersStorage, MCP_CLIENTS_SCHEMA, MCP_CLIENT_VERSIONS_SCHEMA, MCP_SERVERS_SCHEMA, MCP_SERVER_VERSIONS_SCHEMA, MastraCompositeStore, MemoryStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PROMPT_BLOCKS_SCHEMA, PROMPT_BLOCK_VERSIONS_SCHEMA, PromptBlocksStorage, SCORERS_SCHEMA, SCORER_DEFINITIONS_SCHEMA, SCORER_DEFINITION_VERSIONS_SCHEMA, SKILLS_SCHEMA, SKILL_BLOBS_SCHEMA, SKILL_VERSIONS_SCHEMA, SPAN_SCHEMA, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, StoreOperations, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TOOL_PROVIDER_CONNECTIONS_SCHEMA, ToolProviderConnectionsStorage, TraceStatus, WORKFLOW_DEFINITIONS_SCHEMA, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, normalizeScheduleTarget, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, toTraceSpans, validateStorageMetadataFilter } from "@mastra/core/storage";
2
+ import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, ExperimentsStorage, FAVORITES_SCHEMA, FavoritesStorage, KNOWLEDGE_ACTIVITY_SCHEMA, KNOWLEDGE_CURSORS_SCHEMA, KNOWLEDGE_MENTIONS_SCHEMA, KNOWLEDGE_NODES_SCHEMA, KNOWLEDGE_RECORDS_SCHEMA, KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, MCPClientsStorage, MCPServersStorage, MCP_CLIENTS_SCHEMA, MCP_CLIENT_VERSIONS_SCHEMA, MCP_SERVERS_SCHEMA, MCP_SERVER_VERSIONS_SCHEMA, MastraCompositeStore, MemoryStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PROMPT_BLOCKS_SCHEMA, PROMPT_BLOCK_VERSIONS_SCHEMA, PromptBlocksStorage, SCORERS_SCHEMA, SCORER_DEFINITIONS_SCHEMA, SCORER_DEFINITION_VERSIONS_SCHEMA, SKILLS_SCHEMA, SKILL_BLOBS_SCHEMA, SKILL_VERSIONS_SCHEMA, SPAN_SCHEMA, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, StoreOperations, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TOOL_PROVIDER_CONNECTIONS_SCHEMA, ToolProviderConnectionsStorage, TraceStatus, WORKFLOW_DEFINITIONS_SCHEMA, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeDescriptionWithinBound, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, normalizeScheduleTarget, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, toTraceSpans, validateStorageMetadataFilter } from "@mastra/core/storage";
3
3
  import { createPool } from "mysql2/promise";
4
4
  import { parseSqlIdentifier } from "@mastra/core/utils";
5
5
  import { randomUUID } from "crypto";
@@ -3953,6 +3953,7 @@ function parseNode(row) {
3953
3953
  name: String(row.name),
3954
3954
  kind: String(row.kind),
3955
3955
  content: row.content == null ? void 0 : String(row.content),
3956
+ description: row.description == null ? void 0 : String(row.description),
3956
3957
  scope: parseJson$1(row.scopeJson ?? row.scope),
3957
3958
  version: Number(row.version),
3958
3959
  mergedInto: row.mergedInto == null ? void 0 : String(row.mergedInto),
@@ -4052,6 +4053,11 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4052
4053
  tableName: TABLE_KNOWLEDGE_NODES,
4053
4054
  schema: KNOWLEDGE_NODES_SCHEMA
4054
4055
  });
4056
+ await this.#operations.alterTable({
4057
+ tableName: TABLE_KNOWLEDGE_NODES,
4058
+ schema: KNOWLEDGE_NODES_SCHEMA,
4059
+ ifNotExists: ["description"]
4060
+ });
4055
4061
  await this.#operations.createTable({
4056
4062
  tableName: TABLE_KNOWLEDGE_RECORDS,
4057
4063
  schema: KNOWLEDGE_RECORDS_SCHEMA
@@ -4091,6 +4097,7 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4091
4097
  });
4092
4098
  }
4093
4099
  async createNode(input) {
4100
+ assertKnowledgeDescriptionWithinBound(input.description);
4094
4101
  const scope = canonicalizeKnowledgeScope(input.scope);
4095
4102
  return this.#transaction(async (tx) => {
4096
4103
  const existing = await this.#getNodeByName(tx, input.name, scope);
@@ -4106,13 +4113,14 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4106
4113
  name: input.name.trim(),
4107
4114
  kind: input.kind,
4108
4115
  content: input.content,
4116
+ description: input.description,
4109
4117
  scope,
4110
4118
  version: 1,
4111
4119
  createdAt: now,
4112
4120
  updatedAt: now
4113
4121
  };
4114
4122
  await tx.execute({
4115
- sql: `INSERT INTO "${TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
4123
+ sql: `INSERT INTO "${TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,description,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
4116
4124
  args: [
4117
4125
  node.id,
4118
4126
  "node",
@@ -4120,6 +4128,7 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4120
4128
  canonicalName(node.name),
4121
4129
  node.kind,
4122
4130
  node.content ?? null,
4131
+ node.description ?? null,
4123
4132
  JSON.stringify(scope),
4124
4133
  knowledgeScopeKey(scope),
4125
4134
  node.version,
@@ -4176,6 +4185,7 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4176
4185
  })).rows.map(parseNode);
4177
4186
  }
4178
4187
  async updateNode(input) {
4188
+ assertKnowledgeDescriptionWithinBound(input.description);
4179
4189
  return this.#transaction(async (tx) => {
4180
4190
  const existing = await this.#getNode(tx, input.id);
4181
4191
  if (!existing) throw new KnowledgeNotFoundError("node", input.id);
@@ -4183,14 +4193,16 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4183
4193
  const scope = canonicalizeKnowledgeScope(input.scope ?? existing.scope);
4184
4194
  const name = (input.name ?? existing.name).trim();
4185
4195
  const content = input.content ?? existing.content;
4196
+ const description = input.description ?? existing.description;
4186
4197
  const now = /* @__PURE__ */ new Date();
4187
4198
  if ((await tx.execute({
4188
- sql: `UPDATE "${TABLE_KNOWLEDGE_NODES}" SET name=?,canonicalName=?,kind=?,content=?,scope=jsonb(?),scopeKey=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=?`,
4199
+ sql: `UPDATE "${TABLE_KNOWLEDGE_NODES}" SET name=?,canonicalName=?,kind=?,content=?,description=?,scope=jsonb(?),scopeKey=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=?`,
4189
4200
  args: [
4190
4201
  name,
4191
4202
  canonicalName(name),
4192
4203
  input.kind ?? existing.kind,
4193
4204
  content ?? null,
4205
+ description ?? null,
4194
4206
  JSON.stringify(scope),
4195
4207
  knowledgeScopeKey(scope),
4196
4208
  now.toISOString(),
@@ -4218,6 +4230,7 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4218
4230
  name,
4219
4231
  kind: input.kind ?? existing.kind,
4220
4232
  content,
4233
+ description,
4221
4234
  scope,
4222
4235
  version: input.version + 1,
4223
4236
  updatedAt: now
@@ -4264,10 +4277,31 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4264
4277
  });
4265
4278
  for (const row of movedFacts.rows) await this.#outbox(tx, "record", String(row.id), row.deletedAt == null ? "upsert" : "delete", createKnowledgeUlid(), parseJson$1(row.scopeJson));
4266
4279
  for (const row of affected.rows) await this.#outbox(tx, String(row.sourceType), String(row.sourceId), Number(row.deleted) ? "delete" : "upsert", createKnowledgeUlid(), parseJson$1(row.scopeJson));
4280
+ let mergedTarget = target;
4281
+ if (target.description === void 0 && source.description) {
4282
+ const adoptedAt = /* @__PURE__ */ new Date();
4283
+ if ((await tx.execute({
4284
+ sql: `UPDATE "${TABLE_KNOWLEDGE_NODES}" SET description=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=? AND description IS NULL`,
4285
+ args: [
4286
+ source.description,
4287
+ adoptedAt.toISOString(),
4288
+ target.id,
4289
+ target.version
4290
+ ]
4291
+ })).rowsAffected > 0) {
4292
+ mergedTarget = {
4293
+ ...target,
4294
+ description: source.description,
4295
+ version: target.version + 1,
4296
+ updatedAt: adoptedAt
4297
+ };
4298
+ await this.#activity(tx, "node-updated", "node", target.id, target.scope);
4299
+ }
4300
+ }
4267
4301
  await this.#activity(tx, "node-merged", "node", source.id, source.scope);
4268
4302
  await this.#outbox(tx, "node", source.id, "delete", input.sourceVersion + 1, source.scope);
4269
- await this.#outbox(tx, "node", target.id, "upsert", createKnowledgeUlid(), target.scope);
4270
- return target;
4303
+ await this.#outbox(tx, "node", target.id, "upsert", createKnowledgeUlid(), mergedTarget.scope);
4304
+ return mergedTarget;
4271
4305
  });
4272
4306
  }
4273
4307
  async appendKnowledge(input) {
@@ -4432,13 +4466,14 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4432
4466
  if (!normalizedQuery) return [];
4433
4467
  const query = `%${escapeLikePattern(normalizedQuery)}%`;
4434
4468
  const results = (await this.#client.execute({
4435
- sql: `SELECT *,scope AS scopeJson FROM "${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 ?`,
4469
+ sql: `SELECT *,scope AS scopeJson FROM "${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 ?`,
4436
4470
  args: [
4437
4471
  key,
4438
4472
  key,
4439
4473
  query,
4440
4474
  query,
4441
4475
  query,
4476
+ query,
4442
4477
  input.limit ?? 20
4443
4478
  ]
4444
4479
  })).rows.map((row) => ({
@@ -4446,7 +4481,11 @@ var KnowledgeMySQL = class extends KnowledgeStorage {
4446
4481
  id: String(row.id),
4447
4482
  recordId: String(row.id),
4448
4483
  name: String(row.name),
4449
- text: row.content ? `${String(row.name)}\n${String(row.content)}` : String(row.name),
4484
+ text: [
4485
+ String(row.name),
4486
+ ...row.description ? [String(row.description)] : [],
4487
+ ...row.content ? [String(row.content)] : []
4488
+ ].join("\n"),
4450
4489
  scope: parseJson$1(row.scopeJson)
4451
4490
  }));
4452
4491
  if (results.length < (input.limit ?? 20)) {