chatluna-plugin-kb 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -41,7 +41,7 @@ import { createSystemdController } from './src/engine/systemd.mjs'
41
41
  import { ensureBootstrap } from './src/engine/bootstrap.mjs'
42
42
  import { registerKbProxy } from './src/proxy/webui-proxy.mjs'
43
43
  import { registerKbWebUI } from './src/webui/server.mjs'
44
- import { registerInstallRoutes } from './src/webui/install-routes.mjs'
44
+ import { registerInstallRoutes, createInstallStatusBridge } from './src/webui/install-routes.mjs'
45
45
  import { registerModelRoutes } from './src/webui/model-routes.mjs'
46
46
  import { createModelBridge } from './src/webui/models.mjs'
47
47
  import { createInstaller, DEFAULT_RELEASE_MANIFEST_URL, platformInfo } from './src/engine/installer.mjs'
@@ -428,6 +428,14 @@ export function apply(ctx, config) {
428
428
  } catch {}
429
429
  }
430
430
 
431
+ // 安装器快照 → 事件桥:进度只推 install;进入终态(installed/failed/cancelled)或
432
+ // installed 翻转时补推 status,同一结论只发一次,三条安装路径(一键/URL/离线上传)共用。
433
+ const installEvents = createInstallStatusBridge({
434
+ emitInstall,
435
+ emitStatus,
436
+ isInstalled: () => existsSync(binaryPath)
437
+ })
438
+
431
439
  // ---- 安装器(仅 managed:负责下载/校验/解包到 <dataDir>/weknora-lite) ----
432
440
  let installer = null
