dsh-wiki-notes 1.6.1 → 1.10.0
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/CHANGELOG.md +195 -0
- package/README.md +112 -20
- package/bin/cli.mjs +2 -2
- package/docs/preview-overview.png +0 -0
- package/docs/preview.png +0 -0
- package/docs//345/272/223/347/273/223/346/236/204.md +1 -1
- package/examples/sample-wiki//350/265/204/346/226/231-sources//346/237/220/350/257/276/347/250/213/347/254/254/344/270/211/350/256/262/302/267/350/265/204/346/226/231/346/221/230/350/246/201.md +1 -1
- package/icon.svg +4 -0
- package/lib/calls.js +24 -4
- package/lib/client.js +1409 -17
- package/lib/corpus.js +3 -1
- package/lib/engine.js +116 -15
- package/lib/index.js +425 -7
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +10 -5
package/lib/client.js
CHANGED
|
@@ -139,12 +139,21 @@ window.__ModuleLoader__.load({
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
function sourceTone(source) {
|
|
142
|
-
|
|
142
|
+
// inline 与 env 一样是「设置页改不动」的覆盖来源,不能报成绿色的 ok
|
|
143
|
+
if (source === 'env' || source === 'inline') return 'warn'
|
|
143
144
|
if (source === 'default') return 'muted'
|
|
144
145
|
if (source === 'unset') return 'warn'
|
|
145
146
|
return 'ok'
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
/** 错误码分流:同一句「请求失败」在 400/403/500 下该做的事不一样。 */
|
|
150
|
+
function callsErrorHint(status) {
|
|
151
|
+
if (status === 400) return '配置或参数没过:去「概览」页检查知识库路径。'
|
|
152
|
+
if (status === 403) return '这个操作只接受本机页面发起:回到当前 DSH 页面再试。'
|
|
153
|
+
if (status === 500) return '宿主侧出错:稍等重试,或看宿主日志。'
|
|
154
|
+
return ''
|
|
155
|
+
}
|
|
156
|
+
|
|
148
157
|
/** 字节数说人话:覆盖诊断里「读进来多少」比页数更能说明问题。 */
|
|
149
158
|
function bytesLabel(value) {
|
|
150
159
|
var bytes = typeof value === 'number' && value > 0 ? value : 0
|
|
@@ -343,7 +352,13 @@ window.__ModuleLoader__.load({
|
|
|
343
352
|
setNotice({ tone: 'err', text: '已保存,但这个路径读不出来:' + (data.error || '未知错误') })
|
|
344
353
|
} else {
|
|
345
354
|
var stats = (data && data.stats) || {}
|
|
346
|
-
|
|
355
|
+
// profile 的 config.root / 环境变量优先级高于配置文件:写盘成功不等于生效。
|
|
356
|
+
// 不说清,用户会一直改设置页里的路径,却怎么都换不掉库。
|
|
357
|
+
if (data && (data.source === 'inline' || data.source === 'env')) {
|
|
358
|
+
setNotice({ tone: 'warn', text: '已保存,但当前生效路径仍被' + (data.source === 'inline' ? '插件 config.root' : '环境变量 DSH_WIKI_ROOT') + '覆盖,设置页改的路径还没生效;要换库请改对应的配置。' })
|
|
359
|
+
} else {
|
|
360
|
+
setNotice({ tone: 'ok', text: '已保存并生效:扫描到 ' + (stats.pages || 0) + ' 页' })
|
|
361
|
+
}
|
|
347
362
|
}
|
|
348
363
|
return data
|
|
349
364
|
})
|
|
@@ -394,7 +409,25 @@ window.__ModuleLoader__.load({
|
|
|
394
409
|
var head = h(
|
|
395
410
|
'div',
|
|
396
411
|
{ className: 'wn-head' },
|
|
397
|
-
h(
|
|
412
|
+
h(
|
|
413
|
+
'div',
|
|
414
|
+
{ className: 'wn-head-row' },
|
|
415
|
+
h('div', { className: 'wn-title' }, '知识库'),
|
|
416
|
+
// 设置页负责「配」,日常查在左侧栏那一页。给一条明路,别让人自己找。
|
|
417
|
+
props !== null && props !== undefined && typeof props.openPanel === 'function'
|
|
418
|
+
? h(
|
|
419
|
+
'button',
|
|
420
|
+
{
|
|
421
|
+
type: 'button',
|
|
422
|
+
className: 'wn-btn wn-head-action',
|
|
423
|
+
onClick: function () {
|
|
424
|
+
props.openPanel()
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
'打开知识库页',
|
|
428
|
+
)
|
|
429
|
+
: null,
|
|
430
|
+
),
|
|
398
431
|
h(
|
|
399
432
|
'div',
|
|
400
433
|
{ className: 'wn-sub' },
|
|
@@ -763,6 +796,10 @@ window.__ModuleLoader__.load({
|
|
|
763
796
|
? h(Notice, { tone: 'warn', message: '环境变量 DSH_WIKI_ROOT 正在覆盖这个值(' + envRoot + '),保存也盖不过它。' })
|
|
764
797
|
: null,
|
|
765
798
|
|
|
799
|
+
state && state.inlineRoot
|
|
800
|
+
? h(Notice, { tone: 'warn', message: '插件 profile 里的 config.root 正在覆盖这个值(' + state.inlineRoot + '),保存也盖不过它;要换库请改 profile 配置。' })
|
|
801
|
+
: null,
|
|
802
|
+
|
|
766
803
|
h(
|
|
767
804
|
'details',
|
|
768
805
|
{ className: 'wn-details' },
|
|
@@ -1183,8 +1220,12 @@ window.__ModuleLoader__.load({
|
|
|
1183
1220
|
*/
|
|
1184
1221
|
function WikiSearchPanel(props) {
|
|
1185
1222
|
var compact = props !== null && props !== undefined && props.compact === true
|
|
1223
|
+
// 从「探索 → 标签」点一个标签进来时,查询词由外面递:进来就带着它跑,
|
|
1224
|
+
// 别让人在检索框里再打一遍刚点的那个词。
|
|
1225
|
+
var seed = props !== null && props !== undefined && typeof props.seed === 'string' ? props.seed : ''
|
|
1226
|
+
var seedSeq = props !== null && props !== undefined && typeof props.seedSeq === 'number' ? props.seedSeq : 0
|
|
1186
1227
|
|
|
1187
|
-
var queryTuple = useState(
|
|
1228
|
+
var queryTuple = useState(seed)
|
|
1188
1229
|
var query = queryTuple[0]
|
|
1189
1230
|
var setQuery = queryTuple[1]
|
|
1190
1231
|
|
|
@@ -1207,6 +1248,11 @@ window.__ModuleLoader__.load({
|
|
|
1207
1248
|
var activeTuple = useState(-1)
|
|
1208
1249
|
var active = activeTuple[0]
|
|
1209
1250
|
var setActive = activeTuple[1]
|
|
1251
|
+
// 最近查过的词。只活在这一次会话里,不落盘 —— 这不是第二本账,
|
|
1252
|
+
// 是「刚查过的还热着」;写盘反而要处理清理、隐私、跨设备不一致。
|
|
1253
|
+
var historyTuple = useState([])
|
|
1254
|
+
var history = historyTuple[0]
|
|
1255
|
+
var setHistory = historyTuple[1]
|
|
1210
1256
|
// 快捷键要把焦点送进输入框,只能靠 DOM 引用
|
|
1211
1257
|
var inputRef = useRef(null)
|
|
1212
1258
|
|
|
@@ -1265,6 +1311,19 @@ window.__ModuleLoader__.load({
|
|
|
1265
1311
|
}
|
|
1266
1312
|
}, [])
|
|
1267
1313
|
|
|
1314
|
+
// 外面递进来的词换了(又点了一个标签)就再跑一次;同一个词点两次也算换 ——
|
|
1315
|
+
// seedSeq 是计数,不是词本身,所以这里不能拿文本比较。
|
|
1316
|
+
var seedRef = useRef(seedSeq)
|
|
1317
|
+
useEffect(
|
|
1318
|
+
function () {
|
|
1319
|
+
if (seed === '') return
|
|
1320
|
+
if (seedRef.current === seedSeq) return
|
|
1321
|
+
seedRef.current = seedSeq
|
|
1322
|
+
runSearch(seed)
|
|
1323
|
+
},
|
|
1324
|
+
[seed, seedSeq],
|
|
1325
|
+
)
|
|
1326
|
+
|
|
1268
1327
|
function runSearch(text) {
|
|
1269
1328
|
var trimmed = String(text === undefined ? query : text).trim()
|
|
1270
1329
|
// 不再因为 busy 就丢弃新查询:中文边打边查时,上一个请求还在飞、
|
|
@@ -1282,6 +1341,14 @@ window.__ModuleLoader__.load({
|
|
|
1282
1341
|
.then(function (data) {
|
|
1283
1342
|
if (seq !== seqRef.current) return
|
|
1284
1343
|
setResult(data)
|
|
1344
|
+
// 记「查完了」而不是「开始查」:请求失败时不该留下一个装作查过的词。
|
|
1345
|
+
setHistory(function (previous) {
|
|
1346
|
+
var next = [trimmed]
|
|
1347
|
+
for (var i = 0; i < previous.length && next.length < SEARCH_HISTORY_MAX; i += 1) {
|
|
1348
|
+
if (previous[i] !== trimmed) next.push(previous[i])
|
|
1349
|
+
}
|
|
1350
|
+
return next
|
|
1351
|
+
})
|
|
1285
1352
|
})
|
|
1286
1353
|
.catch(function (failure) {
|
|
1287
1354
|
if (seq !== seqRef.current) return
|
|
@@ -1396,7 +1463,38 @@ window.__ModuleLoader__.load({
|
|
|
1396
1463
|
),
|
|
1397
1464
|
),
|
|
1398
1465
|
|
|
1399
|
-
|
|
1466
|
+
// 最近查过:一排词,点一下就重查。不复用 seed 那条通道 ——
|
|
1467
|
+
// 那是「别的窗递进来的词」,这是「我刚查过的词」,混在一起会互相覆盖。
|
|
1468
|
+
history.length === 0
|
|
1469
|
+
? null
|
|
1470
|
+
: h(
|
|
1471
|
+
'div',
|
|
1472
|
+
{ className: 'wn-history', role: 'group', 'aria-label': '最近查过' },
|
|
1473
|
+
h('span', { className: 'wn-history-label' }, '最近'),
|
|
1474
|
+
history.map(function (item) {
|
|
1475
|
+
return h(
|
|
1476
|
+
'button',
|
|
1477
|
+
{
|
|
1478
|
+
type: 'button',
|
|
1479
|
+
key: 'hist-' + item,
|
|
1480
|
+
className: 'wn-btn wn-history-item',
|
|
1481
|
+
title: '再查一次「' + item + '」',
|
|
1482
|
+
onClick: function () {
|
|
1483
|
+
runSearch(item)
|
|
1484
|
+
},
|
|
1485
|
+
},
|
|
1486
|
+
item,
|
|
1487
|
+
)
|
|
1488
|
+
}),
|
|
1489
|
+
),
|
|
1490
|
+
|
|
1491
|
+
error !== ''
|
|
1492
|
+
? h('div', { className: 'wn-notice wn-notice-err' },
|
|
1493
|
+
h('span', { className: 'wn-notice-mark' }, '!'),
|
|
1494
|
+
h('span', { className: 'wn-notice-text' }, error),
|
|
1495
|
+
h('button', { type: 'button', className: 'wn-btn', onClick: function () { runSearch(query) } }, '重试'),
|
|
1496
|
+
)
|
|
1497
|
+
: null,
|
|
1400
1498
|
|
|
1401
1499
|
busy
|
|
1402
1500
|
? h('div', { className: 'wn-busy', role: 'status', 'aria-live': 'polite' }, '检索中…')
|
|
@@ -1416,6 +1514,37 @@ window.__ModuleLoader__.load({
|
|
|
1416
1514
|
})
|
|
1417
1515
|
: null,
|
|
1418
1516
|
|
|
1517
|
+
// 零命中时把宿主算好的「最接近的几页」摆出来:0 命中在界面上和「库里没有这块」
|
|
1518
|
+
// 长得一模一样,这一栏是两者唯一的区别。它只在零命中时出现,永不混进命中列表。
|
|
1519
|
+
result !== null && hits.length === 0 && Array.isArray(result.nearMiss) && result.nearMiss.length > 0
|
|
1520
|
+
? h(
|
|
1521
|
+
'div',
|
|
1522
|
+
{ className: 'wn-near' },
|
|
1523
|
+
h('div', { className: 'wn-near-head' }, '最接近的 ' + result.nearMiss.length + ' 页'),
|
|
1524
|
+
result.nearMiss.map(function (item) {
|
|
1525
|
+
return h(
|
|
1526
|
+
'button',
|
|
1527
|
+
{
|
|
1528
|
+
key: String(item.file || item.name),
|
|
1529
|
+
type: 'button',
|
|
1530
|
+
className: 'wn-near-row',
|
|
1531
|
+
title:
|
|
1532
|
+
item.filtered === true
|
|
1533
|
+
? '这一页被这次的过滤条件筛掉了 —— 放开筛选再搜一次'
|
|
1534
|
+
: '按这一页的措辞再搜一遍',
|
|
1535
|
+
onClick: function () {
|
|
1536
|
+
runSearch(String(item.name))
|
|
1537
|
+
},
|
|
1538
|
+
},
|
|
1539
|
+
h('span', { className: 'wn-near-name' }, String(item.name)),
|
|
1540
|
+
h('span', { className: 'wn-near-cov' }, '沾边 ' + String(item.coverage) + '%'),
|
|
1541
|
+
item.filtered === true ? h('span', { className: 'wn-near-tag' }, '被过滤') : null,
|
|
1542
|
+
)
|
|
1543
|
+
}),
|
|
1544
|
+
h('p', { className: 'wn-note' }, '这些只是字面最沾边,不等于它们回答了问题;点一条按它的措辞再搜一遍。'),
|
|
1545
|
+
)
|
|
1546
|
+
: null,
|
|
1547
|
+
|
|
1419
1548
|
h(HitList, { hits: hits, active: active }),
|
|
1420
1549
|
|
|
1421
1550
|
result === null && error === '' && busy === false ? h(EmptyState, { lib: lib, onPick: runSearch }) : null,
|
|
@@ -1427,6 +1556,10 @@ window.__ModuleLoader__.load({
|
|
|
1427
1556
|
/** 轮询间隔。2 秒够看清「模型刚刚查了没有」,又不至于把本机 HTTP 当心跳打。 */
|
|
1428
1557
|
var CALLS_POLL_MS = 2000
|
|
1429
1558
|
var CALLS_LIMIT = 200
|
|
1559
|
+
/** 检索窗留几个「最近查过」的词。8 个正好一排,再多就得换行,反而挡结果。 */
|
|
1560
|
+
var SEARCH_HISTORY_MAX = 8
|
|
1561
|
+
/** 一页几条。10 条是「一眼扫完、不用滚」的量,再多就该靠筛选而不是靠滚动。 */
|
|
1562
|
+
var CALLS_PAGE_SIZE = 10
|
|
1430
1563
|
|
|
1431
1564
|
function callsSourceLabel(source) {
|
|
1432
1565
|
return source === 'panel' ? '面板' : '模型'
|
|
@@ -1549,7 +1682,7 @@ window.__ModuleLoader__.load({
|
|
|
1549
1682
|
* 所以「模型到底查没查库」这件事,之前只能去翻会话转录。这个页面就是那本账。
|
|
1550
1683
|
*/
|
|
1551
1684
|
function WikiCallsSection(props) {
|
|
1552
|
-
var stateTuple = useState({ rows: [], totals: null, enabled: true, window: 0, governance: null, error: '', loading: true })
|
|
1685
|
+
var stateTuple = useState({ rows: [], totals: null, enabled: true, window: 0, governance: null, error: '', errorStatus: 0, loading: true })
|
|
1553
1686
|
var state = stateTuple[0]
|
|
1554
1687
|
var setState = stateTuple[1]
|
|
1555
1688
|
|
|
@@ -1561,6 +1694,12 @@ window.__ModuleLoader__.load({
|
|
|
1561
1694
|
var onlyMiss = missTuple[0]
|
|
1562
1695
|
var setOnlyMiss = missTuple[1]
|
|
1563
1696
|
|
|
1697
|
+
// 账本是流水,页码也是流水式的:翻页只切当前这一屏,不重新请求。
|
|
1698
|
+
// 一次最多 200 条已经在手里了,切页再去问服务端只是多一次往返。
|
|
1699
|
+
var pageTuple = useState(0)
|
|
1700
|
+
var page = pageTuple[0]
|
|
1701
|
+
var setPage = pageTuple[1]
|
|
1702
|
+
|
|
1564
1703
|
// 清空要按两次:第一次只把按钮变成「确认清空?」,4 秒内不确认就复原。
|
|
1565
1704
|
// 不用 window.confirm —— 系统对话框在自己页面里显得突兀,也不好统一风格。
|
|
1566
1705
|
var confirmClearTuple = useState(false)
|
|
@@ -1588,13 +1727,14 @@ window.__ModuleLoader__.load({
|
|
|
1588
1727
|
window: data && typeof data.window === 'number' ? data.window : 0,
|
|
1589
1728
|
governance: data && data.governance && typeof data.governance === 'object' ? data.governance : null,
|
|
1590
1729
|
error: '',
|
|
1730
|
+
errorStatus: 0,
|
|
1591
1731
|
loading: false,
|
|
1592
1732
|
})
|
|
1593
1733
|
},
|
|
1594
1734
|
function (error) {
|
|
1595
1735
|
if (aliveRef.current !== true) return
|
|
1596
1736
|
setState(function (prev) {
|
|
1597
|
-
return patchState(prev, { loading: false, error: String((error && error.message) || error) })
|
|
1737
|
+
return patchState(prev, { loading: false, error: String((error && error.message) || error), errorStatus: (error && error.status) || 0 })
|
|
1598
1738
|
})
|
|
1599
1739
|
},
|
|
1600
1740
|
)
|
|
@@ -1602,6 +1742,14 @@ window.__ModuleLoader__.load({
|
|
|
1602
1742
|
[filter, onlyMiss],
|
|
1603
1743
|
)
|
|
1604
1744
|
|
|
1745
|
+
// 换筛选条件就会换一批行:留在第 5 页只会看到一片空白,页码归零。
|
|
1746
|
+
useEffect(
|
|
1747
|
+
function () {
|
|
1748
|
+
setPage(0)
|
|
1749
|
+
},
|
|
1750
|
+
[filter, onlyMiss],
|
|
1751
|
+
)
|
|
1752
|
+
|
|
1605
1753
|
useEffect(
|
|
1606
1754
|
function () {
|
|
1607
1755
|
aliveRef.current = true
|
|
@@ -1676,6 +1824,7 @@ window.__ModuleLoader__.load({
|
|
|
1676
1824
|
key: item[0],
|
|
1677
1825
|
type: 'button',
|
|
1678
1826
|
className: filter === item[0] ? 'wn-btn wn-btn-on' : 'wn-btn',
|
|
1827
|
+
'aria-pressed': filter === item[0],
|
|
1679
1828
|
onClick: function () {
|
|
1680
1829
|
setFilter(item[0])
|
|
1681
1830
|
},
|
|
@@ -1684,27 +1833,147 @@ window.__ModuleLoader__.load({
|
|
|
1684
1833
|
)
|
|
1685
1834
|
})
|
|
1686
1835
|
|
|
1687
|
-
var
|
|
1836
|
+
var allRows = state.rows || []
|
|
1837
|
+
var dayOf = function (row) {
|
|
1838
|
+
return typeof row.ts === 'string' ? row.ts.slice(0, 10) : ''
|
|
1839
|
+
}
|
|
1840
|
+
// 只把「需要注意」的状态挑出来:ok 是常态,铺一列绿字只会让异常更难被发现。
|
|
1841
|
+
// 兜底优先于 status:一次 or / 字面兜底命中,status 仍然是 ok,但结果的可信度已经降了一档。
|
|
1842
|
+
var badgeOf = function (row) {
|
|
1843
|
+
var fallback = typeof row.fallback === 'string' ? row.fallback : ''
|
|
1844
|
+
if (fallback === 'coverage') return { text: '字面兜底', warn: true }
|
|
1845
|
+
if (fallback === 'or') return { text: '放宽 OR', warn: false }
|
|
1846
|
+
var status = typeof row.status === 'string' ? row.status : ''
|
|
1847
|
+
if (status === '' || status === 'ok') return null
|
|
1848
|
+
return { text: status, warn: status !== 'partial' }
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
var rows = allRows.map(function (row, index) {
|
|
1688
1852
|
var slow = typeof row.ms === 'number' && row.ms > 1000
|
|
1853
|
+
// 日期只在跨天的那一行加深:同一天里重复 10 次日期只是噪声,
|
|
1854
|
+
// 但整列都不写日期,翻到第二页就分不清「昨天」和「刚才」。
|
|
1855
|
+
var day = dayOf(row)
|
|
1856
|
+
var dayIsNew = index === 0 || dayOf(allRows[index - 1]) !== day
|
|
1857
|
+
var badge = badgeOf(row)
|
|
1858
|
+
var scannedHint = row.considered === null || row.considered === undefined
|
|
1859
|
+
? ''
|
|
1860
|
+
: '参与 ' + String(row.considered) + ' 页'
|
|
1861
|
+
var scoreHint = row.topScore === null || row.topScore === undefined ? '' : '最高 ' + String(row.topScore) + ' 分'
|
|
1862
|
+
var hints = [scannedHint, scoreHint].filter(function (part) { return part !== '' }).join(' · ')
|
|
1689
1863
|
return h(
|
|
1690
1864
|
'tr',
|
|
1691
1865
|
{ key: String(row.ts) + '-' + String(index) },
|
|
1692
|
-
h(
|
|
1866
|
+
h(
|
|
1867
|
+
'td',
|
|
1868
|
+
{ className: 'wn-calls-time' },
|
|
1869
|
+
h('span', { className: dayIsNew ? 'wn-calls-day wn-calls-day-new' : 'wn-calls-day' }, day === '' ? '—' : day.slice(5)),
|
|
1870
|
+
h('span', { className: 'wn-calls-clock' }, typeof row.ts === 'string' ? row.ts.slice(11, 16) : ''),
|
|
1871
|
+
),
|
|
1693
1872
|
h('td', null, callsSourceLabel(row.source)),
|
|
1694
1873
|
h('td', null, row.tool === '' || row.tool === undefined ? '—' : row.tool),
|
|
1874
|
+
h('td', null, row.mode === '' || row.mode === undefined ? '—' : row.mode),
|
|
1695
1875
|
h(
|
|
1696
1876
|
'td',
|
|
1697
1877
|
{ className: 'wn-calls-query', title: typeof row.query === 'string' ? row.query : '' },
|
|
1698
1878
|
row.query === '' || row.query === undefined ? '(无查询词)' : row.query,
|
|
1699
1879
|
),
|
|
1700
|
-
h(
|
|
1880
|
+
h(
|
|
1881
|
+
'td',
|
|
1882
|
+
{ className: 'wn-calls-hits', title: hints },
|
|
1883
|
+
row.hits === null || row.hits === undefined ? '—' : String(row.hits),
|
|
1884
|
+
),
|
|
1701
1885
|
h('td', { className: slow ? 'wn-calls-ms wn-slow' : 'wn-calls-ms' }, typeof row.ms === 'number' ? row.ms + 'ms' : '—'),
|
|
1886
|
+
h(
|
|
1887
|
+
'td',
|
|
1888
|
+
{ className: 'wn-calls-diag' },
|
|
1889
|
+
badge === null
|
|
1890
|
+
? '—'
|
|
1891
|
+
: h('span', { className: badge.warn ? 'wn-badge wn-badge-warn' : 'wn-badge' }, badge.text),
|
|
1892
|
+
),
|
|
1893
|
+
h('td', { className: row.ok === false ? 'wn-calls-ms wn-slow' : 'wn-calls-ms' }, row.ok === false ? '失败' : row.ok === true ? '成功' : '—'),
|
|
1702
1894
|
)
|
|
1703
1895
|
})
|
|
1704
1896
|
|
|
1897
|
+
// 反复打空的查询:同一句话查了三次还是 0,比「今天零命中 6 次」有用得多 ——
|
|
1898
|
+
// 前者指向「该换词」,后者只说明「今天运气不好」。
|
|
1899
|
+
var missGroups = (function () {
|
|
1900
|
+
var map = new Map()
|
|
1901
|
+
allRows.forEach(function (row) {
|
|
1902
|
+
if (row.hits !== 0) return
|
|
1903
|
+
var key = typeof row.query === 'string' ? row.query.trim().toLowerCase() : ''
|
|
1904
|
+
if (key === '') key = '(无查询词)'
|
|
1905
|
+
var item = map.get(key) || { query: key, count: 0, last: '' }
|
|
1906
|
+
item.count += 1
|
|
1907
|
+
if (typeof row.ts === 'string' && row.ts > item.last) item.last = row.ts
|
|
1908
|
+
map.set(key, item)
|
|
1909
|
+
})
|
|
1910
|
+
var out = []
|
|
1911
|
+
map.forEach(function (item) { out.push(item) })
|
|
1912
|
+
out.sort(function (a, b) {
|
|
1913
|
+
return b.count - a.count || (a.query < b.query ? -1 : a.query > b.query ? 1 : 0)
|
|
1914
|
+
})
|
|
1915
|
+
return out
|
|
1916
|
+
})()
|
|
1917
|
+
|
|
1918
|
+
// 一页 10 条:账本是流水,200 行铺开只会把「今天查了什么」埋在中间。
|
|
1919
|
+
// 切页只在本地切片,不再发请求 —— 全部行本来就在这一屏手里。
|
|
1920
|
+
var totalRows = rows.length
|
|
1921
|
+
var totalPages = Math.max(1, Math.ceil(totalRows / CALLS_PAGE_SIZE))
|
|
1922
|
+
// 轮询会整批换行:页码可能已经越界,夹住它,而不是让列表凭空变空。
|
|
1923
|
+
var safePage = Math.min(Math.max(page, 0), totalPages - 1)
|
|
1924
|
+
var pageStart = safePage * CALLS_PAGE_SIZE
|
|
1925
|
+
var pageRows = rows.slice(pageStart, pageStart + CALLS_PAGE_SIZE)
|
|
1926
|
+
|
|
1927
|
+
var pager =
|
|
1928
|
+
totalRows <= CALLS_PAGE_SIZE
|
|
1929
|
+
? null
|
|
1930
|
+
: h(
|
|
1931
|
+
'div',
|
|
1932
|
+
{ className: 'wn-pager', role: 'group', 'aria-label': '调用记录分页' },
|
|
1933
|
+
h(
|
|
1934
|
+
'button',
|
|
1935
|
+
{
|
|
1936
|
+
type: 'button',
|
|
1937
|
+
className: 'wn-btn',
|
|
1938
|
+
disabled: safePage === 0,
|
|
1939
|
+
onClick: function () {
|
|
1940
|
+
setPage(safePage - 1)
|
|
1941
|
+
},
|
|
1942
|
+
},
|
|
1943
|
+
'上一页',
|
|
1944
|
+
),
|
|
1945
|
+
h(
|
|
1946
|
+
'span',
|
|
1947
|
+
{ className: 'wn-pager-info' },
|
|
1948
|
+
'第 ' +
|
|
1949
|
+
String(pageStart + 1) +
|
|
1950
|
+
'–' +
|
|
1951
|
+
String(Math.min(pageStart + CALLS_PAGE_SIZE, totalRows)) +
|
|
1952
|
+
' 条 · 共 ' +
|
|
1953
|
+
String(totalRows) +
|
|
1954
|
+
' 条 · 第 ' +
|
|
1955
|
+
String(safePage + 1) +
|
|
1956
|
+
'/' +
|
|
1957
|
+
String(totalPages) +
|
|
1958
|
+
' 页',
|
|
1959
|
+
),
|
|
1960
|
+
h(
|
|
1961
|
+
'button',
|
|
1962
|
+
{
|
|
1963
|
+
type: 'button',
|
|
1964
|
+
className: 'wn-btn',
|
|
1965
|
+
disabled: safePage >= totalPages - 1,
|
|
1966
|
+
onClick: function () {
|
|
1967
|
+
setPage(safePage + 1)
|
|
1968
|
+
},
|
|
1969
|
+
},
|
|
1970
|
+
'下一页',
|
|
1971
|
+
),
|
|
1972
|
+
)
|
|
1973
|
+
|
|
1705
1974
|
var body =
|
|
1706
1975
|
rows.length === 0
|
|
1707
|
-
? h('div', { className: 'wn-calls-empty' }, '
|
|
1976
|
+
? h('div', { className: 'wn-calls-empty' }, '还没有调用记录。让模型查一次库,或者在「检索」页签里自己查一次 —— 两条路都记进同一个账本。')
|
|
1708
1977
|
: h(
|
|
1709
1978
|
'table',
|
|
1710
1979
|
{ className: 'wn-calls-table' },
|
|
@@ -1717,14 +1986,20 @@ window.__ModuleLoader__.load({
|
|
|
1717
1986
|
h('th', null, '时间'),
|
|
1718
1987
|
h('th', null, '来源'),
|
|
1719
1988
|
h('th', null, '工具'),
|
|
1989
|
+
h('th', null, '模式'),
|
|
1720
1990
|
h('th', null, '问题'),
|
|
1721
1991
|
h('th', null, '命中'),
|
|
1722
1992
|
h('th', null, '耗时'),
|
|
1993
|
+
h('th', null, '诊断'),
|
|
1994
|
+
h('th', null, '成败'),
|
|
1723
1995
|
),
|
|
1724
1996
|
),
|
|
1725
|
-
h('tbody', null,
|
|
1997
|
+
h('tbody', null, pageRows),
|
|
1726
1998
|
)
|
|
1727
1999
|
|
|
2000
|
+
// 一屏十条 + 翻页脚:表格和翻页脚是一体的,别让 pager 漂到别处。
|
|
2001
|
+
if (pager !== null) body = h('div', { className: 'wn-calls-body' }, body, pager)
|
|
2002
|
+
|
|
1728
2003
|
var embedded = props !== null && props !== undefined && props.embedded === true
|
|
1729
2004
|
|
|
1730
2005
|
return h(
|
|
@@ -1756,6 +2031,32 @@ window.__ModuleLoader__.load({
|
|
|
1756
2031
|
{ className: 'wn-calls-note' },
|
|
1757
2032
|
'统计基于最近 ' + String(state.window === undefined ? 0 : state.window) + ' 条记录;命中率分母不含 verify / observe。',
|
|
1758
2033
|
),
|
|
2034
|
+
missGroups.length === 0
|
|
2035
|
+
? null
|
|
2036
|
+
: h(
|
|
2037
|
+
'div',
|
|
2038
|
+
{ className: 'wn-card wn-miss-card' },
|
|
2039
|
+
h(
|
|
2040
|
+
'div',
|
|
2041
|
+
{ className: 'wn-card-head' },
|
|
2042
|
+
h('span', { className: 'wn-card-title' }, '反复打空的查询'),
|
|
2043
|
+
h('span', { className: 'wn-badge wn-badge-warn' }, String(missGroups.length) + ' 句'),
|
|
2044
|
+
),
|
|
2045
|
+
h('div', { className: 'wn-dim' }, '同一句话反复查还是 0 命中,多半是库里的说法和这句对不上 —— 换词比再查一次有用。'),
|
|
2046
|
+
h(
|
|
2047
|
+
'div',
|
|
2048
|
+
{ className: 'wn-miss-list' },
|
|
2049
|
+
missGroups.slice(0, 5).map(function (item) {
|
|
2050
|
+
return h(
|
|
2051
|
+
'div',
|
|
2052
|
+
{ className: 'wn-miss-row', key: item.query },
|
|
2053
|
+
h('span', { className: 'wn-miss-count' }, '×' + String(item.count)),
|
|
2054
|
+
h('span', { className: 'wn-miss-query', title: item.query }, item.query),
|
|
2055
|
+
h('span', { className: 'wn-miss-when' }, item.last === '' ? '' : item.last.slice(5, 16)),
|
|
2056
|
+
)
|
|
2057
|
+
}),
|
|
2058
|
+
),
|
|
2059
|
+
),
|
|
1759
2060
|
h(WikiGovernancePanel, { governance: state.governance }),
|
|
1760
2061
|
h(
|
|
1761
2062
|
'div',
|
|
@@ -1792,9 +2093,13 @@ window.__ModuleLoader__.load({
|
|
|
1792
2093
|
),
|
|
1793
2094
|
state.error === '' || state.error === undefined
|
|
1794
2095
|
? null
|
|
1795
|
-
: h('div', { className: 'wn-notice wn-notice-
|
|
2096
|
+
: h('div', { className: 'wn-notice wn-notice-err' },
|
|
2097
|
+
h('span', { className: 'wn-notice-mark' }, '!'),
|
|
2098
|
+
h('span', { className: 'wn-notice-text' }, callsErrorHint(state.errorStatus), state.error),
|
|
2099
|
+
h('button', { type: 'button', className: 'wn-btn', onClick: load }, '重试'),
|
|
2100
|
+
),
|
|
1796
2101
|
body,
|
|
1797
|
-
h('div', { className: 'wn-foot' }, '账本只记这
|
|
2102
|
+
h('div', { className: 'wn-foot' }, '账本只记这 13 个字段:时间、来源、工具、模式、问题、命中、耗时、成败,外加状态、兜底方式、参与页数、告警数、最高分。页面路径与正文一律不进。'),
|
|
1798
2103
|
)
|
|
1799
2104
|
}
|
|
1800
2105
|
|
|
@@ -1850,6 +2155,8 @@ window.__ModuleLoader__.load({
|
|
|
1850
2155
|
'.wn-btn:focus-visible,.wn-input:focus-visible{outline:2px solid var(--wn-brand);outline-offset:2px;}',
|
|
1851
2156
|
'.wn-btn-primary{background:var(--wn-brand);color:var(--wn-brand-fg);border-color:transparent;}',
|
|
1852
2157
|
'.wn-btn-ghost{background:transparent;color:var(--wn-muted);}',
|
|
2158
|
+
// 筛选按钮的选中态:以前只有类名没有规则,点「全部/模型/面板」看不出当前是哪一个
|
|
2159
|
+
'.wn-btn.wn-btn-on{color:var(--wn-brand);border-color:var(--wn-brand);font-weight:600;}',
|
|
1853
2160
|
'.wn-btn-danger{color:var(--wn-err);border-color:color-mix(in srgb,var(--wn-err) 45%,transparent);background:color-mix(in srgb,var(--wn-err) 8%,transparent);}',
|
|
1854
2161
|
'.wn-notice{font-size:12.5px;line-height:1.55;padding:8px 11px;border-radius:8px;border:1px solid var(--wn-line-soft);background:var(--wn-bar);color:var(--wn-muted);}',
|
|
1855
2162
|
'.wn-notice-ok{color:var(--wn-ok);border-color:color-mix(in srgb,var(--wn-ok) 30%,transparent);background:color-mix(in srgb,var(--wn-ok) 8%,transparent);}',
|
|
@@ -1900,6 +2207,16 @@ window.__ModuleLoader__.load({
|
|
|
1900
2207
|
'.wn-count{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap;font-size:12px;color:var(--wn-muted);font-variant-numeric:tabular-nums;}',
|
|
1901
2208
|
'.wn-count-main{color:var(--wn-fg);font-weight:600;}',
|
|
1902
2209
|
'.wn-count-degraded{font-size:11.5px;color:var(--wn-warn);}',
|
|
2210
|
+
'.wn-near{display:flex;flex-direction:column;gap:6px;padding:14px 16px;border:1px solid rgba(168,152,133,0.45);border-radius:2px;background:#fffdf9;}',
|
|
2211
|
+
'.wn-near-head{font-size:11px;font-weight:400;letter-spacing:0.12em;color:#6f6558;}',
|
|
2212
|
+
'.wn-near-row{display:flex;align-items:center;gap:10px;width:100%;font:inherit;text-align:left;padding:6px 0;border:0;border-bottom:1px solid rgba(168,152,133,0.22);background:transparent;color:#2b2724;cursor:pointer;transition:color 700ms ease-in-out;}',
|
|
2213
|
+
'.wn-near-row:hover{color:#5a7a6b;}',
|
|
2214
|
+
'.wn-near-name{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
|
|
2215
|
+
'.wn-near-cov{flex:0 0 auto;font-size:11.5px;color:#6f6558;font-variant-numeric:tabular-nums;}',
|
|
2216
|
+
'.wn-near-tag{flex:0 0 auto;font-size:11px;color:var(--wn-warn);}',
|
|
2217
|
+
'.wn-history{display:flex;align-items:center;gap:6px;flex-wrap:wrap;}',
|
|
2218
|
+
'.wn-history-label{font-size:11px;color:var(--wn-muted);letter-spacing:0.08em;}',
|
|
2219
|
+
'.wn-history-item{max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
|
|
1903
2220
|
'.wn-count-meta{margin-left:auto;font-size:11px;color:var(--wn-muted);}',
|
|
1904
2221
|
// 结果按行排、不按卡片:一列的边框会把 1/2/3 名的强弱比较打断。
|
|
1905
2222
|
'.wn-hit-list{display:flex;flex-direction:column;border-top:1px solid var(--wn-line-soft);}',
|
|
@@ -1970,6 +2287,23 @@ window.__ModuleLoader__.load({
|
|
|
1970
2287
|
// 页签不是 .wn-btn,得单独给焦点环:否则用 Tab 键走过去时「当前焦点在哪」完全看不见
|
|
1971
2288
|
'.wn-tab:focus-visible{outline:2px solid var(--wn-brand);outline-offset:2px;}',
|
|
1972
2289
|
'.wn-tab-on{color:var(--wn-fg);font-weight:600;border-bottom-color:var(--wn-brand);}',
|
|
2290
|
+
// 左侧栏点开的那一整页:比设置页宽松,正文不封顶;页面自己滚,
|
|
2291
|
+
// 这样宿主给不给滚动容器都不会被裁掉半截。
|
|
2292
|
+
'.wn-page{height:100%;overflow:auto;padding:20px 22px 34px;gap:16px;max-width:1000px;margin:0 auto;width:100%;}',
|
|
2293
|
+
'.wn-page .wn-hit-text{max-height:none;}',
|
|
2294
|
+
'.wn-kv{display:flex;gap:10px;align-items:baseline;font-size:12.5px;line-height:1.7;}',
|
|
2295
|
+
'.wn-kv-key{flex:0 0 auto;min-width:78px;color:var(--wn-muted);}',
|
|
2296
|
+
'.wn-kv-value{flex:1 1 auto;min-width:0;overflow-wrap:anywhere;}',
|
|
2297
|
+
'.wn-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;}',
|
|
2298
|
+
'.wn-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center;}',
|
|
2299
|
+
// 标题与「打开知识库页」同一行:那条跳转是次要动作,不该单独占一行。
|
|
2300
|
+
'.wn-head-row{display:flex;align-items:center;gap:10px;}',
|
|
2301
|
+
'.wn-head-action{margin-left:auto;}',
|
|
2302
|
+
// 圆点表示「现在怎么样」。只靠文字写「正常」的话,扫一眼看不出来。
|
|
2303
|
+
'.wn-dot{width:7px;height:7px;border-radius:50%;flex:0 0 auto;background:var(--wn-faint);}',
|
|
2304
|
+
'.wn-dot-ok{background:var(--wn-ok);}',
|
|
2305
|
+
'.wn-dot-warn{background:var(--wn-warn);}',
|
|
2306
|
+
'.wn-dot-err{background:var(--wn-err);}',
|
|
1973
2307
|
'.wn-calls-stats{display:flex;gap:10px;flex-wrap:wrap;}',
|
|
1974
2308
|
'.wn-calls-stat{flex:1 1 120px;display:flex;flex-direction:column;gap:2px;padding:10px 12px;background:var(--wn-card);border:1px solid var(--wn-line-soft);border-radius:10px;}',
|
|
1975
2309
|
'.wn-calls-stat b{font-size:20px;line-height:1.1;}',
|
|
@@ -1980,23 +2314,108 @@ window.__ModuleLoader__.load({
|
|
|
1980
2314
|
'.wn-calls-table{width:100%;border-collapse:collapse;font-size:12px;}',
|
|
1981
2315
|
'.wn-calls-table th{text-align:left;font-weight:600;color:var(--wn-muted);border-bottom:1px solid var(--wn-line);padding:6px 8px;}',
|
|
1982
2316
|
'.wn-calls-table td{border-bottom:1px solid var(--wn-line-soft);padding:6px 8px;vertical-align:top;}',
|
|
1983
|
-
'.wn-calls-time{color:var(--wn-muted);white-space:nowrap;}',
|
|
2317
|
+
'.wn-calls-time{color:var(--wn-muted);white-space:nowrap;display:flex;flex-direction:column;gap:1px;line-height:1.25;}',
|
|
2318
|
+
'.wn-calls-day{font-size:10.5px;color:var(--wn-faint);font-variant-numeric:tabular-nums;}',
|
|
2319
|
+
'.wn-calls-day-new{color:var(--wn-fg);font-weight:600;}',
|
|
2320
|
+
'.wn-calls-clock{font-variant-numeric:tabular-nums;}',
|
|
2321
|
+
'.wn-calls-diag{white-space:nowrap;}',
|
|
2322
|
+
'.wn-miss-card{gap:8px;}',
|
|
2323
|
+
'.wn-miss-list{display:flex;flex-direction:column;gap:4px;}',
|
|
2324
|
+
'.wn-miss-row{display:flex;align-items:baseline;gap:8px;font-size:12px;}',
|
|
2325
|
+
'.wn-miss-count{flex:0 0 auto;color:var(--wn-warn);font-variant-numeric:tabular-nums;}',
|
|
2326
|
+
'.wn-miss-query{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
|
|
2327
|
+
'.wn-miss-when{flex:0 0 auto;color:var(--wn-faint);font-size:11px;font-variant-numeric:tabular-nums;}',
|
|
1984
2328
|
'.wn-calls-query{max-width:320px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
|
|
1985
2329
|
'.wn-calls-hits{text-align:right;font-variant-numeric:tabular-nums;}',
|
|
1986
2330
|
'.wn-calls-ms{text-align:right;font-variant-numeric:tabular-nums;color:var(--wn-muted);}',
|
|
1987
2331
|
'.wn-calls-ms.wn-slow{color:#b4552d;}',
|
|
1988
2332
|
'.wn-calls-empty{padding:18px 12px;text-align:center;color:var(--wn-muted);font-size:12.5px;background:var(--wn-card);border:1px dashed var(--wn-line);border-radius:10px;}',
|
|
1989
2333
|
'.wn-calls-warn{font-size:11.5px;color:var(--wn-warn);}',
|
|
2334
|
+
'.wn-calls-body{display:flex;flex-direction:column;gap:8px;}',
|
|
2335
|
+
'.wn-pager{display:flex;gap:8px;align-items:center;flex-wrap:wrap;}',
|
|
2336
|
+
'.wn-pager-info{font-size:11.5px;color:var(--wn-muted);font-variant-numeric:tabular-nums;}',
|
|
1990
2337
|
'.wn-gov{display:flex;flex-direction:column;gap:7px;padding:12px;background:var(--wn-card);border:1px solid var(--wn-line-soft);border-radius:10px;}',
|
|
1991
2338
|
'.wn-gov-head{font-size:12.5px;font-weight:600;color:var(--wn-fg);}',
|
|
1992
2339
|
'.wn-gov-off{padding:8px 10px;background:var(--wn-bar);border-radius:8px;font-size:12px;color:var(--wn-muted);}',
|
|
1993
2340
|
'.wn-gov-rows{display:flex;flex-direction:column;gap:6px;}',
|
|
1994
2341
|
'.wn-gov-row{display:flex;flex-direction:column;gap:2px;padding:8px 10px;background:var(--wn-field);border:1px solid var(--wn-line-soft);border-radius:8px;}',
|
|
1995
|
-
|
|
2342
|
+
// 分组行靠内缩表达层级,但**不能缩外框**:margin-left 会把右边那条边也推走,
|
|
2343
|
+
// 于是这一行的数字和上面三行右对齐就断了。缩内边距,外框宽度不动。
|
|
2344
|
+
'.wn-gov-row.wn-gov-sub{margin-left:0;padding-left:26px;background:transparent;border-style:dashed;}',
|
|
1996
2345
|
'.wn-gov-row-head{display:flex;justify-content:space-between;gap:10px;font-size:12.5px;}',
|
|
1997
2346
|
'.wn-gov-row-head b{font-variant-numeric:tabular-nums;}',
|
|
1998
2347
|
'.wn-gov-detail,.wn-gov-note{font-size:11.5px;color:var(--wn-muted);line-height:1.5;}',
|
|
1999
2348
|
'}',
|
|
2349
|
+
'.hx{gap:0;max-width:1040px;margin:0 auto;width:100%;font-family:Inter,"Segoe UI",system-ui,-apple-system,sans-serif;font-weight:300;line-height:1.8;color:#2b2724;}',
|
|
2350
|
+
'.hx *{box-sizing:border-box;}',
|
|
2351
|
+
'.hx-sec{margin:56px 0 0;}',
|
|
2352
|
+
'.hx-sec-head{display:flex;align-items:baseline;gap:16px;margin:0 0 24px;}',
|
|
2353
|
+
'.hx-h{margin:0;font-size:20px;font-weight:300;letter-spacing:0.04em;color:#2b2724;}',
|
|
2354
|
+
'.hx-sec-note{font-size:12px;font-weight:400;letter-spacing:0.12em;color:#6f6558;}',
|
|
2355
|
+
'.hx-card{background:#fffdf9;border:1px solid rgba(168,152,133,0.55);border-radius:2px;padding:28px;transition:border-color 700ms ease-in-out,background-color 700ms ease-in-out;}',
|
|
2356
|
+
'.hx-card:hover{border-color:rgba(90,122,107,0.55);}',
|
|
2357
|
+
'.hx-card-lead{padding:40px;}',
|
|
2358
|
+
'.hx-pad{padding:24px 28px;}',
|
|
2359
|
+
'.hx-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px;}',
|
|
2360
|
+
'.hx-grid-2{grid-template-columns:repeat(auto-fit,minmax(260px,1fr));}',
|
|
2361
|
+
'.hx-grid-3{grid-template-columns:repeat(auto-fit,minmax(190px,1fr));}',
|
|
2362
|
+
// 输入框与「打开」按钮在 1.8.3 跟页面窗一起删掉了,关系窗的「页面关联」又需要它们:
|
|
2363
|
+
// 同一个视觉语言重新长回来,仍是 2px 直角 + 700ms 过渡,不另起一套。
|
|
2364
|
+
'.hx-input{font:inherit;font-size:13px;line-height:1.6;color:#2b2724;background:#fffdf9;border:1px solid rgba(168,152,133,0.60);border-radius:2px;padding:7px 10px;transition:border-color 700ms ease-in-out;}',
|
|
2365
|
+
'.hx-input:focus{outline:none;border-color:rgba(90,122,107,0.70);}',
|
|
2366
|
+
'.hx-input::placeholder{color:#9c9184;}',
|
|
2367
|
+
'.hx-bad{color:#9a4b3c;}',
|
|
2368
|
+
'.hx-row-act{font:inherit;font-size:11px;letter-spacing:0.08em;color:#4f7d99;background:transparent;border:1px solid rgba(168,152,133,0.50);border-radius:2px;padding:2px 8px;cursor:pointer;transition:border-color 700ms ease-in-out,color 700ms ease-in-out;}',
|
|
2369
|
+
'.hx-row-act:hover{border-color:rgba(90,122,107,0.70);color:#5a7a6b;}',
|
|
2370
|
+
'.hx-co-row{align-items:center;}',
|
|
2371
|
+
'.hx-co-head{font:inherit;font-size:13px;color:#2b2724;background:transparent;border:0;padding:0;min-width:96px;text-align:left;cursor:pointer;transition:color 700ms ease-in-out;}',
|
|
2372
|
+
'.hx-co-head:hover{color:#5a7a6b;}',
|
|
2373
|
+
'.hx-co-list{display:flex;flex-wrap:wrap;gap:6px;justify-content:flex-end;}',
|
|
2374
|
+
'.hx-chip-sm{font-size:11px;padding:2px 8px;}',
|
|
2375
|
+
'.hx-link-bar{display:flex;gap:8px;align-items:center;margin-bottom:14px;}',
|
|
2376
|
+
'.hx-link-input{flex:1 1 auto;min-width:0;}',
|
|
2377
|
+
'.hx-link-col{display:flex;flex-direction:column;gap:8px;}',
|
|
2378
|
+
'.hx-link-row{display:flex;align-items:center;gap:8px;border-bottom:1px solid rgba(168,152,133,0.25);padding:4px 0;}',
|
|
2379
|
+
'.hx-link-name{font:inherit;font-size:13px;color:#2b2724;background:transparent;border:0;padding:0;flex:1 1 auto;text-align:left;cursor:pointer;transition:color 700ms ease-in-out;}',
|
|
2380
|
+
'.hx-link-name:hover{color:#5a7a6b;}',
|
|
2381
|
+
'.hx-pane{display:flex;flex-direction:column;gap:16px;}',
|
|
2382
|
+
'.hx-label{font-size:11px;font-weight:400;letter-spacing:0.12em;color:#6f6558;margin:0 0 8px;}',
|
|
2383
|
+
'.hx-value{font-size:32px;font-weight:200;line-height:1.2;letter-spacing:-0.01em;color:#2b2724;font-variant-numeric:tabular-nums;}',
|
|
2384
|
+
'.hx-note{margin:8px 0 0;font-size:12px;font-weight:300;line-height:1.8;color:#6f6558;}',
|
|
2385
|
+
'.hx-stale{margin:0;padding:14px 18px;border:1px solid rgba(201,168,140,0.55);border-radius:2px;background:rgba(201,168,140,0.10);color:#6f6558;}',
|
|
2386
|
+
'.hx-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;letter-spacing:0;}',
|
|
2387
|
+
'.hx-status-row{display:flex;align-items:center;gap:12px;flex-wrap:wrap;}',
|
|
2388
|
+
'.hx-dot{width:8px;height:8px;border-radius:50%;flex:0 0 auto;}',
|
|
2389
|
+
'.hx-dot-ok{background:#5a7a6b;}',
|
|
2390
|
+
'.hx-dot-warn{background:#c9a88c;}',
|
|
2391
|
+
'.hx-dot-err{background:#a9715c;}',
|
|
2392
|
+
'.hx-status-text{font-size:26px;font-weight:200;letter-spacing:0.02em;}',
|
|
2393
|
+
'.hx-status-path{margin-left:auto;color:#6f6558;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
|
|
2394
|
+
'.hx-row{display:flex;align-items:baseline;justify-content:space-between;gap:16px;padding:8px 0;border-bottom:1px solid rgba(168,152,133,0.35);font-size:13px;font-weight:300;}',
|
|
2395
|
+
'.hx-row:last-child{border-bottom:0;}',
|
|
2396
|
+
'.hx-row-value{flex:0 0 auto;color:#4a423a;font-variant-numeric:tabular-nums;}',
|
|
2397
|
+
'.hx-row-unit{font-size:11px;letter-spacing:0.04em;}',
|
|
2398
|
+
'.hx-link{font:inherit;font-weight:300;color:#4f7d99;background:none;border:0;padding:0;cursor:pointer;text-align:left;transition:color 700ms ease-in-out;}',
|
|
2399
|
+
'.hx-link:hover{color:#5a7a6b;}',
|
|
2400
|
+
'.hx-actions{display:flex;gap:12px;flex-wrap:wrap;}',
|
|
2401
|
+
'.hx-btn{font:inherit;font-size:13px;font-weight:300;letter-spacing:0.08em;padding:12px 28px;border-radius:2px;border:1px solid #a89a8a;background:transparent;color:#2b2724;cursor:pointer;transition:background-color 700ms ease-in-out,border-color 700ms ease-in-out,color 700ms ease-in-out;}',
|
|
2402
|
+
'.hx-btn:hover:not(:disabled){border-color:#5a7a6b;color:#5a7a6b;}',
|
|
2403
|
+
'.hx-btn:disabled{opacity:0.45;cursor:default;}',
|
|
2404
|
+
'.hx-btn:focus-visible{outline:1px solid #5a7a6b;outline-offset:2px;}',
|
|
2405
|
+
'.hx-btn-solid{background:#3d3d3d;border-color:#3d3d3d;color:#f5f0eb;}',
|
|
2406
|
+
'.hx-btn-solid:hover:not(:disabled){background:#5a7a6b;border-color:#5a7a6b;color:#f5f0eb;}',
|
|
2407
|
+
'.hx-chips{display:flex;flex-wrap:wrap;gap:8px;}',
|
|
2408
|
+
'.hx-chip{display:inline-flex;align-items:center;gap:8px;font-size:12px;font-weight:300;padding:6px 12px;border:1px solid rgba(168,152,133,0.60);border-radius:2px;background:#fffdf9;color:#2b2724;}',
|
|
2409
|
+
'.hx-chip-count{font-size:11px;color:#6f6558;font-variant-numeric:tabular-nums;}',
|
|
2410
|
+
'.hx-chip-btn{cursor:pointer;font-family:inherit;transition:border-color 700ms ease-in-out,color 700ms ease-in-out;}',
|
|
2411
|
+
'.hx-chip-btn:hover{border-color:rgba(90,122,107,0.80);color:#5a7a6b;}',
|
|
2412
|
+
'.hx-chip-btn:focus-visible{outline:2px solid rgba(90,122,107,0.45);outline-offset:2px;}',
|
|
2413
|
+
'.hx-subtabs{display:flex;align-items:center;gap:8px;margin:0 0 24px;}',
|
|
2414
|
+
'.hx-subtab{font:inherit;font-size:11px;font-weight:300;letter-spacing:0.12em;padding:8px 16px;border:1px solid transparent;border-radius:2px;background:transparent;color:#6f6558;cursor:pointer;transition:border-color 700ms ease-in-out,color 700ms ease-in-out;}',
|
|
2415
|
+
'.hx-subtab:hover{color:#5a7a6b;border-color:rgba(90,122,107,0.40);}',
|
|
2416
|
+
'.hx-subtab-on{color:#2b2724;border-color:rgba(168,152,133,0.60);background:#fffdf9;}',
|
|
2417
|
+
'.hx-usage{display:flex;flex-direction:column;gap:16px;}',
|
|
2418
|
+
'.hx-meta{display:flex;flex-wrap:wrap;gap:8px;margin:12px 0 0;}',
|
|
2000
2419
|
].join('')
|
|
2001
2420
|
|
|
2002
2421
|
/* ------------------------------ 右侧栏 ------------------------------ */
|
|
@@ -2018,6 +2437,923 @@ window.__ModuleLoader__.load({
|
|
|
2018
2437
|
)
|
|
2019
2438
|
}
|
|
2020
2439
|
|
|
2440
|
+
/* ------------------------------ 左侧栏工作台 ------------------------------ */
|
|
2441
|
+
|
|
2442
|
+
var PANEL_ID = 'wiki-notes'
|
|
2443
|
+
// 排在「插件」(order 0) 与「自动化任务」(10) 后面:前两项回答「这个软件怎么用」,
|
|
2444
|
+
// 知识库回答「我自己的东西在哪」。同一排,但不是第一个该看的东西。
|
|
2445
|
+
var PANEL_ORDER = 20
|
|
2446
|
+
|
|
2447
|
+
// 竖排里的一本书。尺寸由宿主给(size),颜色吃 currentColor ——
|
|
2448
|
+
// 两个都不写死:写死 px 和色值,换主题时它就跟旁边几个图标不是一套。
|
|
2449
|
+
function WikiPanelIcon(props) {
|
|
2450
|
+
var size = props !== null && props !== undefined && typeof props.size === 'number' ? props.size : 16
|
|
2451
|
+
var active = props !== null && props !== undefined && props.active === true
|
|
2452
|
+
return h(
|
|
2453
|
+
'svg',
|
|
2454
|
+
{
|
|
2455
|
+
width: size,
|
|
2456
|
+
height: size,
|
|
2457
|
+
viewBox: '0 0 36 36',
|
|
2458
|
+
fill: 'none',
|
|
2459
|
+
stroke: 'currentColor',
|
|
2460
|
+
// 选中时描粗一点:展开着、旁边又没有别的高亮时,这是唯一的「你现在在这儿」。
|
|
2461
|
+
strokeWidth: active ? 2.6 : 2.1,
|
|
2462
|
+
strokeLinecap: 'round',
|
|
2463
|
+
strokeLinejoin: 'round',
|
|
2464
|
+
'aria-hidden': 'true',
|
|
2465
|
+
focusable: 'false',
|
|
2466
|
+
},
|
|
2467
|
+
h('path', {
|
|
2468
|
+
d: 'M18 11.2c-2.3-1.7-5.2-2.4-8.6-2.4v17.4c3.4 0 6.3.7 8.6 2.4 2.3-1.7 5.2-2.4 8.6-2.4V8.8c-3.4 0-6.3.7-8.6 2.4Z',
|
|
2469
|
+
}),
|
|
2470
|
+
h('path', { d: 'M18 11.2v17.2' }),
|
|
2471
|
+
)
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
function Kv(props) {
|
|
2475
|
+
return h(
|
|
2476
|
+
'div',
|
|
2477
|
+
{ className: 'wn-kv' },
|
|
2478
|
+
h('span', { className: 'wn-kv-key' }, props.label),
|
|
2479
|
+
h('span', { className: 'wn-kv-value' + (props.mono === true ? ' wn-mono' : '') }, props.value),
|
|
2480
|
+
)
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
/**
|
|
2484
|
+
* 时间戳 → `11-17 17:32`。这一页只关心「最近」,年份可以省。
|
|
2485
|
+
*
|
|
2486
|
+
* 两套格式得分开处理,混着切字符串就会差出一整个时区:
|
|
2487
|
+
* - 带 `Z` / `+08:00` 的是绝对时刻(`scannedAt` 就是 `toISOString()`),必须换算成本地;
|
|
2488
|
+
* - 调用账本 / 访问账本里写的是本地墙钟(`stampNow()`,不带时区),切字符串才对。
|
|
2489
|
+
* 早先一律 `slice(11, 16)`,于是「最近扫描」永远比真实时间早 8 小时。
|
|
2490
|
+
*/
|
|
2491
|
+
function whenText(iso) {
|
|
2492
|
+
if (typeof iso !== 'string' || iso.length < 16) return '—'
|
|
2493
|
+
if (/(Z|[+-]\d{2}:?\d{2})$/.test(iso)) {
|
|
2494
|
+
var parsed = Date.parse(iso)
|
|
2495
|
+
if (Number.isFinite(parsed)) {
|
|
2496
|
+
var local = new Date(parsed)
|
|
2497
|
+
var pad = function (value) {
|
|
2498
|
+
return (value < 10 ? '0' : '') + value
|
|
2499
|
+
}
|
|
2500
|
+
return pad(local.getMonth() + 1) + '-' + pad(local.getDate()) + ' ' + pad(local.getHours()) + ':' + pad(local.getMinutes())
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
return iso.slice(5, 16).replace('T', ' ')
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/**
|
|
2507
|
+
* 概览页签。
|
|
2508
|
+
*
|
|
2509
|
+
* 两条纪律,破了任一条这页就得重做:
|
|
2510
|
+
*
|
|
2511
|
+
* 1) **数字全部来自宿主**。组件只读 `state.overview`,不在前端数标签、不在前端算比例。
|
|
2512
|
+
* 前端自己算一套,早晚和工具输出分家 —— 而分家那天两边都「看起来正常」,
|
|
2513
|
+
* 谁也证明不了谁错。所以这里一个 `reduce` 都不该有。
|
|
2514
|
+
* 2) **只读**。路径、提示词、主题词都在设置页改。这里出现第二个输入框,
|
|
2515
|
+
* 就一定会有人改在错的地方,然后问为什么没生效。
|
|
2516
|
+
*
|
|
2517
|
+
* 视觉跟 `design (1).md`:北欧极简,charcoal 字、warm-white 纸、sand 细线、
|
|
2518
|
+
* 2px 直角、无阴影,字重只用 200/300/400,hover 只动边框与底色。
|
|
2519
|
+
*/
|
|
2520
|
+
function WikiPanelStatus(props) {
|
|
2521
|
+
// 一个组件出两个一级窗(概览 / 探索),探索里再分标签与关系。
|
|
2522
|
+
// 拆成几个组件会让
|
|
2523
|
+
// 「读 /state」这段代码抄四遍 —— 四份 state 迟早不同步。
|
|
2524
|
+
var view =
|
|
2525
|
+
props !== null && typeof props === 'object' && typeof props.view === 'string' ? props.view : 'overview'
|
|
2526
|
+
// 「探索」这一个窗里放两张榜:标签是「按主题切」,关系是「按链接切」。
|
|
2527
|
+
// 它们同属「看库的结构」,分成两个一级页签只会把导航撑长,不会多出信息。
|
|
2528
|
+
var subTuple = useState(
|
|
2529
|
+
props !== null && typeof props === 'object' && props.explore === 'relations' ? 'relations' : 'tags',
|
|
2530
|
+
)
|
|
2531
|
+
var exploreTab = subTuple[0]
|
|
2532
|
+
var setExploreTab = subTuple[1]
|
|
2533
|
+
|
|
2534
|
+
// 静态预览(tools/preview.mjs)会直接喂一份 /state 的数据:截图里出现
|
|
2535
|
+
// 「读状态失败」比什么都不画更糟,所以给了 data 就不再打接口。
|
|
2536
|
+
var seeded =
|
|
2537
|
+
props !== null && typeof props === 'object' && props.data !== null && typeof props.data === 'object'
|
|
2538
|
+
? props.data
|
|
2539
|
+
: null
|
|
2540
|
+
|
|
2541
|
+
var dataTuple = useState(seeded)
|
|
2542
|
+
var data = dataTuple[0]
|
|
2543
|
+
var setData = dataTuple[1]
|
|
2544
|
+
|
|
2545
|
+
// 关系窗的「页面关联」。这里是这一页唯一的「详情抽屉」:
|
|
2546
|
+
// 枢纽页、孤岛、页面关联里的每一行都落到同一张卡上 ——
|
|
2547
|
+
// 三处各写一个弹层,必然出现「同一个页名,三个地方显示三种链接数」。
|
|
2548
|
+
var linkTuple = useState({ name: '', data: null, error: '', loading: false })
|
|
2549
|
+
var linkState = linkTuple[0]
|
|
2550
|
+
var setLinkState = linkTuple[1]
|
|
2551
|
+
|
|
2552
|
+
function openLinks(name) {
|
|
2553
|
+
var wanted = String(name === undefined || name === null ? '' : name).trim()
|
|
2554
|
+
if (wanted === '') return
|
|
2555
|
+
setLinkState({ name: wanted, data: null, error: '', loading: true })
|
|
2556
|
+
apiGet('/links?name=' + encodeURIComponent(wanted), TIMEOUT_MS)
|
|
2557
|
+
.then(function (payload) {
|
|
2558
|
+
setLinkState({ name: wanted, data: payload, error: '', loading: false })
|
|
2559
|
+
})
|
|
2560
|
+
.catch(function (failure) {
|
|
2561
|
+
setLinkState({
|
|
2562
|
+
name: wanted,
|
|
2563
|
+
data: null,
|
|
2564
|
+
error: failure && failure.message ? failure.message : '没读到这一页的链接',
|
|
2565
|
+
loading: false,
|
|
2566
|
+
})
|
|
2567
|
+
})
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
// 概览的「查看异常」:跳探索窗并把子页切到关系。
|
|
2571
|
+
// 用一个自增序号而不是布尔值 —— 连点两次也要能再切一次,
|
|
2572
|
+
// 布尔值第二次点击是「同一个值」,React 不会重渲染。
|
|
2573
|
+
var anomalyTick =
|
|
2574
|
+
props !== null && typeof props === 'object' && typeof props.anomalyTick === 'number' ? props.anomalyTick : 0
|
|
2575
|
+
useEffect(
|
|
2576
|
+
function () {
|
|
2577
|
+
if (anomalyTick > 0) setExploreTab('relations')
|
|
2578
|
+
},
|
|
2579
|
+
[anomalyTick],
|
|
2580
|
+
)
|
|
2581
|
+
|
|
2582
|
+
// 首帧就是 load:否则会先闪一下「还没配置」再跳到真实状态。
|
|
2583
|
+
var busyTuple = useState(seeded === null ? 'load' : '')
|
|
2584
|
+
var busy = busyTuple[0]
|
|
2585
|
+
var setBusy = busyTuple[1]
|
|
2586
|
+
|
|
2587
|
+
var noticeTuple = useState(null)
|
|
2588
|
+
var notice = noticeTuple[0]
|
|
2589
|
+
var setNotice = noticeTuple[1]
|
|
2590
|
+
|
|
2591
|
+
// 正在打开的那一行。面板里不再有「点开一页读正文」——读文件交给你自己的
|
|
2592
|
+
// markdown 编辑器,这里只负责把它叫起来,所以只留一个防连点的标记。
|
|
2593
|
+
var openBusyTuple = useState('')
|
|
2594
|
+
var openBusy = openBusyTuple[0]
|
|
2595
|
+
var setOpenBusy = openBusyTuple[1]
|
|
2596
|
+
|
|
2597
|
+
// 切走页签后别再 setState:请求还在路上,往已卸载的组件写 state 只会刷警告。
|
|
2598
|
+
var aliveRef = useRef(true)
|
|
2599
|
+
|
|
2600
|
+
var refresh = useCallback(function () {
|
|
2601
|
+
setBusy('load')
|
|
2602
|
+
return apiGet('/state', SCAN_TIMEOUT_MS)
|
|
2603
|
+
.then(function (next) {
|
|
2604
|
+
if (aliveRef.current !== true) return
|
|
2605
|
+
setData(next)
|
|
2606
|
+
setNotice(null)
|
|
2607
|
+
})
|
|
2608
|
+
.catch(function (error) {
|
|
2609
|
+
if (aliveRef.current !== true) return
|
|
2610
|
+
setNotice({ tone: 'err', text: '读状态失败:' + error.message })
|
|
2611
|
+
})
|
|
2612
|
+
.then(function () {
|
|
2613
|
+
if (aliveRef.current === true) setBusy('')
|
|
2614
|
+
})
|
|
2615
|
+
}, [])
|
|
2616
|
+
|
|
2617
|
+
useEffect(
|
|
2618
|
+
function () {
|
|
2619
|
+
aliveRef.current = true
|
|
2620
|
+
if (seeded === null) refresh()
|
|
2621
|
+
return function () {
|
|
2622
|
+
aliveRef.current = false
|
|
2623
|
+
}
|
|
2624
|
+
},
|
|
2625
|
+
[refresh, seeded],
|
|
2626
|
+
)
|
|
2627
|
+
|
|
2628
|
+
function rescan() {
|
|
2629
|
+
if (busy !== '') return
|
|
2630
|
+
setBusy('scan')
|
|
2631
|
+
apiPost('/rescan', {}, SCAN_TIMEOUT_MS)
|
|
2632
|
+
.then(function (next) {
|
|
2633
|
+
if (aliveRef.current !== true) return
|
|
2634
|
+
setData(next)
|
|
2635
|
+
setNotice({ tone: 'ok', text: '已重新扫描,缓存作废' })
|
|
2636
|
+
})
|
|
2637
|
+
.catch(function (error) {
|
|
2638
|
+
if (aliveRef.current !== true) return
|
|
2639
|
+
setNotice({ tone: 'err', text: '重新扫描失败:' + error.message })
|
|
2640
|
+
})
|
|
2641
|
+
.then(function () {
|
|
2642
|
+
if (aliveRef.current === true) setBusy('')
|
|
2643
|
+
})
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
// 点一行 = 在那个 .md 的编辑器里打开(系统关联程序)。面板里读正文是另一件事:
|
|
2647
|
+
// 读得到字、改不了字,也接不上笔记软件的补全和反链,所以它只能当第二选择,
|
|
2648
|
+
// 不能顶替「打开文件」。
|
|
2649
|
+
function openFile(file, name) {
|
|
2650
|
+
if (typeof file !== 'string' || file === '') {
|
|
2651
|
+
setNotice({ tone: 'warn', text: '这一行没有文件路径,打不开(旧账本里可能没记 file)' })
|
|
2652
|
+
return
|
|
2653
|
+
}
|
|
2654
|
+
if (openBusy !== '') return
|
|
2655
|
+
setOpenBusy(String(name || file))
|
|
2656
|
+
apiPost('/open', { path: file }, TIMEOUT_MS)
|
|
2657
|
+
.then(function (next) {
|
|
2658
|
+
if (aliveRef.current !== true) return
|
|
2659
|
+
if (next !== null && typeof next === 'object' && next.ok === true) {
|
|
2660
|
+
setNotice(null)
|
|
2661
|
+
return
|
|
2662
|
+
}
|
|
2663
|
+
setNotice({ tone: 'err', text: (next && next.error) || '打不开这个文件' })
|
|
2664
|
+
})
|
|
2665
|
+
.catch(function (error) {
|
|
2666
|
+
if (aliveRef.current !== true) return
|
|
2667
|
+
setNotice({ tone: 'err', text: '打不开这个文件:' + error.message })
|
|
2668
|
+
})
|
|
2669
|
+
.then(function () {
|
|
2670
|
+
if (aliveRef.current === true) setOpenBusy('')
|
|
2671
|
+
})
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
var ov = data !== null && data.overview !== null && typeof data.overview === 'object' ? data.overview : null
|
|
2675
|
+
var stats = data !== null && data.stats !== null && typeof data.stats === 'object' ? data.stats : {}
|
|
2676
|
+
var rootPath = data !== null && typeof data.root === 'string' ? data.root : ''
|
|
2677
|
+
var scannedPath = data !== null && typeof data.scannedRoot === 'string' ? data.scannedRoot : ''
|
|
2678
|
+
var connection =
|
|
2679
|
+
data === null
|
|
2680
|
+
? ''
|
|
2681
|
+
: typeof data.connection === 'string'
|
|
2682
|
+
? data.connection
|
|
2683
|
+
: data.ok === true
|
|
2684
|
+
? 'connected'
|
|
2685
|
+
: 'unavailable'
|
|
2686
|
+
var connText =
|
|
2687
|
+
connection === 'connected' ? '已连接' : connection === 'unconfigured' ? '未配置' : connection === 'unavailable' ? '不可用' : '读取中'
|
|
2688
|
+
var connTone = connection === 'connected' ? 'ok' : connection === 'unconfigured' ? 'warn' : 'err'
|
|
2689
|
+
var prompt = data !== null && data.prompt !== null && typeof data.prompt === 'object' ? data.prompt : null
|
|
2690
|
+
var topics = data !== null && Array.isArray(data.topics) ? data.topics : []
|
|
2691
|
+
|
|
2692
|
+
var pages = ov === null ? null : ov.pages
|
|
2693
|
+
var index = ov === null ? null : ov.index
|
|
2694
|
+
var problems = ov === null ? null : ov.problems
|
|
2695
|
+
var relations = ov === null ? null : ov.relations
|
|
2696
|
+
var tags = ov !== null && Array.isArray(ov.tags) ? ov.tags : []
|
|
2697
|
+
|
|
2698
|
+
/** 一格数字:小标签在上,大数字在下,注释垫底。 */
|
|
2699
|
+
function metric(label, value, note, hint) {
|
|
2700
|
+
return h(
|
|
2701
|
+
'div',
|
|
2702
|
+
{ className: 'hx-cell', title: hint || '' },
|
|
2703
|
+
h('div', { className: 'hx-label' }, label),
|
|
2704
|
+
h('div', { className: 'hx-value' }, String(value)),
|
|
2705
|
+
note === '' || note === undefined || note === null ? null : h('div', { className: 'hx-note' }, note),
|
|
2706
|
+
)
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
/** 一行「名 · 值」:给榜单用(枢纽页、断链目标)。 */
|
|
2710
|
+
function rankRow(name, value, label, onPick) {
|
|
2711
|
+
return h(
|
|
2712
|
+
'div',
|
|
2713
|
+
{ className: 'hx-row', key: 'r-' + name },
|
|
2714
|
+
onPick === undefined
|
|
2715
|
+
? h('span', { className: 'hx-row-name' }, name)
|
|
2716
|
+
: h(
|
|
2717
|
+
'button',
|
|
2718
|
+
{ type: 'button', className: 'hx-link', onClick: onPick },
|
|
2719
|
+
name,
|
|
2720
|
+
),
|
|
2721
|
+
value === '' || value === undefined || value === null
|
|
2722
|
+
? null
|
|
2723
|
+
: h(
|
|
2724
|
+
'span',
|
|
2725
|
+
{ className: 'hx-row-value' },
|
|
2726
|
+
String(value),
|
|
2727
|
+
label === '' || label === undefined ? null : h('span', { className: 'hx-row-unit' }, ' ' + label),
|
|
2728
|
+
),
|
|
2729
|
+
)
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
function section(title, note, children) {
|
|
2733
|
+
return h(
|
|
2734
|
+
'section',
|
|
2735
|
+
{ className: 'hx-sec' },
|
|
2736
|
+
h(
|
|
2737
|
+
'div',
|
|
2738
|
+
{ className: 'hx-sec-head' },
|
|
2739
|
+
h('h2', { className: 'hx-h' }, title),
|
|
2740
|
+
note === '' || note === undefined || note === null ? null : h('span', { className: 'hx-sec-note' }, note),
|
|
2741
|
+
),
|
|
2742
|
+
children,
|
|
2743
|
+
)
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2746
|
+
// 宿主还没算 overview(多半是进程还停在旧版本):这时下面的数字只能显示「—」,
|
|
2747
|
+
// 不解释一句,人只会以为库是空的。
|
|
2748
|
+
var staleHost =
|
|
2749
|
+
data !== null && ov === null
|
|
2750
|
+
? h(
|
|
2751
|
+
'div',
|
|
2752
|
+
{ className: 'hx-note hx-stale' },
|
|
2753
|
+
'这一页要宿主重算一遍才有数:重启一次 DSH(宿主侧这轮新增了概览统计),回来刷新这个面板。',
|
|
2754
|
+
)
|
|
2755
|
+
: null
|
|
2756
|
+
|
|
2757
|
+
var statusCard = h(
|
|
2758
|
+
'div',
|
|
2759
|
+
{ className: 'hx-card hx-card-lead' },
|
|
2760
|
+
h(
|
|
2761
|
+
'div',
|
|
2762
|
+
{ className: 'hx-status-row' },
|
|
2763
|
+
h('span', { className: 'hx-dot hx-dot-' + connTone }),
|
|
2764
|
+
h('span', { className: 'hx-status-text' }, connText),
|
|
2765
|
+
data === null || scannedPath === '' ? null : h('span', { className: 'hx-mono hx-status-path' }, scannedPath),
|
|
2766
|
+
),
|
|
2767
|
+
data === null
|
|
2768
|
+
? h('p', { className: 'hx-note' }, '正在读库状态…')
|
|
2769
|
+
: connection === 'unconfigured'
|
|
2770
|
+
? h(
|
|
2771
|
+
'p',
|
|
2772
|
+
{ className: 'hx-note' },
|
|
2773
|
+
'知识库路径还没配。去 设置 →「知识库」填上装着 .md 笔记的那个文件夹,回到这一页就有内容了。',
|
|
2774
|
+
)
|
|
2775
|
+
: connection === 'unavailable'
|
|
2776
|
+
? h('p', { className: 'hx-note' }, '配置好了,但这一轮没读出来:' + String((data && data.error) || '未知原因'))
|
|
2777
|
+
: h(
|
|
2778
|
+
'p',
|
|
2779
|
+
{ className: 'hx-note' },
|
|
2780
|
+
'发现 ' + String(index === null ? 0 : index.discovered) + ' 个文件 · 读到 ' +
|
|
2781
|
+
String(pages === null ? 0 : pages.all) + ' 页 · ' + bytesLabel(pages === null ? 0 : pages.bytes),
|
|
2782
|
+
),
|
|
2783
|
+
scannedPath !== '' && rootPath !== '' && scannedPath !== rootPath
|
|
2784
|
+
? h('p', { className: 'hx-note' }, '设置里配的是 ' + rootPath + ',实际扫的是上面那条。')
|
|
2785
|
+
: null,
|
|
2786
|
+
)
|
|
2787
|
+
|
|
2788
|
+
var countsSection = section(
|
|
2789
|
+
'页面数量',
|
|
2790
|
+
'只数这一份库,不估',
|
|
2791
|
+
h(
|
|
2792
|
+
'div',
|
|
2793
|
+
{ className: 'hx-grid' },
|
|
2794
|
+
metric('可检索页面', pages === null ? '—' : pages.searchable, '超大页没读正文,不算在内', '读进正文的页数 = 总页数 − 超大页'),
|
|
2795
|
+
metric('资料页面', pages === null ? '—' : pages.resources, '类型写着「资料」的页'),
|
|
2796
|
+
metric('小节', pages === null ? '—' : pages.sections, '正文里 ## 的数量'),
|
|
2797
|
+
metric('体积', pages === null ? '—' : bytesLabel(pages.bytes), '正文合计'),
|
|
2798
|
+
),
|
|
2799
|
+
)
|
|
2800
|
+
|
|
2801
|
+
var indexSection = section(
|
|
2802
|
+
'索引状态',
|
|
2803
|
+
'扫描只在启动与改动后发生',
|
|
2804
|
+
h(
|
|
2805
|
+
'div',
|
|
2806
|
+
{ className: 'hx-grid' },
|
|
2807
|
+
metric('最近扫描', index === null ? '—' : whenText(index.scannedAt), '本地时间'),
|
|
2808
|
+
metric('耗时', index === null ? '—' : String(index.scannedMs) + ' ms', '扫一遍整库'),
|
|
2809
|
+
metric('发现文件', index === null ? '—' : index.discovered, '目录里数到的 .md'),
|
|
2810
|
+
metric('跳过', index === null ? '—' : index.skipped, '不算页面、也不进索引'),
|
|
2811
|
+
),
|
|
2812
|
+
)
|
|
2813
|
+
|
|
2814
|
+
var problemItems = [
|
|
2815
|
+
[
|
|
2816
|
+
'红链',
|
|
2817
|
+
problems === null ? '—' : String(problems.brokenTotal),
|
|
2818
|
+
problems === null ? '' : '涉及 ' + String(problems.brokenPages) + ' 页',
|
|
2819
|
+
'正文里 [[指向不存在的页]]:指向的页没有,或名字写错了',
|
|
2820
|
+
],
|
|
2821
|
+
['不可读取', problems === null ? '—' : String(problems.unreadable), '权限/编码读不进来', '这些页既搜不到、也不会报错,只在扫描统计里出现'],
|
|
2822
|
+
['超大页面', problems === null ? '—' : String(problems.oversized), '只记文件名,不读正文', '超过体积上限的页不会进索引 —— 搜不到它不等于它不存在'],
|
|
2823
|
+
['重名', problems === null ? '—' : String(problems.duplicates), '同名不同目录', '名字撞了,[[]] 只能指到其中一个'],
|
|
2824
|
+
]
|
|
2825
|
+
var problemsSection = section(
|
|
2826
|
+
'内容问题',
|
|
2827
|
+
problems === null || problems.brokenTotal + problems.unreadable + problems.oversized + problems.duplicates === 0
|
|
2828
|
+
? '这一轮没发现'
|
|
2829
|
+
: '要修的地方',
|
|
2830
|
+
h(
|
|
2831
|
+
'div',
|
|
2832
|
+
{ className: 'hx-grid' },
|
|
2833
|
+
problemItems.map(function (item) {
|
|
2834
|
+
return metric(item[0], item[1], item[2], item[3])
|
|
2835
|
+
}),
|
|
2836
|
+
),
|
|
2837
|
+
)
|
|
2838
|
+
|
|
2839
|
+
// 使用情况:数字全部来自宿主算好的 usage(调用账本那一本),
|
|
2840
|
+
// 这里一个 reduce 都没有 —— 前端再算一遍就会出现第二个口径。
|
|
2841
|
+
var usage =
|
|
2842
|
+
data !== null && typeof data === 'object' && data.usage !== null && typeof data.usage === 'object'
|
|
2843
|
+
? data.usage
|
|
2844
|
+
: null
|
|
2845
|
+
var usageTools =
|
|
2846
|
+
usage === null || !Array.isArray(usage.byTool)
|
|
2847
|
+
? ''
|
|
2848
|
+
: usage.byTool
|
|
2849
|
+
.map(function (item) {
|
|
2850
|
+
return String(item.tool) + ' ' + String(item.count)
|
|
2851
|
+
})
|
|
2852
|
+
.join(' · ')
|
|
2853
|
+
var usageSource = usage !== null && usage.bySource !== null && typeof usage.bySource === 'object' ? usage.bySource : null
|
|
2854
|
+
var usageSection = section(
|
|
2855
|
+
'使用情况',
|
|
2856
|
+
usage === null
|
|
2857
|
+
? '宿主还没报这一块(重启一次 DSH)'
|
|
2858
|
+
: usage.ok === false
|
|
2859
|
+
? '这本账读不出来'
|
|
2860
|
+
: String(usage.rows) + ' 条记录 · 最近一次 ' + whenText(usage.lastAt),
|
|
2861
|
+
h(
|
|
2862
|
+
'div',
|
|
2863
|
+
{ className: 'hx-usage' },
|
|
2864
|
+
h(
|
|
2865
|
+
'div',
|
|
2866
|
+
{ className: 'hx-grid' },
|
|
2867
|
+
metric(
|
|
2868
|
+
'模型调用',
|
|
2869
|
+
usageSource === null ? '—' : String(usageSource.model),
|
|
2870
|
+
'真正走了工具的',
|
|
2871
|
+
'这是模型自己调的次数。和你手动点在面板里查的分开算 —— 混在一起,「模型用了多少」就成了没法核对的数。',
|
|
2872
|
+
),
|
|
2873
|
+
metric(
|
|
2874
|
+
'你自己查的',
|
|
2875
|
+
usageSource === null ? '—' : String(usageSource.panel),
|
|
2876
|
+
'面板里手动搜',
|
|
2877
|
+
'面板里点出来的检索。同一本账,但来源标成 panel,不占模型那一栏。',
|
|
2878
|
+
),
|
|
2879
|
+
metric(
|
|
2880
|
+
'零命中率',
|
|
2881
|
+
usage === null || usage.zeroRate === null || typeof usage.zeroRate !== 'number'
|
|
2882
|
+
? '—'
|
|
2883
|
+
: String(Math.round(usage.zeroRate * 100)) + '%',
|
|
2884
|
+
usage === null ? '' : String(usage.zeroHit) + ' / ' + String(usage.hitsKnown) + ' 次知道结果',
|
|
2885
|
+
'只算有「命中几页」这回事的调用(检索类)。分母为 0 时显示「—」:一次都没查过,不等于查一次都没命中。',
|
|
2886
|
+
),
|
|
2887
|
+
metric(
|
|
2888
|
+
'今天',
|
|
2889
|
+
usage !== null && usage.today !== null && Number.isFinite(usage.today.calls) ? String(usage.today.calls) : '—',
|
|
2890
|
+
usage !== null && usage.today !== null && typeof usage.today.today === 'string' ? usage.today.today.slice(5) : '',
|
|
2891
|
+
'今天(本地日期)记了几条。跨天自己会归零,不用手动清。',
|
|
2892
|
+
),
|
|
2893
|
+
),
|
|
2894
|
+
usageTools === ''
|
|
2895
|
+
? null
|
|
2896
|
+
: h('p', { className: 'hx-note' }, '按工具:' + usageTools + '。观察(wiki_observe)没被调过就显示 0 —— 那是「没观察」,不是「观察了但没违规」。'),
|
|
2897
|
+
),
|
|
2898
|
+
)
|
|
2899
|
+
|
|
2900
|
+
var quickSection = section(
|
|
2901
|
+
'快捷操作',
|
|
2902
|
+
'',
|
|
2903
|
+
h(
|
|
2904
|
+
'div',
|
|
2905
|
+
{ className: 'hx-actions' },
|
|
2906
|
+
h(
|
|
2907
|
+
'button',
|
|
2908
|
+
{
|
|
2909
|
+
type: 'button',
|
|
2910
|
+
className: 'hx-btn hx-btn-solid',
|
|
2911
|
+
onClick: function () {
|
|
2912
|
+
if (typeof props.onSearch === 'function') props.onSearch()
|
|
2913
|
+
},
|
|
2914
|
+
},
|
|
2915
|
+
'搜索',
|
|
2916
|
+
),
|
|
2917
|
+
h(
|
|
2918
|
+
'button',
|
|
2919
|
+
{
|
|
2920
|
+
type: 'button',
|
|
2921
|
+
className: 'hx-btn',
|
|
2922
|
+
onClick: function () {
|
|
2923
|
+
if (typeof props.onCalls === 'function') props.onCalls()
|
|
2924
|
+
},
|
|
2925
|
+
},
|
|
2926
|
+
'调用记录',
|
|
2927
|
+
),
|
|
2928
|
+
h(
|
|
2929
|
+
'button',
|
|
2930
|
+
{
|
|
2931
|
+
type: 'button',
|
|
2932
|
+
className: 'hx-btn',
|
|
2933
|
+
onClick: function () {
|
|
2934
|
+
if (typeof props.onAnomaly === 'function') props.onAnomaly()
|
|
2935
|
+
},
|
|
2936
|
+
},
|
|
2937
|
+
'查看异常',
|
|
2938
|
+
),
|
|
2939
|
+
h(
|
|
2940
|
+
'button',
|
|
2941
|
+
{ type: 'button', className: 'hx-btn', disabled: busy !== '', onClick: refresh },
|
|
2942
|
+
busy === 'load' ? '读取中…' : '刷新',
|
|
2943
|
+
),
|
|
2944
|
+
h(
|
|
2945
|
+
'button',
|
|
2946
|
+
{ type: 'button', className: 'hx-btn', disabled: busy !== '', onClick: rescan },
|
|
2947
|
+
busy === 'scan' ? '扫描中…' : '重新扫描',
|
|
2948
|
+
),
|
|
2949
|
+
h(
|
|
2950
|
+
'p',
|
|
2951
|
+
{ className: 'hx-note' },
|
|
2952
|
+
'路径、提示词开关、主题词规则都在 设置 →「知识库」里改。这一页只读 —— 改的地方只有一个,省得两处各说一套。',
|
|
2953
|
+
),
|
|
2954
|
+
),
|
|
2955
|
+
)
|
|
2956
|
+
|
|
2957
|
+
var tagsSection = section(
|
|
2958
|
+
'主题与标签',
|
|
2959
|
+
ov === null ? '' : String(tags.length) + ' / ' + String(ov.tagTotal) + ' 个标签' + (topics.length > 0 ? ' · 提示词里的主题词 ' + String(topics.length) + ' 个' : ''),
|
|
2960
|
+
tags.length === 0
|
|
2961
|
+
? h('p', { className: 'hx-note' }, '这一份库里还没有页写「标签」字段。写了才会在这里出现,也才会进标签筛选。')
|
|
2962
|
+
: h(
|
|
2963
|
+
'div',
|
|
2964
|
+
{ className: 'hx-chips' },
|
|
2965
|
+
tags.map(function (item) {
|
|
2966
|
+
return h(
|
|
2967
|
+
'button',
|
|
2968
|
+
{
|
|
2969
|
+
className: 'hx-chip hx-chip-btn',
|
|
2970
|
+
key: 'tag-' + item.tag,
|
|
2971
|
+
type: 'button',
|
|
2972
|
+
title: '用「' + String(item.tag) + '」去检索',
|
|
2973
|
+
onClick: function () {
|
|
2974
|
+
if (typeof props.onPickTag === 'function') props.onPickTag(String(item.tag))
|
|
2975
|
+
},
|
|
2976
|
+
},
|
|
2977
|
+
String(item.tag),
|
|
2978
|
+
h('span', { className: 'hx-chip-count' }, String(item.count)),
|
|
2979
|
+
)
|
|
2980
|
+
}),
|
|
2981
|
+
),
|
|
2982
|
+
prompt !== null && prompt.enabled === false
|
|
2983
|
+
? h('p', { className: 'hx-note' }, '提示词开关是关的:主题词不占上下文。')
|
|
2984
|
+
: null,
|
|
2985
|
+
)
|
|
2986
|
+
|
|
2987
|
+
// 标签共现:从「一个标签」走到「相邻主题」。
|
|
2988
|
+
// 用途不是给标签做管理,而是回答「我还写过什么和它一起出现的东西」——
|
|
2989
|
+
// 这是检索平时答不上来的问题(检索只认字面命中)。
|
|
2990
|
+
var coRows = tags
|
|
2991
|
+
.map(function (item) {
|
|
2992
|
+
var partners = Array.isArray(item.with) ? item.with : []
|
|
2993
|
+
if (partners.length === 0) return null
|
|
2994
|
+
return h(
|
|
2995
|
+
'div',
|
|
2996
|
+
{ className: 'hx-row hx-co-row', key: 'co-' + String(item.tag) },
|
|
2997
|
+
h(
|
|
2998
|
+
'button',
|
|
2999
|
+
{
|
|
3000
|
+
type: 'button',
|
|
3001
|
+
className: 'hx-co-head',
|
|
3002
|
+
title: '用「' + String(item.tag) + '」去检索',
|
|
3003
|
+
onClick: function () {
|
|
3004
|
+
if (typeof props.onPickTag === 'function') props.onPickTag(String(item.tag))
|
|
3005
|
+
},
|
|
3006
|
+
},
|
|
3007
|
+
String(item.tag),
|
|
3008
|
+
),
|
|
3009
|
+
h(
|
|
3010
|
+
'div',
|
|
3011
|
+
{ className: 'hx-co-list' },
|
|
3012
|
+
partners.map(function (partner) {
|
|
3013
|
+
return h(
|
|
3014
|
+
'button',
|
|
3015
|
+
{
|
|
3016
|
+
type: 'button',
|
|
3017
|
+
className: 'hx-chip hx-chip-btn hx-chip-sm',
|
|
3018
|
+
key: 'co-' + String(item.tag) + '-' + String(partner.tag),
|
|
3019
|
+
title: '一起查「' + String(item.tag) + ' ' + String(partner.tag) + '」',
|
|
3020
|
+
onClick: function () {
|
|
3021
|
+
if (typeof props.onPickTag === 'function') {
|
|
3022
|
+
props.onPickTag(String(item.tag) + ' ' + String(partner.tag))
|
|
3023
|
+
}
|
|
3024
|
+
},
|
|
3025
|
+
},
|
|
3026
|
+
String(partner.tag),
|
|
3027
|
+
h('span', { className: 'hx-chip-count' }, String(partner.count)),
|
|
3028
|
+
)
|
|
3029
|
+
}),
|
|
3030
|
+
),
|
|
3031
|
+
)
|
|
3032
|
+
})
|
|
3033
|
+
.filter(function (row) {
|
|
3034
|
+
return row !== null
|
|
3035
|
+
})
|
|
3036
|
+
|
|
3037
|
+
var tagCoSection = section(
|
|
3038
|
+
'标签共现',
|
|
3039
|
+
ov === null || ov.tagPages === undefined || ov.tagPages === null
|
|
3040
|
+
? ''
|
|
3041
|
+
: '有标签 ' + String(ov.tagPages.tagged) + ' 页 · 没标签 ' + String(ov.tagPages.untagged) + ' 页',
|
|
3042
|
+
coRows.length === 0
|
|
3043
|
+
? h('p', { className: 'hx-note' }, '还没有两个标签同时出现在一页里 —— 共现要两页以上的交叉才看得出来。')
|
|
3044
|
+
: h(
|
|
3045
|
+
'div',
|
|
3046
|
+
{ className: 'hx-list' },
|
|
3047
|
+
coRows,
|
|
3048
|
+
h('p', { className: 'hx-note' }, '左边是高频标签,右边是跟它一起出现最多的标签(数字是共同出现的页数)。'),
|
|
3049
|
+
),
|
|
3050
|
+
)
|
|
3051
|
+
|
|
3052
|
+
var relationsSection = section(
|
|
3053
|
+
'知识关系',
|
|
3054
|
+
relations === null ? '' : String(relations.links) + ' 条链接',
|
|
3055
|
+
h(
|
|
3056
|
+
'div',
|
|
3057
|
+
{ className: 'hx-grid hx-grid-2' },
|
|
3058
|
+
h(
|
|
3059
|
+
'div',
|
|
3060
|
+
{ className: 'hx-card hx-pad' },
|
|
3061
|
+
h('div', { className: 'hx-label' }, '枢纽页'),
|
|
3062
|
+
relations !== null && relations.hubPages.length > 0
|
|
3063
|
+
? h(
|
|
3064
|
+
'div',
|
|
3065
|
+
{ className: 'hx-list' },
|
|
3066
|
+
relations.hubPages.map(function (item) {
|
|
3067
|
+
return rankRow(item.name, item.inlinks, '页指向它', function () {
|
|
3068
|
+
openFile(item.file, item.name)
|
|
3069
|
+
})
|
|
3070
|
+
}),
|
|
3071
|
+
)
|
|
3072
|
+
: h('p', { className: 'hx-note' }, '没有页被别的页引用。'),
|
|
3073
|
+
),
|
|
3074
|
+
h(
|
|
3075
|
+
'div',
|
|
3076
|
+
{ className: 'hx-card hx-pad' },
|
|
3077
|
+
h('div', { className: 'hx-label' }, '孤岛 · ' + (relations === null ? '—' : String(relations.orphans)) + ' 页没人链'),
|
|
3078
|
+
relations !== null && relations.orphanSample.length > 0
|
|
3079
|
+
? h(
|
|
3080
|
+
'div',
|
|
3081
|
+
{ className: 'hx-list' },
|
|
3082
|
+
relations.orphanSample.map(function (item) {
|
|
3083
|
+
return rankRow(item.name, '', '', function () {
|
|
3084
|
+
openFile(item.file, item.name)
|
|
3085
|
+
})
|
|
3086
|
+
}),
|
|
3087
|
+
)
|
|
3088
|
+
: h('p', { className: 'hx-note' }, '每一页都至少被链到过一次。'),
|
|
3089
|
+
),
|
|
3090
|
+
h(
|
|
3091
|
+
'div',
|
|
3092
|
+
{ className: 'hx-card hx-pad' },
|
|
3093
|
+
h('div', { className: 'hx-label' }, '最该先补的页'),
|
|
3094
|
+
relations !== null && relations.brokenTargets.length > 0
|
|
3095
|
+
? h(
|
|
3096
|
+
'div',
|
|
3097
|
+
{ className: 'hx-list' },
|
|
3098
|
+
relations.brokenTargets.map(function (item) {
|
|
3099
|
+
return rankRow(item.name, item.count, '处断链')
|
|
3100
|
+
}),
|
|
3101
|
+
)
|
|
3102
|
+
: h('p', { className: 'hx-note' }, '没有断链目标。'),
|
|
3103
|
+
),
|
|
3104
|
+
),
|
|
3105
|
+
)
|
|
3106
|
+
|
|
3107
|
+
// 「页面关联」:三列 + 红链。点任一页名 = 看那个页的链接(顺着走),
|
|
3108
|
+
// 点「打开」= 交给系统默认程序。前者是探索,后者是干活,两件事不合并。
|
|
3109
|
+
var linkCol = function (label, items, empty) {
|
|
3110
|
+
return h(
|
|
3111
|
+
'div',
|
|
3112
|
+
{ className: 'hx-card hx-pad hx-link-col' },
|
|
3113
|
+
h('div', { className: 'hx-label' }, label + ' · ' + String(items.length)),
|
|
3114
|
+
items.length === 0
|
|
3115
|
+
? h('p', { className: 'hx-note' }, empty)
|
|
3116
|
+
: h(
|
|
3117
|
+
'div',
|
|
3118
|
+
{ className: 'hx-list' },
|
|
3119
|
+
items.map(function (item) {
|
|
3120
|
+
return h(
|
|
3121
|
+
'div',
|
|
3122
|
+
{ className: 'hx-link-row', key: label + '-' + String(item.name) },
|
|
3123
|
+
h(
|
|
3124
|
+
'button',
|
|
3125
|
+
{
|
|
3126
|
+
type: 'button',
|
|
3127
|
+
className: 'hx-link-name',
|
|
3128
|
+
title: '看「' + String(item.name) + '」这一页的链接',
|
|
3129
|
+
onClick: function () {
|
|
3130
|
+
openLinks(item.name)
|
|
3131
|
+
},
|
|
3132
|
+
},
|
|
3133
|
+
String(item.name),
|
|
3134
|
+
),
|
|
3135
|
+
typeof item.file === 'string' && item.file !== ''
|
|
3136
|
+
? h(
|
|
3137
|
+
'button',
|
|
3138
|
+
{
|
|
3139
|
+
type: 'button',
|
|
3140
|
+
className: 'hx-row-act',
|
|
3141
|
+
title: '用系统默认程序打开这一页',
|
|
3142
|
+
onClick: function () {
|
|
3143
|
+
openFile(item.file, item.name)
|
|
3144
|
+
},
|
|
3145
|
+
},
|
|
3146
|
+
'打开',
|
|
3147
|
+
)
|
|
3148
|
+
: null,
|
|
3149
|
+
)
|
|
3150
|
+
}),
|
|
3151
|
+
),
|
|
3152
|
+
)
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
var linkBody = null
|
|
3156
|
+
if (linkState.loading) {
|
|
3157
|
+
linkBody = h('p', { className: 'hx-note' }, '读取中…')
|
|
3158
|
+
} else if (linkState.error !== '') {
|
|
3159
|
+
linkBody = h('p', { className: 'hx-note hx-bad' }, linkState.error)
|
|
3160
|
+
} else if (linkState.data !== null) {
|
|
3161
|
+
var graph = linkState.data
|
|
3162
|
+
linkBody = h(
|
|
3163
|
+
'div',
|
|
3164
|
+
{ className: 'hx-links-body' },
|
|
3165
|
+
h(
|
|
3166
|
+
'div',
|
|
3167
|
+
{ className: 'hx-label' },
|
|
3168
|
+
String(graph.name) + (graph.type === '' ? '' : ' · ' + String(graph.type)),
|
|
3169
|
+
),
|
|
3170
|
+
h(
|
|
3171
|
+
'div',
|
|
3172
|
+
{ className: 'hx-grid hx-grid-3' },
|
|
3173
|
+
linkCol('出链', Array.isArray(graph.out) ? graph.out : [], '它没有链到别的页。'),
|
|
3174
|
+
linkCol('入链', Array.isArray(graph.inn) ? graph.inn : [], '没有页链到它。'),
|
|
3175
|
+
linkCol('双向', Array.isArray(graph.both) ? graph.both : [], '没有互相当回事的页。'),
|
|
3176
|
+
),
|
|
3177
|
+
Array.isArray(graph.broken) && graph.broken.length > 0
|
|
3178
|
+
? h(
|
|
3179
|
+
'p',
|
|
3180
|
+
{ className: 'hx-note' },
|
|
3181
|
+
'红链 ' + String(graph.broken.length) + ' 个:' + graph.broken.map(function (item) {
|
|
3182
|
+
return String(item.name)
|
|
3183
|
+
}).join('、'),
|
|
3184
|
+
)
|
|
3185
|
+
: h('p', { className: 'hx-note' }, '这一页没有红链。'),
|
|
3186
|
+
)
|
|
3187
|
+
} else {
|
|
3188
|
+
linkBody = h('p', { className: 'hx-note' }, '写一个页名回车,或者点上面任一页 —— 看它指向谁、谁指向它。')
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
|
+
var linksSection = section(
|
|
3192
|
+
'页面关联',
|
|
3193
|
+
linkState.data === null ? '入链要逐页扫,所以这一个是现算的' : '点页名顺着走,点「打开」交给编辑器',
|
|
3194
|
+
h(
|
|
3195
|
+
'div',
|
|
3196
|
+
{ className: 'hx-card hx-pad' },
|
|
3197
|
+
h(
|
|
3198
|
+
'div',
|
|
3199
|
+
{ className: 'hx-link-bar' },
|
|
3200
|
+
h('input', {
|
|
3201
|
+
className: 'hx-input hx-link-input',
|
|
3202
|
+
placeholder: '页名,回车看它的出链与入链',
|
|
3203
|
+
value: linkState.name,
|
|
3204
|
+
onChange: function (event) {
|
|
3205
|
+
setLinkState({ name: event.target.value, data: linkState.data, error: '', loading: false })
|
|
3206
|
+
},
|
|
3207
|
+
onKeyDown: function (event) {
|
|
3208
|
+
if (event.key === 'Enter') openLinks(event.target.value)
|
|
3209
|
+
},
|
|
3210
|
+
}),
|
|
3211
|
+
h(
|
|
3212
|
+
'button',
|
|
3213
|
+
{ type: 'button', className: 'hx-btn', onClick: function () { openLinks(linkState.name) } },
|
|
3214
|
+
'查链接',
|
|
3215
|
+
),
|
|
3216
|
+
),
|
|
3217
|
+
linkBody,
|
|
3218
|
+
),
|
|
3219
|
+
)
|
|
3220
|
+
|
|
3221
|
+
// 探索窗:两张榜共用一个窗口,上面一排小页签切换。
|
|
3222
|
+
var exploreSection = h(
|
|
3223
|
+
'div',
|
|
3224
|
+
{ className: 'hx-explore' },
|
|
3225
|
+
h(
|
|
3226
|
+
'div',
|
|
3227
|
+
{ className: 'hx-subtabs', role: 'tablist', 'aria-label': '知识探索' },
|
|
3228
|
+
[
|
|
3229
|
+
['tags', '标签'],
|
|
3230
|
+
['relations', '关系'],
|
|
3231
|
+
].map(function (item) {
|
|
3232
|
+
return h(
|
|
3233
|
+
'button',
|
|
3234
|
+
{
|
|
3235
|
+
key: item[0],
|
|
3236
|
+
type: 'button',
|
|
3237
|
+
role: 'tab',
|
|
3238
|
+
'aria-selected': exploreTab === item[0],
|
|
3239
|
+
className: exploreTab === item[0] ? 'hx-subtab hx-subtab-on' : 'hx-subtab',
|
|
3240
|
+
onClick: function () {
|
|
3241
|
+
setExploreTab(item[0])
|
|
3242
|
+
},
|
|
3243
|
+
},
|
|
3244
|
+
item[1],
|
|
3245
|
+
)
|
|
3246
|
+
}),
|
|
3247
|
+
),
|
|
3248
|
+
exploreTab === 'tags' ? h('div', { className: 'hx-pane' }, tagsSection, tagCoSection) : h('div', { className: 'hx-pane' }, relationsSection, linksSection),
|
|
3249
|
+
)
|
|
3250
|
+
|
|
3251
|
+
// 一个组件,三个窗。挤在一起会变成一屏小字:五块计数还没看完,
|
|
3252
|
+
// 榜单已经滑出视野了。
|
|
3253
|
+
var viewSections = {
|
|
3254
|
+
overview: [staleHost, statusCard, countsSection, indexSection, problemsSection, usageSection, quickSection],
|
|
3255
|
+
explore: [exploreSection],
|
|
3256
|
+
tags: [tagsSection, tagCoSection],
|
|
3257
|
+
relations: [relationsSection, linksSection],
|
|
3258
|
+
}
|
|
3259
|
+
var body = viewSections[view] === undefined ? viewSections.overview : viewSections[view]
|
|
3260
|
+
|
|
3261
|
+
return h(
|
|
3262
|
+
'div',
|
|
3263
|
+
{ className: 'wn-root hx hx-view-' + view },
|
|
3264
|
+
notice === null ? null : h(Notice, { tone: notice.tone, message: notice.text }),
|
|
3265
|
+
body,
|
|
3266
|
+
)
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
// 概览是首页:进来先看「这个库现在什么状况」,再决定去查什么。
|
|
3270
|
+
// 一级页签只留四个动词:看状态 / 查内容 / 看结构 / 看模型怎么用。
|
|
3271
|
+
// 标签和关系都是「看结构」,合成「探索」—— 一级导航撑长了,多出来的不是信息。
|
|
3272
|
+
var PANEL_TABS = [
|
|
3273
|
+
['overview', '概览'],
|
|
3274
|
+
['search', '检索'],
|
|
3275
|
+
['explore', '探索'],
|
|
3276
|
+
['calls', '调用记录'],
|
|
3277
|
+
]
|
|
3278
|
+
|
|
3279
|
+
/** 左侧栏点开的那一页:概览做首页,其余各自成窗,都复用现成组件。 */
|
|
3280
|
+
function WikiPanel() {
|
|
3281
|
+
var tabTuple = useState('overview')
|
|
3282
|
+
var tab = tabTuple[0]
|
|
3283
|
+
var setTab = tabTuple[1]
|
|
3284
|
+
// 从标签点进检索:词 + 序号一起递下去。序号是必须的 —— 同一个词点两次,
|
|
3285
|
+
// 只比文本比不出变化,检索面板就再也不会重跑。
|
|
3286
|
+
var seedTuple = useState({ text: '', seq: 0 })
|
|
3287
|
+
var seed = seedTuple[0]
|
|
3288
|
+
var setSeed = seedTuple[1]
|
|
3289
|
+
// 「查看异常」的次数:0 → 1 才算一次点击,和 seed 用序号是同一个理由。
|
|
3290
|
+
var anomalyTuple = useState(0)
|
|
3291
|
+
var anomaly = anomalyTuple[0]
|
|
3292
|
+
var setAnomaly = anomalyTuple[1]
|
|
3293
|
+
|
|
3294
|
+
var tabs = h(
|
|
3295
|
+
'div',
|
|
3296
|
+
{ className: 'wn-tabs', role: 'tablist', 'aria-label': '知识库分页' },
|
|
3297
|
+
PANEL_TABS.map(function (item) {
|
|
3298
|
+
return h(
|
|
3299
|
+
'button',
|
|
3300
|
+
{
|
|
3301
|
+
key: item[0],
|
|
3302
|
+
type: 'button',
|
|
3303
|
+
role: 'tab',
|
|
3304
|
+
'aria-selected': tab === item[0],
|
|
3305
|
+
className: tab === item[0] ? 'wn-tab wn-tab-on' : 'wn-tab',
|
|
3306
|
+
onClick: function () {
|
|
3307
|
+
setTab(item[0])
|
|
3308
|
+
},
|
|
3309
|
+
},
|
|
3310
|
+
item[1],
|
|
3311
|
+
)
|
|
3312
|
+
}),
|
|
3313
|
+
)
|
|
3314
|
+
|
|
3315
|
+
return h(
|
|
3316
|
+
'div',
|
|
3317
|
+
{ className: 'wn-root wn-page' },
|
|
3318
|
+
h(
|
|
3319
|
+
'div',
|
|
3320
|
+
{ className: 'wn-head' },
|
|
3321
|
+
h('div', { className: 'wn-title' }, '知识库'),
|
|
3322
|
+
h(
|
|
3323
|
+
'div',
|
|
3324
|
+
{ className: 'wn-sub' },
|
|
3325
|
+
'你自己查一遍:走的是同一次检索、同一本账,所以这里看到的命中理由,就是模型为什么会引用那条笔记。',
|
|
3326
|
+
),
|
|
3327
|
+
),
|
|
3328
|
+
tabs,
|
|
3329
|
+
tab === 'search'
|
|
3330
|
+
? h(WikiSearchPanel, { compact: false, seed: seed.text, seedSeq: seed.seq })
|
|
3331
|
+
: tab === 'calls'
|
|
3332
|
+
? h(WikiCallsSection, { embedded: true })
|
|
3333
|
+
: h(WikiPanelStatus, {
|
|
3334
|
+
// 同一个组件按 view 出不同的窗:概览只摆六块,页面/标签/关系各自成页。
|
|
3335
|
+
view: tab,
|
|
3336
|
+
onSearch: function () {
|
|
3337
|
+
setTab('search')
|
|
3338
|
+
},
|
|
3339
|
+
onPickTag: function (tag) {
|
|
3340
|
+
setSeed({ text: tag, seq: seed.seq + 1 })
|
|
3341
|
+
setTab('search')
|
|
3342
|
+
},
|
|
3343
|
+
onCalls: function () {
|
|
3344
|
+
setTab('calls')
|
|
3345
|
+
},
|
|
3346
|
+
// 「查看异常」要的是「跳过去并且落在关系页」,只 setTab 不够:
|
|
3347
|
+
// 探索窗上次停在标签页时,人会以为自己点错了。
|
|
3348
|
+
onAnomaly: function () {
|
|
3349
|
+
setAnomaly(anomaly + 1)
|
|
3350
|
+
setTab('explore')
|
|
3351
|
+
},
|
|
3352
|
+
anomalyTick: anomaly,
|
|
3353
|
+
}),
|
|
3354
|
+
)
|
|
3355
|
+
}
|
|
3356
|
+
|
|
2021
3357
|
/* ------------------------------ 注册 ------------------------------ */
|
|
2022
3358
|
|
|
2023
3359
|
function apply(ctx) {
|
|
@@ -2035,6 +3371,20 @@ window.__ModuleLoader__.load({
|
|
|
2035
3371
|
}
|
|
2036
3372
|
}, 'dsh-wiki-notes: styles')
|
|
2037
3373
|
|
|
3374
|
+
// 「打开知识库页」的跳转。面板藏在左侧竖排图标里,没看说明未必知道点那儿;
|
|
3375
|
+
// ui-layout 不在时 selectPanel 无从谈起,按钮也随之不出现(openPanel 一直是空)。
|
|
3376
|
+
var layout = null
|
|
3377
|
+
if (typeof ctx.inject === 'function') {
|
|
3378
|
+
ctx.inject(['layout'], function (owner) {
|
|
3379
|
+
layout = owner.get('layout')
|
|
3380
|
+
})
|
|
3381
|
+
}
|
|
3382
|
+
function openPanel() {
|
|
3383
|
+
if (layout !== null && layout !== undefined && typeof layout.selectPanel === 'function') {
|
|
3384
|
+
layout.selectPanel(PANEL_ID)
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
|
|
2038
3388
|
// 设置弹层左侧的一级入口
|
|
2039
3389
|
ctx.slots.inject('settings.section', function () {
|
|
2040
3390
|
return ctx.slots.register(
|
|
@@ -2047,7 +3397,45 @@ window.__ModuleLoader__.load({
|
|
|
2047
3397
|
},
|
|
2048
3398
|
},
|
|
2049
3399
|
function (props) {
|
|
2050
|
-
return h(
|
|
3400
|
+
return h(
|
|
3401
|
+
WikiNotesSection,
|
|
3402
|
+
Object.assign({}, props !== null && props !== undefined ? props : {}, { openPanel: openPanel }),
|
|
3403
|
+
)
|
|
3404
|
+
},
|
|
3405
|
+
)
|
|
3406
|
+
})
|
|
3407
|
+
|
|
3408
|
+
// 左侧栏入口:竖排里的一本书,点开是主列里的一整页工作台。
|
|
3409
|
+
// 跟右侧栏一样的态度 —— 槽位不在就静默跳过:注册不进去只是少一个图标,
|
|
3410
|
+
// 不该让设置页跟着进不去。
|
|
3411
|
+
ctx.slots.inject('sidebar.panellist', function () {
|
|
3412
|
+
return ctx.slots.register(
|
|
3413
|
+
{
|
|
3414
|
+
name: 'sidebar.panellist',
|
|
3415
|
+
id: PANEL_ID,
|
|
3416
|
+
order: PANEL_ORDER,
|
|
3417
|
+
label: function () {
|
|
3418
|
+
return '知识库'
|
|
3419
|
+
},
|
|
3420
|
+
},
|
|
3421
|
+
WikiPanelIcon,
|
|
3422
|
+
)
|
|
3423
|
+
})
|
|
3424
|
+
|
|
3425
|
+
// 同一个 id 还必须是 main 的 key:图标负责「有得点」,main 负责「点开有东西」。
|
|
3426
|
+
// 两处共用 PANEL_ID 一个常量 —— 写两个字符串、改一个忘一个的结果,
|
|
3427
|
+
// 就是点了没反应且不报错,最难查的那种。
|
|
3428
|
+
ctx.slots.inject('main', function () {
|
|
3429
|
+
return ctx.slots.register(
|
|
3430
|
+
{
|
|
3431
|
+
name: 'main',
|
|
3432
|
+
key: PANEL_ID,
|
|
3433
|
+
inject: function () {
|
|
3434
|
+
return {}
|
|
3435
|
+
},
|
|
3436
|
+
},
|
|
3437
|
+
function () {
|
|
3438
|
+
return h(WikiPanel, {})
|
|
2051
3439
|
},
|
|
2052
3440
|
)
|
|
2053
3441
|
})
|
|
@@ -2124,6 +3512,10 @@ window.__ModuleLoader__.load({
|
|
|
2124
3512
|
WikiSearchPanel: WikiSearchPanel,
|
|
2125
3513
|
WikiSearchSidebarTab: WikiSearchSidebarTab,
|
|
2126
3514
|
WikiCallsSection: WikiCallsSection,
|
|
3515
|
+
WikiPanel: WikiPanel,
|
|
3516
|
+
WikiPanelIcon: WikiPanelIcon,
|
|
3517
|
+
WikiPanelStatus: WikiPanelStatus,
|
|
3518
|
+
whenText: whenText,
|
|
2127
3519
|
WikiGovernancePanel: WikiGovernancePanel,
|
|
2128
3520
|
},
|
|
2129
3521
|
}
|