Fix: The save interface is continuously called without any operation being performed on the agent page. (#17576)

This commit is contained in:
balibabu
2026-07-31 11:23:12 +08:00
committed by GitHub
parent 0fe49688d1
commit 569a29500f
6 changed files with 24 additions and 9 deletions

View File

@@ -1153,7 +1153,8 @@ async def update_agent(agent_id, tenant_id):
if not replica_ok:
return get_data_error_result(message="agent saved, but replica sync failed.")
return get_json_result(data=True)
_, updated_agent = UserCanvasService.get_by_id(agent_id)
return get_json_result(data={"update_time": updated_agent.update_time})
@manager.route("/agents/<agent_id>/reset", methods=["POST"]) # noqa: F821

View File

@@ -341,7 +341,14 @@ func (h *AgentHandler) UpdateAgent(c *gin.Context) {
common.ResponseWithCodeData(c, ec, nil, em)
return
}
common.SuccessWithData(c, true, "success")
canvas, err := h.agentService.GetAgent(c.Request.Context(), user.ID, canvasID)
if err != nil || canvas == nil {
common.SuccessWithData(c, map[string]interface{}{}, "success")
return
}
common.SuccessWithData(c, map[string]interface{}{
"update_time": canvas.UpdateTime,
}, "success")
}
// DeleteAgent removes the canvas and cascades to its versions.

View File

@@ -590,7 +590,7 @@ def test_agents_crud_unit_branches(monkeypatch):
monkeypatch.setattr(
module.UserCanvasService,
"get_by_id",
lambda _id: (True, SimpleNamespace(title="agent-1", canvas_category=module.CanvasCategory.Agent)),
lambda _id: (True, SimpleNamespace(title="agent-1", canvas_category=module.CanvasCategory.Agent, update_time=1234567890)),
)
monkeypatch.setattr(
module.UserCanvasService,

View File

@@ -444,7 +444,10 @@ export const useResetAgent = () => {
return { data, loading, resetAgent: mutateAsync };
};
export const useSetAgent = (showMessage: boolean = true) => {
export const useSetAgent = (
showMessage: boolean = true,
skipInvalidation: boolean = false,
) => {
const { id } = useParams();
const queryClient = useQueryClient();
const {
@@ -483,7 +486,7 @@ export const useSetAgent = (showMessage: boolean = true) => {
queryClient.invalidateQueries({
queryKey: [AgentApiAction.FetchAgentListByPage],
});
if (agentId) {
if (agentId && !skipInvalidation) {
queryClient.invalidateQueries({
queryKey: [AgentApiAction.FetchAgentDetail, agentId],
});

View File

@@ -14,9 +14,12 @@ import { useParams } from 'react-router';
import useGraphStore from '../store';
import { useBuildDslData } from './use-build-dsl';
export const useSaveGraph = (showMessage: boolean = true) => {
export const useSaveGraph = (
showMessage: boolean = true,
skipInvalidation: boolean = false,
) => {
const { data } = useFetchAgent();
const { setAgent, loading } = useSetAgent(showMessage);
const { setAgent, loading } = useSetAgent(showMessage, skipInvalidation);
const { id } = useParams();
const { buildDslData } = useBuildDslData();
@@ -72,7 +75,7 @@ export const useWatchAgentChange = (chatDrawerVisible: boolean) => {
const [time, setTime] = useState<string>();
const nodes = useGraphStore((state) => state.nodes);
const edges = useGraphStore((state) => state.edges);
const { saveGraph } = useSaveGraph(false);
const { saveGraph } = useSaveGraph(false, true);
const { data: flowDetail } = useFetchAgent();
const setSaveTime = useCallback((updateTime: number) => {
@@ -86,7 +89,7 @@ export const useWatchAgentChange = (chatDrawerVisible: boolean) => {
const saveAgent = useCallback(async () => {
if (!chatDrawerVisible) {
const ret = await saveGraph();
setSaveTime(ret.data.update_time);
setSaveTime(ret.data.update_time ?? Date.now());
}
}, [chatDrawerVisible, saveGraph, setSaveTime]);

View File

@@ -94,6 +94,7 @@ export function WikiLeftPanel({
<Button
variant="ghost"
size="icon-sm"
className="ml-auto"
disabled={loading}
data-testid="wiki-clear-trigger"
>