dsh-remote-plugin 0.8.5 → 0.8.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.
@@ -418,6 +418,47 @@
418
418
  "minVersion": "",
419
419
  "maxVersion": "",
420
420
  "publishedAt": "2026-11-03T01:40:44.207Z"
421
+ },
422
+ {
423
+ "id": "2026-11-05-basic-relay-pilot-open",
424
+ "title": "基础云中转试运营开始|付款请备注申请编号,使用前请更新 0.8.5",
425
+ "content": "基础云中转试运营现已开始。此前预告中的规则继续适用,本公告为正式开放说明。请先看完申请步骤再付款;已开通用户请按第 03、05 节更新并刷新有效期。\n\n【01|试运营规则】\n\n- 单次微信赞赏 1 元及以上,人工核验到账后开通一个月;更高金额不增加期限、流量或网关数量,暂不接受多月预付。\n- 每个服务月含 5GB 上传与下载合计额度,对话图片预览计入;不包含文件浏览、上传、下载和文件导出。\n- 一个资格绑定一台 Remote 网关;更换电脑或重装丢失绑定时,需联系人工处理。\n- 初期名额上限 79 个,实际以申请页为准;名额是上限,不代表同时在线人数或性能承诺。\n\n【02|申请步骤:先拿编号,再付款】\n\n1. 进入申请页,先获取申请编号,确认有名额后再付款。编号预留 30 分钟。\n2. 付款时务必在微信赞赏备注中填写申请编号。未备注、金额或截图无法核对,会延误匹配和审核。\n3. 按页面提示提交实际金额、付款成功截图和接收邮箱;请勿重复付款。\n4. 人工核验到账后,审核通过并人工发送中转开通密钥,请同时检查垃圾邮件。\n5. 请私下保存申请查询凭证;通过其他赞赏入口直接付款,无法自动获得中转资格。\n6. 已付款但遇到编号过期、申请异常或无法开通时,保留申请编号与付款截图,联系 2687104205@qq.com 核对;已到账但无法开通的,按约定处理退款。\n\n【03|使用前必须更新到 0.8.5】\n\n- 电脑端 Remote 插件和 Android App 都需要更新到 0.8.5 或更高版本;旧版本无法使用新的加密中转和局域网自动配对。\n- 电脑端:DSH → 插件中心 → 已安装 → DSH Remote → 更新 0.8.5。若提示“尚未达到发布年龄”,勾选“我信任以上明确版本,并批准列出的豁免与规则合并。”,再点“确认更新”;安装完成后重启 DSH。\n- 手机端:安装 0.8.5 APK(覆盖安装,保留数据)。可从电脑 Remote 管理页的下载入口或 GitHub Releases 获取。\n- 发布年龄限制只影响电脑插件更新,不限制 APK 安装。\n- 普通浏览器和鸿蒙暂不支持新的配对入口,请继续使用局域网连接;旧版 App 无法使用新的加密入口。\n\n【04|0.8.5 的连接方式】\n\n1. 在电脑端绑定并开启中转密钥;首次激活只绑定这一台网关。\n2. 手机先连接电脑的局域网地址(http://电脑局域网IP:8787)并完成认证。\n3. 进入“更多 → 主机与连接 → 云服务器中转”,点击“通过当前局域网连接自动配对”,确认后等待约 90 秒。\n4. 成功后会自动添加公网地址并保留局域网连接,无需传输配对文件。\n- 启用加密中转的主机会拒绝旧版公网入口(426);浏览器、鸿蒙和旧 App 不能使用该入口。\n- 中转密钥只用于主机接入,不能替代 Remote 访问令牌。端到端加密默认开启;关闭需确认风险,关闭后中转方在技术上可读取内容和访问令牌。\n\n【05|已开通用户:有效期延长与刷新】\n\n- 已开通用户的有效期已在原到期日基础上统一延长 7 天,无需重新申请或付款。\n- 在电脑端“云服务器中转”的“更换个人中转密钥”处粘贴原中转密钥,点击“绑定新密钥”(密钥不变,只是重新核对);看到“已绑定此主机 · … · 有效期至 …”显示为新日期即可。\n- 已绑定的主机需要这一步刷新本地有效期;未绑定的资格首次绑定即显示新日期。连接会短暂重连。\n- 手机请按第 04 节重新配对一次,尤其是之前手动导入过配对文件的用户。\n- 本次只延长使用时间,5GB 服务月额度不变,不额外增加流量。\n\n【06|问题反馈与注意事项】\n\n- 配对失败或连接异常时,在 App 的“端到端加密配对(试验)”展开“配对日志(可复制反馈)”,复制日志并连同申请编号发送到 2687104205@qq.com。\n- 日志不含访问令牌、设备密钥或路由凭据;请勿发送中转密钥或 Remote 访问令牌本身,也不要公开中转密钥。\n- 电脑仍需开机,DSH 和 Remote 网关需保持运行;试运营期间会根据反馈调整规则,后续变化以申请页和公告为准。",
426
+ "summary": "基础云中转试运营已开始。申请前先获取编号,付款时务必备注编号;电脑插件与 Android App 需更新到 0.8.5 后才能使用新的加密配对。已开通用户有效期已延长 7 天,重新输入原密钥可刷新显示。",
427
+ "sections": [
428
+ {
429
+ "title": "试运营规则",
430
+ "content": "- 单次微信赞赏 1 元及以上,人工核验到账后开通一个月;更高金额不增加期限、流量或网关数量,暂不接受多月预付。\n- 每个服务月含 5GB 上传与下载合计额度,对话图片预览计入;不包含文件浏览、上传、下载和文件导出。\n- 一个资格绑定一台 Remote 网关;更换电脑或重装丢失绑定时,需联系人工处理。\n- 初期名额上限 79 个,实际以申请页为准;名额是上限,不代表同时在线人数或性能承诺。",
431
+ "expanded": false
432
+ },
433
+ {
434
+ "title": "申请步骤:先拿编号,再付款",
435
+ "content": "1. 进入申请页,先获取申请编号,确认有名额后再付款。编号预留 30 分钟。\n2. 付款时务必在微信赞赏备注中填写申请编号。未备注、金额或截图无法核对,会延误匹配和审核。\n3. 按页面提示提交实际金额、付款成功截图和接收邮箱;请勿重复付款。\n4. 人工核验到账后,审核通过并人工发送中转开通密钥,请同时检查垃圾邮件。\n5. 请私下保存申请查询凭证;通过其他赞赏入口直接付款,无法自动获得中转资格。\n6. 已付款但遇到编号过期、申请异常或无法开通时,保留申请编号与付款截图,联系 2687104205@qq.com 核对;已到账但无法开通的,按约定处理退款。",
436
+ "expanded": false
437
+ },
438
+ {
439
+ "title": "使用前必须更新到 0.8.5",
440
+ "content": "- 电脑端 Remote 插件和 Android App 都需要更新到 0.8.5 或更高版本;旧版本无法使用新的加密中转和局域网自动配对。\n- 电脑端:DSH → 插件中心 → 已安装 → DSH Remote → 更新 0.8.5。若提示“尚未达到发布年龄”,勾选“我信任以上明确版本,并批准列出的豁免与规则合并。”,再点“确认更新”;安装完成后重启 DSH。\n- 手机端:安装 0.8.5 APK(覆盖安装,保留数据)。可从电脑 Remote 管理页的下载入口或 GitHub Releases 获取。\n- 发布年龄限制只影响电脑插件更新,不限制 APK 安装。\n- 普通浏览器和鸿蒙暂不支持新的配对入口,请继续使用局域网连接;旧版 App 无法使用新的加密入口。",
441
+ "expanded": false
442
+ },
443
+ {
444
+ "title": "0.8.5 的连接方式",
445
+ "content": "1. 在电脑端绑定并开启中转密钥;首次激活只绑定这一台网关。\n2. 手机先连接电脑的局域网地址(http://电脑局域网IP:8787)并完成认证。\n3. 进入“更多 → 主机与连接 → 云服务器中转”,点击“通过当前局域网连接自动配对”,确认后等待约 90 秒。\n4. 成功后会自动添加公网地址并保留局域网连接,无需传输配对文件。\n- 启用加密中转的主机会拒绝旧版公网入口(426);浏览器、鸿蒙和旧 App 不能使用该入口。\n- 中转密钥只用于主机接入,不能替代 Remote 访问令牌。端到端加密默认开启;关闭需确认风险,关闭后中转方在技术上可读取内容和访问令牌。",
446
+ "expanded": false
447
+ },
448
+ {
449
+ "title": "已开通用户:有效期延长与刷新",
450
+ "content": "- 已开通用户的有效期已在原到期日基础上统一延长 7 天,无需重新申请或付款。\n- 在电脑端“云服务器中转”的“更换个人中转密钥”处粘贴原中转密钥,点击“绑定新密钥”(密钥不变,只是重新核对);看到“已绑定此主机 · … · 有效期至 …”显示为新日期即可。\n- 已绑定的主机需要这一步刷新本地有效期;未绑定的资格首次绑定即显示新日期。连接会短暂重连。\n- 手机请按第 04 节重新配对一次,尤其是之前手动导入过配对文件的用户。\n- 本次只延长使用时间,5GB 服务月额度不变,不额外增加流量。",
451
+ "expanded": false
452
+ },
453
+ {
454
+ "title": "问题反馈与注意事项",
455
+ "content": "- 配对失败或连接异常时,在 App 的“端到端加密配对(试验)”展开“配对日志(可复制反馈)”,复制日志并连同申请编号发送到 2687104205@qq.com。\n- 日志不含访问令牌、设备密钥或路由凭据;请勿发送中转密钥或 Remote 访问令牌本身,也不要公开中转密钥。\n- 电脑仍需开机,DSH 和 Remote 网关需保持运行;试运营期间会根据反馈调整规则,后续变化以申请页和公告为准。",
456
+ "expanded": false
457
+ }
458
+ ],
459
+ "minVersion": "",
460
+ "maxVersion": "",
461
+ "publishedAt": "2026-11-05T15:05:33.266Z"
421
462
  }
