From 88d78f063613f6d356877be15c432ad5b0ebfe84 Mon Sep 17 00:00:00 2001 From: JianFeeeee <109188060+JianFeeeee@users.noreply.github.com> Date: Thu, 13 Aug 2026 10:18:53 +0800 Subject: [PATCH] fix: WebUI and handler bug fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend: - handleChat/handleOpenAICompletions: added 60s timeout via context.WithTimeout - handleAgents POST: added config.Put() to persist agent config - handleKnowledge GET: fixed error handling (was swallowing Search errors) - addChatMsg: reduced persistence to latest 50 messages (was 200) - SSE: added Last-Event-ID parsing for reconnection support Frontend: - api(): added HTTP status code checking (throw on non-ok responses) - setInterval(renderAll, 15000): replaced with smartRefresh() that only refreshes data and redraws active non-form tabs - Added btn-warning/btn-success CSS classes - SSE: fixed reconnection防叠加 in onerror handler Tests: all passing --- internal/plugins/webui/dashboard.html | 6243 +++++++++++++++++-------- internal/plugins/webui/handler.go | 71 +- 2 files changed, 4437 insertions(+), 1877 deletions(-) diff --git a/internal/plugins/webui/dashboard.html b/internal/plugins/webui/dashboard.html index c5b354c0..5e5d06ee 100644 --- a/internal/plugins/webui/dashboard.html +++ b/internal/plugins/webui/dashboard.html @@ -1,1912 +1,4413 @@ - + -
- - -' + + __("运行中...", "Running...") + + "
"; + try { + var r = await api("/kernel"); + var tools = r?.tools || []; + var healthTool = tools.find(function (t) { + return t.name === "healthcheck"; + }); + if (!healthTool) { + panel.innerHTML = + '' + + __("healthcheck 工具未注册", "healthcheck tool not registered") + + "
"; + return; + } + panel.innerHTML = + '' + + __( + "通过 Agent 对话触发 healthcheck...", + "Triggering healthcheck via Agent...", + ) + + "
"; + var chatR = await api("/chat", { + method: "POST", + body: JSON.stringify({ + message: __( + "请运行 healthcheck 工具进行全面健康检查并报告结果", + "Please run the healthcheck tool for a full system check and report the results", + ), + }), + }); + panel.innerHTML = + "" + escHtml(JSON.stringify(chatR, null, 2)) + ""; + } catch (e) { + panel.innerHTML = + '
' + + __("错误: ", "Error: ") + + escHtml(e.message) + + "
"; + toast( + __("健康检查失败: ", "Health check failed: ") + e.message, + true, + ); + } + } + + function renderHealthResult(r) { + if (!r || !r.checks) + return ( + '' + + __("暂无健康检查数据", "No health check data") + + "
" + ); + var checks = r.checks || []; + var passed = checks.filter(function (c) { + return c.pass; + }).length; + var failed = checks.filter(function (c) { + return !c.pass; + }).length; + var html = + '' + + __("内核未响应", "Kernel not responding") + + "
' + __("无", "None") + "
"; + } + html += "' + + __("暂无设置项", "No settings") + + "
' + + escHtml(desc) + + "
" + : ""; + html += + '' + + __( + "配置 Model Context Protocol 服务端连接", + "Configure Model Context Protocol server connections", + ) + + "
' + + __("设置面板已加载", "Settings panel loaded") + + "
' + + __( + "上传自定义 Lua 适配器脚本以支持新的 LLM 提供商。脚本文件将保存到适配器目录并自动加载到 Lua VM。", + "Upload custom Lua adapter scripts to support new LLM providers. Scripts are saved to the adapter directory and auto-loaded into the Lua VM.", + ) + + "
' + + __("暂无适配器", "No adapters") + + "
"; + } else { + html += + "| " + + __("名称", "Name") + + " | " + + __("版本", "Version") + + " | " + + __("操作", "Actions") + + " |
|---|---|---|
| " + + escHtml(a.name) + + " | " + + escHtml(a.version || "-") + + " | " + + '
' + + __("加载适配器失败: ", "Failed to load adapters: ") + + escHtml(e.message) + + "