dsh-dafeiyu-life 2.8.2 → 2.8.3-dev.14

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.
Files changed (107) hide show
  1. package/AGENTS.md +14 -2
  2. package/CHANGELOG.md +515 -0
  3. package/README.md +6 -2
  4. package/client.js +333 -84
  5. package/docs/ROADMAP.md +10 -4
  6. package/docs/architecture/2.8.2-current-architecture.md +2 -0
  7. package/docs/architecture/2.8.3-dev2-storage-and-memory.md +42 -0
  8. package/docs/architecture/2.8.3-dev3-cross-platform-installer-audit.md +44 -0
  9. package/docs/architecture/2.8.3-dev3-preview-read-auto-recovery.md +31 -0
  10. package/docs/architecture/2.8.3-dev3-storage-domains.md +163 -0
  11. package/docs/architecture/2.8.3-video-perception-memory-roadmap.md +20 -1
  12. package/docs/architecture/README.md +13 -1
  13. package/docs/architecture/diagrams/life-candidates-current.mmd +40 -0
  14. package/docs/architecture/diagrams/life-receipt-memory-current.mmd +50 -1
  15. package/docs/architecture/diagrams/life-system-current.mmd +46 -0
  16. package/docs/architecture/diagrams/life-universal-episodes-current.mmd +37 -0
  17. package/docs/architecture/future-layered-memory-progressive-recall-proposal.md +2 -2
  18. package/docs/architecture/life-system-current-view.md +173 -1
  19. package/docs/architecture/life-system-current.md +34 -0
  20. package/index.js +922 -219
  21. package/lib/account-binding.mjs +13 -2
  22. package/lib/asr.py +16 -3
  23. package/lib/autonomous-planner.mjs +155 -32
  24. package/lib/backup-directory.mjs +13 -6
  25. package/lib/backup-rotation.mjs +74 -0
  26. package/lib/cold-state-snapshot.mjs +9 -0
  27. package/lib/conversation-life-feedback.mjs +2 -1
  28. package/lib/data-backup.mjs +77 -20
  29. package/lib/embedding-memory-index.mjs +96 -12
  30. package/lib/embedding-runtime-manager.mjs +8 -4
  31. package/lib/emotion-recall.mjs +2 -1
  32. package/lib/emotional-state.mjs +2 -1
  33. package/lib/interaction-batch.mjs +10 -4
  34. package/lib/life-continuation.mjs +4 -0
  35. package/lib/life-decision-trace.mjs +4 -1
  36. package/lib/life-experience-continuity.mjs +2 -1
  37. package/lib/life-interests.mjs +14 -4
  38. package/lib/life-management-events.mjs +1 -1
  39. package/lib/life-memory-associations.mjs +72 -0
  40. package/lib/life-memory-coordinator.mjs +5 -2
  41. package/lib/life-memory-details.mjs +178 -0
  42. package/lib/life-memory-gateway.mjs +443 -43
  43. package/lib/life-reflection.mjs +90 -15
  44. package/lib/life-video-gallery.mjs +159 -0
  45. package/lib/life-willingness.mjs +15 -3
  46. package/lib/local-vision-model-manager.mjs +4 -1
  47. package/lib/long-term-memory.mjs +38 -9
  48. package/lib/main-session-bridge.mjs +47 -8
  49. package/lib/management-console.html +760 -108
  50. package/lib/management-console.js +1147 -182
  51. package/lib/management-host-auth.mjs +77 -0
  52. package/lib/mcp.mjs +9 -4
  53. package/lib/memory-neural-projection.mjs +59 -5
  54. package/lib/memory-retriever.mjs +200 -21
  55. package/lib/migration-wait.html +13 -0
  56. package/lib/migration-wait.js +35 -0
  57. package/lib/owner-dm-agent.mjs +7 -1
  58. package/lib/owner-video-debug-local-vision.mjs +136 -0
  59. package/lib/owner-video-revisit.mjs +30 -0
  60. package/lib/preview_vision.py +513 -80
  61. package/lib/private-conversation-experiences.mjs +2 -1
  62. package/lib/read-action-execution-gate.mjs +44 -5
  63. package/lib/recent-comments.mjs +14 -4
  64. package/lib/social-context-assembler.mjs +23 -6
  65. package/lib/state.mjs +6 -13
  66. package/lib/storage-archive-inventory.mjs +50 -0
  67. package/lib/storage-cleanup-queue.mjs +154 -0
  68. package/lib/storage-external-life-retired.mjs +130 -0
  69. package/lib/storage-large-data-v2.mjs +215 -0
  70. package/lib/storage-layout.mjs +629 -0
  71. package/lib/storage-life-cleanup-queue.mjs +129 -0
  72. package/lib/storage-life-retained.mjs +161 -0
  73. package/lib/storage-life-return-evidence.mjs +40 -0
  74. package/lib/storage-life-runtime-check.mjs +184 -0
  75. package/lib/storage-location.mjs +154 -0
  76. package/lib/storage-maintenance.mjs +112 -0
  77. package/lib/storage-migration-maintenance-state.mjs +31 -0
  78. package/lib/storage-migration-maintenance.mjs +85 -0
  79. package/lib/storage-migration-queue.mjs +199 -0
  80. package/lib/storage-model-runtime-check.mjs +110 -0
  81. package/lib/storage-platform.mjs +23 -0
  82. package/lib/storage-python-cache-check.mjs +55 -0
  83. package/lib/storage-vision-cache-access.mjs +44 -0
  84. package/lib/storage-vision-runtime-check.mjs +160 -0
  85. package/lib/system-health-projection.mjs +20 -3
  86. package/lib/video-cache-retention.mjs +75 -0
  87. package/lib/video-dependencies.mjs +5 -2
  88. package/lib/video-evidence-bundle.mjs +13 -13
  89. package/lib/video-experience.mjs +65 -0
  90. package/lib/video-memory-observation-groups.mjs +88 -0
  91. package/lib/video-moment-followup.mjs +1 -1
  92. package/lib/video-visual-attempt-diagnostics.mjs +3 -2
  93. package/lib/video-visual-failure.mjs +14 -1
  94. package/lib/vision-environment-repair.mjs +49 -8
  95. package/lib/vision-production-status.mjs +7 -1
  96. package/lib/vision-python-runtime.mjs +15 -5
  97. package/lib/vision_dsh.py +12 -7
  98. package/lib/whisper-model-cache.mjs +5 -1
  99. package/package.json +4 -1
  100. package/scripts/check-vision-cache-access.mjs +22 -0
  101. package/scripts/migrate-bili-duty-after-exit.mjs +10 -0
  102. package/scripts/resolve-bili-duty-storage.mjs +13 -0
  103. package/tools/repair-dsh-python-runtime.ps1 +9 -3
  104. package/tools/repair-dsh-vision-python.ps1 +9 -3
  105. package/tools//345/257/274/345/207/272B/347/253/231/346/227/245/345/277/227.bat +19 -1
  106. package/vendor/bilibili-mcp/mcp_server.py +82 -20
  107. package/vendor/bilibili-mcp/read_action_gate.py +118 -37
package/client.js CHANGED
@@ -21,7 +21,7 @@
21
21
  * 这一页要满足使用者 2026-10-14 说的形状:
22
22
  * · **总开关 → 打开之后配置自定义自动刷时间段**(支持跨午夜和多时段)
23
23
  * · **数字项要能自己填**(定量刷:每天几条)
