@agentstep/agent-sdk 0.4.31 → 0.4.33
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/auth/middleware.js +5 -5
- package/dist/backends/claude/args.js +3 -3
- package/dist/backends/claude/index.js +4 -4
- package/dist/backends/codex/auth.js +3 -3
- package/dist/backends/codex/index.js +7 -7
- package/dist/backends/factory/auth.js +3 -3
- package/dist/backends/factory/index.js +4 -4
- package/dist/backends/gemini/auth.js +3 -3
- package/dist/backends/gemini/index.js +7 -7
- package/dist/backends/opencode/auth.js +3 -3
- package/dist/backends/opencode/index.js +7 -7
- package/dist/backends/pi/auth.js +3 -3
- package/dist/backends/pi/index.js +4 -4
- package/dist/backends/registry.js +21 -21
- package/dist/{chunk-O3XR457F.js → chunk-25D47TYW.js} +2 -2
- package/dist/{chunk-KRLVSKID.js → chunk-2FTX45HM.js} +4 -4
- package/dist/{chunk-TGEDOUUD.js → chunk-2GIX4HAT.js} +1 -1
- package/dist/{chunk-JIURGVRG.js → chunk-2I35VGHX.js} +4 -4
- package/dist/{chunk-ULS4X3UQ.js → chunk-2PPB644A.js} +1 -1
- package/dist/{chunk-FOOPNRHA.js → chunk-2Q46G6VW.js} +2 -2
- package/dist/{chunk-UCOSSYKZ.js → chunk-2ZVFMBAA.js} +8 -7
- package/dist/{chunk-KFORPY7J.js → chunk-3NK6YTA5.js} +17 -10
- package/dist/{chunk-W63RBT7H.js → chunk-3SZ42O5O.js} +181 -15
- package/dist/chunk-4XXQAVKE.js +34 -0
- package/dist/{chunk-O5B7GRUK.js → chunk-5EQJOUWM.js} +1 -1
- package/dist/{chunk-PTYMGYNJ.js → chunk-5F5SHXHX.js} +1 -1
- package/dist/{chunk-AJPZY6EJ.js → chunk-5IGBMS2U.js} +1 -1
- package/dist/{chunk-A7CS7RTM.js → chunk-5YBJAYIH.js} +3 -3
- package/dist/{chunk-IN5KO2L2.js → chunk-6IYCBW4J.js} +1 -1
- package/dist/{chunk-BQRKJAOP.js → chunk-6RH4KQJJ.js} +1 -1
- package/dist/{chunk-UW4T4TG3.js → chunk-76DKCO5N.js} +1 -1
- package/dist/{chunk-TLH4JLC7.js → chunk-7CD4QT5R.js} +2 -2
- package/dist/{chunk-Y2VQ65PM.js → chunk-7GG3FEK2.js} +3 -3
- package/dist/{chunk-UZQLLGX4.js → chunk-A75T7PVY.js} +12 -12
- package/dist/{chunk-33OBMYKV.js → chunk-B3I4ELID.js} +1 -1
- package/dist/{chunk-XVK7YFZP.js → chunk-C46UG6GQ.js} +1 -1
- package/dist/{chunk-I2SLDKCN.js → chunk-C6AXM3M7.js} +2 -2
- package/dist/{chunk-OLF7H564.js → chunk-CDD7O43R.js} +5 -5
- package/dist/{chunk-NJ4JTJJM.js → chunk-CREPPDHX.js} +1 -1
- package/dist/{chunk-55SVTKOM.js → chunk-EOCBMN5V.js} +2 -2
- package/dist/{chunk-YS5UPMTH.js → chunk-EUIR2ADY.js} +8 -8
- package/dist/{chunk-G6JKWW2S.js → chunk-FESFSQMR.js} +1 -1
- package/dist/{chunk-RCF2SVUO.js → chunk-FWQSTFNW.js} +20 -16
- package/dist/{chunk-Q3DOTREK.js → chunk-FXLUSECC.js} +1 -1
- package/dist/chunk-G7KUVNDY.js +80 -0
- package/dist/{chunk-OZJG5G7V.js → chunk-GQCMR7WS.js} +3 -3
- package/dist/{chunk-NIW3B4V2.js → chunk-GVPJL3XS.js} +5 -5
- package/dist/{chunk-ZG7FD2KD.js → chunk-IDQZ2AOM.js} +2 -2
- package/dist/{chunk-MHL3EXDR.js → chunk-JCW3ZRES.js} +1 -1
- package/dist/{chunk-BNXUV6NZ.js → chunk-JFUEQ6ED.js} +3 -3
- package/dist/{chunk-RKL2NK3V.js → chunk-JZL4L54R.js} +4 -4
- package/dist/{chunk-WU52LOGJ.js → chunk-KEQXISSM.js} +1 -1
- package/dist/{chunk-MVC2FD32.js → chunk-MHBLVGRF.js} +3 -3
- package/dist/{chunk-ZOWT6X6Y.js → chunk-MQQ44IGX.js} +4 -4
- package/dist/{chunk-UBFEHVPY.js → chunk-MX53KOBD.js} +2 -2
- package/dist/{chunk-GNHRAWOX.js → chunk-N3QIXC2B.js} +2 -2
- package/dist/{chunk-V5XH43NK.js → chunk-OB5IFO65.js} +7 -7
- package/dist/{chunk-JWSR5TZ3.js → chunk-OGJUSGF7.js} +1 -1
- package/dist/{chunk-KLFJTFDB.js → chunk-P26WOAA3.js} +1 -1
- package/dist/{chunk-LHQD4KLV.js → chunk-P3PHXVMA.js} +1 -1
- package/dist/{chunk-UZHSDRAK.js → chunk-PIJKJNGB.js} +3 -3
- package/dist/{chunk-M7W3PCFS.js → chunk-PNXHXIX6.js} +1 -1
- package/dist/{chunk-CGKRD37R.js → chunk-PXVLLMKV.js} +2 -2
- package/dist/{chunk-FEXR57M4.js → chunk-R6V363NP.js} +4 -4
- package/dist/{chunk-S4AYCMMB.js → chunk-RVR6C22M.js} +1 -1
- package/dist/{chunk-WORPHTCS.js → chunk-S6FREUL2.js} +33 -4
- package/dist/{chunk-JJGAQMPS.js → chunk-S7W3KJYH.js} +1 -1
- package/dist/{chunk-4MDF5N2L.js → chunk-T4YKZUL6.js} +2 -2
- package/dist/{chunk-ZKHUJB7A.js → chunk-TPPLYCJF.js} +1 -1
- package/dist/{chunk-5H2CQ6L4.js → chunk-UKXYPXIB.js} +2 -2
- package/dist/{chunk-4LKSYF4M.js → chunk-V2R7RWVY.js} +1 -1
- package/dist/{chunk-6YZ5WTLB.js → chunk-V7MTIMPB.js} +7 -5
- package/dist/{chunk-PVITAFPJ.js → chunk-VYDO52CO.js} +2 -2
- package/dist/{chunk-CIUFOD65.js → chunk-WQARLGBG.js} +3 -3
- package/dist/{chunk-DKBNLGZO.js → chunk-XT3TAZB7.js} +11 -11
- package/dist/{chunk-7RJNOZLB.js → chunk-Y3LYQJHC.js} +14 -14
- package/dist/{chunk-R3Q62FVO.js → chunk-YT2JWLSK.js} +2 -2
- package/dist/{chunk-TLEGXMX7.js → chunk-YXVKDLMN.js} +3 -3
- package/dist/config/index.js +2 -2
- package/dist/containers/client.js +3 -3
- package/dist/containers/exec.js +3 -3
- package/dist/containers/lifecycle.js +38 -33
- package/dist/containers/setup.js +4 -4
- package/dist/containers/warm-pool.js +21 -0
- package/dist/db/agents.js +2 -2
- package/dist/db/api_keys.js +2 -2
- package/dist/db/batch.js +6 -6
- package/dist/db/environments.js +2 -2
- package/dist/db/events.js +2 -2
- package/dist/db/files.js +2 -2
- package/dist/db/memory.js +2 -2
- package/dist/db/proxy.js +2 -2
- package/dist/db/session-resources.js +2 -2
- package/dist/db/sessions.js +3 -3
- package/dist/db/sync.js +2 -2
- package/dist/db/vaults.js +2 -2
- package/dist/handlers/agents.js +48 -47
- package/dist/handlers/api_keys.js +48 -47
- package/dist/handlers/audit.js +48 -47
- package/dist/handlers/batch.js +49 -48
- package/dist/handlers/credentials.js +49 -48
- package/dist/handlers/environments.js +49 -48
- package/dist/handlers/events.js +51 -50
- package/dist/handlers/files.js +49 -48
- package/dist/handlers/index.js +96 -95
- package/dist/handlers/license.js +48 -47
- package/dist/handlers/memory.js +49 -48
- package/dist/handlers/metrics.js +48 -47
- package/dist/handlers/models.js +49 -48
- package/dist/handlers/providers.js +48 -47
- package/dist/handlers/resources.js +48 -47
- package/dist/handlers/sessions.js +51 -50
- package/dist/handlers/settings.js +48 -47
- package/dist/handlers/skills-write.js +48 -47
- package/dist/handlers/skills.js +49 -48
- package/dist/handlers/stream.js +48 -47
- package/dist/handlers/tenants.js +48 -47
- package/dist/handlers/threads.js +48 -47
- package/dist/handlers/traces.js +48 -47
- package/dist/handlers/upstream_keys.js +49 -48
- package/dist/handlers/vaults.js +48 -47
- package/dist/handlers/whoami.js +48 -47
- package/dist/http.js +47 -46
- package/dist/index.js +60 -59
- package/dist/init.js +44 -43
- package/dist/lib/model-registry.js +3 -3
- package/dist/lib/skills-cache.js +3 -3
- package/dist/observability/otlp.js +8 -8
- package/dist/observability/redactor.js +4 -4
- package/dist/providers/apple-container.js +2 -2
- package/dist/providers/docker.js +1 -1
- package/dist/providers/fly.js +2 -2
- package/dist/providers/modal.js +2 -2
- package/dist/providers/podman.js +24 -21
- package/dist/providers/registry.js +1 -1
- package/dist/providers/resolve-secrets.js +3 -3
- package/dist/providers/sprites.js +5 -4
- package/dist/providers/upstream-keys.js +6 -6
- package/dist/providers/vercel.js +2 -2
- package/dist/proxy/forward.js +3 -3
- package/dist/queue/index.js +3 -3
- package/dist/sessions/bus.js +6 -6
- package/dist/sessions/driver.js +37 -36
- package/dist/sessions/grader.js +2 -2
- package/dist/sessions/secrets.js +3 -3
- package/dist/sessions/sweeper.js +35 -34
- package/dist/sessions/threads.js +38 -37
- package/dist/shutdown.js +36 -35
- package/dist/sync/anthropic.js +6 -6
- package/dist/sync/container-file-sync.js +3 -3
- package/dist/sync/file-sync.js +12 -12
- package/package.json +1 -1
- package/dist/chunk-RMZRSYIJ.js +0 -31
- package/dist/{chunk-2COVNKOK.js → chunk-5EKQBD2H.js} +5 -5
- package/dist/{chunk-WNHJTUPW.js → chunk-A3KHFT7I.js} +5 -5
- package/dist/{chunk-VND46TDY.js → chunk-E7DD7F7J.js} +4 -4
- package/dist/{chunk-BCUBVYE3.js → chunk-L2RX552S.js} +4 -4
- package/dist/{chunk-LASUEMN6.js → chunk-SUGSHXND.js} +5 -5
- package/dist/{chunk-NDVC4J3H.js → chunk-TH7WJLZC.js} +5 -5
- package/dist/{chunk-XTZWBXAO.js → chunk-USYY3L7G.js} +4 -4
- package/dist/{chunk-C4II4GGZ.js → chunk-WPK4ZPMG.js} +0 -0
- package/dist/{chunk-QVFRPABA.js → chunk-X6IQ57SC.js} +5 -5
- package/dist/{chunk-P2IGNOJI.js → chunk-ZTH5JRZG.js} +5 -5
- package/dist/{chunk-J37F7PXJ.js → chunk-ZVXIZ2JD.js} +5 -5
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveVaultSecrets
|
|
3
|
-
} from "./chunk-AJPZY6EJ.js";
|
|
4
1
|
import {
|
|
5
2
|
dockerProvider
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4XXQAVKE.js";
|
|
4
|
+
import {
|
|
5
|
+
resolveVaultSecrets
|
|
6
|
+
} from "./chunk-5IGBMS2U.js";
|
|
7
7
|
import {
|
|
8
8
|
appendEvent
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MHBLVGRF.js";
|
|
10
10
|
import {
|
|
11
11
|
getSession,
|
|
12
12
|
getSessionRow,
|
|
13
13
|
setSessionSandbox
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-3NK6YTA5.js";
|
|
15
15
|
import {
|
|
16
16
|
deleteSprite,
|
|
17
17
|
listSprites
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-FXLUSECC.js";
|
|
19
19
|
import {
|
|
20
20
|
allSessionSandboxes,
|
|
21
21
|
countInEnv,
|
|
@@ -24,20 +24,29 @@ import {
|
|
|
24
24
|
} from "./chunk-EFOIR7R3.js";
|
|
25
25
|
import {
|
|
26
26
|
resolveContainerProvider
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-WPK4ZPMG.js";
|
|
28
28
|
import {
|
|
29
29
|
getEnvironment,
|
|
30
|
-
getEnvironmentRow
|
|
31
|
-
|
|
30
|
+
getEnvironmentRow,
|
|
31
|
+
listEnvironments
|
|
32
|
+
} from "./chunk-X6IQ57SC.js";
|
|
33
|
+
import {
|
|
34
|
+
addWarm,
|
|
35
|
+
claimWarm,
|
|
36
|
+
countInflight,
|
|
37
|
+
countWarm,
|
|
38
|
+
decrementInflight,
|
|
39
|
+
incrementInflight
|
|
40
|
+
} from "./chunk-G7KUVNDY.js";
|
|
32
41
|
import {
|
|
33
42
|
getAgent
|
|
34
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-ZTH5JRZG.js";
|
|
35
44
|
import {
|
|
36
45
|
resolveBackend
|
|
37
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-EUIR2ADY.js";
|
|
38
47
|
import {
|
|
39
48
|
getConfig
|
|
40
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-V7MTIMPB.js";
|
|
41
50
|
import {
|
|
42
51
|
init_clock,
|
|
43
52
|
nowMs
|
|
@@ -48,6 +57,7 @@ import {
|
|
|
48
57
|
|
|
49
58
|
// src/containers/lifecycle.ts
|
|
50
59
|
init_clock();
|
|
60
|
+
import { ulid } from "ulid";
|
|
51
61
|
var lcLog = (...args) => {
|
|
52
62
|
if (process.env.DEBUG_LIFECYCLE === "1") console.log(...args);
|
|
53
63
|
};
|
|
@@ -94,7 +104,8 @@ async function installSkills(sandboxName, provider, skills, engine) {
|
|
|
94
104
|
}
|
|
95
105
|
}
|
|
96
106
|
function deriveSandboxName(sessionId) {
|
|
97
|
-
|
|
107
|
+
const tail = sessionId.replace(/^[a-z]+_/, "").toLowerCase();
|
|
108
|
+
return `${SANDBOX_NAME_PREFIX}${tail}`;
|
|
98
109
|
}
|
|
99
110
|
async function acquireForFirstTurn(sessionId) {
|
|
100
111
|
const row = getSessionRow(sessionId);
|
|
@@ -109,7 +120,8 @@ async function acquireForFirstTurn(sessionId) {
|
|
|
109
120
|
`environment is not ready (state=${env.state})`
|
|
110
121
|
);
|
|
111
122
|
}
|
|
112
|
-
|
|
123
|
+
const config = getConfig();
|
|
124
|
+
if (countInEnv(env.id) + countWarm(env.id) >= config.maxSandboxesPerEnv) {
|
|
113
125
|
throw new ApiError(503, "server_busy", "env sandbox pool exhausted");
|
|
114
126
|
}
|
|
115
127
|
const agent = getAgent(row.agent_id, row.agent_version);
|
|
@@ -128,6 +140,84 @@ async function acquireForFirstTurn(sessionId) {
|
|
|
128
140
|
}
|
|
129
141
|
}
|
|
130
142
|
const sp = wrapProviderWithSecrets(provider, secrets);
|
|
143
|
+
const warm = claimWarm(env.id, backend.name, provider.name);
|
|
144
|
+
if (warm) {
|
|
145
|
+
lcLog(`[lifecycle] ${sessionId} claimed warm container: ${warm.sandboxName}`);
|
|
146
|
+
const name2 = warm.sandboxName;
|
|
147
|
+
try {
|
|
148
|
+
if (agent.engine === "claude") {
|
|
149
|
+
const customTools = agent.tools.filter(
|
|
150
|
+
(t) => t.type === "custom"
|
|
151
|
+
);
|
|
152
|
+
const allBridgeTools = [...customTools];
|
|
153
|
+
if (agent.threads_enabled) {
|
|
154
|
+
allBridgeTools.push({
|
|
155
|
+
type: "custom",
|
|
156
|
+
name: "spawn_agent",
|
|
157
|
+
description: "Spawn a sub-agent to handle a task. Returns the sub-agent's response.",
|
|
158
|
+
input_schema: {
|
|
159
|
+
type: "object",
|
|
160
|
+
properties: {
|
|
161
|
+
agent_id: { type: "string", description: "ID of the agent to spawn" },
|
|
162
|
+
prompt: { type: "string", description: "Task for the sub-agent" }
|
|
163
|
+
},
|
|
164
|
+
required: ["agent_id", "prompt"]
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (allBridgeTools.length > 0) {
|
|
169
|
+
const { installToolBridge } = await import("./backends/claude/index.js");
|
|
170
|
+
await installToolBridge(name2, allBridgeTools, sp);
|
|
171
|
+
}
|
|
172
|
+
if (agent.confirmation_mode) {
|
|
173
|
+
const { installPermissionHook } = await import("./backends/claude/index.js");
|
|
174
|
+
await installPermissionHook(name2, sp);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (agent.skills && agent.skills.length > 0) {
|
|
178
|
+
lcLog(`[lifecycle] ${sessionId} installing ${agent.skills.length} skill(s) on warm container...`);
|
|
179
|
+
await installSkills(name2, sp, agent.skills, agent.engine);
|
|
180
|
+
}
|
|
181
|
+
} catch (err) {
|
|
182
|
+
await sp.delete(name2).catch(() => {
|
|
183
|
+
});
|
|
184
|
+
throw err;
|
|
185
|
+
}
|
|
186
|
+
const { listResources: listSessionResources2 } = await import("./db/session-resources.js");
|
|
187
|
+
const tableResources2 = listSessionResources2(sessionId);
|
|
188
|
+
if (tableResources2.length > 0) {
|
|
189
|
+
const mapped = tableResources2.map((r) => {
|
|
190
|
+
if (r.type === "file") return { type: "file", file_id: r.file_id, mount_path: r.mount_path };
|
|
191
|
+
if (r.type === "github_repository") {
|
|
192
|
+
const checkout = r.checkout;
|
|
193
|
+
return {
|
|
194
|
+
type: "github_repository",
|
|
195
|
+
repository_url: r.url,
|
|
196
|
+
mount_path: r.mount_path,
|
|
197
|
+
branch: checkout?.type === "branch" ? checkout.name : void 0,
|
|
198
|
+
commit: checkout?.type === "commit" ? checkout.name : void 0
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return { type: "uri", uri: r.url, mount_path: r.mount_path };
|
|
202
|
+
});
|
|
203
|
+
await provisionResources(name2, mapped, sp);
|
|
204
|
+
} else {
|
|
205
|
+
const session = getSession(sessionId);
|
|
206
|
+
if (session?.resources && session.resources.length > 0) {
|
|
207
|
+
await provisionResources(name2, session.resources, sp);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
register({
|
|
211
|
+
sandboxName: name2,
|
|
212
|
+
envId: env.id,
|
|
213
|
+
sessionId,
|
|
214
|
+
createdAt: nowMs(),
|
|
215
|
+
vaultSecrets: Object.keys(secrets).length > 0 ? secrets : void 0
|
|
216
|
+
});
|
|
217
|
+
setSessionSandbox(sessionId, name2);
|
|
218
|
+
void replenishWarmPool(env.id, backend.name, provider, secrets);
|
|
219
|
+
return name2;
|
|
220
|
+
}
|
|
131
221
|
const name = deriveSandboxName(sessionId);
|
|
132
222
|
lcLog(`[lifecycle] ${sessionId} creating container via ${sp.name}...`);
|
|
133
223
|
try {
|
|
@@ -234,6 +324,80 @@ async function acquireForFirstTurn(sessionId) {
|
|
|
234
324
|
setSessionSandbox(sessionId, name);
|
|
235
325
|
return name;
|
|
236
326
|
}
|
|
327
|
+
function effectiveWarmPoolSize(envId) {
|
|
328
|
+
const cfg = getConfig();
|
|
329
|
+
const envObj = getEnvironment(envId);
|
|
330
|
+
return envObj?.config?.warm_pool_size ?? cfg.warmPoolSize;
|
|
331
|
+
}
|
|
332
|
+
async function replenishWarmPool(envId, engine, provider, secrets) {
|
|
333
|
+
if (!provider.supportsWarmPool) return;
|
|
334
|
+
const target = effectiveWarmPoolSize(envId);
|
|
335
|
+
if (target <= 0) return;
|
|
336
|
+
if (countWarm(envId) + countInflight(envId) >= target) return;
|
|
337
|
+
const cfg = getConfig();
|
|
338
|
+
if (countInEnv(envId) + countWarm(envId) + countInflight(envId) >= cfg.maxSandboxesPerEnv) return;
|
|
339
|
+
incrementInflight(envId);
|
|
340
|
+
try {
|
|
341
|
+
const sp = wrapProviderWithSecrets(provider, secrets);
|
|
342
|
+
const name = `ca-warm-${ulid().toLowerCase()}`;
|
|
343
|
+
lcLog(`[warm-pool] creating warm container for env=${envId} engine=${engine}: ${name}`);
|
|
344
|
+
await sp.create({ name });
|
|
345
|
+
const backend = resolveBackend(engine);
|
|
346
|
+
await backend.prepareOnSandbox(name, sp);
|
|
347
|
+
const cfg2 = getConfig();
|
|
348
|
+
addWarm({
|
|
349
|
+
sandboxName: name,
|
|
350
|
+
envId,
|
|
351
|
+
engine,
|
|
352
|
+
provider: provider.name,
|
|
353
|
+
createdAt: nowMs(),
|
|
354
|
+
expiresAt: nowMs() + cfg2.warmPoolTtlMs,
|
|
355
|
+
vaultSecrets: Object.keys(secrets).length > 0 ? secrets : void 0
|
|
356
|
+
});
|
|
357
|
+
lcLog(`[warm-pool] warm container ready: ${name} (env=${envId})`);
|
|
358
|
+
} catch (err) {
|
|
359
|
+
console.warn(`[warm-pool] replenish failed for env=${envId} engine=${engine}:`, err);
|
|
360
|
+
} finally {
|
|
361
|
+
decrementInflight(envId);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
async function fillWarmPools() {
|
|
365
|
+
const cfg = getConfig();
|
|
366
|
+
if (cfg.warmPoolSize <= 0) return;
|
|
367
|
+
const envs = listEnvironments({ includeArchived: false, limit: 100 });
|
|
368
|
+
const readyEnvs = envs.filter((e) => e.state === "ready");
|
|
369
|
+
if (readyEnvs.length === 0) return;
|
|
370
|
+
const CONCURRENCY = 3;
|
|
371
|
+
let active = 0;
|
|
372
|
+
let idx = 0;
|
|
373
|
+
async function processNext() {
|
|
374
|
+
while (idx < readyEnvs.length) {
|
|
375
|
+
if (active >= CONCURRENCY) {
|
|
376
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const env = readyEnvs[idx++];
|
|
380
|
+
active++;
|
|
381
|
+
void fillOneEnv(env).finally(() => active--);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
void processNext();
|
|
385
|
+
}
|
|
386
|
+
async function fillOneEnv(env) {
|
|
387
|
+
const target = effectiveWarmPoolSize(env.id);
|
|
388
|
+
if (target <= 0) return;
|
|
389
|
+
try {
|
|
390
|
+
const provider = await resolveContainerProvider(env.config?.provider);
|
|
391
|
+
if (!provider.supportsWarmPool) return;
|
|
392
|
+
const backend = resolveBackend("claude");
|
|
393
|
+
const needed = target - countWarm(env.id) - countInflight(env.id);
|
|
394
|
+
for (let i = 0; i < needed; i++) {
|
|
395
|
+
void replenishWarmPool(env.id, backend.name, provider, {});
|
|
396
|
+
}
|
|
397
|
+
} catch (err) {
|
|
398
|
+
console.warn(`[warm-pool] fillOneEnv failed for env=${env.id}:`, err);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
237
401
|
async function provisionResources(sandboxName, resources, provider) {
|
|
238
402
|
await provider.exec(sandboxName, ["mkdir", "-p", "/mnt/session/resources", "/mnt/session/uploads", "/mnt/session/outputs"]);
|
|
239
403
|
const MAX_RESOURCE_BYTES = 50 * 1024 * 1024;
|
|
@@ -405,6 +569,8 @@ export {
|
|
|
405
569
|
wrapProviderWithSecrets,
|
|
406
570
|
installSkills,
|
|
407
571
|
acquireForFirstTurn,
|
|
572
|
+
replenishWarmPool,
|
|
573
|
+
fillWarmPools,
|
|
408
574
|
provisionResources,
|
|
409
575
|
releaseSession,
|
|
410
576
|
reconcileOrphanSandboxes,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCliProvider
|
|
3
|
+
} from "./chunk-5ZFOKZGR.js";
|
|
4
|
+
|
|
5
|
+
// src/providers/docker.ts
|
|
6
|
+
var DEFAULT_IMAGE = process.env.DOCKER_IMAGE ?? "node:22";
|
|
7
|
+
var dockerProvider = Object.assign(
|
|
8
|
+
createCliProvider({
|
|
9
|
+
name: "docker",
|
|
10
|
+
binary: "docker",
|
|
11
|
+
createSteps: (name) => [
|
|
12
|
+
["create", "--name", name, DEFAULT_IMAGE, "sleep", "infinity"],
|
|
13
|
+
["start", name]
|
|
14
|
+
],
|
|
15
|
+
deleteArgs: (name) => ["rm", "-f", name],
|
|
16
|
+
execArgs: (name, argv) => ["exec", "-i", name, ...argv],
|
|
17
|
+
listArgs: (prefix) => [
|
|
18
|
+
"ps",
|
|
19
|
+
"-a",
|
|
20
|
+
"--filter",
|
|
21
|
+
`name=${prefix}`,
|
|
22
|
+
"--format",
|
|
23
|
+
"{{.Names}}"
|
|
24
|
+
],
|
|
25
|
+
parseList: (stdout) => stdout.trim().split("\n").filter(Boolean),
|
|
26
|
+
checkCmd: ["version", "--format", "{{.Server.Version}}"],
|
|
27
|
+
checkFailMsg: (msg) => msg.includes("ENOENT") ? "Docker not installed. Run: brew install --cask docker" : "Docker not running \u2014 launch Docker Desktop"
|
|
28
|
+
}),
|
|
29
|
+
{ supportsWarmPool: true }
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
dockerProvider
|
|
34
|
+
};
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
jsonOk,
|
|
17
17
|
routeWrap
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-T4YKZUL6.js";
|
|
19
19
|
import {
|
|
20
20
|
createApiKey,
|
|
21
21
|
getApiKeyById,
|
|
@@ -23,10 +23,10 @@ import {
|
|
|
23
23
|
listApiKeys,
|
|
24
24
|
revokeApiKey,
|
|
25
25
|
updateApiKeyPermissions
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-USYY3L7G.js";
|
|
27
27
|
import {
|
|
28
28
|
listSessionsByApiKey
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-3NK6YTA5.js";
|
|
30
30
|
import {
|
|
31
31
|
getDb,
|
|
32
32
|
init_client
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildClaudeArgs,
|
|
3
3
|
buildClaudeAuthEnv
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-S7W3KJYH.js";
|
|
5
5
|
import {
|
|
6
6
|
PERMISSION_BRIDGE_DIR,
|
|
7
7
|
PERMISSION_HOOK_SCRIPT_PATH,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
} from "./chunk-IU457W7Q.js";
|
|
26
26
|
import {
|
|
27
27
|
getConfig
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-V7MTIMPB.js";
|
|
29
29
|
|
|
30
30
|
// src/backends/claude/index.ts
|
|
31
31
|
function buildTurn(input) {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createSession
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3NK6YTA5.js";
|
|
4
4
|
import {
|
|
5
5
|
createEnvironment,
|
|
6
6
|
deleteEnvironment,
|
|
7
7
|
getEnvironment
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-X6IQ57SC.js";
|
|
9
9
|
import {
|
|
10
10
|
archiveAgent,
|
|
11
11
|
createAgent,
|
|
12
12
|
getAgent
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ZTH5JRZG.js";
|
|
14
14
|
import {
|
|
15
15
|
getDrizzle,
|
|
16
16
|
init_drizzle
|
|
@@ -21,24 +21,24 @@ import {
|
|
|
21
21
|
} from "./chunk-72BKGVBE.js";
|
|
22
22
|
import {
|
|
23
23
|
loadSessionSecrets
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-TPPLYCJF.js";
|
|
25
25
|
import {
|
|
26
26
|
isProxied
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-E7DD7F7J.js";
|
|
28
28
|
import {
|
|
29
29
|
acquireForFirstTurn,
|
|
30
30
|
installSkills,
|
|
31
31
|
provisionResources,
|
|
32
32
|
wrapProviderWithSecrets
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-3SZ42O5O.js";
|
|
34
34
|
import {
|
|
35
35
|
BLOCKED_ENV_KEYS,
|
|
36
36
|
resolveVaultSecrets
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-5IGBMS2U.js";
|
|
38
38
|
import {
|
|
39
39
|
appendEvent,
|
|
40
40
|
appendEventsBatch
|
|
41
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-MHBLVGRF.js";
|
|
42
42
|
import {
|
|
43
43
|
bumpSessionStats,
|
|
44
44
|
getOutcomeCriteria,
|
|
@@ -49,26 +49,26 @@ import {
|
|
|
49
49
|
setOutcomeCriteria,
|
|
50
50
|
updateSessionMutable,
|
|
51
51
|
updateSessionStatus
|
|
52
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-3NK6YTA5.js";
|
|
53
53
|
import {
|
|
54
54
|
listEvents,
|
|
55
55
|
markUserEventProcessed
|
|
56
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-TH7WJLZC.js";
|
|
57
57
|
import {
|
|
58
58
|
getBySession
|
|
59
59
|
} from "./chunk-EFOIR7R3.js";
|
|
60
60
|
import {
|
|
61
61
|
resolveContainerProvider
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-WPK4ZPMG.js";
|
|
63
63
|
import {
|
|
64
64
|
getEnvironment
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-X6IQ57SC.js";
|
|
66
66
|
import {
|
|
67
67
|
getAgent
|
|
68
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-ZTH5JRZG.js";
|
|
69
69
|
import {
|
|
70
70
|
resolveBackend
|
|
71
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-EUIR2ADY.js";
|
|
72
72
|
import {
|
|
73
73
|
PERMISSION_BRIDGE_PENDING_PATH,
|
|
74
74
|
PERMISSION_BRIDGE_REQUEST_PATH,
|
|
@@ -84,7 +84,7 @@ import {
|
|
|
84
84
|
} from "./chunk-XBHDQK4Z.js";
|
|
85
85
|
import {
|
|
86
86
|
getConfig
|
|
87
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-V7MTIMPB.js";
|
|
88
88
|
import {
|
|
89
89
|
init_clock,
|
|
90
90
|
nowMs
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveContainerProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WPK4ZPMG.js";
|
|
4
4
|
import {
|
|
5
5
|
getEnvironmentRow,
|
|
6
6
|
updateEnvironmentState
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-X6IQ57SC.js";
|
|
8
8
|
import {
|
|
9
9
|
installClaudeWrapper
|
|
10
10
|
} from "./chunk-IU457W7Q.js";
|
|
@@ -6,27 +6,27 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
jsonOk,
|
|
8
8
|
routeWrap
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-T4YKZUL6.js";
|
|
10
10
|
import {
|
|
11
11
|
forwardToAnthropic,
|
|
12
12
|
validateAnthropicProxy
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-JCW3ZRES.js";
|
|
14
14
|
import {
|
|
15
15
|
getProxiedTenantId,
|
|
16
16
|
isProxied,
|
|
17
17
|
markProxied,
|
|
18
18
|
unmarkProxied
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-E7DD7F7J.js";
|
|
20
20
|
import {
|
|
21
21
|
archiveAgent,
|
|
22
22
|
createAgent,
|
|
23
23
|
getAgent,
|
|
24
24
|
listAgents,
|
|
25
25
|
updateAgent
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-ZTH5JRZG.js";
|
|
27
27
|
import {
|
|
28
28
|
resolveBackend
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-EUIR2ADY.js";
|
|
30
30
|
import {
|
|
31
31
|
getDb,
|
|
32
32
|
init_client
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
piBackend
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5EQJOUWM.js";
|
|
4
4
|
import {
|
|
5
5
|
opencodeBackend
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MQQ44IGX.js";
|
|
7
|
+
import {
|
|
8
|
+
factoryBackend
|
|
9
|
+
} from "./chunk-2GIX4HAT.js";
|
|
7
10
|
import {
|
|
8
11
|
geminiBackend
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-JZL4L54R.js";
|
|
10
13
|
import {
|
|
11
14
|
codexBackend
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
factoryBackend
|
|
15
|
-
} from "./chunk-TGEDOUUD.js";
|
|
15
|
+
} from "./chunk-2I35VGHX.js";
|
|
16
16
|
import {
|
|
17
17
|
claudeBackend
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-7CD4QT5R.js";
|
|
19
19
|
|
|
20
20
|
// src/backends/registry.ts
|
|
21
21
|
var BACKENDS = {
|