feat(prompts): add prompts loader and configuration management

- Implemented a new prompts loader in `loader.go` to manage prompt templates and configurations.
- Introduced caching mechanism for prompt configurations to optimize loading.
- Added functions to apply platform-specific prompt template overrides.
- Created unit tests in `loader_test.go` to validate prompt configuration loading and reloading behavior.
- Ensured that the last valid configuration is retained in case of errors during reload.
This commit is contained in:
2026-04-13 16:08:12 +08:00
parent 6066f43a7d
commit 1b01caac0f
21 changed files with 1630 additions and 392 deletions
@@ -26,6 +26,9 @@ func (r *cachedTemplateRepository) ListTemplates(ctx context.Context, tenantID i
if data, err := r.cache.Get(ctx, key); err == nil {
var records []TemplateRecord
if err := json.Unmarshal(data, &records); err == nil {
for i := range records {
applyPlatformTemplatePromptOverrides(&records[i])
}
return records, nil
}
}
@@ -38,6 +41,9 @@ func (r *cachedTemplateRepository) ListTemplates(ctx context.Context, tenantID i
if data, err := json.Marshal(records); err == nil {
_ = r.cache.Set(ctx, key, data, templateCacheTTL)
}
for i := range records {
applyPlatformTemplatePromptOverrides(&records[i])
}
return records, nil
}
@@ -47,6 +53,7 @@ func (r *cachedTemplateRepository) GetTemplateByID(ctx context.Context, id, tena
if data, err := r.cache.Get(ctx, key); err == nil {
var record TemplateRecord
if err := json.Unmarshal(data, &record); err == nil {
applyPlatformTemplatePromptOverrides(&record)
return &record, nil
}
}
@@ -59,5 +66,6 @@ func (r *cachedTemplateRepository) GetTemplateByID(ctx context.Context, id, tena
if data, err := json.Marshal(record); err == nil {
_ = r.cache.Set(ctx, key, data, templateCacheTTL)
}
applyPlatformTemplatePromptOverrides(record)
return record, nil
}