Files
opencode2api/internal/admin/availability.go
T
CheerC 1e2702f6e0 fix: preserve manual control of free models (#57)
Keep manually restored free models enabled until automatic control is selected.
Persist the control mode and expose an authenticated per-model toggle in the WebUI and admin API.
Preserve disable evidence, renew expired 24-hour retries after inconclusive probes, and keep mode changes idempotent.

Validation: local regression checks, go vet/build, formatting and WebUI syntax passed; all five GitHub Checks passed. Test files were removed after validation.

Closes #56
2026-10-08 22:12:40 +08:00

47 lines
1.3 KiB
Go

package admin
import (
"net/http"
"opencode2api/internal/httpx"
)
func (a *Server) handleAvailability(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
httpx.WriteJSON(w, http.StatusOK, map[string]any{"models": a.manager.AvailabilitySnapshot()})
}
func (a *Server) handleRestoreModel(w http.ResponseWriter, r *http.Request) {
var input struct {
Model string `json:"model"`
}
if err := decodeAdminJSON(w, r, &input); err != nil {
writeAdminError(w, 400, "invalid_request", err.Error())
return
}
if err := a.manager.RestoreModel(input.Model); err != nil {
writeAdminError(w, 400, "restore_failed", a.manager.Redact(err.Error()))
return
}
a.handleAvailability(w, r)
}
func (a *Server) handleManualModel(w http.ResponseWriter, r *http.Request) {
var input struct {
Model string `json:"model"`
Manual *bool `json:"manual"`
}
if err := decodeAdminJSON(w, r, &input); err != nil {
writeAdminError(w, 400, "invalid_request", err.Error())
return
}
if input.Manual == nil {
writeAdminError(w, 400, "invalid_request", "manual is required")
return
}
if err := a.manager.SetManualModel(input.Model, *input.Manual); err != nil {
writeAdminError(w, 400, "manual_failed", a.manager.Redact(err.Error()))
return
}
a.handleAvailability(w, r)
}