UNPKG

@mastra/core

Version:

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

132 lines 4.61 kB
import { TTLCache } from '@isaacs/ttlcache'; import type { MastraLanguageModel } from '../../llm/model/shared.types.js'; import type { CoreTool } from '../../tools/types.js'; import type { MessageList } from '../message-list/index.js'; import type { SaveQueueManager } from '../save-queue/index.js'; import type { RunRegistryEntry } from './types.js'; /** * Global registry for accessing run entries from workflow steps. * This is necessary because workflow steps don't have direct access to * the DurableAgent instance's registry. * * Entries are keyed by runId (which are unique UUIDs). * * Uses TTLCache to prevent unbounded memory growth: entries auto-expire * after 10 minutes (refreshed on access) and the registry is hard-capped * at 1000 concurrent entries. */ export declare const globalRunRegistry: TTLCache<string, RunRegistryEntry>; /** * Registry for per-run non-serializable state. * * During durable execution, the DurableAgent needs to store non-serializable * objects (tools with execute functions, SaveQueueManager, etc.) that can't * flow through workflow state. This registry provides a way to store and * retrieve these objects keyed by runId. * * The registry is scoped to a single DurableAgent instance and entries are * cleaned up when a run completes. */ export declare class RunRegistry { #private; /** * Register non-serializable state for a run * @param runId - The unique run identifier * @param entry - The registry entry containing tools, saveQueueManager, etc. */ register(runId: string, entry: RunRegistryEntry): void; /** * Get the registry entry for a run * @param runId - The unique run identifier * @returns The registry entry or undefined if not found */ get(runId: string): RunRegistryEntry | undefined; /** * Get tools for a specific run * @param runId - The unique run identifier * @returns The tools record or an empty object if not found */ getTools(runId: string): Record<string, CoreTool>; /** * Get SaveQueueManager for a specific run * @param runId - The unique run identifier * @returns The SaveQueueManager or undefined if not found */ getSaveQueueManager(runId: string): SaveQueueManager | undefined; /** * Get the language model for a specific run * @param runId - The unique run identifier * @returns The MastraLanguageModel or undefined if not found */ getModel(runId: string): MastraLanguageModel | undefined; /** * Check if a run is registered * @param runId - The unique run identifier * @returns True if the run is registered */ has(runId: string): boolean; /** * Cleanup and remove a run's entry from the registry * @param runId - The unique run identifier */ cleanup(runId: string): void; /** * Get the number of active runs in the registry */ get size(): number; /** * Get all active run IDs */ get runIds(): string[]; /** * Clear all entries from the registry * Calls cleanup on each entry before removing */ clear(): void; } /** * Extended registry entry that also stores the MessageList reference. * This is useful for accessing message state outside of workflow steps * (e.g., for callbacks that need to read messages). */ export interface ExtendedRunRegistryEntry extends RunRegistryEntry { /** MessageList reference for callback access */ messageList?: MessageList; /** Thread ID for memory */ threadId?: string; /** Resource ID for memory */ resourceId?: string; } /** * Extended run registry that also stores MessageList references and memory info */ export declare class ExtendedRunRegistry extends RunRegistry { #private; /** * Register non-serializable state for a run including MessageList */ registerWithMessageList(runId: string, entry: RunRegistryEntry, messageList: MessageList, memoryInfo?: { threadId?: string; resourceId?: string; }): void; /** * Get MessageList for a specific run */ getMessageList(runId: string): MessageList | undefined; /** * Get memory info for a specific run */ getMemoryInfo(runId: string): { threadId?: string; resourceId?: string; } | undefined; /** * Override cleanup to also remove MessageList and memory info */ cleanup(runId: string): void; /** * Override clear to also clear MessageLists and memory info */ clear(): void; } //# sourceMappingURL=run-registry.d.ts.map