dsh-mobile-plugin 0.5.88 → 0.5.91

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 (68) hide show
  1. package/config/agent-presets/standard/agent.cordis.yml +5 -0
  2. package/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +54 -0
  3. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/ipv4.md +38 -0
  4. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/ipv6.md +36 -0
  5. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network.md +27 -0
  6. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/offline.md +30 -0
  7. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/pairing.md +27 -0
  8. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay.md +23 -0
  9. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/selfhost-common.md +44 -0
  10. package/docs/extension-authoring.md +24 -8
  11. package/extension-registry/index.json +19 -1
  12. package/host.js +7 -15
  13. package/lib/client.js +151 -40
  14. package/lib/host-compat.cjs +4 -1
  15. package/lib/host-preset-patches.cjs +40 -0
  16. package/lib/impl.js +39 -35
  17. package/lib/index.js +3 -0
  18. package/lib/mobile/agent-presets.js +12 -0
  19. package/lib/mobile/answer-sources.js +3 -2
  20. package/lib/mobile/approval-facts.js +26 -3
  21. package/lib/mobile/approvals.js +42 -11
  22. package/lib/mobile/archive-clean.js +5 -0
  23. package/lib/mobile/extension-catalog.js +29 -3
  24. package/lib/mobile/extension-dev.js +7 -0
  25. package/lib/mobile/extension-metadata.cjs +40 -0
  26. package/lib/mobile/feedback-read.cjs +59 -0
  27. package/lib/mobile/feedback.js +24 -16
  28. package/lib/mobile/history-derive.js +3 -7
  29. package/lib/mobile/host-bridge/shims.js +20 -3
  30. package/lib/mobile/host-bridge.js +30 -1
  31. package/lib/mobile/live-steps.js +4 -3
  32. package/lib/mobile/mux.js +30 -3
  33. package/lib/mobile/permissions.js +30 -0
  34. package/lib/mobile/plugin-catalog.js +5 -0
  35. package/lib/mobile/plugin-self.js +4 -0
  36. package/lib/mobile/questions.js +21 -2
  37. package/lib/mobile/relay-control.js +67 -3
  38. package/lib/mobile/session-cache.js +12 -1
  39. package/lib/mobile/session-models.js +1 -0
  40. package/lib/mobile/session-presets.js +5 -2
  41. package/lib/mobile/session-send.js +12 -2
  42. package/lib/mobile/session-step.js +3 -2
  43. package/lib/mobile/stats-collect.cjs +26 -8
  44. package/lib/mobile/step-index.js +4 -3
  45. package/lib/mobile/stream-registry.js +29 -4
  46. package/lib/mobile/subagents.js +1 -1
  47. package/lib/mobile/third-party-extensions.js +6 -1
  48. package/lib/mobile/tool-result-state.js +12 -0
  49. package/lib/panel/index.html +27 -26
  50. package/lib/relay/identity-rotate.cjs +4 -1
  51. package/lib/relay/lan-discovery.cjs +18 -3
  52. package/lib/relay/lan-proxy.js +22 -2
  53. package/lib/relay/preview.js +10 -1
  54. package/lib/relay/protocol.js +2 -2
  55. package/lib/relay/tunnel.js +7 -2
  56. package/lib/remote/controller.cjs +4 -1
  57. package/lib/remote/tunnel-helper.cjs +2 -2
  58. package/lib/routes/control-plane.js +34 -13
  59. package/lib/routes/feedback.cjs +20 -0
  60. package/lib/session-cleanup.cjs +17 -0
  61. package/lib/shared/route-order.cjs +6 -0
  62. package/lib/shared/session-storage.cjs +82 -0
  63. package/lib/shell/first-install.js +102 -0
  64. package/lib/shell/updater.js +6 -5
  65. package/lib/sidecar-facade-worker.cjs +10 -2
  66. package/lib/sidecar-lifecycle.cjs +94 -14
  67. package/lib/tailcat/wiring.cjs +2 -2
  68. package/package.json +3 -2
package/lib/client.js CHANGED
@@ -1,4 +1,4 @@
1
- // 用途:桌面端入口;诊断窗就地提交插件反馈并回显线程 key,不依赖 AI 工具。
1
+ // 用途:桌面端入口与诊断反馈;网页管理失败附带稳定原因码,不外发原始错误和访问凭据。
2
2
  /**
3
3
  * 移动端插件提供电脑插件页面目录;标准页面保留宿主上下文并支持直接导航。
4
4
  * 聊天嵌入服务合并顶部栏显示声明,随提供方与消费方生命周期释放。
@@ -16,6 +16,10 @@
16
16
  *
17
17
  * 本文件不经任何构建(package.json 直接收录 lib 下的 .js),所以不能写 JSX,统一用
18
18
  * `React.createElement` 的别名 `h`;客户端插件按约定写成惰性工厂,定时器与页签在物化时才起。
19
+ *
20
+ * 诊断 / 控制台 / 远程电脑共用那一扇弹窗外壳:打开时复位 display(复用已收起的 keep 窗)、
21
+ * 把焦点移入并锁背景滚动,收起时还原;compact 整页窗另在外壳层放一颗固定关闭角标。侧边栏
22
+ * 两颗图标的轮询不再拿到地址就停,改为低频刷新并在页面重新可见时补一次。
19
23
  */
20
24
 
