From cf31ff5e8e77789df21a8f69e397040f7c176cc5 Mon Sep 17 00:00:00 2001 From: xiaowei Date: Fri, 12 Jun 2026 08:54:00 +0800 Subject: [PATCH] api: add /api/v1/metrics endpoint exposing Dashboard metrics (avg_distill_loss, etc.) --- go/internal/api/server.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/go/internal/api/server.go b/go/internal/api/server.go index 07d5bc0..2fd6117 100644 --- a/go/internal/api/server.go +++ b/go/internal/api/server.go @@ -304,6 +304,19 @@ func NewServer() http.Handler { mux.HandleFunc("/api/v1/bootstrap", api.Bootstrap) mux.HandleFunc("/api/v1/stats", api.Stats) mux.HandleFunc("/api/v1/batch-commit", api.BatchCommit) + // 自优化指标(Dashboard,含 avg_distill_loss) + mux.HandleFunc("/api/v1/metrics", func(w http.ResponseWriter, r *http.Request) { + m := selfoptimize.Dash.Metrics() + if stats, err := ldb.Stats(); err == nil { + if total, ok := stats["total_memories"].(float64); ok { + m["total_memories"] = total + } + if total, ok := stats["total_episodes"].(float64); ok { + m["total_episodes"] = total + } + } + respondJSON(w, 200, m) + }) // ─── WebSocket 实时推送 ────────────────────── mux.HandleFunc("/api/v1/ws/", routes.WSHandler) mux.HandleFunc("/api/v1/ws", func(w http.ResponseWriter, r *http.Request) {