chatluna-plugin-kb 0.1.2 → 0.1.4

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/web/client.js CHANGED
@@ -33,6 +33,12 @@ import {
33
33
  Collapsible,
34
34
  CollapsibleContent,
35
35
  CollapsibleTrigger,
36
+ Combobox,
37
+ ComboboxContent,
38
+ ComboboxEmpty,
39
+ ComboboxInput,
40
+ ComboboxItem,
41
+ ComboboxList,
36
42
  CopyButton,
37
43
  Dialog,
38
44
  DialogContent,
@@ -321,6 +327,8 @@ export function viewStatus(snapshot) {
321
327
  port: finite(data.port),
322
328
  baseUrl: typeof data.baseUrl === 'string' ? data.baseUrl : '',
323
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() : '',
324
332
  uptime: uptimeSecondsOf(data),
325
333
  restarts: finite(data.restarts),
326
334
  rss: finite(data.rssBytes) ?? finite(data.rss) ?? finite(data.memoryBytes),
@@ -368,6 +376,74 @@ function formatHealth(health) {
368
376
  return '异常'
369
377
  }
370
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
+
371
447
  function rulesOf(snapshot) {
372
448
  const value = snapshot?.data
373
449
  if (Array.isArray(value)) return value
@@ -1149,20 +1225,105 @@ function modelSelectionKey(item) {
1149
1225
  return `${item?.providerId ?? ''}\u0000${item?.modelId ?? ''}\u0000${item?.type ?? ''}`
1150
1226
  }
1151
1227
 
1228
+ const MODEL_FILTER_LABELS = {
1229
+ chat: '对话',
1230
+ embedding: 'Embedding',
1231
+ vlm: 'VLM',
1232
+ rerank: 'ReRank'
1233
+ }
1234
+ const MODEL_GROUP_LIMIT = 5
1235
+
1236
+ const providerGroupOf = (item) => {
1237
+ const label = typeof item?.providerLabel === 'string' ? item.providerLabel.trim() : ''
1238
+ if (label !== '') return label
1239
+ const id = typeof item?.providerId === 'string' ? item.providerId.trim() : ''
1240
+ return id === '' ? '—' : id
1241
+ }
1242
+
1243
+ /**
1244
+ * 模型复制列表的搜索/类型筛选/厂商分组(纯函数,SSR 与单测共用)。
1245
+ * - 类型计数与 chips 基于完整目录,只展示有模型的类型;
1246
+ * - 每个厂商默认最多 5 行;选中项所在厂商自动展开到选中行,保证始终可见。
1247
+ * @returns {{matched: object[], counts: Record<string, number>, typeOptions: object[], activeType: string, groups: object[], empty: boolean}}
1248
+ */
1249
+ export function modelCopyReport(models, options = {}) {
1250
+ const list = Array.isArray(models) ? models.filter((item) => item !== null && typeof item === 'object') : []
1251
+ const query = typeof options.query === 'string' ? options.query.trim() : ''
1252
+ const requestedType = typeof options.type === 'string' && options.type !== '' ? options.type : 'all'
1253
+ const selectedKey = typeof options.selectedKey === 'string' ? options.selectedKey : ''
1254
+ const expanded = options.expanded !== null && typeof options.expanded === 'object' ? options.expanded : {}
1255
+ const matched =
1256
+ query === ''
1257
+ ? list
1258
+ : list.filter((item) =>
1259
+ matchesQuery(query, item.providerLabel, item.providerId, item.modelId, item.baseUrl)
1260
+ )
1261
+ // 计数基于完整目录,chips 在搜索过程中保持稳定;只展示有模型的类型。
1262
+ const counts = { all: list.length }
1263
+ for (const item of list) {
1264
+ if (MODEL_TYPE_LABELS[item.type] === undefined) continue
1265
+ counts[item.type] = (counts[item.type] ?? 0) + 1
1266
+ }
1267
+ const typeOptions = [
1268
+ { value: 'all', label: '全部', count: counts.all },
1269
+ ...MODEL_TYPE_ORDER.filter((type) => (counts[type] ?? 0) > 0).map((type) => ({
1270
+ value: type,
1271
+ label: MODEL_FILTER_LABELS[type] ?? type,
1272
+ count: counts[type]
1273
+ }))
1274
+ ]
1275
+ const activeType = requestedType === 'all' || counts[requestedType] > 0 ? requestedType : 'all'
1276
+ const typed = activeType === 'all' ? matched : matched.filter((item) => item.type === activeType)
1277
+ const groupMap = new Map()
1278
+ for (const item of typed) {
1279
+ const key = providerGroupOf(item)
1280
+ if (!groupMap.has(key)) groupMap.set(key, [])
1281
+ groupMap.get(key).push(item)
1282
+ }
1283
+ const groups = []
1284
+ for (const [key, items] of groupMap) {
1285
+ const selectedIndex = items.findIndex((item) => modelSelectionKey(item) === selectedKey)
1286
+ const isExpanded = expanded[key] === true
1287
+ const limit = isExpanded
1288
+ ? items.length
1289
+ : selectedIndex >= MODEL_GROUP_LIMIT
1290
+ ? selectedIndex + 1
1291
+ : Math.min(items.length, MODEL_GROUP_LIMIT)
1292
+ const visible = items.slice(0, limit)
1293
+ groups.push({
1294
+ key,
1295
+ label: key,
1296
+ items: visible,
1297
+ total: items.length,
1298
+ hidden: items.length - visible.length,
1299
+ expanded: isExpanded,
1300
+ hasSelected: selectedIndex >= 0
1301
+ })
1302
+ }
1303
+ return { matched, counts, typeOptions, activeType, groups, empty: typed.length === 0 }
1304
+ }
1305
+
1152
1306
  /**
1153
1307
  * 纯渲染层:所有状态与请求都在 ModelCopyPanel 里,便于 SSR 桩测试直接喂模型。
1154
1308
  * @param {{
1155
1309
  * open: boolean,
1310
+ * layout?: 'workbench'|'card',
1156
1311
  * state: 'idle'|'loading'|'ready'|'error',
1157
1312
  * models: Array<object>,
1158
1313
  * error?: string,
1159
1314
  * selectedKey?: string,
1315
+ * query?: string,
1316
+ * type?: string,
1317
+ * expanded?: object,
1160
1318
  * importing?: boolean,
1161
1319
  * copyError?: string,
1162
1320
  * result?: object|null,
1163
1321
  * onToggle?: Function,
1164
1322
  * onLoad?: Function,
1165
1323
  * onSelect?: Function,
1324
+ * onQueryChange?: Function,
1325
+ * onTypeChange?: Function,
1326
+ * onToggleGroup?: Function,
1166
1327
  * onCopy?: Function
1167
1328
  * }} m
1168
1329
  */
@@ -1170,22 +1331,24 @@ export function modelCopyView(m = {}) {
1170
1331
  const models = Array.isArray(m.models) ? m.models : []
1171
1332
  const selectedKey = typeof m.selectedKey === 'string' ? m.selectedKey : ''
1172
1333
  const selected = models.find((item) => modelSelectionKey(item) === selectedKey) ?? null
1173
- const groups = MODEL_TYPE_ORDER.map((type) => ({
1174
- type,
1175
- items: models.filter((item) => item?.type === type)
1176
- })).filter((group) => group.items.length > 0)
1334
+ const query = typeof m.query === 'string' ? m.query : ''
1335
+ const report = modelCopyReport(models, {
1336
+ query,
1337
+ type: m.type,
1338
+ expanded: m.expanded,
1339
+ selectedKey
1340
+ })
1177
1341
  const selectedRoles = selected === null ? [] : importRolesFor(selected)
1178
1342
  const activeImportRole = selectedRoles.includes(m.importRole) ? m.importRole : selected?.type
1179
1343
  const result = m.result !== null && typeof m.result === 'object' ? m.result : null
1180
- const open = m.open === true
1344
+ const workbench = m.layout === 'workbench'
1345
+ // 工作台形态常驻展开,不再有折叠交互。
1346
+ const open = workbench ? true : m.open === true
1181
1347
  const state = typeof m.state === 'string' ? m.state : 'idle'
1182
1348
  const loadLabel = state === 'loading' ? '加载中…' : state === 'ready' ? '刷新' : '加载模型列表'
1183
- return h(
1184
- Section,
1185
- { title: '模型配置' },
1186
- h(
1187
- Card,
1188
- { size: 'sm' },
1349
+ const card = h(
1350
+ Card,
1351
+ { size: 'sm', className: workbench ? 'kb-model-workbench-card' : undefined },
1189
1352
  h(
1190
1353
  CardHeader,
1191
1354
  null,
@@ -1209,22 +1372,24 @@ export function modelCopyView(m = {}) {
1209
1372
  loadLabel
1210
1373
  )
1211
1374
  : null,
1212
- h(
1213
- Button,
1214
- {
1215
- variant: 'ghost',
1216
- size: 'sm',
1217
- onClick: typeof m.onToggle === 'function' ? m.onToggle : undefined
1218
- },
1219
- open ? '收起' : '展开'
1220
- )
1375
+ workbench
1376
+ ? null
1377
+ : h(
1378
+ Button,
1379
+ {
1380
+ variant: 'ghost',
1381
+ size: 'sm',
1382
+ onClick: typeof m.onToggle === 'function' ? m.onToggle : undefined
1383
+ },
1384
+ open ? '收起' : '展开'
1385
+ )
1221
1386
  )
1222
1387
  )
1223
1388
  ),
1224
1389
  open
1225
1390
  ? h(
1226
1391
  CardContent,
1227
- null,
1392
+ { className: workbench ? 'kb-model-workbench-content' : undefined },
1228
1393
  h(
1229
1394
  'div',
1230
1395
  { className: 'kb-card-stack' },
@@ -1239,137 +1404,229 @@ export function modelCopyView(m = {}) {
1239
1404
  state === 'ready' && models.length === 0
1240
1405
  ? h('p', { className: 'kb-muted-text' }, 'ChatLuna 暂无可用于复制的知识库模型。')
1241
1406
  : null,
1242
- groups.map((group) =>
1243
- h(
1244
- 'div',
1245
- { key: group.type, className: 'kb-model-group' },
1246
- h('p', { className: 'kb-model-group-title' }, MODEL_TYPE_LABELS[group.type] ?? group.type),
1247
- h(
1248
- 'ul',
1249
- { className: 'kb-model-list' },
1250
- group.items.map((item) => {
1251
- const key = modelSelectionKey(item)
1252
- const active = key === selectedKey
1253
- const role = modelRoleLabel(item.type)
1254
- const roles = importRolesFor(item)
1255
- return h(
1256
- 'li',
1257
- { key },
1258
- h(
1259
- 'button',
1260
- {
1261
- type: 'button',
1262
- className: 'kb-model-item',
1263
- 'aria-pressed': active,
1264
- onClick: typeof m.onSelect === 'function' ? () => m.onSelect(key) : undefined
1265
- },
1266
- h(
1267
- 'span',
1268
- { className: 'kb-model-main' },
1269
- h(
1270
- 'span',
1271
- { className: 'kb-model-title' },
1272
- `${item.providerLabel || item.providerId || '—'} · ${item.modelId || '—'}`,
1273
- h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, role),
1274
- item.supportsVision === true ? h(Badge, { variant: 'secondary' }, '支持视觉') : null,
1275
- item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null
1276
- ),
1277
- h(
1278
- 'span',
1279
- { className: 'kb-model-url', title: item.baseUrl || '' },
1280
- shortenUrl(item.baseUrl)
1281
- ),
1282
- item.protocolHint
1283
- ? h(
1284
- 'span',
1285
- { className: 'kb-muted-text' },
1286
- '该路由使用非 OpenAI 原生协议,复制后可能需要在 WeKnora 中调整接口类型。'
1287
- )
1288
- : null
1289
-
1290
- ),
1291
- active
1292
- ? h('span', { className: 'kb-model-check', 'aria-hidden': true }, h(UiIcon, { name: 'check' }))
1293
- : null
1294
- )
1295
- )
1407
+ state === 'ready' && models.length > 0
1408
+ ? h(
1409
+ 'div',
1410
+ { className: 'kb-model-toolbar' },
1411
+ h(SearchBox, {
1412
+ value: query,
1413
+ onChange: (value) =>
1414
+ typeof m.onQueryChange === 'function' ? m.onQueryChange(value) : undefined,
1415
+ placeholder: '搜索厂商、模型或 baseUrl…',
1416
+ clearLabel: '清除搜索'
1417
+ }),
1418
+ h(FilterChips, {
1419
+ options: report.typeOptions,
1420
+ value: report.activeType,
1421
+ onChange: (value) =>
1422
+ typeof m.onTypeChange === 'function' ? m.onTypeChange(value) : undefined,
1423
+ label: '按模型类型筛选'
1296
1424
  })
1297
1425
  )
1298
- )
1299
- ),
1300
- m.copyError ? errorAlert(m.copyError, '复制失败') : null,
1301
- result !== null
1426
+ : null,
1427
+ state === 'ready' && models.length > 0 && report.empty
1428
+ ? h('p', { className: 'kb-muted-text' }, '没有匹配的模型;调整搜索关键词或类型筛选。')
1429
+ : null,
1430
+ state === 'ready' && report.groups.length > 0
1302
1431
  ? h(
1303
- Alert,
1304
- { className: 'kb-alert-success' },
1305
- h(UiIcon, { name: 'check' }),
1306
- h(AlertTitle, null, '已复制到 WeKnora'),
1307
- h(
1308
- AlertDescription,
1309
- null,
1310
- `模型 id ${result.modelId ?? '—'}${result.dimension ? ` · 维度 ${result.dimension}` : ''}`
1432
+ 'div',
1433
+ { className: 'kb-model-scroll' },
1434
+ report.groups.map((group) =>
1435
+ h(
1436
+ 'div',
1437
+ { key: group.key, className: 'kb-model-group' },
1438
+ h(
1439
+ 'div',
1440
+ { className: 'kb-model-group-head' },
1441
+ h('p', { className: 'kb-model-group-title' }, group.label),
1442
+ h(Badge, { variant: 'outline' }, String(group.total))
1443
+ ),
1444
+ h(
1445
+ 'ul',
1446
+ { className: 'kb-model-list' },
1447
+ group.items.map((item) => {
1448
+ const key = modelSelectionKey(item)
1449
+ const active = key === selectedKey
1450
+ const role = modelRoleLabel(item.type)
1451
+ return h(
1452
+ 'li',
1453
+ { key },
1454
+ h(
1455
+ 'button',
1456
+ {
1457
+ type: 'button',
1458
+ className: 'kb-model-item',
1459
+ 'aria-pressed': active,
1460
+ onClick: typeof m.onSelect === 'function' ? () => m.onSelect(key) : undefined
1461
+ },
1462
+ h(
1463
+ 'span',
1464
+ { className: 'kb-model-main' },
1465
+ h(
1466
+ 'span',
1467
+ { className: 'kb-model-title' },
1468
+ `${item.providerLabel || item.providerId || '—'} · ${item.modelId || '—'}`,
1469
+ h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, role),
1470
+ item.supportsVision === true
1471
+ ? h(Badge, { variant: 'secondary' }, '支持视觉')
1472
+ : null,
1473
+ item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null
1474
+ ),
1475
+ h(
1476
+ 'span',
1477
+ { className: 'kb-model-url', title: item.baseUrl || '' },
1478
+ shortenUrl(item.baseUrl)
1479
+ ),
1480
+ item.protocolHint
1481
+ ? h(
1482
+ 'span',
1483
+ { className: 'kb-muted-text' },
1484
+ '该路由使用非 OpenAI 原生协议,复制后可能需要在 WeKnora 中调整接口类型。'
1485
+ )
1486
+ : null
1487
+ ),
1488
+ active
1489
+ ? h(
1490
+ 'span',
1491
+ { className: 'kb-model-check', 'aria-hidden': true },
1492
+ h(UiIcon, { name: 'check' })
1493
+ )
1494
+ : null
1495
+ )
1496
+ )
1497
+ })
1498
+ ),
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'
1508
+ ? m.onToggleGroup(group.key)
1509
+ : undefined
1510
+ },
1511
+ `显示更多 ${group.hidden}`
1512
+ )
1513
+ : null,
1514
+ group.expanded && group.total > MODEL_GROUP_LIMIT
1515
+ ? h(
1516
+ Button,
1517
+ {
1518
+ variant: 'ghost',
1519
+ size: 'sm',
1520
+ className: 'kb-model-more',
1521
+ onClick: () =>
1522
+ typeof m.onToggleGroup === 'function'
1523
+ ? m.onToggleGroup(group.key)
1524
+ : undefined
1525
+ },
1526
+ '收起'
1527
+ )
1528
+ : null
1529
+ )
1311
1530
  )
1312
1531
  )
1313
1532
  : null,
1314
- selected !== null
1315
- ? h(
1316
- 'div',
1317
- { className: 'kb-model-footer' },
1318
- selectedRoles.length > 1
1319
- ? h(
1320
- Select,
1321
- {
1322
- value: activeImportRole,
1323
- disabled: m.importing === true,
1324
- onValueChange: (next) =>
1325
- typeof m.onImportRole === 'function' ? m.onImportRole(String(next)) : undefined
1326
- },
1327
- h(
1328
- SelectTrigger,
1329
- { id: 'kb-model-import-role', className: 'kb-rule-select', 'aria-label': '导入为' },
1330
- h(SelectValue, null, activeImportRole === 'vlm' ? '仅作为视觉模型 (VLLM)' : '对话模型(含视觉)')
1331
- ),
1332
- h(
1333
- SelectContent,
1334
- null,
1335
- selectedRoles.map((role) =>
1533
+ h(
1534
+ 'div',
1535
+ {
1536
+ className: workbench
1537
+ ? 'kb-model-actionbar kb-model-actionbar-sticky'
1538
+ : 'kb-model-actionbar'
1539
+ },
1540
+ m.copyError ? errorAlert(m.copyError, '复制失败') : null,
1541
+ result !== null
1542
+ ? h(
1543
+ Alert,
1544
+ { className: 'kb-alert-success' },
1545
+ h(UiIcon, { name: 'check' }),
1546
+ h(AlertTitle, null, '已复制到 WeKnora'),
1547
+ h(
1548
+ AlertDescription,
1549
+ null,
1550
+ `模型 id ${result.modelId ?? '—'}${result.dimension ? ` · 维度 ${result.dimension}` : ''}`
1551
+ )
1552
+ )
1553
+ : null,
1554
+ selected !== null
1555
+ ? h(
1556
+ 'div',
1557
+ { className: 'kb-model-footer' },
1558
+ selectedRoles.length > 1
1559
+ ? h(
1560
+ Select,
1561
+ {
1562
+ value: activeImportRole,
1563
+ disabled: m.importing === true,
1564
+ onValueChange: (next) =>
1565
+ typeof m.onImportRole === 'function' ? m.onImportRole(String(next)) : undefined
1566
+ },
1567
+ h(
1568
+ SelectTrigger,
1569
+ { id: 'kb-model-import-role', className: 'kb-rule-select', 'aria-label': '导入为' },
1336
1570
  h(
1337
- SelectItem,
1338
- { key: role, value: role },
1339
- role === 'vlm' ? '仅作为视觉模型 (VLLM)' : '对话模型(含视觉)'
1571
+ SelectValue,
1572
+ null,
1573
+ activeImportRole === 'vlm' ? '仅作为视觉模型 (VLLM)' : '对话模型(含视觉)'
1574
+ )
1575
+ ),
1576
+ h(
1577
+ SelectContent,
1578
+ null,
1579
+ selectedRoles.map((role) =>
1580
+ h(
1581
+ SelectItem,
1582
+ { key: role, value: role },
1583
+ role === 'vlm' ? '仅作为视觉模型 (VLLM)' : '对话模型(含视觉)'
1584
+ )
1340
1585
  )
1341
1586
  )
1342
1587
  )
1343
- )
1344
- : null,
1345
- h(
1346
- Button,
1347
- {
1348
- size: 'sm',
1349
- disabled: m.importing === true || typeof m.onCopy !== 'function',
1350
- onClick: typeof m.onCopy === 'function' ? m.onCopy : undefined
1351
- },
1352
- m.importing === true ? '复制中…' : '复制到 WeKnora'
1588
+ : null,
1589
+ h(
1590
+ Button,
1591
+ {
1592
+ size: 'sm',
1593
+ disabled: m.importing === true || typeof m.onCopy !== 'function',
1594
+ onClick: typeof m.onCopy === 'function' ? m.onCopy : undefined
1595
+ },
1596
+ m.importing === true ? '复制中…' : '复制到 WeKnora'
1597
+ )
1353
1598
  )
1354
- )
1355
- : null
1599
+ : workbench
1600
+ ? h(
1601
+ 'p',
1602
+ { className: 'kb-model-empty-hint' },
1603
+ '点击上方任意模型即可一键复制到知识库(不暴露 API Key)。'
1604
+ )
1605
+ : null
1606
+ )
1356
1607
  )
1357
1608
  )
1358
1609
  : null
1359
- )
1360
1610
  )
1611
+ return workbench
1612
+ ? h('section', { className: 'kb-model-workbench' }, card)
1613
+ : h(Section, { title: '模型配置' }, card)
1361
1614
  }
1362
1615
 
1363
- function ModelCopyPanel() {
1616
+ function ModelCopyPanel({ layout = 'card', autoLoad = false } = {}) {
1364
1617
  const [open, setOpen] = useState(true)
1365
1618
  const [state, setState] = useState('idle')
1366
1619
  const [models, setModels] = useState([])
1367
1620
  const [error, setError] = useState('')
1368
1621
  const [selectedKey, setSelectedKey] = useState('')
1369
1622
  const [importRole, setImportRole] = useState('')
1623
+ const [query, setQuery] = useState('')
1624
+ const [modelType, setModelType] = useState('all')
1625
+ const [expanded, setExpanded] = useState({})
1370
1626
  const [importing, setImporting] = useState(false)
1371
1627
  const [copyError, setCopyError] = useState('')
1372
1628
  const [result, setResult] = useState(null)
1629
+ const autoLoadRef = useRef(false)
1373
1630
 
1374
1631
  const load = useCallback(async () => {
1375
1632
  setState('loading')
@@ -1379,6 +1636,9 @@ function ModelCopyPanel() {
1379
1636
  const list = Array.isArray(response?.models) ? response.models : []
1380
1637
  setModels(list)
1381
1638
  setSelectedKey('')
1639
+ setQuery('')
1640
+ setModelType('all')
1641
+ setExpanded({})
1382
1642
  setState('ready')
1383
1643
  } catch (err) {
1384
1644
  setError(apiErrorMessage(err))
@@ -1386,6 +1646,13 @@ function ModelCopyPanel() {
1386
1646
  }
1387
1647
  }, [])
1388
1648
 
1649
+ // 工作台在宽屏首次出现或用户切到模型分段时懒加载一次;不阻塞日志首屏。
1650
+ useEffect(() => {
1651
+ if (!autoLoad || autoLoadRef.current || state !== 'idle') return
1652
+ autoLoadRef.current = true
1653
+ load()
1654
+ }, [autoLoad, state, load])
1655
+
1389
1656
  const copy = useCallback(async () => {
1390
1657
  const selected = models.find((item) => modelSelectionKey(item) === selectedKey)
1391
1658
  if (!selected) return
@@ -1409,11 +1676,15 @@ function ModelCopyPanel() {
1409
1676
  }, [models, selectedKey, importRole])
1410
1677
 
1411
1678
  return modelCopyView({
1412
- open,
1679
+ open: layout === 'workbench' ? true : open,
1680
+ layout,
1413
1681
  state,
1414
1682
  models,
1415
1683
  error,
1416
1684
  selectedKey,
1685
+ query,
1686
+ type: modelType,
1687
+ expanded,
1417
1688
  importRole,
1418
1689
  importing,
1419
1690
  copyError,
@@ -1426,6 +1697,10 @@ function ModelCopyPanel() {
1426
1697
  setCopyError('')
1427
1698
  setResult(null)
1428
1699
  },
1700
+ onQueryChange: (value) => setQuery(value),
1701
+ onTypeChange: (value) => setModelType(value === '' ? 'all' : value),
1702
+ onToggleGroup: (key) =>
1703
+ setExpanded((current) => ({ ...current, [key]: current[key] !== true })),
1429
1704
  onCopy: copy
1430
1705
  })
1431
1706
  }
@@ -2561,38 +2836,58 @@ function RuleLevelSelect({ value, options, disabled, onChange }) {
2561
2836
  )
2562
2837
  }
2563
2838
 
2839
+ /** 候选匹配只看「名称 · ID」文本,大小写无关;空查询不过滤。 */
2840
+ export function pickerMatches(label, query) {
2841
+ const needle = String(query ?? '').trim().toLowerCase()
2842
+ if (needle === '') return true
2843
+ return String(label ?? '').toLowerCase().includes(needle)
2844
+ }
2845
+
2564
2846
  /**
2565
- * 可搜索 + 可手输:ui-kit Input 加原生 datalist(value=ID,label 带名称)。
2566
- * 目录为空时仍可输入任意 ID,留空表示不限。
2847
+ * 可搜索 + 可手输的候选选择器:Combobox 提供真实下拉列表,输入框本身负责手输兜底。
2848
+ * 目录为空时仍可输入任意 ID,留空表示不限;已选旧值不在目录中时照常回显。
2567
2849
  */
2568
- function RulePicker({ id, value, options, placeholder, disabled, onChange }) {
2569
- const listId = `${id}-options`
2850
+ function RulePicker({ id, value, options, placeholder, emptyLabel, disabled, onChange }) {
2851
+ const items = []
2852
+ const labels = new Map()
2853
+ for (const item of Array.isArray(options) ? options : []) {
2854
+ const raw = String(item.id)
2855
+ if (labels.has(raw)) continue
2856
+ items.push(raw)
2857
+ const name = typeof item.name === 'string' ? item.name.trim() : ''
2858
+ labels.set(raw, name === '' ? raw : `${name} · ${raw}`)
2859
+ }
2570
2860
  return h(
2571
- 'div',
2572
- { className: 'kb-rule-picker' },
2573
- h(Input, {
2861
+ Combobox,
2862
+ {
2863
+ items,
2864
+ // 只有命中目录的值才算选中;手输的任意 ID 依靠 inputValue 回显。
2865
+ value: items.includes(value) ? value : null,
2866
+ inputValue: value ?? '',
2867
+ disabled,
2868
+ filter: (item, query) => pickerMatches(labels.get(String(item)) ?? String(item), query),
2869
+ onInputValueChange: (next) => onChange(typeof next === 'string' ? next : ''),
2870
+ onValueChange: (next) => onChange(next === null || next === undefined ? '' : String(next))
2871
+ },
2872
+ h(ComboboxInput, {
2574
2873
  id,
2575
- type: 'text',
2576
- value: value ?? '',
2874
+ className: 'kb-rule-picker-input',
2577
2875
  placeholder,
2578
2876
  disabled,
2579
2877
  autoComplete: 'off',
2580
- list: listId,
2581
- 'aria-label': placeholder,
2582
- onChange: (event) => onChange(event.target.value)
2878
+ 'aria-label': placeholder
2583
2879
  }),
2584
2880
  h(
2585
- 'datalist',
2586
- { id: listId },
2587
- (Array.isArray(options) ? options : []).map((item) => {
2588
- const raw = String(item.id)
2589
- const name = typeof item.name === 'string' ? item.name.trim() : ''
2590
- return h('option', {
2591
- key: `${item.platform ?? ''}\u0000${raw}`,
2592
- value: raw,
2593
- label: name === '' ? raw : `${name} · ${raw}`
2594
- })
2595
- })
2881
+ ComboboxContent,
2882
+ null,
2883
+ h(ComboboxEmpty, null, emptyLabel ?? '无匹配,可直接输入 ID'),
2884
+ h(ComboboxList, null, (raw) =>
2885
+ h(
2886
+ ComboboxItem,
2887
+ { key: raw, value: raw },
2888
+ h('span', { className: 'kb-rule-picker-name' }, labels.get(String(raw)) ?? String(raw))
2889
+ )
2890
+ )
2596
2891
  )
2597
2892
  )
2598
2893
  }
@@ -2897,6 +3192,7 @@ export function RuleEditor({
2897
3192
  value: draft.guildId ?? '',
2898
3193
  options: guilds,
2899
3194
  placeholder: '不限;搜索群名称或直接输入群 ID',
3195
+ emptyLabel: '引擎离线或暂无群,可直接输入群 ID',
2900
3196
  disabled: saving,
2901
3197
  onChange: change('guildId')
2902
3198
  })
@@ -2910,6 +3206,7 @@ export function RuleEditor({
2910
3206
  value: draft.userId ?? '',
2911
3207
  options: users,
2912
3208
  placeholder: '不限;搜索昵称或直接输入用户 ID',
3209
+ emptyLabel: '引擎离线或暂无用户,可直接输入用户 ID',
2913
3210
  disabled: saving,
2914
3211
  onChange: change('userId')
2915
3212
  })
@@ -3221,8 +3518,196 @@ function Kpi({ label, value, tone }) {
3221
3518
  )
3222
3519
  }
3223
3520
 
3521
+ function EngineSideCard({ title, children }) {
3522
+ return h(
3523
+ 'section',
3524
+ { className: 'kb-engine-side-card' },
3525
+ h('h3', { className: 'kb-engine-side-title' }, title),
3526
+ h('div', { className: 'kb-side-rows' }, children)
3527
+ )
3528
+ }
3529
+
3530
+ function EngineSideRow({ label, children }) {
3531
+ return h(
3532
+ 'div',
3533
+ { className: 'kb-side-row' },
3534
+ h('span', { className: 'kb-side-label' }, label),
3535
+ h('span', { className: 'kb-side-value' }, children)
3536
+ )
3537
+ }
3538
+
3539
+ function OcrDepBadge({ name, found }) {
3540
+ const state = found === true ? 'ok' : found === false ? 'missing' : 'unknown'
3541
+ return h(
3542
+ 'span',
3543
+ { className: 'kb-ocr-dep', 'data-state': state },
3544
+ `${name} ${found === true ? '✓' : found === false ? '✗' : '?'}`
3545
+ )
3546
+ }
3547
+
3548
+ function OcrHealthCard({ status }) {
3549
+ const ocr = ocrSummary(status)
3550
+ const tone = ocr.ready === true ? 'success' : ocr.ready === false ? 'danger' : 'muted'
3551
+ return h(
3552
+ EngineSideCard,
3553
+ { title: '解析与 OCR 状态' },
3554
+ h(
3555
+ EngineSideRow,
3556
+ { label: 'OCR 状态' },
3557
+ h(
3558
+ 'span',
3559
+ { className: 'kb-ocr-state', 'data-state': ocr.ready === true ? 'ok' : ocr.ready === false ? 'missing' : 'unknown' },
3560
+ h(StatusDot, { tone }),
3561
+ ocr.available ? ocr.label : '由引擎自动检测'
3562
+ )
3563
+ ),
3564
+ ocr.available
3565
+ ? [
3566
+ h('div', { key: 'engine', className: 'kb-side-row' }, h('span', { className: 'kb-side-label' }, '解析引擎'), h('span', { className: 'kb-side-value' }, ocr.engine)),
3567
+ h(
3568
+ 'div',
3569
+ { key: 'deps', className: 'kb-side-row' },
3570
+ h('span', { className: 'kb-side-label' }, '依赖检查'),
3571
+ h(
3572
+ 'span',
3573
+ { className: 'kb-side-value kb-ocr-deps' },
3574
+ h(OcrDepBadge, { name: 'tesseract', found: ocr.tesseractFound }),
3575
+ h(OcrDepBadge, { name: 'pdftoppm', found: ocr.pdftoppmFound })
3576
+ )
3577
+ ),
3578
+ h(
3579
+ 'div',
3580
+ { key: 'tessdata', className: 'kb-side-row' },
3581
+ h('span', { className: 'kb-side-label' }, '词库目录'),
3582
+ h(
3583
+ 'span',
3584
+ { className: 'kb-side-value' },
3585
+ ocr.tessdataDir !== ''
3586
+ ? h(CodeValue, { value: ocr.tessdataDir, copy: '复制词库路径' })
3587
+ : h('span', { className: 'kb-muted-text' }, '由引擎自动检测')
3588
+ )
3589
+ )
3590
+ ]
3591
+ : h('p', { className: 'kb-side-note' }, '当前引擎未返回 OCR 体检字段,解析能力由引擎自动检测。')
3592
+ )
3593
+ }
3594
+
3595
+ function LogConsole({
3596
+ logs,
3597
+ fallback,
3598
+ query,
3599
+ warningsOnly,
3600
+ wrap,
3601
+ logRef,
3602
+ onQuery,
3603
+ onWarningsOnly,
3604
+ onWrap,
3605
+ onJump
3606
+ }) {
3607
+ const logLines = filterLogs(logs, { query, warningsOnly })
3608
+ const logsText = logs.join('\n')
3609
+ const filterValue = warningsOnly ? 'warn' : 'all'
3610
+ return h(
3611
+ 'section',
3612
+ { className: 'kb-engine-panel kb-engine-log-panel' },
3613
+ h(
3614
+ 'div',
3615
+ { className: 'kb-engine-panel-head' },
3616
+ h(
3617
+ 'div',
3618
+ { className: 'kb-engine-panel-title' },
3619
+ h('span', null, '运行日志'),
3620
+ h(Badge, { variant: 'outline', className: 'kb-count' }, String(logs.length))
3621
+ ),
3622
+ h(
3623
+ 'div',
3624
+ { className: 'kb-engine-log-tools' },
3625
+ h(
3626
+ ToggleGroup,
3627
+ {
3628
+ value: [filterValue],
3629
+ variant: 'outline',
3630
+ size: 'sm',
3631
+ spacing: 0,
3632
+ 'aria-label': '日志筛选',
3633
+ onValueChange: (next) => {
3634
+ const picked = next.find((value) => value !== filterValue)
3635
+ if (picked === 'warn' || picked === 'all') onWarningsOnly(picked === 'warn')
3636
+ }
3637
+ },
3638
+ h(ToggleGroupItem, { value: 'all' }, '全部'),
3639
+ h(ToggleGroupItem, { value: 'warn' }, '仅警告与错误')
3640
+ ),
3641
+ h(SearchBox, {
3642
+ className: 'kb-log-search',
3643
+ value: query,
3644
+ onChange: onQuery,
3645
+ placeholder: '过滤日志关键字…',
3646
+ clearLabel: '清除日志过滤'
3647
+ }),
3648
+ h(
3649
+ Button,
3650
+ {
3651
+ variant: 'ghost',
3652
+ size: 'sm',
3653
+ 'aria-pressed': wrap,
3654
+ onClick: onWrap
3655
+ },
3656
+ h(UiIcon, { name: 'wrap-text' }),
3657
+ '自动换行'
3658
+ ),
3659
+ h(
3660
+ Button,
3661
+ { variant: 'ghost', size: 'sm', onClick: onJump },
3662
+ h(UiIcon, { name: 'arrow-down' }),
3663
+ '跳至底部'
3664
+ ),
3665
+ h(CopyButton, { value: logsText, label: '复制日志' })
3666
+ )
3667
+ ),
3668
+ logs.length > 0
3669
+ ? h(
3670
+ 'div',
3671
+ {
3672
+ ref: logRef,
3673
+ className: 'kb-log-console',
3674
+ role: 'log',
3675
+ 'aria-label': '运行日志内容',
3676
+ 'data-wrap': wrap ? 'true' : 'false'
3677
+ },
3678
+ logLines.length === 0
3679
+ ? h('p', { className: 'kb-log-empty' }, '没有匹配的日志行。')
3680
+ : logLines.map((line, index) =>
3681
+ h(
3682
+ 'div',
3683
+ { key: `${index}-${line.length}`, className: 'kb-log-line', 'data-tone': logLineTone(line) },
3684
+ line
3685
+ )
3686
+ )
3687
+ )
3688
+ : h('div', { className: 'kb-log-console kb-log-console-empty' }, h('p', { className: 'kb-log-empty' }, fallback)),
3689
+ h(
3690
+ 'div',
3691
+ { className: 'kb-log-footer' },
3692
+ h('span', null, `显示 ${logs.length > 0 ? logLines.length : 0} / ${logs.length} 行`),
3693
+ logs.length > 0 ? h('span', { className: 'kb-log-footer-hint' }, 'WARN / ERROR 已着色') : null
3694
+ )
3695
+ )
3696
+ }
3697
+
3698
+ const WIDE_WORKBENCH_QUERY = '(min-width: 1520px)'
3699
+
3700
+ function matchesWideWorkbench() {
3701
+ return typeof window !== 'undefined' && window.matchMedia?.(WIDE_WORKBENCH_QUERY)?.matches === true
3702
+ }
3703
+
3224
3704
  export function EngineTab({ status, actions, retrying, onRetry }) {
3225
3705
  const [wrap, setWrap] = useState(true)
3706
+ const [logQuery, setLogQuery] = useState('')
3707
+ const [warningsOnly, setWarningsOnly] = useState(false)
3708
+ const [pane, setPane] = useState(() => (matchesWideWorkbench() ? 'models' : 'logs'))
3709
+ const [wideWorkbench, setWideWorkbench] = useState(() => matchesWideWorkbench())
3710
+ const logRef = useRef(null)
3226
3711
  const busy = actions.pending !== ''
3227
3712
  const loading = status.live === 'loading'
3228
3713
  const broken =
@@ -3297,7 +3782,7 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
3297
3782
 
3298
3783
  const detailRows = [
3299
3784
  { label: '运行模式', value: modeLabel(status.mode) },
3300
- status.unit !== '' && {
3785
+ typeof status.unit === 'string' && status.unit !== '' && {
3301
3786
  label: 'systemd Unit',
3302
3787
  value: h(CodeValue, { value: status.unit, copy: '复制 Unit 名称' })
3303
3788
  },
@@ -3308,102 +3793,134 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
3308
3793
  value: status.baseUrl !== '' ? h(CodeValue, { value: status.baseUrl, copy: '复制地址' }) : '—'
3309
3794
  },
3310
3795
  broken && { label: '状态通道', value: status.liveError || '不可用' }
3311
- ]
3796
+ ].filter(Boolean)
3312
3797
 
3313
- const logs = status.logs
3314
- const logsText = logs.join('\n')
3798
+ const logs = Array.isArray(status.logs) ? status.logs : []
3315
3799
  const logFallback =
3316
3800
  status.logLines !== undefined && status.logLines > 0
3317
3801
  ? `共 ${status.logLines} 行(status.logs 未提供,无法展示尾部)`
3318
3802
  : '暂无引擎输出日志'
3319
3803
 
3804
+ useEffect(() => {
3805
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return undefined
3806
+ const query = window.matchMedia(WIDE_WORKBENCH_QUERY)
3807
+ const apply = () => setWideWorkbench(query.matches === true)
3808
+ apply()
3809
+ query.addEventListener?.('change', apply)
3810
+ return () => query.removeEventListener?.('change', apply)
3811
+ }, [])
3812
+
3813
+ const jumpToBottom = () => {
3814
+ const node = logRef.current
3815
+ if (!node) return
3816
+ if (typeof node.scrollTo === 'function') node.scrollTo({ top: node.scrollHeight, behavior: 'smooth' })
3817
+ else node.scrollTop = node.scrollHeight
3818
+ }
3819
+
3320
3820
  return h(
3321
3821
  'div',
3322
- { className: 'kb-page-stack' },
3822
+ { className: 'kb-engine-workbench', 'data-pane': pane },
3323
3823
  h(
3324
- Card,
3325
- null,
3824
+ 'section',
3825
+ { className: 'kb-engine-hero' },
3326
3826
  h(
3327
- CardHeader,
3328
- null,
3827
+ 'div',
3828
+ { className: 'kb-engine-hero-bar' },
3329
3829
  h(
3330
- CardTitle,
3331
- null,
3830
+ 'div',
3831
+ { className: 'kb-engine-identity' },
3332
3832
  h(
3333
3833
  'span',
3334
- { className: 'kb-title-with-dot' },
3834
+ { className: 'kb-engine-state' },
3335
3835
  h(StatusDot, { tone: stateTone }),
3336
- stateLabel,
3337
- h(Badge, { variant: 'secondary' }, modeLabel(status.mode))
3338
- )
3836
+ stateLabel
3837
+ ),
3838
+ h(Badge, { variant: 'secondary' }, modeLabel(status.mode)),
3839
+ typeof status.version === 'string' && status.version !== ''
3840
+ ? h(Badge, { variant: 'outline' }, status.version)
3841
+ : null
3339
3842
  ),
3340
- h(CardAction, null, h('div', { className: 'kb-hero-actions' }, buttons))
3843
+ h('div', { className: 'kb-hero-actions' }, buttons)
3341
3844
  ),
3342
3845
  h(
3343
- CardContent,
3344
- null,
3345
- h(
3346
- 'div',
3347
- { className: 'kb-kpi-grid' },
3348
- h(Kpi, { label: '健康状态', value: health, tone: healthTone }),
3349
- h(Kpi, { label: '运行时长', value: formatUptime(status.uptime) }),
3350
- h(Kpi, { label: '内存占用 (RSS)', value: formatBytes(status.rss) }),
3351
- h(Kpi, {
3352
- label: '重启次数',
3353
- value: restarts ?? '—',
3354
- tone: restarts !== undefined && restarts > 0 ? 'warning' : undefined
3355
- })
3356
- ),
3357
- status.lastError !== ''
3358
- ? h(
3359
- Alert,
3360
- { variant: 'destructive', className: 'kb-hero-alert' },
3361
- h(UiIcon, { name: 'alert-circle' }),
3362
- h(AlertTitle, null, '最新错误'),
3363
- h(AlertDescription, null, h('span', { className: 'kb-error-text' }, status.lastError)),
3364
- h(AlertAction, null, h(CopyButton, { value: status.lastError, label: '复制错误信息' }))
3365
- )
3366
- : null
3367
- )
3846
+ 'div',
3847
+ { className: 'kb-engine-kpis' },
3848
+ h(Kpi, { label: '健康状态', value: health, tone: healthTone }),
3849
+ h(Kpi, { label: '运行时长', value: formatUptime(status.uptime) }),
3850
+ h(Kpi, { label: '内存占用 (RSS)', value: formatBytes(status.rss) }),
3851
+ h(Kpi, {
3852
+ label: '重启次数',
3853
+ value: restarts ?? '—',
3854
+ tone: restarts !== undefined && restarts > 0 ? 'warning' : undefined
3855
+ })
3856
+ ),
3857
+ typeof status.lastError === 'string' && status.lastError !== ''
3858
+ ? h(
3859
+ Alert,
3860
+ { variant: 'destructive', className: 'kb-hero-alert' },
3861
+ h(UiIcon, { name: 'alert-circle' }),
3862
+ h(AlertTitle, null, '最新错误'),
3863
+ h(AlertDescription, null, h('span', { className: 'kb-error-text' }, status.lastError)),
3864
+ h(AlertAction, null, h(CopyButton, { value: status.lastError, label: '复制错误信息' }))
3865
+ )
3866
+ : null
3368
3867
  ),
3369
3868
  h(
3370
- Section,
3371
- { title: '运行详情' },
3372
- h(Card, { size: 'sm' }, h(CardContent, null, h(Facts, { rows: detailRows })))
3869
+ 'aside',
3870
+ { className: 'kb-engine-rail' },
3871
+ h(
3872
+ EngineSideCard,
3873
+ { title: '运行详情' },
3874
+ detailRows.map((row) =>
3875
+ h(EngineSideRow, { key: row.label, label: row.label }, row.value)
3876
+ )
3877
+ ),
3878
+ h(OcrHealthCard, { status })
3373
3879
  ),
3374
- h(ModelCopyPanel, null),
3375
3880
  h(
3376
- Section,
3377
- {
3378
- title: '运行日志',
3379
- actions: h(
3380
- 'div',
3381
- { className: 'kb-card-actions' },
3382
- logs.length > 0 ? h(CopyButton, { value: logsText, label: '复制日志' }) : null,
3383
- h(
3384
- Button,
3385
- {
3386
- variant: 'ghost',
3387
- size: 'sm',
3388
- 'aria-pressed': wrap,
3389
- onClick: () => setWrap((value) => !value)
3390
- },
3391
- h(UiIcon, { name: 'wrap-text' }),
3392
- '自动换行'
3393
- )
3394
- )
3395
- },
3881
+ 'div',
3882
+ { className: 'kb-engine-segmented' },
3396
3883
  h(
3397
- Card,
3398
- { size: 'sm' },
3884
+ ToggleGroup,
3885
+ {
3886
+ value: [pane],
3887
+ variant: 'outline',
3888
+ size: 'sm',
3889
+ spacing: 0,
3890
+ 'aria-label': '引擎工作台面板',
3891
+ onValueChange: (next) => {
3892
+ const picked = next.find((value) => value !== pane)
3893
+ if (picked === 'logs' || picked === 'models') setPane(picked)
3894
+ }
3895
+ },
3399
3896
  h(
3400
- CardContent,
3401
- null,
3402
- logs.length > 0
3403
- ? h('pre', { className: 'kb-log', 'data-wrap': wrap ? 'true' : 'false' }, logsText)
3404
- : h('p', { className: 'kb-log-empty' }, logFallback)
3405
- )
3897
+ ToggleGroupItem,
3898
+ { value: 'logs' },
3899
+ '运行日志',
3900
+ h(Badge, { variant: 'secondary', className: 'kb-count' }, String(logs.length))
3901
+ ),
3902
+ h(ToggleGroupItem, { value: 'models' }, '从 ChatLuna 复制模型')
3406
3903
  )
3904
+ ),
3905
+ h(LogConsole, {
3906
+ logs,
3907
+ fallback: logFallback,
3908
+ query: logQuery,
3909
+ warningsOnly,
3910
+ wrap,
3911
+ logRef,
3912
+ onQuery: setLogQuery,
3913
+ onWarningsOnly: setWarningsOnly,
3914
+ onWrap: () => setWrap((value) => !value),
3915
+ onJump: jumpToBottom
3916
+ }),
3917
+ h(
3918
+ 'div',
3919
+ { className: 'kb-engine-model-panel' },
3920
+ h(ModelCopyPanel, {
3921
+ layout: 'workbench',
3922
+ autoLoad: pane === 'models' || wideWorkbench
3923
+ })
3407
3924
  )
3408
3925
  )
3409
3926
  }