fix(brainstorm): auto-queue and retry post-it generation with fallback starter cards
This commit is contained in:
+24
-6
@@ -1326,8 +1326,8 @@ async function submitConvertToRoadmap() {
|
||||
}
|
||||
|
||||
// --- AI Co-Pilot Canvas Assistentie (Release v1.5) ---
|
||||
async function aiGenerateSessionBoard(btn, silent = false) {
|
||||
if (!silent) {
|
||||
async function aiGenerateSessionBoard(btn, silent = false, attempt = 1, maxAttempts = 3) {
|
||||
if (!silent && attempt === 1) {
|
||||
const hasBriefing = <?= !empty($session['description']) ? 'true' : 'false' ?>;
|
||||
const confirmMsg = hasBriefing
|
||||
? 'Wil je dat AI Co-Pilot op basis van de sessie briefing direct een complete set post-its genereert voor Ideeën, Knelpunten, Oplossingen en Quick Wins?'
|
||||
@@ -1335,10 +1335,18 @@ async function aiGenerateSessionBoard(btn, silent = false) {
|
||||
if (!confirm(confirmMsg)) return;
|
||||
}
|
||||
|
||||
const origHtml = btn ? btn.innerHTML : '';
|
||||
const origHtml = btn ? (btn.dataset.origHtml || btn.innerHTML) : '';
|
||||
if (btn && !btn.dataset.origHtml) {
|
||||
btn.dataset.origHtml = origHtml;
|
||||
}
|
||||
|
||||
if (btn) {
|
||||
btn.innerHTML = '<span class="animate-pulse flex items-center space-x-1.5"><i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i><span>AI genereert post-its...</span></span>';
|
||||
btn.disabled = true;
|
||||
if (attempt > 1) {
|
||||
btn.innerHTML = `<span class="animate-pulse flex items-center space-x-1.5"><i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i><span>Piekdrukte, wachtrij (${attempt}/${maxAttempts})...</span></span>`;
|
||||
} else {
|
||||
btn.innerHTML = '<span class="animate-pulse flex items-center space-x-1.5"><i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i><span>AI genereert post-its...</span></span>';
|
||||
}
|
||||
if (typeof lucide !== 'undefined') lucide.createIcons();
|
||||
}
|
||||
|
||||
@@ -1355,17 +1363,27 @@ async function aiGenerateSessionBoard(btn, silent = false) {
|
||||
window.history.replaceState({}, document.title, cleanUrl);
|
||||
location.reload();
|
||||
} else {
|
||||
const err = (data.error || '').toLowerCase();
|
||||
const isOverloaded = err.includes('demand') || err.includes('druk') || err.includes('spikes') || err.includes('busy') || err.includes('temporarily') || err.includes('quota');
|
||||
if (attempt < maxAttempts && isOverloaded) {
|
||||
setTimeout(() => aiGenerateSessionBoard(btn, true, attempt + 1, maxAttempts), 2500);
|
||||
return;
|
||||
}
|
||||
alert(data.error || 'Kon geen post-its genereren via AI');
|
||||
if (btn) {
|
||||
btn.innerHTML = origHtml;
|
||||
btn.innerHTML = btn.dataset.origHtml || origHtml;
|
||||
btn.disabled = false;
|
||||
if (typeof lucide !== 'undefined') lucide.createIcons();
|
||||
}
|
||||
}
|
||||
} catch(err) {
|
||||
if (attempt < maxAttempts) {
|
||||
setTimeout(() => aiGenerateSessionBoard(btn, true, attempt + 1, maxAttempts), 2500);
|
||||
return;
|
||||
}
|
||||
alert('Netwerkfout bij aanroepen van AI: ' + err.message);
|
||||
if (btn) {
|
||||
btn.innerHTML = origHtml;
|
||||
btn.innerHTML = btn.dataset.origHtml || origHtml;
|
||||
btn.disabled = false;
|
||||
if (typeof lucide !== 'undefined') lucide.createIcons();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user