@chenacc/dsh-agentbridge 0.1.0 → 0.1.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/lib/index.js +34 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -45,6 +45,36 @@ function textFromError(error) {
|
|
|
45
45
|
return error instanceof Error ? error.message : String(error);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Whether the bridge was simply not there.
|
|
50
|
+
*
|
|
51
|
+
* The distinction matters for the message the user sees: a refused connection
|
|
52
|
+
* means the plugin loaded fine and only the local bridge is missing, which is a
|
|
53
|
+
* setup step — while a 401 from a live bridge is a different problem entirely.
|
|
54
|
+
*/
|
|
55
|
+
function isBridgeAbsent(error) {
|
|
56
|
+
const cause = error && typeof error === "object" ? error.cause?.code ?? "" : "";
|
|
57
|
+
return /ECONNREFUSED|ECONNRESET|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|UND_ERR_CONNECT|fetch failed|socket hang up/i
|
|
58
|
+
.test(`${textFromError(error)} ${cause}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The setup steps a user needs when /phone finds nothing listening. */
|
|
62
|
+
function bridgeSetupText(origin) {
|
|
63
|
+
return [
|
|
64
|
+
`无法连接 AgentBridge 桥(${origin})。插件本身已经加载,缺的是电脑上这个本地服务。`,
|
|
65
|
+
"",
|
|
66
|
+
"在电脑上开一个终端,第一次使用时依次执行:",
|
|
67
|
+
"1) git clone https://github.com/chenacc1/agentbridge.git",
|
|
68
|
+
"2) cd agentbridge && npm install",
|
|
69
|
+
"3) npm start",
|
|
70
|
+
"",
|
|
71
|
+
"已经下载过这个仓库的话,进到那个目录执行 npm start 就行。",
|
|
72
|
+
`桥启动后终端里会打印 ${origin},那时再敲一次 /phone。`,
|
|
73
|
+
"",
|
|
74
|
+
"桥不在默认端口的话,先设置环境变量 AGENTBRIDGE_ORIGIN 指向实际地址,再重启 DSH Desktop。",
|
|
75
|
+
].join("\n");
|
|
76
|
+
}
|
|
77
|
+
|
|
48
78
|
function clipped(value, limit) {
|
|
49
79
|
return typeof value === "string" ? value.slice(0, limit) : "";
|
|
50
80
|
}
|
|
@@ -817,9 +847,12 @@ function apply(ctx) {
|
|
|
817
847
|
].join("\n\n"),
|
|
818
848
|
};
|
|
819
849
|
} catch (error) {
|
|
850
|
+
const origin = String(process.env.AGENTBRIDGE_ORIGIN || DEFAULT_ORIGIN).replace(/\/$/, "");
|
|
820
851
|
return {
|
|
821
852
|
kind: "error",
|
|
822
|
-
text:
|
|
853
|
+
text: isBridgeAbsent(error)
|
|
854
|
+
? bridgeSetupText(origin)
|
|
855
|
+
: `无法连接 AgentBridge:${textFromError(error)}。请确认本机 ${origin} 正在运行。`,
|
|
823
856
|
};
|
|
824
857
|
}
|
|
825
858
|
},
|
package/package.json
CHANGED