mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-22 06:57:37 +08:00
feat(cliproxy): add unregisterOpenAICompatExecutor and sync runtime configuration
- Implemented `unregisterOpenAICompatExecutor` to remove OpenAI-compatible executors dynamically. - Updated `ensureExecutorsForAuth` to unregister incompatible executors while handling plugin candidates. - Adjusted runtime configuration logic to ensure proper synchronization during updates with `syncPluginModelRuntime`.
This commit is contained in:
@@ -852,6 +852,24 @@ func (s *Service) hasNativeOpenAICompatExecutorConfig(a *coreauth.Auth, provider
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Service) unregisterOpenAICompatExecutor(providerKey string) {
|
||||
if s == nil || s.coreManager == nil {
|
||||
return
|
||||
}
|
||||
providerKey = strings.ToLower(strings.TrimSpace(providerKey))
|
||||
if providerKey == "" {
|
||||
return
|
||||
}
|
||||
existing, okExecutor := s.coreManager.Executor(providerKey)
|
||||
if !okExecutor || existing == nil {
|
||||
return
|
||||
}
|
||||
if _, okOpenAICompat := existing.(*executor.OpenAICompatExecutor); !okOpenAICompat {
|
||||
return
|
||||
}
|
||||
s.coreManager.UnregisterExecutor(providerKey)
|
||||
}
|
||||
|
||||
func (s *Service) ensureExecutorsForAuth(a *coreauth.Auth) {
|
||||
s.ensureExecutorsForAuthWithMode(a, false)
|
||||
}
|
||||
@@ -984,6 +1002,7 @@ func (s *Service) registerExecutorForAuth(a *coreauth.Auth, forceReplace bool) {
|
||||
if s.pluginHost != nil &&
|
||||
s.pluginHost.HasExecutorCandidateProvider(providerKey) &&
|
||||
!s.hasNativeOpenAICompatExecutorConfig(a, providerKey) {
|
||||
s.unregisterOpenAICompatExecutor(providerKey)
|
||||
return
|
||||
}
|
||||
s.coreManager.RegisterExecutor(executor.NewOpenAICompatExecutor(providerKey, s.cfg))
|
||||
@@ -1223,6 +1242,8 @@ func (s *Service) applyConfigUpdateWithAuthSynthesis(newCfg *config.Config, synt
|
||||
s.coreManager.SetConfig(newCfg)
|
||||
s.coreManager.SetOAuthModelAlias(newCfg.OAuthModelAlias)
|
||||
}
|
||||
ctx := coreauth.WithSkipPersist(context.Background())
|
||||
s.syncPluginRuntimeConfig(ctx)
|
||||
var auths []*coreauth.Auth
|
||||
if s.coreManager != nil {
|
||||
auths = s.coreManager.List()
|
||||
@@ -1232,7 +1253,6 @@ func (s *Service) applyConfigUpdateWithAuthSynthesis(newCfg *config.Config, synt
|
||||
forceReplaceAuths: true,
|
||||
auths: auths,
|
||||
})
|
||||
ctx := coreauth.WithSkipPersist(context.Background())
|
||||
if synthesizeConfigAuths {
|
||||
s.registerConfigAPIKeyAuths(ctx, newCfg)
|
||||
}
|
||||
@@ -1241,7 +1261,7 @@ func (s *Service) applyConfigUpdateWithAuthSynthesis(newCfg *config.Config, synt
|
||||
log.Warnf("failed to restore cooldown state after config update: %v", errRestoreCooldown)
|
||||
}
|
||||
}
|
||||
s.syncPluginRuntime(ctx)
|
||||
s.syncPluginModelRuntime(ctx)
|
||||
}
|
||||
|
||||
func (s *Service) reloadConfigFromWatcher() bool {
|
||||
|
||||
Reference in New Issue
Block a user