@madarco/agentbox 0.11.0 → 0.11.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madarco/agentbox",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Launch Claude Code, Codex, and other coding agents in isolated sandboxes",
5
5
  "license": "MIT",
6
6
  "author": "Marco D'Alia",
@@ -64,10 +64,10 @@
64
64
  "@agentbox/sandbox-cloud": "0.0.0",
65
65
  "@agentbox/relay": "0.0.0",
66
66
  "@agentbox/sandbox-core": "0.0.0",
67
+ "@agentbox/sandbox-daytona": "0.0.0",
67
68
  "@agentbox/sandbox-docker": "0.0.0",
68
69
  "@agentbox/sandbox-hetzner": "0.0.0",
69
- "@agentbox/sandbox-vercel": "0.0.0",
70
- "@agentbox/sandbox-daytona": "0.0.0"
70
+ "@agentbox/sandbox-vercel": "0.0.0"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsup",
@@ -21074,57 +21074,72 @@ async function defaultCountWorkingBoxes(registry, statusStore, idleGraceMs) {
21074
21074
  sinceCreateMs: msSince2(b.createdAt)
21075
21075
  };
21076
21076
  });
21077
- let count2 = countWorkingSlots(entries, idleGraceMs);
21077
+ const count2 = countWorkingSlots(entries, idleGraceMs);
21078
21078
  let jobs;
21079
21079
  try {
21080
21080
  jobs = await loadQueue();
21081
21081
  } catch {
21082
21082
  return count2;
21083
21083
  }
21084
+ return count2 + countInFlightCreateJobs(jobs, registeredIds);
21085
+ }
21086
+ function countInFlightCreateJobs(jobs, accountedBoxIds) {
21087
+ let n2 = 0;
21084
21088
  for (const j of jobs) {
21085
21089
  if (j.status !== "running") continue;
21086
- if (j.boxId && registeredIds.has(j.boxId)) continue;
21090
+ if (j.boxId && accountedBoxIds.has(j.boxId)) continue;
21087
21091
  if (typeof j.pid === "number" && !processAlive(j.pid)) continue;
21088
- count2 += 1;
21092
+ n2 += 1;
21089
21093
  }
21090
- return count2;
21094
+ return n2;
21091
21095
  }
21092
21096
  var RUNNING_COUNT_CACHE_MS = 3e3;
21093
- var runningCountCache = null;
21097
+ var boxStateCache = null;
21094
21098
  async function defaultCountRunningBoxes() {
21099
+ const { boxCount, stateIds } = await cachedBoxState();
21100
+ let jobs;
21101
+ try {
21102
+ jobs = await loadQueue();
21103
+ } catch {
21104
+ return boxCount;
21105
+ }
21106
+ return boxCount + countInFlightCreateJobs(jobs, stateIds);
21107
+ }
21108
+ async function cachedBoxState() {
21095
21109
  const now = Date.now();
21096
- if (runningCountCache && runningCountCache.expiresAt > now) {
21097
- return runningCountCache.value;
21110
+ if (boxStateCache && boxStateCache.expiresAt > now) {
21111
+ return { boxCount: boxStateCache.boxCount, stateIds: boxStateCache.stateIds };
21098
21112
  }
21099
- const value = await uncachedCountRunningBoxes();
21100
- runningCountCache = { value, expiresAt: now + RUNNING_COUNT_CACHE_MS };
21101
- return value;
21113
+ const fresh = await uncachedBoxStateCount();
21114
+ boxStateCache = { ...fresh, expiresAt: now + RUNNING_COUNT_CACHE_MS };
21115
+ return fresh;
21102
21116
  }
21103
- async function uncachedCountRunningBoxes() {
21117
+ async function uncachedBoxStateCount() {
21104
21118
  let boxes;
21105
21119
  try {
21106
21120
  boxes = (await readState(STATE_FILE)).boxes;
21107
21121
  } catch {
21108
- return 0;
21122
+ return { boxCount: 0, stateIds: /* @__PURE__ */ new Set() };
21109
21123
  }
21110
- if (boxes.length === 0) return 0;
21111
- let count2 = 0;
21124
+ const stateIds = new Set(boxes.map((b) => b.id));
21125
+ if (boxes.length === 0) return { boxCount: 0, stateIds };
21126
+ let boxCount = 0;
21112
21127
  const dockerBoxes = [];
21113
21128
  for (const b of boxes) {
21114
21129
  const provider = b.provider ?? "docker";
21115
21130
  if (provider === "docker") {
21116
21131
  dockerBoxes.push(b);
21117
21132
  } else {
21118
- count2 += 1;
21133
+ boxCount += 1;
21119
21134
  }
21120
21135
  }
21121
21136
  if (dockerBoxes.length > 0) {
21122
21137
  const states = await Promise.all(dockerBoxes.map((b) => inspectDockerState(b.container)));
21123
21138
  for (const s of states) {
21124
- if (s === "running") count2 += 1;
21139
+ if (s === "running") boxCount += 1;
21125
21140
  }
21126
21141
  }
21127
- return count2;
21142
+ return { boxCount, stateIds };
21128
21143
  }
21129
21144
  function inspectDockerState(containerName) {
21130
21145
  return new Promise((resolveP) => {