echo-t3-bridge 0.1.3 → 0.1.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/dist/cli.mjs CHANGED
@@ -216,7 +216,7 @@ import { homedir as homedir2, hostname } from "node:os";
216
216
  import { dirname, join as join2, resolve } from "node:path";
217
217
  var DEFAULT_HUB_SERVER = "https://wq.stormapex.top";
218
218
  var DEFAULT_LOCAL_T3_URL = "http://127.0.0.1:3773";
219
- var APP_VERSION = "0.1.3";
219
+ var APP_VERSION = "0.1.4";
220
220
  function defaultDataDir() {
221
221
  if (process.env.ECHO_T3_BRIDGE_DATA_DIR?.trim()) {
222
222
  return resolve(process.env.ECHO_T3_BRIDGE_DATA_DIR.trim());
@@ -1959,8 +1959,13 @@ function createHubWebSocketAgent(targetUrl) {
1959
1959
  return void 0;
1960
1960
  }
1961
1961
  }
1962
+ const agent = new HttpConnectAgent({ keepAlive: false });
1963
+ Object.assign(agent, {
1964
+ protocol: isSecureTarget ? "https:" : "http:",
1965
+ defaultPort: isSecureTarget ? 443 : 80
1966
+ });
1962
1967
  return {
1963
- agent: new HttpConnectAgent({ keepAlive: false }),
1968
+ agent,
1964
1969
  proxyUrl: proxyUrlStr
1965
1970
  };
1966
1971
  }
@@ -3,7 +3,7 @@ import { homedir, hostname } from 'node:os';
3
3
  import { dirname, join, resolve } from 'node:path';
4
4
  export const DEFAULT_HUB_SERVER = 'https://wq.stormapex.top';
5
5
  export const DEFAULT_LOCAL_T3_URL = 'http://127.0.0.1:3773';
6
- export const APP_VERSION = '0.1.3';
6
+ export const APP_VERSION = '0.1.4';
7
7
  export function defaultDataDir() {
8
8
  if (process.env.ECHO_T3_BRIDGE_DATA_DIR?.trim()) {
9
9
  return resolve(process.env.ECHO_T3_BRIDGE_DATA_DIR.trim());
package/dist/tsc/proxy.js CHANGED
@@ -277,8 +277,14 @@ export function createHubWebSocketAgent(targetUrl) {
277
277
  return undefined;
278
278
  }
279
279
  }
280
+ const agent = new HttpConnectAgent({ keepAlive: false });
281
+ // Node's `https.request` (used by `ws` for `wss://`) validates `agent.protocol === 'https:'`.
282
+ Object.assign(agent, {
283
+ protocol: isSecureTarget ? 'https:' : 'http:',
284
+ defaultPort: isSecureTarget ? 443 : 80,
285
+ });
280
286
  return {
281
- agent: new HttpConnectAgent({ keepAlive: false }),
287
+ agent,
282
288
  proxyUrl: proxyUrlStr,
283
289
  };
284
290
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echo-t3-bridge",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Zero-fork bridge connecting an unmodified local T3 Code server to Echo Hub over a reverse WebSocket tunnel.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -132,6 +132,11 @@ function runCmd(cmd, args, ignoreFailure = false) {
132
132
  if (!ignoreFailure && res.status !== 0) {
133
133
  process.exit(res.status ?? 1);
134
134
  }
135
+ return res.status ?? 0;
136
+ }
137
+
138
+ function sleepMs(ms) {
139
+ return new Promise((resolve) => setTimeout(resolve, ms));
135
140
  }
136
141
 
137
142
  async function manageLaunchd(mode) {
@@ -177,7 +182,26 @@ ${proxyXml ? `${proxyXml}\n` : ''} </dict>
177
182
  `;
178
183
  await writeFile(target, plist, { mode: 0o600 });
179
184
  runCmd('launchctl', ['enable', `${domain}/${LAUNCHD_LABEL}`], true);
180
- runCmd('launchctl', ['bootstrap', domain, target]);
185
+ // macOS launchd tears down bootout asynchronously; retry bootstrap briefly before failing.
186
+ let bootstrapped = false;
187
+ for (let attempt = 1; attempt <= 4; attempt++) {
188
+ if (attempt > 1) {
189
+ await sleepMs(700);
190
+ runCmd('launchctl', ['bootout', `${domain}/${LAUNCHD_LABEL}`], true);
191
+ await sleepMs(400);
192
+ }
193
+ const status = runCmd('launchctl', ['bootstrap', domain, target], true);
194
+ if (status === 0) {
195
+ bootstrapped = true;
196
+ break;
197
+ }
198
+ }
199
+ if (!bootstrapped) {
200
+ const kicked = runCmd('launchctl', ['kickstart', '-k', `${domain}/${LAUNCHD_LABEL}`], true);
201
+ if (kicked !== 0) {
202
+ process.exit(1);
203
+ }
204
+ }
181
205
  console.log(`✓ 已安装并启动 macOS 后台服务: ${LAUNCHD_LABEL}`);
182
206
  console.log(` 日志目录: ${logDir}`);
183
207
  }