MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / TestConnection

Method TestConnection

server-source-code/internal/handler/ai.go:207–233  ·  view source on GitHub ↗

TestConnection tests the AI connection (admin only).

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

205
206// TestConnection tests the AI connection (admin only).
207func (h *AIHandler) TestConnection(w http.ResponseWriter, r *http.Request) {
208 s, err := h.settings.GetFirst(r.Context())
209 if err != nil {
210 Error(w, http.StatusInternalServerError, "Failed to load settings")
211 return
212 }
213 if s.AiAPIKey == nil || *s.AiAPIKey == "" {
214 Error(w, http.StatusBadRequest, "AI API key not configured")
215 return
216 }
217
218 response, err := h.aiSvc.GetAssistance(s, "Respond with exactly: 'Connection successful!' - nothing else.", "", nil)
219 if err != nil {
220 Error(w, http.StatusBadRequest, "Connection test failed: "+err.Error())
221 return
222 }
223
224 if strings.Contains(strings.ToLower(response), "connection successful") {
225 JSON(w, http.StatusOK, map[string]interface{}{"success": true, "message": "AI connection test successful"})
226 return
227 }
228 JSON(w, http.StatusOK, map[string]interface{}{
229 "success": true,
230 "message": "AI responded",
231 "response": response,
232 })
233}
234
235// AssistRequest is the body for POST /ai/assist.
236type AssistRequest struct {

Callers

nothing calls this directly

Calls 5

ErrorFunction · 0.85
GetFirstMethod · 0.80
GetAssistanceMethod · 0.80
ErrorMethod · 0.80
JSONFunction · 0.70

Tested by

no test coverage detected