@agentstep/agent-sdk 0.5.11 → 0.5.12

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.
Files changed (191) hide show
  1. package/dist/auth/middleware.js +8 -8
  2. package/dist/backends/claude/args.js +6 -6
  3. package/dist/backends/claude/index.js +11 -11
  4. package/dist/backends/codex/auth.js +6 -6
  5. package/dist/backends/codex/index.js +12 -12
  6. package/dist/backends/factory/auth.js +6 -6
  7. package/dist/backends/factory/index.js +14 -14
  8. package/dist/backends/gemini/auth.js +6 -6
  9. package/dist/backends/gemini/index.js +10 -10
  10. package/dist/backends/opencode/auth.js +6 -6
  11. package/dist/backends/opencode/index.js +12 -12
  12. package/dist/backends/pi/auth.js +6 -6
  13. package/dist/backends/pi/index.js +12 -12
  14. package/dist/backends/registry.js +30 -30
  15. package/dist/{chunk-ZEDULYKX.js → chunk-2IISXUVF.js} +1 -1
  16. package/dist/{chunk-34Q6WMIT.js → chunk-2Z56TPBL.js} +3 -3
  17. package/dist/{chunk-MMB7ZTAF.js → chunk-3DRK36FB.js} +5 -5
  18. package/dist/{chunk-LXSGQ2VF.js → chunk-3NNU7TQ4.js} +8 -8
  19. package/dist/{chunk-SAA6477U.js → chunk-3UK3IF27.js} +4 -4
  20. package/dist/chunk-4ANV3AH3.js +65 -0
  21. package/dist/{chunk-RNU253MD.js → chunk-4ENK7S24.js} +21 -2
  22. package/dist/{chunk-IFZ7EXMG.js → chunk-4EVT4MFD.js} +1 -1
  23. package/dist/{chunk-7POF237O.js → chunk-4MKJB6U2.js} +1 -1
  24. package/dist/{chunk-WKPUTJGD.js → chunk-5LDBCBOR.js} +1 -1
  25. package/dist/{chunk-5KXAMBPI.js → chunk-6PIL2RJD.js} +2 -2
  26. package/dist/{chunk-KZGFT75I.js → chunk-6X3G5SAS.js} +41 -18
  27. package/dist/{chunk-WUMBZMBF.js → chunk-7ASUTNKE.js} +2 -2
  28. package/dist/{chunk-CR3UN3BC.js → chunk-7BT6V4CH.js} +20 -18
  29. package/dist/{chunk-5COWXLGO.js → chunk-7D55V4XP.js} +1 -1
  30. package/dist/{chunk-BJ3EPRZU.js → chunk-7NZ46LIO.js} +29 -28
  31. package/dist/{chunk-6FNPCZTL.js → chunk-7SO7O6RV.js} +2 -2
  32. package/dist/{chunk-4JPJ3ZIV.js → chunk-7Z6LTBYQ.js} +5 -5
  33. package/dist/{chunk-NVTDXBGV.js → chunk-APKELBCA.js} +1 -1
  34. package/dist/{chunk-RYVVSBST.js → chunk-B3UOTIOI.js} +7 -7
  35. package/dist/{chunk-4UNMDYKD.js → chunk-B5JUCPYW.js} +1 -1
  36. package/dist/{chunk-LJSD6G6K.js → chunk-BQ5MWNWN.js} +3 -3
  37. package/dist/{chunk-KB4EKC5T.js → chunk-BYJRL4IQ.js} +5 -5
  38. package/dist/{chunk-7NIUHK63.js → chunk-C3ZPWUDE.js} +2 -2
  39. package/dist/{chunk-LSXVCZN7.js → chunk-CD2FQVQR.js} +1 -1
  40. package/dist/{chunk-6BOOQV4Q.js → chunk-CFLMIJ2C.js} +3 -3
  41. package/dist/{chunk-GMIAU3CP.js → chunk-CGGGCKSK.js} +4 -4
  42. package/dist/chunk-D2GADI73.js +253 -0
  43. package/dist/{chunk-MPG77WHN.js → chunk-D3TY7PMJ.js} +5 -5
  44. package/dist/{chunk-UHPS3XNG.js → chunk-DAIEVD4O.js} +4 -4
  45. package/dist/{chunk-2U2KCTMF.js → chunk-DDF2CRA3.js} +2 -2
  46. package/dist/{chunk-WL3VMUAI.js → chunk-FCKUWBUL.js} +2 -2
  47. package/dist/{chunk-YFGBTXID.js → chunk-FV2XE3DX.js} +2 -2
  48. package/dist/{chunk-73BYGQWA.js → chunk-G7Y5YGLE.js} +1 -1
  49. package/dist/{chunk-JE5Z2GLG.js → chunk-HE3IEIKM.js} +3 -3
  50. package/dist/{chunk-WKMRBRJQ.js → chunk-HH23DOBB.js} +1 -1
  51. package/dist/{chunk-HCORTMQH.js → chunk-HHS6EHSG.js} +4 -4
  52. package/dist/{chunk-T4IPZC4G.js → chunk-ISXWS5Y4.js} +6 -6
  53. package/dist/{chunk-TCTAUIAQ.js → chunk-JK2GXKOQ.js} +5 -5
  54. package/dist/{chunk-7KSQJK2V.js → chunk-JXU6SA6S.js} +42 -1
  55. package/dist/{chunk-ALIJNBQY.js → chunk-KHICXOTH.js} +3 -3
  56. package/dist/{chunk-BUQATYS7.js → chunk-KNWM237Q.js} +2 -2
  57. package/dist/{chunk-RNDLMMKI.js → chunk-LOWHDHDD.js} +3 -3
  58. package/dist/{chunk-6SVZD3UA.js → chunk-M4OF5D4K.js} +4 -4
  59. package/dist/{chunk-VFVLRR3Z.js → chunk-M7SYXJBT.js} +1 -1
  60. package/dist/{chunk-IBO36HUU.js → chunk-MQBNN4KH.js} +1 -1
  61. package/dist/{chunk-32RP2UX6.js → chunk-MTB7SCZ5.js} +5 -5
  62. package/dist/{chunk-LEVIKSPQ.js → chunk-MTRTBT7L.js} +1 -1
  63. package/dist/{chunk-UMIIZKVX.js → chunk-N5F5OUUZ.js} +3 -3
  64. package/dist/{chunk-KGTWD46T.js → chunk-NWIMPG4M.js} +1 -1
  65. package/dist/chunk-ONEKY3CM.js +146 -0
  66. package/dist/{chunk-OMI5CR4P.js → chunk-ONS32E65.js} +28 -20
  67. package/dist/{chunk-N5C3WQWD.js → chunk-PDUQCDIO.js} +1 -1
  68. package/dist/{chunk-DSNNEER4.js → chunk-PJTGQVKB.js} +1 -1
  69. package/dist/{chunk-M2ZBXMYO.js → chunk-PLSXDJT4.js} +5 -4
  70. package/dist/{chunk-2UDGQWRA.js → chunk-PPI76YVT.js} +2 -2
  71. package/dist/{chunk-N33MOUCH.js → chunk-PRWWTLPR.js} +3 -3
  72. package/dist/{chunk-T75UYYMI.js → chunk-PVFGDKXO.js} +2 -2
  73. package/dist/{chunk-PIJJXKMK.js → chunk-PXMTLKUJ.js} +3 -3
  74. package/dist/{chunk-6ERUVF2Y.js → chunk-QB7JAMWG.js} +1 -1
  75. package/dist/{chunk-KRQRJEQY.js → chunk-QS544PN6.js} +4 -4
  76. package/dist/{chunk-4N7WVJHB.js → chunk-R5LXEIOJ.js} +9 -9
  77. package/dist/{chunk-OJUDLJOG.js → chunk-REY2YZ5X.js} +3 -3
  78. package/dist/{chunk-4IEDAORR.js → chunk-RFK4W5PZ.js} +1 -1
  79. package/dist/{chunk-NOG7ZJJA.js → chunk-RLLVP37Q.js} +1 -1
  80. package/dist/{chunk-UONJFSWM.js → chunk-S5NB47IR.js} +6 -6
  81. package/dist/{chunk-3XGUMXGR.js → chunk-SXR4HQZY.js} +2 -2
  82. package/dist/{chunk-YN2F26NN.js → chunk-T3CXZ2BE.js} +2 -2
  83. package/dist/{chunk-I7FLMXEF.js → chunk-TN34IN7S.js} +16 -13
  84. package/dist/{chunk-XUODI55L.js → chunk-U3QU5AVC.js} +1 -1
  85. package/dist/{chunk-GTHATO73.js → chunk-UB5WVCY4.js} +3 -3
  86. package/dist/{chunk-3TF3YLM2.js → chunk-UROFA6OZ.js} +2 -2
  87. package/dist/{chunk-4HFKDLD7.js → chunk-UTQRPXTL.js} +9 -8
  88. package/dist/{chunk-Y3EUEPGQ.js → chunk-UWHV7EJG.js} +2 -2
  89. package/dist/{chunk-5VL4L6BJ.js → chunk-VG2TYPZ4.js} +18 -2
  90. package/dist/{chunk-EZBJEV6F.js → chunk-VTH56ERA.js} +4 -4
  91. package/dist/{chunk-Z4DZMNDE.js → chunk-W6QYWXOZ.js} +2 -2
  92. package/dist/{chunk-3WZGFAV4.js → chunk-WKGJQIRC.js} +4 -3
  93. package/dist/{chunk-EGN4TPN5.js → chunk-WT3SEE34.js} +3 -3
  94. package/dist/{chunk-CZ4IOIWV.js → chunk-X23OAFFE.js} +4 -4
  95. package/dist/{chunk-DVDNHXCM.js → chunk-XSRIFWHR.js} +2 -2
  96. package/dist/{chunk-SS5IC3XV.js → chunk-Y6BFKPNB.js} +1 -1
  97. package/dist/{chunk-EFSLGRY2.js → chunk-YCL5RHEC.js} +2 -2
  98. package/dist/{chunk-RTLMLG3A.js → chunk-YD67W6DW.js} +7 -7
  99. package/dist/{chunk-4QRE6LZG.js → chunk-YE47YUGE.js} +6 -6
  100. package/dist/{chunk-F6DCNXO5.js → chunk-YEJFXJHR.js} +2 -2
  101. package/dist/{chunk-RJB7YG26.js → chunk-YUVQQCT4.js} +15 -15
  102. package/dist/{chunk-T64ECODW.js → chunk-YUZFNAG6.js} +21 -0
  103. package/dist/{chunk-G43CK3VC.js → chunk-YWAMRRAX.js} +9 -9
  104. package/dist/config/index.js +5 -5
  105. package/dist/containers/client.js +6 -6
  106. package/dist/containers/exec.js +6 -6
  107. package/dist/containers/lifecycle.js +42 -42
  108. package/dist/containers/setup.js +9 -8
  109. package/dist/db/agents.js +6 -6
  110. package/dist/db/api_keys.js +5 -5
  111. package/dist/db/audit.js +3 -3
  112. package/dist/db/batch.js +10 -10
  113. package/dist/db/client.js +2 -2
  114. package/dist/db/credentials.js +3 -3
  115. package/dist/db/drizzle.js +4 -4
  116. package/dist/db/environments.js +6 -6
  117. package/dist/db/events.js +5 -5
  118. package/dist/db/files.js +5 -5
  119. package/dist/db/memory.js +5 -5
  120. package/dist/db/migrations.js +1 -1
  121. package/dist/db/proxy.js +5 -5
  122. package/dist/db/schema.js +5 -3
  123. package/dist/db/session-resources.js +5 -5
  124. package/dist/db/sessions.js +8 -8
  125. package/dist/db/skills.js +5 -5
  126. package/dist/db/sync.js +5 -5
  127. package/dist/db/tenants.js +3 -3
  128. package/dist/db/threads.js +7 -7
  129. package/dist/db/traces.js +5 -5
  130. package/dist/db/upstream_keys.js +3 -3
  131. package/dist/db/vaults.js +6 -6
  132. package/dist/db/work.js +33 -0
  133. package/dist/dreaming/review.js +11 -11
  134. package/dist/handlers/agents.js +58 -58
  135. package/dist/handlers/api_keys.js +59 -59
  136. package/dist/handlers/audit.js +59 -59
  137. package/dist/handlers/batch.js +59 -59
  138. package/dist/handlers/credentials.js +59 -59
  139. package/dist/handlers/environments.js +59 -59
  140. package/dist/handlers/events.js +62 -62
  141. package/dist/handlers/files.js +59 -59
  142. package/dist/handlers/index.js +135 -114
  143. package/dist/handlers/license.js +58 -58
  144. package/dist/handlers/memory.js +60 -60
  145. package/dist/handlers/metrics.js +58 -58
  146. package/dist/handlers/models.js +59 -59
  147. package/dist/handlers/providers.js +58 -58
  148. package/dist/handlers/resources.js +58 -58
  149. package/dist/handlers/sessions.js +62 -62
  150. package/dist/handlers/settings.js +58 -58
  151. package/dist/handlers/skills-write.js +61 -59
  152. package/dist/handlers/skills.js +59 -59
  153. package/dist/handlers/stream.js +58 -58
  154. package/dist/handlers/tenants.js +59 -59
  155. package/dist/handlers/threads.js +59 -59
  156. package/dist/handlers/traces.js +59 -59
  157. package/dist/handlers/ui.d.ts +6 -0
  158. package/dist/handlers/ui.d.ts.map +1 -0
  159. package/dist/handlers/ui.js +1 -1
  160. package/dist/handlers/upstream_keys.js +61 -61
  161. package/dist/handlers/vaults.js +58 -58
  162. package/dist/handlers/whoami.js +58 -58
  163. package/dist/handlers/work.js +114 -0
  164. package/dist/http.js +57 -57
  165. package/dist/index.js +78 -67
  166. package/dist/init.js +54 -54
  167. package/dist/lib/model-registry.js +6 -6
  168. package/dist/lib/skills-cache.js +6 -6
  169. package/dist/observability/otlp.js +12 -12
  170. package/dist/observability/redactor.js +8 -8
  171. package/dist/providers/fly.js +5 -5
  172. package/dist/providers/modal.js +5 -5
  173. package/dist/providers/registry.js +15 -3
  174. package/dist/providers/resolve-secrets.js +7 -7
  175. package/dist/providers/sprites.js +7 -7
  176. package/dist/providers/upstream-keys.js +12 -12
  177. package/dist/providers/vercel.js +5 -5
  178. package/dist/proxy/forward.js +6 -6
  179. package/dist/queue/index.js +6 -6
  180. package/dist/sessions/bus.js +10 -10
  181. package/dist/sessions/driver.js +47 -47
  182. package/dist/sessions/grader.js +5 -5
  183. package/dist/sessions/secrets.js +8 -8
  184. package/dist/sessions/sweeper.js +43 -43
  185. package/dist/sessions/threads.js +48 -48
  186. package/dist/shutdown.js +44 -44
  187. package/dist/sync/anthropic.js +10 -10
  188. package/dist/sync/container-file-sync.js +6 -6
  189. package/dist/sync/file-sync.js +17 -17
  190. package/dist/workers/runner.js +85 -0
  191. package/package.json +1 -1
