1623 lines
64 KiB
HTML
1623 lines
64 KiB
HTML
<!doctype html>
|
||
<html lang="ru">
|
||
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>NUBES Fission Console</title>
|
||
<link rel="icon" type="image/png"
|
||
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAA4ZJREFUeJztm8+Lm0UYxz/fySZUoWIrVtbmXfyBP05Fa3e3rogsglJRK0p7E2svnrz6B3gQ8eRJFooXET14KKJ4FUQo3UQQ9CRC6W4WQW0VXZduTd7HQ9c22bzbTCY/ZpO8n0syb56Z+c437zPvhMzIzJhkXGwBsckNiC0gNrkBsQXEZsonSJLj4GNPgb2ACo9j9gDOvrSV6qkB6+sJ6WSJ5MIxUo4h5sDuI9U7tlZ57/+YTAN0zyOPUi+9jOxJxMOUj9wJOBBg117QvqGMwhNpcQ/J+rOkPIc0j+xeytyGsaWXa2+kvc312gxQMleHYgFtrQ9GYJmgmSfup3z15xuDNW/dGXOAjd680NgshlYdvcH2mfEwQIU0tOp4GNADuQGxBcRmPAyQgh/W42FAD+QGxBYQm/EwIF8HhJMbEFtAX3DreQqEkhsQW0BsxsMAlz8Gg8kNiC0gNuNhgJvK54BQcgNiC+gLhUlPgcuTbkAP5AbEFhCbcAOM4LyLitIW3eEGyP7qWUwMHFdaixNO1v4Av5pG8H/yfWfvesk7tq5GczHDAHnmtu727nTQbJYe8o51+qOl2BYgNv1a0iHvTgeNGq94x6buYnOx3YCU3/1asn06ePQZ744HiXTCO3a6/m1zsd0Ax/f+HTc+kU76598AUDL/LpjfjjWxYdXqRvOljDvAfezfO3dQvvCDtLjHu04f0czsaSx9y7uC8eP2S20GWO38Z+A7DwDwIOX135TMvylpKI9VJQv7lcx+hfEhurELsCPOfdDWVtZ5ASWzZ4GXArQ1QJfA/kTW6BhtLgX+7qL9IqTTmKa7GjgAumKry7dsv5q9Vfbfq29QLL1I9wulAtgB4ADmoy9kY4fodugAODuT2dpOJ0aUzH8E6asBXe0+zP5h7bvbzay+/aOdv+Ha8mnE5YEKGxqF17MGDzcxwMzqTBUWgc65vKuxT7cm9kx2TIHrATOzxzHOEpZ5sanYamXuZgEdJzlbqXyOmzrO6N0J56hVj3YK8prl7eK5L6g3DmFc6l3XEDCWbLWyYGYdf9h1TIGWYMmRHDlDaqcY0qKnO/Qr4oStLH/jXSPk4KSShf2ovoTZ80Db4iICv2D2ttWqS91WDDKgpYHy4adR8TWww8BdmN2KrOg5Zwoo+PV0">
|
||
<script>
|
||
if (window.location.protocol !== 'https:' && window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
|
||
window.location.replace('https://' + window.location.host + window.location.pathname + window.location.search + window.location.hash);
|
||
}
|
||
</script>
|
||
<style>
|
||
:root {
|
||
--bg-page: #001120;
|
||
--bg-surface: #001929;
|
||
--bg-navbar: #001c34;
|
||
--border: #0b2d50;
|
||
--accent: #1a7fd4;
|
||
--text-primary: #e2ecf6;
|
||
--text-secondary: #6b8eaa;
|
||
}
|
||
|
||
* {
|
||
box-sizing: border-box;
|
||
margin: 0;
|
||
padding: 0;
|
||
}
|
||
|
||
body {
|
||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
|
||
background: var(--bg-page);
|
||
color: var(--text-primary);
|
||
min-height: 100vh;
|
||
}
|
||
|
||
.navbar {
|
||
height: 56px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 0 20px;
|
||
background: var(--bg-navbar);
|
||
border-bottom: 1px solid var(--border);
|
||
}
|
||
|
||
.title {
|
||
font-weight: 700;
|
||
letter-spacing: .3px;
|
||
}
|
||
|
||
.brand {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.brand-mark {
|
||
width: 30px;
|
||
height: 30px;
|
||
border-radius: 8px;
|
||
background: linear-gradient(135deg, #009dff 0%, #0055d4 100%);
|
||
color: #fff;
|
||
display: grid;
|
||
place-items: center;
|
||
font-size: 14px;
|
||
font-weight: 800;
|
||
letter-spacing: .02em;
|
||
box-shadow: 0 6px 18px rgba(0, 125, 255, .35);
|
||
}
|
||
|
||
.brand-text {
|
||
display: flex;
|
||
flex-direction: column;
|
||
line-height: 1.08;
|
||
}
|
||
|
||
.brand-text .nubes {
|
||
font-size: 12px;
|
||
letter-spacing: .22em;
|
||
font-weight: 800;
|
||
color: #8bc7ff;
|
||
}
|
||
|
||
.brand-text .product {
|
||
font-size: 13px;
|
||
font-weight: 700;
|
||
letter-spacing: .04em;
|
||
}
|
||
|
||
.btn {
|
||
background: var(--accent);
|
||
color: #fff;
|
||
border: 0;
|
||
border-radius: 6px;
|
||
padding: 8px 12px;
|
||
cursor: pointer;
|
||
font-size: 13px;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.btn:disabled {
|
||
opacity: .6;
|
||
cursor: not-allowed;
|
||
}
|
||
|
||
.btn.danger {
|
||
background: #b43232;
|
||
}
|
||
|
||
.btn.ghost {
|
||
background: #0c2b49;
|
||
}
|
||
|
||
.wrap {
|
||
max-width: 1100px;
|
||
margin: 0 auto;
|
||
padding: 20px;
|
||
}
|
||
|
||
.grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||
gap: 12px;
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.card {
|
||
background: var(--bg-surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 14px;
|
||
}
|
||
|
||
.k {
|
||
color: var(--text-secondary);
|
||
font-size: 12px;
|
||
text-transform: uppercase;
|
||
letter-spacing: .06em;
|
||
}
|
||
|
||
.v {
|
||
font-size: 24px;
|
||
font-weight: 700;
|
||
margin-top: 6px;
|
||
}
|
||
|
||
.box {
|
||
background: var(--bg-surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 14px;
|
||
margin-top: 12px;
|
||
}
|
||
|
||
.toolbar {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
gap: 10px;
|
||
align-items: center;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
font-size: 13px;
|
||
margin-top: 8px;
|
||
}
|
||
|
||
th,
|
||
td {
|
||
text-align: left;
|
||
padding: 8px;
|
||
border-bottom: 1px solid #0b2a48;
|
||
}
|
||
|
||
.hint {
|
||
color: var(--text-secondary);
|
||
font-size: 12px;
|
||
margin-top: 8px;
|
||
}
|
||
|
||
.mono {
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.status {
|
||
margin-top: 10px;
|
||
padding: 9px 10px;
|
||
border-radius: 6px;
|
||
font-size: 13px;
|
||
background: #0c2b49;
|
||
border: 1px solid #1d486d;
|
||
display: none;
|
||
}
|
||
|
||
.status.ok {
|
||
background: #103625;
|
||
border-color: #236843;
|
||
}
|
||
|
||
.status.err {
|
||
background: #411d1d;
|
||
border-color: #7a2f2f;
|
||
}
|
||
|
||
.chip {
|
||
display: inline-block;
|
||
padding: 2px 7px;
|
||
border-radius: 999px;
|
||
border: 1px solid #1d486d;
|
||
background: #0c2b49;
|
||
font-size: 11px;
|
||
margin-right: 4px;
|
||
}
|
||
|
||
.modal {
|
||
position: fixed;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, .45);
|
||
display: none;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 16px;
|
||
}
|
||
|
||
.modal.open {
|
||
display: flex;
|
||
}
|
||
|
||
.panel {
|
||
width: min(820px, 100%);
|
||
max-height: 90vh;
|
||
overflow: auto;
|
||
background: var(--bg-surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: 10px;
|
||
padding: 16px;
|
||
}
|
||
|
||
.panel h3 {
|
||
margin-bottom: 10px;
|
||
font-size: 16px;
|
||
}
|
||
|
||
.row {
|
||
display: flex;
|
||
gap: 10px;
|
||
margin-bottom: 10px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.field {
|
||
flex: 1;
|
||
min-width: 180px;
|
||
}
|
||
|
||
label {
|
||
display: block;
|
||
margin-bottom: 4px;
|
||
font-size: 12px;
|
||
color: var(--text-secondary);
|
||
}
|
||
|
||
input,
|
||
select,
|
||
textarea {
|
||
width: 100%;
|
||
border: 1px solid #1d486d;
|
||
background: #03192c;
|
||
color: var(--text-primary);
|
||
border-radius: 6px;
|
||
padding: 8px 10px;
|
||
font-size: 13px;
|
||
}
|
||
|
||
textarea {
|
||
min-height: 220px;
|
||
resize: vertical;
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||
}
|
||
|
||
.actions {
|
||
display: flex;
|
||
gap: 8px;
|
||
justify-content: flex-end;
|
||
margin-top: 8px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.nowrap {
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.help-section {
|
||
margin-top: 14px;
|
||
padding-top: 14px;
|
||
border-top: 1px solid #0b2a48;
|
||
}
|
||
|
||
.help-section:first-of-type {
|
||
margin-top: 0;
|
||
padding-top: 0;
|
||
border-top: 0;
|
||
}
|
||
|
||
.help-section h4 {
|
||
margin-bottom: 8px;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.help-list {
|
||
display: grid;
|
||
gap: 8px;
|
||
font-size: 13px;
|
||
line-height: 1.5;
|
||
color: var(--text-primary);
|
||
}
|
||
|
||
.help-code {
|
||
margin-top: 8px;
|
||
padding: 10px 12px;
|
||
border-radius: 8px;
|
||
border: 1px solid #0b2a48;
|
||
background: #021221;
|
||
color: #d8e5f2;
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||
font-size: 12px;
|
||
white-space: pre-wrap;
|
||
word-break: break-word;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
<div id="login-overlay"
|
||
style="display:none; position:fixed; inset:0; background:rgba(0,0,0,.85); z-index:999; align-items:center; justify-content:center; padding:16px;">
|
||
<div class="panel" style="width:min(440px,100%);">
|
||
<div class="brand" style="margin-bottom:24px;">
|
||
<div class="brand-mark">N</div>
|
||
<div class="brand-text">
|
||
<div class="nubes">NUBES</div>
|
||
<div class="product">FISSION CONSOLE</div>
|
||
</div>
|
||
</div>
|
||
<div class="row" style="flex-direction:column; gap:6px; margin-bottom:12px;">
|
||
<label style="font-size:12px; color:#999;">Стенд</label>
|
||
<select id="l-env"
|
||
style="background:var(--bg-base); border:1px solid var(--border); color:var(--fg); padding:8px 10px; border-radius:6px;">
|
||
<option value="dev">Dev</option>
|
||
<option value="test" selected>Test</option>
|
||
<option value="prod">Prod</option>
|
||
</select>
|
||
</div>
|
||
<div class="row" style="flex-direction:column; gap:6px; margin-bottom:12px;">
|
||
<label style="font-size:12px; color:#999;">Токен</label>
|
||
<textarea id="l-token" rows="5"
|
||
style="background:var(--bg-base); border:1px solid var(--border); color:var(--fg); padding:8px 10px; border-radius:6px; font-family:monospace; font-size:12px; resize:vertical; width:100%; box-sizing:border-box;"
|
||
placeholder="Введите токен..."></textarea>
|
||
<div style="font-size:11px; color:var(--text-secondary); margin-top:4px;">Токен: <strong
|
||
style="color:#8bc7ff;">Личный кабинет → Профиль пользователя → Токены</strong></div>
|
||
</div>
|
||
<div id="l-error" style="display:none; color:#ff6b6b; font-size:13px; margin-bottom:10px;"></div>
|
||
<button id="l-btn" class="btn" style="width:100%;" onclick="doLogin()">Войти</button>
|
||
</div>
|
||
</div>
|
||
<!-- Overlay: инициализация нового окружения -->
|
||
<div id="init-overlay"
|
||
style="display:none; position:fixed; inset:0; background:rgba(0,0,0,.88); z-index:1000; align-items:center; justify-content:center; padding:16px;">
|
||
<div class="panel" style="width:min(520px,100%);">
|
||
<div style="margin-bottom:16px;">
|
||
<div style="font-size:16px; font-weight:700; margin-bottom:6px;">⚙️ Инициализация окружения</div>
|
||
<div style="font-size:13px; color:var(--text-secondary);">Первый вход. Настраиваем ваше окружение — это займёт
|
||
~5 минут.</div>
|
||
</div>
|
||
<div style="display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin-bottom:12px;">
|
||
<div style="background:#0d1827; border:1px solid var(--border); border-radius:6px; padding:10px;">
|
||
<div style="font-size:11px; color:var(--text-secondary); margin-bottom:4px;">Время настройки</div>
|
||
<div id="init-elapsed" style="font-size:18px; font-weight:700; color:#8bc7ff;">0с</div>
|
||
</div>
|
||
<div style="background:#0d1827; border:1px solid var(--border); border-radius:6px; padding:10px;">
|
||
<div style="font-size:11px; color:var(--text-secondary); margin-bottom:4px;">Текущий этап</div>
|
||
<div id="init-current-stage" style="font-size:14px; font-weight:600; color:#f4f7fb;">Ожидание старта</div>
|
||
</div>
|
||
</div>
|
||
<div id="init-summary"
|
||
style="display:none; margin-bottom:10px; background:#101c2b; border:1px solid var(--border); border-radius:6px; padding:10px 12px; font-size:13px; color:#d8e5f2;">
|
||
</div>
|
||
<div id="init-reason"
|
||
style="display:none; margin-bottom:10px; background:#2d2310; border:1px solid #6a5427; border-radius:6px; padding:10px 12px; font-size:13px; color:#ffd98a;">
|
||
</div>
|
||
<div id="init-error"
|
||
style="display:none; margin-bottom:10px; background:#2a1416; border:1px solid #7d3138; border-radius:6px; padding:10px 12px; font-size:13px; color:#ff9da5;">
|
||
</div>
|
||
<div id="init-log"
|
||
style="background:#000d1a; border:1px solid var(--border); border-radius:6px; padding:12px; font-family:monospace; font-size:12px; height:160px; overflow-y:auto; color:#4fc3f7; white-space:pre-wrap; line-height:1.6;">
|
||
</div>
|
||
<div id="init-stages" style="margin-top:14px; display:flex; flex-direction:column; gap:8px;"></div>
|
||
<div style="margin-top:14px; font-size:12px; color:var(--text-secondary);">Страница обновится автоматически когда
|
||
всё будет готово.</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="navbar">
|
||
<div class="brand-mark">N</div>
|
||
<div class="brand-text">
|
||
<div class="nubes">NUBES</div>
|
||
<div class="product">FISSION CONSOLE</div>
|
||
</div>
|
||
</div>
|
||
<div class="row" style="margin:0;">
|
||
<button class="btn ghost" onclick="reloadAll()">Refresh</button>
|
||
<button class="btn" onclick="openCreate()">+ Создать функцию</button>
|
||
<button class="btn ghost" onclick="openHelp()">Help</button>
|
||
<a class="btn ghost" href="/cron/" target="_blank" rel="noopener">Cron</a>
|
||
<button class="btn ghost" onclick="doLogout()" style="margin-left:8px;">Выход</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="wrap">
|
||
<div class="grid">
|
||
<div class="card">
|
||
<div class="k">Окружения</div>
|
||
<div id="env-count" class="v">-</div>
|
||
</div>
|
||
<div class="card">
|
||
<div class="k">Пакеты</div>
|
||
<div id="pkg-count" class="v">-</div>
|
||
</div>
|
||
<div class="card">
|
||
<div class="k">Функции</div>
|
||
<div id="fn-count" class="v">-</div>
|
||
</div>
|
||
<div class="card">
|
||
<div class="k">HTTP-триггеры</div>
|
||
<div id="http-count" class="v">-</div>
|
||
</div>
|
||
<div class="card">
|
||
<div class="k">Крон-функции</div>
|
||
<div id="cron-count" class="v">-</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="box">
|
||
<div class="toolbar">
|
||
<div style="font-weight:600;">Функции</div>
|
||
<div class="hint">Actions: view, edit code, invoke, delete</div>
|
||
</div>
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>Имя</th>
|
||
<th>Окружение</th>
|
||
<th>Пакет</th>
|
||
<th>Создана</th>
|
||
<th>Изменена</th>
|
||
<th>Маршрут</th>
|
||
<th>Методы</th>
|
||
<th>Cron</th>
|
||
<th class="nowrap">Действия</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="fn-rows"></tbody>
|
||
</table>
|
||
<div id="status" class="status"></div>
|
||
<div class="hint">Изменения применяются напрямую через CRD Fission.</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="create-modal" class="modal">
|
||
<div class="panel">
|
||
<h3>Создать функцию</h3>
|
||
<div class="row">
|
||
<div class="field">
|
||
<label>Name</label>
|
||
<input id="c-name" placeholder="demo-fn">
|
||
</div>
|
||
<div class="field">
|
||
<label>Language</label>
|
||
<select id="c-lang" onchange="onLangChange()">
|
||
<option value="python">Python</option>
|
||
<option value="nodejs">Node.js</option>
|
||
<option value="php">PHP</option>
|
||
<option value="ruby">Ruby</option>
|
||
</select>
|
||
</div>
|
||
<div class="field">
|
||
<label>Entrypoint</label>
|
||
<input id="c-entry" value="main.main">
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div class="field">
|
||
<label>Route</label>
|
||
<input id="c-route" placeholder="/demo-fn">
|
||
</div>
|
||
<div class="field">
|
||
<label>Методы (через запятую)</label>
|
||
<input id="c-methods" value="GET">
|
||
</div>
|
||
<div class="field">
|
||
<label>Timeout (сек)</label>
|
||
<input id="c-timeout" type="number" min="1" value="60">
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div class="field" style="min-width:240px; flex:0 0 260px;">
|
||
<label style="display:flex; align-items:center; gap:8px; color:var(--text-primary); margin-top:18px;">
|
||
<input id="c-schedule-enabled" type="checkbox" onchange="toggleScheduleFields('c')" style="width:auto;">
|
||
Выполнять по расписанию
|
||
</label>
|
||
</div>
|
||
<div class="field">
|
||
<label>Cron</label>
|
||
<input id="c-cron" placeholder="*/5 * * * *" disabled>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<label>Код</label>
|
||
<textarea id="c-code">def main():
|
||
return {"ok": True, "msg": "hello from fission console"}
|
||
</textarea>
|
||
<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>
|
||
<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')">📖 LLM:
|
||
Что
|
||
делает?</button>
|
||
</div>
|
||
<div id="c-gen-prompt" style="display:none; margin-top:8px; display:none; gap:6px; align-items:center;">
|
||
<input id="c-gen-desc" type="text"
|
||
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%;"
|
||
onkeydown="if(event.key==='Enter')aiGenerate()" />
|
||
<button class="btn" onclick="aiGenerate()" style="white-space:nowrap;">▶ Генерировать LLM</button>
|
||
</div>
|
||
<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;">
|
||
</div>
|
||
</div>
|
||
<div class="actions">
|
||
<button class="btn ghost" onclick="closeCreate()">Отмена</button>
|
||
<button id="c-submit" class="btn" onclick="submitCreate()">Создать</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="edit-modal" class="modal">
|
||
<div class="panel">
|
||
<h3 id="e-title">Редактирование кода</h3>
|
||
<div id="e-tf-warn"
|
||
style="display:none;background:#553300;color:#ffa;padding:8px 12px;border-radius:6px;margin-bottom:10px;font-size:13px;">
|
||
⚠️ Эта функция управляется Terraform. Изменения могут быть перезаписаны при следующем
|
||
<code>terraform apply</code>.
|
||
</div>
|
||
<input type="hidden" id="e-lang-hidden" value="">
|
||
<div class="row">
|
||
<div class="field">
|
||
<label>Name</label>
|
||
<input id="e-name" disabled>
|
||
</div>
|
||
<div class="field">
|
||
<label>Environment</label>
|
||
<input id="e-env" disabled>
|
||
</div>
|
||
<div class="field">
|
||
<label>Entrypoint</label>
|
||
<input id="e-entry" disabled>
|
||
</div>
|
||
<div class="field">
|
||
<label>Timeout (сек)</label>
|
||
<input id="e-timeout" type="number" min="1" value="60">
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div class="field" style="min-width:240px; flex:0 0 260px;">
|
||
<label style="display:flex; align-items:center; gap:8px; color:var(--text-primary); margin-top:18px;">
|
||
<input id="e-schedule-enabled" type="checkbox" onchange="toggleScheduleFields('e')" style="width:auto;">
|
||
Выполнять по расписанию
|
||
</label>
|
||
</div>
|
||
<div class="field">
|
||
<label>Cron</label>
|
||
<input id="e-cron" placeholder="*/5 * * * *" disabled>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<label>Код</label>
|
||
<textarea id="e-code"></textarea>
|
||
<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>
|
||
<button class="btn ghost" id="e-exp-btn" onclick="aiExplain('e-code','e-lang-hidden','e-ai-result')">📖
|
||
LLM:
|
||
Что делает?</button>
|
||
</div>
|
||
<div id="e-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;">
|
||
</div>
|
||
</div>
|
||
<div class="actions">
|
||
<button class="btn ghost" onclick="closeEdit()">Отмена</button>
|
||
<button id="e-submit" class="btn" onclick="submitEdit()">Сохранить</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="help-modal" class="modal">
|
||
<div class="panel">
|
||
<h3>Help</h3>
|
||
|
||
<div class="help-section">
|
||
<h4>Поля при создании функции</h4>
|
||
<div class="help-list">
|
||
<div><strong>Name</strong> — имя Function в Fission. Используется в CRD и в связанных объектах.</div>
|
||
<div><strong>Language</strong> — язык runtime. От него зависят environment, шаблон кода и entrypoint по
|
||
умолчанию.</div>
|
||
<div><strong>Entrypoint</strong> — точка входа внутри пакета. Например, <span class="mono">main.main</span>
|
||
для Python или <span class="mono">main.php::handler</span> для PHP.</div>
|
||
<div><strong>Route</strong> — HTTP путь функции. Внешний пользовательский вызов идёт через <span
|
||
class="mono">/fn + ваш Route</span>.</div>
|
||
<div><strong>Методы</strong> — HTTP методы route, например <span class="mono">GET</span> или <span
|
||
class="mono">GET,POST</span>.</div>
|
||
<div><strong>Timeout (сек)</strong> — максимум времени выполнения именно этой функции.</div>
|
||
<div><strong>Код</strong> — исходный код функции.</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="help-section">
|
||
<h4>Поля при редактировании функции</h4>
|
||
<div class="help-list">
|
||
<div><strong>Name</strong> — только для просмотра, не редактируется.</div>
|
||
<div><strong>Environment</strong> — только для просмотра, не редактируется из этой формы.</div>
|
||
<div><strong>Entrypoint</strong> — только для просмотра, не редактируется из этой формы.</div>
|
||
<div><strong>Timeout (сек)</strong> — редактируется и сохраняется в <span
|
||
class="mono">spec.functionTimeout</span>.</div>
|
||
<div><strong>Код</strong> — редактируется и обновляет Package функции.</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="help-section">
|
||
<h4>Как вызвать функцию вне веб-интерфейса</h4>
|
||
<div class="help-list">
|
||
<div>Обычный пользователь вызывает функцию через HTTP gateway console: <span class="mono">/fn/...</span>.
|
||
</div>
|
||
<div>Используется только ваш токен из личного кабинета в заголовке <span class="mono">Authorization: Bearer
|
||
<token></span>.</div>
|
||
<div>Работают обычные HTTP методы: <span class="mono">GET</span>, <span class="mono">POST</span>, <span
|
||
class="mono">PUT</span>, <span class="mono">DELETE</span> и другие, если они разрешены в поле Методы.
|
||
</div>
|
||
</div>
|
||
<div class="help-code">export TOKEN="<ваш пользовательский токен>"
|
||
curl -sk -X POST https://fission.kube5s.ru/fn/ВАШ_ROUTE \
|
||
-H "Authorization: Bearer $TOKEN" \
|
||
-H "Content-Type: application/json" \
|
||
-d '{"x":1,"y":2}'</div>
|
||
<div class="help-code">export TOKEN="<ваш пользовательский токен>"
|
||
curl -sk https://fission.kube5s.ru/fn/ВАШ_ROUTE \
|
||
-H "Authorization: Bearer $TOKEN"</div>
|
||
<div class="help-code">import requests
|
||
|
||
token = "ВАШ_ТОКЕН"
|
||
url = "https://fission.kube5s.ru/fn/ВАШ_ROUTE"
|
||
|
||
response = requests.post(
|
||
url,
|
||
headers={"Authorization": f"Bearer {token}"},
|
||
json={"x": 1, "y": 2},
|
||
timeout=60,
|
||
)
|
||
|
||
print(response.status_code)
|
||
print(response.text)</div>
|
||
</div>
|
||
|
||
<div class="help-section">
|
||
<h4>Где взять токен</h4>
|
||
<div class="help-list">
|
||
<div><strong>Для обычного пользователя</strong> — используйте ваш пользовательский токен из личного кабинета:
|
||
Профиль пользователя → Токены.</div>
|
||
<div>Тот же пользовательский токен подходит и для входа в console, и для внешнего вызова через <span
|
||
class="mono">/fn/...</span>.</div>
|
||
<div>Токен удобно класть в переменную окружения и потом подставлять в curl как <span
|
||
class="mono">$TOKEN</span>.</div>
|
||
</div>
|
||
<div class="help-code">export TOKEN="<вставьте сюда токен из личного кабинета>"</div>
|
||
</div>
|
||
|
||
<div class="actions">
|
||
<button class="btn ghost" onclick="closeHelp()">Закрыть</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="invoke-modal" class="modal">
|
||
<div class="panel">
|
||
<h3 id="i-title">Вызов</h3>
|
||
<div>
|
||
<label>JSON тело запроса</label>
|
||
<textarea id="i-body">{"name":"world"}</textarea>
|
||
</div>
|
||
<div class="actions">
|
||
<button class="btn ghost" onclick="closeInvoke()">Отмена</button>
|
||
<button id="i-submit" class="btn" onclick="submitInvoke()">Вызвать</button>
|
||
</div>
|
||
<div id="i-status" style="margin-top:8px;font-size:13px;color:var(--text-secondary);min-height:20px;"></div>
|
||
<div id="i-meta"
|
||
style="display:none;margin-top:8px;background:#101c2b;border:1px solid var(--border);border-radius:6px;padding:10px 12px;font-size:13px;color:#d8e5f2;white-space:pre-wrap;">
|
||
</div>
|
||
<div style="margin-top:6px;">
|
||
<label>Response</label>
|
||
<textarea id="i-resp" readonly style="min-height:160px;"></textarea>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
const API_BASE = window.location.pathname.startsWith('/console') ? '/console/api' : '/api';
|
||
|
||
const S = {
|
||
envs: [],
|
||
fns: [],
|
||
httpTriggers: [],
|
||
timeTriggers: [],
|
||
currentEdit: null,
|
||
currentInvoke: null
|
||
};
|
||
|
||
function authHeaders() {
|
||
return {
|
||
'X-Auth-Token': localStorage.getItem('auth_token') || '',
|
||
'X-Auth-Env': localStorage.getItem('auth_env') || 'test'
|
||
};
|
||
}
|
||
|
||
async function getJSON(url) {
|
||
const r = await fetch(url, { headers: authHeaders() });
|
||
if (r.status === 401) { doLogout(); throw new Error('Сессия истекла'); }
|
||
if (!r.ok) {
|
||
let msg = '';
|
||
try {
|
||
const body = await r.json();
|
||
msg = body.error || JSON.stringify(body);
|
||
} catch (_) {
|
||
msg = await r.text();
|
||
}
|
||
throw new Error(url + ': ' + r.status + (msg ? ' - ' + msg : ''));
|
||
}
|
||
return r.json();
|
||
}
|
||
|
||
async function requestJSON(url, method, body) {
|
||
const r = await fetch(url, {
|
||
method: method,
|
||
headers: Object.assign({ 'Content-Type': 'application/json' }, authHeaders()),
|
||
body: body ? JSON.stringify(body) : undefined
|
||
});
|
||
if (r.status === 401) { doLogout(); throw new Error('Сессия истекла'); }
|
||
let data = {};
|
||
try { data = await r.json(); } catch (_) { }
|
||
if (!r.ok) {
|
||
throw new Error(data.error || (url + ': ' + r.status));
|
||
}
|
||
return data;
|
||
}
|
||
|
||
function setText(id, value) {
|
||
document.getElementById(id).textContent = String(value);
|
||
}
|
||
|
||
function showStatus(message, kind) {
|
||
const el = document.getElementById('status');
|
||
el.style.display = 'block';
|
||
el.className = 'status ' + (kind || '');
|
||
el.textContent = message;
|
||
}
|
||
|
||
function clearStatus() {
|
||
const el = document.getElementById('status');
|
||
el.style.display = 'none';
|
||
el.className = 'status';
|
||
el.textContent = '';
|
||
}
|
||
|
||
function parseMethods(v) {
|
||
const items = String(v || '').split(',').map(s => s.trim().toUpperCase()).filter(Boolean);
|
||
return items.length ? Array.from(new Set(items)) : ['GET'];
|
||
}
|
||
|
||
function parseTimeout(v) {
|
||
var n = Number(String(v || '').trim());
|
||
if (!Number.isFinite(n) || n <= 0) return 60;
|
||
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 httpTriggerByFn(fnName) {
|
||
return (S.httpTriggers || []).find(function (t) {
|
||
return t.spec && t.spec.functionref && t.spec.functionref.name === fnName;
|
||
});
|
||
}
|
||
|
||
function timeTriggerByFn(fnName) {
|
||
return (S.timeTriggers || []).find(function (t) {
|
||
return t.spec && t.spec.functionref && t.spec.functionref.name === fnName;
|
||
});
|
||
}
|
||
|
||
function toggleScheduleFields(prefix) {
|
||
var enabled = !!document.getElementById(prefix + '-schedule-enabled').checked;
|
||
var cronEl = document.getElementById(prefix + '-cron');
|
||
cronEl.disabled = !enabled;
|
||
if (enabled && !cronEl.value.trim()) {
|
||
cronEl.value = '*/5 * * * *';
|
||
}
|
||
}
|
||
|
||
function schedulePayload(prefix) {
|
||
return {
|
||
enabled: !!document.getElementById(prefix + '-schedule-enabled').checked,
|
||
cron: (document.getElementById(prefix + '-cron').value || '').trim()
|
||
};
|
||
}
|
||
|
||
async function syncScheduleForFunction(name, prefix) {
|
||
var schedule = schedulePayload(prefix);
|
||
var existing = timeTriggerByFn(name);
|
||
var existingName = (existing && existing.metadata && existing.metadata.name) || name;
|
||
|
||
if (!schedule.enabled) {
|
||
if (existing) {
|
||
await requestJSON(API_BASE + '/timetriggers/' + encodeURIComponent(existingName), 'DELETE');
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (!schedule.cron) {
|
||
throw new Error('cron is required');
|
||
}
|
||
|
||
var payload = {
|
||
name: existingName,
|
||
functionName: name,
|
||
cron: schedule.cron,
|
||
method: 'POST',
|
||
subpath: '/'
|
||
};
|
||
|
||
if (existing) {
|
||
await requestJSON(API_BASE + '/timetriggers/' + encodeURIComponent(existingName), 'PUT', payload);
|
||
} else {
|
||
await requestJSON(API_BASE + '/timetriggers', 'POST', payload);
|
||
}
|
||
}
|
||
|
||
function h(v) {
|
||
return String(v == null ? '' : v)
|
||
.replaceAll('&', '&')
|
||
.replaceAll('<', '<')
|
||
.replaceAll('>', '>')
|
||
.replaceAll('"', '"')
|
||
.replaceAll("'", ''');
|
||
}
|
||
|
||
function formatTimestamp(ts) {
|
||
if (!ts) return '—';
|
||
var d = new Date(ts);
|
||
if (isNaN(d.getTime())) return String(ts);
|
||
return d.toLocaleString('ru-RU', {
|
||
year: 'numeric',
|
||
month: '2-digit',
|
||
day: '2-digit',
|
||
hour: '2-digit',
|
||
minute: '2-digit',
|
||
second: '2-digit'
|
||
});
|
||
}
|
||
|
||
function timestampCell(ts) {
|
||
var text = formatTimestamp(ts);
|
||
return '<span class="mono" title="' + h(ts || '') + '">' + h(text) + '</span>';
|
||
}
|
||
|
||
const LANG_TEMPLATES = {
|
||
python: {
|
||
entrypoint: 'main.main',
|
||
code: 'def main():\n return {"ok": True}'
|
||
},
|
||
nodejs: {
|
||
entrypoint: 'main',
|
||
code: 'module.exports = async function(context) {\n return {\n status: 200,\n body: "hello from fission"\n };\n}'
|
||
},
|
||
php: {
|
||
entrypoint: 'main.php::handler',
|
||
code: '<?php\nfunction handler($context)\n{\n $response = $context["response"];\n $response->getBody()->write("hello from fission");\n}'
|
||
},
|
||
ruby: {
|
||
entrypoint: 'handler',
|
||
code: '# frozen_string_literal: true\n\ndef handler\n "hello from fission"\nend'
|
||
}
|
||
};
|
||
|
||
function onLangChange() {
|
||
var lang = document.getElementById('c-lang').value;
|
||
var t = LANG_TEMPLATES[lang];
|
||
if (t) {
|
||
document.getElementById('c-entry').value = t.entrypoint;
|
||
document.getElementById('c-code').value = t.code;
|
||
}
|
||
}
|
||
|
||
function openCreate() {
|
||
document.getElementById('c-lang').value = 'python';
|
||
onLangChange();
|
||
document.getElementById('c-timeout').value = '60';
|
||
document.getElementById('c-schedule-enabled').checked = false;
|
||
document.getElementById('c-cron').value = '';
|
||
toggleScheduleFields('c');
|
||
document.getElementById('create-modal').classList.add('open');
|
||
document.getElementById('c-name').focus();
|
||
}
|
||
|
||
function closeCreate() {
|
||
document.getElementById('create-modal').classList.remove('open');
|
||
}
|
||
|
||
async function submitCreate() {
|
||
const btn = document.getElementById('c-submit');
|
||
btn.disabled = true;
|
||
const progress = startTimedStatus('Создаём функцию...', 'Создание функции...', explainDelay);
|
||
try {
|
||
const name = document.getElementById('c-name').value.trim();
|
||
if (!name) throw new Error('name is required');
|
||
const lang = document.getElementById('c-lang').value.trim();
|
||
if (!lang) throw new Error('language is required');
|
||
|
||
await requestJSON(API_BASE + '/functions', 'POST', {
|
||
name: name,
|
||
language: lang,
|
||
entrypoint: document.getElementById('c-entry').value.trim(),
|
||
route: document.getElementById('c-route').value.trim(),
|
||
methods: parseMethods(document.getElementById('c-methods').value),
|
||
timeout: parseTimeout(document.getElementById('c-timeout').value),
|
||
code: document.getElementById('c-code').value
|
||
});
|
||
|
||
try {
|
||
await syncScheduleForFunction(name, 'c');
|
||
} catch (scheduleErr) {
|
||
try {
|
||
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name), 'DELETE');
|
||
} catch (rollbackErr) {
|
||
scheduleErr.message += '; rollback failed: ' + rollbackErr.message;
|
||
}
|
||
throw scheduleErr;
|
||
}
|
||
|
||
closeCreate();
|
||
progress.stop('\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0430: ' + name, 'ok');
|
||
await reloadAll();
|
||
} catch (e) {
|
||
progress.stop('\u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f: ' + e.message, 'err');
|
||
} finally {
|
||
btn.disabled = false;
|
||
}
|
||
}
|
||
|
||
async function openEdit(name) {
|
||
try {
|
||
const fn = await getJSON(API_BASE + '/functions/' + encodeURIComponent(name));
|
||
S.currentEdit = fn;
|
||
document.getElementById('e-title').textContent = '\u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435: ' + name;
|
||
document.getElementById('e-name').value = name;
|
||
document.getElementById('e-env').value = fn.environment || '';
|
||
document.getElementById('e-entry').value = fn.entrypoint || '';
|
||
document.getElementById('e-timeout').value = String(fn.timeout || 60);
|
||
document.getElementById('e-code').value = fn.code || '';
|
||
var schedule = timeTriggerByFn(name);
|
||
document.getElementById('e-schedule-enabled').checked = !!schedule;
|
||
document.getElementById('e-cron').value = (schedule && schedule.spec && schedule.spec.cron) || '';
|
||
toggleScheduleFields('e');
|
||
// Определяем язык по имени environment для линтера
|
||
var envName = (fn.environment || '').toLowerCase();
|
||
var lang = 'python';
|
||
if (envName.includes('node')) lang = 'nodejs';
|
||
else if (envName.includes('go')) lang = 'go';
|
||
else if (envName.includes('ruby')) lang = 'ruby';
|
||
else if (envName.includes('php')) lang = 'php';
|
||
document.getElementById('e-lang-hidden').value = lang;
|
||
// сбросить предыдущий AI-результат
|
||
var aiRes = document.getElementById('e-ai-result');
|
||
if (aiRes) { aiRes.style.display = 'none'; aiRes.textContent = ''; }
|
||
var warnEl = document.getElementById('e-tf-warn');
|
||
if (warnEl) {
|
||
var isTf = /^tf-/.test(name) || /go[-_]env/.test(fn.environment || '');
|
||
warnEl.style.display = isTf ? 'block' : 'none';
|
||
}
|
||
document.getElementById('edit-modal').classList.add('open');
|
||
} catch (e) {
|
||
showStatus('\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: ' + e.message, 'err');
|
||
}
|
||
}
|
||
|
||
function closeEdit() {
|
||
document.getElementById('edit-modal').classList.remove('open');
|
||
S.currentEdit = null;
|
||
}
|
||
|
||
function openHelp() {
|
||
document.getElementById('help-modal').classList.add('open');
|
||
}
|
||
|
||
function closeHelp() {
|
||
document.getElementById('help-modal').classList.remove('open');
|
||
}
|
||
|
||
async function submitEdit() {
|
||
if (!S.currentEdit) return;
|
||
const btn = document.getElementById('e-submit');
|
||
btn.disabled = true;
|
||
const progress = startTimedStatus('Сохраняем код...', 'Сохранение кода...', explainDelay);
|
||
try {
|
||
const name = S.currentEdit.name;
|
||
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name) + '/code', 'PUT', {
|
||
code: document.getElementById('e-code').value,
|
||
timeout: parseTimeout(document.getElementById('e-timeout').value)
|
||
});
|
||
|
||
await syncScheduleForFunction(name, 'e');
|
||
closeEdit();
|
||
progress.stop('\u041a\u043e\u0434 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d: ' + name, 'ok');
|
||
await reloadAll();
|
||
} catch (e) {
|
||
progress.stop('\u041e\u0448\u0438\u0431\u043a\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f: ' + e.message, 'err');
|
||
} finally {
|
||
btn.disabled = false;
|
||
}
|
||
}
|
||
|
||
function openInvoke(name) {
|
||
S.currentInvoke = name;
|
||
document.getElementById('i-title').textContent = '\u0412\u044b\u0437\u043e\u0432: ' + name;
|
||
document.getElementById('i-resp').value = '';
|
||
document.getElementById('i-status').textContent = '';
|
||
document.getElementById('i-meta').style.display = 'none';
|
||
document.getElementById('i-meta').textContent = '';
|
||
document.getElementById('invoke-modal').classList.add('open');
|
||
}
|
||
|
||
function closeInvoke() {
|
||
document.getElementById('invoke-modal').classList.remove('open');
|
||
S.currentInvoke = null;
|
||
}
|
||
|
||
async function submitInvoke() {
|
||
if (!S.currentInvoke) return;
|
||
const btn = document.getElementById('i-submit');
|
||
const statusEl = document.getElementById('i-status');
|
||
const metaEl = document.getElementById('i-meta');
|
||
const respEl = document.getElementById('i-resp');
|
||
btn.disabled = true;
|
||
respEl.value = '';
|
||
metaEl.style.display = 'none';
|
||
metaEl.textContent = '';
|
||
let elapsed = 0;
|
||
statusEl.textContent = 'Вызов...';
|
||
const timer = setInterval(() => {
|
||
elapsed++;
|
||
if (elapsed < 5) {
|
||
statusEl.textContent = 'Вызов... ' + elapsed + 'с';
|
||
} else if (elapsed < 10) {
|
||
statusEl.textContent = '⏳ Возможен cold start — прогрев пула... ' + elapsed + 'с';
|
||
} else {
|
||
statusEl.textContent = '⏳ Возможны cold start или specialization... ' + elapsed + 'с';
|
||
}
|
||
}, 1000);
|
||
try {
|
||
const raw = document.getElementById('i-body').value.trim();
|
||
let parsed = {};
|
||
if (raw) parsed = JSON.parse(raw);
|
||
const result = await requestJSON(API_BASE + '/functions/' + encodeURIComponent(S.currentInvoke) + '/invoke', 'POST', parsed);
|
||
var latencyMs = Number(result.latency_ms || 0);
|
||
var measuredSeconds = latencyMs > 0 ? Math.max(1, Math.round(latencyMs / 1000)) : elapsed;
|
||
statusEl.textContent = '✓ Выполнено за ' + formatSeconds(measuredSeconds);
|
||
metaEl.style.display = 'block';
|
||
metaEl.textContent = [
|
||
'HTTP status: ' + (result.status || 'n/a'),
|
||
'Latency: ' + (latencyMs || 'n/a') + ' ms',
|
||
'Причина задержки: ' + explainDelay(measuredSeconds),
|
||
'Invoke URL: ' + (result.invoke_url || 'n/a')
|
||
].join('\n');
|
||
respEl.value = JSON.stringify(result, null, 2);
|
||
} catch (e) {
|
||
statusEl.textContent = '✗ Ошибка после ' + formatSeconds(elapsed);
|
||
metaEl.style.display = 'block';
|
||
metaEl.textContent = [
|
||
'Последняя ошибка: ' + e.message,
|
||
'Вероятная причина задержки: ' + explainDelay(elapsed)
|
||
].join('\n');
|
||
respEl.value = 'Ошибка вызова: ' + e.message;
|
||
} finally {
|
||
clearInterval(timer);
|
||
btn.disabled = false;
|
||
}
|
||
}
|
||
|
||
async function removeFn(name) {
|
||
var tfWarn = (/^tf-/.test(name)) ? '\n\n\u26a0\ufe0f \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f Terraform. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0440\u0430\u0441\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 state!' : '';
|
||
if (!confirm('\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e ' + name + '?' + tfWarn)) return;
|
||
var progress = startTimedStatus('\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e...', '\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438...', explainDelay);
|
||
try {
|
||
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name), 'DELETE');
|
||
progress.stop('\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0430: ' + name, 'ok');
|
||
await reloadAll();
|
||
} catch (e) {
|
||
progress.stop('\u041e\u0448\u0438\u0431\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f: ' + e.message, 'err');
|
||
}
|
||
}
|
||
|
||
async function reloadAll() {
|
||
try {
|
||
const [envs, pkgs, fns, http, times] = await Promise.all([
|
||
getJSON(API_BASE + '/environments'),
|
||
getJSON(API_BASE + '/packages'),
|
||
getJSON(API_BASE + '/functions'),
|
||
getJSON(API_BASE + '/httptriggers'),
|
||
getJSON(API_BASE + '/timetriggers')
|
||
]);
|
||
|
||
S.envs = envs || [];
|
||
S.fns = fns || [];
|
||
S.httpTriggers = http || [];
|
||
S.timeTriggers = times || [];
|
||
|
||
setText('env-count', envs.length || 0);
|
||
setText('pkg-count', pkgs.length || 0);
|
||
setText('fn-count', fns.length || 0);
|
||
setText('http-count', http.length || 0);
|
||
setText('cron-count', new Set((times || []).map(function (t) {
|
||
return t && t.spec && t.spec.functionref && t.spec.functionref.name;
|
||
}).filter(Boolean)).size);
|
||
|
||
const rows = (fns || []).map(function (f) {
|
||
const spec = f.spec || {};
|
||
const meta = f.metadata || {};
|
||
const ann = meta.annotations || {};
|
||
const env = (spec.environment && spec.environment.name) || '-';
|
||
const pkg = (spec.package && spec.package.packageref && spec.package.packageref.name) || '-';
|
||
const name = (f.metadata && f.metadata.name) || '-';
|
||
const trig = httpTriggerByFn(name) || {};
|
||
const timeTrig = timeTriggerByFn(name) || {};
|
||
const route = (trig.spec && trig.spec.relativeurl) || '-';
|
||
const methods = (trig.spec && trig.spec.methods) || [];
|
||
const chips = methods.map(function (m) { return '<span class="chip">' + h(m) + '</span>'; }).join('');
|
||
const cron = (timeTrig.spec && timeTrig.spec.cron) || '';
|
||
const cronCell = cron ? '<span class="chip">' + h(cron) + '</span>' : '<span class="mono" style="color:var(--text-secondary)">—</span>';
|
||
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) ? '<span class="chip" style="background:#555;color:#ffa" title="Управляется Terraform. Изменения могут быть перезаписаны при terraform apply.">TF</span> ' : '';
|
||
var actions = tfBadge +
|
||
'<button class="btn ghost" onclick="openEdit(\'' + h(name) + '\')">\u0420\u0435\u0434.</button> ' +
|
||
'<button class="btn ghost" onclick="openInvoke(\'' + h(name) + '\')">\u0412\u044b\u0437\u043e\u0432</button> ' +
|
||
'<button class="btn danger" onclick="removeFn(\'' + h(name) + '\')">\u0423\u0434\u0430\u043b\u0438\u0442\u044c</button>';
|
||
return '<tr>' +
|
||
'<td class="mono">' + h(name) + '</td>' +
|
||
'<td>' + h(env) + '</td>' +
|
||
'<td class="mono">' + h(pkg) + '</td>' +
|
||
'<td>' + timestampCell(createdAt) + '</td>' +
|
||
'<td>' + timestampCell(updatedAt) + '</td>' +
|
||
'<td class="mono">' + h(route) + '</td>' +
|
||
'<td>' + chips + '</td>' +
|
||
'<td>' + cronCell + '</td>' +
|
||
'<td class="nowrap">' + actions + '</td>' +
|
||
'</tr>';
|
||
}).join('');
|
||
|
||
document.getElementById('fn-rows').innerHTML = rows || '<tr><td colspan="9">\u041d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439</td></tr>';
|
||
if (!rows) {
|
||
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="9">\u041d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439</td></tr>';
|
||
}
|
||
} catch (e) {
|
||
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="9">Load error: ' + e.message + '</td></tr>';
|
||
showStatus('\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438: ' + e.message, 'err');
|
||
}
|
||
}
|
||
|
||
function showLoginOverlay() {
|
||
document.getElementById('login-overlay').style.display = 'flex';
|
||
}
|
||
|
||
function hideLoginOverlay() {
|
||
document.getElementById('login-overlay').style.display = 'none';
|
||
}
|
||
|
||
async function doLogin() {
|
||
var btn = document.getElementById('l-btn');
|
||
var errEl = document.getElementById('l-error');
|
||
var token = (document.getElementById('l-token').value || '').trim();
|
||
var env = document.getElementById('l-env').value;
|
||
if (!token) { errEl.textContent = 'Введите токен'; errEl.style.display = 'block'; return; }
|
||
btn.disabled = true;
|
||
errEl.style.display = 'none';
|
||
try {
|
||
const res = await fetch(API_BASE + '/auth', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ token: token, env: env })
|
||
});
|
||
if (!res.ok) {
|
||
const d = await res.json().catch(function () { return {}; });
|
||
throw new Error(d.error || 'Ошибка входа');
|
||
}
|
||
localStorage.setItem('auth_token', token);
|
||
localStorage.setItem('auth_env', env);
|
||
hideLoginOverlay();
|
||
// Проверяем статус NS — если не ready, показываем init overlay
|
||
try {
|
||
var sr = await fetch(API_BASE + '/ns/status', { headers: { 'X-Auth-Token': token, 'X-Auth-Env': env } });
|
||
var sd = await sr.json();
|
||
if (!sd.ready) {
|
||
pollNSStatus();
|
||
return;
|
||
}
|
||
} catch (_) { }
|
||
reloadAll();
|
||
} catch (e) {
|
||
errEl.textContent = e.message;
|
||
errEl.style.display = 'block';
|
||
} finally {
|
||
btn.disabled = false;
|
||
}
|
||
}
|
||
|
||
function doLogout() {
|
||
localStorage.removeItem('auth_token');
|
||
localStorage.removeItem('auth_env');
|
||
try { document.getElementById('l-token').value = ''; } catch (_) { }
|
||
showLoginOverlay();
|
||
}
|
||
|
||
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;
|
||
|
||
function initLog(msg) {
|
||
var el = document.getElementById('init-log');
|
||
var ts = new Date().toLocaleTimeString('ru-RU');
|
||
el.textContent += '[' + ts + '] ' + msg + '\n';
|
||
el.scrollTop = el.scrollHeight;
|
||
}
|
||
|
||
function formatSeconds(totalSeconds) {
|
||
totalSeconds = Math.max(0, Number(totalSeconds) || 0);
|
||
var minutes = Math.floor(totalSeconds / 60);
|
||
var seconds = totalSeconds % 60;
|
||
if (minutes <= 0) return seconds + 'с';
|
||
return minutes + 'м ' + seconds + 'с';
|
||
}
|
||
|
||
function setInitElapsed(seconds) {
|
||
document.getElementById('init-elapsed').textContent = formatSeconds(seconds);
|
||
}
|
||
|
||
function setInitCurrentStage(text) {
|
||
document.getElementById('init-current-stage').textContent = text || 'Ожидание старта';
|
||
}
|
||
|
||
function setBox(id, text) {
|
||
var el = document.getElementById(id);
|
||
if (!el) return;
|
||
if (!text) {
|
||
el.style.display = 'none';
|
||
el.textContent = '';
|
||
return;
|
||
}
|
||
el.style.display = 'block';
|
||
el.textContent = text;
|
||
}
|
||
|
||
function missingKeys(obj) {
|
||
return Object.keys(obj || {}).filter(function (key) {
|
||
return !obj[key];
|
||
});
|
||
}
|
||
|
||
function firstPendingStage(stages) {
|
||
var list = stages || [];
|
||
for (var i = 0; i < list.length; i++) {
|
||
if (!list[i].done) return list[i].name;
|
||
}
|
||
return list.length ? list[list.length - 1].name : 'Ожидание старта';
|
||
}
|
||
|
||
function describeInitReason(debug) {
|
||
if (!debug) return 'Собираем диагностические данные по namespace и control-plane...';
|
||
if (!debug.exists) return 'Ещё не создан Kubernetes namespace пользователя.';
|
||
if (!debug.active) return 'Namespace создан, но Kubernetes ещё не перевёл его в состояние Active.';
|
||
|
||
var preparation = debug.preparation || {};
|
||
if (!preparation.managedByConsole) return 'Namespace существует, но ещё не помечен как managed-by=fission-console.';
|
||
if (!preparation.watcherLabel) return 'Namespace ещё не помечен label fission.io/managed=true для NSWatcher.';
|
||
|
||
var missingSAs = missingKeys(preparation.serviceAccounts);
|
||
if (missingSAs.length) return 'Не готовы bootstrap service accounts: ' + missingSAs.join(', ') + '.';
|
||
|
||
var missingRBs = missingKeys(preparation.roleBindings);
|
||
if (missingRBs.length) return 'Не готовы bootstrap role bindings: ' + missingRBs.join(', ') + '.';
|
||
|
||
var control = debug.controlPlane || {};
|
||
if (!control.executor || !control.executor.ready) {
|
||
return 'Executor ещё не ready. Возможна задержка из-за cold start, image pull или specialization.';
|
||
}
|
||
if (!control.router || !control.router.ready) {
|
||
return 'Router ещё не ready. HTTP маршрутизация пока не активна.';
|
||
}
|
||
|
||
return 'Ожидаем финальное подтверждение готовности control-plane.';
|
||
}
|
||
|
||
function summarizeInit(status, debug) {
|
||
var done = status && status.stages ? status.stages.filter(function (s) { return s.done; }).length : 0;
|
||
var namespace = debug && debug.namespace ? debug.namespace : 'не определён';
|
||
return 'Namespace: ' + namespace + '. Завершено шагов: ' + done + '/3.';
|
||
}
|
||
|
||
function explainDelay(seconds) {
|
||
if (seconds < 5) return 'Обычная операция без заметной задержки.';
|
||
if (seconds < 10) return 'Вероятен cold start: прогрев пула, image pull или ожидание specialization.';
|
||
return 'Задержка выше нормы: возможны cold start, specialization или ожидание готовности control-plane.';
|
||
}
|
||
|
||
function startTimedStatus(startText, waitingPrefix, waitingHint) {
|
||
var startedAt = Date.now();
|
||
showStatus(startText, '');
|
||
var timer = setInterval(function () {
|
||
var elapsed = Math.max(1, Math.floor((Date.now() - startedAt) / 1000));
|
||
var text = waitingPrefix + ' ' + formatSeconds(elapsed);
|
||
if (waitingHint) text += ' · ' + waitingHint(elapsed);
|
||
showStatus(text, '');
|
||
}, 1000);
|
||
return {
|
||
stop: function (message, kind) {
|
||
clearInterval(timer);
|
||
var elapsed = Math.max(0, Math.round((Date.now() - startedAt) / 1000));
|
||
var text = message;
|
||
if (message) text += ' за ' + formatSeconds(elapsed);
|
||
showStatus(text, kind || '');
|
||
}
|
||
};
|
||
}
|
||
|
||
function renderInitStages(stages) {
|
||
var el = document.getElementById('init-stages');
|
||
el.innerHTML = stages.map(function (s) {
|
||
var icon = s.done ? '✅' : '⏳';
|
||
var color = s.done ? '#4caf50' : '#8bc7ff';
|
||
return '<div style="font-size:13px; color:' + color + ';">' + icon + ' ' + s.name + '</div>';
|
||
}).join('');
|
||
}
|
||
|
||
async function pollNSStatus() {
|
||
if (_initPolling) return;
|
||
_initPolling = true;
|
||
_initTickBusy = false;
|
||
_initStartedAt = Date.now();
|
||
var overlay = document.getElementById('init-overlay');
|
||
overlay.style.display = 'flex';
|
||
document.getElementById('init-log').textContent = '';
|
||
setInitElapsed(0);
|
||
setInitCurrentStage('Подготовка запуска');
|
||
setBox('init-summary', 'Проверяем состояние namespace и control-plane...');
|
||
setBox('init-reason', 'Если пользователь новый, возможны cold start и создание bootstrap ресурсов.');
|
||
setBox('init-error', '');
|
||
initLog('Запуск инициализации...');
|
||
var attempt = 0;
|
||
var maxAttempts = 60; // 5 минут
|
||
var interval = setInterval(async function () {
|
||
if (_initTickBusy) return;
|
||
_initTickBusy = true;
|
||
attempt++;
|
||
try {
|
||
var elapsed = Math.floor((Date.now() - _initStartedAt) / 1000);
|
||
setInitElapsed(elapsed);
|
||
var statusResp = await fetch(API_BASE + '/ns/status', { headers: authHeaders() });
|
||
var debugResp = await fetch(API_BASE + '/ns/debug', { headers: authHeaders() });
|
||
var d = await statusResp.json();
|
||
var dbg = await debugResp.json().catch(function () { return null; });
|
||
if (d.stages) renderInitStages(d.stages);
|
||
setInitCurrentStage(firstPendingStage(d.stages));
|
||
setBox('init-summary', summarizeInit(d, dbg));
|
||
setBox('init-reason', describeInitReason(dbg));
|
||
setBox('init-error', '');
|
||
var done = d.stages ? d.stages.filter(function (s) { return s.done; }).length : 0;
|
||
initLog('Шагов завершено: ' + done + '/3');
|
||
if (d.ready) {
|
||
initLog('✅ Готово! Загружаем консоль...');
|
||
clearInterval(interval);
|
||
_initPolling = false;
|
||
_initTickBusy = false;
|
||
overlay.style.display = 'none';
|
||
reloadAll();
|
||
return;
|
||
}
|
||
} catch (e) {
|
||
setBox('init-error', 'Последняя ошибка: ' + e.message);
|
||
initLog('Ошибка опроса: ' + e.message);
|
||
} finally {
|
||
_initTickBusy = false;
|
||
}
|
||
if (attempt >= maxAttempts) {
|
||
clearInterval(interval);
|
||
_initPolling = false;
|
||
_initTickBusy = false;
|
||
setBox('init-error', 'Превышено время ожидания. Чаще всего это bootstrap RBAC, control-plane readiness или холодный старт.');
|
||
initLog('⚠️ Превышено время ожидания. Попробуйте обновить страницу.');
|
||
}
|
||
}, 5000);
|
||
}
|
||
|
||
function checkAuth() {
|
||
if (!localStorage.getItem('auth_token')) {
|
||
showLoginOverlay();
|
||
return;
|
||
}
|
||
hideLoginOverlay();
|
||
reloadAll();
|
||
}
|
||
|
||
checkAuth();
|
||
</script>
|
||
|
||
<!-- ================================================================
|
||
ai/ask feature — удалить весь блок до "end ai/ask feature"
|
||
================================================================ -->
|
||
<div id="assistant-panel" style="
|
||
position:fixed; bottom:0; right:24px;
|
||
width:720px; background:#1e1e2e; border:1px solid #3a3a5c;
|
||
border-bottom:none; border-radius:8px 8px 0 0;
|
||
font-family:inherit; z-index:900; box-shadow:0 -2px 12px rgba(0,0,0,.4);
|
||
">
|
||
<div id="assistant-header" onclick="toggleAssistant()" style="
|
||
display:flex; align-items:center; justify-content:space-between;
|
||
padding:8px 12px; cursor:pointer; background:#2a2a42; border-radius:8px 8px 0 0;
|
||
user-select:none;
|
||
">
|
||
<span style="font-weight:600; font-size:.85rem;">💬 LLM Ассистент</span>
|
||
<span id="assistant-toggle-icon" style="font-size:.75rem; opacity:.7;">▲</span>
|
||
</div>
|
||
<div id="assistant-body" style="padding:10px; display:flex; flex-direction:column; gap:8px;">
|
||
<div id="assistant-messages" style="
|
||
min-height:80px; max-height:400px; overflow-y:auto;
|
||
font-size:.82rem; line-height:1.5; color:#cdd6f4;
|
||
background:#13131f; border-radius:4px; padding:8px;
|
||
white-space:pre-wrap; word-break:break-word;
|
||
">Чем могу помочь?</div>
|
||
<div style="display:flex; gap:6px;">
|
||
<input id="assistant-input" type="text" placeholder="Введи вопрос..." style="flex:1; background:#2a2a42; border:1px solid #3a3a5c; border-radius:4px;
|
||
color:#cdd6f4; padding:6px 8px; font-size:.82rem; outline:none;"
|
||
onkeydown="if(event.key==='Enter')askAssistant()" />
|
||
<button onclick="askAssistant()" style="
|
||
background:#7c3aed; color:#fff; border:none; border-radius:4px;
|
||
padding:6px 12px; cursor:pointer; font-size:.82rem; white-space:nowrap;
|
||
">→</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<script>
|
||
// ai/ask feature
|
||
var _assistantOpen = true;
|
||
function toggleAssistant() {
|
||
_assistantOpen = !_assistantOpen;
|
||
document.getElementById('assistant-body').style.display = _assistantOpen ? 'flex' : 'none';
|
||
document.getElementById('assistant-toggle-icon').textContent = _assistantOpen ? '▲' : '▼';
|
||
}
|
||
async function askAssistant() {
|
||
var inp = document.getElementById('assistant-input');
|
||
var msgs = document.getElementById('assistant-messages');
|
||
var q = inp.value.trim();
|
||
if (!q) return;
|
||
inp.value = '';
|
||
msgs.textContent += '\n\n👤 ' + q + '\n⏳ ...';
|
||
msgs.scrollTop = msgs.scrollHeight;
|
||
try {
|
||
var r = await fetch('/console/api/ai/ask', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json', ...authHeaders() },
|
||
body: JSON.stringify({ mode: 'chat', question: q })
|
||
});
|
||
var d = await r.json();
|
||
msgs.textContent = msgs.textContent.replace('⏳ ...', '🤖 ' + (d.answer || d.error || 'Нет ответа'));
|
||
} catch (e) {
|
||
msgs.textContent = msgs.textContent.replace('⏳ ...', '❌ Ошибка: ' + e.message);
|
||
}
|
||
msgs.scrollTop = msgs.scrollHeight;
|
||
}
|
||
function showGenPrompt() {
|
||
var el = document.getElementById('c-gen-prompt');
|
||
el.style.display = 'flex';
|
||
document.getElementById('c-gen-desc').focus();
|
||
}
|
||
async function aiGenerate() {
|
||
var name = (document.getElementById('c-name').value || '').trim() || 'my-func';
|
||
var lang = document.getElementById('c-lang').value || 'python';
|
||
var desc = (document.getElementById('c-gen-desc').value || '').trim();
|
||
if (!desc) { document.getElementById('c-gen-desc').focus(); return; }
|
||
var btn = document.getElementById('c-gen-btn');
|
||
var resEl = document.getElementById('c-ai-result');
|
||
btn.disabled = true; btn.textContent = '⏳ Генерирую...';
|
||
resEl.style.display = 'block'; resEl.style.background = 'var(--bg-alt)'; resEl.style.color = 'var(--fg)';
|
||
resEl.textContent = 'Запрашиваю у LLM...';
|
||
try {
|
||
var d = await requestJSON('/console/api/ai/ask', 'POST', {
|
||
mode: 'codegen',
|
||
language: lang,
|
||
name: name,
|
||
description: desc
|
||
});
|
||
var code = (d.answer || '').replace(/^```[\w]*\n?/, '').replace(/\n?```$/, '');
|
||
document.getElementById('c-code').value = addLLMWarning(code, lang);
|
||
document.getElementById('c-gen-prompt').style.display = 'none';
|
||
resEl.style.background = '#1a3a1a'; resEl.style.color = '#8f8';
|
||
resEl.textContent = 'Код сгенерирован и вставлен.';
|
||
} catch (e) {
|
||
resEl.style.background = '#3a2a00'; resEl.style.color = '#ffa';
|
||
resEl.textContent = 'Ошибка: ' + e.message;
|
||
} finally {
|
||
btn.disabled = false; btn.textContent = '✨ Сгенерировать код LLM';
|
||
}
|
||
}
|
||
async function aiExplain(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);
|
||
var btnId = codeId === 'c-code' ? 'c-exp-btn' : 'e-exp-btn';
|
||
var btn = document.getElementById(btnId);
|
||
if (!code) { resEl.style.display = 'block'; resEl.style.background = 'var(--bg-alt)'; resEl.textContent = 'Введите код.'; return; }
|
||
btn.disabled = true; btn.textContent = '⏳ Объясняю...';
|
||
resEl.style.display = 'block'; resEl.style.background = 'var(--bg-alt)'; resEl.style.color = 'var(--fg)';
|
||
resEl.textContent = 'Запрашиваю у LLM...';
|
||
try {
|
||
var d = await requestJSON('/console/api/ai/ask', 'POST', {
|
||
mode: 'explain',
|
||
language: lang,
|
||
code: code
|
||
});
|
||
resEl.style.background = '#1a2a3a'; resEl.style.color = '#8cf';
|
||
resEl.textContent = d.answer || '(пустой ответ)';
|
||
} catch (e) {
|
||
resEl.style.background = '#3a2a00'; resEl.style.color = '#ffa';
|
||
resEl.textContent = 'Ошибка: ' + e.message;
|
||
} finally {
|
||
btn.disabled = false; btn.textContent = '📖 LLM: Что делает?';
|
||
}
|
||
}
|
||
// end ai/ask feature
|
||
</script>
|
||
<!-- end ai/ask feature -->
|
||
|
||
</body>
|
||
|
||
</html> |