@mastra/libsql 1.22.0-alpha.2 → 1.22.1-alpha.0

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 (36) hide show
  1. package/CHANGELOG.md +73 -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-agents-human-in-the-loop.md +2 -0
  6. package/dist/docs/references/docs-agents-networks.md +2 -0
  7. package/dist/docs/references/docs-deployment-workers.md +6 -1
  8. package/dist/docs/references/docs-memory-memory-processors.md +2 -0
  9. package/dist/docs/references/docs-memory-message-history.md +2 -0
  10. package/dist/docs/references/docs-memory-multi-user-threads.md +2 -0
  11. package/dist/docs/references/docs-memory-overview.md +2 -0
  12. package/dist/docs/references/docs-memory-semantic-recall.md +21 -0
  13. package/dist/docs/references/docs-memory-working-memory.md +2 -0
  14. package/dist/docs/references/docs-storage.md +2 -0
  15. package/dist/docs/references/docs-studio-editor.md +2 -0
  16. package/dist/docs/references/docs-workflows-snapshots.md +2 -0
  17. package/dist/docs/references/integrations-channels-github.md +58 -9
  18. package/dist/docs/references/integrations-databases-dynamodb.md +2 -0
  19. package/dist/docs/references/integrations-databases-libsql.md +2 -0
  20. package/dist/docs/references/reference-ai-sdk-overview.md +2 -0
  21. package/dist/docs/references/reference-core-getMemory.md +2 -0
  22. package/dist/docs/references/reference-core-listMemory.md +2 -0
  23. package/dist/docs/references/reference-core-mastra-class.md +4 -0
  24. package/dist/docs/references/reference-file-based-agents-memory.md +2 -0
  25. package/dist/docs/references/reference-file-based-agents-storage.md +2 -0
  26. package/dist/docs/references/reference-memory-memory-class.md +2 -0
  27. package/dist/docs/references/reference-rag-retrieval.md +2 -0
  28. package/dist/docs/references/reference-storage-composite.md +2 -0
  29. package/dist/docs/references/reference-storage-retention.md +2 -0
  30. package/dist/docs/references/reference-vectors-libsql.md +2 -0
  31. package/dist/index.cjs +45 -6
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.js +46 -7
  34. package/dist/index.js.map +1 -1
  35. package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
  36. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createClient } from "@libsql/client";
2
2
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
3
- 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, FactoryStorage, FavoritesStorage, HarnessStorage, 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, NotificationsStorage, 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, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_HARNESS_SESSIONS, 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, THREAD_STATE_SCHEMA, TOOL_PROVIDER_CONNECTIONS_SCHEMA, ThreadStateStorage, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, getSqlType, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, matchesExpectedWorkflowStatus, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, safelyParseJSON, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
3
+ 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, FactoryStorage, FavoritesStorage, HarnessStorage, 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, NotificationsStorage, 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, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_HARNESS_SESSIONS, 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, THREAD_STATE_SCHEMA, TOOL_PROVIDER_CONNECTIONS_SCHEMA, ThreadStateStorage, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeDescriptionWithinBound, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, getSqlType, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, matchesExpectedWorkflowStatus, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, safelyParseJSON, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
4
4
  import { parseFieldKey, parseSqlIdentifier } from "@mastra/core/utils";
5
5
  import { MastraVector, validateTopK, validateUpsertInput } from "@mastra/core/vector";
6
6
  import { BaseFilterTranslator } from "@mastra/core/vector/filter";
@@ -5814,6 +5814,7 @@ function parseNode(row) {
5814
5814
  name: String(row.name),
5815
5815
  kind: row.kind == null ? "" : String(row.kind),
5816
5816
  content: row.content == null ? void 0 : String(row.content),
5817
+ description: row.description == null ? void 0 : String(row.description),
5817
5818
  scope: parseJson$3(row.scopeJson ?? row.scope),
5818
5819
  version: Number(row.version),
5819
5820
  mergedInto: row.mergedInto == null ? void 0 : String(row.mergedInto),
@@ -5870,6 +5871,11 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
5870
5871
  tableName: TABLE_KNOWLEDGE_NODES,
5871
5872
  schema: KNOWLEDGE_NODES_SCHEMA
5872
5873
  });
5874
+ await this.#db.alterTable({
5875
+ tableName: TABLE_KNOWLEDGE_NODES,
5876
+ schema: KNOWLEDGE_NODES_SCHEMA,
5877
+ ifNotExists: ["description"]
5878
+ });
5873
5879
  await this.#db.createTable({
5874
5880
  tableName: TABLE_KNOWLEDGE_RECORDS,
5875
5881
  schema: KNOWLEDGE_RECORDS_SCHEMA
@@ -5944,6 +5950,7 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
5944
5950
  });
5945
5951
  }
5946
5952
  async createNode(input) {
5953
+ assertKnowledgeDescriptionWithinBound(input.description);
5947
5954
  const scope = canonicalizeKnowledgeScope(input.scope);
5948
5955
  return this.#transaction(async (tx) => {
5949
5956
  const existing = await this.#getNodeByName(tx, input.name, scope);
@@ -5959,13 +5966,14 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
5959
5966
  name: input.name.trim(),
5960
5967
  kind: input.kind,
5961
5968
  content: input.content,
5969
+ description: input.description,
5962
5970
  scope,
5963
5971
  version: 1,
5964
5972
  createdAt: now,
5965
5973
  updatedAt: now
5966
5974
  };
