@mastra/pg 1.22.0 → 1.22.1

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 (30) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE.md +6 -4
  3. package/dist/docs/SKILL.md +1 -1
  4. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  5. package/dist/docs/references/docs-deployment-workers.md +6 -1
  6. package/dist/docs/references/docs-memory-semantic-recall.md +2 -0
  7. package/dist/docs/references/docs-memory-working-memory.md +2 -0
  8. package/dist/docs/references/docs-storage.md +2 -0
  9. package/dist/docs/references/integrations-databases-dynamodb.md +2 -0
  10. package/dist/docs/references/integrations-databases-neon.md +2 -0
  11. package/dist/docs/references/integrations-databases-postgresql.md +2 -0
  12. package/dist/docs/references/reference-memory-memory-class.md +2 -0
  13. package/dist/docs/references/reference-processors-message-history-processor.md +2 -0
  14. package/dist/docs/references/reference-processors-semantic-recall-processor.md +2 -0
  15. package/dist/docs/references/reference-processors-working-memory-processor.md +2 -0
  16. package/dist/docs/references/reference-rag-chunking-and-embedding.md +2 -0
  17. package/dist/docs/references/reference-rag-metadata-filters.md +2 -0
  18. package/dist/docs/references/reference-rag-overview.md +2 -0
  19. package/dist/docs/references/reference-rag-retrieval.md +2 -0
  20. package/dist/docs/references/reference-rag-vector-databases.md +2 -0
  21. package/dist/docs/references/reference-storage-composite.md +2 -0
  22. package/dist/docs/references/reference-storage-retention.md +2 -0
  23. package/dist/docs/references/reference-tools-vector-query-tool.md +2 -0
  24. package/dist/docs/references/reference-vectors-pg.md +2 -0
  25. package/dist/index.cjs +45 -6
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.js +46 -7
  28. package/dist/index.js.map +1 -1
  29. package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
  30. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
2
- import { AgentsStorage, BRANCH_SPAN_TYPES, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, EntityType, ExperimentsStorage, FactoryStorage, 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, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, NotificationsStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PromptBlocksStorage, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, 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_NOTIFICATIONS, 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_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, ThreadStateStorage, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, getDefaultValue, getSqlType, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, matchesExpectedWorkflowStatus, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
2
+ import { AgentsStorage, BRANCH_SPAN_TYPES, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, EntityType, ExperimentsStorage, FactoryStorage, 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, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, NotificationsStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PromptBlocksStorage, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, 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_NOTIFICATIONS, 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_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, ThreadStateStorage, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeDescriptionWithinBound, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, getDefaultValue, getSqlType, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, matchesExpectedWorkflowStatus, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
3
3
  import { parseFieldKey, parseSqlIdentifier } from "@mastra/core/utils";
4
4
  import { MastraVector, validateTopK, validateUpsertInput } from "@mastra/core/vector";
5
5
  import { Mutex } from "async-mutex";
@@ -7920,6 +7920,7 @@ function parseNode(row) {
7920
7920
  name: String(row.name),
7921
7921
  kind: String(row.kind),
7922
7922
  content: row.content == null ? void 0 : String(row.content),
7923
+ description: row.description == null ? void 0 : String(row.description),
7923
7924
  scope: parseJson$1(row.scopeJson ?? row.scope),
7924
7925
  version: Number(row.version),
7925
7926
  mergedInto: row.mergedInto == null ? void 0 : String(row.mergedInto),
@@ -8079,6 +8080,11 @@ var KnowledgePG = class extends KnowledgeStorage {
8079
8080
  tableName: TABLE_KNOWLEDGE_NODES,
8080
8081
  schema: KNOWLEDGE_NODES_SCHEMA
8081
8082
  });
8083
+ await this.#db.alterTable({
8084
+ tableName: TABLE_KNOWLEDGE_NODES,
8085
+ schema: KNOWLEDGE_NODES_SCHEMA,
8086
+ ifNotExists: ["description"]
8087
+ });
8082
8088
  await this.#db.createTable({
8083
8089
  tableName: TABLE_KNOWLEDGE_RECORDS,
8084
8090
  schema: KNOWLEDGE_RECORDS_SCHEMA
@@ -8120,6 +8126,7 @@ var KnowledgePG = class extends KnowledgeStorage {
8120
8126
  });
8121
8127
  }
