From 3156109c71fc6bc04b1587829a65b2210eaa8414 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Sun, 4 Jan 2026 12:21:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(management):=20=E6=94=AF=E6=8C=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F/=E5=BC=BA=E5=88=B6=E5=89=8D=E7=BC=80/?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/handlers/management/config_basic.go | 66 +++++++++++++++++++ internal/api/server.go | 12 ++++ 2 files changed, 78 insertions(+) diff --git a/internal/api/handlers/management/config_basic.go b/internal/api/handlers/management/config_basic.go index ae292982..2d3cd1fb 100644 --- a/internal/api/handlers/management/config_basic.go +++ b/internal/api/handlers/management/config_basic.go @@ -202,6 +202,26 @@ func (h *Handler) PutLoggingToFile(c *gin.Context) { h.updateBoolField(c, func(v bool) { h.cfg.LoggingToFile = v }) } +// LogsMaxTotalSizeMB +func (h *Handler) GetLogsMaxTotalSizeMB(c *gin.Context) { + c.JSON(200, gin.H{"logs-max-total-size-mb": h.cfg.LogsMaxTotalSizeMB}) +} +func (h *Handler) PutLogsMaxTotalSizeMB(c *gin.Context) { + var body struct { + Value *int `json:"value"` + } + if errBindJSON := c.ShouldBindJSON(&body); errBindJSON != nil || body.Value == nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"}) + return + } + value := *body.Value + if value < 0 { + value = 0 + } + h.cfg.LogsMaxTotalSizeMB = value + h.persist(c) +} + // Request log func (h *Handler) GetRequestLog(c *gin.Context) { c.JSON(200, gin.H{"request-log": h.cfg.RequestLog}) } func (h *Handler) PutRequestLog(c *gin.Context) { @@ -232,6 +252,52 @@ func (h *Handler) PutMaxRetryInterval(c *gin.Context) { h.updateIntField(c, func(v int) { h.cfg.MaxRetryInterval = v }) } +// ForceModelPrefix +func (h *Handler) GetForceModelPrefix(c *gin.Context) { + c.JSON(200, gin.H{"force-model-prefix": h.cfg.ForceModelPrefix}) +} +func (h *Handler) PutForceModelPrefix(c *gin.Context) { + h.updateBoolField(c, func(v bool) { h.cfg.ForceModelPrefix = v }) +} + +func normalizeRoutingStrategy(strategy string) (string, bool) { + normalized := strings.ToLower(strings.TrimSpace(strategy)) + switch normalized { + case "", "round-robin", "roundrobin", "rr": + return "round-robin", true + case "fill-first", "fillfirst", "ff": + return "fill-first", true + default: + return "", false + } +} + +// RoutingStrategy +func (h *Handler) GetRoutingStrategy(c *gin.Context) { + strategy, ok := normalizeRoutingStrategy(h.cfg.Routing.Strategy) + if !ok { + c.JSON(200, gin.H{"strategy": strings.TrimSpace(h.cfg.Routing.Strategy)}) + return + } + c.JSON(200, gin.H{"strategy": strategy}) +} +func (h *Handler) PutRoutingStrategy(c *gin.Context) { + var body struct { + Value *string `json:"value"` + } + if errBindJSON := c.ShouldBindJSON(&body); errBindJSON != nil || body.Value == nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"}) + return + } + normalized, ok := normalizeRoutingStrategy(*body.Value) + if !ok { + c.JSON(http.StatusBadRequest, gin.H{"error": "invalid strategy"}) + return + } + h.cfg.Routing.Strategy = normalized + h.persist(c) +} + // Proxy URL func (h *Handler) GetProxyURL(c *gin.Context) { c.JSON(200, gin.H{"proxy-url": h.cfg.ProxyURL}) } func (h *Handler) PutProxyURL(c *gin.Context) { diff --git a/internal/api/server.go b/internal/api/server.go index ceafd6b5..3119bbb9 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -492,6 +492,10 @@ func (s *Server) registerManagementRoutes() { mgmt.PUT("/logging-to-file", s.mgmt.PutLoggingToFile) mgmt.PATCH("/logging-to-file", s.mgmt.PutLoggingToFile) + mgmt.GET("/logs-max-total-size-mb", s.mgmt.GetLogsMaxTotalSizeMB) + mgmt.PUT("/logs-max-total-size-mb", s.mgmt.PutLogsMaxTotalSizeMB) + mgmt.PATCH("/logs-max-total-size-mb", s.mgmt.PutLogsMaxTotalSizeMB) + mgmt.GET("/usage-statistics-enabled", s.mgmt.GetUsageStatisticsEnabled) mgmt.PUT("/usage-statistics-enabled", s.mgmt.PutUsageStatisticsEnabled) mgmt.PATCH("/usage-statistics-enabled", s.mgmt.PutUsageStatisticsEnabled) @@ -564,6 +568,14 @@ func (s *Server) registerManagementRoutes() { mgmt.PUT("/max-retry-interval", s.mgmt.PutMaxRetryInterval) mgmt.PATCH("/max-retry-interval", s.mgmt.PutMaxRetryInterval) + mgmt.GET("/force-model-prefix", s.mgmt.GetForceModelPrefix) + mgmt.PUT("/force-model-prefix", s.mgmt.PutForceModelPrefix) + mgmt.PATCH("/force-model-prefix", s.mgmt.PutForceModelPrefix) + + mgmt.GET("/routing/strategy", s.mgmt.GetRoutingStrategy) + mgmt.PUT("/routing/strategy", s.mgmt.PutRoutingStrategy) + mgmt.PATCH("/routing/strategy", s.mgmt.PutRoutingStrategy) + mgmt.GET("/claude-api-key", s.mgmt.GetClaudeKeys) mgmt.PUT("/claude-api-key", s.mgmt.PutClaudeKeys) mgmt.PATCH("/claude-api-key", s.mgmt.PatchClaudeKey)