UNPKG

@mastra/core

Version:
62 lines • 2.79 kB
import type { Lock, QueueEntry, StateAdapter } from 'chat'; import type { MemoryStorage } from '../storage/domains/memory/base.js'; /** * Chat SDK StateAdapter backed by Mastra storage. * * Thread subscriptions are persisted to the Mastra `MemoryStorage` domain * using thread metadata (`channel_subscribed`), so they survive restarts. * * Cache, locks, and dedup keys remain in-memory — they are inherently * short-lived (seconds to minutes) and don't need persistence. */ export declare class MastraStateAdapter implements StateAdapter { private memoryStore; private getOwnerId?; private connected; private connectPromise; private readonly cache; private readonly locks; private readonly lists; private readonly queues; constructor(memoryStore: MemoryStorage, getOwnerId?: () => string | null); connect(): Promise<void>; disconnect(): Promise<void>; subscribe(threadId: string): Promise<void>; unsubscribe(threadId: string): Promise<void>; isSubscribed(threadId: string): Promise<boolean>; get<T = unknown>(key: string): Promise<T | null>; set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void>; setIfNotExists(key: string, value: unknown, ttlMs?: number): Promise<boolean>; delete(key: string): Promise<void>; appendToList(key: string, value: unknown, options?: { maxLength?: number; ttlMs?: number; }): Promise<void>; getList<T = unknown>(key: string): Promise<T[]>; acquireLock(threadId: string, ttlMs: number): Promise<Lock | null>; releaseLock(lock: Lock): Promise<void>; extendLock(lock: Lock, ttlMs: number): Promise<boolean>; forceReleaseLock(threadId: string): Promise<void>; enqueue(threadId: string, entry: QueueEntry, maxSize: number): Promise<number>; dequeue(threadId: string): Promise<QueueEntry | null>; queueDepth(threadId: string): Promise<number>; private cleanExpiredLocks; /** * Claim stamp for write paths: when an owner id is known and the thread has * not been claimed yet, include `channel_ownerId` so the write adopts the * legacy thread. Read paths (`isSubscribed`) never claim. */ private ownerStamp; /** * Find a Mastra thread by its external (SDK) thread ID. * External thread IDs are stored in `channel_externalThreadId` metadata. * * When an owner id is available, the lookup is scoped per agent via the * `channel_ownerId` metadata key, with a legacy fallback that matches only * threads no agent has claimed yet. Threads claimed by a different agent * are never returned. Without an owner id the old unscoped behavior is * preserved. */ private findThreadByExternalId; } //# sourceMappingURL=state-adapter.d.ts.map