dsh-mobile-plugin 0.5.90 → 0.5.92
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/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +14 -3
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/ipv4.md +38 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/ipv6.md +36 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/selfhost-common.md +44 -0
- package/docs/extension-authoring.md +4 -4
- package/extension-registry/index.json +5 -1
- package/host.js +7 -15
- package/lib/client.js +20 -12
- package/lib/host-compat.cjs +4 -1
- package/lib/host-preset-patches.cjs +40 -0
- package/lib/http/routing.js +5 -36
- package/lib/impl.js +38 -22
- package/lib/index.js +3 -0
- package/lib/mobile/agent-presets.js +12 -0
- package/lib/mobile/answer-sources.js +3 -2
- package/lib/mobile/archive-clean.js +5 -0
- package/lib/mobile/history-derive.js +3 -7
- package/lib/mobile/host-bridge/shims.js +20 -3
- package/lib/mobile/host-bridge.js +30 -1
- package/lib/mobile/live-steps.js +4 -3
- package/lib/mobile/plugin-self.js +4 -0
- package/lib/mobile/relay-control.js +76 -5
- package/lib/mobile/session-cache.js +12 -1
- package/lib/mobile/session-models.js +1 -1
- package/lib/mobile/session-presets.js +5 -2
- package/lib/mobile/session-send.js +0 -4
- package/lib/mobile/session-step.js +3 -2
- package/lib/mobile/stats-collect.cjs +26 -8
- package/lib/mobile/step-index.js +4 -3
- package/lib/mobile/subagents.js +0 -5
- package/lib/mobile/tool-result-state.js +12 -0
- package/lib/panel/index.html +27 -28
- package/lib/relay/control.js +53 -1
- package/lib/relay/lan-discovery.cjs +18 -3
- package/lib/relay/lan-proxy.js +22 -2
- package/lib/remote/routes.cjs +3 -2
- package/lib/routes/control-plane.js +30 -25
- package/lib/routes/mobile-api.js +2 -0
- package/lib/session-cleanup.cjs +17 -0
- package/lib/shared/session-storage.cjs +82 -0
- package/lib/shell/first-install.js +102 -0
- package/lib/shell/transport-host.js +3 -0
- package/lib/shell/updater.js +6 -5
- package/lib/sidecar-facade-worker.cjs +2 -0
- package/lib/tailcat/wiring.cjs +2 -2
- package/lib/update-install.cjs +88 -0
- package/package.json +2 -2
- package/lib/mobile/ai-recipient.cjs +0 -61
package/lib/shell/updater.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** 更新账本保留安装恢复结果,常驻 Tailcat 代码变化提示重新载入外壳。 */
|
|
2
2
|
/**
|
|
3
3
|
* 更新编排:查与装都归实现自己,装完就地换代(不重启 DSH)。
|
|
4
4
|
*
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* 兜底那条路不下载、不解包、不校验、不写 profile,只回答「有没有新版、装完了没、盘上是什么
|
|
14
14
|
* 版本」。
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* 外壳指纹包含入口、外壳目录和外壳持有的 Tailcat 静态依赖,由换代守卫逐文件钉住;
|
|
17
|
+
* 常驻模块必须同步进来,否则换代沿用旧代码时面板收不到重启提示。
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import fs from 'node:fs'
|
|
@@ -62,7 +62,7 @@ function installedPackageDirSafe() {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* 外壳及其常驻 Tailcat 依赖的内容指纹;传输门面跨代存活,依赖也要重载才会更换。
|
|
66
66
|
*
|
|
67
67
|
* **外壳换不掉**:它在进程启动时被 Node 缓存,改它必须重启 DSH —— 而重启是被明令禁止的。
|
|
68
68
|
* 所以「新版本连外壳一起改了」这件事**不会**在这次更新里生效:实现换成新的了,装载它的
|
|
@@ -73,7 +73,8 @@ function installedPackageDirSafe() {
|
|
|
73
73
|
*/
|
|
74
74
|
export function shellFingerprint(pkgDir) {
|
|
75
75
|
if (!pkgDir) return null
|
|
76
|
-
const files = ['lib/index.js', 'lib/shell/runtime.js', 'lib/shell/manager.js', 'lib/shell/updater.js', 'lib/shell/device-ota.js', 'lib/shell/ota-package.js', 'lib/shell/ota-signing.js', 'lib/shell/ota-public-key.js', 'lib/shell/half-route.js', 'lib/shell/half-view.js', 'lib/shell/self-check-after-swap.js', 'lib/shell/transport-host.js'
|
|
76
|
+
const files = ['lib/index.js', 'lib/shell/runtime.js', 'lib/shell/manager.js', 'lib/shell/updater.js', 'lib/shell/device-ota.js', 'lib/shell/ota-package.js', 'lib/shell/ota-signing.js', 'lib/shell/ota-public-key.js', 'lib/shell/half-route.js', 'lib/shell/half-view.js', 'lib/shell/self-check-after-swap.js', 'lib/shell/transport-host.js', 'lib/shell/first-install.js',
|
|
77
|
+
'lib/tailcat/wiring.cjs', 'lib/tailcat/session.cjs', 'lib/tailcat/ingress.cjs', 'lib/tailcat/host-process.cjs', 'lib/relay/tunnel-forwarder.cjs', 'lib/shared/via-header.js']
|
|
77
78
|
const hash = createHash('sha256')
|
|
78
79
|
let seen = 0
|
|
79
80
|
for (const rel of files) {
|
|
@@ -744,6 +744,8 @@ async function startLan() {
|
|
|
744
744
|
pairingTier: config.pairingTier || 'full',
|
|
745
745
|
upstreamPort: config.upstreamPort,
|
|
746
746
|
upstreamHost: config.upstreamHost || '127.0.0.1',
|
|
747
|
+
// 手填直连地址:交给局域网代理按 Host 区分「外网穿透」与「局域网」,别再标成局域网。
|
|
748
|
+
manualLanUrl: config.manualLanUrl || '',
|
|
747
749
|
readSnapshot: snapshotRead,
|
|
748
750
|
onLog: (...args) => process.stderr.write(`[dsh-ai-hub sidecar] ${args.join(' ')}\n`),
|
|
749
751
|
// 配对成功之后换码 + 换票据:走宿主的控制面(那是唯一能写状态文件的地方)。
|
package/lib/tailcat/wiring.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 装配门面保留真实启动错误,正常等待与默认关闭不产生故障。
|
|
2
2
|
'use strict';
|
|
3
3
|
// 隧道始终走独立的带来源标记入口,不依赖局域网监听。
|
|
4
4
|
// 落点代理转给宿主时跟随宿主实际绑定地址(见 relay/tunnel-forwarder.cjs)。
|
|
@@ -92,7 +92,7 @@ function mountTailcat(options) {
|
|
|
92
92
|
const base = session && !startupError
|
|
93
93
|
? session.status()
|
|
94
94
|
: { available: Boolean(ingress && forwarder && !startupError), enabled: (readState() || {}).tailcatEnabled === true,
|
|
95
|
-
ready: false, address: '', paired: 0, error: startupError
|
|
95
|
+
ready: false, address: '', paired: 0, error: startupError };
|
|
96
96
|
return { ...base, targetPort: resolvedTargetPort() };
|
|
97
97
|
},
|
|
98
98
|
openPairingWindow: ttl => (session ? session.openPairingWindow(ttl) : Promise.resolve(null)),
|
package/lib/update-install.cjs
CHANGED
|
@@ -31,6 +31,67 @@ const HOIST_DIFF = /ERR_PNPM_PUBLIC_HOIST_PATTERN_DIFF|ERR_PNPM_VIRTUAL_STORE_DI
|
|
|
31
31
|
/** 命令输出留多少字符(日志与错误信息里给个人看得懂的尾巴)。 */
|
|
32
32
|
const OUTPUT_TAIL = 4000;
|
|
33
33
|
|
|
34
|
+
/** 等 profile 写锁的上限:DSH 的插件管理自己最长等 120 秒,这里不跟它比耐心,超时就让出这一轮。 */
|
|
35
|
+
const PROFILE_LOCK_WAIT_MS = 30 * 1000;
|
|
36
|
+
|
|
37
|
+
/** 锁记录里那个 `pid\n` 进程还在不在;认不出来的一律当「活着」,不抢。 */
|
|
38
|
+
function holderProcessExited(record) {
|
|
39
|
+
if (!/^\d+\n$/.test(record)) return false;
|
|
40
|
+
const pid = Number(record.trim());
|
|
41
|
+
if (pid === 0 || pid > 0x7fffffff) return false;
|
|
42
|
+
if (pid === process.pid) return false;
|
|
43
|
+
try {
|
|
44
|
+
process.kill(pid, 0);
|
|
45
|
+
return false;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return error.code === 'ESRCH';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 拿 profile 的包写锁再干活,和 DSH 插件管理抢**同一个锁文件**(`<profile>/package.json.lock`)。
|
|
53
|
+
*
|
|
54
|
+
* 本插件自己会跑 `pnpm add` 换包,DSH 的插件管理在更新/卸载时也会跑。两边同时改同一个 profile,
|
|
55
|
+
* 轻则锁文件、依赖目录装坏,重则插件起不来、手机断连。DSH 那边已经用这个 `<package.json>.lock`
|
|
56
|
+
* 串行化它所有的包操作;我们抢同一把锁就自然和它排上队 —— 不用它配合,也不用它知道我们。
|
|
57
|
+
* 抢不到就认输(抛 `PROFILE_BUSY`),绝不硬装。
|
|
58
|
+
*
|
|
59
|
+
* 锁的格式和 @deepseek-ai/dsh-atomic-write 的 withFileLock 一致:`wx` 建同名 `.lock`、写入持有者
|
|
60
|
+
* pid;持有者进程没了(`ESRCH`)就清掉残留锁重来,免得一次崩溃把自动更新永久卡死。pid 只在本机
|
|
61
|
+
* 可比,跨机共享同一个 profile 不在支持范围。
|
|
62
|
+
*/
|
|
63
|
+
async function withProfileLock(profileDir, operation, { waitMs = PROFILE_LOCK_WAIT_MS } = {}) {
|
|
64
|
+
const lockPath = path.join(profileDir, 'package.json.lock');
|
|
65
|
+
const deadline = Date.now() + waitMs;
|
|
66
|
+
let delay = 20;
|
|
67
|
+
for (;;) {
|
|
68
|
+
try {
|
|
69
|
+
fs.writeFileSync(lockPath, `${process.pid}\n`, { flag: 'wx', mode: 0o600 });
|
|
70
|
+
break;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (!error || (error.code !== 'EEXIST' && error.code !== 'EPERM')) throw error;
|
|
73
|
+
let record = null;
|
|
74
|
+
try { record = fs.readFileSync(lockPath, 'utf8'); } catch { /* 刚被释放,下一轮再抢 */ }
|
|
75
|
+
if (record !== null && holderProcessExited(record)) {
|
|
76
|
+
try { fs.rmSync(lockPath, { force: true }); } catch { /* 别人也在清,下一轮再抢 */ }
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (Date.now() >= deadline) {
|
|
80
|
+
const busy = new Error('profile 的包目录正被另一个安装/卸载操作占用(可能 DSH 正在装别的插件),这次先不动盘,稍后再试。');
|
|
81
|
+
busy.code = 'PROFILE_BUSY';
|
|
82
|
+
throw busy;
|
|
83
|
+
}
|
|
84
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
85
|
+
delay = Math.min(delay * 2, 200);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return await operation();
|
|
90
|
+
} finally {
|
|
91
|
+
try { fs.rmSync(lockPath, { force: true }); } catch { /* 释放失败不掩盖真正的结果 */ }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
34
95
|
/**
|
|
35
96
|
* 去哪儿找包管理器。
|
|
36
97
|
*
|
|
@@ -702,6 +763,9 @@ async function installLatest({
|
|
|
702
763
|
);
|
|
703
764
|
}
|
|
704
765
|
|
|
766
|
+
// 真正会改盘的一段(备份 → pnpm add → 核对/回滚 → 登记排除清单)整体在 profile 写锁里跑,
|
|
767
|
+
// 和 DSH 插件管理的装卸操作排同一队,避免两边同时改坏同一份依赖树。
|
|
768
|
+
const performInstall = async () => {
|
|
705
769
|
const previousComplete = beforeVersion !== null && installationProblem(profileNodeModules, name, beforeVersion) === null;
|
|
706
770
|
// 备份正在跑的那一代:包的活就落在下面那一行 spawn 上,它一跑旧目录就没了。
|
|
707
771
|
// 备份失败不该挡住更新(那是多一层保险),所以这里吞掉它的异常,由调用方记日志。
|
|
@@ -827,6 +891,28 @@ async function installLatest({
|
|
|
827
891
|
message: withReason(`${command} 跑完了,但盘上还是 ${after ?? '读不到版本'},这一次不算数`, output),
|
|
828
892
|
},
|
|
829
893
|
};
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
try {
|
|
897
|
+
return await withProfileLock(profileDir, performInstall);
|
|
898
|
+
} catch (error) {
|
|
899
|
+
if (error && error.code === 'PROFILE_BUSY') {
|
|
900
|
+
// 「现在不行」,不是坏了:DSH 的插件管理正握着锁在装/卸别的插件。一行都不写盘,下个 tick 再来。
|
|
901
|
+
return {
|
|
902
|
+
installed: false,
|
|
903
|
+
skipped: true,
|
|
904
|
+
retryable: true,
|
|
905
|
+
beforeVersion,
|
|
906
|
+
installedVersion: beforeVersion,
|
|
907
|
+
source: declaredSource(profileDir, name),
|
|
908
|
+
command: null,
|
|
909
|
+
output: '',
|
|
910
|
+
detail: error.message,
|
|
911
|
+
failure: null,
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
throw error;
|
|
915
|
+
}
|
|
830
916
|
}
|
|
831
917
|
|
|
832
918
|
/**
|
|
@@ -967,4 +1053,6 @@ module.exports = {
|
|
|
967
1053
|
DEFAULT_NAME,
|
|
968
1054
|
INSTALL_TIMEOUT_MS,
|
|
969
1055
|
OUTPUT_TAIL,
|
|
1056
|
+
// profile 写锁单测直接打它:验「拿不到锁就让路、拿到就串行」,比隔着整条安装链路更快更稳。
|
|
1057
|
+
withProfileLock,
|
|
970
1058
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mobile-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.92",
|
|
4
4
|
"description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"icon": "./icon.png",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"bonjour-service": "1.4.4",
|
|
77
77
|
"qrcode": "1.5.4",
|
|
78
|
-
"ws": "8.
|
|
78
|
+
"ws": "8.23.0"
|
|
79
79
|
},
|
|
80
80
|
"optionalDependencies": {
|
|
81
81
|
"dsh-mobile-shell-darwin-arm64": "0.1.2",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/** 已知自建端点在接入 prompt 前核对当前模型与配置;不读取凭据,不承诺队列未来每步的路由。 */
|
|
2
|
-
'use strict';
|
|
3
|
-
const { unwrap } = require('./envelope.js');
|
|
4
|
-
|
|
5
|
-
function publicEndpoint(value) {
|
|
6
|
-
try {
|
|
7
|
-
const url = new URL(typeof value === 'string' ? value : '');
|
|
8
|
-
if (url.protocol !== 'https:' && url.protocol !== 'http:') return '';
|
|
9
|
-
return `${url.protocol}//${url.host}${url.pathname.replace(/\/+$/, '')}`;
|
|
10
|
-
} catch { return ''; }
|
|
11
|
-
}
|
|
12
|
-
function refusal(code) {
|
|
13
|
-
return { code, message: code === 'ai-recipient-changed'
|
|
14
|
-
? '模型接收方已改变,请回到手机重新确认后发送。'
|
|
15
|
-
: '这台电脑无法核实已确认的模型接收方,请更新插件或重新确认当前路由。' };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** 缺省字段保留逐消息授权电脑当前路由的旧路径;显式字段不允许悄悄降级。 */
|
|
19
|
-
async function expectedAiRecipientError(ctx, { sessionId, expected, selection, child = false }) {
|
|
20
|
-
if (expected === undefined) return null;
|
|
21
|
-
if (!expected || typeof expected !== 'object' || typeof expected.provider !== 'string'
|
|
22
|
-
|| !expected.provider.trim() || !publicEndpoint(expected.endpoint)) {
|
|
23
|
-
return { code: 'bad-request', message: 'expectedAiRecipient 需要 { provider, endpoint }。' };
|
|
24
|
-
}
|
|
25
|
-
const provider = expected.provider.trim();
|
|
26
|
-
const endpoint = publicEndpoint(expected.endpoint);
|
|
27
|
-
if (selection && selection.provider !== provider) return refusal('ai-recipient-changed');
|
|
28
|
-
try {
|
|
29
|
-
const llm = ctx.get && ctx.get('llm');
|
|
30
|
-
if (!llm || typeof llm.resolveCallConfig !== 'function') return refusal('ai-recipient-unverifiable');
|
|
31
|
-
const agents = ctx.get && ctx.get('agents');
|
|
32
|
-
let agent = agents && typeof agents.get === 'function' ? agents.get(sessionId) : null;
|
|
33
|
-
if (!agent && !child) {
|
|
34
|
-
const controller = ctx.get && ctx.get('sessionController');
|
|
35
|
-
if (controller && typeof controller.resolveAgent === 'function') {
|
|
36
|
-
const resolved = await controller.resolveAgent(sessionId);
|
|
37
|
-
if (resolved && !resolved.error) agent = resolved.agent;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const actual = agent && agent.model && typeof agent.model.current === 'function' ? agent.model.current() : null;
|
|
41
|
-
if (!actual || !actual.provider || !actual.model) return refusal('ai-recipient-unverifiable');
|
|
42
|
-
if (actual.provider !== provider) return refusal('ai-recipient-changed');
|
|
43
|
-
// 这是宿主当前模型配置校验,不把客户端声称的 route 当成实际 route。
|
|
44
|
-
const resolved = await llm.resolveCallConfig(actual);
|
|
45
|
-
if (!resolved || resolved.provider !== actual.provider || resolved.model !== actual.model) return refusal('ai-recipient-unverifiable');
|
|
46
|
-
const settings = unwrap(await ctx.apiProxy.settings.describe({ rpcId: 'mobile', method: 'settings.describe', payload: {} }));
|
|
47
|
-
if (settings.error) return refusal('ai-recipient-unverifiable');
|
|
48
|
-
const rows = Array.isArray(settings.value) ? settings.value : settings.value && settings.value.namespaces;
|
|
49
|
-
const namespace = Array.isArray(rows) ? rows.find((row) => row && row.ns === 'llm-pi-ai') : null;
|
|
50
|
-
const profiles = namespace && namespace.value && namespace.value.providers;
|
|
51
|
-
const profile = profiles && Object.hasOwn(profiles, provider) ? profiles[provider] : null;
|
|
52
|
-
// llm-pi-ai 的显式 baseURL 覆盖全部模型端点;无显式值时内置模型可能各用自己的端点。
|
|
53
|
-
const actualEndpoint = publicEndpoint(profile && profile.baseURL);
|
|
54
|
-
if (!actualEndpoint) return refusal('ai-recipient-unverifiable');
|
|
55
|
-
if (actualEndpoint !== endpoint) return refusal('ai-recipient-changed');
|
|
56
|
-
return null;
|
|
57
|
-
} catch {
|
|
58
|
-
return refusal('ai-recipient-unverifiable');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
module.exports = { publicEndpoint, expectedAiRecipientError };
|