Changeset 0.22.0.1 (#94)
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"git.gobha.me/xcaliber/chat-switchboard/events"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/extraction"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/handlers"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/health"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/knowledge"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/memory"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/middleware"
|
||||
@@ -54,6 +55,8 @@ func main() {
|
||||
uekCache := crypto.NewUEKCache()
|
||||
var keyResolver *crypto.KeyResolver
|
||||
var objStore storage.ObjectStore
|
||||
var healthAccum *health.Accumulator
|
||||
var healthStore *postgres.HealthStore
|
||||
|
||||
if err := database.Connect(cfg); err != nil {
|
||||
log.Printf("⚠ Database unavailable: %v", err)
|
||||
@@ -89,6 +92,26 @@ func main() {
|
||||
// Initialize store layer
|
||||
stores = postgres.NewStores(database.DB)
|
||||
|
||||
// Provider health accumulator (v0.22.0)
|
||||
healthStore = postgres.NewHealthStore(database.DB)
|
||||
healthAccum = health.NewAccumulator(healthStore)
|
||||
defer healthAccum.Stop()
|
||||
|
||||
// Background health cleanup: prune windows older than 7 days
|
||||
go func() {
|
||||
ticker := time.NewTicker(6 * time.Hour)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
if n, err := healthStore.Prune(ctx, time.Now().UTC().Add(-health.PruneAge)); err != nil {
|
||||
log.Printf("⚠ health prune failed: %v", err)
|
||||
} else if n > 0 {
|
||||
log.Printf("🧹 health: pruned %d old windows", n)
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
|
||||
// Bootstrap admin from env (K8s secret) — upserts on every restart
|
||||
handlers.BootstrapAdmin(cfg, stores)
|
||||
|
||||
@@ -350,6 +373,9 @@ func main() {
|
||||
|
||||
// Chat Completions
|
||||
comp := handlers.NewCompletionHandler(keyResolver, stores, hub, objStore, kbEmbedder)
|
||||
if healthAccum != nil {
|
||||
comp.SetHealthRecorder(healthAccum)
|
||||
}
|
||||
protected.POST("/chat/completions", comp.Complete)
|
||||
protected.GET("/tools", comp.ListTools)
|
||||
|
||||
@@ -722,6 +748,18 @@ func main() {
|
||||
admin.POST("/extensions", extAdm.AdminInstallExtension)
|
||||
admin.PUT("/extensions/:id", extAdm.AdminUpdateExtension)
|
||||
admin.DELETE("/extensions/:id", extAdm.AdminUninstallExtension)
|
||||
|
||||
// Provider Health (admin — v0.22.0)
|
||||
healthAdm := handlers.NewHealthAdminHandler(healthStore, stores)
|
||||
admin.GET("/providers/health", healthAdm.GetAllProviderHealth)
|
||||
admin.GET("/providers/:id/health", healthAdm.GetProviderHealth)
|
||||
|
||||
// Capability Overrides (admin — v0.22.0)
|
||||
capAdm := handlers.NewCapOverrideAdminHandler(stores)
|
||||
admin.GET("/models/:id/capabilities", capAdm.GetModelCapabilities)
|
||||
admin.PUT("/models/:id/capabilities", capAdm.SetModelCapability)
|
||||
admin.DELETE("/models/:id/capabilities/:overrideId", capAdm.DeleteModelCapability)
|
||||
admin.GET("/capability-overrides", capAdm.ListAllOverrides)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,6 +782,7 @@ func main() {
|
||||
log.Printf(" Storage: disabled")
|
||||
}
|
||||
log.Printf(" EventBus: ready, WebSocket on %s/ws", cfg.BasePath)
|
||||
log.Printf(" Health: provider tracking active (flush=%s, prune=%s)", health.FlushInterval, health.PruneAge)
|
||||
if err := r.Run(":" + cfg.Port); err != nil {
|
||||
log.Fatalf("Failed to start server: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user