import { OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS } from '@internal/core/memory'; import { spanRecordSchema } from './domains/observability'; import { buildStorageSchema } from './types'; import type { StorageColumn, StorageTableConfig } from './types'; export const TABLE_WORKFLOW_SNAPSHOT = 'mastra_workflow_snapshot'; export const TABLE_MESSAGES = 'mastra_messages'; export const TABLE_THREADS = 'mastra_threads'; export const TABLE_TRACES = 'mastra_traces'; export const TABLE_RESOURCES = 'mastra_resources'; export const TABLE_SCORERS = 'mastra_scorers'; export const TABLE_SPANS = 'mastra_ai_spans'; export const TABLE_AGENTS = 'mastra_agents'; export const TABLE_AGENT_VERSIONS = 'mastra_agent_versions'; export const TABLE_OBSERVATIONAL_MEMORY = 'mastra_observational_memory'; export const TABLE_PROMPT_BLOCKS = 'mastra_prompt_blocks'; export const TABLE_PROMPT_BLOCK_VERSIONS = 'mastra_prompt_block_versions'; export const TABLE_SCORER_DEFINITIONS = 'mastra_scorer_definitions'; export const TABLE_SCORER_DEFINITION_VERSIONS = 'mastra_scorer_definition_versions'; export const TABLE_MCP_CLIENTS = 'mastra_mcp_clients'; export const TABLE_MCP_CLIENT_VERSIONS = 'mastra_mcp_client_versions'; export const TABLE_MCP_SERVERS = 'mastra_mcp_servers'; export const TABLE_MCP_SERVER_VERSIONS = 'mastra_mcp_server_versions'; export const TABLE_WORKSPACES = 'mastra_workspaces'; export const TABLE_WORKSPACE_VERSIONS = 'mastra_workspace_versions'; export const TABLE_SKILLS = 'mastra_skills'; export const TABLE_SKILL_VERSIONS = 'mastra_skill_versions'; export const TABLE_SKILL_BLOBS = 'mastra_skill_blobs'; export const TABLE_FAVORITES = 'mastra_favorites'; // Dataset tables export const TABLE_DATASETS = 'mastra_datasets'; export const TABLE_DATASET_ITEMS = 'mastra_dataset_items'; export const TABLE_DATASET_VERSIONS = 'mastra_dataset_versions'; // Experiment tables export const TABLE_EXPERIMENTS = 'mastra_experiments'; export const TABLE_EXPERIMENT_RESULTS = 'mastra_experiment_results'; export const TABLE_BACKGROUND_TASKS = 'mastra_background_tasks'; // Schedules tables export const TABLE_SCHEDULES = 'mastra_schedules'; export const TABLE_SCHEDULE_TRIGGERS = 'mastra_schedule_triggers'; // Static workflow definitions (chat-built / studio-saved workflows) export const TABLE_WORKFLOW_DEFINITIONS = 'mastra_workflow_definitions'; // Channel tables export const TABLE_CHANNEL_INSTALLATIONS = 'mastra_channel_installations'; export const TABLE_CHANNEL_CONFIG = 'mastra_channel_config'; // Tool provider connections export const TABLE_TOOL_PROVIDER_CONNECTIONS = 'mastra_tool_provider_connections'; // Notifications export const TABLE_NOTIFICATIONS = 'mastra_notifications'; // Harness sessions export const TABLE_HARNESS_SESSIONS = 'mastra_harness_sessions'; // Thread state (per-thread, per-type durable state; e.g. the task list) export const TABLE_THREAD_STATE = 'mastra_thread_state'; // Knowledge store tables export const TABLE_KNOWLEDGE_NODES = 'mastra_knowledge_nodes'; export const TABLE_KNOWLEDGE_RECORDS = 'mastra_knowledge_records'; export const TABLE_KNOWLEDGE_MENTIONS = 'mastra_knowledge_mentions'; /** * @deprecated Curation cursors were removed and Knowledge no longer creates this table. Kept so adapters built * against earlier Core versions still resolve the export. */ export const TABLE_KNOWLEDGE_CURSORS = 'mastra_knowledge_cursors'; export const TABLE_KNOWLEDGE_ACTIVITY = 'mastra_knowledge_activity'; export const TABLE_KNOWLEDGE_SEMANTIC_OUTBOX = 'mastra_knowledge_semantic_outbox'; export const TABLE_KNOWLEDGE_NODE_SCOPES = 'mastra_knowledge_node_scopes'; export const TABLE_KNOWLEDGE_RECORD_SCOPES = 'mastra_knowledge_record_scopes'; export const TABLE_KNOWLEDGE_SCOPE_GRANTS = 'mastra_knowledge_scope_grants'; export const TABLE_KNOWLEDGE_ACCESS_STATE = 'mastra_knowledge_access_state'; export const TABLE_KNOWLEDGE_SCOPE_ADDRESSES = 'mastra_knowledge_scope_addresses'; export const TABLE_KNOWLEDGE_NODE_ADDRESSES = 'mastra_knowledge_node_addresses'; export const TABLE_KNOWLEDGE_IMPORT_STATE = 'mastra_knowledge_import_state'; export const TABLE_KNOWLEDGE_IMPORT_RUNS = 'mastra_knowledge_import_runs'; export const TABLE_KNOWLEDGE_PROPOSALS = 'mastra_knowledge_proposals'; /** Physical tables owned by one Knowledge domain. Explicit reset may target only this list. */ export const KNOWLEDGE_TABLE_NAMES = [ TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_KNOWLEDGE_NODE_SCOPES, TABLE_KNOWLEDGE_RECORD_SCOPES, TABLE_KNOWLEDGE_SCOPE_GRANTS, TABLE_KNOWLEDGE_ACCESS_STATE, TABLE_KNOWLEDGE_SCOPE_ADDRESSES, TABLE_KNOWLEDGE_NODE_ADDRESSES, TABLE_KNOWLEDGE_IMPORT_STATE, TABLE_KNOWLEDGE_IMPORT_RUNS, TABLE_KNOWLEDGE_PROPOSALS, ] as const; export type KNOWLEDGE_TABLE_NAME = (typeof KNOWLEDGE_TABLE_NAMES)[number]; /** Union of all core table name constants. */ export type TABLE_NAMES = | typeof TABLE_WORKFLOW_SNAPSHOT | typeof TABLE_MESSAGES | typeof TABLE_THREADS | typeof TABLE_TRACES | typeof TABLE_RESOURCES | typeof TABLE_SCORERS | typeof TABLE_SPANS | typeof TABLE_AGENTS | typeof TABLE_AGENT_VERSIONS | typeof TABLE_PROMPT_BLOCKS | typeof TABLE_PROMPT_BLOCK_VERSIONS | typeof TABLE_SCORER_DEFINITIONS | typeof TABLE_SCORER_DEFINITION_VERSIONS | typeof TABLE_MCP_CLIENTS | typeof TABLE_MCP_CLIENT_VERSIONS | typeof TABLE_MCP_SERVERS | typeof TABLE_MCP_SERVER_VERSIONS | typeof TABLE_WORKSPACES | typeof TABLE_WORKSPACE_VERSIONS | typeof TABLE_SKILLS | typeof TABLE_SKILL_VERSIONS | typeof TABLE_SKILL_BLOBS | typeof TABLE_DATASETS | typeof TABLE_DATASET_ITEMS | typeof TABLE_DATASET_VERSIONS | typeof TABLE_EXPERIMENTS | typeof TABLE_EXPERIMENT_RESULTS | typeof TABLE_BACKGROUND_TASKS | typeof TABLE_FAVORITES | typeof TABLE_SCHEDULES | typeof TABLE_SCHEDULE_TRIGGERS | typeof TABLE_CHANNEL_INSTALLATIONS | typeof TABLE_CHANNEL_CONFIG | typeof TABLE_TOOL_PROVIDER_CONNECTIONS | typeof TABLE_NOTIFICATIONS | typeof TABLE_HARNESS_SESSIONS | typeof TABLE_THREAD_STATE | typeof TABLE_WORKFLOW_DEFINITIONS | typeof TABLE_KNOWLEDGE_NODES | typeof TABLE_KNOWLEDGE_RECORDS | typeof TABLE_KNOWLEDGE_MENTIONS | typeof TABLE_KNOWLEDGE_ACTIVITY | typeof TABLE_KNOWLEDGE_SEMANTIC_OUTBOX; export const SCORERS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, scorerId: { type: 'text' }, traceId: { type: 'text', nullable: true }, spanId: { type: 'text', nullable: true }, runId: { type: 'text' }, scorer: { type: 'jsonb' }, preprocessStepResult: { type: 'jsonb', nullable: true }, extractStepResult: { type: 'jsonb', nullable: true }, analyzeStepResult: { type: 'jsonb', nullable: true }, score: { type: 'float' }, reason: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, preprocessPrompt: { type: 'text', nullable: true }, extractPrompt: { type: 'text', nullable: true }, generateScorePrompt: { type: 'text', nullable: true }, generateReasonPrompt: { type: 'text', nullable: true }, analyzePrompt: { type: 'text', nullable: true }, // Deprecated reasonPrompt: { type: 'text', nullable: true }, input: { type: 'jsonb' }, output: { type: 'jsonb' }, // MESSAGE OUTPUT additionalContext: { type: 'jsonb', nullable: true }, // DATA FROM THE CONTEXT PARAM ON AN AGENT requestContext: { type: 'jsonb', nullable: true }, // THE EVALUATE Request Context FOR THE RUN /** * Things you can evaluate */ entityType: { type: 'text', nullable: true }, // WORKFLOW, AGENT, TOOL, STEP, NETWORK entity: { type: 'jsonb', nullable: true }, // MINIMAL JSON DATA ABOUT WORKFLOW, AGENT, TOOL, STEP, NETWORK entityId: { type: 'text', nullable: true }, source: { type: 'text' }, resourceId: { type: 'text', nullable: true }, threadId: { type: 'text', nullable: true }, organizationId: { type: 'text', nullable: true }, projectId: { type: 'text', nullable: true }, // Batch handle: groups all per-trace scores produced by one batch scoring call. // Each score keeps its own per-execution `runId`; `batchId` is shared across the batch. batchId: { type: 'text', nullable: true }, // Dataset provenance: which curated dataset item this score was produced against. // Lets baseline scores join back to dataset items (ground truth) without re-running. datasetId: { type: 'text', nullable: true }, datasetItemId: { type: 'text', nullable: true }, createdAt: { type: 'timestamp' }, updatedAt: { type: 'timestamp' }, }; export const SPAN_SCHEMA = buildStorageSchema(spanRecordSchema); /** * @deprecated Use SPAN_SCHEMA instead. This legacy schema is retained only for migration purposes. * @internal */ export const OLD_SPAN_SCHEMA: Record = { // Composite primary key of traceId and spanId traceId: { type: 'text', nullable: false }, spanId: { type: 'text', nullable: false }, parentSpanId: { type: 'text', nullable: true }, name: { type: 'text', nullable: false }, scope: { type: 'jsonb', nullable: true }, // Mastra package info {"core-version": "0.1.0"} spanType: { type: 'text', nullable: false }, // WORKFLOW_RUN, WORKFLOW_STEP, AGENT_RUN, AGENT_STEP, TOOL_RUN, TOOL_STEP, etc. attributes: { type: 'jsonb', nullable: true }, metadata: { type: 'jsonb', nullable: true }, links: { type: 'jsonb', nullable: true }, input: { type: 'jsonb', nullable: true }, output: { type: 'jsonb', nullable: true }, error: { type: 'jsonb', nullable: true }, startedAt: { type: 'timestamp', nullable: false }, // When the span started endedAt: { type: 'timestamp', nullable: true }, // When the span ended createdAt: { type: 'timestamp', nullable: false }, // The time the database record was created updatedAt: { type: 'timestamp', nullable: true }, // The time the database record was last updated isEvent: { type: 'boolean', nullable: false }, }; export const AGENTS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, status: { type: 'text', nullable: false }, // 'draft' or 'published' activeVersionId: { type: 'text', nullable: true }, // FK to agent_versions.id authorId: { type: 'text', nullable: true }, // Author identifier for multi-tenant filtering visibility: { type: 'text', nullable: true }, // 'private' | 'public' | null (legacy) metadata: { type: 'jsonb', nullable: true }, // Additional metadata for the agent favoriteCount: { type: 'integer', nullable: true }, // Denormalised count of favorites for this agent createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const AGENT_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, // UUID agentId: { type: 'text', nullable: false }, versionNumber: { type: 'integer', nullable: false }, // Agent config fields name: { type: 'text', nullable: false }, // Agent display name description: { type: 'text', nullable: true }, instructions: { type: 'text', nullable: false }, model: { type: 'jsonb', nullable: false }, modelList: { type: 'jsonb', nullable: true }, tools: { type: 'jsonb', nullable: true }, defaultOptions: { type: 'jsonb', nullable: true }, workflows: { type: 'jsonb', nullable: true }, agents: { type: 'jsonb', nullable: true }, integrationTools: { type: 'jsonb', nullable: true }, toolProviders: { type: 'jsonb', nullable: true }, inputProcessors: { type: 'jsonb', nullable: true }, outputProcessors: { type: 'jsonb', nullable: true }, memory: { type: 'jsonb', nullable: true }, scorers: { type: 'jsonb', nullable: true }, mcpClients: { type: 'jsonb', nullable: true }, requestContextSchema: { type: 'jsonb', nullable: true }, workspace: { type: 'jsonb', nullable: true }, skills: { type: 'jsonb', nullable: true }, skillsFormat: { type: 'text', nullable: true }, durable: { type: 'jsonb', nullable: true }, browser: { type: 'jsonb', nullable: true }, // Version metadata changedFields: { type: 'jsonb', nullable: true }, // Array of field names changeMessage: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const PROMPT_BLOCKS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, status: { type: 'text', nullable: false }, // 'draft', 'published', or 'archived' activeVersionId: { type: 'text', nullable: true }, // FK to prompt_block_versions.id authorId: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const PROMPT_BLOCK_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, blockId: { type: 'text', nullable: false }, versionNumber: { type: 'integer', nullable: false }, name: { type: 'text', nullable: false }, description: { type: 'text', nullable: true }, content: { type: 'text', nullable: false }, rules: { type: 'jsonb', nullable: true }, requestContextSchema: { type: 'jsonb', nullable: true }, changedFields: { type: 'jsonb', nullable: true }, changeMessage: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const SCORER_DEFINITIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, status: { type: 'text', nullable: false }, // 'draft', 'published', or 'archived' activeVersionId: { type: 'text', nullable: true }, // FK to scorer_definition_versions.id authorId: { type: 'text', nullable: true }, organizationId: { type: 'text', nullable: true }, projectId: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const SCORER_DEFINITION_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, scorerDefinitionId: { type: 'text', nullable: false }, versionNumber: { type: 'integer', nullable: false }, name: { type: 'text', nullable: false }, description: { type: 'text', nullable: true }, type: { type: 'text', nullable: false }, // 'llm-judge', 'bias', 'toxicity', etc. model: { type: 'jsonb', nullable: true }, instructions: { type: 'text', nullable: true }, scoreRange: { type: 'jsonb', nullable: true }, presetConfig: { type: 'jsonb', nullable: true }, defaultSampling: { type: 'jsonb', nullable: true }, changedFields: { type: 'jsonb', nullable: true }, changeMessage: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const MCP_CLIENTS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, status: { type: 'text', nullable: false }, // 'draft', 'published', or 'archived' activeVersionId: { type: 'text', nullable: true }, // FK to mcp_client_versions.id authorId: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const MCP_CLIENT_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, mcpClientId: { type: 'text', nullable: false }, versionNumber: { type: 'integer', nullable: false }, name: { type: 'text', nullable: false }, description: { type: 'text', nullable: true }, servers: { type: 'jsonb', nullable: false }, changedFields: { type: 'jsonb', nullable: true }, changeMessage: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const MCP_SERVERS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, status: { type: 'text', nullable: false }, // 'draft', 'published', or 'archived' activeVersionId: { type: 'text', nullable: true }, // FK to mcp_server_versions.id authorId: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const MCP_SERVER_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, mcpServerId: { type: 'text', nullable: false }, versionNumber: { type: 'integer', nullable: false }, name: { type: 'text', nullable: false }, version: { type: 'text', nullable: false }, description: { type: 'text', nullable: true }, instructions: { type: 'text', nullable: true }, repository: { type: 'jsonb', nullable: true }, releaseDate: { type: 'text', nullable: true }, isLatest: { type: 'boolean', nullable: true }, packageCanonical: { type: 'text', nullable: true }, tools: { type: 'jsonb', nullable: true }, agents: { type: 'jsonb', nullable: true }, workflows: { type: 'jsonb', nullable: true }, changedFields: { type: 'jsonb', nullable: true }, changeMessage: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const WORKFLOW_DEFINITIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, description: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, inputSchema: { type: 'jsonb', nullable: false }, outputSchema: { type: 'jsonb', nullable: false }, stateSchema: { type: 'jsonb', nullable: true }, requestContextSchema: { type: 'jsonb', nullable: true }, graph: { type: 'jsonb', nullable: false }, schedule: { type: 'jsonb', nullable: true }, status: { type: 'text', nullable: false }, // 'active' | 'archived' source: { type: 'text', nullable: false }, // always 'storage' for now authorId: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const WORKSPACES_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, status: { type: 'text', nullable: false }, // 'draft', 'published', or 'archived' activeVersionId: { type: 'text', nullable: true }, // FK to workspace_versions.id authorId: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const WORKSPACE_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, workspaceId: { type: 'text', nullable: false }, versionNumber: { type: 'integer', nullable: false }, name: { type: 'text', nullable: false }, description: { type: 'text', nullable: true }, filesystem: { type: 'jsonb', nullable: true }, sandbox: { type: 'jsonb', nullable: true }, mounts: { type: 'jsonb', nullable: true }, search: { type: 'jsonb', nullable: true }, skills: { type: 'jsonb', nullable: true }, tools: { type: 'jsonb', nullable: true }, autoSync: { type: 'boolean', nullable: true }, operationTimeout: { type: 'integer', nullable: true }, changedFields: { type: 'jsonb', nullable: true }, changeMessage: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const SKILLS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, status: { type: 'text', nullable: false }, // 'draft', 'published', or 'archived' activeVersionId: { type: 'text', nullable: true }, // FK to skill_versions.id authorId: { type: 'text', nullable: true }, visibility: { type: 'text', nullable: true }, // 'private' | 'public' | null (legacy) favoriteCount: { type: 'integer', nullable: true }, // Denormalised count of favorites for this skill createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const FAVORITES_SCHEMA: Record = { userId: { type: 'text', nullable: false }, entityType: { type: 'text', nullable: false }, // 'agent' | 'skill' entityId: { type: 'text', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, }; /** * Per-author registry of authorized tool provider connections. Stores a stable * user-supplied label across agents. Composite primary key on * (authorId, providerId, connectionId). `scope` buckets identity: * 'per-author' (default), 'shared' (visible to all callers), or * 'caller-supplied' (authorId is a host-app end-user id forwarded via request * context). */ export const TOOL_PROVIDER_CONNECTIONS_SCHEMA: Record = { authorId: { type: 'text', nullable: false }, providerId: { type: 'text', nullable: false }, connectionId: { type: 'text', nullable: false }, toolkit: { type: 'text', nullable: false }, label: { type: 'text', nullable: true }, scope: { type: 'text', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const NOTIFICATIONS_SCHEMA: Record = { id: { type: 'text', nullable: false }, threadId: { type: 'text', nullable: false }, source: { type: 'text', nullable: false }, kind: { type: 'text', nullable: false }, priority: { type: 'text', nullable: false }, status: { type: 'text', nullable: false }, summary: { type: 'text', nullable: false }, payload: { type: 'jsonb', nullable: true }, resourceId: { type: 'text', nullable: true }, agentId: { type: 'text', nullable: true }, sourceId: { type: 'text', nullable: true }, dedupeKey: { type: 'text', nullable: true }, coalesceKey: { type: 'text', nullable: true }, coalescedCount: { type: 'integer', nullable: false }, attributes: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, deliveredAt: { type: 'timestamp', nullable: true }, seenAt: { type: 'timestamp', nullable: true }, dismissedAt: { type: 'timestamp', nullable: true }, archivedAt: { type: 'timestamp', nullable: true }, discardedAt: { type: 'timestamp', nullable: true }, deliverAt: { type: 'timestamp', nullable: true }, summaryAt: { type: 'timestamp', nullable: true }, deliveryReason: { type: 'text', nullable: true }, deliveryAttempts: { type: 'integer', nullable: false }, lastDeliveryAttemptAt: { type: 'timestamp', nullable: true }, lastDeliveryError: { type: 'text', nullable: true }, deliveredSignalId: { type: 'text', nullable: true }, summarySignalId: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, }; export const HARNESS_SESSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, ownerId: { type: 'text', nullable: false }, resourceId: { type: 'text', nullable: false }, threadId: { type: 'text', nullable: false }, parentSessionId: { type: 'text', nullable: true }, subagentDepth: { type: 'integer', nullable: true }, source: { type: 'jsonb', nullable: true }, origin: { type: 'text', nullable: false }, runtimeCompatibilityGeneration: { type: 'text', nullable: true }, modeId: { type: 'text', nullable: false }, modelId: { type: 'text', nullable: false }, title: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, state: { type: 'jsonb', nullable: true }, pending: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, lastActivityAt: { type: 'timestamp', nullable: false }, closingAt: { type: 'timestamp', nullable: true }, closeDeadlineAt: { type: 'timestamp', nullable: true }, closedAt: { type: 'timestamp', nullable: true }, deletedAt: { type: 'timestamp', nullable: true }, }; export const THREAD_STATE_SCHEMA: Record = { threadId: { type: 'text', nullable: false }, type: { type: 'text', nullable: false }, value: { type: 'jsonb', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const SKILL_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, skillId: { type: 'text', nullable: false }, versionNumber: { type: 'integer', nullable: false }, name: { type: 'text', nullable: false }, description: { type: 'text', nullable: false }, instructions: { type: 'text', nullable: false }, license: { type: 'text', nullable: true }, compatibility: { type: 'jsonb', nullable: true }, source: { type: 'jsonb', nullable: true }, references: { type: 'jsonb', nullable: true }, scripts: { type: 'jsonb', nullable: true }, assets: { type: 'jsonb', nullable: true }, files: { type: 'jsonb', nullable: true }, metadata: { type: 'jsonb', nullable: true }, tree: { type: 'jsonb', nullable: true }, changedFields: { type: 'jsonb', nullable: true }, changeMessage: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const SKILL_BLOBS_SCHEMA: Record = { hash: { type: 'text', nullable: false, primaryKey: true }, content: { type: 'text', nullable: false }, size: { type: 'integer', nullable: false }, mimeType: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const OBSERVATIONAL_MEMORY_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, lookupKey: { type: 'text', nullable: false }, // 'resource:{resourceId}' or 'thread:{threadId}' scope: { type: 'text', nullable: false }, // 'resource' or 'thread' resourceId: { type: 'text', nullable: true }, threadId: { type: 'text', nullable: true }, activeObservations: { type: 'text', nullable: false }, // JSON array of observations activeObservationsPendingUpdate: { type: 'text', nullable: true }, // JSON array, used during updates originType: { type: 'text', nullable: false }, // 'initialization', 'observation', or 'reflection' config: { type: 'text', nullable: false }, // JSON object generationCount: { type: 'integer', nullable: false }, supersededBy: OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS.supersededBy, lastObservedAt: { type: 'timestamp', nullable: true }, lastReflectionAt: { type: 'timestamp', nullable: true }, pendingMessageTokens: { type: 'integer', nullable: false }, // Token count totalTokensObserved: { type: 'integer', nullable: false }, // Running total of all observed tokens observationTokenCount: { type: 'integer', nullable: false }, // Current observation size in tokens isObserving: { type: 'boolean', nullable: false }, isReflecting: { type: 'boolean', nullable: false }, observedMessageIds: { type: 'jsonb', nullable: true }, // JSON array of message IDs already observed observedTimezone: { type: 'text', nullable: true }, // Timezone used for Observer date formatting (e.g., "America/Los_Angeles") // Async buffering columns bufferedObservations: { type: 'text', nullable: true }, // JSON string of buffered observation content bufferedObservationTokens: { type: 'integer', nullable: true }, // Token count of buffered observations bufferedMessageIds: { type: 'jsonb', nullable: true }, // JSON array of message IDs in the buffer bufferedReflection: { type: 'text', nullable: true }, // JSON string of buffered reflection content bufferedReflectionTokens: { type: 'integer', nullable: true }, // Token count of buffered reflection (post-compression) bufferedReflectionInputTokens: { type: 'integer', nullable: true }, // Token count of observations fed to reflector (pre-compression) reflectedObservationLineCount: { type: 'integer', nullable: true }, // Number of observation lines that were reflected on during async buffering bufferedObservationChunks: { type: 'jsonb', nullable: true }, // JSON array of BufferedObservationChunk objects isBufferingObservation: { type: 'boolean', nullable: false }, isBufferingReflection: { type: 'boolean', nullable: false }, lastBufferedAtTokens: { type: 'integer', nullable: false }, lastBufferedAtTime: { type: 'timestamp', nullable: true }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; // Dataset schemas export const DATASETS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, name: { type: 'text', nullable: false }, description: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, inputSchema: { type: 'jsonb', nullable: true }, groundTruthSchema: { type: 'jsonb', nullable: true }, requestContextSchema: { type: 'jsonb', nullable: true }, tags: { type: 'jsonb', nullable: true }, targetType: { type: 'text', nullable: true }, targetIds: { type: 'jsonb', nullable: true }, scorerIds: { type: 'jsonb', nullable: true }, organizationId: { type: 'text', nullable: true }, projectId: { type: 'text', nullable: true }, candidateKey: { type: 'text', nullable: true }, candidateId: { type: 'text', nullable: true }, version: { type: 'integer', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const DATASET_ITEMS_SCHEMA: Record = { id: { type: 'text', nullable: false }, datasetId: { type: 'text', nullable: false, references: { table: 'mastra_datasets', column: 'id' } }, datasetVersion: { type: 'integer', nullable: false }, externalId: { type: 'text', nullable: true }, organizationId: { type: 'text', nullable: true }, projectId: { type: 'text', nullable: true }, validTo: { type: 'integer', nullable: true }, isDeleted: { type: 'boolean', nullable: false }, input: { type: 'jsonb', nullable: false }, groundTruth: { type: 'jsonb', nullable: true }, requestContext: { type: 'jsonb', nullable: true }, metadata: { type: 'jsonb', nullable: true }, source: { type: 'jsonb', nullable: true }, expectedTrajectory: { type: 'jsonb', nullable: true }, toolMocks: { type: 'jsonb', nullable: true }, unmockedToolPolicy: { type: 'text', nullable: true }, scorerIds: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const DATASET_VERSIONS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, datasetId: { type: 'text', nullable: false, references: { table: 'mastra_datasets', column: 'id' } }, version: { type: 'integer', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, }; // Experiment schemas export const EXPERIMENTS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, name: { type: 'text', nullable: true }, description: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, provenance: { type: 'jsonb', nullable: true }, runnerAttestation: { type: 'jsonb', nullable: true }, experimentSetId: { type: 'text', nullable: true }, comparisonId: { type: 'text', nullable: true }, variantId: { type: 'text', nullable: true }, trialIndex: { type: 'integer', nullable: true }, datasetId: { type: 'text', nullable: true, references: { table: 'mastra_datasets', column: 'id' } }, datasetVersion: { type: 'integer', nullable: true }, // Nullable: caller-driven ingestion experiments have no registered target. targetType: { type: 'text', nullable: true }, targetId: { type: 'text', nullable: true }, // Run-level scorer IDs pinned at create time for caller-driven experiments. scorerIds: { type: 'jsonb', nullable: true }, // Stored-scorer versions pinned at create time: { [scorerId]: versionId }. scorerVersions: { type: 'jsonb', nullable: true }, status: { type: 'text', nullable: false }, totalItems: { type: 'integer', nullable: false }, succeededCount: { type: 'integer', nullable: false }, failedCount: { type: 'integer', nullable: false }, skippedCount: { type: 'integer', nullable: false }, startedAt: { type: 'timestamp', nullable: true }, completedAt: { type: 'timestamp', nullable: true }, agentVersion: { type: 'text', nullable: true }, organizationId: { type: 'text', nullable: true }, projectId: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const EXPERIMENT_RESULTS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, experimentId: { type: 'text', nullable: false, references: { table: 'mastra_experiments', column: 'id' } }, itemId: { type: 'text', nullable: false, references: { table: 'mastra_dataset_items', column: 'id' } }, itemDatasetVersion: { type: 'integer', nullable: true }, input: { type: 'jsonb', nullable: false }, output: { type: 'jsonb', nullable: true }, groundTruth: { type: 'jsonb', nullable: true }, metadata: { type: 'jsonb', nullable: true }, error: { type: 'jsonb', nullable: true }, startedAt: { type: 'timestamp', nullable: false }, completedAt: { type: 'timestamp', nullable: false }, retryCount: { type: 'integer', nullable: false }, // Nullable for backwards compatibility with pre-existing rows; readers treat NULL as 0. attempt: { type: 'integer', nullable: true }, traceId: { type: 'text', nullable: true }, status: { type: 'text', nullable: true }, tags: { type: 'jsonb', nullable: true }, comment: { type: 'text', nullable: true }, toolMockReport: { type: 'jsonb', nullable: true }, organizationId: { type: 'text', nullable: true }, projectId: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const KNOWLEDGE_NODES_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, type: { type: 'text', nullable: false }, name: { type: 'text', nullable: false }, canonicalName: { type: 'text', nullable: false }, kind: { type: 'text', nullable: true }, content: { type: 'text', nullable: true }, description: { type: 'text', nullable: true }, scope: { type: 'jsonb', nullable: false }, scopeKey: { type: 'text', nullable: false }, version: { type: 'integer', nullable: false }, mergedInto: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const KNOWLEDGE_RECORDS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, node: { type: 'text', nullable: false }, text: { type: 'text', nullable: false }, scope: { type: 'jsonb', nullable: false }, scopeKey: { type: 'text', nullable: false }, sourceThreadId: { type: 'text', nullable: false }, capturedAt: { type: 'timestamp', nullable: false }, when: { type: 'timestamp', nullable: true }, maxScope: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, deletedAt: { type: 'timestamp', nullable: true }, deletedBy: { type: 'text', nullable: true }, }; export const KNOWLEDGE_MENTIONS_SCHEMA: Record = { sourceType: { type: 'text', nullable: false }, sourceId: { type: 'text', nullable: false }, recordId: { type: 'text', nullable: false }, }; /** * @deprecated Curation cursors were removed and Knowledge no longer creates this table. Kept so adapters built * against earlier Core versions still resolve the export. */ export const KNOWLEDGE_CURSORS_SCHEMA: Record = { sourceThreadId: { type: 'text', nullable: false }, agent: { type: 'text', nullable: false }, lastKnowledgeId: { type: 'text', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; export const KNOWLEDGE_ACTIVITY_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, action: { type: 'text', nullable: false }, recordType: { type: 'text', nullable: false }, recordId: { type: 'text', nullable: false }, scope: { type: 'jsonb', nullable: false }, scopeKey: { type: 'text', nullable: false }, sourceThreadId: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; export const KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, idempotencyKey: { type: 'text', nullable: false }, documentId: { type: 'text', nullable: false }, documentType: { type: 'text', nullable: false }, operation: { type: 'text', nullable: false }, scope: { type: 'jsonb', nullable: false }, scopeKey: { type: 'text', nullable: false }, status: { type: 'text', nullable: false }, attempts: { type: 'integer', nullable: false }, availableAt: { type: 'timestamp', nullable: false }, claimedAt: { type: 'timestamp', nullable: true }, claimedBy: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, completedAt: { type: 'timestamp', nullable: true }, }; /** Normalized Knowledge v2 node schema plus nullable v1 facade columns. */ export const KNOWLEDGE_V2_NODES_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, name: { type: 'text', nullable: false }, kind: { type: 'text', nullable: true }, isScope: { type: 'boolean', nullable: false }, metadata: { type: 'jsonb', nullable: true }, version: { type: 'integer', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, deletedAt: { type: 'timestamp', nullable: true }, deletedBy: { type: 'text', nullable: true }, type: { type: 'text', nullable: true }, canonicalName: { type: 'text', nullable: true }, content: { type: 'text', nullable: true }, description: { type: 'text', nullable: true }, scope: { type: 'jsonb', nullable: true }, scopeKey: { type: 'text', nullable: true }, mergedInto: { type: 'text', nullable: true }, }; /** Knowledge v2 record schema. Scope rules live in `mastra_knowledge_record_scopes`. */ export const KNOWLEDGE_V2_RECORDS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, node: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, text: { type: 'text', nullable: false }, metadata: { type: 'jsonb', nullable: true }, version: { type: 'integer', nullable: false }, capturedAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, deletedAt: { type: 'timestamp', nullable: true }, deletedBy: { type: 'text', nullable: true }, scope: { type: 'jsonb', nullable: true }, scopeKey: { type: 'text', nullable: true }, sourceThreadId: { type: 'text', nullable: true }, when: { type: 'timestamp', nullable: true }, }; export const KNOWLEDGE_V2_MENTIONS_SCHEMA: Record = { recordId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_RECORDS, column: 'id' } }, targetNodeId: { type: 'text', nullable: true, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, sourceType: { type: 'text', nullable: true }, sourceId: { type: 'text', nullable: true }, }; export const KNOWLEDGE_NODE_SCOPES_SCHEMA: Record = { nodeId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, scopeNodeId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, addedAt: { type: 'timestamp', nullable: false }, }; export const KNOWLEDGE_RECORD_SCOPES_SCHEMA: Record = { recordId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_RECORDS, column: 'id' } }, scopeNodeId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, addedAt: { type: 'timestamp', nullable: false }, }; export const KNOWLEDGE_SCOPE_GRANTS_SCHEMA: Record = { scopeNodeId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, scopeRefId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, role: { type: 'text', nullable: false }, canSuggest: { type: 'boolean', nullable: true }, }; export const KNOWLEDGE_ACCESS_STATE_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, epoch: { type: 'integer', nullable: false }, schemaVersion: { type: 'integer', nullable: false }, }; export const KNOWLEDGE_SCOPE_ADDRESSES_SCHEMA: Record = { address: { type: 'text', nullable: false, primaryKey: true }, scopeNodeId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, }; export const KNOWLEDGE_NODE_ADDRESSES_SCHEMA: Record = { source: { type: 'text', nullable: false }, address: { type: 'text', nullable: false }, nodeId: { type: 'text', nullable: false, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, }; export const KNOWLEDGE_IMPORT_STATE_SCHEMA: Record = { importerId: { type: 'text', nullable: false }, binding: { type: 'text', nullable: false }, key: { type: 'text', nullable: false }, value: { type: 'text', nullable: false }, }; export const KNOWLEDGE_IMPORT_RUNS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, importerId: { type: 'text', nullable: false }, binding: { type: 'text', nullable: false }, importKind: { type: 'text', nullable: false }, triggerKind: { type: 'text', nullable: false }, status: { type: 'text', nullable: false }, error: { type: 'text', nullable: true }, transcriptThreadId: { type: 'text', nullable: true }, traceId: { type: 'text', nullable: true }, queuedAt: { type: 'timestamp', nullable: false }, startedAt: { type: 'timestamp', nullable: true }, completedAt: { type: 'timestamp', nullable: true }, }; export const KNOWLEDGE_V2_ACTIVITY_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, action: { type: 'text', nullable: false }, targetType: { type: 'text', nullable: true }, targetId: { type: 'text', nullable: true }, contextScopeId: { type: 'text', nullable: true, references: { table: TABLE_KNOWLEDGE_NODES, column: 'id' } }, importRunId: { type: 'text', nullable: true, references: { table: TABLE_KNOWLEDGE_IMPORT_RUNS, column: 'id' } }, details: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, recordType: { type: 'text', nullable: true }, recordId: { type: 'text', nullable: true }, scope: { type: 'jsonb', nullable: true }, scopeKey: { type: 'text', nullable: true }, sourceThreadId: { type: 'text', nullable: true }, }; export const KNOWLEDGE_PROPOSALS_SCHEMA: Record = { id: { type: 'text', nullable: false, primaryKey: true }, targetType: { type: 'text', nullable: false }, targetId: { type: 'text', nullable: false }, action: { type: 'text', nullable: false }, changes: { type: 'jsonb', nullable: false }, reason: { type: 'text', nullable: true }, proposerContextScopeId: { type: 'text', nullable: false }, expectedVersion: { type: 'integer', nullable: false }, status: { type: 'text', nullable: false }, reviewerContextScopeId: { type: 'text', nullable: true }, reviewedAt: { type: 'timestamp', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, }; /** * Schema definitions for all core tables. */ export const TABLE_SCHEMAS: Record> = { [TABLE_WORKFLOW_SNAPSHOT]: { workflow_name: { type: 'text', }, run_id: { type: 'text', }, resourceId: { type: 'text', nullable: true }, snapshot: { type: 'jsonb', }, createdAt: { type: 'timestamp', }, updatedAt: { type: 'timestamp', }, }, [TABLE_SCORERS]: SCORERS_SCHEMA, [TABLE_THREADS]: { id: { type: 'text', nullable: false, primaryKey: true }, resourceId: { type: 'text', nullable: false }, title: { type: 'text', nullable: false }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }, [TABLE_MESSAGES]: { id: { type: 'text', nullable: false, primaryKey: true }, thread_id: { type: 'text', nullable: false }, content: { type: 'text', nullable: false }, role: { type: 'text', nullable: false }, type: { type: 'text', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, resourceId: { type: 'text', nullable: true }, }, [TABLE_SPANS]: SPAN_SCHEMA, [TABLE_TRACES]: { id: { type: 'text', nullable: false, primaryKey: true }, parentSpanId: { type: 'text', nullable: true }, name: { type: 'text', nullable: false }, traceId: { type: 'text', nullable: false }, scope: { type: 'text', nullable: false }, kind: { type: 'integer', nullable: false }, attributes: { type: 'jsonb', nullable: true }, status: { type: 'jsonb', nullable: true }, events: { type: 'jsonb', nullable: true }, links: { type: 'jsonb', nullable: true }, other: { type: 'text', nullable: true }, startTime: { type: 'bigint', nullable: false }, endTime: { type: 'bigint', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, }, [TABLE_RESOURCES]: { id: { type: 'text', nullable: false, primaryKey: true }, workingMemory: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }, [TABLE_AGENTS]: AGENTS_SCHEMA, [TABLE_AGENT_VERSIONS]: AGENT_VERSIONS_SCHEMA, [TABLE_PROMPT_BLOCKS]: PROMPT_BLOCKS_SCHEMA, [TABLE_PROMPT_BLOCK_VERSIONS]: PROMPT_BLOCK_VERSIONS_SCHEMA, [TABLE_SCORER_DEFINITIONS]: SCORER_DEFINITIONS_SCHEMA, [TABLE_SCORER_DEFINITION_VERSIONS]: SCORER_DEFINITION_VERSIONS_SCHEMA, [TABLE_MCP_CLIENTS]: MCP_CLIENTS_SCHEMA, [TABLE_MCP_CLIENT_VERSIONS]: MCP_CLIENT_VERSIONS_SCHEMA, [TABLE_MCP_SERVERS]: MCP_SERVERS_SCHEMA, [TABLE_MCP_SERVER_VERSIONS]: MCP_SERVER_VERSIONS_SCHEMA, [TABLE_WORKSPACES]: WORKSPACES_SCHEMA, [TABLE_WORKSPACE_VERSIONS]: WORKSPACE_VERSIONS_SCHEMA, [TABLE_SKILLS]: SKILLS_SCHEMA, [TABLE_SKILL_VERSIONS]: SKILL_VERSIONS_SCHEMA, [TABLE_SKILL_BLOBS]: SKILL_BLOBS_SCHEMA, [TABLE_DATASETS]: DATASETS_SCHEMA, [TABLE_DATASET_ITEMS]: DATASET_ITEMS_SCHEMA, [TABLE_DATASET_VERSIONS]: DATASET_VERSIONS_SCHEMA, [TABLE_EXPERIMENTS]: EXPERIMENTS_SCHEMA, [TABLE_EXPERIMENT_RESULTS]: EXPERIMENT_RESULTS_SCHEMA, [TABLE_FAVORITES]: FAVORITES_SCHEMA, [TABLE_BACKGROUND_TASKS]: { id: { type: 'text', nullable: false, primaryKey: true }, tool_call_id: { type: 'text', nullable: false }, tool_name: { type: 'text', nullable: false }, agent_id: { type: 'text', nullable: false }, run_id: { type: 'text', nullable: false }, thread_id: { type: 'text', nullable: true }, resource_id: { type: 'text', nullable: true }, status: { type: 'text', nullable: false }, args: { type: 'jsonb', nullable: false }, result: { type: 'jsonb', nullable: true }, error: { type: 'jsonb', nullable: true }, suspend_payload: { type: 'jsonb', nullable: true }, retry_count: { type: 'integer', nullable: false }, max_retries: { type: 'integer', nullable: false }, timeout_ms: { type: 'integer', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, startedAt: { type: 'timestamp', nullable: true }, suspendedAt: { type: 'timestamp', nullable: true }, completedAt: { type: 'timestamp', nullable: true }, ownerId: { type: 'text', nullable: true }, leaseExpiresAt: { type: 'timestamp', nullable: true }, expiresAt: { type: 'timestamp', nullable: true }, metadata: { type: 'jsonb', nullable: true }, }, [TABLE_SCHEDULES]: { id: { type: 'text', nullable: false, primaryKey: true }, target: { type: 'jsonb', nullable: false }, cron: { type: 'text', nullable: false }, timezone: { type: 'text', nullable: true }, status: { type: 'text', nullable: false }, next_fire_at: { type: 'bigint', nullable: false }, last_fire_at: { type: 'bigint', nullable: true }, last_run_id: { type: 'text', nullable: true }, created_at: { type: 'bigint', nullable: false }, updated_at: { type: 'bigint', nullable: false }, metadata: { type: 'jsonb', nullable: true }, owner_type: { type: 'text', nullable: true }, owner_id: { type: 'text', nullable: true }, run_at: { type: 'bigint', nullable: true }, end_at: { type: 'bigint', nullable: true }, }, [TABLE_SCHEDULE_TRIGGERS]: { id: { type: 'text', nullable: false, primaryKey: true }, schedule_id: { type: 'text', nullable: false }, run_id: { type: 'text', nullable: true }, scheduled_fire_at: { type: 'bigint', nullable: false }, actual_fire_at: { type: 'bigint', nullable: false }, outcome: { type: 'text', nullable: false }, error: { type: 'text', nullable: true }, trigger_kind: { type: 'text', nullable: false }, parent_trigger_id: { type: 'text', nullable: true }, metadata: { type: 'jsonb', nullable: true }, }, [TABLE_CHANNEL_INSTALLATIONS]: { id: { type: 'text', nullable: false, primaryKey: true }, platform: { type: 'text', nullable: false }, agentId: { type: 'text', nullable: false }, status: { type: 'text', nullable: false }, webhookId: { type: 'text', nullable: true }, data: { type: 'jsonb', nullable: false }, configHash: { type: 'text', nullable: true }, error: { type: 'text', nullable: true }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }, [TABLE_CHANNEL_CONFIG]: { platform: { type: 'text', nullable: false, primaryKey: true }, data: { type: 'jsonb', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }, [TABLE_TOOL_PROVIDER_CONNECTIONS]: TOOL_PROVIDER_CONNECTIONS_SCHEMA, [TABLE_NOTIFICATIONS]: NOTIFICATIONS_SCHEMA, [TABLE_HARNESS_SESSIONS]: HARNESS_SESSIONS_SCHEMA, [TABLE_THREAD_STATE]: THREAD_STATE_SCHEMA, [TABLE_WORKFLOW_DEFINITIONS]: WORKFLOW_DEFINITIONS_SCHEMA, [TABLE_KNOWLEDGE_NODES]: KNOWLEDGE_NODES_SCHEMA, [TABLE_KNOWLEDGE_RECORDS]: KNOWLEDGE_RECORDS_SCHEMA, [TABLE_KNOWLEDGE_MENTIONS]: KNOWLEDGE_MENTIONS_SCHEMA, [TABLE_KNOWLEDGE_ACTIVITY]: KNOWLEDGE_ACTIVITY_SCHEMA, [TABLE_KNOWLEDGE_SEMANTIC_OUTBOX]: KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA, }; /** * Table-level config for tables that need composite primary keys or other table-level settings. * Keyed by table name. Tables not listed here use single-column PKs from their schema. */ export const TABLE_CONFIGS: Partial> = { [TABLE_DATASET_ITEMS]: { columns: DATASET_ITEMS_SCHEMA, compositePrimaryKey: ['id', 'datasetVersion'] }, [TABLE_FAVORITES]: { columns: FAVORITES_SCHEMA, compositePrimaryKey: ['userId', 'entityType', 'entityId'] }, [TABLE_TOOL_PROVIDER_CONNECTIONS]: { columns: TOOL_PROVIDER_CONNECTIONS_SCHEMA, compositePrimaryKey: ['authorId', 'providerId', 'connectionId'], }, [TABLE_NOTIFICATIONS]: { columns: NOTIFICATIONS_SCHEMA, compositePrimaryKey: ['threadId', 'id'] }, [TABLE_THREAD_STATE]: { columns: THREAD_STATE_SCHEMA, compositePrimaryKey: ['threadId', 'type'] }, [TABLE_KNOWLEDGE_MENTIONS]: { columns: KNOWLEDGE_MENTIONS_SCHEMA, compositePrimaryKey: ['sourceType', 'sourceId', 'recordId'], }, }; /** * Schema for the observational memory table. * Exported separately as OM is optional and not part of TABLE_NAMES. */ export const OBSERVATIONAL_MEMORY_TABLE_SCHEMA = { [TABLE_OBSERVATIONAL_MEMORY]: OBSERVATIONAL_MEMORY_SCHEMA, }; export const TABLE_WORKFLOW_RUN_OWNERS = 'mastra_workflow_run_owners'; export const TABLE_MEMORY_RUN_FENCES = 'mastra_memory_run_fences'; /** * Run ownership records for workflows stores that support run fencing. * `leaseExpiresAt` and `updatedAt` are epoch milliseconds on the database * clock; `leaseExpiresAt` is null once released. `updatedAt` is refreshed by * every claim, renewal and release and anchors `workflows.runOwnership` * retention. A run's first generation is the store clock in epoch * milliseconds, so a run claimed again after its record was pruned still gets * a higher generation. */ export const WORKFLOW_RUN_OWNERS_SCHEMA: Record = { runId: { type: 'text', nullable: false, primaryKey: true }, generation: { type: 'bigint', nullable: false }, ownerId: { type: 'text', nullable: false }, leaseExpiresAt: { type: 'bigint', nullable: true }, updatedAt: { type: 'bigint', nullable: false }, }; /** * The claim each run's memory writes must carry, for memory stores that support run fencing. * `retiredAt` is epoch milliseconds on the database clock, set once the * execution holding the fence settles and cleared when the fence is raised * again. It anchors `memory.runFences` retention; NULL rows are never pruned. */ export const MEMORY_RUN_FENCES_SCHEMA: Record = { runId: { type: 'text', nullable: false, primaryKey: true }, generation: { type: 'bigint', nullable: false }, ownerId: { type: 'text', nullable: false }, retiredAt: { type: 'bigint', nullable: true }, }; /** * Schemas for the run fencing tables. * Exported separately because only adapters that support run fencing create them, * so they are not part of TABLE_NAMES. */ export const RUN_FENCING_TABLE_SCHEMAS = { [TABLE_WORKFLOW_RUN_OWNERS]: WORKFLOW_RUN_OWNERS_SCHEMA, [TABLE_MEMORY_RUN_FENCES]: MEMORY_RUN_FENCES_SCHEMA, }; export const TABLE_WORKFLOW_RUNS = 'mastra_workflow_runs'; export const TABLE_WORKFLOW_RUN_ENTRIES = 'mastra_workflow_run_entries'; /** * Storage v2 run headers: the run's `WorkflowRunHeader` (its `WorkflowRunState` without * `context` and `value`). `status` and `threadId` are copied out of the snapshot so they * can be filtered and indexed. `lastSeq` is the highest `seq` the run's entries have used; * it only increases, across checkpoints too. `startStateSeq` is the state version the run's * current drive started from (see `StoredWorkflowRunHeader`). `stateShared` is set once another * run's state builds on this run's state, so a checkpoint keeps the earlier state entries and a * delete knows to detach the runs built on it. `stateSeq`, `statePatchCount`, `statePatchBytes` * and `stateBytes` track where the run's state chain stands (see `StoredStateColumns`). * @experimental */ export const WORKFLOW_RUNS_SCHEMA: Record = { workflow_name: { type: 'text', nullable: false }, run_id: { type: 'text', nullable: false }, resourceId: { type: 'text', nullable: true }, threadId: { type: 'text', nullable: true }, status: { type: 'text', nullable: false }, header: { type: 'jsonb', nullable: false }, lastSeq: { type: 'integer', nullable: false }, startStateSeq: { type: 'integer', nullable: false }, stateShared: { type: 'boolean', nullable: false }, stateSeq: { type: 'integer', nullable: false }, statePatchCount: { type: 'integer', nullable: false }, statePatchBytes: { type: 'integer', nullable: false }, stateBytes: { type: 'integer', nullable: true }, /** Picked when the run is first stored, kept until it is deleted (see `StoredWorkflowRunHeader`). */ runToken: { type: 'text', nullable: false }, createdAt: { type: 'timestamp', nullable: false }, updatedAt: { type: 'timestamp', nullable: false }, }; /** * Storage v2 run entries: one step result (`kind: 'step'`) or one state entry (`kind` `state`, * `state-patch`, `state-base` or `state-draft`, `step_id` null; see `WorkflowRunEntry`) per row, * ordered by `seq` within a run. `first_seq` is a step entry's `firstSeq`: the `seq` of the step's * first entry, set when the entry replaced (deleted) the step's earlier ones. * @experimental */ export const WORKFLOW_RUN_ENTRIES_SCHEMA: Record = { workflow_name: { type: 'text', nullable: false }, run_id: { type: 'text', nullable: false }, seq: { type: 'integer', nullable: false }, kind: { type: 'text', nullable: false }, step_id: { type: 'text', nullable: true }, payload: { type: 'jsonb', nullable: true }, first_seq: { type: 'integer', nullable: true }, }; /** * Table configs for the storage v2 run tables (`storageVersion: 2`). * Exported separately because only adapters that support run journals create them, * so they are not part of TABLE_NAMES. * @experimental */ export const WORKFLOW_RUN_JOURNAL_TABLE_CONFIGS = { [TABLE_WORKFLOW_RUNS]: { columns: WORKFLOW_RUNS_SCHEMA, compositePrimaryKey: ['workflow_name', 'run_id'] }, [TABLE_WORKFLOW_RUN_ENTRIES]: { columns: WORKFLOW_RUN_ENTRIES_SCHEMA, compositePrimaryKey: ['workflow_name', 'run_id', 'seq'], }, } satisfies Record;