UNPKG

anon-identity

Version:

Decentralized identity framework with DIDs, Verifiable Credentials, and privacy-preserving selective disclosure

179 lines 4.83 kB
/** * Conversation Manager for MCP * * Orchestrates conversation flow between agents and LLMs with context management */ import { EventEmitter } from 'events'; import { LLMRequest, LLMResponse, LLMResponseChunk, ConversationContext, MessageRole, ContextPriority, ContextRetention, RequestPriority, FunctionCall, FunctionResult } from '../types'; import { MessageRouter } from '../routing/message-router'; import { ContextManager } from '../context/context-manager'; import { AgentLLMManager } from '../agent/agent-llm-manager'; /** * Conversation session */ export interface ConversationSession { id: string; agentDID: string; contextId: string; metadata: { domain: string; purpose: string; startedAt: Date; lastActivity: Date; messageCount: number; totalTokens: number; }; status: 'active' | 'paused' | 'ended'; participants: string[]; } /** * Conversation flow configuration */ export interface ConversationFlowConfig { autoSummarize: boolean; maxIdleTime: number; contextSwitchThreshold: number; multiTurnEnabled: boolean; persistHistory: boolean; enableStreaming: boolean; } /** * Turn result */ export interface TurnResult { request: LLMRequest; response: LLMResponse; context: ConversationContext; session: ConversationSession; functionCalls?: FunctionCall[]; functionResults?: FunctionResult[]; metrics: { turnDuration: number; tokensUsed: number; providerUsed: string; }; } /** * Conversation Manager */ export declare class ConversationManager extends EventEmitter { private messageRouter; private contextManager; private agentLLMManager; private config; private sessions; private agentSessions; private multiTurnStates; private idleCheckTimer?; constructor(messageRouter: MessageRouter, contextManager: ContextManager, agentLLMManager: AgentLLMManager, config?: ConversationFlowConfig); /** * Start conversation session */ startConversation(agentDID: string, options?: { domain?: string; purpose?: string; priority?: ContextPriority; retention?: Partial<ContextRetention>; systemPrompt?: string; metadata?: Record<string, any>; }): Promise<ConversationSession>; /** * Send message in conversation */ sendMessage(sessionId: string, content: string, options?: { role?: MessageRole; priority?: RequestPriority; providerId?: string; temperature?: number; maxTokens?: number; enableFunctions?: boolean; streamResponse?: boolean; metadata?: Record<string, any>; }): Promise<TurnResult>; /** * Stream message in conversation */ streamMessage(sessionId: string, content: string, options?: { role?: MessageRole; priority?: RequestPriority; providerId?: string; temperature?: number; maxTokens?: number; enableFunctions?: boolean; metadata?: Record<string, any>; }): AsyncIterable<LLMResponseChunk>; /** * Handle streaming request */ private handleStreamingRequest; /** * Handle multi-turn conversation */ private handleMultiTurn; /** * Check if multi-turn should continue */ private shouldContinueMultiTurn; /** * Build prompt from context */ private buildPrompt; /** * Get function definitions for agent */ private getFunctionDefinitions; /** * Check if context should be switched */ private shouldSwitchContext; /** * Handle context switch */ private handleContextSwitch; /** * Pause conversation */ pauseConversation(sessionId: string): void; /** * Resume conversation */ resumeConversation(sessionId: string): void; /** * End conversation */ endConversation(sessionId: string): Promise<void>; /** * Get agent conversations */ getAgentConversations(agentDID: string): ConversationSession[]; /** * Get conversation statistics */ getStatistics(): { totalSessions: number; activeSessions: number; pausedSessions: number; endedSessions: number; averageMessagesPerSession: number; averageTokensPerSession: number; multiTurnSessions: number; }; /** * Setup event handlers */ private setupEventHandlers; /** * Start idle session check */ private startIdleCheck; /** * Check for idle sessions */ private checkIdleSessions; /** * Shutdown */ shutdown(): void; } export default ConversationManager; //# sourceMappingURL=conversation-manager.d.ts.map