chatluna-plugin-kb 0.1.8 → 0.2.8
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/index.mjs +34 -0
- package/package.json +1 -1
- package/src/engine/deps-installer.mjs +410 -0
- package/src/webui/model-routes.mjs +69 -0
- package/src/webui/models.mjs +491 -11
- package/src/webui/server.mjs +97 -1
- package/web/client.css +198 -73
- package/web/client.js +1094 -688
package/web/client.js
CHANGED
|
@@ -126,9 +126,9 @@ const INSTALL_UPLOAD_URL = '/kb-admin/install/upload'
|
|
|
126
126
|
|
|
127
127
|
const WIZARD_STEPS = [
|
|
128
128
|
{ key: 'mode', label: '选择模式' },
|
|
129
|
-
{ key: 'install', label: '
|
|
130
|
-
{ key: '
|
|
131
|
-
{ key: 'done', label: '
|
|
129
|
+
{ key: 'install', label: '安装并启动' },
|
|
130
|
+
{ key: 'sync', label: '同步模型' },
|
|
131
|
+
{ key: 'done', label: '准备就绪' }
|
|
132
132
|
]
|
|
133
133
|
|
|
134
134
|
const INSTALL_STATE_LABELS = {
|
|
@@ -139,6 +139,7 @@ const INSTALL_STATE_LABELS = {
|
|
|
139
139
|
verifying: '校验中',
|
|
140
140
|
extracting: '解压中',
|
|
141
141
|
installing: '安装中',
|
|
142
|
+
installing_deps: '补齐 OCR 组件中',
|
|
142
143
|
starting: '启动中',
|
|
143
144
|
installed: '已安装',
|
|
144
145
|
failed: '失败',
|
|
@@ -1279,7 +1280,7 @@ function engineOfflineCard(status, actions, options) {
|
|
|
1279
1280
|
)
|
|
1280
1281
|
}
|
|
1281
1282
|
|
|
1282
|
-
// ---- 从 ChatLuna
|
|
1283
|
+
// ---- 从 ChatLuna 同步模型配置 ---------------------------------------------
|
|
1283
1284
|
// 列表只来自服务端脱敏元数据;页面从不接收、保存或展示 API Key。
|
|
1284
1285
|
const MODEL_TYPE_LABELS = {
|
|
1285
1286
|
chat: '对话模型',
|
|
@@ -1288,9 +1289,12 @@ const MODEL_TYPE_LABELS = {
|
|
|
1288
1289
|
rerank: 'ReRank 模型'
|
|
1289
1290
|
}
|
|
1290
1291
|
const MODEL_TYPE_ORDER = ['chat', 'embedding', 'vlm', 'rerank']
|
|
1292
|
+
const MODEL_ROLE_LABELS = { chat: '对话', embedding: 'Embedding', vlm: 'VLM', rerank: 'ReRank' }
|
|
1293
|
+
const MODEL_GROUP_LIMIT = 5
|
|
1294
|
+
const MODEL_SYNC_LIMIT = 32
|
|
1291
1295
|
|
|
1292
1296
|
function modelRoleLabel(role) {
|
|
1293
|
-
return role
|
|
1297
|
+
return MODEL_ROLE_LABELS[role] ?? 'Embedding'
|
|
1294
1298
|
}
|
|
1295
1299
|
|
|
1296
1300
|
function importRolesFor(item) {
|
|
@@ -1305,17 +1309,72 @@ function shortenUrl(value, max = 52) {
|
|
|
1305
1309
|
return text.length <= max ? text : `${text.slice(0, max - 1)}…`
|
|
1306
1310
|
}
|
|
1307
1311
|
|
|
1312
|
+
/** ChatLuna 侧模型标识:脱敏卡片可能用 modelId、name 或 id 作为唯一键。 */
|
|
1313
|
+
function modelIdOf(item) {
|
|
1314
|
+
return textOf(item?.modelId) || textOf(item?.name) || textOf(item?.id)
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function modelBaseUrlOf(item) {
|
|
1318
|
+
return textOf(item?.baseUrl) || textOf(item?.base_url)
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1308
1321
|
function modelSelectionKey(item) {
|
|
1309
1322
|
return `${item?.providerId ?? ''}\u0000${item?.modelId ?? ''}\u0000${item?.type ?? ''}`
|
|
1310
1323
|
}
|
|
1311
1324
|
|
|
1325
|
+
/** baseUrl 归一化:去空白、去尾斜杠、主机与路径大小写不敏感。 */
|
|
1326
|
+
export function normalizeModelBaseUrl(value) {
|
|
1327
|
+
const text = typeof value === 'string' ? value.trim() : ''
|
|
1328
|
+
if (text === '') return ''
|
|
1329
|
+
return text.replace(/\/+$/, '').toLowerCase()
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
/** 知识库里已有模型的匹配键:modelId + baseUrl + type。 */
|
|
1333
|
+
/** WeKnora 后端类型 → 前端角色;ChatLuna 卡片本身已是 chat/vlm/embedding/rerank。 */
|
|
1334
|
+
export function canonicalModelRole(value) {
|
|
1335
|
+
const role = textOf(value).toLowerCase()
|
|
1336
|
+
if (role === 'knowledgeqa' || role === 'knowledge_qa' || role === 'qa' || role === 'chat') return 'chat'
|
|
1337
|
+
if (role === 'embedding') return 'embedding'
|
|
1338
|
+
if (role === 'vllm' || role === 'vlm') return 'vlm'
|
|
1339
|
+
if (role === 'rerank') return 'rerank'
|
|
1340
|
+
return role
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function modelTargetKey(item, role = '') {
|
|
1344
|
+
return `${modelIdOf(item)}\u0000${normalizeModelBaseUrl(modelBaseUrlOf(item))}\u0000${
|
|
1345
|
+
canonicalModelRole(role || textOf(item?.type))
|
|
1346
|
+
}`
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/** 把 `kb.models.weknora` 的返回(数组或 {models})摊平成可匹配的键集合。 */
|
|
1350
|
+
export function syncedModelKeys(value) {
|
|
1351
|
+
const list = Array.isArray(value) ? value : Array.isArray(value?.models) ? value.models : []
|
|
1352
|
+
const keys = new Set()
|
|
1353
|
+
for (const item of list) {
|
|
1354
|
+
if (item === null || typeof item !== 'object') continue
|
|
1355
|
+
const role = textOf(item.role) || textOf(item.type)
|
|
1356
|
+
const key = modelTargetKey(item, role)
|
|
1357
|
+
if (modelIdOf(item) !== '') keys.add(key)
|
|
1358
|
+
}
|
|
1359
|
+
return keys
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
function keySetOf(value) {
|
|
1363
|
+
if (value instanceof Set) return value
|
|
1364
|
+
return new Set(Array.isArray(value) ? value : [])
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
/** 工作站/向导共用的已同步判定;role 缺省时用卡片自身的 type。 */
|
|
1368
|
+
export function modelIsSynced(item, role, syncedKeys) {
|
|
1369
|
+
return keySetOf(syncedKeys).has(modelTargetKey(item, role || textOf(item?.type)))
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1312
1372
|
const MODEL_FILTER_LABELS = {
|
|
1313
1373
|
chat: '对话',
|
|
1314
1374
|
embedding: 'Embedding',
|
|
1315
1375
|
vlm: 'VLM',
|
|
1316
1376
|
rerank: 'ReRank'
|
|
1317
1377
|
}
|
|
1318
|
-
const MODEL_GROUP_LIMIT = 5
|
|
1319
1378
|
|
|
1320
1379
|
const providerGroupOf = (item) => {
|
|
1321
1380
|
const label = typeof item?.providerLabel === 'string' ? item.providerLabel.trim() : ''
|
|
@@ -1332,17 +1391,62 @@ export function modelProviderLabel(value) {
|
|
|
1332
1391
|
return stripped === '' ? raw : stripped
|
|
1333
1392
|
}
|
|
1334
1393
|
|
|
1394
|
+
function roleFor(item, roles) {
|
|
1395
|
+
const key = modelSelectionKey(item)
|
|
1396
|
+
const requested = typeof roles === 'object' && roles !== null ? roles[key] : undefined
|
|
1397
|
+
return importRolesFor(item).includes(requested) ? requested : item.type
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/** 已选统计:按实际同步角色(VLM 切换后计入 VLM)分类。 */
|
|
1401
|
+
export function syncSelectionSummary(models, selectedKeys, roles = {}) {
|
|
1402
|
+
const list = Array.isArray(models) ? models : []
|
|
1403
|
+
const chosen = keySetOf(selectedKeys)
|
|
1404
|
+
const counts = { chat: 0, embedding: 0, vlm: 0, rerank: 0 }
|
|
1405
|
+
for (const item of list) {
|
|
1406
|
+
if (!chosen.has(modelSelectionKey(item))) continue
|
|
1407
|
+
const role = roleFor(item, roles)
|
|
1408
|
+
if (counts[role] !== undefined) counts[role] += 1
|
|
1409
|
+
}
|
|
1410
|
+
const total = MODEL_TYPE_ORDER.reduce((sum, role) => sum + counts[role], 0)
|
|
1411
|
+
const parts = MODEL_TYPE_ORDER.filter((role) => counts[role] > 0).map(
|
|
1412
|
+
(role) => `${MODEL_ROLE_LABELS[role]} ${counts[role]}`
|
|
1413
|
+
)
|
|
1414
|
+
return {
|
|
1415
|
+
total,
|
|
1416
|
+
counts,
|
|
1417
|
+
label: total === 0 ? '请选择要同步的模型' : `已选 ${total} 个(${parts.join(' · ')})`
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
/** 推荐预选:一个未同步的 Embedding + 一个未同步的对话/多模态模型。 */
|
|
1422
|
+
export function recommendModelKeys(models, syncedKeys = []) {
|
|
1423
|
+
const list = Array.isArray(models) ? models.filter((item) => item !== null && typeof item === 'object') : []
|
|
1424
|
+
const ready = (item) => importRolesFor(item).length > 0 && !modelIsSynced(item, item.type, syncedKeys)
|
|
1425
|
+
const embedding = list.find((item) => item.type === 'embedding' && ready(item))
|
|
1426
|
+
const chat =
|
|
1427
|
+
list.find((item) => item.type === 'chat' && item.supportsVision === true && ready(item)) ??
|
|
1428
|
+
list.find((item) => item.type === 'chat' && ready(item)) ??
|
|
1429
|
+
list.find((item) => item.type === 'vlm' && ready(item))
|
|
1430
|
+
return [embedding, chat].filter((item) => item !== undefined).map(modelSelectionKey)
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1335
1433
|
/**
|
|
1336
|
-
*
|
|
1434
|
+
* 模型同步列表的搜索/类型筛选/厂商分组(纯函数,SSR 与单测共用)。
|
|
1337
1435
|
* - 类型计数与 chips 基于完整目录,只展示有模型的类型;
|
|
1338
|
-
* - 每个厂商默认最多 5
|
|
1436
|
+
* - 每个厂商默认最多 5 行;已勾选行自动展开到可见范围。
|
|
1339
1437
|
* @returns {{matched: object[], counts: Record<string, number>, typeOptions: object[], activeType: string, groups: object[], empty: boolean}}
|
|
1340
1438
|
*/
|
|
1341
1439
|
export function modelCopyReport(models, options = {}) {
|
|
1342
1440
|
const list = Array.isArray(models) ? models.filter((item) => item !== null && typeof item === 'object') : []
|
|
1343
1441
|
const query = typeof options.query === 'string' ? options.query.trim() : ''
|
|
1344
1442
|
const requestedType = typeof options.type === 'string' && options.type !== '' ? options.type : 'all'
|
|
1345
|
-
const
|
|
1443
|
+
const selectedKeys =
|
|
1444
|
+
Array.isArray(options.selectedKeys) && options.selectedKeys.length > 0
|
|
1445
|
+
? options.selectedKeys
|
|
1446
|
+
: typeof options.selectedKey === 'string' && options.selectedKey !== ''
|
|
1447
|
+
? [options.selectedKey]
|
|
1448
|
+
: []
|
|
1449
|
+
const selectedSet = keySetOf(selectedKeys)
|
|
1346
1450
|
const expanded = options.expanded !== null && typeof options.expanded === 'object' ? options.expanded : {}
|
|
1347
1451
|
const matched =
|
|
1348
1452
|
query === ''
|
|
@@ -1374,7 +1478,7 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1374
1478
|
}
|
|
1375
1479
|
const groups = []
|
|
1376
1480
|
for (const [key, items] of groupMap) {
|
|
1377
|
-
const selectedIndex = items.findIndex((item) => modelSelectionKey(item)
|
|
1481
|
+
const selectedIndex = items.findIndex((item) => selectedSet.has(modelSelectionKey(item)))
|
|
1378
1482
|
const isExpanded = expanded[key] === true
|
|
1379
1483
|
const limit = isExpanded
|
|
1380
1484
|
? items.length
|
|
@@ -1386,6 +1490,7 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1386
1490
|
key,
|
|
1387
1491
|
label: modelProviderLabel(key),
|
|
1388
1492
|
items: visible,
|
|
1493
|
+
allItems: items,
|
|
1389
1494
|
total: items.length,
|
|
1390
1495
|
hidden: items.length - visible.length,
|
|
1391
1496
|
expanded: isExpanded,
|
|
@@ -1395,583 +1500,643 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1395
1500
|
return { matched, counts, typeOptions, activeType, groups, empty: typed.length === 0 }
|
|
1396
1501
|
}
|
|
1397
1502
|
|
|
1503
|
+
/** 后端脱敏滤网之外再收窄一次:失败原因里绝不回显疑似密钥。 */
|
|
1504
|
+
export function sanitizeSyncReason(value) {
|
|
1505
|
+
let text = typeof value === 'string' ? value : textOf(value?.message)
|
|
1506
|
+
text = text
|
|
1507
|
+
.replace(/(?:sk|api|key)[-_]?[A-Za-z0-9]{8,}/gi, '••••')
|
|
1508
|
+
.replace(/Bearer\s+\S+/gi, 'Bearer ••••')
|
|
1509
|
+
.replace(/api[_-]?key\s*[=:]\s*\S+/gi, 'apiKey=••••')
|
|
1510
|
+
return text.length > 160 ? `${text.slice(0, 159)}…` : text
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/** 批量同步响应归一化:兼容 {result}、{summary} 与直接返回三种形状。 */
|
|
1514
|
+
export function syncBatchOutcome(response, items = []) {
|
|
1515
|
+
const data =
|
|
1516
|
+
response?.result !== undefined && response.result !== null
|
|
1517
|
+
? response.result
|
|
1518
|
+
: response?.summary !== undefined && response.summary !== null
|
|
1519
|
+
? response.summary
|
|
1520
|
+
: response
|
|
1521
|
+
const source = data !== null && typeof data === 'object' ? data : {}
|
|
1522
|
+
const results = Array.isArray(source.results)
|
|
1523
|
+
? source.results.filter((item) => item !== null && typeof item === 'object')
|
|
1524
|
+
: []
|
|
1525
|
+
const statusOf = (item) => textOf(item.status).toLowerCase()
|
|
1526
|
+
const count = (...names) => results.filter((item) => names.includes(statusOf(item))).length
|
|
1527
|
+
const imported = finite(source.imported) ?? count('imported', 'created', 'synced', 'ok', 'success')
|
|
1528
|
+
const skipped = finite(source.skipped) ?? count('skipped', 'exists', 'existed')
|
|
1529
|
+
const failed = finite(source.failed) ?? count('failed', 'error')
|
|
1530
|
+
return {
|
|
1531
|
+
total: finite(source.total) ?? (items.length > 0 ? items.length : results.length),
|
|
1532
|
+
imported,
|
|
1533
|
+
skipped,
|
|
1534
|
+
failed,
|
|
1535
|
+
boundEmbeddingModelId: textOf(source.boundEmbeddingModelId) || '',
|
|
1536
|
+
boundEmbeddingModelName: textOf(source.boundEmbeddingModelName) || '',
|
|
1537
|
+
boundSummaryModelId: textOf(source.boundSummaryModelId) || '',
|
|
1538
|
+
boundSummaryModelName: textOf(source.boundSummaryModelName) || '',
|
|
1539
|
+
results
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
export function syncOutcomeLabel(summary) {
|
|
1544
|
+
if (summary === null || typeof summary !== 'object') return ''
|
|
1545
|
+
const imported = finite(summary.imported) ?? 0
|
|
1546
|
+
const skipped = finite(summary.skipped) ?? 0
|
|
1547
|
+
const failed = finite(summary.failed) ?? 0
|
|
1548
|
+
return `同步完成:成功 ${imported} 个 · 跳过 ${skipped} 个(已存在) · 失败 ${failed} 个`
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
/**
|
|
1552
|
+
* 批量同步后的本地状态折叠(纯函数):成功/跳过的项取消勾选并点亮已同步,
|
|
1553
|
+
* 失败项保留勾选并写入脱敏原因。全成功时由调用方决定是否自动进入下一步。
|
|
1554
|
+
*/
|
|
1555
|
+
export function applySyncOutcome(state, items, response) {
|
|
1556
|
+
const models = Array.isArray(state?.models) ? state.models : []
|
|
1557
|
+
const roles = state?.roles !== null && typeof state?.roles === 'object' ? state.roles : {}
|
|
1558
|
+
const nextSynced = new Set(keySetOf(state?.syncedKeys))
|
|
1559
|
+
const remaining = new Set(keySetOf(state?.selectedKeys))
|
|
1560
|
+
const itemErrors = {}
|
|
1561
|
+
const successes = []
|
|
1562
|
+
const findings = syncBatchOutcome(response, items)
|
|
1563
|
+
const results =
|
|
1564
|
+
findings.results.length > 0
|
|
1565
|
+
? findings.results
|
|
1566
|
+
: findings.failed === 0
|
|
1567
|
+
? items.map((item) => ({ ...item, status: 'imported' }))
|
|
1568
|
+
: []
|
|
1569
|
+
const summary = results === findings.results ? findings : { ...findings, results }
|
|
1570
|
+
for (const item of items) {
|
|
1571
|
+
const match = results.find(
|
|
1572
|
+
(entry) =>
|
|
1573
|
+
textOf(entry.providerId) === textOf(item.providerId) &&
|
|
1574
|
+
textOf(entry.modelId) === textOf(item.modelId) &&
|
|
1575
|
+
textOf(entry.role) === textOf(item.role)
|
|
1576
|
+
)
|
|
1577
|
+
if (match === undefined) continue
|
|
1578
|
+
const model = models.find(
|
|
1579
|
+
(candidate) =>
|
|
1580
|
+
textOf(candidate.providerId) === textOf(item.providerId) &&
|
|
1581
|
+
textOf(candidate.modelId) === textOf(item.modelId) &&
|
|
1582
|
+
roleFor(candidate, roles) === item.role
|
|
1583
|
+
)
|
|
1584
|
+
if (model === undefined) continue
|
|
1585
|
+
const status = textOf(match.status).toLowerCase()
|
|
1586
|
+
if (status === 'skipped' || status === 'exists' || status === 'existed') {
|
|
1587
|
+
remaining.delete(modelSelectionKey(model))
|
|
1588
|
+
nextSynced.add(modelTargetKey(model, item.role))
|
|
1589
|
+
successes.push(item)
|
|
1590
|
+
} else if (
|
|
1591
|
+
status === 'imported' ||
|
|
1592
|
+
status === 'created' ||
|
|
1593
|
+
status === 'synced' ||
|
|
1594
|
+
status === 'ok' ||
|
|
1595
|
+
status === 'success'
|
|
1596
|
+
) {
|
|
1597
|
+
remaining.delete(modelSelectionKey(model))
|
|
1598
|
+
nextSynced.add(modelTargetKey(model, item.role))
|
|
1599
|
+
successes.push(item)
|
|
1600
|
+
} else {
|
|
1601
|
+
itemErrors[modelSelectionKey(model)] = sanitizeSyncReason(match.reason || match.error || '同步失败')
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
return {
|
|
1605
|
+
summary,
|
|
1606
|
+
syncedKeys: [...nextSynced],
|
|
1607
|
+
selectedKeys: [...remaining],
|
|
1608
|
+
itemErrors,
|
|
1609
|
+
successes,
|
|
1610
|
+
complete: summary.failed === 0 && successes.length === items.length
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1398
1614
|
/**
|
|
1399
|
-
*
|
|
1615
|
+
* 纯渲染层:多选同步工作台,弹窗与向导共用。
|
|
1400
1616
|
* @param {{
|
|
1401
|
-
*
|
|
1402
|
-
* layout?: 'workbench'|'card',
|
|
1617
|
+
* layout?: 'workbench'|'wizard',
|
|
1403
1618
|
* state: 'idle'|'loading'|'ready'|'error',
|
|
1404
1619
|
* models: Array<object>,
|
|
1405
1620
|
* error?: string,
|
|
1406
|
-
*
|
|
1621
|
+
* selectedKeys?: string[],
|
|
1622
|
+
* roles?: object,
|
|
1623
|
+
* syncedKeys?: string[]|Set<string>,
|
|
1407
1624
|
* query?: string,
|
|
1408
1625
|
* type?: string,
|
|
1409
1626
|
* expanded?: object,
|
|
1410
|
-
*
|
|
1411
|
-
*
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1627
|
+
* syncing?: boolean,
|
|
1628
|
+
* syncProgress?: {done: number, total: number},
|
|
1629
|
+
* syncSummary?: object|null,
|
|
1630
|
+
* syncError?: string,
|
|
1631
|
+
* itemErrors?: object,
|
|
1632
|
+
* bindDefaultKb?: boolean,
|
|
1414
1633
|
* onLoad?: Function,
|
|
1415
|
-
*
|
|
1634
|
+
* onToggle?: Function,
|
|
1635
|
+
* onGroupSelect?: Function,
|
|
1636
|
+
* onClear?: Function,
|
|
1637
|
+
* onRoleChange?: Function,
|
|
1416
1638
|
* onQueryChange?: Function,
|
|
1417
1639
|
* onTypeChange?: Function,
|
|
1418
1640
|
* onToggleGroup?: Function,
|
|
1419
|
-
*
|
|
1641
|
+
* onSync?: Function,
|
|
1642
|
+
* onClose?: Function,
|
|
1643
|
+
* onSkip?: Function
|
|
1420
1644
|
* }} m
|
|
1421
1645
|
*/
|
|
1422
1646
|
export function modelCopyView(m = {}) {
|
|
1423
1647
|
const models = Array.isArray(m.models) ? m.models : []
|
|
1424
|
-
const
|
|
1425
|
-
const
|
|
1648
|
+
const selectedKeys = Array.isArray(m.selectedKeys) ? m.selectedKeys : []
|
|
1649
|
+
const selectedSet = keySetOf(selectedKeys)
|
|
1650
|
+
const roles = m.roles !== null && typeof m.roles === 'object' ? m.roles : {}
|
|
1651
|
+
const synced = keySetOf(m.syncedKeys)
|
|
1426
1652
|
const query = typeof m.query === 'string' ? m.query : ''
|
|
1427
1653
|
const report = modelCopyReport(models, {
|
|
1428
1654
|
query,
|
|
1429
1655
|
type: m.type,
|
|
1430
1656
|
expanded: m.expanded,
|
|
1431
|
-
|
|
1657
|
+
selectedKeys
|
|
1432
1658
|
})
|
|
1433
|
-
const
|
|
1434
|
-
const
|
|
1435
|
-
const
|
|
1436
|
-
const workbench = m.layout === 'workbench'
|
|
1437
|
-
const open = workbench ? true : m.open === true
|
|
1659
|
+
const summary = syncSelectionSummary(models, selectedKeys, roles)
|
|
1660
|
+
const total = summary.total
|
|
1661
|
+
const wizard = m.layout === 'wizard'
|
|
1438
1662
|
const state = typeof m.state === 'string' ? m.state : 'idle'
|
|
1439
1663
|
const loadLabel = state === 'loading' ? '刷新中…' : '刷新'
|
|
1440
|
-
const fullLabel = (item) =>
|
|
1441
|
-
|
|
1442
|
-
const
|
|
1664
|
+
const fullLabel = (item) => `${item.providerLabel || item.providerId || '—'} · ${item.modelId || '—'}`
|
|
1665
|
+
const syncResult = m.syncSummary !== null && typeof m.syncSummary === 'object' ? m.syncSummary : null
|
|
1666
|
+
const progress = m.syncProgress !== null && typeof m.syncProgress === 'object' ? m.syncProgress : {}
|
|
1667
|
+
const errorOf = (key) => (m.itemErrors !== null && typeof m.itemErrors === 'object' ? m.itemErrors[key] : undefined)
|
|
1668
|
+
const doToggle = (key) => (typeof m.onToggle === 'function' ? () => m.onToggle(key) : undefined)
|
|
1669
|
+
const doRole = (key, role) =>
|
|
1670
|
+
typeof m.onRoleChange === 'function'
|
|
1671
|
+
? (event) => {
|
|
1672
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
1673
|
+
m.onRoleChange(key, role)
|
|
1674
|
+
}
|
|
1675
|
+
: undefined
|
|
1443
1676
|
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
h(
|
|
1454
|
-
SelectTrigger,
|
|
1455
|
-
{ id: withId ? 'kb-model-import-role' : undefined, className: 'kb-rule-select', 'aria-label': '导入为' },
|
|
1456
|
-
h(SelectValue, null, roleLabel(activeImportRole))
|
|
1457
|
-
),
|
|
1458
|
-
h(
|
|
1459
|
-
SelectContent,
|
|
1460
|
-
null,
|
|
1461
|
-
selectedRoles.map((role) =>
|
|
1462
|
-
h(SelectItem, { key: role, value: role }, roleLabel(role))
|
|
1463
|
-
)
|
|
1464
|
-
)
|
|
1465
|
-
)
|
|
1677
|
+
const syncLabel = () => {
|
|
1678
|
+
if (m.syncing === true) {
|
|
1679
|
+
const done = finite(progress.done) ?? 0
|
|
1680
|
+
const limit = finite(progress.total) ?? Math.max(1, total)
|
|
1681
|
+
return `同步中 (${done}/${limit})…`
|
|
1682
|
+
}
|
|
1683
|
+
if (total === 0) return '同步到知识库'
|
|
1684
|
+
return wizard ? `同步所选模型并继续 (${total})` : `同步所选模型 (${total})`
|
|
1685
|
+
}
|
|
1466
1686
|
|
|
1467
|
-
const
|
|
1687
|
+
const syncButton = () =>
|
|
1468
1688
|
h(
|
|
1469
1689
|
Button,
|
|
1470
1690
|
{
|
|
1471
1691
|
size: 'sm',
|
|
1472
|
-
disabled:
|
|
1473
|
-
onClick:
|
|
1692
|
+
disabled: total === 0 || m.syncing === true || typeof m.onSync !== 'function',
|
|
1693
|
+
onClick: typeof m.onSync === 'function' ? m.onSync : undefined
|
|
1474
1694
|
},
|
|
1475
|
-
|
|
1695
|
+
syncLabel()
|
|
1476
1696
|
)
|
|
1477
1697
|
|
|
1478
|
-
const
|
|
1479
|
-
|
|
1698
|
+
const roleSwitch = (item) => {
|
|
1699
|
+
const key = modelSelectionKey(item)
|
|
1700
|
+
const active = roleFor(item, roles)
|
|
1480
1701
|
return h(
|
|
1481
1702
|
'div',
|
|
1482
|
-
{ className: 'kb-model-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1703
|
+
{ className: 'kb-model-inline-role', role: 'group', 'aria-label': '同步为' },
|
|
1704
|
+
importRolesFor(item).map((role) =>
|
|
1705
|
+
h(
|
|
1706
|
+
Button,
|
|
1707
|
+
{
|
|
1708
|
+
key: role,
|
|
1709
|
+
type: 'button',
|
|
1710
|
+
variant: active === role ? 'secondary' : 'ghost',
|
|
1711
|
+
size: 'sm',
|
|
1712
|
+
'aria-pressed': active === role ? 'true' : 'false',
|
|
1713
|
+
onClick: doRole(key, role)
|
|
1714
|
+
},
|
|
1715
|
+
role === 'vlm' ? '仅视觉' : '对话(含视觉)'
|
|
1716
|
+
)
|
|
1717
|
+
)
|
|
1497
1718
|
)
|
|
1498
1719
|
}
|
|
1499
1720
|
|
|
1500
|
-
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1721
|
+
const itemCard = (item) => {
|
|
1722
|
+
const key = modelSelectionKey(item)
|
|
1723
|
+
const active = selectedSet.has(key)
|
|
1724
|
+
const role = roleFor(item, roles)
|
|
1725
|
+
const already = modelIsSynced(item, role, synced)
|
|
1726
|
+
const failure = sanitizeSyncReason(errorOf(key))
|
|
1727
|
+
return h(
|
|
1728
|
+
'div',
|
|
1729
|
+
{
|
|
1730
|
+
key,
|
|
1731
|
+
className: `kb-model-item${active ? ' kb-model-item-selected' : ''}${already ? ' kb-model-item-synced' : ''}`,
|
|
1732
|
+
title: fullLabel(item),
|
|
1733
|
+
role: 'checkbox',
|
|
1734
|
+
tabIndex: 0,
|
|
1735
|
+
'aria-checked': active ? 'true' : 'false',
|
|
1736
|
+
'aria-pressed': active ? 'true' : 'false',
|
|
1737
|
+
onClick: doToggle(key),
|
|
1738
|
+
onKeyDown:
|
|
1739
|
+
typeof m.onToggle === 'function'
|
|
1740
|
+
? (event) => {
|
|
1741
|
+
if (event.target !== event.currentTarget) return
|
|
1742
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
1743
|
+
event.preventDefault?.()
|
|
1744
|
+
m.onToggle(key)
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
: undefined
|
|
1748
|
+
},
|
|
1749
|
+
h(
|
|
1750
|
+
'span',
|
|
1751
|
+
{ className: 'kb-model-main' },
|
|
1514
1752
|
h(
|
|
1515
1753
|
'span',
|
|
1516
|
-
{ className: 'kb-model-
|
|
1517
|
-
h(
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
h(
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
),
|
|
1525
|
-
h(
|
|
1526
|
-
'span',
|
|
1527
|
-
{ className: 'kb-model-url', title: item.baseUrl || '' },
|
|
1528
|
-
shortenUrl(item.baseUrl)
|
|
1529
|
-
),
|
|
1530
|
-
item.protocolHint
|
|
1531
|
-
? h(
|
|
1532
|
-
'span',
|
|
1533
|
-
{ className: 'kb-muted-text' },
|
|
1534
|
-
'该路由使用非 OpenAI 原生协议,复制后可能需要在知识库设置中调整接口类型。'
|
|
1535
|
-
)
|
|
1536
|
-
: null
|
|
1754
|
+
{ className: 'kb-model-title' },
|
|
1755
|
+
h('span', { className: 'kb-model-model-id' }, modelIdOf(item) || '—'),
|
|
1756
|
+
h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, modelRoleLabel(item.type)),
|
|
1757
|
+
item.supportsVision === true && item.type !== 'vlm'
|
|
1758
|
+
? h(Badge, { variant: 'secondary' }, '支持视觉')
|
|
1759
|
+
: null,
|
|
1760
|
+
item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null,
|
|
1761
|
+
already ? h(Badge, { className: 'kb-model-synced-badge' }, '已同步') : null
|
|
1537
1762
|
),
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
h(
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
'
|
|
1559
|
-
{ className: 'kb-model-scroll' },
|
|
1560
|
-
h('p', { className: 'kb-muted-text' }, 'ChatLuna 暂无可用于复制的知识库模型。')
|
|
1561
|
-
)
|
|
1562
|
-
} else if (report.groups.length === 0) {
|
|
1563
|
-
body = h(
|
|
1564
|
-
'div',
|
|
1565
|
-
{ className: 'kb-model-scroll' },
|
|
1566
|
-
h('p', { className: 'kb-muted-text' }, '没有匹配的模型;调整搜索关键词或类型筛选。')
|
|
1567
|
-
)
|
|
1568
|
-
} else {
|
|
1569
|
-
body = h(
|
|
1570
|
-
'div',
|
|
1571
|
-
{ className: 'kb-model-scroll' },
|
|
1572
|
-
report.groups.map((group) =>
|
|
1573
|
-
h(
|
|
1574
|
-
'div',
|
|
1575
|
-
{ key: group.key, className: 'kb-model-group' },
|
|
1576
|
-
h(
|
|
1577
|
-
'div',
|
|
1578
|
-
{ className: 'kb-model-group-head' },
|
|
1579
|
-
h('p', { className: 'kb-model-group-title' }, group.label),
|
|
1580
|
-
h(Badge, { variant: 'outline' }, String(group.total))
|
|
1581
|
-
),
|
|
1582
|
-
h('div', { className: 'kb-model-list' }, group.items.map(workbenchItem)),
|
|
1583
|
-
group.hidden > 0
|
|
1584
|
-
? h(
|
|
1585
|
-
Button,
|
|
1586
|
-
{
|
|
1587
|
-
variant: 'ghost',
|
|
1588
|
-
size: 'sm',
|
|
1589
|
-
className: 'kb-model-more',
|
|
1590
|
-
onClick: () =>
|
|
1591
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1592
|
-
},
|
|
1593
|
-
`显示更多 ${group.hidden}`
|
|
1594
|
-
)
|
|
1595
|
-
: null,
|
|
1596
|
-
group.expanded && group.total > MODEL_GROUP_LIMIT
|
|
1597
|
-
? h(
|
|
1598
|
-
Button,
|
|
1599
|
-
{
|
|
1600
|
-
variant: 'ghost',
|
|
1601
|
-
size: 'sm',
|
|
1602
|
-
className: 'kb-model-more',
|
|
1603
|
-
onClick: () =>
|
|
1604
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1605
|
-
},
|
|
1606
|
-
'收起'
|
|
1607
|
-
)
|
|
1608
|
-
: null
|
|
1609
|
-
)
|
|
1610
|
-
)
|
|
1763
|
+
h('span', { className: 'kb-model-url', title: modelBaseUrlOf(item) }, shortenUrl(modelBaseUrlOf(item))),
|
|
1764
|
+
item.protocolHint
|
|
1765
|
+
? h(
|
|
1766
|
+
'span',
|
|
1767
|
+
{ className: 'kb-muted-text' },
|
|
1768
|
+
'该路由使用非 OpenAI 原生协议,同步后可能需要在知识库设置中调整接口类型。'
|
|
1769
|
+
)
|
|
1770
|
+
: null,
|
|
1771
|
+
active && roleSwitch(item)
|
|
1772
|
+
),
|
|
1773
|
+
failure !== ''
|
|
1774
|
+
? h('span', { className: 'kb-model-error' }, `原因:${failure}`)
|
|
1775
|
+
: null,
|
|
1776
|
+
h(
|
|
1777
|
+
'span',
|
|
1778
|
+
{
|
|
1779
|
+
className: 'kb-model-checkbox',
|
|
1780
|
+
'data-checked': active ? 'true' : 'false',
|
|
1781
|
+
'aria-hidden': 'true'
|
|
1782
|
+
},
|
|
1783
|
+
active ? h(UiIcon, { name: 'check' }) : null
|
|
1611
1784
|
)
|
|
1612
|
-
|
|
1785
|
+
)
|
|
1786
|
+
}
|
|
1613
1787
|
|
|
1788
|
+
const groupBody = (group) => {
|
|
1789
|
+
const selectable = group.allItems
|
|
1790
|
+
.filter((item) => !modelIsSynced(item, roleFor(item, roles), synced))
|
|
1791
|
+
.map(modelSelectionKey)
|
|
1792
|
+
const everyKey = group.allItems.map(modelSelectionKey)
|
|
1614
1793
|
return h(
|
|
1615
1794
|
'div',
|
|
1616
|
-
{ className: 'kb-model-
|
|
1795
|
+
{ key: group.key, className: 'kb-model-group' },
|
|
1617
1796
|
h(
|
|
1618
1797
|
'div',
|
|
1619
|
-
{ className: 'kb-model-
|
|
1620
|
-
h(
|
|
1621
|
-
h(
|
|
1622
|
-
|
|
1623
|
-
{ className: 'kb-model-workbench-subtitle' },
|
|
1624
|
-
'选择已配置的模型复制到知识库;仅同步元数据,不会暴露 API Key。'
|
|
1625
|
-
)
|
|
1626
|
-
),
|
|
1627
|
-
h(
|
|
1628
|
-
'div',
|
|
1629
|
-
{ className: 'kb-model-toolbar' },
|
|
1630
|
-
h(SearchBox, {
|
|
1631
|
-
value: query,
|
|
1632
|
-
onChange: (value) => (typeof m.onQueryChange === 'function' ? m.onQueryChange(value) : undefined),
|
|
1633
|
-
placeholder: '搜索厂商、模型或地址…',
|
|
1634
|
-
clearLabel: '清除搜索'
|
|
1635
|
-
}),
|
|
1636
|
-
h(FilterChips, {
|
|
1637
|
-
options: report.typeOptions,
|
|
1638
|
-
value: report.activeType,
|
|
1639
|
-
onChange: (value) => (typeof m.onTypeChange === 'function' ? m.onTypeChange(value) : undefined),
|
|
1640
|
-
label: '按模型类型筛选'
|
|
1641
|
-
}),
|
|
1642
|
-
h(
|
|
1643
|
-
Button,
|
|
1644
|
-
{
|
|
1645
|
-
variant: 'outline',
|
|
1646
|
-
size: 'sm',
|
|
1647
|
-
disabled: state === 'loading' || typeof m.onLoad !== 'function',
|
|
1648
|
-
onClick: typeof m.onLoad === 'function' ? m.onLoad : undefined
|
|
1649
|
-
},
|
|
1650
|
-
loadLabel
|
|
1651
|
-
)
|
|
1652
|
-
),
|
|
1653
|
-
body,
|
|
1654
|
-
resultAlert(),
|
|
1655
|
-
h(
|
|
1656
|
-
DialogFooter,
|
|
1657
|
-
{ className: 'kb-model-dialog-footer' },
|
|
1658
|
-
h(
|
|
1659
|
-
'div',
|
|
1660
|
-
{ className: 'kb-model-selection' },
|
|
1661
|
-
selected === null
|
|
1662
|
-
? h('span', { className: 'kb-model-selection-empty' }, '请选择一个要复制的模型')
|
|
1663
|
-
: h(
|
|
1664
|
-
'span',
|
|
1665
|
-
{ className: 'kb-model-selection-text' },
|
|
1666
|
-
'已选:',
|
|
1667
|
-
h('strong', { className: 'kb-model-selection-name' }, selected.modelId || '—'),
|
|
1668
|
-
h(
|
|
1669
|
-
'span',
|
|
1670
|
-
{ className: 'kb-model-selection-provider' },
|
|
1671
|
-
` · ${selected.providerLabel || selected.providerId || '—'}`
|
|
1672
|
-
)
|
|
1673
|
-
),
|
|
1674
|
-
selected !== null && selectedRoles.length > 1
|
|
1675
|
-
? h('div', { className: 'kb-model-role' }, roleSelect(true))
|
|
1676
|
-
: null
|
|
1677
|
-
),
|
|
1678
|
-
h(
|
|
1679
|
-
'div',
|
|
1680
|
-
{ className: 'kb-model-footer-actions' },
|
|
1798
|
+
{ className: 'kb-model-group-head' },
|
|
1799
|
+
h('p', { className: 'kb-model-group-title' }, group.label),
|
|
1800
|
+
h('div', { className: 'kb-model-group-actions' },
|
|
1801
|
+
h(Badge, { variant: 'outline' }, String(group.total)),
|
|
1681
1802
|
h(
|
|
1682
1803
|
Button,
|
|
1683
1804
|
{
|
|
1684
|
-
variant: '
|
|
1805
|
+
variant: 'ghost',
|
|
1685
1806
|
size: 'sm',
|
|
1686
|
-
|
|
1807
|
+
disabled: typeof m.onGroupSelect !== 'function',
|
|
1808
|
+
onClick:
|
|
1809
|
+
typeof m.onGroupSelect === 'function' ? () => m.onGroupSelect(selectable, true) : undefined
|
|
1687
1810
|
},
|
|
1688
|
-
'
|
|
1811
|
+
'全选本组'
|
|
1689
1812
|
),
|
|
1690
|
-
|
|
1813
|
+
h(
|
|
1814
|
+
Button,
|
|
1815
|
+
{
|
|
1816
|
+
variant: 'ghost',
|
|
1817
|
+
size: 'sm',
|
|
1818
|
+
disabled: typeof m.onGroupSelect !== 'function',
|
|
1819
|
+
onClick:
|
|
1820
|
+
typeof m.onGroupSelect === 'function' ? () => m.onGroupSelect(everyKey, false) : undefined
|
|
1821
|
+
},
|
|
1822
|
+
'取消本组'
|
|
1823
|
+
)
|
|
1691
1824
|
)
|
|
1692
|
-
)
|
|
1825
|
+
),
|
|
1826
|
+
h('div', { className: 'kb-model-list' }, group.items.map(itemCard)),
|
|
1827
|
+
group.hidden > 0
|
|
1828
|
+
? h(
|
|
1829
|
+
Button,
|
|
1830
|
+
{
|
|
1831
|
+
variant: 'ghost',
|
|
1832
|
+
size: 'sm',
|
|
1833
|
+
className: 'kb-model-more',
|
|
1834
|
+
onClick: () =>
|
|
1835
|
+
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1836
|
+
},
|
|
1837
|
+
`显示更多 ${group.hidden}`
|
|
1838
|
+
)
|
|
1839
|
+
: null,
|
|
1840
|
+
group.expanded && group.total > MODEL_GROUP_LIMIT
|
|
1841
|
+
? h(
|
|
1842
|
+
Button,
|
|
1843
|
+
{
|
|
1844
|
+
variant: 'ghost',
|
|
1845
|
+
size: 'sm',
|
|
1846
|
+
className: 'kb-model-more',
|
|
1847
|
+
onClick: () =>
|
|
1848
|
+
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1849
|
+
},
|
|
1850
|
+
'收起'
|
|
1851
|
+
)
|
|
1852
|
+
: null
|
|
1693
1853
|
)
|
|
1694
1854
|
}
|
|
1695
1855
|
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
const active = key === selectedKey
|
|
1856
|
+
const resultBar = () => {
|
|
1857
|
+
if (!m.syncError && syncResult === null) return null
|
|
1699
1858
|
return h(
|
|
1700
|
-
'
|
|
1701
|
-
{
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
'span',
|
|
1715
|
-
{ className: 'kb-model-title' },
|
|
1716
|
-
fullLabel(item),
|
|
1717
|
-
h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, modelRoleLabel(item.type)),
|
|
1718
|
-
item.supportsVision === true ? h(Badge, { variant: 'secondary' }, '支持视觉') : null,
|
|
1719
|
-
item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null
|
|
1720
|
-
),
|
|
1721
|
-
h('span', { className: 'kb-model-url', title: item.baseUrl || '' }, shortenUrl(item.baseUrl)),
|
|
1722
|
-
item.protocolHint
|
|
1723
|
-
? h(
|
|
1724
|
-
'span',
|
|
1725
|
-
{ className: 'kb-muted-text' },
|
|
1726
|
-
'该路由使用非 OpenAI 原生协议,复制后可能需要在知识库设置中调整接口类型。'
|
|
1727
|
-
)
|
|
1728
|
-
: null
|
|
1729
|
-
),
|
|
1730
|
-
active
|
|
1731
|
-
? h('span', { className: 'kb-model-check', 'aria-hidden': true }, h(UiIcon, { name: 'check' }))
|
|
1732
|
-
: null
|
|
1733
|
-
)
|
|
1859
|
+
'div',
|
|
1860
|
+
{ className: 'kb-model-result' },
|
|
1861
|
+
m.syncError ? errorAlert(m.syncError, '同步失败') : null,
|
|
1862
|
+
syncResult !== null
|
|
1863
|
+
? h(
|
|
1864
|
+
Alert,
|
|
1865
|
+
{ className: syncResult.failed > 0 ? 'kb-alert-warning' : 'kb-alert-success' },
|
|
1866
|
+
h(UiIcon, { name: syncResult.failed > 0 ? 'alert-circle' : 'check' }),
|
|
1867
|
+
h(AlertTitle, null, syncOutcomeLabel(syncResult)),
|
|
1868
|
+
syncResult.boundEmbeddingModelId !== ''
|
|
1869
|
+
? h(AlertDescription, null, '已自动绑定默认知识库的 Embedding 模型。')
|
|
1870
|
+
: null
|
|
1871
|
+
)
|
|
1872
|
+
: null
|
|
1734
1873
|
)
|
|
1735
1874
|
}
|
|
1736
1875
|
|
|
1876
|
+
let body
|
|
1877
|
+
if (state === 'loading') {
|
|
1878
|
+
body = h(
|
|
1879
|
+
'div',
|
|
1880
|
+
{ className: 'kb-model-scroll' },
|
|
1881
|
+
h(Skeleton, { className: 'kb-skeleton-row' }),
|
|
1882
|
+
h(Skeleton, { className: 'kb-skeleton-row' })
|
|
1883
|
+
)
|
|
1884
|
+
} else if (state === 'error' && typeof m.error === 'string' && m.error !== '') {
|
|
1885
|
+
body = h('div', { className: 'kb-model-scroll' }, errorAlert(m.error, '读取模型列表失败'))
|
|
1886
|
+
} else if (state === 'idle') {
|
|
1887
|
+
body = h('div', { className: 'kb-model-scroll' }, h('p', { className: 'kb-muted-text' }, '点击刷新加载模型列表。'))
|
|
1888
|
+
} else if (models.length === 0) {
|
|
1889
|
+
body = h(
|
|
1890
|
+
'div',
|
|
1891
|
+
{ className: 'kb-model-scroll' },
|
|
1892
|
+
h('p', { className: 'kb-muted-text' }, 'ChatLuna 暂无可用于同步的知识库模型。')
|
|
1893
|
+
)
|
|
1894
|
+
} else if (report.groups.length === 0) {
|
|
1895
|
+
body = h(
|
|
1896
|
+
'div',
|
|
1897
|
+
{ className: 'kb-model-scroll' },
|
|
1898
|
+
h('p', { className: 'kb-muted-text' }, '没有匹配的模型;调整搜索关键词或类型筛选。')
|
|
1899
|
+
)
|
|
1900
|
+
} else {
|
|
1901
|
+
body = h('div', { className: 'kb-model-scroll' }, report.groups.map(groupBody))
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1737
1904
|
return h(
|
|
1738
|
-
|
|
1739
|
-
{
|
|
1905
|
+
'div',
|
|
1906
|
+
{ className: `kb-model-workbench${wizard ? ' kb-model-workbench-wizard' : ''}` },
|
|
1907
|
+
wizard
|
|
1908
|
+
? null
|
|
1909
|
+
: h(
|
|
1910
|
+
'div',
|
|
1911
|
+
{ className: 'kb-model-workbench-header' },
|
|
1912
|
+
h(DialogTitle, { className: 'kb-model-workbench-title' }, '从 ChatLuna 同步模型'),
|
|
1913
|
+
h(
|
|
1914
|
+
'p',
|
|
1915
|
+
{ className: 'kb-model-workbench-subtitle' },
|
|
1916
|
+
'勾选已配置的模型一次性同步到知识库;仅读取配置元数据,不会暴露 API Key。'
|
|
1917
|
+
)
|
|
1918
|
+
),
|
|
1740
1919
|
h(
|
|
1741
|
-
|
|
1742
|
-
{
|
|
1920
|
+
'div',
|
|
1921
|
+
{ className: 'kb-model-toolbar' },
|
|
1922
|
+
h(SearchBox, {
|
|
1923
|
+
value: query,
|
|
1924
|
+
onChange: (value) => (typeof m.onQueryChange === 'function' ? m.onQueryChange(value) : undefined),
|
|
1925
|
+
placeholder: '搜索厂商、模型或地址…',
|
|
1926
|
+
clearLabel: '清除搜索'
|
|
1927
|
+
}),
|
|
1928
|
+
h(FilterChips, {
|
|
1929
|
+
options: report.typeOptions,
|
|
1930
|
+
value: report.activeType,
|
|
1931
|
+
onChange: (value) => (typeof m.onTypeChange === 'function' ? m.onTypeChange(value) : undefined),
|
|
1932
|
+
label: '按模型类型筛选'
|
|
1933
|
+
}),
|
|
1743
1934
|
h(
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
open ? importButton() : null,
|
|
1766
|
-
open
|
|
1767
|
-
? h(
|
|
1768
|
-
Button,
|
|
1769
|
-
{
|
|
1770
|
-
variant: 'outline',
|
|
1771
|
-
size: 'sm',
|
|
1772
|
-
disabled: state === 'loading' || typeof m.onLoad !== 'function',
|
|
1773
|
-
onClick: typeof m.onLoad === 'function' ? m.onLoad : undefined
|
|
1774
|
-
},
|
|
1775
|
-
loadLabel
|
|
1776
|
-
)
|
|
1777
|
-
: null,
|
|
1778
|
-
h(
|
|
1935
|
+
Button,
|
|
1936
|
+
{
|
|
1937
|
+
variant: 'outline',
|
|
1938
|
+
size: 'sm',
|
|
1939
|
+
disabled: state === 'loading' || typeof m.onLoad !== 'function',
|
|
1940
|
+
onClick: typeof m.onLoad === 'function' ? m.onLoad : undefined
|
|
1941
|
+
},
|
|
1942
|
+
loadLabel
|
|
1943
|
+
)
|
|
1944
|
+
),
|
|
1945
|
+
body,
|
|
1946
|
+
resultBar(),
|
|
1947
|
+
h(
|
|
1948
|
+
'div',
|
|
1949
|
+
{ className: 'kb-model-dialog-footer' },
|
|
1950
|
+
h(
|
|
1951
|
+
'div',
|
|
1952
|
+
{ className: 'kb-model-selection' },
|
|
1953
|
+
h('span', { className: 'kb-model-selection-text' }, summary.label),
|
|
1954
|
+
total > 0
|
|
1955
|
+
? h(
|
|
1779
1956
|
Button,
|
|
1780
1957
|
{
|
|
1781
1958
|
variant: 'ghost',
|
|
1782
1959
|
size: 'sm',
|
|
1783
|
-
'
|
|
1784
|
-
onClick: typeof m.onToggle === 'function' ? m.onToggle : undefined
|
|
1960
|
+
onClick: typeof m.onClear === 'function' ? m.onClear : undefined
|
|
1785
1961
|
},
|
|
1786
|
-
|
|
1962
|
+
'清空已选'
|
|
1787
1963
|
)
|
|
1788
|
-
|
|
1789
|
-
)
|
|
1964
|
+
: null
|
|
1790
1965
|
),
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
? errorAlert(m.error, '读取模型列表失败')
|
|
1803
|
-
: null,
|
|
1804
|
-
state === 'idle'
|
|
1805
|
-
? h('p', { className: 'kb-muted-text' }, '点击「加载模型列表」查看可复制的对话 / Embedding / VLM / ReRank 模型。')
|
|
1806
|
-
: null,
|
|
1807
|
-
state === 'ready' && models.length === 0
|
|
1808
|
-
? h('p', { className: 'kb-muted-text' }, 'ChatLuna 暂无可用于复制的知识库模型。')
|
|
1809
|
-
: null,
|
|
1810
|
-
state === 'ready' && models.length > 0
|
|
1811
|
-
? h(
|
|
1812
|
-
'div',
|
|
1813
|
-
{ className: 'kb-model-toolbar' },
|
|
1814
|
-
h(SearchBox, {
|
|
1815
|
-
value: query,
|
|
1816
|
-
onChange: (value) =>
|
|
1817
|
-
typeof m.onQueryChange === 'function' ? m.onQueryChange(value) : undefined,
|
|
1818
|
-
placeholder: '搜索厂商、模型或地址…',
|
|
1819
|
-
clearLabel: '清除搜索'
|
|
1820
|
-
}),
|
|
1821
|
-
h(FilterChips, {
|
|
1822
|
-
options: report.typeOptions,
|
|
1823
|
-
value: report.activeType,
|
|
1824
|
-
onChange: (value) =>
|
|
1825
|
-
typeof m.onTypeChange === 'function' ? m.onTypeChange(value) : undefined,
|
|
1826
|
-
label: '按模型类型筛选'
|
|
1827
|
-
})
|
|
1828
|
-
)
|
|
1829
|
-
: null,
|
|
1830
|
-
state === 'ready' && models.length > 0 && report.empty
|
|
1831
|
-
? h('p', { className: 'kb-muted-text' }, '没有匹配的模型;调整搜索关键词或类型筛选。')
|
|
1832
|
-
: null,
|
|
1833
|
-
state === 'ready' && report.groups.length > 0
|
|
1834
|
-
? h(
|
|
1835
|
-
'div',
|
|
1836
|
-
{ className: 'kb-model-scroll' },
|
|
1837
|
-
report.groups.map((group) =>
|
|
1838
|
-
h(
|
|
1839
|
-
'div',
|
|
1840
|
-
{ key: group.key, className: 'kb-model-group' },
|
|
1841
|
-
h(
|
|
1842
|
-
'div',
|
|
1843
|
-
{ className: 'kb-model-group-head' },
|
|
1844
|
-
h('p', { className: 'kb-model-group-title' }, group.label),
|
|
1845
|
-
h(Badge, { variant: 'outline' }, String(group.total))
|
|
1846
|
-
),
|
|
1847
|
-
h('ul', { className: 'kb-model-list' }, group.items.map(cardItem)),
|
|
1848
|
-
group.hidden > 0
|
|
1849
|
-
? h(
|
|
1850
|
-
Button,
|
|
1851
|
-
{
|
|
1852
|
-
variant: 'ghost',
|
|
1853
|
-
size: 'sm',
|
|
1854
|
-
className: 'kb-model-more',
|
|
1855
|
-
onClick: () =>
|
|
1856
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1857
|
-
},
|
|
1858
|
-
`显示更多 ${group.hidden}`
|
|
1859
|
-
)
|
|
1860
|
-
: null,
|
|
1861
|
-
group.expanded && group.total > MODEL_GROUP_LIMIT
|
|
1862
|
-
? h(
|
|
1863
|
-
Button,
|
|
1864
|
-
{
|
|
1865
|
-
variant: 'ghost',
|
|
1866
|
-
size: 'sm',
|
|
1867
|
-
className: 'kb-model-more',
|
|
1868
|
-
onClick: () =>
|
|
1869
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1870
|
-
},
|
|
1871
|
-
'收起'
|
|
1872
|
-
)
|
|
1873
|
-
: null
|
|
1874
|
-
)
|
|
1875
|
-
)
|
|
1876
|
-
)
|
|
1877
|
-
: null
|
|
1878
|
-
)
|
|
1879
|
-
)
|
|
1880
|
-
: null
|
|
1966
|
+
h(
|
|
1967
|
+
'div',
|
|
1968
|
+
{ className: 'kb-model-footer-actions' },
|
|
1969
|
+
wizard && typeof m.onSkip === 'function'
|
|
1970
|
+
? h(Button, { variant: 'outline', size: 'sm', onClick: m.onSkip }, '跳过,稍后同步')
|
|
1971
|
+
: null,
|
|
1972
|
+
!wizard && typeof m.onClose === 'function'
|
|
1973
|
+
? h(Button, { variant: 'outline', size: 'sm', onClick: m.onClose }, '取消')
|
|
1974
|
+
: null,
|
|
1975
|
+
syncButton()
|
|
1976
|
+
)
|
|
1881
1977
|
)
|
|
1882
1978
|
)
|
|
1883
1979
|
}
|
|
1884
1980
|
|
|
1885
|
-
function
|
|
1886
|
-
|
|
1981
|
+
function ModelSyncPanel({
|
|
1982
|
+
layout = 'workbench',
|
|
1983
|
+
autoLoad = false,
|
|
1984
|
+
autoRecommend = false,
|
|
1985
|
+
bindDefaultKb = false,
|
|
1986
|
+
onClose,
|
|
1987
|
+
onSkip,
|
|
1988
|
+
onDone
|
|
1989
|
+
} = {}) {
|
|
1887
1990
|
const [state, setState] = useState('idle')
|
|
1888
1991
|
const [models, setModels] = useState([])
|
|
1889
1992
|
const [error, setError] = useState('')
|
|
1890
|
-
const [
|
|
1891
|
-
const [
|
|
1993
|
+
const [selectedKeys, setSelectedKeys] = useState([])
|
|
1994
|
+
const [roles, setRoles] = useState({})
|
|
1995
|
+
const [syncedKeys, setSyncedKeys] = useState([])
|
|
1892
1996
|
const [query, setQuery] = useState('')
|
|
1893
1997
|
const [modelType, setModelType] = useState('all')
|
|
1894
1998
|
const [expanded, setExpanded] = useState({})
|
|
1895
|
-
const [
|
|
1896
|
-
const [
|
|
1897
|
-
const [
|
|
1999
|
+
const [syncing, setSyncing] = useState(false)
|
|
2000
|
+
const [syncProgress, setSyncProgress] = useState({ done: 0, total: 0 })
|
|
2001
|
+
const [syncSummary, setSyncSummary] = useState(null)
|
|
2002
|
+
const [syncError, setSyncError] = useState('')
|
|
2003
|
+
const [itemErrors, setItemErrors] = useState({})
|
|
1898
2004
|
const autoLoadRef = useRef(false)
|
|
1899
2005
|
|
|
1900
2006
|
const load = useCallback(async () => {
|
|
1901
2007
|
setState('loading')
|
|
1902
2008
|
setError('')
|
|
1903
2009
|
try {
|
|
1904
|
-
const
|
|
1905
|
-
|
|
2010
|
+
const [chatluna, weknora] = await Promise.allSettled([
|
|
2011
|
+
callAction('kb.models.chatluna', {}),
|
|
2012
|
+
callAction('kb.models.weknora', {})
|
|
2013
|
+
])
|
|
2014
|
+
if (chatluna.status === 'rejected') throw chatluna.reason
|
|
2015
|
+
const list = Array.isArray(chatluna.value?.models) ? chatluna.value.models : []
|
|
2016
|
+
const existing = weknora.status === 'fulfilled' ? syncedModelKeys(weknora.value) : new Set()
|
|
1906
2017
|
setModels(list)
|
|
1907
|
-
|
|
2018
|
+
setSyncedKeys([...existing])
|
|
2019
|
+
setSelectedKeys(autoRecommend ? recommendModelKeys(list, existing) : [])
|
|
2020
|
+
setRoles({})
|
|
1908
2021
|
setQuery('')
|
|
1909
2022
|
setModelType('all')
|
|
1910
2023
|
setExpanded({})
|
|
2024
|
+
setSyncSummary(null)
|
|
2025
|
+
setSyncError('')
|
|
2026
|
+
setItemErrors({})
|
|
1911
2027
|
setState('ready')
|
|
1912
2028
|
} catch (err) {
|
|
1913
2029
|
setError(apiErrorMessage(err))
|
|
1914
2030
|
setState('error')
|
|
1915
2031
|
}
|
|
1916
|
-
}, [])
|
|
2032
|
+
}, [autoRecommend])
|
|
1917
2033
|
|
|
1918
|
-
//
|
|
2034
|
+
// 工作台/向导首次出现时懒加载一次;不阻塞页面首屏。
|
|
1919
2035
|
useEffect(() => {
|
|
1920
|
-
if (!autoLoad ||
|
|
2036
|
+
if (!autoLoad || autoLoadRef.current || state !== 'idle') return
|
|
1921
2037
|
autoLoadRef.current = true
|
|
1922
2038
|
load()
|
|
1923
|
-
}, [autoLoad,
|
|
1924
|
-
|
|
1925
|
-
const
|
|
1926
|
-
const
|
|
1927
|
-
if (
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
2039
|
+
}, [autoLoad, state, load])
|
|
2040
|
+
|
|
2041
|
+
const sync = useCallback(async () => {
|
|
2042
|
+
const chosen = models.filter((item) => selectedKeys.includes(modelSelectionKey(item)))
|
|
2043
|
+
if (chosen.length === 0) return
|
|
2044
|
+
if (chosen.length > MODEL_SYNC_LIMIT) {
|
|
2045
|
+
setSyncError(`一次最多同步 ${MODEL_SYNC_LIMIT} 个模型,请减少勾选后再试。`)
|
|
2046
|
+
return
|
|
2047
|
+
}
|
|
2048
|
+
const items = chosen.map((item) => ({
|
|
2049
|
+
providerId: item.providerId,
|
|
2050
|
+
modelId: item.modelId,
|
|
2051
|
+
role: roleFor(item, roles)
|
|
2052
|
+
}))
|
|
2053
|
+
setSyncing(true)
|
|
2054
|
+
setSyncError('')
|
|
2055
|
+
setSyncSummary(null)
|
|
2056
|
+
setItemErrors({})
|
|
2057
|
+
setSyncProgress({ done: 0, total: items.length })
|
|
1931
2058
|
try {
|
|
1932
|
-
const
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
providerId: selected.providerId,
|
|
1936
|
-
modelId: selected.modelId
|
|
2059
|
+
const response = await callAction('kb.models.syncBatch', {
|
|
2060
|
+
items,
|
|
2061
|
+
bindDefaultKb: bindDefaultKb === true
|
|
1937
2062
|
})
|
|
1938
|
-
const
|
|
1939
|
-
|
|
2063
|
+
const applied = applySyncOutcome(
|
|
2064
|
+
{ models, selectedKeys, syncedKeys, roles },
|
|
2065
|
+
items,
|
|
2066
|
+
response
|
|
2067
|
+
)
|
|
2068
|
+
setSyncedKeys(applied.syncedKeys)
|
|
2069
|
+
setSelectedKeys(applied.selectedKeys)
|
|
2070
|
+
setItemErrors(applied.itemErrors)
|
|
2071
|
+
setSyncProgress({ done: items.length, total: items.length })
|
|
2072
|
+
setSyncSummary(applied.summary)
|
|
2073
|
+
if (applied.complete && typeof onDone === 'function') {
|
|
2074
|
+
onDone(applied.summary, applied.successes)
|
|
2075
|
+
}
|
|
1940
2076
|
} catch (err) {
|
|
1941
|
-
|
|
2077
|
+
setSyncError(apiErrorMessage(err))
|
|
1942
2078
|
} finally {
|
|
1943
|
-
|
|
2079
|
+
setSyncing(false)
|
|
1944
2080
|
}
|
|
1945
|
-
}, [models,
|
|
2081
|
+
}, [models, selectedKeys, roles, syncedKeys, bindDefaultKb, onDone])
|
|
2082
|
+
|
|
2083
|
+
const toggleGroup = useCallback(
|
|
2084
|
+
(keys, select) => {
|
|
2085
|
+
const list = Array.isArray(keys) ? keys : []
|
|
2086
|
+
setSelectedKeys((current) => {
|
|
2087
|
+
const next = new Set(current)
|
|
2088
|
+
for (const key of list) {
|
|
2089
|
+
if (select) next.add(key)
|
|
2090
|
+
else next.delete(key)
|
|
2091
|
+
}
|
|
2092
|
+
return [...next]
|
|
2093
|
+
})
|
|
2094
|
+
},
|
|
2095
|
+
[]
|
|
2096
|
+
)
|
|
1946
2097
|
|
|
1947
2098
|
return modelCopyView({
|
|
1948
|
-
open,
|
|
1949
2099
|
layout,
|
|
1950
2100
|
state,
|
|
1951
2101
|
models,
|
|
1952
2102
|
error,
|
|
1953
|
-
|
|
2103
|
+
selectedKeys,
|
|
2104
|
+
roles,
|
|
2105
|
+
syncedKeys,
|
|
1954
2106
|
query,
|
|
1955
2107
|
type: modelType,
|
|
1956
2108
|
expanded,
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2109
|
+
syncing,
|
|
2110
|
+
syncProgress,
|
|
2111
|
+
syncSummary,
|
|
2112
|
+
syncError,
|
|
2113
|
+
itemErrors,
|
|
2114
|
+
bindDefaultKb,
|
|
1963
2115
|
onLoad: load,
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2116
|
+
onToggle: (key) => {
|
|
2117
|
+
setSelectedKeys((current) =>
|
|
2118
|
+
current.includes(key) ? current.filter((item) => item !== key) : [...current, key]
|
|
2119
|
+
)
|
|
2120
|
+
setItemErrors((current) => {
|
|
2121
|
+
if (current[key] === undefined) return current
|
|
2122
|
+
const next = { ...current }
|
|
2123
|
+
delete next[key]
|
|
2124
|
+
return next
|
|
2125
|
+
})
|
|
1969
2126
|
},
|
|
2127
|
+
onGroupSelect: toggleGroup,
|
|
2128
|
+
onClear: () => {
|
|
2129
|
+
setSelectedKeys([])
|
|
2130
|
+
setRoles({})
|
|
2131
|
+
},
|
|
2132
|
+
onRoleChange: (key, role) => setRoles((current) => ({ ...current, [key]: role })),
|
|
1970
2133
|
onQueryChange: (value) => setQuery(value),
|
|
1971
2134
|
onTypeChange: (value) => setModelType(value === '' ? 'all' : value),
|
|
1972
2135
|
onToggleGroup: (key) =>
|
|
1973
2136
|
setExpanded((current) => ({ ...current, [key]: current[key] !== true })),
|
|
1974
|
-
|
|
2137
|
+
onSync: sync,
|
|
2138
|
+
onClose,
|
|
2139
|
+
onSkip
|
|
1975
2140
|
})
|
|
1976
2141
|
}
|
|
1977
2142
|
|
|
@@ -1979,6 +2144,9 @@ function ModelCopyPanel({ layout = 'card', autoLoad = false, onClose } = {}) {
|
|
|
1979
2144
|
// 结构:InstallWizard 持有全部表单/请求状态;WizardPanel 是纯渲染层,接收一个
|
|
1980
2145
|
// model,便于 SSR 桩测试逐步渲染 0..3。所有网络调用都经由 callAction 或原生
|
|
1981
2146
|
// fetch,绝不把密钥写进页面文本。
|
|
2147
|
+
//
|
|
2148
|
+
// 新版 OOBE:模式 → 安装并启动(自动补齐 OCR 依赖、自动拉起)→ 同步模型 →
|
|
2149
|
+
// 准备就绪。安装完成后的 deps/start 串联全部软降级,绝不用系统包失败卡死主流程。
|
|
1982
2150
|
|
|
1983
2151
|
function TextField({ id, label, value, onChange, placeholder, type, hint, disabled, autoComplete }) {
|
|
1984
2152
|
return h(
|
|
@@ -2041,7 +2209,7 @@ function installFeedback(install) {
|
|
|
2041
2209
|
: ''
|
|
2042
2210
|
return h(
|
|
2043
2211
|
Alert,
|
|
2044
|
-
{ 'aria-live': 'polite' },
|
|
2212
|
+
{ 'aria-live': 'polite', className: 'kb-alert-status' },
|
|
2045
2213
|
h(AlertTitle, null, installStateLabel(install.state)),
|
|
2046
2214
|
h(
|
|
2047
2215
|
AlertDescription,
|
|
@@ -2059,7 +2227,56 @@ function installFeedback(install) {
|
|
|
2059
2227
|
)
|
|
2060
2228
|
}
|
|
2061
2229
|
|
|
2062
|
-
const isOkay = (value) => value.state === 'ok'
|
|
2230
|
+
const isOkay = (value) => value.state === 'ok'
|
|
2231
|
+
|
|
2232
|
+
function platformInstallHint(data) {
|
|
2233
|
+
const platform = typeof data?.platform === 'string' ? data.platform : ''
|
|
2234
|
+
if (/darwin|mac/i.test(platform)) return 'brew install tesseract poppler'
|
|
2235
|
+
if (/alpine/i.test(platform)) return 'apk add --no-cache tesseract-ocr poppler-utils'
|
|
2236
|
+
return 'sudo apt install -y tesseract-ocr poppler-utils'
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
function ocrReadyOf(status, detect) {
|
|
2240
|
+
const fromDetect = detect !== null && typeof detect === 'object' ? ocrSummary(detect) : null
|
|
2241
|
+
if (fromDetect !== null && fromDetect.available) return fromDetect
|
|
2242
|
+
return ocrSummary(status)
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
/** deps 动作返回体里的非阻塞告警;安装器失败也只是一条 warning。 */
|
|
2246
|
+
export function depsSoftWarning(response) {
|
|
2247
|
+
if (response === null || typeof response !== 'object') return ''
|
|
2248
|
+
if (typeof response.warning === 'string' && response.warning.trim() !== '') return response.warning.trim()
|
|
2249
|
+
if (typeof response.reason === 'string' && response.reason.trim() !== '') return response.reason.trim()
|
|
2250
|
+
if (response.ok === false) {
|
|
2251
|
+
return typeof response.error?.message === 'string'
|
|
2252
|
+
? response.error.message
|
|
2253
|
+
: typeof response.error === 'string'
|
|
2254
|
+
? response.error
|
|
2255
|
+
: '本地 OCR 系统组件未能自动补齐'
|
|
2256
|
+
}
|
|
2257
|
+
return ''
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
export function depsFailureWarning(error) {
|
|
2261
|
+
const reason = apiErrorMessage(error)
|
|
2262
|
+
const detail = reason !== '' && !/unknown action|not registered|未注册/i.test(reason) ? `:${reason}` : ''
|
|
2263
|
+
return `本地 OCR 系统组件未能自动安装${detail}。文本 / Markdown / Office 解析仍可用;如需扫描件识别,请手动运行安装命令。`
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
/** 已安装且运行的实例重进向导时直达同步步;已安装未运行停在安装步自动拉起。 */
|
|
2267
|
+
export function initialWizardStep(status = {}, install = {}) {
|
|
2268
|
+
const installed = install.installed === true || status.installed === true
|
|
2269
|
+
const running = status.running === true
|
|
2270
|
+
if (installed && running) return 2
|
|
2271
|
+
if (installed) return 1
|
|
2272
|
+
return 0
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
/** 启动成功(或 live 状态翻到 running)后自动进入同步步;只会推进一次。 */
|
|
2276
|
+
export function wizardAdvanceAfterStart({ step, started, running }) {
|
|
2277
|
+
if (step !== 1) return null
|
|
2278
|
+
return started === true || running === true ? 2 : null
|
|
2279
|
+
}
|
|
2063
2280
|
|
|
2064
2281
|
function wizardBody(m) {
|
|
2065
2282
|
const step = m.step
|
|
@@ -2068,6 +2285,15 @@ function wizardBody(m) {
|
|
|
2068
2285
|
const embedding = m.embedding
|
|
2069
2286
|
|
|
2070
2287
|
if (step === 0) {
|
|
2288
|
+
const detected = m.detect
|
|
2289
|
+
const ocr = ocrReadyOf(status, detected.data)
|
|
2290
|
+
const platformText = detectSummary(detected.data)
|
|
2291
|
+
const ocrText =
|
|
2292
|
+
ocr.ready === true
|
|
2293
|
+
? '本地 OCR 组件已就绪 ✓'
|
|
2294
|
+
: ocr.available && ocr.ready === false
|
|
2295
|
+
? '本地 OCR 组件未就绪(安装步骤中可自动补齐)'
|
|
2296
|
+
: '尚未检测本地 OCR 组件'
|
|
2071
2297
|
return h(
|
|
2072
2298
|
'div',
|
|
2073
2299
|
{ className: 'kb-card-stack' },
|
|
@@ -2089,6 +2315,20 @@ function wizardBody(m) {
|
|
|
2089
2315
|
onClick: () => m.onMode('external')
|
|
2090
2316
|
})
|
|
2091
2317
|
),
|
|
2318
|
+
h(
|
|
2319
|
+
'div',
|
|
2320
|
+
{ className: 'kb-detect-row' },
|
|
2321
|
+
h('span', null, '环境预览'),
|
|
2322
|
+
h(
|
|
2323
|
+
'span',
|
|
2324
|
+
{ 'data-error': detected.state === 'error' ? 'true' : undefined },
|
|
2325
|
+
detected.state === 'loading'
|
|
2326
|
+
? '检测中…'
|
|
2327
|
+
: detected.state === 'error'
|
|
2328
|
+
? '检测失败'
|
|
2329
|
+
: `${platformText !== '' ? platformText : '未知平台'} · ${ocrText}`
|
|
2330
|
+
)
|
|
2331
|
+
),
|
|
2092
2332
|
m.mode === 'external'
|
|
2093
2333
|
? h(
|
|
2094
2334
|
Alert,
|
|
@@ -2109,25 +2349,30 @@ function wizardBody(m) {
|
|
|
2109
2349
|
embedding.baseUrl !== ''
|
|
2110
2350
|
? h(CodeValue, { value: embedding.baseUrl })
|
|
2111
2351
|
: h('p', { className: 'kb-muted-text' }, '尚未读取到 baseUrl。'),
|
|
2112
|
-
h('p', { className: 'kb-muted-text' }, '
|
|
2352
|
+
h('p', { className: 'kb-muted-text' }, '连通正常时可继续把 ChatLuna 模型同步到外部引擎。')
|
|
2113
2353
|
)
|
|
2114
2354
|
)
|
|
2115
2355
|
)
|
|
2116
|
-
:
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2356
|
+
: null,
|
|
2357
|
+
h(
|
|
2358
|
+
'div',
|
|
2359
|
+
{ className: 'kb-form-actions' },
|
|
2360
|
+
m.mode === 'external'
|
|
2361
|
+
? h(Button, { onClick: () => m.onStep(2) }, '下一步:同步模型')
|
|
2362
|
+
: h(Button, { onClick: () => m.onStep(1) }, '下一步:安装并启动')
|
|
2363
|
+
)
|
|
2121
2364
|
)
|
|
2122
2365
|
}
|
|
2123
2366
|
|
|
2124
2367
|
if (step === 1) {
|
|
2125
2368
|
const detected = m.detect
|
|
2126
2369
|
const platformText = detectSummary(detected.data)
|
|
2370
|
+
const ocr = ocrReadyOf(status, detected.data)
|
|
2371
|
+
const running = status.running === true || m.started === true
|
|
2127
2372
|
return h(
|
|
2128
2373
|
'div',
|
|
2129
2374
|
{ className: 'kb-card-stack' },
|
|
2130
|
-
h('p', { className: 'kb-section-lead' }, '
|
|
2375
|
+
h('p', { className: 'kb-section-lead' }, '安装并启动引擎'),
|
|
2131
2376
|
h(
|
|
2132
2377
|
'div',
|
|
2133
2378
|
{ className: 'kb-detect-row' },
|
|
@@ -2145,6 +2390,22 @@ function wizardBody(m) {
|
|
|
2145
2390
|
)
|
|
2146
2391
|
),
|
|
2147
2392
|
detected.state === 'error' && detected.error ? errorAlert(detected.error, '平台检测失败') : null,
|
|
2393
|
+
ocr.ready === true
|
|
2394
|
+
? h('p', { className: 'kb-ocr-ready' }, h(UiIcon, { name: 'check' }), '本地 OCR 组件已就绪 ✓')
|
|
2395
|
+
: h(
|
|
2396
|
+
'label',
|
|
2397
|
+
{ className: 'kb-check-row' },
|
|
2398
|
+
h(Checkbox, {
|
|
2399
|
+
checked: m.autoDeps !== false,
|
|
2400
|
+
onCheckedChange: (next) =>
|
|
2401
|
+
typeof m.onAutoDeps === 'function' ? m.onAutoDeps(next === true) : undefined
|
|
2402
|
+
}),
|
|
2403
|
+
h(
|
|
2404
|
+
'span',
|
|
2405
|
+
null,
|
|
2406
|
+
'自动补齐本地 OCR 解析组件(tesseract / poppler),以支持扫描件与图片识别'
|
|
2407
|
+
)
|
|
2408
|
+
),
|
|
2148
2409
|
h(
|
|
2149
2410
|
Tabs,
|
|
2150
2411
|
{ value: m.source, onValueChange: (value) => m.onSource(String(value)) },
|
|
@@ -2164,7 +2425,6 @@ function wizardBody(m) {
|
|
|
2164
2425
|
{ className: 'kb-card-stack' },
|
|
2165
2426
|
(() => {
|
|
2166
2427
|
const release = detected.data && typeof detected.data === 'object' ? detected.data.release : null
|
|
2167
|
-
const ocr = detected.data && typeof detected.data === 'object' ? detected.data.ocr : null
|
|
2168
2428
|
if (!release || release.available !== true) {
|
|
2169
2429
|
return h(
|
|
2170
2430
|
Alert,
|
|
@@ -2188,22 +2448,24 @@ function wizardBody(m) {
|
|
|
2188
2448
|
{ className: 'kb-muted-text' },
|
|
2189
2449
|
`平台 ${detected.data?.platformKey || detected.data?.platform || ''} · 下载后强制校验 SHA-256。`
|
|
2190
2450
|
),
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
)
|
|
2199
|
-
: null,
|
|
2451
|
+
h(
|
|
2452
|
+
'p',
|
|
2453
|
+
{ className: 'kb-muted-text' },
|
|
2454
|
+
ocr.ready
|
|
2455
|
+
? '本地高精度 OCR(内置 tessdata_best)已就绪。'
|
|
2456
|
+
: `扫描件/图片高精度 OCR 将在安装后自动补齐;如需手动安装:${platformInstallHint(detected.data)}`
|
|
2457
|
+
),
|
|
2200
2458
|
h(
|
|
2201
2459
|
'div',
|
|
2202
2460
|
{ className: 'kb-form-actions' },
|
|
2203
2461
|
h(
|
|
2204
2462
|
Button,
|
|
2205
2463
|
{ disabled: m.busy !== '' || install.active, onClick: m.onInstallRelease },
|
|
2206
|
-
m.busy === 'install'
|
|
2464
|
+
m.busy === 'install'
|
|
2465
|
+
? '准备安装…'
|
|
2466
|
+
: m.installed
|
|
2467
|
+
? '一键启动引擎'
|
|
2468
|
+
: '一键安装并启动'
|
|
2207
2469
|
)
|
|
2208
2470
|
)
|
|
2209
2471
|
)
|
|
@@ -2282,16 +2544,35 @@ function wizardBody(m) {
|
|
|
2282
2544
|
)
|
|
2283
2545
|
),
|
|
2284
2546
|
installFeedback(install),
|
|
2547
|
+
m.pipeline && m.pipeline.message !== ''
|
|
2548
|
+
? h('p', { className: 'kb-muted-text', role: 'status' }, m.pipeline.message)
|
|
2549
|
+
: null,
|
|
2550
|
+
m.deps && m.deps.warning !== ''
|
|
2551
|
+
? h(
|
|
2552
|
+
Alert,
|
|
2553
|
+
{ className: 'kb-alert-muted' },
|
|
2554
|
+
h(UiIcon, { name: 'alert-circle' }),
|
|
2555
|
+
h(AlertTitle, null, '本地 OCR 组件未自动补齐(不阻塞安装)'),
|
|
2556
|
+
h(AlertDescription, null, m.deps.warning)
|
|
2557
|
+
)
|
|
2558
|
+
: null,
|
|
2285
2559
|
m.installed
|
|
2286
2560
|
? h(
|
|
2287
2561
|
Alert,
|
|
2288
2562
|
{ className: 'kb-alert-muted', 'aria-live': 'polite' },
|
|
2289
2563
|
h(UiIcon, { name: 'check' }),
|
|
2290
|
-
h(AlertTitle, null, '安装完成'),
|
|
2291
|
-
h(
|
|
2564
|
+
h(AlertTitle, null, running ? '引擎已启动' : '安装完成'),
|
|
2565
|
+
h(
|
|
2566
|
+
AlertDescription,
|
|
2567
|
+
null,
|
|
2568
|
+
running
|
|
2569
|
+
? '正在进入模型同步;可随时点「上一步」回看安装结果。'
|
|
2570
|
+
: '正在自动补齐本地组件并启动引擎…'
|
|
2571
|
+
)
|
|
2292
2572
|
)
|
|
2293
2573
|
: null,
|
|
2294
2574
|
m.error !== '' && install.error === '' ? errorAlert(m.error) : null,
|
|
2575
|
+
m.startError !== '' ? errorAlert(m.startError, '启动失败') : null,
|
|
2295
2576
|
h(
|
|
2296
2577
|
'div',
|
|
2297
2578
|
{ className: 'kb-card-footer-actions' },
|
|
@@ -2301,80 +2582,35 @@ function wizardBody(m) {
|
|
|
2301
2582
|
: install.error !== ''
|
|
2302
2583
|
? h(Button, { disabled: m.busy !== '', onClick: m.onRetry }, '重试')
|
|
2303
2584
|
: null,
|
|
2304
|
-
install.
|
|
2305
|
-
? h(Button, {
|
|
2306
|
-
: null
|
|
2585
|
+
!running && (install.error !== '' || m.startError !== '')
|
|
2586
|
+
? h(Button, { disabled: m.busy !== '', onClick: m.onStart }, m.busy === 'start' ? '启动中…' : '重试启动')
|
|
2587
|
+
: null,
|
|
2588
|
+
running ? h(Button, { onClick: () => m.onStep(2) }, '下一步:同步模型') : null
|
|
2307
2589
|
)
|
|
2308
2590
|
)
|
|
2309
2591
|
}
|
|
2310
2592
|
|
|
2311
2593
|
if (step === 2) {
|
|
2312
|
-
const
|
|
2594
|
+
const running = status.running === true || m.started === true
|
|
2313
2595
|
return h(
|
|
2314
2596
|
'div',
|
|
2315
|
-
{ className: 'kb-card-stack' },
|
|
2316
|
-
h('p', { className: 'kb-section-lead' }, '
|
|
2317
|
-
h(
|
|
2318
|
-
Card,
|
|
2319
|
-
{ size: 'sm' },
|
|
2320
|
-
h(
|
|
2321
|
-
CardHeader,
|
|
2322
|
-
null,
|
|
2323
|
-
h(CardTitle, null, '当前配置'),
|
|
2324
|
-
h(
|
|
2325
|
-
CardDescription,
|
|
2326
|
-
null,
|
|
2327
|
-
embedding.baseUrl !== '' ? '默认复用 ChatLuna 已配置模型' : '尚未检测到 Embedding 配置'
|
|
2328
|
-
)
|
|
2329
|
-
),
|
|
2330
|
-
h(
|
|
2331
|
-
CardContent,
|
|
2332
|
-
null,
|
|
2333
|
-
embedding.baseUrl !== ''
|
|
2334
|
-
? h(Facts, {
|
|
2335
|
-
rows: [
|
|
2336
|
-
{ label: 'baseUrl', value: h(CodeValue, { value: embedding.baseUrl }) },
|
|
2337
|
-
{ label: '模型', value: embedding.model !== '' ? embedding.model : '—' },
|
|
2338
|
-
{ label: '维度', value: h('span', { className: 'kb-num' }, embedding.dimension ?? '—') },
|
|
2339
|
-
{
|
|
2340
|
-
label: 'API Key',
|
|
2341
|
-
value:
|
|
2342
|
-
embedding.hasKey || embedding.apiKeyFile !== ''
|
|
2343
|
-
? `已配置 ${embedding.apiKeyFile !== '' ? maskPath(embedding.apiKeyFile) : '••••'}`
|
|
2344
|
-
: '未配置'
|
|
2345
|
-
}
|
|
2346
|
-
]
|
|
2347
|
-
})
|
|
2348
|
-
: h(
|
|
2349
|
-
'p',
|
|
2350
|
-
{ className: 'kb-muted-text' },
|
|
2351
|
-
'尚未检测到 Embedding 配置;可在下方手动填写,或先在插件配置中复用 ChatLuna 模型。'
|
|
2352
|
-
)
|
|
2353
|
-
)
|
|
2354
|
-
),
|
|
2597
|
+
{ className: 'kb-card-stack kb-wizard-sync' },
|
|
2598
|
+
h('p', { className: 'kb-section-lead' }, '同步模型'),
|
|
2355
2599
|
h(
|
|
2356
|
-
'
|
|
2357
|
-
{ className: 'kb-
|
|
2358
|
-
|
|
2359
|
-
Button,
|
|
2360
|
-
{ variant: 'outline', disabled: test.state === 'running', onClick: m.onTest },
|
|
2361
|
-
test.state === 'running' ? '测试中…' : '测试连通性'
|
|
2362
|
-
),
|
|
2363
|
-
isOkay(test)
|
|
2364
|
-
? h(
|
|
2365
|
-
'span',
|
|
2366
|
-
{ className: 'kb-muted-text' },
|
|
2367
|
-
`连接正常 · 维度 ${test.dimension ?? '—'} · 延迟 ${
|
|
2368
|
-
test.latencyMs !== undefined ? `${Math.round(test.latencyMs)} ms` : '—'
|
|
2369
|
-
}`
|
|
2370
|
-
)
|
|
2371
|
-
: null,
|
|
2372
|
-
test.state === 'error' ? h('span', { className: 'kb-error-text' }, '测试失败') : null
|
|
2600
|
+
'p',
|
|
2601
|
+
{ className: 'kb-muted-text' },
|
|
2602
|
+
'引擎已在运行,勾选 ChatLuna 已配置的对话 / 视觉 / Embedding / ReRank 模型一次性同步到知识库;默认不预选已同步项。'
|
|
2373
2603
|
),
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2604
|
+
running
|
|
2605
|
+
? h(ModelSyncPanel, {
|
|
2606
|
+
layout: 'wizard',
|
|
2607
|
+
autoLoad: true,
|
|
2608
|
+
autoRecommend: true,
|
|
2609
|
+
bindDefaultKb: true,
|
|
2610
|
+
onSkip: () => m.onStep(3),
|
|
2611
|
+
onDone: (summary, items) =>
|
|
2612
|
+
typeof m.onSyncDone === 'function' ? m.onSyncDone(summary, items) : undefined
|
|
2613
|
+
})
|
|
2378
2614
|
: h(
|
|
2379
2615
|
Alert,
|
|
2380
2616
|
{ className: 'kb-alert-muted' },
|
|
@@ -2383,123 +2619,235 @@ function wizardBody(m) {
|
|
|
2383
2619
|
h(
|
|
2384
2620
|
AlertDescription,
|
|
2385
2621
|
null,
|
|
2386
|
-
'
|
|
2622
|
+
'引擎运行后才能写入模型;可先重试启动,或稍后再同步。'
|
|
2387
2623
|
)
|
|
2388
2624
|
),
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
CollapsibleTrigger,
|
|
2399
|
-
{
|
|
2400
|
-
render: h(Button, { variant: 'ghost', size: 'sm' })
|
|
2401
|
-
},
|
|
2402
|
-
h(UiIcon, { name: m.manualOpen ? 'chevron-down' : 'chevron-right' }),
|
|
2403
|
-
'手动配置(可选)'
|
|
2404
|
-
),
|
|
2405
|
-
h(
|
|
2406
|
-
CollapsibleContent,
|
|
2407
|
-
null,
|
|
2408
|
-
h(
|
|
2409
|
-
'div',
|
|
2410
|
-
{ className: 'kb-card-stack' },
|
|
2411
|
-
h(TextField, {
|
|
2412
|
-
id: 'kb-embedding-base',
|
|
2413
|
-
label: 'baseUrl',
|
|
2414
|
-
value: m.form.baseUrl,
|
|
2415
|
-
onChange: (value) => m.onForm('baseUrl', value),
|
|
2416
|
-
placeholder: 'https://api.openai.com/v1'
|
|
2417
|
-
}),
|
|
2418
|
-
h(TextField, {
|
|
2419
|
-
id: 'kb-embedding-model',
|
|
2420
|
-
label: '模型',
|
|
2421
|
-
value: m.form.model,
|
|
2422
|
-
onChange: (value) => m.onForm('model', value),
|
|
2423
|
-
placeholder: 'text-embedding-3-small'
|
|
2424
|
-
}),
|
|
2425
|
-
h(TextField, {
|
|
2426
|
-
id: 'kb-embedding-key',
|
|
2427
|
-
label: 'API Key',
|
|
2428
|
-
value: m.form.apiKey,
|
|
2429
|
-
onChange: (value) => m.onForm('apiKey', value),
|
|
2430
|
-
type: 'password',
|
|
2431
|
-
autoComplete: 'new-password',
|
|
2432
|
-
placeholder: '仅提交给本机服务,不回显'
|
|
2433
|
-
}),
|
|
2434
|
-
h(TextField, {
|
|
2435
|
-
id: 'kb-embedding-dimension',
|
|
2436
|
-
label: '维度(可选)',
|
|
2437
|
-
value: m.form.dimension,
|
|
2438
|
-
onChange: (value) => m.onForm('dimension', value),
|
|
2439
|
-
placeholder: '1536'
|
|
2440
|
-
}),
|
|
2625
|
+
running
|
|
2626
|
+
? h(
|
|
2627
|
+
Collapsible,
|
|
2628
|
+
{
|
|
2629
|
+
open: m.manualOpen,
|
|
2630
|
+
onOpenChange: (next) => {
|
|
2631
|
+
if (next !== m.manualOpen) m.onToggleManual()
|
|
2632
|
+
}
|
|
2633
|
+
},
|
|
2441
2634
|
h(
|
|
2442
|
-
|
|
2443
|
-
{
|
|
2444
|
-
|
|
2635
|
+
CollapsibleTrigger,
|
|
2636
|
+
{
|
|
2637
|
+
render: h(Button, { variant: 'ghost', size: 'sm' })
|
|
2638
|
+
},
|
|
2639
|
+
h(UiIcon, { name: m.manualOpen ? 'chevron-down' : 'chevron-right' }),
|
|
2640
|
+
'手动配置自定义 Embedding(可选)'
|
|
2641
|
+
),
|
|
2642
|
+
h(
|
|
2643
|
+
CollapsibleContent,
|
|
2644
|
+
null,
|
|
2445
2645
|
h(
|
|
2446
|
-
|
|
2447
|
-
{
|
|
2448
|
-
|
|
2646
|
+
'div',
|
|
2647
|
+
{ className: 'kb-card-stack' },
|
|
2648
|
+
embedding.baseUrl !== ''
|
|
2649
|
+
? h(
|
|
2650
|
+
'p',
|
|
2651
|
+
{ className: 'kb-muted-text' },
|
|
2652
|
+
`当前默认复用:${embedding.baseUrl}${embedding.model !== '' ? ` · ${embedding.model}` : ''}`
|
|
2653
|
+
)
|
|
2654
|
+
: h('p', { className: 'kb-muted-text' }, '尚未检测到 Embedding 配置;可手动填写。'),
|
|
2655
|
+
h(TextField, {
|
|
2656
|
+
id: 'kb-embedding-base',
|
|
2657
|
+
label: 'baseUrl',
|
|
2658
|
+
value: m.form.baseUrl,
|
|
2659
|
+
onChange: (value) => m.onForm('baseUrl', value),
|
|
2660
|
+
placeholder: 'https://api.openai.com/v1'
|
|
2661
|
+
}),
|
|
2662
|
+
h(TextField, {
|
|
2663
|
+
id: 'kb-embedding-model',
|
|
2664
|
+
label: '模型',
|
|
2665
|
+
value: m.form.model,
|
|
2666
|
+
onChange: (value) => m.onForm('model', value),
|
|
2667
|
+
placeholder: 'text-embedding-3-small'
|
|
2668
|
+
}),
|
|
2669
|
+
h(TextField, {
|
|
2670
|
+
id: 'kb-embedding-key',
|
|
2671
|
+
label: 'API Key',
|
|
2672
|
+
value: m.form.apiKey,
|
|
2673
|
+
onChange: (value) => m.onForm('apiKey', value),
|
|
2674
|
+
type: 'password',
|
|
2675
|
+
autoComplete: 'new-password',
|
|
2676
|
+
placeholder: '仅提交给本机服务,不回显'
|
|
2677
|
+
}),
|
|
2678
|
+
h(TextField, {
|
|
2679
|
+
id: 'kb-embedding-dimension',
|
|
2680
|
+
label: '维度(可选)',
|
|
2681
|
+
value: m.form.dimension,
|
|
2682
|
+
onChange: (value) => m.onForm('dimension', value),
|
|
2683
|
+
placeholder: '1536'
|
|
2684
|
+
}),
|
|
2685
|
+
h(
|
|
2686
|
+
'div',
|
|
2687
|
+
{ className: 'kb-form-actions' },
|
|
2688
|
+
h(
|
|
2689
|
+
Button,
|
|
2690
|
+
{ variant: 'outline', disabled: m.test.state === 'running', onClick: m.onTest },
|
|
2691
|
+
m.test.state === 'running' ? '测试中…' : '测试连通性'
|
|
2692
|
+
),
|
|
2693
|
+
isOkay(m.test)
|
|
2694
|
+
? h(
|
|
2695
|
+
'span',
|
|
2696
|
+
{ className: 'kb-muted-text' },
|
|
2697
|
+
`连接正常 · 维度 ${m.test.dimension ?? '—'}`
|
|
2698
|
+
)
|
|
2699
|
+
: null,
|
|
2700
|
+
h(
|
|
2701
|
+
Button,
|
|
2702
|
+
{ disabled: m.busy !== '', onClick: m.onSave },
|
|
2703
|
+
m.busy === 'save' ? '保存中…' : '保存配置'
|
|
2704
|
+
)
|
|
2705
|
+
),
|
|
2706
|
+
m.test.state === 'error' && m.test.error ? errorAlert(m.test.error, '连通性测试失败') : null,
|
|
2707
|
+
m.saved !== '' ? h('p', { className: 'kb-muted-text', role: 'status' }, m.saved) : null,
|
|
2708
|
+
m.formError !== '' ? errorAlert(m.formError, '保存失败') : null
|
|
2449
2709
|
)
|
|
2450
2710
|
)
|
|
2451
2711
|
)
|
|
2452
|
-
|
|
2453
|
-
),
|
|
2454
|
-
m.saved !== '' ? h('p', { className: 'kb-muted-text', role: 'status' }, m.saved) : null,
|
|
2455
|
-
m.formError !== '' ? errorAlert(m.formError, '保存失败') : null,
|
|
2712
|
+
: null,
|
|
2456
2713
|
h(
|
|
2457
2714
|
'div',
|
|
2458
2715
|
{ className: 'kb-card-footer-actions' },
|
|
2459
|
-
h(Button, { variant: 'outline', onClick: () => m.onStep(1) }, '
|
|
2460
|
-
|
|
2716
|
+
h(Button, { variant: 'outline', onClick: () => m.onStep(1) }, '上一步:安装与启动'),
|
|
2717
|
+
!running
|
|
2718
|
+
? h(
|
|
2719
|
+
Button,
|
|
2720
|
+
{ disabled: m.busy !== '', onClick: m.onStart },
|
|
2721
|
+
m.busy === 'start' ? '启动中…' : '重试启动'
|
|
2722
|
+
)
|
|
2723
|
+
: null
|
|
2461
2724
|
)
|
|
2462
2725
|
)
|
|
2463
2726
|
}
|
|
2464
2727
|
|
|
2465
2728
|
const running = status.running || m.started
|
|
2466
2729
|
const installed = install.installed || status.installed === true
|
|
2730
|
+
const ocr = ocrSummary(status)
|
|
2731
|
+
const summary = m.syncSummary !== null && typeof m.syncSummary === 'object' ? m.syncSummary : null
|
|
2732
|
+
const results = Array.isArray(summary?.results) ? summary.results : []
|
|
2733
|
+
const syncedRows = results
|
|
2734
|
+
.filter((entry) => !['failed', 'error'].includes(textOf(entry.status).toLowerCase()))
|
|
2735
|
+
.map((entry) => ({
|
|
2736
|
+
modelId: textOf(entry.createdModelId) || textOf(entry.modelId) || '—',
|
|
2737
|
+
name: textOf(entry.name) || textOf(entry.modelId) || '—',
|
|
2738
|
+
role: textOf(entry.role)
|
|
2739
|
+
}))
|
|
2740
|
+
const syncedCount = summary
|
|
2741
|
+
? (finite(summary.imported) ?? 0) + (finite(summary.skipped) ?? 0)
|
|
2742
|
+
: 0
|
|
2743
|
+
const ocrLabel =
|
|
2744
|
+
ocr.ready === true
|
|
2745
|
+
? '本地高精度 OCR 已就绪'
|
|
2746
|
+
: ocr.available && ocr.ready === false
|
|
2747
|
+
? `仅文本 / Office 解析就绪;手动安装:${platformInstallHint(m.detect?.data)}`
|
|
2748
|
+
: 'OCR 状态未知'
|
|
2467
2749
|
return h(
|
|
2468
2750
|
'div',
|
|
2469
2751
|
{ className: 'kb-card-stack' },
|
|
2470
|
-
h('p', { className: 'kb-section-lead' }, '
|
|
2752
|
+
h('p', { className: 'kb-section-lead' }, '准备就绪,开始使用'),
|
|
2471
2753
|
h(
|
|
2472
2754
|
'div',
|
|
2473
|
-
{ className: 'kb-
|
|
2474
|
-
h(StatusDot, { tone: running ? 'success' : 'offline' }),
|
|
2755
|
+
{ className: 'kb-done-overview' },
|
|
2475
2756
|
h(
|
|
2476
|
-
'
|
|
2477
|
-
{ className: 'kb-done-
|
|
2478
|
-
h(
|
|
2757
|
+
'div',
|
|
2758
|
+
{ className: 'kb-done-row' },
|
|
2759
|
+
h(StatusDot, { tone: running ? 'success' : 'offline' }),
|
|
2760
|
+
h(
|
|
2761
|
+
'span',
|
|
2762
|
+
{ className: 'kb-done-text' },
|
|
2763
|
+
h('strong', null, running ? '引擎运行中' : installed ? '引擎已安装,尚未启动' : '引擎尚未安装'),
|
|
2764
|
+
h(
|
|
2765
|
+
'span',
|
|
2766
|
+
{ className: 'kb-muted-text' },
|
|
2767
|
+
installed
|
|
2768
|
+
? `模式:${modeLabel(status.mode)}${status.port !== undefined ? ` · 端口 ${status.port}` : ''}`
|
|
2769
|
+
: '请返回上一步完成引擎安装。'
|
|
2770
|
+
)
|
|
2771
|
+
)
|
|
2772
|
+
),
|
|
2773
|
+
h(
|
|
2774
|
+
'div',
|
|
2775
|
+
{ className: 'kb-done-row' },
|
|
2776
|
+
h(StatusDot, { tone: ocr.ready === true ? 'success' : 'warning' }),
|
|
2777
|
+
h(
|
|
2778
|
+
'span',
|
|
2779
|
+
{ className: 'kb-done-text' },
|
|
2780
|
+
h('strong', null, ocr.ready === true ? '文档与 OCR 解析' : '文档解析'),
|
|
2781
|
+
h('span', { className: 'kb-muted-text' }, ocrLabel)
|
|
2782
|
+
)
|
|
2783
|
+
),
|
|
2784
|
+
h(
|
|
2785
|
+
'div',
|
|
2786
|
+
{ className: 'kb-done-row' },
|
|
2787
|
+
h(StatusDot, { tone: syncedCount > 0 ? 'success' : 'muted' }),
|
|
2479
2788
|
h(
|
|
2480
2789
|
'span',
|
|
2481
|
-
{ className: 'kb-
|
|
2482
|
-
|
|
2790
|
+
{ className: 'kb-done-text' },
|
|
2791
|
+
h(
|
|
2792
|
+
'strong',
|
|
2793
|
+
null,
|
|
2794
|
+
syncedCount > 0 ? `已同步 ${syncedCount} 个模型` : '尚未同步模型'
|
|
2795
|
+
),
|
|
2796
|
+
syncedRows.length > 0
|
|
2797
|
+
? h(
|
|
2798
|
+
'span',
|
|
2799
|
+
{ className: 'kb-done-models' },
|
|
2800
|
+
syncedRows.map((row) =>
|
|
2801
|
+
h(
|
|
2802
|
+
'span',
|
|
2803
|
+
{ key: `${row.role}:${row.modelId}`, className: 'kb-done-model' },
|
|
2804
|
+
h('span', { className: 'kb-model-model-id' }, row.name || row.modelId),
|
|
2805
|
+
h('span', { className: 'kb-done-model-role' }, `· ${modelRoleLabel(row.role)}`)
|
|
2806
|
+
)
|
|
2807
|
+
)
|
|
2808
|
+
)
|
|
2809
|
+
: h('span', { className: 'kb-muted-text' }, '可返回同步更多模型,或稍后在引擎状态中同步。'),
|
|
2810
|
+
summary?.boundEmbeddingModelId
|
|
2811
|
+
? h(
|
|
2812
|
+
'span',
|
|
2813
|
+
{ className: 'kb-muted-text' },
|
|
2814
|
+
`已自动绑定默认 Embedding:${summary.boundEmbeddingModelName || summary.boundEmbeddingModelId} ✓`
|
|
2815
|
+
)
|
|
2816
|
+
: null,
|
|
2817
|
+
summary?.boundSummaryModelId
|
|
2818
|
+
? h(
|
|
2819
|
+
'span',
|
|
2820
|
+
{ className: 'kb-muted-text' },
|
|
2821
|
+
`已自动绑定默认对话模型:${summary.boundSummaryModelName || summary.boundSummaryModelId} ✓`
|
|
2822
|
+
)
|
|
2823
|
+
: null
|
|
2483
2824
|
)
|
|
2484
2825
|
)
|
|
2485
2826
|
),
|
|
2827
|
+
m.deps && m.deps.warning !== ''
|
|
2828
|
+
? h(
|
|
2829
|
+
Alert,
|
|
2830
|
+
{ className: 'kb-alert-muted' },
|
|
2831
|
+
h(UiIcon, { name: 'alert-circle' }),
|
|
2832
|
+
h(AlertTitle, null, '本地 OCR 组件未能自动安装'),
|
|
2833
|
+
h(AlertDescription, null, m.deps.warning)
|
|
2834
|
+
)
|
|
2835
|
+
: null,
|
|
2486
2836
|
m.startError !== '' ? errorAlert(m.startError, '启动失败') : null,
|
|
2487
2837
|
h(
|
|
2488
2838
|
'div',
|
|
2489
2839
|
{ className: 'kb-card-footer-actions' },
|
|
2490
|
-
h(Button, { variant: 'outline', onClick: () => m.onStep(
|
|
2491
|
-
h(Button, { variant: 'outline', onClick: () => m.onStep(2) }, '配置 Embedding'),
|
|
2840
|
+
h(Button, { variant: 'outline', onClick: () => m.onStep(2) }, '返回同步更多模型'),
|
|
2492
2841
|
running
|
|
2493
2842
|
? h(Button, { onClick: m.onEnter }, '进入知识库')
|
|
2494
2843
|
: installed
|
|
2495
2844
|
? h(
|
|
2496
2845
|
Button,
|
|
2497
2846
|
{ disabled: m.busy !== '', onClick: m.onStart },
|
|
2498
|
-
m.busy === 'start' ? '启动中…' : '
|
|
2847
|
+
m.busy === 'start' ? '启动中…' : '重试启动'
|
|
2499
2848
|
)
|
|
2500
|
-
:
|
|
2501
|
-
)
|
|
2502
|
-
h('p', { className: 'kb-muted-text' }, '首次启动会创建默认知识库并写入 Embedding 配置,可能需要数十秒。')
|
|
2849
|
+
: h(Button, { onClick: () => m.onStep(1) }, '去安装')
|
|
2850
|
+
)
|
|
2503
2851
|
)
|
|
2504
2852
|
}
|
|
2505
2853
|
|
|
@@ -2516,27 +2864,23 @@ export function WizardPanel({ model }) {
|
|
|
2516
2864
|
'div',
|
|
2517
2865
|
{ className: 'kb-wizard-inner' },
|
|
2518
2866
|
h(
|
|
2519
|
-
|
|
2520
|
-
|
|
2867
|
+
'div',
|
|
2868
|
+
{ className: 'kb-wizard-header' },
|
|
2521
2869
|
h(
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
h(
|
|
2525
|
-
h(
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
h(Button, { variant: 'outline', size: 'sm', onClick: m.onDismiss }, '稍后设置')
|
|
2531
|
-
)
|
|
2532
|
-
: null
|
|
2870
|
+
'div',
|
|
2871
|
+
{ className: 'kb-wizard-heading' },
|
|
2872
|
+
h('h2', { className: 'kb-wizard-title' }, '知识库配置向导'),
|
|
2873
|
+
h(
|
|
2874
|
+
'p',
|
|
2875
|
+
{ className: 'kb-wizard-desc' },
|
|
2876
|
+
'安装并启动本地知识库引擎,直接完成模型同步后即可使用。'
|
|
2877
|
+
)
|
|
2533
2878
|
),
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
null
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
)
|
|
2879
|
+
m.onDismiss
|
|
2880
|
+
? h(Button, { variant: 'outline', size: 'sm', onClick: m.onDismiss }, '稍后设置')
|
|
2881
|
+
: null
|
|
2882
|
+
),
|
|
2883
|
+
h('div', { className: 'kb-wizard-body' }, h(WizardSteps, { step: m.step }), wizardBody(m))
|
|
2540
2884
|
)
|
|
2541
2885
|
)
|
|
2542
2886
|
)
|
|
@@ -2544,17 +2888,8 @@ export function WizardPanel({ model }) {
|
|
|
2544
2888
|
|
|
2545
2889
|
const INSTALL_AUTO_ADVANCE_MS = 600
|
|
2546
2890
|
|
|
2547
|
-
/**
|
|
2548
|
-
* 安装完成跃迁:只有「此前未安装 → 现在已安装」且仍停在安装/配置步时才自动前进。
|
|
2549
|
-
* 600ms 延迟仅用于展示完成反馈;向导组件本身始终保持挂载。
|
|
2550
|
-
*/
|
|
2551
|
-
export function installAdvance({ previousInstalled, installed, step }) {
|
|
2552
|
-
if (installed !== true || previousInstalled === true) return null
|
|
2553
|
-
return step === 0 || step === 1 ? 2 : null
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
2891
|
function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
2557
|
-
const [step, setStep] = useState(
|
|
2892
|
+
const [step, setStep] = useState(() => initialWizardStep(status, install))
|
|
2558
2893
|
const [mode, setMode] = useState(status.mode === 'external' ? 'external' : 'lite')
|
|
2559
2894
|
const [detect, setDetect] = useState({ state: 'idle' })
|
|
2560
2895
|
const [source, setSource] = useState('release')
|
|
@@ -2569,13 +2904,20 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2569
2904
|
const [saved, setSaved] = useState('')
|
|
2570
2905
|
const [formError, setFormError] = useState('')
|
|
2571
2906
|
const [started, setStarted] = useState(false)
|
|
2907
|
+
const [startFallback, setStartFallback] = useState(false)
|
|
2572
2908
|
const [startError, setStartError] = useState('')
|
|
2909
|
+
const [autoDeps, setAutoDeps] = useState(true)
|
|
2910
|
+
const [deps, setDeps] = useState({ state: 'idle', warning: '' })
|
|
2911
|
+
const [pipeline, setPipeline] = useState({ phase: '', message: '' })
|
|
2912
|
+
const [syncSummary, setSyncSummary] = useState(null)
|
|
2573
2913
|
const lastRequest = useRef(null)
|
|
2574
2914
|
const lastFile = useRef(null)
|
|
2915
|
+
const autoFlow = useRef(false)
|
|
2916
|
+
const advanceOnce = useRef(false)
|
|
2575
2917
|
|
|
2576
|
-
//
|
|
2918
|
+
// 进入选择模式/安装步都探测平台,Step 0 的环境预览才有数据;失败可重进重试。
|
|
2577
2919
|
useEffect(() => {
|
|
2578
|
-
if (step !== 1) return
|
|
2920
|
+
if (step !== 0 && step !== 1) return
|
|
2579
2921
|
let live = true
|
|
2580
2922
|
setDetect({ state: 'loading' })
|
|
2581
2923
|
callAction('kb.detect', {})
|
|
@@ -2590,19 +2932,76 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2590
2932
|
}
|
|
2591
2933
|
}, [step])
|
|
2592
2934
|
|
|
2593
|
-
// 引擎安装完成时允许直接进下一步,但保留用户手动确认。
|
|
2594
2935
|
const installed = install.installed || status.installed === true
|
|
2595
|
-
const wasInstalled = useRef(installed)
|
|
2596
2936
|
|
|
2597
|
-
|
|
2937
|
+
const startEngine = useCallback(async () => {
|
|
2938
|
+
setBusy('start')
|
|
2939
|
+
setStartError('')
|
|
2940
|
+
try {
|
|
2941
|
+
await callAction('kb.start', {})
|
|
2942
|
+
setStarted(true)
|
|
2943
|
+
} catch (err) {
|
|
2944
|
+
setStartError(apiErrorMessage(err))
|
|
2945
|
+
} finally {
|
|
2946
|
+
setBusy('')
|
|
2947
|
+
}
|
|
2948
|
+
}, [])
|
|
2949
|
+
|
|
2950
|
+
// 安装完成后自动串联:补齐 OCR 依赖(失败软降级)→ 拉起并初始化。绝不阻塞主流程。
|
|
2951
|
+
useEffect(() => {
|
|
2952
|
+
if (step !== 1 || !installed || autoFlow.current || mode === 'external') return undefined
|
|
2953
|
+
autoFlow.current = true
|
|
2954
|
+
let live = true
|
|
2955
|
+
const run = async () => {
|
|
2956
|
+
let warning = ''
|
|
2957
|
+
if (autoDeps !== false) {
|
|
2958
|
+
if (live) setPipeline({ phase: 'deps', message: '正在补齐本地 OCR 组件(tesseract / poppler)…' })
|
|
2959
|
+
try {
|
|
2960
|
+
const response = await callAction('kb.install.deps', {})
|
|
2961
|
+
warning = depsSoftWarning(response)
|
|
2962
|
+
} catch (err) {
|
|
2963
|
+
warning = depsFailureWarning(err)
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
if (!live) return
|
|
2967
|
+
setDeps({ state: 'done', warning })
|
|
2968
|
+
setPipeline({ phase: 'starting', message: '正在拉起并初始化知识库引擎…' })
|
|
2969
|
+
try {
|
|
2970
|
+
await callAction('kb.start', {})
|
|
2971
|
+
if (live) setStarted(true)
|
|
2972
|
+
} catch (err) {
|
|
2973
|
+
if (live) setStartError(apiErrorMessage(err))
|
|
2974
|
+
if (live) setPipeline({ phase: 'error', message: '' })
|
|
2975
|
+
return
|
|
2976
|
+
}
|
|
2977
|
+
if (live) setPipeline({ phase: 'done', message: '' })
|
|
2978
|
+
}
|
|
2979
|
+
run()
|
|
2980
|
+
return () => {
|
|
2981
|
+
live = false
|
|
2982
|
+
}
|
|
2983
|
+
}, [step, installed, autoDeps, mode])
|
|
2984
|
+
|
|
2985
|
+
// 等待 live 状态翻到 running;状态通道异常时 5 秒后按启动返回值兜底推进。
|
|
2986
|
+
useEffect(() => {
|
|
2987
|
+
if (started !== true) return undefined
|
|
2988
|
+
const timer = setTimeout(() => setStartFallback(true), 5000)
|
|
2989
|
+
return () => clearTimeout(timer)
|
|
2990
|
+
}, [started])
|
|
2991
|
+
|
|
2992
|
+
// 启动成功后平滑推进到同步步;只推进一次,避免用户回看安装步时被再次弹走。
|
|
2598
2993
|
useEffect(() => {
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2994
|
+
if (advanceOnce.current) return undefined
|
|
2995
|
+
const target = wizardAdvanceAfterStart({
|
|
2996
|
+
step,
|
|
2997
|
+
started: startFallback === true,
|
|
2998
|
+
running: status.running === true && started === true
|
|
2999
|
+
})
|
|
2602
3000
|
if (target === null) return undefined
|
|
3001
|
+
advanceOnce.current = true
|
|
2603
3002
|
const timer = setTimeout(() => setStep(target), INSTALL_AUTO_ADVANCE_MS)
|
|
2604
3003
|
return () => clearTimeout(timer)
|
|
2605
|
-
}, [
|
|
3004
|
+
}, [step, started, startFallback, status.running])
|
|
2606
3005
|
|
|
2607
3006
|
const submitUrl = useCallback(async (payload) => {
|
|
2608
3007
|
setBusy('install')
|
|
@@ -2635,6 +3034,10 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2635
3034
|
|
|
2636
3035
|
const onInstallRelease = useCallback(async () => {
|
|
2637
3036
|
if (install.active) return
|
|
3037
|
+
if (installed) {
|
|
3038
|
+
await startEngine()
|
|
3039
|
+
return
|
|
3040
|
+
}
|
|
2638
3041
|
const release = detect.data && typeof detect.data === 'object' ? detect.data.release : null
|
|
2639
3042
|
if (!release || release.available !== true) {
|
|
2640
3043
|
setError(release?.error || '当前没有可用的发布清单')
|
|
@@ -2651,7 +3054,7 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2651
3054
|
} finally {
|
|
2652
3055
|
setBusy('')
|
|
2653
3056
|
}
|
|
2654
|
-
}, [detect.data, install.active])
|
|
3057
|
+
}, [detect.data, install.active, installed, startEngine])
|
|
2655
3058
|
|
|
2656
3059
|
const onUpload = useCallback(
|
|
2657
3060
|
async (file) => {
|
|
@@ -2768,17 +3171,9 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2768
3171
|
}
|
|
2769
3172
|
}, [form, install.embedding])
|
|
2770
3173
|
|
|
2771
|
-
const
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
try {
|
|
2775
|
-
await callAction('kb.start', {})
|
|
2776
|
-
setStarted(true)
|
|
2777
|
-
} catch (err) {
|
|
2778
|
-
setStartError(apiErrorMessage(err))
|
|
2779
|
-
} finally {
|
|
2780
|
-
setBusy('')
|
|
2781
|
-
}
|
|
3174
|
+
const onSyncDone = useCallback((summary) => {
|
|
3175
|
+
setSyncSummary(summary)
|
|
3176
|
+
setStep(3)
|
|
2782
3177
|
}, [])
|
|
2783
3178
|
|
|
2784
3179
|
const model = {
|
|
@@ -2802,6 +3197,10 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2802
3197
|
formError,
|
|
2803
3198
|
started,
|
|
2804
3199
|
startError,
|
|
3200
|
+
autoDeps,
|
|
3201
|
+
deps,
|
|
3202
|
+
pipeline,
|
|
3203
|
+
syncSummary,
|
|
2805
3204
|
onStep: setStep,
|
|
2806
3205
|
onMode: setMode,
|
|
2807
3206
|
onSource: setSource,
|
|
@@ -2816,7 +3215,9 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2816
3215
|
onForm: (key, value) => setForm((current) => ({ ...current, [key]: value })),
|
|
2817
3216
|
onTest,
|
|
2818
3217
|
onSave,
|
|
2819
|
-
onStart,
|
|
3218
|
+
onStart: startEngine,
|
|
3219
|
+
onAutoDeps: setAutoDeps,
|
|
3220
|
+
onSyncDone,
|
|
2820
3221
|
onEnter,
|
|
2821
3222
|
onDismiss
|
|
2822
3223
|
}
|
|
@@ -4041,7 +4442,7 @@ function LogConsole({
|
|
|
4041
4442
|
/** 左栏档案卡暂不进入 UI;组件保留,便于以后恢复。 */
|
|
4042
4443
|
const SHOW_ENGINE_RAIL = false
|
|
4043
4444
|
|
|
4044
|
-
/**
|
|
4445
|
+
/** 低频模型同步:Dialog 覆盖层,关闭后日志 DOM/滚动位置完全不变。 */
|
|
4045
4446
|
export function ModelCopyDialog({ open = false, onOpenChange, children }) {
|
|
4046
4447
|
const close = () => {
|
|
4047
4448
|
if (typeof onOpenChange === 'function') onOpenChange(false)
|
|
@@ -4060,7 +4461,12 @@ export function ModelCopyDialog({ open = false, onOpenChange, children }) {
|
|
|
4060
4461
|
children !== undefined
|
|
4061
4462
|
? children
|
|
4062
4463
|
: open === true
|
|
4063
|
-
? h(
|
|
4464
|
+
? h(ModelSyncPanel, {
|
|
4465
|
+
layout: 'workbench',
|
|
4466
|
+
autoLoad: true,
|
|
4467
|
+
bindDefaultKb: true,
|
|
4468
|
+
onClose: close
|
|
4469
|
+
})
|
|
4064
4470
|
: null
|
|
4065
4471
|
)
|
|
4066
4472
|
)
|
|
@@ -4228,8 +4634,8 @@ export function EngineTab({ status, actions, retrying, onRetry, onWizard }) {
|
|
|
4228
4634
|
h(
|
|
4229
4635
|
Button,
|
|
4230
4636
|
{ variant: 'ghost', size: 'sm', onClick: () => setModelOpen(true) },
|
|
4231
|
-
h(UiIcon, { name: '
|
|
4232
|
-
'
|
|
4637
|
+
h(UiIcon, { name: 'refresh' }),
|
|
4638
|
+
'同步模型'
|
|
4233
4639
|
)
|
|
4234
4640
|
)
|
|
4235
4641
|
),
|