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

Method deliver

internal/httpapi/outbound.go:379–411  ·  view source on GitHub ↗

deliver runs the domain-verified + enforce-cap checks then DeliverOutbound under the idempotency handshake, mapping the OutboundResult to the wire view.

(ctx context.Context, user *identity.User, ag *identity.AgentIdentity, req outbound.SendRequest, msgType, replyTo, route, idemKey string, rawBody []byte, referenced *identity.Message)

Source from the content-addressed store, hash-verified

377// deliver runs the domain-verified + enforce-cap checks then DeliverOutbound
378// under the idempotency handshake, mapping the OutboundResult to the wire view.
379func (s *Server) deliver(ctx context.Context, user *identity.User, ag *identity.AgentIdentity, req outbound.SendRequest, msgType, replyTo, route, idemKey string, rawBody []byte, referenced *identity.Message) (*sendOutput, error) {
380 if env := s.checkSendLimit(ag.ID); env != nil {
381 return nil, env
382 }
383 if !ag.DomainVerified {
384 return nil, NewError(http.StatusForbidden, "domain_not_verified", "agent domain must be verified before sending")
385 }
386 if s.deps.EnforceMessageSend != nil {
387 if err := s.deps.EnforceMessageSend(ctx, user.ID); err != nil {
388 if env, ok := limitEnvelope(err); ok {
389 return nil, env
390 }
391 return nil, NewError(http.StatusInternalServerError, "internal_error", "limits check failed")
392 }
393 }
394 if s.deps.DeliverOutbound == nil {
395 return nil, NewError(http.StatusInternalServerError, "internal_error", "outbound delivery unavailable")
396 }
397 status, view, err := runIdempotent(s, ctx, user.ID, idemKey, route, rawBody, func() (int, SendResultView, error) {
398 res, derr := s.deps.DeliverOutbound(ctx, user, ag, req, msgType, replyTo, referenced)
399 if derr != nil {
400 return 0, SendResultView{}, NewError(derr.Status, derr.Code, derr.Msg)
401 }
402 if res.Held {
403 return http.StatusAccepted, SendResultView{Status: "pending_review", MessageID: res.PendingMessageID, ApprovalExpiresAt: res.ApprovalExpiresAt}, nil
404 }
405 return http.StatusOK, SendResultView{Status: "sent", MessageID: res.MessageID, ProviderMessageID: res.ProviderMessageID, SentAs: res.SentAs, Method: res.Method}, nil
406 })
407 if err != nil {
408 return nil, err
409 }
410 return &sendOutput{Status: status, Body: view}, nil
411}
412
413// checkSendLimit applies the per-agent outbound rate limit (mirrors the
414// legacy sendLimit). On block it returns a 429 envelope carrying the

Callers 3

handleReplyMethod · 0.95
handleForwardMethod · 0.95
handleCreateMessageMethod · 0.95

Calls 5

checkSendLimitMethod · 0.95
NewErrorFunction · 0.85
limitEnvelopeFunction · 0.85
runIdempotentFunction · 0.85
DeliverOutboundMethod · 0.80

Tested by

no test coverage detected