diff --git a/README.md b/README.md index 49ef2c4..ed91e6f 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,7 @@ Manual control also pauses effort discovery for `reasoning.effort=auto`; learned State survives restarts in `config.json..availability.json`, separated by the Zen upstream URL. The background scheduler checks for due models once per minute, skips manually controlled models, and probes the rest sequentially, with a 60-second timeout per lane. No channels available means no automatic disable. -Administration endpoints (login required; writes also require CSRF): `GET /api/models/availability`, `POST /api/models/restore` with `{"model":"MODEL_ID"}` (restores and takes manual control), and `POST /api/models/manual` with `{"model":"MODEL_ID","manual":true|false}` to switch between manual and automatic control. +Administration endpoints (login required; writes also require CSRF): `GET /api/models/availability`, `POST /api/models/probe` (marks every automatic free model due and starts a probe sweep right away, so the WebUI's refresh status button re-probes instead of only reloading the cached view), `POST /api/models/restore` with `{"model":"MODEL_ID"}` (restores and takes manual control), and `POST /api/models/manual` with `{"model":"MODEL_ID","manual":true|false}` to switch between manual and automatic control. ### Sessions and proxies diff --git a/README.zh-CN.md b/README.zh-CN.md index a2de430..c0317d9 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -278,7 +278,7 @@ System One 使用原生 `noul` 类型询问“1+1 是否等于 2”,不注入 状态保存在 `config.json.<上游地址指纹>.availability.json`,重启后保留,按 Zen 上游 URL 隔离。后台每分钟检查到期项,跳过手动控制的模型,串行探测其余模型,每条通道最多等待 60 秒。 -管理接口:`GET /api/models/availability` 查看状态;`POST /api/models/restore` 携带 `{"model":"MODEL_ID"}` 恢复并进入手动控制;`POST /api/models/manual` 携带 `{"model":"MODEL_ID","manual":true|false}` 在手动与自动之间切换。均需管理登录,写入接口还需 CSRF 校验。 +管理接口:`GET /api/models/availability` 查看状态;`POST /api/models/probe` 将所有自动探测的免费模型标记为到期并立即开始一轮探测,WebUI「刷新状态」按钮即调用它(真正的重新探测,而不是只重载缓存视图);`POST /api/models/restore` 携带 `{"model":"MODEL_ID"}` 恢复并进入手动控制;`POST /api/models/manual` 携带 `{"model":"MODEL_ID","manual":true|false}` 在手动与自动之间切换。均需管理登录,写入接口还需 CSRF 校验。 ### 会话与代理 diff --git a/internal/admin/availability.go b/internal/admin/availability.go index ac420cc..429dbbd 100644 --- a/internal/admin/availability.go +++ b/internal/admin/availability.go @@ -12,6 +12,15 @@ func (a *Server) handleAvailability(w http.ResponseWriter, r *http.Request) { httpx.WriteJSON(w, http.StatusOK, map[string]any{"models": a.manager.AvailabilitySnapshot()}) } +// handleProbeModels marks every automatic free model due and wakes the probe +// loop, so the availability page's refresh triggers a real re-probe instead +// of only reloading the cached snapshot. It answers with the current +// availability list; the fresh results land as the sweep records them. +func (a *Server) handleProbeModels(w http.ResponseWriter, r *http.Request) { + a.manager.RequestAvailabilitySweep() + a.handleAvailability(w, r) +} + // 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. diff --git a/internal/admin/server.go b/internal/admin/server.go index 8e94f38..6b83706 100644 --- a/internal/admin/server.go +++ b/internal/admin/server.go @@ -67,6 +67,7 @@ func (a *Server) Handler() http.Handler { mux.Handle("GET /api/models/availability", a.authenticate(http.HandlerFunc(a.handleAvailability))) mux.Handle("POST /api/models/restore", a.authenticate(a.csrf(http.HandlerFunc(a.handleRestoreModel)))) mux.Handle("POST /api/models/manual", a.authenticate(a.csrf(http.HandlerFunc(a.handleManualModel)))) + mux.Handle("POST /api/models/probe", a.authenticate(a.csrf(http.HandlerFunc(a.handleProbeModels)))) mux.Handle("GET /api/rotation", a.authenticate(http.HandlerFunc(a.handleRotation))) mux.Handle("PUT /api/rotation", a.authenticate(a.csrf(http.HandlerFunc(a.handleSaveRotation)))) mux.Handle("POST /api/rotation/current", a.authenticate(a.csrf(http.HandlerFunc(a.handleSelectRotation)))) diff --git a/internal/gateway/availability.go b/internal/gateway/availability.go index bf8219a..a2a7b40 100644 --- a/internal/gateway/availability.go +++ b/internal/gateway/availability.go @@ -68,6 +68,7 @@ func (m *RuntimeController) SetManualModel(model string, manual bool) error { func (m *RuntimeController) startAvailabilityChecks() { ctx, cancel := context.WithCancel(m.root) m.availabilityCancel = cancel + m.availabilitySweep = make(chan struct{}, 1) go func() { ticker := time.NewTicker(time.Minute) defer ticker.Stop() @@ -76,12 +77,32 @@ func (m *RuntimeController) startAvailabilityChecks() { select { case <-ctx.Done(): return + case <-m.availabilitySweep: case <-ticker.C: } } }() } +// RequestAvailabilitySweep marks every automatic free model due for a probe +// and wakes the probe loop, so the availability page's refresh re-probes +// instead of waiting out the minute ticker. A request while a sweep is +// already queued is a no-op: the queued sweep reads the freshly marked +// records as it iterates. +func (m *RuntimeController) RequestAvailabilitySweep() { + r := m.current.Load() + if r == nil { + return + } + if err := r.availability.ScheduleSweep(); err != nil { + m.logger.Warn("model availability sweep could not be scheduled", "error", err) + } + select { + case m.availabilitySweep <- struct{}{}: + default: + } +} + // checkFreeModels probes, one at a time, every free model under automatic // control whose next check is due. A result is recorded only while the // runtime that ran the probe is still current. diff --git a/internal/gateway/runtime.go b/internal/gateway/runtime.go index 1c68bc5..8ee47aa 100644 --- a/internal/gateway/runtime.go +++ b/internal/gateway/runtime.go @@ -64,6 +64,9 @@ type RuntimeController struct { effective EffectiveListeners metadata *modelcatalog.PricingRegistry availabilityCancel context.CancelFunc + // availabilitySweep wakes the probe loop ahead of its minute tick; the + // capacity-one buffer coalesces requests while a sweep is in flight. + availabilitySweep chan struct{} // warpPool is the pool shared by successive runtimes when the WARP size // and stack are unchanged. warpKey is the identity used for that reuse. warpPool *warp.Pool diff --git a/internal/models/availability.go b/internal/models/availability.go index 530b025..281aa16 100644 --- a/internal/models/availability.go +++ b/internal/models/availability.go @@ -150,6 +150,22 @@ func (s *AvailabilityRegistry) Restore(model string, now time.Time) error { return s.SetManual(model, true, now) } +// ScheduleSweep marks every automatically controlled model due for a probe, +// so the next check pass re-probes them instead of waiting out their +// scheduled backoff. Manually controlled records are left untouched. +func (s *AvailabilityRegistry) ScheduleSweep() error { + s.mu.Lock() + defer s.mu.Unlock() + for model, item := range s.items { + if item.Manual { + continue + } + item.NextCheck = time.Time{} + s.items[model] = item + } + return s.saveLocked() +} + // Record stores the result of an automatic probe that started when the record // was at generation. The result is dropped when Generation has moved on since // then or the model is under manual control. Only the reason diff --git a/webui/css/components.css b/webui/css/components.css index df6bcc4..6c576ea 100644 --- a/webui/css/components.css +++ b/webui/css/components.css @@ -290,6 +290,30 @@ textarea { color: var(--bad); } +.chip.chip-toggle { + cursor: pointer; + color: var(--text-2); + border-style: dashed; + background: transparent; +} + +.chip.chip-toggle:hover { + color: var(--text-1); +} + +.pager { + display: flex; + align-items: center; + gap: var(--sp-3); + margin-top: var(--sp-3); +} + +.pager-info { + color: var(--text-2); + font-size: var(--fs-sm); + white-space: nowrap; +} + .code-card { margin: var(--sp-3) 0; border: 1px solid var(--border-1); diff --git a/webui/css/tokens.css b/webui/css/tokens.css index 25ba5ee..2fe0995 100644 --- a/webui/css/tokens.css +++ b/webui/css/tokens.css @@ -56,29 +56,29 @@ --content-max: 1280px; } -@media (prefers-color-scheme: dark) { - :root { - color-scheme: dark; +/* The theme module (webui/js/theme.js) resolves the stored choice and the + system preference before first paint and sets data-theme accordingly. */ +:root[data-theme="dark"] { + color-scheme: dark; - --bg: #0a0a0a; - --bg-subtle: #171717; - --surface: #121212; - --surface-2: #0d0d0d; - --text-1: #ededed; - --text-2: #a0a0a0; - --text-3: #787878; - --border-1: #262626; - --border-2: #3a3a3a; - --inverse-bg: #ededed; - --inverse-text: #0a0a0a; - --inverse-hover: #cfcfcf; - --focus-ring: rgba(237, 237, 237, 0.18); - --overlay: rgba(0, 0, 0, 0.6); + --bg: #0a0a0a; + --bg-subtle: #171717; + --surface: #121212; + --surface-2: #0d0d0d; + --text-1: #ededed; + --text-2: #a0a0a0; + --text-3: #787878; + --border-1: #262626; + --border-2: #3a3a3a; + --inverse-bg: #ededed; + --inverse-text: #0a0a0a; + --inverse-hover: #cfcfcf; + --focus-ring: rgba(237, 237, 237, 0.18); + --overlay: rgba(0, 0, 0, 0.6); - --ok: #3fb950; - --warn: #d29922; - --warn-bg: rgba(210, 153, 34, 0.15); - --bad: #f85149; - --bad-bg: rgba(248, 81, 73, 0.15); - } + --ok: #3fb950; + --warn: #d29922; + --warn-bg: rgba(210, 153, 34, 0.15); + --bad: #f85149; + --bad-bg: rgba(248, 81, 73, 0.15); } diff --git a/webui/index.html b/webui/index.html index cdcff2e..636dd8f 100644 --- a/webui/index.html +++ b/webui/index.html @@ -13,6 +13,16 @@ + @@ -81,6 +91,7 @@

+ @@ -326,7 +337,7 @@

请求路由

-

最多展示最近 100 条。

+

最多展示最近 500 条,分页显示。

@@ -347,12 +358,28 @@
+
+ + + + +

上游尝试

-

最多展示最近 100 条。

+

最多展示最近 500 条,分页显示。

@@ -372,6 +399,22 @@
+
+ + + + +