@@ -0,0 +1,65 @@
1
+ import {
2
+ ackWorkItem,
3
+ completeWorkItem,
4
+ getWorkItemInputs,
5
+ heartbeatWorkItem,
6
+ pollWorkItem
7
+ } from "./chunk-D2GADI73.js";
8
+ import {
9
+ runTurn
10
+ } from "./chunk-7NZ46LIO.js";
11
+
12
+ // src/workers/runner.ts
13
+ async function startWorker(opts) {
14
+ const pollInterval = opts.pollIntervalMs ?? 5e3;
15
+ const workerId = opts.workerId ?? `worker-${process.pid}`;
16
+ let stopping = false;
17
+ process.on("SIGINT", () => {
18
+ stopping = true;
19
+ });
20
+ process.on("SIGTERM", () => {
21
+ stopping = true;
22
+ });
23
+ console.log(`[worker] starting: env=${opts.environmentId} poll=${pollInterval}ms worker=${workerId}`);
24
+ while (!stopping) {
25
+ const item = pollWorkItem(opts.environmentId, workerId);
26
+ if (!item) {
27
+ await new Promise((r) => setTimeout(r, pollInterval));
28
+ continue;
29
+ }
30
+ console.log(`[worker] claimed ${item.id} -> session ${item.data.id}`);
31
+ const acked = ackWorkItem(item.id, workerId);
32
+ if (!acked) {
33
+ console.warn(`[worker] ack failed for ${item.id} \u2014 another worker claimed it`);
34
+ continue;
35
+ }
36
+ const heartbeatTimer = setInterval(() => {
37
+ const result = heartbeatWorkItem(item.id);
38
+ if (result && !result.lease_extended) {
39
+ console.warn(`[worker] heartbeat failed for ${item.id}: state=${result.state}`);
40
+ }
41
+ }, 3e4);
42
+ try {
43
+ const inputsRaw = getWorkItemInputs(item.id);
44
+ const inputs = inputsRaw ? JSON.parse(inputsRaw) : [];
45
+ if (inputs.length > 0) {
46
+ await runTurn(item.data.id, inputs);
47
+ } else {
48
+ console.warn(`[worker] no inputs for ${item.id} \u2014 skipping`);
49
+ }
50
+ completeWorkItem(item.id, "completed");
51
+ console.log(`[worker] completed ${item.id}`);
52
+ } catch (err) {
53
+ const msg = err instanceof Error ? err.message : String(err);
54
+ console.error(`[worker] failed ${item.id}: ${msg}`);
55
+ completeWorkItem(item.id, "failed");
56
+ } finally {
57
+ clearInterval(heartbeatTimer);
58
+ }
59
+ }
60
+ console.log("[worker] stopped");
61
+ }
62
+
63
+ export {
64
+ startWorker
65
+ };
@@ -24,10 +24,11 @@ __export(schema_exports, {
24
24
  skillVersions: () => skillVersions,
25
25
  skills: () => skills,
26
26
  vaultEntries: () => vaultEntries,
27
- vaults: () => vaults
27
+ vaults: () => vaults,
28
+ workItems: () => workItems
28
29
  });
