|
9 | 9 |
|
10 | 10 | if (typeof visualizerAI !== 'undefined') { |
11 | 11 | console.log('visualizerAI data:', visualizerAI); |
| 12 | + console.log('Chart Library:', visualizerAI.chart_library); |
| 13 | + console.log('Chart Type:', visualizerAI.chart_type); |
12 | 14 |
|
13 | 15 | // Show welcome message with animation |
| 16 | + var libraryName = visualizerAI.chart_library && visualizerAI.chart_library.toLowerCase() === 'chartjs' ? 'Chart.js' : 'Google Charts'; |
14 | 17 | 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!'); |
16 | 19 | }, 300); |
17 | 20 | } else { |
18 | 21 | console.error('visualizerAI is not defined!'); |
|
110 | 113 | }; |
111 | 114 |
|
112 | 115 | console.log('Request data:', requestData); |
| 116 | + console.log('Sending chart_library:', requestData.chart_library); |
113 | 117 |
|
114 | 118 | $.ajax({ |
115 | 119 | url: visualizerAI.ajaxurl, |
|
126 | 130 | // Add AI response to chat |
127 | 131 | addAIMessage(data.message); |
128 | 132 |
|
129 | | - // Intelligently handle configuration if provided |
| 133 | + // Auto-apply configuration if provided (no preview, just apply) |
130 | 134 | if (data.configuration) { |
131 | 135 | currentConfig = data.configuration; |
132 | 136 |
|
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 |
151 | 142 | } |
152 | 143 |
|
153 | 144 | // Add to history |
|
328 | 319 | } |
329 | 320 | } |
330 | 321 |
|
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 | | - |
395 | 322 | function escapeHtml(text) { |
396 | 323 | var map = { |
397 | 324 | '&': '&', |
|
0 commit comments