mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
feat(codex): add config toggle for codex instructions injection
This commit is contained in:
@@ -85,6 +85,10 @@ nonstream-keepalive-interval: 0
|
|||||||
# keepalive-seconds: 15 # Default: 0 (disabled). <= 0 disables keep-alives.
|
# keepalive-seconds: 15 # Default: 0 (disabled). <= 0 disables keep-alives.
|
||||||
# bootstrap-retries: 1 # Default: 0 (disabled). Retries before first byte is sent.
|
# bootstrap-retries: 1 # Default: 0 (disabled). Retries before first byte is sent.
|
||||||
|
|
||||||
|
# When true, enable custom Codex instructions injection for Codex API requests.
|
||||||
|
# When false (default), CodexInstructionsForModel returns immediately without modification.
|
||||||
|
codex-instructions-enabled: false
|
||||||
|
|
||||||
# Gemini API keys
|
# Gemini API keys
|
||||||
# gemini-api-key:
|
# gemini-api-key:
|
||||||
# - api-key: "AIzaSy...01"
|
# - api-key: "AIzaSy...01"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/logging"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/logging"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/managementasset"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/managementasset"
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/misc"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/usage"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/usage"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
||||||
sdkaccess "github.com/router-for-me/CLIProxyAPI/v6/sdk/access"
|
sdkaccess "github.com/router-for-me/CLIProxyAPI/v6/sdk/access"
|
||||||
@@ -254,6 +255,7 @@ func NewServer(cfg *config.Config, authManager *auth.Manager, accessManager *sdk
|
|||||||
}
|
}
|
||||||
managementasset.SetCurrentConfig(cfg)
|
managementasset.SetCurrentConfig(cfg)
|
||||||
auth.SetQuotaCooldownDisabled(cfg.DisableCooling)
|
auth.SetQuotaCooldownDisabled(cfg.DisableCooling)
|
||||||
|
misc.SetCodexInstructionsEnabled(cfg.CodexInstructionsEnabled)
|
||||||
// Initialize management handler
|
// Initialize management handler
|
||||||
s.mgmt = managementHandlers.NewHandler(cfg, configFilePath, authManager)
|
s.mgmt = managementHandlers.NewHandler(cfg, configFilePath, authManager)
|
||||||
if optionState.localPassword != "" {
|
if optionState.localPassword != "" {
|
||||||
@@ -912,6 +914,16 @@ func (s *Server) UpdateClients(cfg *config.Config) {
|
|||||||
log.Debugf("disable_cooling toggled to %t", cfg.DisableCooling)
|
log.Debugf("disable_cooling toggled to %t", cfg.DisableCooling)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if oldCfg == nil || oldCfg.CodexInstructionsEnabled != cfg.CodexInstructionsEnabled {
|
||||||
|
misc.SetCodexInstructionsEnabled(cfg.CodexInstructionsEnabled)
|
||||||
|
if oldCfg != nil {
|
||||||
|
log.Debugf("codex_instructions_enabled updated from %t to %t", oldCfg.CodexInstructionsEnabled, cfg.CodexInstructionsEnabled)
|
||||||
|
} else {
|
||||||
|
log.Debugf("codex_instructions_enabled toggled to %t", cfg.CodexInstructionsEnabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if s.handlers != nil && s.handlers.AuthManager != nil {
|
if s.handlers != nil && s.handlers.AuthManager != nil {
|
||||||
s.handlers.AuthManager.SetRetryConfig(cfg.RequestRetry, time.Duration(cfg.MaxRetryInterval)*time.Second)
|
s.handlers.AuthManager.SetRetryConfig(cfg.RequestRetry, time.Duration(cfg.MaxRetryInterval)*time.Second)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,11 @@ type Config struct {
|
|||||||
// WebsocketAuth enables or disables authentication for the WebSocket API.
|
// WebsocketAuth enables or disables authentication for the WebSocket API.
|
||||||
WebsocketAuth bool `yaml:"ws-auth" json:"ws-auth"`
|
WebsocketAuth bool `yaml:"ws-auth" json:"ws-auth"`
|
||||||
|
|
||||||
|
// CodexInstructionsEnabled controls whether custom Codex instructions are injected.
|
||||||
|
// When false (default), CodexInstructionsForModel returns immediately without modification.
|
||||||
|
// When true, the original instruction injection logic is used.
|
||||||
|
CodexInstructionsEnabled bool `yaml:"codex-instructions-enabled" json:"codex-instructions-enabled"`
|
||||||
|
|
||||||
// GeminiKey defines Gemini API key configurations with optional routing overrides.
|
// GeminiKey defines Gemini API key configurations with optional routing overrides.
|
||||||
GeminiKey []GeminiKey `yaml:"gemini-api-key" json:"gemini-api-key"`
|
GeminiKey []GeminiKey `yaml:"gemini-api-key" json:"gemini-api-key"`
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,27 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"github.com/tidwall/sjson"
|
"github.com/tidwall/sjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// codexInstructionsEnabled controls whether CodexInstructionsForModel returns custom instructions.
|
||||||
|
// When false (default), CodexInstructionsForModel returns (true, "") immediately.
|
||||||
|
// Set via SetCodexInstructionsEnabled from config.
|
||||||
|
var codexInstructionsEnabled atomic.Bool
|
||||||
|
|
||||||
|
// SetCodexInstructionsEnabled sets whether codex instructions processing is enabled.
|
||||||
|
func SetCodexInstructionsEnabled(enabled bool) {
|
||||||
|
codexInstructionsEnabled.Store(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCodexInstructionsEnabled returns whether codex instructions processing is enabled.
|
||||||
|
func GetCodexInstructionsEnabled() bool {
|
||||||
|
return codexInstructionsEnabled.Load()
|
||||||
|
}
|
||||||
|
|
||||||
//go:embed codex_instructions
|
//go:embed codex_instructions
|
||||||
var codexInstructionsDir embed.FS
|
var codexInstructionsDir embed.FS
|
||||||
|
|
||||||
@@ -124,6 +140,9 @@ func codexInstructionsForCodex(modelName, systemInstructions string) (bool, stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CodexInstructionsForModel(modelName, systemInstructions, userAgent string) (bool, string) {
|
func CodexInstructionsForModel(modelName, systemInstructions, userAgent string) (bool, string) {
|
||||||
|
if !GetCodexInstructionsEnabled() {
|
||||||
|
return true, ""
|
||||||
|
}
|
||||||
if IsOpenCodeUserAgent(userAgent) {
|
if IsOpenCodeUserAgent(userAgent) {
|
||||||
return codexInstructionsForOpenCode(systemInstructions)
|
return codexInstructionsForOpenCode(systemInstructions)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user