feat: add webui http channel for chat and file upload

This commit is contained in:
2026-03-10 10:23:53 +08:00
parent bd41f48971
commit 49f6297631
6 changed files with 527 additions and 2 deletions

View File

@@ -25,6 +25,7 @@ type Config struct {
Telegram TelegramConfig
Feishu FeishuConfig
WebUI WebUIConfig
LLM LLMConfig
Security SecurityConfig
WebSearch WebSearchConfig
@@ -45,6 +46,11 @@ type FeishuConfig struct {
EventPath string
}
type WebUIConfig struct {
ListenAddr string
MaxUploadBytes int64
}
type LLMConfig struct {
BaseURL string
APIKey string
@@ -95,6 +101,10 @@ func Load() (Config, error) {
ListenAddr: defaultIfEmpty(os.Getenv("FEISHU_LISTEN_ADDR"), ":8080"),
EventPath: defaultIfEmpty(os.Getenv("FEISHU_EVENT_PATH"), "/feishu/events"),
},
WebUI: WebUIConfig{
ListenAddr: defaultIfEmpty(os.Getenv("WEBUI_LISTEN_ADDR"), ":8090"),
MaxUploadBytes: int64(intFromEnv("WEBUI_MAX_UPLOAD_MB", 20)) * 1024 * 1024,
},
LLM: LLMConfig{
BaseURL: strings.TrimRight(defaultIfEmpty(os.Getenv("LLM_BASE_URL"), "https://api.openai.com/v1"), "/"),
APIKey: strings.TrimSpace(os.Getenv("LLM_API_KEY")),
@@ -116,8 +126,8 @@ func Load() (Config, error) {
cfg.MessageChannel = strings.ToLower(strings.TrimSpace(cfg.MessageChannel))
cfg.LogLevel = strings.ToLower(strings.TrimSpace(cfg.LogLevel))
if cfg.MessageChannel != "telegram" && cfg.MessageChannel != "feishu" {
return Config{}, fmt.Errorf("MESSAGE_CHANNEL must be telegram or feishu")
if cfg.MessageChannel != "telegram" && cfg.MessageChannel != "feishu" && cfg.MessageChannel != "webui" {
return Config{}, fmt.Errorf("MESSAGE_CHANNEL must be telegram, feishu, or webui")
}
if cfg.LogLevel != "debug" && cfg.LogLevel != "info" && cfg.LogLevel != "warn" && cfg.LogLevel != "error" {
return Config{}, fmt.Errorf("LOG_LEVEL must be debug, info, warn, or error")
@@ -137,6 +147,9 @@ func Load() (Config, error) {
if cfg.GapClusterLookbackHours < 1 || cfg.GapClusterLookbackHours > 24*365 {
return Config{}, fmt.Errorf("GAP_CLUSTER_LOOKBACK_HOURS must be between 1 and 8760")
}
if cfg.WebUI.MaxUploadBytes < 1024 || cfg.WebUI.MaxUploadBytes > 200*1024*1024 {
return Config{}, fmt.Errorf("WEBUI_MAX_UPLOAD_MB must be between 1 and 200")
}
if cfg.MessageChannel == "telegram" {
if cfg.Telegram.Token == "" {
@@ -156,6 +169,12 @@ func Load() (Config, error) {
}
}
if cfg.MessageChannel == "webui" {
if strings.TrimSpace(cfg.WebUI.ListenAddr) == "" {
return Config{}, fmt.Errorf("WEBUI_LISTEN_ADDR is required when MESSAGE_CHANNEL=webui")
}
}
if cfg.LLM.APIKey == "" {
return Config{}, fmt.Errorf("LLM_API_KEY is required")
}