@mastra/factory 0.2.1-alpha.4 → 0.2.2-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.
@@ -10404,7 +10404,7 @@ __export(dist_exports, {
10404
10404
  WorkspacesLibSQL: () => WorkspacesLibSQL
10405
10405
  });
10406
10406
  import { MastraError, ErrorCategory, ErrorDomain } from "@mastra/core/error";
10407
- 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 as UniqueViolationError2, TraceStatus, mergeWorkflowStepResult } from "@mastra/core/storage";
10407
+ 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 as UniqueViolationError2, TraceStatus, mergeWorkflowStepResult } from "@mastra/core/storage";
10408
10408
  import { parseSqlIdentifier, parseFieldKey } from "@mastra/core/utils";
10409
10409
  import { MastraVector, validateTopK, validateUpsertInput } from "@mastra/core/vector";
10410
10410
  import { BaseFilterTranslator } from "@mastra/core/vector/filter";
@@ -11020,6 +11020,40 @@ function sessionToRecord(record) {
11020
11020
  deletedAt: record.deletedAt ?? null
11021
11021
  };
11022
11022
  }
11023
+ function addSqliteMetadataFilter(conditions, params, metadataFilter) {
11024
+ if (!metadataFilter) return;
11025
+ for (const [key, value] of Object.entries(metadataFilter)) {
11026
+ const path = `$.metadata.${key}`;
11027
+ conditions.push(`CASE WHEN json_valid(content) THEN json_type(content, ?) IS NOT NULL ELSE 0 END`);
11028
+ params.push(path);
11029
+ addSqliteMetadataValuePredicate(conditions, params, path, value);
11030
+ }
11031
+ }
11032
+ function addSqliteMetadataValuePredicate(conditions, params, path, value) {
11033
+ if (value === null) {
11034
+ conditions.push(`CASE WHEN json_valid(content) THEN json_type(content, ?) = 'null' ELSE 0 END`);
11035
+ params.push(path);
11036
+ return;
11037
+ }
11038
+ if (typeof value === "string") {
11039
+ conditions.push(
11040
+ `CASE WHEN json_valid(content) THEN json_type(content, ?) = 'text' AND json_extract(content, ?) = ? ELSE 0 END`
11041
+ );
11042
+ params.push(path, path, value);
11043
+ return;
11044
+ }
11045
+ if (typeof value === "number") {
11046
+ conditions.push(
11047
+ `CASE WHEN json_valid(content) THEN json_type(content, ?) IN ('integer', 'real') AND json_extract(content, ?) = ? ELSE 0 END`
11048
+ );
11049
+ params.push(path, path, value);
11050
+ return;
11051
+ }
11052
+ conditions.push(
11053
+ `CASE WHEN json_valid(content) THEN json_type(content, ?) = ? AND json_extract(content, ?) = ? ELSE 0 END`
11054
+ );
11055
+ params.push(path, value ? "true" : "false", path, value ? 1 : 0);
11056
+ }
11023
11057
  function parseJson2(value) {
11024
11058
  if (value == null) return void 0;
11025
11059
  if (typeof value === "string") {
@@ -17829,6 +17863,7 @@ Note: This migration may take some time for large tables.
17829
17863
  }
17830
17864
  const perPage = normalizePerPage(perPageInput, 40);
17831
17865
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
17866
+ const metadataFilter = validateStorageMetadataFilter(filter?.metadata);
17832
17867
  try {
17833
17868
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
17834
17869
  const orderByStatement = `ORDER BY "${field}" ${direction}`;
@@ -17853,6 +17888,7 @@ Note: This migration may take some time for large tables.
17853
17888
  filter.dateRange.end instanceof Date ? filter.dateRange.end.toISOString() : filter.dateRange.end
17854
17889
  );
17855
17890
  }
17891
+ addSqliteMetadataFilter(conditions, queryParams, metadataFilter);
17856
17892
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
17857
17893
  if (perPage === 0 && (!include || include.length === 0)) {
17858
17894
  return { messages: [], total: 0, page, perPage: perPageForResponse, hasMore: false };
@@ -17882,6 +17918,7 @@ Note: This migration may take some time for large tables.
17882
17918
  args: [...queryParams, limitValue, offset]
17883
17919
  });
17884
17920
  const messages = (dataResult.rows || []).map((row) => this.parseRow(row));
17921
+ const paginatedCount = messages.length;
17885
17922
  if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
17886
17923
  return {
17887
17924
  messages: [],
@@ -17910,7 +17947,7 @@ Note: This migration may take some time for large tables.
17910
17947
  finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
17911
17948
  );
17912
17949
  const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
17913
- const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
17950
+ const hasMore = metadataFilter ? perPageInput !== false && offset + paginatedCount < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
17914
17951
  return {
17915
17952
  messages: finalMessages,
17916
17953
  total,
@@ -17968,6 +18005,7 @@ Note: This migration may take some time for large tables.
17968
18005
  }
17969
18006
  const perPage = normalizePerPage(perPageInput, 40);
17970
18007
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
18008
+ const metadataFilter = validateStorageMetadataFilter(filter?.metadata);
17971
18009
  try {
17972
18010
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
17973
18011
  const orderByStatement = `ORDER BY "${field}" ${direction}`;
@@ -17989,6 +18027,7 @@ Note: This migration may take some time for large tables.
17989
18027
  filter.dateRange.end instanceof Date ? filter.dateRange.end.toISOString() : filter.dateRange.end
17990
18028
  );
17991
18029
  }
18030
+ addSqliteMetadataFilter(conditions, queryParams, metadataFilter);
17992
18031
  const whereClause = `WHERE ${conditions.join(" AND ")}`;
17993
18032
  if (perPage === 0 && (!include || include.length === 0)) {
17994
18033
  return { messages: [], total: 0, page, perPage: perPageForResponse, hasMore: false };