@mastra/core
Version:
119 lines • 6.89 kB
TypeScript
import type { MastraDBMessage, StorageThreadType } from '../../../memory/types.js';
import type { RunFence } from '../../run-fencing.js';
import type { StorageMessageType, StorageResourceType, StorageListMessagesInput, StorageListMessagesByResourceIdInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput, StorageCloneThreadInput, StorageCopyThreadOutput, ObservationalMemoryRecord, ObservationalMemoryHistoryOptions, CreateObservationalMemoryInput, UpdateActiveObservationsInput, UpdateActiveObservationsResult, UpdateBufferedObservationsInput, UpdateBufferedObservationsResult, UpdateBufferedReflectionInput, SwapBufferedToActiveInput, SwapBufferedToActiveResult, SwapBufferedReflectionToActiveInput, CreateReflectionGenerationInput, UpdateObservationalMemoryConfigInput } from '../../types.js';
import type { InMemoryDB } from '../inmemory-db.js';
import { MemoryStorage } from './base.js';
export declare class InMemoryMemory extends MemoryStorage {
readonly supportsPartialThreadUpdate: boolean;
readonly supportsObservationalMemory = true;
readonly supportsObservationalMemoryHistorySearch = true;
private db;
constructor({ db }: {
db: InMemoryDB;
});
dangerouslyClearAll(): Promise<void>;
supportsRunFencing(): boolean;
private assertFence;
raiseRunFence(fence: RunFence): Promise<boolean>;
retireRunFence(fence: RunFence): Promise<boolean>;
getThreadById({ threadId, resourceId, }: {
threadId: string;
resourceId?: string;
}): Promise<StorageThreadType | null>;
saveThread({ thread, fence }: {
thread: StorageThreadType;
fence?: RunFence;
}): Promise<StorageThreadType>;
updateThread({ id, title, metadata, fence, }: {
id: string;
title?: string;
metadata?: Record<string, unknown>;
fence?: RunFence;
}): Promise<StorageThreadType>;
deleteThread({ threadId }: {
threadId: string;
}): Promise<void>;
listMessages({ threadId, resourceId: optionalResourceId, include, filter, perPage: perPageInput, page, orderBy, }: StorageListMessagesInput): Promise<StorageListMessagesOutput>;
/**
* Resolves `include` entries to their target message plus the requested context window.
* The thread is discovered from the target message itself so cross-thread includes work,
* but the resource scope of the query is always honoured: when a `resourceId` is given,
* neither the target nor its neighbours may belong to another resource.
*/
private resolveIncludedMessages;
listMessagesByResourceId({ resourceId, include, filter, perPage: perPageInput, page, orderBy, }: StorageListMessagesByResourceIdInput): Promise<StorageListMessagesOutput>;
protected parseStoredMessage(message: StorageMessageType): MastraDBMessage;
listMessagesById({ messageIds }: {
messageIds: string[];
}): Promise<{
messages: MastraDBMessage[];
}>;
saveMessages(args: {
messages: MastraDBMessage[];
fence?: RunFence;
}): Promise<{
messages: MastraDBMessage[];
}>;
updateMessages(args: {
messages: (Partial<MastraDBMessage> & {
id: string;
})[];
fence?: RunFence;
}): Promise<MastraDBMessage[]>;
deleteMessages(messageIds: string[], options?: {
fence?: RunFence;
}): Promise<void>;
listThreads(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
getResourceById({ resourceId }: {
resourceId: string;
}): Promise<StorageResourceType | null>;
saveResource({ resource }: {
resource: StorageResourceType;
}): Promise<StorageResourceType>;
updateResource({ resourceId, workingMemory, metadata, fence, }: {
resourceId: string;
workingMemory?: string;
metadata?: Record<string, unknown>;
fence?: RunFence;
}): Promise<StorageResourceType>;
copyThread(args: StorageCloneThreadInput): Promise<StorageCopyThreadOutput>;
private sortThreads;
private getObservationalMemoryKey;
getObservationalMemory(threadId: string | null, resourceId: string): Promise<ObservationalMemoryRecord | null>;
/** Head generation for a lookup key, by the canonical order (generationCount DESC, createdAt ASC, id ASC). */
private getObservationalMemoryHead;
/**
* Resolve a record id to the live record lifecycle writes should target: the record itself
* while live, otherwise the head of its lookup key. Returns null when the id does not exist.
*/
private resolveLiveObservationalMemoryRecord;
getObservationalMemoryHistory(threadId: string | null, resourceId: string, limit?: number, options?: ObservationalMemoryHistoryOptions): Promise<ObservationalMemoryRecord[]>;
initializeObservationalMemory(input: CreateObservationalMemoryInput): Promise<ObservationalMemoryRecord>;
insertObservationalMemoryRecord(record: ObservationalMemoryRecord): Promise<void>;
updateActiveObservations(input: UpdateActiveObservationsInput): Promise<void>;
commitActiveObservations(input: UpdateActiveObservationsInput): Promise<UpdateActiveObservationsResult>;
updateBufferedObservations(input: UpdateBufferedObservationsInput): Promise<void>;
appendBufferedObservations(input: UpdateBufferedObservationsInput): Promise<UpdateBufferedObservationsResult>;
swapBufferedToActive(input: SwapBufferedToActiveInput): Promise<SwapBufferedToActiveResult>;
createReflectionGeneration(input: CreateReflectionGenerationInput): Promise<ObservationalMemoryRecord>;
/**
* Create the next generation from the stored record and retire the stored record in one
* synchronous step. Buffered chunks move to the new generation; buffering state, flags,
* counters, and the cursor carry over; buffered reflection state does not.
*/
private rollOverObservationalMemory;
updateBufferedReflection(input: UpdateBufferedReflectionInput): Promise<void>;
swapBufferedReflectionToActive(input: SwapBufferedReflectionToActiveInput): Promise<ObservationalMemoryRecord>;
setReflectingFlag(id: string, isReflecting: boolean): Promise<void>;
setObservingFlag(id: string, isObserving: boolean): Promise<void>;
setBufferingObservationFlag(id: string, isBuffering: boolean, lastBufferedAtTokens?: number): Promise<void>;
setBufferingReflectionFlag(id: string, isBuffering: boolean): Promise<void>;
clearObservationalMemory(threadId: string | null, resourceId: string): Promise<void>;
setPendingMessageTokens(id: string, tokenCount: number): Promise<void>;
updateObservationalMemoryConfig(input: UpdateObservationalMemoryConfigInput): Promise<void>;
/**
* Helper to find an observational memory record by ID across all keys
*/
private findObservationalMemoryRecordById;
}
//# sourceMappingURL=inmemory.d.ts.map