8122
8128
  async createNode(input) {
8129
+ assertKnowledgeDescriptionWithinBound(input.description);
8123
8130
  const scope = canonicalizeKnowledgeScope(input.scope);
8124
8131
  return this.#transaction(async (tx) => {
8125
8132
  const existing = await this.#getNodeByName(tx, input.name, scope);
@@ -8135,13 +8142,14 @@ var KnowledgePG = class extends KnowledgeStorage {
8135
8142
  name: input.name.trim(),
8136
8143
  kind: input.kind,
8137
8144
  content: input.content,
8145
+ description: input.description,
8138
8146
  scope,
8139
8147
  version: 1,
8140
8148
  createdAt: now,
8141
8149
  updatedAt: now
8142
8150
  };
8143
8151
  await tx.execute({
8144
- sql: `INSERT INTO "${TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
8152
+ sql: `INSERT INTO "${TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,description,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
8145
8153
  args: [
8146
8154
  node.id,
8147
8155
  "node",
@@ -8149,6 +8157,7 @@ var KnowledgePG = class extends KnowledgeStorage {
8149
8157
  canonicalName(node.name),
8150
8158
  node.kind,
8151
8159
  node.content ?? null,
8160
+ node.description ?? null,
8152
8161
  JSON.stringify(scope),
8153
8162
  knowledgeScopeKey(scope),
8154
8163
  node.version,
@@ -8205,6 +8214,7 @@ var KnowledgePG = class extends KnowledgeStorage {
8205
8214
  })).rows.map(parseNode);
8206
8215
  }
8207
8216
  async updateNode(input) {
8217
+ assertKnowledgeDescriptionWithinBound(input.description);
8208
8218
  return this.#transaction(async (tx) => {
8209
8219
  const existing = await this.#getNode(tx, input.id);
8210
8220
  if (!existing) throw new KnowledgeNotFoundError("node", input.id);
@@ -8212,14 +8222,16 @@ var KnowledgePG = class extends KnowledgeStorage {
8212
8222
  const scope = canonicalizeKnowledgeScope(input.scope ?? existing.scope);
8213
8223
  const name = (input.name ?? existing.name).trim();
8214
8224
  const content = input.content ?? existing.content;
8225
+ const description = input.description ?? existing.description;
8215
8226
  const now = /* @__PURE__ */ new Date();
8216
8227
  if ((await tx.execute({
8217
- sql: `UPDATE "${TABLE_KNOWLEDGE_NODES}" SET name=?,canonicalName=?,kind=?,content=?,scope=jsonb(?),scopeKey=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=?`,
8228
+ 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=?`,
8218
8229
  args: [
8219
8230
  name,
8220
8231
  canonicalName(name),
8221
8232
  input.kind ?? existing.kind,
8222
8233
  content ?? null,
8234
+ description ?? null,
8223
8235
  JSON.stringify(scope),
8224
8236
  knowledgeScopeKey(scope),
8225
8237
  now.toISOString(),
@@ -8247,6 +8259,7 @@ var KnowledgePG = class extends KnowledgeStorage {
8247
8259
  name,
8248
8260
  kind: input.kind ?? existing.kind,
8249
8261
  content,
8262
+ description,
8250
8263
  scope,
8251
8264
  version: input.version + 1,
8252
8265
  updatedAt: now
@@ -8293,10 +8306,31 @@ var KnowledgePG = class extends KnowledgeStorage {
8293
8306
  });
8294
8307
  for (const row of movedFacts.rows) await this.#outbox(tx, "record", String(row.id), row.deletedAt == null ? "upsert" : "delete", createKnowledgeUlid(), parseJson$1(row.scopeJson));
8295
8308
  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));
8309
+ let mergedTarget = target;
8310
+ if (target.description === void 0 && source.description) {
8311
+ const adoptedAt = /* @__PURE__ */ new Date();
8312
+ if ((await tx.execute({
8313
+ sql: `UPDATE "${TABLE_KNOWLEDGE_NODES}" SET description=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=? AND description IS NULL`,
8314
+ args: [
8315
+ source.description,
8316
+ adoptedAt.toISOString(),
8317
+ target.id,
8318
+ target.version
8319
+ ]
8320
+ })).rowsAffected > 0) {
8321
+ mergedTarget = {
8322
+ ...target,
8323
+ description: source.description,
8324
+ version: target.version + 1,
8325
+ updatedAt: adoptedAt
8326
+ };
8327
+ await this.#activity(tx, "node-updated", "node", target.id, target.scope);
8328
+ }
8329
+ }
8296
8330
  await this.#activity(tx, "node-merged", "node", source.id, source.scope);
8297
8331
  await this.#outbox(tx, "node", source.id, "delete", input.sourceVersion + 1, source.scope);
8298
- await this.#outbox(tx, "node", target.id, "upsert", createKnowledgeUlid(), target.scope);
8299
- return target;
8332
+ await this.#outbox(tx, "node", target.id, "upsert", createKnowledgeUlid(), mergedTarget.scope);
8333
+ return mergedTarget;
8300
8334
  });
8301
8335
  }
8302
8336
  async appendKnowledge(input) {
@@ -8461,13 +8495,14 @@ var KnowledgePG = class extends KnowledgeStorage {
8461
8495
  if (!normalizedQuery) return [];
8462
8496
  const query = `%${escapeLikePattern(normalizedQuery)}%`;
8463
8497
  const results = (await this.#executor.execute({
8464
- 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 ?`,
8498
+ 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 ?`,
8465
8499
  args: [
8466
8500
  key,
8467
8501
  key,
8468
8502
  query,
8469
8503
  query,
8470
8504
  query,
8505
+ query,
8471
8506
  input.limit ?? 20
8472
8507
  ]
8473
8508
  })).rows.map((row) => ({
@@ -8475,7 +8510,11 @@ var KnowledgePG = class extends KnowledgeStorage {
8475
8510
  id: String(row.id),
8476
8511
  recordId: String(row.id),
8477
8512
  name: String(row.name),
8478
- text: row.content ? `${String(row.name)}\n${String(row.content)}` : String(row.name),
8513
+ text: [
8514
+ String(row.name),
8515
+ ...row.description ? [String(row.description)] : [],
8516
+ ...row.content ? [String(row.content)] : []
8517
+ ].join("\n"),
8479
8518
  scope: parseJson$1(row.scopeJson)
8480
8519
  }));
8481
8520
  if (results.length < (input.limit ?? 20)) {