163 lines
4.2 KiB
Go
163 lines
4.2 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"cursor-api-proxy/pkg/infrastructure/env"
|
|
|
|
"github.com/zeromicro/go-zero/rest"
|
|
)
|
|
|
|
// Config for go-zero (generated by goctl)
|
|
type Config struct {
|
|
rest.RestConf
|
|
|
|
// Cursor 配置
|
|
AgentBin string
|
|
DefaultModel string
|
|
Provider string
|
|
TimeoutMs int
|
|
|
|
// 多帳號池
|
|
ConfigDirs []string
|
|
MultiPort bool
|
|
|
|
// TLS
|
|
TLSCertPath string
|
|
TLSKeyPath string
|
|
|
|
// 日誌
|
|
SessionsLogPath string
|
|
Verbose bool
|
|
|
|
// Gemini
|
|
GeminiAccountDir string
|
|
GeminiBrowserVisible bool
|
|
GeminiMaxSessions int
|
|
|
|
// 工作區
|
|
Workspace string
|
|
ChatOnlyWorkspace bool
|
|
WinCmdlineMax int
|
|
|
|
// Agent
|
|
Force bool
|
|
ApproveMcps bool
|
|
MaxMode bool
|
|
StrictModel bool
|
|
|
|
// API Key
|
|
RequiredKey string
|
|
}
|
|
|
|
// BridgeConfig for backward compatibility with existing code
|
|
type BridgeConfig struct {
|
|
AgentBin string
|
|
Host string
|
|
Port int
|
|
RequiredKey string
|
|
DefaultModel string
|
|
Mode string
|
|
Provider string
|
|
Force bool
|
|
ApproveMcps bool
|
|
StrictModel bool
|
|
Workspace string
|
|
TimeoutMs int
|
|
TLSCertPath string
|
|
TLSKeyPath string
|
|
SessionsLogPath string
|
|
ChatOnlyWorkspace bool
|
|
Verbose bool
|
|
MaxMode bool
|
|
ConfigDirs []string
|
|
MultiPort bool
|
|
WinCmdlineMax int
|
|
GeminiAccountDir string
|
|
GeminiBrowserVisible bool
|
|
GeminiMaxSessions int
|
|
}
|
|
|
|
// ToBridgeConfig converts Config to BridgeConfig
|
|
func (c Config) ToBridgeConfig() BridgeConfig {
|
|
home := os.Getenv("HOME")
|
|
if home == "" {
|
|
home = os.Getenv("USERPROFILE")
|
|
}
|
|
|
|
configDirs := c.ConfigDirs
|
|
if len(configDirs) == 0 {
|
|
configDirs = []string{filepath.Join(home, ".cursor-api-proxy", "accounts", "default")}
|
|
} else {
|
|
for i, dir := range configDirs {
|
|
if len(dir) > 0 && dir[0] == '~' {
|
|
configDirs[i] = filepath.Join(home, dir[1:])
|
|
}
|
|
}
|
|
}
|
|
|
|
geminiDir := c.GeminiAccountDir
|
|
if geminiDir != "" && geminiDir[0] == '~' {
|
|
geminiDir = filepath.Join(home, geminiDir[1:])
|
|
}
|
|
|
|
return BridgeConfig{
|
|
AgentBin: c.AgentBin,
|
|
Host: c.Host,
|
|
Port: c.Port,
|
|
RequiredKey: c.RequiredKey,
|
|
DefaultModel: c.DefaultModel,
|
|
Mode: "ask",
|
|
Provider: c.Provider,
|
|
Force: c.Force,
|
|
ApproveMcps: c.ApproveMcps,
|
|
StrictModel: c.StrictModel,
|
|
Workspace: c.Workspace,
|
|
TimeoutMs: c.TimeoutMs,
|
|
TLSCertPath: c.TLSCertPath,
|
|
TLSKeyPath: c.TLSKeyPath,
|
|
SessionsLogPath: c.SessionsLogPath,
|
|
ChatOnlyWorkspace: c.ChatOnlyWorkspace,
|
|
Verbose: c.Verbose,
|
|
MaxMode: c.MaxMode,
|
|
ConfigDirs: configDirs,
|
|
MultiPort: c.MultiPort,
|
|
WinCmdlineMax: c.WinCmdlineMax,
|
|
GeminiAccountDir: geminiDir,
|
|
GeminiBrowserVisible: c.GeminiBrowserVisible,
|
|
GeminiMaxSessions: c.GeminiMaxSessions,
|
|
}
|
|
}
|
|
|
|
// LoadBridgeConfig loads config from environment (for backward compatibility)
|
|
func LoadBridgeConfig(e env.EnvSource, cwd string) BridgeConfig {
|
|
loaded := env.LoadEnvConfig(e, cwd)
|
|
return BridgeConfig{
|
|
AgentBin: loaded.AgentBin,
|
|
Host: loaded.Host,
|
|
Port: loaded.Port,
|
|
RequiredKey: loaded.RequiredKey,
|
|
DefaultModel: loaded.DefaultModel,
|
|
Mode: "ask",
|
|
Provider: loaded.Provider,
|
|
Force: loaded.Force,
|
|
ApproveMcps: loaded.ApproveMcps,
|
|
StrictModel: loaded.StrictModel,
|
|
Workspace: loaded.Workspace,
|
|
TimeoutMs: loaded.TimeoutMs,
|
|
TLSCertPath: loaded.TLSCertPath,
|
|
TLSKeyPath: loaded.TLSKeyPath,
|
|
SessionsLogPath: loaded.SessionsLogPath,
|
|
ChatOnlyWorkspace: loaded.ChatOnlyWorkspace,
|
|
Verbose: loaded.Verbose,
|
|
MaxMode: loaded.MaxMode,
|
|
ConfigDirs: loaded.ConfigDirs,
|
|
MultiPort: loaded.MultiPort,
|
|
WinCmdlineMax: loaded.WinCmdlineMax,
|
|
GeminiAccountDir: loaded.GeminiAccountDir,
|
|
GeminiBrowserVisible: loaded.GeminiBrowserVisible,
|
|
GeminiMaxSessions: loaded.GeminiMaxSessions,
|
|
}
|
|
}
|