feat: add /reload to gateway api and command (#1725)

* feat: add /reload to gateway api and command

* prevent duplicate reload request in same time
This commit is contained in:
Cytown
2026-03-19 13:42:36 +08:00
committed by GitHub
parent 14a28ae93e
commit 2a6ade0fe4
6 changed files with 150 additions and 14 deletions
+12
View File
@@ -49,6 +49,7 @@ type AgentLoop struct {
cmdRegistry *commands.Registry
mcp mcpRuntime
mu sync.RWMutex
reloadFunc func() error
// Track active requests for safe provider cleanup
activeRequests sync.WaitGroup
}
@@ -498,6 +499,11 @@ func (al *AgentLoop) SetTranscriber(t voice.Transcriber) {
al.transcriber = t
}
// SetReloadFunc sets the callback function for triggering config reload.
func (al *AgentLoop) SetReloadFunc(fn func() error) {
al.reloadFunc = fn
}
var audioAnnotationRe = regexp.MustCompile(`\[(voice|audio)(?::[^\]]*)?\]`)
// transcribeAudioInMessage resolves audio media refs, transcribes them, and
@@ -1931,6 +1937,12 @@ func (al *AgentLoop) buildCommandsRuntime(agent *AgentInstance, opts *processOpt
return nil
},
}
rt.ReloadConfig = func() error {
if al.reloadFunc == nil {
return fmt.Errorf("reload not configured")
}
return al.reloadFunc()
}
if agent != nil {
rt.GetModelInfo = func() (string, string) {
return agent.Model, cfg.Agents.Defaults.Provider