UNPKG

@mastra/core

Version:
58 lines • 2.58 kB
import type { IMastraLogger } from '../../logger/index.js'; import type { ThreadStateStorage } from '../../storage/domains/thread-state/index.js'; import type { FileReadRecord, FileReadTracker } from './file-read-tracker.js'; /** * `threadState` storage `type` namespace under which workspace read records * are stored. One slot per thread, alongside the built-in task list * (`'task'`) and goal objectives (`'goal'`). */ export declare const WORKSPACE_READS_STATE_TYPE = "workspace-reads"; /** * FileReadTracker backed by the `threadState` storage domain. * * Read records are stored per thread under `type: 'workspace-reads'`, so * `requireReadBeforeWrite` state survives suspend/resume (plan approval, * `requireApproval` tools), later turns on the same thread, and process * restarts on serverless runtimes — whenever the configured storage adapter * persists the thread-state domain. Tracker instances are cheap and carry no * authoritative state of their own: the agent constructs one per run. * * Storage failures degrade gracefully: the tracker keeps an in-instance cache * that stays correct for the current run, and persistence resumes on the next * successful write. */ export declare class ThreadStateFileReadTracker implements FileReadTracker { private readonly threadId; private readonly store; private readonly logger?; private cache?; private loadPromise?; /** Serializes setState calls so parallel tool calls don't interleave writes. */ private writeQueue; constructor({ threadId, store, logger, }: { threadId: string; store: ThreadStateStorage; logger?: Pick<IMastraLogger, 'debug'>; }); recordRead(path: string, modifiedAt: Date, scope?: string): Promise<void>; getReadRecord(path: string): Promise<FileReadRecord | undefined>; needsReRead(path: string, currentModifiedAt: Date, scope?: string): Promise<{ needsReRead: boolean; reason?: string; }>; clearReadRecord(path: string): Promise<void>; clear(): Promise<void>; /** * Load records from storage once per instance; later calls hit the cache. * Load failures fall back to an empty record set (per-run semantics). */ private ensureLoaded; private evictOldest; /** * Persist the full record map (full-replacement semantics of the * thread-state domain). Failures are logged at debug and swallowed — the * in-instance cache keeps the current run correct. */ private persist; } //# sourceMappingURL=thread-state-read-tracker.d.ts.map