auto-save 2026-05-11 14:56 (~5)

This commit is contained in:
2026-05-11 14:56:13 +08:00
parent d95aed8917
commit a3a60f151e
5 changed files with 123 additions and 10 deletions

View File

@@ -594,6 +594,100 @@ async function testApiConnection() {
}
}
let _hermesConfigLoaded = false;
let _hermesConfigLoading = false;
function setHermesConfigStatus(text, isError = false) {
const el = document.getElementById("hermesConfigStatus");
if (!el) return;
el.textContent = text;
el.style.color = isError ? "var(--err)" : "";
}
async function refreshHermesConfig(force = false) {
if (_hermesConfigLoading || (_hermesConfigLoaded && !force)) return;
const modelEl = document.getElementById("hermesModelDefault");
if (!modelEl) return;
_hermesConfigLoading = true;
setHermesConfigStatus("正在读取线上配置...");
try {
const res = await fetch("/feishu/hermes-config", {
credentials: "same-origin",
cache: "no-store",
});
const data = await res.json().catch(() => ({}));
if (!res.ok || data.code !== 0) throw new Error(data.msg || ("HTTP " + res.status));
const config = data.config || {};
const model = config.model || {};
document.getElementById("hermesModelDefault").value = model.default || "";
document.getElementById("hermesModelProvider").value = model.provider || "";
document.getElementById("hermesModelBaseUrl").value = model.base_url || "";
document.getElementById("mcpServersYaml").value = config.mcp_servers_yaml || "";
if (model.default) syncModelPick(model.default);
_hermesConfigLoaded = true;
setHermesConfigStatus("已读取线上配置" + (config.lxc ? " · " + config.lxc : ""));
} catch (e) {
setHermesConfigStatus("读取失败: " + (e.message || e), true);
} finally {
_hermesConfigLoading = false;
}
}
async function saveHermesConfig() {
const modelDefault = document.getElementById("hermesModelDefault")?.value.trim() || "";
const provider = document.getElementById("hermesModelProvider")?.value.trim() || "openrouter";
const baseUrl = document.getElementById("hermesModelBaseUrl")?.value.trim() || "";
const mcpServersYaml = document.getElementById("mcpServersYaml")?.value || "";
if (!modelDefault) {
toast("默认模型不能为空");
return;
}
if (!confirm("保存后会重启线上 Hermes agent当前正在生成的任务可能中断。继续吗")) return;
const btn = document.getElementById("hermesConfigSaveBtn");
const oldHTML = btn?.innerHTML;
if (btn) {
btn.disabled = true;
btn.textContent = "保存并重启中...";
}
setHermesConfigStatus("正在写入 config.yaml 并重启 Hermes agent...");
try {
const res = await fetch("/feishu/hermes-config", {
method: "POST",
credentials: "same-origin",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: {
default: modelDefault,
provider,
base_url: baseUrl,
},
mcp_servers_yaml: mcpServersYaml,
restart: true,
}),
});
const data = await res.json().catch(() => ({}));
if (!res.ok || data.code !== 0) throw new Error(data.msg || ("HTTP " + res.status));
const saved = data.config || {};
const savedModel = saved.model || {};
if (savedModel.default) syncModelPick(savedModel.default);
document.getElementById("mcpServersYaml").value = saved.mcp_servers_yaml || "";
_hermesConfigLoaded = false;
setHermesConfigStatus("已保存并重启 · 备份 " + (saved.backup || "已创建"));
toast("模型与 MCP 配置已生效");
setTimeout(() => {
pingBackend();
refreshDashboard();
}, 1800);
} catch (e) {
setHermesConfigStatus("保存失败: " + (e.message || e), true);
toast("保存失败: " + (e.message || e));
} finally {
if (btn) {
btn.disabled = false;
btn.innerHTML = oldHTML;
}
}
}
async function fetchIP() {
const el = document.getElementById("statIP");
if (el) el.textContent = location.hostname;

View File

@@ -2504,6 +2504,14 @@ a { color: var(--orange-3); text-decoration: none; }
gap: 16px;
min-width: 0;
}
.settings-grid-3 {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 14px;
}
@media (max-width: 900px) {
.settings-grid-3 { grid-template-columns: 1fr; }
}
.settings-field {
display: flex;
@@ -2526,7 +2534,8 @@ a { color: var(--orange-3); text-decoration: none; }
}
.settings-field.toggle-field > div:first-child { flex: 1 1 200px; min-width: 0; }
.settings-field input[type="text"],
.settings-field input[type="password"] {
.settings-field input[type="password"],
.settings-field textarea {
width: 100%;
max-width: 100%;
box-sizing: border-box;
@@ -2540,7 +2549,14 @@ a { color: var(--orange-3); text-decoration: none; }
outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
}
.settings-field input:focus {
.settings-field textarea {
min-height: 156px;
resize: vertical;
line-height: 1.55;
font-family: "SF Mono", ui-monospace, Menlo, monospace;
}
.settings-field input:focus,
.settings-field textarea:focus {
border-color: var(--orange);
box-shadow: 0 0 0 3px rgba(255,105,0,0.12);
}

View File

@@ -1,6 +1,6 @@
// 爱马仕 Hermes · 轻量 Service Worker
// 静态壳走 network-first拿不到再回退缓存API 直通
const CACHE = "hermes-ui-v17";
const CACHE = "hermes-ui-v18";
const ASSETS = [
"./",
"./index.html",