@chenacc/dsh-agentbridge 0.3.0 → 0.3.2
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 -4
- package/lib/index.js +38 -5
- package/lib/tunnel.js +220 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,13 +11,17 @@ AgentBridge 的 DSH Desktop 集成插件。在某个项目会话里执行 `/phon
|
|
|
11
11
|
|
|
12
12
|
从 0.2.0 起,桥作为依赖随插件一起安装,**DSH Desktop 启动时插件会自己在后台把桥拉起来**,所以正常情况下你什么都不用敲,重启桌面后直接 `/phone` 就行。
|
|
13
13
|
|
|
14
|
-
从 0.3.0 起,插件默认还会**自动开一条 Cloudflare 隧道**,把桥映射成一个公网 https 地址——手机用流量、在外地都能扫码打开,不必和电脑连同一个 Wi-Fi
|
|
14
|
+
从 0.3.0 起,插件默认还会**自动开一条 Cloudflare 隧道**,把桥映射成一个公网 https 地址——手机用流量、在外地都能扫码打开,不必和电脑连同一个 Wi-Fi。
|
|
15
|
+
|
|
16
|
+
这一步需要一个叫 `cloudflared` 的小工具(Cloudflare 官方客户端)。**你不用管它**:插件会先在本机找,找不到就自己从 Cloudflare 官方的 GitHub Releases 下载一份到 `~\.agentbridge\bin\cloudflared.exe`(约 55 MB,只下一次,不用管理员权限,删掉那个文件夹就等于卸载)。下载完还会跑一次 `cloudflared --version` 验证,验不过的文件不会留在磁盘上。
|
|
17
|
+
|
|
18
|
+
想自己装也行,插件优先用系统里已有的那份:
|
|
15
19
|
|
|
16
20
|
```powershell
|
|
17
21
|
winget install --id Cloudflare.cloudflared
|
|
18
22
|
```
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
下载不到(断网、公司代理拦着)也能用,只是退回到"手机和电脑同一个 Wi-Fi",日志里会说明原因。
|
|
21
25
|
|
|
22
26
|
只有自动启动失败时(沙箱限制、端口被占、装在非常规位置)才需要手动起桥:
|
|
23
27
|
|
|
@@ -79,7 +83,9 @@ pnpm add @chenacc/dsh-agentbridge@latest
|
|
|
79
83
|
| `AGENTBRIDGE_NO_TUNNEL` | 未设置 | 设为 `1` 只用局域网,不起 Cloudflare 隧道(比如你只在家里用) |
|
|
80
84
|
| `AGENTBRIDGE_PUBLIC_ORIGIN` | 未设置 | 自己指定对外的地址(命名隧道、Tailscale、ZeroTier);设了它插件就不起隧道 |
|
|
81
85
|
| `AGENTBRIDGE_TUNNEL_URL` | 未设置 | 直接指定一个隧道域名;主要给测试和"隧道自己管"的人用 |
|
|
82
|
-
| `AGENTBRIDGE_CLOUDFLARED` | 自动查找 | `cloudflared
|
|
86
|
+
| `AGENTBRIDGE_CLOUDFLARED` | 自动查找 | 用你自己那份 `cloudflared`;设了它插件既不搜索也不下载 |
|
|
87
|
+
| `AGENTBRIDGE_NO_DOWNLOAD` | 未设置 | 设为 `1` 禁止插件自动下载 `cloudflared`(会退回局域网) |
|
|
88
|
+
| `AGENTBRIDGE_CLOUDFLARED_URL` | 官方 GitHub Releases | 换一个下载源(内网镜像之类);下载后照样要过 `--version` 校验 |
|
|
83
89
|
|
|
84
90
|
变量要设在**真正启动 DSH Desktop 的环境里**(插件读 `process.env`),不是设在跑 bridge 的终端里。
|
|
85
91
|
|
|
@@ -99,7 +105,7 @@ pnpm remove @chenacc/dsh-agentbridge
|
|
|
99
105
|
| 版本 | 需要 |
|
|
100
106
|
|---|---|
|
|
101
107
|
| 插件 0.1.x | DSH Desktop(`@deepseek-ai/dsh-commands`、`@deepseek-ai/cordis` 由 DSH 提供)、AgentBridge `0.1.x` |
|
|
102
|
-
| 插件 0.3.x | 同上 +
|
|
108
|
+
| 插件 0.3.x | 同上 + `cloudflared`(跨网络用;缺了会自动下载) |
|
|
103
109
|
|
|
104
110
|
插件与 bridge 之间有一份集成版本号握手:bridge 侧要求的最低集成版本比插件旧时,手机端会提示"桌面端集成是旧版",升级插件即可。
|
|
105
111
|
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createRequire } from "node:module";
|
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { ensureAccessKey, findCloudflared, startQuickTunnel } from "./tunnel.js";
|
|
7
|
+
import { ensureAccessKey, ensureAutostartToken, ensureCloudflared, findCloudflared, readAutostartToken, startQuickTunnel } from "./tunnel.js";
|
|
8
8
|
|
|
9
9
|
const name = "agentbridge-dsh-phone";
|
|
10
10
|
// `agents` is not optional: creating a conversation from the phone asks the agent
|
|
@@ -198,6 +198,9 @@ async function startBridge(origin, log = () => {}, extraEnv = {}) {
|
|
|
198
198
|
// Marks this child as the plugin's own, so a later launch may stop it to pick
|
|
199
199
|
// up a new address. A bridge the user started by hand never gets this flag.
|
|
200
200
|
AGENTBRIDGE_AUTOSTART: "1",
|
|
201
|
+
// The bridge only accepts a restart request carrying this token, which is how
|
|
202
|
+
// the advertised address changes once a tunnel exists.
|
|
203
|
+
AGENTBRIDGE_AUTOSTART_TOKEN: ensureAutostartToken(dataDir),
|
|
201
204
|
...extraEnv,
|
|
202
205
|
};
|
|
203
206
|
// Under Electron `process.execPath` is DSH Desktop itself, not node: launching
|
|
@@ -276,6 +279,31 @@ function bridgeDataDir() {
|
|
|
276
279
|
return process.env.AGENTBRIDGE_DATA_DIR || path.join(homedir(), ".agentbridge");
|
|
277
280
|
}
|
|
278
281
|
|
|
282
|
+
/**
|
|
283
|
+
* The cloudflared to run, fetching the official build the first time.
|
|
284
|
+
*
|
|
285
|
+
* Remote mode is supposed to be the default, and "the default" cannot depend on
|
|
286
|
+
* the user having heard of cloudflared. So the machine is searched first (a real
|
|
287
|
+
* install wins, whoever put it there), and only when nothing is found does the
|
|
288
|
+
* plugin download Cloudflare's own binary into its data directory — no elevation,
|
|
289
|
+
* nothing in Program Files, removable by deleting one folder.
|
|
290
|
+
*/
|
|
291
|
+
async function resolveCloudflared(log) {
|
|
292
|
+
const installed = findCloudflared({ env: process.env, home: homedir() });
|
|
293
|
+
if (installed) return installed;
|
|
294
|
+
|
|
295
|
+
log("cloudflared was not found; fetching the official build into the bridge's data directory (once)");
|
|
296
|
+
const downloaded = await ensureCloudflared({ dataDir: bridgeDataDir(), env: process.env, log });
|
|
297
|
+
if (!downloaded) {
|
|
298
|
+
log(
|
|
299
|
+
"still no cloudflared, so this machine stays on same-Wi-Fi pairing: "
|
|
300
|
+
+ "install it with `winget install --id Cloudflare.cloudflared`, or download cloudflared-windows-amd64.exe "
|
|
301
|
+
+ "from https://github.com/cloudflare/cloudflared/releases and point AGENTBRIDGE_CLOUDFLARED at it",
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
return downloaded;
|
|
305
|
+
}
|
|
306
|
+
|
|
279
307
|
/**
|
|
280
308
|
* The address the QR code should carry, and the key that unlocks it.
|
|
281
309
|
*
|
|
@@ -290,9 +318,9 @@ async function resolveRemoteOrigin(log) {
|
|
|
290
318
|
const supplied = String(process.env.AGENTBRIDGE_TUNNEL_URL ?? "").trim().replace(/\/$/, "");
|
|
291
319
|
if (supplied) return { origin: supplied, accessKey: ensureAccessKey(bridgeDataDir()), how: "AGENTBRIDGE_TUNNEL_URL" };
|
|
292
320
|
|
|
293
|
-
const command =
|
|
321
|
+
const command = await resolveCloudflared(log);
|
|
294
322
|
if (!command) {
|
|
295
|
-
log("no cloudflared
|
|
323
|
+
log("no cloudflared is available, staying on this Wi-Fi only");
|
|
296
324
|
return null;
|
|
297
325
|
}
|
|
298
326
|
|
|
@@ -326,11 +354,16 @@ async function resolveRemoteOrigin(log) {
|
|
|
326
354
|
* endpoint reports whether it was autostarted, and only that flag authorises this.
|
|
327
355
|
*/
|
|
328
356
|
async function stopBridge(origin, log) {
|
|
357
|
+
const token = readAutostartToken(bridgeDataDir());
|
|
358
|
+
if (!token) {
|
|
359
|
+
log("cannot restart the bridge: its autostart token is missing");
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
329
362
|
let response;
|
|
330
363
|
try {
|
|
331
|
-
response = await fetch(`${origin}/api/local/shutdown`, {
|
|
364
|
+
response = await fetch(`${origin}/api/local/autostart/shutdown`, {
|
|
332
365
|
method: "POST",
|
|
333
|
-
headers: { "content-type": "application/json" },
|
|
366
|
+
headers: { "content-type": "application/json", "x-agentbridge-autostart": token },
|
|
334
367
|
body: "{}",
|
|
335
368
|
signal: AbortSignal.timeout(5_000),
|
|
336
369
|
});
|
package/lib/tunnel.js
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { spawn } from "node:child_process";
|
|
18
18
|
import { randomBytes } from "node:crypto";
|
|
19
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
20
|
+
import https from "node:https";
|
|
20
21
|
import os from "node:os";
|
|
21
22
|
import path from "node:path";
|
|
23
|
+
import tls from "node:tls";
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* A quick tunnel hostname.
|
|
@@ -70,10 +72,199 @@ export function findCloudflared({ env = process.env, home = os.homedir(), exists
|
|
|
70
72
|
return null;
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
/** The official release asset for this machine, or null when there is none. */
|
|
76
|
+
export function cloudflaredAssetUrl({ platform = process.platform, arch = process.arch } = {}) {
|
|
77
|
+
if (platform === "win32" && arch === "x64") {
|
|
78
|
+
return "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe";
|
|
79
|
+
}
|
|
80
|
+
if (platform === "win32" && arch === "arm64") {
|
|
81
|
+
return "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-arm64.exe";
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function cloudflaredBinaryPath(dataDir, { platform = process.platform } = {}) {
|
|
87
|
+
return path.join(dataDir, "bin", platform === "win32" ? "cloudflared.exe" : "cloudflared");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function cloudflaredVersionPath(dataDir) {
|
|
91
|
+
return path.join(dataDir, "bin", "cloudflared.json");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Proves a downloaded file is the real cloudflared before anything runs through it.
|
|
96
|
+
*
|
|
97
|
+
* `--version` is the honest test: it exercises the binary the tunnel is about to
|
|
98
|
+
* use, and the banner ("cloudflared version 2026.10.7 ...") is a shape no HTML
|
|
99
|
+
* error page or truncated download can produce.
|
|
100
|
+
*/
|
|
101
|
+
export async function cloudflaredVersion(command, { spawnImpl = spawn, timeoutMs = 20_000 } = {}) {
|
|
102
|
+
return new Promise((resolve) => {
|
|
103
|
+
let output = "";
|
|
104
|
+
let child;
|
|
105
|
+
try {
|
|
106
|
+
child = spawnImpl(command, ["--version"], { windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
107
|
+
} catch {
|
|
108
|
+
return resolve(null);
|
|
109
|
+
}
|
|
110
|
+
const done = (value) => {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
resolve(value);
|
|
113
|
+
};
|
|
114
|
+
const timer = setTimeout(() => {
|
|
115
|
+
try { child.kill("SIGKILL"); } catch { /* already gone */ }
|
|
116
|
+
done(null);
|
|
117
|
+
}, timeoutMs);
|
|
118
|
+
timer.unref?.();
|
|
119
|
+
child.stdout?.on("data", (chunk) => { output += String(chunk); });
|
|
120
|
+
child.stderr?.on("data", (chunk) => { output += String(chunk); });
|
|
121
|
+
child.once?.("error", () => done(null));
|
|
122
|
+
child.once?.("exit", () => {
|
|
123
|
+
const match = /cloudflared version v?(\d+\.\d+\.\d+\S*)/i.exec(output);
|
|
124
|
+
done(match ? match[1] : null);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Fetch the official binary to `<dataDir>` and hand back its path.
|
|
131
|
+
*
|
|
132
|
+
* Two details make this work where a naive `fetch` would not: GitHub redirects to
|
|
133
|
+
* a versioned asset host, and on machines behind a TLS-inspecting proxy (common in
|
|
134
|
+
* corporate networks and in China) the OS trust store is the only thing that
|
|
135
|
+
* verifies the certificate — so the request carries the system roots alongside
|
|
136
|
+
* Node's bundled ones.
|
|
137
|
+
*/
|
|
138
|
+
function downloadToFile(url, target, { log = () => {}, maxRedirects = 5, timeoutMs = 120_000 } = {}) {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
const ca = (() => {
|
|
141
|
+
try {
|
|
142
|
+
const system = typeof tls.getCACertificates === "function" ? tls.getCACertificates("system") : [];
|
|
143
|
+
return [...tls.rootCertificates, ...system];
|
|
144
|
+
} catch {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
})();
|
|
148
|
+
|
|
149
|
+
const get = (current, redirectsLeft) => {
|
|
150
|
+
const request = https.get(current, {
|
|
151
|
+
...(ca ? { ca } : {}),
|
|
152
|
+
headers: { "user-agent": "agentbridge-dsh-phone", accept: "application/octet-stream" },
|
|
153
|
+
timeout: timeoutMs,
|
|
154
|
+
}, (response) => {
|
|
155
|
+
const status = response.statusCode ?? 0;
|
|
156
|
+
if (status >= 300 && status < 400 && response.headers.location) {
|
|
157
|
+
response.resume();
|
|
158
|
+
if (redirectsLeft <= 0) return reject(new Error("too many redirects"));
|
|
159
|
+
return get(new URL(response.headers.location, current).href, redirectsLeft - 1);
|
|
160
|
+
}
|
|
161
|
+
if (status !== 200) {
|
|
162
|
+
response.resume();
|
|
163
|
+
return reject(new Error(`HTTP ${status} downloading ${current}`));
|
|
164
|
+
}
|
|
165
|
+
const expected = Number(response.headers["content-length"] ?? 0);
|
|
166
|
+
if (expected) log(`downloading ${(expected / 1024 / 1024).toFixed(1)} MB from Cloudflare`);
|
|
167
|
+
const file = createWriteStream(target);
|
|
168
|
+
let written = 0;
|
|
169
|
+
let nextReport = 10 * 1024 * 1024;
|
|
170
|
+
response.on("data", (chunk) => {
|
|
171
|
+
written += chunk.length;
|
|
172
|
+
// A 55 MB download on a slow link otherwise looks like a hang.
|
|
173
|
+
if (written >= nextReport) {
|
|
174
|
+
nextReport += 10 * 1024 * 1024;
|
|
175
|
+
log(`cloudflared download: ${(written / 1024 / 1024).toFixed(0)} MB${expected ? ` of ${(expected / 1024 / 1024).toFixed(0)}` : ""}`);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
response.pipe(file);
|
|
179
|
+
file.on("finish", () => file.close(() => {
|
|
180
|
+
// A truncated download that still "finished" is the failure mode that
|
|
181
|
+
// would otherwise land a corrupt exe on disk.
|
|
182
|
+
if (expected && written !== expected) return reject(new Error(`truncated download: ${written} of ${expected} bytes`));
|
|
183
|
+
resolve(written);
|
|
184
|
+
}));
|
|
185
|
+
file.on("error", reject);
|
|
186
|
+
response.on("error", reject);
|
|
187
|
+
});
|
|
188
|
+
request.on("timeout", () => request.destroy(new Error("download timed out")));
|
|
189
|
+
request.on("error", reject);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
get(url, maxRedirects);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The cloudflared this machine should use, downloaded on first need.
|
|
198
|
+
*
|
|
199
|
+
* A missing cloudflared used to mean "same Wi-Fi only", which made the plugin's
|
|
200
|
+
* remote mode an opt-in nobody opted into. Downloading the official build into the
|
|
201
|
+
* bridge's own data directory keeps it out of Program Files, needs no elevation,
|
|
202
|
+
* and can be removed by deleting one folder.
|
|
203
|
+
*/
|
|
204
|
+
export async function ensureCloudflared({
|
|
205
|
+
dataDir,
|
|
206
|
+
env = process.env,
|
|
207
|
+
log = () => {},
|
|
208
|
+
platform = process.platform,
|
|
209
|
+
arch = process.arch,
|
|
210
|
+
exists = existsSync,
|
|
211
|
+
download = downloadToFile,
|
|
212
|
+
verify = cloudflaredVersion,
|
|
213
|
+
now = () => new Date().toISOString(),
|
|
214
|
+
} = {}) {
|
|
215
|
+
const override = String(env.AGENTBRIDGE_CLOUDFLARED ?? "").trim();
|
|
216
|
+
if (override) {
|
|
217
|
+
return exists(override) ? override : null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const target = cloudflaredBinaryPath(dataDir, { platform });
|
|
221
|
+
|
|
222
|
+
if (exists(target)) {
|
|
223
|
+
const version = await verify(target);
|
|
224
|
+
if (version) return target;
|
|
225
|
+
log(`the downloaded cloudflared at ${target} does not run; removing it and fetching a fresh copy`);
|
|
226
|
+
try { rmSync(target, { force: true }); } catch { /* a locked file just fails the download below */ }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const url = String(env.AGENTBRIDGE_CLOUDFLARED_URL ?? "").trim() || cloudflaredAssetUrl({ platform, arch });
|
|
230
|
+
if (!url) {
|
|
231
|
+
log(`no official cloudflared build for ${platform}/${arch}; install one yourself and point AGENTBRIDGE_CLOUDFLARED at it`);
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
if (env.AGENTBRIDGE_NO_DOWNLOAD === "1") {
|
|
235
|
+
log("cloudflared is not installed and AGENTBRIDGE_NO_DOWNLOAD=1 forbids downloading it");
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const temporary = `${target}.download`;
|
|
240
|
+
try {
|
|
241
|
+
mkdirSync(path.dirname(target), { recursive: true });
|
|
242
|
+
await download(url, temporary, { log });
|
|
243
|
+
const version = await verify(temporary);
|
|
244
|
+
if (!version) throw new Error("the downloaded file does not report a cloudflared version");
|
|
245
|
+
renameSync(temporary, target);
|
|
246
|
+
try {
|
|
247
|
+
writeFileSync(cloudflaredVersionPath(dataDir), JSON.stringify({ version, url, downloadedAt: now() }, null, 2), "utf8");
|
|
248
|
+
} catch {
|
|
249
|
+
// The record is a convenience, not a requirement.
|
|
250
|
+
}
|
|
251
|
+
log(`cloudflared ${version} is ready at ${target}`);
|
|
252
|
+
return target;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
try { rmSync(temporary, { force: true }); } catch { /* nothing to clean */ }
|
|
255
|
+
log(`could not fetch cloudflared from ${url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
73
260
|
export function accessKeyPath(dataDir) {
|
|
74
261
|
return path.join(dataDir, "access-key");
|
|
75
262
|
}
|
|
76
263
|
|
|
264
|
+
export function autostartTokenPath(dataDir) {
|
|
265
|
+
return path.join(dataDir, "autostart-token");
|
|
266
|
+
}
|
|
267
|
+
|
|
77
268
|
/**
|
|
78
269
|
* The key that gates a publicly exposed bridge.
|
|
79
270
|
*
|
|
@@ -82,17 +273,40 @@ export function accessKeyPath(dataDir) {
|
|
|
82
273
|
* out of its own bridge.
|
|
83
274
|
*/
|
|
84
275
|
export function ensureAccessKey(dataDir, { readFile = readFileSync, writeFile = writeFileSync, mkdir = mkdirSync, random } = {}) {
|
|
85
|
-
|
|
276
|
+
return ensureSecret(accessKeyPath(dataDir), dataDir, { readFile, writeFile, mkdir, random });
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* The secret that lets this plugin ask its own bridge to restart.
|
|
281
|
+
*
|
|
282
|
+
* A restart is how the advertised address changes (the tunnel hostname only
|
|
283
|
+
* exists once cloudflared is up), and the bridge accepts that request only from
|
|
284
|
+
* loopback *with this token* — so a random local page cannot stop the bridge, and
|
|
285
|
+
* a second, unrelated DSH profile cannot either.
|
|
286
|
+
*/
|
|
287
|
+
export function ensureAutostartToken(dataDir, options = {}) {
|
|
288
|
+
return ensureSecret(autostartTokenPath(dataDir), dataDir, options);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function readAutostartToken(dataDir, { readFile = readFileSync } = {}) {
|
|
292
|
+
try {
|
|
293
|
+
return String(readFile(autostartTokenPath(dataDir), "utf8")).trim() || null;
|
|
294
|
+
} catch {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function ensureSecret(target, dataDir, { readFile = readFileSync, writeFile = writeFileSync, mkdir = mkdirSync, random } = {}) {
|
|
86
300
|
try {
|
|
87
301
|
const existing = String(readFile(target, "utf8")).trim();
|
|
88
302
|
if (existing.length >= 16) return existing;
|
|
89
303
|
} catch {
|
|
90
|
-
// No usable
|
|
304
|
+
// No usable secret on disk yet.
|
|
91
305
|
}
|
|
92
|
-
const
|
|
306
|
+
const secret = (random ?? (() => randomBytes(24).toString("base64url")))();
|
|
93
307
|
mkdir(dataDir, { recursive: true });
|
|
94
|
-
writeFile(target,
|
|
95
|
-
return
|
|
308
|
+
writeFile(target, secret, "utf8");
|
|
309
|
+
return secret;
|
|
96
310
|
}
|
|
97
311
|
|
|
98
312
|
export function tunnelStatePath(dataDir) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chenacc/dsh-agentbridge",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "AgentBridge for DSH Desktop: run /phone in a conversation to pair a phone console with that exact live Agent.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@chenacc/agentbridge": "^0.1.
|
|
48
|
+
"@chenacc/agentbridge": "^0.1.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@deepseek-ai/dsh-commands": "^0.1.0-rc.7",
|