Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 57 additions & 56 deletions internal/config/types.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

type Config struct {
Server ServerConfig `yaml:"server"`
Endpoints []EndpointConfig `yaml:"endpoints"`
Logging LoggingConfig `yaml:"logging"`
Validation ValidationConfig `yaml:"validation"`
Tagging TaggingConfig `yaml:"tagging"` // 标签系统配置(永远启用)
Timeouts TimeoutConfig `yaml:"timeouts"` // 超时配置
I18n I18nConfig `yaml:"i18n"` // 国际化配置
Server ServerConfig `yaml:"server"`
Endpoints []EndpointConfig `yaml:"endpoints"`
Logging LoggingConfig `yaml:"logging"`
Validation ValidationConfig `yaml:"validation"`
Tagging TaggingConfig `yaml:"tagging"` // 标签系统配置(永远启用)
Timeouts TimeoutConfig `yaml:"timeouts"` // 超时配置
I18n I18nConfig `yaml:"i18n"` // 国际化配置
}

// I18nConfig 国际化配置
Expand All @@ -23,43 +23,44 @@ type ServerConfig struct {
}

type EndpointConfig struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
EndpointType string `yaml:"endpoint_type"` // "anthropic" | "openai" 等
PathPrefix string `yaml:"path_prefix,omitempty"` // OpenAI端点的路径前缀,如 "/v1/chat/completions"
AuthType string `yaml:"auth_type"`
AuthValue string `yaml:"auth_value"`
Enabled bool `yaml:"enabled"`
Priority int `yaml:"priority"`
Tags []string `yaml:"tags"` // 新增:支持的tag列表
ModelRewrite *ModelRewriteConfig `yaml:"model_rewrite,omitempty"` // 新增:模型重写配置
Proxy *ProxyConfig `yaml:"proxy,omitempty"` // 新增:代理配置
OAuthConfig *OAuthConfig `yaml:"oauth_config,omitempty"` // 新增:OAuth配置
HeaderOverrides map[string]string `yaml:"header_overrides,omitempty" json:"header_overrides,omitempty"` // 新增:HTTP Header覆盖配置
ParameterOverrides map[string]string `yaml:"parameter_overrides,omitempty" json:"parameter_overrides,omitempty"` // 新增:Request Parameters覆盖配置
MaxTokensFieldName string `yaml:"max_tokens_field_name,omitempty" json:"max_tokens_field_name,omitempty"` // max_tokens 参数名转换选项
RateLimitReset *int64 `yaml:"rate_limit_reset,omitempty" json:"rate_limit_reset,omitempty"` // Anthropic-Ratelimit-Unified-Reset
RateLimitStatus *string `yaml:"rate_limit_status,omitempty" json:"rate_limit_status,omitempty"` // Anthropic-Ratelimit-Unified-Status
EnhancedProtection bool `yaml:"enhanced_protection,omitempty" json:"enhanced_protection,omitempty"` // 官方帐号增强保护:allowed_warning时即禁用端点
Name string `yaml:"name"`
URL string `yaml:"url"`
EndpointType string `yaml:"endpoint_type"` // "anthropic" | "openai" 等
PathPrefix string `yaml:"path_prefix,omitempty"` // OpenAI端点的路径前缀,如 "/v1/chat/completions"
AuthType string `yaml:"auth_type"`
AuthValue string `yaml:"auth_value"`
Enabled bool `yaml:"enabled"`
Priority int `yaml:"priority"`
Tags []string `yaml:"tags"` // 新增:支持的tag列表
ModelAlias string `yaml:"model_alias,omitempty" json:"model_alias,omitempty"`
ModelRewrite *ModelRewriteConfig `yaml:"model_rewrite,omitempty"` // 新增:模型重写配置
Proxy *ProxyConfig `yaml:"proxy,omitempty"` // 新增:代理配置
OAuthConfig *OAuthConfig `yaml:"oauth_config,omitempty"` // 新增:OAuth配置
HeaderOverrides map[string]string `yaml:"header_overrides,omitempty" json:"header_overrides,omitempty"` // 新增:HTTP Header覆盖配置
ParameterOverrides map[string]string `yaml:"parameter_overrides,omitempty" json:"parameter_overrides,omitempty"` // 新增:Request Parameters覆盖配置
MaxTokensFieldName string `yaml:"max_tokens_field_name,omitempty" json:"max_tokens_field_name,omitempty"` // max_tokens 参数名转换选项
RateLimitReset *int64 `yaml:"rate_limit_reset,omitempty" json:"rate_limit_reset,omitempty"` // Anthropic-Ratelimit-Unified-Reset
RateLimitStatus *string `yaml:"rate_limit_status,omitempty" json:"rate_limit_status,omitempty"` // Anthropic-Ratelimit-Unified-Status
EnhancedProtection bool `yaml:"enhanced_protection,omitempty" json:"enhanced_protection,omitempty"` // 官方帐号增强保护:allowed_warning时即禁用端点
}

