diff --git a/backend/internal/http/handler/admin_read.go b/backend/internal/http/handler/admin_read.go index e338a38..2e09ab9 100644 --- a/backend/internal/http/handler/admin_read.go +++ b/backend/internal/http/handler/admin_read.go @@ -67,6 +67,13 @@ func (h *AdminReadHandler) Logs(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) return } + // Resolve account_id -> account label (email) so the log table can show which + // provider account fulfilled each generation under the user. + accountByID, err := h.admin.AccountNameMap(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) + return + } out := make([]gin.H, 0, len(items)) for _, item := range items { var userName any @@ -77,6 +84,14 @@ func (h *AdminReadHandler) Logs(c *gin.Context) { } else { userName = item.UserID } + var accountName any + if item.AccountID != "" { + if label, ok := accountByID[item.AccountID]; ok { + accountName = label + } else { + accountName = item.AccountID + } + } out = append(out, gin.H{ "id": item.ID, "ts": item.TS.Unix(), @@ -92,6 +107,8 @@ func (h *AdminReadHandler) Logs(c *gin.Context) { "source": item.Source, "user_id": emptyStringNil(item.UserID), "user_name": userName, + "account_id": emptyStringNil(item.AccountID), + "account": accountName, "cost": item.Cost, "elapsed_ms": item.ElapsedMS, "file": emptyStringNil(item.File), diff --git a/backend/internal/http/handler/user_generation.go b/backend/internal/http/handler/user_generation.go index d432657..1cad5ff 100644 --- a/backend/internal/http/handler/user_generation.go +++ b/backend/internal/http/handler/user_generation.go @@ -218,6 +218,13 @@ func (h *UserGenerationHandler) Logs(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) return } + // Resolve account_id -> account label so the log table can show which + // provider account fulfilled each generation under the user. + accountByID, err := h.admin.AccountNameMap(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) + return + } out := make([]gin.H, 0, len(items)) for _, item := range items { @@ -229,6 +236,14 @@ func (h *UserGenerationHandler) Logs(c *gin.Context) { } else { userName = item.UserID } + var accountName any + if item.AccountID != "" { + if label, ok := accountByID[item.AccountID]; ok { + accountName = label + } else { + accountName = item.AccountID + } + } out = append(out, gin.H{ "id": item.ID, "ts": item.TS.Unix(), @@ -244,6 +259,8 @@ func (h *UserGenerationHandler) Logs(c *gin.Context) { "source": emptyStringNil(item.Source), "user_id": emptyStringNil(item.UserID), "user_name": userName, + "account_id": emptyStringNil(item.AccountID), + "account": accountName, "cost": item.Cost, "elapsed_ms": item.ElapsedMS, "file": emptyStringNil(item.File), diff --git a/backend/internal/service/admin_read.go b/backend/internal/service/admin_read.go index b6f62e8..413a1bb 100644 --- a/backend/internal/service/admin_read.go +++ b/backend/internal/service/admin_read.go @@ -136,6 +136,28 @@ func (s *AdminReadService) UserNameMap(ctx context.Context) (map[string]string, return out, nil } +// AccountNameMap builds a token-account id -> display label lookup (account +// email, else display name, else id) used to annotate log rows with which +// provider account fulfilled each generation (event_logs.account_id). +func (s *AdminReadService) AccountNameMap(ctx context.Context) (map[string]string, error) { + accounts, err := s.tokens.List(ctx) + if err != nil { + return nil, err + } + out := make(map[string]string, len(accounts)) + for _, a := range accounts { + label := strings.TrimSpace(a.AccountEmail) + if label == "" { + label = strings.TrimSpace(a.AccountDisplayName) + } + if label == "" { + label = a.ID + } + out[a.ID] = label + } + return out, nil +} + func (s *AdminReadService) Stats(ctx context.Context) (map[string]any, error) { stats, err := s.events.Stats(ctx) if err != nil { diff --git a/frontend/src/views/LogsView.vue b/frontend/src/views/LogsView.vue index c9d1212..ff7775a 100644 --- a/frontend/src/views/LogsView.vue +++ b/frontend/src/views/LogsView.vue @@ -237,7 +237,7 @@ const sourcePill = (s) => ({ 预览 时间 状态 - 用户 + 用户 / 账号 模型 提示词 / 错误 参数 @@ -280,6 +280,7 @@ const sourcePill = (s) => ({
{{ e.user_name || '匿名' }}
+
{{ e.account }}
{{ e.model }}
diff --git a/frontend/src/views/UserLogsTableView.vue b/frontend/src/views/UserLogsTableView.vue index 4451405..6ce6570 100644 --- a/frontend/src/views/UserLogsTableView.vue +++ b/frontend/src/views/UserLogsTableView.vue @@ -194,6 +194,7 @@ const params = (e) => { + @@ -205,6 +206,7 @@ const params = (e) => { 预览 时间 状态 + 用户 / 账号 模型 提示词 / 错误 参数 @@ -236,6 +238,10 @@ const params = (e) => { {{ statusLabel(e.status) }} + +
{{ e.user_name || '匿名' }}
+
{{ e.account }}
+
{{ e.model }}