mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-13 23:07:33 +08:00
Fix provider hot reload and restore memory API
This commit is contained in:
@@ -48,7 +48,7 @@ type Server struct {
|
||||
logFilePath string
|
||||
onChat func(ctx context.Context, sessionKey, content string) (string, error)
|
||||
onChatHistory func(sessionKey string) []map[string]interface{}
|
||||
onConfigAfter func() error
|
||||
onConfigAfter func(forceRuntimeReload bool) error
|
||||
onCron func(action string, args map[string]interface{}) (interface{}, error)
|
||||
onToolsCatalog func() interface{}
|
||||
whatsAppBridge *channels.WhatsAppBridgeService
|
||||
@@ -85,7 +85,7 @@ func (s *Server) SetChatHandler(fn func(ctx context.Context, sessionKey, content
|
||||
func (s *Server) SetChatHistoryHandler(fn func(sessionKey string) []map[string]interface{}) {
|
||||
s.onChatHistory = fn
|
||||
}
|
||||
func (s *Server) SetConfigAfterHook(fn func() error) { s.onConfigAfter = fn }
|
||||
func (s *Server) SetConfigAfterHook(fn func(forceRuntimeReload bool) error) { s.onConfigAfter = fn }
|
||||
func (s *Server) SetCronHandler(fn func(action string, args map[string]interface{}) (interface{}, error)) {
|
||||
s.onCron = fn
|
||||
}
|
||||
@@ -414,7 +414,7 @@ func (s *Server) persistWebUIConfig(cfg *cfgpkg.Config) error {
|
||||
return err
|
||||
}
|
||||
if s.onConfigAfter != nil {
|
||||
return s.onConfigAfter()
|
||||
return s.onConfigAfter(false)
|
||||
}
|
||||
return requestSelfReloadSignal()
|
||||
}
|
||||
@@ -978,7 +978,9 @@ func (s *Server) saveProviderConfig(cfg *cfgpkg.Config, name string, pc cfgpkg.P
|
||||
return err
|
||||
}
|
||||
if s.onConfigAfter != nil {
|
||||
if err := s.onConfigAfter(); err != nil {
|
||||
// Provider updates can take effect through external credential files
|
||||
// even when config.json remains structurally identical.
|
||||
if err := s.onConfigAfter(true); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@@ -3118,12 +3120,15 @@ func (s *Server) handleWebUIMemory(w http.ResponseWriter, r *http.Request) {
|
||||
case http.MethodGet:
|
||||
path := strings.TrimSpace(r.URL.Query().Get("path"))
|
||||
if path == "" {
|
||||
files := make([]string, 0, 16)
|
||||
if _, err := os.Stat(filepath.Join(s.workspacePath, "MEMORY.md")); err == nil {
|
||||
files = append(files, "MEMORY.md")
|
||||
}
|
||||
entries, err := os.ReadDir(memoryDir)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
files := make([]string, 0, len(entries))
|
||||
for _, e := range entries {
|
||||
if e.IsDir() {
|
||||
continue
|
||||
@@ -3133,7 +3138,11 @@ func (s *Server) handleWebUIMemory(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, map[string]interface{}{"ok": true, "files": files})
|
||||
return
|
||||
}
|
||||
clean, content, found, err := readRelativeTextFile(memoryDir, path)
|
||||
baseDir := memoryDir
|
||||
if strings.EqualFold(path, "MEMORY.md") {
|
||||
baseDir = strings.TrimSpace(s.workspacePath)
|
||||
}
|
||||
clean, content, found, err := readRelativeTextFile(baseDir, path)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user