From 1f1afa95e195ed59aaf0e561d1b6da14cd2019b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 2 May 2026 17:30:33 +0400 Subject: [PATCH] refactor(ui): step9 - extract ai.js (llmGeneratedWarning, addLLMWarning, aiCheck, aiGenerate, aiExplain, askAssistant, toggleAssistant, showGenPrompt) --- console/ui/index.html | 217 +----------------------------------------- console/ui/js/ai.js | 149 +++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 216 deletions(-) create mode 100644 console/ui/js/ai.js diff --git a/console/ui/index.html b/console/ui/index.html index 1e76ec3..792201f 100644 --- a/console/ui/index.html +++ b/console/ui/index.html @@ -20,6 +20,7 @@ + @@ -416,131 +417,6 @@ currentInvoke: null }; - function llmGeneratedWarning(lang) { - var text = 'Сделано LLM. Не доверяй, проверяй!'; - switch (lang) { - case 'php': - return '// ' + text; - case 'nodejs': - case 'go': - return '// ' + text; - case 'ruby': - case 'python': - default: - return '# ' + text; - } - } - - function addLLMWarning(code, lang) { - var body = String(code || '').replace(/^\s+/, ''); - var warning = llmGeneratedWarning(lang); - if (!body) return warning; - if (body.indexOf(warning) === 0) return body; - if (lang === 'php' && body.indexOf('' + h(m) + ''; }).join(''); - const cron = (timeTrig.spec && timeTrig.spec.cron) || ''; - const cronCell = cron ? '' + h(cron) + '' : ''; - const createdAt = ann['fission-console/created-at'] || meta.creationTimestamp || '-'; - const updatedAt = ann['fission-console/updated-at'] || createdAt; - var isGo = /go[-_]env/.test(env); - var isTf = /^tf-/.test(name); - var tfBadge = (isGo || isTf) ? 'TF ' : ''; - var actions = tfBadge + - ' ' + - ' ' + - ''; - return '' + - '' + h(name) + '' + - '' + h(env) + '' + - '' + h(pkg) + '' + - '' + timestampCell(createdAt) + '' + - '' + timestampCell(updatedAt) + '' + - '' + h(route) + '' + - '' + chips + '' + - '' + cronCell + '' + - '' + actions + '' + - ''; - }).join(''); - - document.getElementById('fn-rows').innerHTML = rows || '\u041d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439'; - if (!rows) { - document.getElementById('fn-rows').innerHTML = '\u041d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439'; - } - } catch (e) { - document.getElementById('fn-rows').innerHTML = 'Load error: ' + e.message + ''; - showStatus('\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438: ' + e.message, 'err'); - } - } - - async function aiCheck(codeId, langId, resultId) { - var code = document.getElementById(codeId).value.trim(); - var lang = (document.getElementById(langId) ? document.getElementById(langId).value : '') || 'python'; - var resEl = document.getElementById(resultId); - if (!code) { resEl.style.display = 'block'; resEl.style.background = 'var(--bg-alt)'; resEl.textContent = 'Введите код для проверки.'; return; } - var btnId = codeId === 'c-code' ? 'c-ai-btn' : 'e-ai-btn'; - var btn = document.getElementById(btnId); - btn.disabled = true; - btn.textContent = '⏳ Проверяю...'; - resEl.style.display = 'block'; - resEl.style.background = 'var(--bg-alt)'; - resEl.style.color = 'var(--fg)'; - resEl.textContent = 'Проверяю код линтером...'; - try { - var data = await requestJSON(API_BASE + '/ai/check', 'POST', { language: lang, code: code }); - resEl.style.background = data.ok ? '#1a3a1a' : '#3a1a1a'; - resEl.style.color = data.ok ? '#8f8' : '#f88'; - resEl.textContent = data.result || '(пустой ответ)'; - } catch (e) { - resEl.style.background = '#3a2a00'; - resEl.style.color = '#ffa'; - resEl.textContent = 'Ошибка: ' + e.message; - } finally { - btn.disabled = false; - btn.textContent = '🔍 Проверить синтаксис линтером'; - } - } - var _initPolling = false; var _initTickBusy = false; var _initStartedAt = 0; @@ -758,97 +634,6 @@ - - diff --git a/console/ui/js/ai.js b/console/ui/js/ai.js new file mode 100644 index 0000000..56f8719 --- /dev/null +++ b/console/ui/js/ai.js @@ -0,0 +1,149 @@ +/* ai.js — AI/LLM функции: проверка, генерация, объяснение, ассистент */ + +function llmGeneratedWarning(lang) { + var text = 'Сделано LLM. Не доверяй, проверяй!'; + switch (lang) { + case 'php': + return '// ' + text; + case 'nodejs': + case 'go': + return '// ' + text; + case 'ruby': + case 'python': + default: + return '# ' + text; + } +} + +function addLLMWarning(code, lang) { + var body = String(code || '').replace(/^\s+/, ''); + var warning = llmGeneratedWarning(lang); + if (!body) return warning; + if (body.indexOf(warning) === 0) return body; + if (lang === 'php' && body.indexOf('