29
30
  import { sqliteTable, text, integer, real, primaryKey } from "drizzle-orm/sqlite-core";
30
- var settings, proxyResources, apiKeys, agents, agentVersions, environments, sessions, events, sessionThreads, vaults, vaultEntries, memoryStores, memoryVersions, memories, files, sessionResources, skills, skillVersions, anthropicSync;
31
+ var settings, proxyResources, apiKeys, agents, agentVersions, environments, sessions, events, sessionThreads, vaults, vaultEntries, memoryStores, memoryVersions, memories, files, sessionResources, skills, skillVersions, workItems, anthropicSync;
31
32
  var init_schema = __esm({
32
33
  "src/db/schema.ts"() {
33
34
  settings = sqliteTable("settings", {
@@ -275,6 +276,23 @@ var init_schema = __esm({
275
276
  files_json: text("files_json").notNull().default("{}"),
276
277
  created_at: integer("created_at").notNull()
277
278
  });
279
+ workItems = sqliteTable("work_items", {
280
+ id: text("id").primaryKey(),
281
+ environment_id: text("environment_id").notNull(),
282
+ session_id: text("session_id").notNull(),
283
+ state: text("state").notNull().default("queued"),
284
+ worker_id: text("worker_id"),
285
+ inputs_json: text("inputs_json"),
286
+ metadata_json: text("metadata_json").notNull().default("{}"),
287
+ tenant_id: text("tenant_id"),
288
+ created_at: integer("created_at").notNull(),
289
+ acknowledged_at: integer("acknowledged_at"),
290
+ started_at: integer("started_at"),
291
+ latest_heartbeat_at: integer("latest_heartbeat_at"),
292
+ stop_requested_at: integer("stop_requested_at"),
293
+ stopped_at: integer("stopped_at"),
294
+ lease_expires_at: integer("lease_expires_at")
295
+ });
278
296
  anthropicSync = sqliteTable("anthropic_sync", {
279
297
  local_id: text("local_id").notNull(),
280
298
  resource_type: text("resource_type").notNull(),
@@ -306,6 +324,7 @@ export {
306
324
  sessionResources,
307
325
  skills,
308
326
  skillVersions,
327
+ workItems,
309
328
  anthropicSync,
310
329
  schema_exports,
311
330
  init_schema
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-3WZGFAV4.js";
3
+ } from "./chunk-WKGJQIRC.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getDrizzle,
3
3
  init_drizzle
4
- } from "./chunk-T75UYYMI.js";
4
+ } from "./chunk-PVFGDKXO.js";
5
5
 
6
6
  // src/db/traces.ts
7
7
  init_drizzle();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-3WZGFAV4.js";
3
+ } from "./chunk-WKGJQIRC.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  BatchError,
3
3
  executeBatch
4
- } from "./chunk-EZBJEV6F.js";
4
+ } from "./chunk-VTH56ERA.js";
5
5
  import {
6
6
  jsonOk,
7
7
  routeWrap
8
- } from "./chunk-WL3VMUAI.js";
8
+ } from "./chunk-FCKUWBUL.js";
9
9
  import {
10
10
  badRequest
11
11
  } from "./chunk-EZYKRG4W.js";
@@ -2,10 +2,10 @@ import {
2
2
  reportUpstreamFailure,
3
3
  reportUpstreamSuccess,
4
4
  resolveAnthropicKey
5
- } from "./chunk-HCORTMQH.js";
5
+ } from "./chunk-HHS6EHSG.js";
6
6
  import {
7
7
  resolveRemoteSessionId
8
- } from "./chunk-RNDLMMKI.js";
8
+ } from "./chunk-LOWHDHDD.js";
9
9
  import {
10
10
  assertResourceTenant
11
11
  } from "./chunk-23UKWXJH.js";
