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

Method registerModelRefreshCallback

sdk/cliproxy/service.go:375–425  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

373}
374
375func (s *Service) registerModelRefreshCallback() {
376 // Register callback for startup and periodic model catalog refresh.
377 // When remote model definitions change, re-register models for affected providers.
378 // This intentionally rebuilds per-auth model availability from the latest catalog
379 // snapshot instead of preserving prior registry suppression state.
380 registry.SetModelRefreshCallback(func(changedProviders []string) {
381 if s == nil || s.coreManager == nil || len(changedProviders) == 0 {
382 return
383 }
384
385 providerSet := make(map[string]bool, len(changedProviders))
386 for _, p := range changedProviders {
387 providerSet[strings.ToLower(strings.TrimSpace(p))] = true
388 }
389
390 auths := s.coreManager.List()
391 refreshed := 0
392 var refreshedMu sync.Mutex
393 tasks := make([]modelRegistrationTask, 0, len(auths))
394 for _, item := range auths {
395 if item == nil || item.ID == "" {
396 continue
397 }
398 auth, ok := s.coreManager.GetByID(item.ID)
399 if !ok || auth == nil || auth.Disabled {
400 continue
401 }
402 provider := strings.ToLower(strings.TrimSpace(auth.Provider))
403 if !providerSet[provider] {
404 continue
405 }
406 authForRefresh := auth
407 tasks = append(tasks, modelRegistrationTask{
408 phase: modelRegistrationPhase(authForRefresh),
409 category: modelRegistrationCategory(authForRefresh),
410 run: func(compatCache *openAICompatibilityRegistrationCache) {
411 if s.refreshModelRegistrationForAuthWithCache(authForRefresh, compatCache) {
412 refreshedMu.Lock()
413 refreshed++
414 refreshedMu.Unlock()
415 }
416 },
417 })
418 }
419 s.runModelRegistrationTasks(context.Background(), tasks)
420
421 if refreshed > 0 {
422 log.Infof("re-registered models for %d auth(s) due to model catalog changes: %v", refreshed, changedProviders)
423 }
424 })
425}
426
427// newDefaultAuthManager creates a default authentication manager with supported OAuth providers.
428func newDefaultAuthManager() *sdkAuth.Manager {

Callers 1

RunMethod · 0.95

Calls 7

SetModelRefreshCallbackFunction · 0.92
modelRegistrationPhaseFunction · 0.85
GetByIDMethod · 0.80
ListMethod · 0.65

Tested by

no test coverage detected