// 新增:代理配置结构
type ProxyConfig struct {
Type string `yaml:"type" json:"type"` // "http" | "socks5"
Address string `yaml:"address" json:"address"` // 代理服务器地址,如 "127.0.0.1:1080"
Type string `yaml:"type" json:"type"` // "http" | "socks5"
Address string `yaml:"address" json:"address"` // 代理服务器地址,如 "127.0.0.1:1080"
Username string `yaml:"username,omitempty" json:"username,omitempty"` // 代理认证用户名(可选)
Password string `yaml:"password,omitempty" json:"password,omitempty"` // 代理认证密码(可选)
}

// 新增:OAuth 配置结构
type OAuthConfig struct {
AccessToken string `yaml:"access_token" json:"access_token"` // 访问令牌
RefreshToken string `yaml:"refresh_token" json:"refresh_token"` // 刷新令牌
ExpiresAt int64 `yaml:"expires_at" json:"expires_at"` // 过期时间戳(毫秒)
TokenURL string `yaml:"token_url" json:"token_url"` // Token刷新URL(必填)
ClientID string `yaml:"client_id,omitempty" json:"client_id,omitempty"` // 客户端ID
Scopes []string `yaml:"scopes,omitempty" json:"scopes,omitempty"` // 权限范围
AutoRefresh bool `yaml:"auto_refresh" json:"auto_refresh"` // 是否自动刷新
AccessToken string `yaml:"access_token" json:"access_token"` // 访问令牌
RefreshToken string `yaml:"refresh_token" json:"refresh_token"` // 刷新令牌
ExpiresAt int64 `yaml:"expires_at" json:"expires_at"` // 过期时间戳(毫秒)
TokenURL string `yaml:"token_url" json:"token_url"` // Token刷新URL(必填)
ClientID string `yaml:"client_id,omitempty" json:"client_id,omitempty"` // 客户端ID
Scopes []string `yaml:"scopes,omitempty" json:"scopes,omitempty"` // 权限范围
AutoRefresh bool `yaml:"auto_refresh" json:"auto_refresh"` // 是否自动刷新
}

// 新增:模型重写配置结构
Expand All @@ -83,23 +84,23 @@ type LoggingConfig struct {
}

type ValidationConfig struct {
PythonJSONFixing PythonJSONFixingConfig `yaml:"python_json_fixing"`
PythonJSONFixing PythonJSONFixingConfig `yaml:"python_json_fixing"`
}

// PythonJSONFixing 配置结构
type PythonJSONFixingConfig struct {
Enabled bool `yaml:"enabled" json:"enabled"` // 是否启用 Python JSON 修复
TargetTools []string `yaml:"target_tools" json:"target_tools"` // 需要修复的工具列表
DebugLogging bool `yaml:"debug_logging" json:"debug_logging"` // 是否启用调试日志
MaxAttempts int `yaml:"max_attempts" json:"max_attempts"` // 最大修复尝试次数
Enabled bool `yaml:"enabled" json:"enabled"` // 是否启用 Python JSON 修复
TargetTools []string `yaml:"target_tools" json:"target_tools"` // 需要修复的工具列表
DebugLogging bool `yaml:"debug_logging" json:"debug_logging"` // 是否启用调试日志
MaxAttempts int `yaml:"max_attempts" json:"max_attempts"` // 最大修复尝试次数
}

