diff --git a/internal/api/handlers/management/api_tools.go b/internal/api/handlers/management/api_tools.go index de546ea820..4103006ff3 100644 --- a/internal/api/handlers/management/api_tools.go +++ b/internal/api/handlers/management/api_tools.go @@ -613,21 +613,15 @@ func tokenValueFromMetadata(metadata map[string]any) string { } func (h *Handler) authByIndex(authIndex string) *coreauth.Auth { - authIndex = strings.TrimSpace(authIndex) - if authIndex == "" || h == nil || h.authManager == nil { - return nil - } - auths := h.authManager.List() - for _, auth := range auths { - if auth == nil { - continue - } - auth.EnsureIndex() - if auth.Index == authIndex { - return auth - } - } - return nil + authIndex = strings.TrimSpace(authIndex) + if authIndex == "" || h == nil || h.authManager == nil { + return nil + } + // 使用直接查找替代 List() 全量拷贝 + if auth, ok := h.authManager.GetByIndex(authIndex); ok { + return auth + } + return nil } func (h *Handler) apiCallTransport(auth *coreauth.Auth) http.RoundTripper { diff --git a/sdk/cliproxy/auth/conductor.go b/sdk/cliproxy/auth/conductor.go index b29e04db8c..241da31451 100644 --- a/sdk/cliproxy/auth/conductor.go +++ b/sdk/cliproxy/auth/conductor.go @@ -2879,3 +2879,22 @@ func (m *Manager) HttpRequest(ctx context.Context, auth *Auth, req *http.Request } return exec.HttpRequest(ctx, auth, req) } + +func (m *Manager) GetByIndex(index string) (*Auth, bool) { + index = strings.TrimSpace(index) + if index == "" { + return nil, false + } + m.mu.Lock() + defer m.mu.Unlock() + for _, auth := range m.auths { + if auth == nil { + continue + } + auth.EnsureIndex() + if auth.Index == index { + return auth.Clone(), true + } + } + return nil, false +}