From 7b8bd8c621d2afa5a74df1bfb7105207d31e6cb7 Mon Sep 17 00:00:00 2001 From: "dayuan.jiang" Date: Fri, 5 Dec 2025 00:43:21 +0900 Subject: [PATCH] fix: use cached chartXML for edit_diagram to avoid Vercel timeout DrawIO iframe export was unreliable on Vercel due to network latency, causing edit_diagram tool to hang. Now uses chartXML from context directly, falling back to export only when no cached XML exists. --- components/chat-panel.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx index bbe67e2..b888bc4 100644 --- a/components/chat-panel.tsx +++ b/components/chat-panel.tsx @@ -99,8 +99,18 @@ export default function ChatPanel({ let currentXml = ""; try { - // Fetch without saving to history - edit_diagram shouldn't create history entry - currentXml = await onFetchChart(false); + console.log("[edit_diagram] Starting..."); + // Use chartXML from context directly - more reliable than export + // especially on Vercel where DrawIO iframe may have latency issues + if (chartXML) { + currentXml = chartXML; + console.log("[edit_diagram] Using cached chartXML, length:", currentXml.length); + } else { + // Fallback to export only if no cached XML + console.log("[edit_diagram] No cached XML, fetching from DrawIO..."); + currentXml = await onFetchChart(false); + console.log("[edit_diagram] Got XML from export, length:", currentXml.length); + } const { replaceXMLParts } = await import("@/lib/utils"); const editedXml = replaceXMLParts(currentXml, edits); @@ -112,8 +122,9 @@ export default function ChatPanel({ toolCallId: toolCall.toolCallId, output: `Successfully applied ${edits.length} edit(s) to the diagram.`, }); + console.log("[edit_diagram] Success"); } catch (error) { - console.error("Edit diagram failed:", error); + console.error("[edit_diagram] Failed:", error); const errorMessage = error instanceof Error @@ -127,7 +138,7 @@ export default function ChatPanel({ Current diagram XML: \`\`\`xml -${currentXml} +${currentXml || "No XML available"} \`\`\` Please retry with an adjusted search pattern or use display_diagram if retries are exhausted.`,