mirror of
https://github.com/githubhjs/CLIProxyAPIPlus.git
synced 2026-07-14 10:35:24 +00:00
refactor(api): remove unused OpenAI compatibility provider logic
Simplify handler logic by removing OpenAI compatibility provider management, including related mutex handling and configuration updates.
This commit is contained in:
@@ -934,12 +934,6 @@ func (s *Server) UpdateClients(cfg *config.Config) {
|
|||||||
// Save YAML snapshot for next comparison
|
// Save YAML snapshot for next comparison
|
||||||
s.oldConfigYaml, _ = yaml.Marshal(cfg)
|
s.oldConfigYaml, _ = yaml.Marshal(cfg)
|
||||||
|
|
||||||
providerNames := make([]string, 0, len(cfg.OpenAICompatibility))
|
|
||||||
for _, p := range cfg.OpenAICompatibility {
|
|
||||||
providerNames = append(providerNames, p.Name)
|
|
||||||
}
|
|
||||||
s.handlers.SetOpenAICompatProviders(providerNames)
|
|
||||||
|
|
||||||
s.handlers.UpdateClients(&cfg.SDKConfig)
|
s.handlers.UpdateClients(&cfg.SDKConfig)
|
||||||
|
|
||||||
if !cfg.RemoteManagement.DisableControlPanel {
|
if !cfg.RemoteManagement.DisableControlPanel {
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
|
||||||
kiroauth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/kiro"
|
kiroauth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/kiro"
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/geminicli"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/geminicli"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/watcher/diff"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/watcher/diff"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -765,7 +765,7 @@ func (w *Watcher) handleKiroIDETokenChange(event fsnotify.Event) {
|
|||||||
log.Infof("Kiro IDE token file updated, access token refreshed (provider: %s)", tokenData.Provider)
|
log.Infof("Kiro IDE token file updated, access token refreshed (provider: %s)", tokenData.Provider)
|
||||||
|
|
||||||
// Trigger auth state refresh to pick up the new token
|
// Trigger auth state refresh to pick up the new token
|
||||||
w.refreshAuthState()
|
w.refreshAuthState(true)
|
||||||
|
|
||||||
// Notify callback if set
|
// Notify callback if set
|
||||||
w.clientsMutex.RLock()
|
w.clientsMutex.RLock()
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
|
||||||
@@ -50,27 +49,6 @@ type BaseAPIHandler struct {
|
|||||||
|
|
||||||
// Cfg holds the current application configuration.
|
// Cfg holds the current application configuration.
|
||||||
Cfg *config.SDKConfig
|
Cfg *config.SDKConfig
|
||||||
|
|
||||||
// OpenAICompatProviders is a list of provider names for OpenAI compatibility.
|
|
||||||
openAICompatProviders []string
|
|
||||||
openAICompatMutex sync.RWMutex
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOpenAICompatProviders safely returns a copy of the provider names
|
|
||||||
func (h *BaseAPIHandler) GetOpenAICompatProviders() []string {
|
|
||||||
h.openAICompatMutex.RLock()
|
|
||||||
defer h.openAICompatMutex.RUnlock()
|
|
||||||
result := make([]string, len(h.openAICompatProviders))
|
|
||||||
copy(result, h.openAICompatProviders)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOpenAICompatProviders safely sets the provider names
|
|
||||||
func (h *BaseAPIHandler) SetOpenAICompatProviders(providers []string) {
|
|
||||||
h.openAICompatMutex.Lock()
|
|
||||||
defer h.openAICompatMutex.Unlock()
|
|
||||||
h.openAICompatProviders = make([]string, len(providers))
|
|
||||||
copy(h.openAICompatProviders, providers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBaseAPIHandlers creates a new API handlers instance.
|
// NewBaseAPIHandlers creates a new API handlers instance.
|
||||||
@@ -82,12 +60,11 @@ func (h *BaseAPIHandler) SetOpenAICompatProviders(providers []string) {
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - *BaseAPIHandler: A new API handlers instance
|
// - *BaseAPIHandler: A new API handlers instance
|
||||||
func NewBaseAPIHandlers(cfg *config.SDKConfig, authManager *coreauth.Manager, openAICompatProviders []string) *BaseAPIHandler {
|
func NewBaseAPIHandlers(cfg *config.SDKConfig, authManager *coreauth.Manager) *BaseAPIHandler {
|
||||||
h := &BaseAPIHandler{
|
h := &BaseAPIHandler{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
AuthManager: authManager,
|
AuthManager: authManager,
|
||||||
}
|
}
|
||||||
h.SetOpenAICompatProviders(openAICompatProviders)
|
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,30 +369,6 @@ func (h *BaseAPIHandler) getRequestDetails(modelName string) (providers []string
|
|||||||
return providers, normalizedModel, metadata, nil
|
return providers, normalizedModel, metadata, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *BaseAPIHandler) parseDynamicModel(modelName string) (providerName, model string, isDynamic bool) {
|
|
||||||
var providerPart, modelPart string
|
|
||||||
for _, sep := range []string{"://"} {
|
|
||||||
if parts := strings.SplitN(modelName, sep, 2); len(parts) == 2 {
|
|
||||||
providerPart = parts[0]
|
|
||||||
modelPart = parts[1]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if providerPart == "" {
|
|
||||||
return "", modelName, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the provider is a configured openai-compatibility provider
|
|
||||||
for _, pName := range h.GetOpenAICompatProviders() {
|
|
||||||
if pName == providerPart {
|
|
||||||
return providerPart, modelPart, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", modelName, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func cloneBytes(src []byte) []byte {
|
func cloneBytes(src []byte) []byte {
|
||||||
if len(src) == 0 {
|
if len(src) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user