mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
Merge pull request #6 from DayuanJiang/edit_fallback
Add 3-retry policy for edit_diagram with automatic fallback
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"permissions": {
|
|
||||||
"allow": [
|
|
||||||
"Bash(npm update:*)",
|
|
||||||
"WebFetch(domain:ai-sdk.dev)",
|
|
||||||
"mcp__ide__getDiagnostics",
|
|
||||||
"Bash(npx tsc:*)",
|
|
||||||
"WebFetch(domain:sdk.vercel.ai)",
|
|
||||||
"Bash(npm run build:*)",
|
|
||||||
"Bash(npm outdated:*)"
|
|
||||||
],
|
|
||||||
"deny": [],
|
|
||||||
"ask": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -72,7 +72,10 @@ When using edit_diagram tool:
|
|||||||
- Example GOOD edit: {"search": " <mxCell id=\"2\" value=\"Old Text\">", "replace": " <mxCell id=\"2\" value=\"New Text\">"}
|
- Example GOOD edit: {"search": " <mxCell id=\"2\" value=\"Old Text\">", "replace": " <mxCell id=\"2\" value=\"New Text\">"}
|
||||||
- Example BAD edit: Including 10+ unchanged lines just to change one attribute
|
- Example BAD edit: Including 10+ unchanged lines just to change one attribute
|
||||||
- For multiple changes, use separate edits: [{"search": "line1", "replace": "new1"}, {"search": "line2", "replace": "new2"}]
|
- For multiple changes, use separate edits: [{"search": "line1", "replace": "new1"}, {"search": "line2", "replace": "new2"}]
|
||||||
- CRITICAL: If edit_diagram fails because the search pattern cannot be found, fall back to using display_diagram to regenerate the entire diagram with your changes. Do NOT keep trying edit_diagram with different search patterns.
|
- RETRY POLICY: If edit_diagram fails because the search pattern cannot be found:
|
||||||
|
* You may retry edit_diagram up to 3 times with adjusted search patterns
|
||||||
|
* After 3 failed attempts, you MUST fall back to using display_diagram to regenerate the entire diagram
|
||||||
|
* The error message will indicate how many retries remain
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const lastMessage = messages[messages.length - 1];
|
const lastMessage = messages[messages.length - 1];
|
||||||
|
|||||||
@@ -98,10 +98,18 @@ export default function ChatPanel() {
|
|||||||
|
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
|
|
||||||
|
// Provide detailed error with current diagram XML
|
||||||
addToolResult({
|
addToolResult({
|
||||||
tool: "edit_diagram",
|
tool: "edit_diagram",
|
||||||
toolCallId: toolCall.toolCallId,
|
toolCallId: toolCall.toolCallId,
|
||||||
output: `Failed to edit diagram: ${errorMessage}`,
|
output: `Edit failed: ${errorMessage}
|
||||||
|
|
||||||
|
Current diagram XML:
|
||||||
|
\`\`\`xml
|
||||||
|
${currentXml}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
Please retry with an adjusted search pattern or use display_diagram if retries are exhausted.`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user