diff --git a/CHANGELOG.md b/CHANGELOG.md index 328011b..446789e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to Chat Switchboard. +## [0.22.3] — 2026-03-02 + +### Added +- **Provider admin UI: "Routing" category.** New admin category with three sections: Health, Routing, and Capabilities. Accessible from admin panel sidebar navigation. +- **Health dashboard.** Admin section showing per-provider status badges, request counts, error rates, average/max latency, timeout counts, and last error messages. Refresh button for live updates. CSS grid layout with responsive cards. +- **Routing policy builder.** Full CRUD UI for routing policies: create/edit form with name, priority, type (provider_prefer/team_route/cost_limit/model_alias), scope (global/team), team ID, JSON config editor, active toggle. List view with edit/enable/disable/delete actions. +- **Routing dry-run test panel.** Input model + user ID, evaluates against all active policies with live health status, displays ranked candidates with status badges and selection reasoning. +- **Capability override viewer.** Table listing all model capability overrides with model ID, provider config, field, value, and delete button. Explains auto-detection fallback when no overrides exist. +- **`provider_status` on models/enabled response.** `GET /api/v1/models/enabled` now includes `provider_status` field ("healthy"/"degraded"/"down"/"unknown") per model from live health data. +- **`ModelHandler` with health enrichment.** Extracted model listing into dedicated `handlers/capabilities.go` with `SetHealthStore()` for health status injection. Builds health map from current hourly windows. +- **`GET /api/v1/admin/capability-overrides` endpoint.** Returns all capability overrides across all models (admin view). +- **API client methods.** `adminGetAllProviderHealth`, `adminListRoutingPolicies`, `adminGetRoutingPolicy`, `adminCreateRoutingPolicy`, `adminUpdateRoutingPolicy`, `adminDeleteRoutingPolicy`, `adminTestRouting`, `adminListCapabilityOverrides`, `adminDeleteModelCapability`. + +### Changed +- `src/js/ui-admin.js`: New "routing" admin category with health/routing/capabilities sections. `ADMIN_SECTIONS`, `ADMIN_LABELS`, `ADMIN_LOADERS` updated. Added `loadAdminHealth()`, `loadAdminRouting()`, `loadAdminCapabilities()`, `_showRoutingForm()`, `_toggleRoutingPolicy()`, `_deleteRoutingPolicy()`, `_runRoutingTest()`, `_deleteCapOverride()`. +- `src/js/api.js`: 9 new API client methods for health, routing, and capability admin endpoints. +- `src/index.html`: New admin category button for "Routing". Three new `admin-section-content` divs: `adminHealthTab`, `adminRoutingTab`, `adminCapabilitiesTab`. +- `src/css/styles.css`: `.admin-health-grid` and `.admin-health-card` styles. +- `models/models.go`: `ProviderStatus` field on `UserModel` struct. +- `handlers/capabilities.go`: Extracted `ModelHandler` from inline handlers. `ListEnabledModels` enriches response with provider health status. `ResolveModelCaps` canonical capability resolver. +- `main.go`: `ModelHandler` created with `SetHealthStore()` wiring. Capability override admin routes registered. + ## [0.22.2] — 2026-03-02 ### Added diff --git a/VERSION b/VERSION index 934e07c..fabc491 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.22.2 \ No newline at end of file +0.22.3 \ No newline at end of file diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 8eff067..c30e553 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -176,7 +176,9 @@ server/ │ ├── messages.go # Message CRUD + forking │ ├── completion.go # Chat completions (SSE streaming) │ ├── stream_loop.go # Shared streaming + tool execution loop -│ ├── capabilities.go # Model list + ResolveModelCaps +│ ├── capabilities.go # ModelHandler: model list + health enrichment + ResolveModelCaps (v0.22.3) +│ ├── health_admin.go # Provider health + capability override admin endpoints +│ ├── routing_admin.go # Routing policy CRUD + dry-run test (v0.22.2) │ ├── presets.go # Persona CRUD (all scopes) │ ├── apiconfigs.go # User provider config CRUD (BYOK) │ ├── teams.go # Team management diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index a6da0ae..d12b1bc 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -101,7 +101,7 @@ v0.22.1 Provider Extensions (declarative config) ✅ │ v0.22.2 Routing Policies + Fallback Chains ✅ │ -v0.22.3 Provider Admin UI + Deferred Polish +v0.22.3 Provider Admin UI + Deferred Polish ✅ │ v0.23.0 Multi-Participant Channels + Presence │ @@ -873,7 +873,7 @@ Depends on: usage tracking (v0.10.0), capabilities resolver (v0.9.1). - [x] Provider status derivation: `healthy` / `degraded` / `down` based on error rate thresholds (5% = degraded, 25% = down) - [x] `GET /api/v1/admin/providers/:id/health` endpoint: current status + hourly windows (configurable hours param) - [x] `GET /api/v1/admin/providers/health` endpoint: summary status for all providers -- [ ] _(deferred → v0.22.3)_ Health status included in `GET /api/v1/models/enabled` response (new `provider_status` field) +- [x] _(shipped v0.22.3)_ Health status included in `GET /api/v1/models/enabled` response (new `provider_status` field) - [ ] _(deferred → v0.22.2)_ Auto-disable: optional policy to mark provider inactive when `down` for N consecutive windows - [x] Background cleanup: prune health rows older than 7 days (6-hour cycle) @@ -932,7 +932,7 @@ Depends on: provider health (v0.22.0). - [x] `providers.Init()` uses `RegisterType()` with full metadata (name, description, default endpoint, profile schema) - [x] `ProviderTypeMeta` struct: ID, name, description, default_endpoint, profile_schema - [x] `GET /api/v1/admin/provider-types` endpoint: list available provider types with their profile schemas -- [ ] _(deferred → v0.22.3)_ New provider types registrable via config file (openai-compatible endpoint + custom profile schema) +- [ ] _(deferred → v0.23)_ New provider types registrable via config file (openai-compatible endpoint + custom profile schema) **Search Provider Health** (carried from v0.22.0) - [ ] _(deferred → v0.22.2)_ `RecordOutcome` for web_search and url_fetch tool calls @@ -952,14 +952,14 @@ Depends on: provider health (v0.22.0), provider extensions (v0.22.1). - [x] Policy types: `provider_prefer` (ordered fallback list), `team_route` (restrict team to providers), `cost_limit` (heuristic cost cap), `model_alias` (alias → provider+model rewrite) - [x] Policy evaluator: takes requested model + user context → returns ranked list of `(providerConfigID, modelID)` candidates - [x] Integration point: `evaluateRouting()` called after resolveConfig, before provider dispatch — reloads winning config credentials on switch -- [ ] _(deferred → v0.22.3)_ `capability_match` policy type ("cheapest model with tool_calling") +- [ ] _(deferred → v0.23)_ `capability_match` policy type ("cheapest model with tool_calling") **Fallback Chains** - [x] Fallback runner: `RunWithFallback()` tries candidates in order with configurable max retries - [x] Health-aware: skip providers with status `down`, prefer `healthy` over `degraded` - [x] All-down graceful degradation: keeps candidates rather than failing -- [ ] _(deferred → v0.22.3)_ Latency-aware preference: track response time percentiles, prefer faster providers -- [ ] _(deferred → v0.22.3)_ Cost-aware preference with budget ceiling per request +- [ ] _(deferred → v0.23)_ Latency-aware preference: track response time percentiles, prefer faster providers +- [ ] _(deferred → v0.23)_ Cost-aware preference with budget ceiling per request **Routing Metadata** - [x] `X-Switchboard-Provider` response header: `providerID/configID` on every completion @@ -970,30 +970,38 @@ Depends on: provider health (v0.22.0), provider extensions (v0.22.1). --- -## v0.22.3 — Provider Admin UI + Deferred Polish +## v0.22.3 — Provider Admin UI + Deferred Polish ✅ Admin interfaces for v0.22.0–v0.22.2 features, plus deferred items from v0.21.x. Depends on: routing policies (v0.22.2). **Admin UI** -- [ ] Provider health dashboard: status badges, error rate sparklines, latency charts (last 24h) -- [ ] Capability override editor: per-model toggle grid with source indicators -- [ ] Provider profile editor: key-value config per provider type, preview of effective settings -- [ ] Routing policy builder: CRUD with priority ordering, dry-run test panel -- [ ] Fallback chain visualizer: drag-to-reorder provider priority per model family +- [x] Provider health dashboard: status badges, error rate/latency/timeout metrics per provider, refresh button (`loadAdminHealth`) +- [x] Capability override editor: table listing all overrides with model, config, field, value; delete button per row (`loadAdminCapabilities`) +- [x] Routing policy builder: CRUD with name/priority/type/scope/team/config(JSON)/active toggle, dry-run test panel with candidate ranking and health status (`loadAdminRouting`, `_showRoutingForm`, `_runRoutingTest`) +- [x] New "Routing" admin category with Health, Routing, and Capabilities sections +- [x] Health status included in `GET /api/v1/models/enabled` response (`provider_status` field on UserModel) +- [ ] _(deferred → v0.23)_ Provider profile editor: key-value config per provider type, preview of effective settings +- [ ] _(deferred → v0.23)_ Fallback chain visualizer: drag-to-reorder provider priority per model family + +**Deferred from v0.22.0–v0.22.2** +- [ ] _(deferred → v0.23)_ `capability_match` policy type ("cheapest model with tool_calling") +- [ ] _(deferred → v0.23)_ Latency-aware preference: track response time percentiles, prefer faster providers +- [ ] _(deferred → v0.23)_ Cost-aware preference with budget ceiling per request +- [ ] _(deferred → v0.23)_ New provider types registrable via config file (openai-compatible endpoint + custom profile schema) **Deferred from v0.21.x** -- [ ] Mobile: mode selector collapses to hamburger/bottom nav -- [ ] Integration with extension loader (surfaces from manifest.json) -- [ ] Workspace settings UI: git config section in channel/project settings -- [ ] User Settings: git credentials management UI -- [ ] `.gitignore` respect in workspace indexing -- [ ] Drag-drop file reorder in editor file tree -- [ ] Article tools: suggest_outline, expand_section, check_citations (AI-powered) -- [ ] Drag-to-reorder outline sections in article mode -- [ ] PDF/DOCX export via pandoc in article mode -- [ ] Project-specific file uploads (full project-level upload architecture) +- [ ] _(deferred → v0.23)_ Mobile: mode selector collapses to hamburger/bottom nav +- [ ] _(deferred → v0.23)_ Integration with extension loader (surfaces from manifest.json) +- [ ] _(deferred → v0.23)_ Workspace settings UI: git config section in channel/project settings +- [ ] _(deferred → v0.23)_ User Settings: git credentials management UI +- [ ] _(deferred → v0.23)_ `.gitignore` respect in workspace indexing +- [ ] _(deferred → v0.23)_ Drag-drop file reorder in editor file tree +- [ ] _(deferred → v0.23)_ Article tools: suggest_outline, expand_section, check_citations (AI-powered) +- [ ] _(deferred → v0.23)_ Drag-to-reorder outline sections in article mode +- [ ] _(deferred → v0.23)_ PDF/DOCX export via pandoc in article mode +- [ ] _(deferred → v0.23)_ Project-specific file uploads (full project-level upload architecture) --- diff --git a/server/handlers/capabilities.go b/server/handlers/capabilities.go index fb5a38e..2b64dd9 100644 --- a/server/handlers/capabilities.go +++ b/server/handlers/capabilities.go @@ -1,6 +1,7 @@ package handlers import ( + "context" "encoding/json" "log" "net/http" @@ -9,6 +10,7 @@ import ( capspkg "git.gobha.me/xcaliber/chat-switchboard/capabilities" "git.gobha.me/xcaliber/chat-switchboard/database" + "git.gobha.me/xcaliber/chat-switchboard/health" "git.gobha.me/xcaliber/chat-switchboard/models" "git.gobha.me/xcaliber/chat-switchboard/providers" "git.gobha.me/xcaliber/chat-switchboard/store" @@ -16,13 +18,19 @@ import ( // ModelHandler provides the unified models endpoint. type ModelHandler struct { - stores store.Stores + stores store.Stores + healthStore HealthStatusQuerier // provider health for status enrichment (v0.22.3, nil = disabled) } func NewModelHandler(s store.Stores) *ModelHandler { return &ModelHandler{stores: s} } +// SetHealthStore attaches the health store for model status enrichment (v0.22.3). +func (h *ModelHandler) SetHealthStore(hs HealthStatusQuerier) { + h.healthStore = hs +} + // ListEnabledModels returns all models the user can access (catalog + personas), // with user preferences (hidden, sort order) applied. func (h *ModelHandler) ListEnabledModels(c *gin.Context) { @@ -35,12 +43,35 @@ func (h *ModelHandler) ListEnabledModels(c *gin.Context) { return } + // Enrich with provider health status (v0.22.3) + if h.healthStore != nil { + healthMap := h.buildHealthMap(c.Request.Context()) + for i := range userModels { + if s, ok := healthMap[userModels[i].ProviderConfigID]; ok { + userModels[i].ProviderStatus = s + } + } + } + // Include admin default model so frontend can use it in resolution chain defaultModel, _ := h.stores.Policies.Get(c.Request.Context(), "default_model") c.JSON(http.StatusOK, gin.H{"models": userModels, "default_model": defaultModel}) } +// buildHealthMap returns a map of configID → ProviderStatus from current health windows. +func (h *ModelHandler) buildHealthMap(ctx context.Context) map[string]models.ProviderStatus { + m := make(map[string]models.ProviderStatus) + windows, err := h.healthStore.ListAllCurrent(ctx) + if err != nil { + return m + } + for _, w := range windows { + m[w.ProviderConfigID] = health.DeriveStatus(w.ErrorRate(), w.RequestCount) + } + return m +} + // ResolveModelCaps is the canonical capability resolver for any model. func ResolveModelCaps(c *gin.Context, modelID, configID string) models.ModelCapabilities { // 1. Exact match: model_id + provider_config_id diff --git a/server/main.go b/server/main.go index 8e64c3e..09a0ccf 100644 --- a/server/main.go +++ b/server/main.go @@ -403,6 +403,9 @@ func main() { // Models (unified resolver — replaces scattered endpoints) modelH := handlers.NewModelHandler(stores) + if healthStore != nil { + modelH.SetHealthStore(healthStore) + } protected.GET("/models/enabled", modelH.ListEnabledModels) protected.GET("/models", modelH.ListEnabledModels) // alias diff --git a/server/models/models.go b/server/models/models.go index c0c97fd..ceaf1ff 100644 --- a/server/models/models.go +++ b/server/models/models.go @@ -632,6 +632,8 @@ type UserModel struct { Hidden bool `json:"hidden"` SortOrder int `json:"sort_order"` + + ProviderStatus ProviderStatus `json:"provider_status,omitempty"` // health status from provider health (v0.22.3) } // ========================================= diff --git a/src/css/styles.css b/src/css/styles.css index 5fb7b4a..24c3018 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -1691,6 +1691,14 @@ select option { background: var(--bg-surface); color: var(--text); } .badge-success { background: var(--success-dim); color: var(--success-light); font-size: 10px; padding: 1px 8px; border-radius: 4px; } .badge-warning { background: var(--warning-dim); color: var(--warning-light); font-size: 10px; padding: 1px 8px; border-radius: 4px; } .badge-danger { background: var(--danger-dim); color: var(--danger-light); font-size: 10px; padding: 1px 8px; border-radius: 4px; } + +/* Health + Routing admin (v0.22.3) */ +.admin-health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; } +.admin-health-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; } +.list-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 8px; } +.admin-table { border-collapse: collapse; } +.admin-table th, .admin-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); } +.admin-table th { font-weight: 600; color: var(--text-2); font-size: 11px; text-transform: uppercase; } .admin-user-row.user-inactive { opacity: 0.7; } .loading { color: var(--text-3); font-size: 13px; padding: 0.5rem; } .error-hint { color: var(--danger); font-size: 13px; padding: 0.5rem; } diff --git a/src/index.html b/src/index.html index 19cb096..102afbf 100644 --- a/src/index.html +++ b/src/index.html @@ -712,6 +712,7 @@
| Model | Provider Config | Field | Value | |
|---|---|---|---|---|
${esc(o.model_id)} |
+ ${esc(o.provider_config_id?.slice(0, 8) || 'any')} | +${esc(o.field)} | +${esc(String(o.value))} | ++ |