Align usage dashboard with CCSwitch

Filter request logs to model API calls and add request, provider, model, and settings tabs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Opus 5 committed 2026-10-19 19:33:51 +08:00
1 parent f729910082
commit 272f604274
8 files changed
+444 -64

No files matched your search

+17 -3
View File
@@ -35,6 +35,8 @@ type LogEntry struct {
Time time.Time `json:"time"`
Method string `json:"method"`
Path string `json:"path"`
App string `json:"app,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
Status int `json:"status"`
DurationMS int64 `json:"duration_ms"`
@@ -71,9 +73,9 @@ func (s *Server) Port() int { return s.port }
// Handler returns the full HTTP handler.
func (s *Server) Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("POST /v1/messages", s.withAuth(s.handleMessages))
mux.Handle("POST /v1/messages", s.withLogging(s.withAuth(s.handleMessages)))
mux.HandleFunc("POST /v1/messages/count_tokens", s.withAuth(s.handleCountTokens))
mux.HandleFunc("POST /v1/responses", s.withAuth(s.handleResponses))
mux.Handle("POST /v1/responses", s.withLogging(s.withAuth(s.handleResponses)))
mux.HandleFunc("GET /api/status", s.handleStatus)
mux.HandleFunc("POST /api/fetch-models", s.handleFetchModels)
mux.HandleFunc("GET /api/providers", s.handleListProviders)
@@ -86,7 +88,7 @@ func (s *Server) Handler() http.Handler {
mux.HandleFunc("GET /api/settings", s.handleGetSettings)
mux.HandleFunc("PUT /api/settings", s.handleUpdateSettings)
mux.HandleFunc("GET /api/logs", s.handleLogs)
return s.withLogging(mux)
return mux
}
// withAuth protects the Anthropic-compatible endpoints with the local
@@ -139,6 +141,17 @@ func (rec *record) update(fn func(*LogEntry)) {
fn(&rec.entry)
}
func requestApp(path string) string {
switch path {
case "/v1/messages":
return "Claude Code"
case "/v1/responses":
return "Codex"
default:
return ""
}
}
func (s *Server) withLogging(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
@@ -146,6 +159,7 @@ func (s *Server) withLogging(next http.Handler) http.Handler {
Time: start,
Method: r.Method,
Path: r.URL.Path,
App: requestApp(r.URL.Path),
}}
ww := &statusWriter{ResponseWriter: w, status: http.StatusOK}
next.ServeHTTP(ww, r.WithContext(context.WithValue(r.Context(), recordKey{}, rec)))