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

Method RejectPendingCore

internal/agent/hitl_api.go:210–237  ·  view source on GitHub ↗

RejectPendingCore is the HTTP-free core of HITL reject: optional expected-agent-email match (mirrors the legacy URL guard), then RejectPending + publish. Shared by the legacy handler and the v1 layer.

(ctx context.Context, userID, messageID, expectedAgentEmail, reason string)

Source from the content-addressed store, hash-verified

208// expected-agent-email match (mirrors the legacy URL guard), then
209// RejectPending + publish. Shared by the legacy handler and the v1 layer.
210func (a *API) RejectPendingCore(ctx context.Context, userID, messageID, expectedAgentEmail, reason string) (*identity.Message, *OutboundError) {
211 if expectedAgentEmail != "" {
212 preview, err := a.store.GetOutboundMessageForUser(ctx, messageID, userID)
213 if err != nil {
214 return nil, &OutboundError{http.StatusNotFound, "not_found", "message not found"}
215 }
216 agent, err := a.store.GetAgentByID(ctx, preview.AgentID)
217 if err != nil || agent.Email != expectedAgentEmail {
218 return nil, &OutboundError{http.StatusNotFound, "not_found", "message not found"}
219 }
220 }
221 rejected, err := a.store.RejectPending(ctx, messageID, userID, reason)
222 if err != nil {
223 switch {
224 case errors.Is(err, identity.ErrMessageNotFound):
225 return nil, &OutboundError{http.StatusNotFound, "not_found", "message not found"}
226 case errors.Is(err, identity.ErrNotPendingApproval):
227 return nil, &OutboundError{http.StatusConflict, "message_not_pending", "message is not pending approval"}
228 default:
229 log.Printf("[api] reject: %v", err)
230 return nil, &OutboundError{http.StatusInternalServerError, "internal_error", "failed to reject message"}
231 }
232 }
233 log.Printf("[mail:%s] dir=outbound type=%s status=%s agent=%s rejected_by=user:%s reason=%q",
234 rejected.ID, rejected.Type, rejected.Status, rejected.AgentID, userID, reason)
235 a.publishRejected(ctx, a.buildRejectedEvent(userID, rejected, reason), rejected.ID)
236 return rejected, nil
237}
238
239// ApproveInboundReviewCore releases a held INBOUND message to its agent's inbox
240// (status pending_review → review_approved, now readable) and fires

Callers

nothing calls this directly

Calls 5

publishRejectedMethod · 0.95
buildRejectedEventMethod · 0.95
GetAgentByIDMethod · 0.80
RejectPendingMethod · 0.80

Tested by

no test coverage detected