MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / registerModelsForAuthWithCache

Method registerModelsForAuthWithCache

sdk/cliproxy/service.go:1905–2128  ·  view source on GitHub ↗
(ctx context.Context, a *coreauth.Auth, compatCache *openAICompatibilityRegistrationCache)

Source from the content-addressed store, hash-verified

1903}
1904
1905func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreauth.Auth, compatCache *openAICompatibilityRegistrationCache) {
1906 if a == nil || a.ID == "" {
1907 return
1908 }
1909 if ctx == nil {
1910 ctx = context.Background()
1911 }
1912 if a.Disabled {
1913 GlobalModelRegistry().UnregisterClient(a.ID)
1914 return
1915 }
1916 authKind := a.AuthKind()
1917 // Unregister legacy client ID (if present) to avoid double counting
1918 if a.Runtime != nil {
1919 if idGetter, ok := a.Runtime.(interface{ GetClientID() string }); ok {
1920 if rid := idGetter.GetClientID(); rid != "" && rid != a.ID {
1921 GlobalModelRegistry().UnregisterClient(rid)
1922 }
1923 }
1924 }
1925 provider := strings.ToLower(strings.TrimSpace(a.Provider))
1926 compatProviderKey, compatDisplayName, compatDetected := openAICompatInfoFromAuth(a)
1927 if compatDetected {
1928 provider = "openai-compatibility"
1929 }
1930 excluded := s.oauthExcludedModels(provider, authKind)
1931 // The synthesizer pre-merges per-account and global exclusions into the "excluded_models" attribute.
1932 // If this attribute is present, it represents the complete list of exclusions and overrides the global config.
1933 if a.Attributes != nil {
1934 if val, ok := a.Attributes["excluded_models"]; ok && strings.TrimSpace(val) != "" {
1935 excluded = strings.Split(val, ",")
1936 }
1937 }
1938 if s.tryRegisterPluginModelsForAuth(ctx, a, provider, authKind, excluded) {
1939 return
1940 }
1941 var models []*ModelInfo
1942 switch provider {
1943 case "gemini":
1944 models = registry.GetGeminiModels()
1945 if entry := s.resolveConfigGeminiKey(a); entry != nil {
1946 if len(entry.Models) > 0 {
1947 models = buildGeminiConfigModels(entry)
1948 }
1949 if authKind == "apikey" {
1950 excluded = entry.ExcludedModels
1951 }
1952 }
1953 models = applyExcludedModels(models, excluded)
1954 case "vertex":
1955 // Vertex AI Gemini supports the same model identifiers as Gemini.
1956 models = registry.GetGeminiVertexModels()
1957 if entry := s.resolveConfigVertexCompatKey(a); entry != nil {
1958 if len(entry.Models) > 0 {
1959 models = buildVertexCompatConfigModels(entry)
1960 }
1961 if authKind == "apikey" {
1962 excluded = entry.ExcludedModels

Tested by

no test coverage detected