@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.9

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 (211) hide show
  1. package/README.en.md +61 -0
  2. package/README.md +60 -2
  3. package/apk/dsh-remote.apk +0 -0
  4. package/approval-summary.mjs +115 -0
  5. package/client.js +197 -0
  6. package/cordis.patch.yml +5 -0
  7. package/doctor-skill.mjs +99 -0
  8. package/doctor-target.mjs +24 -0
  9. package/file-delivery.mjs +84 -0
  10. package/gateway-stats.cjs +501 -0
  11. package/gateway.cjs +8451 -0
  12. package/index.mjs +1788 -0
  13. package/insights.mjs +111 -0
  14. package/market.mjs +86 -0
  15. package/package.json +73 -4
  16. package/peak-reminders.mjs +50 -0
  17. package/plugin-center.mjs +777 -0
  18. package/plugin-transaction.mjs +300 -0
  19. package/public/activity.js +188 -0
  20. package/public/admin.html +820 -0
  21. package/public/admin.js +1167 -0
  22. package/public/announcement-forms.js +89 -0
  23. package/public/announcements.json +464 -0
  24. package/public/app.js +8826 -0
  25. package/public/approval-records.js +301 -0
  26. package/public/approval-summary.js +78 -0
  27. package/public/build.json +5 -0
  28. package/public/cache-upgrade.js +51 -0
  29. package/public/chat-copy.js +59 -0
  30. package/public/chat-files.js +87 -0
  31. package/public/desktop/desktop.css +816 -0
  32. package/public/desktop/desktop.html +871 -0
  33. package/public/desktop/desktop.js +4548 -0
  34. package/public/desktop/i18n.js +85 -0
  35. package/public/diagnostics.js +203 -0
  36. package/public/doctor-entry.js +94 -0
  37. package/public/doctor.css +205 -0
  38. package/public/doctor.js +769 -0
  39. package/public/donate.png +0 -0
  40. package/public/e2ee-transport.js +219 -0
  41. package/public/extensions.css +109 -0
  42. package/public/extensions.js +215 -0
  43. package/public/file-inbox.css +66 -0
  44. package/public/file-inbox.js +289 -0
  45. package/public/genui.css +8 -0
  46. package/public/genui.js +254 -0
  47. package/public/history.js +304 -0
  48. package/public/i18n.js +57 -0
  49. package/public/icon.svg +12 -0
  50. package/public/image-cache.js +141 -0
  51. package/public/image-preview.js +290 -0
  52. package/public/index.html +1568 -0
  53. package/public/insights.css +28 -0
  54. package/public/insights.js +290 -0
  55. package/public/jsqr.min.js +10104 -0
  56. package/public/lan-discovery.js +94 -0
  57. package/public/link-check.js +109 -0
  58. package/public/manifest.webmanifest +16 -0
  59. package/public/md.js +333 -0
  60. package/public/morphicons-init.js +41 -0
  61. package/public/motion.js +557 -0
  62. package/public/network.js +100 -0
  63. package/public/onboarding.css +36 -0
  64. package/public/onboarding.js +253 -0
  65. package/public/operations.js +141 -0
  66. package/public/permission-presets.js +159 -0
  67. package/public/plugin-center.css +120 -0
  68. package/public/plugin-center.js +666 -0
  69. package/public/plugin-icon.svg +5 -0
  70. package/public/plugin.html +68 -0
  71. package/public/plugin.js +211 -0
  72. package/public/qrcode.min.js +2297 -0
  73. package/public/relay-autopair.js +251 -0
  74. package/public/relay-devices.js +80 -0
  75. package/public/relay-settings.css +24 -0
  76. package/public/relay-settings.js +194 -0
  77. package/public/remote-state.js +27 -0
  78. package/public/remote-ui.css +148 -0
  79. package/public/remote-ui.js +243 -0
  80. package/public/session-deck.css +79 -0
  81. package/public/session-deck.js +180 -0
  82. package/public/session-presets.js +47 -0
  83. package/public/setup.css +18 -0
  84. package/public/setup.js +213 -0
  85. package/public/sha256.js +119 -0
  86. package/public/skills.css +81 -0
  87. package/public/skills.js +202 -0
  88. package/public/skins/blue-fish/DESIGN.md +24 -0
  89. package/public/skins/blue-fish/face.png +0 -0
  90. package/public/skins/blue-fish/icon-blush.png +0 -0
  91. package/public/skins/blue-fish/icon-sleep.png +0 -0
  92. package/public/skins/blue-fish/icon-smile.png +0 -0
  93. package/public/skins/blue-fish/icon-star.png +0 -0
  94. package/public/skins/blue-fish/icon-wink.png +0 -0
  95. package/public/skins/blue-fish/icon.png +0 -0
  96. package/public/skins/blue-fish/mascot.png +0 -0
  97. package/public/skins/blue-fish/pattern.png +0 -0
  98. package/public/skins/blue-fish/preview.html +12 -0
  99. package/public/skins/blue-fish/skin.css +122 -0
  100. package/public/skins/blue-fish/sparkles.svg +18 -0
  101. package/public/skins/bocchi/DESIGN.md +99 -0
  102. package/public/skins/bocchi/face.png +0 -0
  103. package/public/skins/bocchi/grain.png +0 -0
  104. package/public/skins/bocchi/icon-blush.png +0 -0
  105. package/public/skins/bocchi/icon-sleep.png +0 -0
  106. package/public/skins/bocchi/icon-smile.png +0 -0
  107. package/public/skins/bocchi/icon-star.png +0 -0
  108. package/public/skins/bocchi/icon-wink.png +0 -0
  109. package/public/skins/bocchi/icon.png +0 -0
  110. package/public/skins/bocchi/pattern-soft.png +0 -0
  111. package/public/skins/bocchi/pattern.png +0 -0
  112. package/public/skins/bocchi/preview.html +55 -0
  113. package/public/skins/bocchi/skin.css +233 -0
  114. package/public/skins/bocchi/stage-bg.png +0 -0
  115. package/public/skins/bocchi/stage-soft.png +0 -0
  116. package/public/skins/bocchi/stand.png +0 -0
  117. package/public/skins/bocchi/sticker-guitar.png +0 -0
  118. package/public/skins/kessoku/DESIGN.md +38 -0
  119. package/public/skins/kessoku/grain.png +0 -0
  120. package/public/skins/kessoku/skin.css +212 -0
  121. package/public/skins/kita/SOURCES.json +51 -0
  122. package/public/skins/kita/face.png +0 -0
  123. package/public/skins/kita/icon-live.png +0 -0
  124. package/public/skins/kita/icon-reddress.png +0 -0
  125. package/public/skins/kita/icon-seifuku.png +0 -0
  126. package/public/skins/kita/pattern.png +0 -0
  127. package/public/skins/kita/preview.html +56 -0
  128. package/public/skins/kita/skin.css +26 -0
  129. package/public/skins/kita/stand.png +0 -0
  130. package/public/skins/kita/sticker-live.png +0 -0
  131. package/public/skins/nijika/SOURCES.json +51 -0
  132. package/public/skins/nijika/face.png +0 -0
  133. package/public/skins/nijika/icon-live.png +0 -0
  134. package/public/skins/nijika/icon-reddress.png +0 -0
  135. package/public/skins/nijika/icon-seifuku.png +0 -0
  136. package/public/skins/nijika/pattern.png +0 -0
  137. package/public/skins/nijika/preview.html +56 -0
  138. package/public/skins/nijika/skin.css +25 -0
  139. package/public/skins/nijika/stand.png +0 -0
  140. package/public/skins/nijika/sticker-live.png +0 -0
  141. package/public/skins/penguin/DESIGN.md +33 -0
  142. package/public/skins/penguin/SOURCES.json +22 -0
  143. package/public/skins/penguin/aic-blueprint.svg +24 -0
  144. package/public/skins/penguin/endfield-triangles.svg +4 -0
  145. package/public/skins/penguin/face.png +0 -0
  146. package/public/skins/penguin/icon-blush.png +0 -0
  147. package/public/skins/penguin/icon-dizzy.png +0 -0
  148. package/public/skins/penguin/icon-laugh.png +0 -0
  149. package/public/skins/penguin/icon-sleep.png +0 -0
  150. package/public/skins/penguin/icon-smile.png +0 -0
  151. package/public/skins/penguin/icon-star.png +0 -0
  152. package/public/skins/penguin/icon-wink.png +0 -0
  153. package/public/skins/penguin/icon.png +0 -0
  154. package/public/skins/penguin/mascot.png +0 -0
  155. package/public/skins/penguin/pattern-night.png +0 -0
  156. package/public/skins/penguin/pattern.png +0 -0
  157. package/public/skins/penguin/preview.html +12 -0
  158. package/public/skins/penguin/skin.css +212 -0
  159. package/public/skins/ryo/SOURCES.json +51 -0
  160. package/public/skins/ryo/face.png +0 -0
  161. package/public/skins/ryo/icon-live.png +0 -0
  162. package/public/skins/ryo/icon-reddress.png +0 -0
  163. package/public/skins/ryo/icon-seifuku.png +0 -0
  164. package/public/skins/ryo/pattern.png +0 -0
  165. package/public/skins/ryo/preview.html +56 -0
  166. package/public/skins/ryo/skin.css +25 -0
  167. package/public/skins/ryo/stand.png +0 -0
  168. package/public/skins/ryo/sticker-live.png +0 -0
  169. package/public/sponsor-entry.js +21 -0
  170. package/public/styles.css +1526 -0
  171. package/public/subagents.css +61 -0
  172. package/public/subagents.js +275 -0
  173. package/public/task-board.js +109 -0
  174. package/public/teams.js +98 -0
  175. package/public/theme-picker.css +58 -0
  176. package/public/theme-vars.css +1044 -0
  177. package/public/theme.js +166 -0
  178. package/public/transcribe-core.js +74 -0
  179. package/public/turn-results.js +121 -0
  180. package/public/update.json +49 -0
  181. package/public/vendor/gsap/NOTICE.md +10 -0
  182. package/public/vendor/gsap/gsap.min.js +11 -0
  183. package/public/vendor/morphicons/LICENSE +21 -0
  184. package/public/vendor/morphicons/README.md +10 -0
  185. package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
  186. package/public/vendor/morphicons/dom.js +206 -0
  187. package/public/vendor/morphicons/element.js +261 -0
  188. package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
  189. package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
  190. package/public/version.json +3 -0
  191. package/public/voice-input.js +1151 -0
  192. package/public/workflow.css +365 -0
  193. package/public/workflow.js +419 -0
  194. package/session-file.mjs +39 -0
  195. package/skills/dsh-remote-doctor/SKILL.md +186 -0
  196. package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
  197. package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
  198. package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
  199. package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
  200. package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
  201. package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
  202. package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
  203. package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
  204. package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
  205. package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
  206. package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
  207. package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
  208. package/skills.mjs +53 -0
  209. package/speech-whisper.mjs +705 -0
  210. package/task-board.mjs +57 -0
  211. package/teams.mjs +58 -0
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
2
+ <rect x=".75" y=".75" width="22.5" height="22.5" rx="5" fill="#F6F9FF" stroke="#0F1724" stroke-opacity=".14"/>
3
+ <path d="M10 6l4 4 4-4m-4 4 4 4" fill="none" stroke="#4F7FEF" stroke-width="2.8" stroke-linecap="square" stroke-linejoin="miter"/>
4
+ <path d="M6 10l4 4-4 4m4-4 4 4" fill="none" stroke="#8A64D8" stroke-width="2.8" stroke-linecap="square" stroke-linejoin="miter"/>
5
+ </svg>
@@ -0,0 +1,68 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta name="dsh-remote-build" content="f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
7
+ <title>DSH Remote</title>
8
+ <script>(function(){try{var t=localStorage.getItem('dshTheme');if(t!=='default'&&t!=='dark'&&t!=='light'&&t!=='neutral'&&t!=='mono'&&t!=='fish'&&t!=='penguin'&&t!=='penguin-night'&&t!=='bocchi'&&t!=='nijika'&&t!=='ryo'&&t!=='kita'){t='fish'}}catch(e){t='fish'}document.documentElement.setAttribute('data-theme',t)})()</script>
9
+ <link rel="stylesheet" href="theme-vars.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
10
+ <link rel="stylesheet" href="setup.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
11
+ <link rel="stylesheet" href="insights.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
12
+ <link rel="stylesheet" href="remote-ui.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
13
+ <link rel="stylesheet" href="doctor.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
14
+ <link rel="stylesheet" href="skins/blue-fish/skin.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
15
+ <link rel="stylesheet" href="skins/penguin/skin.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
16
+ <link rel="stylesheet" href="skins/bocchi/skin.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
17
+ <link rel="stylesheet" href="skins/kessoku/skin.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
18
+ <link rel="stylesheet" href="skins/nijika/skin.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
19
+ <link rel="stylesheet" href="skins/ryo/skin.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
20
+ <link rel="stylesheet" href="skins/kita/skin.css?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c">
21
+ <style>html[data-theme="light"],html[data-theme="neutral"],html[data-theme="fish"],html[data-theme="penguin"],html[data-theme="bocchi"],html[data-theme="nijika"],html[data-theme="ryo"],html[data-theme="kita"]{color-scheme:light}</style>
22
+ </head>
23
+ <body class="remote-panel-body">
24
+ <main class="plugin-shell" data-motion-view>
25
+ <header class="plugin-head">
26
+ <div class="plugin-brand"><span class="plugin-brand-mark" aria-hidden="true"><morph-icon id="plugin-toggle-icon" data-morph-closed="M8 3h8v18H8zM11 17h2" data-morph-open="M8 3h8v18H8zM10 11l2 2 4-4"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7"><path d="M8 3h8v18H8zM11 17h2"/></svg></morph-icon></span><span class="plugin-brand-copy"><span class="plugin-brand-name">DSH Remote</span><span id="plugin-host" class="plugin-brand-sub">本地控制器</span></span></div>
27
+ <button id="plugin-close" class="plugin-close" type="button" aria-label="关闭面板" title="关闭面板">×</button>
28
+ </header>
29
+ <section id="plugin-hero" class="plugin-hero" aria-live="polite">
30
+ <div id="plugin-status" class="plugin-status">正在检查连接</div>
31
+ <div id="plugin-status-desc" class="plugin-status-desc">读取主机与网关状态</div>
32
+ <div class="plugin-status-line"><span id="plugin-status-meta"></span></div>
33
+ <div class="plugin-primary-actions">
34
+ <button id="plugin-primary" class="plugin-primary" type="button">打开控制台</button>
35
+ <button id="plugin-doctor" class="plugin-primary plugin-doctor-button" type="button">AI 排查问题</button>
36
+ </div>
37
+ </section>
38
+ <div id="plugin-health-path" class="remote-health-path" aria-label="连接链路"></div>
39
+ <div id="plugin-error" class="plugin-error hidden" role="alert"></div>
40
+ <section class="plugin-actions" aria-label="快速操作">
41
+ <button id="plugin-pair" class="plugin-action" type="button">已有 App,去配对</button>
42
+ <button id="plugin-console" class="plugin-action" type="button">完整控制台</button>
43
+ </section>
44
+ <div id="plugin-setup" hidden></div>
45
+ <section class="plugin-usage" aria-labelledby="plugin-usage-title">
46
+ <div class="remote-section-head"><h3 id="plugin-usage-title">额度与余额</h3><button id="plugin-usage-refresh" class="remote-link" type="button">刷新</button></div>
47
+ <div id="plugin-cost-data" aria-live="polite"><p class="remote-empty">正在读取额度…</p></div>
48
+ </section>
49
+ <section class="remote-connections" aria-labelledby="plugin-online-title">
50
+ <div class="remote-section-head"><h3 id="plugin-online-title">在线连接</h3></div>
51
+ <div id="plugin-client-list"><p class="remote-empty">正在读取连接列表…</p></div>
52
+ </section>
53
+ <footer class="plugin-foot"><span id="plugin-version">—</span><a id="plugin-about" href="/remote/admin/#remote/settings" target="_blank" rel="noopener">关于与支持</a></footer>
54
+ </main>
55
+ <script src="i18n.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
56
+ <script src="vendor/gsap/gsap.min.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
57
+ <script src="motion.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
58
+ <script type="module" src="morphicons-init.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
59
+ <script src="qrcode.min.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
60
+ <script src="remote-state.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
61
+ <script src="remote-ui.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
62
+ <script src="setup.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
63
+ <script src="insights.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
64
+ <script src="plugin.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
65
+ <script src="doctor.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
66
+ <script src="doctor-entry.js?dsr-build=f8d6f991d76f42d2027fc446d197b1ed83a3f083295f0acaac045a9a12d7340c"></script>
67
+ </body>
68
+ </html>
@@ -0,0 +1,211 @@
1
+ /* DSH Remote 插件端快速状态面板 · 零依赖 */
2
+ 'use strict'
3
+
4
+ const $ = (id) => document.getElementById(id)
5
+ const API = '/remote/admin/api'
6
+ let latest = null
7
+ let busy = false
8
+ let usageBusy = false
9
+ let usageLoadedAt = 0
10
+ let usageData = null
11
+ const setup = window.DshSetup?.mount($('plugin-setup'), {
12
+ base: '/remote/', start: () => toggleGateway(), console: () => openConsole(null,'diagnostics'), deviceKey: () => openConsole(null,'devices'),
13
+ })
14
+
15
+ function text(id, value) { const el = $(id); if (el) el.textContent = value == null ? '—' : String(value) }
16
+ function escapeText(value) { return String(value ?? '').replace(/[<>&"]/g, c => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' }[c])) }
17
+ function openConsole(event, section = '') {
18
+ event?.preventDefault()
19
+ // Desktop 拒绝 dsh-app: 弹窗;在当前 iframe 导航,沿用宿主认证与抽屉。
20
+ const target = '/remote/admin/' + (section ? '#remote/' + section : '')
21
+ if (location.protocol === 'dsh-app:') location.assign(target)
22
+ else window.open(target, '_blank', 'noopener')
23
+ }
24
+ function closePanel() { window.parent.postMessage({ source: '@hyprnos/dsh-remote-plugin', type: 'close' }, location.origin) }
25
+ function renderUsage(data, phase = '') {
26
+ const target = $('plugin-cost-data')
27
+ const html = window.DshInsights?.costHtml(data, phase, true, false, true) || '额度组件暂不可用'
28
+ if (target && target.innerHTML !== html) target.innerHTML = html
29
+ }
30
+ async function loadUsage() {
31
+ if (usageBusy) return
32
+ usageBusy = true
33
+ $('plugin-usage-refresh').disabled = true
34
+ try {
35
+ const res = await fetch(`${API}/cost`, { credentials: 'same-origin', signal: AbortSignal.timeout(20000), headers: { 'x-dsh-remote-client': 'plugin' } })
36
+ if (!res.ok) throw new Error('HTTP ' + res.status)
37
+ const out = await res.json()
38
+ usageData = out
39
+ renderUsage(out)
40
+ } catch {
41
+ renderUsage(usageData, 'error')
42
+ } finally {
43
+ usageLoadedAt = Date.now()
44
+ usageBusy = false
45
+ $('plugin-usage-refresh').disabled = false
46
+ }
47
+ }
48
+
49
+ function setBusy(value) {
50
+ busy = value
51
+ $('plugin-primary').disabled = value
52
+ if ($('plugin-toggle')) $('plugin-toggle').disabled = value
53
+ }
54
+
55
+ function render(st) {
56
+ latest = st
57
+ setup?.update(st)
58
+ /** 网关解释器来源说明:Windows 上必须位于 DSH 安装目录之外,否则 DSH 更新会被占用。 */
59
+ function runtimeNote(runtime) {
60
+ if (!runtime) return ''
61
+ if (runtime.source === 'unknown') return ' · 网关解释器待确认'
62
+ if (runtime.insideInstallDir) return ' · 网关解释器位于 DSH 安装目录内,DSH 更新可能失败'
63
+ const label = runtime.source === 'env' ? 'DSH_REMOTE_NODE'
64
+ : runtime.source === 'path' ? 'PATH'
65
+ : runtime.source === 'desktop-runtime' ? '内置副本' : runtime.source === 'external' ? '外部 node' : '宿主 node'
66
+ return ' · node ' + (runtime.version || '?') + '(' + label + ')'
67
+ }
68
+ const gateway = st.mode === 'gateway' || st.gatewayRunning === true
69
+ const authError = st.gatewayAuthError || ''
70
+ const healthy = st.mode === 'gateway' && !authError && st.upstream?.reachable === true
71
+ const model = typeof window !== 'undefined' ? window.DshRemoteUI?.derive(st) : null
72
+ const installed = st.gatewayInstalled !== false
73
+ const hero = $('plugin-hero')
74
+ hero.classList.toggle('ok', healthy)
75
+ hero.classList.toggle('warn', gateway && !healthy)
76
+ hero.classList.toggle('off', !gateway)
77
+
78
+ text('plugin-status', healthy ? '系统运行正常' : gateway ? '网关需要关注' : installed ? '网关待启动' : 'DSH 已连接')
79
+ text('plugin-status-desc', healthy
80
+ ? `${model?.onlineCount ?? (st.devices || []).filter(d => d.online && (d.kind === 'app' || d.kind === 'web')).length} 个在线连接`
81
+ : authError || (gateway ? st.upstream?.reachable === false ? 'DSH 上游暂时不可达,请打开控制台诊断' : '连接状态尚未确认,请打开控制台检查' : installed ? '本地网关尚未运行,启动后即可远程连接' : '插件已连接 DSH,但未检测到网关程序'))
82
+ text('plugin-status-meta', healthy ? '本地服务可用' : gateway ? '需要查看诊断' : installed ? '本地服务未启动' : '仅 DSH 内嵌模式')
83
+
84
+ const primary = $('plugin-primary')
85
+ const hasClient = (st.devices || []).some(d => d.online && (d.kind === 'app' || d.kind === 'web'))
86
+ const pairedBefore = (st.devices || []).some(d => d.kind === 'app' || d.kind === 'web') || st.deviceKeys?.entries?.length
87
+ primary.textContent = healthy && !hasClient ? pairedBefore ? '添加手机' : '安装 App 并连接手机' : healthy ? '添加手机' : gateway ? '检查连接' : installed ? '启动网关' : '查看控制台'
88
+ primary.dataset.action = healthy && typeof setup?.show === 'function' ? 'setup' : gateway ? 'console' : installed ? 'start' : 'console'
89
+ text('plugin-toggle-label', gateway ? '停止网关' : '启动网关')
90
+ $('plugin-toggle-icon')?.setAttribute('data-morph-state', gateway ? 'open' : 'closed')
91
+ $('plugin-toggle')?.classList.toggle('hidden', !installed)
92
+
93
+ text('plugin-version', (st.version ? 'v' + st.version : '—') + runtimeNote(st.gatewayRuntime))
94
+ if ($('plugin-version')) {
95
+ $('plugin-version').title = st.gatewayRuntime?.warning || st.gatewayRuntime?.executable || ''
96
+ }
97
+ text('plugin-gateway-version', gateway ? ('v' + (st.gatewayVersion || st.version || '未知')) : '未运行')
98
+ text('plugin-devices', `${st.onlineCount || 0} / ${st.deviceCount || 0}`)
99
+ text('plugin-host', (st.lanIPs || []).find(x => x && x !== '127.0.0.1') || st.host || '127.0.0.1')
100
+ if (typeof window !== 'undefined' && window.DshRemoteUI) {
101
+ const ui = window.DshRemoteUI
102
+ const path = $('plugin-health-path'), list = $('plugin-client-list')
103
+ const pathHtml = ui.pathHtml(model), clientHtml = ui.clientHtml(st)
104
+ if (path && path.innerHTML !== pathHtml) path.innerHTML = pathHtml
105
+ if (list && list.innerHTML !== clientHtml) list.innerHTML = clientHtml
106
+ text('plugin-online-title', ui.t('online'))
107
+ text('plugin-console', ui.t('console'))
108
+ text('plugin-pair', ui.t('pair'))
109
+ text('plugin-about', ui.t('help'))
110
+ if ($('plugin-pair')) $('plugin-pair').disabled = !model.authenticated
111
+ if (model.phase === 'ready') text('plugin-status', ui.t('ready'))
112
+ else if (!authError) text('plugin-status', ui.t(model.phase))
113
+ }
114
+ $('plugin-error').classList.add('hidden')
115
+ }
116
+
117
+ let stateLoadPromise = null
118
+ async function load() {
119
+ if (stateLoadPromise) return stateLoadPromise
120
+ stateLoadPromise = readState().finally(() => { stateLoadPromise = null })
121
+ return stateLoadPromise
122
+ }
123
+ async function readState() {
124
+ try {
125
+ const res = await fetch(`${API}/state`, { headers: { 'x-dsh-remote-client': 'plugin' },
126
+ signal: typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(10000) : undefined })
127
+ if (!res.ok) throw new Error('HTTP ' + res.status)
128
+ render(await res.json())
129
+ } catch (e) {
130
+ setup?.update(null)
131
+ if (typeof window !== 'undefined' && window.DshRemoteUI) {
132
+ const path = $('plugin-health-path')
133
+ if (path) path.innerHTML = window.DshRemoteUI.pathHtml(window.DshRemoteUI.derive(null))
134
+ }
135
+ $('plugin-hero').classList.remove('ok', 'warn')
136
+ $('plugin-hero').classList.add('off')
137
+ text('plugin-status', '无法读取状态')
138
+ text('plugin-status-desc', 'DSH Remote 插件暂时无法访问本地服务')
139
+ text('plugin-status-meta', '请稍后重试')
140
+ $('plugin-error').textContent = '状态读取失败:' + escapeText(e.message || e)
141
+ $('plugin-error').classList.remove('hidden')
142
+ }
143
+ }
144
+
145
+ async function toggleGateway() {
146
+ if (busy) return
147
+ setBusy(true)
148
+ const action = latest?.mode === 'gateway' || latest?.gatewayRunning === true ? 'stop' : 'start'
149
+ try {
150
+ const res = await fetch(`${API}/gateway`, {
151
+ method: 'POST',
152
+ headers: { 'content-type': 'application/json', 'x-dsh-remote-client': 'plugin' },
153
+ body: JSON.stringify({ action }),
154
+ })
155
+ if (!res.ok) throw new Error('HTTP ' + res.status)
156
+ const out = await res.json()
157
+ if (!out.ok) throw new Error(out.error || '网关操作未完成')
158
+ await new Promise(resolve => setTimeout(resolve, 650))
159
+ await load()
160
+ } catch (e) {
161
+ $('plugin-error').textContent = '网关操作失败:' + (e.message || e)
162
+ $('plugin-error').classList.remove('hidden')
163
+ } finally { setBusy(false) }
164
+ }
165
+
166
+ async function copyToken() {
167
+ const token = latest?.token || ''
168
+ if (!token) return
169
+ try {
170
+ await navigator.clipboard.writeText(token)
171
+ const button = $('plugin-copy')
172
+ const old = button.lastChild
173
+ if (old) old.textContent = '已复制'
174
+ setTimeout(() => { if (old) old.textContent = '复制令牌' }, 1400)
175
+ } catch {
176
+ $('plugin-error').textContent = '复制失败,请从控制台手动复制'
177
+ $('plugin-error').classList.remove('hidden')
178
+ }
179
+ }
180
+
181
+ $('plugin-close').addEventListener('click', closePanel)
182
+ $('plugin-doctor')?.addEventListener('click', () => {
183
+ const report=value=>{text('plugin-error',value);$('plugin-error').classList.remove('hidden')}
184
+ if(typeof window.DshDoctorEntry?.open!=='function'){report('诊疗组件未能加载,请刷新页面后重试。');return}
185
+ window.DshDoctorEntry.open({state:()=>latest,pluginMode:true,copy:async value=>{try{await navigator.clipboard.writeText(value);return true}catch{return false}},toast:report})
186
+ })
187
+ $('plugin-console').addEventListener('click', openConsole)
188
+ if (location.protocol === 'dsh-app:') $('plugin-about').addEventListener('click', openConsole)
189
+ $('plugin-toggle')?.addEventListener('click', toggleGateway)
190
+ $('plugin-copy')?.addEventListener('click', copyToken)
191
+ $('plugin-pair')?.addEventListener('click', () => {
192
+ if ($('plugin-setup')) $('plugin-setup').hidden = false
193
+ setup?.show(2)
194
+ })
195
+ $('plugin-primary').addEventListener('click', () => {
196
+ if ($('plugin-primary').dataset.action === 'start') toggleGateway()
197
+ else if ($('plugin-primary').dataset.action === 'setup' && setup?.show) {
198
+ if ($('plugin-setup')) $('plugin-setup').hidden = false
199
+ setup.show()
200
+ }
201
+ else openConsole()
202
+ })
203
+
204
+ const panelIsVisible = () => document.visibilityState !== 'hidden'
205
+ if (panelIsVisible()) load()
206
+ setInterval(() => { if (panelIsVisible()) void load() }, 5000)
207
+ $('plugin-usage-refresh').addEventListener('click', loadUsage)
208
+ if (panelIsVisible()) loadUsage()
209
+ setInterval(() => { if (panelIsVisible() && Date.now() - usageLoadedAt >= 30000) void loadUsage() }, 30000)
210
+ const resumePanel = () => { if (panelIsVisible()) { void load(); if (Date.now() - usageLoadedAt >= 30000) void loadUsage() } }
211
+ document.addEventListener('visibilitychange', resumePanel)