#pragma once #include "AudioInterface.hpp" #include #include #include #include #include #include #include #include #include #include class Conversation { public: using CallbackAgentResponse = std::function; using CallbackAgentResponseCorrection = std::function; using CallbackUserTranscript = std::function; using CallbackLatencyMeasurement = std::function; Conversation( const std::string& agentId, bool requiresAuth, std::shared_ptr audioInterface, CallbackAgentResponse callbackAgentResponse = nullptr, CallbackAgentResponseCorrection callbackAgentResponseCorrection = nullptr, CallbackUserTranscript callbackUserTranscript = nullptr, CallbackLatencyMeasurement callbackLatencyMeasurement = nullptr ); ~Conversation(); void startSession(); void endSession(); std::string waitForSessionEnd(); void sendUserMessage(const std::string& text); void registerUserActivity(); void sendContextualUpdate(const std::string& content); private: void run(); void handleMessage(const nlohmann::json& message); std::string getWssUrl() const; // networking members boost::asio::io_context ioc_; boost::asio::ssl::context sslCtx_{boost::asio::ssl::context::tlsv12_client}; using tcp = boost::asio::ip::tcp; using websocket_t = boost::beast::websocket::stream< boost::beast::ssl_stream>; std::unique_ptr ws_; // general state std::string agentId_; bool requiresAuth_; std::shared_ptr audioInterface_; CallbackAgentResponse callbackAgentResponse_; CallbackAgentResponseCorrection callbackAgentResponseCorrection_; CallbackUserTranscript callbackUserTranscript_; CallbackLatencyMeasurement callbackLatencyMeasurement_; std::thread workerThread_; std::atomic shouldStop_{false}; std::string conversationId_; std::atomic lastInterruptId_{0}; };