UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

46 lines (45 loc) • 2.26 kB
/** * Shared Summarization Engine * * Extracted from ConversationMemoryManager and RedisConversationMemoryManager * to eliminate code duplication. Both managers delegate to this engine. */ import type { ChatMessage, ConversationMemoryConfig, SessionMemory } from "../types/index.js"; /** * Centralized summarization engine for conversation memory. * Handles token counting, threshold checking, and summary generation. */ export declare class SummarizationEngine { /** * Check if a session needs summarization and perform it if so. * @param session - Session memory to check and potentially summarize * @param threshold - Token threshold that triggers summarization * @param config - Conversation memory configuration (partial allowed) * @param logPrefix - Prefix for log messages * @returns True if summarization was performed */ checkAndSummarize(session: SessionMemory, threshold: number, config: Partial<ConversationMemoryConfig>, logPrefix?: string, requestId?: string): Promise<boolean>; /** * Perform token-based summarization on a session. * Uses pointer-based, non-destructive approach. * @param session - Session memory to summarize * @param threshold - Token threshold for calculating split point * @param config - Conversation memory configuration (partial allowed) * @param logPrefix - Prefix for log messages */ summarizeSession(session: SessionMemory, threshold: number, config: Partial<ConversationMemoryConfig>, logPrefix?: string, requestId?: string): Promise<void>; /** * Estimate total tokens for a message array. * @param messages - Array of chat messages * @returns Estimated token count */ estimateTokens(messages: ChatMessage[]): number; /** * Find split index to keep recent messages within target token count. * Works backwards from the most recent message to find the split point. * @param messages - Array of messages to analyze * @param targetRecentTokens - Target token count for recent messages * @returns Index at which to split (messages before this index will be summarized) */ findSplitIndexByTokens(messages: ChatMessage[], targetRecentTokens: number): number; }