@@ -20,46 +20,50 @@ import {
20
20
  listMemoryStores,
21
21
  searchMemories,
22
22
  updateMemory
23
- } from "./chunk-YN2F26NN.js";
23
+ } from "./chunk-T3CXZ2BE.js";
24
24
  import {
25
25
  jsonOk,
26
26
  paginatedOk,
27
27
  routeWrap
28
- } from "./chunk-WL3VMUAI.js";
28
+ } from "./chunk-FCKUWBUL.js";
29
29
  import {
30
30
  forwardToAnthropic
31
- } from "./chunk-WKPUTJGD.js";
31
+ } from "./chunk-5LDBCBOR.js";
32
32
  import {
33
33
  enqueueTurn
34
- } from "./chunk-LEVIKSPQ.js";
34
+ } from "./chunk-MTRTBT7L.js";
35
35
  import {
36
36
  runTurn,
37
37
  writePermissionResponse
38
- } from "./chunk-BJ3EPRZU.js";
38
+ } from "./chunk-7NZ46LIO.js";
39
39
  import {
40
40
  getProxiedTenantId,
41
41
  isProxied
42
- } from "./chunk-EFSLGRY2.js";
42
+ } from "./chunk-YCL5RHEC.js";
43
43
  import {
44
44
  getActor
45
45
  } from "./chunk-LAWTTG2E.js";