5967
5975
  await tx.execute({
5968
- sql: `INSERT INTO "${TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
5976
+ sql: `INSERT INTO "${TABLE_KNOWLEDGE_NODES}" (id,type,name,canonicalName,kind,content,description,scope,scopeKey,version,mergedInto,createdAt,updatedAt) VALUES (?,?,?,?,?,?,?,jsonb(?),?,?,NULL,?,?)`,
5969
5977
  args: [
5970
5978
  node.id,
5971
5979
  "node",
@@ -5973,6 +5981,7 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
5973
5981
  canonicalName(node.name),
5974
5982
  node.kind,
5975
5983
  node.content ?? null,
5984
+ node.description ?? null,
5976
5985
  JSON.stringify(scope),
5977
5986
  knowledgeScopeKey(scope),
5978
5987
  node.version,
@@ -6029,6 +6038,7 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
6029
6038
  })).rows.map(parseNode);
6030
6039
  }
6031
6040
  async updateNode(input) {
6041
+ assertKnowledgeDescriptionWithinBound(input.description);
6032
6042
  return this.#transaction(async (tx) => {
6033
6043
  const existing = await this.#getNode(tx, input.id);
6034
6044
  if (!existing) throw new KnowledgeNotFoundError("node", input.id);
@@ -6036,14 +6046,16 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
6036
6046
  const scope = canonicalizeKnowledgeScope(input.scope ?? existing.scope);
6037
6047
  const name = (input.name ?? existing.name).trim();
6038
6048
  const content = input.content ?? existing.content;
6049
+ const description = input.description ?? existing.description;
6039
6050
  const now = /* @__PURE__ */ new Date();
6040
6051
  if ((await tx.execute({
6041
- sql: `UPDATE "${TABLE_KNOWLEDGE_NODES}" SET name=?,canonicalName=?,kind=?,content=?,scope=jsonb(?),scopeKey=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=?`,
6052
+ 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=?`,
6042
6053
  args: [
6043
6054
  name,
6044
6055
  canonicalName(name),
6045
6056
  input.kind ?? existing.kind,
6046
6057
  content ?? null,
6058
+ description ?? null,
6047
6059
  JSON.stringify(scope),
6048
6060
  knowledgeScopeKey(scope),
6049
6061
  now.toISOString(),
@@ -6071,6 +6083,7 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
6071
6083
  name,
6072
6084
  kind: input.kind ?? existing.kind,
6073
6085
  content,
6086
+ description,
6074
6087
  scope,
6075
6088
  version: input.version + 1,
6076
6089
  updatedAt: now
@@ -6117,10 +6130,31 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
6117
6130
  });
6118
6131
  for (const row of movedKnowledge.rows) await this.#outbox(tx, "record", String(row.id), row.deletedAt == null ? "upsert" : "delete", createKnowledgeUlid(), parseJson$3(row.scopeJson));
6119
6132
  for (const row of affected.rows) await this.#outbox(tx, String(row.sourceType), String(row.sourceId), Number(row.deleted) ? "delete" : "upsert", createKnowledgeUlid(), parseJson$3(row.scopeJson));
6133
+ let mergedTarget = target;
6134
+ if (target.description === void 0 && source.description) {
6135
+ const adoptedAt = /* @__PURE__ */ new Date();
6136
+ if ((await tx.execute({
6137
+ sql: `UPDATE "${TABLE_KNOWLEDGE_NODES}" SET description=?,version=version+1,updatedAt=? WHERE id=? AND type='node' AND version=? AND description IS NULL`,
6138
+ args: [
6139
+ source.description,
6140
+ adoptedAt.toISOString(),
6141
+ target.id,
6142
+ target.version
6143
+ ]
6144
+ })).rowsAffected > 0) {
6145
+ mergedTarget = {
6146
+ ...target,
6147
+ description: source.description,
6148
+ version: target.version + 1,
6149
+ updatedAt: adoptedAt
6150
+ };
6151
+ await this.#activity(tx, "node-updated", "node", target.id, target.scope);
6152
+ }
6153
+ }
6120
6154
  await this.#activity(tx, "node-merged", "node", source.id, source.scope);
6121
6155
  await this.#outbox(tx, "node", source.id, "delete", input.sourceVersion + 1, source.scope);
6122
- await this.#outbox(tx, "node", target.id, "upsert", createKnowledgeUlid(), target.scope);
6123
- return target;
6156
+ await this.#outbox(tx, "node", target.id, "upsert", createKnowledgeUlid(), mergedTarget.scope);
6157
+ return mergedTarget;
6124
6158
  });
6125
6159
  }
6126
6160
  async appendKnowledge(input) {
@@ -6285,13 +6319,14 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
6285
6319
  if (!normalizedQuery) return [];
6286
6320
  const query = `%${escapeLikePattern(normalizedQuery)}%`;
6287
6321
  const results = (await this.#client.execute({
6288
- sql: `SELECT *,json(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 ?`,
6322
+ sql: `SELECT *,json(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 ?`,
6289
6323
  args: [
6290
6324
  key,
6291
6325
  key,
6292
6326
  query,
6293
6327
  query,
6294
6328
  query,
6329
+ query,
6295
6330
  input.limit ?? 20
6296
6331
  ]
6297
6332
  })).rows.map((row) => ({
@@ -6299,7 +6334,11 @@ var KnowledgeLibSQL = class extends KnowledgeStorage {
6299
6334
  id: String(row.id),
6300
6335
  recordId: String(row.id),
6301
6336
  name: String(row.name),
6302
- text: row.content ? `${String(row.name)}\n${String(row.content)}` : String(row.name),
6337
+ text: [
6338
+ String(row.name),
6339
+ ...row.description ? [String(row.description)] : [],
6340
+ ...row.content ? [String(row.content)] : []
6341
+ ].join("\n"),
6303
6342
  scope: parseJson$3(row.scopeJson)
6304
6343
  }));
6305
6344
  if (results.length < (input.limit ?? 20)) {