console: label linter and llm actions
This commit is contained in:
+42
-12
@@ -471,9 +471,10 @@
|
|||||||
</textarea>
|
</textarea>
|
||||||
<div style="margin-top:6px; display:flex; gap:6px; flex-wrap:wrap;">
|
<div style="margin-top:6px; display:flex; gap:6px; flex-wrap:wrap;">
|
||||||
<button class="btn ghost" id="c-ai-btn" onclick="aiCheck('c-code','c-lang','c-ai-result')">🔍 Проверить
|
<button class="btn ghost" id="c-ai-btn" onclick="aiCheck('c-code','c-lang','c-ai-result')">🔍 Проверить
|
||||||
синтаксис</button>
|
синтаксис линтером</button>
|
||||||
<button class="btn ghost" id="c-gen-btn" onclick="showGenPrompt()">✨ Сгенерировать код</button>
|
<button class="btn ghost" id="c-gen-btn" onclick="showGenPrompt()">✨ Сгенерировать код LLM</button>
|
||||||
<button class="btn ghost" id="c-exp-btn" onclick="aiExplain('c-code','c-lang','c-ai-result')">📖 Что
|
<button class="btn ghost" id="c-exp-btn" onclick="aiExplain('c-code','c-lang','c-ai-result')">📖 LLM:
|
||||||
|
Что
|
||||||
делает?</button>
|
делает?</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="c-gen-prompt" style="display:none; margin-top:8px; display:none; gap:6px; align-items:center;">
|
<div id="c-gen-prompt" style="display:none; margin-top:8px; display:none; gap:6px; align-items:center;">
|
||||||
@@ -481,7 +482,7 @@
|
|||||||
placeholder="Что должна делать функция? (напр: принять JSON, вернуть сумму чисел)" style="flex:1; background:#2a2a42; border:1px solid #3a3a5c; border-radius:4px;
|
placeholder="Что должна делать функция? (напр: принять JSON, вернуть сумму чисел)" style="flex:1; background:#2a2a42; border:1px solid #3a3a5c; border-radius:4px;
|
||||||
color:#cdd6f4; padding:6px 8px; font-size:.82rem; outline:none; width:100%;"
|
color:#cdd6f4; padding:6px 8px; font-size:.82rem; outline:none; width:100%;"
|
||||||
onkeydown="if(event.key==='Enter')aiGenerate()" />
|
onkeydown="if(event.key==='Enter')aiGenerate()" />
|
||||||
<button class="btn" onclick="aiGenerate()" style="white-space:nowrap;">▶ Генерировать</button>
|
<button class="btn" onclick="aiGenerate()" style="white-space:nowrap;">▶ Генерировать LLM</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="c-ai-result"
|
<div id="c-ai-result"
|
||||||
style="display:none;margin-top:8px;padding:10px 12px;border-radius:6px;font-size:13px;line-height:1.5;white-space:pre-wrap;font-family:monospace;">
|
style="display:none;margin-top:8px;padding:10px 12px;border-radius:6px;font-size:13px;line-height:1.5;white-space:pre-wrap;font-family:monospace;">
|
||||||
@@ -526,8 +527,9 @@
|
|||||||
<textarea id="e-code"></textarea>
|
<textarea id="e-code"></textarea>
|
||||||
<div style="margin-top:6px; display:flex; gap:6px; flex-wrap:wrap;">
|
<div style="margin-top:6px; display:flex; gap:6px; flex-wrap:wrap;">
|
||||||
<button class="btn ghost" id="e-ai-btn" onclick="aiCheck('e-code','e-lang-hidden','e-ai-result')">🔍
|
<button class="btn ghost" id="e-ai-btn" onclick="aiCheck('e-code','e-lang-hidden','e-ai-result')">🔍
|
||||||
Проверить синтаксис</button>
|
Проверить синтаксис линтером</button>
|
||||||
<button class="btn ghost" id="e-exp-btn" onclick="aiExplain('e-code','e-lang-hidden','e-ai-result')">📖
|
<button class="btn ghost" id="e-exp-btn" onclick="aiExplain('e-code','e-lang-hidden','e-ai-result')">📖
|
||||||
|
LLM:
|
||||||
Что делает?</button>
|
Что делает?</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="e-ai-result"
|
<div id="e-ai-result"
|
||||||
@@ -641,6 +643,34 @@
|
|||||||
return Math.round(n);
|
return Math.round(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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('<?php') === 0) {
|
||||||
|
var rest = body.slice(5);
|
||||||
|
rest = rest.replace(/^\r?\n/, '');
|
||||||
|
return '<?php\n' + warning + '\n' + rest;
|
||||||
|
}
|
||||||
|
return warning + '\n' + body;
|
||||||
|
}
|
||||||
|
|
||||||
function triggerByFn(fnName) {
|
function triggerByFn(fnName) {
|
||||||
return (S.triggers || []).find(function (t) {
|
return (S.triggers || []).find(function (t) {
|
||||||
return t.spec && t.spec.functionref && t.spec.functionref.name === fnName;
|
return t.spec && t.spec.functionref && t.spec.functionref.name === fnName;
|
||||||
@@ -771,8 +801,8 @@
|
|||||||
try {
|
try {
|
||||||
const name = S.currentEdit.name;
|
const name = S.currentEdit.name;
|
||||||
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name) + '/code', 'PUT', {
|
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name) + '/code', 'PUT', {
|
||||||
code: document.getElementById('e-code').value,
|
code: document.getElementById('e-code').value,
|
||||||
timeout: parseTimeout(document.getElementById('e-timeout').value)
|
timeout: parseTimeout(document.getElementById('e-timeout').value)
|
||||||
});
|
});
|
||||||
closeEdit();
|
closeEdit();
|
||||||
progress.stop('\u041a\u043e\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d: ' + name, 'ok');
|
progress.stop('\u041a\u043e\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d: ' + name, 'ok');
|
||||||
@@ -985,7 +1015,7 @@
|
|||||||
resEl.style.display = 'block';
|
resEl.style.display = 'block';
|
||||||
resEl.style.background = 'var(--bg-alt)';
|
resEl.style.background = 'var(--bg-alt)';
|
||||||
resEl.style.color = 'var(--fg)';
|
resEl.style.color = 'var(--fg)';
|
||||||
resEl.textContent = 'Отправляю код в LLM...';
|
resEl.textContent = 'Проверяю код линтером...';
|
||||||
try {
|
try {
|
||||||
var data = await requestJSON(API_BASE + '/ai/check', 'POST', { language: lang, code: code });
|
var data = await requestJSON(API_BASE + '/ai/check', 'POST', { language: lang, code: code });
|
||||||
resEl.style.background = data.ok ? '#1a3a1a' : '#3a1a1a';
|
resEl.style.background = data.ok ? '#1a3a1a' : '#3a1a1a';
|
||||||
@@ -997,7 +1027,7 @@
|
|||||||
resEl.textContent = 'Ошибка: ' + e.message;
|
resEl.textContent = 'Ошибка: ' + e.message;
|
||||||
} finally {
|
} finally {
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
btn.textContent = '🔍 Проверить синтаксис';
|
btn.textContent = '🔍 Проверить синтаксис линтером';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1275,7 +1305,7 @@
|
|||||||
var q = 'Напиши функцию Fission на ' + lang + ' с именем "' + name + '". Функция должна: ' + desc + '. Верни только чистый код без пояснений и без markdown-блоков.';
|
var q = 'Напиши функцию Fission на ' + lang + ' с именем "' + name + '". Функция должна: ' + desc + '. Верни только чистый код без пояснений и без markdown-блоков.';
|
||||||
var d = await requestJSON('/console/api/ai/ask', 'POST', { question: q });
|
var d = await requestJSON('/console/api/ai/ask', 'POST', { question: q });
|
||||||
var code = (d.answer || '').replace(/^```[\w]*\n?/, '').replace(/\n?```$/, '');
|
var code = (d.answer || '').replace(/^```[\w]*\n?/, '').replace(/\n?```$/, '');
|
||||||
document.getElementById('c-code').value = code;
|
document.getElementById('c-code').value = addLLMWarning(code, lang);
|
||||||
document.getElementById('c-gen-prompt').style.display = 'none';
|
document.getElementById('c-gen-prompt').style.display = 'none';
|
||||||
resEl.style.background = '#1a3a1a'; resEl.style.color = '#8f8';
|
resEl.style.background = '#1a3a1a'; resEl.style.color = '#8f8';
|
||||||
resEl.textContent = 'Код сгенерирован и вставлен.';
|
resEl.textContent = 'Код сгенерирован и вставлен.';
|
||||||
@@ -1283,7 +1313,7 @@
|
|||||||
resEl.style.background = '#3a2a00'; resEl.style.color = '#ffa';
|
resEl.style.background = '#3a2a00'; resEl.style.color = '#ffa';
|
||||||
resEl.textContent = 'Ошибка: ' + e.message;
|
resEl.textContent = 'Ошибка: ' + e.message;
|
||||||
} finally {
|
} finally {
|
||||||
btn.disabled = false; btn.textContent = '✨ Сгенерировать код';
|
btn.disabled = false; btn.textContent = '✨ Сгенерировать код LLM';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function aiExplain(codeId, langId, resultId) {
|
async function aiExplain(codeId, langId, resultId) {
|
||||||
@@ -1305,7 +1335,7 @@
|
|||||||
resEl.style.background = '#3a2a00'; resEl.style.color = '#ffa';
|
resEl.style.background = '#3a2a00'; resEl.style.color = '#ffa';
|
||||||
resEl.textContent = 'Ошибка: ' + e.message;
|
resEl.textContent = 'Ошибка: ' + e.message;
|
||||||
} finally {
|
} finally {
|
||||||
btn.disabled = false; btn.textContent = '📖 Что делает?';
|
btn.disabled = false; btn.textContent = '📖 LLM: Что делает?';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// end ai/ask feature
|
// end ai/ask feature
|
||||||
|
|||||||
Reference in New Issue
Block a user