46
46
  import {
47
47
  appendEvent
48
- } from "./chunk-CZ4IOIWV.js";
48
+ } from "./chunk-X23OAFFE.js";
49
49
  import {
50
50
  bumpSessionStats,
51
51
  getSession,
52
52
  getSessionRow,
53
53
  setOutcomeCriteria,
54
54
  updateSessionMutable
55
- } from "./chunk-32RP2UX6.js";
55
+ } from "./chunk-MTB7SCZ5.js";
56
56
  import {
57
57
  listEvents,
58
58
  rowToManagedEvent
59
- } from "./chunk-N33MOUCH.js";
59
+ } from "./chunk-PRWWTLPR.js";
60
+ import {
61
+ getEnvironment,
62
+ getEnvironmentRow
63
+ } from "./chunk-CFLMIJ2C.js";
60
64
  import {
61
65
  getAgent
62
- } from "./chunk-EGN4TPN5.js";
66
+ } from "./chunk-WT3SEE34.js";
63
67
  import {
64
68
  init_clock,
65
69
  nowMs
@@ -67,7 +71,7 @@ import {
67
71
  import {
68
72
  getDb,
69
73
  init_client
70
- } from "./chunk-XUODI55L.js";
74
+ } from "./chunk-U3QU5AVC.js";
71
75
  import {
72
76
  badRequest,
73
77
  notFound
@@ -655,11 +659,30 @@ function handlePostEvents(request, sessionId) {
655
659
  if (appended.pendingForTurn.length > 0) {
656
660
  const row = getSessionRow(sessionId);
657
661
  if (row) {
658
- void enqueueTurn(row.environment_id, () => runTurn(sessionId, appended.pendingForTurn)).catch(
659
- (err) => {
660
- console.error(`[events] enqueueTurn failed:`, err);
661
- }
662
- );
662
+ const env = getEnvironment(row.environment_id);
663
+ if (env?.config?.type === "self_hosted") {
664
+ const { createWorkItem } = await import("./db/work.js");
665
+ const { updateSessionStatus } = await import("./db/sessions.js");
666
+ const inputsJson = JSON.stringify(appended.pendingForTurn);
667
+ const envRow = getEnvironmentRow(row.environment_id);
668
+ createWorkItem(row.environment_id, sessionId, {
669
+ inputsJson,
670
+ tenantId: envRow?.tenant_id ?? void 0
671
+ });
672
+ updateSessionStatus(sessionId, "running");
673
+ appendEvent(sessionId, {
674
+ type: "session.status_running",
675
+ payload: {},
676
+ origin: "server",
677
+ processedAt: nowMs()
678
+ });
679
+ } else {
680
+ void enqueueTurn(row.environment_id, () => runTurn(sessionId, appended.pendingForTurn)).catch(
681
+ (err) => {
682
+ console.error(`[events] enqueueTurn failed:`, err);
683
+ }
684
+ );
685
+ }
663
686
  }
664
687
  }
665
688
  return jsonOk({ data: appended.rows.map(rowToManagedEvent) });
@@ -4,11 +4,11 @@ import {
4
4
  } from "./chunk-23UKWXJH.js";
5
5
  import {
6
6
  listAudit
7
- } from "./chunk-N5C3WQWD.js";
7
+ } from "./chunk-PDUQCDIO.js";
8
8
  import {
9
9
  paginatedOk,
10
10
  routeWrap
11
- } from "./chunk-WL3VMUAI.js";
11
+ } from "./chunk-FCKUWBUL.js";
12
12
  import {
13
13
  badRequest
14
14
  } from "./chunk-EZYKRG4W.js";
@@ -1,60 +1,60 @@
1
1
  import {
2
2
  enqueueTurn
3
- } from "./chunk-LEVIKSPQ.js";
3
+ } from "./chunk-MTRTBT7L.js";
4
4
  import {
5
5
  runTurn
6
- } from "./chunk-BJ3EPRZU.js";
6
+ } from "./chunk-7NZ46LIO.js";
7
7
  import {
8
8
  installOtlpExporter
9
- } from "./chunk-4JPJ3ZIV.js";
9
+ } from "./chunk-7Z6LTBYQ.js";
10
10
  import {
11
11
  redactAppendInput
12
- } from "./chunk-YFGBTXID.js";
12
+ } from "./chunk-FV2XE3DX.js";
13
13
  import {
14
14
  createApiKey,
15
15
  listApiKeys
16
- } from "./chunk-Z4DZMNDE.js";
16
+ } from "./chunk-W6QYWXOZ.js";
17
17
  import {
18
18
  initSentry
19
19
  } from "./chunk-3MQ2FWXS.js";
