UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

263 lines • 13.6 kB
import type { BackgroundTask } from '../../background-tasks/types.js'; import type { StorageThreadType } from '../../memory/types.js'; import type { StorageAgentType, StorageMCPClientType, StorageMCPServerType, StorageMessageType, StoragePromptBlockType, StorageResourceType, StorageScorerDefinitionType, StorageFavoriteType, StorageWorkspaceType, StorageSkillType, StorageWorkflowRun, ObservationalMemoryRecord, DatasetRecord, DatasetItemRow, DatasetVersion, Experiment, ExperimentResult } from '../types.js'; import type { AgentVersion } from './agents/index.js'; import type { MCPClientVersion } from './mcp-clients/index.js'; import type { MCPServerVersion } from './mcp-servers/index.js'; import type { TraceEntry } from './observability/index.js'; import type { FeedbackRecord } from './observability/feedback.js'; import type { LogRecord } from './observability/logs.js'; import type { MetricRecord } from './observability/metrics.js'; import type { ScoreRecord } from './observability/scores.js'; import type { PromptBlockVersion } from './prompt-blocks/index.js'; import type { Schedule, ScheduleTrigger } from './schedules/base.js'; import type { ScorerDefinitionVersion } from './scorer-definitions/index.js'; import type { SkillVersion } from './skills/index.js'; import type { WorkspaceVersion } from './workspaces/index.js'; /** * InMemoryDB is a thin database layer for in-memory storage. * It holds all the Maps that store data, similar to how a real database * connection (pg-promise client, libsql client) is shared across domains. * * Each domain receives a reference to this db and operates on the relevant Maps. */ export declare class InMemoryDB { readonly threads: Map<string, StorageThreadType>; readonly messages: Map<string, StorageMessageType>; readonly resources: Map<string, StorageResourceType>; readonly workflows: Map<string, StorageWorkflowRun>; readonly scores: Map<string, { createdAt: Date; updatedAt: Date | null; id: string; scorerId: string; entityId: string; runId: string; output: unknown; score: number; scorer: Record<string, unknown>; source: "LIVE" | "TEST"; entity: Record<string, unknown>; input?: unknown; additionalContext?: Record<string, unknown> | undefined; requestContext?: Record<string, unknown> | undefined; extractStepResult?: Record<string, unknown> | undefined; extractPrompt?: string | undefined; analyzeStepResult?: Record<string, unknown> | undefined; analyzePrompt?: string | undefined; reason?: string | undefined; reasonPrompt?: string | undefined; metadata?: Record<string, unknown> | undefined; entityType?: string | undefined; structuredOutput?: boolean | undefined; traceId?: string | undefined; spanId?: string | undefined; resourceId?: string | undefined; threadId?: string | undefined; preprocessStepResult?: Record<string, unknown> | undefined; preprocessPrompt?: string | undefined; generateScorePrompt?: string | undefined; generateReasonPrompt?: string | undefined; }>; readonly traces: Map<string, TraceEntry>; readonly metricRecords: MetricRecord[]; readonly logRecords: LogRecord[]; readonly scoreRecords: ScoreRecord[]; readonly feedbackRecords: FeedbackRecord[]; observabilityNextCursorId: number; readonly traceCursorIds: Map<string, number>; readonly branchCursorIds: Map<string, number>; readonly metricCursorIds: Map<{ labels: Record<string, string>; timestamp: Date; name: string; value: number; source?: string | null | undefined; provider?: string | null | undefined; model?: string | null | undefined; estimatedCost?: number | null | undefined; costUnit?: string | null | undefined; costMetadata?: Record<string, unknown> | null | undefined; metadata?: Record<string, unknown> | null | undefined; executionSource?: string | null | undefined; tags?: string[] | null | undefined; entityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; entityId?: string | null | undefined; entityName?: string | null | undefined; parentEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; parentEntityId?: string | null | undefined; parentEntityName?: string | null | undefined; rootEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; rootEntityId?: string | null | undefined; rootEntityName?: string | null | undefined; userId?: string | null | undefined; organizationId?: string | null | undefined; resourceId?: string | null | undefined; runId?: string | null | undefined; sessionId?: string | null | undefined; threadId?: string | null | undefined; requestId?: string | null | undefined; environment?: string | null | undefined; serviceName?: string | null | undefined; scope?: Record<string, unknown> | null | undefined; entityVersionId?: string | null | undefined; parentEntityVersionId?: string | null | undefined; rootEntityVersionId?: string | null | undefined; experimentId?: string | null | undefined; metricId?: string | null | undefined; traceId?: string | null | undefined; spanId?: string | null | undefined; }, number>; readonly logCursorIds: Map<{ timestamp: Date; level: "debug" | "info" | "warn" | "error" | "fatal"; message: string; source?: string | null | undefined; metadata?: Record<string, unknown> | null | undefined; executionSource?: string | null | undefined; tags?: string[] | null | undefined; entityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; entityId?: string | null | undefined; entityName?: string | null | undefined; parentEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; parentEntityId?: string | null | undefined; parentEntityName?: string | null | undefined; rootEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; rootEntityId?: string | null | undefined; rootEntityName?: string | null | undefined; userId?: string | null | undefined; organizationId?: string | null | undefined; resourceId?: string | null | undefined; runId?: string | null | undefined; sessionId?: string | null | undefined; threadId?: string | null | undefined; requestId?: string | null | undefined; environment?: string | null | undefined; serviceName?: string | null | undefined; scope?: Record<string, unknown> | null | undefined; entityVersionId?: string | null | undefined; parentEntityVersionId?: string | null | undefined; rootEntityVersionId?: string | null | undefined; experimentId?: string | null | undefined; logId?: string | null | undefined; data?: Record<string, unknown> | null | undefined; traceId?: string | null | undefined; spanId?: string | null | undefined; }, number>; readonly scoreCursorIds: Map<{ timestamp: Date; scorerId: string; score: number; scoreTraceId?: string | null | undefined; metadata?: Record<string, unknown> | null | undefined; executionSource?: string | null | undefined; tags?: string[] | null | undefined; entityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; entityId?: string | null | undefined; entityName?: string | null | undefined; parentEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; parentEntityId?: string | null | undefined; parentEntityName?: string | null | undefined; rootEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; rootEntityId?: string | null | undefined; rootEntityName?: string | null | undefined; userId?: string | null | undefined; organizationId?: string | null | undefined; resourceId?: string | null | undefined; runId?: string | null | undefined; sessionId?: string | null | undefined; threadId?: string | null | undefined; requestId?: string | null | undefined; environment?: string | null | undefined; serviceName?: string | null | undefined; scope?: Record<string, unknown> | null | undefined; entityVersionId?: string | null | undefined; parentEntityVersionId?: string | null | undefined; rootEntityVersionId?: string | null | undefined; experimentId?: string | null | undefined; scoreId?: string | null | undefined; traceId?: string | null | undefined; spanId?: string | null | undefined; scorerName?: string | null | undefined; scorerVersion?: string | null | undefined; scoreSource?: string | null | undefined; source?: string | null | undefined; reason?: string | null | undefined; }, number>; readonly feedbackCursorIds: Map<{ timestamp: Date; feedbackType: string; value: string | number; sourceId?: string | null | undefined; metadata?: Record<string, unknown> | null | undefined; executionSource?: string | null | undefined; tags?: string[] | null | undefined; entityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; entityId?: string | null | undefined; entityName?: string | null | undefined; parentEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; parentEntityId?: string | null | undefined; parentEntityName?: string | null | undefined; rootEntityType?: import("../../_types/@internal_core/dist/index.js").EntityType | null | undefined; rootEntityId?: string | null | undefined; rootEntityName?: string | null | undefined; userId?: string | null | undefined; organizationId?: string | null | undefined; resourceId?: string | null | undefined; runId?: string | null | undefined; sessionId?: string | null | undefined; threadId?: string | null | undefined; requestId?: string | null | undefined; environment?: string | null | undefined; serviceName?: string | null | undefined; scope?: Record<string, unknown> | null | undefined; entityVersionId?: string | null | undefined; parentEntityVersionId?: string | null | undefined; rootEntityVersionId?: string | null | undefined; experimentId?: string | null | undefined; feedbackId?: string | null | undefined; traceId?: string | null | undefined; spanId?: string | null | undefined; feedbackSource?: string | null | undefined; source?: string | null | undefined; comment?: string | null | undefined; feedbackUserId?: string | null | undefined; }, number>; readonly agents: Map<string, StorageAgentType>; readonly agentVersions: Map<string, AgentVersion>; readonly promptBlocks: Map<string, StoragePromptBlockType>; readonly promptBlockVersions: Map<string, PromptBlockVersion>; readonly scorerDefinitions: Map<string, StorageScorerDefinitionType>; readonly scorerDefinitionVersions: Map<string, ScorerDefinitionVersion>; readonly mcpClients: Map<string, StorageMCPClientType>; readonly mcpClientVersions: Map<string, MCPClientVersion>; readonly mcpServers: Map<string, StorageMCPServerType>; readonly mcpServerVersions: Map<string, MCPServerVersion>; readonly workspaces: Map<string, StorageWorkspaceType>; readonly workspaceVersions: Map<string, WorkspaceVersion>; readonly skills: Map<string, StorageSkillType>; readonly skillVersions: Map<string, SkillVersion>; /** * Favorites keyed by `${userId}\u0000${entityType}\u0000${entityId}`. The * favorites domain owns reads/writes; this Map lives on InMemoryDB so the * favorites domain can also mutate `agents` / `skills` `favoriteCount` atomically * within the same synchronous block. */ readonly favorites: Map<string, StorageFavoriteType>; /** Observational memory records, keyed by resourceId, each holding array of records (generations) */ readonly observationalMemory: Map<string, ObservationalMemoryRecord[]>; readonly datasets: Map<string, DatasetRecord>; readonly datasetItems: Map<string, DatasetItemRow[]>; readonly datasetVersions: Map<string, DatasetVersion>; readonly experiments: Map<string, Experiment>; readonly experimentResults: Map<string, ExperimentResult>; readonly backgroundTasks: Map<string, BackgroundTask>; readonly schedules: Map<string, Schedule>; readonly scheduleTriggers: ScheduleTrigger[]; /** * Clears all data from all collections. * Useful for testing. */ clear(): void; } //# sourceMappingURL=inmemory-db.d.ts.map