import type { ObservationalMemoryRecord } from '@mastra/core/storage'; import type { ResolvedObservationConfig, ResolvedReflectionConfig } from './types.js'; /** * Manages the static buffering state machine for async observation and reflection. * * Static maps are shared across all ObservationalMemory instances in a process. * This is critical because multiple OM instances are created per agent loop step, * and they need to share knowledge of in-flight operations. */ export declare class BufferingCoordinator { private readonly observationConfig; private readonly reflectionConfig; private readonly scope; /** * Track in-flight async buffering operations per resource/thread. * Key format: "obs:{lockKey}" or "refl:{lockKey}" * Value: Promise that resolves when buffering completes */ static asyncBufferingOps: Map>; /** * Track the last token boundary at which we started buffering. * Key format: "obs:{lockKey}" or "refl:{lockKey}" */ static lastBufferedBoundary: Map; /** * Track the timestamp cursor for buffered messages. * Key format: "obs:{lockKey}" */ static lastBufferedAtTime: Map; /** * Tracks cycleId for in-flight buffered reflections. * Key format: "refl:{lockKey}" */ static reflectionBufferCycleIds: Map; constructor(opts: { observationConfig: ResolvedObservationConfig; reflectionConfig: ResolvedReflectionConfig; scope: 'thread' | 'resource'; }); getLockKey(threadId: string | null | undefined, resourceId: string | null | undefined): string; isAsyncObservationEnabled(): boolean; isAsyncReflectionEnabled(): boolean; getObservationBufferKey(lockKey: string): string; getReflectionBufferKey(lockKey: string): string; isAsyncBufferingInProgress(bufferKey: string): boolean; /** * Clean up static maps for a thread/resource to prevent memory leaks. */ cleanupStaticMaps(threadId: string, resourceId?: string | null, activatedMessageIds?: string[]): void; /** * Check if we've crossed a new bufferTokens interval boundary for async observation. */ shouldTriggerAsyncObservation(currentTokens: number, lockKey: string, record: ObservationalMemoryRecord, storage?: { setBufferingObservationFlag(id: string, flag: boolean): Promise; }, messageTokensThreshold?: number): boolean; /** * Await any in-flight async buffering operations for a given thread/resource. */ static awaitBuffering(threadId: string | null | undefined, resourceId: string | null | undefined, scope: 'thread' | 'resource', timeoutMs?: number): Promise; } //# sourceMappingURL=buffering-coordinator.d.ts.map