mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
- Remove the new/New prefix from constructors; rename the colliding types semantically (ModelCatalog, RuntimeController, Metrics, LogBroker, Redactor, proxyTransports, upstreamNodes, ...). - Unify upstream lane naming on v1 (/zen, OpenCode 1.x shape) and v2 (/inference and /zen/go, 2.x CLI shape); add models.IsV1Upstream and drop the duplicated lane detection. - Fix inaccurate, truncated and stale comments across all packages and document exported symbols plus non-obvious internals. - Fix anthropicThinking passing "enabled"/"adaptive" through as an effort; derive the level from the budget instead. - Delete dead code (identity.StableID, unused protocol decoders and stream parser wrappers). - Export EffectiveListeners, rename modelsDev* metadata constants, and describe the metadata source as the OpenCode endpoint. - Rename the forced-collapse log event to stream_collapse_failed and add an anonymous field. - Correct the README upstream.zen default and add upstream.anonymous.
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"opencode2api/internal/httpx"
|
|
)
|
|
|
|
// handleAvailability lists the free models with their probe state, so the
|
|
// availability page can show which ones are disabled and why.
|
|
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()})
|
|
}
|
|
|
|
// handleRestoreModel returns a disabled free model to manual control, which
|
|
// re-enables it and keeps automatic probes from disabling it again. It answers
|
|
// with the refreshed availability list.
|
|
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)
|
|
}
|
|
|
|
// handleManualModel switches a free model between manual and automatic
|
|
// control: a manual model stays enabled and is not probed, while switching
|
|
// back to automatic schedules a probe. It answers with the refreshed list.
|
|
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)
|
|
}
|