echo-t3-bridge 0.1.0 → 0.1.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/dist/cli.mjs +26 -5
- package/dist/tsc/local-t3.js +31 -6
- package/package.json +1 -1
- package/scripts/service.mjs +23 -2
package/dist/cli.mjs
CHANGED
|
@@ -1036,6 +1036,7 @@ var LocalT3Client = class {
|
|
|
1036
1036
|
lastProviders = [];
|
|
1037
1037
|
pending = /* @__PURE__ */ new Map();
|
|
1038
1038
|
streams = /* @__PURE__ */ new Map();
|
|
1039
|
+
streamThreads = /* @__PURE__ */ new Map();
|
|
1039
1040
|
subscribedThreads = /* @__PURE__ */ new Set();
|
|
1040
1041
|
wantedThreads = /* @__PURE__ */ new Map();
|
|
1041
1042
|
terminalMetadata = /* @__PURE__ */ new Map();
|
|
@@ -1083,6 +1084,7 @@ var LocalT3Client = class {
|
|
|
1083
1084
|
const wasConnected = this.connected;
|
|
1084
1085
|
this.connected = false;
|
|
1085
1086
|
this.subscribedThreads.clear();
|
|
1087
|
+
this.streamThreads.clear();
|
|
1086
1088
|
this.terminalStreams.clear();
|
|
1087
1089
|
this.terminalMetadata.clear();
|
|
1088
1090
|
this.streams.clear();
|
|
@@ -1214,6 +1216,11 @@ var LocalT3Client = class {
|
|
|
1214
1216
|
}
|
|
1215
1217
|
if (msg._tag === "Exit") {
|
|
1216
1218
|
this.streams.delete(reqId);
|
|
1219
|
+
const exitedThread = this.streamThreads.get(reqId);
|
|
1220
|
+
if (exitedThread) {
|
|
1221
|
+
this.streamThreads.delete(reqId);
|
|
1222
|
+
this.subscribedThreads.delete(exitedThread);
|
|
1223
|
+
}
|
|
1217
1224
|
const pending = this.pending.get(reqId);
|
|
1218
1225
|
if (!pending) return;
|
|
1219
1226
|
this.pending.delete(reqId);
|
|
@@ -1346,22 +1353,32 @@ var LocalT3Client = class {
|
|
|
1346
1353
|
ensureThreadSubscribed(threadId, afterSequence = 0) {
|
|
1347
1354
|
if (!threadId) return;
|
|
1348
1355
|
const prev = this.wantedThreads.get(threadId) ?? 0;
|
|
1349
|
-
|
|
1350
|
-
|
|
1356
|
+
const effectiveAfter = Math.max(prev, afterSequence);
|
|
1357
|
+
if (effectiveAfter > prev || !this.wantedThreads.has(threadId)) {
|
|
1358
|
+
this.wantedThreads.set(threadId, effectiveAfter);
|
|
1351
1359
|
}
|
|
1352
1360
|
if (this.subscribedThreads.has(threadId) || !this.isConnected()) return;
|
|
1353
1361
|
this.subscribedThreads.add(threadId);
|
|
1354
1362
|
const payload = { threadId };
|
|
1355
|
-
if (
|
|
1363
|
+
if (effectiveAfter > 0) payload.afterSequence = effectiveAfter;
|
|
1356
1364
|
const reqId = this.startStream("orchestration.subscribeThread", payload, (rawItem) => {
|
|
1357
1365
|
if (!rawItem || typeof rawItem !== "object") return;
|
|
1358
1366
|
const env = rawItem;
|
|
1367
|
+
if (env.kind === "snapshot" && typeof env.snapshotSequence === "number") {
|
|
1368
|
+
const cur2 = this.wantedThreads.get(threadId) ?? 0;
|
|
1369
|
+
if (env.snapshotSequence > cur2) {
|
|
1370
|
+
this.wantedThreads.set(threadId, env.snapshotSequence);
|
|
1371
|
+
}
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1359
1374
|
if (env.kind !== "event" || typeof env.sequence !== "number" || !env.event) return;
|
|
1360
1375
|
const cur = this.wantedThreads.get(threadId) ?? 0;
|
|
1361
1376
|
if (env.sequence > cur) this.wantedThreads.set(threadId, env.sequence);
|
|
1362
1377
|
this.callbacks.onThreadEvent({ sequence: env.sequence, event: env.event });
|
|
1363
1378
|
});
|
|
1364
|
-
if (
|
|
1379
|
+
if (reqId) {
|
|
1380
|
+
this.streamThreads.set(reqId, threadId);
|
|
1381
|
+
} else {
|
|
1365
1382
|
this.subscribedThreads.delete(threadId);
|
|
1366
1383
|
}
|
|
1367
1384
|
}
|
|
@@ -1514,7 +1531,11 @@ var LocalT3Client = class {
|
|
|
1514
1531
|
message: text.trim() || `HTTP ${resp.status}`
|
|
1515
1532
|
};
|
|
1516
1533
|
}
|
|
1517
|
-
|
|
1534
|
+
const parsed = JSON.parse(text);
|
|
1535
|
+
if (parsed && typeof parsed === "object" && typeof parsed.sequence !== "number" && typeof parsed.snapshotSequence === "number") {
|
|
1536
|
+
parsed.sequence = parsed.snapshotSequence;
|
|
1537
|
+
}
|
|
1538
|
+
return parsed;
|
|
1518
1539
|
}
|
|
1519
1540
|
async resolveDefaultCwd(override) {
|
|
1520
1541
|
const trimmed = (override ?? "").trim();
|
package/dist/tsc/local-t3.js
CHANGED
|
@@ -194,6 +194,7 @@ export class LocalT3Client {
|
|
|
194
194
|
lastProviders = [];
|
|
195
195
|
pending = new Map();
|
|
196
196
|
streams = new Map();
|
|
197
|
+
streamThreads = new Map();
|
|
197
198
|
subscribedThreads = new Set();
|
|
198
199
|
wantedThreads = new Map();
|
|
199
200
|
terminalMetadata = new Map();
|
|
@@ -242,6 +243,7 @@ export class LocalT3Client {
|
|
|
242
243
|
const wasConnected = this.connected;
|
|
243
244
|
this.connected = false;
|
|
244
245
|
this.subscribedThreads.clear();
|
|
246
|
+
this.streamThreads.clear();
|
|
245
247
|
this.terminalStreams.clear();
|
|
246
248
|
this.terminalMetadata.clear();
|
|
247
249
|
this.streams.clear();
|
|
@@ -388,6 +390,11 @@ export class LocalT3Client {
|
|
|
388
390
|
}
|
|
389
391
|
if (msg._tag === 'Exit') {
|
|
390
392
|
this.streams.delete(reqId);
|
|
393
|
+
const exitedThread = this.streamThreads.get(reqId);
|
|
394
|
+
if (exitedThread) {
|
|
395
|
+
this.streamThreads.delete(reqId);
|
|
396
|
+
this.subscribedThreads.delete(exitedThread);
|
|
397
|
+
}
|
|
391
398
|
const pending = this.pending.get(reqId);
|
|
392
399
|
if (!pending)
|
|
393
400
|
return;
|
|
@@ -531,19 +538,27 @@ export class LocalT3Client {
|
|
|
531
538
|
if (!threadId)
|
|
532
539
|
return;
|
|
533
540
|
const prev = this.wantedThreads.get(threadId) ?? 0;
|
|
534
|
-
|
|
535
|
-
|
|
541
|
+
const effectiveAfter = Math.max(prev, afterSequence);
|
|
542
|
+
if (effectiveAfter > prev || !this.wantedThreads.has(threadId)) {
|
|
543
|
+
this.wantedThreads.set(threadId, effectiveAfter);
|
|
536
544
|
}
|
|
537
545
|
if (this.subscribedThreads.has(threadId) || !this.isConnected())
|
|
538
546
|
return;
|
|
539
547
|
this.subscribedThreads.add(threadId);
|
|
540
548
|
const payload = { threadId };
|
|
541
|
-
if (
|
|
542
|
-
payload.afterSequence =
|
|
549
|
+
if (effectiveAfter > 0)
|
|
550
|
+
payload.afterSequence = effectiveAfter;
|
|
543
551
|
const reqId = this.startStream('orchestration.subscribeThread', payload, (rawItem) => {
|
|
544
552
|
if (!rawItem || typeof rawItem !== 'object')
|
|
545
553
|
return;
|
|
546
554
|
const env = rawItem;
|
|
555
|
+
if (env.kind === 'snapshot' && typeof env.snapshotSequence === 'number') {
|
|
556
|
+
const cur = this.wantedThreads.get(threadId) ?? 0;
|
|
557
|
+
if (env.snapshotSequence > cur) {
|
|
558
|
+
this.wantedThreads.set(threadId, env.snapshotSequence);
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
547
562
|
if (env.kind !== 'event' || typeof env.sequence !== 'number' || !env.event)
|
|
548
563
|
return;
|
|
549
564
|
const cur = this.wantedThreads.get(threadId) ?? 0;
|
|
@@ -551,7 +566,10 @@ export class LocalT3Client {
|
|
|
551
566
|
this.wantedThreads.set(threadId, env.sequence);
|
|
552
567
|
this.callbacks.onThreadEvent({ sequence: env.sequence, event: env.event });
|
|
553
568
|
});
|
|
554
|
-
if (
|
|
569
|
+
if (reqId) {
|
|
570
|
+
this.streamThreads.set(reqId, threadId);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
555
573
|
this.subscribedThreads.delete(threadId);
|
|
556
574
|
}
|
|
557
575
|
}
|
|
@@ -707,7 +725,14 @@ export class LocalT3Client {
|
|
|
707
725
|
message: text.trim() || `HTTP ${resp.status}`,
|
|
708
726
|
};
|
|
709
727
|
}
|
|
710
|
-
|
|
728
|
+
const parsed = JSON.parse(text);
|
|
729
|
+
if (parsed &&
|
|
730
|
+
typeof parsed === 'object' &&
|
|
731
|
+
typeof parsed.sequence !== 'number' &&
|
|
732
|
+
typeof parsed.snapshotSequence === 'number') {
|
|
733
|
+
parsed.sequence = parsed.snapshotSequence;
|
|
734
|
+
}
|
|
735
|
+
return parsed;
|
|
711
736
|
}
|
|
712
737
|
async resolveDefaultCwd(override) {
|
|
713
738
|
const trimmed = (override ?? '').trim();
|
package/package.json
CHANGED
package/scripts/service.mjs
CHANGED
|
@@ -8,6 +8,16 @@ import { spawnSync } from 'node:child_process';
|
|
|
8
8
|
|
|
9
9
|
const SERVICE_NAME = 'echo-t3-bridge';
|
|
10
10
|
const LAUNCHD_LABEL = 'top.stormapex.echo-t3-bridge';
|
|
11
|
+
const PROXY_ENV_KEYS = [
|
|
12
|
+
'http_proxy',
|
|
13
|
+
'https_proxy',
|
|
14
|
+
'all_proxy',
|
|
15
|
+
'no_proxy',
|
|
16
|
+
'HTTP_PROXY',
|
|
17
|
+
'HTTPS_PROXY',
|
|
18
|
+
'ALL_PROXY',
|
|
19
|
+
'NO_PROXY',
|
|
20
|
+
];
|
|
11
21
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
12
22
|
const cliEntry = join(root, 'dist', 'cli.mjs');
|
|
13
23
|
const action = process.argv[2];
|
|
@@ -59,6 +69,11 @@ function buildServicePath() {
|
|
|
59
69
|
return [...new Set([...extras, ...current])].join(':');
|
|
60
70
|
}
|
|
61
71
|
|
|
72
|
+
function collectProxyEnvEntries() {
|
|
73
|
+
return PROXY_ENV_KEYS.map((key) => [key, process.env[key]])
|
|
74
|
+
.filter(([, val]) => typeof val === 'string' && val.trim().length > 0);
|
|
75
|
+
}
|
|
76
|
+
|
|
62
77
|
function xmlEscape(val) {
|
|
63
78
|
return String(val)
|
|
64
79
|
.replaceAll('&', '&')
|
|
@@ -90,6 +105,9 @@ async function manageLaunchd(mode) {
|
|
|
90
105
|
await mkdir(dirname(target), { recursive: true });
|
|
91
106
|
await mkdir(logDir, { recursive: true, mode: 0o700 });
|
|
92
107
|
|
|
108
|
+
const proxyXml = collectProxyEnvEntries()
|
|
109
|
+
.map(([k, v]) => ` <key>${xmlEscape(k)}</key><string>${xmlEscape(v)}</string>`)
|
|
110
|
+
.join('\n');
|
|
93
111
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
94
112
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
95
113
|
<plist version="1.0"><dict>
|
|
@@ -105,7 +123,7 @@ async function manageLaunchd(mode) {
|
|
|
105
123
|
<key>HOME</key><string>${xmlEscape(homedir())}</string>
|
|
106
124
|
<key>SHELL</key><string>${xmlEscape(process.env.SHELL ?? '/bin/zsh')}</string>
|
|
107
125
|
<key>PATH</key><string>${xmlEscape(buildServicePath())}</string>
|
|
108
|
-
</dict>
|
|
126
|
+
${proxyXml ? `${proxyXml}\n` : ''} </dict>
|
|
109
127
|
<key>RunAtLoad</key><true/>
|
|
110
128
|
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
111
129
|
<key>ThrottleInterval</key><integer>5</integer>
|
|
@@ -132,6 +150,9 @@ async function manageSystemd(mode) {
|
|
|
132
150
|
|
|
133
151
|
runCmd('systemctl', ['--user', 'stop', SERVICE_NAME], true);
|
|
134
152
|
await mkdir(dirname(target), { recursive: true });
|
|
153
|
+
const proxyLines = collectProxyEnvEntries()
|
|
154
|
+
.map(([k, v]) => `Environment="${k}=${v}"`)
|
|
155
|
+
.join('\n');
|
|
135
156
|
const unit = `[Unit]
|
|
136
157
|
Description=Echo T3 Bridge (zero-fork local T3 to Echo Hub reverse tunnel)
|
|
137
158
|
After=network-online.target
|
|
@@ -142,7 +163,7 @@ Type=simple
|
|
|
142
163
|
Environment="ECHO_T3_BRIDGE_CONFIG=${configPath}"
|
|
143
164
|
Environment="ECHO_T3_BRIDGE_DATA_DIR=${dataDir}"
|
|
144
165
|
Environment="PATH=${buildServicePath()}"
|
|
145
|
-
ExecStart="${process.execPath}" "${cliEntry}" run
|
|
166
|
+
${proxyLines ? `${proxyLines}\n` : ''}ExecStart="${process.execPath}" "${cliEntry}" run
|
|
146
167
|
Restart=always
|
|
147
168
|
RestartSec=3
|
|
148
169
|
|