dsh-mobile-plugin 0.5.51 → 0.5.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dsh-mobile-credentials/lib/credentials.js +34 -2
- package/lib/client.js +203 -11
- package/lib/impl.js +5 -0
- package/lib/mobile/channels.js +18 -21
- package/lib/mobile/directory-listing.js +3 -1
- package/lib/mobile/events.js +2 -0
- package/lib/mobile/host-bridge/endpoints.js +2 -1
- package/lib/mobile/host-bridge/event-synthesis.js +48 -39
- package/lib/mobile/host-web.js +2 -2
- package/lib/mobile/model-caps.js +15 -5
- package/lib/mobile/model-meta-table.cjs +5 -4
- package/lib/mobile/model-meta.js +5 -3
- package/lib/mobile/permissions.js +1 -3
- package/lib/mobile/stream.js +2 -0
- package/lib/mobile/workspaces.js +6 -5
- package/lib/panel/index.html +15 -15
- package/lib/relay/lan-proxy.js +15 -8
- package/lib/remote/browser-notice.cjs +118 -0
- package/lib/remote/controller.cjs +212 -0
- package/lib/remote/crypto.cjs +197 -0
- package/lib/remote/host-control.cjs +59 -0
- package/lib/remote/host.cjs +226 -0
- package/lib/remote/local-headers.cjs +102 -0
- package/lib/remote/local-upstream.cjs +144 -0
- package/lib/remote/local.cjs +144 -0
- package/lib/remote/network.cjs +42 -0
- package/lib/remote/router.cjs +194 -0
- package/lib/remote/routes.cjs +73 -0
- package/lib/remote/runtime.cjs +36 -0
- package/lib/remote/store.cjs +60 -0
- package/lib/remote/transport.cjs +184 -0
- package/lib/remote/tunnel-helper.cjs +167 -0
- package/lib/remote/tunnels.cjs +190 -0
- package/lib/routes/mobile-api.js +7 -2
- package/lib/shared/route-order.cjs +202 -0
- package/lib/tailcat/session.cjs +31 -36
- package/package.json +7 -6
- package/lib/mobile/perf-trace.js +0 -142
package/README.md
CHANGED
|
@@ -45,6 +45,16 @@
|
|
|
45
45
|
- **模型**:随时换模型,看有哪些渠道和可用模型,本机自建的渠道也能直接在手机上配。
|
|
46
46
|
- **日程与子代理**:定时任务能看、新建、改、暂停恢复、立刻跑一次、删掉;看正在跑的子代理,打断它或者补一句话。
|
|
47
47
|
|
|
48
|
+
### 远程电脑
|
|
49
|
+
|
|
50
|
+
在家里的 A 电脑打开插件控制台的「远程电脑」,生成并复制绑定信息,再到随身的 B 电脑粘贴添加。绑定信息十分钟内有效、只能使用一次;两台电脑都需要安装支持远程电脑的插件。
|
|
51
|
+
|
|
52
|
+
绑定后在 B 点击「浏览器打开」,即可通过本机地址使用 A 的完整 DSH 网页,不需要域名或手机参与。默认自动选择局域网、直连、IPv6、中转或可用隧道;网络变化后重新选路,正常的实时连接不会因细小测速差异被打断。完整网页授权具有远程操作该 DSH 的能力,只向自己信任的电脑发放。
|
|
53
|
+
|
|
54
|
+
每次网页访问允许一小时,临近到期会提示;在 B 的插件控制台主动续期才能继续,到期后须重新打开,绑定关系保留。停止访问、插件退出或 A 撤销授权会断开网页连接,不停止 A 上已经运行的任务。A 可在「可访问本机的电脑」中撤销 B;B 可移除自己保存的绑定。
|
|
55
|
+
|
|
56
|
+
网页字节在两端插件之间加密,线路只转发密文;长期绑定凭据由宿主凭据存储保存,浏览器只持有本次访问的临时会话。默认只监听本机回环,不把浏览器入口开放给局域网。
|
|
57
|
+
|
|
48
58
|
### 连接
|
|
49
59
|
|
|
50
60
|
- 两种连法:经 relay v2 隧道从公网连回来,或者同一个 Wi-Fi 下走局域网直连。
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
// 电脑网页授权独立于手机权限;调整设备权限会同步收回该授权。
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 每设备凭据库:签发、校验、吊销手机端的持久化凭据。
|
|
@@ -211,6 +212,7 @@ function issue(instanceId, device, hostToken, ttlMs = DEFAULT_TTL_MS, extra = {}
|
|
|
211
212
|
// **只在真给了数组时才写这一格**:不写 = 全权,这是老记录与现网设备的兼容命门,
|
|
212
213
|
// 绝不能在这里补一个默认数组把「没设置」变成「设置成某个子集」。
|
|
213
214
|
if (Array.isArray(extra?.permissions)) record.permissions = extra.permissions.slice();
|
|
215
|
+
if (extra?.remoteWeb === true && deviceKey && keyId) { record.remoteWeb = true; record.kind = 'computer'; }
|
|
214
216
|
prune(now);
|
|
215
217
|
records.push(record);
|
|
216
218
|
rebuildIndex();
|
|
@@ -248,6 +250,7 @@ function setDevicePermissions(instanceId, deviceId, permissions) {
|
|
|
248
250
|
for (const record of records) {
|
|
249
251
|
if (record.instanceId !== instanceId || record.deviceId !== deviceId || !isLive(record)) continue;
|
|
250
252
|
record.permissions = wanted.slice();
|
|
253
|
+
if (record.remoteWeb === true) record.remoteWeb = false;
|
|
251
254
|
count += 1;
|
|
252
255
|
}
|
|
253
256
|
if (count) save();
|
|
@@ -305,6 +308,17 @@ function findByKeyId(instanceId, keyId) {
|
|
|
305
308
|
return null;
|
|
306
309
|
}
|
|
307
310
|
|
|
311
|
+
/** 电脑通道只用它签署已吊销/到期的拒绝,不把失效记录恢复为授权。 */
|
|
312
|
+
function lookupRemoteByKeyId(instanceId, keyId) {
|
|
313
|
+
refresh();
|
|
314
|
+
if (typeof keyId !== 'string' || !keyId) return null;
|
|
315
|
+
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
316
|
+
const record = records[i];
|
|
317
|
+
if (record.instanceId === instanceId && record.keyId === keyId && record.deviceKey) return record;
|
|
318
|
+
}
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
|
|
308
322
|
/**
|
|
309
323
|
* 记一次「这台设备刚连上过」。
|
|
310
324
|
*
|
|
@@ -402,6 +416,22 @@ function revokeAllByInstance(instanceId) {
|
|
|
402
416
|
return count;
|
|
403
417
|
}
|
|
404
418
|
|
|
419
|
+
/** 本实例仍有效的电脑网页授权,只返回管理清单需要的公开字段。 */
|
|
420
|
+
function listRemoteComputers(instanceId) {
|
|
421
|
+
refresh();
|
|
422
|
+
const now = Date.now();
|
|
423
|
+
const devices = new Map();
|
|
424
|
+
for (const record of records) {
|
|
425
|
+
if (record.instanceId !== instanceId || record.remoteWeb !== true || !isLive(record, now)) continue;
|
|
426
|
+
const previous = devices.get(record.deviceId);
|
|
427
|
+
if (!previous || record.createdAt > previous.createdAt) devices.set(record.deviceId, {
|
|
428
|
+
deviceId: record.deviceId, name: record.name || '', platform: record.platform || '',
|
|
429
|
+
lastSeenAt: Number(record.lastSeenAt) || 0, createdAt: Number(record.createdAt) || 0,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
return [...devices.values()];
|
|
433
|
+
}
|
|
434
|
+
|
|
405
435
|
function listActive() {
|
|
406
436
|
load();
|
|
407
437
|
const now = Date.now();
|
|
@@ -428,7 +458,7 @@ function scanDevices(instanceId, now = Date.now()) {
|
|
|
428
458
|
/** 名下有过活记录的 deviceId:这种设备在活动清单里已经有一行,历史那半不能再出现它。 */
|
|
429
459
|
const living = new Set();
|
|
430
460
|
for (const record of records) {
|
|
431
|
-
if (record.instanceId !== instanceId) continue;
|
|
461
|
+
if (record.instanceId !== instanceId || record.kind === 'computer') continue;
|
|
432
462
|
const key = String(record.deviceId || '');
|
|
433
463
|
const createdAt = Number(record.createdAt) || 0;
|
|
434
464
|
if (isLive(record, now)) {
|
|
@@ -644,7 +674,7 @@ function activeDigests(instanceId) {
|
|
|
644
674
|
// 记录只在新签发时追加,倒着走就是 createdAt 倒序:超出上限时被截掉的是最老的。
|
|
645
675
|
for (let i = records.length - 1; i >= 0 && live.length < MAX_ACTIVE_DIGESTS; i -= 1) {
|
|
646
676
|
const record = records[i];
|
|
647
|
-
if (record.instanceId !== instanceId || !isLive(record, now)) continue;
|
|
677
|
+
if (record.instanceId !== instanceId || record.kind === 'computer' || !isLive(record, now)) continue;
|
|
648
678
|
live.push({ hash: record.hash, ...(record.expiresAt ? { expiresAt: record.expiresAt } : {}) });
|
|
649
679
|
}
|
|
650
680
|
return live;
|
|
@@ -671,12 +701,14 @@ module.exports = {
|
|
|
671
701
|
lookup,
|
|
672
702
|
isLive,
|
|
673
703
|
findByKeyId,
|
|
704
|
+
lookupRemoteByKeyId,
|
|
674
705
|
touch,
|
|
675
706
|
renew,
|
|
676
707
|
refresh,
|
|
677
708
|
setReadOnly,
|
|
678
709
|
isReadOnly,
|
|
679
710
|
listActive,
|
|
711
|
+
listRemoteComputers,
|
|
680
712
|
listDevices,
|
|
681
713
|
listHistory,
|
|
682
714
|
listDevicesWithHistory,
|
package/lib/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 移动端插件提供电脑插件页面目录;标准页面保留宿主上下文并支持直接导航。
|
|
3
3
|
*
|
|
4
4
|
* 五件事:桌面侧边栏的展开态与「读过了」报给宿主;手机端的已读回执应用回桌面绿点;
|
|
5
5
|
* 设置里那一项「移动端」(一张薄卡,一颗「打开配置页面」);在侧边栏最底下那一行挂一颗
|
|
@@ -52,7 +52,7 @@ window.__ModuleLoader__.load({
|
|
|
52
52
|
.dshm_dialogWide{max-width:1040px;height:82vh;max-height:82vh;overflow:hidden}
|
|
53
53
|
.dshm_dialogWide .dshm_frameWrap{flex:1;min-height:0;display:flex;position:relative}
|
|
54
54
|
.dshm_frame{flex:1;min-height:0;width:100%;border:0;border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1)}
|
|
55
|
-
/* iframe
|
|
55
|
+
/* 加载提示由内嵌页就绪回执撤掉,不能只凭 iframe load。 */
|
|
56
56
|
.dshm_frameTip{position:absolute;inset:auto 0 0;margin:0;padding:8px 10px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
|
|
57
57
|
/* 版面竖向排列的那一列(外壳里没法内嵌时用它摆读数)。 */
|
|
58
58
|
.dshm_dialogColumn{flex:1;min-height:0;overflow:auto;display:flex;flex-direction:column;gap:10px}
|
|
@@ -429,6 +429,10 @@ window.__ModuleLoader__.load({
|
|
|
429
429
|
const NS = 'settings.mobileRelay';
|
|
430
430
|
const DICT = {
|
|
431
431
|
zh: {
|
|
432
|
+
pluginPages: '电脑插件',
|
|
433
|
+
pluginPagesEmpty: '这台电脑暂时没有可打开的插件页面。',
|
|
434
|
+
pluginPagesHint: '这里打开电脑上的插件界面,不要求插件专门适配 App。',
|
|
435
|
+
pluginPageMissing: '这个页面已经不可用,请返回列表重试。',
|
|
432
436
|
nav: '移动端',
|
|
433
437
|
heading: '移动端',
|
|
434
438
|
cardPanel: '配置页面',
|
|
@@ -455,7 +459,9 @@ window.__ModuleLoader__.load({
|
|
|
455
459
|
consoleTroubleshoot: '报错调试',
|
|
456
460
|
consolePopupBlocked: '浏览器拦掉了新窗口,允许本站弹出窗口后再点一次。',
|
|
457
461
|
consoleOpenBrowser: '在浏览器里打开',
|
|
458
|
-
|
|
462
|
+
consoleLoading: '正在载入控制台…',
|
|
463
|
+
consoleReload: '重新载入',
|
|
464
|
+
consoleFrameless: '控制台未能完成加载,请点「重新载入」重试,也可以在浏览器里打开。',
|
|
459
465
|
diagTitleLoad: '打不开移动端配置页',
|
|
460
466
|
diagTitleOpen: '开放网页管理失败',
|
|
461
467
|
diagChecking: '正在读取宿主状态…',
|
|
@@ -501,6 +507,10 @@ window.__ModuleLoader__.load({
|
|
|
501
507
|
diagFactWindow: '两小时窗口',
|
|
502
508
|
},
|
|
503
509
|
en: {
|
|
510
|
+
pluginPages: 'Computer plugins',
|
|
511
|
+
pluginPagesEmpty: 'This computer has no plugin pages available to open.',
|
|
512
|
+
pluginPagesHint: 'Open computer plugin interfaces here, including plugins without App adaptation.',
|
|
513
|
+
pluginPageMissing: 'This page is no longer available. Return to the list and try again.',
|
|
504
514
|
nav: 'Mobile',
|
|
505
515
|
heading: 'Mobile',
|
|
506
516
|
cardPanel: 'Configuration page',
|
|
@@ -527,7 +537,9 @@ window.__ModuleLoader__.load({
|
|
|
527
537
|
consoleTroubleshoot: 'Troubleshoot',
|
|
528
538
|
consolePopupBlocked: 'The browser blocked the new window — allow pop-ups for this site and press again.',
|
|
529
539
|
consoleOpenBrowser: 'Open in a browser',
|
|
530
|
-
|
|
540
|
+
consoleLoading: 'Loading the console…',
|
|
541
|
+
consoleReload: 'Reload',
|
|
542
|
+
consoleFrameless: 'The console could not finish loading. Choose Reload to try again, or open it in a browser.',
|
|
531
543
|
diagTitleLoad: 'Cannot open the mobile configuration page',
|
|
532
544
|
diagTitleOpen: 'Could not open web management',
|
|
533
545
|
diagChecking: 'Reading host status…',
|
|
@@ -605,6 +617,8 @@ window.__ModuleLoader__.load({
|
|
|
605
617
|
* 同源 `postMessage` 通知,页面那边听不到就照常按 `document.hidden` 判。
|
|
606
618
|
*/
|
|
607
619
|
const PANEL_VISIBILITY = 'dsh-mobile-plugin:panel-visibility';
|
|
620
|
+
const PANEL_STATE = 'dsh-mobile-plugin:panel-state';
|
|
621
|
+
const PANEL_LOAD_TIMEOUT_MS = 20000;
|
|
608
622
|
|
|
609
623
|
/** 通知嵌着的那一页:现在看得见 / 看不见。拿不到窗口就静默跳过。 */
|
|
610
624
|
function tellFrame(overlay, visible) {
|
|
@@ -625,7 +639,10 @@ window.__ModuleLoader__.load({
|
|
|
625
639
|
/** 底下那一句说明(复制结果就地改它,不重画整窗)。 */
|
|
626
640
|
let noteEl = null;
|
|
627
641
|
let escapeListener = null;
|
|
642
|
+
let stopFrame = () => {};
|
|
628
643
|
const hide = () => {
|
|
644
|
+
// 只有已确认就绪的页面保活;加载中或失败的页面,下次打开必须重新请求。
|
|
645
|
+
if (overlay && overlay.__dshmFrameState !== 'ready') overlay.__dshmKeep = false;
|
|
629
646
|
// **`keep` 的窗只收起、不销毁**:那一页是一份 1.4MB 的单文件产物,销毁掉下次
|
|
630
647
|
// 打开就得整份重新下载 + 重新挂载,实测每次多花七百来毫秒 —— 而用户点一下手机图标
|
|
631
648
|
// 只是想看一眼。留着它、隐藏起来,再打开是热的(实测 866ms → 123ms)。
|
|
@@ -636,6 +653,7 @@ window.__ModuleLoader__.load({
|
|
|
636
653
|
tellFrame(overlay, false);
|
|
637
654
|
// 说明那一行**不清**:下次复用这一窗时还要往上写一句「已复制」之类。
|
|
638
655
|
} else if (overlay) {
|
|
656
|
+
stopFrame();
|
|
639
657
|
if (typeof overlay.remove === 'function' && overlay.parentElement) overlay.remove();
|
|
640
658
|
// 不保留的那种收起就是彻底不留:引用一并清掉,下次是全新一窗(Esc / 遮罩也重新挂)。
|
|
641
659
|
overlay = null;
|
|
@@ -658,7 +676,8 @@ window.__ModuleLoader__.load({
|
|
|
658
676
|
const frameSrc = spec.frame && spec.frame.src ? String(spec.frame.src) : '';
|
|
659
677
|
// **同一页再开一次,直接把上一次那一窗亮出来**(见 `hide` 里的说明):那一页还活着,
|
|
660
678
|
// 重建等于把整份产物重新解析、React 重新挂载一遍。地址变了(换了页)才重建。
|
|
661
|
-
if (overlay && overlay.__dshmKeep && overlay.__dshmSrc === frameSrc
|
|
679
|
+
if (overlay && overlay.__dshmKeep && overlay.__dshmSrc === frameSrc
|
|
680
|
+
&& overlay.__dshmFrameState === 'ready') {
|
|
662
681
|
if (typeof overlay.style === 'object') overlay.style.display = '';
|
|
663
682
|
if (spec.title) overlay.setAttribute('aria-label', spec.title);
|
|
664
683
|
tellFrame(overlay, true);
|
|
@@ -692,8 +711,10 @@ window.__ModuleLoader__.load({
|
|
|
692
711
|
if (spec.title) overlay.setAttribute('aria-label', spec.title);
|
|
693
712
|
// 「这一窗收起时不销毁」的记号(见 `hide`)。只有带整页 iframe 的那一窗需要它:
|
|
694
713
|
// 那一页重建一次要重新解析一整份产物,而诊断窗那几行读数是现拼的,重建几乎不要钱。
|
|
714
|
+
stopFrame();
|
|
695
715
|
overlay.__dshmKeep = Boolean(spec.keep);
|
|
696
716
|
overlay.__dshmSrc = frameSrc;
|
|
717
|
+
overlay.__dshmFrameState = frameSrc ? 'loading' : '';
|
|
697
718
|
// 每次重画:读数与按钮都是这一轮的现场,别留上一轮的字。
|
|
698
719
|
// **`children` 是 HTMLCollection,没有 `slice()`**(假元素是数组,测试覆盖不到);
|
|
699
720
|
// 先摊成数组再边删边走。
|
|
@@ -713,20 +734,59 @@ window.__ModuleLoader__.load({
|
|
|
713
734
|
// `src` 已经由调用方按同源地址算好(壳里是 `dsh-app://app/api/relay/panel/debug`,
|
|
714
735
|
// 网页里是同源 http),远程浏览器的那两小时窗口也在拨号那一步开好了。
|
|
715
736
|
//
|
|
716
|
-
//
|
|
717
|
-
// 静默留白,用户看到一屏空。所以先摆一句「正在载入」,`onload` 一到就撤掉;一直不
|
|
718
|
-
// load 就一直是那句话 + 底下那颗「在浏览器里打开」——不至于「点了没反应」。
|
|
737
|
+
// load 只说明文档结束导航;空页、错误响应、脚本启动失败都不能算控制台就绪。
|
|
719
738
|
if (spec.frame && spec.frame.src) {
|
|
720
739
|
const wrap = make('div', 'dshm_frameWrap');
|
|
721
740
|
const frame = doc.createElement('iframe');
|
|
722
741
|
frame.className = 'dshm_frame';
|
|
723
|
-
frame.setAttribute('src', spec.frame.src);
|
|
724
742
|
frame.setAttribute('title', spec.frame.title || spec.title || '');
|
|
725
743
|
frame.setAttribute('loading', 'eager');
|
|
726
|
-
const tip = make('p', 'dshm_frameTip', spec.frame.
|
|
744
|
+
const tip = make('p', 'dshm_frameTip', spec.frame.loading || '');
|
|
745
|
+
const owner = overlay;
|
|
746
|
+
const host = doc.defaultView || window;
|
|
747
|
+
let timer = null;
|
|
748
|
+
const clearTimer = () => {
|
|
749
|
+
if (timer !== null) host.clearTimeout(timer);
|
|
750
|
+
timer = null;
|
|
751
|
+
};
|
|
752
|
+
const update = (state, message) => {
|
|
753
|
+
if (overlay !== owner) return;
|
|
754
|
+
owner.__dshmFrameState = state;
|
|
755
|
+
clearTimer();
|
|
756
|
+
if (state === 'ready') {
|
|
757
|
+
if (tip.parentElement) tip.remove();
|
|
758
|
+
tellFrame(owner, !(owner.style && owner.style.display === 'none'));
|
|
759
|
+
} else {
|
|
760
|
+
tip.textContent = message || spec.frame.hint || '';
|
|
761
|
+
if (!tip.parentElement) wrap.appendChild(tip);
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
const onMessage = (event) => {
|
|
765
|
+
if (!frame.contentWindow || event.source !== frame.contentWindow) return;
|
|
766
|
+
const data = event.data;
|
|
767
|
+
if (!data || data.type !== PANEL_STATE) return;
|
|
768
|
+
if (data.state === 'ready' || data.state === 'error') update(data.state, data.message);
|
|
769
|
+
};
|
|
770
|
+
host.addEventListener('message', onMessage);
|
|
727
771
|
frame.onload = () => {
|
|
728
|
-
|
|
772
|
+
try {
|
|
773
|
+
const root = frame.contentDocument && frame.contentDocument.documentElement;
|
|
774
|
+
const state = root && root.getAttribute('data-dshm-panel-state');
|
|
775
|
+
if (state === 'ready' || state === 'error') {
|
|
776
|
+
update(state, root.getAttribute('data-dshm-panel-error'));
|
|
777
|
+
}
|
|
778
|
+
} catch { /* 被协议或浏览器阻断时,由超时提示与重试入口接管。 */ }
|
|
779
|
+
};
|
|
780
|
+
frame.onerror = () => update('error');
|
|
781
|
+
timer = host.setTimeout(() => update('error'), PANEL_LOAD_TIMEOUT_MS);
|
|
782
|
+
stopFrame = () => {
|
|
783
|
+
clearTimer();
|
|
784
|
+
host.removeEventListener('message', onMessage);
|
|
785
|
+
frame.onload = null;
|
|
786
|
+
frame.onerror = null;
|
|
787
|
+
stopFrame = () => {};
|
|
729
788
|
};
|
|
789
|
+
frame.setAttribute('src', spec.frame.src);
|
|
730
790
|
wrap.appendChild(frame);
|
|
731
791
|
wrap.appendChild(tip);
|
|
732
792
|
card.appendChild(wrap);
|
|
@@ -771,6 +831,7 @@ window.__ModuleLoader__.load({
|
|
|
771
831
|
* 用户已经不在这里看了,把那一页和一整份产物继续占着内存没有道理。
|
|
772
832
|
*/
|
|
773
833
|
const dispose = () => {
|
|
834
|
+
stopFrame();
|
|
774
835
|
if (overlay && typeof overlay.remove === 'function' && overlay.parentElement) overlay.remove();
|
|
775
836
|
overlay = null;
|
|
776
837
|
noteEl = null;
|
|
@@ -1182,6 +1243,10 @@ window.__ModuleLoader__.load({
|
|
|
1182
1243
|
const [anchored, setAnchored] = useState(true);
|
|
1183
1244
|
const nodeRef = useRef(null);
|
|
1184
1245
|
const dialogRef = useRef(null);
|
|
1246
|
+
useEffect(() => () => {
|
|
1247
|
+
if (dialogRef.current) dialogRef.current.dispose();
|
|
1248
|
+
dialogRef.current = null;
|
|
1249
|
+
}, []);
|
|
1185
1250
|
/**
|
|
1186
1251
|
* 文案在这里取、并把结果塞进下面那些 effect 的依赖里。
|
|
1187
1252
|
*
|
|
@@ -1392,9 +1457,11 @@ window.__ModuleLoader__.load({
|
|
|
1392
1457
|
frame: {
|
|
1393
1458
|
src: consolePage,
|
|
1394
1459
|
title: t('consoleTitle'),
|
|
1460
|
+
loading: t('consoleLoading'),
|
|
1395
1461
|
hint: t('consoleFrameless'),
|
|
1396
1462
|
},
|
|
1397
1463
|
actions: [
|
|
1464
|
+
{ label: t('consoleReload'), onClick: () => { dialog.dispose(); openPanel(); } },
|
|
1398
1465
|
{ label: t('consoleOpenBrowser'), primary: true, onClick: () => openBrowser(consolePage) },
|
|
1399
1466
|
{ label: t('consoleTroubleshoot'), onClick: () => openBrowser(debugPage) },
|
|
1400
1467
|
{ label: t('diagCopy'), onClick: () => void copyConsole() },
|
|
@@ -1803,6 +1870,130 @@ window.__ModuleLoader__.load({
|
|
|
1803
1870
|
}, 'mobile-plugin: 客户端半边自检上报');
|
|
1804
1871
|
}
|
|
1805
1872
|
|
|
1873
|
+
/** 列实际页面注册,不把工具、装饰槽或后台插件当作可打开的页面。 */
|
|
1874
|
+
function pluginPageRows(ctx) {
|
|
1875
|
+
const slots = ctx.slots;
|
|
1876
|
+
if (typeof slots.entries !== 'function') return [];
|
|
1877
|
+
const rows = [];
|
|
1878
|
+
const add = (kind, id, label) => {
|
|
1879
|
+
if (!id || id === 'mobile' || id === 'dsh-mobile-plugins' || id === 'conversation') return;
|
|
1880
|
+
if (kind === 'settings' && ['general', 'account', 'models', 'agent-presets', 'archived-sessions', 'plugins'].includes(id)) return;
|
|
1881
|
+
const value = typeof label === 'function' ? label() : label;
|
|
1882
|
+
rows.push({ key: `${kind}:${id}`, kind, id, label: value || id });
|
|
1883
|
+
};
|
|
1884
|
+
for (const entry of slots.entries('settings.section')) add('settings', entry.options.id, entry.options.label);
|
|
1885
|
+
const nav = slots.entries('sidebar.panellist');
|
|
1886
|
+
for (const entry of slots.entries('main')) {
|
|
1887
|
+
const id = entry.options.key;
|
|
1888
|
+
const label = nav.find((row) => row.options.id === id)?.options.label;
|
|
1889
|
+
if (id !== 'plugins') add('panel', id, label);
|
|
1890
|
+
}
|
|
1891
|
+
for (const entry of slots.entries('plugins.bundle.config')) add('bundle', entry.options.key, entry.options.label);
|
|
1892
|
+
for (const entry of slots.entries('plugins.row.config')) add('row', entry.options.key, entry.options.label);
|
|
1893
|
+
return rows.sort((a, b) => a.label.localeCompare(b.label));
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/** 导航既有页面,复用其共享 store,保留页面自己的注入、权限与生命周期。 */
|
|
1897
|
+
function openPluginPage(ctx, row) {
|
|
1898
|
+
if (!pluginPageRows(ctx).some((entry) => entry.key === row.key)) return false;
|
|
1899
|
+
const layout = ctx.get('layout');
|
|
1900
|
+
if (!layout) return false;
|
|
1901
|
+
if (row.kind === 'panel') {
|
|
1902
|
+
layout.selectPanel(row.id);
|
|
1903
|
+
return true;
|
|
1904
|
+
}
|
|
1905
|
+
if (row.kind === 'settings') {
|
|
1906
|
+
const entry = ctx.slots.entries('sidebar.settings')[0];
|
|
1907
|
+
const actions = entry?.store?.create().actions;
|
|
1908
|
+
if (typeof actions?.openSection !== 'function') return false;
|
|
1909
|
+
actions.openSection(row.id);
|
|
1910
|
+
return true;
|
|
1911
|
+
}
|
|
1912
|
+
const navigation = ctx.get('pluginNavigation');
|
|
1913
|
+
if (typeof navigation?.openBundle !== 'function') return false;
|
|
1914
|
+
const [name, rowId] = row.id.split('#');
|
|
1915
|
+
navigation.openBundle(name);
|
|
1916
|
+
if (row.kind === 'row') {
|
|
1917
|
+
const entry = ctx.slots.entries('main').find((item) => item.options.key === 'plugins');
|
|
1918
|
+
const actions = entry?.store?.create().actions;
|
|
1919
|
+
if (typeof actions?.setView !== 'function') return false;
|
|
1920
|
+
actions.setView({ kind: 'row', name, rowId });
|
|
1921
|
+
}
|
|
1922
|
+
return true;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
let pluginPageProblem = false;
|
|
1926
|
+
function PluginPages({ ctx, t }) {
|
|
1927
|
+
const [rows, setRows] = useState(() => pluginPageRows(ctx));
|
|
1928
|
+
const [problem, setProblem] = useState(() => pluginPageProblem);
|
|
1929
|
+
useEffect(() => {
|
|
1930
|
+
const failed = () => setProblem(true);
|
|
1931
|
+
window.addEventListener('dsh-mobile-plugin-missing', failed);
|
|
1932
|
+
return () => window.removeEventListener('dsh-mobile-plugin-missing', failed);
|
|
1933
|
+
}, []);
|
|
1934
|
+
useEffect(() => {
|
|
1935
|
+
const update = () => setRows(pluginPageRows(ctx));
|
|
1936
|
+
const offs = ['settings.section', 'main', 'sidebar.panellist', 'plugins.bundle.config', 'plugins.row.config']
|
|
1937
|
+
.map((name) => ctx.slots.subscribe(name, update));
|
|
1938
|
+
offs.push(ctx.locale.subscribe(update));
|
|
1939
|
+
update();
|
|
1940
|
+
return () => offs.forEach((off) => off());
|
|
1941
|
+
}, [ctx]);
|
|
1942
|
+
return h('section', { className: 'dshm_root', style: { padding: '16px', boxSizing: 'border-box', overflow: 'auto', height: '100%' } },
|
|
1943
|
+
h('h2', { className: 'dshm_heading' }, t('pluginPages')),
|
|
1944
|
+
h('p', { className: 'dshm_note' }, t('pluginPagesHint')),
|
|
1945
|
+
problem ? h('p', { className: 'dshm_error' }, t('pluginPageMissing')) : null,
|
|
1946
|
+
rows.length === 0 ? h('p', { className: 'dshm_note' }, t('pluginPagesEmpty')) : null,
|
|
1947
|
+
rows.map((row) => h('button', {
|
|
1948
|
+
key: row.key, type: 'button', className: 'dshm_btn',
|
|
1949
|
+
onClick: () => {
|
|
1950
|
+
pluginPageProblem = false;
|
|
1951
|
+
setProblem(false);
|
|
1952
|
+
window.location.hash = `#dsh-mobile-plugin=${encodeURIComponent(row.key)}`;
|
|
1953
|
+
},
|
|
1954
|
+
}, row.label)));
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
function installPluginPages(ctx, t) {
|
|
1958
|
+
if (typeof window === 'undefined' || typeof ctx.slots.entries !== 'function') return;
|
|
1959
|
+
ctx.effect(() => {
|
|
1960
|
+
let release = null;
|
|
1961
|
+
const route = () => {
|
|
1962
|
+
const hash = window.location.hash;
|
|
1963
|
+
const layout = ctx.get('layout');
|
|
1964
|
+
if (!layout) return;
|
|
1965
|
+
if (hash === '#dsh-mobile-plugins') {
|
|
1966
|
+
const shell = ctx.slots.entries('sidebar.settings')[0];
|
|
1967
|
+
shell?.store?.create().actions.close();
|
|
1968
|
+
layout.selectPanel('dsh-mobile-plugins');
|
|
1969
|
+
} else if (hash.startsWith('#dsh-mobile-plugin=')) {
|
|
1970
|
+
let key;
|
|
1971
|
+
try { key = decodeURIComponent(hash.slice('#dsh-mobile-plugin='.length)); } catch { return; }
|
|
1972
|
+
const row = pluginPageRows(ctx).find((item) => item.key === key);
|
|
1973
|
+
let opened = false;
|
|
1974
|
+
try { opened = Boolean(row && openPluginPage(ctx, row)); } catch { opened = false; }
|
|
1975
|
+
pluginPageProblem = !opened;
|
|
1976
|
+
if (!opened) {
|
|
1977
|
+
layout.selectPanel('dsh-mobile-plugins');
|
|
1978
|
+
window.dispatchEvent(new Event('dsh-mobile-plugin-missing'));
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
const activate = () => {
|
|
1983
|
+
if (window.location.hash !== '#dsh-mobile-plugins' && !window.location.hash.startsWith('#dsh-mobile-plugin=')) return;
|
|
1984
|
+
if (release) { route(); return; }
|
|
1985
|
+
release = ctx.inject(['layout'], (scope) => scope.slots.inject('main', () => {
|
|
1986
|
+
const off = scope.slots.register({ name: 'main', key: 'dsh-mobile-plugins', locale: NS, inject: () => ({ ctx, t }) }, PluginPages);
|
|
1987
|
+
route();
|
|
1988
|
+
return off;
|
|
1989
|
+
}));
|
|
1990
|
+
};
|
|
1991
|
+
activate();
|
|
1992
|
+
window.addEventListener('hashchange', activate);
|
|
1993
|
+
return () => { window.removeEventListener('hashchange', activate); if (typeof release === 'function') release(); };
|
|
1994
|
+
}, 'mobile-plugin: computer plugin pages');
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1806
1997
|
/* ── 设置里的那一项「移动端」───────────────────────────────────────────
|
|
1807
1998
|
* 设置里的「移动端」与侧边栏那颗图标进的是同一个页面、走同一条拨号链路(图标是快捷方式,
|
|
1808
1999
|
* 这一张是设置里的正规入口):介绍产品时说的入口就是「设置 → 移动端」,只留图标会让从
|
|
@@ -1908,6 +2099,7 @@ window.__ModuleLoader__.load({
|
|
|
1908
2099
|
apply(ctx) {
|
|
1909
2100
|
ctx.effect(() => ctx.locale.register(NS, DICT), 'mobile-plugin: settings dictionaries');
|
|
1910
2101
|
const t = ctx.locale.bind(NS);
|
|
2102
|
+
installPluginPages(ctx, t);
|
|
1911
2103
|
captureSessions(ctx);
|
|
1912
2104
|
startDesktopReadSync(ctx);
|
|
1913
2105
|
startReadReceiptSync(ctx);
|
package/lib/impl.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* `lib/sidecar-lifecycle.cjs`、路由表在 `lib/routes/*`,这些实现不许搬回来
|
|
5
5
|
* (`test/assembly-layer.test.cjs` 钉着)。
|
|
6
6
|
*/
|
|
7
|
+
// 远程电脑入口独立装配,手机端路由与权限保持原有边界。
|
|
7
8
|
import { createRequire } from 'node:module'
|
|
8
9
|
import os from 'node:os'
|
|
9
10
|
import path from 'node:path'
|
|
@@ -36,6 +37,7 @@ const { resolvePort } = require('./relay/port-allocator.cjs')
|
|
|
36
37
|
const { mountTailcat } = require('./tailcat/wiring.cjs') // 直连隧道:入口 + 落点代理 + 助手会话 + 启停
|
|
37
38
|
const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会话 + 落点代理(连接从隧道里进来,不必开回环门)
|
|
38
39
|
const { createPreviewService } = require('./relay/preview.js')
|
|
40
|
+
const { mountRemoteComputers } = require('./remote/runtime.cjs')
|
|
39
41
|
// 手机打开「电脑上的网页版」时用的那枚一次性登录令牌(见 mobile/host-web.js)。
|
|
40
42
|
const hostWeb = require('./mobile/host-web.js')
|
|
41
43
|
// 本机设备凭据库:/api/relay/revoke-all 必须同时吊销局域网直连的 dshc_ 凭据,
|
|
@@ -536,10 +538,13 @@ function apply(ctx) {
|
|
|
536
538
|
})
|
|
537
539
|
ctx.effect(() => () => preview.close(), `${name}: preview pipes`)
|
|
538
540
|
|
|
541
|
+
const remoteComputers = mount('远程电脑', () => mountRemoteComputers({ ctx, state, credentials, registerRoute, lanPortInUse: advertisedLanPort, tailcat, p2p, log: warn }))
|
|
542
|
+
|
|
539
543
|
// 移动端路由表在 lib/routes/mobile-api.js:那里是一张可以对着 App 侧 apiPaths.ts
|
|
540
544
|
// 核对的「路径 → handler」表,不用在 1000 行装配代码里翻。
|
|
541
545
|
mount('移动端路由', () => registerMobileRoutes({
|
|
542
546
|
registerRoute,
|
|
547
|
+
remoteComputers,
|
|
543
548
|
// 直连隧道:已配对的手机走这条拿到自己的入口地址,不用重新扫码。
|
|
544
549
|
tailcat,
|
|
545
550
|
// 点对点隧道:会合那一步(手机报上候选、这里把它拉起来并回自己的候选)。
|
package/lib/mobile/channels.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 新模型按公开资料补齐能力,已有模型保留原配置。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -18,6 +19,7 @@ const { sendJson, readJsonBody } = require('../shared/http-util');
|
|
|
18
19
|
const { unwrap } = require('./envelope.js');
|
|
19
20
|
const { dropSessionModelsForDevice } = require('./session-cache.js');
|
|
20
21
|
const { unchangedListBody, revisionOf, stableRevision } = require('../shared/list-revision.js');
|
|
22
|
+
const { lookupModelMeta } = require('./model-meta.js');
|
|
21
23
|
|
|
22
24
|
/** 自建渠道写在这个命名空间里;桌面端 `src/custom-channels.js` 的 PI_AI_NS 同值。 */
|
|
23
25
|
const PI_AI_NS = 'llm-pi-ai';
|
|
@@ -127,12 +129,11 @@ function normalizeModels(raw) {
|
|
|
127
129
|
/**
|
|
128
130
|
* 一条渠道 → pi-ai 的 provider profile。
|
|
129
131
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
+
* 自建路由显式声明协议。新模型优先使用端点返回的容量,其次用公开资料补齐能力,
|
|
133
|
+
* 没有公开资料时才使用通用缺省。
|
|
132
134
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* 模型用表单值或缺省,不认识的字段原样带回去。
|
|
135
|
+
* 编辑已有模型时完整保留原条目,获取模型带回的参数也不会覆盖已有能力与扩展字段。
|
|
136
|
+
* 进一步修改模型能力走独立的模型配置弹窗。
|
|
136
137
|
*/
|
|
137
138
|
function profileOf(channel, existing) {
|
|
138
139
|
const previous = new Map();
|
|
@@ -148,28 +149,24 @@ function profileOf(channel, existing) {
|
|
|
148
149
|
apiKeyEnv: credentialRefOf(channel.id),
|
|
149
150
|
models: channel.models.map((model) => {
|
|
150
151
|
const before = previous.get(model.id);
|
|
152
|
+
// 获取模型带回的参数也不能改掉用户已配好的能力,已有条目整体沿用。
|
|
153
|
+
if (before) return { ...before, name: before.name || model.name };
|
|
154
|
+
const meta = lookupModelMeta(model.id);
|
|
151
155
|
const contextWindow = Number(model.contextWindow) > 0
|
|
152
156
|
? Math.trunc(model.contextWindow)
|
|
153
|
-
: (
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
: (Number(before && before.maxTokens) > 0 ? Math.trunc(before.maxTokens) : DEFAULT_MAX_TOKENS);
|
|
157
|
+
: (meta?.contextWindow ?? DEFAULT_CONTEXT_WINDOW);
|
|
158
|
+
const outputFallback = meta?.maxTokens ?? Math.min(DEFAULT_MAX_TOKENS, Math.max(1, contextWindow - 1));
|
|
159
|
+
const maxTokens = Number(model.maxTokens) > 0 ? Math.trunc(model.maxTokens) : outputFallback;
|
|
157
160
|
return {
|
|
158
161
|
id: model.id,
|
|
159
|
-
|
|
160
|
-
// 别因为一次「只改了地址」把桌面那边起好的名字冲成 id。
|
|
161
|
-
name: model.name && model.name !== model.id
|
|
162
|
-
? model.name
|
|
163
|
-
: (before && typeof before.name === 'string' && before.name.trim() ? before.name : model.name),
|
|
162
|
+
name: model.name,
|
|
164
163
|
contextWindow,
|
|
165
164
|
maxTokens,
|
|
166
|
-
input: model.vision === true
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
? before.reasoningEfforts
|
|
172
|
-
: Object.fromEntries(DEFAULT_REASONING.map((level) => [level, level])),
|
|
165
|
+
input: model.vision === true || meta?.vision ? ['text', 'image'] : ['text'],
|
|
166
|
+
// false 表示明确不思考;资料没有档位时才沿用通用缺省。
|
|
167
|
+
reasoningEfforts: meta?.reasoning?.length === 0
|
|
168
|
+
? false
|
|
169
|
+
: Object.fromEntries((meta?.reasoning ?? DEFAULT_REASONING).map((level) => [level, meta?.reasoningWires?.[level] ?? level])),
|
|
173
170
|
};
|
|
174
171
|
}),
|
|
175
172
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 文件浏览保留真实目录路径,仅把全空白输入视为缺省目录。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -82,7 +83,8 @@ async function listingRow(directory, name) {
|
|
|
82
83
|
*/
|
|
83
84
|
async function handleDirectoryListing(_ctx, req, res) {
|
|
84
85
|
const url = new URL(req.url, 'http://x');
|
|
85
|
-
const
|
|
86
|
+
const rawPath = url.searchParams.get('path') || '';
|
|
87
|
+
const asked = rawPath.trim() ? rawPath : '';
|
|
86
88
|
if (asked && !fullyQualified(asked)) {
|
|
87
89
|
return fail(res, 'bad-request', `cannot list "${asked}": not a fully qualified path`);
|
|
88
90
|
}
|
package/lib/mobile/events.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* 设备流响应声明心跳周期,供客户端检测首帧缺失。
|
|
2
3
|
* 设备级事件流(GET /api/mobile/v1/events/stream):手机上侧栏那条 SSE。
|
|
3
4
|
*
|
|
4
5
|
* 它只是「有东西变了」的信号,绝不是数据源,所以每条宿主帧都削到只剩「列表需要重拉」的
|
|
@@ -126,6 +127,7 @@ async function handleDeviceStream(ctx, req, res) {
|
|
|
126
127
|
try {
|
|
127
128
|
res.writeHead(200, {
|
|
128
129
|
'content-type': 'text/event-stream; charset=utf-8',
|
|
130
|
+
'x-dsh-heartbeat-ms': String(HEARTBEAT_MS),
|
|
129
131
|
'cache-control': 'no-cache',
|
|
130
132
|
connection: 'keep-alive',
|
|
131
133
|
...(sealFrame ? { 'x-dsh-proto': '2' } : {}),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 本地目录浏览与宿主网关一致,保留路径中的首尾空格。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -232,7 +233,7 @@ async function subagentInterrupt(ctx, payload, signal) {
|
|
|
232
233
|
* `formatDirectoryError` 已经按它们写好了文案,两条路对客户端应当不可区分。
|
|
233
234
|
*/
|
|
234
235
|
async function localListDirectory(ctx, payload, signal) {
|
|
235
|
-
const path = payload && typeof payload.path === 'string' && payload.path.trim() ? payload.path
|
|
236
|
+
const path = payload && typeof payload.path === 'string' && payload.path.trim() ? payload.path : undefined;
|
|
236
237
|
try {
|
|
237
238
|
return ok(await listDirectory(path, { signal }));
|
|
238
239
|
} catch (error) {
|