@mastra/libsql 1.17.1-alpha.1 → 1.17.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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createClient } from '@libsql/client';
2
2
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
3
- import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, TABLE_SCHEMAS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, ensureDate, safelyParseJSON, hasErrorCode, ExperimentsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, FavoritesStorage, FAVORITES_SCHEMA, TABLE_FAVORITES, TABLE_SKILLS, HarnessStorage, TABLE_HARNESS_SESSIONS, MCPClientsStorage, MCP_CLIENTS_SCHEMA, TABLE_MCP_CLIENTS, MCP_CLIENT_VERSIONS_SCHEMA, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, MCP_SERVERS_SCHEMA, TABLE_MCP_SERVERS, MCP_SERVER_VERSIONS_SCHEMA, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_RESOURCES, TABLE_MESSAGES, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, NotificationsStorage, TABLE_NOTIFICATIONS, ObservabilityStorage, TABLE_SPANS, SPAN_SCHEMA, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, PROMPT_BLOCKS_SCHEMA, TABLE_PROMPT_BLOCKS, PROMPT_BLOCK_VERSIONS_SCHEMA, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEDULES, ScorerDefinitionsStorage, SCORER_DEFINITIONS_SCHEMA, TABLE_SCORER_DEFINITIONS, SCORER_DEFINITION_VERSIONS_SCHEMA, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SCORERS_SCHEMA, transformScoreRow, SkillsStorage, SKILLS_SCHEMA, SKILL_VERSIONS_SCHEMA, TABLE_SKILL_VERSIONS, ThreadStateStorage, TABLE_THREAD_STATE, THREAD_STATE_SCHEMA, ToolProviderConnectionsStorage, TOOL_PROVIDER_CONNECTIONS_SCHEMA, TABLE_TOOL_PROVIDER_CONNECTIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, WORKSPACES_SCHEMA, TABLE_WORKSPACES, WORKSPACE_VERSIONS_SCHEMA, TABLE_WORKSPACE_VERSIONS, FactoryStorage, MastraCompositeStore, getSqlType, parseDuration, normalizeScheduleTarget, UniqueViolationError, TraceStatus, mergeWorkflowStepResult } from '@mastra/core/storage';
3
+ import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, TABLE_SCHEMAS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, ensureDate, safelyParseJSON, hasErrorCode, ExperimentsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, FavoritesStorage, FAVORITES_SCHEMA, TABLE_FAVORITES, TABLE_SKILLS, HarnessStorage, TABLE_HARNESS_SESSIONS, MCPClientsStorage, MCP_CLIENTS_SCHEMA, TABLE_MCP_CLIENTS, MCP_CLIENT_VERSIONS_SCHEMA, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, MCP_SERVERS_SCHEMA, TABLE_MCP_SERVERS, MCP_SERVER_VERSIONS_SCHEMA, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_RESOURCES, TABLE_MESSAGES, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, validateStorageMetadataFilter, NotificationsStorage, TABLE_NOTIFICATIONS, ObservabilityStorage, TABLE_SPANS, SPAN_SCHEMA, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, PROMPT_BLOCKS_SCHEMA, TABLE_PROMPT_BLOCKS, PROMPT_BLOCK_VERSIONS_SCHEMA, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEDULES, ScorerDefinitionsStorage, SCORER_DEFINITIONS_SCHEMA, TABLE_SCORER_DEFINITIONS, SCORER_DEFINITION_VERSIONS_SCHEMA, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SCORERS_SCHEMA, transformScoreRow, SkillsStorage, SKILLS_SCHEMA, SKILL_VERSIONS_SCHEMA, TABLE_SKILL_VERSIONS, ThreadStateStorage, TABLE_THREAD_STATE, THREAD_STATE_SCHEMA, ToolProviderConnectionsStorage, TOOL_PROVIDER_CONNECTIONS_SCHEMA, TABLE_TOOL_PROVIDER_CONNECTIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, WORKSPACES_SCHEMA, TABLE_WORKSPACES, WORKSPACE_VERSIONS_SCHEMA, TABLE_WORKSPACE_VERSIONS, FactoryStorage, MastraCompositeStore, getSqlType, parseDuration, normalizeScheduleTarget, UniqueViolationError, TraceStatus, mergeWorkflowStepResult } from '@mastra/core/storage';
4
4
  import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
5
5
  import { MastraVector, validateTopK, validateUpsertInput } from '@mastra/core/vector';
6
6
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
@@ -7006,6 +7006,40 @@ var MCPServersLibSQL = class extends MCPServersStorage {
7006
7006
  }
7007
7007
  };
7008
7008
  var OM_TABLE = "mastra_observational_memory";
