aboutsummaryrefslogtreecommitdiff
path: root/chat
diff options
context:
space:
mode:
Diffstat (limited to 'chat')
-rw-r--r--chat/chat-modules.js16
-rw-r--r--chat/chat-ui.html5
2 files changed, 18 insertions, 3 deletions
diff --git a/chat/chat-modules.js b/chat/chat-modules.js
index 8483d48..26ad115 100644
--- a/chat/chat-modules.js
+++ b/chat/chat-modules.js
@@ -296,7 +296,15 @@ async function generateModuleWithAI() {
if (!response.ok) throw new Error('AI request failed');
var data = await response.json();
- var result = JSON.parse(data.response);
+ var result;
+ try {
+ result = JSON.parse(data.response);
+ } catch (e) {
+ showToast('AI response was not valid JSON. Try a different model.');
+ btn.disabled = false;
+ btn.textContent = 'Generate with AI';
+ return;
+ }
document.getElementById('moduleName').value = result.name || '';
document.getElementById('moduleDesc').value = result.desc || '';
@@ -361,5 +369,7 @@ function importModules() {
// Load modules from storage (runs after core.js)
-// Auto-init once DOM + deps are ready
-document.addEventListener('DOMContentLoaded', function() { loadModules(); });
+// Auto-init — DOM is already ready when this script loads dynamically
+if (document.getElementById('chat-overlay')) {
+ loadModules();
+}
diff --git a/chat/chat-ui.html b/chat/chat-ui.html
index 5eedce6..9f6dd4b 100644
--- a/chat/chat-ui.html
+++ b/chat/chat-ui.html
@@ -95,6 +95,11 @@
<label>Commands (comma-separated)</label>
<input type="text" id="moduleCommands" placeholder="e.g., /search, /find, /web">
</div>
+ <div class="form-group" style="margin-top:16px;padding-top:16px;border-top:1px solid var(--border);">
+ <label>Generate with AI</label>
+ <textarea id="aiModuleDesc" placeholder="Describe the module you want... e.g. A code review assistant that checks for security issues" style="min-height:60px;"></textarea>
+ <button class="btn btn-secondary" style="width:100%;margin-top:8px;" onclick="generateModuleWithAI(event)">🤖 Generate with AI</button>
+ </div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" onclick="closeModuleModal()">Cancel</button>