@madarco/agentbox 0.11.0 → 0.11.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/CHANGELOG.md +19 -0
- package/dist/_cloud-attach-XWCVLO5V.js +15 -0
- package/dist/{chunk-NVSRGC5W.js → chunk-GYJ62GFL.js} +37 -17
- package/dist/chunk-GYJ62GFL.js.map +1 -0
- package/dist/{chunk-D4Q2RUQI.js → chunk-MXXXKJYS.js} +2 -2
- package/dist/{chunk-GUNUBIRB.js → chunk-ZJXTIH6C.js} +51 -22
- package/dist/{chunk-GUNUBIRB.js.map → chunk-ZJXTIH6C.js.map} +1 -1
- package/dist/{dist-ZEGIMYWZ.js → dist-ASLPRUQR.js} +2 -2
- package/dist/{dist-PJFJNXO2.js → dist-PTJ6CEQY.js} +3 -3
- package/dist/{dist-HT2YV6PB.js → dist-RAZP76VX.js} +3 -3
- package/dist/{dist-4SUIXKSD.js → dist-WMQDMTWS.js} +3 -3
- package/dist/index.js +83 -41
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/runtime/relay/bin.cjs +32 -17
- package/dist/_cloud-attach-6C5NMOHD.js +0 -13
- package/dist/chunk-NVSRGC5W.js.map +0 -1
- /package/dist/{_cloud-attach-6C5NMOHD.js.map → _cloud-attach-XWCVLO5V.js.map} +0 -0
- /package/dist/{chunk-D4Q2RUQI.js.map → chunk-MXXXKJYS.js.map} +0 -0
- /package/dist/{dist-ZEGIMYWZ.js.map → dist-ASLPRUQR.js.map} +0 -0
- /package/dist/{dist-PJFJNXO2.js.map → dist-PTJ6CEQY.js.map} +0 -0
- /package/dist/{dist-HT2YV6PB.js.map → dist-RAZP76VX.js.map} +0 -0
- /package/dist/{dist-4SUIXKSD.js.map → dist-WMQDMTWS.js.map} +0 -0
|
@@ -1870,42 +1870,71 @@ async function loadQueue() {
|
|
|
1870
1870
|
out.sort((a, b) => a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : 0);
|
|
1871
1871
|
return out;
|
|
1872
1872
|
}
|
|
1873
|
+
function processAlive(pid) {
|
|
1874
|
+
try {
|
|
1875
|
+
process.kill(pid, 0);
|
|
1876
|
+
return true;
|
|
1877
|
+
} catch {
|
|
1878
|
+
return false;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
function countInFlightCreateJobs(jobs, accountedBoxIds) {
|
|
1882
|
+
let n = 0;
|
|
1883
|
+
for (const j of jobs) {
|
|
1884
|
+
if (j.status !== "running") continue;
|
|
1885
|
+
if (j.boxId && accountedBoxIds.has(j.boxId)) continue;
|
|
1886
|
+
if (typeof j.pid === "number" && !processAlive(j.pid)) continue;
|
|
1887
|
+
n += 1;
|
|
1888
|
+
}
|
|
1889
|
+
return n;
|
|
1890
|
+
}
|
|
1873
1891
|
var RUNNING_COUNT_CACHE_MS = 3e3;
|
|
1874
|
-
var
|
|
1892
|
+
var boxStateCache = null;
|
|
1875
1893
|
async function defaultCountRunningBoxes() {
|
|
1894
|
+
const { boxCount, stateIds } = await cachedBoxState();
|
|
1895
|
+
let jobs;
|
|
1896
|
+
try {
|
|
1897
|
+
jobs = await loadQueue();
|
|
1898
|
+
} catch {
|
|
1899
|
+
return boxCount;
|
|
1900
|
+
}
|
|
1901
|
+
return boxCount + countInFlightCreateJobs(jobs, stateIds);
|
|
1902
|
+
}
|
|
1903
|
+
async function cachedBoxState() {
|
|
1876
1904
|
const now = Date.now();
|
|
1877
|
-
if (
|
|
1878
|
-
return
|
|
1905
|
+
if (boxStateCache && boxStateCache.expiresAt > now) {
|
|
1906
|
+
return { boxCount: boxStateCache.boxCount, stateIds: boxStateCache.stateIds };
|
|
1879
1907
|
}
|
|
1880
|
-
const
|
|
1881
|
-
|
|
1882
|
-
return
|
|
1908
|
+
const fresh = await uncachedBoxStateCount();
|
|
1909
|
+
boxStateCache = { ...fresh, expiresAt: now + RUNNING_COUNT_CACHE_MS };
|
|
1910
|
+
return fresh;
|
|
1883
1911
|
}
|
|
1884
|
-
async function
|
|
1912
|
+
async function uncachedBoxStateCount() {
|
|
1885
1913
|
let boxes;
|
|
1886
1914
|
try {
|
|
1887
1915
|
boxes = (await readState(STATE_FILE)).boxes;
|
|
1888
1916
|
} catch {
|
|
1889
|
-
return 0;
|
|
1917
|
+
return { boxCount: 0, stateIds: /* @__PURE__ */ new Set() };
|
|
1890
1918
|
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1919
|
+
const stateIds = new Set(boxes.map((b) => b.id));
|
|
1920
|
+
if (boxes.length === 0) return { boxCount: 0, stateIds };
|
|
1921
|
+
let boxCount = 0;
|
|
1893
1922
|
const dockerBoxes = [];
|
|
1894
1923
|
for (const b of boxes) {
|
|
1895
1924
|
const provider = b.provider ?? "docker";
|
|
1896
1925
|
if (provider === "docker") {
|
|
1897
1926
|
dockerBoxes.push(b);
|
|
1898
1927
|
} else {
|
|
1899
|
-
|
|
1928
|
+
boxCount += 1;
|
|
1900
1929
|
}
|
|
1901
1930
|
}
|
|
1902
1931
|
if (dockerBoxes.length > 0) {
|
|
1903
1932
|
const states = await Promise.all(dockerBoxes.map((b) => inspectDockerState(b.container)));
|
|
1904
1933
|
for (const s of states) {
|
|
1905
|
-
if (s === "running")
|
|
1934
|
+
if (s === "running") boxCount += 1;
|
|
1906
1935
|
}
|
|
1907
1936
|
}
|
|
1908
|
-
return
|
|
1937
|
+
return { boxCount, stateIds };
|
|
1909
1938
|
}
|
|
1910
1939
|
function inspectDockerState(containerName) {
|
|
1911
1940
|
return new Promise((resolveP) => {
|
|
@@ -5464,7 +5493,7 @@ async function ensureRelay(opts = {}) {
|
|
|
5464
5493
|
await reclaimRelay(health.pid, log);
|
|
5465
5494
|
} else {
|
|
5466
5495
|
const existingPid = await readPidFile();
|
|
5467
|
-
if (existingPid !== null && await
|
|
5496
|
+
if (existingPid !== null && await processAlive2(existingPid)) {
|
|
5468
5497
|
for (let i = 0; i < 10; i++) {
|
|
5469
5498
|
if (await pingHealthz(300)) return ENDPOINT;
|
|
5470
5499
|
await delay2(200);
|
|
@@ -5493,7 +5522,7 @@ async function reclaimRelay(reportedPid, log) {
|
|
|
5493
5522
|
for (const pid of [reportedPid, pidFromFile]) {
|
|
5494
5523
|
if (typeof pid !== "number" || pid <= 0 || seen.has(pid)) continue;
|
|
5495
5524
|
seen.add(pid);
|
|
5496
|
-
if (!await
|
|
5525
|
+
if (!await processAlive2(pid)) continue;
|
|
5497
5526
|
log(`stopping crippled relay pid ${String(pid)}`);
|
|
5498
5527
|
await killPid(pid);
|
|
5499
5528
|
}
|
|
@@ -5512,7 +5541,7 @@ async function killPid(pid) {
|
|
|
5512
5541
|
return;
|
|
5513
5542
|
}
|
|
5514
5543
|
for (let i = 0; i < 20; i++) {
|
|
5515
|
-
if (!await
|
|
5544
|
+
if (!await processAlive2(pid)) return;
|
|
5516
5545
|
await delay2(100);
|
|
5517
5546
|
}
|
|
5518
5547
|
try {
|
|
@@ -5663,7 +5692,7 @@ async function stopRelay() {
|
|
|
5663
5692
|
if (pid === null) {
|
|
5664
5693
|
return { stopped: false, pid: null };
|
|
5665
5694
|
}
|
|
5666
|
-
if (!await
|
|
5695
|
+
if (!await processAlive2(pid)) {
|
|
5667
5696
|
await unlink2(PID_FILE).catch(() => {
|
|
5668
5697
|
});
|
|
5669
5698
|
return { stopped: false, pid };
|
|
@@ -5673,10 +5702,10 @@ async function stopRelay() {
|
|
|
5673
5702
|
} catch {
|
|
5674
5703
|
}
|
|
5675
5704
|
for (let i = 0; i < 20; i++) {
|
|
5676
|
-
if (!await
|
|
5705
|
+
if (!await processAlive2(pid)) break;
|
|
5677
5706
|
await delay2(100);
|
|
5678
5707
|
}
|
|
5679
|
-
if (await
|
|
5708
|
+
if (await processAlive2(pid)) {
|
|
5680
5709
|
try {
|
|
5681
5710
|
process.kill(pid, "SIGKILL");
|
|
5682
5711
|
} catch {
|
|
@@ -5688,7 +5717,7 @@ async function stopRelay() {
|
|
|
5688
5717
|
}
|
|
5689
5718
|
async function getRelayStatus() {
|
|
5690
5719
|
const pid = await readPidFile();
|
|
5691
|
-
const pidAlive2 = pid !== null && await
|
|
5720
|
+
const pidAlive2 = pid !== null && await processAlive2(pid);
|
|
5692
5721
|
const health = await fetchHealthz(300);
|
|
5693
5722
|
return {
|
|
5694
5723
|
running: health !== null,
|
|
@@ -5772,7 +5801,7 @@ async function readPidFile() {
|
|
|
5772
5801
|
return null;
|
|
5773
5802
|
}
|
|
5774
5803
|
}
|
|
5775
|
-
async function
|
|
5804
|
+
async function processAlive2(pid) {
|
|
5776
5805
|
try {
|
|
5777
5806
|
process.kill(pid, 0);
|
|
5778
5807
|
return true;
|
|
@@ -8449,4 +8478,4 @@ export {
|
|
|
8449
8478
|
browserSessionActive,
|
|
8450
8479
|
ensureBoxBrowser
|
|
8451
8480
|
};
|
|
8452
|
-
//# sourceMappingURL=chunk-
|
|
8481
|
+
//# sourceMappingURL=chunk-ZJXTIH6C.js.map
|