@chenacc/dsh-agentbridge 0.3.3 → 0.4.1
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 +27 -3
- package/assets/icon.png +0 -0
- package/assets/phone-console-1.png +0 -0
- package/lib/index.js +39 -67
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
# @chenacc/dsh-agentbridge
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@chenacc/dsh-agentbridge)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://github.com/chenacc1/agentbridge/stargazers)
|
|
6
|
+
|
|
3
7
|
AgentBridge 的 DSH Desktop 集成插件。在某个项目会话里执行 `/phone`,把**屏幕上那一条** live Agent 会话接到手机控制台:手机扫码后可以发消息、审批、切换模型、停止任务,桌面与手机看到同一份事件流。
|
|
4
8
|
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
一条命令装进当前 profile:
|
|
12
|
+
|
|
13
|
+
```powershell
|
|
14
|
+
cd "$env:USERPROFILE\.dsh\profiles\desktop"; pnpm add @chenacc/dsh-agentbridge@latest
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
重启 DSH Desktop,在项目会话里输入 `/phone`——二维码默认就是公网地址,手机用流量也能打开。
|
|
18
|
+
|
|
5
19
|
- 精确绑定当前会话:会话 ID、项目目录、provider / 模型都取自真实会话,不是新建一个"类似的"会话。
|
|
6
20
|
- 电脑始终是唯一执行端:凭据和文件访问留在本机,手机只下发命令。
|
|
7
21
|
|
|
22
|
+
> 觉得有用就给主仓库点个 star:[chenacc1/agentbridge](https://github.com/chenacc1/agentbridge) —— 不影响任何功能。
|
|
23
|
+
|
|
8
24
|
## 前置条件(重要)
|
|
9
25
|
|
|
10
26
|
这个插件**只是一个桥接层**,真正的服务端是本机运行的 AgentBridge 桥(默认 `http://127.0.0.1:8787`)。
|
|
@@ -80,12 +96,17 @@ pnpm add @chenacc/dsh-agentbridge@latest
|
|
|
80
96
|
| `AGENTBRIDGE_ORIGIN` | `http://127.0.0.1:8787` | 插件连接的 AgentBridge 地址;桥换了端口时设置它 |
|
|
81
97
|
| `AGENTBRIDGE_DATA_DIR` | `~/.agentbridge`(自动启动时) | 桥的会话、配对、密钥与日志目录,不会写进 `~/.dsh` |
|
|
82
98
|
| `AGENTBRIDGE_NO_AUTOSTART` | 未设置 | 设为 `1` 关掉"插件加载时自动起桥",只保留 `/phone` 里的手动提示 |
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
99
|
+
| `AGENTBRIDGE_REMOTE` | `auto` | 走哪条路径:`auto` / `cloudflare` / `named` / `funnel` / `tailscale` / `zerotier` / `lan` |
|
|
100
|
+
| `AGENTBRIDGE_NO_TUNNEL` | 未设置 | 设为 `1` 只用局域网(等价于 `AGENTBRIDGE_REMOTE=lan`) |
|
|
101
|
+
| `AGENTBRIDGE_PUBLIC_ORIGIN` | 未设置 | 自己指定对外的地址;设了它插件不再挑路径 |
|
|
85
102
|
| `AGENTBRIDGE_TUNNEL_URL` | 未设置 | 直接指定一个隧道域名;主要给测试和"隧道自己管"的人用 |
|
|
103
|
+
| `AGENTBRIDGE_CLOUDFLARE_TUNNEL` / `AGENTBRIDGE_CLOUDFLARE_HOSTNAME` | 未设置 | 用已经建好的 Cloudflare 命名隧道 + 自己的域名 |
|
|
86
104
|
| `AGENTBRIDGE_CLOUDFLARED` | 自动查找 | 用你自己那份 `cloudflared`;设了它插件既不搜索也不下载 |
|
|
87
105
|
| `AGENTBRIDGE_NO_DOWNLOAD` | 未设置 | 设为 `1` 禁止插件自动下载 `cloudflared`(会退回局域网) |
|
|
88
106
|
| `AGENTBRIDGE_CLOUDFLARED_URL` | 官方 GitHub Releases | 换一个下载源(内网镜像之类);下载后照样要过 `--version` 校验 |
|
|
107
|
+
| `AGENTBRIDGE_TAILSCALE` / `AGENTBRIDGE_ZEROTIER` | 自动检测 | 手动指定 Tailscale 可执行文件 / ZeroTier 的 IPv4 |
|
|
108
|
+
|
|
109
|
+
路径选择由桥包的 `@chenacc/agentbridge/remote` 负责,CLI 与插件共用同一份实现:同一个顺序、同一把访问密钥。当前实际走的是哪条,看 `/api/health` 的 `remoteProvider` 字段。
|
|
89
110
|
|
|
90
111
|
变量要设在**真正启动 DSH Desktop 的环境里**(插件读 `process.env`),不是设在跑 bridge 的终端里。
|
|
91
112
|
|
|
@@ -105,7 +126,10 @@ pnpm remove @chenacc/dsh-agentbridge
|
|
|
105
126
|
| 版本 | 需要 |
|
|
106
127
|
|---|---|
|
|
107
128
|
| 插件 0.1.x | DSH Desktop(`@deepseek-ai/dsh-commands`、`@deepseek-ai/cordis` 由 DSH 提供)、AgentBridge `0.1.x` |
|
|
108
|
-
| 插件 0.
|
|
129
|
+
| 插件 0.2.x | 同上;桥随插件安装并由插件自动拉起 |
|
|
130
|
+
| 插件 0.3.x | 同上 + 默认开 Cloudflare 隧道;`cloudflared` 缺了自动下载到 `~/.agentbridge/bin` |
|
|
131
|
+
|
|
132
|
+
当前版本:插件 `0.3.3` / 桥 `0.1.4`。插件把隧道逻辑交给桥包(`@chenacc/agentbridge/tunnel`),所以 CLI 的 `/phone` 和这里用的是同一份实现、同一条隧道、同一把访问密钥。
|
|
109
133
|
|
|
110
134
|
插件与 bridge 之间有一份集成版本号握手:bridge 侧要求的最低集成版本比插件旧时,手机端会提示"桌面端集成是旧版",升级插件即可。
|
|
111
135
|
|
package/assets/icon.png
ADDED
|
Binary file
|
|
Binary file
|
package/lib/index.js
CHANGED
|
@@ -6,8 +6,9 @@ import path from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* The tunnel machinery lives in the bridge package, because
|
|
10
|
-
* the same thing — `agentbridge phone` has to publish
|
|
9
|
+
* The tunnel and path-selection machinery lives in the bridge package, because
|
|
10
|
+
* the CLI needs exactly the same thing — `agentbridge phone` has to publish an
|
|
11
|
+
* address too, on whichever network path suits this machine.
|
|
11
12
|
*
|
|
12
13
|
* Loaded lazily rather than at module scope: inside this repository the plugin
|
|
13
14
|
* sits in the bridge package's own tree with no `node_modules` entry to resolve,
|
|
@@ -15,15 +16,27 @@ import { fileURLToPath } from "node:url";
|
|
|
15
16
|
* (which is what the release check does). The published package always carries
|
|
16
17
|
* the dependency, so the relative fallback only runs for development and tests.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
const lazyModules = new Map();
|
|
20
|
+
function loadModule(specifier, fallback) {
|
|
21
|
+
const cached = lazyModules.get(specifier);
|
|
22
|
+
if (cached) return cached;
|
|
23
|
+
const loading = (async () => {
|
|
24
|
+
try {
|
|
25
|
+
return await import(specifier);
|
|
26
|
+
} catch {
|
|
27
|
+
return await import(fallback);
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
lazyModules.set(specifier, loading);
|
|
31
|
+
return loading;
|
|
32
|
+
}
|
|
33
|
+
|
|
19
34
|
async function tunnel() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return tunnelModule;
|
|
35
|
+
return loadModule("@chenacc/agentbridge/tunnel", "../../../src/tunnel.js");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function remote() {
|
|
39
|
+
return loadModule("@chenacc/agentbridge/remote", "../../../src/remote.js");
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
const name = "agentbridge-dsh-phone";
|
|
@@ -299,75 +312,28 @@ function bridgeDataDir() {
|
|
|
299
312
|
return process.env.AGENTBRIDGE_DATA_DIR || path.join(homedir(), ".agentbridge");
|
|
300
313
|
}
|
|
301
314
|
|
|
302
|
-
/**
|
|
303
|
-
* The cloudflared to run, fetching the official build the first time.
|
|
304
|
-
*
|
|
305
|
-
* Remote mode is supposed to be the default, and "the default" cannot depend on
|
|
306
|
-
* the user having heard of cloudflared. So the machine is searched first (a real
|
|
307
|
-
* install wins, whoever put it there), and only when nothing is found does the
|
|
308
|
-
* plugin download Cloudflare's own binary into its data directory — no elevation,
|
|
309
|
-
* nothing in Program Files, removable by deleting one folder.
|
|
310
|
-
*/
|
|
311
|
-
async function resolveCloudflared(log) {
|
|
312
|
-
const { findCloudflared, ensureCloudflared } = await tunnel();
|
|
313
|
-
const installed = findCloudflared({ env: process.env, home: homedir() });
|
|
314
|
-
if (installed) return installed;
|
|
315
|
-
|
|
316
|
-
log("cloudflared was not found; fetching the official build into the bridge's data directory (once)");
|
|
317
|
-
const downloaded = await ensureCloudflared({ dataDir: bridgeDataDir(), env: process.env, log });
|
|
318
|
-
if (!downloaded) {
|
|
319
|
-
log(
|
|
320
|
-
"still no cloudflared, so this machine stays on same-Wi-Fi pairing: "
|
|
321
|
-
+ "install it with `winget install --id Cloudflare.cloudflared`, or download cloudflared-windows-amd64.exe "
|
|
322
|
-
+ "from https://github.com/cloudflare/cloudflared/releases and point AGENTBRIDGE_CLOUDFLARED at it",
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
return downloaded;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
315
|
/**
|
|
329
316
|
* The address the QR code should carry, and the key that unlocks it.
|
|
330
317
|
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
318
|
+
* The decision itself lives in the bridge package (`@chenacc/agentbridge/remote`)
|
|
319
|
+
* so the CLI's `/phone` and this plugin cannot drift apart: one order of
|
|
320
|
+
* providers, one place that knows about Funnel, Tailscale and ZeroTier.
|
|
321
|
+
* Returns null when the machine should stay on the LAN — an explicit opt-out or
|
|
322
|
+
* nothing that could be brought up — and that is logged, never thrown.
|
|
334
323
|
*/
|
|
335
324
|
async function resolveRemoteOrigin(log) {
|
|
336
|
-
const
|
|
337
|
-
if (explicit) return { origin: explicit, accessKey: null, how: "AGENTBRIDGE_PUBLIC_ORIGIN" };
|
|
338
|
-
|
|
339
|
-
const { ensureAccessKey, startQuickTunnel } = await tunnel();
|
|
340
|
-
const supplied = String(process.env.AGENTBRIDGE_TUNNEL_URL ?? "").trim().replace(/\/$/, "");
|
|
341
|
-
if (supplied) return { origin: supplied, accessKey: ensureAccessKey(bridgeDataDir()), how: "AGENTBRIDGE_TUNNEL_URL" };
|
|
342
|
-
|
|
343
|
-
const command = await resolveCloudflared(log);
|
|
344
|
-
if (!command) {
|
|
345
|
-
log("no cloudflared is available, staying on this Wi-Fi only");
|
|
346
|
-
return null;
|
|
347
|
-
}
|
|
348
|
-
|
|
325
|
+
const { resolveRemote } = await remote();
|
|
349
326
|
const origin = localOrigin();
|
|
350
327
|
let port;
|
|
351
328
|
try {
|
|
352
329
|
port = new URL(origin).port || "8787";
|
|
353
330
|
} catch {
|
|
354
|
-
log(`
|
|
355
|
-
return null;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
try {
|
|
359
|
-
const started = await startQuickTunnel({
|
|
360
|
-
command,
|
|
361
|
-
origin: `http://127.0.0.1:${port}`,
|
|
362
|
-
dataDir: bridgeDataDir(),
|
|
363
|
-
log,
|
|
364
|
-
timeoutMs: TUNNEL_TIMEOUT_MS,
|
|
365
|
-
});
|
|
366
|
-
return { origin: started.url, accessKey: ensureAccessKey(bridgeDataDir()), how: started.reused ? "cloudflare (existing tunnel)" : "cloudflare" };
|
|
367
|
-
} catch (error) {
|
|
368
|
-
log(`cloudflare tunnel failed, staying on this Wi-Fi only: ${textFromError(error)}`);
|
|
331
|
+
log(`remote mode skipped: ${origin} is not a usable local origin`);
|
|
369
332
|
return null;
|
|
370
333
|
}
|
|
334
|
+
const decided = await resolveRemote({ env: process.env, dataDir: bridgeDataDir(), port, log });
|
|
335
|
+
if (!decided) return null;
|
|
336
|
+
return { ...decided, how: decided.detail ?? decided.provider };
|
|
371
337
|
}
|
|
372
338
|
|
|
373
339
|
/**
|
|
@@ -415,6 +381,8 @@ async function stopBridge(origin, log) {
|
|
|
415
381
|
function remoteEnv(remote) {
|
|
416
382
|
return {
|
|
417
383
|
AGENTBRIDGE_PUBLIC_ORIGIN: remote.origin,
|
|
384
|
+
// Lets /api/health and the bridge log name the path that won.
|
|
385
|
+
AGENTBRIDGE_REMOTE_PROVIDER: remote.provider ?? "remote",
|
|
418
386
|
...(remote.accessKey ? { AGENTBRIDGE_ACCESS_KEY: remote.accessKey } : {}),
|
|
419
387
|
};
|
|
420
388
|
}
|
|
@@ -1250,6 +1218,10 @@ function apply(ctx) {
|
|
|
1250
1218
|
`会话:${agent.session.id}`,
|
|
1251
1219
|
`模型:${model}`,
|
|
1252
1220
|
pairingAddressNote(registration.pairing.url),
|
|
1221
|
+
// A one-line, no-strings ask. Nothing fires on the user's behalf —
|
|
1222
|
+
// market ranking reads stars, so this is where a willing user can
|
|
1223
|
+
// help without leaving the conversation.
|
|
1224
|
+
"觉得有用就给项目点个星:https://github.com/chenacc1/agentbridge(不影响任何功能)",
|
|
1253
1225
|
].join("\n\n"),
|
|
1254
1226
|
};
|
|
1255
1227
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chenacc/dsh-agentbridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"lib/index.js",
|
|
13
13
|
"cordis.patch.yml",
|
|
14
14
|
"README.md",
|
|
15
|
-
"LICENSE"
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"assets/phone-console-1.png",
|
|
17
|
+
"assets/icon.png"
|
|
16
18
|
],
|
|
17
19
|
"keywords": [
|
|
18
20
|
"dsh-plugin",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
}
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
47
|
-
"@chenacc/agentbridge": "^0.1
|
|
49
|
+
"@chenacc/agentbridge": "^0.2.1"
|
|
48
50
|
},
|
|
49
51
|
"peerDependencies": {
|
|
50
52
|
"@deepseek-ai/dsh-commands": "^0.1.0-rc.7",
|