21
25
  window.__ModuleLoader__.load({
@@ -86,6 +90,10 @@ window.__ModuleLoader__.load({
86
90
  .dshm_factMono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px}
87
91
  .dshm_steps{margin:0;padding-left:18px;display:flex;flex-direction:column;gap:4px;font-size:12px;line-height:18px}
88
92
  .dshm_dialogActions{display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;margin-top:2px}
93
+ /* 整页嵌入窗的外壳关闭角标:页面顶栏出不来(加载失败)时也能收起这一窗。 */
94
+ .dshm_shellClose{position:absolute;top:10px;right:10px;z-index:1;width:32px;height:32px;padding:0;border:.5px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-settings-card-fill);color:var(--dsw-alias-label-primary);font-size:18px;line-height:1;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}
95
+ .dshm_shellClose:hover{background:var(--dsw-alias-interactive-bg-hover)}
96
+ .dshm_shellClose:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:-2px}
89
97
  .dshm_root{display:flex;flex-direction:column;gap:14px;width:100%;max-width:760px;color:var(--dsw-alias-label-primary)}
90
98
  .dshm_card{border:.5px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-xl);background:var(--dsw-alias-settings-card-fill);display:flex;flex-direction:column;gap:10px;padding:14px 16px}
91
99
  .dshm_heading{font-size:18px;font-weight:600;margin:0}
@@ -155,12 +163,16 @@ window.__ModuleLoader__.load({
155
163
  ...(init || {}),
156
164
  });
157
165
  } catch (error) {
158
- throw new Error(String((error && error.message) || error));
166
+ const failed = new Error(String((error && error.message) || error));
167
+ failed.code = 'network-request-failed';
168
+ throw failed;
159
169
  }
160
170
  const body = await response.json().catch(() => ({}));
161
171
  if (!response.ok) {
162
172
  const error = new Error(errorText(body, response.status));
163
173
  error.status = response.status;
174
+ const code = body && body.error && typeof body.error === 'object' ? body.error.code : '';
175
+ error.code = typeof code === 'string' && /^[A-Za-z][A-Za-z0-9._-]{0,79}$/.test(code) ? code : `http-${response.status}`;
164
176
  throw error;
165
177
  }
166
178
  return body;
