dsh-aurorix-agentbook 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/web.js +245 -143
- package/package.json +1 -1
package/lib/web.js
CHANGED
|
@@ -10,174 +10,222 @@ import { existsSync } from 'node:fs'
|
|
|
10
10
|
|
|
11
11
|
const PAGE_TITLE = '记忆库'
|
|
12
12
|
|
|
13
|
-
/** 页面 HTML
|
|
13
|
+
/** 页面 HTML。信息架构与 dsh-go 原生面板一致:分层计数 → 召回 → 保险箱 → 写一条 → 详情。 */
|
|
14
14
|
export function pageHtml(locale = 'zh-CN') {
|
|
15
15
|
const zh = !String(locale).toLowerCase().startsWith('en')
|
|
16
16
|
const t = zh
|
|
17
|
-
? { title:
|
|
18
|
-
: { title:
|
|
17
|
+
? { title:'记忆库', total:(n)=>`共 ${n} 条`, recall:'搜一条', recallPh:'关键词,回车或点右侧', vault:'保险箱', vaultPh:'按标识或用途筛选', write:'写一条', plane:'平面', wTitle:'标题', wBody:'正文', wRead:'读时机(什么时候该读这条)', save:'保存', detail:'详情', edit:'编辑', cancel:'取消', back:'返回', del:'删除', empty:'还没有记录', emptyHit:'没有匹配的记录', emptyVault:'保险箱是空的', loading:'读取中…', ok:'已保存', fail:'操作失败:', purpose:'用途', updated:'更新时间', id:'ID', bytes:'大小', verified:'校验' }
|
|
18
|
+
: { title:'Memory', total:(n)=>`${n} records`, recall:'Search', recallPh:'keyword, Enter to search', vault:'Vault', vaultPh:'filter by ident or purpose', write:'Write', plane:'Plane', wTitle:'Title', wBody:'Body', wRead:'Read when', save:'Save', detail:'Detail', edit:'Edit', cancel:'Cancel', back:'Back', del:'Delete', empty:'Nothing yet', emptyHit:'No match', emptyVault:'Vault is empty', loading:'Loading…', ok:'Saved', fail:'Failed: ', purpose:'Purpose', updated:'Updated', id:'ID', bytes:'Size', verified:'Verified' }
|
|
19
19
|
|
|
20
20
|
return `<!doctype html>
|
|
21
21
|
<html lang="${zh ? 'zh-CN' : 'en'}"><head>
|
|
22
|
-
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
22
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|
23
23
|
<title>${t.title}</title>
|
|
24
24
|
<style>
|
|
25
|
-
:root{
|
|
26
|
-
|
|
25
|
+
:root{
|
|
26
|
+
--bg:#0f1312;--card:#161c1b;--card2:#1c2423;--ink:#e9efee;--muted:#8d9c99;--line:#26302e;
|
|
27
|
+
--accent:#5fd3c6;--accent-ink:#06201d;--accent-weak:#14302c;--danger:#f97066;
|
|
28
|
+
}
|
|
29
|
+
@media (prefers-color-scheme:light){:root{
|
|
30
|
+
--bg:#f6f8f7;--card:#fff;--card2:#f2f5f4;--ink:#141a19;--muted:#66716f;--line:#e2e8e6;
|
|
31
|
+
--accent:#0f766e;--accent-ink:#fff;--accent-weak:#e4f3f0;--danger:#c0261d;
|
|
32
|
+
}}
|
|
27
33
|
*{box-sizing:border-box}
|
|
28
|
-
body{margin:0;background:var(--bg);color:var(--ink)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
html,body{margin:0;background:var(--bg);color:var(--ink)}
|
|
35
|
+
body{font:15px/1.6 -apple-system,system-ui,"PingFang SC","Noto Sans CJK SC",sans-serif;-webkit-font-smoothing:antialiased}
|
|
36
|
+
.wrap{max-width:820px;margin:0 auto;padding:20px 16px 80px}
|
|
37
|
+
header{display:flex;align-items:baseline;gap:10px;margin-bottom:16px}
|
|
38
|
+
h1{font-size:20px;font-weight:600;margin:0;letter-spacing:.01em}
|
|
39
|
+
.total{color:var(--muted);font-size:13px;font-variant-numeric:tabular-nums}
|
|
40
|
+
h2{font-size:14px;font-weight:600;margin:0 0 12px;color:var(--muted);letter-spacing:.02em}
|
|
41
|
+
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:16px;margin-bottom:14px}
|
|
42
|
+
.planes{display:flex;flex-wrap:wrap;gap:7px;margin-bottom:14px}
|
|
43
|
+
.pill{background:var(--card);border:1px solid var(--line);border-radius:999px;padding:5px 11px;font-size:12.5px;color:var(--muted);font-variant-numeric:tabular-nums}
|
|
44
|
+
.pill b{color:var(--ink);font-weight:600;margin-left:5px}
|
|
45
|
+
.row{display:flex;gap:9px}
|
|
46
|
+
input,textarea,select{width:100%;background:var(--card2);border:1px solid var(--line);border-radius:10px;padding:10px 12px;color:var(--ink);font:inherit;outline:none}
|
|
47
|
+
input:focus,textarea:focus,select:focus{border-color:var(--accent)}
|
|
48
|
+
textarea{min-height:140px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13.5px;line-height:1.65}
|
|
49
|
+
button{background:var(--accent);color:var(--accent-ink);border:0;border-radius:10px;padding:10px 16px;font:inherit;font-weight:500;cursor:pointer;white-space:nowrap}
|
|
50
|
+
button.ghost{background:transparent;color:var(--accent);border:1px solid var(--line)}
|
|
40
51
|
button:disabled{opacity:.5;cursor:default}
|
|
41
|
-
.
|
|
42
|
-
.
|
|
43
|
-
.
|
|
44
|
-
.item
|
|
45
|
-
.item
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
<div class="row"><input id="q" placeholder="${t.search}" autocomplete="off"><button id="go">${t.search}</button></div>
|
|
60
|
-
</div>
|
|
52
|
+
.field{margin-bottom:12px}
|
|
53
|
+
.label{font-size:12.5px;color:var(--muted);margin-bottom:6px}
|
|
54
|
+
.list{margin-top:12px}
|
|
55
|
+
.item{padding:11px 12px;border-radius:10px;cursor:pointer;border:1px solid transparent}
|
|
56
|
+
.item:hover{background:var(--card2);border-color:var(--line)}
|
|
57
|
+
.item .t{font-weight:500;font-size:14.5px}
|
|
58
|
+
.item .m{color:var(--muted);font-size:12.5px;margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
59
|
+
.hint{color:var(--muted);font-size:13px;padding:8px 0}
|
|
60
|
+
.err{color:var(--danger);font-size:13px;margin-top:10px}
|
|
61
|
+
#detail{position:fixed;inset:0;background:var(--bg);overflow:auto;display:none;z-index:9}
|
|
62
|
+
#detail.on{display:block}
|
|
63
|
+
#detail .inner{max-width:820px;margin:0 auto;padding:20px 16px 80px}
|
|
64
|
+
.dtitle{font-size:19px;font-weight:600;line-height:1.4;margin-bottom:14px}
|
|
65
|
+
.meta{display:grid;grid-template-columns:auto 1fr;gap:7px 16px;font-size:13px;color:var(--muted);margin-bottom:16px;padding:12px 14px;background:var(--card);border:1px solid var(--line);border-radius:12px}
|
|
66
|
+
.meta b{font-weight:500}
|
|
67
|
+
.body{white-space:pre-wrap;word-break:break-word;font-size:14.5px;line-height:1.75;background:var(--card);border:1px solid var(--line);border-radius:12px;padding:16px}
|
|
68
|
+
.acts{display:flex;gap:9px;flex-wrap:wrap;margin-top:18px}
|
|
69
|
+
</style></head><body>
|
|
61
70
|
|
|
62
|
-
<div class="
|
|
71
|
+
<div class="wrap">
|
|
72
|
+
<header><h1>${t.title}</h1><span class="total" id="total"></span></header>
|
|
73
|
+
<div class="planes" id="planes"></div>
|
|
63
74
|
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<
|
|
71
|
-
<button class="
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
<section class="card">
|
|
76
|
+
<div class="row"><input id="q" placeholder="${t.recallPh}" autocomplete="off"><button id="go">${t.recall}</button></div>
|
|
77
|
+
<div class="list" id="results"></div>
|
|
78
|
+
</section>
|
|
79
|
+
|
|
80
|
+
<section class="card">
|
|
81
|
+
<h2>${t.vault}</h2>
|
|
82
|
+
<div class="row"><input id="vq" placeholder="${t.vaultPh}" autocomplete="off"><button class="ghost" id="vgo">${t.recall}</button></div>
|
|
83
|
+
<div class="list" id="vlist"></div>
|
|
84
|
+
</section>
|
|
85
|
+
|
|
86
|
+
<section class="card">
|
|
87
|
+
<h2>${t.write}</h2>
|
|
88
|
+
<div class="field"><div class="label">${t.plane}</div>
|
|
89
|
+
<select id="wp"><option value="explicit">explicit</option><option value="long_term">long_term</option><option value="episodic">episodic</option><option value="rules">rules</option><option value="profile">profile</option><option value="soul">soul</option></select></div>
|
|
90
|
+
<div class="field"><div class="label">${t.wTitle}</div><input id="wt"></div>
|
|
91
|
+
<div class="field"><div class="label">${t.wBody}</div><textarea id="wb"></textarea></div>
|
|
92
|
+
<div class="field"><div class="label">${t.wRead}</div><input id="wr"></div>
|
|
93
|
+
<button id="wsave">${t.save}</button>
|
|
94
|
+
<div class="err" id="werr"></div>
|
|
95
|
+
</section>
|
|
75
96
|
</div>
|
|
97
|
+
|
|
98
|
+
<div id="detail"><div class="inner">
|
|
99
|
+
<div class="dtitle" id="dt"></div>
|
|
100
|
+
<div class="meta" id="dm"></div>
|
|
101
|
+
<div class="body" id="db"></div>
|
|
102
|
+
<div id="de" style="display:none"></div>
|
|
103
|
+
<div class="acts">
|
|
104
|
+
<button class="ghost" id="dback">${t.back}</button>
|
|
105
|
+
<button class="ghost" id="dedit">${t.edit}</button>
|
|
106
|
+
<button id="dsave" style="display:none">${t.save}</button>
|
|
107
|
+
<button class="ghost" id="dcancel" style="display:none">${t.cancel}</button>
|
|
108
|
+
</div>
|
|
109
|
+
<div class="err" id="derr"></div>
|
|
110
|
+
</div></div>
|
|
111
|
+
|
|
76
112
|
<script>
|
|
77
113
|
const T = ${JSON.stringify(t)};
|
|
78
|
-
let S = { planes:{}, total:0, hits:[], detail:null, editing:false, draft:{} };
|
|
79
|
-
|
|
80
114
|
const $ = (id) => document.getElementById(id);
|
|
81
|
-
const esc = (
|
|
115
|
+
const esc = (v) => String(v == null ? '' : v).replace(/[&<>"]/g, (c) => ({'&':'&','<':'<','>':'>','"':'"'}[c]));
|
|
116
|
+
let D = null; // 当前详情
|
|
117
|
+
let EDITING = false;
|
|
82
118
|
|
|
83
|
-
async function api(
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!r.ok) throw new Error('HTTP ' + r.status + ' ' +
|
|
88
|
-
return
|
|
119
|
+
async function api(name, body) {
|
|
120
|
+
const opt = body === undefined ? {} : { method:'POST', headers:{'content-type':'application/json'}, body: JSON.stringify(body) };
|
|
121
|
+
const r = await fetch('api/' + name, opt);
|
|
122
|
+
const text = await r.text();
|
|
123
|
+
if (!r.ok) throw new Error('HTTP ' + r.status + ' ' + text.slice(0, 100));
|
|
124
|
+
return JSON.parse(text);
|
|
89
125
|
}
|
|
90
126
|
|
|
91
|
-
function renderPlanes() {
|
|
92
|
-
const
|
|
93
|
-
$('planes').innerHTML =
|
|
94
|
-
$('
|
|
127
|
+
function renderPlanes(planes, total) {
|
|
128
|
+
const order = ['soul','rules','profile','explicit','long_term','episodic'];
|
|
129
|
+
$('planes').innerHTML = order.map((k) => '<span class="pill">' + k + '<b>' + (planes[k] || 0) + '</b></span>').join('');
|
|
130
|
+
$('total').textContent = T.total(total || 0);
|
|
95
131
|
}
|
|
96
132
|
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
[...document.querySelectorAll('.item')].forEach((el) => {
|
|
104
|
-
el.onclick = () => openDetail((S.hits || [])[Number(el.dataset.i)]);
|
|
133
|
+
function renderItems(el, rows, kind, emptyText) {
|
|
134
|
+
if (!rows || rows.length === 0) { el.innerHTML = '<div class="hint">' + esc(emptyText) + '</div>'; return; }
|
|
135
|
+
el.innerHTML = rows.map((r, i) => '<div class="item" data-i="' + i + '"><div class="t">' + esc(r.title || r.ident || '(无标题)') +
|
|
136
|
+
'</div><div class="m">' + esc((r.plane ? r.plane + ' · ' : '') + String(r.preview || r.purpose || '').slice(0, 90)) + '</div></div>').join('');
|
|
137
|
+
[...el.querySelectorAll('.item')].forEach((node) => {
|
|
138
|
+
node.onclick = () => openDetail(rows[Number(node.dataset.i)], kind);
|
|
105
139
|
});
|
|
106
140
|
}
|
|
107
141
|
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
: [['平面', d.plane || '—'], ['更新时间', d.updated || '—'], ['ID', d.id]];
|
|
117
|
-
const body = (d.blocks && d.blocks.length ? d.blocks.join('\\n\\n') : d.body) || '';
|
|
118
|
-
$('detailView').innerHTML =
|
|
119
|
-
'<div class="t" style="font-weight:600;font-size:17px">' + esc(d.title || '—') + '</div>' +
|
|
120
|
-
'<div class="meta">' + meta.map(([k, v]) => '<b>' + esc(k) + '</b><span>' + esc(v) + '</span>').join('') + '</div>' +
|
|
121
|
-
'<div class="body">' + esc(body) + '</div>';
|
|
122
|
-
|
|
123
|
-
const fields = isVault
|
|
124
|
-
? '<div style="margin-bottom:10px"><div class="m">' + T.purpose + '</div><input id="f-purpose" value="' + esc(S.draft.purpose || '') + '"></div>' +
|
|
125
|
-
'<div><div class="m">' + T.bodyField + '</div><textarea id="f-body">' + esc(S.draft.body || '') + '</textarea></div>'
|
|
126
|
-
: '<div style="margin-bottom:10px"><div class="m">' + T.titleField + '</div><input id="f-title" value="' + esc(S.draft.title || '') + '"></div>' +
|
|
127
|
-
'<div style="margin-bottom:10px"><div class="m">' + T.readWhen + '</div><input id="f-read" value="' + esc(S.draft.readWhen || '') + '"></div>' +
|
|
128
|
-
'<div><div class="m">' + T.bodyField + '</div><textarea id="f-body">' + esc(S.draft.body || '') + '</textarea></div>';
|
|
129
|
-
$('detailEdit').innerHTML = fields;
|
|
130
|
-
$('detailEdit').classList.toggle('hide', !S.editing);
|
|
131
|
-
$('detailView').classList.toggle('hide', S.editing);
|
|
132
|
-
$('edit').classList.toggle('hide', S.editing);
|
|
133
|
-
$('save').classList.toggle('hide', !S.editing);
|
|
134
|
-
$('cancel').classList.toggle('hide', !S.editing);
|
|
142
|
+
async function boot() {
|
|
143
|
+
try {
|
|
144
|
+
const s = await api('state');
|
|
145
|
+
renderPlanes(s.planes, s.total);
|
|
146
|
+
renderItems($('results'), s.hits, 'memory', T.empty);
|
|
147
|
+
const v = await api('vault-list', {});
|
|
148
|
+
renderItems($('vlist'), v.items, 'vault', T.emptyVault);
|
|
149
|
+
} catch (e) { $('results').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>'; }
|
|
135
150
|
}
|
|
136
151
|
|
|
137
|
-
async function openDetail(
|
|
152
|
+
async function openDetail(row, kind) {
|
|
138
153
|
try {
|
|
139
|
-
const d = await api('detail', { id:
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
const d = await api('detail', { id: row.id || row.ident, kind });
|
|
155
|
+
if (!d.ok) throw new Error(d.reason || 'read failed');
|
|
156
|
+
D = d.detail; EDITING = false;
|
|
157
|
+
show();
|
|
158
|
+
$('detail').classList.add('on');
|
|
159
|
+
} catch (e) { alert(T.fail + e.message); }
|
|
142
160
|
}
|
|
143
161
|
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
$('
|
|
162
|
+
function show() {
|
|
163
|
+
const isVault = D.kind === 'vault';
|
|
164
|
+
$('dt').textContent = D.title || '—';
|
|
165
|
+
const rows = isVault
|
|
166
|
+
? [[T.id, D.id], [T.purpose, D.purpose || '—'], [T.bytes, (D.bytes || 0) + ' B']]
|
|
167
|
+
: [[T.plane, D.plane || '—'], [T.updated, D.updated || '—'], [T.id, D.id]];
|
|
168
|
+
$('dm').innerHTML = rows.map(([k, v]) => '<b>' + esc(k) + '</b><span>' + esc(v) + '</span>').join('');
|
|
169
|
+
$('db').textContent = D.body || '';
|
|
170
|
+
$('db').style.display = EDITING ? 'none' : '';
|
|
171
|
+
$('de').style.display = EDITING ? '' : 'none';
|
|
172
|
+
if (EDITING) {
|
|
173
|
+
$('de').innerHTML = isVault
|
|
174
|
+
? '<div class="field"><div class="label">' + T.purpose + '</div><input id="ep" value="' + esc(D.purpose || '') + '"></div>' +
|
|
175
|
+
'<div class="field"><div class="label">' + T.wBody + '</div><textarea id="eb">' + esc(D.body || '') + '</textarea></div>'
|
|
176
|
+
: '<div class="field"><div class="label">' + T.wTitle + '</div><input id="et" value="' + esc(D.title || '') + '"></div>' +
|
|
177
|
+
'<div class="field"><div class="label">' + T.wRead + '</div><input id="er" value="' + esc(D.readWhen || '') + '"></div>' +
|
|
178
|
+
'<div class="field"><div class="label">' + T.wBody + '</div><textarea id="eb">' + esc(D.body || '') + '</textarea></div>';
|
|
179
|
+
}
|
|
180
|
+
$('dedit').style.display = EDITING ? 'none' : '';
|
|
181
|
+
$('dsave').style.display = EDITING ? '' : 'none';
|
|
182
|
+
$('dcancel').style.display = EDITING ? '' : 'none';
|
|
183
|
+
$('derr').textContent = '';
|
|
147
184
|
}
|
|
148
185
|
|
|
149
|
-
$('
|
|
150
|
-
$('
|
|
151
|
-
$('
|
|
152
|
-
$('
|
|
153
|
-
const isVault =
|
|
154
|
-
const payload = isVault
|
|
155
|
-
? { ident: S.detail.id, purpose: $('f-purpose').value, body: $('f-body').value }
|
|
156
|
-
: { id: S.detail.id, title: $('f-title').value, readWhen: $('f-read').value, body: $('f-body').value };
|
|
186
|
+
$('dback').onclick = () => { $('detail').classList.remove('on'); D = null; };
|
|
187
|
+
$('dedit').onclick = () => { EDITING = true; show(); };
|
|
188
|
+
$('dcancel').onclick = () => { EDITING = false; show(); };
|
|
189
|
+
$('dsave').onclick = async () => {
|
|
190
|
+
const isVault = D.kind === 'vault';
|
|
157
191
|
try {
|
|
158
|
-
const r =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
192
|
+
const r = isVault
|
|
193
|
+
? await api('vault-save', { ident: D.id, purpose: $('ep').value, body: $('eb').value })
|
|
194
|
+
: await api('save', { id: D.id, title: $('et').value, readWhen: $('er').value, body: $('eb').value, revision: D.revision });
|
|
195
|
+
if (!r.ok) { $('derr').textContent = T.fail + (r.reason || ''); return; }
|
|
196
|
+
D = r.detail; EDITING = false; show(); boot();
|
|
197
|
+
} catch (e) { $('derr').textContent = T.fail + e.message; }
|
|
162
198
|
};
|
|
163
199
|
|
|
164
|
-
async function reload() {
|
|
165
|
-
const s = await api('state');
|
|
166
|
-
S.planes = s.planes; S.total = s.total; S.hits = s.hits;
|
|
167
|
-
renderPlanes(); renderList();
|
|
168
|
-
}
|
|
169
200
|
$('go').onclick = async () => {
|
|
170
201
|
const q = $('q').value.trim();
|
|
171
202
|
try {
|
|
172
203
|
const s = await api('search', { query: q });
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
} catch (e) { $('err').textContent = T.fail + e.message; }
|
|
204
|
+
renderPlanes(s.planes, s.total);
|
|
205
|
+
renderItems($('results'), s.hits, 'memory', q === '' ? T.empty : T.emptyHit);
|
|
206
|
+
} catch (e) { $('results').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>'; }
|
|
177
207
|
};
|
|
178
208
|
$('q').addEventListener('keydown', (e) => { if (e.key === 'Enter') $('go').click(); });
|
|
179
209
|
|
|
180
|
-
|
|
210
|
+
$('vgo').onclick = async () => {
|
|
211
|
+
try {
|
|
212
|
+
const v = await api('vault-list', { query: $('vq').value.trim() });
|
|
213
|
+
renderItems($('vlist'), v.items, 'vault', T.emptyVault);
|
|
214
|
+
} catch (e) { $('vlist').innerHTML = '<div class="err">' + esc(T.fail + e.message) + '</div>'; }
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
$('wsave').onclick = async () => {
|
|
218
|
+
const title = $('wt').value.trim(), body = $('wb').value;
|
|
219
|
+
if (title === '' || body.trim() === '') { $('werr').textContent = T.fail + '标题与正文都要填'; return; }
|
|
220
|
+
try {
|
|
221
|
+
const r = await api('write', { plane: $('wp').value, title, body, readWhen: $('wr').value.trim() });
|
|
222
|
+
if (!r.ok) { $('werr').textContent = T.fail + (r.reason || ''); return; }
|
|
223
|
+
$('werr').textContent = ''; $('wt').value = ''; $('wb').value = ''; $('wr').value = '';
|
|
224
|
+
boot();
|
|
225
|
+
} catch (e) { $('werr').textContent = T.fail + e.message; }
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
boot();
|
|
181
229
|
</script></body></html>`
|
|
182
230
|
}
|
|
183
231
|
|
|
@@ -185,22 +233,56 @@ reload().catch((e) => { $('sub').textContent = T.fail + e.message; });
|
|
|
185
233
|
export function sidebarScript(prefix, title) {
|
|
186
234
|
return `(function(){
|
|
187
235
|
if (window.__AURORIX_ENTRY__) return; window.__AURORIX_ENTRY__ = true;
|
|
188
|
-
var HREF = ${JSON.stringify(prefix)}, NAME = ${JSON.stringify(title)};
|
|
236
|
+
var HREF = ${JSON.stringify(prefix + '/')}, NAME = ${JSON.stringify(title)};
|
|
237
|
+
|
|
238
|
+
// 记忆库图标(书本 + 书签),24×24,跟宿主图标同规格
|
|
239
|
+
var ICON = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5.5A1.5 1.5 0 0 1 5.5 4H10a2 2 0 0 1 2 2v14a1.5 1.5 0 0 0-1.5-1.5H5.5A1.5 1.5 0 0 1 4 17V5.5Z"/><path d="M20 5.5A1.5 1.5 0 0 0 18.5 4H14a2 2 0 0 0-2 2v14a1.5 1.5 0 0 1 1.5-1.5h5A1.5 1.5 0 0 0 20 17V5.5Z"/></svg>';
|
|
240
|
+
|
|
241
|
+
function setText(el, text){
|
|
242
|
+
var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
|
|
243
|
+
var node, hit = false;
|
|
244
|
+
while ((node = walker.nextNode())) {
|
|
245
|
+
if (node.textContent.trim() === '') continue;
|
|
246
|
+
node.textContent = text; hit = true; break;
|
|
247
|
+
}
|
|
248
|
+
if (!hit) el.appendChild(document.createTextNode(text));
|
|
249
|
+
}
|
|
250
|
+
|
|
189
251
|
function insert(){
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
252
|
+
if (document.querySelector('[data-aurorix-entry]')) return true;
|
|
253
|
+
var nav = document.querySelector('nav[aria-label], aside nav, nav, [role="navigation"]');
|
|
254
|
+
if (!nav) return false;
|
|
255
|
+
|
|
256
|
+
// 拿一个真实的导航项当样板,克隆它的 class 和层级,样式就不会割裂。
|
|
257
|
+
var sample = Array.prototype.find.call(nav.querySelectorAll('a,button'), function(el){
|
|
258
|
+
var t = (el.textContent || '').trim();
|
|
259
|
+
return t.length > 0 && t.length <= 8 && !el.querySelector('input');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
if (!sample) return false;
|
|
263
|
+
var el = sample.cloneNode(true);
|
|
264
|
+
el.setAttribute('data-aurorix-entry','');
|
|
265
|
+
if (el.tagName === 'A') { el.href = HREF; el.target = '_blank'; el.rel = 'noopener'; }
|
|
266
|
+
else { el.onclick = function(){ window.open(HREF, '_blank', 'noopener'); }; }
|
|
267
|
+
el.removeAttribute('aria-current');
|
|
268
|
+
el.removeAttribute('data-active');
|
|
269
|
+
if (el.className && typeof el.className === 'string') el.className = el.className.replace(/\bactive\b/g, '').trim();
|
|
270
|
+
|
|
271
|
+
// 换图标:保留宿主图标的容器与尺寸,只换内容。
|
|
272
|
+
var svg = el.querySelector('svg');
|
|
273
|
+
if (svg) { var box = document.createElementNS('http://www.w3.org/2000/svg','svg'); box.innerHTML = ICON; svg.replaceWith(box.firstChild); }
|
|
274
|
+
setText(el, NAME);
|
|
275
|
+
|
|
276
|
+
sample.parentNode.insertBefore(el, sample.nextSibling);
|
|
198
277
|
return true;
|
|
199
278
|
}
|
|
279
|
+
|
|
200
280
|
var tries = 0;
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
|
|
281
|
+
var timer = setInterval(function(){
|
|
282
|
+
var ok = false;
|
|
283
|
+
try { ok = insert(); } catch (e) { ok = true; }
|
|
284
|
+
if (ok || ++tries > 60) clearInterval(timer);
|
|
285
|
+
}, 400);
|
|
204
286
|
})();`
|
|
205
287
|
}
|
|
206
288
|
|
|
@@ -208,7 +290,9 @@ export function sidebarScript(prefix, title) {
|
|
|
208
290
|
* 把 Web 面板挂进 web 载体。拿不到 webServer 就安静跳过——dsh-go 手机上本来就没有它。
|
|
209
291
|
*/
|
|
210
292
|
export function attachWeb(ctx, { backend, root }) {
|
|
211
|
-
|
|
293
|
+
// prefix 不能带尾斜杠:匹配逻辑是 pathname.startsWith(prefix + '/'),
|
|
294
|
+
// 写成 '/aurorix/' 会变成 '/aurorix//',子路径全部 404。
|
|
295
|
+
const prefix = '/aurorix'
|
|
212
296
|
ctx.inject(['webServer'], (webCtx) => {
|
|
213
297
|
const json = (res, code, value) => {
|
|
214
298
|
res.writeHead(code, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
@@ -230,14 +314,14 @@ export function attachWeb(ctx, { backend, root }) {
|
|
|
230
314
|
const url = new URL(req.url ?? '/', 'http://localhost')
|
|
231
315
|
const path = url.pathname
|
|
232
316
|
|
|
233
|
-
if (path === prefix || path === prefix
|
|
317
|
+
if (path === prefix || path === prefix + '/') {
|
|
234
318
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
|
|
235
319
|
res.end(pageHtml(url.searchParams.get('lang') ?? 'zh-CN'))
|
|
236
320
|
return
|
|
237
321
|
}
|
|
238
|
-
if (!path.startsWith(prefix + 'api/')) { json(res, 404, { ok: false, reason: 'not found' }); return }
|
|
322
|
+
if (!path.startsWith(prefix + '/api/')) { json(res, 404, { ok: false, reason: 'not found' }); return }
|
|
239
323
|
|
|
240
|
-
const action = path.slice((prefix + 'api/').length)
|
|
324
|
+
const action = path.slice((prefix + '/api/').length)
|
|
241
325
|
const ok = (value) => json(res, 200, value)
|
|
242
326
|
try {
|
|
243
327
|
if (action === 'state' && req.method === 'GET') {
|
|
@@ -258,6 +342,24 @@ export function attachWeb(ctx, { backend, root }) {
|
|
|
258
342
|
ok({ planes: c.planes ?? {}, total: c.total ?? 0, hits: (list.items ?? []).map((x) => ({ id: x.id, title: x.title, plane: x.plane, preview: x.preview ?? '' })) })
|
|
259
343
|
return
|
|
260
344
|
}
|
|
345
|
+
if (action === 'vault-list') {
|
|
346
|
+
const q = String(body.query ?? '').trim().toLowerCase()
|
|
347
|
+
const r = await backend.vaultList()
|
|
348
|
+
if (!r.ok) { ok({ ok: false, items: [], reason: r.reason }); return }
|
|
349
|
+
const items = (r.items ?? []).filter((x) => q === '' || (x.ident + ' ' + x.purpose).toLowerCase().includes(q))
|
|
350
|
+
ok({ ok: true, items })
|
|
351
|
+
return
|
|
352
|
+
}
|
|
353
|
+
if (action === 'write') {
|
|
354
|
+
const plane = String(body.plane ?? 'explicit')
|
|
355
|
+
const title = String(body.title ?? '').trim()
|
|
356
|
+
const text = String(body.body ?? '')
|
|
357
|
+
if (title === '' || text.trim() === '') { ok({ ok: false, reason: '标题与正文都要填' }); return }
|
|
358
|
+
const r = await backend.write({ plane, title, body: text, readWhen: String(body.readWhen ?? '') })
|
|
359
|
+
if (!r.ok) { ok({ ok: false, reason: r.reason }); return }
|
|
360
|
+
ok({ ok: true, record: r.record })
|
|
361
|
+
return
|
|
362
|
+
}
|
|
261
363
|
if (action === 'detail') {
|
|
262
364
|
const isVault = String(body.kind ?? '') === 'vault'
|
|
263
365
|
if (isVault) {
|