mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-28 03:38:11 +08:00
fix(go): agent settings update clearing DSL (#16495)
### Summary This PR fixes a Go backend bug where updating agent settings, such as description, could clear the agent DSL. Root cause: PUT /api/v1/agents/:canvas_id only bound the dsl field in Go. When the frontend submitted settings without dsl, the service still updated the canvas with an empty DSL value. Changes: - Treat agent updates as partial patches. - Preserve existing DSL when dsl is not present in the request. - Update only specified user_canvas fields instead of saving the full row. - Add a regression test for settings updates preserving DSL. Test: `go test ./internal/service ./internal/handler` Co-authored-by: Zhichang Yu <yuzhichang@gmail.com>
This commit is contained in:
@@ -306,17 +306,15 @@ func (h *AgentHandler) GetAgent(c *gin.Context) {
|
||||
}
|
||||
|
||||
// updateAgentRequest is the wire shape for PUT /api/v1/agents/:canvas_id.
|
||||
type updateAgentRequest struct {
|
||||
DSL entity.JSONMap `json:"dsl"`
|
||||
}
|
||||
type updateAgentRequest map[string]interface{}
|
||||
|
||||
// UpdateAgent writes a new draft DSL to the canvas (no version created).
|
||||
// @Summary Update Agent (Draft)
|
||||
// UpdateAgent applies a partial update to the canvas draft.
|
||||
// @Summary Update Agent
|
||||
// @Tags agents
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param canvas_id path string true "canvas id"
|
||||
// @Param request body updateAgentRequest true "draft DSL payload"
|
||||
// @Param request body updateAgentRequest true "agent update payload"
|
||||
// @Success 200 {object} map[string]interface{}
|
||||
// @Router /api/v1/agents/{canvas_id} [put]
|
||||
func (h *AgentHandler) UpdateAgent(c *gin.Context) {
|
||||
@@ -331,7 +329,10 @@ func (h *AgentHandler) UpdateAgent(c *gin.Context) {
|
||||
jsonError(c, common.CodeArgumentError, "Invalid request: "+err.Error())
|
||||
return
|
||||
}
|
||||
if err := h.agentService.UpdateAgent(c.Request.Context(), user.ID, canvasID, req.DSL); err != nil {
|
||||
if req == nil {
|
||||
req = updateAgentRequest{}
|
||||
}
|
||||
if err := h.agentService.UpdateAgent(c.Request.Context(), user.ID, canvasID, map[string]interface{}(req)); err != nil {
|
||||
ec, em := mapAgentError(err)
|
||||
jsonError(c, ec, em)
|
||||
return
|
||||
|
||||
@@ -441,7 +441,7 @@ func (f *fullFakeAgentService) GetAgent(context.Context, string, string) (*entit
|
||||
}
|
||||
return f.getRow, nil
|
||||
}
|
||||
func (f *fullFakeAgentService) UpdateAgent(context.Context, string, string, entity.JSONMap) error {
|
||||
func (f *fullFakeAgentService) UpdateAgent(context.Context, string, string, map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
func (f *fullFakeAgentService) DeleteAgent(context.Context, string, string) error {
|
||||
|
||||
@@ -84,7 +84,7 @@ func (f *waitFakeAgentService) CreateAgent(context.Context, *service.CreateAgent
|
||||
func (f *waitFakeAgentService) GetAgent(context.Context, string, string) (*entity.UserCanvas, error) {
|
||||
return &entity.UserCanvas{ID: "canvas-wait"}, nil
|
||||
}
|
||||
func (f *waitFakeAgentService) UpdateAgent(context.Context, string, string, entity.JSONMap) error {
|
||||
func (f *waitFakeAgentService) UpdateAgent(context.Context, string, string, map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
func (f *waitFakeAgentService) DeleteAgent(context.Context, string, string) error {
|
||||
|
||||
Reference in New Issue
Block a user