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
@@ -19,10 +19,10 @@ const kolAssistReferenceContentMaxRunes = 6000
var kolAssistURLPattern = regexp.MustCompile(`https?://[^\s]+`)
type kolAssistURLResolver struct {
arkBaseURL string
arkAPIKey string
httpClient *http.Client
logger *zap.Logger
cfg config.LLMConfig
configProvider runtimeConfigProvider
httpClient *http.Client
logger *zap.Logger
}
type kolAssistReferenceMaterial struct {
@@ -38,17 +38,25 @@ func newKolAssistURLResolver(llmCfg config.LLMConfig, logger *zap.Logger) *kolAs
}
return &kolAssistURLResolver{
arkBaseURL: strings.TrimRight(baseURL, "/"),
arkAPIKey: strings.TrimSpace(llmCfg.APIKey),
cfg: config.LLMConfig{
BaseURL: baseURL,
APIKey: strings.TrimSpace(llmCfg.APIKey),
},
httpClient: &http.Client{Timeout: defaultKnowledgeURLParseTimeout},
logger: logger,
}
}
func (r *kolAssistURLResolver) extract(ctx context.Context, rawURL string) (*kolAssistReferenceMaterial, error) {
if r == nil || r.httpClient == nil || strings.TrimSpace(r.arkAPIKey) == "" {
llmCfg := r.runtimeConfig()
apiKey := strings.TrimSpace(llmCfg.APIKey)
if r == nil || r.httpClient == nil || apiKey == "" {
return nil, fmt.Errorf("url resolver is unavailable")
}
baseURL := strings.TrimRight(strings.TrimSpace(llmCfg.BaseURL), "/")
if baseURL == "" {
baseURL = defaultKnowledgeArkBaseURL
}
body, err := json.Marshal(arkToolExecuteRequest{
ActionName: "LinkReader",
@@ -62,11 +70,11 @@ func (r *kolAssistURLResolver) extract(ctx context.Context, rawURL string) (*kol
return nil, fmt.Errorf("marshal webpage parser request: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, r.arkBaseURL+"/tools/execute", bytes.NewReader(body))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+"/tools/execute", bytes.NewReader(body))
if err != nil {
return nil, fmt.Errorf("create webpage parser request: %w", err)
}
req.Header.Set("Authorization", "Bearer "+r.arkAPIKey)
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := r.httpClient.Do(req)
@@ -108,6 +116,26 @@ func (r *kolAssistURLResolver) extract(ctx context.Context, rawURL string) (*kol
}, nil
}
func (r *kolAssistURLResolver) withConfigProvider(provider runtimeConfigProvider) *kolAssistURLResolver {
if r == nil {
return nil
}
r.configProvider = provider
return r
}
func (r *kolAssistURLResolver) runtimeConfig() config.LLMConfig {
if r != nil && r.configProvider != nil {
if cfg := r.configProvider.Current(); cfg != nil {
return cfg.LLM
}
}
if r == nil {
return config.LLMConfig{BaseURL: defaultKnowledgeArkBaseURL}
}
return r.cfg
}
func (s *KolAssistService) enrichGenerateDescription(ctx context.Context, description string) string {
description = strings.TrimSpace(description)
urls := extractKolAssistURLs(description)