chatluna-plugin-kb 0.1.3 → 0.1.7
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/package.json +1 -1
- package/web/client.css +470 -20
- package/web/client.js +708 -198
package/web/client.js
CHANGED
|
@@ -327,6 +327,8 @@ export function viewStatus(snapshot) {
|
|
|
327
327
|
port: finite(data.port),
|
|
328
328
|
baseUrl: typeof data.baseUrl === 'string' ? data.baseUrl : '',
|
|
329
329
|
health: data.health ?? data.healthy,
|
|
330
|
+
ocr: data.ocr ?? (data.health !== null && typeof data.health === 'object' ? data.health.ocr : undefined),
|
|
331
|
+
version: typeof data.version === 'string' ? data.version.trim() : '',
|
|
330
332
|
uptime: uptimeSecondsOf(data),
|
|
331
333
|
restarts: finite(data.restarts),
|
|
332
334
|
rss: finite(data.rssBytes) ?? finite(data.rss) ?? finite(data.memoryBytes),
|
|
@@ -374,6 +376,74 @@ function formatHealth(health) {
|
|
|
374
376
|
return '异常'
|
|
375
377
|
}
|
|
376
378
|
|
|
379
|
+
/**
|
|
380
|
+
* 日志纯前端过滤:关键字大小写无关、空格分词 AND;warningsOnly 只保留告警/错误行。
|
|
381
|
+
* @param {unknown} logs
|
|
382
|
+
* @param {{query?: string, warningsOnly?: boolean}} [options]
|
|
383
|
+
*/
|
|
384
|
+
export function filterLogs(logs, options = {}) {
|
|
385
|
+
const list = Array.isArray(logs) ? logs.filter((line) => typeof line === 'string') : []
|
|
386
|
+
const terms = (typeof options.query === 'string' ? options.query : '')
|
|
387
|
+
.trim()
|
|
388
|
+
.toLowerCase()
|
|
389
|
+
.split(/\s+/)
|
|
390
|
+
.filter((term) => term !== '')
|
|
391
|
+
const warningsOnly = options.warningsOnly === true
|
|
392
|
+
return list.filter((line) => {
|
|
393
|
+
if (warningsOnly && !/WARN|ERROR|FATAL|panic|fail/i.test(line)) return false
|
|
394
|
+
if (terms.length === 0) return true
|
|
395
|
+
const haystack = line.toLowerCase()
|
|
396
|
+
return terms.every((term) => haystack.includes(term))
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** 日志行着色:错误 > 告警 > 普通。 */
|
|
401
|
+
export function logLineTone(line) {
|
|
402
|
+
const text = typeof line === 'string' ? line : ''
|
|
403
|
+
if (/ERROR|FATAL|panic|fail/i.test(text)) return 'error'
|
|
404
|
+
if (/WARN/i.test(text)) return 'warning'
|
|
405
|
+
return 'info'
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 解析引擎 /health 的 OCR 体检字段;兼容顶层 ocr 与 health.ocr,缺失时返回 available=false。
|
|
410
|
+
* @param {unknown} status
|
|
411
|
+
*/
|
|
412
|
+
export function ocrSummary(status) {
|
|
413
|
+
const source = status !== null && typeof status === 'object' ? status : {}
|
|
414
|
+
const health = source.health !== null && typeof source.health === 'object' ? source.health : {}
|
|
415
|
+
const raw = source.ocr ?? health.ocr
|
|
416
|
+
const ocr = raw !== null && typeof raw === 'object' ? raw : {}
|
|
417
|
+
const hasOcr = ['ready', 'engine', 'tessdataDir', 'tesseractFound', 'pdftoppmFound'].some(
|
|
418
|
+
(key) => ocr[key] !== undefined
|
|
419
|
+
)
|
|
420
|
+
const hasTop = ['tesseractFound', 'pdftoppmFound', 'tessdataDir'].some((key) => source[key] !== undefined)
|
|
421
|
+
if (!hasOcr && !hasTop) {
|
|
422
|
+
return {
|
|
423
|
+
available: false,
|
|
424
|
+
ready: undefined,
|
|
425
|
+
label: '未知',
|
|
426
|
+
engine: '—',
|
|
427
|
+
tesseractFound: undefined,
|
|
428
|
+
pdftoppmFound: undefined,
|
|
429
|
+
tessdataDir: ''
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const pick = (key) => (ocr[key] !== undefined ? ocr[key] : source[key])
|
|
433
|
+
const ready = pick('ready')
|
|
434
|
+
const engine = typeof ocr.engine === 'string' && ocr.engine.trim() !== '' ? ocr.engine.trim() : 'tesseract'
|
|
435
|
+
const dir = typeof pick('tessdataDir') === 'string' ? pick('tessdataDir').trim() : ''
|
|
436
|
+
return {
|
|
437
|
+
available: true,
|
|
438
|
+
ready: ready === true ? true : ready === false ? false : undefined,
|
|
439
|
+
label: ready === true ? '本地就绪' : ready === false ? '未就绪' : '未知',
|
|
440
|
+
engine,
|
|
441
|
+
tesseractFound: typeof pick('tesseractFound') === 'boolean' ? pick('tesseractFound') : undefined,
|
|
442
|
+
pdftoppmFound: typeof pick('pdftoppmFound') === 'boolean' ? pick('pdftoppmFound') : undefined,
|
|
443
|
+
tessdataDir: dir
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
377
447
|
function rulesOf(snapshot) {
|
|
378
448
|
const value = snapshot?.data
|
|
379
449
|
if (Array.isArray(value)) return value
|
|
@@ -1170,6 +1240,14 @@ const providerGroupOf = (item) => {
|
|
|
1170
1240
|
return id === '' ? '—' : id
|
|
1171
1241
|
}
|
|
1172
1242
|
|
|
1243
|
+
/** 分组展示名:去掉 chatluna 内部前缀与 8+ 位实例后缀;原值仍用于 key/title。 */
|
|
1244
|
+
export function modelProviderLabel(value) {
|
|
1245
|
+
const raw = typeof value === 'string' ? value.trim() : ''
|
|
1246
|
+
if (raw === '') return '—'
|
|
1247
|
+
const stripped = raw.replace(/^chatluna-provider-/i, '').replace(/-[a-z0-9]{8,}$/i, '')
|
|
1248
|
+
return stripped === '' ? raw : stripped
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1173
1251
|
/**
|
|
1174
1252
|
* 模型复制列表的搜索/类型筛选/厂商分组(纯函数,SSR 与单测共用)。
|
|
1175
1253
|
* - 类型计数与 chips 基于完整目录,只展示有模型的类型;
|
|
@@ -1222,7 +1300,7 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1222
1300
|
const visible = items.slice(0, limit)
|
|
1223
1301
|
groups.push({
|
|
1224
1302
|
key,
|
|
1225
|
-
label: key,
|
|
1303
|
+
label: modelProviderLabel(key),
|
|
1226
1304
|
items: visible,
|
|
1227
1305
|
total: items.length,
|
|
1228
1306
|
hidden: items.length - visible.length,
|
|
@@ -1237,6 +1315,7 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1237
1315
|
* 纯渲染层:所有状态与请求都在 ModelCopyPanel 里,便于 SSR 桩测试直接喂模型。
|
|
1238
1316
|
* @param {{
|
|
1239
1317
|
* open: boolean,
|
|
1318
|
+
* layout?: 'workbench'|'card',
|
|
1240
1319
|
* state: 'idle'|'loading'|'ready'|'error',
|
|
1241
1320
|
* models: Array<object>,
|
|
1242
1321
|
* error?: string,
|
|
@@ -1270,9 +1349,307 @@ export function modelCopyView(m = {}) {
|
|
|
1270
1349
|
const selectedRoles = selected === null ? [] : importRolesFor(selected)
|
|
1271
1350
|
const activeImportRole = selectedRoles.includes(m.importRole) ? m.importRole : selected?.type
|
|
1272
1351
|
const result = m.result !== null && typeof m.result === 'object' ? m.result : null
|
|
1273
|
-
const
|
|
1352
|
+
const workbench = m.layout === 'workbench'
|
|
1353
|
+
const open = workbench ? true : m.open === true
|
|
1274
1354
|
const state = typeof m.state === 'string' ? m.state : 'idle'
|
|
1275
|
-
const loadLabel = state === 'loading' ? '
|
|
1355
|
+
const loadLabel = state === 'loading' ? '刷新中…' : '刷新'
|
|
1356
|
+
const fullLabel = (item) =>
|
|
1357
|
+
`${item.providerLabel || item.providerId || '—'} · ${item.modelId || '—'}`
|
|
1358
|
+
const roleLabel = (role) => (role === 'vlm' ? '仅作为视觉模型' : '对话模型(含视觉)')
|
|
1359
|
+
|
|
1360
|
+
const roleSelect = (withId) =>
|
|
1361
|
+
h(
|
|
1362
|
+
Select,
|
|
1363
|
+
{
|
|
1364
|
+
value: activeImportRole,
|
|
1365
|
+
disabled: m.importing === true,
|
|
1366
|
+
onValueChange: (next) =>
|
|
1367
|
+
typeof m.onImportRole === 'function' ? m.onImportRole(String(next)) : undefined
|
|
1368
|
+
},
|
|
1369
|
+
h(
|
|
1370
|
+
SelectTrigger,
|
|
1371
|
+
{ id: withId ? 'kb-model-import-role' : undefined, className: 'kb-rule-select', 'aria-label': '导入为' },
|
|
1372
|
+
h(SelectValue, null, roleLabel(activeImportRole))
|
|
1373
|
+
),
|
|
1374
|
+
h(
|
|
1375
|
+
SelectContent,
|
|
1376
|
+
null,
|
|
1377
|
+
selectedRoles.map((role) =>
|
|
1378
|
+
h(SelectItem, { key: role, value: role }, roleLabel(role))
|
|
1379
|
+
)
|
|
1380
|
+
)
|
|
1381
|
+
)
|
|
1382
|
+
|
|
1383
|
+
const importButton = () =>
|
|
1384
|
+
h(
|
|
1385
|
+
Button,
|
|
1386
|
+
{
|
|
1387
|
+
size: 'sm',
|
|
1388
|
+
disabled: selected === null || m.importing === true || typeof m.onCopy !== 'function',
|
|
1389
|
+
onClick: selected !== null && typeof m.onCopy === 'function' ? m.onCopy : undefined
|
|
1390
|
+
},
|
|
1391
|
+
m.importing === true ? '复制中…' : '复制到知识库'
|
|
1392
|
+
)
|
|
1393
|
+
|
|
1394
|
+
const resultAlert = () => {
|
|
1395
|
+
if (!m.copyError && result === null) return null
|
|
1396
|
+
return h(
|
|
1397
|
+
'div',
|
|
1398
|
+
{ className: 'kb-model-result' },
|
|
1399
|
+
m.copyError ? errorAlert(m.copyError, '复制失败') : null,
|
|
1400
|
+
result !== null
|
|
1401
|
+
? h(
|
|
1402
|
+
Alert,
|
|
1403
|
+
{ className: 'kb-alert-success' },
|
|
1404
|
+
h(UiIcon, { name: 'check' }),
|
|
1405
|
+
h(AlertTitle, null, '已复制到知识库'),
|
|
1406
|
+
h(
|
|
1407
|
+
AlertDescription,
|
|
1408
|
+
null,
|
|
1409
|
+
`模型 id ${result.modelId ?? '—'}${result.dimension ? ` · 维度 ${result.dimension}` : ''}`
|
|
1410
|
+
)
|
|
1411
|
+
)
|
|
1412
|
+
: null
|
|
1413
|
+
)
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
if (workbench) {
|
|
1417
|
+
const workbenchItem = (item) => {
|
|
1418
|
+
const key = modelSelectionKey(item)
|
|
1419
|
+
const active = key === selectedKey
|
|
1420
|
+
return h(
|
|
1421
|
+
'button',
|
|
1422
|
+
{
|
|
1423
|
+
type: 'button',
|
|
1424
|
+
key,
|
|
1425
|
+
className: 'kb-model-item',
|
|
1426
|
+
title: fullLabel(item),
|
|
1427
|
+
'aria-pressed': active,
|
|
1428
|
+
onClick: typeof m.onSelect === 'function' ? () => m.onSelect(key) : undefined
|
|
1429
|
+
},
|
|
1430
|
+
h(
|
|
1431
|
+
'span',
|
|
1432
|
+
{ className: 'kb-model-main' },
|
|
1433
|
+
h(
|
|
1434
|
+
'span',
|
|
1435
|
+
{ className: 'kb-model-title' },
|
|
1436
|
+
h('span', { className: 'kb-model-model-id' }, item.modelId || '—'),
|
|
1437
|
+
h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, modelRoleLabel(item.type)),
|
|
1438
|
+
item.supportsVision === true ? h(Badge, { variant: 'secondary' }, '支持视觉') : null,
|
|
1439
|
+
item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null
|
|
1440
|
+
),
|
|
1441
|
+
h(
|
|
1442
|
+
'span',
|
|
1443
|
+
{ className: 'kb-model-url', title: item.baseUrl || '' },
|
|
1444
|
+
shortenUrl(item.baseUrl)
|
|
1445
|
+
),
|
|
1446
|
+
item.protocolHint
|
|
1447
|
+
? h(
|
|
1448
|
+
'span',
|
|
1449
|
+
{ className: 'kb-muted-text' },
|
|
1450
|
+
'该路由使用非 OpenAI 原生协议,复制后可能需要在知识库设置中调整接口类型。'
|
|
1451
|
+
)
|
|
1452
|
+
: null
|
|
1453
|
+
),
|
|
1454
|
+
active
|
|
1455
|
+
? h('span', { className: 'kb-model-check', 'aria-hidden': true }, h(UiIcon, { name: 'check' }))
|
|
1456
|
+
: null
|
|
1457
|
+
)
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
let body
|
|
1461
|
+
if (state === 'loading') {
|
|
1462
|
+
body = h(
|
|
1463
|
+
'div',
|
|
1464
|
+
{ className: 'kb-model-scroll' },
|
|
1465
|
+
h(Skeleton, { className: 'kb-skeleton-row' }),
|
|
1466
|
+
h(Skeleton, { className: 'kb-skeleton-row' })
|
|
1467
|
+
)
|
|
1468
|
+
} else if (state === 'error' && typeof m.error === 'string' && m.error !== '') {
|
|
1469
|
+
body = h('div', { className: 'kb-model-scroll' }, errorAlert(m.error, '读取模型列表失败'))
|
|
1470
|
+
} else if (state === 'idle') {
|
|
1471
|
+
body = h('div', { className: 'kb-model-scroll' }, h('p', { className: 'kb-muted-text' }, '点击刷新加载模型列表。'))
|
|
1472
|
+
} else if (models.length === 0) {
|
|
1473
|
+
body = h(
|
|
1474
|
+
'div',
|
|
1475
|
+
{ className: 'kb-model-scroll' },
|
|
1476
|
+
h('p', { className: 'kb-muted-text' }, 'ChatLuna 暂无可用于复制的知识库模型。')
|
|
1477
|
+
)
|
|
1478
|
+
} else if (report.groups.length === 0) {
|
|
1479
|
+
body = h(
|
|
1480
|
+
'div',
|
|
1481
|
+
{ className: 'kb-model-scroll' },
|
|
1482
|
+
h('p', { className: 'kb-muted-text' }, '没有匹配的模型;调整搜索关键词或类型筛选。')
|
|
1483
|
+
)
|
|
1484
|
+
} else {
|
|
1485
|
+
body = h(
|
|
1486
|
+
'div',
|
|
1487
|
+
{ className: 'kb-model-scroll' },
|
|
1488
|
+
report.groups.map((group) =>
|
|
1489
|
+
h(
|
|
1490
|
+
'div',
|
|
1491
|
+
{ key: group.key, className: 'kb-model-group' },
|
|
1492
|
+
h(
|
|
1493
|
+
'div',
|
|
1494
|
+
{ className: 'kb-model-group-head' },
|
|
1495
|
+
h('p', { className: 'kb-model-group-title' }, group.label),
|
|
1496
|
+
h(Badge, { variant: 'outline' }, String(group.total))
|
|
1497
|
+
),
|
|
1498
|
+
h('div', { className: 'kb-model-list' }, group.items.map(workbenchItem)),
|
|
1499
|
+
group.hidden > 0
|
|
1500
|
+
? h(
|
|
1501
|
+
Button,
|
|
1502
|
+
{
|
|
1503
|
+
variant: 'ghost',
|
|
1504
|
+
size: 'sm',
|
|
1505
|
+
className: 'kb-model-more',
|
|
1506
|
+
onClick: () =>
|
|
1507
|
+
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1508
|
+
},
|
|
1509
|
+
`显示更多 ${group.hidden}`
|
|
1510
|
+
)
|
|
1511
|
+
: null,
|
|
1512
|
+
group.expanded && group.total > MODEL_GROUP_LIMIT
|
|
1513
|
+
? h(
|
|
1514
|
+
Button,
|
|
1515
|
+
{
|
|
1516
|
+
variant: 'ghost',
|
|
1517
|
+
size: 'sm',
|
|
1518
|
+
className: 'kb-model-more',
|
|
1519
|
+
onClick: () =>
|
|
1520
|
+
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1521
|
+
},
|
|
1522
|
+
'收起'
|
|
1523
|
+
)
|
|
1524
|
+
: null
|
|
1525
|
+
)
|
|
1526
|
+
)
|
|
1527
|
+
)
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
return h(
|
|
1531
|
+
'div',
|
|
1532
|
+
{ className: 'kb-model-workbench' },
|
|
1533
|
+
h(
|
|
1534
|
+
'div',
|
|
1535
|
+
{ className: 'kb-model-workbench-header' },
|
|
1536
|
+
h(DialogTitle, { className: 'kb-model-workbench-title' }, '从 ChatLuna 复制模型'),
|
|
1537
|
+
h(
|
|
1538
|
+
DialogDescription,
|
|
1539
|
+
{ className: 'kb-model-workbench-subtitle' },
|
|
1540
|
+
'选择已配置的模型复制到知识库;仅同步元数据,不会暴露 API Key。'
|
|
1541
|
+
)
|
|
1542
|
+
),
|
|
1543
|
+
h(
|
|
1544
|
+
'div',
|
|
1545
|
+
{ className: 'kb-model-toolbar' },
|
|
1546
|
+
h(SearchBox, {
|
|
1547
|
+
value: query,
|
|
1548
|
+
onChange: (value) => (typeof m.onQueryChange === 'function' ? m.onQueryChange(value) : undefined),
|
|
1549
|
+
placeholder: '搜索厂商、模型或地址…',
|
|
1550
|
+
clearLabel: '清除搜索'
|
|
1551
|
+
}),
|
|
1552
|
+
h(FilterChips, {
|
|
1553
|
+
options: report.typeOptions,
|
|
1554
|
+
value: report.activeType,
|
|
1555
|
+
onChange: (value) => (typeof m.onTypeChange === 'function' ? m.onTypeChange(value) : undefined),
|
|
1556
|
+
label: '按模型类型筛选'
|
|
1557
|
+
}),
|
|
1558
|
+
h(
|
|
1559
|
+
Button,
|
|
1560
|
+
{
|
|
1561
|
+
variant: 'outline',
|
|
1562
|
+
size: 'sm',
|
|
1563
|
+
disabled: state === 'loading' || typeof m.onLoad !== 'function',
|
|
1564
|
+
onClick: typeof m.onLoad === 'function' ? m.onLoad : undefined
|
|
1565
|
+
},
|
|
1566
|
+
loadLabel
|
|
1567
|
+
)
|
|
1568
|
+
),
|
|
1569
|
+
body,
|
|
1570
|
+
resultAlert(),
|
|
1571
|
+
h(
|
|
1572
|
+
DialogFooter,
|
|
1573
|
+
{ className: 'kb-model-dialog-footer' },
|
|
1574
|
+
h(
|
|
1575
|
+
'div',
|
|
1576
|
+
{ className: 'kb-model-selection' },
|
|
1577
|
+
selected === null
|
|
1578
|
+
? h('span', { className: 'kb-model-selection-empty' }, '请选择一个要复制的模型')
|
|
1579
|
+
: h(
|
|
1580
|
+
'span',
|
|
1581
|
+
{ className: 'kb-model-selection-text' },
|
|
1582
|
+
'已选:',
|
|
1583
|
+
h('strong', { className: 'kb-model-selection-name' }, selected.modelId || '—'),
|
|
1584
|
+
h(
|
|
1585
|
+
'span',
|
|
1586
|
+
{ className: 'kb-model-selection-provider' },
|
|
1587
|
+
` · ${selected.providerLabel || selected.providerId || '—'}`
|
|
1588
|
+
)
|
|
1589
|
+
),
|
|
1590
|
+
selected !== null && selectedRoles.length > 1
|
|
1591
|
+
? h('div', { className: 'kb-model-role' }, roleSelect(true))
|
|
1592
|
+
: null
|
|
1593
|
+
),
|
|
1594
|
+
h(
|
|
1595
|
+
'div',
|
|
1596
|
+
{ className: 'kb-model-footer-actions' },
|
|
1597
|
+
h(
|
|
1598
|
+
Button,
|
|
1599
|
+
{
|
|
1600
|
+
variant: 'outline',
|
|
1601
|
+
size: 'sm',
|
|
1602
|
+
onClick: typeof m.onClose === 'function' ? m.onClose : undefined
|
|
1603
|
+
},
|
|
1604
|
+
'取消'
|
|
1605
|
+
),
|
|
1606
|
+
importButton()
|
|
1607
|
+
)
|
|
1608
|
+
)
|
|
1609
|
+
)
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
const cardItem = (item) => {
|
|
1613
|
+
const key = modelSelectionKey(item)
|
|
1614
|
+
const active = key === selectedKey
|
|
1615
|
+
return h(
|
|
1616
|
+
'li',
|
|
1617
|
+
{ key },
|
|
1618
|
+
h(
|
|
1619
|
+
'button',
|
|
1620
|
+
{
|
|
1621
|
+
type: 'button',
|
|
1622
|
+
className: 'kb-model-item',
|
|
1623
|
+
'aria-pressed': active,
|
|
1624
|
+
onClick: typeof m.onSelect === 'function' ? () => m.onSelect(key) : undefined
|
|
1625
|
+
},
|
|
1626
|
+
h(
|
|
1627
|
+
'span',
|
|
1628
|
+
{ className: 'kb-model-main' },
|
|
1629
|
+
h(
|
|
1630
|
+
'span',
|
|
1631
|
+
{ className: 'kb-model-title' },
|
|
1632
|
+
fullLabel(item),
|
|
1633
|
+
h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, modelRoleLabel(item.type)),
|
|
1634
|
+
item.supportsVision === true ? h(Badge, { variant: 'secondary' }, '支持视觉') : null,
|
|
1635
|
+
item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null
|
|
1636
|
+
),
|
|
1637
|
+
h('span', { className: 'kb-model-url', title: item.baseUrl || '' }, shortenUrl(item.baseUrl)),
|
|
1638
|
+
item.protocolHint
|
|
1639
|
+
? h(
|
|
1640
|
+
'span',
|
|
1641
|
+
{ className: 'kb-muted-text' },
|
|
1642
|
+
'该路由使用非 OpenAI 原生协议,复制后可能需要在知识库设置中调整接口类型。'
|
|
1643
|
+
)
|
|
1644
|
+
: null
|
|
1645
|
+
),
|
|
1646
|
+
active
|
|
1647
|
+
? h('span', { className: 'kb-model-check', 'aria-hidden': true }, h(UiIcon, { name: 'check' }))
|
|
1648
|
+
: null
|
|
1649
|
+
)
|
|
1650
|
+
)
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1276
1653
|
return h(
|
|
1277
1654
|
Section,
|
|
1278
1655
|
{ title: '模型配置' },
|
|
@@ -1289,7 +1666,19 @@ export function modelCopyView(m = {}) {
|
|
|
1289
1666
|
null,
|
|
1290
1667
|
h(
|
|
1291
1668
|
'div',
|
|
1292
|
-
{ className: 'kb-
|
|
1669
|
+
{ className: 'kb-model-top-actions' },
|
|
1670
|
+
open && selected !== null
|
|
1671
|
+
? h(
|
|
1672
|
+
'span',
|
|
1673
|
+
{
|
|
1674
|
+
className: 'kb-model-selected',
|
|
1675
|
+
title: fullLabel(selected)
|
|
1676
|
+
},
|
|
1677
|
+
`已选:${selected.modelId || '—'} · ${selected.providerLabel || selected.providerId || '—'}`
|
|
1678
|
+
)
|
|
1679
|
+
: null,
|
|
1680
|
+
open && selectedRoles.length > 1 ? roleSelect(true) : null,
|
|
1681
|
+
open ? importButton() : null,
|
|
1293
1682
|
open
|
|
1294
1683
|
? h(
|
|
1295
1684
|
Button,
|
|
@@ -1307,6 +1696,7 @@ export function modelCopyView(m = {}) {
|
|
|
1307
1696
|
{
|
|
1308
1697
|
variant: 'ghost',
|
|
1309
1698
|
size: 'sm',
|
|
1699
|
+
'aria-expanded': open,
|
|
1310
1700
|
onClick: typeof m.onToggle === 'function' ? m.onToggle : undefined
|
|
1311
1701
|
},
|
|
1312
1702
|
open ? '收起' : '展开'
|
|
@@ -1321,6 +1711,7 @@ export function modelCopyView(m = {}) {
|
|
|
1321
1711
|
h(
|
|
1322
1712
|
'div',
|
|
1323
1713
|
{ className: 'kb-card-stack' },
|
|
1714
|
+
resultAlert(),
|
|
1324
1715
|
state === 'loading' ? h(Skeleton, { className: 'kb-skeleton-row' }) : null,
|
|
1325
1716
|
state === 'loading' ? h(Skeleton, { className: 'kb-skeleton-row' }) : null,
|
|
1326
1717
|
state === 'error' && typeof m.error === 'string' && m.error !== ''
|
|
@@ -1340,7 +1731,7 @@ export function modelCopyView(m = {}) {
|
|
|
1340
1731
|
value: query,
|
|
1341
1732
|
onChange: (value) =>
|
|
1342
1733
|
typeof m.onQueryChange === 'function' ? m.onQueryChange(value) : undefined,
|
|
1343
|
-
placeholder: '
|
|
1734
|
+
placeholder: '搜索厂商、模型或地址…',
|
|
1344
1735
|
clearLabel: '清除搜索'
|
|
1345
1736
|
}),
|
|
1346
1737
|
h(FilterChips, {
|
|
@@ -1369,61 +1760,7 @@ export function modelCopyView(m = {}) {
|
|
|
1369
1760
|
h('p', { className: 'kb-model-group-title' }, group.label),
|
|
1370
1761
|
h(Badge, { variant: 'outline' }, String(group.total))
|
|
1371
1762
|
),
|
|
1372
|
-
h(
|
|
1373
|
-
'ul',
|
|
1374
|
-
{ className: 'kb-model-list' },
|
|
1375
|
-
group.items.map((item) => {
|
|
1376
|
-
const key = modelSelectionKey(item)
|
|
1377
|
-
const active = key === selectedKey
|
|
1378
|
-
const role = modelRoleLabel(item.type)
|
|
1379
|
-
return h(
|
|
1380
|
-
'li',
|
|
1381
|
-
{ key },
|
|
1382
|
-
h(
|
|
1383
|
-
'button',
|
|
1384
|
-
{
|
|
1385
|
-
type: 'button',
|
|
1386
|
-
className: 'kb-model-item',
|
|
1387
|
-
'aria-pressed': active,
|
|
1388
|
-
onClick: typeof m.onSelect === 'function' ? () => m.onSelect(key) : undefined
|
|
1389
|
-
},
|
|
1390
|
-
h(
|
|
1391
|
-
'span',
|
|
1392
|
-
{ className: 'kb-model-main' },
|
|
1393
|
-
h(
|
|
1394
|
-
'span',
|
|
1395
|
-
{ className: 'kb-model-title' },
|
|
1396
|
-
`${item.providerLabel || item.providerId || '—'} · ${item.modelId || '—'}`,
|
|
1397
|
-
h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, role),
|
|
1398
|
-
item.supportsVision === true
|
|
1399
|
-
? h(Badge, { variant: 'secondary' }, '支持视觉')
|
|
1400
|
-
: null,
|
|
1401
|
-
item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null
|
|
1402
|
-
),
|
|
1403
|
-
h(
|
|
1404
|
-
'span',
|
|
1405
|
-
{ className: 'kb-model-url', title: item.baseUrl || '' },
|
|
1406
|
-
shortenUrl(item.baseUrl)
|
|
1407
|
-
),
|
|
1408
|
-
item.protocolHint
|
|
1409
|
-
? h(
|
|
1410
|
-
'span',
|
|
1411
|
-
{ className: 'kb-muted-text' },
|
|
1412
|
-
'该路由使用非 OpenAI 原生协议,复制后可能需要在 WeKnora 中调整接口类型。'
|
|
1413
|
-
)
|
|
1414
|
-
: null
|
|
1415
|
-
),
|
|
1416
|
-
active
|
|
1417
|
-
? h(
|
|
1418
|
-
'span',
|
|
1419
|
-
{ className: 'kb-model-check', 'aria-hidden': true },
|
|
1420
|
-
h(UiIcon, { name: 'check' })
|
|
1421
|
-
)
|
|
1422
|
-
: null
|
|
1423
|
-
)
|
|
1424
|
-
)
|
|
1425
|
-
})
|
|
1426
|
-
),
|
|
1763
|
+
h('ul', { className: 'kb-model-list' }, group.items.map(cardItem)),
|
|
1427
1764
|
group.hidden > 0
|
|
1428
1765
|
? h(
|
|
1429
1766
|
Button,
|
|
@@ -1432,9 +1769,7 @@ export function modelCopyView(m = {}) {
|
|
|
1432
1769
|
size: 'sm',
|
|
1433
1770
|
className: 'kb-model-more',
|
|
1434
1771
|
onClick: () =>
|
|
1435
|
-
typeof m.onToggleGroup === 'function'
|
|
1436
|
-
? m.onToggleGroup(group.key)
|
|
1437
|
-
: undefined
|
|
1772
|
+
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1438
1773
|
},
|
|
1439
1774
|
`显示更多 ${group.hidden}`
|
|
1440
1775
|
)
|
|
@@ -1447,9 +1782,7 @@ export function modelCopyView(m = {}) {
|
|
|
1447
1782
|
size: 'sm',
|
|
1448
1783
|
className: 'kb-model-more',
|
|
1449
1784
|
onClick: () =>
|
|
1450
|
-
typeof m.onToggleGroup === 'function'
|
|
1451
|
-
? m.onToggleGroup(group.key)
|
|
1452
|
-
: undefined
|
|
1785
|
+
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1453
1786
|
},
|
|
1454
1787
|
'收起'
|
|
1455
1788
|
)
|
|
@@ -1457,62 +1790,6 @@ export function modelCopyView(m = {}) {
|
|
|
1457
1790
|
)
|
|
1458
1791
|
)
|
|
1459
1792
|
)
|
|
1460
|
-
: null,
|
|
1461
|
-
m.copyError ? errorAlert(m.copyError, '复制失败') : null,
|
|
1462
|
-
result !== null
|
|
1463
|
-
? h(
|
|
1464
|
-
Alert,
|
|
1465
|
-
{ className: 'kb-alert-success' },
|
|
1466
|
-
h(UiIcon, { name: 'check' }),
|
|
1467
|
-
h(AlertTitle, null, '已复制到 WeKnora'),
|
|
1468
|
-
h(
|
|
1469
|
-
AlertDescription,
|
|
1470
|
-
null,
|
|
1471
|
-
`模型 id ${result.modelId ?? '—'}${result.dimension ? ` · 维度 ${result.dimension}` : ''}`
|
|
1472
|
-
)
|
|
1473
|
-
)
|
|
1474
|
-
: null,
|
|
1475
|
-
selected !== null
|
|
1476
|
-
? h(
|
|
1477
|
-
'div',
|
|
1478
|
-
{ className: 'kb-model-footer' },
|
|
1479
|
-
selectedRoles.length > 1
|
|
1480
|
-
? h(
|
|
1481
|
-
Select,
|
|
1482
|
-
{
|
|
1483
|
-
value: activeImportRole,
|
|
1484
|
-
disabled: m.importing === true,
|
|
1485
|
-
onValueChange: (next) =>
|
|
1486
|
-
typeof m.onImportRole === 'function' ? m.onImportRole(String(next)) : undefined
|
|
1487
|
-
},
|
|
1488
|
-
h(
|
|
1489
|
-
SelectTrigger,
|
|
1490
|
-
{ id: 'kb-model-import-role', className: 'kb-rule-select', 'aria-label': '导入为' },
|
|
1491
|
-
h(SelectValue, null, activeImportRole === 'vlm' ? '仅作为视觉模型 (VLLM)' : '对话模型(含视觉)')
|
|
1492
|
-
),
|
|
1493
|
-
h(
|
|
1494
|
-
SelectContent,
|
|
1495
|
-
null,
|
|
1496
|
-
selectedRoles.map((role) =>
|
|
1497
|
-
h(
|
|
1498
|
-
SelectItem,
|
|
1499
|
-
{ key: role, value: role },
|
|
1500
|
-
role === 'vlm' ? '仅作为视觉模型 (VLLM)' : '对话模型(含视觉)'
|
|
1501
|
-
)
|
|
1502
|
-
)
|
|
1503
|
-
)
|
|
1504
|
-
)
|
|
1505
|
-
: null,
|
|
1506
|
-
h(
|
|
1507
|
-
Button,
|
|
1508
|
-
{
|
|
1509
|
-
size: 'sm',
|
|
1510
|
-
disabled: m.importing === true || typeof m.onCopy !== 'function',
|
|
1511
|
-
onClick: typeof m.onCopy === 'function' ? m.onCopy : undefined
|
|
1512
|
-
},
|
|
1513
|
-
m.importing === true ? '复制中…' : '复制到 WeKnora'
|
|
1514
|
-
)
|
|
1515
|
-
)
|
|
1516
1793
|
: null
|
|
1517
1794
|
)
|
|
1518
1795
|
)
|
|
@@ -1521,7 +1798,7 @@ export function modelCopyView(m = {}) {
|
|
|
1521
1798
|
)
|
|
1522
1799
|
}
|
|
1523
1800
|
|
|
1524
|
-
function ModelCopyPanel() {
|
|
1801
|
+
function ModelCopyPanel({ layout = 'card', autoLoad = false, onClose } = {}) {
|
|
1525
1802
|
const [open, setOpen] = useState(true)
|
|
1526
1803
|
const [state, setState] = useState('idle')
|
|
1527
1804
|
const [models, setModels] = useState([])
|
|
@@ -1534,6 +1811,7 @@ function ModelCopyPanel() {
|
|
|
1534
1811
|
const [importing, setImporting] = useState(false)
|
|
1535
1812
|
const [copyError, setCopyError] = useState('')
|
|
1536
1813
|
const [result, setResult] = useState(null)
|
|
1814
|
+
const autoLoadRef = useRef(false)
|
|
1537
1815
|
|
|
1538
1816
|
const load = useCallback(async () => {
|
|
1539
1817
|
setState('loading')
|
|
@@ -1553,6 +1831,13 @@ function ModelCopyPanel() {
|
|
|
1553
1831
|
}
|
|
1554
1832
|
}, [])
|
|
1555
1833
|
|
|
1834
|
+
// 工作台在宽屏首次出现或用户切到模型分段时懒加载一次;不阻塞日志首屏。
|
|
1835
|
+
useEffect(() => {
|
|
1836
|
+
if (!autoLoad || !open || autoLoadRef.current || state !== 'idle') return
|
|
1837
|
+
autoLoadRef.current = true
|
|
1838
|
+
load()
|
|
1839
|
+
}, [autoLoad, open, state, load])
|
|
1840
|
+
|
|
1556
1841
|
const copy = useCallback(async () => {
|
|
1557
1842
|
const selected = models.find((item) => modelSelectionKey(item) === selectedKey)
|
|
1558
1843
|
if (!selected) return
|
|
@@ -1577,6 +1862,7 @@ function ModelCopyPanel() {
|
|
|
1577
1862
|
|
|
1578
1863
|
return modelCopyView({
|
|
1579
1864
|
open,
|
|
1865
|
+
layout,
|
|
1580
1866
|
state,
|
|
1581
1867
|
models,
|
|
1582
1868
|
error,
|
|
@@ -1588,6 +1874,7 @@ function ModelCopyPanel() {
|
|
|
1588
1874
|
importing,
|
|
1589
1875
|
copyError,
|
|
1590
1876
|
result,
|
|
1877
|
+
onClose,
|
|
1591
1878
|
onToggle: () => setOpen((value) => !value),
|
|
1592
1879
|
onLoad: load,
|
|
1593
1880
|
onSelect: (key) => {
|
|
@@ -2735,6 +3022,13 @@ function RuleLevelSelect({ value, options, disabled, onChange }) {
|
|
|
2735
3022
|
)
|
|
2736
3023
|
}
|
|
2737
3024
|
|
|
3025
|
+
/** 候选匹配只看「名称 · ID」文本,大小写无关;空查询不过滤。 */
|
|
3026
|
+
export function pickerMatches(label, query) {
|
|
3027
|
+
const needle = String(query ?? '').trim().toLowerCase()
|
|
3028
|
+
if (needle === '') return true
|
|
3029
|
+
return String(label ?? '').toLowerCase().includes(needle)
|
|
3030
|
+
}
|
|
3031
|
+
|
|
2738
3032
|
/**
|
|
2739
3033
|
* 可搜索 + 可手输的候选选择器:Combobox 提供真实下拉列表,输入框本身负责手输兜底。
|
|
2740
3034
|
* 目录为空时仍可输入任意 ID,留空表示不限;已选旧值不在目录中时照常回显。
|
|
@@ -2757,6 +3051,7 @@ function RulePicker({ id, value, options, placeholder, emptyLabel, disabled, onC
|
|
|
2757
3051
|
value: items.includes(value) ? value : null,
|
|
2758
3052
|
inputValue: value ?? '',
|
|
2759
3053
|
disabled,
|
|
3054
|
+
filter: (item, query) => pickerMatches(labels.get(String(item)) ?? String(item), query),
|
|
2760
3055
|
onInputValueChange: (next) => onChange(typeof next === 'string' ? next : ''),
|
|
2761
3056
|
onValueChange: (next) => onChange(next === null || next === undefined ? '' : String(next))
|
|
2762
3057
|
},
|
|
@@ -3409,8 +3704,217 @@ function Kpi({ label, value, tone }) {
|
|
|
3409
3704
|
)
|
|
3410
3705
|
}
|
|
3411
3706
|
|
|
3707
|
+
function EngineSideCard({ title, children }) {
|
|
3708
|
+
return h(
|
|
3709
|
+
'section',
|
|
3710
|
+
{ className: 'kb-engine-side-card' },
|
|
3711
|
+
h('h3', { className: 'kb-engine-side-title' }, title),
|
|
3712
|
+
h('div', { className: 'kb-side-rows' }, children)
|
|
3713
|
+
)
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3716
|
+
function EngineSideRow({ label, children }) {
|
|
3717
|
+
return h(
|
|
3718
|
+
'div',
|
|
3719
|
+
{ className: 'kb-side-row' },
|
|
3720
|
+
h('span', { className: 'kb-side-label' }, label),
|
|
3721
|
+
h('span', { className: 'kb-side-value' }, children)
|
|
3722
|
+
)
|
|
3723
|
+
}
|
|
3724
|
+
|
|
3725
|
+
function OcrDepBadge({ name, found }) {
|
|
3726
|
+
const state = found === true ? 'ok' : found === false ? 'missing' : 'unknown'
|
|
3727
|
+
return h(
|
|
3728
|
+
'span',
|
|
3729
|
+
{ className: 'kb-ocr-dep', 'data-state': state },
|
|
3730
|
+
`${name} ${found === true ? '✓' : found === false ? '✗' : '?'}`
|
|
3731
|
+
)
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
function OcrHealthCard({ status }) {
|
|
3735
|
+
const ocr = ocrSummary(status)
|
|
3736
|
+
const tone = ocr.ready === true ? 'success' : ocr.ready === false ? 'danger' : 'muted'
|
|
3737
|
+
return h(
|
|
3738
|
+
EngineSideCard,
|
|
3739
|
+
{ title: '解析与 OCR 状态' },
|
|
3740
|
+
h(
|
|
3741
|
+
EngineSideRow,
|
|
3742
|
+
{ label: 'OCR 状态' },
|
|
3743
|
+
h(
|
|
3744
|
+
'span',
|
|
3745
|
+
{ className: 'kb-ocr-state', 'data-state': ocr.ready === true ? 'ok' : ocr.ready === false ? 'missing' : 'unknown' },
|
|
3746
|
+
h(StatusDot, { tone }),
|
|
3747
|
+
ocr.available ? ocr.label : '由引擎自动检测'
|
|
3748
|
+
)
|
|
3749
|
+
),
|
|
3750
|
+
ocr.available
|
|
3751
|
+
? [
|
|
3752
|
+
h('div', { key: 'engine', className: 'kb-side-row' }, h('span', { className: 'kb-side-label' }, '解析引擎'), h('span', { className: 'kb-side-value' }, ocr.engine)),
|
|
3753
|
+
h(
|
|
3754
|
+
'div',
|
|
3755
|
+
{ key: 'deps', className: 'kb-side-row' },
|
|
3756
|
+
h('span', { className: 'kb-side-label' }, '依赖检查'),
|
|
3757
|
+
h(
|
|
3758
|
+
'span',
|
|
3759
|
+
{ className: 'kb-side-value kb-ocr-deps' },
|
|
3760
|
+
h(OcrDepBadge, { name: 'tesseract', found: ocr.tesseractFound }),
|
|
3761
|
+
h(OcrDepBadge, { name: 'pdftoppm', found: ocr.pdftoppmFound })
|
|
3762
|
+
)
|
|
3763
|
+
),
|
|
3764
|
+
h(
|
|
3765
|
+
'div',
|
|
3766
|
+
{ key: 'tessdata', className: 'kb-side-row' },
|
|
3767
|
+
h('span', { className: 'kb-side-label' }, '词库目录'),
|
|
3768
|
+
h(
|
|
3769
|
+
'span',
|
|
3770
|
+
{ className: 'kb-side-value' },
|
|
3771
|
+
ocr.tessdataDir !== ''
|
|
3772
|
+
? h(CodeValue, { value: ocr.tessdataDir, copy: '复制词库路径' })
|
|
3773
|
+
: h('span', { className: 'kb-muted-text' }, '由引擎自动检测')
|
|
3774
|
+
)
|
|
3775
|
+
)
|
|
3776
|
+
]
|
|
3777
|
+
: h('p', { className: 'kb-side-note' }, '当前引擎未返回 OCR 体检字段,解析能力由引擎自动检测。')
|
|
3778
|
+
)
|
|
3779
|
+
}
|
|
3780
|
+
|
|
3781
|
+
function LogConsole({
|
|
3782
|
+
logs,
|
|
3783
|
+
fallback,
|
|
3784
|
+
query,
|
|
3785
|
+
warningsOnly,
|
|
3786
|
+
wrap,
|
|
3787
|
+
logRef,
|
|
3788
|
+
onQuery,
|
|
3789
|
+
onWarningsOnly,
|
|
3790
|
+
onWrap,
|
|
3791
|
+
onJump
|
|
3792
|
+
}) {
|
|
3793
|
+
const logLines = filterLogs(logs, { query, warningsOnly })
|
|
3794
|
+
const logsText = logs.join('\n')
|
|
3795
|
+
const filterValue = warningsOnly ? 'warn' : 'all'
|
|
3796
|
+
return h(
|
|
3797
|
+
'section',
|
|
3798
|
+
{ className: 'kb-engine-panel kb-engine-log-panel' },
|
|
3799
|
+
h(
|
|
3800
|
+
'div',
|
|
3801
|
+
{ className: 'kb-engine-panel-head' },
|
|
3802
|
+
h(
|
|
3803
|
+
'div',
|
|
3804
|
+
{ className: 'kb-engine-panel-title' },
|
|
3805
|
+
h('span', null, '运行日志'),
|
|
3806
|
+
h(Badge, { variant: 'outline', className: 'kb-count' }, String(logs.length))
|
|
3807
|
+
),
|
|
3808
|
+
h(
|
|
3809
|
+
'div',
|
|
3810
|
+
{ className: 'kb-engine-log-tools' },
|
|
3811
|
+
h(
|
|
3812
|
+
ToggleGroup,
|
|
3813
|
+
{
|
|
3814
|
+
value: [filterValue],
|
|
3815
|
+
variant: 'outline',
|
|
3816
|
+
size: 'sm',
|
|
3817
|
+
spacing: 0,
|
|
3818
|
+
'aria-label': '日志筛选',
|
|
3819
|
+
onValueChange: (next) => {
|
|
3820
|
+
const picked = next.find((value) => value !== filterValue)
|
|
3821
|
+
if (picked === 'warn' || picked === 'all') onWarningsOnly(picked === 'warn')
|
|
3822
|
+
}
|
|
3823
|
+
},
|
|
3824
|
+
h(ToggleGroupItem, { value: 'all' }, '全部'),
|
|
3825
|
+
h(ToggleGroupItem, { value: 'warn' }, '仅警告与错误')
|
|
3826
|
+
),
|
|
3827
|
+
h(SearchBox, {
|
|
3828
|
+
className: 'kb-log-search',
|
|
3829
|
+
value: query,
|
|
3830
|
+
onChange: onQuery,
|
|
3831
|
+
placeholder: '过滤日志关键字…',
|
|
3832
|
+
clearLabel: '清除日志过滤'
|
|
3833
|
+
}),
|
|
3834
|
+
h(
|
|
3835
|
+
Button,
|
|
3836
|
+
{
|
|
3837
|
+
variant: 'ghost',
|
|
3838
|
+
size: 'sm',
|
|
3839
|
+
'aria-pressed': wrap,
|
|
3840
|
+
onClick: onWrap
|
|
3841
|
+
},
|
|
3842
|
+
h(UiIcon, { name: 'wrap-text' }),
|
|
3843
|
+
'自动换行'
|
|
3844
|
+
),
|
|
3845
|
+
h(
|
|
3846
|
+
Button,
|
|
3847
|
+
{ variant: 'ghost', size: 'sm', onClick: onJump },
|
|
3848
|
+
h(UiIcon, { name: 'arrow-down' }),
|
|
3849
|
+
'跳至底部'
|
|
3850
|
+
),
|
|
3851
|
+
h(CopyButton, { value: logsText, label: '复制日志' })
|
|
3852
|
+
)
|
|
3853
|
+
),
|
|
3854
|
+
logs.length > 0
|
|
3855
|
+
? h(
|
|
3856
|
+
'div',
|
|
3857
|
+
{
|
|
3858
|
+
ref: logRef,
|
|
3859
|
+
className: 'kb-log-console',
|
|
3860
|
+
role: 'log',
|
|
3861
|
+
'aria-label': '运行日志内容',
|
|
3862
|
+
'data-wrap': wrap ? 'true' : 'false'
|
|
3863
|
+
},
|
|
3864
|
+
logLines.length === 0
|
|
3865
|
+
? h('p', { className: 'kb-log-empty' }, '没有匹配的日志行。')
|
|
3866
|
+
: logLines.map((line, index) =>
|
|
3867
|
+
h(
|
|
3868
|
+
'div',
|
|
3869
|
+
{ key: `${index}-${line.length}`, className: 'kb-log-line', 'data-tone': logLineTone(line) },
|
|
3870
|
+
line
|
|
3871
|
+
)
|
|
3872
|
+
)
|
|
3873
|
+
)
|
|
3874
|
+
: h('div', { className: 'kb-log-console kb-log-console-empty' }, h('p', { className: 'kb-log-empty' }, fallback)),
|
|
3875
|
+
h(
|
|
3876
|
+
'div',
|
|
3877
|
+
{ className: 'kb-log-footer' },
|
|
3878
|
+
h('span', null, `显示 ${logs.length > 0 ? logLines.length : 0} / ${logs.length} 行`),
|
|
3879
|
+
logs.length > 0 ? h('span', { className: 'kb-log-footer-hint' }, 'WARN / ERROR 已着色') : null
|
|
3880
|
+
)
|
|
3881
|
+
)
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
/** 左栏档案卡暂不进入 UI;组件保留,便于以后恢复。 */
|
|
3885
|
+
const SHOW_ENGINE_RAIL = false
|
|
3886
|
+
|
|
3887
|
+
/** 低频模型复制:Dialog 覆盖层,关闭后日志 DOM/滚动位置完全不变。 */
|
|
3888
|
+
export function ModelCopyDialog({ open = false, onOpenChange, children }) {
|
|
3889
|
+
const close = () => {
|
|
3890
|
+
if (typeof onOpenChange === 'function') onOpenChange(false)
|
|
3891
|
+
}
|
|
3892
|
+
return h(
|
|
3893
|
+
Dialog,
|
|
3894
|
+
{
|
|
3895
|
+
open: open === true,
|
|
3896
|
+
onOpenChange: (next) => {
|
|
3897
|
+
if (next !== true) close()
|
|
3898
|
+
}
|
|
3899
|
+
},
|
|
3900
|
+
h(
|
|
3901
|
+
DialogContent,
|
|
3902
|
+
{ className: 'flex flex-col kb-model-copy-dialog' },
|
|
3903
|
+
children !== undefined
|
|
3904
|
+
? children
|
|
3905
|
+
: open === true
|
|
3906
|
+
? h(ModelCopyPanel, { layout: 'workbench', autoLoad: true, onClose: close })
|
|
3907
|
+
: null
|
|
3908
|
+
)
|
|
3909
|
+
)
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3412
3912
|
export function EngineTab({ status, actions, retrying, onRetry }) {
|
|
3413
3913
|
const [wrap, setWrap] = useState(true)
|
|
3914
|
+
const [logQuery, setLogQuery] = useState('')
|
|
3915
|
+
const [warningsOnly, setWarningsOnly] = useState(false)
|
|
3916
|
+
const [modelOpen, setModelOpen] = useState(false)
|
|
3917
|
+
const logRef = useRef(null)
|
|
3414
3918
|
const busy = actions.pending !== ''
|
|
3415
3919
|
const loading = status.live === 'loading'
|
|
3416
3920
|
const broken =
|
|
@@ -3485,7 +3989,7 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
|
|
|
3485
3989
|
|
|
3486
3990
|
const detailRows = [
|
|
3487
3991
|
{ label: '运行模式', value: modeLabel(status.mode) },
|
|
3488
|
-
status.unit !== '' && {
|
|
3992
|
+
typeof status.unit === 'string' && status.unit !== '' && {
|
|
3489
3993
|
label: 'systemd Unit',
|
|
3490
3994
|
value: h(CodeValue, { value: status.unit, copy: '复制 Unit 名称' })
|
|
3491
3995
|
},
|
|
@@ -3496,103 +4000,109 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
|
|
|
3496
4000
|
value: status.baseUrl !== '' ? h(CodeValue, { value: status.baseUrl, copy: '复制地址' }) : '—'
|
|
3497
4001
|
},
|
|
3498
4002
|
broken && { label: '状态通道', value: status.liveError || '不可用' }
|
|
3499
|
-
]
|
|
4003
|
+
].filter(Boolean)
|
|
3500
4004
|
|
|
3501
|
-
const logs = status.logs
|
|
3502
|
-
const logsText = logs.join('\n')
|
|
4005
|
+
const logs = Array.isArray(status.logs) ? status.logs : []
|
|
3503
4006
|
const logFallback =
|
|
3504
4007
|
status.logLines !== undefined && status.logLines > 0
|
|
3505
4008
|
? `共 ${status.logLines} 行(status.logs 未提供,无法展示尾部)`
|
|
3506
4009
|
: '暂无引擎输出日志'
|
|
3507
4010
|
|
|
4011
|
+
const jumpToBottom = () => {
|
|
4012
|
+
const node = logRef.current
|
|
4013
|
+
if (!node) return
|
|
4014
|
+
if (typeof node.scrollTo === 'function') node.scrollTo({ top: node.scrollHeight, behavior: 'smooth' })
|
|
4015
|
+
else node.scrollTop = node.scrollHeight
|
|
4016
|
+
}
|
|
4017
|
+
|
|
3508
4018
|
return h(
|
|
3509
4019
|
'div',
|
|
3510
|
-
{ className: 'kb-
|
|
4020
|
+
{ className: 'kb-engine-workbench' },
|
|
3511
4021
|
h(
|
|
3512
|
-
|
|
3513
|
-
|
|
4022
|
+
'section',
|
|
4023
|
+
{ className: 'kb-engine-hero' },
|
|
3514
4024
|
h(
|
|
3515
|
-
|
|
3516
|
-
|
|
4025
|
+
'div',
|
|
4026
|
+
{ className: 'kb-engine-hero-bar' },
|
|
3517
4027
|
h(
|
|
3518
|
-
|
|
3519
|
-
|
|
4028
|
+
'div',
|
|
4029
|
+
{ className: 'kb-engine-identity' },
|
|
3520
4030
|
h(
|
|
3521
4031
|
'span',
|
|
3522
|
-
{ className: 'kb-
|
|
4032
|
+
{ className: 'kb-engine-state' },
|
|
3523
4033
|
h(StatusDot, { tone: stateTone }),
|
|
3524
|
-
stateLabel
|
|
3525
|
-
|
|
3526
|
-
)
|
|
4034
|
+
stateLabel
|
|
4035
|
+
),
|
|
4036
|
+
h(Badge, { variant: 'secondary' }, modeLabel(status.mode)),
|
|
4037
|
+
typeof status.version === 'string' && status.version !== ''
|
|
4038
|
+
? h(Badge, { variant: 'outline' }, status.version)
|
|
4039
|
+
: null
|
|
3527
4040
|
),
|
|
3528
|
-
h(CardAction, null, h('div', { className: 'kb-hero-actions' }, buttons))
|
|
3529
|
-
),
|
|
3530
|
-
h(
|
|
3531
|
-
CardContent,
|
|
3532
|
-
null,
|
|
3533
4041
|
h(
|
|
3534
4042
|
'div',
|
|
3535
|
-
{ className: 'kb-
|
|
3536
|
-
|
|
3537
|
-
h(Kpi, { label: '运行时长', value: formatUptime(status.uptime) }),
|
|
3538
|
-
h(Kpi, { label: '内存占用 (RSS)', value: formatBytes(status.rss) }),
|
|
3539
|
-
h(Kpi, {
|
|
3540
|
-
label: '重启次数',
|
|
3541
|
-
value: restarts ?? '—',
|
|
3542
|
-
tone: restarts !== undefined && restarts > 0 ? 'warning' : undefined
|
|
3543
|
-
})
|
|
3544
|
-
),
|
|
3545
|
-
status.lastError !== ''
|
|
3546
|
-
? h(
|
|
3547
|
-
Alert,
|
|
3548
|
-
{ variant: 'destructive', className: 'kb-hero-alert' },
|
|
3549
|
-
h(UiIcon, { name: 'alert-circle' }),
|
|
3550
|
-
h(AlertTitle, null, '最新错误'),
|
|
3551
|
-
h(AlertDescription, null, h('span', { className: 'kb-error-text' }, status.lastError)),
|
|
3552
|
-
h(AlertAction, null, h(CopyButton, { value: status.lastError, label: '复制错误信息' }))
|
|
3553
|
-
)
|
|
3554
|
-
: null
|
|
3555
|
-
)
|
|
3556
|
-
),
|
|
3557
|
-
h(
|
|
3558
|
-
Section,
|
|
3559
|
-
{ title: '运行详情' },
|
|
3560
|
-
h(Card, { size: 'sm' }, h(CardContent, null, h(Facts, { rows: detailRows })))
|
|
3561
|
-
),
|
|
3562
|
-
h(ModelCopyPanel, null),
|
|
3563
|
-
h(
|
|
3564
|
-
Section,
|
|
3565
|
-
{
|
|
3566
|
-
title: '运行日志',
|
|
3567
|
-
actions: h(
|
|
3568
|
-
'div',
|
|
3569
|
-
{ className: 'kb-card-actions' },
|
|
3570
|
-
logs.length > 0 ? h(CopyButton, { value: logsText, label: '复制日志' }) : null,
|
|
4043
|
+
{ className: 'kb-hero-actions' },
|
|
4044
|
+
buttons,
|
|
3571
4045
|
h(
|
|
3572
4046
|
Button,
|
|
3573
|
-
{
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
'aria-pressed': wrap,
|
|
3577
|
-
onClick: () => setWrap((value) => !value)
|
|
3578
|
-
},
|
|
3579
|
-
h(UiIcon, { name: 'wrap-text' }),
|
|
3580
|
-
'自动换行'
|
|
4047
|
+
{ variant: 'ghost', size: 'sm', onClick: () => setModelOpen(true) },
|
|
4048
|
+
h(UiIcon, { name: 'copy' }),
|
|
4049
|
+
'复制模型'
|
|
3581
4050
|
)
|
|
3582
4051
|
)
|
|
3583
|
-
|
|
4052
|
+
),
|
|
3584
4053
|
h(
|
|
3585
|
-
|
|
3586
|
-
{
|
|
3587
|
-
h(
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
4054
|
+
'div',
|
|
4055
|
+
{ className: 'kb-engine-kpis' },
|
|
4056
|
+
h(Kpi, { label: '健康状态', value: health, tone: healthTone }),
|
|
4057
|
+
h(Kpi, { label: '运行时长', value: formatUptime(status.uptime) }),
|
|
4058
|
+
h(Kpi, { label: '内存占用 (RSS)', value: formatBytes(status.rss) }),
|
|
4059
|
+
h(Kpi, {
|
|
4060
|
+
label: '重启次数',
|
|
4061
|
+
value: restarts ?? '—',
|
|
4062
|
+
tone: restarts !== undefined && restarts > 0 ? 'warning' : undefined
|
|
4063
|
+
})
|
|
4064
|
+
),
|
|
4065
|
+
typeof status.lastError === 'string' && status.lastError !== ''
|
|
4066
|
+
? h(
|
|
4067
|
+
Alert,
|
|
4068
|
+
{ variant: 'destructive', className: 'kb-hero-alert' },
|
|
4069
|
+
h(UiIcon, { name: 'alert-circle' }),
|
|
4070
|
+
h(AlertTitle, null, '最新错误'),
|
|
4071
|
+
h(AlertDescription, null, h('span', { className: 'kb-error-text' }, status.lastError)),
|
|
4072
|
+
h(AlertAction, null, h(CopyButton, { value: status.lastError, label: '复制错误信息' }))
|
|
4073
|
+
)
|
|
4074
|
+
: null
|
|
4075
|
+
),
|
|
4076
|
+
SHOW_ENGINE_RAIL
|
|
4077
|
+
? h(
|
|
4078
|
+
'aside',
|
|
4079
|
+
{ className: 'kb-engine-rail' },
|
|
4080
|
+
h(
|
|
4081
|
+
EngineSideCard,
|
|
4082
|
+
{ title: '运行详情' },
|
|
4083
|
+
detailRows.map((row) =>
|
|
4084
|
+
h(EngineSideRow, { key: row.label, label: row.label }, row.value)
|
|
4085
|
+
)
|
|
4086
|
+
),
|
|
4087
|
+
h(OcrHealthCard, { status })
|
|
3593
4088
|
)
|
|
3594
|
-
|
|
3595
|
-
|
|
4089
|
+
: null,
|
|
4090
|
+
h(LogConsole, {
|
|
4091
|
+
logs,
|
|
4092
|
+
fallback: logFallback,
|
|
4093
|
+
query: logQuery,
|
|
4094
|
+
warningsOnly,
|
|
4095
|
+
wrap,
|
|
4096
|
+
logRef,
|
|
4097
|
+
onQuery: setLogQuery,
|
|
4098
|
+
onWarningsOnly: setWarningsOnly,
|
|
4099
|
+
onWrap: () => setWrap((value) => !value),
|
|
4100
|
+
onJump: jumpToBottom
|
|
4101
|
+
}),
|
|
4102
|
+
h(ModelCopyDialog, {
|
|
4103
|
+
open: modelOpen,
|
|
4104
|
+
onOpenChange: (next) => setModelOpen(next === true)
|
|
4105
|
+
})
|
|
3596
4106
|
)
|
|
3597
4107
|
}
|
|
3598
4108
|
|