24
- * · B站账号绑定及扫码登录统一由管理中心 → 首次设置管理。
24
+ * · B站账号常规登录由管理中心管理;原生设置保留显式安全恢复入口。
25
25
  * · 会发东西出去的(自动评论)、要下大模型的(本地转写)**默认关**
26
26
  * ============================================================================
27
27
  */
@@ -45,14 +45,57 @@ window.__ModuleLoader__.load({
45
45
  } catch { /* 不是 JSON 时保留明确 HTTP 状态 */ }
46
46
  throw new Error('HTTP ' + res.status + (reason ? ':' + reason : '(本地接口拒绝,原因未返回)'))
47
47
  }
48
- const jget = async (p) => asJson(await fetch(API + p, { credentials: 'same-origin' }))
49
- const jpost = async (p, body) => asJson(await fetch(API + p, {
50
- method: 'POST',
48
+ const jget = async (p) => asJson(await fetch(API + p, { credentials: 'same-origin', referrerPolicy:'no-referrer' }))
49
+ const jpost = async (p, body, signal) => asJson(await fetch(API + p, {
50
+ method: 'POST', signal,
51
51
  credentials: 'same-origin',
52
- headers: { 'content-type': 'application/json' },
52
+ referrerPolicy:'no-referrer',
53
+ headers: { 'content-type': 'application/json', 'x-dafeiyu-management-intent':'1' },
53
54
  body: JSON.stringify(body || {}),
54
55
  }))
55
56
 
57
+ // Official optional sidebar slot. No session creation/navigation or DOM hacks.
58
+ // Resolve the optional primitive only when the row actually renders.
59
+ const bindNativeMainSession=async(sessionId)=>{
60
+ const current=await jget('/main-session?directory=1')
61
+ if(current?.directoryProtocol!==4||current.nativeBindingAvailable!==true||typeof current.selectedId!=='string')throw Error('当前后端或宿主不支持原生绑定,请使用管理页手动选择。')
62
+ const result=await jpost('/main-session/bind',{confirm:'BIND_EXISTING_MAIN_SESSION',sessionId,expectedId:current.selectedId})
63
+ if(result?.ok!==true||result.selectedId!==String(sessionId).replace(/^session-/,''))throw Error('绑定未获确认,请在管理页核对。')
64
+ return result
65
+ }
66
+ function BindMainSessionMenu({sessionId,useMenuOpenState}){
67
+ const [menuOpen,setMenuOpen]=useMenuOpenState()
68
+ const pending=React.useRef(false)
69
+ const [busy,setBusy]=React.useState(false)
70
+ const [binding,setBinding]=React.useState(null)
71
+ // Read fresh when this native menu opens. A failed/old backend never
72
+ // supplies a misleading bound badge; no list polling or host mutation.
73
+ React.useEffect(()=>{
74
+ let active=true
75
+ if(menuOpen){
76
+ setBinding(null)
77
+ jget('/main-session?directory=1').then(data=>{
78
+ if(active&&data?.directoryProtocol===4&&typeof data.selectedId==='string')setBinding({row:sessionId,selectedId:data.selectedId})
79
+ }).catch(()=>{})
80
+ }else setBinding(null)
81
+ return ()=>{active=false}
82
+ },[menuOpen,sessionId])
83
+ const isBound=menuOpen&&binding?.row===sessionId&&typeof sessionId==='string'&&!!sessionId&&binding.selectedId===sessionId.replace(/^session-/,'')
84
+ let MenuItemButton
85
+ try{MenuItemButton=require('@deepseek-ai/dsh-client-ui-primitives').MenuItemButton}catch{}
86
+ const select=async()=>{
87
+ if(pending.current||isBound||typeof sessionId!=='string'||!sessionId)return
88
+ pending.current=true;setBusy(true)
89
+ try{
90
+ const result=await bindNativeMainSession(sessionId)
91
+ setMenuOpen(false)
92
+ window.alert('已设为大肥鱼主 Session。'+(result.targetLive?'':'会话尚未驻留,待 DSH 激活后可同步。')+' 未改变其他设置。')
93
+ }catch(e){window.alert('主 Session 绑定未确认:'+String(e?.message||e).slice(0,200)+' 可在管理页手动选择。')}
94
+ finally{pending.current=false;setBusy(false)}
95
+ }
96
+ const label=busy?'正在绑定…':isBound?'★ 当前大肥鱼主 Session':'设为大肥鱼主 Session'
97
+ return MenuItemButton?h(MenuItemButton,{separatorBefore:true,disabled:busy||isBound,onSelect:select},label):h('button',{type:'button',role:'menuitem','data-bd-btn':'',disabled:busy||isBound,onClick:select},label)
98
+ }
56
99
  const CSS = `
57
100
  [data-bd-page]{display:flex;flex-direction:column;gap:18px;padding:2px 2px 8px;max-width:640px;}
58
101
  [data-bd-page][data-bd-wide]{max-width:none;width:100%;}
@@ -87,6 +130,8 @@ window.__ModuleLoader__.load({
87
130
  background:var(--dsw-alias-bg-layer-4,rgba(128,128,128,.12));color:var(--dsw-alias-label-tertiary,#9aa0a6);}
88
131
  [data-bd-msg][data-warn]{color:#f59e0b;}
89
132
  [data-bd-msg][data-good]{color:#22c55e;}
133
+ [data-bd-migration-spin]{display:inline-block;width:20px;height:20px;margin-right:10px;border:3px solid currentColor;border-right-color:transparent;border-radius:50%;vertical-align:middle;animation:bd-migration-rotate .8s linear infinite}
134
+ @keyframes bd-migration-rotate{to{transform:rotate(360deg)}}
90
135
  [data-bd-qr]{display:flex;gap:14px;align-items:flex-start;}
91
136
  [data-bd-qr] img{width:150px;height:150px;border-radius:8px;background:#fff;padding:6px;}
92
137
  [data-bd-pre]{margin:6px 0 0;padding:8px 9px;border-radius:8px;max-height:170px;overflow:auto;font-size:11px;
@@ -164,6 +209,11 @@ window.__ModuleLoader__.load({
164
209
  [data-bd-btn]{border-radius:10px;font-weight:650;transition:filter .15s,transform .15s;}
165
210
  [data-bd-btn]:not(:disabled):hover{transform:translateY(-1px);}
166
211
  [data-bd-btn][data-primary]{background:#187c63;border-color:#187c63;color:#fff;}
212
+ [data-bd-browser-auth]{display:flex;flex-direction:column;gap:10px;padding:13px;border:1px solid rgba(24,124,99,.48);border-radius:12px;background:rgba(24,124,99,.065);margin:4px 0;}
213
+ [data-bd-browser-auth] [data-bd-note]{font-size:12px;line-height:1.65;color:var(--dsw-alias-label-secondary,inherit)}
214
+ [data-bd-browser-recovery]:not([hidden]){display:flex;flex-direction:column;gap:10px}
215
+ [data-bd-browser-auth] [data-bd-label]{font-size:14px;font-weight:750}
216
+ [data-bd-browser-auth] [data-bd-input]{max-width:180px;font-size:14px;letter-spacing:.08em}
167
217
  [data-bd-tabs]{border-radius:12px;}
168
218
  [data-bd-tab][aria-selected=true]{box-shadow:0 3px 10px rgba(40,88,160,.1);}
169
219
  [data-bd-item]{box-shadow:0 5px 18px rgba(26,57,98,.07);border-radius:14px;}
@@ -199,29 +249,49 @@ window.__ModuleLoader__.load({
199
249
  // ⭐ 2026-10-19(用户报"没有开关这一项,只能让 ai 帮我开"):读不到配置时界面只显示"读设置中…",
200
250
  // 用户会以为是开关坏了 ✗ ⇒ 数一下连续失败次数,交给界面把话说清楚(版本太旧 / 没重启 / 读不到)
201
251
  const [fails, setFails] = React.useState(0)
252
+ const [maintenance, setMaintenance] = React.useState(null)
202
253
  React.useEffect(() => {
203
254
  let alive = true
204
255
  const tick = async () => {
205
256
  try {
206
257
  const d = await jget('/status')
207
258
  if (!alive) return
208
- if (d && d.ok) { setSt(d); setFails(0) } else setFails((n) => n + 1)
209
- } catch { if (alive) setFails((n) => n + 1) }
259
+ if (d && d.ok) { setSt(d); setFails(0); setMaintenance(null); return }
260
+ } catch { /* Try the independent maintenance-only endpoint below. */ }
261
+ try {
262
+ const m = await jget('/migration/status')
263
+ if (!alive) return
264
+ if (m?.ok && (m.maintenance || ['completed','cancelled','failed'].includes(m.status))) {
265
+ setMaintenance(m);setFails(0);return
266
+ }
267
+ } catch { /* No maintenance route means a normal startup issue. */ }
268
+ if (alive) {setMaintenance(null);setFails(n=>n+1)}
210
269
  }
211
270
  tick()
212
- const t = setInterval(tick, intervalMs || 5000)
271
+ const t = setInterval(tick, 2500)
213
272
  return () => { alive = false; clearInterval(t) }
214
273
  }, [intervalMs])
215
- return [st, setSt, fails]
274
+ return [st, setSt, fails, maintenance, setMaintenance]
216
275
  }
217
276
 
218
277
  /* ────────────── 设置页正文 ────────────── */
219
278
 
220
279
  function Panel() {
221
- const [st, setSt, fails] = useStatus(5000)
280
+ const [st, setSt, fails, maintenance, setMaintenance] = useStatus(5000)
222
281
  const [busy, setBusy] = React.useState('')
223
282
  const [msg, setMsg] = React.useState('')
224
283
  const [manageError, setManageError] = React.useState('')
284
+ const [manageBrowser,setManageBrowser] = React.useState(null)
285
+ const [pairCode,setPairCode] = React.useState('')
286
+ const [pairBusy,setPairBusy] = React.useState(false)
287
+ const [pairResult,setPairResult] = React.useState('')
288
+ const pairPending=React.useRef(false)
289
+ const pairAbort=React.useRef(null)
290
+ const manageOpenAbort=React.useRef(null)
291
+ const [manageOpening,setManageOpening]=React.useState(false)
292
+ const [manageNotice,setManageNotice]=React.useState('')
293
+ const [browserAuthExpanded,setBrowserAuthExpanded]=React.useState(false)
294
+ React.useEffect(()=>()=>{pairAbort.current?.abort();manageOpenAbort.current?.abort()},[])
225
295
  const [msgTone, setMsgTone] = React.useState('')
226
296
  const [kws, setKws] = React.useState(null)
227
297
  const [favFolders, setFavFolders] = React.useState(null) // 收藏夹列表(下拉用,null = 还没读)
@@ -339,56 +409,166 @@ window.__ModuleLoader__.load({
339
409
  setRunNote(text ? { t: text, tone: tone || '' } : null) // ⭐ 同时镜像到顶部,免得提示掉到页面最底下看不见
340
410
  }
341
411
 
342
- // DSH Mobile 是手机上运行的已配对 HTTPS WebView,实际业务仍在电脑端。
343
- // 后台调用系统浏览器只会在电脑上打开页面,不能作为手机的管理入口。
344
- // 始终使用当前 WebView 的同源路径;不要从 Host 推断、拼接或返回本机地址。
345
- const onOpenManage = async (tab = '', anchor = '') => {
346
- setManageError('')
412
+ // Official login links confer full Host owner access. Read only on an
413
+ // explicit Desktop open action; never put the link into React state, plugin
414
+ // API responses, logs, clipboard, management URL or persistent storage.
415
+ const openExternalManagementLink = href => {
416
+ const link=document.createElement('a');link.href=href;link.target='_blank';link.rel='noopener noreferrer';link.referrerPolicy='no-referrer';link.hidden=true
417
+ document.body.appendChild(link);try{link.click()}finally{link.remove()}
418
+ }
419
+ const tryOfficialBrowserLogin = async (origin, signal) => {
420
+ try {
421
+ const raw=await pairingRpc('loginUrl',{},AbortSignal.any([signal,AbortSignal.timeout(4000)]))
422
+ signal.throwIfAborted()
423
+ if(typeof raw!=='string'||raw.length>8192)return false
424
+ const login=new URL(raw)
425
+ // Do not rewrite a credential for another authority, accept extra
426
+ // query parameters, or forward it to a custom/plugin route.
427
+ if(login.origin!==origin||login.pathname!=='/'||login.username||login.password||login.hash||login.searchParams.getAll('token').length!==1||!login.searchParams.get('token')||Array.from(login.searchParams.keys()).length!==1)return false
428
+ openExternalManagementLink(login.href)
429
+ return true
430
+ }catch {return false} // never surface a credential-bearing exception
431
+ }
432
+ // Desktop opens a clean external launcher; mobile/web keep their authenticated carrier.
433
+ // The optional internal fallback is explicit, never silently replaces the chat window.
434
+ const onOpenManage = async (tab = '', anchor = '', inside = false) => {
435
+ if(manageOpenAbort.current)return
436
+ const controller=new AbortController();manageOpenAbort.current=controller;setManageOpening(true)
437
+ const timeout=setTimeout(()=>controller.abort(),12000)
438
+ setManageError('');setPairResult('');setManageNotice('')
347
439
  try {
348
440
  const safeTab = ['firststart', 'models', 'home', 'life', 'life-agent'].includes(tab) ? tab : ''
349
441
  const safeAnchor=safeTab==='firststart'&&anchor==='fs-deps-card'?'fs-deps-card':''
350
- const ua = String(window.navigator?.userAgent || '')
351
- const smallTouch = Number(window.navigator?.maxTouchPoints || 0) > 0 &&
352
- Number(window.innerWidth || 1024) <= 900
353
- const isMobile = /Android|iPhone|iPad|iPod|Mobile/i.test(ua) || smallTouch
354
- if (!isMobile) {
355
- const result = await jpost('/open', {what: 'manage', tab: safeTab, anchor: safeAnchor})
356
- if (result?.ok !== true) throw new Error(result?.error || '宿主没有确认打开管理中心')
357
- return
358
- }
359
-
360
- // 通过 DSH Mobile 同源 HTTPS 入口时,配对、TLS 和代理 CSRF 校验由网关执行。
361
- // 非 HTTP(S)(例如不带已配对网关的私有 scheme)不可跳转 127.0.0.1。
362
- if (!/^https?:$/i.test(String(window.location?.protocol || '')))
363
- throw new Error('当前不是 DSH Mobile 的 HTTP(S) 配对页面;请在已配对设备内打开 DSH')
442
+ const protocol=String(window.location?.protocol||'')
443
+ const desktop=protocol==='dsh-app:'&&window.location?.host==='app'
444
+ if (!desktop&&!/^https?:$/i.test(protocol))
445
+ throw new Error('当前不是受支持的 DSH Desktop 或 HTTP(S) 登录/配对页面')
364
446
  const path = '/api/bili-duty/manage' + (safeTab ? '?tab=' + encodeURIComponent(safeTab) : '')
365
- const probe = await fetch(path, {credentials: 'same-origin', redirect: 'follow'})
447
+ const probe = await fetch(path, {credentials: 'same-origin', redirect: 'manual', cache:'no-store', referrerPolicy:'no-referrer',signal:controller.signal})
448
+ controller.signal.throwIfAborted()
366
449
  if (!probe.ok) {
367
- let reason = ''
368
- try {const json = await probe.json();if (typeof json?.error === 'string') reason = json.error.slice(0, 120)} catch {}
369
- throw new Error('HTTP ' + probe.status + (reason ? ':' + reason : ':管理页面被当前移动通道拒绝'))
450
+ const reason=({401:'DSH 宿主尚未登录;无需重新扫码 B站',403:'当前来源或主人权限被拒绝',503:'宿主认证服务暂不可用'})[probe.status]||'没有获得管理中心页面,请检查插件是否已加载'
451
+ throw new Error('HTTP '+probe.status+':'+reason)
370
452
  }
371
453
  if (!/text\/html/i.test(String(probe.headers?.get?.('content-type') || '')))
372
- throw new Error('移动网关未返回管理中心 HTML 页面')
373
- // 代理或认证层可能在返回 200 后显示通用登录页;必须确认响应来自本插件。
454
+ throw new Error('宿主未返回管理中心 HTML 页面')
374
455
  let isManage = probe.headers?.get?.('x-dafeiyu-management') === '1'
375
456
  if (!isManage && typeof probe.text === 'function') {
376
457
  const html = await probe.text()
377
458
  isManage = html.includes('<meta name="dafeiyu-management" content="1">')
378
459
  }
379
- if (!isManage) throw new Error('移动访问通道返回的不是大肥鱼管理中心;请检查配对登录状态')
380
- // 同一个已配对 HTTPS Origin 打开,不触发电脑浏览器、不暴露独立管理端口。
381
- window.location.assign(path+(safeAnchor?'#'+safeAnchor:''))
460
+ if (!isManage) throw new Error('当前访问通道返回的不是大肥鱼管理中心;请检查 DSH 登录或配对状态')
461
+ controller.signal.throwIfAborted()
462
+ const target=path+(safeAnchor?'#'+safeAnchor:'')
463
+ if(desktop&&!inside){
464
+ const result=await jpost('/open',{what:'manage',tab:safeTab,anchor:safeAnchor,external:true},controller.signal)
465
+ controller.signal.throwIfAborted()
466
+ const external=new URL(result.url)
467
+ if(result.ok!==true||result.openIn!=='external-browser'||result.path!==target||!['http:','https:'].includes(external.protocol)||!['127.0.0.1','localhost','[::1]'].includes(external.hostname)||external.username||external.password||external.pathname+external.search+external.hash!==target.replace('/manage','/browser'))throw Error('未取得可信本机浏览器入口')
468
+ pairAbort.current?.abort();setPairCode('');setPairResult('');setManageBrowser({origin:external.origin,tab:safeTab,anchor:safeAnchor})
469
+ // The official exchange is rooted at /, not at the management path.
470
+ // Launch it separately; the clean landing page confirms the actual
471
+ // owner session and navigates after the browser has the cookie.
472
+ const auto=await tryOfficialBrowserLogin(external.origin,controller.signal)
473
+ controller.signal.throwIfAborted()
474
+ if(auto){external.searchParams.set('auto','1');setManageNotice('请查看大肥鱼管理中心标签页。')}
475
+ else {setBrowserAuthExpanded(true);setManageNotice('若未能打开管理中心,请按下方指引授权。')}
476
+ openExternalManagementLink(external.href)
477
+ }else if(desktop){
478
+ // Main-frame navigation preserves the official Desktop bridge. A
479
+ // no-referrer link avoids forwarding the private scheme as Referer.
480
+ const link=document.createElement('a');link.href=target;link.target='_self';link.rel='noreferrer';link.referrerPolicy='no-referrer';link.hidden=true
481
+ document.body.appendChild(link);try{link.click()}finally{link.remove()}
482
+ }else window.location.assign(target)
382
483
  } catch (e) {
383
- const detail = String(e?.message || e)
384
- const message = '打开管理中心失败:' + detail +
385
- '。请确认手机已通过 DSH Mobile 配对并连接到电脑;不要直接将电脑本机 DSH 端口暴露到公网。'
386
- setManageError(message)
387
- say(message, 'warn')
388
- }
484
+ const message = '打开管理中心失败:' + (controller.signal.aborted?'请求已取消或超时':String(e?.message || e)) +
485
+ '。请在当前 DSH 内重新登录或重启;手机请检查配对,不要直接将电脑本机 DSH 端口暴露到公网。'
486
+ setManageError(message);setBrowserAuthExpanded(true);say(message, 'warn')
487
+ } finally {clearTimeout(timeout);manageOpenAbort.current=null;setManageOpening(false)}
389
488
  }
390
489
 
391
490
 
491
+ // First-time authorization can start directly at the official Host root.
492
+ // Derive it only from the authenticated, validated local /open response.
493
+ const onOpenBrowserLogin = async () => {
494
+ setManageError('')
495
+ try {
496
+ if(window.location?.protocol!=='dsh-app:'||window.location?.host!=='app')throw Error('请在本机 DSH 原生设置中打开登录页')
497
+ const result=await jpost('/open',{what:'manage',external:true})
498
+ const external=new URL(result.url)
499
+ if(result.ok!==true||result.openIn!=='external-browser'||result.path!=='/api/bili-duty/manage'||!['http:','https:'].includes(external.protocol)||!['127.0.0.1','localhost','[::1]'].includes(external.hostname)||external.username||external.password||external.pathname!=='/api/bili-duty/browser'||external.search||external.hash)throw Error('未取得可信本机浏览器入口')
500
+ const login=new URL('/',external.origin)
501
+ const link=document.createElement('a');link.href=login.href;link.target='_blank';link.rel='noopener noreferrer';link.referrerPolicy='no-referrer';link.hidden=true
502
+ document.body.appendChild(link);try{link.click()}finally{link.remove()}
503
+ }catch(e){setManageError('打开 DSH 官方登录页失败:'+String(e?.message||e).slice(0,160))}
504
+ }
505
+
506
+ // Alpha's official HTTP Remote wire contract. Desktop hides the Remote settings
507
+ // component; the already authenticated same-origin bridge is independent of it.
508
+ // No synthesized identity, generic RPC proxy or retry of a decision. The
509
+ // official loginUrl response is handled only by tryOfficialBrowserLogin.
510
+ const pairingRpc = async (method, args, signal) => {
511
+ if(window.location?.protocol!=='dsh-app:'||window.location?.host!=='app')throw Error('请在本机 DSH 原生设置中批准浏览器登录')
512
+ if(!['loginUrl','pairingRequests','decidePairing'].includes(method))throw Error('未知配对操作')
513
+ signal.throwIfAborted()
514
+ const endpoint='remoteConnection/'+method
515
+ const rpcId=crypto.randomUUID()
516
+ const res=await fetch('/api/'+endpoint,{method:'POST',credentials:'same-origin',redirect:'error',cache:'no-store',referrerPolicy:'no-referrer',headers:{'content-type':'application/json'},body:JSON.stringify({type:'client-request',rpcId,method:endpoint,payload:{args}}),signal})
517
+ signal.throwIfAborted()
518
+ if(!res.ok)throw Error(({401:'DSH 原生会话未认证',403:'宿主拒绝当前主人权限或请求来源',404:'当前宿主未提供浏览器配对接口(旧版无需配对时请直接打开)',503:'宿主认证服务暂不可用'})[res.status]||'宿主配对接口 HTTP '+res.status)
519
+ if(!/application\/json/i.test(res.headers.get('content-type')||''))throw Error('宿主未返回配对 RPC 响应')
520
+ const reply=await res.json()
521
+ signal.throwIfAborted()
522
+ if(reply?.type!=='server-response'||reply.rpcId!==rpcId||typeof reply.result?.ok!=='boolean')throw Error('宿主配对响应格式不匹配')
523
+ if(reply.result.ok!==true){
524
+ const reason=reply.result.error?.code
525
+ throw Error(reason==='remote-connection/owner-required'||reason==='remote-access/denied'?'宿主拒绝主人权限':typeof reason==='string'&&/^[a-z0-9/-]{1,80}$/.test(reason)?'宿主配对接口拒绝('+reason+')':'宿主配对接口拒绝')
526
+ }
527
+ return reply.result.value
528
+ }
529
+ // Request list and decision stay on the official authenticated Remote.
530
+ // The human compares the code; never approve automatically, or pass a token.
531
+ const approveBrowser = async () => {
532
+ if(pairPending.current)return
533
+ const code=pairCode.trim().replace(/\s+/g,'').toUpperCase()
534
+ if(!/^[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{8}$/.test(code)){
535
+ setPairResult('');setManageError('请输入浏览器「配对此设备」显示的八位配对码(可含空格)。');return
536
+ }
537
+ pairPending.current=true;setPairBusy(true);setManageError('');setPairResult('');setManageNotice('')
538
+ const controller=new AbortController();pairAbort.current=controller
539
+ const timer=setTimeout(()=>controller.abort(),10000)
540
+ try{
541
+ // Resolve the current authority even after leaving/reopening settings.
542
+ // Only an authenticated /open response supplies this origin.
543
+ const result=await jpost('/open',{what:'manage',external:true})
544
+ const external=new URL(result.url)
545
+ if(result.ok!==true||result.openIn!=='external-browser'||result.path!=='/api/bili-duty/manage'||!['http:','https:'].includes(external.protocol)||!['127.0.0.1','localhost','[::1]'].includes(external.hostname)||external.username||external.password||external.pathname!=='/api/bili-duty/browser'||external.search||external.hash)throw Error('未取得可信本机浏览器入口')
546
+ controller.signal.throwIfAborted()
547
+ const listed=await pairingRpc('pairingRequests',{},controller.signal)
548
+ if(!Array.isArray(listed?.requests))throw Error('无法读取宿主配对申请')
549
+ const matches=listed.requests.filter(row=>typeof row?.id==='string'&&row.id.length>0&&row.code===code&&row.authority===external.origin&&Number.isFinite(row.expiresInMs)&&row.expiresInMs>0)
550
+ if(matches.length!==1)throw Error('未找到唯一有效的本机配对码;请在浏览器重新申请后核对八位码')
551
+ controller.signal.throwIfAborted()
552
+ const approved=await pairingRpc('decidePairing',{id:matches[0].id,decision:'allow'},controller.signal)
553
+ if(approved!=='approved')throw Error('宿主尚未确认配对,请核对浏览器状态')
554
+ if(!controller.signal.aborted){setPairCode('');setPairResult('DSH 已批准。请回到浏览器等待登录完成,再点击本设置页的「打开管理中心」(使用同一浏览器)。若已打开管理中心引导页,也可点击「重新检查登录状态」。')}
555
+ }catch(e){if(!controller.signal.aborted)setManageError('浏览器配对未确认:'+String(e?.message||e).slice(0,160));else setManageError('配对结果尚未确认,请先核对浏览器状态。')}
556
+ finally{clearTimeout(timer);pairAbort.current=null;pairPending.current=false;setPairBusy(false)}
557
+ }
558
+ const browserRecovery=({statusPending=false}={})=>window.location?.protocol==='dsh-app:'&&window.location?.host==='app'?h('div',{'data-bd-browser-auth':'','aria-label':'管理中心浏览器授权'},
559
+ statusPending?h('div',{'data-bd-row':''},h('button',{'data-bd-btn':'','data-primary':'',disabled:manageOpening,onClick:()=>onOpenManage()},manageOpening?'正在打开…':'在独立浏览器中打开管理中心 ↗')):null,
560
+ manageNotice?h('div',{'data-bd-note':'',role:'status'},manageNotice):null,
561
+ pairResult?h('div',{'data-bd-msg':'','data-good':'',role:'status'},pairResult):null,
562
+ manageError?h('div',{'data-bd-msg':'','data-warn':'',role:'alert'},manageError):null,
563
+ h('button',{'data-bd-btn':'',type:'button','aria-expanded':browserAuthExpanded,onClick:()=>setBrowserAuthExpanded(v=>!v)},(browserAuthExpanded?'▾ ':'▸ ')+'浏览器授权与故障恢复'),
564
+ h('div',{'data-bd-browser-recovery':'',hidden:!browserAuthExpanded},
565
+ h('div',{'data-bd-note':''},'① 直接打开 DSH 官方登录页,在浏览器选择「配对此设备」。已经登录的浏览器无需重复授权。'),
566
+ h('div',{'data-bd-row':''},h('button',{'data-bd-btn':'',type:'button',onClick:onOpenBrowserLogin},'打开 DSH 官方登录页 ↗')),
567
+ h('div',{'data-bd-note':''},'② 看到八位配对码后,回到这里输入并批准(不用找 DSH 的远程连接设置,也不用另一台设备)。'),
568
+ h('div',{'data-bd-row':''},h('input',{'data-bd-input':'','aria-label':'八位浏览器配对码',autoComplete:'off',spellCheck:false,value:pairCode,maxLength:16,placeholder:'如 ABCD EFGH',onChange:e=>{setPairCode(e.target.value);setPairResult('');setManageError('')}}),h('button',{'data-bd-btn':'','data-primary':'',disabled:pairBusy||!pairCode.trim(),onClick:approveBrowser},pairBusy?'正在核对…':'核对并批准浏览器登录')),
569
+ h('div',{'data-bd-note':''},'③ 登录成功后,点击「打开管理中心」。仅批准自己的请求;授权后,浏览器也能访问完整的 DSH 功能,无需重新登录 B站。'),
570
+ h('div',{'data-bd-row':''},h('button',{'data-bd-btn':'',onClick:()=>onOpenManage(manageBrowser?.tab||(st?.onboarding&&!(st.onboarding.welcomeCompleted??st.onboarding.completed)?'firststart':''),manageBrowser?.anchor||'',true)},'在 DSH 内打开管理中心'),h('span',{'data-bd-note':''},'浏览器暂时无法登录时使用;页面顶部可返回 DSH 主界面。')))):null
571
+
392
572
  const patch = async (p, what) => {
393
573
  setBusy(JSON.stringify(p))
394
574
  try {
@@ -560,16 +740,19 @@ window.__ModuleLoader__.load({
560
740
  if (!r.qr) { setLoginTone('warn'); setLoginState('没画出二维码 —— 先点上面的「重装依赖」(venv 里要有 qrcode)') }
561
741
  else setLoginState('用手机 B站 扫这张码')
562
742
  if (loginTimer.current) { clearInterval(loginTimer.current); loginTimer.current = null } // 重复点:先把上一轮停掉
563
- let n = 0
743
+ let n = 0, polling=false
564
744
  const stop = () => { clearInterval(timer); if (loginTimer.current === timer) loginTimer.current = null }
565
745
  const timer = setInterval(async () => {
566
746
  if (!alive.current) { stop(); return } // 已经切走设置页了:别再问、别再 setState
567
- n += 1
747
+ if(polling)return
748
+ polling=true;n += 1
568
749
  try {
569
750
  const p = await jpost('/login/poll', { key: r.key })
751
+ if(!alive.current||loginTimer.current!==timer)return
570
752
  if (p?.state === 'staged') {
571
753
  stop(); setLogin(null)
572
- setLoginTone('warn'); setLoginState('扫码成功但尚未启用:请进入管理中心「B站视频探索 → 鱼鱼的身份与 B站账号」,确认 UID 并在线核验。换号后需重启 DSH。')
754
+ setLoginTone('warn'); setLoginState('扫码成功但尚未启用:请确认待绑定 UID 并在线核验。换号后需重启 DSH。')
755
+ try{const account=await jget('/account/status');if(alive.current)setSt(old=>({...old,account}))}catch{}
573
756
  } else if (p?.state === 'scanned') { setLoginTone(''); setLoginState('扫到了,请在手机上确认') }
574
757
  else if (p?.state === 'expired') { stop(); setLogin(null); setLoginTone('warn'); setLoginState('二维码过期了,再点一次「扫码登录」') }
575
758
  // ⚠️ 扫码成功但响应里没有 SESSDATA 时服务端回 state='unknown':原来没这个分支
@@ -580,13 +763,68 @@ window.__ModuleLoader__.load({
580
763
  }
581
764
  else { setLoginTone(''); setLoginState('等扫码…') }
582
765
  } catch { /* 抖动就下次再问 */ }
583
- if (n > 90) { stop(); setLogin(null); setLoginTone('warn'); setLoginState('超时了,再点一次「扫码登录」') }
766
+ finally{polling=false}
767
+ if (loginTimer.current===timer&&n > 90) { stop(); setLogin(null); setLoginTone('warn'); setLoginState('超时了,再点一次「扫码登录」') }
584
768
  }, 2000)
585
769
  loginTimer.current = timer
586
770
  } catch (e) { setLoginTone('warn'); setLoginState(String(e?.message ?? e)) }
587
771
  finally { setBusy('') }
588
772
  }
589
773
 
774
+ // Authenticated native settings recovery, independent of the external
775
+ // management browser. Reuse the exact existing explicit account gates.
776
+ const recoverAccount = async (action) => {
777
+ setBusy('account-recovery');setLoginTone('');setLoginState('正在核验账号状态…')
778
+ try {
779
+ const a=await jget('/account/status')
780
+ if(a?.ok!==true)throw Error('无法读取账号状态')
781
+ let result
782
+ if(action==='confirm'){
783
+ if(!a.pendingUid)throw Error('没有待确认的扫码账号')
784
+ if(!window.confirm('在线核验并绑定 UID '+a.pendingUid+'?切换账号后必须重启 DSH,旧账号任务不会自动转移。')){setLoginState('已取消确认');return}
785
+ result=await jpost('/account/confirm',{uid:a.pendingUid})
786
+ if(result?.ok!==true||result.verifiedUid!==a.pendingUid)throw Error('未获得账号绑定确认')
787
+ }else if(action==='cancel'){
788
+ if(!a.pendingUid||!window.confirm('取消待确认的扫码凭证?原账号不变。')){setLoginState('未取消扫码');return}
789
+ result=await jpost('/account/cancel',{})
790
+ if(result?.ok!==true)throw Error('未获得取消确认')
791
+ }else if(action==='resume'){
792
+ if(!a.activeUid||a.restartRequired||!a.reviewRequired)throw Error('请先完成账号确认并按提示重启')
793
+ if(!window.confirm('仅在已复核 UID '+a.activeUid+' 的私信、评论、发布授权后才恢复;无法复核请取消并保持冻结。旧账号任务不会转移。本操作不修改授权。确认恢复?')){setLoginState('保持冻结');return}
794
+ result=await jpost('/account/resume',{uid:a.activeUid})
795
+ if(result?.ok!==true||result.blocked!==false)throw Error('账号仍处于安全冻结状态')
796
+ }else if(action==='verify'){
797
+ if(a.blocked)throw Error('请先完成账号确认、重启和权限复核')
798
+ result=await jpost('/onboarding/bili/verify',{})
799
+ if(result?.biliVerified!==true)throw Error('首次设置尚未确认 B站验证成功')
800
+ }
801
+ const fresh=await jget('/account/status')
802
+ setSt(old=>({...old,account:fresh,...(action==='verify'?{onboarding:result}:{})}))
803
+ setLoginTone(fresh.blocked?'warn':'good')
804
+ setLoginState(fresh.restartRequired?'已绑定,请完全退出并重启 DSH 后复核授权。':fresh.blocked?'账号仍处于冻结状态,请按下方提示继续。':'账号绑定已就绪;首次设置的 B站验证及其他必需项目请按状态完成。')
805
+ }catch(e){setLoginTone('warn');setLoginState(String(e?.message||e))}
806
+ finally{setBusy('')}
807
+ }
808
+ const nativeAccountRecovery = () => {
809
+ const a=st?.account
810
+ if(!a||(!a.blocked&&st?.onboarding?.biliVerified===true))return null
811
+ const labels={unbound:'尚未绑定','credential-missing':'缺少凭证','uid-mismatch':'身份不匹配','login-staged':'扫码待确认','restart-required':'必须重启 DSH','review-required':'等待权限复核','restore-review-required':'恢复后等待权限复核',ready:'账号已就绪'}
812
+ return h('div',{'data-bd-sec':'',style:{border:'1px solid var(--dsw-alias-bg-layer-3,rgba(127,127,127,.24))',borderRadius:'12px',padding:'12px'}},
813
+ h('div',{'data-bd-label':''},'B站账号安全恢复 · 管理中心打不开时可在此操作'),
814
+ h('div',{'data-bd-note':''},'状态:'+(labels[a.reason]||a.reason)+' · 当前 UID:'+(a.activeUid||'未绑定')+' · 待确认 UID:'+(a.pendingUid||'无')),
815
+ h('div',{'data-bd-row':''},
816
+ a.pendingUid?h('button',{'data-bd-btn':'',disabled:!!busy,onClick:()=>recoverAccount('confirm')},'核验并确认 UID '+a.pendingUid):null,
817
+ a.pendingUid?h('button',{'data-bd-btn':'',disabled:!!busy,onClick:()=>recoverAccount('cancel')},'取消待确认扫码'):null,
818
+ !a.pendingUid&&!a.restartRequired&&a.reviewRequired?h('button',{'data-bd-btn':'',disabled:!!busy,onClick:()=>recoverAccount('resume')},'已复核权限,恢复账号'):null,
819
+ a.blocked&&!a.pendingUid&&!a.restartRequired&&!a.reviewRequired&&st.venvReady?h('button',{'data-bd-btn':'',disabled:!!busy||!!login,onClick:onLoginStart},'重新扫码登录'):null,
820
+ !a.blocked&&st?.onboarding?.biliVerified!==true?h('button',{'data-bd-btn':'',disabled:!!busy,onClick:()=>recoverAccount('verify')},'验证 B站登录'):null,
821
+ h('button',{'data-bd-btn':'',disabled:!!busy,onClick:()=>recoverAccount('refresh')},'刷新账号状态')),
822
+ login?.qr?h('img',{src:login.qr,alt:'B站登录二维码',style:{width:'180px',maxWidth:'100%'}}):null,
823
+ loginState?h('div',{'data-bd-note':'',role:'status',style:{color:loginTone==='warn'?'#c74351':undefined}},loginState):null,
824
+ a.restartRequired?h('div',{'data-bd-note':''},'请完全退出并重新启动 DSH,再返回本页。重启不会自动解除授权冻结。'):null,
825
+ a.blocked&&!st.venvReady?h('div',{'data-bd-note':''},'扫码需要主依赖就绪;已暂存的账号仍可尝试在线核验。'):null)
826
+ }
827
+
590
828
  const onFavToday = async () => {
591
829
  setBusy('fav')
592
830
  try {
@@ -605,6 +843,34 @@ window.__ModuleLoader__.load({
605
843
  await patch({ keywords: list, clear: list.length ? [] : ['keywords'] }, '主人额外关注词')
606
844
  }
607
845
 
846
+ if (maintenance && !cfg) {
847
+ const pending=maintenance.status==='waiting'||maintenance.status==='running'
848
+ const label=({python:'Python 包管理缓存',model:'模型与视觉缓存',memory:'Life 记忆'})[maintenance.domain]||'数据'
849
+ const cancel=async()=>{
850
+ if(!pending||maintenance.cancelRequested)return
851
+ if(!window.confirm('取消这次迁移?系统只会请求安全停止,不删除旧数据或强制切换目录。'))return
852
+ setBusy('migration-cancel')
853
+ try {
854
+ await jpost('/migration/cancel',{jobId:maintenance.id,confirm:true})
855
+ setMaintenance(old=>({...old,cancelRequested:true}))
856
+ setMsg('取消请求已提交,等待离线助手安全结算')
857
+ }catch(e){setMsg('取消请求失败:'+String(e?.message||e))}
858
+ finally{setBusy('')}
859
+ }
860
+ return h('div',{'data-bd-page':'','data-bd-sec':'',role:'status','aria-live':'polite'},
861
+ h('div',{'data-bd-msg':'',style:{padding:'16px',borderRadius:'12px'}},
862
+ pending?h('span',{'data-bd-migration-spin':'','aria-hidden':'true'}):null,
863
+ h('strong',null,label+' · '+(pending?'正在安全迁移':maintenance.status==='completed'?'迁移完成':maintenance.status==='cancelled'?'已安全取消':'迁移已停止')),
864
+ h('div',{'data-bd-note':'',style:{marginTop:'12px'}},pending?
865
+ maintenance.cancelRequested?'已请求取消,正在等待安全检查点结算。':
866
+ 'DSH 处于迁移维护模式:业务模块暂停,进度每约 2.5 秒自动刷新。'+(maintenance.status==='waiting'?'当前仍在等待旧进程退出。':'正在复制或验证数据。'):
867
+ (maintenance.reason||'当前迁移已结算。')+' 请重新启动 DSH,恢复完整插件。'),
868
+ h('div',{'data-bd-row':'',style:{marginTop:'12px'}},
869
+ pending?h('button',{type:'button','data-bd-btn':'',disabled:!!maintenance.cancelRequested||busy==='migration-cancel',onClick:cancel},
870
+ maintenance.cancelRequested?'等待安全取消…':'取消迁移'):null,
871
+ h('button',{type:'button','data-bd-btn':'',onClick:()=>window.open(API+'/manage','_blank','noopener')},'查看迁移等待页 ↗')),
872
+ h('div',{'data-bd-note':'',style:{marginTop:'10px'}},'原数据保留,绝不拿未完成的副本接管缓存;取消不能中断已进入最终提交的步骤。')))
873
+ }
608
874
  if (!cfg) {
609
875
  return h('div', { 'data-bd-page': '' },
610
876
  h('div', { 'data-bd-note': '' }, fails >= 3
@@ -612,39 +878,14 @@ window.__ModuleLoader__.load({
612
878
  : '读设置中…'),
613
879
  fails >= 6 ? h('div', { 'data-bd-note': '' },
614
880
  '请核对安装版本与实际加载版本,勿反复重装或清空数据;仍失败请导出插件日志和 DSH 宿主的插件激活错误。详情见 ' +
615
- '%USERPROFILE%\\.dsh\\bili-duty\\duty.log,另请检查 DSH 宿主插件加载错误日志。') : null)
616
- }
617
-
618
- // A first-start welcome is required even for existing users. B站 login
619
- // and Headless verification take place only in the unified management UI.
620
- if(st?.onboarding && !(st.onboarding.welcomeCompleted??st.onboarding.completed)){
621
- const steps=st.onboarding;
622
- return h('div',{'data-bd-page':''},
623
- h('div',{'data-bd-sec':'',style:{padding:'10px',borderRadius:'12px'}},
624
- h('div',{'data-bd-row':''},
625
- h('button',{'data-bd-btn':'',onClick:newVer?onUpgrade:onCheckUpdate,
626
- disabled:busy==='update'||busy==='upgrade',
627
- style:{position:'relative',...(newVer?{color:'#c62828',borderColor:'#d32f2f'}:{})}},
628
- newVer?'更新至 v'+newVer:npmUpdateState.status==='checking'?'正在检查 npm…':'检查更新',
629
- newVer?h('span',{title:'发现 npm 更新',style:{position:'absolute',right:'-5px',top:'-5px',width:'11px',height:'11px',borderRadius:'50%',background:'#e53935'}}):null)),
630
- h('div',{'data-bd-note':''},npmUpdateState.status==='error'?'npm 查询失败:'+npmUpdateState.error:
631
- newVer?'npm 有新版 v'+newVer:npmUpdateState.status==='current'?'npm 暂无比本机更高的版本':'正在核实 npm 版本')),
632
- h('div',{'data-bd-sec':'',style:{padding:'20px',borderRadius:'16px',border:'2px solid #c74351',background:'rgba(218,61,73,.08)'}},
633
- h('div',{'data-bd-label':'',style:{fontSize:'19px',fontWeight:800,color:'#c74351'}},'🐟 欢迎来到大肥鱼 · 首次配置'),
634
- h('div',{'data-bd-note':''},'新用户和老用户都会看到一次这份向导;不会清除你的旧资料。B站账号与 Headless 模型是两项必需配置,未完成前所有业务功能锁定。'),
635
- h('div',{'data-bd-281-intro':'','aria-label':'首次设置检查项目'},
636
- h('span',null,'✅ B站登录核对'),h('span',null,'🧠 文字模型验证'),
637
- h('span',null,'🎬 视频视觉按需开启'),h('span',null,'🔒 互动权限明确保存')),
638
- h('div',{'data-bd-label':''},(steps.biliVerified?'✓':'○')+' B站账号登录并验证'+(steps.biliVerified?' · 已完成':'')),
639
- h('div',{'data-bd-label':''},(steps.headlessVerified?'✓':'○')+' Headless 模型同步并验证'+(steps.headlessVerified?' · 已完成':'')),
640
- h('div',{'data-bd-row':''},
641
- !st.venvReady?h('div',{'data-bd-note':''},'① B站/MCP 主依赖尚未就绪:请从下面的安装入口开始。安装完成后才能扫码,不需要事先安装 Conda。'):null,
642
- !st.venvReady?h('button',{'data-bd-btn':'','data-primary':'',onClick:()=>onOpenManage('firststart','fs-deps-card')},st.installing?'查看主依赖安装进度 ↗':'① 安装/修复主依赖 ↗'):null,
643
- h('button',{'data-bd-btn':'',onClick:()=>onOpenManage('firststart')},st.venvReady?'打开管理中心,开始配置 · 登录及模型 ↗':'② 打开管理中心,开始配置 ↗')),
644
- h('div',{'data-bd-note':''},'主 Session、人生记忆、人格成长与社交偏好可以先跳过;设置以后都能在管理中心修改。'),
645
- manageError ? h('div',{'data-bd-msg':'','data-warn':''},manageError) : null))
881
+ '%USERPROFILE%\\.dsh\\bili-duty\\duty.log,另请检查 DSH 宿主插件加载错误日志。') : null, browserRecovery({statusPending:true}))
646
882
  }
647
883
 
884
+ // Native settings remain reachable even before onboarding. The server and
885
+ // management console still enforce account/model readiness and permission gates.
886
+ const needsSetup=!!st?.onboarding&&!(st.onboarding.welcomeCompleted??st.onboarding.completed)
887
+ const setupTab=needsSetup?'firststart':''
888
+ const setupAnchor=needsSetup&&!st.venvReady?'fs-deps-card':''
648
889
  const sw = (k) => Boolean(cfg[k])
649
890
 
650
891
  return h('div', { 'data-bd-page': '' },
@@ -662,7 +903,10 @@ window.__ModuleLoader__.load({
662
903
  npmUpdateState.status==='error'?'更新检查失败 · 重试':'检查更新',
663
904
  newVer?h('span',{title:'npm 检测到更高版本',style:{display:'inline-block',position:'absolute',right:'-5px',top:'-5px',
664
905
  width:'11px',height:'11px',borderRadius:'50%',background:'#e53935',boxShadow:'0 0 0 2px white'}}):null),
665
- h('button',{type:'button','data-bd-btn':'',onClick:()=>onOpenManage()},'打开管理中心 ↗'))),
906
+ h('button',{type:'button','data-bd-btn':'','data-primary':'',disabled:manageOpening,onClick:()=>onOpenManage(setupTab,setupAnchor)},manageOpening?'正在打开…':'打开管理中心 ↗'))),
907
+ browserRecovery(),
908
+ needsSetup?h('div',{'data-bd-note':'','role':'status'},window.location?.protocol==='dsh-app:'?'首次使用:点击打开管理中心,完成 B站账号与模型验证。登录遇到问题时,展开浏览器授权与故障恢复。完成配置后才会启动后台功能。':'首次使用:请在管理中心完成 B站账号与 Headless 模型验证。完成必需配置前,后台业务仍不会启动。'):null,
909
+ window.location?.protocol!=='dsh-app:' && manageError ? h('div',{'data-bd-msg':'','data-warn':''},manageError) : null,
666
910
  h('div',{'data-bd-feature-panel':'release','aria-label':'2.8.2 版本新增特性'},
667
911
  h('div',{'data-bd-feature-heading':''},'✨ 2.8.2 版本亮点 · 视频感知体验优化'),
668
912
  h('div',{'data-bd-note':''},'本次重点优化了鱼鱼看视频的流程、观看记录与自主选择,语音转写和模型管理也更方便。'),
@@ -684,8 +928,7 @@ window.__ModuleLoader__.load({
684
928
  npmUpdateState.status==='available'?'npm 发现新版本 v'+newVer+';点击上方按钮更新并重启 DSH。':
685
929
  npmUpdateState.status==='checking'?'正在查询 npm 仓库版本(不会自动更新)…':
686
930
  npmUpdateState.status==='error'?'npm 查询失败:'+npmUpdateState.error+'。请检查网络后手动重试。':
687
- 'npm 未发现更高正式版(本地 v'+(st.version||'?')+';仓库 v'+(npmUpdateState.latest||'?')+')。'),
688
- manageError ? h('div',{'data-bd-msg':'','data-warn':''},manageError) : null),
931
+ 'npm 未发现更高正式版(本地 v'+(st.version||'?')+';仓库 v'+(npmUpdateState.latest||'?')+')。')),
689
932
 
690
933
  /* ── 大肥鱼总开关:永久展示,不隐藏设置,不清除历史 ── */
691
934
  h('div', { 'data-bd-sec': '', style: {padding:'12px',border:'1px solid var(--dsw-alias-bg-layer-3,rgba(127,127,127,.24))',borderRadius:'12px'} },
@@ -902,6 +1145,7 @@ window.__ModuleLoader__.load({
902
1145
  h('div',{'data-bd-note':''},'后台互动沿用原有统一批量生成队列:私信与评论共享一个互动模型,节省重复人设提示词。'),
903
1146
  h('div', { 'data-bd-sep': '' }),
904
1147
  h('div', { 'data-bd-h': '' }, '环境与账号'),
1148
+ nativeAccountRecovery(),
905
1149
  h('div', { 'data-bd-row': '' },
906
1150
  h('button', { 'data-bd-btn': '', onClick:()=>onOpenManage('firststart') }, '安装/修复主依赖 ↗'),
907
1151
  h('button', { 'data-bd-btn': '', disabled: busy === 'check', onClick: onCheck }, '测一下'),
@@ -910,7 +1154,7 @@ window.__ModuleLoader__.load({
910
1154
  h('div', { 'data-bd-note': '' },
911
1155
  !st.venvReady ? (st.installFailed ? '上次安装失败 → 到首次设置修复' : '主依赖未就绪 → 前往首次设置安装')
912
1156
  : (st.loggedIn ? '已有 B站凭据,可在管理中心重新验证' : '环境好了 → 去管理中心登录 B站'))),
913
- h('div', { 'data-bd-note': '' }, '运行环境安装与账号登录均已统一到管理中心 → 快速设置;本页只显示只读状态。'),
1157
+ h('div', { 'data-bd-note': '' }, '常规安装与登录在管理中心 → 快速设置;账号被冻结时可在本页安全恢复。'),
914
1158
  h('div', { 'data-bd-note': '' }, '安装进度和主依赖日志集中在管理中心 → 首次设置,避免设置页重复显示。'),
915
1159
  h('div', { 'data-bd-note': '' }, '如需重新登录,请前往大肥鱼管理中心 → 首次设置。')),
916
1160
  (Array.isArray(st.missingDeps) && st.missingDeps.length)
@@ -972,7 +1216,6 @@ window.__ModuleLoader__.load({
972
1216
  style.textContent = CSS
973
1217
  document.head.appendChild(style)
974
1218
  ctx.effect(() => () => style.remove(), 'dsh-dafeiyu-life: 设置页样式')
975
-
976
1219
  // ⭐ 进「设置」:label 就是左侧导航里那一项(抄 dsh-meme 的写法)
977
1220
  const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
978
1221
  if (!slots) return
@@ -981,6 +1224,12 @@ window.__ModuleLoader__.load({
981
1224
  () => h(Panel),
982
1225
  ))
983
1226
 
1227
+ // Slot may not exist on older Desktop builds. Settings/manual binding
1228
+ // remain available independently; the host owns the row and its identity.
1229
+ try{slots.inject('sidebar.workspaces.session.menu.item',()=>slots.register({
1230
+ name:'sidebar.workspaces.session.menu.item',id:'dafeiyu-life.bind-main-session',order:500,
1231
+ },BindMainSessionMenu))}catch{/* optional host slot */}
1232
+
984
1233
  // 会话视图保持为原生 Chat;视频与已确认评论足迹仍可在管理中心查看。
985
1234
  },
986
1235
  }