Skip to content

Commit 344066f

Browse files
committed
refactor(api): remove unused OpenAI compatibility provider logic
Simplify handler logic by removing OpenAI compatibility provider management, including related mutex handling and configuration updates.
1 parent bcb8092 commit 344066f

File tree

3 files changed

+11
-64
lines changed

3 files changed

+11
-64
lines changed

internal/api/server.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,6 @@ func (s *Server) UpdateClients(cfg *config.Config) {
934934
// Save YAML snapshot for next comparison
935935
s.oldConfigYaml, _ = yaml.Marshal(cfg)
936936

937-
providerNames := make([]string, 0, len(cfg.OpenAICompatibility))
938-
for _, p := range cfg.OpenAICompatibility {
939-
providerNames = append(providerNames, p.Name)
940-
}
941-
s.handlers.SetOpenAICompatProviders(providerNames)
942-
943937
s.handlers.UpdateClients(&cfg.SDKConfig)
944938

945939
if !cfg.RemoteManagement.DisableControlPanel {

internal/watcher/watcher.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"time"
2222

2323
"github.com/fsnotify/fsnotify"
24-
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
2524
kiroauth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/kiro"
25+
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
2626
"github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/geminicli"
2727
"github.com/router-for-me/CLIProxyAPI/v6/internal/watcher/diff"
2828
"gopkg.in/yaml.v3"
@@ -203,7 +203,7 @@ func (w *Watcher) watchKiroIDETokenFile() {
203203

204204
// Kiro IDE stores tokens in ~/.aws/sso/cache/
205205
kiroTokenDir := filepath.Join(homeDir, ".aws", "sso", "cache")
206-
206+
207207
// Check if directory exists
208208
if _, statErr := os.Stat(kiroTokenDir); os.IsNotExist(statErr) {
209209
log.Debugf("Kiro IDE token directory does not exist: %s", kiroTokenDir)
@@ -657,16 +657,16 @@ func (w *Watcher) handleEvent(event fsnotify.Event) {
657657
normalizedAuthDir := w.normalizeAuthPath(w.authDir)
658658
isConfigEvent := normalizedName == normalizedConfigPath && event.Op&configOps != 0
659659
authOps := fsnotify.Create | fsnotify.Write | fsnotify.Remove | fsnotify.Rename
660-
isAuthJSON := strings.HasPrefix(normalizedName, normalizedAuthDir) && strings.HasSuffix(normalizedName, ".json") && event.Op&authOps != 0
661-
660+
isAuthJSON := strings.HasPrefix(normalizedName, normalizedAuthDir) && strings.HasSuffix(normalizedName, ".json") && event.Op&authOps != 0
661+
662662
// Check for Kiro IDE token file changes
663663
isKiroIDEToken := w.isKiroIDETokenFile(event.Name) && event.Op&authOps != 0
664-
664+
665665
if !isConfigEvent && !isAuthJSON && !isKiroIDEToken {
666666
// Ignore unrelated files (e.g., cookie snapshots *.cookie) and other noise.
667667
return
668668
}
669-
669+
670670
// Handle Kiro IDE token file changes
671671
if isKiroIDEToken {
672672
w.handleKiroIDETokenChange(event)
@@ -765,7 +765,7 @@ func (w *Watcher) handleKiroIDETokenChange(event fsnotify.Event) {
765765
log.Infof("Kiro IDE token file updated, access token refreshed (provider: %s)", tokenData.Provider)
766766

767767
// Trigger auth state refresh to pick up the new token
768-
w.refreshAuthState()
768+
w.refreshAuthState(true)
769769

770770
// Notify callback if set
771771
w.clientsMutex.RLock()
@@ -1381,15 +1381,15 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
13811381
continue
13821382
}
13831383
t, _ := metadata["type"].(string)
1384-
1384+
13851385
// Detect Kiro auth files by auth_method field (they don't have "type" field)
13861386
if t == "" {
13871387
if authMethod, _ := metadata["auth_method"].(string); authMethod == "builder-id" || authMethod == "social" {
13881388
t = "kiro"
13891389
log.Debugf("SnapshotCoreAuths: detected Kiro auth by auth_method: %s", name)
13901390
}
13911391
}
1392-
1392+
13931393
if t == "" {
13941394
log.Debugf("SnapshotCoreAuths: skipping file without type: %s", name)
13951395
continue
@@ -1452,7 +1452,7 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
14521452
a.NextRefreshAfter = expiresAt.Add(-30 * time.Minute)
14531453
}
14541454
}
1455-
1455+
14561456
// Apply global preferred endpoint setting if not present in metadata
14571457
if cfg.KiroPreferredEndpoint != "" {
14581458
// Check if already set in metadata (which takes precedence in executor)

sdk/api/handlers/handlers.go

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"net/http"
1111
"strings"
12-
"sync"
1312

1413
"github.com/gin-gonic/gin"
1514
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
@@ -50,27 +49,6 @@ type BaseAPIHandler struct {
5049

5150
// Cfg holds the current application configuration.
5251
Cfg *config.SDKConfig
53-
54-
// OpenAICompatProviders is a list of provider names for OpenAI compatibility.
55-
openAICompatProviders []string
56-
openAICompatMutex sync.RWMutex
57-
}
58-
59-
// GetOpenAICompatProviders safely returns a copy of the provider names
60-
func (h *BaseAPIHandler) GetOpenAICompatProviders() []string {
61-
h.openAICompatMutex.RLock()
62-
defer h.openAICompatMutex.RUnlock()
63-
result := make([]string, len(h.openAICompatProviders))
64-
copy(result, h.openAICompatProviders)
65-
return result
66-
}
67-
68-
// SetOpenAICompatProviders safely sets the provider names
69-
func (h *BaseAPIHandler) SetOpenAICompatProviders(providers []string) {
70-
h.openAICompatMutex.Lock()
71-
defer h.openAICompatMutex.Unlock()
72-
h.openAICompatProviders = make([]string, len(providers))
73-
copy(h.openAICompatProviders, providers)
7452
}
7553

7654
// NewBaseAPIHandlers creates a new API handlers instance.
@@ -82,12 +60,11 @@ func (h *BaseAPIHandler) SetOpenAICompatProviders(providers []string) {
8260
//
8361
// Returns:
8462
// - *BaseAPIHandler: A new API handlers instance
85-
func NewBaseAPIHandlers(cfg *config.SDKConfig, authManager *coreauth.Manager, openAICompatProviders []string) *BaseAPIHandler {
63+
func NewBaseAPIHandlers(cfg *config.SDKConfig, authManager *coreauth.Manager) *BaseAPIHandler {
8664
h := &BaseAPIHandler{
8765
Cfg: cfg,
8866
AuthManager: authManager,
8967
}
90-
h.SetOpenAICompatProviders(openAICompatProviders)
9168
return h
9269
}
9370

@@ -392,30 +369,6 @@ func (h *BaseAPIHandler) getRequestDetails(modelName string) (providers []string
392369
return providers, normalizedModel, metadata, nil
393370
}
394371

395-
func (h *BaseAPIHandler) parseDynamicModel(modelName string) (providerName, model string, isDynamic bool) {
396-
var providerPart, modelPart string
397-
for _, sep := range []string{"://"} {
398-
if parts := strings.SplitN(modelName, sep, 2); len(parts) == 2 {
399-
providerPart = parts[0]
400-
modelPart = parts[1]
401-
break
402-
}
403-
}
404-
405-
if providerPart == "" {
406-
return "", modelName, false
407-
}
408-
409-
// Check if the provider is a configured openai-compatibility provider
410-
for _, pName := range h.GetOpenAICompatProviders() {
411-
if pName == providerPart {
412-
return providerPart, modelPart, true
413-
}
414-
}
415-
416-
return "", modelName, false
417-
}
418-
419372
func cloneBytes(src []byte) []byte {
420373
if len(src) == 0 {
421374
return nil

0 commit comments

Comments
 (0)