更新 lib/page.js

This commit is contained in:
QQ 2026-11-12 00:55:07 +08:00
parent 23f4e5a7ad
commit 5f4bdc510f
1 changed files with 189 additions and 84 deletions

View File

@ -27,94 +27,193 @@ export function renderConfigPage(options) {
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>云端记忆 · DSH 插件</title>
<title>DSH Brain · 云端记忆</title>
<style>
:root { color-scheme: light dark; }
* { box-sizing: border-box; }
body {
margin: 0;
padding: 32px 24px 64px;
font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
background: #f6f7f9;
color: #1c1f23;
:root {
color-scheme: light dark;
--bg: #f4f5fa; --card: #ffffff; --ink: #191c22; --ink2: #5b6472; --ink3: #8a93a3;
--line: #e4e7f0; --field: #fbfbfe; --field-line: #d8dce8;
--brand: #6366f1; --brand2: #8b5cf6; --brand-ink: #4f46e5;
--shadow: 0 1px 2px rgba(23, 25, 60, .04), 0 8px 24px -12px rgba(23, 25, 60, .12);
--ok-bg: #e5f7ec; --ok: #177245; --bad-bg: #fdecec; --bad: #b3261e;
--warn-bg: #fff4d6; --warn: #8a5a00; --sk-bg: #edf0f6; --sk: #55606d;
--code-bg: #eef0f7; --track: #d5d9e6;
}
@media (prefers-color-scheme: dark) {
body { background: #14161a; color: #e6e8eb; }
.card { background: #1c1f24 !important; border-color: #2b303a !important; }
input, select { background: #12141a !important; color: #e6e8eb !important; border-color: #333a45 !important; }
th { color: #9aa3af !important; }
tr + tr td { border-color: #262b33 !important; }
.muted { color: #8b949e !important; }
code { background: #22262d !important; }
:root {
--bg: #101218; --card: #171a21; --ink: #e8eaf0; --ink2: #a3abb9; --ink3: #767f8f;
--line: #262b36; --field: #12151c; --field-line: #313947;
--brand-ink: #a5b4fc; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -12px rgba(0,0,0,.5);
--ok-bg: #123324; --ok: #4ade80; --bad-bg: #3d1a17; --bad: #f28b82;
--warn-bg: #3a2f10; --warn: #fbbf24; --sk-bg: #232833; --sk: #9aa3af;
--code-bg: #22262f; --track: #39415a;
}
}
.wrap { max-width: 980px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: .2px; }
h2 { font-size: 14px; margin: 0 0 14px; font-weight: 600; letter-spacing: .3px; }
.sub { margin: 0 0 24px; color: #5c6672; font-size: 13px; }
@media (prefers-color-scheme: dark) { .sub { color: #8b949e; } }
* { box-sizing: border-box; }
body {
margin: 0; padding: 40px 24px 56px;
font: 14px/1.65 -apple-system, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
color: var(--ink);
background:
radial-gradient(720px 300px at 12% -60px, rgba(99,102,241,.13), transparent 70%),
radial-gradient(640px 280px at 88% -40px, rgba(139,92,246,.10), transparent 70%),
var(--bg);
background-attachment: fixed;
}
.wrap { max-width: 1020px; margin: 0 auto; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
/* ---------- masthead ---------- */
.masthead { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.logo {
width: 54px; height: 54px; border-radius: 16px; flex: none;
display: flex; align-items: center; justify-content: center; font-size: 28px;
background: linear-gradient(135deg, var(--brand), var(--brand2));
box-shadow: 0 8px 20px -6px rgba(99,102,241,.55);
}
.masthead h1 { font-size: 24px; margin: 0; letter-spacing: .2px; line-height: 1.25; }
.masthead h1 .thin { font-weight: 500; color: var(--ink2); }
.ver {
font-size: 11.5px; font-weight: 600; color: var(--brand-ink);
background: color-mix(in srgb, var(--brand) 12%, transparent);
padding: 2px 9px; border-radius: 999px; vertical-align: 3px; margin-left: 8px; white-space: nowrap;
}
.tagline { margin: 2px 0 0; color: var(--ink2); font-size: 13px; }
.mast-actions { margin-left: auto; flex: none; }
.btn-link {
display: inline-flex; align-items: center; gap: 7px;
padding: 9px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand2));
box-shadow: 0 6px 16px -6px rgba(99,102,241,.6);
}
.btn-link:hover { text-decoration: none; filter: brightness(1.06); }
.rule { height: 3px; border-radius: 3px; margin: 18px 0 22px;
background: linear-gradient(90deg, var(--brand), var(--brand2), transparent 75%); opacity: .55; }
/* ---------- cards ---------- */
.card {
background: #fff; border: 1px solid #e3e6ea; border-radius: 12px;
padding: 20px 22px; margin-bottom: 18px;
background: var(--card); border: 1px solid var(--line); border-radius: 16px;
padding: 22px 24px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.card-head { display: flex; align-items: center; gap: 11px; margin-bottom: 16px; }
.chip {
width: 32px; height: 32px; border-radius: 10px; flex: none; font-size: 16px;
display: flex; align-items: center; justify-content: center;
background: color-mix(in srgb, var(--brand) 12%, transparent);
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.card-head .desc { margin-left: auto; font-size: 12px; color: var(--ink3); text-align: right; }
/* ---------- forms ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }
label { display: block; font-size: 12px; font-weight: 600; color: #4a5361; margin-bottom: 6px; }
@media (prefers-color-scheme: dark) { label { color: #a7b0bb; } }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink2); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number] {
width: 100%; padding: 9px 11px; font: inherit; font-size: 13px;
border: 1px solid #d7dbe1; border-radius: 8px; background: #fdfdfe; color: inherit;
width: 100%; padding: 10px 12px; font: inherit; font-size: 13.5px;
border: 1px solid var(--field-line); border-radius: 10px; background: var(--field); color: var(--ink);
transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus { outline: 2px solid #4b7bec33; border-color: #4b7bec; }
.hint { font-size: 12px; color: #6b7480; margin-top: 5px; }
.muted { color: #6b7480; }
input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.hint { font-size: 12px; color: var(--ink3); margin-top: 6px; }
.muted { color: var(--ink3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
button {
font: inherit; font-size: 13px; padding: 9px 16px; border-radius: 8px;
border: 1px solid #d7dbe1; background: #fff; color: inherit; cursor: pointer;
transition: background .15s ease, border-color .15s ease;
.tip { margin-top: 14px; font-size: 12.5px; color: var(--ink2); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; background: var(--code-bg); padding: 1px 6px; border-radius: 5px; }
/* ---------- toggles ---------- */
.toggles { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 6px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 10px 2px; cursor: pointer; margin: 0; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track {
width: 40px; height: 22px; border-radius: 999px; flex: none; position: relative;
background: var(--track); transition: background .18s ease;
}
button:hover { background: #f2f4f7; }
button.primary { background: #2f6fed; border-color: #2f6fed; color: #fff; }
button.primary:hover { background: #255fd4; }
button:disabled { opacity: .55; cursor: default; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 2px; }
.stat { flex: 1 1 120px; border: 1px solid #e6e9ee; border-radius: 9px; padding: 10px 12px; }
@media (prefers-color-scheme: dark) { .stat { border-color: #2b303a; } }
.stat .k { font-size: 11px; letter-spacing: .4px; color: #6b7480; text-transform: uppercase; }
.stat .v { font-size: 18px; font-weight: 600; margin-top: 2px; }
.toggle .track::after {
content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .18s ease;
}
.toggle input:checked + .track { background: linear-gradient(135deg, var(--brand), var(--brand2)); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }
.toggle .ttitle { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.toggle .tdesc { display: block; font-size: 12px; color: var(--ink3); font-weight: 400; }
.inline-field { display: flex; align-items: center; gap: 12px; padding: 8px 2px 2px; }
.inline-field label { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.inline-field input { max-width: 150px; }
/* ---------- buttons ---------- */
button {
font: inherit; font-size: 13.5px; font-weight: 550; padding: 9px 18px; border-radius: 10px;
border: 1px solid var(--field-line); background: var(--card); color: var(--ink); cursor: pointer;
transition: all .15s ease;
}
button:hover { border-color: var(--brand); color: var(--brand-ink); transform: translateY(-1px); }
button.primary {
background: linear-gradient(135deg, var(--brand), var(--brand2)); border: none; color: #fff;
box-shadow: 0 6px 16px -6px rgba(99,102,241,.55); padding: 10px 20px;
}
button.primary:hover { color: #fff; filter: brightness(1.07); }
button:disabled { opacity: .55; cursor: default; transform: none; }
/* ---------- stats ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
flex: 1 1 118px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 10px;
background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 4%, transparent), transparent 65%);
position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
background: linear-gradient(90deg, var(--brand), var(--brand2)); opacity: .35; }
.stat:nth-child(3)::before, .stat:nth-child(7)::before { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.stat .k { font-size: 11.5px; letter-spacing: .5px; color: var(--ink3); font-weight: 600; }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 1px; font-variant-numeric: tabular-nums; }
/* ---------- pills / table ---------- */
.pill { display: inline-block; padding: 1.5px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.ok { background: var(--ok-bg); color: var(--ok); }
.bad { background: var(--bad-bg); color: var(--bad); }
.warn { background: var(--warn-bg); color: var(--warn); }
.sk { background: var(--sk-bg); color: var(--sk); }
.table-wrap { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font-size: 11px; letter-spacing: .4px; text-transform: uppercase; color: #6b7480; padding: 6px 8px; }
td { padding: 7px 8px; border-top: 1px solid #eef1f4; vertical-align: top; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; background: #f1f3f6; padding: 1px 5px; border-radius: 4px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.ok { background: #e6f6ec; color: #1c7c43; }
.bad { background: #fdeaea; color: #b3261e; }
.warn { background: #fff5e0; color: #92600a; }
.sk { background: #eef1f5; color: #55606d; }
.tip { margin-top: 14px; font-size: 12px; color: #6b7480; }
th { text-align: left; font-size: 11px; letter-spacing: .6px; color: var(--ink3); font-weight: 600;
padding: 9px 12px; background: color-mix(in srgb, var(--brand) 5%, transparent); }
td { padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
tbody tr:hover td { background: color-mix(in srgb, var(--brand) 4%, transparent); }
.foot { text-align: center; color: var(--ink3); font-size: 12px; margin-top: 26px; }
.toast {
position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
background: #1c1f23; color: #fff; padding: 10px 18px; border-radius: 999px;
background: #1c1f23; color: #fff; padding: 11px 20px; border-radius: 999px;
font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s ease;
max-width: 80vw; text-align: center;
max-width: 80vw; text-align: center; box-shadow: 0 12px 32px rgba(0,0,0,.3); z-index: 10;
}
.toast.show { opacity: .95; }
.toast.show { opacity: .97; }
</style>
</head>
<body>
<div class="wrap">
<h1>云端记忆 · DSH 插件</h1>
<p class="sub">v${escapeHtml(options.version)} · 每轮结束上报活动计数 · 提供 memory_search / memory_read / memory_add 工具</p>
<p class="sub"><a href="/dsh-brain/skills">技能管理(列表 · 启停 · 安装)→</a></p>
<header class="masthead">
<div class="logo">🧠</div>
<div>
<h1>DSH Brain<span class="thin"> · 云端记忆</span><span class="ver">v${escapeHtml(options.version)}</span></h1>
<p class="tagline">每轮结束上报活动计数 · 提供 memory_search / memory_read / memory_add 工具</p>
</div>
<div class="mast-actions">
<a class="btn-link" href="/dsh-brain/skills">技能管理 →</a>
</div>
</header>
<div class="rule"></div>
<section class="card">
<h2>当前状态</h2>
<div class="card-head"><span class="chip">📊</span><h2>当前状态</h2><span class="desc">每 15 秒自动刷新</span></div>
<div class="stats" id="stats"></div>
<div class="tip" id="statDetail">加载中…</div>
</section>
<section class="card">
<h2>连接配置</h2>
<div class="card-head"><span class="chip">🔌</span><h2>连接配置</h2></div>
<div class="grid">
<div>
<label for="baseUrl">服务基址</label>
@ -135,24 +234,26 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
<input id="defaultK" type="number" min="1" max="100" />
</div>
</div>
<div class="row" style="margin-top:14px">
<label style="margin:0;display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500">
<input id="enabled" type="checkbox" style="width:auto" /> 启用插件(关闭后不上报、不提供工具)
<div class="toggles">
<label class="toggle" for="enabled">
<input id="enabled" type="checkbox" />
<span class="track"></span>
<span><span class="ttitle">启用插件</span><span class="tdesc">关闭后不上报、不提供工具</span></span>
</label>
</div>
<div class="row" style="margin-top:10px">
<label style="margin:0;display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500">
<input id="summaryEnabled" type="checkbox" style="width:auto" /> 轮次结束后自动生成待确认摘要(只进入待确认队列,确认后才写云端)
<label class="toggle" for="summaryEnabled">
<input id="summaryEnabled" type="checkbox" />
<span class="track"></span>
<span><span class="ttitle">轮次结束后自动生成待确认摘要</span><span class="tdesc">只进入待确认队列,确认后才写云端</span></span>
</label>
</div>
<div class="row" style="margin-top:10px;align-items:center;gap:10px">
<label for="summaryMaxChars" style="margin:0;font-size:13px;font-weight:500">单轮摘要字数上限</label>
<input id="summaryMaxChars" type="number" min="1000" max="16000" step="500" style="max-width:140px" />
<div class="inline-field">
<label for="summaryMaxChars">单轮摘要字数上限</label>
<input id="summaryMaxChars" type="number" min="1000" max="16000" step="500" />
</div>
</div>
</section>
<section class="card">
<h2>账号登录</h2>
<div class="card-head"><span class="chip">🔑</span><h2>账号登录</h2><span class="desc">用账号一次性换取令牌,密码不保存</span></div>
<div class="grid">
<div>
<label for="username">用户名</label>
@ -163,7 +264,7 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
<input id="password" type="password" spellcheck="false" autocomplete="current-password" placeholder="只用于本次换取令牌" />
</div>
</div>
<div class="row" style="margin-top:14px">
<div class="row" style="margin-top:16px">
<button class="primary" id="login">登录并获取令牌</button>
</div>
<div class="tip">
@ -174,7 +275,7 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
</section>
<section class="card">
<h2>访问令牌</h2>
<div class="card-head"><span class="chip">🎫</span><h2>访问令牌</h2><span class="desc">只存本机,页面只显示掩码</span></div>
<div class="grid">
<div>
<label for="activityToken">活动上报令牌(activity:write)</label>
@ -192,7 +293,7 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
<div class="hint" id="summaryTokenHint">用于 POST /activity/summary:只把已脱敏摘要送进待确认队列。</div>
</div>
</div>
<div class="row" style="margin-top:14px">
<div class="row" style="margin-top:16px">
<button class="primary" id="save">保存配置</button>
<button id="clearTokens">清除已存令牌</button>
</div>
@ -203,7 +304,7 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
</section>
<section class="card">
<h2>诊断</h2>
<div class="card-head"><span class="chip">🩺</span><h2>诊断</h2></div>
<div class="row">
<button id="test">测试连接</button>
<button id="flush">重试上报队列</button>
@ -213,14 +314,18 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
</section>
<section class="card">
<h2>最近上报</h2>
<table>
<thead>
<tr><th>时间</th><th>状态</th><th>结果</th><th>HTTP</th><th>turn_id</th></tr>
</thead>
<tbody id="recent"><tr><td colspan="5" class="muted">暂无记录</td></tr></tbody>
</table>
<div class="card-head"><span class="chip">🕘</span><h2>最近上报</h2></div>
<div class="table-wrap">
<table>
<thead>
<tr><th>时间</th><th>状态</th><th>结果</th><th>HTTP</th><th>turn_id</th></tr>
</thead>
<tbody id="recent"><tr><td colspan="5" class="muted">暂无记录</td></tr></tbody>
</table>
</div>
</section>
<p class="foot">DSH Brain · 云端记忆插件 — 配置只保存在这台机器上</p>
</div>
<div class="toast" id="toast"></div>
<script>