feat(app): wire chat module + LocalFS storage + LLM registry into app.New

This commit is contained in:
2026-05-04 19:37:14 +08:00
parent 7aa8456b1b
commit 8effeee063
3 changed files with 133 additions and 0 deletions
+47
View File
@@ -37,6 +37,8 @@ type Config struct {
Bootstrap BootstrapConfig `mapstructure:"bootstrap"`
Workspace Workspace `mapstructure:"workspace"`
Git Git `mapstructure:"git"`
Chat Chat `mapstructure:"chat"`
Storage Storage `mapstructure:"storage"`
}
// HTTPConfig 描述 HTTP 服务监听参数。
@@ -70,6 +72,41 @@ type Git struct {
Binary string `mapstructure:"binary"`
}
// Chat 配置 chat 模块的附件、流式、历史与定时清理策略。
type Chat struct {
Attachment ChatAttachment `mapstructure:"attachment"`
Stream ChatStream `mapstructure:"stream"`
History ChatHistory `mapstructure:"history"`
}
// ChatAttachment 控制单文件 / 单消息上限与允许的 MIME 白名单。
type ChatAttachment struct {
MaxFileSizeMB int64 `mapstructure:"max_file_size_mb"`
MaxMessageSizeMB int64 `mapstructure:"max_message_size_mb"`
MimeWhitelist []string `mapstructure:"mime_whitelist"`
}
// ChatStream 控制 SSE ring buffer 保留时长与取消宽限期。
type ChatStream struct {
RingBufferRetentionSeconds int `mapstructure:"ring_buffer_retention_seconds"`
}
// ChatHistory 控制 token 预算的安全余量百分比(如 5 表示保留 5% 余量)。
type ChatHistory struct {
SafetyMarginPct float64 `mapstructure:"safety_margin_pct"`
}
// Storage 选择附件落盘驱动与对应参数。
type Storage struct {
Driver string `mapstructure:"driver"` // 当前仅支持 "localfs"
LocalFS StorageLocalFS `mapstructure:"localfs"`
}
// StorageLocalFS 是 driver=localfs 时的根目录。
type StorageLocalFS struct {
BasePath string `mapstructure:"base_path"`
}
// Load 从(按优先级递增)默认值 → 配置文件(如有)→ 环境变量 加载配置。
// configFile 可为空字符串,仅用环境变量。
func Load(configFile string) (*Config, error) {
@@ -85,6 +122,16 @@ func Load(configFile string) (*Config, error) {
v.SetDefault("workspace.push_timeout", "5m")
v.SetDefault("workspace.ops_timeout", "60s")
v.SetDefault("git.binary", "git")
v.SetDefault("chat.attachment.max_file_size_mb", 20)
v.SetDefault("chat.attachment.max_message_size_mb", 50)
v.SetDefault("chat.attachment.mime_whitelist", []string{
"image/png", "image/jpeg", "image/webp", "image/gif",
"application/pdf", "text/*",
})
v.SetDefault("chat.stream.ring_buffer_retention_seconds", 300)
v.SetDefault("chat.history.safety_margin_pct", 5.0)
v.SetDefault("storage.driver", "localfs")
v.SetDefault("storage.localfs.base_path", "./data/uploads")
if configFile != "" {
v.SetConfigFile(configFile)