HTTP Handlers
(w http.ResponseWriter, r *http.Request)
| 163 | // HTTP Handlers |
| 164 | |
| 165 | func (b *WebBridge) handleChat(w http.ResponseWriter, r *http.Request) { |
| 166 | if r.Method != http.MethodPost { |
| 167 | http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) |
| 168 | return |
| 169 | } |
| 170 | |
| 171 | var req struct { |
| 172 | AgentID string `json:"agent_id"` |
| 173 | Message string `json:"message"` |
| 174 | } |
| 175 | |
| 176 | if err := json.NewDecoder(r.Body).Decode(&req); err != nil { |
| 177 | writeJSON(w, http.StatusBadRequest, BackendResponse{ |
| 178 | Success: false, |
| 179 | Error: err.Error(), |
| 180 | }) |
| 181 | return |
| 182 | } |
| 183 | |
| 184 | resp, err := b.handler(&FrontendMessage{ |
| 185 | ID: generateID(), |
| 186 | Type: MsgTypeChat, |
| 187 | AgentID: req.AgentID, |
| 188 | Payload: mustMarshal(ChatPayload{Message: req.Message}), |
| 189 | }) |
| 190 | |
| 191 | if err != nil { |
| 192 | writeJSON(w, http.StatusInternalServerError, BackendResponse{ |
| 193 | Success: false, |
| 194 | Error: err.Error(), |
| 195 | }) |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | writeJSON(w, http.StatusOK, resp) |
| 200 | } |
| 201 | |
| 202 | func (b *WebBridge) handleCancel(w http.ResponseWriter, r *http.Request) { |
| 203 | if r.Method != http.MethodPost { |
nothing calls this directly
no test coverage detected