From babef2a1ef5a7c04d855e12e77e03da8540b09b7 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Sun, 21 Jun 2026 11:21:05 +0800 Subject: [PATCH] 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`. --- sdk/cliproxy/service.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index 720ec13b2..6f2d99673 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -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 {