@chenacc/dsh-agentbridge 0.2.2 → 0.2.4
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/index.js +34 -7
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { closeSync, existsSync, mkdirSync, openSync } from "node:fs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
@@ -180,6 +180,28 @@ async function startBridge(origin, log = () => {}) {
|
|
|
180
180
|
return false;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
const dataDir = process.env.AGENTBRIDGE_DATA_DIR || path.join(homedir(), ".agentbridge");
|
|
184
|
+
const env = {
|
|
185
|
+
...process.env,
|
|
186
|
+
AGENTBRIDGE_PORT: process.env.AGENTBRIDGE_PORT || port,
|
|
187
|
+
AGENTBRIDGE_DATA_DIR: dataDir,
|
|
188
|
+
};
|
|
189
|
+
// Under Electron `process.execPath` is DSH Desktop itself, not node: launching
|
|
190
|
+
// it with a .js path starts the app again and no server ever binds. Electron
|
|
191
|
+
// ships a Node runtime behind ELECTRON_RUN_AS_NODE, which is exactly this.
|
|
192
|
+
if (process.versions.electron) env.ELECTRON_RUN_AS_NODE = "1";
|
|
193
|
+
|
|
194
|
+
// Keep the child's own output: when a spawned bridge dies, its stderr is the
|
|
195
|
+
// only place that says why (port in use, missing module, bad config).
|
|
196
|
+
let logFd = "ignore";
|
|
197
|
+
try {
|
|
198
|
+
const logDir = path.join(dataDir, "logs");
|
|
199
|
+
mkdirSync(logDir, { recursive: true });
|
|
200
|
+
logFd = openSync(path.join(logDir, "autostart.log"), "a");
|
|
201
|
+
} catch {
|
|
202
|
+
// No writable data dir: run without output capture rather than not at all.
|
|
203
|
+
}
|
|
204
|
+
|
|
183
205
|
try {
|
|
184
206
|
// Loaded lazily: the plugin normally runs with a bridge already up, so the
|
|
185
207
|
// child-process machinery is dead weight on the common path.
|
|
@@ -192,18 +214,22 @@ async function startBridge(origin, log = () => {}) {
|
|
|
192
214
|
// some internal folder.
|
|
193
215
|
cwd: homedir(),
|
|
194
216
|
detached: true,
|
|
195
|
-
stdio: "ignore",
|
|
217
|
+
stdio: ["ignore", logFd, logFd],
|
|
196
218
|
windowsHide: true,
|
|
197
|
-
env
|
|
198
|
-
...process.env,
|
|
199
|
-
AGENTBRIDGE_PORT: process.env.AGENTBRIDGE_PORT || port,
|
|
200
|
-
AGENTBRIDGE_DATA_DIR: process.env.AGENTBRIDGE_DATA_DIR || path.join(homedir(), ".agentbridge"),
|
|
201
|
-
},
|
|
219
|
+
env,
|
|
202
220
|
});
|
|
203
221
|
child.unref();
|
|
204
222
|
} catch (error) {
|
|
205
223
|
log(`auto-start failed to spawn ${entry}: ${textFromError(error)}`);
|
|
206
224
|
return false;
|
|
225
|
+
} finally {
|
|
226
|
+
if (typeof logFd === "number") {
|
|
227
|
+
try {
|
|
228
|
+
closeSync(logFd);
|
|
229
|
+
} catch {
|
|
230
|
+
// The child holds its own duplicate; nothing to recover here.
|
|
231
|
+
}
|
|
232
|
+
}
|
|
207
233
|
}
|
|
208
234
|
|
|
209
235
|
const deadline = Date.now() + AUTOSTART_TIMEOUT_MS;
|
|
@@ -984,6 +1010,7 @@ function apply(ctx) {
|
|
|
984
1010
|
`项目:${registration.project.cwd}`,
|
|
985
1011
|
`会话:${agent.session.id}`,
|
|
986
1012
|
`模型:${model}`,
|
|
1013
|
+
"手机需与电脑连同一个 Wi-Fi。扫码后若提示「该地址为 IP 地址」或「将要访问」,点「继续访问」即可。",
|
|
987
1014
|
].join("\n\n"),
|
|
988
1015
|
};
|
|
989
1016
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chenacc/dsh-agentbridge",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@chenacc/agentbridge": "^0.1.
|
|
47
|
+
"@chenacc/agentbridge": "^0.1.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@deepseek-ai/dsh-commands": "^0.1.0-rc.7",
|