433
441
  if (managed) {
@@ -439,8 +447,8 @@ export function apply(ctx, config) {
439
447
  releaseManifestUrl: config.releaseManifestUrl || DEFAULT_RELEASE_MANIFEST_URL,
440
448
  mirrors: Array.isArray(config.installMirrors) ? config.installMirrors : [],
441
449
  pluginVersion: String(config.pluginVersion ?? '').trim(),
442
- onStatus: () => {
443
- emitInstall()
450
+ onStatus: (snap) => {
451
+ installEvents.handleStatus(snap)
444
452
  },
445
453
  logger
446
454
  })
@@ -979,12 +987,10 @@ export function apply(ctx, config) {
979
987
  const engineInstaller = requireInstaller('自动安装')
980
988
  try {
981
989
  const result = await engineInstaller.installFromRelease()
982
- emitInstall()
983
- emitStatus()
990
+ installEvents.handleStatus({ state: 'ready' })
984
991
  return result ?? { ok: true }
985
992
  } catch (err) {
986
- emitInstall()
987
- emitStatus()
993
+ installEvents.handleStatus({ state: 'error' })
988
994
  throw new Error(sanitizeError(err))
989
995
  }
990
996
  }
@@ -996,12 +1002,10 @@ export function apply(ctx, config) {
996
1002
  try {
997
1003
  const options = typeof input?.sha256 === 'string' && input.sha256 !== '' ? { sha256: input.sha256 } : {}
998
1004
  const result = await engineInstaller.installFromUrl(url, options)
999
- emitInstall()
1000
- emitStatus()
1005
+ installEvents.handleStatus({ state: 'ready' })
1001
1006
  return result ?? { ok: true }
1002
1007
  } catch (err) {
1003
- emitInstall()
1004
- emitStatus()
1008
+ installEvents.handleStatus({ state: 'error' })
1005
1009
  throw new Error(sanitizeError(err))
1006
1010
  }
1007
1011
  }
@@ -1018,12 +1022,10 @@ export function apply(ctx, config) {
1018
1022
  try {
1019
1023
  const options = typeof input?.sha256 === 'string' && input.sha256 !== '' ? { sha256: input.sha256 } : {}
1020
1024
  const result = await engineInstaller.installFromFile(path, options)
1021
- emitInstall()
1022
- emitStatus()
1025
+ installEvents.handleStatus({ state: 'ready' })
1023
1026
  return result ?? { ok: true }
1024
1027
  } catch (err) {
1025
- emitInstall()
1026
- emitStatus()
1028
+ installEvents.handleStatus({ state: 'error' })
1027
1029
  throw new Error(sanitizeError(err))
1028
1030
  }
1029
1031
  }
@@ -1626,6 +1628,7 @@ export function apply(ctx, config) {
1626
1628
  prefix: '/kb-admin',
1627
1629
  installer,
1628
1630
  authorize: (context, req) => isWebuiAuthorized(context ?? ctx, req, logger),
1631
+ onInstalled: (snapshot) => installEvents.handleStatus(snapshot),
1629
1632
  maxBytes: INSTALL_UPLOAD_MAX,
1630
1633
  logger
1631
1634
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatluna-plugin-kb",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "ChatLuna v2 knowledge base plugin: WeKnora REST tools, managed weknora-lite engine and WebUI install wizard",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
@@ -127,6 +127,65 @@ function disposeOf(handle) {
127
127
  else if (typeof handle?.dispose === 'function') handle.dispose()
128
128
  }
129
129
 
130
+ const INSTALLED_STATES = new Set(['ready', 'installed'])
131
+ const FAILED_STATES = new Set(['error', 'failed'])
132
+ const TERMINAL_STATES = new Set([...INSTALLED_STATES, ...FAILED_STATES, 'cancelled'])
133
+
134
+ /**
135
+ * Bridge installer snapshots to ChatLuna events.
136
+ *
137
+ * Every snapshot feeds the `install` event (progress). A `status` broadcast is added only when
138
+ * the installer reaches a terminal state (installed / failed / cancelled) or when `installed`
139
+ * flips, so the WebUI sees the outcome of all three install paths — release download, URL and
140
+ * offline upload — without a page reload. The same conclusion is emitted once: the terminal
141
+ * outcome plus the installed flag form the dedupe key, and the key resets when a new job starts
142
+ * (busy state entered from a settled one) so a retry still announces its own result.
143
+ *
144
+ * Snapshots only produce events; nothing here logs.
145
+ */
146
+ export function createInstallStatusBridge(options = {}) {
147
+ const emitInstall = typeof options.emitInstall === 'function' ? options.emitInstall : () => {}
148
+ const emitStatus = typeof options.emitStatus === 'function' ? options.emitStatus : () => {}
149
+ const isInstalled = typeof options.isInstalled === 'function' ? options.isInstalled : null
150
+
151
+ let lastState = null
152
+ let lastInstalled = false
153
+ let lastKey = ''
154
+
155
+ return {
156
+ /** @param {{ state?: string, message?: string, error?: string }} [snap] installer snapshot */
157
+ handleStatus(snap) {
158
+ emitInstall()
159
+ if (snap === null || typeof snap !== 'object') return
160
+
161
+ const state = typeof snap.state === 'string' ? snap.state.trim().toLowerCase() : ''
162
+ const previous = lastState
163
+ lastState = state
164
+
165
+ const previousBusy =
166
+ previous !== null && previous !== '' && previous !== 'idle' && !TERMINAL_STATES.has(previous)
167
+ const busy = state !== '' && state !== 'idle' && !TERMINAL_STATES.has(state)
168
+ if (busy && !previousBusy) lastKey = ''
169
+
170
+ let outcome = ''
171
+ if (INSTALLED_STATES.has(state)) outcome = 'installed'
172
+ else if (FAILED_STATES.has(state)) outcome = 'failed'
173
+ else if (state === 'cancelled' || (state === 'idle' && previousBusy)) outcome = 'cancelled'
174
+
175
+ let installed = lastInstalled
176
+ if (isInstalled !== null) installed = isInstalled() === true
177
+ const installedChanged = installed !== lastInstalled
178
+ lastInstalled = installed
179
+
180
+ if (outcome === '' && !installedChanged) return
181
+ const key = `${outcome}|${installed}`
182
+ if (key === lastKey) return
183
+ lastKey = key
184
+ emitStatus()
185
+ }
186
+ }
187
+ }
188
+
130
189
  /**
131
190
  * Register the install wizard endpoints on the ChatLuna server.
132
191
  *
@@ -135,6 +194,8 @@ function disposeOf(handle) {
135
194
  * @param {string} [options.prefix='/kb-admin']
136
195
  * @param {{ installFromStream: (stream: import('node:stream').Readable, meta: { sha256?: string, filename?: string }) => Promise<unknown>, status: () => unknown }} options.installer
137
196
  * @param {(ctx: object, req: object) => boolean | Promise<boolean>} options.authorize
197
+ * @param {(snapshot: unknown) => void} [options.onInstalled] runs after a successful upload with
198
+ * the fresh installer status so the host can broadcast `chatluna-kb/status`
138
199
  * @param {number} [options.maxBytes=314572800]
139
200
  * @param {object} [options.logger]
140
201
  * @returns {() => void} dispose
@@ -156,6 +217,9 @@ export function registerInstallRoutes(ctx, options = {}) {
156
217
  if (typeof options.authorize !== 'function') {
157
218
  throw new TypeError('registerInstallRoutes: options.authorize must be a function')
158
219
  }
220
+ if (options.onInstalled !== undefined && typeof options.onInstalled !== 'function') {
221
+ throw new TypeError('registerInstallRoutes: options.onInstalled must be a function')
222
+ }
159
223
 
160
224
  const prefix = normalizePrefix(options.prefix)
161
225
  const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES
@@ -164,6 +228,7 @@ export function registerInstallRoutes(ctx, options = {}) {
164
228
  }
165
229
  const logger = options.logger ?? defaultLogger
166
230
  const authorize = options.authorize
231
+ const onInstalled = options.onInstalled
167
232
 
168
233
  const allowed = async (req) => {
169
234
  try {
@@ -254,6 +319,13 @@ export function registerInstallRoutes(ctx, options = {}) {
254
319
  sendError(res, 500, 'INSTALL_FAILED', '无法读取安装状态')
255
320
  return
256
321
  }
322
+ if (onInstalled !== undefined) {
323
+ try {
324
+ onInstalled(snapshot)
325
+ } catch {
326
+ // Broadcasting is best-effort: a listener failure must not turn a finished upload into a 500.
327
+ }
328
+ }
257
329
  sendJson(res, 200, { success: true, data: snapshot })
258
330
  }
259
331
 
package/web/client.js CHANGED
@@ -244,6 +244,88 @@ function wizardVisible(status) {
244
244
  return status.installed === false
245
245
  }
246
246
 
247
+ /**
248
+ * 向导会话锁:idle 只在首次可展示时进入 active;active/dismissed 是显式状态,
249
+ * 安装或启动带来的 installed/running 翻转绝不中途卸载正在使用的 InstallWizard。
250
+ */
251
+ export function advanceWizardSession(session, status) {
252
+ if (session === 'active' || session === 'dismissed') return session
253
+ return wizardVisible(status) ? 'active' : 'idle'
254
+ }
255
+
256
+ /** 同源 WeKnora 精简前端会写这些键;换实例后旧值指向别的 jwt-secret,必须清场。 */
257
+ const WEKNORA_SESSION_KEYS = [
258
+ 'weknora_token',
259
+ 'weknora_refresh_token',
260
+ 'weknora_user',
261
+ 'weknora_tenant',
262
+ 'weknora_knowledge_bases',
263
+ 'weknora_current_kb',
264
+ 'weknora_selected_tenant_id',
265
+ 'weknora_selected_tenant_name',
266
+ 'weknora_memberships'
267
+ ]
268
+
269
+ /** 记录当前 iframe 属于哪个引擎实例;指纹一致时绝不重复清缓存。 */
270
+ export const WEKNORA_INSTANCE_KEY = 'chatluna-kb:weknora-instance'
271
+
272
+ function localStorageOf(storage) {
273
+ if (storage !== undefined) return storage
274
+ try {
275
+ return typeof localStorage !== 'undefined' ? localStorage : null
276
+ } catch {
277
+ return null
278
+ }
279
+ }
280
+
281
+ /** 清理同源旧 WeKnora 会话;返回实际删除的键数量。隐私模式失败不阻断进入知识库。 */
282
+ export function clearStaleWeKnoraSession(storage) {
283
+ const store = localStorageOf(storage)
284
+ if (!store) return 0
285
+ let removed = 0
286
+ for (const key of WEKNORA_SESSION_KEYS) {
287
+ try {
288
+ if (store.getItem(key) === null) continue
289
+ store.removeItem(key)
290
+ removed += 1
291
+ } catch {
292
+ // 单个键不可写不影响其余键的清理。
293
+ }
294
+ }
295
+ return removed
296
+ }
297
+
298
+ /** 引擎实例指纹:kbId 与 readyAt 共同标识一次启动的 WeKnora 实例。 */
299
+ export function weknoraInstanceFingerprint(status) {
300
+ const kbId = textOf(status?.kbId)
301
+ const readyAt = finite(status?.readyAt) ?? 0
302
+ if (kbId === '' && readyAt === 0) return ''
303
+ return `${kbId}@${readyAt}`
304
+ }
305
+
306
+ /**
307
+ * 实例身份变化(kbId/readyAt 且本地指纹不一致)时清理旧会话,返回是否需要重载 iframe。
308
+ * 首次只记录指纹,避免每次重渲染或首次加载都清掉可用缓存。
309
+ */
310
+ export function syncWeKnoraInstance(status, storage) {
311
+ const store = localStorageOf(storage)
312
+ const fingerprint = weknoraInstanceFingerprint(status)
313
+ if (!store || fingerprint === '') return false
314
+ let previous = null
315
+ try {
316
+ previous = store.getItem(WEKNORA_INSTANCE_KEY)
317
+ } catch {
318
+ return false
319
+ }
320
+ try {
321
+ store.setItem(WEKNORA_INSTANCE_KEY, fingerprint)
322
+ } catch {
323
+ // 指纹写不进去只影响下一次判定,不影响本次清理。
324
+ }
325
+ if (previous === null || previous === fingerprint) return false
326
+ return clearStaleWeKnoraSession(store) > 0
327
+ }
328
+
247
329
  /** 非 ASCII 文件名不能直接进 HTTP 头;安全时原样发送,否则百分号编码。 */
248
330
  function headerFileName(name) {
249
331
  return /^[\x20-\x7e]*$/.test(name) ? name : encodeURIComponent(name)
@@ -320,6 +402,8 @@ export function viewStatus(snapshot) {
320
402
  mode: typeof data.mode === 'string' ? data.mode : '',
321
403
  managed: data.managed !== false && data.mode !== 'external',
322
404
  installed: typeof data.installed === 'boolean' ? data.installed : undefined,
405
+ kbId: textOf(data.kbId),
406
+ readyAt: finite(data.readyAt) ?? 0,
323
407
  running: data.running === true,
324
408
  ready: data.ready === true || data.running === true,
325
409
  unit: unitCandidate === undefined ? '' : unitCandidate.trim(),
@@ -2198,6 +2282,15 @@ function wizardBody(m) {
2198
2282
  )
2199
2283
  ),
2200
2284
  installFeedback(install),
2285
+ m.installed
2286
+ ? h(
2287
+ Alert,
2288
+ { className: 'kb-alert-muted', 'aria-live': 'polite' },
2289
+ h(UiIcon, { name: 'check' }),
2290
+ h(AlertTitle, null, '安装完成'),
2291
+ h(AlertDescription, null, '正在进入 Embedding 配置;可随时点「上一步」回看安装结果。')
2292
+ )
2293
+ : null,
2201
2294
  m.error !== '' && install.error === '' ? errorAlert(m.error) : null,
2202
2295
  h(
2203
2296
  'div',
@@ -2279,7 +2372,20 @@ function wizardBody(m) {
2279
2372
  test.state === 'error' ? h('span', { className: 'kb-error-text' }, '测试失败') : null
2280
2373
  ),
2281
2374
  test.state === 'error' && test.error ? errorAlert(test.error, '连通性测试失败') : null,
2282
- h(ModelCopyPanel, null),
2375
+ // Step 2 时引擎通常还没启动;此时复制模型面板必然连不上引擎,改为入口提示。
2376
+ status.running === true || m.started === true
2377
+ ? h(ModelCopyPanel, null)
2378
+ : h(
2379
+ Alert,
2380
+ { className: 'kb-alert-muted' },
2381
+ h(UiIcon, { name: 'alert-circle' }),
2382
+ h(AlertTitle, null, '引擎尚未启动'),
2383
+ h(
2384
+ AlertDescription,
2385
+ null,
2386
+ '引擎启动后,可在「引擎状态 → 复制模型」中一键同步 ChatLuna 的对话 / 视觉 / Embedding 模型。'
2387
+ )
2388
+ ),
2283
2389
  h(
2284
2390
  Collapsible,
2285
2391
  {
@@ -2436,6 +2542,17 @@ export function WizardPanel({ model }) {
2436
2542
  )
2437
2543
  }
2438
2544
 
2545
+ const INSTALL_AUTO_ADVANCE_MS = 600
2546
+
2547
+ /**
2548
+ * 安装完成跃迁:只有「此前未安装 → 现在已安装」且仍停在安装/配置步时才自动前进。
2549
+ * 600ms 延迟仅用于展示完成反馈;向导组件本身始终保持挂载。
2550
+ */
2551
+ export function installAdvance({ previousInstalled, installed, step }) {
2552
+ if (installed !== true || previousInstalled === true) return null
2553
+ return step === 0 || step === 1 ? 2 : null
2554
+ }
2555
+
2439
2556
  function InstallWizard({ status, install, onEnter, onDismiss }) {
2440
2557
  const [step, setStep] = useState(status.installed === true || install.installed ? 3 : 0)
2441
2558
  const [mode, setMode] = useState(status.mode === 'external' ? 'external' : 'lite')
@@ -2475,6 +2592,17 @@ function InstallWizard({ status, install, onEnter, onDismiss }) {
2475
2592
 
2476
2593
  // 引擎安装完成时允许直接进下一步,但保留用户手动确认。
2477
2594
  const installed = install.installed || status.installed === true
2595
+ const wasInstalled = useRef(installed)
2596
+
2597
+ // Step 1 安装完成后实时切到完成反馈,并自动进入 Step 2;向导保持挂载、无需刷新。
2598
+ useEffect(() => {
2599
+ const previous = wasInstalled.current
2600
+ wasInstalled.current = installed
2601
+ const target = installAdvance({ previousInstalled: previous, installed, step })
2602
+ if (target === null) return undefined
2603
+ const timer = setTimeout(() => setStep(target), INSTALL_AUTO_ADVANCE_MS)
2604
+ return () => clearTimeout(timer)
2605
+ }, [installed, step])
2478
2606
 
2479
2607
  const submitUrl = useCallback(async (payload) => {
2480
2608
  setBusy('install')
@@ -2704,6 +2832,35 @@ export function knowledgeTab(status, actions, install, wizard) {
2704
2832
  onDismiss: wizard.onDismiss
2705
2833
  })
2706
2834
  }
2835
+ // 暂缓引导但引擎都还没装:给专属空态,绝不能落「重启引擎」离线卡。
2836
+ if (status.managed === true && status.installed === false) {
2837
+ return h(
2838
+ Centered,
2839
+ null,
2840
+ h('p', { className: 'kb-section-lead' }, '知识库尚未初始化'),
2841
+ h('p', { className: 'kb-muted-text' }, '当前尚未安装本地知识库引擎,完成简短引导后即可使用。'),
2842
+ h(
2843
+ 'div',
2844
+ { className: 'kb-form-actions' },
2845
+ h(
2846
+ Button,
2847
+ {
2848
+ onClick: typeof wizard.onReopen === 'function' ? wizard.onReopen : undefined
2849
+ },
2850
+ h(UiIcon, { name: 'download' }),
2851
+ '继续安装引导'
2852
+ ),
2853
+ h(
2854
+ Button,
2855
+ {
2856
+ variant: 'outline',
2857
+ onClick: typeof wizard.onOpenEngine === 'function' ? wizard.onOpenEngine : undefined
2858
+ },
2859
+ '查看引擎状态'
2860
+ )
2861
+ )
2862
+ )
2863
+ }
2707
2864
  if (status.live === 'loading') {
2708
2865
  return h(Centered, null, h('p', { className: 'kb-muted-text' }, '正在读取引擎状态…'))
2709
2866
  }
@@ -3909,7 +4066,7 @@ export function ModelCopyDialog({ open = false, onOpenChange, children }) {
3909
4066
  )
3910
4067
  }
3911
4068
 
3912
- export function EngineTab({ status, actions, retrying, onRetry }) {
4069
+ export function EngineTab({ status, actions, retrying, onRetry, onWizard }) {
3913
4070
  const [wrap, setWrap] = useState(true)
3914
4071
  const [logQuery, setLogQuery] = useState('')
3915
4072
  const [warningsOnly, setWarningsOnly] = useState(false)
@@ -3942,6 +4099,21 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
3942
4099
  retrying === true ? '检测中…' : '重新检测'
3943
4100
  )
3944
4101
  )
4102
+ } else if (status.installed === false) {
4103
+ // 引擎还没装:重启/停止必然失败,直接给安装引导主入口。
4104
+ buttons.push(
4105
+ h(
4106
+ Button,
4107
+ {
4108
+ key: 'install-wizard',
4109
+ size: 'sm',
4110
+ disabled: loading || typeof onWizard !== 'function',
4111
+ onClick: typeof onWizard === 'function' ? onWizard : undefined
4112
+ },
4113
+ h(UiIcon, { name: 'download' }),
4114
+ '开始安装引导'
4115
+ )
4116
+ )
3945
4117
  } else if (running) {
3946
4118
  buttons.push(
3947
4119
  h(
@@ -3986,6 +4158,17 @@ export function EngineTab({ status, actions, retrying, onRetry }) {
3986
4158
  )
3987
4159
  )
3988
4160
  }
4161
+ // 已安装的托管引擎保留轻量入口,方便复查 Embedding 或重新拉起。
4162
+ if (status.managed && status.installed === true && typeof onWizard === 'function') {
4163
+ buttons.push(
4164
+ h(
4165
+ Button,
4166
+ { key: 'rewizard', variant: 'ghost', size: 'sm', onClick: onWizard },
4167
+ h(UiIcon, { name: 'settings' }),
4168
+ '配置向导'
4169
+ )
4170
+ )
4171
+ }
3989
4172
 
3990
4173
  const detailRows = [
3991
4174
  { label: '运行模式', value: modeLabel(status.mode) },
@@ -4112,7 +4295,7 @@ export function KBPage() {
4112
4295
  const [params, setParams] = useSearchParams()
4113
4296
  const [tab, setTab] = useState(() => tabFromParams(params) ?? initialTab())
4114
4297
  const legacyPath = useRef(initialTab() !== 'knowledge')
4115
- const [wizardDismissed, setWizardDismissed] = useState(false)
4298
+ const [wizardSession, setWizardSession] = useState('idle')
4116
4299
  const [offlineMessage, setOfflineMessage] = useState('')
4117
4300
  const [retrying, setRetrying] = useState(false)
4118
4301
  const [frameKey, setFrameKey] = useState(0)
@@ -4160,6 +4343,28 @@ export function KBPage() {
4160
4343
  lastRunning.current = status.running
4161
4344
  }, [status.running, reloadFrame])
4162
4345
 
4346
+ // 会话锁:首次可展示时进入 active;之后 installed/running 翻转都不再卸载向导。
4347
+ useEffect(() => {
4348
+ setWizardSession((current) => advanceWizardSession(current, status))
4349
+ }, [status.live, status.managed, status.installed, status.running])
4350
+
4351
+ // 引擎实例身份变化(kbId/readyAt 且本地指纹不一致):清旧 WeKnora 会话并重载 iframe。
4352
+ useEffect(() => {
4353
+ if (syncWeKnoraInstance(status)) reloadFrame()
4354
+ }, [status.kbId, status.readyAt, reloadFrame])
4355
+
4356
+ const enterKnowledge = useCallback(() => {
4357
+ // 同源残留的旧实例 token 会让 WeKnora 撞死在登录页;进入前先清场再重载 iframe。
4358
+ clearStaleWeKnoraSession()
4359
+ reloadFrame()
4360
+ setWizardSession('dismissed')
4361
+ }, [reloadFrame])
4362
+ const dismissWizard = useCallback(() => setWizardSession('dismissed'), [])
4363
+ const reopenWizard = useCallback(() => {
4364
+ changeTab('knowledge')
4365
+ setWizardSession('active')
4366
+ }, [changeTab])
4367
+
4163
4368
  // 「重试连接」直接探测同源反代:200 说明引擎已恢复,503 则继续展示离线卡片。
4164
4369
  const probe = useCallback(async () => {
4165
4370
  setRetrying(true)
@@ -4193,7 +4398,7 @@ export function KBPage() {
4193
4398
  }
4194
4399
  }, [reloadFrame])
4195
4400
 
4196
- const showWizard = !wizardDismissed && wizardVisible(status)
4401
+ const showWizard = wizardSession === 'active'
4197
4402
 
4198
4403
  // 三个面板常驻,只切换 display;知识库 iframe 绝不能因切 Tab 被卸载重载。
4199
4404
  const knowledgePane = h(
@@ -4205,8 +4410,10 @@ export function KBPage() {
4205
4410
  },
4206
4411
  knowledgeTab(status, actions, install, {
4207
4412
  visible: showWizard,
4208
- onEnter: () => setWizardDismissed(true),
4209
- onDismiss: () => setWizardDismissed(true),
4413
+ onEnter: enterKnowledge,
4414
+ onDismiss: dismissWizard,
4415
+ onReopen: reopenWizard,
4416
+ onOpenEngine: () => changeTab('engine'),
4210
4417
  engineOffline: offlineMessage !== '',
4211
4418
  engineOfflineMessage: offlineMessage,
4212
4419
  retrying,
@@ -4222,7 +4429,7 @@ export function KBPage() {
4222
4429
  const enginePane = h(
4223
4430
  'div',
4224
4431
  { key: 'pane-engine', className: 'kb-pane-scroll', style: { display: tab === 'engine' ? 'block' : 'none' } },
4225
- h(EngineTab, { status, actions, retrying, onRetry: probe })
4432
+ h(EngineTab, { status, actions, retrying, onRetry: probe, onWizard: reopenWizard })
4226
4433
  )
4227
4434
 
4228
4435
  const engineAlert =