20
20
  import {
21
21
  installShutdownHandlers
22
- } from "./chunk-DVDNHXCM.js";
22
+ } from "./chunk-XSRIFWHR.js";
23
23
  import {
24
24
  runSweep
25
- } from "./chunk-4HFKDLD7.js";
25
+ } from "./chunk-UTQRPXTL.js";
26
26
  import {
27
27
  fillWarmPools,
28
28
  reconcileDockerOrphanSandboxes,
29
29
  reconcileOrphanSandboxes
30
- } from "./chunk-I7FLMXEF.js";
30
+ } from "./chunk-TN34IN7S.js";
31
31
  import {
32
32
  appendEvent,
33
33
  installPayloadRedactor
34
- } from "./chunk-CZ4IOIWV.js";
34
+ } from "./chunk-X23OAFFE.js";
35
35
  import {
36
36
  setSessionSandbox
37
- } from "./chunk-32RP2UX6.js";
37
+ } from "./chunk-MTB7SCZ5.js";
38
38
  import {
39
39
  readEnvValue,
40
40
  upsertEnvLine
41
41
  } from "./chunk-YPXI7Q2M.js";
42
42
  import {
43
43
  getLastUnprocessedUserMessage
44
- } from "./chunk-N33MOUCH.js";
44
+ } from "./chunk-PRWWTLPR.js";
45
45
  import {
46
46
  getBySession,
47
47
  register
48
48
  } from "./chunk-EFOIR7R3.js";
