@mastra/core
Version:
157 lines • 5.02 kB
TypeScript
import type { CoreSystemMessage } from '../../../_types/@internal_ai-sdk-v4/dist/index.d.ts';
import type { SerializedMessage } from './serialization.js';
import type { MastraDBMessage, MessageSource, MemoryInfo } from './types.js';
export type { MessageSource };
/**
* MessageStateManager - Manages the state of messages in a MessageList
*
* Handles:
* - Tracking messages by their source (memory, input, response, context)
* - Tracking which messages have been persisted
* - Providing efficient lookups for message categorization
*
* This replaces the 8 Sets in the original MessageList with a more manageable interface.
*/
export declare class MessageStateManager {
private memoryMessages;
private newUserMessages;
private newResponseMessages;
private userContextMessages;
private memoryMessagesPersisted;
private newUserMessagesPersisted;
private newResponseMessagesPersisted;
private userContextMessagesPersisted;
/**
* Add a message to the appropriate source set and persisted set
*/
addToSource(message: MastraDBMessage, source: MessageSource): void;
/**
* Check if a message belongs to the memory source
*/
isMemoryMessage(message: MastraDBMessage): boolean;
/**
* Check if a message belongs to the input source
*/
isUserMessage(message: MastraDBMessage): boolean;
/**
* Check if a message belongs to the response source
*/
isResponseMessage(message: MastraDBMessage): boolean;
/**
* Check if a message belongs to the context source
*/
isContextMessage(message: MastraDBMessage): boolean;
/**
* Get all memory messages
*/
getMemoryMessages(): Set<MastraDBMessage>;
/**
* Get all user/input messages
*/
getUserMessages(): Set<MastraDBMessage>;
/**
* Get all response messages
*/
getResponseMessages(): Set<MastraDBMessage>;
/**
* Get all context messages
*/
getContextMessages(): Set<MastraDBMessage>;
/**
* Get persisted memory messages
*/
getMemoryMessagesPersisted(): Set<MastraDBMessage>;
/**
* Get persisted user/input messages
*/
getUserMessagesPersisted(): Set<MastraDBMessage>;
/**
* Get persisted response messages
*/
getResponseMessagesPersisted(): Set<MastraDBMessage>;
/**
* Get persisted context messages
*/
getContextMessagesPersisted(): Set<MastraDBMessage>;
/**
* Remove a message from all source sets
*/
removeMessage(message: MastraDBMessage): void;
/**
* Clear all user messages
*/
clearUserMessages(): void;
/**
* Clear all response messages
*/
clearResponseMessages(): void;
/**
* Clear all context messages
*/
clearContextMessages(): void;
/**
* Clear all messages from all sources (but not persisted tracking)
*/
clearAll(): void;
/**
* Create a lookup function to determine message source
*/
createSourceChecker(): {
memory: Set<string>;
input: Set<string>;
output: Set<string>;
context: Set<string>;
getSource: (message: MastraDBMessage) => MessageSource | null;
};
/**
* Check if a message is a new (unsaved) user or response message by ID
*/
isNewMessage(messageOrId: MastraDBMessage | string): boolean;
/**
* Serialize source tracking state (message IDs only)
*/
private serializeSourceTracking;
/**
* Deserialize source tracking state from message IDs
*/
private deserializeSourceTracking;
/**
* Serialize all MessageList state for workflow suspend/resume
*/
serializeAll(data: {
messages: MastraDBMessage[];
systemMessages: CoreSystemMessage[];
taggedSystemMessages: Record<string, CoreSystemMessage[]>;
memoryInfo: MemoryInfo | null;
agentNetworkAppend: boolean;
}): SerializedMessageListState;
/**
* Deserialize all MessageList state from workflow suspend/resume
*/
deserializeAll(state: SerializedMessageListState): {
messages: MastraDBMessage[];
systemMessages: CoreSystemMessage[];
taggedSystemMessages: Record<string, CoreSystemMessage[]>;
memoryInfo: MemoryInfo | null;
agentNetworkAppend: boolean;
};
}
/**
* Serialized form of the complete MessageList state
*/
export interface SerializedMessageListState {
messages: SerializedMessage[];
systemMessages: CoreSystemMessage[];
taggedSystemMessages: Record<string, CoreSystemMessage[]>;
memoryInfo: MemoryInfo | null;
_agentNetworkAppend: boolean;
memoryMessages: string[];
newUserMessages: string[];
newResponseMessages: string[];
userContextMessages: string[];
memoryMessagesPersisted: string[];
newUserMessagesPersisted: string[];
newResponseMessagesPersisted: string[];
userContextMessagesPersisted: string[];
}
//# sourceMappingURL=MessageStateManager.d.ts.map