@@ -210,7 +222,7 @@ window.__ModuleLoader__.load({
210
222
  * 就地反馈附件的诊断文本:只放插件自己认得的固定字段。原始错误串、面板地址与 UA
211
223
  * 只留在「复制诊断信息」那份给人看的全文里,不随附件出门。
212
224
  */
213
- function feedbackDiagnosisText({ version, stage, code, scope }) {
225
+ function feedbackDiagnosisText({ version, stage, code, scope, error_code }) {
214
226
  return [
215
227
  'dsh-mobile-plugin feedback',
216
228
  `source=plugin`,
@@ -219,6 +231,7 @@ window.__ModuleLoader__.load({
219
231
  `stage=${stage || ''}`,
220
232
  `code=${code === undefined || code === null ? '' : String(code)}`,
221
233
  `scope=${scope || ''}`,
234
+ ...(error_code ? [`error_code=${error_code}`] : []),
222
235
  ].join('\n');
223
236
  }
224
237
 
@@ -837,7 +850,79 @@ window.__ModuleLoader__.load({
837
850
  let noteEl = null;
838
851
  let escapeListener = null;
839
852
  let stopFrame = () => {};
853
+ /**
854
+ * 打开时把焦点移进这一窗、锁住背景滚动(并让背景 inert);收起时原样还原。
855
+ * 弹窗是 modal:不锁的话滚轮会把背后页面带着滚,Tab 也会跑到背景里。
856
+ */
857
+ let chromePrev = null;
858
+ const focusablesOf = (root) => {
859
+ if (!root || typeof root.querySelectorAll !== 'function') return [];
860
+ try {
861
+ return Array.from(root.querySelectorAll(
862
+ 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),iframe,[tabindex]:not([tabindex="-1"])',
863
+ ));
864
+ } catch {
865
+ return [];
866
+ }
867
+ };
868
+ const trapTab = (event) => {
869
+ if (!event || event.key !== 'Tab') return;
870
+ const list = focusablesOf(overlay);
871
+ if (list.length === 0) { if (typeof event.preventDefault === 'function') event.preventDefault(); return; }
872
+ const active = doc.activeElement;
873
+ const inside = overlay && typeof overlay.contains === 'function' ? overlay.contains(active) : false;
874
+ if (event.shiftKey && (active === list[0] || !inside)) {
875
+ if (typeof event.preventDefault === 'function') event.preventDefault();
876
+ try { list[list.length - 1].focus(); } catch { /* ignore */ }
877
+ } else if (!event.shiftKey && (active === list[list.length - 1] || !inside)) {
878
+ if (typeof event.preventDefault === 'function') event.preventDefault();
879
+ try { list[0].focus(); } catch { /* ignore */ }
880
+ }
881
+ };
882
+ const applyChrome = () => {
883
+ const body = doc.body;
884
+ const first = !chromePrev;
885
+ if (first) {
886
+ chromePrev = {
887
+ focus: doc.activeElement || null,
888
+ overflow: body && body.style ? body.style.overflow : '',
889
+ inert: [],
890
+ };
891
+ // 背景 inert:挡掉 Tab / 指针落到遮罩后的页面上。不支持 inert 的老环境就只靠焦点陷阱。
892
+ if (body) {
893
+ for (const child of Array.from(body.children || [])) {
894
+ // 不要 inert 另一扇已打开的弹窗(它自己有壳),只 inert 背景页面。
895
+ if (child === overlay || ('getAttribute' in child && child.getAttribute(DIAG_MARK) !== null)) continue;
896
+ if (!('inert' in child)) continue;
897
+ try { child.inert = true; chromePrev.inert.push(child); } catch { /* ignore */ }
898
+ }
899
+ }
900
+ }
901
+ if (body && body.style) body.style.overflow = 'hidden';
902
+ if (overlay && typeof overlay.addEventListener === 'function' && !overlay.__dshmTrap) {
903
+ overlay.addEventListener('keydown', trapTab);
904
+ overlay.__dshmTrap = true;
905
+ }
906
+ // 只在第一次打开时移入焦点:之后的重画(render 就地更新)不许把用户手上的焦点抢回来。
907
+ if (!first) return;
908
+ const list = focusablesOf(overlay);
909
+ const target = list[0] || overlay;
910
+ if (target === overlay && typeof overlay.setAttribute === 'function') overlay.setAttribute('tabindex', '-1');
911
+ try { if (typeof target.focus === 'function') target.focus(); } catch { /* 无焦点环境 */ }
912
+ };
913
+ const releaseChrome = () => {
914
+ if (!chromePrev) return;
915
+ const prev = chromePrev;
916
+ chromePrev = null;
917
+ const body = doc.body;
918
+ if (body && body.style) body.style.overflow = prev.overflow;
919
+ for (const child of prev.inert || []) {
920
+ try { child.inert = false; } catch { /* ignore */ }
921
+ }
922
+ try { if (prev.focus && typeof prev.focus.focus === 'function') prev.focus.focus(); } catch { /* ignore */ }
923
+ };
840
924
  const hide = () => {
925
+ releaseChrome();
841
926
  // 只有已确认就绪的页面保活;加载中或失败的页面,下次打开必须重新请求。
842
927
  if (overlay && overlay.__dshmFrameState !== 'ready') overlay.__dshmKeep = false;
843
928
  // **`keep` 的窗只收起、不销毁**:那一页是一份 1.4MB 的单文件产物,销毁掉下次
@@ -886,6 +971,7 @@ window.__ModuleLoader__.load({
886
971
  };
887
972
  doc.addEventListener('keydown', escapeListener);
888
973
  }
974
+ applyChrome();
889
975
  return overlay;
890
976
  }
891
977
  if (!overlay) {
@@ -905,6 +991,9 @@ window.__ModuleLoader__.load({
905
991
  doc.addEventListener('keydown', escapeListener);
906
992
  }
907
993
  }
994
+ // 复用一个**已收起**(keep 且被 `hide` 设成 display:none)的窗时,必须显式把 display 复位。
995
+ // 否则从控制台窗切到诊断窗会落进同一个 overlay、整窗仍是隐藏的 —— 点了没反应。
996
+ if (typeof overlay.style === 'object') overlay.style.display = '';
908
997
  if (spec.title) overlay.setAttribute('aria-label', spec.title);
909
998
  // 「这一窗收起时不销毁」的记号(见 `hide`)。只有带整页 iframe 的那一窗需要它:
910
999
  // 那一页重建一次要重新解析一整份产物,而诊断窗那几行读数是现拼的,重建几乎不要钱。
@@ -1031,6 +1120,16 @@ window.__ModuleLoader__.load({
1031
1120
  }
1032
1121
  card.appendChild(actions);
1033
1122
  }
1123
+ // compact(整页嵌入)没有外壳标题栏,平时靠页面顶栏那两颗按钮收起;可一旦嵌页加载失败,
1124
+ // 页面按钮出不来,就只剩 Esc 与点边缘。这里在外壳层固定放一颗关闭角标,任何时候都能收起。
1125
+ if (compact) {
1126
+ const close = make('button', 'dshm_shellClose', '×');
1127
+ close.setAttribute('type', 'button');
1128
+ close.setAttribute('aria-label', spec.title || spec.frame.title || '关闭');
1129
+ close.onclick = () => hide();
1130
+ overlay.appendChild(close);
1131
+ }
1132
+ applyChrome();
1034
1133
  return overlay;
1035
1134
  };
1036
1135
  /**
@@ -1040,6 +1139,7 @@ window.__ModuleLoader__.load({
1040
1139
  * 用户已经不在这里看了,把那一页和一整份产物继续占着内存没有道理。
1041
1140
  */
1042
1141
  const dispose = () => {
1142
+ releaseChrome();
1043
1143
  stopFrame();
1044
1144
  if (overlay && typeof overlay.remove === 'function' && overlay.parentElement) overlay.remove();
1045
1145
  overlay = null;
@@ -1203,6 +1303,7 @@ window.__ModuleLoader__.load({
1203
1303
  ok: false,
1204
1304
  missing: false,
1205
1305
  status: Number(error && error.status) || 0,
1306
+ code: error && typeof error.code === 'string' ? error.code : '',
1206
1307
  message: String((error && error.message) || error),
1207
1308
  });
1208
1309
 
@@ -1226,12 +1327,12 @@ window.__ModuleLoader__.load({
1226
1327
  }
1227
1328
  }
1228
1329
  if (!state.panelUrl) {
1229
- return { ok: false, missing: false, status: 0, message: t('panelMissing') };
1330
+ return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
1230
1331
  }
1231
1332
  }
1232
1333
 
1233
1334
  const url = state.panelUrl || sameOriginPanelUrl();
1234
- if (!url) return { ok: false, missing: false, status: 0, message: t('panelMissing') };
1335
+ if (!url) return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
1235
1336
 
1236
1337
  if (state.panelScope === 'public'
1237
1338
  && !confirmed
@@ -1262,7 +1363,7 @@ window.__ModuleLoader__.load({
1262
1363
  return { ok: true, url, webAccess: state.webAccess };
1263
1364
  }
1264
1365
  const opened = typeof window.open === 'function' ? window.open(url, '_blank', 'noreferrer') : null;
1265
- if (!opened) return { ok: false, missing: false, status: 0, message: t('diagPopupBlocked') };
1366
+ if (!opened) return { ok: false, missing: false, status: 0, code: 'popup-blocked', message: t('diagPopupBlocked') };
1266
1367
  return { ok: true, url, webAccess: state.webAccess };
1267
1368
  }
1268
1369
 
@@ -1857,7 +1958,7 @@ window.__ModuleLoader__.load({
1857
1958
  void openDiagnosis('load', { status: outcome.status || 404, message: (problem && problem.message) || '' });
1858
1959
  return;
1859
1960
  }
1860
- void openDiagnosis('open', { status: outcome.status || 0, message: outcome.message });
1961
+ void openDiagnosis('open', { status: outcome.status || 0, code: outcome.code || '', message: outcome.message });
1861
1962
  })();
1862
1963
  }
1863
1964
 
@@ -1869,11 +1970,11 @@ window.__ModuleLoader__.load({
1869
1970
  * 在这一步之前已经把窗口开好了(它的 `target` 传 null,不导航任何地方)。
1870
1971
  */
1871
1972
  async function openConsole({ view, loadStatus, t }) {
1872
- if (typeof document === 'undefined') return { ok: false, missing: false, status: 0, message: t('panelMissing') };
1973
+ if (typeof document === 'undefined') return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
1873
1974
  const outcome = await openConfigurationPage({ view, loadStatus, t, target: null, confirmed: true, navigate: false });
1874
1975
  if (!outcome.ok) return outcome;
1875
1976
  const consolePage = panelPageUrlOf('console');
1876
- if (!consolePage) return { ok: false, missing: false, status: 0, message: t('panelMissing') };
1977
+ if (!consolePage) return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
1877
1978
  const dialog = diagnosisDialog();
1878
1979
 
1879
1980
  /**
@@ -2100,8 +2201,9 @@ window.__ModuleLoader__.load({
2100
2201
  const safeFacts = {
2101
2202
  version: half && half.version ? String(half.version) : '',
2102
2203
  stage: kind,
2103
- code: current && current.status ? String(current.status) : '',
2204
+ code: current && Number.isFinite(current.status) ? String(current.status) : '',
2104
2205
  scope: snapshot.scope,
2206
+ error_code: current && typeof current.code === 'string' && /^[A-Za-z][A-Za-z0-9._-]{0,79}$/.test(current.code) ? current.code : '',
2105
2207
  };
2106
2208
  const result = await submitIssueFeedback({
2107
2209
  summary: `${title}\n${summaryOf()}`,
@@ -2166,26 +2268,30 @@ window.__ModuleLoader__.load({
2166
2268
  // 地址与分类都得提前在手上。宿主还没起来时留一个定时器,取到地址就自己收掉。
2167
2269
  useEffect(() => {
2168
2270
  let alive = true;
2169
- let timer = null;
2170
2271
  const load = async () => {
2171
- const outcome = await refreshStatus();
2172
- if (!alive || !outcome.ok) return;
2173
- const next = outcome.status || {};
2174
- if (typeof next.panelUrl === 'string' && next.panelUrl && timer !== null) {
2175
- clearInterval(timer);
2176
- timer = null;
2177
- }
2272
+ if (!alive) return;
2273
+ // 拿到地址后**不停止**刷新:设备台数、告警、需要重启这些都要跟着变。低频轮询就够,
2274
+ // 页面不可见时跳过;重新可见时立刻补一次,别等下一拍。
2275
+ await refreshStatus();
2178
2276
  };
2179
2277
  void load();
2180
- if (timer === null) {
2181
- timer = setInterval(() => {
2182
- if (typeof document !== 'undefined' && document.hidden) return;
2183
- void load();
2184
- }, FOOTER_URL_RETRY_MS);
2278
+ const timer = setInterval(() => {
2279
+ if (typeof document !== 'undefined' && document.hidden) return;
2280
+ void load();
2281
+ }, FOOTER_URL_RETRY_MS);
2282
+ const onVisible = () => {
2283
+ if (typeof document !== 'undefined' && document.hidden) return;
2284
+ void load();
2285
+ };
2286
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
2287
+ document.addEventListener('visibilitychange', onVisible);
2185
2288
  }
2186
2289
  return () => {
2187
2290
  alive = false;
2188
- if (timer !== null) clearInterval(timer);
2291
+ clearInterval(timer);
2292
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
2293
+ document.removeEventListener('visibilitychange', onVisible);
2294
+ }
2189
2295
  };
2190
2296
  }, []);
2191
2297
 
@@ -2411,8 +2517,9 @@ window.__ModuleLoader__.load({
2411
2517
  const safeFacts = {
2412
2518
  version: half && half.version ? String(half.version) : '',
2413
2519
  stage: 'open',
2414
- code: current && current.status ? String(current.status) : '',
2520
+ code: current && Number.isFinite(current.status) ? String(current.status) : '',
2415
2521
  scope: snapshot.scope,
2522
+ error_code: current && typeof current.code === 'string' && /^[A-Za-z][A-Za-z0-9._-]{0,79}$/.test(current.code) ? current.code : '',
2416
2523
  };
2417
2524
  const result = await submitIssueFeedback({
2418
2525
  summary: `${t('diagTitleOpen')}\n${current ? t('diagSummaryOpenFailed') : ''}`,
@@ -2480,7 +2587,7 @@ window.__ModuleLoader__.load({
2480
2587
  });
2481
2588
  if (!outcome.ok) {
2482
2589
  if (outcome.missing) void openDiagnosis({ status: outcome.status || 404, message: '' });
2483
- else void openDiagnosis({ status: outcome.status || 0, message: outcome.message });
2590
+ else void openDiagnosis({ status: outcome.status || 0, code: outcome.code || '', message: outcome.message });
2484
2591
  return;
2485
2592
  }
2486
2593
  if (outcome.webAccess) setWebAccess(outcome.webAccess);
@@ -2513,26 +2620,30 @@ window.__ModuleLoader__.load({
2513
2620
  // 页面一打开就问一次地址:点下去要么进窗、要么先开窗再读。取到就停,没取到后台重试。
2514
2621
  useEffect(() => {
2515
2622
  let alive = true;
2516
- let timer = null;
2517
2623
  const load = async () => {
2518
- const outcome = await refreshStatus();
2519
- if (!alive || !outcome.ok) return;
2520
- const next = outcome.status || {};
2521
- if (typeof next.panelUrl === 'string' && next.panelUrl && timer !== null) {
2522
- clearInterval(timer);
2523
- timer = null;
2524
- }
2624
+ if (!alive) return;
2625
+ // 拿到地址后**不停止**刷新:设备台数、告警、需要重启这些都要跟着变。低频轮询就够,
2626
+ // 页面不可见时跳过;重新可见时立刻补一次,别等下一拍。
2627
+ await refreshStatus();
2525
2628
  };
2526
2629
  void load();
2527
- if (timer === null) {
2528
- timer = setInterval(() => {
2529
- if (typeof document !== 'undefined' && document.hidden) return;
2530
- void load();
2531
- }, FOOTER_URL_RETRY_MS);
2630
+ const timer = setInterval(() => {
2631
+ if (typeof document !== 'undefined' && document.hidden) return;
2632
+ void load();
2633
+ }, FOOTER_URL_RETRY_MS);
2634
+ const onVisible = () => {
2635
+ if (typeof document !== 'undefined' && document.hidden) return;
2636
+ void load();
2637
+ };
2638
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
2639
+ document.addEventListener('visibilitychange', onVisible);
2532
2640
  }
2533
2641
  return () => {
2534
2642
  alive = false;
2535
- if (timer !== null) clearInterval(timer);
2643
+ clearInterval(timer);
2644
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
2645
+ document.removeEventListener('visibilitychange', onVisible);
2646
+ }
2536
2647
  };
2537
2648
  }, []);
2538
2649
 
@@ -1,3 +1,4 @@
1
+ /** 官方工具同步副本和插入行跟随运行时,patch 的 name 断言保持原样。 */
1
2
  'use strict'
2
3
 
3
4
  /**
@@ -156,7 +157,9 @@ function pinInsertedRows(patches, targets) {
156
157
  if (Array.isArray(next.insert)) return { ...next, insert: next.insert.map(swap) }
157
158
  return next
158
159
  }
159
- return patches.map(swap)
160
+ return patches.map(patch => Array.isArray(patch?.insert)
161
+ ? { ...patch, insert: patch.insert.map(swap) }
162
+ : patch)
160
163
  }
161
164
 
162
165
  module.exports = {
@@ -0,0 +1,40 @@
1
+ /** 按 Web bundle 的真实预设声明选择移动 standard 的挂载方式。 */
2
+ 'use strict'
3
+
4
+ const path = require('node:path')
5
+ const { pathToFileURL } = require('node:url')
6
+
7
+ /** 新版声明通过原生 Include 读取移动预设,保留子行表达式和技能目录的 baseUrl。 */
8
+ function mobilePresetPatches(webPatches, presetDir) {
9
+ const rows = webPatches.flatMap(patch => patch.insert ?? [])
10
+ const standard = rows.find(row => row.id === 'preset-standard'
11
+ && row.config?.id === 'standard' && Array.isArray(row.config.plugins))
12
+ if (standard) {
13
+ return [{
14
+ id: standard.id,
15
+ name: standard.name,
16
+ config: {
17
+ ...standard.config,
18
+ plugins: [{
19
+ id: 'mobile-standard',
20
+ name: 'cordis:include',
21
+ config: { path: pathToFileURL(path.join(presetDir, 'standard', 'agent.cordis.yml')).href },
22
+ }],
23
+ },
24
+ }]
25
+ }
26
+
27
+ // 旧版 Web bundle 的目录注册表仍由宿主提供 roots,不按版本号猜测代际。
28
+ const legacy = rows.find(row => row.id === 'agent-presets'
29
+ && row.name === '@deepseek-ai/dsh-agent-preset-registry')
30
+ if (legacy) {
31
+ return [{
32
+ id: legacy.id,
33
+ name: legacy.name,
34
+ config: { ...legacy.config, default: 'standard', roots: [{ path: presetDir, trust: 'system' }] },
35
+ }]
36
+ }
37
+ throw new Error('DSH Web bundle 没有可识别的 standard 预设声明或目录注册表')
38
+ }
39
+
40
+ module.exports = { mobilePresetPatches }
package/lib/impl.js CHANGED
@@ -1,4 +1,5 @@
1
- // 每代兼容桥独立持有服务与延迟装配定时器,卸载时一起清理。
1
+ // 身份变更同时迁移三类连接登记,主动重连独立于普通配置同步。
2
+ // apiProxy 兼容服务启动即提供(宿主那份晚到则自动接管),会话列表不再在启动瞬间报缺服务。
2
3
  // 真实监听状态同步总控和穿透,固定入口约束自动换号。
3
4
  // 配置 schema 与投影拆到 lib/relay/config-store.js,装配层只留装配与状态仓外壳(行数兜底)。
4
5
  // 装配移动 API、设备吊销与独立直连生命周期,并向本机面板提供真实上报目的地。
@@ -32,7 +33,7 @@ const { readRawBody } = require('./shared/e2ee-request')
32
33
  const streamRegistry = require('./mobile/stream-registry.js')
33
34
  const { viaChannel } = require('./shared/via-header')
34
35
  const { deviceMetaFromHeaders } = require('./shared/device-headers.js')
35
- const { createSidecarLifecycle, createRouteAdopter } = require('./sidecar-lifecycle.cjs')
36
+ const { createSidecarLifecycle, createRouteAdopter, createTunnelReconnector } = require('./sidecar-lifecycle.cjs')
36
37
  const { createMirrorPusher } = require('./mirror/pusher.cjs')
37
38
  const { randomBytes } = require('node:crypto')
38
39
  const { lanUrls, advertisedCandidates, phoneCandidates, ipv6Candidates, withManualIpv6Candidate } = require('./relay/lan-network.cjs')
@@ -47,7 +48,7 @@ const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会
47
48
  // FRP 直连:用面板导入的配置拉起本地 frpc(见 lib/frpc/runner.cjs)。
48
49
  const { createFrpcRunner } = require('./frpc/runner.cjs')
49
50
  const { createPreviewService } = require('./relay/preview.js')
50
- const { createMuxService } = require('./mobile/mux.js')
51
+ const { createMuxService, createMuxAuthorizer } = require('./mobile/mux.js')
51
52
  const { mountRemoteComputers } = require('./remote/runtime.cjs')
52
53
  // 手机打开「电脑上的网页版」时用的那枚一次性登录令牌(见 mobile/host-web.js)。
53
54
  const hostWeb = require('./mobile/host-web.js')
@@ -55,7 +56,7 @@ const hostWeb = require('./mobile/host-web.js')
55
56
  // 否则「撤销全部授权」只清了中转侧,同网设备仍能用旧凭据直连宿主。
56
57
  // 入口按两条盘上布局分别找(嵌在插件包内 / 与插件包同级),见 shared/credentials-entry.js。
57
58
  const credentials = require('./shared/credentials-entry.js').credentialsEntry()
58
- const { createApiProxy, runtimeProvidesApiProxy } = require('./mobile/host-bridge.js')
59
+ const { createApiProxyService, runtimeProvidesApiProxy } = require('./mobile/host-bridge.js')
59
60
  const { installApprovalBridge, setPushNotifier: setApprovalPushNotifier } = require('./mobile/approvals.js')
60
61
  const { installQuestionBridge, setPushNotifier: setQuestionPushNotifier } = require('./mobile/questions.js')
61
62
  const { createPushNotifier } = require('./mobile/push-notify.js')
@@ -200,11 +201,11 @@ function apply(ctx) {
200
201
  // ApiProxyService,由 dsh-web-app 那一层供给),这时再 provide 一次会让整棵树加载
201
202
  // 失败:`service "apiProxy" has been registered at <dsh-mobile-plugin>`,报错挂在
202
203
  // 后到的 api-gateway 入口上,服务器宿主曾因此完全起不来。而且旧运行时的桥也翻译不动
203
- // —— host-bridge.js 是翻译到 0.2.0 的 `ctx.get('typertGateway')` 的。所以按运行时
204
- // 有没有这个包二选一:有就用宿主那份真 apiProxy,没有才装兼容服务。
205
- // (不能靠 `ctx.get('apiProxy')` 判断:宿主是后于本插件装载的,那时它还不在。)
206
- // 这两条二选一,判据同源:0.1.x 宿主自带真 apiProxy(审批帧与回答都还走得通),
207
- // 0.2.x 才需要兼容桥,也才需要审批桥(见 mobile/approvals.js 的文件头)。
204
+ // —— host-bridge.js 是翻译到 0.2.0 的 `ctx.get('typertGateway')` 的。因为兼容服务建在
205
+ // 本代独立作用域里(`ctx.isolate`),和宿主的根作用域互不冲突,所以可以**启动即提供**,
206
+ // 不必再等宿主那份出现:提供的对象优先取宿主的真 apiProxy,取不到才走兼容桥。
207
+ // 判据仍同源:0.1.x 宿主自带真 apiProxy(审批帧与回答都还走得通),0.2.x 才需要兼容桥,
208
+ // 也才需要审批桥(见 mobile/approvals.js 的文件头)。
208
209
  const hasHostApiProxy = runtimeProvidesApiProxy()
209
210
  /** 装配层自己的告警出口:拿不到 logger 也照样往下走,不打日志不是失败。 */
210
211
  const warn = (message, ...rest) => {
@@ -227,31 +228,36 @@ function apply(ctx) {
227
228
  const notifyInteraction = (sessionId, card, hints) => { if (pushNotify) { try { void pushNotify.notifyInteraction(sessionId, card, { ...(hints && typeof hints === 'object' ? hints : {}), title: mirror?.sessionTitleOf?.(sessionId) }) } catch { /* ignore */ } } }
228
229
  setApprovalPushNotifier(notifyInteraction); setQuestionPushNotifier(notifyInteraction)
229
230
  /**
230
- * 装兼容桥与两条帧桥(审批 / 提问)。
231
+ * 取宿主自己那份 apiProxy(旧运行时)。新版宿主上没有这个服务,取不到就回 null。
231
232
  *
232
- * 三者都只在「宿主这一代没有真 apiProxy」时才装:旧宿主自带真服务,多 provide 一次会让
233
- * 整棵树加载失败(`service "apiProxy" has been registered at <dsh-mobile-plugin>`)。
234
- * 兼容服务只在本代作用域可见;蓝绿换代时旧代仍在服务,新代也能独立完成装配。
233
+ * 必须判 `typeof hostContext.get === 'function'`:老宿主上的 cordis 未必有 `ctx.get`,
234
+ * 裸调会在定时器回调里抛出去(被进程级错误边界吞掉、进程不死),apiProxy 就再也补不上,
235
+ * 手机侧会永久报「without inject」。本文件其它取宿主服务的地方都这么判。
235
236
  */
236
- const installCompatBridges = () => {
237
- mount('apiProxy 兼容桥', () => ctx.reflect.provide('apiProxy', createApiProxy(ctx)))
237
+ const hostApiProxy = () => {
238
+ try { return typeof hostContext.get === 'function' ? hostContext.get('apiProxy') : null } catch { return null }
239
+ }
240
+ /**
241
+ * apiProxy **启动即提供**;走宿主真服务还是网关兼容桥由 host-bridge 的 createApiProxyService
242
+ * 推迟到调用那一刻决定。插件刚启动 / 刚换代的瞬间被打到也不会读到「还没提供的服务」,不会抛
243
+ * `cannot get property "apiProxy" without inject`(「加载会话列表失败」就是这条)。
244
+ */
245
+ const provideApiProxy = () => mount('apiProxy 兼容桥', () => ctx.reflect.provide('apiProxy', createApiProxyService(ctx, hostApiProxy)))
246
+ /** 两条帧桥(审批 / 提问):旧宿主自带真服务时由它处理、不装;新版宿主才补上。 */
247
+ const installFrameBridges = () => {
238
248
  mount('审批桥', () => ctx.effect(() => installApprovalBridge(ctx), `${name}: host approval bridge`))
239
249
  mount('提问桥', () => ctx.effect(() => installQuestionBridge(ctx), `${name}: host question bridge`))
240
250
  }
241
- if (!hasHostApiProxy) installCompatBridges()
251
+ provideApiProxy()
252
+ if (!hasHostApiProxy) installFrameBridges()
242
253
  else {
243
254
  // 解析到包只说明「宿主可能是旧版」:新版宿主上包名还在、`apiProxy` 服务已经没了
244
- // (2026-11-02 反馈 #11)。先给它一会儿把真服务 provide 出来(旧宿主在本插件装配
245
- // 前后就会挂上),到点还没有就当作新版宿主,自己把兼容桥与两条帧桥装上 —— 否则
246
- // 十几个移动端模块读到的是一个永远不来的服务,手机侧全程静默失败。
255
+ // (2026-11-02 反馈 #11)。给它一会儿把真服务 provide 出来;到点还没有,就按新版宿主
256
+ // 补上两条帧桥(apiProxy 本身上面已经提供,届时自动走兼容桥)。
247
257
  const timer = setTimeout(() => {
248
- const hostProxy = hostContext.get('apiProxy')
249
- if (hostProxy) {
250
- ctx.reflect.provide('apiProxy', hostProxy)
251
- return
252
- }
258
+ if (hostApiProxy()) return
253
259
  warn('等不到宿主的 apiProxy,按新版宿主装配兼容桥')
254
- installCompatBridges()
260
+ installFrameBridges()
255
261
  }, API_PROXY_GRACE_MS)
256
262
  timer.unref?.()
257
263
  ctx.effect(() => () => clearTimeout(timer), `${name}: host apiProxy grace timer`)
@@ -353,11 +359,12 @@ function apply(ctx) {
353
359
  })
354
360
  }
355
361
  const { sidecarToken, syncSidecar, restartSidecar, tunnelConnected } = sidecarLifecycle
362
+ const reconnectTunnel = createTunnelReconnector(sidecarLifecycle, async () => { await resolveLanPort(); return buildSidecarConfig(lanPortInUse()) })
356
363
  relayConnectedOf = tunnelConnected
357
364
 
358
365
  // 身份冲突时换身份:实现在 relay/identity-rotate.cjs,装配层只把它挂上(含重入保护)。
359
366
  // 换号后把本机签发的设备凭据整体迁到新号(凭据库归本进程),否则换第二次会甩下更早配对的手机。
360
- const rotateNow = createIdentityRotator({ state, rotateIdentity: core.rotateIdentity, saveState: core.saveState, syncSidecar, syncControl: () => control.sync(), migrateCredentials: (toId) => credentials.reassignInstance(toId) })
367
+ const rotateNow = createIdentityRotator({ state, rotateIdentity: core.rotateIdentity, saveState: core.saveState, syncSidecar, syncControl: () => control.sync(), migrateCredentials: (toId) => credentials.reassignInstance(toId), migrateConnections: (fromId, toId) => { streamRegistry.reassignInstance(fromId, toId); preview.reassignInstance(fromId, toId); if (typeof mux.reassignInstance === 'function') mux.reassignInstance(fromId, toId); else mux.dropAll?.() } })
361
368
 
362
369
  // 总控上报:优先用**稳定外壳**持有的那份(换代不断开上报连接);外壳不在时本地创建兜底。
363
370
  // getPort 依赖上面刚就位的 sidecar/advertisedLanPort,所以放在这里建。
@@ -547,6 +554,7 @@ function apply(ctx) {
547
554
  status,
548
555
  settings,
549
556
  syncSidecar,
557
+ reconnectTunnel,
550
558
  // ⚠️ 必须传取值器:sidecar 会被自重启整体替换,传实例就是一份永远指向旧 facade 的快照。
551
559
  getSidecar: sidecarLifecycle.getSidecar,
552
560
  credentials,
@@ -643,16 +651,9 @@ function apply(ctx) {
643
651
  ctx.effect(() => () => preview.close(), `${name}: preview pipes`)
644
652
 
645
653
  // 对话页长连接(mux):一条手机 WS 上按 id 多路复用,逐条转成本地回环请求打到移动 API。
646
- // 鉴权口径与预览升级路由同一套(设备凭据有效即可);逐路由权限仍由回环 HTTP 的 guarded 判,
654
+ // 升级先验设备凭据与查看权限;当前authorizer也覆盖外壳仍持旧service的热换代,逐路由仍由guarded判。
647
655
  // mux 只是搬运工,不另立权限面。帧契约见 `docs/mux-long-connection-design.md` §11。
648
- const muxAuthorize = (req) => {
649
- try {
650
- const outcome = authOutcome(req)
651
- if (!outcome.ok || !outcome.record) return false
652
- req.__dshRecord = outcome.record
653
- return true
654
- } catch { return false }
655
- }
656
+ const muxAuthorize = createMuxAuthorizer(authOutcome)
656
657
  // mux 优先用**稳定外壳**持有的那份(换代时已建立的手机 WS 不断);外壳不在时本地创建兜底。
657
658
  // 升级路由由外壳直接挂(见 shell/transport-host.js),这一代不再重复注册。
658
659
  let muxHost = null
@@ -731,6 +732,7 @@ function apply(ctx) {
731
732
  state,
732
733
  settings,
733
734
  syncSidecar,
735
+ reconnectTunnel,
734
736
  status,
735
737
  resolveLanPort,
736
738
  lanPortInUse: advertisedLanPort,
@@ -747,6 +749,8 @@ function apply(ctx) {
747
749
  getControl: () => control.snapshot(),
748
750
  syncControl: () => control.sync(),
749
751
  controlAddresses: () => control.addresses(),
752
+ // 让「立即同步」在电脑端把总控存的那份也解开一并回给手机(见 relay-control.handleControlSync)。
753
+ getHistoryKey,
750
754
  },
751
755
  }))
752
756
  mount('服务同步', () => ctx.effect(() => {
package/lib/index.js CHANGED
@@ -31,6 +31,7 @@ import { installedPackageDir, installedVersion, profileNodeModules, snapshotRunn
31
31
  import { createDeviceOta } from './shell/device-ota.js'
32
32
  import { installHostHalf } from './shell/half-route.js'
33
33
  import { installTransportHosts } from './shell/transport-host.js'
34
+ import { firstInstallNeedsRestart } from './shell/first-install.js'
34
35
 
35
36
  export const name = 'dsh-mobile-plugin'
36
37
  // 外壳同样只等 `webServer`:它不读 `sessions`,多注一个只是多一种「整行 pending」的理由。
@@ -203,6 +204,8 @@ export function apply(ctx) {
203
204
  marketResult: updateState.result,
204
205
  lastApply: updateState.lastApply,
205
206
  appliedAt: updateState.appliedAt,
207
+ /** 第一次装进一台正在跑的 DSH、还没重启过:手机端据此要求重启一次(见 shell/first-install.js)。 */
208
+ firstInstallPendingRestart: firstInstallNeedsRestart(),
206
209
  }),
207
210
  check,
208
211
  apply: applyUpdate,
@@ -1,3 +1,4 @@
1
+ // 默认预设写入前拒绝激活失败的条目,并保留宿主诊断原因。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -177,6 +178,17 @@ async function handleAgentPresetDefault(ctx, req, res) {
177
178
  },
178
179
  });
179
180
  }
181
+ const reason = typeof row.broken === 'string' && row.broken.trim() ? row.broken : undefined;
182
+ if (row.broken === true || reason !== undefined) {
183
+ return sendJson(res, 400, {
184
+ ok: false,
185
+ error: {
186
+ code: 'agent-preset-invalid',
187
+ message: '这个 Agent 预设加载失败,不能设为默认',
188
+ details: { agentPreset: id.value, ...(reason === undefined ? {} : { reason }) },
189
+ },
190
+ });
191
+ }
180
192
  // 已经是默认档就不再写:settings.mutate 一次就推进一次 revision,白写等于让别处正在
181
193
  // 改设置的人撞上冲突。
182
194
  if (row.isDefault === true) return sendJson(res, 200, { ok: true, agentPreset: id.value });
@@ -1,3 +1,4 @@
1
+ // 回答来源与实时、历史步骤共用工具结果状态。
1
2
  'use strict';
2
3
 
3
4
  /**
@@ -30,6 +31,7 @@ const { parseArgs } = require('./step-index.js');
30
31
  const { liveStepOf, liveStepsOf, liveStepsTurnOf } = require('./live-steps.js');
31
32
  const { readTurnEvents } = require('./session-changes.js');
32
33
  const { resultCallId, successfulResult } = require('./turn-facts.js');
34
+ const { toolResultState } = require('./tool-result-state.js');
33
35
 
34
36
  /** 来源条数的极端兜底:一轮读到的材料照单全出,这里只防回包被几百份材料撑爆。 */
35
37
  const MAX_SOURCES = 60;
@@ -134,8 +136,7 @@ function stepsByTurnOf(events) {
134
136
  if (event?.type !== 'tool/result') continue;
135
137
  const id = resultCallId(event);
136
138
  if (!id) continue;
137
- const interrupted = event.data?.error?.code === 'interrupted';
138
- results.set(id, successfulResult(event) ? 'ok' : interrupted ? 'stopped' : 'error');
139
+ results.set(id, toolResultState({ isError: !successfulResult(event), code: event.data?.error?.code }));
139
140
  }
140
141
  const push = (turn, entry) => {
141
142
  if (!byTurn.has(turn)) {