fix(agent): 画布审批 - 大事件改用快照刷新避免执行回滚
This commit is contained in:
1 parent
e54a1c46a5
commit
0b7fb7120f
5 files changed
+197
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
"yingce/backend/internal/repository"
|
||||
@@ -85,6 +86,8 @@ func cloudAgentShrinkChange(before, after map[string]any) (map[string]any, map[s
|
||||
return shrunkBefore, shrunkAfter
|
||||
}
|
||||
|
||||
// emitCloudAgentCanvasChange 生成与画布写入同事务保存的事件。
|
||||
// 增量无法完整表达变更或超过事件上限时通知客户端重新读取,不截断真实画布内容。
|
||||
func emitCloudAgentCanvasChange(repo *repository.Repository, runID string, state *cloudAgentRuntime, input cloudAgentMutationInput) error {
|
||||
before, err := creationDocument(input.BeforeJSON)
|
||||
if err != nil {
|
||||
@@ -190,6 +193,24 @@ func emitCloudAgentCanvasChange(repo *repository.Repository, runID string, state
|
||||
if state.CallIndex >= 0 && state.CallIndex < len(state.Calls) {
|
||||
payload["callId"] = state.Calls[state.CallIndex].ID
|
||||
}
|
||||
raw, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(raw) > cloudAgentEventPayloadLimit {
|
||||
// 修改标题或关联素材也可能携带整份分镜正文的 before/after,导致审批事务回滚。
|
||||
// 大增量沿用已有的快照刷新路径;画布、撤销记录和工具回执仍由原事务完整保存。
|
||||
delete(payload, "canvasPatch")
|
||||
payload["requiresRefresh"] = true
|
||||
raw, err = json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(raw) > cloudAgentEventPayloadLimit {
|
||||
// 摘要本身也超限时不截断字段,退回既有的完整刷新通知。
|
||||
payload = map[string]any{"canvasId": input.CanvasID, "operation": input.Operation, "requiresRefresh": true}
|
||||
}
|
||||
}
|
||||
state.event(runID, "canvas_updated", payload)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user