49
49
  import {
50
- resolveContainerProvider
51
- } from "./chunk-7KSQJK2V.js";
50
+ tryResolveProvider
51
+ } from "./chunk-JXU6SA6S.js";
52
52
  import {
53
53
  getEnvironment
54
- } from "./chunk-6BOOQV4Q.js";
54
+ } from "./chunk-CFLMIJ2C.js";
55
55
  import {
56
56
  getConfig
57
- } from "./chunk-3WZGFAV4.js";
57
+ } from "./chunk-WKGJQIRC.js";
58
58
  import {
59
59
  init_clock,
60
60
  nowMs
@@ -62,7 +62,7 @@ import {
62
62
  import {
63
63
  getDb,
64
64
  init_client
65
- } from "./chunk-XUODI55L.js";
65
+ } from "./chunk-U3QU5AVC.js";
66
66
  import {
67
67
  getRuntime
68
68
  } from "./chunk-UYTSKFGK.js";
@@ -184,7 +184,8 @@ async function recoverStaleSessions() {
184
184
  if (lastMsg) {
185
185
  if (row.sandbox_name) {
186
186
  const envObj = getEnvironment(row.environment_id);
187
- const provider = await resolveContainerProvider(envObj?.config?.provider);
187
+ const provider = await tryResolveProvider({ envConfigProvider: envObj?.config?.provider });
188
+ if (!provider) continue;
188
189
  try {
189
190
  const containers = await provider.list({ prefix: row.sandbox_name });
190
191
  const alive = containers.some((c) => c.name === row.sandbox_name);
@@ -267,7 +268,8 @@ async function rebuildContainerPool() {
267
268
  if (getBySession(row.id)) continue;
268
269
  try {
269
270
  const envObj = getEnvironment(row.environment_id);
270
- const provider = await resolveContainerProvider(envObj?.config?.provider);
271
+ const provider = await tryResolveProvider({ envConfigProvider: envObj?.config?.provider });
272
+ if (!provider) continue;
271
273
  const containers = await provider.list({ prefix: row.sandbox_name });
272
274
  const alive = containers.some((c) => c.name === row.sandbox_name);
273
275
  if (alive) {
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  getDb,
16
16
  init_client
17
- } from "./chunk-XUODI55L.js";
17
+ } from "./chunk-U3QU5AVC.js";
18
18
 
19
19
  // src/db/credentials.ts
20
20
  init_client();
@@ -1,6 +1,13 @@
1
1
  import {
2
2
  parseNDJSONLines
3
3
  } from "./chunk-PJZ5TQYW.js";
4
+ import {
5
+ childSpan,
6
+ newTrace
7
+ } from "./chunk-AU4NAQGA.js";
8
+ import {
9
+ injectMcpAuthHeaders
10
+ } from "./chunk-DBFPJSOY.js";
4
11
  import {
5
12
  incrementRetry,
6
13
  resetRetry,
@@ -9,14 +16,7 @@ import {
9
16
  } from "./chunk-72BKGVBE.js";
10
17
  import {
11
18
  loadSessionSecrets
12
- } from "./chunk-Y3EUEPGQ.js";
13
- import {
14
- childSpan,
15
- newTrace
16
- } from "./chunk-AU4NAQGA.js";
17
- import {
18
- injectMcpAuthHeaders
19
- } from "./chunk-DBFPJSOY.js";
19
+ } from "./chunk-UWHV7EJG.js";
20
20
  import {
21
21
  buildErrorPayload,
22
22
  classifyError,
@@ -24,21 +24,21 @@ import {
24
24
  } from "./chunk-H6TQGV4L.js";
25
25
  import {
26
26
  isProxied
27
- } from "./chunk-EFSLGRY2.js";
27
+ } from "./chunk-YCL5RHEC.js";
28
28
  import {
29
29
  acquireForFirstTurn,
30
30
  installSkills,
31
31
  provisionResources,
32
32
  wrapProviderWithSecrets
33
- } from "./chunk-I7FLMXEF.js";
33
+ } from "./chunk-TN34IN7S.js";
34
34
  import {
35
35
  BLOCKED_ENV_KEYS,
36
36
  resolveVaultSecrets
37
- } from "./chunk-6ERUVF2Y.js";
37
+ } from "./chunk-QB7JAMWG.js";
38
38
  import {
39
39
  appendEvent,
40
40
  appendEventsBatch
41
- } from "./chunk-CZ4IOIWV.js";
41
+ } from "./chunk-X23OAFFE.js";
42
42
  import {
43
43
  bumpSessionStats,
44
44
  getOutcomeCriteria,
@@ -49,26 +49,27 @@ import {
49
49
  setOutcomeCriteria,
50
50
  updateSessionMutable,
51
51
  updateSessionStatus
52
- } from "./chunk-32RP2UX6.js";
52
+ } from "./chunk-MTB7SCZ5.js";
53
53
  import {
54
54
  listEvents,
55
55
  markUserEventProcessed
56
- } from "./chunk-N33MOUCH.js";
56
+ } from "./chunk-PRWWTLPR.js";
57
57
  import {
58
58
  getBySession
59
59
  } from "./chunk-EFOIR7R3.js";
60
60
  import {
61
- resolveContainerProvider
62
- } from "./chunk-7KSQJK2V.js";
61
+ resolveProvider,
62
+ resolveProviderName
63
+ } from "./chunk-JXU6SA6S.js";
63
64
  import {
64
65
  getEnvironment
65
- } from "./chunk-6BOOQV4Q.js";
66
+ } from "./chunk-CFLMIJ2C.js";
66
67
  import {
67
68
  getAgent
68
- } from "./chunk-EGN4TPN5.js";
69
+ } from "./chunk-WT3SEE34.js";
69
70
  import {
70
71
  resolveBackend
71
- } from "./chunk-4N7WVJHB.js";
72
+ } from "./chunk-R5LXEIOJ.js";
72
73
  import {
73
74
  PERMISSION_BRIDGE_PENDING_PATH,
74
75
  PERMISSION_BRIDGE_REQUEST_PATH,
@@ -84,7 +85,7 @@ import {
84
85
  } from "./chunk-FX2AEKOV.js";
85
86
  import {
86
87
  getConfig
87
- } from "./chunk-3WZGFAV4.js";
88
+ } from "./chunk-WKGJQIRC.js";
88
89
  import {
89
90
  init_clock,
90
91
  nowMs
@@ -236,7 +237,7 @@ async function runTurn(sessionId, inputs, _depth = 0, parentTrace) {
236
237
  if (newSkills.length > 0) {
237
238
  console.log(`[driver] ${sessionId} injecting ${newSkills.length} new skill(s)...`);
238
239
  const envRow = getEnvironment(session.environment_id);
239
- const baseProvider = await resolveContainerProvider(envRow?.config?.provider);
240
+ const baseProvider = await resolveProvider({ envConfigProvider: envRow?.config?.provider });
240
241
  const sp = wrapProviderWithSecrets(baseProvider, postAcquireSecrets);
241
242
  await installSkills(sandboxName, sp, newSkills, agent.engine);
242
243
  console.log(`[driver] ${sessionId} skills injected`);
@@ -245,7 +246,7 @@ async function runTurn(sessionId, inputs, _depth = 0, parentTrace) {
245
246
  const freshSession2 = getSession(sessionId);
246
247
  if (freshSession2?.resources && freshSession2.resources.length > 0) {
247
248
  const envRow = getEnvironment(session.environment_id);
248
- const baseProvider = await resolveContainerProvider(envRow?.config?.provider);
249
+ const baseProvider = await resolveProvider({ envConfigProvider: envRow?.config?.provider });
249
250
  const sp = wrapProviderWithSecrets(baseProvider, postAcquireSecrets);
250
251
  await provisionResources(sandboxName, freshSession2.resources, sp);
251
252
  }
@@ -308,7 +309,7 @@ async function runTurn(sessionId, inputs, _depth = 0, parentTrace) {
308
309
  }
309
310
  if (agent.engine === "codex") {
310
311
  const envRow = getEnvironment(session.environment_id);
311
- const provName = envRow?.config?.provider ?? "docker";
312
+ const provName = resolveProviderName({ envConfigProvider: envRow?.config?.provider });
312
313
  const firecrackerProviders = /* @__PURE__ */ new Set(["sprites", "fly", "apple-firecracker"]);
313
314
  if (firecrackerProviders.has(provName)) {
314
315
  const faIdx = turnBuild.argv.indexOf("--full-auto");
@@ -352,7 +353,7 @@ async function runTurn(sessionId, inputs, _depth = 0, parentTrace) {
352
353
  let ollamaHostPort;
353
354
  if (!turnBuild.env.OLLAMA_HOST) {
354
355
  const envRow = getEnvironment(session.environment_id);
355
- const provName = envRow?.config?.provider ?? "docker";
356
+ const provName = resolveProviderName({ envConfigProvider: envRow?.config?.provider });
356
357
  if (provName === "docker" || provName === "podman") {
357
358
  ollamaHostPort = "host.docker.internal:11434";
358
359
  } else if (provName === "apple-container" || provName === "apple-firecracker") {
@@ -392,7 +393,7 @@ async function runTurn(sessionId, inputs, _depth = 0, parentTrace) {
392
393
 
393
394
  ${turnBuild.stdin}`;
394
395
  const env = getEnvironment(session.environment_id);
395
- const provider = await resolveContainerProvider(env?.config?.provider);
396
+ const provider = await resolveProvider({ envConfigProvider: env?.config?.provider });
396
397
  const poolEntry = getBySession(sessionId);
397
398
  const secrets = poolEntry?.vaultSecrets ?? (session.vault_ids?.length ? resolveVaultSecrets(session.vault_ids) : void 0);
398
399
  const tools = resolveToolset(agent.tools);
@@ -666,7 +667,7 @@ ${turnBuild.stdin}`;
666
667
  if (sprName) {
667
668
  const responseJson = JSON.stringify({ content: [{ type: "text", text: serverToolResult.text }] });
668
669
  const envForSession = getEnvironment(session.environment_id);
669
- const providerForReentry = await resolveContainerProvider(envForSession?.config?.provider);
670
+ const providerForReentry = await resolveProvider({ envConfigProvider: envForSession?.config?.provider });
670
671
  const reentrySecrets = getBySession(sessionId)?.vaultSecrets;
671
672
  await providerForReentry.exec(
672
673
  sprName,
@@ -867,7 +868,7 @@ async function writePermissionResponse(sessionId, result, denyMessage) {
867
868
  return;
868
869
  }
869
870
  const env = getEnvironment(row.environment_id);
870
- const provider = await resolveContainerProvider(env?.config?.provider);
871
+ const provider = await resolveProvider({ envConfigProvider: env?.config?.provider });
871
872
  const permSecrets = getBySession(sessionId)?.vaultSecrets;
872
873
  const response = JSON.stringify({
873
874
  result,
@@ -936,7 +937,7 @@ async function writeToolBridgeResponse(sessionId, content) {
936
937
  return;
937
938
  }
938
939
  const env = getEnvironment(row.environment_id);
939
- const provider = await resolveContainerProvider(env?.config?.provider);
940
+ const provider = await resolveProvider({ envConfigProvider: env?.config?.provider });
940
941
  const bridgeSecrets = getBySession(sessionId)?.vaultSecrets;
941
942
  const response = JSON.stringify({ content });
942
943
  try {
@@ -8,14 +8,14 @@ import {
8
8
  import {
9
9
  jsonOk,
10
10
  routeWrap
11
- } from "./chunk-WL3VMUAI.js";
11
+ } from "./chunk-FCKUWBUL.js";
12
12
  import {
13
13
  snapshotApiMetrics
14
14
  } from "./chunk-D2XITRN6.js";
15
15
  import {
16
16
  getDb,
17
17
  init_client
18
- } from "./chunk-XUODI55L.js";
18
+ } from "./chunk-U3QU5AVC.js";
19
19
  import {
20
20
  badRequest
21
21
  } from "./chunk-EZYKRG4W.js";
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  onAfterCommit
3
- } from "./chunk-CZ4IOIWV.js";
3
+ } from "./chunk-X23OAFFE.js";
4
4
  import {
5
5
  getSessionRow
6
- } from "./chunk-32RP2UX6.js";
6
+ } from "./chunk-MTB7SCZ5.js";
7
7
  import {
8
8
  listEventsByTrace
9
- } from "./chunk-N33MOUCH.js";
9
+ } from "./chunk-PRWWTLPR.js";
10
10
  import {
11
11
  getAgent
12
- } from "./chunk-EGN4TPN5.js";
12
+ } from "./chunk-WT3SEE34.js";
13
13
  import {
14
14
  getConfig
15
- } from "./chunk-3WZGFAV4.js";
15
+ } from "./chunk-WKGJQIRC.js";
16
16
 
17
17
  // src/observability/otlp.ts
18
18
  import { createHash } from "crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-3WZGFAV4.js";
3
+ } from "./chunk-WKGJQIRC.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -1,3 +1,10 @@
1
+ import {
2
+ buildCodexArgs
3
+ } from "./chunk-PJYCPDV5.js";
4
+ import {
5
+ buildCodexAuthEnv,
6
+ validateCodexRuntime
7
+ } from "./chunk-MQBNN4KH.js";
1
8
  import {
2
9
  prepareCodexOnSandbox
3
10
  } from "./chunk-NMZMRH3E.js";
@@ -7,13 +14,6 @@ import {
7
14
  import {
8
15
  CODEX_WRAPPER_PATH
9
16
  } from "./chunk-XJYR5HE3.js";
10
- import {
11
- buildCodexArgs
12
- } from "./chunk-PJYCPDV5.js";
13
- import {
14
- buildCodexAuthEnv,
15
- validateCodexRuntime
16
- } from "./chunk-IBO36HUU.js";
17
17
  import {
18
18
  wrapPromptWithSystem
19
19
  } from "./chunk-YE2RMJY7.js";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  jsonOk,
6
6
  routeWrap
7
- } from "./chunk-WL3VMUAI.js";
7
+ } from "./chunk-FCKUWBUL.js";
8
8
 
9
9
  // src/handlers/license.ts
10
10
  function handleGetLicense(request) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  forwardToAnthropic
3
- } from "./chunk-WKPUTJGD.js";
3
+ } from "./chunk-5LDBCBOR.js";
4
4
  import {
5
5
  isAnthropicApiKey,
6
6
  isPassthroughAllowedPath
@@ -8,10 +8,10 @@ import {
8
8
  import {
9
9
  findByRawKey,
10
10
  hydratePermissions
11
- } from "./chunk-Z4DZMNDE.js";
11
+ } from "./chunk-W6QYWXOZ.js";
12
12
  import {
13
13
  getConfig
14
- } from "./chunk-3WZGFAV4.js";
14
+ } from "./chunk-WKGJQIRC.js";
15
15
  import {
16
16
  unauthorized
17
17
  } from "./chunk-EZYKRG4W.js";