Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
transport_sse.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
13#pragma once
14
16
17#include <atomic>
18#include <condition_variable>
19#include <cstdint>
20#include <map>
21#include <memory>
22#include <mutex>
23#include <string>
24#include <thread>
25
26namespace httplib { class Client; }
27
28namespace entropic {
29
39class SSETransport : public Transport {
40public:
47 explicit SSETransport(std::string url,
48 uint32_t default_timeout_ms = 30000);
49
50 ~SSETransport() override;
51
57 bool open() override;
58
63 void close() override;
64
72 std::string send_request(
73 const std::string& request_json,
74 uint32_t timeout_ms = 0) override;
75
81 bool is_connected() const override;
82
83private:
84 std::string url_;
85 std::string host_;
86 std::string sse_path_;
87 std::string message_endpoint_;
88 uint32_t default_timeout_ms_;
89
90 std::unique_ptr<httplib::Client> client_;
91 std::atomic<bool> connected_{false};
92 std::atomic<bool> running_{false};
93 std::thread sse_reader_thread_;
94
95 std::mutex pending_mutex_;
96 std::condition_variable pending_cv_;
97 std::map<int, std::string> pending_responses_;
98 std::atomic<int> next_request_id_{1};
99
106 bool parse_url();
107
113 void warn_if_cleartext() const;
114
123 static bool parse_request_id(
124 const std::string& request_json, int& request_id);
125
133 bool post_request(const std::string& request_json);
134
143 std::string await_response(int request_id, uint32_t timeout_ms);
144
150 void sse_reader_loop();
151
158 void handle_sse_data(const std::string& data);
159
166 void handle_endpoint_event(const std::string& data);
167
174 void process_sse_line(const std::string& line);
175
176 std::string current_event_type_;
177};
178
179} // namespace entropic
SSE transport: HTTP GET for event stream, POST for requests.
void close() override
Stop SSE reader and close HTTP client.
bool is_connected() const override
Check if SSE stream is connected.
std::string send_request(const std::string &request_json, uint32_t timeout_ms=0) override
POST a JSON-RPC request and wait for matching response.
bool open() override
Connect to SSE endpoint and start reader thread.
~SSETransport() override
Destructor — ensures reader thread is stopped.
Abstract transport for external MCP communication.
Definition transport.h:29
Activate model on GPU (WARM → ACTIVE).
Abstract transport for external MCP server communication.