MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / HandleUpdateAgent

Method HandleUpdateAgent

internal/auth/auth.go:643–704  ·  view source on GitHub ↗

HandleUpdateAgent updates an agent owned by the authenticated user.

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

Source from the content-addressed store, hash-verified

641
642// HandleUpdateAgent updates an agent owned by the authenticated user.
643func (ua *UserAuth) HandleUpdateAgent(w http.ResponseWriter, r *http.Request) {
644 user := ua.AuthenticateRequest(r)
645 if user == nil {
646 http.Error(w, "not authenticated", http.StatusUnauthorized)
647 return
648 }
649
650 path := strings.TrimPrefix(r.URL.Path, "/api/dashboard/agents/")
651 email, _ := url.PathUnescape(path)
652 email = identity.NormalizeEmail(email)
653 if email == "" {
654 http.Error(w, "agent email required", http.StatusBadRequest)
655 return
656 }
657
658 // Use pointer fields so we can distinguish "not present in request"
659 // from "explicitly set to zero value". Clients PATCH individual
660 // HITL settings — each may appear alone or combined in a single PUT.
661 var req struct {
662 HITLTTLSeconds *int `json:"hitl_ttl_seconds"`
663 HITLExpirationAction *string `json:"hitl_expiration_action"`
664 }
665 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
666 http.Error(w, "invalid request body", http.StatusBadRequest)
667 return
668 }
669
670 agnt, err := ua.store.GetAgentByEmail(r.Context(), email)
671 if err != nil {
672 http.Error(w, "agent not found", http.StatusNotFound)
673 return
674 }
675
676 // Track whether the body carried any understood field. An empty PUT
677 // is treated as a 400 so mistakes don't silently no-op.
678 touched := false
679
680 // HITL settings update. Individual fields may be present; missing
681 // fields keep their current value.
682 if req.HITLTTLSeconds != nil || req.HITLExpirationAction != nil {
683 ttl := agnt.HITLTTLSeconds
684 if req.HITLTTLSeconds != nil {
685 ttl = *req.HITLTTLSeconds
686 }
687 action := agnt.HITLExpirationAction
688 if req.HITLExpirationAction != nil {
689 action = *req.HITLExpirationAction
690 }
691 if err := ua.store.UpdateAgentHITL(r.Context(), agnt.ID, user.ID, ttl, action); err != nil {
692 http.Error(w, err.Error(), http.StatusBadRequest)
693 return
694 }
695 touched = true
696 }
697
698 if !touched {
699 http.Error(w, "no recognized fields in request", http.StatusBadRequest)
700 return

Callers

nothing calls this directly

Calls 6

AuthenticateRequestMethod · 0.95
NormalizeEmailFunction · 0.92
UpdateAgentHITLMethod · 0.80
GetAgentByEmailMethod · 0.65
ErrorMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected