add oidc
This commit is contained in:
+115
-18
@@ -20,6 +20,7 @@ type Config struct {
|
||||
Server *ServerConfig `yaml:"server" json:"server"`
|
||||
KnowledgeBase *KnowledgeBaseConfig `yaml:"knowledge_base" json:"knowledge_base"`
|
||||
Tenant *TenantConfig `yaml:"tenant" json:"tenant"`
|
||||
OIDCAuth *OIDCAuthConfig `yaml:"oidc_auth" json:"oidc_auth"`
|
||||
Models []ModelConfig `yaml:"models" json:"models"`
|
||||
VectorDatabase *VectorDatabaseConfig `yaml:"vector_database" json:"vector_database"`
|
||||
DocReader *DocReaderConfig `yaml:"docreader" json:"docreader"`
|
||||
@@ -85,13 +86,13 @@ type ConversationConfig struct {
|
||||
Summary *SummaryConfig `yaml:"summary" json:"summary"`
|
||||
|
||||
// Prompt template ID fields — resolved to text by backfillConversationDefaults
|
||||
FallbackPromptID string `yaml:"fallback_prompt_id" json:"fallback_prompt_id"`
|
||||
RewritePromptID string `yaml:"rewrite_prompt_id" json:"rewrite_prompt_id"`
|
||||
GenerateSessionTitlePromptID string `yaml:"generate_session_title_prompt_id" json:"generate_session_title_prompt_id"`
|
||||
GenerateSummaryPromptID string `yaml:"generate_summary_prompt_id" json:"generate_summary_prompt_id"`
|
||||
ExtractEntitiesPromptID string `yaml:"extract_entities_prompt_id" json:"extract_entities_prompt_id"`
|
||||
ExtractRelationshipsPromptID string `yaml:"extract_relationships_prompt_id" json:"extract_relationships_prompt_id"`
|
||||
GenerateQuestionsPromptID string `yaml:"generate_questions_prompt_id" json:"generate_questions_prompt_id"`
|
||||
FallbackPromptID string `yaml:"fallback_prompt_id" json:"fallback_prompt_id"`
|
||||
RewritePromptID string `yaml:"rewrite_prompt_id" json:"rewrite_prompt_id"`
|
||||
GenerateSessionTitlePromptID string `yaml:"generate_session_title_prompt_id" json:"generate_session_title_prompt_id"`
|
||||
GenerateSummaryPromptID string `yaml:"generate_summary_prompt_id" json:"generate_summary_prompt_id"`
|
||||
ExtractEntitiesPromptID string `yaml:"extract_entities_prompt_id" json:"extract_entities_prompt_id"`
|
||||
ExtractRelationshipsPromptID string `yaml:"extract_relationships_prompt_id" json:"extract_relationships_prompt_id"`
|
||||
GenerateQuestionsPromptID string `yaml:"generate_questions_prompt_id" json:"generate_questions_prompt_id"`
|
||||
|
||||
// Resolved prompt text fields (populated by backfill, not from YAML)
|
||||
FallbackPrompt string `yaml:"-" json:"fallback_prompt"`
|
||||
@@ -162,6 +163,25 @@ type TenantConfig struct {
|
||||
EnableCrossTenantAccess bool `yaml:"enable_cross_tenant_access" json:"enable_cross_tenant_access"`
|
||||
}
|
||||
|
||||
type OIDCUserInfoMapping struct {
|
||||
Username string `yaml:"username" json:"username"`
|
||||
Email string `yaml:"email" json:"email"`
|
||||
}
|
||||
|
||||
type OIDCAuthConfig struct {
|
||||
Enable bool `yaml:"enable" json:"enable"`
|
||||
IssuerURL string `yaml:"issuer_url" json:"issuer_url"`
|
||||
DiscoveryURL string `yaml:"discovery_url" json:"discovery_url"`
|
||||
ProviderDisplayName string `yaml:"provider_display_name" json:"provider_display_name"`
|
||||
ClientID string `yaml:"client_id" json:"client_id"`
|
||||
ClientSecret string `yaml:"client_secret" json:"-"`
|
||||
AuthorizationEndpoint string `yaml:"authorization_endpoint" json:"authorization_endpoint"`
|
||||
TokenEndpoint string `yaml:"token_endpoint" json:"token_endpoint"`
|
||||
UserInfoEndpoint string `yaml:"user_info_endpoint" json:"user_info_endpoint"`
|
||||
Scopes []string `yaml:"scopes" json:"scopes"`
|
||||
UserInfoMapping *OIDCUserInfoMapping `yaml:"user_info_mapping" json:"user_info_mapping"`
|
||||
}
|
||||
|
||||
// PromptTemplateI18n holds localized name and description for a prompt template.
|
||||
type PromptTemplateI18n struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
@@ -175,16 +195,16 @@ type PromptTemplateI18n struct {
|
||||
// - user: 用户侧 Prompt(仅在需要 system+user 配对的模板中使用,如 rewrite、keywords_extraction)
|
||||
// - i18n: 多语言 name/description,键为 locale(如 "zh-CN"、"en-US"、"ko-KR"),后端根据请求语言替换 Name/Description 再返回
|
||||
type PromptTemplate struct {
|
||||
ID string `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Description string `yaml:"description" json:"description"`
|
||||
Content string `yaml:"content" json:"content"`
|
||||
User string `yaml:"user" json:"user,omitempty"`
|
||||
HasKnowledgeBase bool `yaml:"has_knowledge_base" json:"has_knowledge_base,omitempty"`
|
||||
HasWebSearch bool `yaml:"has_web_search" json:"has_web_search,omitempty"`
|
||||
Default bool `yaml:"default" json:"default,omitempty"`
|
||||
Mode string `yaml:"mode" json:"mode,omitempty"`
|
||||
I18n map[string]PromptTemplateI18n `yaml:"i18n" json:"-"`
|
||||
ID string `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Description string `yaml:"description" json:"description"`
|
||||
Content string `yaml:"content" json:"content"`
|
||||
User string `yaml:"user" json:"user,omitempty"`
|
||||
HasKnowledgeBase bool `yaml:"has_knowledge_base" json:"has_knowledge_base,omitempty"`
|
||||
HasWebSearch bool `yaml:"has_web_search" json:"has_web_search,omitempty"`
|
||||
Default bool `yaml:"default" json:"default,omitempty"`
|
||||
Mode string `yaml:"mode" json:"mode,omitempty"`
|
||||
I18n map[string]PromptTemplateI18n `yaml:"i18n" json:"-"`
|
||||
}
|
||||
|
||||
// PromptTemplatesConfig 提示词模板配置
|
||||
@@ -386,6 +406,8 @@ func LoadConfig() (*Config, error) {
|
||||
}
|
||||
|
||||
// Validate configuration values
|
||||
applyOIDCEnvOverrides(&cfg)
|
||||
|
||||
if err := ValidateConfig(&cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -398,6 +420,19 @@ func LoadConfig() (*Config, error) {
|
||||
func ValidateConfig(cfg *Config) error {
|
||||
var errs []string
|
||||
|
||||
if cfg.OIDCAuth != nil && cfg.OIDCAuth.Enable {
|
||||
if strings.TrimSpace(cfg.OIDCAuth.ClientID) == "" {
|
||||
errs = append(errs, "oidc_auth.client_id is required when OIDC is enabled")
|
||||
}
|
||||
if strings.TrimSpace(cfg.OIDCAuth.ClientSecret) == "" {
|
||||
errs = append(errs, "oidc_auth.client_secret is required when OIDC is enabled")
|
||||
}
|
||||
if strings.TrimSpace(cfg.OIDCAuth.DiscoveryURL) == "" &&
|
||||
(strings.TrimSpace(cfg.OIDCAuth.AuthorizationEndpoint) == "" || strings.TrimSpace(cfg.OIDCAuth.TokenEndpoint) == "") {
|
||||
errs = append(errs, "oidc_auth.discovery_url or both oidc_auth.authorization_endpoint and oidc_auth.token_endpoint are required when OIDC is enabled")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Conversation != nil {
|
||||
if cfg.Conversation.EmbeddingTopK < 0 {
|
||||
errs = append(errs, "conversation.embedding_top_k must be >= 0")
|
||||
@@ -437,6 +472,68 @@ func ValidateConfig(cfg *Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyOIDCEnvOverrides(cfg *Config) {
|
||||
if cfg.OIDCAuth == nil {
|
||||
cfg.OIDCAuth = &OIDCAuthConfig{}
|
||||
}
|
||||
if cfg.OIDCAuth.UserInfoMapping == nil {
|
||||
cfg.OIDCAuth.UserInfoMapping = &OIDCUserInfoMapping{}
|
||||
}
|
||||
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_ENABLE")); value != "" {
|
||||
cfg.OIDCAuth.Enable = strings.EqualFold(value, "true")
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_ISSUER_URL")); value != "" {
|
||||
cfg.OIDCAuth.IssuerURL = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_DISCOVERY_URL")); value != "" {
|
||||
cfg.OIDCAuth.DiscoveryURL = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_PROVIDER_DISPLAY_NAME")); value != "" {
|
||||
cfg.OIDCAuth.ProviderDisplayName = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_CLIENT_ID")); value != "" {
|
||||
cfg.OIDCAuth.ClientID = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_CLIENT_SECRET")); value != "" {
|
||||
cfg.OIDCAuth.ClientSecret = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_AUTHORIZATION_ENDPOINT")); value != "" {
|
||||
cfg.OIDCAuth.AuthorizationEndpoint = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_TOKEN_ENDPOINT")); value != "" {
|
||||
cfg.OIDCAuth.TokenEndpoint = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_USER_INFO_ENDPOINT")); value != "" {
|
||||
cfg.OIDCAuth.UserInfoEndpoint = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_AUTH_SCOPES")); value != "" {
|
||||
cfg.OIDCAuth.Scopes = strings.Fields(strings.ReplaceAll(value, ",", " "))
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_USER_INFO_MAPPING_USER_NAME")); value != "" {
|
||||
cfg.OIDCAuth.UserInfoMapping.Username = value
|
||||
}
|
||||
if value := strings.TrimSpace(os.Getenv("OIDC_USER_INFO_MAPPING_EMAIL")); value != "" {
|
||||
cfg.OIDCAuth.UserInfoMapping.Email = value
|
||||
}
|
||||
|
||||
if cfg.OIDCAuth.ProviderDisplayName == "" {
|
||||
cfg.OIDCAuth.ProviderDisplayName = "OIDC"
|
||||
}
|
||||
if len(cfg.OIDCAuth.Scopes) == 0 {
|
||||
cfg.OIDCAuth.Scopes = []string{"openid", "profile", "email"}
|
||||
}
|
||||
if cfg.OIDCAuth.UserInfoMapping.Username == "" {
|
||||
cfg.OIDCAuth.UserInfoMapping.Username = "name"
|
||||
}
|
||||
if cfg.OIDCAuth.UserInfoMapping.Email == "" {
|
||||
cfg.OIDCAuth.UserInfoMapping.Email = "email"
|
||||
}
|
||||
if cfg.OIDCAuth.DiscoveryURL == "" && cfg.OIDCAuth.IssuerURL != "" {
|
||||
cfg.OIDCAuth.DiscoveryURL = strings.TrimRight(cfg.OIDCAuth.IssuerURL, "/") + "/.well-known/openid-configuration"
|
||||
}
|
||||
}
|
||||
|
||||
// backfillConversationDefaults resolves prompt template ID references
|
||||
// into actual prompt text content. Only xxx_id fields are used;
|
||||
// no fallback to default templates.
|
||||
@@ -592,7 +689,7 @@ func loadPromptTemplates(configDir string) (*PromptTemplatesConfig, error) {
|
||||
"agent_system_prompt.yaml": &config.AgentSystemPrompt,
|
||||
"graph_extraction.yaml": &config.GraphExtraction,
|
||||
"generate_questions.yaml": &config.GenerateQuestions,
|
||||
"intent_prompts.yaml": &config.IntentPrompts,
|
||||
"intent_prompts.yaml": &config.IntentPrompts,
|
||||
}
|
||||
|
||||
// 加载每个模板文件
|
||||
|
||||
Reference in New Issue
Block a user