mslxdff 0.1.175 → 0.1.177
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/package.json +1 -1
- package/src/warp-pool/config.js +2 -2
- package/src/warp-pool/index.js +42 -46
- package/src/warp-pool/nodes.js +2 -1
- package/src/warp-pool/revive.js +117 -0
- package/src/warp-pool/wireproxy.js +6 -2
package/package.json
CHANGED
package/src/warp-pool/config.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { logDir } from "../logs.js";
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/** 缺省关:2026-10-16 真机实测证伪「N 设备 = N 桶」(免费版 WARP 的 IPv4 出口是共享 NAT,见 ADR-0059 修订)。 */
|
|
6
6
|
export const DEFAULTS = {
|
|
7
|
-
enabled:
|
|
7
|
+
enabled: false,
|
|
8
8
|
mode: "leader",
|
|
9
9
|
count: 4,
|
|
10
10
|
basePort: 10800,
|
package/src/warp-pool/index.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
// warp-pool · 装配入口。
|
|
2
2
|
//
|
|
3
|
-
// 定位(见 MODULES.md §0):WARP
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// 关键约束:bootstrap(注册设备 + 起隧道)很慢(注册有 6–15s 间隔、可能退避 60–120s),
|
|
7
|
-
// 因此**绝不阻塞 daemon 启动**——createWarpPool 同步返回,dispatcher 先是空池(直连兜底),
|
|
8
|
-
// bootstrap 完成后 setNodes() 换上真实出口。
|
|
3
|
+
// 定位(见 MODULES.md §0/§10):WARP 池是**增量**出口,不是替代成员自身出口。开关缺省**关**——
|
|
4
|
+
// 2026-10-16 真机实测证伪「N 设备 = N 桶」(免费版 WARP 的 IPv4 出口是共享 NAT);设 MSLXDFF_WARP_POOL=1 才建池。
|
|
9
5
|
import { resolveWarpConfig } from "./config.js";
|
|
10
6
|
import { createRotatingDispatcher } from "./rotate.js";
|
|
11
7
|
import { createHealthMonitor } from "./health.js";
|
|
12
8
|
import { ensureDir, loadNodes, removeNode, saveNode } from "./nodes.js";
|
|
13
9
|
import { registerWarpDevice } from "./register.js";
|
|
14
|
-
import { ensureBinary, resolveAsset, startTunnel, writeTunnelConf } from "./wireproxy.js";
|
|
15
|
-
|
|
10
|
+
import { ensureBinary, probeTunnel, resolveAsset, startTunnel, writeTunnelConf } from "./wireproxy.js";
|
|
11
|
+
import { createReviver, labelExits } from "./revive.js";
|
|
12
|
+
|
|
13
|
+
/** 重拨节流:连续失败指数退避。网络不通的机器绝不能让重注册把 CF 刷到 429。 */
|
|
16
14
|
const REDIAL_MIN_GAP_MS = 5 * 60_000;
|
|
17
15
|
const REDIAL_MAX_GAP_MS = 30 * 60_000;
|
|
18
16
|
|
|
@@ -22,9 +20,13 @@ function gapMs(cfg, rnd = Math.random) {
|
|
|
22
20
|
return Math.round(cfg.registerMinGapMs + rnd() * span);
|
|
23
21
|
}
|
|
24
22
|
|
|
23
|
+
/** 注册响应 → 节点对象(bootstrap 与重拨共用,避免同一份字段表写两遍)。 */
|
|
24
|
+
function nodeFromReg(port, reg, now) {
|
|
25
|
+
return { port, id: reg.id, token: reg.token, v4: reg.v4, v6: reg.v6, endpoint: reg.endpoint, peerKey: reg.peerKey, privateKey: reg.privateKey, registeredAt: new Date(now()).toISOString() };
|
|
26
|
+
}
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
29
|
+
* 建池。开关缺省关,故「未启用」= 未设 MSLXDFF_WARP_POOL=1 或 非 leader;那时返回 null,调用方据此不注入。
|
|
28
30
|
* @returns {null | { dispatcher: object, ready: Promise<void>, close: () => Promise<void>, stats: () => object }}
|
|
29
31
|
*/
|
|
30
32
|
export function createWarpPool({
|
|
@@ -34,6 +36,7 @@ export function createWarpPool({
|
|
|
34
36
|
register = registerWarpDevice,
|
|
35
37
|
ensureBin = ensureBinary,
|
|
36
38
|
start = startTunnel,
|
|
39
|
+
probe = probeTunnel,
|
|
37
40
|
now = Date.now,
|
|
38
41
|
rnd = Math.random,
|
|
39
42
|
wait = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
@@ -44,6 +47,16 @@ export function createWarpPool({
|
|
|
44
47
|
const dispatcher = createRotatingDispatcher({ nodes: [], strategy: cfg.strategy, cooldownMs: cfg.cooldownMs, log });
|
|
45
48
|
/** @type {Map<number, {stop: () => void}>} */
|
|
46
49
|
const tunnels = new Map();
|
|
50
|
+
|
|
51
|
+
/** 复活:用磁盘已有 conf 重起,不重注册(进程挂了 ≠ 设备失效,省 CF 配额)。 */
|
|
52
|
+
async function reviveTunnel(port) {
|
|
53
|
+
if (closed) return false;
|
|
54
|
+
const node = loadNodes(cfg.dir, [port])[0];
|
|
55
|
+
if (!node) return false;
|
|
56
|
+
await bringUp(node);
|
|
57
|
+
return tunnels.has(port);
|
|
58
|
+
}
|
|
59
|
+
const reviver = createReviver({ revive: reviveTunnel, log });
|
|
47
60
|
let binPath = "";
|
|
48
61
|
let closed = false;
|
|
49
62
|
let lastRedialAt = 0;
|
|
@@ -68,7 +81,8 @@ export function createWarpPool({
|
|
|
68
81
|
log,
|
|
69
82
|
onExit: ({ port, code }) => {
|
|
70
83
|
tunnels.delete(port);
|
|
71
|
-
log(`[warp-pool] 隧道 :${port} 退出(code=${code}
|
|
84
|
+
log(`[warp-pool] 隧道 :${port} 退出(code=${code}),尝试复活`);
|
|
85
|
+
void reviver.onExit(port);
|
|
72
86
|
},
|
|
73
87
|
});
|
|
74
88
|
tunnels.set(node.port, t);
|
|
@@ -101,17 +115,7 @@ export function createWarpPool({
|
|
|
101
115
|
try {
|
|
102
116
|
if (nodes.length > 0) await wait(gapMs(cfg, rnd));
|
|
103
117
|
const reg = await register({ log });
|
|
104
|
-
const node =
|
|
105
|
-
port,
|
|
106
|
-
id: reg.id,
|
|
107
|
-
token: reg.token,
|
|
108
|
-
v4: reg.v4,
|
|
109
|
-
v6: reg.v6,
|
|
110
|
-
endpoint: reg.endpoint,
|
|
111
|
-
peerKey: reg.peerKey,
|
|
112
|
-
privateKey: reg.privateKey,
|
|
113
|
-
registeredAt: new Date(now()).toISOString(),
|
|
114
|
-
};
|
|
118
|
+
const node = nodeFromReg(port, reg, now);
|
|
115
119
|
saveNode(cfg.dir, node);
|
|
116
120
|
nodes.push(node);
|
|
117
121
|
log(`[warp-pool] 注册节点 :${port}(v6=${reg.v6})`);
|
|
@@ -129,14 +133,23 @@ export function createWarpPool({
|
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
|
|
132
|
-
//
|
|
133
|
-
const live =
|
|
136
|
+
// 入池前实测探活:WARP 握手不通时 wireproxy 进程照样在跑却转不动流量(挂到超时),那种节点进池会黑洞全部请求
|
|
137
|
+
const live = [];
|
|
138
|
+
for (const n of nodes) {
|
|
139
|
+
if (!tunnels.has(n.port)) continue;
|
|
140
|
+
const r = await probe({ port: n.port, baseUrl, path: cfg.probePath });
|
|
141
|
+
if (r.ok) live.push(n);
|
|
142
|
+
else log(`[warp-pool] 节点 :${n.port} 隧道未通(${r.status || r.error || "?"}),不进池`);
|
|
143
|
+
}
|
|
134
144
|
if (live.length) {
|
|
135
145
|
await dispatcher.setNodes(live.map((n) => ({ port: n.port, uri: `http://127.0.0.1:${n.port}` })));
|
|
136
146
|
log(`[warp-pool] 出口池就绪:${live.length} 个节点`);
|
|
137
147
|
} else {
|
|
138
148
|
log("[warp-pool] 无可用节点,保持直连");
|
|
139
149
|
}
|
|
150
|
+
|
|
151
|
+
// 5. 出口取证:把每台设备的真实出口地址打进日志(免费版 WARP 的 IPv4 是共享 NAT,N 台设备很可能折叠成同一个出口)
|
|
152
|
+
if (live.length) await labelExits({ ports: live.map((n) => n.port), log });
|
|
140
153
|
}
|
|
141
154
|
|
|
142
155
|
const monitor = createHealthMonitor({
|
|
@@ -145,9 +158,7 @@ export function createWarpPool({
|
|
|
145
158
|
probePath: cfg.probePath,
|
|
146
159
|
log,
|
|
147
160
|
onExhausted: async () => {
|
|
148
|
-
// 重拨 =
|
|
149
|
-
// 隧道全活却探活全挂 ⇒ 网络路径问题(实测墙内到 CF 的 UDP 被选择性屏蔽),
|
|
150
|
-
// 重注册换不来出路,只会把 CF 注册接口刷到 429 拉黑——故必须过 redialPlan 这道门。
|
|
161
|
+
// 重拨 = 重新注册换出口。只重拨「进程已死」的隧道:全活却全挂 = 网络路径问题,重注册只会把 CF 刷到 429
|
|
151
162
|
const plan = redialPlan({ ports: cfg.ports, alivePorts: [...tunnels.keys()], lastRedialAt, redialGapMs, now });
|
|
152
163
|
if (plan.reason === "all-alive") {
|
|
153
164
|
log("[warp-pool] 隧道均存活但全池不通,判定为网络路径问题,跳过重拨");
|
|
@@ -168,17 +179,7 @@ export function createWarpPool({
|
|
|
168
179
|
tunnels.delete(port);
|
|
169
180
|
removeNode(cfg.dir, port);
|
|
170
181
|
const reg = await register({ log });
|
|
171
|
-
saveNode(cfg.dir,
|
|
172
|
-
port,
|
|
173
|
-
id: reg.id,
|
|
174
|
-
token: reg.token,
|
|
175
|
-
v4: reg.v4,
|
|
176
|
-
v6: reg.v6,
|
|
177
|
-
endpoint: reg.endpoint,
|
|
178
|
-
peerKey: reg.peerKey,
|
|
179
|
-
privateKey: reg.privateKey,
|
|
180
|
-
registeredAt: new Date(now()).toISOString(),
|
|
181
|
-
});
|
|
182
|
+
saveNode(cfg.dir, nodeFromReg(port, reg, now));
|
|
182
183
|
await bringUp({ port, ...reg });
|
|
183
184
|
} catch (e) {
|
|
184
185
|
log(`[warp-pool] 重拨 :${port} 失败:${String(e?.message || e)}`);
|
|
@@ -186,7 +187,7 @@ export function createWarpPool({
|
|
|
186
187
|
await wait(gapMs(cfg, rnd));
|
|
187
188
|
}
|
|
188
189
|
if (!closed && [...tunnels.keys()].length) {
|
|
189
|
-
// 重拨确实把隧道拉起来了 ⇒
|
|
190
|
+
// 重拨确实把隧道拉起来了 ⇒ 退避复位
|
|
190
191
|
redialGapMs = REDIAL_MIN_GAP_MS;
|
|
191
192
|
await dispatcher.setNodes([...tunnels.keys()].map((port) => ({ port, uri: `http://127.0.0.1:${port}` })));
|
|
192
193
|
}
|
|
@@ -228,19 +229,14 @@ export function createWarpPool({
|
|
|
228
229
|
};
|
|
229
230
|
}
|
|
230
231
|
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* 只取轮换 dispatcher 的便捷入口(隧道进程由模块内的 process exit 钩子兜底清理)。
|
|
234
|
-
* 未启用(开关关 / 非 leader)时返回 undefined —— 调用方直接透传即是"关闭态"。
|
|
235
|
-
*/
|
|
232
|
+
/** 只取轮换 dispatcher 的便捷入口;未启用时返回 undefined(调用方直接透传即"关闭态")。 */
|
|
233
|
+
/** 隧道进程由模块内的 process exit 钩子兜底清理。 */
|
|
236
234
|
export function createWarpDispatcher(opts) {
|
|
237
235
|
return createWarpPool(opts)?.dispatcher;
|
|
238
236
|
}
|
|
239
237
|
|
|
240
238
|
/**
|
|
241
|
-
*
|
|
242
|
-
* 隧道全活却探活全挂 ⇒ 网络路径问题(实测:墙内到 CF 的 UDP 被选择性屏蔽),
|
|
243
|
-
* 此时重拨换不来出路,只会把 CF 注册接口刷到 429 拉黑。
|
|
239
|
+
* 重拨门(纯函数,便于单测):只「有隧道进程已死」且「距上次重拨超过退避间隔」才放行——全活却全挂是网络问题。
|
|
244
240
|
* @returns {{ dead: number[], reason: "ok" | "all-alive" | "throttled" }}
|
|
245
241
|
*/
|
|
246
242
|
export function redialPlan({ ports = [], alivePorts = [], lastRedialAt = 0, redialGapMs = REDIAL_MIN_GAP_MS, now = Date.now } = {}) {
|
package/src/warp-pool/nodes.js
CHANGED
|
@@ -40,6 +40,7 @@ export function loadNode(dir, port) {
|
|
|
40
40
|
v6: String(j.v6 || ""),
|
|
41
41
|
endpoint: String(j.endpoint || ""),
|
|
42
42
|
peerKey: String(j.peerKey || ""),
|
|
43
|
+
privateKey: String(j.privateKey || ""), // 必须读回:bringUp 靠它渲染 conf,漏了就是 PrivateKey = undefined(2026-10-16 真机事故:复用节点的隧道全起不来)
|
|
43
44
|
registeredAt: String(j.registeredAt || ""),
|
|
44
45
|
...(j.cooldownUntil ? { cooldownUntil: Number(j.cooldownUntil) } : {}),
|
|
45
46
|
};
|
|
@@ -65,7 +66,7 @@ export function loadNodes(dir, ports) {
|
|
|
65
66
|
const out = [];
|
|
66
67
|
for (const p of ports) {
|
|
67
68
|
const n = loadNode(dir, p);
|
|
68
|
-
if (n && n.id && n.token) out.push(n);
|
|
69
|
+
if (n && n.id && n.token && n.privateKey) out.push(n);
|
|
69
70
|
}
|
|
70
71
|
return out;
|
|
71
72
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// warp-pool · 复活与取证(真机事故后新增,2026-10-16)。
|
|
2
|
+
//
|
|
3
|
+
// 两件事,都来自组长 VPS 上暴露的缺陷:
|
|
4
|
+
//
|
|
5
|
+
// 1. `revive`: 隧道进程意外退出后**必须自愈**。原先 `onExit` 只把端口从表里删掉、打一行日志就完事,
|
|
6
|
+
// 而唯一的补拉路径 `onExhausted` 要求「全池不通」——3 条活着时探活一直成功,那条死隧道
|
|
7
|
+
// 就**再也不会被拉起**,池静默从 4 降到 3,直到 daemon 重启。(真机::10800 死了就一直死。)
|
|
8
|
+
// 注意:复活走**磁盘上已有的 conf**(不重新注册)——进程挂了不代表设备失效,重注册只会白烧 CF 配额。
|
|
9
|
+
//
|
|
10
|
+
// 2. `labelExits`: 入池后实测各节点**真实出口地址**并标注撞车。WARP 的 IPv4 出口是共享 NAT,
|
|
11
|
+
// 「N 设备」很可能折叠成一个出口;没有这条读数就只能靠人手工 curl 才发现。
|
|
12
|
+
import { probeTunnel } from "./wireproxy.js";
|
|
13
|
+
|
|
14
|
+
/** 出口取证目标:Cloudflare 自己的 trace 端点,回 `ip=` 一行(不烧上游 token)。 */
|
|
15
|
+
export const EXIT_PROBE_URL = "https://cloudflare.com/cdn-cgi/trace";
|
|
16
|
+
|
|
17
|
+
/** 从 cdn-cgi/trace 正文里取出口地址;取不到返回 ""。 */
|
|
18
|
+
export function parseExitIp(text) {
|
|
19
|
+
const m = String(text || "").match(/^\s*ip=(\S+)\s*$/m);
|
|
20
|
+
return m ? m[1] : "";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 按端口独立的退避复活器。
|
|
25
|
+
* @param {{ revive: (port:number)=>Promise<boolean>, minGapMs?: number, maxGapMs?: number,
|
|
26
|
+
* now?: ()=>number, log?: (s:string)=>void }} opts
|
|
27
|
+
*/
|
|
28
|
+
export function createReviver({ revive, minGapMs = 30_000, maxGapMs = 10 * 60_000, now = Date.now, log = () => {} } = {}) {
|
|
29
|
+
/** @type {Map<number, {attempts:number, nextAt:number, busy:boolean}>} */
|
|
30
|
+
const state = new Map();
|
|
31
|
+
|
|
32
|
+
function entry(port) {
|
|
33
|
+
let s = state.get(port);
|
|
34
|
+
if (!s) {
|
|
35
|
+
s = { attempts: 0, nextAt: 0, busy: false };
|
|
36
|
+
state.set(port, s);
|
|
37
|
+
}
|
|
38
|
+
return s;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
/** 进程退出时调用。首次立即复活,之后按 30s→10min 指数退避。 */
|
|
43
|
+
async onExit(port) {
|
|
44
|
+
const s = entry(port);
|
|
45
|
+
const wait = Math.max(0, s.nextAt - now());
|
|
46
|
+
if (wait > 0) {
|
|
47
|
+
log(`[warp-pool] :${port} 复活退避中(还剩 ${Math.round(wait / 1000)}s)`);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (s.busy) return false;
|
|
51
|
+
s.busy = true;
|
|
52
|
+
s.attempts += 1;
|
|
53
|
+
const gap = Math.min(minGapMs * 2 ** (s.attempts - 1), maxGapMs);
|
|
54
|
+
s.nextAt = now() + gap;
|
|
55
|
+
let ok = false;
|
|
56
|
+
try {
|
|
57
|
+
ok = await revive(port);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
log(`[warp-pool] :${port} 复活失败:${String(e?.message || e)}`);
|
|
60
|
+
}
|
|
61
|
+
s.busy = false;
|
|
62
|
+
if (ok) {
|
|
63
|
+
state.delete(port);
|
|
64
|
+
log(`[warp-pool] :${port} 已复活`);
|
|
65
|
+
} else {
|
|
66
|
+
log(`[warp-pool] :${port} 复活未成功(第 ${s.attempts} 次,下次最早 ${Math.round(gap / 1000)}s 后)`);
|
|
67
|
+
}
|
|
68
|
+
return ok;
|
|
69
|
+
},
|
|
70
|
+
/** 探活成功时调用:清掉退避账,恢复正常节奏。 */
|
|
71
|
+
noteHealthy(port) {
|
|
72
|
+
state.delete(port);
|
|
73
|
+
},
|
|
74
|
+
stats() {
|
|
75
|
+
return [...state.entries()].map(([port, s]) => ({
|
|
76
|
+
port,
|
|
77
|
+
attempts: s.attempts,
|
|
78
|
+
nextAt: s.nextAt,
|
|
79
|
+
cooldownMsLeft: Math.max(0, s.nextAt - now()),
|
|
80
|
+
}));
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 入池后实测各节点真实出口地址并打日志(含撞车警告)。
|
|
87
|
+
* 只读探测:打 Cloudflare 的 trace 端点,不碰上游配额。
|
|
88
|
+
* @returns {Promise<{ ip: string, nodes: number[] }[]>} 按出口地址分组的节点清单
|
|
89
|
+
*/
|
|
90
|
+
export async function labelExits({ ports = [], fetchImpl, timeoutMs = 12_000, log = () => {} } = {}) {
|
|
91
|
+
const byIp = new Map();
|
|
92
|
+
let failed = 0;
|
|
93
|
+
for (const port of ports) {
|
|
94
|
+
let ip = "";
|
|
95
|
+
try {
|
|
96
|
+
const res = await probeTunnel({ port, baseUrl: EXIT_PROBE_URL, path: "", fetchImpl, timeoutMs, wantText: true });
|
|
97
|
+
ip = typeof res?.text === "string" ? parseExitIp(res.text) : "";
|
|
98
|
+
} catch {
|
|
99
|
+
ip = "";
|
|
100
|
+
}
|
|
101
|
+
if (!ip) {
|
|
102
|
+
failed += 1;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!byIp.has(ip)) byIp.set(ip, []);
|
|
106
|
+
byIp.get(ip).push(port);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const groups = [...byIp.entries()].map(([ip, nodes]) => ({ ip, nodes }));
|
|
110
|
+
if (groups.length === 1) {
|
|
111
|
+
log(`[warp-pool] ⚠ 出口不分散:${groups[0].nodes.length} 个节点共用同一个出口 ${groups[0].ip}(免费版 WARP 的 IPv4 是共享 NAT)`);
|
|
112
|
+
} else if (groups.length > 1) {
|
|
113
|
+
log(`[warp-pool] 出口分散:${groups.length} 个不同地址 / ${groups.reduce((a, g) => a + g.nodes.length, 0)} 个节点`);
|
|
114
|
+
}
|
|
115
|
+
if (failed) log(`[warp-pool] ${failed} 个节点出口取证失败(不影响其进池)`);
|
|
116
|
+
return groups;
|
|
117
|
+
}
|
|
@@ -91,6 +91,7 @@ function runCommand(cmd, args, { log = () => {} } = {}) {
|
|
|
91
91
|
|
|
92
92
|
/** 写出某节点的 wireproxy 配置(含私钥 ⇒ 0600)。 */
|
|
93
93
|
export function writeTunnelConf(dir, node) {
|
|
94
|
+
if (!node?.privateKey) throw new Error(`节点 :${node?.port} 缺 WireGuard 私钥,拒绝写出一份跑不起来的配置`);
|
|
94
95
|
const { conf } = nodePaths(dir, node.port);
|
|
95
96
|
return writeSecret(conf, renderWireproxyConf({ ...node, port: node.port }));
|
|
96
97
|
}
|
|
@@ -135,7 +136,7 @@ export function startTunnel({ binPath: exe, dir, port, log = () => {}, onExit =
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
/** 探活一个已起的隧道:经该端口访问上游 models 路径(不烧 token)。 */
|
|
138
|
-
export async function probeTunnel({ port, baseUrl = "https://opencode.ai", path = "/zen/v1/models", fetchImpl = compatFetch, timeoutMs = 8000, headers = {} } = {}) {
|
|
139
|
+
export async function probeTunnel({ port, baseUrl = "https://opencode.ai", path = "/zen/v1/models", fetchImpl = compatFetch, timeoutMs = 8000, headers = {}, wantText = false } = {}) {
|
|
139
140
|
const { ProxyAgent } = getUndici();
|
|
140
141
|
const agent = new ProxyAgent({ uri: `http://127.0.0.1:${port}`, connections: 2, keepAliveTimeout: 10_000 });
|
|
141
142
|
try {
|
|
@@ -144,7 +145,10 @@ export async function probeTunnel({ port, baseUrl = "https://opencode.ai", path
|
|
|
144
145
|
signal: AbortSignal.timeout(timeoutMs),
|
|
145
146
|
dispatcher: agent,
|
|
146
147
|
});
|
|
147
|
-
|
|
148
|
+
const base = { ok: res.ok, status: res.status };
|
|
149
|
+
if (!wantText) return base;
|
|
150
|
+
const text = await res.text().catch(() => "");
|
|
151
|
+
return { ...base, text: String(text).slice(0, 2000) };
|
|
148
152
|
} catch (e) {
|
|
149
153
|
return { ok: false, status: 0, error: String(e?.message || e) };
|
|
150
154
|
} finally {
|