Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fix AI and config profile handlers broken in v5 single-tenant mode
rcourtman743ef17b7901
diff --git a/internal/api/ai_handler.go b/internal/api/ai_handler.goindex fb1ff67e91..70fd6ba943 100644--- a/internal/api/ai_handler.go+++ b/internal/api/ai_handler.go@@ -260,6 +260,17 @@ func (h *AIHandler) loadAIConfig(ctx context.Context) *config.AIConfig {return cfg}+// SetLegacyRuntime wires the single-tenant runtime config and persistence explicitly.+// This is needed in v5 single-tenant mode where MultiTenantPersistence is nil.+func (h *AIHandler) SetLegacyRuntime(cfg *config.Config, persistence AIPersistence) {+ if cfg != nil {+ h.legacyConfig = cfg+ }+ if persistence != nil {+ h.legacyPersistence = persistence+ }+}+// SetMultiTenantPersistence updates the persistence managerfunc (h *AIHandler) SetMultiTenantPersistence(mtp *config.MultiTenantPersistence) {h.mtPersistence = mtpdiff --git a/internal/api/config_profiles.go b/internal/api/config_profiles.goindex 063b9b8ced..b1e685bfec 100644--- a/internal/api/config_profiles.go+++ b/internal/api/config_profiles.go@@ -18,6 +18,7 @@ import (// ConfigProfileHandler handles configuration profile operationstype ConfigProfileHandler struct {mtPersistence *config.MultiTenantPersistence+ legacyPersistence *config.ConfigPersistencevalidator *models.ProfileValidatormu sync.RWMutexsuggestionHandler *ProfileSuggestionHandler@@ -31,15 +32,26 @@ func NewConfigProfileHandler(mtp *config.MultiTenantPersistence) *ConfigProfileH}}+// SetLegacyPersistence sets the single-tenant persistence fallback.+func (h *ConfigProfileHandler) SetLegacyPersistence(p *config.ConfigPersistence) {+ h.legacyPersistence = p+}+// getPersistence resolves the persistence instance for the current tenantfunc (h *ConfigProfileHandler) getPersistence(ctx context.Context) (*config.ConfigPersistence, error) {- orgID := GetOrgID(ctx)- return h.mtPersistence.GetPersistence(orgID)+ if h.mtPersistence != nil {+ orgID := GetOrgID(ctx)+ return h.mtPersistence.GetPersistence(orgID)+ }+ if h.legacyPersistence != nil {+ return h.legacyPersistence, nil+ }+ return nil, fmt.Errorf("no persistence available")}// SetAIHandler sets the AI handler for profile suggestionsfunc (h *ConfigProfileHandler) SetAIHandler(aiHandler *AIHandler) {- h.suggestionHandler = NewProfileSuggestionHandler(h.mtPersistence, aiHandler)+ h.suggestionHandler = NewProfileSuggestionHandler(h.mtPersistence, h.legacyPersistence, aiHandler)}// ServeHTTP implements the http.Handler interfacediff --git a/internal/api/profile_suggestions.go b/internal/api/profile_suggestions.goindex 234be45da0..d38dbc9057 100644--- a/internal/api/profile_suggestions.go+++ b/internal/api/profile_suggestions.go@@ -16,15 +16,17 @@ import (// ProfileSuggestionHandler handles AI-assisted profile suggestionstype ProfileSuggestionHandler struct {- mtPersistence *config.MultiTenantPersistence- aiHandler *AIHandler+ mtPersistence *config.MultiTenantPersistence+ legacyPersistence *config.ConfigPersistence+ aiHandler *AIHandler}// NewProfileSuggestionHandler creates a new suggestion handler-func NewProfileSuggestionHandler(mtp *config.MultiTenantPersistence, aiHandler *AIHandler) *ProfileSuggestionHandler {+func NewProfileSuggestionHandler(mtp *config.MultiTenantPersistence, legacyPersistence *config.ConfigPersistence, aiHandler *AIHandler) *ProfileSuggestionHandler {return &ProfileSuggestionHandler{- mtPersistence: mtp,- aiHandler: aiHandler,+ mtPersistence: mtp,+ legacyPersistence: legacyPersistence,+ aiHandler: aiHandler,}}@@ -72,18 +74,22 @@ func (h *ProfileSuggestionHandler) HandleSuggestProfile(w http.ResponseWriter, rcontextParts := []string{}// Add existing profiles for reference (if persistence is available)+ var persistence *config.ConfigPersistenceif h.mtPersistence != nil {orgID := GetOrgID(r.Context())- persistence, err := h.mtPersistence.GetPersistence(orgID)- if err == nil {- profiles, err := persistence.LoadAgentProfiles()- if err == nil && len(profiles) > 0 {- profileNames := make([]string, len(profiles))- for i, p := range profiles {- profileNames[i] = p.Name- }- contextParts = append(contextParts, fmt.Sprintf("Existing profiles: %s", strings.Join(profileNames, ", ")))+ persistence, _ = h.mtPersistence.GetPersistence(orgID)+ }+ if persistence == nil {+ persistence = h.legacyPersistence+ }+ if persistence != nil {+ profiles, err := persistence.LoadAgentProfiles()+ if err == nil && len(profiles) > 0 {+ profileNames := make([]string, len(profiles))+ for i, p := range profiles {+ profileNames[i] = p.Name}+ contextParts = append(contextParts, fmt.Sprintf("Existing profiles: %s", strings.Join(profileNames, ", ")))}}diff --git a/internal/api/profile_suggestions_handlers_test.go b/internal/api/profile_suggestions_handlers_test.goindex 152d8aea2b..edea31d106 100644--- a/internal/api/profile_suggestions_handlers_test.go+++ b/internal/api/profile_suggestions_handlers_test.go@@ -21,7 +21,7 @@ func withOrgContext(req *http.Request) *http.Request {}func TestProfileSuggestionHandler_MethodNotAllowed(t *testing.T) {- handler := NewProfileSuggestionHandler(config.NewMultiTenantPersistence(t.TempDir()), &AIHandler{})+ handler := NewProfileSuggestionHandler(config.NewMultiTenantPersistence(t.TempDir()), nil, &AIHandler{})req := withOrgContext(httptest.NewRequest(http.MethodGet, "/api/admin/profiles/suggestions", nil))rr := httptest.NewRecorder()@@ -37,7 +37,7 @@ func TestProfileSuggestionHandler_ServiceUnavailable(t *testing.T) {mockSvc.On("IsRunning").Return(false)aiHandler := &AIHandler{legacyService: mockSvc}- handler := NewProfileSuggestionHandler(config.NewMultiTenantPersistence(t.TempDir()), aiHandler)+ handler := NewProfileSuggestionHandler(config.NewMultiTenantPersistence(t.TempDir()), nil, aiHandler)req := withOrgContext(httptest.NewRequest(http.MethodPost, "/api/admin/profiles/suggestions", bytes.NewReader([]byte(`{"prompt":"test"}`))))rr := httptest.NewRecorder()@@ -52,7 +52,7 @@ func TestProfileSuggestionHandler_InvalidRequest(t *testing.T) {mockSvc := new(MockAIService)mockSvc.On("IsRunning").Return(true)aiHandler := &AIHandler{legacyService: mockSvc}- handler := NewProfileSuggestionHandler(config.NewMultiTenantPersistence(t.TempDir()), aiHandler)+ handler := NewProfileSuggestionHandler(config.NewMultiTenantPersistence(t.TempDir()), nil, aiHandler)req := withOrgContext(httptest.NewRequest(http.MethodPost, "/api/admin/profiles/suggestions", bytes.NewReader([]byte("{bad"))))rr := httptest.NewRecorder()@@ -87,7 +87,7 @@ func TestProfileSuggestionHandler_SuccessAndParseFailure(t *testing.T) {}, nil).Once()aiHandler := &AIHandler{legacyService: mockSvc}- handler := NewProfileSuggestionHandler(mtPersistence, aiHandler)+ handler := NewProfileSuggestionHandler(mtPersistence, nil, aiHandler)req := withOrgContext(httptest.NewRequest(http.MethodPost, "/api/admin/profiles/suggestions", bytes.NewReader([]byte(`{"prompt":"build a profile"}`))))rr := httptest.NewRecorder()diff --git a/internal/api/router.go b/internal/api/router.goindex e3bf281410..a37612b9cf 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -278,6 +278,7 @@ func (r *Router) setupRoutes() {r.hostAgentHandlers = NewHostAgentHandlers(r.mtMonitor, r.monitor, r.wsHub)r.resourceHandlers = NewResourceHandlers()r.configProfileHandler = NewConfigProfileHandler(r.multiTenant)+ r.configProfileHandler.SetLegacyPersistence(r.persistence)r.licenseHandlers = NewLicenseHandlers(r.multiTenant)r.licenseHandlers.SetLegacyPersistence(r.persistence)// Wire license service provider so middleware can access per-tenant license services@@ -1483,6 +1484,7 @@ func (r *Router) setupRoutes() {// AI chat handlerr.aiHandler = NewAIHandler(r.multiTenant, r.mtMonitor, r.agentExecServer)+ r.aiHandler.SetLegacyRuntime(r.config, r.persistence)// AI-powered infrastructure discovery handlers// Note: The actual service is wired up later via SetDiscoveryService