feat: improve diagram edit tracking and cache handling

- Track lastGeneratedXml to detect user modifications
- Only send XML context when needed (saves tokens)
- Fix cached response streaming to include tool output
- Add debug logging for model messages and steps
- Enable multi-step tool execution with maxSteps: 5
This commit is contained in:
dayuan.jiang
2025-12-02 19:11:23 +09:00
parent e2adfb49aa
commit a20d14ef9d
5 changed files with 120 additions and 28 deletions

View File

@@ -190,9 +190,15 @@ export function replaceXMLParts(
let result = formatXML(xmlContent);
let lastProcessedIndex = 0;
console.log('[replaceXMLParts] Input XML length:', xmlContent.length);
console.log('[replaceXMLParts] Formatted XML length:', result.length);
console.log('[replaceXMLParts] Number of edits:', searchReplacePairs.length);
for (const { search, replace } of searchReplacePairs) {
// Also format the search content for consistency
const formattedSearch = formatXML(search);
console.log('[replaceXMLParts] Search pattern (first 200):', search.substring(0, 200));
console.log('[replaceXMLParts] Formatted search (first 200):', formattedSearch.substring(0, 200));
const searchLines = formattedSearch.split('\n');
// Split into lines for exact line matching
@@ -276,6 +282,9 @@ export function replaceXMLParts(
}
if (!matchFound) {
console.log('[replaceXMLParts] SEARCH FAILED!');
console.log('[replaceXMLParts] Current XML content:\n', result);
console.log('[replaceXMLParts] Search pattern:\n', formattedSearch);
throw new Error(`Search pattern not found in the diagram. The pattern may not exist in the current structure.`);
}