mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
fix: prevent duplicate history entries when edit_diagram tool is called (#64)
- Add handleExportWithoutHistory function for fetching current diagram state without saving to history - Update onFetchChart to accept saveToHistory parameter (defaults to true) - edit_diagram tool now fetches with saveToHistory=false since it only needs the current state - Only the initial form submission saves to history as intended
This commit is contained in:
@@ -27,18 +27,23 @@ export default function ChatPanel({
|
||||
const {
|
||||
loadDiagram: onDisplayChart,
|
||||
handleExport: onExport,
|
||||
handleExportWithoutHistory,
|
||||
resolverRef,
|
||||
chartXML,
|
||||
clearDiagram,
|
||||
} = useDiagram();
|
||||
|
||||
const onFetchChart = () => {
|
||||
const onFetchChart = (saveToHistory = true) => {
|
||||
return Promise.race([
|
||||
new Promise<string>((resolve) => {
|
||||
if (resolverRef && "current" in resolverRef) {
|
||||
resolverRef.current = resolve;
|
||||
}
|
||||
onExport();
|
||||
if (saveToHistory) {
|
||||
onExport();
|
||||
} else {
|
||||
handleExportWithoutHistory();
|
||||
}
|
||||
}),
|
||||
new Promise<string>((_, reject) =>
|
||||
setTimeout(
|
||||
@@ -87,7 +92,8 @@ export default function ChatPanel({
|
||||
|
||||
let currentXml = "";
|
||||
try {
|
||||
currentXml = await onFetchChart();
|
||||
// Fetch without saving to history - edit_diagram shouldn't create history entry
|
||||
currentXml = await onFetchChart(false);
|
||||
|
||||
const { replaceXMLParts } = await import("@/lib/utils");
|
||||
const editedXml = replaceXMLParts(currentXml, edits);
|
||||
|
||||
Reference in New Issue
Block a user