Skip to content

Commit bfe80e8

Browse files
Add debug logging for ChartJS detection and remove preview logic
Changes: 1. Added comprehensive debug logging: - Log visualizerAI.chart_library on page load - Log chart_library being sent in AJAX request - Show library name in welcome message (Chart.js vs Google Charts) 2. Removed preview logic - always auto-apply: - Removed detectActionIntent function - All AI configurations now auto-apply immediately - Configs are merged with existing settings (safe) - No more "preview" step or "apply" confirmation needed This will help debug why ChartJS charts aren't being recognized, and improves UX by removing unnecessary preview step. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1c8f527 commit bfe80e8

1 file changed

Lines changed: 11 additions & 84 deletions

File tree

js/ai-config.js

Lines changed: 11 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
if (typeof visualizerAI !== 'undefined') {
1111
console.log('visualizerAI data:', visualizerAI);
12+
console.log('Chart Library:', visualizerAI.chart_library);
13+
console.log('Chart Type:', visualizerAI.chart_type);
1214

1315
// Show welcome message with animation
16+
var libraryName = visualizerAI.chart_library && visualizerAI.chart_library.toLowerCase() === 'chartjs' ? 'Chart.js' : 'Google Charts';
1417
setTimeout(function() {
15-
addAIMessage('👋 Hello! I\'m your AI chart assistant. I can help you customize this ' + visualizerAI.chart_type + ' chart.\n\n✨ Try a Quick Action above, choose a Preset, or ask me anything!');
18+
addAIMessage('👋 Hello! I\'m your AI chart assistant. I can help you customize this ' + visualizerAI.chart_type + ' chart (' + libraryName + ').\n\n✨ Try a Quick Action above, choose a Preset, or ask me anything!');
1619
}, 300);
1720
} else {
1821
console.error('visualizerAI is not defined!');
@@ -110,6 +113,7 @@
110113
};
111114

112115
console.log('Request data:', requestData);
116+
console.log('Sending chart_library:', requestData.chart_library);
113117

114118
$.ajax({
115119
url: visualizerAI.ajaxurl,
@@ -126,28 +130,15 @@
126130
// Add AI response to chat
127131
addAIMessage(data.message);
128132

129-
// Intelligently handle configuration if provided
133+
// Auto-apply configuration if provided (no preview, just apply)
130134
if (data.configuration) {
131135
currentConfig = data.configuration;
132136

133-
// Detect user intent: is this an action request or just a question?
134-
var isActionRequest = detectActionIntent(prompt);
135-
136-
if (isActionRequest) {
137-
// User wants to make a change - auto-apply configuration
138-
console.log('Detected action request - auto-applying configuration');
139-
addConfigPreview(data.configuration);
140-
141-
// Auto-apply after a short delay to let user see the preview
142-
setTimeout(function() {
143-
applyConfiguration(true); // Show success message
144-
}, 500);
145-
} else {
146-
// User is asking for information - show preview but don't apply
147-
console.log('Detected informational request - showing preview only');
148-
addConfigPreview(data.configuration);
149-
addAIMessage('ℹ️ This is a preview of what the configuration would look like. If you want to apply it, just ask me to make the change!');
150-
}
137+
console.log('Configuration received - auto-applying');
138+
addConfigPreview(data.configuration);
139+
140+
// Auto-apply immediately
141+
applyConfiguration(true); // Show success message
151142
}
152143

153144
// Add to history
@@ -328,70 +319,6 @@
328319
}
329320
}
330321

331-
function detectActionIntent(prompt) {
332-
// Convert to lowercase for easier matching
333-
var lowerPrompt = prompt.toLowerCase();
334-
335-
// Strong action indicators - if these are present, user wants to make a change
336-
var actionKeywords = [
337-
'make', 'change', 'set', 'update', 'modify', 'create', 'add',
338-
'remove', 'delete', 'apply', 'use', 'turn', 'enable', 'disable',
339-
'increase', 'decrease', 'adjust', 'switch', 'convert', 'transform',
340-
'put', 'give', 'let\'s', 'i want', 'i need', 'please'
341-
];
342-
343-
// Question indicators - if these are primary, user is asking for information
344-
var questionKeywords = [
345-
'what can', 'what are', 'what\'s', 'how can', 'how do',
346-
'which', 'show me', 'tell me', 'explain', 'describe',
347-
'suggest', 'recommend', 'list', 'options', 'possibilities',
348-
'examples', 'ideas', 'help'
349-
];
350-
351-
// Check if prompt starts with a question word (strong indicator of informational query)
352-
var startsWithQuestion = /^(what|how|which|could|should|can|would|where|when|why)\b/i.test(prompt);
353-
354-
// Count action and question keywords
355-
var actionCount = 0;
356-
var questionCount = 0;
357-
358-
actionKeywords.forEach(function(keyword) {
359-
if (lowerPrompt.indexOf(keyword) !== -1) {
360-
actionCount++;
361-
}
362-
});
363-
364-
questionKeywords.forEach(function(keyword) {
365-
if (lowerPrompt.indexOf(keyword) !== -1) {
366-
questionCount++;
367-
}
368-
});
369-
370-
// Decision logic:
371-
// 1. If starts with question word and has question keywords, it's informational
372-
if (startsWithQuestion && questionCount > 0) {
373-
return false;
374-
}
375-
376-
// 2. If has action keywords but no question keywords, it's an action
377-
if (actionCount > 0 && questionCount === 0) {
378-
return true;
379-
}
380-
381-
// 3. If has more action keywords than question keywords, it's likely an action
382-
if (actionCount > questionCount) {
383-
return true;
384-
}
385-
386-
// 4. If ends with a question mark, it's probably informational
387-
if (prompt.trim().endsWith('?')) {
388-
return false;
389-
}
390-
391-
// 5. Default: if has any action keywords, treat as action
392-
return actionCount > 0;
393-
}
394-
395322
function escapeHtml(text) {
396323
var map = {
397324
'&': '&amp;',

0 commit comments

Comments
 (0)