| 156 | } |
| 157 | |
| 158 | bool HttpStreamTransport::resolveRpcStream(const fl::json& msg, const fl::string& idKey) { |
| 159 | auto it = mPendingStreams.find(idKey); |
| 160 | if (it == mPendingStreams.end()) { |
| 161 | return false; |
| 162 | } |
| 163 | PendingStream* pending = &it->second; |
| 164 | |
| 165 | // Check for error |
| 166 | if (msg.contains("error")) { |
| 167 | fl::task::Error err(msg["error"]["message"].as_string().value()); |
| 168 | pending->promise.complete_with_error(err); |
| 169 | mPendingStreams.erase(idKey); |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | // Check for ACK |
| 174 | if (msg.contains("result") && msg["result"].contains("acknowledged")) { |
| 175 | if (msg["result"]["acknowledged"].as_bool() == true) { |
| 176 | pending->ackReceived = true; |
| 177 | return true; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Check for stream update |
| 182 | if (msg.contains("result") && msg["result"].contains("update")) { |
| 183 | if (pending->updateCallback && *pending->updateCallback) { |
| 184 | (*pending->updateCallback)(msg["result"]["update"]); |
| 185 | } |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | // Check for stream final (stop marker) |
| 190 | if (msg.contains("result") && msg["result"].contains("stop")) { |
| 191 | if (msg["result"]["stop"].as_bool() == true) { |
| 192 | // Resolve with the value field if present, otherwise the full result |
| 193 | if (msg["result"].contains("value")) { |
| 194 | pending->promise.complete_with_value(msg["result"]["value"]); |
| 195 | } else { |
| 196 | pending->promise.complete_with_value(msg["result"]); |
| 197 | } |
| 198 | mPendingStreams.erase(idKey); |
| 199 | return true; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // Unrecognized message shape - treat as final |
| 204 | pending->promise.complete_with_value(msg); |
| 205 | mPendingStreams.erase(idKey); |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | fl::task::Promise<fl::json> HttpStreamTransport::rpc(const fl::string& method, const fl::json& params) { |
| 210 | int id = mNextCallId++; |
nothing calls this directly
no test coverage detected