HTTP Handlers (delegated to common implementation)
(w http.ResponseWriter, r *http.Request)
| 192 | // HTTP Handlers (delegated to common implementation) |
| 193 | |
| 194 | func (b *ElectronBridge) handleChat(w http.ResponseWriter, r *http.Request) { |
| 195 | if r.Method != http.MethodPost { |
| 196 | http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) |
| 197 | return |
| 198 | } |
| 199 | |
| 200 | var req struct { |
| 201 | AgentID string `json:"agent_id"` |
| 202 | Message string `json:"message"` |
| 203 | } |
| 204 | |
| 205 | if err := json.NewDecoder(r.Body).Decode(&req); err != nil { |
| 206 | writeJSON(w, http.StatusBadRequest, BackendResponse{ |
| 207 | Success: false, |
| 208 | Error: err.Error(), |
| 209 | }) |
| 210 | return |
| 211 | } |
| 212 | |
| 213 | resp, err := b.handler(&FrontendMessage{ |
| 214 | ID: generateID(), |
| 215 | Type: MsgTypeChat, |
| 216 | AgentID: req.AgentID, |
| 217 | Payload: mustMarshal(ChatPayload{Message: req.Message}), |
| 218 | }) |
| 219 | |
| 220 | if err != nil { |
| 221 | writeJSON(w, http.StatusInternalServerError, BackendResponse{ |
| 222 | Success: false, |
| 223 | Error: err.Error(), |
| 224 | }) |
| 225 | return |
| 226 | } |
| 227 | |
| 228 | writeJSON(w, http.StatusOK, resp) |
| 229 | } |
| 230 | |
| 231 | func (b *ElectronBridge) handleCancel(w http.ResponseWriter, r *http.Request) { |
| 232 | if r.Method != http.MethodPost { |
nothing calls this directly
no test coverage detected