chatluna-plugin-kb 0.1.7 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +52 -15
- package/package.json +1 -1
- package/src/engine/deps-installer.mjs +410 -0
- package/src/webui/install-routes.mjs +72 -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 +137 -54
- package/web/client.js +1273 -655
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: '失败',
|
|
@@ -244,6 +245,88 @@ function wizardVisible(status) {
|
|
|
244
245
|
return status.installed === false
|
|
245
246
|
}
|
|
246
247
|
|
|
248
|
+
/**
|
|
249
|
+
* 向导会话锁:idle 只在首次可展示时进入 active;active/dismissed 是显式状态,
|
|
250
|
+
* 安装或启动带来的 installed/running 翻转绝不中途卸载正在使用的 InstallWizard。
|
|
251
|
+
*/
|
|
252
|
+
export function advanceWizardSession(session, status) {
|
|
253
|
+
if (session === 'active' || session === 'dismissed') return session
|
|
254
|
+
return wizardVisible(status) ? 'active' : 'idle'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** 同源 WeKnora 精简前端会写这些键;换实例后旧值指向别的 jwt-secret,必须清场。 */
|
|
258
|
+
const WEKNORA_SESSION_KEYS = [
|
|
259
|
+
'weknora_token',
|
|
260
|
+
'weknora_refresh_token',
|
|
261
|
+
'weknora_user',
|
|
262
|
+
'weknora_tenant',
|
|
263
|
+
'weknora_knowledge_bases',
|
|
264
|
+
'weknora_current_kb',
|
|
265
|
+
'weknora_selected_tenant_id',
|
|
266
|
+
'weknora_selected_tenant_name',
|
|
267
|
+
'weknora_memberships'
|
|
268
|
+
]
|
|
269
|
+
|
|
270
|
+
/** 记录当前 iframe 属于哪个引擎实例;指纹一致时绝不重复清缓存。 */
|
|
271
|
+
export const WEKNORA_INSTANCE_KEY = 'chatluna-kb:weknora-instance'
|
|
272
|
+
|
|
273
|
+
function localStorageOf(storage) {
|
|
274
|
+
if (storage !== undefined) return storage
|
|
275
|
+
try {
|
|
276
|
+
return typeof localStorage !== 'undefined' ? localStorage : null
|
|
277
|
+
} catch {
|
|
278
|
+
return null
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** 清理同源旧 WeKnora 会话;返回实际删除的键数量。隐私模式失败不阻断进入知识库。 */
|
|
283
|
+
export function clearStaleWeKnoraSession(storage) {
|
|
284
|
+
const store = localStorageOf(storage)
|
|
285
|
+
if (!store) return 0
|
|
286
|
+
let removed = 0
|
|
287
|
+
for (const key of WEKNORA_SESSION_KEYS) {
|
|
288
|
+
try {
|
|
289
|
+
if (store.getItem(key) === null) continue
|
|
290
|
+
store.removeItem(key)
|
|
291
|
+
removed += 1
|
|
292
|
+
} catch {
|
|
293
|
+
// 单个键不可写不影响其余键的清理。
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return removed
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** 引擎实例指纹:kbId 与 readyAt 共同标识一次启动的 WeKnora 实例。 */
|
|
300
|
+
export function weknoraInstanceFingerprint(status) {
|
|
301
|
+
const kbId = textOf(status?.kbId)
|
|
302
|
+
const readyAt = finite(status?.readyAt) ?? 0
|
|
303
|
+
if (kbId === '' && readyAt === 0) return ''
|
|
304
|
+
return `${kbId}@${readyAt}`
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 实例身份变化(kbId/readyAt 且本地指纹不一致)时清理旧会话,返回是否需要重载 iframe。
|
|
309
|
+
* 首次只记录指纹,避免每次重渲染或首次加载都清掉可用缓存。
|
|
310
|
+
*/
|
|
311
|
+
export function syncWeKnoraInstance(status, storage) {
|
|
312
|
+
const store = localStorageOf(storage)
|
|
313
|
+
const fingerprint = weknoraInstanceFingerprint(status)
|
|
314
|
+
if (!store || fingerprint === '') return false
|
|
315
|
+
let previous = null
|
|
316
|
+
try {
|
|
317
|
+
previous = store.getItem(WEKNORA_INSTANCE_KEY)
|
|
318
|
+
} catch {
|
|
319
|
+
return false
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
store.setItem(WEKNORA_INSTANCE_KEY, fingerprint)
|
|
323
|
+
} catch {
|
|
324
|
+
// 指纹写不进去只影响下一次判定,不影响本次清理。
|
|
325
|
+
}
|
|
326
|
+
if (previous === null || previous === fingerprint) return false
|
|
327
|
+
return clearStaleWeKnoraSession(store) > 0
|
|
328
|
+
}
|
|
329
|
+
|
|
247
330
|
/** 非 ASCII 文件名不能直接进 HTTP 头;安全时原样发送,否则百分号编码。 */
|
|
248
331
|
function headerFileName(name) {
|
|
249
332
|
return /^[\x20-\x7e]*$/.test(name) ? name : encodeURIComponent(name)
|
|
@@ -320,6 +403,8 @@ export function viewStatus(snapshot) {
|
|
|
320
403
|
mode: typeof data.mode === 'string' ? data.mode : '',
|
|
321
404
|
managed: data.managed !== false && data.mode !== 'external',
|
|
322
405
|
installed: typeof data.installed === 'boolean' ? data.installed : undefined,
|
|
406
|
+
kbId: textOf(data.kbId),
|
|
407
|
+
readyAt: finite(data.readyAt) ?? 0,
|
|
323
408
|
running: data.running === true,
|
|
324
409
|
ready: data.ready === true || data.running === true,
|
|
325
410
|
unit: unitCandidate === undefined ? '' : unitCandidate.trim(),
|
|
@@ -1195,7 +1280,7 @@ function engineOfflineCard(status, actions, options) {
|
|
|
1195
1280
|
)
|
|
1196
1281
|
}
|
|
1197
1282
|
|
|
1198
|
-
// ---- 从 ChatLuna
|
|
1283
|
+
// ---- 从 ChatLuna 同步模型配置 ---------------------------------------------
|
|
1199
1284
|
// 列表只来自服务端脱敏元数据;页面从不接收、保存或展示 API Key。
|
|
1200
1285
|
const MODEL_TYPE_LABELS = {
|
|
1201
1286
|
chat: '对话模型',
|
|
@@ -1204,9 +1289,12 @@ const MODEL_TYPE_LABELS = {
|
|
|
1204
1289
|
rerank: 'ReRank 模型'
|
|
1205
1290
|
}
|
|
1206
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
|
|
1207
1295
|
|
|
1208
1296
|
function modelRoleLabel(role) {
|
|
1209
|
-
return role
|
|
1297
|
+
return MODEL_ROLE_LABELS[role] ?? 'Embedding'
|
|
1210
1298
|
}
|
|
1211
1299
|
|
|
1212
1300
|
function importRolesFor(item) {
|
|
@@ -1221,17 +1309,72 @@ function shortenUrl(value, max = 52) {
|
|
|
1221
1309
|
return text.length <= max ? text : `${text.slice(0, max - 1)}…`
|
|
1222
1310
|
}
|
|
1223
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
|
+
|
|
1224
1321
|
function modelSelectionKey(item) {
|
|
1225
1322
|
return `${item?.providerId ?? ''}\u0000${item?.modelId ?? ''}\u0000${item?.type ?? ''}`
|
|
1226
1323
|
}
|
|
1227
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
|
+
|
|
1228
1372
|
const MODEL_FILTER_LABELS = {
|
|
1229
1373
|
chat: '对话',
|
|
1230
1374
|
embedding: 'Embedding',
|
|
1231
1375
|
vlm: 'VLM',
|
|
1232
1376
|
rerank: 'ReRank'
|
|
1233
1377
|
}
|
|
1234
|
-
const MODEL_GROUP_LIMIT = 5
|
|
1235
1378
|
|
|
1236
1379
|
const providerGroupOf = (item) => {
|
|
1237
1380
|
const label = typeof item?.providerLabel === 'string' ? item.providerLabel.trim() : ''
|
|
@@ -1248,17 +1391,62 @@ export function modelProviderLabel(value) {
|
|
|
1248
1391
|
return stripped === '' ? raw : stripped
|
|
1249
1392
|
}
|
|
1250
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
|
+
|
|
1251
1433
|
/**
|
|
1252
|
-
*
|
|
1434
|
+
* 模型同步列表的搜索/类型筛选/厂商分组(纯函数,SSR 与单测共用)。
|
|
1253
1435
|
* - 类型计数与 chips 基于完整目录,只展示有模型的类型;
|
|
1254
|
-
* - 每个厂商默认最多 5
|
|
1436
|
+
* - 每个厂商默认最多 5 行;已勾选行自动展开到可见范围。
|
|
1255
1437
|
* @returns {{matched: object[], counts: Record<string, number>, typeOptions: object[], activeType: string, groups: object[], empty: boolean}}
|
|
1256
1438
|
*/
|
|
1257
1439
|
export function modelCopyReport(models, options = {}) {
|
|
1258
1440
|
const list = Array.isArray(models) ? models.filter((item) => item !== null && typeof item === 'object') : []
|
|
1259
1441
|
const query = typeof options.query === 'string' ? options.query.trim() : ''
|
|
1260
1442
|
const requestedType = typeof options.type === 'string' && options.type !== '' ? options.type : 'all'
|
|
1261
|
-
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)
|
|
1262
1450
|
const expanded = options.expanded !== null && typeof options.expanded === 'object' ? options.expanded : {}
|
|
1263
1451
|
const matched =
|
|
1264
1452
|
query === ''
|
|
@@ -1290,7 +1478,7 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1290
1478
|
}
|
|
1291
1479
|
const groups = []
|
|
1292
1480
|
for (const [key, items] of groupMap) {
|
|
1293
|
-
const selectedIndex = items.findIndex((item) => modelSelectionKey(item)
|
|
1481
|
+
const selectedIndex = items.findIndex((item) => selectedSet.has(modelSelectionKey(item)))
|
|
1294
1482
|
const isExpanded = expanded[key] === true
|
|
1295
1483
|
const limit = isExpanded
|
|
1296
1484
|
? items.length
|
|
@@ -1302,6 +1490,7 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1302
1490
|
key,
|
|
1303
1491
|
label: modelProviderLabel(key),
|
|
1304
1492
|
items: visible,
|
|
1493
|
+
allItems: items,
|
|
1305
1494
|
total: items.length,
|
|
1306
1495
|
hidden: items.length - visible.length,
|
|
1307
1496
|
expanded: isExpanded,
|
|
@@ -1311,583 +1500,643 @@ export function modelCopyReport(models, options = {}) {
|
|
|
1311
1500
|
return { matched, counts, typeOptions, activeType, groups, empty: typed.length === 0 }
|
|
1312
1501
|
}
|
|
1313
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
|
+
|
|
1314
1551
|
/**
|
|
1315
|
-
*
|
|
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
|
+
|
|
1614
|
+
/**
|
|
1615
|
+
* 纯渲染层:多选同步工作台,弹窗与向导共用。
|
|
1316
1616
|
* @param {{
|
|
1317
|
-
*
|
|
1318
|
-
* layout?: 'workbench'|'card',
|
|
1617
|
+
* layout?: 'workbench'|'wizard',
|
|
1319
1618
|
* state: 'idle'|'loading'|'ready'|'error',
|
|
1320
1619
|
* models: Array<object>,
|
|
1321
1620
|
* error?: string,
|
|
1322
|
-
*
|
|
1621
|
+
* selectedKeys?: string[],
|
|
1622
|
+
* roles?: object,
|
|
1623
|
+
* syncedKeys?: string[]|Set<string>,
|
|
1323
1624
|
* query?: string,
|
|
1324
1625
|
* type?: string,
|
|
1325
1626
|
* expanded?: object,
|
|
1326
|
-
*
|
|
1327
|
-
*
|
|
1328
|
-
*
|
|
1329
|
-
*
|
|
1627
|
+
* syncing?: boolean,
|
|
1628
|
+
* syncProgress?: {done: number, total: number},
|
|
1629
|
+
* syncSummary?: object|null,
|
|
1630
|
+
* syncError?: string,
|
|
1631
|
+
* itemErrors?: object,
|
|
1632
|
+
* bindDefaultKb?: boolean,
|
|
1330
1633
|
* onLoad?: Function,
|
|
1331
|
-
*
|
|
1634
|
+
* onToggle?: Function,
|
|
1635
|
+
* onGroupSelect?: Function,
|
|
1636
|
+
* onClear?: Function,
|
|
1637
|
+
* onRoleChange?: Function,
|
|
1332
1638
|
* onQueryChange?: Function,
|
|
1333
1639
|
* onTypeChange?: Function,
|
|
1334
1640
|
* onToggleGroup?: Function,
|
|
1335
|
-
*
|
|
1641
|
+
* onSync?: Function,
|
|
1642
|
+
* onClose?: Function,
|
|
1643
|
+
* onSkip?: Function
|
|
1336
1644
|
* }} m
|
|
1337
1645
|
*/
|
|
1338
1646
|
export function modelCopyView(m = {}) {
|
|
1339
1647
|
const models = Array.isArray(m.models) ? m.models : []
|
|
1340
|
-
const
|
|
1341
|
-
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)
|
|
1342
1652
|
const query = typeof m.query === 'string' ? m.query : ''
|
|
1343
1653
|
const report = modelCopyReport(models, {
|
|
1344
1654
|
query,
|
|
1345
1655
|
type: m.type,
|
|
1346
1656
|
expanded: m.expanded,
|
|
1347
|
-
|
|
1657
|
+
selectedKeys
|
|
1348
1658
|
})
|
|
1349
|
-
const
|
|
1350
|
-
const
|
|
1351
|
-
const
|
|
1352
|
-
const workbench = m.layout === 'workbench'
|
|
1353
|
-
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'
|
|
1354
1662
|
const state = typeof m.state === 'string' ? m.state : 'idle'
|
|
1355
1663
|
const loadLabel = state === 'loading' ? '刷新中…' : '刷新'
|
|
1356
|
-
const fullLabel = (item) =>
|
|
1357
|
-
|
|
1358
|
-
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
|
|
1359
1676
|
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
h(
|
|
1370
|
-
SelectTrigger,
|
|
1371
|
-
{ id: withId ? 'kb-model-import-role' : undefined, className: 'kb-rule-select', 'aria-label': '导入为' },
|
|
1372
|
-
h(SelectValue, null, roleLabel(activeImportRole))
|
|
1373
|
-
),
|
|
1374
|
-
h(
|
|
1375
|
-
SelectContent,
|
|
1376
|
-
null,
|
|
1377
|
-
selectedRoles.map((role) =>
|
|
1378
|
-
h(SelectItem, { key: role, value: role }, roleLabel(role))
|
|
1379
|
-
)
|
|
1380
|
-
)
|
|
1381
|
-
)
|
|
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
|
+
}
|
|
1382
1686
|
|
|
1383
|
-
const
|
|
1687
|
+
const syncButton = () =>
|
|
1384
1688
|
h(
|
|
1385
1689
|
Button,
|
|
1386
1690
|
{
|
|
1387
1691
|
size: 'sm',
|
|
1388
|
-
disabled:
|
|
1389
|
-
onClick:
|
|
1692
|
+
disabled: total === 0 || m.syncing === true || typeof m.onSync !== 'function',
|
|
1693
|
+
onClick: typeof m.onSync === 'function' ? m.onSync : undefined
|
|
1390
1694
|
},
|
|
1391
|
-
|
|
1695
|
+
syncLabel()
|
|
1392
1696
|
)
|
|
1393
1697
|
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1698
|
+
const roleSwitch = (item) => {
|
|
1699
|
+
const key = modelSelectionKey(item)
|
|
1700
|
+
const active = roleFor(item, roles)
|
|
1396
1701
|
return h(
|
|
1397
1702
|
'div',
|
|
1398
|
-
{ className: 'kb-model-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
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
|
+
)
|
|
1413
1718
|
)
|
|
1414
1719
|
}
|
|
1415
1720
|
|
|
1416
|
-
|
|
1417
|
-
const
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
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' },
|
|
1430
1752
|
h(
|
|
1431
1753
|
'span',
|
|
1432
|
-
{ className: 'kb-model-
|
|
1433
|
-
h(
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
h(
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
),
|
|
1441
|
-
h(
|
|
1442
|
-
'span',
|
|
1443
|
-
{ className: 'kb-model-url', title: item.baseUrl || '' },
|
|
1444
|
-
shortenUrl(item.baseUrl)
|
|
1445
|
-
),
|
|
1446
|
-
item.protocolHint
|
|
1447
|
-
? h(
|
|
1448
|
-
'span',
|
|
1449
|
-
{ className: 'kb-muted-text' },
|
|
1450
|
-
'该路由使用非 OpenAI 原生协议,复制后可能需要在知识库设置中调整接口类型。'
|
|
1451
|
-
)
|
|
1452
|
-
: null
|
|
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
|
|
1453
1762
|
),
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
h(
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
'
|
|
1475
|
-
{ className: 'kb-model-scroll' },
|
|
1476
|
-
h('p', { className: 'kb-muted-text' }, 'ChatLuna 暂无可用于复制的知识库模型。')
|
|
1477
|
-
)
|
|
1478
|
-
} else if (report.groups.length === 0) {
|
|
1479
|
-
body = h(
|
|
1480
|
-
'div',
|
|
1481
|
-
{ className: 'kb-model-scroll' },
|
|
1482
|
-
h('p', { className: 'kb-muted-text' }, '没有匹配的模型;调整搜索关键词或类型筛选。')
|
|
1483
|
-
)
|
|
1484
|
-
} else {
|
|
1485
|
-
body = h(
|
|
1486
|
-
'div',
|
|
1487
|
-
{ className: 'kb-model-scroll' },
|
|
1488
|
-
report.groups.map((group) =>
|
|
1489
|
-
h(
|
|
1490
|
-
'div',
|
|
1491
|
-
{ key: group.key, className: 'kb-model-group' },
|
|
1492
|
-
h(
|
|
1493
|
-
'div',
|
|
1494
|
-
{ className: 'kb-model-group-head' },
|
|
1495
|
-
h('p', { className: 'kb-model-group-title' }, group.label),
|
|
1496
|
-
h(Badge, { variant: 'outline' }, String(group.total))
|
|
1497
|
-
),
|
|
1498
|
-
h('div', { className: 'kb-model-list' }, group.items.map(workbenchItem)),
|
|
1499
|
-
group.hidden > 0
|
|
1500
|
-
? h(
|
|
1501
|
-
Button,
|
|
1502
|
-
{
|
|
1503
|
-
variant: 'ghost',
|
|
1504
|
-
size: 'sm',
|
|
1505
|
-
className: 'kb-model-more',
|
|
1506
|
-
onClick: () =>
|
|
1507
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1508
|
-
},
|
|
1509
|
-
`显示更多 ${group.hidden}`
|
|
1510
|
-
)
|
|
1511
|
-
: null,
|
|
1512
|
-
group.expanded && group.total > MODEL_GROUP_LIMIT
|
|
1513
|
-
? h(
|
|
1514
|
-
Button,
|
|
1515
|
-
{
|
|
1516
|
-
variant: 'ghost',
|
|
1517
|
-
size: 'sm',
|
|
1518
|
-
className: 'kb-model-more',
|
|
1519
|
-
onClick: () =>
|
|
1520
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1521
|
-
},
|
|
1522
|
-
'收起'
|
|
1523
|
-
)
|
|
1524
|
-
: null
|
|
1525
|
-
)
|
|
1526
|
-
)
|
|
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
|
|
1527
1784
|
)
|
|
1528
|
-
|
|
1785
|
+
)
|
|
1786
|
+
}
|
|
1529
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)
|
|
1530
1793
|
return h(
|
|
1531
1794
|
'div',
|
|
1532
|
-
{ className: 'kb-model-
|
|
1533
|
-
h(
|
|
1534
|
-
'div',
|
|
1535
|
-
{ className: 'kb-model-workbench-header' },
|
|
1536
|
-
h(DialogTitle, { className: 'kb-model-workbench-title' }, '从 ChatLuna 复制模型'),
|
|
1537
|
-
h(
|
|
1538
|
-
DialogDescription,
|
|
1539
|
-
{ className: 'kb-model-workbench-subtitle' },
|
|
1540
|
-
'选择已配置的模型复制到知识库;仅同步元数据,不会暴露 API Key。'
|
|
1541
|
-
)
|
|
1542
|
-
),
|
|
1795
|
+
{ key: group.key, className: 'kb-model-group' },
|
|
1543
1796
|
h(
|
|
1544
1797
|
'div',
|
|
1545
|
-
{ className: 'kb-model-
|
|
1546
|
-
h(
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
placeholder: '搜索厂商、模型或地址…',
|
|
1550
|
-
clearLabel: '清除搜索'
|
|
1551
|
-
}),
|
|
1552
|
-
h(FilterChips, {
|
|
1553
|
-
options: report.typeOptions,
|
|
1554
|
-
value: report.activeType,
|
|
1555
|
-
onChange: (value) => (typeof m.onTypeChange === 'function' ? m.onTypeChange(value) : undefined),
|
|
1556
|
-
label: '按模型类型筛选'
|
|
1557
|
-
}),
|
|
1558
|
-
h(
|
|
1559
|
-
Button,
|
|
1560
|
-
{
|
|
1561
|
-
variant: 'outline',
|
|
1562
|
-
size: 'sm',
|
|
1563
|
-
disabled: state === 'loading' || typeof m.onLoad !== 'function',
|
|
1564
|
-
onClick: typeof m.onLoad === 'function' ? m.onLoad : undefined
|
|
1565
|
-
},
|
|
1566
|
-
loadLabel
|
|
1567
|
-
)
|
|
1568
|
-
),
|
|
1569
|
-
body,
|
|
1570
|
-
resultAlert(),
|
|
1571
|
-
h(
|
|
1572
|
-
DialogFooter,
|
|
1573
|
-
{ className: 'kb-model-dialog-footer' },
|
|
1574
|
-
h(
|
|
1575
|
-
'div',
|
|
1576
|
-
{ className: 'kb-model-selection' },
|
|
1577
|
-
selected === null
|
|
1578
|
-
? h('span', { className: 'kb-model-selection-empty' }, '请选择一个要复制的模型')
|
|
1579
|
-
: h(
|
|
1580
|
-
'span',
|
|
1581
|
-
{ className: 'kb-model-selection-text' },
|
|
1582
|
-
'已选:',
|
|
1583
|
-
h('strong', { className: 'kb-model-selection-name' }, selected.modelId || '—'),
|
|
1584
|
-
h(
|
|
1585
|
-
'span',
|
|
1586
|
-
{ className: 'kb-model-selection-provider' },
|
|
1587
|
-
` · ${selected.providerLabel || selected.providerId || '—'}`
|
|
1588
|
-
)
|
|
1589
|
-
),
|
|
1590
|
-
selected !== null && selectedRoles.length > 1
|
|
1591
|
-
? h('div', { className: 'kb-model-role' }, roleSelect(true))
|
|
1592
|
-
: null
|
|
1593
|
-
),
|
|
1594
|
-
h(
|
|
1595
|
-
'div',
|
|
1596
|
-
{ className: 'kb-model-footer-actions' },
|
|
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)),
|
|
1597
1802
|
h(
|
|
1598
1803
|
Button,
|
|
1599
1804
|
{
|
|
1600
|
-
variant: '
|
|
1805
|
+
variant: 'ghost',
|
|
1601
1806
|
size: 'sm',
|
|
1602
|
-
|
|
1807
|
+
disabled: typeof m.onGroupSelect !== 'function',
|
|
1808
|
+
onClick:
|
|
1809
|
+
typeof m.onGroupSelect === 'function' ? () => m.onGroupSelect(selectable, true) : undefined
|
|
1603
1810
|
},
|
|
1604
|
-
'
|
|
1811
|
+
'全选本组'
|
|
1605
1812
|
),
|
|
1606
|
-
|
|
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
|
+
)
|
|
1607
1824
|
)
|
|
1608
|
-
)
|
|
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
|
|
1609
1853
|
)
|
|
1610
1854
|
}
|
|
1611
1855
|
|
|
1612
|
-
const
|
|
1613
|
-
|
|
1614
|
-
const active = key === selectedKey
|
|
1856
|
+
const resultBar = () => {
|
|
1857
|
+
if (!m.syncError && syncResult === null) return null
|
|
1615
1858
|
return h(
|
|
1616
|
-
'
|
|
1617
|
-
{
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
'span',
|
|
1631
|
-
{ className: 'kb-model-title' },
|
|
1632
|
-
fullLabel(item),
|
|
1633
|
-
h(Badge, { variant: item.type === 'embedding' ? 'secondary' : 'outline' }, modelRoleLabel(item.type)),
|
|
1634
|
-
item.supportsVision === true ? h(Badge, { variant: 'secondary' }, '支持视觉') : null,
|
|
1635
|
-
item.protocolHint ? h(Badge, { variant: 'outline' }, '原生协议') : null
|
|
1636
|
-
),
|
|
1637
|
-
h('span', { className: 'kb-model-url', title: item.baseUrl || '' }, shortenUrl(item.baseUrl)),
|
|
1638
|
-
item.protocolHint
|
|
1639
|
-
? h(
|
|
1640
|
-
'span',
|
|
1641
|
-
{ className: 'kb-muted-text' },
|
|
1642
|
-
'该路由使用非 OpenAI 原生协议,复制后可能需要在知识库设置中调整接口类型。'
|
|
1643
|
-
)
|
|
1644
|
-
: null
|
|
1645
|
-
),
|
|
1646
|
-
active
|
|
1647
|
-
? h('span', { className: 'kb-model-check', 'aria-hidden': true }, h(UiIcon, { name: 'check' }))
|
|
1648
|
-
: null
|
|
1649
|
-
)
|
|
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
|
|
1650
1873
|
)
|
|
1651
1874
|
}
|
|
1652
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
|
+
|
|
1653
1904
|
return h(
|
|
1654
|
-
|
|
1655
|
-
{
|
|
1905
|
+
'div',
|
|
1906
|
+
{ className: `kb-model-workbench${wizard ? ' kb-model-workbench-wizard' : ''}` },
|
|
1656
1907
|
h(
|
|
1657
|
-
|
|
1658
|
-
{
|
|
1908
|
+
'div',
|
|
1909
|
+
{ className: 'kb-model-workbench-header' },
|
|
1910
|
+
wizard
|
|
1911
|
+
? h('p', { className: 'kb-model-workbench-title' }, '从 ChatLuna 同步模型')
|
|
1912
|
+
: h(DialogTitle, { className: 'kb-model-workbench-title' }, '从 ChatLuna 同步模型'),
|
|
1659
1913
|
h(
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1914
|
+
'p',
|
|
1915
|
+
{ className: 'kb-model-workbench-subtitle' },
|
|
1916
|
+
'勾选已配置的模型一次性同步到知识库;仅读取配置元数据,不会暴露 API Key。'
|
|
1917
|
+
)
|
|
1918
|
+
),
|
|
1919
|
+
h(
|
|
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
|
+
}),
|
|
1934
|
+
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(
|
|
1695
1956
|
Button,
|
|
1696
1957
|
{
|
|
1697
1958
|
variant: 'ghost',
|
|
1698
1959
|
size: 'sm',
|
|
1699
|
-
'
|
|
1700
|
-
onClick: typeof m.onToggle === 'function' ? m.onToggle : undefined
|
|
1960
|
+
onClick: typeof m.onClear === 'function' ? m.onClear : undefined
|
|
1701
1961
|
},
|
|
1702
|
-
|
|
1962
|
+
'清空已选'
|
|
1703
1963
|
)
|
|
1704
|
-
|
|
1705
|
-
)
|
|
1964
|
+
: null
|
|
1706
1965
|
),
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
? errorAlert(m.error, '读取模型列表失败')
|
|
1719
|
-
: null,
|
|
1720
|
-
state === 'idle'
|
|
1721
|
-
? h('p', { className: 'kb-muted-text' }, '点击「加载模型列表」查看可复制的对话 / Embedding / VLM / ReRank 模型。')
|
|
1722
|
-
: null,
|
|
1723
|
-
state === 'ready' && models.length === 0
|
|
1724
|
-
? h('p', { className: 'kb-muted-text' }, 'ChatLuna 暂无可用于复制的知识库模型。')
|
|
1725
|
-
: null,
|
|
1726
|
-
state === 'ready' && models.length > 0
|
|
1727
|
-
? h(
|
|
1728
|
-
'div',
|
|
1729
|
-
{ className: 'kb-model-toolbar' },
|
|
1730
|
-
h(SearchBox, {
|
|
1731
|
-
value: query,
|
|
1732
|
-
onChange: (value) =>
|
|
1733
|
-
typeof m.onQueryChange === 'function' ? m.onQueryChange(value) : undefined,
|
|
1734
|
-
placeholder: '搜索厂商、模型或地址…',
|
|
1735
|
-
clearLabel: '清除搜索'
|
|
1736
|
-
}),
|
|
1737
|
-
h(FilterChips, {
|
|
1738
|
-
options: report.typeOptions,
|
|
1739
|
-
value: report.activeType,
|
|
1740
|
-
onChange: (value) =>
|
|
1741
|
-
typeof m.onTypeChange === 'function' ? m.onTypeChange(value) : undefined,
|
|
1742
|
-
label: '按模型类型筛选'
|
|
1743
|
-
})
|
|
1744
|
-
)
|
|
1745
|
-
: null,
|
|
1746
|
-
state === 'ready' && models.length > 0 && report.empty
|
|
1747
|
-
? h('p', { className: 'kb-muted-text' }, '没有匹配的模型;调整搜索关键词或类型筛选。')
|
|
1748
|
-
: null,
|
|
1749
|
-
state === 'ready' && report.groups.length > 0
|
|
1750
|
-
? h(
|
|
1751
|
-
'div',
|
|
1752
|
-
{ className: 'kb-model-scroll' },
|
|
1753
|
-
report.groups.map((group) =>
|
|
1754
|
-
h(
|
|
1755
|
-
'div',
|
|
1756
|
-
{ key: group.key, className: 'kb-model-group' },
|
|
1757
|
-
h(
|
|
1758
|
-
'div',
|
|
1759
|
-
{ className: 'kb-model-group-head' },
|
|
1760
|
-
h('p', { className: 'kb-model-group-title' }, group.label),
|
|
1761
|
-
h(Badge, { variant: 'outline' }, String(group.total))
|
|
1762
|
-
),
|
|
1763
|
-
h('ul', { className: 'kb-model-list' }, group.items.map(cardItem)),
|
|
1764
|
-
group.hidden > 0
|
|
1765
|
-
? h(
|
|
1766
|
-
Button,
|
|
1767
|
-
{
|
|
1768
|
-
variant: 'ghost',
|
|
1769
|
-
size: 'sm',
|
|
1770
|
-
className: 'kb-model-more',
|
|
1771
|
-
onClick: () =>
|
|
1772
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1773
|
-
},
|
|
1774
|
-
`显示更多 ${group.hidden}`
|
|
1775
|
-
)
|
|
1776
|
-
: null,
|
|
1777
|
-
group.expanded && group.total > MODEL_GROUP_LIMIT
|
|
1778
|
-
? h(
|
|
1779
|
-
Button,
|
|
1780
|
-
{
|
|
1781
|
-
variant: 'ghost',
|
|
1782
|
-
size: 'sm',
|
|
1783
|
-
className: 'kb-model-more',
|
|
1784
|
-
onClick: () =>
|
|
1785
|
-
typeof m.onToggleGroup === 'function' ? m.onToggleGroup(group.key) : undefined
|
|
1786
|
-
},
|
|
1787
|
-
'收起'
|
|
1788
|
-
)
|
|
1789
|
-
: null
|
|
1790
|
-
)
|
|
1791
|
-
)
|
|
1792
|
-
)
|
|
1793
|
-
: null
|
|
1794
|
-
)
|
|
1795
|
-
)
|
|
1796
|
-
: 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
|
+
)
|
|
1797
1977
|
)
|
|
1798
1978
|
)
|
|
1799
1979
|
}
|
|
1800
1980
|
|
|
1801
|
-
function
|
|
1802
|
-
|
|
1981
|
+
function ModelSyncPanel({
|
|
1982
|
+
layout = 'workbench',
|
|
1983
|
+
autoLoad = false,
|
|
1984
|
+
autoRecommend = false,
|
|
1985
|
+
bindDefaultKb = false,
|
|
1986
|
+
onClose,
|
|
1987
|
+
onSkip,
|
|
1988
|
+
onDone
|
|
1989
|
+
} = {}) {
|
|
1803
1990
|
const [state, setState] = useState('idle')
|
|
1804
1991
|
const [models, setModels] = useState([])
|
|
1805
1992
|
const [error, setError] = useState('')
|
|
1806
|
-
const [
|
|
1807
|
-
const [
|
|
1993
|
+
const [selectedKeys, setSelectedKeys] = useState([])
|
|
1994
|
+
const [roles, setRoles] = useState({})
|
|
1995
|
+
const [syncedKeys, setSyncedKeys] = useState([])
|
|
1808
1996
|
const [query, setQuery] = useState('')
|
|
1809
1997
|
const [modelType, setModelType] = useState('all')
|
|
1810
1998
|
const [expanded, setExpanded] = useState({})
|
|
1811
|
-
const [
|
|
1812
|
-
const [
|
|
1813
|
-
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({})
|
|
1814
2004
|
const autoLoadRef = useRef(false)
|
|
1815
2005
|
|
|
1816
2006
|
const load = useCallback(async () => {
|
|
1817
2007
|
setState('loading')
|
|
1818
2008
|
setError('')
|
|
1819
2009
|
try {
|
|
1820
|
-
const
|
|
1821
|
-
|
|
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()
|
|
1822
2017
|
setModels(list)
|
|
1823
|
-
|
|
2018
|
+
setSyncedKeys([...existing])
|
|
2019
|
+
setSelectedKeys(autoRecommend ? recommendModelKeys(list, existing) : [])
|
|
2020
|
+
setRoles({})
|
|
1824
2021
|
setQuery('')
|
|
1825
2022
|
setModelType('all')
|
|
1826
2023
|
setExpanded({})
|
|
2024
|
+
setSyncSummary(null)
|
|
2025
|
+
setSyncError('')
|
|
2026
|
+
setItemErrors({})
|
|
1827
2027
|
setState('ready')
|
|
1828
2028
|
} catch (err) {
|
|
1829
2029
|
setError(apiErrorMessage(err))
|
|
1830
2030
|
setState('error')
|
|
1831
2031
|
}
|
|
1832
|
-
}, [])
|
|
2032
|
+
}, [autoRecommend])
|
|
1833
2033
|
|
|
1834
|
-
//
|
|
2034
|
+
// 工作台/向导首次出现时懒加载一次;不阻塞页面首屏。
|
|
1835
2035
|
useEffect(() => {
|
|
1836
|
-
if (!autoLoad ||
|
|
2036
|
+
if (!autoLoad || autoLoadRef.current || state !== 'idle') return
|
|
1837
2037
|
autoLoadRef.current = true
|
|
1838
2038
|
load()
|
|
1839
|
-
}, [autoLoad,
|
|
1840
|
-
|
|
1841
|
-
const
|
|
1842
|
-
const
|
|
1843
|
-
if (
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
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 })
|
|
1847
2058
|
try {
|
|
1848
|
-
const
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
providerId: selected.providerId,
|
|
1852
|
-
modelId: selected.modelId
|
|
2059
|
+
const response = await callAction('kb.models.syncBatch', {
|
|
2060
|
+
items,
|
|
2061
|
+
bindDefaultKb: bindDefaultKb === true
|
|
1853
2062
|
})
|
|
1854
|
-
const
|
|
1855
|
-
|
|
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
|
+
}
|
|
1856
2076
|
} catch (err) {
|
|
1857
|
-
|
|
2077
|
+
setSyncError(apiErrorMessage(err))
|
|
1858
2078
|
} finally {
|
|
1859
|
-
|
|
2079
|
+
setSyncing(false)
|
|
1860
2080
|
}
|
|
1861
|
-
}, [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
|
+
)
|
|
1862
2097
|
|
|
1863
2098
|
return modelCopyView({
|
|
1864
|
-
open,
|
|
1865
2099
|
layout,
|
|
1866
2100
|
state,
|
|
1867
2101
|
models,
|
|
1868
2102
|
error,
|
|
1869
|
-
|
|
2103
|
+
selectedKeys,
|
|
2104
|
+
roles,
|
|
2105
|
+
syncedKeys,
|
|
1870
2106
|
query,
|
|
1871
2107
|
type: modelType,
|
|
1872
2108
|
expanded,
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
2109
|
+
syncing,
|
|
2110
|
+
syncProgress,
|
|
2111
|
+
syncSummary,
|
|
2112
|
+
syncError,
|
|
2113
|
+
itemErrors,
|
|
2114
|
+
bindDefaultKb,
|
|
1879
2115
|
onLoad: load,
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
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
|
+
})
|
|
2126
|
+
},
|
|
2127
|
+
onGroupSelect: toggleGroup,
|
|
2128
|
+
onClear: () => {
|
|
2129
|
+
setSelectedKeys([])
|
|
2130
|
+
setRoles({})
|
|
1885
2131
|
},
|
|
2132
|
+
onRoleChange: (key, role) => setRoles((current) => ({ ...current, [key]: role })),
|
|
1886
2133
|
onQueryChange: (value) => setQuery(value),
|
|
1887
2134
|
onTypeChange: (value) => setModelType(value === '' ? 'all' : value),
|
|
1888
2135
|
onToggleGroup: (key) =>
|
|
1889
2136
|
setExpanded((current) => ({ ...current, [key]: current[key] !== true })),
|
|
1890
|
-
|
|
2137
|
+
onSync: sync,
|
|
2138
|
+
onClose,
|
|
2139
|
+
onSkip
|
|
1891
2140
|
})
|
|
1892
2141
|
}
|
|
1893
2142
|
|
|
@@ -1895,6 +2144,9 @@ function ModelCopyPanel({ layout = 'card', autoLoad = false, onClose } = {}) {
|
|
|
1895
2144
|
// 结构:InstallWizard 持有全部表单/请求状态;WizardPanel 是纯渲染层,接收一个
|
|
1896
2145
|
// model,便于 SSR 桩测试逐步渲染 0..3。所有网络调用都经由 callAction 或原生
|
|
1897
2146
|
// fetch,绝不把密钥写进页面文本。
|
|
2147
|
+
//
|
|
2148
|
+
// 新版 OOBE:模式 → 安装并启动(自动补齐 OCR 依赖、自动拉起)→ 同步模型 →
|
|
2149
|
+
// 准备就绪。安装完成后的 deps/start 串联全部软降级,绝不用系统包失败卡死主流程。
|
|
1898
2150
|
|
|
1899
2151
|
function TextField({ id, label, value, onChange, placeholder, type, hint, disabled, autoComplete }) {
|
|
1900
2152
|
return h(
|
|
@@ -1977,6 +2229,55 @@ function installFeedback(install) {
|
|
|
1977
2229
|
|
|
1978
2230
|
const isOkay = (value) => value.state === 'ok'
|
|
1979
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
|
+
}
|
|
2280
|
+
|
|
1980
2281
|
function wizardBody(m) {
|
|
1981
2282
|
const step = m.step
|
|
1982
2283
|
const status = m.status
|
|
@@ -1984,6 +2285,15 @@ function wizardBody(m) {
|
|
|
1984
2285
|
const embedding = m.embedding
|
|
1985
2286
|
|
|
1986
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 组件'
|
|
1987
2297
|
return h(
|
|
1988
2298
|
'div',
|
|
1989
2299
|
{ className: 'kb-card-stack' },
|
|
@@ -2005,6 +2315,20 @@ function wizardBody(m) {
|
|
|
2005
2315
|
onClick: () => m.onMode('external')
|
|
2006
2316
|
})
|
|
2007
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
|
+
),
|
|
2008
2332
|
m.mode === 'external'
|
|
2009
2333
|
? h(
|
|
2010
2334
|
Alert,
|
|
@@ -2024,26 +2348,31 @@ function wizardBody(m) {
|
|
|
2024
2348
|
),
|
|
2025
2349
|
embedding.baseUrl !== ''
|
|
2026
2350
|
? h(CodeValue, { value: embedding.baseUrl })
|
|
2027
|
-
: h('p', { className: 'kb-muted-text' }, '尚未读取到 baseUrl。'),
|
|
2028
|
-
h('p', { className: 'kb-muted-text' }, '
|
|
2029
|
-
)
|
|
2030
|
-
)
|
|
2031
|
-
)
|
|
2032
|
-
: h(
|
|
2033
|
-
'div',
|
|
2034
|
-
{ className: 'kb-form-actions' },
|
|
2035
|
-
h(Button, { onClick: () => m.onStep(1) }, '下一步:安装引擎')
|
|
2351
|
+
: h('p', { className: 'kb-muted-text' }, '尚未读取到 baseUrl。'),
|
|
2352
|
+
h('p', { className: 'kb-muted-text' }, '连通正常时可继续把 ChatLuna 模型同步到外部引擎。')
|
|
2353
|
+
)
|
|
2354
|
+
)
|
|
2036
2355
|
)
|
|
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
|
+
)
|
|
2037
2364
|
)
|
|
2038
2365
|
}
|
|
2039
2366
|
|
|
2040
2367
|
if (step === 1) {
|
|
2041
2368
|
const detected = m.detect
|
|
2042
2369
|
const platformText = detectSummary(detected.data)
|
|
2370
|
+
const ocr = ocrReadyOf(status, detected.data)
|
|
2371
|
+
const running = status.running === true || m.started === true
|
|
2043
2372
|
return h(
|
|
2044
2373
|
'div',
|
|
2045
2374
|
{ className: 'kb-card-stack' },
|
|
2046
|
-
h('p', { className: 'kb-section-lead' }, '
|
|
2375
|
+
h('p', { className: 'kb-section-lead' }, '安装并启动引擎'),
|
|
2047
2376
|
h(
|
|
2048
2377
|
'div',
|
|
2049
2378
|
{ className: 'kb-detect-row' },
|
|
@@ -2061,6 +2390,22 @@ function wizardBody(m) {
|
|
|
2061
2390
|
)
|
|
2062
2391
|
),
|
|
2063
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
|
+
),
|
|
2064
2409
|
h(
|
|
2065
2410
|
Tabs,
|
|
2066
2411
|
{ value: m.source, onValueChange: (value) => m.onSource(String(value)) },
|
|
@@ -2080,7 +2425,6 @@ function wizardBody(m) {
|
|
|
2080
2425
|
{ className: 'kb-card-stack' },
|
|
2081
2426
|
(() => {
|
|
2082
2427
|
const release = detected.data && typeof detected.data === 'object' ? detected.data.release : null
|
|
2083
|
-
const ocr = detected.data && typeof detected.data === 'object' ? detected.data.ocr : null
|
|
2084
2428
|
if (!release || release.available !== true) {
|
|
2085
2429
|
return h(
|
|
2086
2430
|
Alert,
|
|
@@ -2104,22 +2448,24 @@ function wizardBody(m) {
|
|
|
2104
2448
|
{ className: 'kb-muted-text' },
|
|
2105
2449
|
`平台 ${detected.data?.platformKey || detected.data?.platform || ''} · 下载后强制校验 SHA-256。`
|
|
2106
2450
|
),
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
)
|
|
2115
|
-
: null,
|
|
2451
|
+
h(
|
|
2452
|
+
'p',
|
|
2453
|
+
{ className: 'kb-muted-text' },
|
|
2454
|
+
ocr.ready
|
|
2455
|
+
? '本地高精度 OCR(内置 tessdata_best)已就绪。'
|
|
2456
|
+
: `扫描件/图片高精度 OCR 将在安装后自动补齐;如需手动安装:${platformInstallHint(detected.data)}`
|
|
2457
|
+
),
|
|
2116
2458
|
h(
|
|
2117
2459
|
'div',
|
|
2118
2460
|
{ className: 'kb-form-actions' },
|
|
2119
2461
|
h(
|
|
2120
2462
|
Button,
|
|
2121
2463
|
{ disabled: m.busy !== '' || install.active, onClick: m.onInstallRelease },
|
|
2122
|
-
m.busy === 'install'
|
|
2464
|
+
m.busy === 'install'
|
|
2465
|
+
? '准备安装…'
|
|
2466
|
+
: m.installed
|
|
2467
|
+
? '一键启动引擎'
|
|
2468
|
+
: '一键安装并启动'
|
|
2123
2469
|
)
|
|
2124
2470
|
)
|
|
2125
2471
|
)
|
|
@@ -2198,7 +2544,35 @@ function wizardBody(m) {
|
|
|
2198
2544
|
)
|
|
2199
2545
|
),
|
|
2200
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,
|
|
2559
|
+
m.installed
|
|
2560
|
+
? h(
|
|
2561
|
+
Alert,
|
|
2562
|
+
{ className: 'kb-alert-muted', 'aria-live': 'polite' },
|
|
2563
|
+
h(UiIcon, { name: 'check' }),
|
|
2564
|
+
h(AlertTitle, null, running ? '引擎已启动' : '安装完成'),
|
|
2565
|
+
h(
|
|
2566
|
+
AlertDescription,
|
|
2567
|
+
null,
|
|
2568
|
+
running
|
|
2569
|
+
? '正在进入模型同步;可随时点「上一步」回看安装结果。'
|
|
2570
|
+
: '正在自动补齐本地组件并启动引擎…'
|
|
2571
|
+
)
|
|
2572
|
+
)
|
|
2573
|
+
: null,
|
|
2201
2574
|
m.error !== '' && install.error === '' ? errorAlert(m.error) : null,
|
|
2575
|
+
m.startError !== '' ? errorAlert(m.startError, '启动失败') : null,
|
|
2202
2576
|
h(
|
|
2203
2577
|
'div',
|
|
2204
2578
|
{ className: 'kb-card-footer-actions' },
|
|
@@ -2208,190 +2582,271 @@ function wizardBody(m) {
|
|
|
2208
2582
|
: install.error !== ''
|
|
2209
2583
|
? h(Button, { disabled: m.busy !== '', onClick: m.onRetry }, '重试')
|
|
2210
2584
|
: null,
|
|
2211
|
-
install.
|
|
2212
|
-
? h(Button, {
|
|
2213
|
-
: 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
|
|
2214
2589
|
)
|
|
2215
2590
|
)
|
|
2216
2591
|
}
|
|
2217
2592
|
|
|
2218
2593
|
if (step === 2) {
|
|
2219
|
-
const
|
|
2594
|
+
const running = status.running === true || m.started === true
|
|
2220
2595
|
return h(
|
|
2221
2596
|
'div',
|
|
2222
|
-
{ className: 'kb-card-stack' },
|
|
2223
|
-
h('p', { className: 'kb-section-lead' }, '
|
|
2597
|
+
{ className: 'kb-card-stack kb-wizard-sync' },
|
|
2598
|
+
h('p', { className: 'kb-section-lead' }, '同步模型'),
|
|
2224
2599
|
h(
|
|
2225
|
-
|
|
2226
|
-
{
|
|
2227
|
-
|
|
2228
|
-
CardHeader,
|
|
2229
|
-
null,
|
|
2230
|
-
h(CardTitle, null, '当前配置'),
|
|
2231
|
-
h(
|
|
2232
|
-
CardDescription,
|
|
2233
|
-
null,
|
|
2234
|
-
embedding.baseUrl !== '' ? '默认复用 ChatLuna 已配置模型' : '尚未检测到 Embedding 配置'
|
|
2235
|
-
)
|
|
2236
|
-
),
|
|
2237
|
-
h(
|
|
2238
|
-
CardContent,
|
|
2239
|
-
null,
|
|
2240
|
-
embedding.baseUrl !== ''
|
|
2241
|
-
? h(Facts, {
|
|
2242
|
-
rows: [
|
|
2243
|
-
{ label: 'baseUrl', value: h(CodeValue, { value: embedding.baseUrl }) },
|
|
2244
|
-
{ label: '模型', value: embedding.model !== '' ? embedding.model : '—' },
|
|
2245
|
-
{ label: '维度', value: h('span', { className: 'kb-num' }, embedding.dimension ?? '—') },
|
|
2246
|
-
{
|
|
2247
|
-
label: 'API Key',
|
|
2248
|
-
value:
|
|
2249
|
-
embedding.hasKey || embedding.apiKeyFile !== ''
|
|
2250
|
-
? `已配置 ${embedding.apiKeyFile !== '' ? maskPath(embedding.apiKeyFile) : '••••'}`
|
|
2251
|
-
: '未配置'
|
|
2252
|
-
}
|
|
2253
|
-
]
|
|
2254
|
-
})
|
|
2255
|
-
: h(
|
|
2256
|
-
'p',
|
|
2257
|
-
{ className: 'kb-muted-text' },
|
|
2258
|
-
'尚未检测到 Embedding 配置;可在下方手动填写,或先在插件配置中复用 ChatLuna 模型。'
|
|
2259
|
-
)
|
|
2260
|
-
)
|
|
2600
|
+
'p',
|
|
2601
|
+
{ className: 'kb-muted-text' },
|
|
2602
|
+
'引擎已在运行,勾选 ChatLuna 已配置的对话 / 视觉 / Embedding / ReRank 模型一次性同步到知识库;默认不预选已同步项。'
|
|
2261
2603
|
),
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
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
|
+
})
|
|
2614
|
+
: h(
|
|
2615
|
+
Alert,
|
|
2616
|
+
{ className: 'kb-alert-muted' },
|
|
2617
|
+
h(UiIcon, { name: 'alert-circle' }),
|
|
2618
|
+
h(AlertTitle, null, '引擎尚未启动'),
|
|
2619
|
+
h(
|
|
2620
|
+
AlertDescription,
|
|
2621
|
+
null,
|
|
2622
|
+
'引擎运行后才能写入模型;可先重试启动,或稍后再同步。'
|
|
2277
2623
|
)
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
if (next !== m.manualOpen) m.onToggleManual()
|
|
2289
|
-
}
|
|
2290
|
-
},
|
|
2291
|
-
h(
|
|
2292
|
-
CollapsibleTrigger,
|
|
2293
|
-
{
|
|
2294
|
-
render: h(Button, { variant: 'ghost', size: 'sm' })
|
|
2295
|
-
},
|
|
2296
|
-
h(UiIcon, { name: m.manualOpen ? 'chevron-down' : 'chevron-right' }),
|
|
2297
|
-
'手动配置(可选)'
|
|
2298
|
-
),
|
|
2299
|
-
h(
|
|
2300
|
-
CollapsibleContent,
|
|
2301
|
-
null,
|
|
2302
|
-
h(
|
|
2303
|
-
'div',
|
|
2304
|
-
{ className: 'kb-card-stack' },
|
|
2305
|
-
h(TextField, {
|
|
2306
|
-
id: 'kb-embedding-base',
|
|
2307
|
-
label: 'baseUrl',
|
|
2308
|
-
value: m.form.baseUrl,
|
|
2309
|
-
onChange: (value) => m.onForm('baseUrl', value),
|
|
2310
|
-
placeholder: 'https://api.openai.com/v1'
|
|
2311
|
-
}),
|
|
2312
|
-
h(TextField, {
|
|
2313
|
-
id: 'kb-embedding-model',
|
|
2314
|
-
label: '模型',
|
|
2315
|
-
value: m.form.model,
|
|
2316
|
-
onChange: (value) => m.onForm('model', value),
|
|
2317
|
-
placeholder: 'text-embedding-3-small'
|
|
2318
|
-
}),
|
|
2319
|
-
h(TextField, {
|
|
2320
|
-
id: 'kb-embedding-key',
|
|
2321
|
-
label: 'API Key',
|
|
2322
|
-
value: m.form.apiKey,
|
|
2323
|
-
onChange: (value) => m.onForm('apiKey', value),
|
|
2324
|
-
type: 'password',
|
|
2325
|
-
autoComplete: 'new-password',
|
|
2326
|
-
placeholder: '仅提交给本机服务,不回显'
|
|
2327
|
-
}),
|
|
2328
|
-
h(TextField, {
|
|
2329
|
-
id: 'kb-embedding-dimension',
|
|
2330
|
-
label: '维度(可选)',
|
|
2331
|
-
value: m.form.dimension,
|
|
2332
|
-
onChange: (value) => m.onForm('dimension', value),
|
|
2333
|
-
placeholder: '1536'
|
|
2334
|
-
}),
|
|
2624
|
+
),
|
|
2625
|
+
running
|
|
2626
|
+
? h(
|
|
2627
|
+
Collapsible,
|
|
2628
|
+
{
|
|
2629
|
+
open: m.manualOpen,
|
|
2630
|
+
onOpenChange: (next) => {
|
|
2631
|
+
if (next !== m.manualOpen) m.onToggleManual()
|
|
2632
|
+
}
|
|
2633
|
+
},
|
|
2335
2634
|
h(
|
|
2336
|
-
|
|
2337
|
-
{
|
|
2338
|
-
|
|
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,
|
|
2339
2645
|
h(
|
|
2340
|
-
|
|
2341
|
-
{
|
|
2342
|
-
|
|
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
|
|
2343
2709
|
)
|
|
2344
2710
|
)
|
|
2345
2711
|
)
|
|
2346
|
-
|
|
2347
|
-
),
|
|
2348
|
-
m.saved !== '' ? h('p', { className: 'kb-muted-text', role: 'status' }, m.saved) : null,
|
|
2349
|
-
m.formError !== '' ? errorAlert(m.formError, '保存失败') : null,
|
|
2712
|
+
: null,
|
|
2350
2713
|
h(
|
|
2351
2714
|
'div',
|
|
2352
2715
|
{ className: 'kb-card-footer-actions' },
|
|
2353
|
-
h(Button, { variant: 'outline', onClick: () => m.onStep(1) }, '
|
|
2354
|
-
|
|
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
|
|
2355
2724
|
)
|
|
2356
2725
|
)
|
|
2357
2726
|
}
|
|
2358
2727
|
|
|
2359
2728
|
const running = status.running || m.started
|
|
2360
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 状态未知'
|
|
2361
2749
|
return h(
|
|
2362
2750
|
'div',
|
|
2363
2751
|
{ className: 'kb-card-stack' },
|
|
2364
|
-
h('p', { className: 'kb-section-lead' }, '
|
|
2752
|
+
h('p', { className: 'kb-section-lead' }, '准备就绪,开始使用'),
|
|
2365
2753
|
h(
|
|
2366
2754
|
'div',
|
|
2367
|
-
{ className: 'kb-
|
|
2368
|
-
h(StatusDot, { tone: running ? 'success' : 'offline' }),
|
|
2755
|
+
{ className: 'kb-done-overview' },
|
|
2369
2756
|
h(
|
|
2370
|
-
'
|
|
2371
|
-
{ className: 'kb-done-
|
|
2372
|
-
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' }),
|
|
2373
2777
|
h(
|
|
2374
2778
|
'span',
|
|
2375
|
-
{ className: 'kb-
|
|
2376
|
-
|
|
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' }),
|
|
2788
|
+
h(
|
|
2789
|
+
'span',
|
|
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(Badge, { variant: 'outline' }, 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
|
|
2377
2824
|
)
|
|
2378
2825
|
)
|
|
2379
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,
|
|
2380
2836
|
m.startError !== '' ? errorAlert(m.startError, '启动失败') : null,
|
|
2381
2837
|
h(
|
|
2382
2838
|
'div',
|
|
2383
2839
|
{ className: 'kb-card-footer-actions' },
|
|
2384
|
-
h(Button, { variant: 'outline', onClick: () => m.onStep(
|
|
2385
|
-
h(Button, { variant: 'outline', onClick: () => m.onStep(2) }, '配置 Embedding'),
|
|
2840
|
+
h(Button, { variant: 'outline', onClick: () => m.onStep(2) }, '返回同步更多模型'),
|
|
2386
2841
|
running
|
|
2387
2842
|
? h(Button, { onClick: m.onEnter }, '进入知识库')
|
|
2388
2843
|
: installed
|
|
2389
2844
|
? h(
|
|
2390
2845
|
Button,
|
|
2391
2846
|
{ disabled: m.busy !== '', onClick: m.onStart },
|
|
2392
|
-
m.busy === 'start' ? '启动中…' : '
|
|
2847
|
+
m.busy === 'start' ? '启动中…' : '重试启动'
|
|
2393
2848
|
)
|
|
2394
|
-
:
|
|
2849
|
+
: h(Button, { onClick: () => m.onStep(1) }, '去安装')
|
|
2395
2850
|
),
|
|
2396
2851
|
h('p', { className: 'kb-muted-text' }, '首次启动会创建默认知识库并写入 Embedding 配置,可能需要数十秒。')
|
|
2397
2852
|
)
|
|
@@ -2415,8 +2870,8 @@ export function WizardPanel({ model }) {
|
|
|
2415
2870
|
h(
|
|
2416
2871
|
CardHeader,
|
|
2417
2872
|
null,
|
|
2418
|
-
h(CardTitle, null, '
|
|
2419
|
-
h(CardDescription, null, '
|
|
2873
|
+
h(CardTitle, null, '知识库配置向导'),
|
|
2874
|
+
h(CardDescription, null, '安装并启动本地知识库引擎,直接完成模型同步后即可使用。'),
|
|
2420
2875
|
m.onDismiss
|
|
2421
2876
|
? h(
|
|
2422
2877
|
CardAction,
|
|
@@ -2436,8 +2891,10 @@ export function WizardPanel({ model }) {
|
|
|
2436
2891
|
)
|
|
2437
2892
|
}
|
|
2438
2893
|
|
|
2894
|
+
const INSTALL_AUTO_ADVANCE_MS = 600
|
|
2895
|
+
|
|
2439
2896
|
function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
2440
|
-
const [step, setStep] = useState(
|
|
2897
|
+
const [step, setStep] = useState(() => initialWizardStep(status, install))
|
|
2441
2898
|
const [mode, setMode] = useState(status.mode === 'external' ? 'external' : 'lite')
|
|
2442
2899
|
const [detect, setDetect] = useState({ state: 'idle' })
|
|
2443
2900
|
const [source, setSource] = useState('release')
|
|
@@ -2452,13 +2909,20 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2452
2909
|
const [saved, setSaved] = useState('')
|
|
2453
2910
|
const [formError, setFormError] = useState('')
|
|
2454
2911
|
const [started, setStarted] = useState(false)
|
|
2912
|
+
const [startFallback, setStartFallback] = useState(false)
|
|
2455
2913
|
const [startError, setStartError] = useState('')
|
|
2914
|
+
const [autoDeps, setAutoDeps] = useState(true)
|
|
2915
|
+
const [deps, setDeps] = useState({ state: 'idle', warning: '' })
|
|
2916
|
+
const [pipeline, setPipeline] = useState({ phase: '', message: '' })
|
|
2917
|
+
const [syncSummary, setSyncSummary] = useState(null)
|
|
2456
2918
|
const lastRequest = useRef(null)
|
|
2457
2919
|
const lastFile = useRef(null)
|
|
2920
|
+
const autoFlow = useRef(false)
|
|
2921
|
+
const advanceOnce = useRef(false)
|
|
2458
2922
|
|
|
2459
|
-
//
|
|
2923
|
+
// 进入选择模式/安装步都探测平台,Step 0 的环境预览才有数据;失败可重进重试。
|
|
2460
2924
|
useEffect(() => {
|
|
2461
|
-
if (step !== 1) return
|
|
2925
|
+
if (step !== 0 && step !== 1) return
|
|
2462
2926
|
let live = true
|
|
2463
2927
|
setDetect({ state: 'loading' })
|
|
2464
2928
|
callAction('kb.detect', {})
|
|
@@ -2473,9 +2937,77 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2473
2937
|
}
|
|
2474
2938
|
}, [step])
|
|
2475
2939
|
|
|
2476
|
-
// 引擎安装完成时允许直接进下一步,但保留用户手动确认。
|
|
2477
2940
|
const installed = install.installed || status.installed === true
|
|
2478
2941
|
|
|
2942
|
+
const startEngine = useCallback(async () => {
|
|
2943
|
+
setBusy('start')
|
|
2944
|
+
setStartError('')
|
|
2945
|
+
try {
|
|
2946
|
+
await callAction('kb.start', {})
|
|
2947
|
+
setStarted(true)
|
|
2948
|
+
} catch (err) {
|
|
2949
|
+
setStartError(apiErrorMessage(err))
|
|
2950
|
+
} finally {
|
|
2951
|
+
setBusy('')
|
|
2952
|
+
}
|
|
2953
|
+
}, [])
|
|
2954
|
+
|
|
2955
|
+
// 安装完成后自动串联:补齐 OCR 依赖(失败软降级)→ 拉起并初始化。绝不阻塞主流程。
|
|
2956
|
+
useEffect(() => {
|
|
2957
|
+
if (step !== 1 || !installed || autoFlow.current || mode === 'external') return undefined
|
|
2958
|
+
autoFlow.current = true
|
|
2959
|
+
let live = true
|
|
2960
|
+
const run = async () => {
|
|
2961
|
+
let warning = ''
|
|
2962
|
+
if (autoDeps !== false) {
|
|
2963
|
+
if (live) setPipeline({ phase: 'deps', message: '正在补齐本地 OCR 组件(tesseract / poppler)…' })
|
|
2964
|
+
try {
|
|
2965
|
+
const response = await callAction('kb.install.deps', {})
|
|
2966
|
+
warning = depsSoftWarning(response)
|
|
2967
|
+
} catch (err) {
|
|
2968
|
+
warning = depsFailureWarning(err)
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
if (!live) return
|
|
2972
|
+
setDeps({ state: 'done', warning })
|
|
2973
|
+
setPipeline({ phase: 'starting', message: '正在拉起并初始化知识库引擎…' })
|
|
2974
|
+
try {
|
|
2975
|
+
await callAction('kb.start', {})
|
|
2976
|
+
if (live) setStarted(true)
|
|
2977
|
+
} catch (err) {
|
|
2978
|
+
if (live) setStartError(apiErrorMessage(err))
|
|
2979
|
+
if (live) setPipeline({ phase: 'error', message: '' })
|
|
2980
|
+
return
|
|
2981
|
+
}
|
|
2982
|
+
if (live) setPipeline({ phase: 'done', message: '' })
|
|
2983
|
+
}
|
|
2984
|
+
run()
|
|
2985
|
+
return () => {
|
|
2986
|
+
live = false
|
|
2987
|
+
}
|
|
2988
|
+
}, [step, installed, autoDeps, mode])
|
|
2989
|
+
|
|
2990
|
+
// 等待 live 状态翻到 running;状态通道异常时 5 秒后按启动返回值兜底推进。
|
|
2991
|
+
useEffect(() => {
|
|
2992
|
+
if (started !== true) return undefined
|
|
2993
|
+
const timer = setTimeout(() => setStartFallback(true), 5000)
|
|
2994
|
+
return () => clearTimeout(timer)
|
|
2995
|
+
}, [started])
|
|
2996
|
+
|
|
2997
|
+
// 启动成功后平滑推进到同步步;只推进一次,避免用户回看安装步时被再次弹走。
|
|
2998
|
+
useEffect(() => {
|
|
2999
|
+
if (advanceOnce.current) return undefined
|
|
3000
|
+
const target = wizardAdvanceAfterStart({
|
|
3001
|
+
step,
|
|
3002
|
+
started: startFallback === true,
|
|
3003
|
+
running: status.running === true && started === true
|
|
3004
|
+
})
|
|
3005
|
+
if (target === null) return undefined
|
|
3006
|
+
advanceOnce.current = true
|
|
3007
|
+
const timer = setTimeout(() => setStep(target), INSTALL_AUTO_ADVANCE_MS)
|
|
3008
|
+
return () => clearTimeout(timer)
|
|
3009
|
+
}, [step, started, startFallback, status.running])
|
|
3010
|
+
|
|
2479
3011
|
const submitUrl = useCallback(async (payload) => {
|
|
2480
3012
|
setBusy('install')
|
|
2481
3013
|
setError('')
|
|
@@ -2507,6 +3039,10 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2507
3039
|
|
|
2508
3040
|
const onInstallRelease = useCallback(async () => {
|
|
2509
3041
|
if (install.active) return
|
|
3042
|
+
if (installed) {
|
|
3043
|
+
await startEngine()
|
|
3044
|
+
return
|
|
3045
|
+
}
|
|
2510
3046
|
const release = detect.data && typeof detect.data === 'object' ? detect.data.release : null
|
|
2511
3047
|
if (!release || release.available !== true) {
|
|
2512
3048
|
setError(release?.error || '当前没有可用的发布清单')
|
|
@@ -2523,7 +3059,7 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2523
3059
|
} finally {
|
|
2524
3060
|
setBusy('')
|
|
2525
3061
|
}
|
|
2526
|
-
}, [detect.data, install.active])
|
|
3062
|
+
}, [detect.data, install.active, installed, startEngine])
|
|
2527
3063
|
|
|
2528
3064
|
const onUpload = useCallback(
|
|
2529
3065
|
async (file) => {
|
|
@@ -2640,17 +3176,9 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2640
3176
|
}
|
|
2641
3177
|
}, [form, install.embedding])
|
|
2642
3178
|
|
|
2643
|
-
const
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
try {
|
|
2647
|
-
await callAction('kb.start', {})
|
|
2648
|
-
setStarted(true)
|
|
2649
|
-
} catch (err) {
|
|
2650
|
-
setStartError(apiErrorMessage(err))
|
|
2651
|
-
} finally {
|
|
2652
|
-
setBusy('')
|
|
2653
|
-
}
|
|
3179
|
+
const onSyncDone = useCallback((summary) => {
|
|
3180
|
+
setSyncSummary(summary)
|
|
3181
|
+
setStep(3)
|
|
2654
3182
|
}, [])
|
|
2655
3183
|
|
|
2656
3184
|
const model = {
|
|
@@ -2674,6 +3202,10 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2674
3202
|
formError,
|
|
2675
3203
|
started,
|
|
2676
3204
|
startError,
|
|
3205
|
+
autoDeps,
|
|
3206
|
+
deps,
|
|
3207
|
+
pipeline,
|
|
3208
|
+
syncSummary,
|
|
2677
3209
|
onStep: setStep,
|
|
2678
3210
|
onMode: setMode,
|
|
2679
3211
|
onSource: setSource,
|
|
@@ -2688,7 +3220,9 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
|
|
|
2688
3220
|
onForm: (key, value) => setForm((current) => ({ ...current, [key]: value })),
|
|
2689
3221
|
onTest,
|
|
2690
3222
|
onSave,
|
|
2691
|
-
onStart,
|
|
3223
|
+
onStart: startEngine,
|
|
3224
|
+
onAutoDeps: setAutoDeps,
|
|
3225
|
+
onSyncDone,
|
|
2692
3226
|
onEnter,
|
|
2693
3227
|
onDismiss
|
|
2694
3228
|
}
|
|
@@ -2704,6 +3238,35 @@ export function knowledgeTab(status, actions, install, wizard) {
|
|
|
2704
3238
|
onDismiss: wizard.onDismiss
|
|
2705
3239
|
})
|
|
2706
3240
|
}
|
|
3241
|
+
// 暂缓引导但引擎都还没装:给专属空态,绝不能落「重启引擎」离线卡。
|
|
3242
|
+
if (status.managed === true && status.installed === false) {
|
|
3243
|
+
return h(
|
|
3244
|
+
Centered,
|
|
3245
|
+
null,
|
|
3246
|
+
h('p', { className: 'kb-section-lead' }, '知识库尚未初始化'),
|
|
3247
|
+
h('p', { className: 'kb-muted-text' }, '当前尚未安装本地知识库引擎,完成简短引导后即可使用。'),
|
|
3248
|
+
h(
|
|
3249
|
+
'div',
|
|
3250
|
+
{ className: 'kb-form-actions' },
|
|
3251
|
+
h(
|
|
3252
|
+
Button,
|
|
3253
|
+
{
|
|
3254
|
+
onClick: typeof wizard.onReopen === 'function' ? wizard.onReopen : undefined
|
|
3255
|
+
},
|
|
3256
|
+
h(UiIcon, { name: 'download' }),
|
|
3257
|
+
'继续安装引导'
|
|
3258
|
+
),
|
|
3259
|
+
h(
|
|
3260
|
+
Button,
|
|
3261
|
+
{
|
|
3262
|
+
variant: 'outline',
|
|
3263
|
+
onClick: typeof wizard.onOpenEngine === 'function' ? wizard.onOpenEngine : undefined
|
|
3264
|
+
},
|
|
3265
|
+
'查看引擎状态'
|
|
3266
|
+
)
|
|
3267
|
+
)
|
|
3268
|
+
)
|
|
3269
|
+
}
|
|
2707
3270
|
if (status.live === 'loading') {
|
|
2708
3271
|
return h(Centered, null, h('p', { className: 'kb-muted-text' }, '正在读取引擎状态…'))
|
|
2709
3272
|
}
|
|
@@ -3884,7 +4447,7 @@ function LogConsole({
|
|
|
3884
4447
|
/** 左栏档案卡暂不进入 UI;组件保留,便于以后恢复。 */
|
|
3885
4448
|
const SHOW_ENGINE_RAIL = false
|
|
3886
4449
|
|
|
3887
|
-
/**
|
|
4450
|
+
/** 低频模型同步:Dialog 覆盖层,关闭后日志 DOM/滚动位置完全不变。 */
|
|
3888
4451
|
export function ModelCopyDialog({ open = false, onOpenChange, children }) {
|
|
3889
4452
|
const close = () => {
|
|
3890
4453
|
if (typeof onOpenChange === 'function') onOpenChange(false)
|
|
@@ -3903,13 +4466,18 @@ export function ModelCopyDialog({ open = false, onOpenChange, children }) {
|
|
|
3903
4466
|
children !== undefined
|
|
3904
4467
|
? children
|
|
3905
4468
|
: open === true
|
|
3906
|
-
? h(
|
|
4469
|
+
? h(ModelSyncPanel, {
|
|
4470
|
+
layout: 'workbench',
|
|
4471
|
+
autoLoad: true,
|
|
4472
|
+
bindDefaultKb: true,
|
|
4473
|
+
onClose: close
|
|
4474
|
+
})
|
|
3907
4475
|
: null
|
|
3908
4476
|
)
|
|
3909
4477
|
)
|
|
3910
4478
|
}
|
|
3911
4479
|
|
|
3912
|
-
export function EngineTab({ status, actions, retrying, onRetry }) {
|
|
4480
|
+
export function EngineTab({ status, actions, retrying, onRetry, onWizard }) {
|
|
3913
4481
|
const [wrap, setWrap] = useState(true)
|
|
3914
4482
|
const [logQuery, setLogQuery] = useState('')
|
|
3915
4483
|
const [warningsOnly, setWarningsOnly] = useState(false)
|
|
@@ -3942,6 +4510,21 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
|
|
|
3942
4510
|
retrying === true ? '检测中…' : '重新检测'
|
|
3943
4511
|
)
|
|
3944
4512
|
)
|
|
4513
|
+
} else if (status.installed === false) {
|
|
4514
|
+
// 引擎还没装:重启/停止必然失败,直接给安装引导主入口。
|
|
4515
|
+
buttons.push(
|
|
4516
|
+
h(
|
|
4517
|
+
Button,
|
|
4518
|
+
{
|
|
4519
|
+
key: 'install-wizard',
|
|
4520
|
+
size: 'sm',
|
|
4521
|
+
disabled: loading || typeof onWizard !== 'function',
|
|
4522
|
+
onClick: typeof onWizard === 'function' ? onWizard : undefined
|
|
4523
|
+
},
|
|
4524
|
+
h(UiIcon, { name: 'download' }),
|
|
4525
|
+
'开始安装引导'
|
|
4526
|
+
)
|
|
4527
|
+
)
|
|
3945
4528
|
} else if (running) {
|
|
3946
4529
|
buttons.push(
|
|
3947
4530
|
h(
|
|
@@ -3986,6 +4569,17 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
|
|
|
3986
4569
|
)
|
|
3987
4570
|
)
|
|
3988
4571
|
}
|
|
4572
|
+
// 已安装的托管引擎保留轻量入口,方便复查 Embedding 或重新拉起。
|
|
4573
|
+
if (status.managed && status.installed === true && typeof onWizard === 'function') {
|
|
4574
|
+
buttons.push(
|
|
4575
|
+
h(
|
|
4576
|
+
Button,
|
|
4577
|
+
{ key: 'rewizard', variant: 'ghost', size: 'sm', onClick: onWizard },
|
|
4578
|
+
h(UiIcon, { name: 'settings' }),
|
|
4579
|
+
'配置向导'
|
|
4580
|
+
)
|
|
4581
|
+
)
|
|
4582
|
+
}
|
|
3989
4583
|
|
|
3990
4584
|
const detailRows = [
|
|
3991
4585
|
{ label: '运行模式', value: modeLabel(status.mode) },
|
|
@@ -4045,8 +4639,8 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
|
|
|
4045
4639
|
h(
|
|
4046
4640
|
Button,
|
|
4047
4641
|
{ variant: 'ghost', size: 'sm', onClick: () => setModelOpen(true) },
|
|
4048
|
-
h(UiIcon, { name: '
|
|
4049
|
-
'
|
|
4642
|
+
h(UiIcon, { name: 'refresh' }),
|
|
4643
|
+
'同步模型'
|
|
4050
4644
|
)
|
|
4051
4645
|
)
|
|
4052
4646
|
),
|
|
@@ -4112,7 +4706,7 @@ export function KBPage() {
|
|
|
4112
4706
|
const [params, setParams] = useSearchParams()
|
|
4113
4707
|
const [tab, setTab] = useState(() => tabFromParams(params) ?? initialTab())
|
|
4114
4708
|
const legacyPath = useRef(initialTab() !== 'knowledge')
|
|
4115
|
-
const [
|
|
4709
|
+
const [wizardSession, setWizardSession] = useState('idle')
|
|
4116
4710
|
const [offlineMessage, setOfflineMessage] = useState('')
|
|
4117
4711
|
const [retrying, setRetrying] = useState(false)
|
|
4118
4712
|
const [frameKey, setFrameKey] = useState(0)
|
|
@@ -4160,6 +4754,28 @@ export function KBPage() {
|
|
|
4160
4754
|
lastRunning.current = status.running
|
|
4161
4755
|
}, [status.running, reloadFrame])
|
|
4162
4756
|
|
|
4757
|
+
// 会话锁:首次可展示时进入 active;之后 installed/running 翻转都不再卸载向导。
|
|
4758
|
+
useEffect(() => {
|
|
4759
|
+
setWizardSession((current) => advanceWizardSession(current, status))
|
|
4760
|
+
}, [status.live, status.managed, status.installed, status.running])
|
|
4761
|
+
|
|
4762
|
+
// 引擎实例身份变化(kbId/readyAt 且本地指纹不一致):清旧 WeKnora 会话并重载 iframe。
|
|
4763
|
+
useEffect(() => {
|
|
4764
|
+
if (syncWeKnoraInstance(status)) reloadFrame()
|
|
4765
|
+
}, [status.kbId, status.readyAt, reloadFrame])
|
|
4766
|
+
|
|
4767
|
+
const enterKnowledge = useCallback(() => {
|
|
4768
|
+
// 同源残留的旧实例 token 会让 WeKnora 撞死在登录页;进入前先清场再重载 iframe。
|
|
4769
|
+
clearStaleWeKnoraSession()
|
|
4770
|
+
reloadFrame()
|
|
4771
|
+
setWizardSession('dismissed')
|
|
4772
|
+
}, [reloadFrame])
|
|
4773
|
+
const dismissWizard = useCallback(() => setWizardSession('dismissed'), [])
|
|
4774
|
+
const reopenWizard = useCallback(() => {
|
|
4775
|
+
changeTab('knowledge')
|
|
4776
|
+
setWizardSession('active')
|
|
4777
|
+
}, [changeTab])
|
|
4778
|
+
|
|
4163
4779
|
// 「重试连接」直接探测同源反代:200 说明引擎已恢复,503 则继续展示离线卡片。
|
|
4164
4780
|
const probe = useCallback(async () => {
|
|
4165
4781
|
setRetrying(true)
|
|
@@ -4193,7 +4809,7 @@ export function KBPage() {
|
|
|
4193
4809
|
}
|
|
4194
4810
|
}, [reloadFrame])
|
|
4195
4811
|
|
|
4196
|
-
const showWizard =
|
|
4812
|
+
const showWizard = wizardSession === 'active'
|
|
4197
4813
|
|
|
4198
4814
|
// 三个面板常驻,只切换 display;知识库 iframe 绝不能因切 Tab 被卸载重载。
|
|
4199
4815
|
const knowledgePane = h(
|
|
@@ -4205,8 +4821,10 @@ export function KBPage() {
|
|
|
4205
4821
|
},
|
|
4206
4822
|
knowledgeTab(status, actions, install, {
|
|
4207
4823
|
visible: showWizard,
|
|
4208
|
-
onEnter:
|
|
4209
|
-
onDismiss:
|
|
4824
|
+
onEnter: enterKnowledge,
|
|
4825
|
+
onDismiss: dismissWizard,
|
|
4826
|
+
onReopen: reopenWizard,
|
|
4827
|
+
onOpenEngine: () => changeTab('engine'),
|
|
4210
4828
|
engineOffline: offlineMessage !== '',
|
|
4211
4829
|
engineOfflineMessage: offlineMessage,
|
|
4212
4830
|
retrying,
|
|
@@ -4222,7 +4840,7 @@ export function KBPage() {
|
|
|
4222
4840
|
const enginePane = h(
|
|
4223
4841
|
'div',
|
|
4224
4842
|
{ key: 'pane-engine', className: 'kb-pane-scroll', style: { display: tab === 'engine' ? 'block' : 'none' } },
|
|
4225
|
-
h(EngineTab, { status, actions, retrying, onRetry: probe })
|
|
4843
|
+
h(EngineTab, { status, actions, retrying, onRetry: probe, onWizard: reopenWizard })
|
|
4226
4844
|
)
|
|
4227
4845
|
|
|
4228
4846
|
const engineAlert =
|