feat(usage): add in-memory usage statistics tracking and API endpoint

- Introduced in-memory request statistics aggregation in `LoggerPlugin`.
- Added new structures for detailed metrics collection (e.g., token breakdown, request success/failure).
- Implemented `/usage` management API endpoint for retrieving aggregated statistics.
- Updated management handlers to support the new usage statistics functionality.
- Enhanced documentation to describe the usage metrics API.
This commit is contained in:
Luis Pater
2025-09-25 01:06:02 +08:00
parent 0db0b03db9
commit 19609db13c
7 changed files with 434 additions and 40 deletions

View File

@@ -476,31 +476,6 @@ func (s *Service) ensureAuthDir() error {
return nil
}
// syncCoreAuthFromAuths registers or updates core auths and disables missing ones.
func (s *Service) syncCoreAuthFromAuths(ctx context.Context, auths []*coreauth.Auth) {
if s.coreManager == nil {
return
}
seen := make(map[string]struct{}, len(auths))
for _, a := range auths {
if a == nil || a.ID == "" {
continue
}
seen[a.ID] = struct{}{}
s.applyCoreAuthAddOrUpdate(ctx, a)
}
// Disable removed auths
for _, stored := range s.coreManager.List() {
if stored == nil {
continue
}
if _, ok := seen[stored.ID]; ok {
continue
}
s.applyCoreAuthRemoval(ctx, stored.ID)
}
}
// registerModelsForAuth (re)binds provider models in the global registry using the core auth ID as client identifier.
func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
if a == nil || a.ID == "" {