open-agents-ai 0.184.21 → 0.184.23
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/index.js +109 -59
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -46470,6 +46470,34 @@ function safeLog(text) {
|
|
|
46470
46470
|
process.stdout.write(text + "\n");
|
|
46471
46471
|
}
|
|
46472
46472
|
}
|
|
46473
|
+
function findPidsByPattern(pattern) {
|
|
46474
|
+
const isWin2 = process.platform === "win32";
|
|
46475
|
+
try {
|
|
46476
|
+
if (isWin2) {
|
|
46477
|
+
const out = nodeExecSync(`wmic process where "CommandLine like '%${pattern.replace(/'/g, "")}%'" get ProcessId /format:csv`, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] });
|
|
46478
|
+
return out.split("\n").map((l) => parseInt(l.split(",").pop() || "", 10)).filter((p) => p > 0 && !isNaN(p));
|
|
46479
|
+
} else {
|
|
46480
|
+
const out = nodeExecSync(`pgrep -f '${pattern}'`, { encoding: "utf-8", timeout: 3e3, stdio: ["pipe", "pipe", "pipe"] });
|
|
46481
|
+
return out.trim().split("\n").map((s) => parseInt(s, 10)).filter((p) => p > 0 && !isNaN(p));
|
|
46482
|
+
}
|
|
46483
|
+
} catch {
|
|
46484
|
+
return [];
|
|
46485
|
+
}
|
|
46486
|
+
}
|
|
46487
|
+
function killPid(pid, signal = "SIGTERM") {
|
|
46488
|
+
try {
|
|
46489
|
+
if (process.platform === "win32") {
|
|
46490
|
+
const flag = signal === "SIGKILL" ? "/F" : "";
|
|
46491
|
+
nodeExecSync(`taskkill /PID ${pid} ${flag}`, { timeout: 3e3, stdio: ["pipe", "pipe", "pipe"] });
|
|
46492
|
+
return true;
|
|
46493
|
+
} else {
|
|
46494
|
+
process.kill(pid, signal);
|
|
46495
|
+
return true;
|
|
46496
|
+
}
|
|
46497
|
+
} catch {
|
|
46498
|
+
return false;
|
|
46499
|
+
}
|
|
46500
|
+
}
|
|
46473
46501
|
async function destroyOrphanProcesses(ctx, global) {
|
|
46474
46502
|
const myPid = process.pid;
|
|
46475
46503
|
const myPpid = process.ppid;
|
|
@@ -46512,28 +46540,58 @@ async function destroyOrphanProcesses(ctx, global) {
|
|
|
46512
46540
|
];
|
|
46513
46541
|
const patternArg = patterns.join("|");
|
|
46514
46542
|
let killed = 0;
|
|
46543
|
+
const isWin2 = process.platform === "win32";
|
|
46515
46544
|
try {
|
|
46516
|
-
|
|
46545
|
+
let psOutput;
|
|
46546
|
+
if (isWin2) {
|
|
46547
|
+
psOutput = nodeExecSync(`wmic process get ProcessId,ParentProcessId,WorkingSetSize,CommandLine /format:csv`, { encoding: "utf-8", timeout: 1e4, stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
46548
|
+
} else {
|
|
46549
|
+
psOutput = nodeExecSync(`ps -eo pid,ppid,rss,%cpu,lstart,args --no-headers 2>/dev/null | grep -E "${patternArg}" | grep -v grep`, { encoding: "utf-8", timeout: 5e3, stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
46550
|
+
}
|
|
46517
46551
|
if (!psOutput)
|
|
46518
46552
|
return 0;
|
|
46519
46553
|
const lines = psOutput.split("\n").filter((l) => l.trim());
|
|
46520
46554
|
const candidates = [];
|
|
46521
|
-
|
|
46522
|
-
const
|
|
46523
|
-
|
|
46524
|
-
|
|
46525
|
-
|
|
46526
|
-
|
|
46527
|
-
|
|
46528
|
-
|
|
46529
|
-
|
|
46530
|
-
|
|
46531
|
-
|
|
46532
|
-
|
|
46555
|
+
if (isWin2) {
|
|
46556
|
+
for (const line of lines) {
|
|
46557
|
+
const cols = line.split(",");
|
|
46558
|
+
if (cols.length < 5)
|
|
46559
|
+
continue;
|
|
46560
|
+
const cmdLine = cols[1] || "";
|
|
46561
|
+
const ppid = parseInt(cols[2], 10) || 0;
|
|
46562
|
+
const pid = parseInt(cols[3], 10) || 0;
|
|
46563
|
+
const wsBytes = parseInt(cols[4], 10) || 0;
|
|
46564
|
+
if (pid === myPid || pid === myPpid || pid <= 10)
|
|
46565
|
+
continue;
|
|
46566
|
+
const matchesPattern = patterns.some((p) => new RegExp(p.replace(/\\\\/g, "\\")).test(cmdLine));
|
|
46567
|
+
if (!matchesPattern)
|
|
46568
|
+
continue;
|
|
46569
|
+
candidates.push({ pid, ppid, rssMb: Math.round(wsBytes / 1048576), cpuPct: 0, cmd: cmdLine.slice(0, 200) });
|
|
46570
|
+
}
|
|
46571
|
+
} else {
|
|
46572
|
+
for (const line of lines) {
|
|
46573
|
+
const parts = line.trim().split(/\s+/);
|
|
46574
|
+
const pid = parseInt(parts[0], 10);
|
|
46575
|
+
const ppid = parseInt(parts[1], 10);
|
|
46576
|
+
const rssKb = parseInt(parts[2], 10) || 0;
|
|
46577
|
+
const cpuPct = parseFloat(parts[3]) || 0;
|
|
46578
|
+
if (pid === myPid || pid === myPpid)
|
|
46579
|
+
continue;
|
|
46580
|
+
if (pid <= 10)
|
|
46581
|
+
continue;
|
|
46582
|
+
const cmd = parts.slice(8).join(" ");
|
|
46583
|
+
candidates.push({ pid, ppid, rssMb: Math.round(rssKb / 1024), cpuPct, cmd });
|
|
46584
|
+
}
|
|
46533
46585
|
}
|
|
46534
46586
|
if (!global) {
|
|
46535
46587
|
const localCandidates = [];
|
|
46536
46588
|
for (const c3 of candidates) {
|
|
46589
|
+
if (isWin2) {
|
|
46590
|
+
if (c3.cmd.includes(cwd4.replace(/\//g, "\\")) || /open-agents|nexus-daemon/.test(c3.cmd)) {
|
|
46591
|
+
localCandidates.push(c3);
|
|
46592
|
+
}
|
|
46593
|
+
continue;
|
|
46594
|
+
}
|
|
46537
46595
|
try {
|
|
46538
46596
|
const procCwd = nodeExecSync(`readlink /proc/${c3.pid}/cwd 2>/dev/null`, { encoding: "utf-8", timeout: 2e3 }).trim();
|
|
46539
46597
|
if (procCwd.startsWith(cwd4)) {
|
|
@@ -46561,28 +46619,19 @@ async function destroyOrphanProcesses(ctx, global) {
|
|
|
46561
46619
|
`);
|
|
46562
46620
|
}
|
|
46563
46621
|
for (const c3 of candidates) {
|
|
46564
|
-
|
|
46622
|
+
if (!isWin2) {
|
|
46565
46623
|
try {
|
|
46566
46624
|
process.kill(-c3.pid, "SIGTERM");
|
|
46567
46625
|
} catch {
|
|
46568
46626
|
}
|
|
46569
|
-
process.kill(c3.pid, "SIGTERM");
|
|
46570
|
-
killed++;
|
|
46571
|
-
} catch {
|
|
46572
|
-
try {
|
|
46573
|
-
process.kill(c3.pid, "SIGKILL");
|
|
46574
|
-
killed++;
|
|
46575
|
-
} catch {
|
|
46576
|
-
}
|
|
46577
46627
|
}
|
|
46628
|
+
if (killPid(c3.pid, "SIGTERM"))
|
|
46629
|
+
killed++;
|
|
46578
46630
|
}
|
|
46579
46631
|
if (killed > 0) {
|
|
46580
46632
|
await new Promise((r) => setTimeout(r, 2e3));
|
|
46581
46633
|
for (const c3 of candidates) {
|
|
46582
|
-
|
|
46583
|
-
process.kill(c3.pid, "SIGKILL");
|
|
46584
|
-
} catch {
|
|
46585
|
-
}
|
|
46634
|
+
killPid(c3.pid, "SIGKILL");
|
|
46586
46635
|
}
|
|
46587
46636
|
}
|
|
46588
46637
|
} catch {
|
|
@@ -48011,22 +48060,14 @@ async function handleSlashCommand(input, ctx) {
|
|
|
48011
48060
|
renderWarning(`Gateway stop: ${err instanceof Error ? err.message : String(err)}`);
|
|
48012
48061
|
}
|
|
48013
48062
|
}
|
|
48014
|
-
|
|
48015
|
-
|
|
48016
|
-
|
|
48017
|
-
|
|
48018
|
-
|
|
48019
|
-
if (p > 0) {
|
|
48020
|
-
try {
|
|
48021
|
-
process.kill(p, "SIGTERM");
|
|
48022
|
-
} catch {
|
|
48023
|
-
}
|
|
48024
|
-
}
|
|
48025
|
-
}
|
|
48026
|
-
if (pids.length > 0 && pids[0])
|
|
48027
|
-
renderInfo(`Killed ${pids.length} orphaned cloudflared process(es).`);
|
|
48028
|
-
} catch {
|
|
48063
|
+
const orphanPids = findPidsByPattern("cloudflared tunnel --url http");
|
|
48064
|
+
let orphansKilled = 0;
|
|
48065
|
+
for (const pid of orphanPids) {
|
|
48066
|
+
if (killPid(pid))
|
|
48067
|
+
orphansKilled++;
|
|
48029
48068
|
}
|
|
48069
|
+
if (orphansKilled > 0)
|
|
48070
|
+
renderInfo(`Killed ${orphansKilled} orphaned cloudflared process(es).`);
|
|
48030
48071
|
renderInfo("Sponsorship removed.");
|
|
48031
48072
|
return "handled";
|
|
48032
48073
|
}
|
|
@@ -48067,20 +48108,15 @@ async function handleSlashCommand(input, ctx) {
|
|
|
48067
48108
|
const existingGateway = ctx.getExposeGateway?.();
|
|
48068
48109
|
const managedPid = existingGateway?._cloudflaredPid || null;
|
|
48069
48110
|
if (!existingGateway?.isActive) {
|
|
48070
|
-
|
|
48071
|
-
|
|
48072
|
-
|
|
48073
|
-
|
|
48074
|
-
|
|
48075
|
-
|
|
48076
|
-
|
|
48077
|
-
|
|
48078
|
-
|
|
48079
|
-
if (orphanPids.length > 0) {
|
|
48080
|
-
renderInfo(`Cleaned up ${orphanPids.length} orphaned tunnel(s) from previous session.`);
|
|
48081
|
-
await new Promise((r) => setTimeout(r, 2e3));
|
|
48082
|
-
}
|
|
48083
|
-
} catch {
|
|
48111
|
+
const staleOrphans = findPidsByPattern("cloudflared tunnel --url http").filter((p) => p !== managedPid);
|
|
48112
|
+
let cleanedUp = 0;
|
|
48113
|
+
for (const pid of staleOrphans) {
|
|
48114
|
+
if (killPid(pid))
|
|
48115
|
+
cleanedUp++;
|
|
48116
|
+
}
|
|
48117
|
+
if (cleanedUp > 0) {
|
|
48118
|
+
renderInfo(`Cleaned up ${cleanedUp} orphaned tunnel(s) from previous session.`);
|
|
48119
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
48084
48120
|
}
|
|
48085
48121
|
}
|
|
48086
48122
|
const tunnelAlreadyActive = existingGateway?.isActive && existingGateway?.tunnelUrl;
|
|
@@ -48109,15 +48145,29 @@ async function handleSlashCommand(input, ctx) {
|
|
|
48109
48145
|
}
|
|
48110
48146
|
}
|
|
48111
48147
|
if (config.transport.libp2p && ctx.exposeStart) {
|
|
48148
|
+
let daemonReady = false;
|
|
48112
48149
|
try {
|
|
48113
48150
|
const nexus = new NexusTool(projectDir);
|
|
48114
|
-
renderInfo("
|
|
48151
|
+
renderInfo("Starting nexus daemon...");
|
|
48115
48152
|
await nexus.execute({ action: "connect" });
|
|
48116
|
-
|
|
48153
|
+
for (let wait = 0; wait < 15; wait++) {
|
|
48154
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
48155
|
+
try {
|
|
48156
|
+
const status = await nexus.execute({ action: "status" });
|
|
48157
|
+
if (typeof status === "string" && status.includes("connected")) {
|
|
48158
|
+
daemonReady = true;
|
|
48159
|
+
renderInfo("Nexus daemon ready.");
|
|
48160
|
+
break;
|
|
48161
|
+
}
|
|
48162
|
+
} catch {
|
|
48163
|
+
}
|
|
48164
|
+
}
|
|
48165
|
+
if (!daemonReady)
|
|
48166
|
+
renderWarning("Nexus daemon did not become ready in 15s. P2P may fail.");
|
|
48117
48167
|
} catch (err) {
|
|
48118
|
-
renderWarning(`Nexus: ${err instanceof Error ? err.message : String(err)}`);
|
|
48168
|
+
renderWarning(`Nexus connect: ${err instanceof Error ? err.message : String(err)}`);
|
|
48119
48169
|
}
|
|
48120
|
-
if (!p2pAlreadyActive) {
|
|
48170
|
+
if (daemonReady && !p2pAlreadyActive) {
|
|
48121
48171
|
try {
|
|
48122
48172
|
const url = await ctx.exposeStart("ollama", void 0, "libp2p");
|
|
48123
48173
|
if (url)
|
package/package.json
CHANGED