422
463
  ]
423
464
  }
package/public/app.js CHANGED
@@ -497,12 +497,17 @@ function saveAutoPairedRelay(origin, connection) {
497
497
  if (state.servers.some(s=>s.url===origin&&serverToken(s)===token&&s.group===state.activeGroup)) return
498
498
  state.servers.push({id:newServerId(),url:origin,note:I18N.lang==='en'?'Cloud relay':'公网中转',group:state.activeGroup,token})
499
499
  saveServers();renderServers();syncBgConfig()
500
- toast(I18N.lang==='en'?'Relay pairing configured. LAN remains connected.':'公网配对已配置,局域网连接保留。','ok')
500
+ toast(I18N.lang==='en'?'Public access verified. LAN remains connected.':'公网已验证,局域网连接保留。','ok')
501
+ }
502
+ let relaySetup = null
503
+ function relaySetupFor(connection) {
504
+ if (relaySetup && relaySetup.token === connection.token && relaySetup.servers.includes(connection.server)) return relaySetup.id
505
+ return ''
501
506
  }
502
507
  function offerLocalRelayPairing(connection=captureConnection(), force=false) {
503
508
  if (!connection.token || !connection.valid()) return
504
509
  return window.DshRelayAutoPair?.offer({
505
- connection:()=>({valid:connection.valid,url:path=>connection.server+path,headers:{authorization:'Bearer '+connection.token}}),
510
+ connection:()=>({valid:connection.valid,url:path=>connection.server+path,headers:{authorization:'Bearer '+connection.token},setupId:relaySetupFor(connection)}),
506
511
  onPaired:saveAutoPairedRelay,force,
507
512
  onStatus:(message,error)=>{if(force&&error&&connection.valid())toast(message,'err')},
508
513
  })
@@ -622,13 +627,25 @@ async function respond(rpcId, value) {
622
627
  return receipt?.accepted === true
623
628
  }
624
629
 
630
+ function operationPendingHost(connection) {
631
+ try {
632
+ const url = new URL(connection?.server || '', location.href)
633
+ return url.host || location.host
634
+ } catch { return location.host }
635
+ }
636
+ // A durable write may have been applied even if the connection identity changed
637
+ // while its receipt was pending. Never drop that fact silently.
638
+ function notifyPendingOperation(error, connection) {
639
+ if (connection?.valid()) toast(error.message, 'err')
640
+ else toast(t('send.unconfirmedSwitched', { host: operationPendingHost(connection) }), 'err')
641
+ }
625
642
  async function safeRpc(method, payload, errText) {
626
643
  const connection = captureConnection()
627
644
  try { const value = await rpc(method, payload); return connection.valid() ? value : null }
628
645
  catch (e) {
646
+ if (e.operationPending) { notifyPendingOperation(e, connection); return null }
629
647
  if (!connection.valid()) return null
630
648
  if (e.message === 'AUTH') authFailure()
631
- else if (e.operationPending) toast(e.message, 'err')
632
649
  else toast(errText ? `${errText}:${e.message}` : e.message, 'err')
633
650
  return null
634
651
  }
@@ -2534,9 +2551,33 @@ async function archiveEmptySessionOnLeave(sessionId, leaving = false) {
2534
2551
  finally { emptySessionCleanup.delete(sessionId) }
2535
2552
  }
2536
2553
 
2554
+ const composerDrafts = new Map()
2555
+ function stashComposerDraft(sessionId = state.current) {
2556
+ const input = $('composer-input')
2557
+ if (!sessionId || !input) return
2558
+ const text = input.value
2559
+ if (text) composerDrafts.set(sessionId, text)
2560
+ else composerDrafts.delete(sessionId)
2561
+ }
2562
+ function restoreComposerDraft(sessionId) {
2563
+ const input = $('composer-input')
2564
+ if (!input) return
2565
+ const text = composerDrafts.get(sessionId) || ''
2566
+ if (input.value === text) return
2567
+ input.value = text
2568
+ if (typeof autosize === 'function') autosize(input)
2569
+ }
2570
+
2537
2571
  async function openSession(id) {
2538
2572
  globalThis.DshDiagnostics?.record('session.open',{phase:'start',sessionId:id,server:state.server})
2539
- if (state.current && state.current !== id) void archiveEmptySessionOnLeave(state.current,true)
2573
+ if (state.current && state.current !== id) {
2574
+ if (typeof stashComposerDraft === 'function') stashComposerDraft(state.current)
2575
+ // Attachments belong to the conversation that added them, never to the next one.
2576
+ if (typeof clearComposerImages === 'function') clearComposerImages()
2577
+ if (typeof hideComposerMenu === 'function') hideComposerMenu()
2578
+ try { $('composer-image-menu')?.classList?.add('hidden') } catch {}
2579
+ void archiveEmptySessionOnLeave(state.current,true)
2580
+ }
2540
2581
  cancelHistoryLoad()
2541
2582
  state.current = id
2542
2583
  setSessionRecovery('loading')
@@ -2544,6 +2585,8 @@ async function openSession(id) {
2544
2585
  const openingHistory=state.history, openingConnection=captureConnection()
2545
2586
  document.body.classList.add('in-session')
2546
2587
  showView('view-session')
2588
+ if (typeof restoreComposerDraft === 'function') restoreComposerDraft(id)
2589
+ if (typeof updateContextRing === 'function') updateContextRing()
2547
2590
  $('btn-rename-session').classList.remove('hidden')
2548
2591
  $('btn-archive-session').classList.toggle('hidden', (state.wbArchived || []).includes(id))
2549
2592
  $('session-cards').innerHTML = ''
@@ -2586,15 +2629,20 @@ function shouldDiscardEmptySession(sessionId) {
2586
2629
  async function closeSession() {
2587
2630
  globalThis.DshDiagnostics?.record('session.back',{phase:'start',sessionId:state.current,loading:state.history.loading,loaded:state.history.loaded,renderErrors:state.history.renderError?1:0})
2588
2631
  const sessionId = state.current
2589
- const parentId = state.byId.get(sessionId)?.parentSessionId
2632
+ if (typeof stashComposerDraft === 'function') stashComposerDraft(sessionId)
2633
+ const closing = state.byId.get(sessionId)
2634
+ // Ordinary forks also carry parentSessionId; only a subagent record returns to its parent.
2635
+ const parentId = closing?.origin === 'subagent' ? closing.parentSessionId : null
2590
2636
  if (parentId && parentId !== sessionId) {
2591
2637
  setComposerFullscreen(false);clearComposerImages();hideComposerMenu()
2638
+ try { $('composer-image-menu')?.classList?.add('hidden') } catch {}
2592
2639
  return openSession(parentId)
2593
2640
  }
2594
2641
  const wasLoading = state.history.loading
2595
2642
  cancelHistoryLoad()
2596
2643
  const connection=captureConnection(),discard=!wasLoading&&shouldDiscardEmptySession(sessionId)
2597
2644
  state.current = null
2645
+ if (typeof updateContextRing === 'function') updateContextRing()
2598
2646
  state.history = emptyHistory()
2599
2647
  document.body.classList.remove('in-session')
2600
2648
  showView('view-home')
@@ -2625,13 +2673,22 @@ function bindNativeBack() {
2625
2673
  if ($('composer-wrap')?.classList.contains('fs')) { setComposerFullscreen(false); return }
2626
2674
  if (customSelectCurrent) { closeCustomSelect(); return }
2627
2675
  if (groupDrawerOpen()) { closeGroupDrawer(); return }
2676
+ if (typeof window !== 'undefined' && window.DshImagePreview?.closeSaveMenu?.()) return
2628
2677
  if (typeof window !== 'undefined' && window.DshImagePreview?.isOpen?.()) { window.DshImagePreview.close(); return }
2629
2678
  if (typeof window !== 'undefined' && window.DshExtensions?.closeShortcuts(true)) return
2630
2679
  if (typeof window !== 'undefined' && window.DshFileInbox?.close()) return
2680
+ // Plain popovers are not .modal or <dialog>; without this the Android back key
2681
+ // skips them and closes the conversation (or the app) instead.
2682
+ const imageMenu = $('composer-image-menu')
2683
+ if (typeof imageMenu?.classList?.contains === 'function' && typeof imageMenu.classList.add === 'function' && !imageMenu.classList.contains('hidden')) { imageMenu.classList.add('hidden'); return }
2684
+ const composerMenu = $('composer-menu')
2685
+ const canHideComposerMenu = typeof hideComposerMenu === 'function' || typeof composerMenu?.classList?.add === 'function'
2686
+ if (canHideComposerMenu && typeof composerMenu?.classList?.contains === 'function' && !composerMenu.classList.contains('hidden')) { if (typeof hideComposerMenu === 'function') hideComposerMenu(); else composerMenu.classList.add('hidden'); return }
2687
+ if (typeof window !== 'undefined' && typeof document.querySelector === 'function' && document.querySelector('.doctor-overlay:not(.hidden)') && typeof window.DshDoctor?.close === 'function') { window.DshDoctor.close(); return }
2631
2688
  const dialog = document.querySelector('dialog[open]')
2632
2689
  if (dialog) { dialog.close(); return }
2633
2690
  const openModal = [...document.querySelectorAll('.modal')].find(m => !m.classList.contains('hidden'))
2634
- if (openModal) { if (openModal.id === 'modal-notes') closeNotesModal(); else if (openModal.id === 'modal-archive') closeArchiveConfirm(); else if (openModal.id === 'modal-rename') closeRenameSession(); else if (openModal.id === 'modal-app-version-warning') closeAppVersionWarning(false); else if (openModal.id === 'modal-scan-live') closeLiveScan(''); else openModal.classList.add('hidden'); return } // 先关弹窗
2691
+ if (openModal) { if (openModal.id === 'modal-notes') closeNotesModal(); else if (openModal.id === 'modal-archive') closeArchiveConfirm(); else if (openModal.id === 'modal-rename') closeRenameSession(); else if (openModal.id === 'modal-app-version-warning') closeAppVersionWarning(false); else if (openModal.id === 'modal-scan-live') closeLiveScan(''); else if (openModal.id === 'modal-announcement') { if (state.announcementItems.some(item => item.force)) return; closeAnnouncement(false); return } else openModal.classList.add('hidden'); return } // 先关弹窗
2635
2692
  if (!$('view-settings').classList.contains('hidden')) {
2636
2693
  if ($('settings-home').classList.contains('hidden')) showSettingsHome()
2637
2694
  else showView('view-home')
@@ -2652,6 +2709,47 @@ function bindNativeBack() {
2652
2709
  function renderSessionTitle() {
2653
2710
  const s = state.byId.get(state.current)
2654
2711
  $('session-title').textContent = s ? titleOf(s) : t('session.unknown')
2712
+ if (typeof updateContextRing === 'function') updateContextRing()
2713
+ }
2714
+
2715
+ const CONTEXT_RING_CIRCUMFERENCE = 2 * Math.PI * 15
2716
+ function formatContextTokens(value) {
2717
+ const n = Number(value) || 0
2718
+ if (n >= 1e6) return (n / 1e6).toFixed(n % 1e6 === 0 ? 0 : 2) + 'M'
2719
+ if (n >= 1e3) return (n / 1e3).toFixed(n % 1e3 === 0 ? 0 : 1) + 'K'
2720
+ return String(Math.round(n))
2721
+ }
2722
+ // The host publishes contextPressure (dsh-context may also publish contextTimeline);
2723
+ // both are plain projections, so the ring works without any plugin installed.
2724
+ function contextUsage() {
2725
+ const session = state.byId.get(state.current)
2726
+ if (!session) return null
2727
+ const pressure = proj(session, 'contextPressure')
2728
+ let used = Number(pressure?.pressureTokens), total = Number(pressure?.contextWindow)
2729
+ if (!Number.isFinite(used) || !Number.isFinite(total) || total <= 0) {
2730
+ const timeline = proj(session, 'contextTimeline')
2731
+ used = Number(timeline?.current?.total)
2732
+ total = Number(timeline?.contextWindow)
2733
+ }
2734
+ if (!Number.isFinite(used) || !Number.isFinite(total) || total <= 0) return null
2735
+ used = Math.max(0, used)
2736
+ return { used, total, ratio: Math.min(1, used / total) }
2737
+ }
2738
+ function updateContextRing() {
2739
+ const ring = $('context-ring')
2740
+ if (!ring) return
2741
+ const usage = contextUsage()
2742
+ if (!usage) { ring.classList.add('hidden'); return }
2743
+ ring.classList.remove('hidden')
2744
+ ring.dataset.level = usage.ratio >= 0.85 ? 'danger' : usage.ratio >= 0.6 ? 'warn' : 'normal'
2745
+ const fill = $('context-ring-fill')
2746
+ if (fill) fill.style.strokeDashoffset = String(CONTEXT_RING_CIRCUMFERENCE * (1 - usage.ratio))
2747
+ const percent = Math.round(usage.ratio * 100)
2748
+ const label = $('context-ring-label')
2749
+ if (label) label.textContent = percent + '%'
2750
+ const detail = t('context.usage', { used: formatContextTokens(usage.used), total: formatContextTokens(usage.total), percent })
2751
+ ring.title = detail
2752
+ ring.setAttribute('aria-label', detail)
2655
2753
  }
2656
2754
 
2657
2755
  function renderSessionSub() {
@@ -2996,7 +3094,7 @@ function bindTurnResultActions() {
2996
3094
  // The fork already returned a confirmed ID. Do not wait for a catalog
2997
3095
  // read before opening it: a reconnecting host can leave that read pending.
2998
3096
  if (!state.byId.has(id)) {
2999
- const branch = { ...parent, projections: parent?.projections ? JSON.parse(JSON.stringify(parent.projections)) : undefined,
3097
+ const branch = { ...parent, projections: parent?.projections ? { ...JSON.parse(JSON.stringify(parent.projections)), asOfSeq: 0 } : undefined,
3000
3098
  sessionId: id, parentSessionId: context.sessionId, origin: 'fork', running: false, blank: false }
3001
3099
  state.byId.set(id, branch)
3002
3100
  state.sessions.unshift(branch)
@@ -3646,7 +3744,27 @@ function setComposerSendFeedback(context, key, phase, message = '') {
3646
3744
  renderComposerSend()
3647
3745
  }
3648
3746
  // No preflight or automatic retry: an ambiguous timeout may already have delivered the message.
3747
+ async function sendPrompt(payload, context) {
3748
+ const connection = captureConnection()
3749
+ try {
3750
+ const value = await rpc('session.prompt', payload)
3751
+ return connection.valid() ? value : null
3752
+ } catch (error) {
3753
+ if (error.operationPending) {
3754
+ // Keep the warning on screen instead of a 3-second toast while the
3755
+ // connection is unchanged; otherwise attribute it to the old connection.
3756
+ if (connection.valid() && composerContext() === context) setComposerSendFeedback(context, 'send.resultUnconfirmed', 'unknown')
3757
+ else notifyPendingOperation(error, connection)
3758
+ return null
3759
+ }
3760
+ if (!connection.valid()) return null
3761
+ if (error.message === 'AUTH') authFailure()
3762
+ else toast(t('send.failed') + ':' + error.message, 'err')
3763
+ return null
3764
+ }
3765
+ }
3649
3766
  async function submitSteer(method, payload, context) {
3767
+ const connection = captureConnection()
3650
3768
  if (steeringInFlight.has(context)) {
3651
3769
  if (composerContext() === context) toast(t('send.steerPending'), 'err')
3652
3770
  return null
@@ -3665,6 +3783,7 @@ async function submitSteer(method, payload, context) {
3665
3783
  return result
3666
3784
  } catch (error) {
3667
3785
  setComposerSendFeedback(context, error.rpcRejected || error.message === 'AUTH' ? 'send.steerRejected' : 'send.steerUnconfirmed', error.rpcRejected ? 'error' : 'unknown', error.message)
3786
+ if (error.operationPending && (!connection.valid() || composerContext() !== context)) notifyPendingOperation(error, connection)
3668
3787
  if (error.message === 'AUTH' && composerContext() === context) authFailure()
3669
3788
  return null
3670
3789
  } finally { clearTimeout(slow); steeringInFlight.delete(context) }
@@ -3748,7 +3867,7 @@ async function sendSessionContent(text, images, requestedMode = 'queue') {
3748
3867
  }
3749
3868
  const v = mode === 'steer'
3750
3869
  ? await submitSteer('session.prompt', payload, context)
3751
- : await safeRpc('session.prompt', payload, t('send.failed'))
3870
+ : await sendPrompt(payload, context)
3752
3871
  if (composerContext() !== context) return !!v?.accepted
3753
3872
  if (v?.accepted) {
3754
3873
  state.sessionActivity.add(sessionId)
@@ -3802,6 +3921,7 @@ async function sendMessage(requestedMode) {
3802
3921
  const mode = typeof requestedMode === 'string' ? requestedMode : composerSendMode()
3803
3922
  if (await sendSessionContent(text, images, mode) && composerContext() === context) {
3804
3923
  if (input.value === originalText) { input.value = ''; autosize(input) }
3924
+ if (typeof composerDrafts !== 'undefined' && composerDrafts.get(state.current) === text) composerDrafts.delete(state.current)
3805
3925
  if (state.composerImages.length === images.length && images.every((item, i) => item === state.composerImages[i])) clearComposerImages()
3806
3926
  }
3807
3927
  }
@@ -4009,7 +4129,7 @@ async function confirmRenameSession() {
4009
4129
  try {
4010
4130
  const value = await safeRpc('session.rename', { sessionId, title }, t('session.renameFailed'))
4011
4131
  if (value == null) { setSessionRecovery('error'); return }
4012
- if (value.title) applyProjection(sessionId, 'title', value.title, value.seq)
4132
+ if (value != null) applyProjection(sessionId, 'title', value.title || title, value.seq)
4013
4133
  closeRenameSession()
4014
4134
  setSessionRecovery('ready')
4015
4135
  toast(t('session.renamed'), 'ok')
@@ -4060,9 +4180,9 @@ async function createSessionInWorkspace() {
4060
4180
  try {
4061
4181
  const v = await safeRpc('session.create', { workspaceId: workspaceId, ...preset.payload }, t('home.createFailed'))
4062
4182
  if (!connection.valid() || !v?.sessionId) return
4063
- state.workspaceFilter = workspaceId
4183
+ // Never repurpose the session-list filter for a newly created session: "sort by
4184
+ // time" must keep showing every workspace. Remember it for the next create only.
4064
4185
  state.fs.workspaceId = workspaceId
4065
- LS.set('workspaceFilterV1', workspaceId)
4066
4186
  LS.set('fsWorkspaceIdV1', workspaceId)
4067
4187
  LS.set('lastNewSessionWorkspaceV1', workspaceId)
4068
4188
  closeNewSessionModal()
@@ -4436,19 +4556,36 @@ function renderSessionPending() {
4436
4556
  async function approveApproval(id, allow) {
4437
4557
  const connection = captureConnection()
4438
4558
  const a = state.approvals.find(x => x.approvalId === id)
4439
- if (!a) return
4559
+ const inFlight = approveApproval.inFlight || (approveApproval.inFlight = new Set())
4560
+ if (!a || inFlight.has(id)) return
4561
+ inFlight.add(id)
4562
+ // Remove the card immediately: a handled or stale approval must not linger, and
4563
+ // a second tap must not submit the same decision twice.
4564
+ state.approvals = state.approvals.filter(x => x.rpcId !== a.rpcId)
4565
+ renderPending()
4566
+ const restoreCard = () => {
4567
+ if (!state.approvals.some(x => x.rpcId === a.rpcId)) state.approvals = [a, ...state.approvals]
4568
+ renderPending()
4569
+ }
4440
4570
  let ok
4441
4571
  try {
4442
4572
  ok = await respond(a.rpcId, { sessionId: a.sessionId, approvalId: a.approvalId, outcome: allow ? 'allowed-once' : 'rejected' })
4443
4573
  } catch (e) {
4444
- if (!connection.valid()) return
4574
+ inFlight.delete(id)
4575
+ if (!connection.valid()) { restoreCard(); return }
4576
+ // Transport failure leaves the decision unknown: put the card back so the user
4577
+ // can retry instead of silently losing the approval.
4578
+ restoreCard()
4445
4579
  if (e.message === 'AUTH') authFailure()
4446
4580
  else toast(t('pending.submitFailed', { msg: e.message || t('fs.networkError') }), 'err')
4447
4581
  return
4448
4582
  }
4449
- if (!connection.valid()) return
4450
- toast(ok ? (allow ? t('pending.allowed') : t('pending.rejected')) : t('pending.stale'), ok ? 'ok' : 'err')
4583
+ inFlight.delete(id)
4584
+ if (!connection.valid()) { restoreCard(); return }
4451
4585
  if (ok) clearPendingNotification({ type: 'approval/resolved', approvalId: a.approvalId })
4586
+ toast(ok ? (allow ? t('pending.allowed') : t('pending.rejected')) : t('pending.stale'), ok ? 'ok' : 'err')
4587
+ // The host either accepted the answer or no longer has the request; either way
4588
+ // the card is finished.
4452
4589
  state.approvals = state.approvals.filter(x => x.rpcId !== a.rpcId)
4453
4590
  renderPending()
4454
4591
  }
@@ -4499,6 +4636,8 @@ async function submitQuestion() {
4499
4636
  return ans
4500
4637
  }).filter(Boolean)
4501
4638
  if (!answers.length) return toast(t('question.needAnswer'), 'err')
4639
+ if (submitQuestion.busy) return
4640
+ submitQuestion.busy = true
4502
4641
  let ok
4503
4642
  try {
4504
4643
  ok = await respond(q.rpcId, { sessionId: q.sessionId, answer: { answers } })
@@ -4507,16 +4646,22 @@ async function submitQuestion() {
4507
4646
  if (e.message === 'AUTH') authFailure()
4508
4647
  else toast(t('question.submitFailed', { msg: e.message || t('fs.networkError') }), 'err')
4509
4648
  return
4649
+ } finally {
4650
+ submitQuestion.busy = false
4510
4651
  }
4511
4652
  if (!connection.valid()) return
4512
4653
  if (ok) {
4513
4654
  clearPendingNotification({ type: 'question/resolved', questionRpcId: q.rpcId })
4514
4655
  toast(t('question.submitted'), 'ok')
4515
- if (state.questionModal === q) { $('modal-question').classList.add('hidden'); state.questionModal = null }
4516
4656
  state.questions = state.questions.filter(x => x.rpcId !== q.rpcId)
4517
- renderPending()
4657
+ } else {
4658
+ // The host no longer holds this question: leave the modal instead of trapping
4659
+ // the user in a form whose answer can never be accepted.
4660
+ toast(t('question.stale'), 'err')
4661
+ state.questions = state.questions.filter(x => x.rpcId !== q.rpcId)
4518
4662
  }
4519
- else toast(t('question.stale'), 'err')
4663
+ if (state.questionModal === q) { $('modal-question').classList.add('hidden'); state.questionModal = null }
4664
+ renderPending()
4520
4665
  }
4521
4666
 
4522
4667
  /* ---------------- 后台任务 ---------------- */
@@ -4743,9 +4888,7 @@ async function createWorkspace() {
4743
4888
  const v = await safeRpc('session.create', { ...sessionPayload, ...preset.payload }, t('home.createFailed'))
4744
4889
  if (!connection.valid()) return
4745
4890
  if (workspace?.workspaceId) {
4746
- state.workspaceFilter = workspace.workspaceId
4747
4891
  state.fs.workspaceId = workspace.workspaceId
4748
- LS.set('workspaceFilterV1', workspace.workspaceId)
4749
4892
  LS.set('fsWorkspaceIdV1', workspace.workspaceId)
4750
4893
  }
4751
4894
  await refreshSessions()
@@ -4775,10 +4918,21 @@ function fsApiUrl(sub, params = {}) {
4775
4918
  }
4776
4919
 
4777
4920
  /** 对话里 Markdown 图片的本地路径:相对路径按当前会话工作区解析,读取走 /fs/file。 */
4778
- async function chatImageAttachment(attachmentId, sessionId) {
4921
+ async function chatImageAttachment(attachment, sessionId) {
4779
4922
  const connection = captureConnection()
4780
4923
  if (!sessionId || sessionId !== state.current || !connection.valid()) throw new Error('stale image')
4781
- const result = await rpc('session.attachment', { sessionId, attachmentId })
4924
+ const ref = typeof attachment === 'string' ? { attachmentId: attachment } : attachment
4925
+ if (!ref || !/^(?:sha256:)?[a-f0-9]{64}$/.test(String(ref.attachmentId || ''))) throw new Error('invalid image attachment')
4926
+ // DSH 现代 RPC 会校验整个附件引用(媒体类型/尺寸/字节数),只传 attachmentId 会被拒绝。
4927
+ const payload = { sessionId, attachment: {
4928
+ attachmentId: ref.attachmentId,
4929
+ ...(ref.mediaType === undefined ? {} : { mediaType: ref.mediaType }),
4930
+ ...(ref.bytes === undefined ? {} : { bytes: ref.bytes }),
4931
+ ...(ref.width === undefined ? {} : { width: ref.width }),
4932
+ ...(ref.height === undefined ? {} : { height: ref.height }),
4933
+ ...(ref.name ? { name: ref.name } : {}),
4934
+ } }
4935
+ const result = await rpc('session.attachment', payload, 120000)
4782
4936
  if (!connection.valid() || state.current !== sessionId) throw new Error('stale image')
4783
4937
  return result
4784
4938
  }
@@ -4793,6 +4947,62 @@ function chatImageRequest(pathValue) {
4793
4947
  return { url: fsApiUrl('/file', { path: target }), headers: fsHeaders() }
4794
4948
  }
4795
4949
 
4950
+ function chatImageFilename(ref) {
4951
+ const safe = value => String(value || '').replace(/[\\/\x00-\x1f]/g, '_').slice(0, 200)
4952
+ if (ref?.name) return safe(ref.name) || 'image'
4953
+ const fromPath = ref?.kind === 'path' ? String(ref.path || '').split(/[\\/]/).pop() : ''
4954
+ if (fromPath) return safe(fromPath) || 'image'
4955
+ const id = String(ref?.attachmentId || '').replace(/^sha256:/, '')
4956
+ const ext = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/webp': 'webp', 'image/gif': 'gif' }[String(ref?.mediaType || '').toLowerCase()] || ''
4957
+ return 'image-' + id.slice(0, 8) + (ext ? '.' + ext : '')
4958
+ }
4959
+
4960
+ // Long-press save for chat images: path images reuse /fs/file, attachment images the
4961
+ // session-file endpoint the plugin now serves for image blocks. Both go through the
4962
+ // system DownloadManager on Android; browsers fall back to an anchor download.
4963
+ async function saveChatImage(ref) {
4964
+ if (!ref || !state.token) return
4965
+ const connection = captureConnection()
4966
+ let url = ''
4967
+ try {
4968
+ if (ref.kind === 'attachment') {
4969
+ if (!/^(?:sha256:)?[a-f0-9]{64}$/.test(String(ref.attachmentId || ''))) return
4970
+ // Native shells serve the UI from https://localhost, so anchor the endpoint on
4971
+ // the paired gateway origin instead of location.href (DownloadManager cannot
4972
+ // reach the device-local WebView origin).
4973
+ const target = new URL((connection.server || '') + '/remote/api/session-file', location.href)
4974
+ target.searchParams.set('sessionId', ref.sessionId || state.current || '')
4975
+ // The plugin validates bare 64-hex ids; some upstream refs carry a sha256: prefix.
4976
+ target.searchParams.set('attachmentId', String(ref.attachmentId).replace(/^sha256:/, ''))
4977
+ url = target.href
4978
+ } else {
4979
+ const request = chatImageRequest(ref.path)
4980
+ if (!request?.url) return
4981
+ url = request.url
4982
+ }
4983
+ if (!connection.valid()) return
4984
+ const name = chatImageFilename(ref)
4985
+ if (CAP?.isNativePlatform?.()) {
4986
+ if (!window.NativeFile?.downloadToDownloads) { toast(t('fs.downloadUnsupported'), 'err'); return }
4987
+ window.NativeFile.downloadToDownloads(url, name, state.token)
4988
+ toast(t('fs.downloadStarted'), 'ok')
4989
+ return
4990
+ }
4991
+ const anchor = document.createElement('a')
4992
+ const target = new URL(url, location.href)
4993
+ target.searchParams.set('token', state.token)
4994
+ anchor.href = target.href
4995
+ anchor.download = name
4996
+ anchor.referrerPolicy = 'no-referrer'
4997
+ document.body.appendChild(anchor)
4998
+ anchor.click()
4999
+ anchor.remove()
5000
+ toast(t('fs.downloadStarted'), 'ok')
5001
+ } catch (error) {
5002
+ toast(t('fs.downloadFailed', { msg: error?.message || '' }), 'err')
5003
+ }
5004
+ }
5005
+
4796
5006
  function fsAuthError(status) {
4797
5007
  if (status === 401) authFailure()
4798
5008
  }
@@ -6208,8 +6418,15 @@ async function openPendingNavigation() {
6208
6418
  const connection = captureConnection()
6209
6419
  await refreshSessions()
6210
6420
  if (!connection.valid()) return
6211
- if (state.byId.has(target.sessionId)) await openSession(target.sessionId)
6212
- else { showView('view-activity'); toast(t('question.stale'), 'err') }
6421
+ if (state.byId.has(target.sessionId)) {
6422
+ await openSession(target.sessionId)
6423
+ // A question notification should land on the answer form, not just the chat.
6424
+ const question = state.questions.find(q => q.sessionId === target.sessionId)
6425
+ if (question && state.current === target.sessionId) openQuestionModal(question)
6426
+ } else {
6427
+ showView('view-activity')
6428
+ toast(t('notify.sessionMissing'), 'err')
6429
+ }
6213
6430
  } catch (error) { toast(error.message, 'err') }
6214
6431
  finally {
6215
6432
  pendingNavigationBusy = false
@@ -7236,6 +7453,17 @@ function applyPairUrl(url, options = {}) {
7236
7453
  renderServers()
7237
7454
  $('token-desc').textContent = t('token.savedScan')
7238
7455
  syncBgConfig()
7456
+ const setupId = u.searchParams.get('relaySetup')
7457
+ if (/^[a-f0-9]{32}$/.test(setupId || '') && window.NativeE2ee?.configure) {
7458
+ relaySetup = { id: setupId, token: tok, servers }
7459
+ showView('view-settings')
7460
+ showSettingsPage('servers')
7461
+ requestAnimationFrame(() => {
7462
+ $('relay-phone-pairing')?.scrollIntoView({ block: 'start' })
7463
+ const connection = captureConnection()
7464
+ if (relaySetupFor(connection) === setupId) void offerLocalRelayPairing(connection)
7465
+ })
7466
+ }
7239
7467
  return true
7240
7468
  } catch {
7241
7469
  return false
@@ -7950,6 +8178,7 @@ function bindUi() {
7950
8178
  $('btn-back').addEventListener('click', () => { void closeSession() })
7951
8179
  $('btn-stats').addEventListener('click', () => { renderSessionCards(); $('modal-stats').classList.remove('hidden') })
7952
8180
  $('btn-insights').addEventListener('click', () => openInsights())
8181
+ $('context-ring')?.addEventListener('click', () => { if (contextUsage()) void openInsights('context', true) })
7953
8182
  $('stats-close').addEventListener('click', () => $('modal-stats').classList.add('hidden'))
7954
8183
  $('conn-badge').addEventListener('click', () => { toast(t('common.refreshing')); openStreams(); void refreshAll() })
7955
8184
  window.DshExtensions?.bindShortcuts({ trigger: $('btn-plugin-shortcuts'), menu: $('plugin-shortcuts-menu'),
@@ -7999,6 +8228,13 @@ function bindUi() {
7999
8228
  $('session-sort')?.addEventListener('change', (e) => {
8000
8229
  state.sessionSort = e.target.value === 'workspace' ? 'workspace' : 'time'
8001
8230
  LS.set('sessionSort', state.sessionSort)
8231
+ // "By time" is a cross-workspace view: a workspace filter left over from an
8232
+ // earlier create must not silently narrow it.
8233
+ if (state.sessionSort === 'time' && state.workspaceFilter) {
8234
+ state.workspaceFilter = ''
8235
+ LS.del('workspaceFilterV1')
8236
+ renderWorkspaceNavigation()
8237
+ }
8002
8238
  renderSessions()
8003
8239
  })
8004
8240
  $('fs-workspace').addEventListener('change', (e) => {
@@ -8319,7 +8555,7 @@ function bindUi() {
8319
8555
  bindFsPullRefresh()
8320
8556
 
8321
8557
  bindRail()
8322
- window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest, resolveAttachment: chatImageAttachment, capture: captureChatImage })
8558
+ window.DshImagePreview?.configure?.({ resolvePath: chatImageRequest, resolveAttachment: chatImageAttachment, capture: captureChatImage, save: saveChatImage })
8323
8559
 
8324
8560
  for (const id of ['history', 'question-body']) window.DshChatFiles?.bind($(id), () => {
8325
8561
  const c=captureConnection(),sessionId=id==='history'?state.current:state.questionModal?.sessionId
@@ -8408,8 +8644,9 @@ function mountWorkflow() {
8408
8644
  },
8409
8645
  command: runSlashCommand, refresh: refreshAll, retry: () => { startOverviewDetection(true); void refreshAll() },
8410
8646
  operations: () => { const connection=captureConnection(); return { url:apiUrl,headers:{authorization:'Bearer '+connection.token},valid:connection.valid } },
8411
- relay: () => { const connection=captureConnection(); return { url:()=>adminApiUrl('/admin/api/relay'),headers:{authorization:'Bearer '+connection.token},valid:connection.valid,connected:!!connection.token } },
8647
+ relay: () => { const connection=captureConnection(); return { url:()=>adminApiUrl('/admin/api/relay'),headers:{authorization:'Bearer '+connection.token},valid:connection.valid,connected:!!connection.token,setupId:relaySetupFor(connection) } },
8412
8648
  e2eeAutoPaired: saveAutoPairedRelay,
8649
+ e2eeScan: () => scanPair('CAMERA'),
8413
8650
  e2eeConnect: (origin, connection) => {
8414
8651
  if (!connection.valid()) return
8415
8652
  const token = connection.headers.authorization.slice(7)
package/public/build.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "schema": 1,
3
- "version": "0.8.5",
4
- "buildId": "7006a2673f19f69788f5c533fbcf9ca1f077d0b4f3b92f4eb3b000ed4ee85623"
3
+ "version": "0.8.7",
4
+ "buildId": "7b7352352544bd35e441ffdb4de480368defbe9386c58dff9a6ed41c2318b2e3"
5
5
  }