7009
+ function addSqliteMetadataFilter(conditions, params, metadataFilter) {
7010
+ if (!metadataFilter) return;
7011
+ for (const [key, value] of Object.entries(metadataFilter)) {
7012
+ const path = `$.metadata.${key}`;
7013
+ conditions.push(`CASE WHEN json_valid(content) THEN json_type(content, ?) IS NOT NULL ELSE 0 END`);
7014
+ params.push(path);
7015
+ addSqliteMetadataValuePredicate(conditions, params, path, value);
7016
+ }
7017
+ }
7018
+ function addSqliteMetadataValuePredicate(conditions, params, path, value) {
7019
+ if (value === null) {
7020
+ conditions.push(`CASE WHEN json_valid(content) THEN json_type(content, ?) = 'null' ELSE 0 END`);
7021
+ params.push(path);
7022
+ return;
7023
+ }
7024
+ if (typeof value === "string") {
7025
+ conditions.push(
7026
+ `CASE WHEN json_valid(content) THEN json_type(content, ?) = 'text' AND json_extract(content, ?) = ? ELSE 0 END`
7027
+ );
7028
+ params.push(path, path, value);
7029
+ return;
7030
+ }
7031
+ if (typeof value === "number") {
7032
+ conditions.push(
7033
+ `CASE WHEN json_valid(content) THEN json_type(content, ?) IN ('integer', 'real') AND json_extract(content, ?) = ? ELSE 0 END`
7034
+ );
7035
+ params.push(path, path, value);
7036
+ return;
7037
+ }
7038
+ conditions.push(
7039
+ `CASE WHEN json_valid(content) THEN json_type(content, ?) = ? AND json_extract(content, ?) = ? ELSE 0 END`
7040
+ );
7041
+ params.push(path, value ? "true" : "false", path, value ? 1 : 0);
7042
+ }
7009
7043
  var MemoryLibSQL = class _MemoryLibSQL extends MemoryStorage {
7010
7044
  supportsObservationalMemory = true;
7011
7045
  /**
@@ -7251,6 +7285,7 @@ var MemoryLibSQL = class _MemoryLibSQL extends MemoryStorage {
7251
7285
  }
7252
7286
  const perPage = normalizePerPage(perPageInput, 40);
7253
7287
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
7288
+ const metadataFilter = validateStorageMetadataFilter(filter?.metadata);
7254
7289
  try {
7255
7290
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7256
7291
  const orderByStatement = `ORDER BY "${field}" ${direction}`;
@@ -7275,6 +7310,7 @@ var MemoryLibSQL = class _MemoryLibSQL extends MemoryStorage {
7275
7310
  filter.dateRange.end instanceof Date ? filter.dateRange.end.toISOString() : filter.dateRange.end
7276
7311
  );
7277
7312
  }
7313
+ addSqliteMetadataFilter(conditions, queryParams, metadataFilter);
7278
7314
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
7279
7315
  if (perPage === 0 && (!include || include.length === 0)) {
7280
7316
  return { messages: [], total: 0, page, perPage: perPageForResponse, hasMore: false };
@@ -7304,6 +7340,7 @@ var MemoryLibSQL = class _MemoryLibSQL extends MemoryStorage {
7304
7340
  args: [...queryParams, limitValue, offset]
7305
7341
  });
7306
7342
  const messages = (dataResult.rows || []).map((row) => this.parseRow(row));
7343
+ const paginatedCount = messages.length;
7307
7344
  if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
7308
7345
  return {
7309
7346
  messages: [],
@@ -7332,7 +7369,7 @@ var MemoryLibSQL = class _MemoryLibSQL extends MemoryStorage {
7332
7369
  finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
7333
7370
  );
7334
7371
  const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
7335
- const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
7372
+ const hasMore = metadataFilter ? perPageInput !== false && offset + paginatedCount < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
7336
7373
  return {
7337
7374
  messages: finalMessages,
7338
7375
  total,
@@ -7390,6 +7427,7 @@ var MemoryLibSQL = class _MemoryLibSQL extends MemoryStorage {
7390
7427
  }
7391
7428
  const perPage = normalizePerPage(perPageInput, 40);
7392
7429
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
7430
+ const metadataFilter = validateStorageMetadataFilter(filter?.metadata);
7393
7431
  try {
7394
7432
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7395
7433
  const orderByStatement = `ORDER BY "${field}" ${direction}`;
@@ -7411,6 +7449,7 @@ var MemoryLibSQL = class _MemoryLibSQL extends MemoryStorage {
7411
7449
  filter.dateRange.end instanceof Date ? filter.dateRange.end.toISOString() : filter.dateRange.end
7412
7450
  );
7413
7451
  }
7452
+ addSqliteMetadataFilter(conditions, queryParams, metadataFilter);
7414
7453
  const whereClause = `WHERE ${conditions.join(" AND ")}`;
7415
7454
  if (perPage === 0 && (!include || include.length === 0)) {
7416
7455
  return { messages: [], total: 0, page, perPage: perPageForResponse, hasMore: false };