feat(admin): add LLM call logs, system info, plugin list pages
- ai-core/llm: ring-buffer call logger with stats - Gateway: /api/v1/admin/llm-calls, /system, /plugins, /sessions endpoints - Frontend: LLMCallsPage (table + stats), SystemPage (version/plugins/sessions) - Admin nav expanded to 7 items
This commit is contained in:
1 parent
8bfda096f7
commit
1a80ac2a00
7 files changed
+318
-1
No files matched your search
@@ -56,6 +56,13 @@ type OrchestratorPipeline interface {
|
||||
// WebSocketHub manages WS connections.
|
||||
type WebSocketHub interface {
|
||||
UpgradeHandler() http.HandlerFunc
|
||||
Count() int
|
||||
}
|
||||
|
||||
// LLMCallLogger provides LLM call history.
|
||||
type LLMCallLogger interface {
|
||||
Recent(n int) []map[string]any
|
||||
Stats() map[string]any
|
||||
}
|
||||
|
||||
// Dependencies holds all injectable services.
|
||||
@@ -65,6 +72,8 @@ type Dependencies struct {
|
||||
VoiceSvc VoiceService
|
||||
Orchestrator OrchestratorPipeline
|
||||
WSHub WebSocketHub
|
||||
LLMLogger LLMCallLogger
|
||||
PluginList []map[string]string
|
||||
}
|
||||
|
||||
// Router handles HTTP routing with middleware support.
|
||||
@@ -101,6 +110,10 @@ func (r *Router) setupRoutes() {
|
||||
|
||||
// Admin
|
||||
r.mux.HandleFunc("/api/v1/admin/dashboard", r.authMW(r.adminMW(r.adminDashboardHandler)))
|
||||
r.mux.HandleFunc("/api/v1/admin/llm-calls", r.authMW(r.adminMW(r.llmCallsHandler)))
|
||||
r.mux.HandleFunc("/api/v1/admin/system", r.authMW(r.adminMW(r.systemInfoHandler)))
|
||||
r.mux.HandleFunc("/api/v1/admin/plugins", r.authMW(r.adminMW(r.pluginListHandler)))
|
||||
r.mux.HandleFunc("/api/v1/admin/sessions", r.authMW(r.adminMW(r.adminSessionsHandler)))
|
||||
}
|
||||
|
||||
// ServeHTTP implements http.Handler.
|
||||
@@ -348,6 +361,40 @@ func (r *Router) adminDashboardHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// --- Admin extra handlers ---
|
||||
|
||||
func (r *Router) llmCallsHandler(w http.ResponseWriter, req *http.Request) {
|
||||
if r.deps.LLMLogger == nil {
|
||||
writeJSON(w, 200, M{"calls": []any{}, "stats": M{}})
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, M{
|
||||
"calls": r.deps.LLMLogger.Recent(50),
|
||||
"stats": r.deps.LLMLogger.Stats(),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Router) systemInfoHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
writeJSON(w, 200, M{
|
||||
"system": M{
|
||||
"version": "2.0.0-dev",
|
||||
"go_version": "1.26",
|
||||
"uptime_sec": int(time.Since(startTime).Seconds()),
|
||||
"ws_clients": r.deps.WSHub.Count(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Router) pluginListHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
plugins := r.deps.PluginList
|
||||
if plugins == nil { plugins = []map[string]string{} }
|
||||
writeJSON(w, 200, M{"plugins": plugins})
|
||||
}
|
||||
|
||||
func (r *Router) adminSessionsHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
writeJSON(w, 200, M{"sessions": []any{}, "total": r.deps.WSHub.Count()})
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
type M = map[string]any
|
||||
|
||||
Reference in new issue
Block a user