dsh-mobile-plugin 0.5.81 → 0.5.83
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 +4 -0
- package/dsh-mobile-credentials/lib/credentials.js +5 -0
- package/lib/client.js +171 -5
- package/lib/frpc/provision.cjs +21 -17
- package/lib/frpc/runner.cjs +231 -168
- package/lib/impl.js +77 -107
- package/lib/index.js +1 -1
- package/lib/mirror/pusher.cjs +60 -10
- package/lib/mobile/approval-memory.js +2 -55
- package/lib/mobile/approvals.js +6 -82
- package/lib/mobile/events.js +2 -1
- package/lib/mobile/feedback.js +6 -5
- package/lib/mobile/file-read.js +4 -2
- package/lib/mobile/host-bridge.js +12 -1
- package/lib/mobile/mux.js +148 -21
- package/lib/mobile/paired-devices.js +2 -1
- package/lib/mobile/pairing.js +8 -7
- package/lib/mobile/relay-control.js +33 -38
- package/lib/mobile/session-changes.js +8 -2
- package/lib/mobile/session-delivery.js +5 -1
- package/lib/mobile/session-file.js +46 -25
- package/lib/mobile/session-head.js +7 -3
- package/lib/mobile/session-snapshot.js +5 -1
- package/lib/mobile/session-step.js +13 -7
- package/lib/mobile/session-stop-summary.js +6 -1
- package/lib/mobile/stream-registry.js +48 -53
- package/lib/mobile/stream.js +17 -2
- package/lib/mobile/uploads.js +190 -163
- package/lib/p2p/session.cjs +169 -70
- package/lib/p2p/wiring.cjs +4 -2
- package/lib/panel/index.html +44 -24
- package/lib/relay/blob-upload.cjs +103 -0
- package/lib/relay/config-store.js +79 -0
- package/lib/relay/control.js +131 -52
- package/lib/relay/core.js +55 -17
- package/lib/relay/lan-discovery.cjs +22 -14
- package/lib/relay/lan-port-policy.cjs +8 -2
- package/lib/relay/lan-proxy.js +47 -12
- package/lib/relay/pairing-payload.cjs +14 -5
- package/lib/relay/preview-webapp.cjs +150 -0
- package/lib/relay/preview.js +35 -8
- package/lib/relay/protocol.js +6 -4
- package/lib/relay/relay-probe.js +112 -21
- package/lib/relay/status.js +4 -7
- package/lib/relay/tunnel-forwarder.cjs +4 -2
- package/lib/relay/tunnel.js +39 -8
- package/lib/remote/controller.cjs +33 -3
- package/lib/remote/host-control.cjs +11 -2
- package/lib/remote/router.cjs +83 -33
- package/lib/remote/transport.cjs +32 -5
- package/lib/remote/tunnel-helper.cjs +51 -25
- package/lib/remote/tunnels.cjs +27 -3
- package/lib/routes/control-plane.js +41 -53
- package/lib/routes/mobile-api.js +21 -31
- package/lib/shared/fresh-request.js +32 -1
- package/lib/shared/route-order.cjs +118 -132
- package/lib/shared/sse-write.js +29 -10
- package/lib/shared/via-header.js +5 -12
- package/lib/shell/transport-host.js +9 -1
- package/lib/shell/updater.js +18 -6
- package/lib/sidecar-facade-worker.cjs +165 -118
- package/lib/sidecar-facade.cjs +6 -1
- package/lib/sidecar-lifecycle.cjs +6 -2
- package/lib/tailcat/host-process.cjs +32 -8
- package/lib/tailcat/session.cjs +27 -10
- package/package.json +6 -6
- package/lib/mobile/auto-review.js +0 -178
package/lib/impl.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 每代兼容桥使用独立服务作用域,热重载时新旧两代可同时提供宿主调用。
|
|
2
|
+
// 真实监听状态同步总控和穿透,固定入口约束自动换号。
|
|
3
|
+
// 配置 schema 与投影拆到 lib/relay/config-store.js,装配层只留装配与状态仓外壳(行数兜底)。
|
|
4
|
+
// 装配移动 API、设备吊销与独立直连生命周期,并向本机面板提供真实上报目的地。
|
|
2
5
|
/**
|
|
3
6
|
* 插件实现(随包发布的基础代):装配路由、移动端 API 网关与 sidecar 生命周期。
|
|
4
7
|
* 只做装配——镜像推送在 `lib/mirror/pusher.cjs`、sidecar 生命周期在
|
|
@@ -11,10 +14,10 @@ import { createRequire } from 'node:module'
|
|
|
11
14
|
import os from 'node:os'
|
|
12
15
|
import path from 'node:path'
|
|
13
16
|
import { fileURLToPath } from 'node:url'
|
|
14
|
-
import z from '@deepseek-ai/schemastery'
|
|
15
17
|
|
|
16
18
|
const require = createRequire(import.meta.url)
|
|
17
19
|
const core = require('./relay/core.js')
|
|
20
|
+
const { RemoteControlSettingsSchema, configOf } = require('./relay/config-store.js')
|
|
18
21
|
const pairingApproval = require('./relay/pairing-policy.js')
|
|
19
22
|
const { sendJson, sendHtml, htmlEtag } = require('./shared/http-util.js')
|
|
20
23
|
// 控制面守卫(localOnly)与移动端守卫(guarded)都住在这里;两套守卫并排放,
|
|
@@ -38,7 +41,7 @@ const { pairingPayload, pairingText } = require('./relay/pairing-payload.cjs')
|
|
|
38
41
|
// 总控上报客户端:把本机全部连接地址报给总控、拿回设备令牌(见 lib/relay/control.js)。
|
|
39
42
|
const { createControlClient } = require('./relay/control.js')
|
|
40
43
|
const { createIdentityRotator } = require('./relay/identity-rotate.cjs')
|
|
41
|
-
const { createLanPortPolicy } = require('./relay/lan-port-policy.cjs')
|
|
44
|
+
const { createLanPortPolicy, lanPortLockReason } = require('./relay/lan-port-policy.cjs')
|
|
42
45
|
const { mountTailcat } = require('./tailcat/wiring.cjs') // 直连隧道:入口 + 落点代理 + 助手会话 + 启停
|
|
43
46
|
const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会话 + 落点代理(连接从隧道里进来,不必开回环门)
|
|
44
47
|
// FRP 直连:用面板导入的配置拉起本地 frpc(见 lib/frpc/runner.cjs)。
|
|
@@ -52,8 +55,8 @@ const hostWeb = require('./mobile/host-web.js')
|
|
|
52
55
|
// 否则「撤销全部授权」只清了中转侧,同网设备仍能用旧凭据直连宿主。
|
|
53
56
|
// 入口按两条盘上布局分别找(嵌在插件包内 / 与插件包同级),见 shared/credentials-entry.js。
|
|
54
57
|
const credentials = require('./shared/credentials-entry.js').credentialsEntry()
|
|
55
|
-
const { createApiProxy } = require('./mobile/host-bridge.js')
|
|
56
|
-
const { installApprovalBridge, setPushNotifier: setApprovalPushNotifier
|
|
58
|
+
const { createApiProxy, runtimeProvidesApiProxy } = require('./mobile/host-bridge.js')
|
|
59
|
+
const { installApprovalBridge, setPushNotifier: setApprovalPushNotifier } = require('./mobile/approvals.js')
|
|
57
60
|
const { installQuestionBridge, setPushNotifier: setQuestionPushNotifier } = require('./mobile/questions.js')
|
|
58
61
|
const { createPushNotifier } = require('./mobile/push-notify.js')
|
|
59
62
|
const { installNarration } = require('./mobile/narration.js') // 过程播报:默认关,开关真值每步现读
|
|
@@ -110,77 +113,7 @@ export const inject = ['webServer']
|
|
|
110
113
|
const API_PROXY_GRACE_MS = 3000
|
|
111
114
|
|
|
112
115
|
export const REMOTE_CONTROL_SETTINGS_NAMESPACE = 'mobile-remote-control'
|
|
113
|
-
export
|
|
114
|
-
enabled: z.boolean().default(false),
|
|
115
|
-
relayUrl: z.string().default(''),
|
|
116
|
-
// 完整的中转地址列表,`relayUrls[0]` 恒等于 `relayUrl`(见 docs/relay-multi-address.md)。
|
|
117
|
-
// 这一轮**行为不变**:隧道仍然只按 `relayUrl` 连,列表只是「以后要有地方落」的形状。
|
|
118
|
-
relayUrls: z.array(z.string()).default([]),
|
|
119
|
-
lanEnabled: z.boolean().default(true),
|
|
120
|
-
lanPort: z.number().step(1).min(1024).max(65535).default(18787),
|
|
121
|
-
name: z.string().default(''),
|
|
122
|
-
// Pairing approval policy; see lib/relay/pairing-policy.js for the two modes and
|
|
123
|
-
// why 'code' is not the old popup. Kept in the config schema so /api/relay/config
|
|
124
|
-
// can change it, and so an unknown value is rejected on write.
|
|
125
|
-
pairingPolicy: z.union(pairingApproval.POLICIES.map(value => z.const(value))).default(pairingApproval.DEFAULT_POLICY),
|
|
126
|
-
// 新配对设备的权限档位(只读 / 可答审批 / 全权)。配对时在电脑侧选定,展开成 permissions
|
|
127
|
-
// 写进凭据记录(见 lib/mobile/permissions.js)。缺省 full = 与今天单 token 全给等价。
|
|
128
|
-
pairingTier: z.union(permissions.TIER_NAMES.map(t => z.const(t))).default(permissions.DEFAULT_TIER), approvalAutoReview: z.boolean().default(false), // 审批自动审阅档(默认关,见 mobile/auto-review.js)
|
|
129
|
-
// 是否把本机网络地址加密上报给「总控」(地址目录)。默认开 = 与历史行为一致;
|
|
130
|
-
// 关掉后宿主不再跑总控上报客户端,手机换网后拿不到这台电脑的新地址(见 relay/control.js)。
|
|
131
|
-
controlReportEnabled: z.boolean().default(true),
|
|
132
|
-
// 桌面设置页那两颗侧边栏图标(手机 / 电脑)的可见性。默认全开;老 relay.json 没这两格时
|
|
133
|
-
// 由 configOf 收成 true,界面不会在升级后突然少一颗。只给桌面控制面写,手机端配置口不收。
|
|
134
|
-
desktopPhoneIcon: z.boolean().default(true),
|
|
135
|
-
desktopComputerIcon: z.boolean().default(true),
|
|
136
|
-
// 中转注册密钥(对偶于中转的 TUNNEL_REGISTER_SECRET)。桌面版拿不到 shell
|
|
137
|
-
// 环境变量,所以它和其他配置一样存在 relay.json(0600),由 /api/relay/config
|
|
138
|
-
// 在回环上写入;status / pairing / 二维码都不回显它。
|
|
139
|
-
registerSecret: z.string().max(512).default(''),
|
|
140
|
-
// 手机优先用哪条地址:空 = 不指定(按宿主网卡优先级排)。选择只挪候选顺序、不删候选,
|
|
141
|
-
// 理由与边界见 relay/lan-network.cjs 的 orderCandidates 与 relay.json 那条地图条目。
|
|
142
|
-
preferredLanAddress: z.string().max(64).default(''),
|
|
143
|
-
// 用户手填的直连地址(`manualLanUrl`,内网穿透域名)也随二维码一起走,见 lan-network.cjs。
|
|
144
|
-
manualLanUrl: z.string().max(200).default(''),
|
|
145
|
-
// 用户手填的 IPv6 直连地址(`manualIpv6Url`,形如 `http://[240e::1]:18787`):与上一条并列,
|
|
146
|
-
// 只是拨的是 IPv6;网卡扫不到的那条固定地址靠它兜底,候选口径见 lan-network.cjs。
|
|
147
|
-
manualIpv6Url: z.string().max(200).default(''),
|
|
148
|
-
// 用户手填的「TCP 直连」目标(`manualTcpUrl`,形如 `主机:端口` / `http://主机:端口`,IPv6 方括号)。
|
|
149
|
-
// 与上面两条并列、同样不进 sidecar;它只决定手机用裸 TCP 拨哪个目标(详见 lan-network.cjs)。
|
|
150
|
-
manualTcpUrl: z.string().max(200).default(''),
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
function configOf(state) {
|
|
155
|
-
// 两格必须一起算:`relayUrls` 是完整列表、`relayUrl` 是它的首项(契约见
|
|
156
|
-
// docs/relay-multi-address.md),任何一处只写一个都会让读的一方看到矛盾的两份值。
|
|
157
|
-
const relay = core.relayAddressesOf(state)
|
|
158
|
-
return {
|
|
159
|
-
enabled: Boolean(state.enabled),
|
|
160
|
-
relayUrl: relay.relayUrl,
|
|
161
|
-
relayUrls: relay.relayUrls,
|
|
162
|
-
lanEnabled: Boolean(state.lanEnabled),
|
|
163
|
-
lanPort: Number.isInteger(state.lanPort) ? state.lanPort : 18787,
|
|
164
|
-
name: typeof state.name === 'string' ? state.name : '',
|
|
165
|
-
// The schema rejects anything outside the enum, so in practice this only
|
|
166
|
-
// ever normalises a value written before pairingPolicy existed.
|
|
167
|
-
pairingPolicy: pairingApproval.normalize(state.pairingPolicy),
|
|
168
|
-
pairingTier: permissions.isKnownTier(state.pairingTier) ? state.pairingTier : permissions.DEFAULT_TIER, // 未知值收敛回 full
|
|
169
|
-
approvalAutoReview: state.approvalAutoReview === true, // 非 true 一律当关
|
|
170
|
-
// 只有明确写成 false 才算关;老状态文件没这一格时按开(与历史行为一致)。
|
|
171
|
-
controlReportEnabled: state.controlReportEnabled !== false,
|
|
172
|
-
// 没写过的老配置按显示处理:这两颗是入口,不因为升级就凭空消失。
|
|
173
|
-
desktopPhoneIcon: state.desktopPhoneIcon !== false,
|
|
174
|
-
desktopComputerIcon: state.desktopComputerIcon !== false,
|
|
175
|
-
// 密钥只往 sidecar 和状态文件走:status() / pairingPayload() 都单独取字段,
|
|
176
|
-
// 不会把它回显给手机、二维码或日志。
|
|
177
|
-
registerSecret: typeof state.registerSecret === 'string' ? state.registerSecret : '',
|
|
178
|
-
preferredLanAddress: typeof state.preferredLanAddress === 'string' ? state.preferredLanAddress : '',
|
|
179
|
-
manualLanUrl: typeof state.manualLanUrl === 'string' ? state.manualLanUrl : '',
|
|
180
|
-
manualIpv6Url: typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : '',
|
|
181
|
-
manualTcpUrl: typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : '',
|
|
182
|
-
}
|
|
183
|
-
}
|
|
116
|
+
export { RemoteControlSettingsSchema }
|
|
184
117
|
|
|
185
118
|
// 0.2.0 之前这份配置注册在宿主 settings 的 `mobile-remote-control` 命名空间里
|
|
186
119
|
// (`ctx.settings.register(ns, schema, { base: configOf(state), applies: 'live' })`),
|
|
@@ -233,6 +166,7 @@ function createConfigStore(state) {
|
|
|
233
166
|
// 函数),否则界面说停用了、实际还在连公用。放在收敛之后、落盘之前,保证
|
|
234
167
|
// relayUrls[0] === relayUrl 的不变式与「真停用」一起成立。
|
|
235
168
|
core.stripPublicRelay(parsed)
|
|
169
|
+
core.expandDefaultPublicRelays(parsed)
|
|
236
170
|
Object.assign(state, parsed)
|
|
237
171
|
core.saveState(state)
|
|
238
172
|
if (options.notify !== false) notify()
|
|
@@ -249,26 +183,9 @@ function createConfigStore(state) {
|
|
|
249
183
|
// 的 `advertisedCandidates`:那是地址策略,不是装配。这里只把它转交给三处消费点。
|
|
250
184
|
// 「手机上最近来过没有」同理,住在 `./mobile/activity.cjs`(守卫记、控制面状态读)。
|
|
251
185
|
|
|
252
|
-
/**
|
|
253
|
-
* 运行时是否自带 `@deepseek-ai/dsh-host-apiproxy`(`api-gateway` 那个入口)。
|
|
254
|
-
*
|
|
255
|
-
* 从本模块所在位置解析,而不是读 DSH 版本号:桌面端插件装在 profile 的 node_modules 里,
|
|
256
|
-
* 往上碰不到 DSH 的依赖树(在 app.asar 里),解析不到就用兼容桥;无头宿主跑在插件包里,
|
|
257
|
-
* 包内就有整套 `@deepseek-ai/*`,解析得到就用宿主自己那份。解析失败只是「没有」。
|
|
258
|
-
*
|
|
259
|
-
* 模块顶层就被 `export const inject` 用了一次,所以必须是函数声明(提升),不能写成 `const`
|
|
260
|
-
* 箭头函数 —— 那会撞上 TDZ。
|
|
261
|
-
*/
|
|
262
|
-
function runtimeProvidesApiProxy() {
|
|
263
|
-
try {
|
|
264
|
-
require.resolve('@deepseek-ai/dsh-host-apiproxy/package.json')
|
|
265
|
-
return true
|
|
266
|
-
} catch {
|
|
267
|
-
return false
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
186
|
function apply(ctx) {
|
|
187
|
+
const hostContext = ctx
|
|
188
|
+
ctx = ctx.isolate('apiProxy')
|
|
272
189
|
// 0.2.0 删掉了 `apiProxy` 服务(宿主 RPC 全走 ctx.get('typertGateway')),但插件里
|
|
273
190
|
// 17 个移动端模块历史上都是 `ctx.apiProxy.<ns>.<method>({rpcId,method,payload}, signal)`
|
|
274
191
|
// + `{result:{ok,value}|{ok:false,error}}` 这一套。这里在自己的 fiber 上把同形状的
|
|
@@ -314,7 +231,7 @@ function apply(ctx) {
|
|
|
314
231
|
*
|
|
315
232
|
* 三者都只在「宿主这一代没有真 apiProxy」时才装:旧宿主自带真服务,多 provide 一次会让
|
|
316
233
|
* 整棵树加载失败(`service "apiProxy" has been registered at <dsh-mobile-plugin>`)。
|
|
317
|
-
*
|
|
234
|
+
* 兼容服务只在本代作用域可见;蓝绿换代时旧代仍在服务,新代也能独立完成装配。
|
|
318
235
|
*/
|
|
319
236
|
const installCompatBridges = () => {
|
|
320
237
|
mount('apiProxy 兼容桥', () => ctx.reflect.provide('apiProxy', createApiProxy(ctx)))
|
|
@@ -328,7 +245,11 @@ function apply(ctx) {
|
|
|
328
245
|
// 前后就会挂上),到点还没有就当作新版宿主,自己把兼容桥与两条帧桥装上 —— 否则
|
|
329
246
|
// 十几个移动端模块读到的是一个永远不来的服务,手机侧全程静默失败。
|
|
330
247
|
const timer = setTimeout(() => {
|
|
331
|
-
|
|
248
|
+
const hostProxy = hostContext.get('apiProxy')
|
|
249
|
+
if (hostProxy) {
|
|
250
|
+
ctx.reflect.provide('apiProxy', hostProxy)
|
|
251
|
+
return
|
|
252
|
+
}
|
|
332
253
|
warn('等不到宿主的 apiProxy,按新版宿主装配兼容桥')
|
|
333
254
|
installCompatBridges()
|
|
334
255
|
}, API_PROXY_GRACE_MS)
|
|
@@ -358,7 +279,7 @@ function apply(ctx) {
|
|
|
358
279
|
// relay.json 是这个命名空间的种子。现在由 createConfigStore 直接以 relay.json
|
|
359
280
|
// 为准(见那里的说明与代价)。
|
|
360
281
|
const settings = createConfigStore(state)
|
|
361
|
-
Object.assign(state, settings.get())
|
|
282
|
+
Object.assign(state, settings.get())
|
|
362
283
|
// 实例历史密钥(HK)的取值器:缺失时惰性生成并落盘(relay.json 单一真源)。配对响应、
|
|
363
284
|
// `/api/mobile/v1/history-key` 与镜像推送三条路共用这一个入口。
|
|
364
285
|
const getHistoryKey = () => core.ensureHistoryKey(state)
|
|
@@ -367,7 +288,11 @@ function apply(ctx) {
|
|
|
367
288
|
const lanPorts = createLanPortPolicy({ state, saveState: core.saveState })
|
|
368
289
|
const lanPortInUse = lanPorts.port
|
|
369
290
|
const resolveLanPort = lanPorts.resolve
|
|
370
|
-
|
|
291
|
+
let syncNetwork = () => {}
|
|
292
|
+
let forwardingConfigured = () => false
|
|
293
|
+
const portLock = () => lanPortLockReason(state, forwardingConfigured())
|
|
294
|
+
const onLanState = lan => { lanPorts.apply(lan); syncNetwork() }
|
|
295
|
+
const advertisedLanPort = () => sidecarLifecycle.getAdvertisedLanPort()
|
|
371
296
|
// 总控上报客户端:把本机全部地址报给总控,拿回设备令牌交给 APP(见 relay/control.js)。
|
|
372
297
|
// 生命周期挂在下面的 effect 上;配置变更由 applyServices → control.sync() 驱动。
|
|
373
298
|
// 隧道状态取值器在下面 sidecar 装配完成后才拿到,这里先放占位,装配完换成权威那个。
|
|
@@ -391,14 +316,19 @@ function apply(ctx) {
|
|
|
391
316
|
// sidecar 子进程的全部生命周期:起停、配置下发、自重启、健康轮询。
|
|
392
317
|
// **传输进程归稳定外壳**:优先取外壳持有的那份(换代时它不重启,隧道跨代存活);外壳不在
|
|
393
318
|
// (实现被单独挂载 / 测试)时退回本地创建,行为与从前一致。配置由这一代组装后交给它。
|
|
394
|
-
|
|
319
|
+
// 父进程地址在这一代挂载时取一次缓存住。下发配置的闭包会被外壳持有的 sidecar 跨代调用,
|
|
320
|
+
// 那时本代 ctx 已 inactive,现读 ctx.webServer 会抛 "cannot get required service webServer
|
|
321
|
+
// in inactive context",导致重启与配置下发全失败(隧道、frpc、P2P 都起不来)。
|
|
322
|
+
const webPortForSidecar = ctx.webServer.port
|
|
323
|
+
const webHostForSidecar = ctx.webServer.host
|
|
324
|
+
const buildSidecarConfig = (lanPort) => ({ enabled: state.enabled, relayUrl: state.relayUrl, relayUrls: core.relayAddressesOf(state).relayUrls, instanceId: state.instanceId, previousInstanceId: state.previousInstanceId || '', pairingCode: state.pairingCode, pairingTicket: state.pairingTicket || '', pairingTier: permissions.isKnownTier(state.pairingTier) ? state.pairingTier : permissions.DEFAULT_TIER, name: state.name, upstreamPort: webPortForSidecar, upstreamHost: webHostForSidecar, lanPort, lanPortLockReason: portLock(), lanEnabled: effectiveLanEnabled(), lanSecret: state.lanSecret, registerSecret: state.registerSecret })
|
|
395
325
|
let hostedSidecar = null
|
|
396
326
|
try { hostedSidecar = typeof ctx.get === 'function' ? ctx.get('dshMobileSidecarHost') || null : null } catch { hostedSidecar = null }
|
|
397
327
|
const sidecarLifecycle = hostedSidecar || createSidecarLifecycle({
|
|
398
328
|
ctx,
|
|
399
329
|
lanPortInUse,
|
|
400
330
|
resolveLanPort,
|
|
401
|
-
onLanState
|
|
331
|
+
onLanState,
|
|
402
332
|
// 本代实现所在的 lib/。默认值能推对,但代际目录里那份推出来的是它自己,
|
|
403
333
|
// 显式传入能让「re-fork 前清的是不是正在跑的那份缓存」不依赖巧合。
|
|
404
334
|
pluginLibDir: path.dirname(fileURLToPath(import.meta.url)),
|
|
@@ -417,7 +347,7 @@ function apply(ctx) {
|
|
|
417
347
|
buildConfig: buildSidecarConfig,
|
|
418
348
|
lanPortInUse,
|
|
419
349
|
resolveLanPort,
|
|
420
|
-
onLanState
|
|
350
|
+
onLanState,
|
|
421
351
|
pluginLibDir: path.dirname(fileURLToPath(import.meta.url)),
|
|
422
352
|
})
|
|
423
353
|
}
|
|
@@ -437,6 +367,8 @@ function apply(ctx) {
|
|
|
437
367
|
getPort: advertisedLanPort,
|
|
438
368
|
getHistoryKey: () => core.ensureHistoryKey(state),
|
|
439
369
|
getRelayConnected: () => relayConnectedOf(),
|
|
370
|
+
getConnectedRelay: () => { const tunnel = sidecarLifecycle.getSnapshot()?.tunnel; return tunnel?.state === 'connected' ? tunnel.relayUrl || tunnel.route?.url || '' : '' },
|
|
371
|
+
log: warn,
|
|
440
372
|
onIdentityConflict: rotateNow,
|
|
441
373
|
})
|
|
442
374
|
if (controlHost && controlHost.client && typeof controlHost.setProviders === 'function') {
|
|
@@ -446,6 +378,7 @@ function apply(ctx) {
|
|
|
446
378
|
getPort: advertisedLanPort,
|
|
447
379
|
getHistoryKey: () => core.ensureHistoryKey(state),
|
|
448
380
|
getRelayConnected: () => relayConnectedOf(),
|
|
381
|
+
getConnectedRelay: () => { const tunnel = sidecarLifecycle.getSnapshot()?.tunnel; return tunnel?.state === 'connected' ? tunnel.relayUrl || tunnel.route?.url || '' : '' },
|
|
449
382
|
onIdentityConflict: rotateNow,
|
|
450
383
|
})
|
|
451
384
|
}
|
|
@@ -540,6 +473,7 @@ function apply(ctx) {
|
|
|
540
473
|
getP2P: () => (p2p ? p2p.status() : null),
|
|
541
474
|
// 总控上报当前状态(地址、令牌、连没连上):手机据此知道该不该、能不能去总控查。
|
|
542
475
|
getControl: () => control.snapshot(),
|
|
476
|
+
getLanPortLock: portLock,
|
|
543
477
|
})
|
|
544
478
|
function applyServices() {
|
|
545
479
|
control.sync()
|
|
@@ -568,7 +502,18 @@ function apply(ctx) {
|
|
|
568
502
|
let frpHost = null
|
|
569
503
|
try { frpHost = typeof ctx.get === 'function' ? ctx.get('dshMobileTransportFrp') || null : null } catch { frpHost = null }
|
|
570
504
|
const frpRunner = frpHost && frpHost.runner ? frpHost.runner : createFrpcRunner({ portOf: advertisedLanPort })
|
|
505
|
+
forwardingConfigured = () => frpRunner.shouldAutoStart()
|
|
506
|
+
syncNetwork = () => { control.sync(); void frpRunner.syncLocalPort?.().catch(warn) }
|
|
507
|
+
syncNetwork()
|
|
571
508
|
if (frpHost && typeof frpHost.setPortProvider === 'function') frpHost.setPortProvider(advertisedLanPort)
|
|
509
|
+
mount('frpc 公网地址', () => ctx.effect(() => {
|
|
510
|
+
if (typeof frpRunner.setAddressListener !== 'function') return () => {}
|
|
511
|
+
frpRunner.setAddressListener(async (address, isCurrent) => {
|
|
512
|
+
if (!isCurrent() || state.manualTcpUrl === address) return
|
|
513
|
+
await settings.update({ manualTcpUrl: address })
|
|
514
|
+
})
|
|
515
|
+
return () => frpRunner.setAddressListener(null)
|
|
516
|
+
}, `${name}: frpc address`))
|
|
572
517
|
if (!(frpHost && frpHost.runner)) {
|
|
573
518
|
mount('frpc 直连进程', () => ctx.effect(() => {
|
|
574
519
|
if (frpRunner.shouldAutoStart()) void frpRunner.start()
|
|
@@ -576,6 +521,14 @@ function apply(ctx) {
|
|
|
576
521
|
}, `${name}: frpc runner`))
|
|
577
522
|
}
|
|
578
523
|
|
|
524
|
+
// closed按唯一连接计数;仅承载本次回执的mux由service有界排空后关闭。
|
|
525
|
+
const dropDeviceStreams = (deviceId, res) => {
|
|
526
|
+
return streamRegistry.drop(deviceId, state.instanceId)
|
|
527
|
+
+ preview.dropDevice(deviceId, state.instanceId)
|
|
528
|
+
+ (mux.dropDevice?.(deviceId, state.instanceId, res) || 0)
|
|
529
|
+
}
|
|
530
|
+
const dropAllDeviceStreams = (res) => streamRegistry.dropAll(state.instanceId) + preview.dropAll(state.instanceId) + (mux.dropAll?.(state.instanceId, res) || 0)
|
|
531
|
+
|
|
579
532
|
mount('控制面路由', () => registerControlPlaneRoutes({
|
|
580
533
|
registerRoute,
|
|
581
534
|
// 更新的机制住在外壳(`lib/index.js`)里,代这边只把它开成本机接口。取不到就如实报
|
|
@@ -606,6 +559,7 @@ function apply(ctx) {
|
|
|
606
559
|
p2p,
|
|
607
560
|
// FRP 直连:导入配置后的启停与运行状态(见 lib/frpc/runner.cjs)。
|
|
608
561
|
frp: frpRunner,
|
|
562
|
+
getControlTargetUrl: () => control.targetUrl,
|
|
609
563
|
restartSidecar,
|
|
610
564
|
// 「手机上最近来过没有」——控制面状态里补给面板用(见 ./mobile/activity.cjs)。
|
|
611
565
|
mobileActivity: activity.snapshot,
|
|
@@ -621,7 +575,8 @@ function apply(ctx) {
|
|
|
621
575
|
getLanProxyStats: () => sidecarLifecycle.getSnapshot()?.streams?.lan ?? null,
|
|
622
576
|
// 吊销时收掉这台设备已经开着的流(§3.3):token 换了只保证「下一次请求」被拒,
|
|
623
577
|
// 一条已经开着的 SSE 不会自己停,被踢的手机还能继续收消息直到它自己重连。
|
|
624
|
-
dropDeviceStreams
|
|
578
|
+
dropDeviceStreams,
|
|
579
|
+
dropAllDeviceStreams,
|
|
625
580
|
}))
|
|
626
581
|
|
|
627
582
|
|
|
@@ -667,7 +622,13 @@ function apply(ctx) {
|
|
|
667
622
|
// `ownWebPort` 是同一条边界上的唯一例外:用户显式要求手机能打开网页版(2026-11-03),
|
|
668
623
|
// 所以 `mode=webapp` 那一档只放行这一个端口(且目标必须是环回)。同样用取值器。
|
|
669
624
|
const preview = createPreviewService({
|
|
670
|
-
authorized
|
|
625
|
+
authorized: (req) => {
|
|
626
|
+
const outcome = authOutcome(req)
|
|
627
|
+
if (!outcome.ok) return false
|
|
628
|
+
req.__dshRecord = outcome.record
|
|
629
|
+
req.__dshInstanceId = state.instanceId
|
|
630
|
+
return true
|
|
631
|
+
},
|
|
671
632
|
protectedPorts: () => {
|
|
672
633
|
const ports = new Set([ctx.webServer.port, lanPortInUse()])
|
|
673
634
|
ports.delete(0)
|
|
@@ -682,8 +643,14 @@ function apply(ctx) {
|
|
|
682
643
|
// 对话页长连接(mux):一条手机 WS 上按 id 多路复用,逐条转成本地回环请求打到移动 API。
|
|
683
644
|
// 鉴权口径与预览升级路由同一套(设备凭据有效即可);逐路由权限仍由回环 HTTP 的 guarded 判,
|
|
684
645
|
// mux 只是搬运工,不另立权限面。帧契约见 `docs/mux-long-connection-design.md` §11。
|
|
685
|
-
const
|
|
686
|
-
|
|
646
|
+
const muxAuthorize = (req) => {
|
|
647
|
+
try {
|
|
648
|
+
const outcome = authOutcome(req)
|
|
649
|
+
if (!outcome.ok || !outcome.record) return false
|
|
650
|
+
req.__dshRecord = outcome.record
|
|
651
|
+
return true
|
|
652
|
+
} catch { return false }
|
|
653
|
+
}
|
|
687
654
|
// mux 优先用**稳定外壳**持有的那份(换代时已建立的手机 WS 不断);外壳不在时本地创建兜底。
|
|
688
655
|
// 升级路由由外壳直接挂(见 shell/transport-host.js),这一代不再重复注册。
|
|
689
656
|
let muxHost = null
|
|
@@ -735,7 +702,8 @@ function apply(ctx) {
|
|
|
735
702
|
// 「这台电脑上还连着哪些手机」的两条路由(见 mobile/paired-devices.js):凭据库真源 +
|
|
736
703
|
// 吊销时收掉被踢设备在途的 SSE。
|
|
737
704
|
credentials,
|
|
738
|
-
dropDeviceStreams
|
|
705
|
+
dropDeviceStreams,
|
|
706
|
+
dropAllDeviceStreams,
|
|
739
707
|
// 取值器而非快照对象:snapshot 会被 applySidecarConfig 整体替换,闭包捕获对象会让
|
|
740
708
|
// 连接信息永远停在进程启动那一刻。
|
|
741
709
|
getSidecarSnapshot: sidecarLifecycle.getSnapshot,
|
|
@@ -770,6 +738,8 @@ function apply(ctx) {
|
|
|
770
738
|
getSidecar: sidecarLifecycle.getSidecar,
|
|
771
739
|
credentials,
|
|
772
740
|
activeGuard,
|
|
741
|
+
dropDeviceStreams,
|
|
742
|
+
dropAllDeviceStreams,
|
|
773
743
|
},
|
|
774
744
|
}))
|
|
775
745
|
mount('服务同步', () => ctx.effect(() => {
|
package/lib/index.js
CHANGED
|
@@ -136,7 +136,7 @@ export function apply(ctx) {
|
|
|
136
136
|
async function applyUpdate(options = {}) {
|
|
137
137
|
const { force = false, auto = false } = options
|
|
138
138
|
try {
|
|
139
|
-
const result = await updater.performUpdate({ runtime, base, hostService, updateState, force, auto, log, beforeInstall: snapshotRunning })
|
|
139
|
+
const result = await updater.performUpdate({ runtime, base, hostService, updateState, force, auto, log, beforeInstall: snapshotRunning, runningShellHash })
|
|
140
140
|
// 换过去了:新代自己挂了隧道,别再起一个助手占端口。没换过去:这里把旧的拉回来。
|
|
141
141
|
if (result?.swapped) tailcatPaused = false
|
|
142
142
|
else await resumeTailcat()
|
package/lib/mirror/pusher.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// blob后台轮次绑定effect代次,停止后不续发旧快照或记录迟到确认。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -355,7 +356,7 @@ function createMirrorPusher(deps) {
|
|
|
355
356
|
*
|
|
356
357
|
* `scope=file` 的 key 按当初记账的归属会话一起删。
|
|
357
358
|
*/
|
|
358
|
-
const deleteRemovedSessionBlobs = async (sidecar) => {
|
|
359
|
+
const deleteRemovedSessionBlobs = async (sidecar, isCurrent) => {
|
|
359
360
|
if (typeof sidecar.deleteBlobs !== 'function') return;
|
|
360
361
|
const deleted = deletedSessionIdsOf(ctx);
|
|
361
362
|
if (!deleted || deleted.size === 0) return;
|
|
@@ -366,22 +367,28 @@ function createMirrorPusher(deps) {
|
|
|
366
367
|
.filter(([, rec]) => rec && goneSet.has(rec.sessionId))
|
|
367
368
|
.map(([key]) => key);
|
|
368
369
|
for (let i = 0; i < goneMessages.length; i += MAX_DELETE_KEYS_PER_FRAME) {
|
|
370
|
+
if (!isCurrent()) return;
|
|
369
371
|
const keys = goneMessages.slice(i, i + MAX_DELETE_KEYS_PER_FRAME);
|
|
370
372
|
try {
|
|
371
373
|
await sidecar.deleteBlobs({ scope: 'messages', keys });
|
|
374
|
+
if (!isCurrent()) return;
|
|
372
375
|
for (const key of keys) pushedMessageBlobs.delete(key);
|
|
373
376
|
blobLogClear(`delete:messages:${keys[0]}`);
|
|
374
377
|
} catch (error) {
|
|
378
|
+
if (!isCurrent()) return;
|
|
375
379
|
blobLog(`delete:messages:${keys[0]}`, errorText(error));
|
|
376
380
|
}
|
|
377
381
|
}
|
|
378
382
|
for (let i = 0; i < goneFiles.length; i += MAX_DELETE_KEYS_PER_FRAME) {
|
|
383
|
+
if (!isCurrent()) return;
|
|
379
384
|
const keys = goneFiles.slice(i, i + MAX_DELETE_KEYS_PER_FRAME);
|
|
380
385
|
try {
|
|
381
386
|
await sidecar.deleteBlobs({ scope: 'file', keys });
|
|
387
|
+
if (!isCurrent()) return;
|
|
382
388
|
for (const key of keys) pushedFileBlobs.delete(key);
|
|
383
389
|
blobLogClear(`delete:file:${keys[0]}`);
|
|
384
390
|
} catch (error) {
|
|
391
|
+
if (!isCurrent()) return;
|
|
385
392
|
blobLog(`delete:file:${keys[0]}`, errorText(error));
|
|
386
393
|
}
|
|
387
394
|
}
|
|
@@ -398,17 +405,41 @@ function createMirrorPusher(deps) {
|
|
|
398
405
|
* `MAX_BLOB_MESSAGE_FRAMES_PER_ROUND` 条、文件最多 `MAX_BLOB_FILE_FRAMES_PER_ROUND` 条,
|
|
399
406
|
* 超出的下一轮再推。
|
|
400
407
|
*/
|
|
401
|
-
|
|
408
|
+
let blobRoundRunning = false;
|
|
409
|
+
let blobStopped = false;
|
|
410
|
+
let blobGeneration = 0;
|
|
411
|
+
let nextBlobRound = null;
|
|
412
|
+
const scheduleHistoryBlobs = (payload, creds) => {
|
|
413
|
+
if (blobStopped) return;
|
|
414
|
+
// 只保留最新一份待办,不让慢上行阻塞镜像tick、revision广播或堆积快照。
|
|
415
|
+
nextBlobRound = { payload, creds, generation: blobGeneration };
|
|
416
|
+
if (blobRoundRunning) return;
|
|
417
|
+
blobRoundRunning = true;
|
|
418
|
+
const run = async () => {
|
|
419
|
+
try {
|
|
420
|
+
while (!blobStopped && nextBlobRound) {
|
|
421
|
+
const round = nextBlobRound;
|
|
422
|
+
nextBlobRound = null;
|
|
423
|
+
await pushHistoryBlobs(round.payload, round.creds, round.generation);
|
|
424
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
425
|
+
}
|
|
426
|
+
} finally { blobRoundRunning = false; }
|
|
427
|
+
};
|
|
428
|
+
void run();
|
|
429
|
+
};
|
|
430
|
+
const pushHistoryBlobs = async (payload, creds, generation) => {
|
|
402
431
|
// blob 是加法:它自己炸了不许把一次已经成功的镜像推送翻成失败(调用方会把异常记成
|
|
403
432
|
// 推送失败)。所以整趟兜一层,失败只留一行诊断。
|
|
404
433
|
try {
|
|
405
|
-
await pushHistoryBlobsUnlocked(payload, creds);
|
|
434
|
+
await pushHistoryBlobsUnlocked(payload, creds, generation);
|
|
406
435
|
} catch (error) {
|
|
407
436
|
blobLog('round', errorText(error));
|
|
408
437
|
}
|
|
409
438
|
};
|
|
410
439
|
|
|
411
|
-
const pushHistoryBlobsUnlocked = async (payload, creds) => {
|
|
440
|
+
const pushHistoryBlobsUnlocked = async (payload, creds, generation) => {
|
|
441
|
+
const isCurrent = () => !blobStopped && generation === blobGeneration;
|
|
442
|
+
if (!isCurrent()) return;
|
|
412
443
|
let hk = '';
|
|
413
444
|
try { hk = getHistoryKey() || ''; } catch { hk = ''; }
|
|
414
445
|
if (!hk) return;
|
|
@@ -435,7 +466,8 @@ function createMirrorPusher(deps) {
|
|
|
435
466
|
}
|
|
436
467
|
blobHistoryKey = hk;
|
|
437
468
|
|
|
438
|
-
await deleteRemovedSessionBlobs(sidecar);
|
|
469
|
+
await deleteRemovedSessionBlobs(sidecar, isCurrent);
|
|
470
|
+
if (!isCurrent()) return;
|
|
439
471
|
|
|
440
472
|
// 一台设备凭据都没有(还没配对过 / 刚吊销完):推上去也没人能拉,中转那边还要求 creds
|
|
441
473
|
// 非空。删除已经在上面做过了,剩下的不发,省得每轮撞一条注定被拒的帧。
|
|
@@ -454,8 +486,14 @@ function createMirrorPusher(deps) {
|
|
|
454
486
|
for (let i = 0; i < targets.length; i += MAX_CREDS_ONLY_BATCH) {
|
|
455
487
|
const batch = targets.slice(i, i + MAX_CREDS_ONLY_BATCH);
|
|
456
488
|
for (const target of batch) {
|
|
457
|
-
|
|
458
|
-
|
|
489
|
+
if (!isCurrent()) return;
|
|
490
|
+
try {
|
|
491
|
+
await sidecar.pushBlob({ ...target, creds: digestList, cipher: '' });
|
|
492
|
+
if (!isCurrent()) return;
|
|
493
|
+
} catch (error) {
|
|
494
|
+
if (!isCurrent()) return;
|
|
495
|
+
allOk = false; blobLog(`creds:${target.scope}:${target.key}`, errorText(error));
|
|
496
|
+
}
|
|
459
497
|
}
|
|
460
498
|
if (!allOk) break; // 下一轮再来,别在这一轮把 stderr 刷满
|
|
461
499
|
}
|
|
@@ -469,6 +507,7 @@ function createMirrorPusher(deps) {
|
|
|
469
507
|
let fileBudget = MAX_BLOB_FILE_FRAMES_PER_ROUND;
|
|
470
508
|
const messages = payload && payload.messages && typeof payload.messages === 'object' ? payload.messages : {};
|
|
471
509
|
for (const [sessionId, body] of Object.entries(messages)) {
|
|
510
|
+
if (!isCurrent()) return;
|
|
472
511
|
if (messageBudget <= 0) break;
|
|
473
512
|
if (!canMessages) break;
|
|
474
513
|
if (!isBlobEligible(body)) continue;
|
|
@@ -481,10 +520,12 @@ function createMirrorPusher(deps) {
|
|
|
481
520
|
catch (error) { blobLog(`build:messages:${sessionId}`, errorText(error)); continue; }
|
|
482
521
|
try {
|
|
483
522
|
await sidecar.pushBlob(frame);
|
|
523
|
+
if (!isCurrent()) return;
|
|
484
524
|
pushedMessageBlobs.set(sessionId, { fingerprint });
|
|
485
525
|
blobLogClear(`put:messages:${sessionId}`);
|
|
486
526
|
messageBudget -= 1;
|
|
487
527
|
} catch (error) {
|
|
528
|
+
if (!isCurrent()) return;
|
|
488
529
|
blobLog(`put:messages:${sessionId}`, errorText(error));
|
|
489
530
|
}
|
|
490
531
|
}
|
|
@@ -495,6 +536,7 @@ function createMirrorPusher(deps) {
|
|
|
495
536
|
// 这一段今天在 `history-blob.cjs` 里没有生产者(见 decisions 里 d2838e82 那条:文件 scope
|
|
496
537
|
// 「今天没有」),所以 `canFiles` 为假时整段不跑 —— 不跑不等于没写,真接上了这里自己就通。
|
|
497
538
|
for (const source of (canFiles ? collectFileBlobSources(payload) : [])) {
|
|
539
|
+
if (!isCurrent()) return;
|
|
498
540
|
if (fileBudget <= 0) break;
|
|
499
541
|
const stat = statFileSource(source);
|
|
500
542
|
if (!stat) continue;
|
|
@@ -514,11 +556,13 @@ function createMirrorPusher(deps) {
|
|
|
514
556
|
catch (error) { blobLog(`build:file:${source.key}`, errorText(error)); continue; }
|
|
515
557
|
try {
|
|
516
558
|
await sidecar.pushBlob(frame);
|
|
559
|
+
if (!isCurrent()) return;
|
|
517
560
|
pushedFileBlobs.set(source.key, { fingerprint, sessionId: source.sessionId });
|
|
518
561
|
blobLogClear(`put:file:${source.key}`);
|
|
519
562
|
blobLogClear(`file-too-large:${source.key}`);
|
|
520
563
|
fileBudget -= 1;
|
|
521
564
|
} catch (error) {
|
|
565
|
+
if (!isCurrent()) return;
|
|
522
566
|
blobLog(`put:file:${source.key}`, errorText(error));
|
|
523
567
|
}
|
|
524
568
|
}
|
|
@@ -555,7 +599,7 @@ function createMirrorPusher(deps) {
|
|
|
555
599
|
// 镜像判重跳过时**仍然过一遍 blob**:blob 自己有指纹判重(推成功才记账),所以这里
|
|
556
600
|
// 通常一条都不发;但上一轮 blob 推送失败、或设备集合刚变过,就得靠这一趟补上 ——
|
|
557
601
|
// 否则镜像内容不变的那些轮次里,失败的 blob 永远等不到重试。
|
|
558
|
-
|
|
602
|
+
scheduleHistoryBlobs(payload, payload.creds);
|
|
559
603
|
return false;
|
|
560
604
|
}
|
|
561
605
|
try {
|
|
@@ -568,7 +612,7 @@ function createMirrorPusher(deps) {
|
|
|
568
612
|
lastPushedCreds = credsKey;
|
|
569
613
|
recordMirrorPush(true, null)
|
|
570
614
|
// 镜像已落地之后再推历史 blob:同一份载荷、同一批凭据摘要。失败不影响上面这次成功。
|
|
571
|
-
|
|
615
|
+
scheduleHistoryBlobs(payload, payload.creds);
|
|
572
616
|
// 基准只在真的推进去(或被判重跳过)之后才前移:推送失败必须能在下一轮重试,
|
|
573
617
|
// 否则「清单变了」会被一次失败吃掉,中转镜像永远停在旧版(见 processBgQueue 的门)。
|
|
574
618
|
lastPushedListRevision = listRevision;
|
|
@@ -1139,6 +1183,8 @@ function createMirrorPusher(deps) {
|
|
|
1139
1183
|
|
|
1140
1184
|
/** 返回 effect 的清理函数,交给 index.js 用 ctx.effect 挂载(与原有形状一致)。 */
|
|
1141
1185
|
const start = () => {
|
|
1186
|
+
const generation = ++blobGeneration;
|
|
1187
|
+
blobStopped = false;
|
|
1142
1188
|
let disposed = false;
|
|
1143
1189
|
const ac = new AbortController();
|
|
1144
1190
|
void (async () => {
|
|
@@ -1190,7 +1236,11 @@ function createMirrorPusher(deps) {
|
|
|
1190
1236
|
// 已经 clearInterval,unref 是给「宿主进程要退出、effect 清理还没轮到」的那一瞬间兜底。
|
|
1191
1237
|
if (bgTimer && typeof bgTimer.unref === 'function') bgTimer.unref();
|
|
1192
1238
|
void pushMirror();
|
|
1193
|
-
return () => {
|
|
1239
|
+
return () => {
|
|
1240
|
+
disposed = true;
|
|
1241
|
+
if (generation === blobGeneration) { blobStopped = true; blobGeneration += 1; nextBlobRound = null; }
|
|
1242
|
+
ac.abort(); clearInterval(bgTimer);
|
|
1243
|
+
};
|
|
1194
1244
|
};
|
|
1195
1245
|
|
|
1196
1246
|
return {
|