diff --git a/neo/api.go b/neo/api.go index 2aa14591..fc300421 100644 --- a/neo/api.go +++ b/neo/api.go @@ -1131,14 +1131,14 @@ func (neo *DSL) handleAssistantDetail(c *gin.Context) { // handleAssistantSave handles creating or updating an assistant func (neo *DSL) handleAssistantSave(c *gin.Context) { - var assistant map[string]interface{} - if err := c.BindJSON(&assistant); err != nil { + var assistantData map[string]interface{} + if err := c.BindJSON(&assistantData); err != nil { c.JSON(400, gin.H{"message": "invalid request body", "code": 400}) c.Done() return } - id, err := neo.Store.SaveAssistant(assistant) + id, err := neo.Store.SaveAssistant(assistantData) if err != nil { c.JSON(500, gin.H{"message": err.Error(), "code": 500}) c.Done() @@ -1146,11 +1146,24 @@ func (neo *DSL) handleAssistantSave(c *gin.Context) { } // Update the assistant map with the returned ID if it's not already set - if _, ok := assistant["assistant_id"]; !ok { - assistant["assistant_id"] = id + if _, ok := assistantData["assistant_id"]; !ok { + assistantData["assistant_id"] = id } - c.JSON(200, gin.H{"message": "ok", "data": assistant}) + // Remove the assistant from cache to ensure fresh data on next load + cache := assistant.GetCache() + if cache != nil { + cache.Remove(id.(string)) + } + + // Reload the assistant to ensure it's available in cache with updated data + _, err = assistant.Get(id.(string)) + if err != nil { + // Just log the error, don't fail the request + fmt.Printf("Error reloading assistant %s: %v\n", id, err) + } + + c.JSON(200, gin.H{"message": "ok", "data": assistantData}) c.Done() } @@ -1170,6 +1183,12 @@ func (neo *DSL) handleAssistantDelete(c *gin.Context) { return } + // Remove the assistant from cache to ensure it's fully deleted + cache := assistant.GetCache() + if cache != nil { + cache.Remove(assistantID) + } + c.JSON(200, gin.H{"message": "ok"}) c.Done() } diff --git a/neo/assistant/load.go b/neo/assistant/load.go index 9dc80b61..052b8de6 100644 --- a/neo/assistant/load.go +++ b/neo/assistant/load.go @@ -148,6 +148,11 @@ func ClearCache() { } } +// GetCache returns the loaded cache +func GetCache() *Cache { + return loaded +} + // LoadStore create a new assistant from store func LoadStore(id string) (*Assistant, error) {