auto-save 2026-05-11 14:50 (~4)
This commit is contained in:
24
src/app.js
24
src/app.js
@@ -108,20 +108,38 @@ function loadSettings() {
|
||||
if (sm) sm.checked = state.stream;
|
||||
}
|
||||
} catch (e) {}
|
||||
syncModelPick(state.model);
|
||||
}
|
||||
function saveSettings(options = {}) {
|
||||
state.apiBase = document.getElementById("apiBase").value.trim();
|
||||
state.apiKey = document.getElementById("apiKey").value.trim();
|
||||
state.stream = document.getElementById("streamMode").checked;
|
||||
state.model = document.getElementById("modelPick")?.value || state.model;
|
||||
localStorage.setItem(LS_SETTINGS, JSON.stringify({
|
||||
apiBase: state.apiBase,
|
||||
apiKey: state.apiKey,
|
||||
stream: state.stream,
|
||||
model: state.model,
|
||||
}));
|
||||
if (!options.silent) toast("设置已保存");
|
||||
pingBackend();
|
||||
}
|
||||
|
||||
function syncModelPick(modelValue) {
|
||||
const model = (modelValue || state.model || "").trim();
|
||||
const pick = document.getElementById("modelPick");
|
||||
if (!pick || !model) return;
|
||||
let option = Array.from(pick.options).find(item => item.value === model);
|
||||
if (!option) {
|
||||
option = new Option(model, model);
|
||||
pick.appendChild(option);
|
||||
}
|
||||
pick.value = model;
|
||||
state.model = model;
|
||||
const stat = document.getElementById("statModel");
|
||||
if (stat) stat.textContent = option.textContent || model;
|
||||
}
|
||||
|
||||
// ---------- 会话持久化 ----------
|
||||
function loadConversations() {
|
||||
try {
|
||||
@@ -359,7 +377,10 @@ function switchTab(name, options = {}) {
|
||||
if (name === "memory") refreshMemory();
|
||||
if (name === "tools") refreshTools();
|
||||
if (name === "integrations") refreshFeishuApps();
|
||||
if (name === "settings") renderWeeklyReports();
|
||||
if (name === "settings") {
|
||||
renderWeeklyReports();
|
||||
refreshHermesConfig();
|
||||
}
|
||||
if (name === "runs") setTimeout(() => document.getElementById("runPrompt")?.focus(), 50);
|
||||
if (name === "dashboard" && _dashboardDirty) {
|
||||
// 推迟到下一帧,避免阻塞切换动画
|
||||
@@ -616,6 +637,7 @@ function bindChat() {
|
||||
document.getElementById("modelPick").addEventListener("change", (e) => {
|
||||
state.model = e.target.value;
|
||||
document.getElementById("statModel").textContent = e.target.options[e.target.selectedIndex].text;
|
||||
saveSettings({ silent: true });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1189,6 +1189,51 @@ git push # Gitea kangwan/hermes-glass-ui-personal
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模型与 MCP -->
|
||||
<div class="settings-group wide">
|
||||
<div class="settings-group-head">
|
||||
<div class="settings-group-icon">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2v20"/><path d="M2 12h20"/><path d="M4.93 4.93 19.07 19.07"/><path d="M19.07 4.93 4.93 19.07"/></svg>
|
||||
</div>
|
||||
<div>
|
||||
<div class="settings-group-title">模型与 MCP</div>
|
||||
<div class="settings-group-desc">线上 Hermes agent 的默认模型和 MCP server 配置</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-group-body">
|
||||
<div class="settings-grid-3">
|
||||
<div class="settings-field">
|
||||
<label for="hermesModelDefault">默认模型</label>
|
||||
<input type="text" id="hermesModelDefault" placeholder="google/gemini-3.1-pro-preview" autocomplete="off">
|
||||
</div>
|
||||
<div class="settings-field">
|
||||
<label for="hermesModelProvider">Provider</label>
|
||||
<input type="text" id="hermesModelProvider" placeholder="openrouter" autocomplete="off">
|
||||
</div>
|
||||
<div class="settings-field">
|
||||
<label for="hermesModelBaseUrl">Base URL</label>
|
||||
<input type="text" id="hermesModelBaseUrl" placeholder="https://openrouter.ai/api/v1" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-field">
|
||||
<label for="mcpServersYaml">MCP Servers YAML</label>
|
||||
<textarea id="mcpServersYaml" rows="8" spellcheck="false" placeholder='mcp_servers:
|
||||
time:
|
||||
command: uvx
|
||||
args: ["mcp-server-time"]'></textarea>
|
||||
<div class="settings-help">留空会移除 <code>mcp_servers</code>;保存会备份配置并重启 <code>hermes-agent</code>。</div>
|
||||
</div>
|
||||
<div class="settings-actions">
|
||||
<button class="glass-btn-sm" onclick="refreshHermesConfig(true)">读取线上配置</button>
|
||||
<button class="glass-btn-sm primary" id="hermesConfigSaveBtn" onclick="saveHermesConfig()">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><path d="M17 21v-8H7v8"/><path d="M7 3v5h8"/></svg>
|
||||
保存并重启
|
||||
</button>
|
||||
<div class="settings-help" id="hermesConfigStatus">打开设置页后自动读取。</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 对话偏好 -->
|
||||
<div class="settings-group">
|
||||
<div class="settings-group-head">
|
||||
|
||||
Reference in New Issue
Block a user