// 新增:超时配置结构
type TimeoutConfig struct {
// 网络超时设置(代理和健康检查共用)
TLSHandshake string `yaml:"tls_handshake" json:"tls_handshake"` // TLS握手超时,默认10s
ResponseHeader string `yaml:"response_header" json:"response_header"` // 响应头超时,默认60s
IdleConnection string `yaml:"idle_connection" json:"idle_connection"` // 空闲连接超时,默认90s
TLSHandshake string `yaml:"tls_handshake" json:"tls_handshake"` // TLS握手超时,默认10s
ResponseHeader string `yaml:"response_header" json:"response_header"` // 响应头超时,默认60s
IdleConnection string `yaml:"idle_connection" json:"idle_connection"` // 空闲连接超时,默认90s
// 健康检查特有配置
HealthCheckTimeout string `yaml:"health_check_timeout" json:"health_check_timeout"` // 健康检查整体响应超时,默认30s
CheckInterval string `yaml:"check_interval" json:"check_interval"` // 健康检查间隔,默认30s
Expand All @@ -108,19 +109,19 @@ type TimeoutConfig struct {

// 代理客户端超时配置(内部使用,从TimeoutConfig转换)
type ProxyTimeoutConfig struct {
TLSHandshake string `yaml:"tls_handshake" json:"tls_handshake"`
ResponseHeader string `yaml:"response_header" json:"response_header"`
IdleConnection string `yaml:"idle_connection" json:"idle_connection"`
OverallRequest string `yaml:"overall_request" json:"overall_request"` // 保持为空,无限制
TLSHandshake string `yaml:"tls_handshake" json:"tls_handshake"`
ResponseHeader string `yaml:"response_header" json:"response_header"`
IdleConnection string `yaml:"idle_connection" json:"idle_connection"`
OverallRequest string `yaml:"overall_request" json:"overall_request"` // 保持为空,无限制
}

// 健康检查超时配置(内部使用,从TimeoutConfig转换)
type HealthCheckTimeoutConfig struct {
TLSHandshake string `yaml:"tls_handshake" json:"tls_handshake"`
ResponseHeader string `yaml:"response_header" json:"response_header"`
IdleConnection string `yaml:"idle_connection" json:"idle_connection"`
OverallRequest string `yaml:"overall_request" json:"overall_request"`
CheckInterval string `yaml:"check_interval" json:"check_interval"`
TLSHandshake string `yaml:"tls_handshake" json:"tls_handshake"`
ResponseHeader string `yaml:"response_header" json:"response_header"`
IdleConnection string `yaml:"idle_connection" json:"idle_connection"`
OverallRequest string `yaml:"overall_request" json:"overall_request"`
CheckInterval string `yaml:"check_interval" json:"check_interval"`
RecoveryThreshold int `yaml:"recovery_threshold" json:"recovery_threshold"`
}

Expand Down Expand Up @@ -148,8 +149,8 @@ func (tc *TimeoutConfig) ToHealthCheckTimeoutConfig() HealthCheckTimeoutConfig {

// Tag系统配置结构 (永远启用)
type TaggingConfig struct {
PipelineTimeout string `yaml:"pipeline_timeout"`
Taggers []TaggerConfig `yaml:"taggers"`
PipelineTimeout string `yaml:"pipeline_timeout"`
Taggers []TaggerConfig `yaml:"taggers"`
}

type TaggerConfig struct {
Expand All @@ -158,6 +159,6 @@ type TaggerConfig struct {
BuiltinType string `yaml:"builtin_type"` // 内置类型: "path" | "header" | "body-json" | "method" | "query"
Tag string `yaml:"tag"` // 标记的tag名称
Enabled bool `yaml:"enabled"`
Priority int `yaml:"priority"` // 执行优先级(未使用,因为并发执行)
Config map[string]interface{} `yaml:"config"` // tagger特定配置
}
Priority int `yaml:"priority"` // 执行优先级(未使用,因为并发执行)
Config map[string]interface{} `yaml:"config"` // tagger特定配置
}
Loading