From 2175a1093220c7030cb4b4f3022a8277d50822e0 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Thu, 25 Sep 2025 10:59:20 +0800 Subject: [PATCH] feat(gemini-web): Introduce stable account label for identification --- internal/provider/gemini-web/state.go | 16 ++++++++++++++++ internal/runtime/executor/gemini_web_executor.go | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/internal/provider/gemini-web/state.go b/internal/provider/gemini-web/state.go index 4442dad7..92c3be26 100644 --- a/internal/provider/gemini-web/state.go +++ b/internal/provider/gemini-web/state.go @@ -80,6 +80,22 @@ func NewGeminiWebState(cfg *config.Config, token *gemini.GeminiWebTokenStorage, return state } +// Label returns a stable account label for logging and persistence. +// If a storage file path is known, it uses the file base name (without extension). +// Otherwise, it falls back to the stable client ID (e.g., "gemini-web-"). +func (s *GeminiWebState) Label() string { + if s == nil { + return "" + } + if s.storagePath != "" { + base := strings.TrimSuffix(filepath.Base(s.storagePath), filepath.Ext(s.storagePath)) + if base != "" { + return base + } + } + return s.stableClientID +} + func (s *GeminiWebState) loadConversationCaches() { if path := s.convStorePath(); path != "" { if store, err := LoadConvStore(path); err == nil { diff --git a/internal/runtime/executor/gemini_web_executor.go b/internal/runtime/executor/gemini_web_executor.go index 5f2e09a6..78f31abb 100644 --- a/internal/runtime/executor/gemini_web_executor.go +++ b/internal/runtime/executor/gemini_web_executor.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "net/http" + "strings" "sync" "time" @@ -136,6 +137,11 @@ func (e *GeminiWebExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth auth.Metadata["secure_1psidts"] = ts.Secure1PSIDTS auth.Metadata["type"] = "gemini-web" auth.Metadata["last_refresh"] = time.Now().Format(time.RFC3339) + if v, ok := auth.Metadata["label"].(string); !ok || strings.TrimSpace(v) == "" { + if lbl := state.Label(); strings.TrimSpace(lbl) != "" { + auth.Metadata["label"] = strings.TrimSpace(lbl) + } + } return auth, nil }