diff --git a/internal/gateway/methods/agents_create.go b/internal/gateway/methods/agents_create.go index b5c054f9..3bbd3378 100644 --- a/internal/gateway/methods/agents_create.go +++ b/internal/gateway/methods/agents_create.go @@ -84,19 +84,19 @@ func (m *AgentsMethods) handleCreate(ctx context.Context, client *gateway.Client ownerID = params.OwnerIDs[0] } - // Resolve tenant_id: cross-tenant callers must provide it; others inherit their own tenant. + // Resolve tenant_id: explicit param for cross-tenant; otherwise inherit from connection scope. var tenantID uuid.UUID if client.IsOwner() { - if params.TenantID == "" { - client.SendResponse(protocol.NewErrorResponse(req.ID, protocol.ErrInvalidRequest, i18n.T(locale, i18n.MsgRequired, "tenant_id"))) - return + if params.TenantID != "" { + tid, err := uuid.Parse(params.TenantID) + if err != nil { + client.SendResponse(protocol.NewErrorResponse(req.ID, protocol.ErrInvalidRequest, i18n.T(locale, i18n.MsgInvalidID, "tenant_id"))) + return + } + tenantID = tid + } else { + tenantID = client.TenantID() } - tid, err := uuid.Parse(params.TenantID) - if err != nil { - client.SendResponse(protocol.NewErrorResponse(req.ID, protocol.ErrInvalidRequest, i18n.T(locale, i18n.MsgInvalidID, "tenant_id"))) - return - } - tenantID = tid } else { tenantID = client.TenantID() } diff --git a/internal/http/agents.go b/internal/http/agents.go index 6421cec0..65ff17e8 100644 --- a/internal/http/agents.go +++ b/internal/http/agents.go @@ -120,11 +120,10 @@ func (h *AgentsHandler) handleCreate(w http.ResponseWriter, r *http.Request) { req.OwnerID = userID - // Resolve tenant_id: cross-tenant callers must provide it; others inherit their own tenant. + // Resolve tenant_id: explicit body field for cross-tenant; otherwise inherit from auth context. if store.IsOwnerRole(r.Context()) { if req.TenantID == uuid.Nil { - writeJSON(w, http.StatusBadRequest, map[string]string{"error": i18n.T(locale, i18n.MsgRequired, "tenant_id")}) - return + req.TenantID = store.TenantIDFromContext(r.Context()) } } else { req.TenantID = store.TenantIDFromContext(r.Context())