dsh-mobile-plugin 0.5.64 → 0.5.66
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/lib/client.js +457 -86
- package/lib/frpc/provision.cjs +384 -0
- package/lib/frpc/runner.cjs +235 -0
- package/lib/impl.js +36 -0
- package/lib/mobile/host-bridge/session-model.js +7 -2
- package/lib/mobile/pairing.js +7 -0
- package/lib/mobile/relay-control.js +11 -0
- package/lib/panel/index.html +11 -11
- package/lib/relay/control.js +260 -0
- package/lib/relay/core.js +13 -1
- package/lib/relay/lan-network.cjs +26 -0
- package/lib/relay/pairing-payload.cjs +8 -0
- package/lib/relay/status.js +3 -0
- package/lib/routes/control-plane.js +60 -1
- package/lib/routes/mobile-api.js +11 -2
- package/package.json +1 -1
package/lib/impl.js
CHANGED
|
@@ -34,9 +34,13 @@ const { randomBytes } = require('node:crypto')
|
|
|
34
34
|
const { lanUrls, advertisedCandidates, phoneCandidates, ipv6Candidates, withManualIpv6Candidate } = require('./relay/lan-network.cjs')
|
|
35
35
|
// 配对二维码的载荷:面板与终端命令共用一份,拼装在 `./relay/pairing-payload.cjs`。
|
|
36
36
|
const { pairingPayload, pairingText } = require('./relay/pairing-payload.cjs')
|
|
37
|
+
// 总控上报客户端:把本机全部连接地址报给总控、拿回设备令牌(见 lib/relay/control.js)。
|
|
38
|
+
const { createControlClient } = require('./relay/control.js')
|
|
37
39
|
const { createLanPortPolicy } = require('./relay/lan-port-policy.cjs')
|
|
38
40
|
const { mountTailcat } = require('./tailcat/wiring.cjs') // 直连隧道:入口 + 落点代理 + 助手会话 + 启停
|
|
39
41
|
const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会话 + 落点代理(连接从隧道里进来,不必开回环门)
|
|
42
|
+
// FRP 直连:用面板导入的配置拉起本地 frpc(见 lib/frpc/runner.cjs)。
|
|
43
|
+
const { createFrpcRunner } = require('./frpc/runner.cjs')
|
|
40
44
|
const { createPreviewService } = require('./relay/preview.js')
|
|
41
45
|
const { mountRemoteComputers } = require('./remote/runtime.cjs')
|
|
42
46
|
// 手机打开「电脑上的网页版」时用的那枚一次性登录令牌(见 mobile/host-web.js)。
|
|
@@ -129,6 +133,9 @@ export const RemoteControlSettingsSchema = z.object({
|
|
|
129
133
|
// 用户手填的 IPv6 直连地址(`manualIpv6Url`,形如 `http://[240e::1]:18787`):与上一条并列,
|
|
130
134
|
// 只是拨的是 IPv6;网卡扫不到的那条固定地址靠它兜底,候选口径见 lan-network.cjs。
|
|
131
135
|
manualIpv6Url: z.string().max(200).default(''),
|
|
136
|
+
// 用户手填的「TCP 直连」目标(`manualTcpUrl`,形如 `主机:端口` / `http://主机:端口`,IPv6 方括号)。
|
|
137
|
+
// 与上面两条并列、同样不进 sidecar;它只决定手机用裸 TCP 拨哪个目标(详见 lan-network.cjs)。
|
|
138
|
+
manualTcpUrl: z.string().max(200).default(''),
|
|
132
139
|
})
|
|
133
140
|
|
|
134
141
|
|
|
@@ -154,6 +161,7 @@ function configOf(state) {
|
|
|
154
161
|
preferredLanAddress: typeof state.preferredLanAddress === 'string' ? state.preferredLanAddress : '',
|
|
155
162
|
manualLanUrl: typeof state.manualLanUrl === 'string' ? state.manualLanUrl : '',
|
|
156
163
|
manualIpv6Url: typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : '',
|
|
164
|
+
manualTcpUrl: typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : '',
|
|
157
165
|
}
|
|
158
166
|
}
|
|
159
167
|
|
|
@@ -320,6 +328,14 @@ function apply(ctx) {
|
|
|
320
328
|
const lanPortInUse = lanPorts.port
|
|
321
329
|
const resolveLanPort = lanPorts.resolve
|
|
322
330
|
const advertisedLanPort = () => (state.lanEnabled ? sidecarLifecycle.getAdvertisedLanPort() : state.lanPort)
|
|
331
|
+
// 总控上报客户端:把本机全部地址报给总控,拿回设备令牌交给 APP(见 relay/control.js)。
|
|
332
|
+
// 生命周期挂在下面的 effect 上;配置变更由 applyServices → control.sync() 驱动。
|
|
333
|
+
const control = createControlClient({
|
|
334
|
+
state,
|
|
335
|
+
persist: () => core.saveState(state),
|
|
336
|
+
getPort: advertisedLanPort,
|
|
337
|
+
getHistoryKey: () => core.ensureHistoryKey(state),
|
|
338
|
+
})
|
|
323
339
|
const tailcat = mountTailcat({ mount, warn, state, saveState: core.saveState, lanEnabled: () => state.lanEnabled, lanPort: lanPortInUse, webPort: () => ctx.webServer.port, hostName: () => state.name, ctx, name })
|
|
324
340
|
const p2p = mountP2P({ mount, warn, state, saveState: core.saveState, localPort: lanPortInUse, lanEnabled: () => state.lanEnabled, lanPort: lanPortInUse, webPort: () => ctx.webServer.port, ctx, name })
|
|
325
341
|
|
|
@@ -352,6 +368,11 @@ function apply(ctx) {
|
|
|
352
368
|
sidecarLifecycle.onRouteAdopted(createRouteAdopter({ state, settings, warn }))
|
|
353
369
|
|
|
354
370
|
mount('sidecar', () => ctx.effect(() => sidecarLifecycle.start(), `${name}: facade sidecar`))
|
|
371
|
+
// 总控上报:启用时连上去报地址,停用时断开。与 sidecar 各自独立,报的是本机地址不是隧道。
|
|
372
|
+
mount('总控上报', () => ctx.effect(() => {
|
|
373
|
+
control.start()
|
|
374
|
+
return () => control.stop()
|
|
375
|
+
}, `${name}: control client`))
|
|
355
376
|
mount('镜像推送', () => ctx.effect(() => mirror.start(), `${name}: mobile mirror sync`))
|
|
356
377
|
|
|
357
378
|
ctx.effect(() => {
|
|
@@ -394,8 +415,11 @@ function apply(ctx) {
|
|
|
394
415
|
getTailcat: () => (tailcat ? tailcat.status() : null),
|
|
395
416
|
// 点对点隧道那一格:手机轮询 `/status` 时据此把这条通道也算进来。
|
|
396
417
|
getP2P: () => (p2p ? p2p.status() : null),
|
|
418
|
+
// 总控上报当前状态(地址、令牌、连没连上):手机据此知道该不该、能不能去总控查。
|
|
419
|
+
getControl: () => control.snapshot(),
|
|
397
420
|
})
|
|
398
421
|
function applyServices() {
|
|
422
|
+
control.sync()
|
|
399
423
|
void syncSidecar().catch(() => undefined)
|
|
400
424
|
}
|
|
401
425
|
/**
|
|
@@ -415,6 +439,14 @@ function apply(ctx) {
|
|
|
415
439
|
mountRoute(route)
|
|
416
440
|
}
|
|
417
441
|
|
|
442
|
+
// FRP 直连:用导入的配置拉起本地 frpc。端口每次启动都按插件的实绑端口对齐;宿主重启时
|
|
443
|
+
// 若上次是启用状态就自动再拉起,插件卸载/重载时收掉进程。
|
|
444
|
+
const frpRunner = createFrpcRunner({ portOf: advertisedLanPort })
|
|
445
|
+
mount('frpc 直连进程', () => ctx.effect(() => {
|
|
446
|
+
if (frpRunner.shouldAutoStart()) void frpRunner.start()
|
|
447
|
+
return () => { void frpRunner.dispose() }
|
|
448
|
+
}, `${name}: frpc runner`))
|
|
449
|
+
|
|
418
450
|
mount('控制面路由', () => registerControlPlaneRoutes({
|
|
419
451
|
registerRoute,
|
|
420
452
|
// 更新的机制住在外壳(`lib/index.js`)里,代这边只把它开成本机接口。取不到就如实报
|
|
@@ -443,6 +475,8 @@ function apply(ctx) {
|
|
|
443
475
|
tailcat,
|
|
444
476
|
// 点对点隧道:二维码要多带一段「电脑的公钥与打洞候选」,配对后两端各持一半。
|
|
445
477
|
p2p,
|
|
478
|
+
// FRP 直连:导入配置后的启停与运行状态(见 lib/frpc/runner.cjs)。
|
|
479
|
+
frp: frpRunner,
|
|
446
480
|
restartSidecar,
|
|
447
481
|
// 「手机上最近来过没有」——控制面状态里补给面板用(见 ./mobile/activity.cjs)。
|
|
448
482
|
mobileActivity: activity.snapshot,
|
|
@@ -530,6 +564,8 @@ function apply(ctx) {
|
|
|
530
564
|
hostWeb: hostWeb.handleHostWeb,
|
|
531
565
|
guarded,
|
|
532
566
|
state,
|
|
567
|
+
// 总控上报状态取值器:`/api/mobile/v1/status` 把它挂在心跳上,APP 据此拿令牌去查地址。
|
|
568
|
+
getControl: () => control.snapshot(),
|
|
533
569
|
hostMetadata,
|
|
534
570
|
// iOS 推送令牌上报(/push-token)的登记 / 删除出口;不传时路由只回 ok。
|
|
535
571
|
pushNotify,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** 手机模型选择等待宿主服务就绪,只写当前会话;缺能力时区分「宿主太老」与「这条会话没有可切模型」。 */
|
|
2
2
|
'use strict';
|
|
3
3
|
const { ok, fail, unsupported } = require('./transport.js');
|
|
4
4
|
|
|
@@ -21,7 +21,12 @@ async function selectSessionModel(ctx, payload) {
|
|
|
21
21
|
const resolved = await controller.resolveAgent(payload.sessionId);
|
|
22
22
|
if (resolved.error) return fail(resolved.error);
|
|
23
23
|
const agent = resolved.agent;
|
|
24
|
-
|
|
24
|
+
// 会话恢复出来了,但这类会话本身没有可切换的模型(特殊会话/子代理):问题在会话,不在版本。
|
|
25
|
+
if (!agent || !agent.model) {
|
|
26
|
+
return fail({ code: 'host-unsupported', message: '这条会话当前没有可切换的模型' });
|
|
27
|
+
}
|
|
28
|
+
// 会话有模型对象却没有 select:是宿主 Agent.model 能力缺失,确实要更新宿主。
|
|
29
|
+
if (typeof agent.model.select !== 'function') {
|
|
25
30
|
return unsupported('仅切换当前会话模型的能力');
|
|
26
31
|
}
|
|
27
32
|
const selected = { provider: payload.provider, model: payload.model,
|
package/lib/mobile/pairing.js
CHANGED
|
@@ -26,6 +26,7 @@ const { openSealedPairRequest, sealPairResponse } = require('../shared/e2ee-pair
|
|
|
26
26
|
// 档位 → 权限位(唯一真源)。配对时电脑侧选定的档位落在 state.pairingTier,这里展开成数组
|
|
27
27
|
// 交给凭据库;缺省 full = 与今天单 token 全给一字不差。
|
|
28
28
|
const permissions = require('./permissions.js');
|
|
29
|
+
const { tcpDirectTarget } = require('../relay/lan-network.cjs');
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* 一条入口一份闸门(见 `shared/pair-throttle.js` 头部的取舍说明)。
|
|
@@ -330,6 +331,12 @@ function createPairHandler(deps) {
|
|
|
330
331
|
...(hostPlatform ? { hostPlatform } : {}),
|
|
331
332
|
...(directCandidates.length ? { lanUrls: directCandidates } : {}),
|
|
332
333
|
...(v6Candidates.length ? { ipv6Candidates: v6Candidates } : {}),
|
|
334
|
+
// 「TCP 直连」那一条:用户配的直连地址里能当裸 TCP 目标的,只此一条(手输配对时手机
|
|
335
|
+
// 没有二维码,这是它拿到这条 TCP 地址的唯一机会)。
|
|
336
|
+
...(() => {
|
|
337
|
+
const tcpUrl = tcpDirectTarget(state.manualTcpUrl);
|
|
338
|
+
return tcpUrl ? { tcpUrl } : {};
|
|
339
|
+
})(),
|
|
333
340
|
};
|
|
334
341
|
|
|
335
342
|
// 新协议的回包必须加密:里面有 token / cookie / deviceCredential,明文回包等于让
|
|
@@ -70,6 +70,7 @@ function configView(state) {
|
|
|
70
70
|
preferredLanAddress: typeof state.preferredLanAddress === 'string' ? state.preferredLanAddress : '',
|
|
71
71
|
manualLanUrl: typeof state.manualLanUrl === 'string' ? state.manualLanUrl : '',
|
|
72
72
|
manualIpv6Url: typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : '',
|
|
73
|
+
manualTcpUrl: typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : '',
|
|
73
74
|
/** 注册密钥设没设(值本身不回)。 */
|
|
74
75
|
registerSecretSet: typeof state.registerSecret === 'string' && state.registerSecret !== '',
|
|
75
76
|
};
|
|
@@ -154,6 +155,14 @@ function configPatch(body) {
|
|
|
154
155
|
}
|
|
155
156
|
patch.manualIpv6Url = body.manualIpv6Url.trim().replace(/\/+$/, '');
|
|
156
157
|
}
|
|
158
|
+
// 用户手填的「TCP 直连」目标:空串合法(= 清掉)。格式由 `relay/lan-network.cjs` 的
|
|
159
|
+
// `tcpDirectTarget` 在产二维码 / 连接信息那一步判,这里只挡类型与长度。
|
|
160
|
+
if (body.manualTcpUrl !== undefined) {
|
|
161
|
+
if (typeof body.manualTcpUrl !== 'string' || body.manualTcpUrl.length > 200) {
|
|
162
|
+
return { ok: false, message: 'TCP 直连目标必须是 200 字以内的字符串(空串表示清掉)' };
|
|
163
|
+
}
|
|
164
|
+
patch.manualTcpUrl = body.manualTcpUrl.trim();
|
|
165
|
+
}
|
|
157
166
|
if (Object.keys(patch).length === 0) return { ok: false, message: '没有任何可改的字段' };
|
|
158
167
|
return { ok: true, patch };
|
|
159
168
|
}
|
|
@@ -269,6 +278,8 @@ function createRelayControlHandlers(deps) {
|
|
|
269
278
|
manual: typeof state.manualLanUrl === 'string' ? state.manualLanUrl : '',
|
|
270
279
|
/** 用户手填的那条 IPv6 直连地址(空串 = 没填),与 `manual` 并列。 */
|
|
271
280
|
manualIpv6: typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : '',
|
|
281
|
+
/** 用户手填的「TCP 直连」目标(空串 = 没填),与上面两条并列。 */
|
|
282
|
+
manualTcp: typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : '',
|
|
272
283
|
};
|
|
273
284
|
}
|
|
274
285
|
|