feat(server): hot-reload config store and reloadable infra clients

- Replace single Load() with a watching Store that re-reads config files
  (and config.local.yaml) and fans out a ReloadEvent with a per-field diff
  so consumers can decide whether the change is hot-applicable or requires
  a process restart.
- Wrap llm, retrieval, vector store, and object storage clients in
  Reloadable* shells so the bootstrap can swap their underlying impls when
  config changes without re-instantiating handlers.
- Make jwt.Manager and ops TokenIssuer mutable under a lock so secrets and
  TTLs can be rotated live; thread default plan code through a setter on
  the ops AdminUserService.
- Wire ConfigStore through bootstrap and every cmd/main.go, scheduler /
  worker / tenant-api / ops-api start the watcher; services and handlers
  take a config.Provider so they always read current values for things
  like generation.stream_enabled, scheduler dispatch, retrieval, etc.
- Switch shared/config decoding off viper to a Kratos-derived runtime
  package so env placeholders (\${VAR:default}) resolve consistently and
  the same source machinery powers both the loader and the watcher.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-01 16:01:23 +08:00
parent ce2d8a2907
commit 618399f86d
61 changed files with 3186 additions and 496 deletions
+20 -17
View File
@@ -25,7 +25,8 @@ func main() {
}
defer app.Close()
generationCfg := app.Config.Generation
generationProvider := tenantapp.NewGenerationStreamDisabledConfigProvider(app.ConfigStore)
generationCfg := app.Config().Generation
generationCfg.StreamEnabled = false
knowledgeSvc := tenantapp.NewKnowledgeService(
@@ -35,11 +36,11 @@ func main() {
app.ObjectStorage,
app.LLM,
app.Logger,
app.Config.Retrieval,
app.Config.LLM,
app.Config().Retrieval,
app.Config().LLM,
0,
0,
)
).WithConfigProvider(app.ConfigStore)
templateSvc := tenantapp.NewTemplateService(
app.DB,
@@ -52,8 +53,8 @@ func main() {
knowledgeSvc,
app.GenerationStreams,
generationCfg,
app.Config.LLM.MaxOutputTokens,
).WithCache(app.Cache)
app.Config().LLM.MaxOutputTokens,
).WithCache(app.Cache).WithConfigProvider(generationProvider)
promptRuleSvc := tenantapp.NewPromptRuleGenerationService(
app.DB,
@@ -62,8 +63,8 @@ func main() {
knowledgeSvc,
app.GenerationStreams,
generationCfg,
app.Config.LLM.MaxOutputTokens,
).WithCache(app.Cache).WithLogger(app.Logger)
app.Config().LLM.MaxOutputTokens,
).WithCache(app.Cache).WithLogger(app.Logger).WithConfigProvider(generationProvider)
publishJobSvc := tenantapp.NewPublishJobService(
app.DB,
@@ -80,8 +81,8 @@ func main() {
knowledgeSvc,
app.GenerationStreams,
generationCfg,
app.Config.LLM.MaxOutputTokens,
).WithCache(app.Cache)
app.Config().LLM.MaxOutputTokens,
).WithCache(app.Cache).WithConfigProvider(generationProvider)
kolWorker := generateworker.NewKolGenerationWorker(
app.DB,
@@ -89,12 +90,14 @@ func main() {
knowledgeSvc,
app.Logger,
generationCfg,
app.Config.LLM.MaxOutputTokens,
).WithCache(app.Cache)
app.Config().LLM.MaxOutputTokens,
).WithCache(app.Cache).WithConfigProvider(app.ConfigStore)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
app.StartConfigWatcher(ctx)
generateworker.NewArticleGenerationWorker(
app.DB,
app.RabbitMQ,
@@ -103,16 +106,16 @@ func main() {
imitationSvc,
kolWorker,
app.Logger,
app.Config.Generation,
).Start(ctx)
app.Config().Generation,
).WithConfigProvider(app.ConfigStore).Start(ctx)
generateworker.NewTemplateAssistWorker(
app.RabbitMQ,
templateSvc,
app.Logger,
app.Config.Generation.WorkerConcurrency,
app.Config.Generation.ArticleTimeout,
).Start(ctx)
app.Config().Generation.WorkerConcurrency,
app.Config().Generation.ArticleTimeout,
).WithConfigProvider(app.ConfigStore).Start(ctx)
app.Logger.Info("worker-generate started")