UNPKG

@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

81 lines (80 loc) 4.62 kB
/** * Conversation Memory Utilities * Handles configuration merging and conversation memory operations */ import type { ConversationMemoryManager } from "../core/conversationMemoryManager.js"; import type { RedisConversationMemoryManager } from "../core/redisConversationMemoryManager.js"; import type { ChatMessage, ConversationMemoryConfig, SessionMemory, TextGenerationOptions, TextGenerationResult } from "../types/index.js"; /** * Legacy sentinel string formerly written by the abort branch of * handleGenerateTextInternalFailure (Curator SI-069 / SI-071). The producer is * removed in this fix, but historical Redis sessions may still contain entries * with this content. Filtered at the prompt-builder boundary so they never * reach the provider — sessions self-heal on the next read without any * migration. Keep in sync with any future renames; do not remove without a * cross-repo grep. */ export declare const ABORT_LEGACY_SENTINEL = "[generation was interrupted]"; /** * Apply conversation memory defaults to user configuration * Merges user config with environment variables and default values */ export declare function applyConversationMemoryDefaults(userConfig?: Partial<ConversationMemoryConfig>): ConversationMemoryConfig; /** * Get conversation history as message array, summarizing if needed. */ export declare function getConversationMessages(conversationMemory: ConversationMemoryManager | RedisConversationMemoryManager | null | undefined, options: TextGenerationOptions): Promise<ChatMessage[]>; /** * Store conversation turn for future context * Saves user messages and AI responses for conversation memory */ export declare function storeConversationTurn(conversationMemory: ConversationMemoryManager | RedisConversationMemoryManager | null | undefined, originalOptions: TextGenerationOptions, result: TextGenerationResult, startTimeStamp?: Date | undefined, requestId?: string): Promise<void>; /** * Build context messages from pointer onwards (token-based memory) * Returns summary message (if exists) + all messages after the summarized pointer * @param session - Session memory with pointer * @returns Context messages to send to LLM */ export declare function buildContextFromPointer(session: SessionMemory, requestId?: string): ChatMessage[]; /** * Create summarization prompt from message history * Used by both in-memory and Redis conversation managers * @param history - Messages to summarize * @param previousSummary - Optional previous summary to build upon */ export declare function createSummarizationPrompt(history: ChatMessage[], previousSummary?: string): string; /** * Calculate token threshold based on model's context window and available input tokens * Uses context window registry for accurate per-provider, per-model limits * @param provider - AI provider name * @param model - Model name * @param maxTokens - Optional explicit maxTokens for output reserve calculation * @returns Token threshold (80% of available input tokens) */ export declare function calculateTokenThreshold(provider?: string, model?: string, maxTokens?: number): number; /** * Get effective token threshold for a session * Priority: session override > env var > model-based (80%) > fallback * @param provider - AI provider name * @param model - Model name * @param envOverride - Environment variable override * @param sessionOverride - Per-session token threshold override * @returns Effective token threshold */ export declare function getEffectiveTokenThreshold(provider: string, model: string, envOverride?: number, sessionOverride?: number): number; /** * Generate summary using configured provider and model * Centralized summarization logic used by both ConversationMemoryManager and RedisConversationMemoryManager * @param messages - Messages to summarize * @param config - Conversation memory configuration containing provider/model settings * @param previousSummary - Optional previous summary to build upon * @param logPrefix - Prefix for log messages (e.g., "[ConversationMemory]" or "[RedisConversationMemoryManager]") * @param requestId - Optional request ID for request-scoped tracing * @returns Summary text or null if generation fails */ export declare function generateSummary(messages: ChatMessage[], config: Partial<ConversationMemoryConfig>, logPrefix?: string, previousSummary?: string, requestId?: string): Promise<string | null>; /** * Check if Redis is available for conversation memory. * Migrated from the deprecated conversationMemoryUtils.ts. */ export declare function checkRedisAvailability(): Promise<boolean>;