UNPKG

toto-agent

Version:

Chatbot agent and reusable components for Toto platform

100 lines (99 loc) 2.91 kB
import { AgentInteractionLog, MetaAgentInsight } from '../../shared/MetaAgent'; import { UserIntent, AgentType, AgentResponse } from '../../shared/AgentTypes'; export interface ConversationSession { sessionId: string; userId?: string; caseId?: string; startTime: Date; endTime?: Date; totalMessages: number; userMessages: number; agentResponses: number; intents: string[]; agents: AgentType[]; outcomes: { donation?: boolean; sharing?: boolean; adoption?: boolean; engagement?: boolean; dropoff?: boolean; }; feedback?: { rating?: number; comment?: string; helpful?: boolean; }; metadata: { language: string; platform?: string; userAgent?: string; location?: string; }; } export interface ConversationAnalytics { sessionId: string; interactions: AgentInteractionLog[]; insights: MetaAgentInsight; patterns: { commonIntents: Record<string, number>; successfulFlows: string[]; dropoffPoints: Record<string, number>; userSatisfaction: number; }; recommendations: { agentImprovements: string[]; flowOptimizations: string[]; contentSuggestions: string[]; }; } export declare class ConversationAnalyticsService { private sessions; private interactions; /** * Check if a session exists */ hasSession(sessionId: string): boolean; /** * Start a new conversation session */ startSession(sessionId: string, userId?: string, caseId?: string, metadata?: any): ConversationSession; /** * Log an interaction and update session analytics */ logInteraction(sessionId: string, userMessage: string, intent: UserIntent, agentResponse: AgentResponse, outcome?: 'success' | 'dropoff' | 'confused' | 'repeated'): void; /** * End a conversation session and generate analytics */ endSession(sessionId: string, feedback?: { rating?: number; comment?: string; helpful?: boolean; }): Promise<ConversationAnalytics>; /** * Analyze conversation patterns */ private analyzePatterns; /** * Generate improvement recommendations */ private generateRecommendations; /** * Get analytics for a specific session */ getSessionAnalytics(sessionId: string): Promise<ConversationAnalytics | null>; /** * Get aggregated analytics across all sessions */ getAggregatedAnalytics(): { totalSessions: number; totalInteractions: number; averageSessionLength: number; topIntents: Record<string, number>; conversionRates: Record<string, number>; commonIssues: string[]; }; /** * Persist analytics to Firestore */ persistAnalytics(sessionId: string): Promise<void>; }