-
public final class ConversationEventHandlerEvent processing pipeline for real-time conversation
This class handles type-safe event routing using sealed classes, async event processing with coroutines, state synchronization with UI layer, and error handling with recovery mechanisms.
-
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<ConversationMode>conversationModeprivate final StateFlow<List<Message>>messages
-
Constructor Summary
Constructors Constructor Description ConversationEventHandler(AudioManager audioManager, ClientToolRegistry toolRegistry, Function1<OutgoingEvent, Unit> messageCallback, Function1<Boolean, Unit> onCanSendFeedbackChange, Function1<ConversationEvent.ClientToolCall, Unit> onUnhandledClientToolCall, Function1<Float, Unit> onVadScore, Function1<Map<String, Object>, Unit> onAudioAlignment, Function1<Map<String, Object>, Unit> onAgentResponseMetadata, Function1<String, Unit> onUserTranscript, Function1<String, Unit> onAgentResponse, Function2<String, String, Unit> onAgentResponseCorrection, Function2<String, Integer, Unit> onUserTranscriptEvent, Function2<String, Integer, Unit> onTentativeUserTranscriptEvent, Function2<String, Integer, Unit> onAgentResponseEvent, Function3<AgentResponsePartType, String, Integer, Unit> onAgentResponsePartEvent, Function2<String, Integer, Unit> onAgentResponseCorrectionEvent, Function4<String, String, String, Boolean, Unit> onAgentToolResponse, Function3<String, String, String, Unit> onConversationInitiationMetadata, Function1<Integer, Unit> onInterruption, SuspendFunction0<Unit> onEndCall, Function2<Integer, String, Unit> onError)
-
Method Summary
Modifier and Type Method Description final StateFlow<ConversationMode>getConversationMode()final StateFlow<List<Message>>getMessages()final UnithandleIncomingEvent(ConversationEvent event)Handle incoming conversation events final UnitsendUserMessage(String content)Send a user message final UnitsendToolResult(String toolCallId, String result, Boolean isError)Send the result of a client tool execution back to the agent final UnitsendFeedback(Boolean isPositive)Send feedback for the last agent response final UnitsendContextualUpdate(String content)Send contextual update without triggering a response final UnitsendUserActivity()Notify agent of user activity (e.g. final ConversationModegetCurrentMode()Get the current conversation mode final Unitcleanup()Clean up resources -
-
Constructor Detail
-
ConversationEventHandler
ConversationEventHandler(AudioManager audioManager, ClientToolRegistry toolRegistry, Function1<OutgoingEvent, Unit> messageCallback, Function1<Boolean, Unit> onCanSendFeedbackChange, Function1<ConversationEvent.ClientToolCall, Unit> onUnhandledClientToolCall, Function1<Float, Unit> onVadScore, Function1<Map<String, Object>, Unit> onAudioAlignment, Function1<Map<String, Object>, Unit> onAgentResponseMetadata, Function1<String, Unit> onUserTranscript, Function1<String, Unit> onAgentResponse, Function2<String, String, Unit> onAgentResponseCorrection, Function2<String, Integer, Unit> onUserTranscriptEvent, Function2<String, Integer, Unit> onTentativeUserTranscriptEvent, Function2<String, Integer, Unit> onAgentResponseEvent, Function3<AgentResponsePartType, String, Integer, Unit> onAgentResponsePartEvent, Function2<String, Integer, Unit> onAgentResponseCorrectionEvent, Function4<String, String, String, Boolean, Unit> onAgentToolResponse, Function3<String, String, String, Unit> onConversationInitiationMetadata, Function1<Integer, Unit> onInterruption, SuspendFunction0<Unit> onEndCall, Function2<Integer, String, Unit> onError)
-
-
Method Detail
-
getConversationMode
final StateFlow<ConversationMode> getConversationMode()
-
getMessages
final StateFlow<List<Message>> getMessages()
-
handleIncomingEvent
final Unit handleIncomingEvent(ConversationEvent event)
Handle incoming conversation events
- Parameters:
event- The conversation event to process
-
sendUserMessage
final Unit sendUserMessage(String content)
Send a user message
- Parameters:
content- Message content to send
-
sendToolResult
final Unit sendToolResult(String toolCallId, String result, Boolean isError)
Send the result of a client tool execution back to the agent
- Parameters:
toolCallId- The unique identifier for the tool callresult- The result string to send back to the agentisError- Whether the tool execution resulted in an error
-
sendFeedback
final Unit sendFeedback(Boolean isPositive)
Send feedback for the last agent response
- Parameters:
isPositive- true for positive feedback, false for negative
-
sendContextualUpdate
final Unit sendContextualUpdate(String content)
Send contextual update without triggering a response
- Parameters:
content- Context information to send
-
sendUserActivity
final Unit sendUserActivity()
Notify agent of user activity (e.g., typing)
-
getCurrentMode
final ConversationMode getCurrentMode()
Get the current conversation mode
-
-
-
-