Merge pull request #1288 from trheyi/main

Refactor CreateAssistant and UpdateAssistant response handling to ret…
This commit is contained in:
Max 2025-11-08 16:27:05 +08:00 committed by GitHub
commit f462236809
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,6 @@
package agent package agent
import ( import (
"encoding/json"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -391,8 +390,10 @@ func CreateAssistant(c *gin.Context) {
log.Error("Error reloading assistant %s: %v", id, err) log.Error("Error reloading assistant %s: %v", id, err)
} }
// Return success response // Return success response with only assistant_id
response.RespondWithSuccess(c, response.StatusOK, assistantData) response.RespondWithSuccess(c, response.StatusOK, map[string]interface{}{
"assistant_id": id,
})
} }
// UpdateAssistant updates an existing assistant // UpdateAssistant updates an existing assistant
@ -488,22 +489,16 @@ func UpdateAssistant(c *gin.Context) {
} }
// Reload the assistant to ensure it's available in cache with updated data // Reload the assistant to ensure it's available in cache with updated data
updatedAssistant, err := assistant.Get(assistantID) _, err = assistant.Get(assistantID)
if err != nil { if err != nil {
// Just log the error, don't fail the request // Just log the error, don't fail the request
log.Error("Error reloading assistant %s: %v", assistantID, err) log.Error("Error reloading assistant %s: %v", assistantID, err)
// Return simple success response
response.RespondWithSuccess(c, response.StatusOK, map[string]interface{}{"assistant_id": assistantID})
return
} }
// Convert updated assistant to map for response // Return success response with only assistant_id
responseData, _ := json.Marshal(updatedAssistant) response.RespondWithSuccess(c, response.StatusOK, map[string]interface{}{
var responseMap map[string]interface{} "assistant_id": assistantID,
json.Unmarshal(responseData, &responseMap) })
// Return success response with updated assistant data
response.RespondWithSuccess(c, response.StatusOK, responseMap)
} }
// checkAssistantPermission checks if the user has permission to access the assistant // checkAssistantPermission checks if the user has permission to access the assistant