188 lines
7.7 KiB
Go
188 lines
7.7 KiB
Go
package tables
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// TableClientConfig represents global client configuration in the database
|
|
type TableClientConfig struct {
|
|
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
DropExcessRequests bool `gorm:"default:false" json:"drop_excess_requests"`
|
|
PrometheusLabelsJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
|
|
AllowedOriginsJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
|
|
AllowedHeadersJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
|
|
HeaderFilterConfigJSON string `gorm:"type:text" json:"-"` // JSON serialized GlobalHeaderFilterConfig
|
|
InitialPoolSize int `gorm:"default:300" json:"initial_pool_size"`
|
|
EnableLogging *bool `gorm:"default:true" json:"enable_logging"`
|
|
DisableContentLogging bool `gorm:"default:false" json:"disable_content_logging"` // DisableContentLogging controls whether sensitive content (inputs, outputs, embeddings, etc.) is logged
|
|
DisableDBPingsInHealth bool `gorm:"default:false" json:"disable_db_pings_in_health"`
|
|
LogRetentionDays int `gorm:"default:365" json:"log_retention_days" validate:"min=1"` // Number of days to retain logs (minimum 1 day)
|
|
EnforceAuthOnInference bool `gorm:"default:false" json:"enforce_auth_on_inference"`
|
|
EnforceGovernanceHeader bool `gorm:"" json:"enforce_governance_header"`
|
|
EnforceSCIMAuth bool `gorm:"default:false" json:"enforce_scim_auth"`
|
|
AllowDirectKeys bool `gorm:"" json:"allow_direct_keys"`
|
|
MaxRequestBodySizeMB int `gorm:"default:100" json:"max_request_body_size_mb"`
|
|
MCPAgentDepth int `gorm:"default:10" json:"mcp_agent_depth"`
|
|
MCPToolExecutionTimeout int `gorm:"default:30" json:"mcp_tool_execution_timeout"` // Timeout for individual tool execution in seconds (default: 30)
|
|
MCPCodeModeBindingLevel string `gorm:"default:server" json:"mcp_code_mode_binding_level"` // How tools are exposed in VFS: "server" or "tool"
|
|
MCPToolSyncInterval int `gorm:"default:10" json:"mcp_tool_sync_interval"` // Global tool sync interval in minutes (default: 10, 0 = disabled)
|
|
MCPDisableAutoToolInject bool `gorm:"default:false" json:"mcp_disable_auto_tool_inject"` // When true, MCP tools are not injected into requests by default
|
|
AsyncJobResultTTL int `gorm:"default:3600" json:"async_job_result_ttl"` // Default TTL for async job results in seconds (default: 3600 = 1 hour)
|
|
RequiredHeadersJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
|
|
LoggingHeadersJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
|
|
HideDeletedVirtualKeysInFilters bool `gorm:"default:false" json:"hide_deleted_virtual_keys_in_filters"` // Hide deleted virtual keys in logs filter dropdowns
|
|
RoutingChainMaxDepth int `gorm:"default:10" json:"routing_chain_max_depth"` // Maximum depth for routing rule chain evaluation (default: 10)
|
|
WhitelistedRoutesJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
|
|
|
|
// Compat plugin feature flags
|
|
CompatConvertTextToChat bool `gorm:"column:compat_convert_text_to_chat;default:false" json:"-"`
|
|
CompatConvertChatToResponses bool `gorm:"column:compat_convert_chat_to_responses;default:false" json:"-"`
|
|
CompatShouldDropParams bool `gorm:"column:compat_should_drop_params;default:false" json:"-"`
|
|
CompatShouldConvertParams bool `gorm:"column:compat_should_convert_params;default:false" json:"-"`
|
|
|
|
// Config hash is used to detect the changes synced from config.json file
|
|
// Every time we sync the config.json file, we will update the config hash
|
|
ConfigHash string `gorm:"type:varchar(255);null" json:"config_hash"`
|
|
|
|
CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"index;not null" json:"updated_at"`
|
|
|
|
// Virtual fields for runtime use (not stored in DB)
|
|
PrometheusLabels []string `gorm:"-" json:"prometheus_labels"`
|
|
AllowedOrigins []string `gorm:"-" json:"allowed_origins,omitempty"`
|
|
AllowedHeaders []string `gorm:"-" json:"allowed_headers,omitempty"`
|
|
RequiredHeaders []string `gorm:"-" json:"required_headers,omitempty"`
|
|
LoggingHeaders []string `gorm:"-" json:"logging_headers,omitempty"`
|
|
WhitelistedRoutes []string `gorm:"-" json:"whitelisted_routes,omitempty"`
|
|
HeaderFilterConfig *GlobalHeaderFilterConfig `gorm:"-" json:"header_filter_config,omitempty"`
|
|
}
|
|
|
|
// TableName sets the table name for each model
|
|
func (TableClientConfig) TableName() string { return "config_client" }
|
|
|
|
func (cc *TableClientConfig) BeforeSave(tx *gorm.DB) error {
|
|
if cc.PrometheusLabels != nil {
|
|
data, err := json.Marshal(cc.PrometheusLabels)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cc.PrometheusLabelsJSON = string(data)
|
|
} else {
|
|
cc.PrometheusLabelsJSON = "[]"
|
|
}
|
|
|
|
if cc.AllowedOrigins != nil {
|
|
data, err := json.Marshal(cc.AllowedOrigins)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cc.AllowedOriginsJSON = string(data)
|
|
} else {
|
|
cc.AllowedOriginsJSON = "[]"
|
|
}
|
|
|
|
if cc.AllowedHeaders != nil {
|
|
data, err := json.Marshal(cc.AllowedHeaders)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cc.AllowedHeadersJSON = string(data)
|
|
} else {
|
|
cc.AllowedHeadersJSON = "[]"
|
|
}
|
|
|
|
if cc.WhitelistedRoutes != nil {
|
|
data, err := json.Marshal(cc.WhitelistedRoutes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cc.WhitelistedRoutesJSON = string(data)
|
|
} else {
|
|
cc.WhitelistedRoutesJSON = "[]"
|
|
}
|
|
|
|
if cc.RequiredHeaders != nil {
|
|
data, err := json.Marshal(cc.RequiredHeaders)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cc.RequiredHeadersJSON = string(data)
|
|
} else {
|
|
cc.RequiredHeadersJSON = "[]"
|
|
}
|
|
|
|
if cc.LoggingHeaders != nil {
|
|
data, err := json.Marshal(cc.LoggingHeaders)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cc.LoggingHeadersJSON = string(data)
|
|
} else {
|
|
cc.LoggingHeadersJSON = "[]"
|
|
}
|
|
|
|
if cc.HeaderFilterConfig != nil {
|
|
data, err := json.Marshal(cc.HeaderFilterConfig)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cc.HeaderFilterConfigJSON = string(data)
|
|
} else {
|
|
cc.HeaderFilterConfigJSON = ""
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// AfterFind hooks for deserialization
|
|
func (cc *TableClientConfig) AfterFind(tx *gorm.DB) error {
|
|
if cc.PrometheusLabelsJSON != "" {
|
|
if err := json.Unmarshal([]byte(cc.PrometheusLabelsJSON), &cc.PrometheusLabels); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if cc.AllowedOriginsJSON != "" {
|
|
if err := json.Unmarshal([]byte(cc.AllowedOriginsJSON), &cc.AllowedOrigins); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if cc.AllowedHeadersJSON != "" {
|
|
if err := json.Unmarshal([]byte(cc.AllowedHeadersJSON), &cc.AllowedHeaders); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if cc.WhitelistedRoutesJSON != "" {
|
|
if err := json.Unmarshal([]byte(cc.WhitelistedRoutesJSON), &cc.WhitelistedRoutes); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if cc.RequiredHeadersJSON != "" {
|
|
if err := json.Unmarshal([]byte(cc.RequiredHeadersJSON), &cc.RequiredHeaders); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if cc.LoggingHeadersJSON != "" {
|
|
if err := json.Unmarshal([]byte(cc.LoggingHeadersJSON), &cc.LoggingHeaders); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if cc.HeaderFilterConfigJSON != "" {
|
|
var headerFilterConfig GlobalHeaderFilterConfig
|
|
if err := json.Unmarshal([]byte(cc.HeaderFilterConfigJSON), &headerFilterConfig); err != nil {
|
|
return err
|
|
}
|
|
cc.HeaderFilterConfig = &headerFilterConfig
|
|
}
|
|
|
|
return nil
|
|
}
|