fix: messages d'erreur AI clairs (401→clé invalide) + succès toast
This commit is contained in:
parent
6c7d7b4506
commit
aacdb1d42f
@ -239,7 +239,10 @@ export async function createAIToolbar(container, getEditorView) {
|
|||||||
try {
|
try {
|
||||||
const result = await aiAction('inline-complete', text);
|
const result = await aiAction('inline-complete', text);
|
||||||
replaceSelection(v, result, 'append');
|
replaceSelection(v, result, 'append');
|
||||||
} catch (e) { showToast('AI: ' + e.message, 'error'); }
|
showToast('AI: complétion ajoutée', 'success');
|
||||||
|
} catch (e) {
|
||||||
|
showToast('AI: ' + (String(e.message || e).includes('401') ? 'clé API invalide' : e.message), 'error');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Edit menu ──
|
// ── Edit menu ──
|
||||||
@ -296,7 +299,10 @@ export async function createAIToolbar(container, getEditorView) {
|
|||||||
try {
|
try {
|
||||||
const result = await aiAction('rewrite', text, { instruction });
|
const result = await aiAction('rewrite', text, { instruction });
|
||||||
replaceSelection(v, result);
|
replaceSelection(v, result);
|
||||||
} catch (e) { showToast('AI: ' + e.message, 'error'); }
|
showToast('AI: texte réécrit', 'success');
|
||||||
|
} catch (e) {
|
||||||
|
showToast('AI: ' + (String(e.message || e).includes('401') ? 'clé API invalide' : e.message), 'error');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Toolbox menu ──
|
// ── Toolbox menu ──
|
||||||
@ -324,11 +330,24 @@ export async function createAIToolbar(container, getEditorView) {
|
|||||||
const v = ev();
|
const v = ev();
|
||||||
if (!v) return;
|
if (!v) return;
|
||||||
const text = getSelection(v);
|
const text = getSelection(v);
|
||||||
if (!text.trim()) return;
|
if (!text.trim()) {
|
||||||
|
showToast('AI: sélectionnez du texte à traiter', 'warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const result = await aiAction(endpoint, text, extra);
|
const result = await aiAction(endpoint, text, extra);
|
||||||
replaceSelection(v, result, mode);
|
replaceSelection(v, result, mode);
|
||||||
} catch (e) { showToast('AI: ' + e.message, 'error'); }
|
showToast('AI: texte traité', 'success');
|
||||||
|
} catch (e) {
|
||||||
|
const msg = String(e.message || e);
|
||||||
|
if (msg.includes('401')) {
|
||||||
|
showToast('AI: clé API invalide. Vérifiez DEEPSEEK_API_KEY dans .env', 'error');
|
||||||
|
} else if (msg.includes('402') || msg.includes('429')) {
|
||||||
|
showToast('AI: quota dépassé ou paiement requis', 'error');
|
||||||
|
} else {
|
||||||
|
showToast('AI: ' + msg, 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Keyboard shortcut Ctrl+J for inline completion ──
|
// ── Keyboard shortcut Ctrl+J for inline completion ──
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user