@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
198 lines (197 loc) • 7.91 kB
TypeScript
/**
* Redis Conversation Memory Manager for NeuroLink
* Redis-based implementation of conversation storage with same interface as ConversationMemoryManager
*/
import type { ChatMessage, ConversationMemoryConfig, ConversationMemoryStats, RedisConversationObject, RedisStorageConfig, SessionMemory, SessionMetadata, StoreConversationTurnOptions, AgenticLoopReportMetadata, IConversationMemoryManager } from "../types/index.js";
/**
* Redis-based implementation of the ConversationMemoryManager
* Uses the same interface but stores data in Redis
*/
export declare class RedisConversationMemoryManager implements IConversationMemoryManager {
config: ConversationMemoryConfig;
private isInitialized;
private summarizationEngine;
private redisConfig;
private redisClient;
/**
* Temporary storage for tool execution data to prevent race conditions
* Key format: "${sessionId}:${userId}"
*/
private pendingToolExecutions;
/**
* Track sessions currently generating titles to prevent race conditions
* Key format: "${sessionId}:${userId}"
*/
private titleGenerationInProgress;
/**
* Track sessions currently being summarized to prevent race conditions
* Key format: "${sessionId}:${userId}"
*/
private summarizationInProgress;
constructor(config: ConversationMemoryConfig, redisConfig?: RedisStorageConfig);
/**
* Initialize the memory manager with Redis connection
*/
initialize(): Promise<void>;
/** Whether this memory manager can persist data (Redis connected and initialized) */
get canPersist(): boolean;
/** Whether Redis client is configured and connected */
get isRedisConfigured(): boolean;
/** Get health status for monitoring */
getHealthStatus(): {
initialized: boolean;
connected: boolean;
host: string;
keyPrefix: string;
};
/**
* Get session by ID, reconstructing a SessionMemory from Redis storage.
*/
getSession(sessionId: string, userId?: string, requestId?: string): Promise<SessionMemory | undefined>;
/**
* Get raw session data without any filtering or transformation.
* Used by the memory retrieval tool and internal APIs that need
* access to full message data including unmodified tool outputs.
*/
getSessionRaw(sessionId: string, userId?: string): Promise<RedisConversationObject | null>;
/**
* Get all sessions for a specific user
*/
getUserSessions(userId: string): Promise<string[]>;
/**
* Add a session to user's session set (private method)
*/
private addUserSession;
/**
* Remove a session from user's session set (private method)
*/
private removeUserSession;
/**
* Generate current timestamp in ISO format
*/
private generateTimestamp;
/**
* Store tool execution data for a session (temporarily to avoid race conditions)
*/
storeToolExecution(sessionId: string, userId: string | undefined, toolCalls: Array<{
toolCallId?: string;
toolName?: string;
args?: Record<string, unknown>;
[key: string]: unknown;
}>, toolResults: Array<{
toolCallId?: string;
output?: unknown;
result?: unknown;
error?: string;
[key: string]: unknown;
}>, currentTime?: Date): Promise<void>;
/**
* Store a conversation turn for a session
*/
storeConversationTurn(options: StoreConversationTurnOptions): Promise<void>;
/**
* Check if summarization is needed based on token count
*/
private checkAndSummarize;
/**
* Build context messages for AI prompt injection (TOKEN-BASED)
* Returns messages from pointer onwards (or all if no pointer)
* Applies sendToolPreview toggle and hydrates result.result for backward compat
*/
buildContextMessages(sessionId: string, userId?: string, enableSummarization?: boolean, requestId?: string): Promise<ChatMessage[]>;
/**
* Get session metadata for a specific user session (optimized for listing)
* Fetches only essential metadata without heavy message arrays
*
* @param userId The user identifier
* @param sessionId The session identifier
* @returns Session metadata or null if session doesn't exist
*/
getUserSessionMetadata(userId: string, sessionId: string): Promise<SessionMetadata | null>;
/**
* Get conversation history for a specific user session
*
* @param userId The user identifier
* @param sessionId The session identifier
* @returns Array of chat messages or null if session doesn't exist
*/
getUserSessionHistory(userId: string, sessionId: string): Promise<ChatMessage[] | null>;
/**
* Get the complete conversation object for a specific user session
*
* This method returns the full conversation object including title, metadata,
* timestamps, and all chat messages. Unlike getUserSessionHistory() which returns
* only the messages array, this method provides the complete conversation context.
*
* @param userId The user identifier who owns the session
* @param sessionId The unique session identifier
* @returns Complete conversation object with all data, or null if session doesn't exist
*/
getUserSessionObject(userId: string, sessionId: string): Promise<RedisConversationObject | null>;
/**
* Generate a conversation title from the first user message
* Uses AI to create a concise, descriptive title (5-8 words)
*/
generateConversationTitle(userMessage: string): Promise<string>;
/**
* Create summary system message
*/
createSummarySystemMessage(content: string, summarizesFrom?: string, summarizesTo?: string): ChatMessage;
/**
* Get the raw messages array for a session.
* Returns the full messages list without context filtering or summarization.
*/
getSessionMessages(sessionId: string, userId?: string): Promise<ChatMessage[]>;
/**
* Replace the entire messages array for a session.
* The session must already exist in Redis.
*/
setSessionMessages(sessionId: string, messages: ChatMessage[], userId?: string): Promise<void>;
/**
* Close Redis connection
*/
close(): Promise<void>;
/**
* Get statistics about conversation storage
*/
getStats(): Promise<ConversationMemoryStats>;
/**
* Clear a specific session
*/
clearSession(sessionId: string, userId?: string): Promise<boolean>;
/**
* Clear all sessions
*/
clearAllSessions(): Promise<void>;
/**
* Ensure Redis client is initialized
*/
private ensureInitialized;
/**
* Get session metadata for all sessions of a user (optimized for listing)
* Returns only essential metadata without heavy message arrays
*
* @param userId The user identifier
* @returns Array of session metadata objects
*/
getUserAllSessionsHistory(userId: string): Promise<SessionMetadata[]>;
/**
* Clean up stale pending tool execution data
* Removes data older than 5 minutes to prevent memory leaks
*/
private cleanupStalePendingData;
/**
* Flush pending tool execution data for a session and merge into conversation
*/
private flushPendingToolData;
/**
* Update agentic loop report metadata for a conversation session.
* Upserts a report entry by reportId — updates existing or adds new.
* Follows the read → patch → write pattern (same as title generation).
*
* @param sessionId The session identifier
* @param userId The user identifier (optional)
* @param report The report metadata to upsert
*/
updateAgenticLoopReport(sessionId: string, userId: string | undefined, report: AgenticLoopReportMetadata): Promise<void>;
}