@stateset/sandbox-cli 1.0.5 → 3.3.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.
Files changed (411) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +22 -0
  3. package/README.md +805 -0
  4. package/dist/client.d.ts +761 -10
  5. package/dist/client.d.ts.map +1 -1
  6. package/dist/client.js +684 -12
  7. package/dist/client.js.map +1 -1
  8. package/dist/commands/alias.d.ts +5 -0
  9. package/dist/commands/alias.d.ts.map +1 -0
  10. package/dist/commands/alias.js +131 -0
  11. package/dist/commands/alias.js.map +1 -0
  12. package/dist/commands/api-key.d.ts +3 -0
  13. package/dist/commands/api-key.d.ts.map +1 -0
  14. package/dist/commands/api-key.js +119 -0
  15. package/dist/commands/api-key.js.map +1 -0
  16. package/dist/commands/artifact.d.ts.map +1 -1
  17. package/dist/commands/artifact.js +105 -46
  18. package/dist/commands/artifact.js.map +1 -1
  19. package/dist/commands/audit.d.ts +3 -0
  20. package/dist/commands/audit.d.ts.map +1 -0
  21. package/dist/commands/audit.js +191 -0
  22. package/dist/commands/audit.js.map +1 -0
  23. package/dist/commands/auth.d.ts +3 -0
  24. package/dist/commands/auth.d.ts.map +1 -0
  25. package/dist/commands/auth.js +126 -0
  26. package/dist/commands/auth.js.map +1 -0
  27. package/dist/commands/benchmark.d.ts +3 -0
  28. package/dist/commands/benchmark.d.ts.map +1 -0
  29. package/dist/commands/benchmark.js +166 -0
  30. package/dist/commands/benchmark.js.map +1 -0
  31. package/dist/commands/billing.d.ts +3 -0
  32. package/dist/commands/billing.d.ts.map +1 -0
  33. package/dist/commands/billing.js +139 -0
  34. package/dist/commands/billing.js.map +1 -0
  35. package/dist/commands/checkpoint.d.ts.map +1 -1
  36. package/dist/commands/checkpoint.js +105 -48
  37. package/dist/commands/checkpoint.js.map +1 -1
  38. package/dist/commands/completion.d.ts +3 -0
  39. package/dist/commands/completion.d.ts.map +1 -0
  40. package/dist/commands/completion.js +134 -0
  41. package/dist/commands/completion.js.map +1 -0
  42. package/dist/commands/computer-use.d.ts +3 -0
  43. package/dist/commands/computer-use.d.ts.map +1 -0
  44. package/dist/commands/computer-use.js +124 -0
  45. package/dist/commands/computer-use.js.map +1 -0
  46. package/dist/commands/config.d.ts.map +1 -1
  47. package/dist/commands/config.js +2 -1
  48. package/dist/commands/config.js.map +1 -1
  49. package/dist/commands/context.d.ts +3 -0
  50. package/dist/commands/context.d.ts.map +1 -0
  51. package/dist/commands/context.js +98 -0
  52. package/dist/commands/context.js.map +1 -0
  53. package/dist/commands/cp.d.ts +3 -0
  54. package/dist/commands/cp.d.ts.map +1 -0
  55. package/dist/commands/cp.js +165 -0
  56. package/dist/commands/cp.js.map +1 -0
  57. package/dist/commands/deploy.d.ts +3 -0
  58. package/dist/commands/deploy.d.ts.map +1 -1
  59. package/dist/commands/deploy.js +68 -20
  60. package/dist/commands/deploy.js.map +1 -1
  61. package/dist/commands/diff.d.ts +3 -0
  62. package/dist/commands/diff.d.ts.map +1 -0
  63. package/dist/commands/diff.js +186 -0
  64. package/dist/commands/diff.js.map +1 -0
  65. package/dist/commands/doctor.d.ts +30 -0
  66. package/dist/commands/doctor.d.ts.map +1 -1
  67. package/dist/commands/doctor.js +177 -207
  68. package/dist/commands/doctor.js.map +1 -1
  69. package/dist/commands/egress.d.ts +3 -0
  70. package/dist/commands/egress.d.ts.map +1 -0
  71. package/dist/commands/egress.js +155 -0
  72. package/dist/commands/egress.js.map +1 -0
  73. package/dist/commands/env.d.ts +3 -0
  74. package/dist/commands/env.d.ts.map +1 -0
  75. package/dist/commands/env.js +169 -0
  76. package/dist/commands/env.js.map +1 -0
  77. package/dist/commands/governance.d.ts +47 -0
  78. package/dist/commands/governance.d.ts.map +1 -0
  79. package/dist/commands/governance.js +345 -0
  80. package/dist/commands/governance.js.map +1 -0
  81. package/dist/commands/grade.d.ts +41 -0
  82. package/dist/commands/grade.d.ts.map +1 -1
  83. package/dist/commands/grade.js +255 -160
  84. package/dist/commands/grade.js.map +1 -1
  85. package/dist/commands/history.d.ts +4 -0
  86. package/dist/commands/history.d.ts.map +1 -0
  87. package/dist/commands/history.js +157 -0
  88. package/dist/commands/history.js.map +1 -0
  89. package/dist/commands/images.d.ts +8 -0
  90. package/dist/commands/images.d.ts.map +1 -0
  91. package/dist/commands/images.js +145 -0
  92. package/dist/commands/images.js.map +1 -0
  93. package/dist/commands/info.d.ts +3 -0
  94. package/dist/commands/info.d.ts.map +1 -0
  95. package/dist/commands/info.js +86 -0
  96. package/dist/commands/info.js.map +1 -0
  97. package/dist/commands/init.d.ts +3 -0
  98. package/dist/commands/init.d.ts.map +1 -0
  99. package/dist/commands/init.js +185 -0
  100. package/dist/commands/init.js.map +1 -0
  101. package/dist/commands/logs.d.ts +3 -0
  102. package/dist/commands/logs.d.ts.map +1 -0
  103. package/dist/commands/logs.js +129 -0
  104. package/dist/commands/logs.js.map +1 -0
  105. package/dist/commands/mcp.d.ts +3 -0
  106. package/dist/commands/mcp.d.ts.map +1 -0
  107. package/dist/commands/mcp.js +141 -0
  108. package/dist/commands/mcp.js.map +1 -0
  109. package/dist/commands/open.d.ts +3 -0
  110. package/dist/commands/open.d.ts.map +1 -0
  111. package/dist/commands/open.js +96 -0
  112. package/dist/commands/open.js.map +1 -0
  113. package/dist/commands/platform-status.d.ts +25 -5
  114. package/dist/commands/platform-status.d.ts.map +1 -1
  115. package/dist/commands/platform-status.js +199 -149
  116. package/dist/commands/platform-status.js.map +1 -1
  117. package/dist/commands/plugin.d.ts +5 -0
  118. package/dist/commands/plugin.d.ts.map +1 -0
  119. package/dist/commands/plugin.js +126 -0
  120. package/dist/commands/plugin.js.map +1 -0
  121. package/dist/commands/pool.d.ts.map +1 -1
  122. package/dist/commands/pool.js +52 -66
  123. package/dist/commands/pool.js.map +1 -1
  124. package/dist/commands/profile.d.ts +3 -0
  125. package/dist/commands/profile.d.ts.map +1 -0
  126. package/dist/commands/profile.js +107 -0
  127. package/dist/commands/profile.js.map +1 -0
  128. package/dist/commands/repl.d.ts +3 -0
  129. package/dist/commands/repl.d.ts.map +1 -0
  130. package/dist/commands/repl.js +390 -0
  131. package/dist/commands/repl.js.map +1 -0
  132. package/dist/commands/run.d.ts +3 -0
  133. package/dist/commands/run.d.ts.map +1 -0
  134. package/dist/commands/run.js +121 -0
  135. package/dist/commands/run.js.map +1 -0
  136. package/dist/commands/sandbox-processes.d.ts +27 -0
  137. package/dist/commands/sandbox-processes.d.ts.map +1 -0
  138. package/dist/commands/sandbox-processes.js +195 -0
  139. package/dist/commands/sandbox-processes.js.map +1 -0
  140. package/dist/commands/sandbox.d.ts.map +1 -1
  141. package/dist/commands/sandbox.js +506 -98
  142. package/dist/commands/sandbox.js.map +1 -1
  143. package/dist/commands/secret.d.ts +3 -0
  144. package/dist/commands/secret.d.ts.map +1 -0
  145. package/dist/commands/secret.js +128 -0
  146. package/dist/commands/secret.js.map +1 -0
  147. package/dist/commands/session.d.ts.map +1 -1
  148. package/dist/commands/session.js +285 -52
  149. package/dist/commands/session.js.map +1 -1
  150. package/dist/commands/snapshot.d.ts +3 -0
  151. package/dist/commands/snapshot.d.ts.map +1 -0
  152. package/dist/commands/snapshot.js +253 -0
  153. package/dist/commands/snapshot.js.map +1 -0
  154. package/dist/commands/ssh.d.ts +5 -0
  155. package/dist/commands/ssh.d.ts.map +1 -0
  156. package/dist/commands/ssh.js +154 -0
  157. package/dist/commands/ssh.js.map +1 -0
  158. package/dist/commands/template.d.ts +3 -0
  159. package/dist/commands/template.d.ts.map +1 -0
  160. package/dist/commands/template.js +102 -0
  161. package/dist/commands/template.js.map +1 -0
  162. package/dist/commands/terminal.d.ts +53 -0
  163. package/dist/commands/terminal.d.ts.map +1 -0
  164. package/dist/commands/terminal.js +381 -0
  165. package/dist/commands/terminal.js.map +1 -0
  166. package/dist/commands/top.d.ts +3 -0
  167. package/dist/commands/top.d.ts.map +1 -0
  168. package/dist/commands/top.js +116 -0
  169. package/dist/commands/top.js.map +1 -0
  170. package/dist/commands/tunnel.d.ts.map +1 -1
  171. package/dist/commands/tunnel.js +73 -26
  172. package/dist/commands/tunnel.js.map +1 -1
  173. package/dist/commands/update.d.ts +3 -0
  174. package/dist/commands/update.d.ts.map +1 -0
  175. package/dist/commands/update.js +51 -0
  176. package/dist/commands/update.js.map +1 -0
  177. package/dist/commands/wait.d.ts +3 -0
  178. package/dist/commands/wait.d.ts.map +1 -0
  179. package/dist/commands/wait.js +64 -0
  180. package/dist/commands/wait.js.map +1 -0
  181. package/dist/commands/webhook.d.ts +3 -0
  182. package/dist/commands/webhook.d.ts.map +1 -0
  183. package/dist/commands/webhook.js +169 -0
  184. package/dist/commands/webhook.js.map +1 -0
  185. package/dist/config.d.ts +14 -6
  186. package/dist/config.d.ts.map +1 -1
  187. package/dist/config.js +109 -16
  188. package/dist/config.js.map +1 -1
  189. package/dist/index.js +165 -11
  190. package/dist/index.js.map +1 -1
  191. package/dist/sandboxctl.d.ts +3 -0
  192. package/dist/sandboxctl.d.ts.map +1 -0
  193. package/dist/sandboxctl.js +37 -0
  194. package/dist/sandboxctl.js.map +1 -0
  195. package/dist/utils/context.d.ts +23 -0
  196. package/dist/utils/context.d.ts.map +1 -0
  197. package/dist/utils/context.js +48 -0
  198. package/dist/utils/context.js.map +1 -0
  199. package/dist/utils/credentials.d.ts +8 -0
  200. package/dist/utils/credentials.d.ts.map +1 -0
  201. package/dist/utils/credentials.js +120 -0
  202. package/dist/utils/credentials.js.map +1 -0
  203. package/dist/utils/dry-run.d.ts +4 -0
  204. package/dist/utils/dry-run.d.ts.map +1 -0
  205. package/dist/utils/dry-run.js +24 -0
  206. package/dist/utils/dry-run.js.map +1 -0
  207. package/dist/utils/egress-policy.d.ts +31 -0
  208. package/dist/utils/egress-policy.d.ts.map +1 -0
  209. package/dist/utils/egress-policy.js +83 -0
  210. package/dist/utils/egress-policy.js.map +1 -0
  211. package/dist/utils/errors.d.ts +53 -0
  212. package/dist/utils/errors.d.ts.map +1 -0
  213. package/dist/utils/errors.js +278 -0
  214. package/dist/utils/errors.js.map +1 -0
  215. package/dist/utils/file-content.d.ts +10 -0
  216. package/dist/utils/file-content.d.ts.map +1 -0
  217. package/dist/utils/file-content.js +14 -0
  218. package/dist/utils/file-content.js.map +1 -0
  219. package/dist/utils/grade-target.d.ts +12 -0
  220. package/dist/utils/grade-target.d.ts.map +1 -0
  221. package/dist/utils/grade-target.js +106 -0
  222. package/dist/utils/grade-target.js.map +1 -0
  223. package/dist/utils/health-report.d.ts +18 -0
  224. package/dist/utils/health-report.d.ts.map +1 -0
  225. package/dist/utils/health-report.js +43 -0
  226. package/dist/utils/health-report.js.map +1 -0
  227. package/dist/utils/output.d.ts +20 -0
  228. package/dist/utils/output.d.ts.map +1 -0
  229. package/dist/utils/output.js +123 -0
  230. package/dist/utils/output.js.map +1 -0
  231. package/dist/utils/plugins.d.ts +17 -0
  232. package/dist/utils/plugins.d.ts.map +1 -0
  233. package/dist/utils/plugins.js +57 -0
  234. package/dist/utils/plugins.js.map +1 -0
  235. package/dist/utils/resource-class.d.ts +12 -0
  236. package/dist/utils/resource-class.d.ts.map +1 -0
  237. package/dist/utils/resource-class.js +17 -0
  238. package/dist/utils/resource-class.js.map +1 -0
  239. package/dist/utils/shutdown.d.ts +14 -0
  240. package/dist/utils/shutdown.d.ts.map +1 -0
  241. package/dist/utils/shutdown.js +54 -0
  242. package/dist/utils/shutdown.js.map +1 -0
  243. package/dist/utils/tty.d.ts +44 -0
  244. package/dist/utils/tty.d.ts.map +1 -0
  245. package/dist/utils/tty.js +93 -0
  246. package/dist/utils/tty.js.map +1 -0
  247. package/dist/utils/warnings.d.ts +4 -0
  248. package/dist/utils/warnings.d.ts.map +1 -0
  249. package/dist/utils/warnings.js +22 -0
  250. package/dist/utils/warnings.js.map +1 -0
  251. package/dist/utils/watch.d.ts +7 -0
  252. package/dist/utils/watch.d.ts.map +1 -0
  253. package/dist/utils/watch.js +55 -0
  254. package/dist/utils/watch.js.map +1 -0
  255. package/dist/workbench/actions.d.ts +26 -0
  256. package/dist/workbench/actions.d.ts.map +1 -0
  257. package/dist/workbench/actions.js +38 -0
  258. package/dist/workbench/actions.js.map +1 -0
  259. package/dist/workbench/agent-chat.d.ts +71 -0
  260. package/dist/workbench/agent-chat.d.ts.map +1 -0
  261. package/dist/workbench/agent-chat.js +223 -0
  262. package/dist/workbench/agent-chat.js.map +1 -0
  263. package/dist/workbench/batch-uploads.d.ts +36 -0
  264. package/dist/workbench/batch-uploads.d.ts.map +1 -0
  265. package/dist/workbench/batch-uploads.js +154 -0
  266. package/dist/workbench/batch-uploads.js.map +1 -0
  267. package/dist/workbench/commands.d.ts +6 -0
  268. package/dist/workbench/commands.d.ts.map +1 -0
  269. package/dist/workbench/commands.js +511 -0
  270. package/dist/workbench/commands.js.map +1 -0
  271. package/dist/workbench/connection-failure.d.ts +9 -0
  272. package/dist/workbench/connection-failure.d.ts.map +1 -0
  273. package/dist/workbench/connection-failure.js +27 -0
  274. package/dist/workbench/connection-failure.js.map +1 -0
  275. package/dist/workbench/connection.d.ts +4 -0
  276. package/dist/workbench/connection.d.ts.map +1 -0
  277. package/dist/workbench/connection.js +28 -0
  278. package/dist/workbench/connection.js.map +1 -0
  279. package/dist/workbench/creation.d.ts +22 -0
  280. package/dist/workbench/creation.d.ts.map +1 -0
  281. package/dist/workbench/creation.js +102 -0
  282. package/dist/workbench/creation.js.map +1 -0
  283. package/dist/workbench/credits.d.ts +11 -0
  284. package/dist/workbench/credits.d.ts.map +1 -0
  285. package/dist/workbench/credits.js +132 -0
  286. package/dist/workbench/credits.js.map +1 -0
  287. package/dist/workbench/docker.d.ts +18 -0
  288. package/dist/workbench/docker.d.ts.map +1 -0
  289. package/dist/workbench/docker.js +207 -0
  290. package/dist/workbench/docker.js.map +1 -0
  291. package/dist/workbench/execution.d.ts +14 -0
  292. package/dist/workbench/execution.d.ts.map +1 -0
  293. package/dist/workbench/execution.js +24 -0
  294. package/dist/workbench/execution.js.map +1 -0
  295. package/dist/workbench/files.d.ts +51 -0
  296. package/dist/workbench/files.d.ts.map +1 -0
  297. package/dist/workbench/files.js +80 -0
  298. package/dist/workbench/files.js.map +1 -0
  299. package/dist/workbench/history.d.ts +34 -0
  300. package/dist/workbench/history.d.ts.map +1 -0
  301. package/dist/workbench/history.js +50 -0
  302. package/dist/workbench/history.js.map +1 -0
  303. package/dist/workbench/input-batch-commands.d.ts +6 -0
  304. package/dist/workbench/input-batch-commands.d.ts.map +1 -0
  305. package/dist/workbench/input-batch-commands.js +41 -0
  306. package/dist/workbench/input-batch-commands.js.map +1 -0
  307. package/dist/workbench/kitty-diacritics.d.ts +2 -0
  308. package/dist/workbench/kitty-diacritics.d.ts.map +1 -0
  309. package/dist/workbench/kitty-diacritics.js +22 -0
  310. package/dist/workbench/kitty-diacritics.js.map +1 -0
  311. package/dist/workbench/kitty-graphics.d.ts +59 -0
  312. package/dist/workbench/kitty-graphics.d.ts.map +1 -0
  313. package/dist/workbench/kitty-graphics.js +263 -0
  314. package/dist/workbench/kitty-graphics.js.map +1 -0
  315. package/dist/workbench/live-execution.d.ts +51 -0
  316. package/dist/workbench/live-execution.d.ts.map +1 -0
  317. package/dist/workbench/live-execution.js +222 -0
  318. package/dist/workbench/live-execution.js.map +1 -0
  319. package/dist/workbench/model.d.ts +106 -0
  320. package/dist/workbench/model.d.ts.map +1 -0
  321. package/dist/workbench/model.js +236 -0
  322. package/dist/workbench/model.js.map +1 -0
  323. package/dist/workbench/overview.d.ts +11 -0
  324. package/dist/workbench/overview.d.ts.map +1 -0
  325. package/dist/workbench/overview.js +92 -0
  326. package/dist/workbench/overview.js.map +1 -0
  327. package/dist/workbench/png.d.ts +10 -0
  328. package/dist/workbench/png.d.ts.map +1 -0
  329. package/dist/workbench/png.js +51 -0
  330. package/dist/workbench/png.js.map +1 -0
  331. package/dist/workbench/python-task.d.ts +21 -0
  332. package/dist/workbench/python-task.d.ts.map +1 -0
  333. package/dist/workbench/python-task.js +52 -0
  334. package/dist/workbench/python-task.js.map +1 -0
  335. package/dist/workbench/registry-commands.d.ts +8 -0
  336. package/dist/workbench/registry-commands.d.ts.map +1 -0
  337. package/dist/workbench/registry-commands.js +93 -0
  338. package/dist/workbench/registry-commands.js.map +1 -0
  339. package/dist/workbench/registry.d.ts +76 -0
  340. package/dist/workbench/registry.d.ts.map +1 -0
  341. package/dist/workbench/registry.js +353 -0
  342. package/dist/workbench/registry.js.map +1 -0
  343. package/dist/workbench/renderer.d.ts +6 -0
  344. package/dist/workbench/renderer.d.ts.map +1 -0
  345. package/dist/workbench/renderer.js +18 -0
  346. package/dist/workbench/renderer.js.map +1 -0
  347. package/dist/workbench/results.d.ts +15 -0
  348. package/dist/workbench/results.d.ts.map +1 -0
  349. package/dist/workbench/results.js +29 -0
  350. package/dist/workbench/results.js.map +1 -0
  351. package/dist/workbench/task-archive.d.ts +23 -0
  352. package/dist/workbench/task-archive.d.ts.map +1 -0
  353. package/dist/workbench/task-archive.js +56 -0
  354. package/dist/workbench/task-archive.js.map +1 -0
  355. package/dist/workbench/task-board.d.ts +26 -0
  356. package/dist/workbench/task-board.d.ts.map +1 -0
  357. package/dist/workbench/task-board.js +43 -0
  358. package/dist/workbench/task-board.js.map +1 -0
  359. package/dist/workbench/task-monitor.d.ts +35 -0
  360. package/dist/workbench/task-monitor.d.ts.map +1 -0
  361. package/dist/workbench/task-monitor.js +176 -0
  362. package/dist/workbench/task-monitor.js.map +1 -0
  363. package/dist/workbench/tasks.d.ts +93 -0
  364. package/dist/workbench/tasks.d.ts.map +1 -0
  365. package/dist/workbench/tasks.js +195 -0
  366. package/dist/workbench/tasks.js.map +1 -0
  367. package/dist/workbench/terminal.d.ts +82 -0
  368. package/dist/workbench/terminal.d.ts.map +1 -0
  369. package/dist/workbench/terminal.js +2577 -0
  370. package/dist/workbench/terminal.js.map +1 -0
  371. package/dist/workbench/text.d.ts +10 -0
  372. package/dist/workbench/text.d.ts.map +1 -0
  373. package/dist/workbench/text.js +72 -0
  374. package/dist/workbench/text.js.map +1 -0
  375. package/dist/workbench/uploads.d.ts +12 -0
  376. package/dist/workbench/uploads.d.ts.map +1 -0
  377. package/dist/workbench/uploads.js +16 -0
  378. package/dist/workbench/uploads.js.map +1 -0
  379. package/dist/workbench/worker-launch.d.ts +10 -0
  380. package/dist/workbench/worker-launch.d.ts.map +1 -0
  381. package/dist/workbench/worker-launch.js +30 -0
  382. package/dist/workbench/worker-launch.js.map +1 -0
  383. package/dist/workbench/worker-monitor.d.ts +33 -0
  384. package/dist/workbench/worker-monitor.d.ts.map +1 -0
  385. package/dist/workbench/worker-monitor.js +142 -0
  386. package/dist/workbench/worker-monitor.js.map +1 -0
  387. package/dist/workbench/worker-output.d.ts +8 -0
  388. package/dist/workbench/worker-output.d.ts.map +1 -0
  389. package/dist/workbench/worker-output.js +32 -0
  390. package/dist/workbench/worker-output.js.map +1 -0
  391. package/dist/workbench/worker-result.d.ts +29 -0
  392. package/dist/workbench/worker-result.d.ts.map +1 -0
  393. package/dist/workbench/worker-result.js +85 -0
  394. package/dist/workbench/worker-result.js.map +1 -0
  395. package/dist/workbench/workers.d.ts +49 -0
  396. package/dist/workbench/workers.d.ts.map +1 -0
  397. package/dist/workbench/workers.js +53 -0
  398. package/dist/workbench/workers.js.map +1 -0
  399. package/package.json +38 -17
  400. package/dist/__tests__/client.test.d.ts +0 -2
  401. package/dist/__tests__/client.test.d.ts.map +0 -1
  402. package/dist/__tests__/client.test.js +0 -198
  403. package/dist/__tests__/client.test.js.map +0 -1
  404. package/dist/__tests__/config.test.d.ts +0 -2
  405. package/dist/__tests__/config.test.d.ts.map +0 -1
  406. package/dist/__tests__/config.test.js +0 -74
  407. package/dist/__tests__/config.test.js.map +0 -1
  408. package/dist/__tests__/utils-cli.test.d.ts +0 -2
  409. package/dist/__tests__/utils-cli.test.d.ts.map +0 -1
  410. package/dist/__tests__/utils-cli.test.js +0 -35
  411. package/dist/__tests__/utils-cli.test.js.map +0 -1
package/dist/client.js CHANGED
@@ -1,5 +1,71 @@
1
1
  import { StateSetSandboxExtended } from '@stateset/sandbox-sdk';
2
2
  import { getConfig } from './config.js';
3
+ import { buildEgressPolicyBody, normalizeEgressPolicy } from './utils/egress-policy.js';
4
+ export function toAuthContextInfo(settings) {
5
+ const { organization, user } = settings;
6
+ return {
7
+ auth_type: user ? 'session' : 'api_key',
8
+ organization: {
9
+ id: organization.id,
10
+ name: organization.name,
11
+ slug: organization.slug,
12
+ plan: organization.planType,
13
+ },
14
+ ...(user
15
+ ? { user: { id: user.id, email: user.email, role: user.role, email_verified: user.emailVerified } }
16
+ : {}),
17
+ };
18
+ }
19
+ /**
20
+ * Call an operator-only route under /api/admin/internal (admin auth). The admin
21
+ * token comes from STATESET_ADMIN_TOKEN, falling back to the configured key.
22
+ */
23
+ export async function requestAdminInternal(apiUrl, adminToken, method, path, body) {
24
+ const response = await fetch(`${apiUrl.replace(/\/+$/, '')}/api/admin/internal${path}`, {
25
+ method,
26
+ headers: {
27
+ 'X-Admin-Token': adminToken,
28
+ ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
29
+ },
30
+ body: body === undefined ? undefined : JSON.stringify(body),
31
+ });
32
+ const text = await response.text();
33
+ let data;
34
+ try {
35
+ data = text ? JSON.parse(text) : undefined;
36
+ }
37
+ catch {
38
+ data = text;
39
+ }
40
+ if (!response.ok) {
41
+ const message = data?.error?.message;
42
+ throw new Error(message || `Admin request ${method} ${path} failed with status ${response.status}`);
43
+ }
44
+ return data;
45
+ }
46
+ /** The SDK's raw request, for routes the installed SDK has no method for. */
47
+ function rawRequest(sdk, what, method, path, body, signal) {
48
+ const request = sdk.request;
49
+ if (typeof request !== 'function') {
50
+ throw new Error(`Installed SDK does not support ${what}`);
51
+ }
52
+ return (signal ? request.call(sdk, method, path, body, { signal })
53
+ : body === undefined ? request.call(sdk, method, path) : request.call(sdk, method, path, body));
54
+ }
55
+ /** POST /sandbox/:id/pause|resume through the SDK's raw request (the body's fields are optional). */
56
+ function pauseResumeRequest(sdk, action, sandboxId, options) {
57
+ const request = sdk.request;
58
+ if (typeof request !== 'function') {
59
+ throw new Error(`Installed SDK does not support sandbox ${action}`);
60
+ }
61
+ const body = {};
62
+ if (options.wait !== undefined)
63
+ body.wait = options.wait;
64
+ if (options.timeoutSeconds !== undefined)
65
+ body.timeout_seconds = options.timeoutSeconds;
66
+ const path = action === 'pause' ? `/sandbox/${sandboxId}/pause` : `/sandbox/${sandboxId}/resume`;
67
+ return request.call(sdk, 'POST', path, body);
68
+ }
3
69
  let clientInstance = null;
4
70
  export function getClient() {
5
71
  if (clientInstance)
@@ -19,41 +85,164 @@ export function getClient() {
19
85
  catch {
20
86
  throw new Error('Configured API URL is invalid. Run `stateset config set-url <url>` with a valid URL.');
21
87
  }
88
+ clientInstance = createClientWithToken(apiKey, apiUrl);
89
+ return clientInstance;
90
+ }
91
+ /** Build a non-singleton client for short-lived credentials such as an agent
92
+ * bootstrap token. Keeping this separate prevents an exchanged credential
93
+ * from replacing the active profile's cached client. */
94
+ export function createClientWithToken(authToken, apiUrl = getConfig().apiUrl, transportOptions = {}) {
95
+ const token = authToken.trim();
96
+ const endpoint = apiUrl?.trim();
97
+ if (!token) {
98
+ throw new Error('Authentication token is required.');
99
+ }
100
+ if (!endpoint) {
101
+ throw new Error('API URL is not configured. Run `stateset config set-url <url>` first.');
102
+ }
103
+ try {
104
+ new URL(endpoint);
105
+ }
106
+ catch {
107
+ throw new Error('Configured API URL is invalid. Run `stateset config set-url <url>` with a valid URL.');
108
+ }
22
109
  const sdk = new StateSetSandboxExtended({
23
- authToken: apiKey,
24
- baseUrl: apiUrl,
110
+ authToken: token,
111
+ baseUrl: endpoint,
112
+ ...transportOptions,
25
113
  });
26
- clientInstance = {
114
+ const adminRequest = (method, path, body) => requestAdminInternal(endpoint, process.env.STATESET_ADMIN_TOKEN?.trim() || token, method, path, body);
115
+ const client = {
116
+ auth: {
117
+ introspect: async () => {
118
+ // The API has no dedicated introspection route; GET /settings returns the
119
+ // authenticated organization (and the user, for session/JWT principals).
120
+ const request = sdk.request?.bind(sdk);
121
+ return toAuthContextInfo(await request('GET', '/settings'));
122
+ },
123
+ exchangeBootstrapToken: () => {
124
+ const request = sdk.request?.bind(sdk);
125
+ return request('POST', '/agent/bootstrap/exchange');
126
+ },
127
+ },
27
128
  sandbox: {
28
- create: (options) => sdk.create(options),
129
+ taskRegistry: sdk.taskRegistry,
130
+ // Cold Kubernetes creation can wait 180s for a node/pod. Keep the
131
+ // generic read timeout short, but give creation its own bounded budget.
132
+ create: (options) => sdk.create({ ...options,
133
+ ...(options.startupTimeoutMs === undefined && transportOptions.timeout === undefined
134
+ ? { startupTimeoutMs: 210_000 } : {}),
135
+ }),
29
136
  list: () => sdk.list(),
30
137
  get: (sandboxId) => sdk.get(sandboxId),
31
- execute: (sandboxId, command) => sdk.execute(sandboxId, { command }),
138
+ execute: (sandboxId, command, timeoutMs) => sdk.execute(sandboxId, { command, ...(timeoutMs !== undefined ? { timeout: timeoutMs } : {}) }),
139
+ executeStream: (sandboxId, command, callbacks, options = {}) => sdk.executeStream(sandboxId, { command, timeout: options.timeout, working_dir: options.workingDir, signal: options.signal }, callbacks),
32
140
  stop: (sandboxId) => sdk.stop(sandboxId),
141
+ fork: (sandboxId, options = {}) => sdk.fork(sandboxId, options),
142
+ promote: (sandboxId, options) => sdk.promote(sandboxId, options),
33
143
  extend: async (sandboxId, additionalSeconds) => {
34
144
  const maybeExtend = sdk.extend;
35
145
  if (typeof maybeExtend === 'function') {
36
- return maybeExtend(sandboxId, additionalSeconds);
146
+ return maybeExtend.call(sdk, sandboxId, additionalSeconds);
37
147
  }
38
- const request = sdk.request;
148
+ const request = sdk.request?.bind(sdk);
39
149
  if (typeof request !== 'function') {
40
150
  throw new Error('Installed SDK does not support sandbox extension');
41
151
  }
42
- return request('POST', `/sandbox/${sandboxId}/extend`, {
152
+ return request.call(sdk, 'POST', `/sandbox/${sandboxId}/extend`, {
43
153
  additional_seconds: additionalSeconds,
44
154
  });
45
155
  },
156
+ pause: (sandboxId, options = {}) => pauseResumeRequest(sdk, 'pause', sandboxId, options),
157
+ resume: (sandboxId, options = {}) => pauseResumeRequest(sdk, 'resume', sandboxId, options),
46
158
  writeFile: (sandboxId, path, content) => sdk.writeFile(sandboxId, path, content),
47
- readFile: (sandboxId, path) => sdk.readFile(sandboxId, path),
159
+ writeFiles: (sandboxId, files) => sdk.writeFiles(sandboxId, files),
160
+ readFile: (...args) => sdk.readFile(...args),
161
+ readFileStream: (...args) => sdk.readFileStream(...args),
48
162
  listFiles: async (sandboxId, path = '/workspace', options) => {
49
163
  const params = new URLSearchParams({ path });
50
164
  if (options?.recursive)
51
165
  params.set('recursive', 'true');
52
- const request = sdk.request;
166
+ const request = sdk.request?.bind(sdk);
53
167
  if (typeof request !== 'function') {
54
168
  throw new Error('Installed SDK does not support listing files');
55
169
  }
56
- return request('GET', `/sandbox/${sandboxId}/files/list?${params}`);
170
+ return request.call(sdk, 'GET', `/sandbox/${sandboxId}/files/list?${params}`);
171
+ },
172
+ glob: (sandboxId, pattern) => {
173
+ const request = sdk.request?.bind(sdk);
174
+ if (typeof request !== 'function') {
175
+ throw new Error('Installed SDK does not support file glob');
176
+ }
177
+ // The API answers { files: [{ name, path, ... }] }; older ones a list of paths.
178
+ return Promise.resolve(request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/glob`, { pattern })).then((result) => (Array.isArray(result) ? result : result?.files ?? []).map((f) => (typeof f === 'string' ? f : f.path)));
179
+ },
180
+ mkdir: (sandboxId, path, recursive) => {
181
+ const request = sdk.request?.bind(sdk);
182
+ if (typeof request !== 'function') {
183
+ throw new Error('Installed SDK does not support mkdir');
184
+ }
185
+ // Explicit: the API's default for an absent `recursive` is true.
186
+ return request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/mkdir`, { path, recursive: recursive === true });
187
+ },
188
+ deleteFile: (sandboxId, path, recursive) => {
189
+ const request = sdk.request?.bind(sdk);
190
+ if (typeof request !== 'function') {
191
+ throw new Error('Installed SDK does not support file deletion');
192
+ }
193
+ return request.call(sdk, 'DELETE', `/sandbox/${sandboxId}/files`, { path, recursive });
194
+ },
195
+ moveFile: (sandboxId, source, destination) => {
196
+ const request = sdk.request?.bind(sdk);
197
+ if (typeof request !== 'function') {
198
+ throw new Error('Installed SDK does not support file move');
199
+ }
200
+ return request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/move`, { source, destination });
201
+ },
202
+ copyFile: (sandboxId, source, destination) => {
203
+ const request = sdk.request?.bind(sdk);
204
+ if (typeof request !== 'function') {
205
+ throw new Error('Installed SDK does not support file copy');
206
+ }
207
+ return request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/copy`, { source, destination });
208
+ },
209
+ terminals: () => {
210
+ const terminals = sdk.terminals;
211
+ if (!terminals || typeof terminals.stream !== 'function') {
212
+ throw new Error('Installed SDK does not support terminal sessions');
213
+ }
214
+ return terminals;
215
+ },
216
+ processes: {
217
+ result: (sandboxId, processId, tailBytes = 16384, signal) => {
218
+ if (!Number.isSafeInteger(tailBytes) || tailBytes < 1 || tailBytes > 1048576)
219
+ throw new Error('tailBytes must be 1-1048576.');
220
+ return rawRequest(sdk, 'worker results', 'GET', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}/result?tail_bytes=${tailBytes}`, undefined, signal);
221
+ },
222
+ start: (sandboxId, body) => rawRequest(sdk, 'processes', 'POST', `/sandbox/${sandboxId}/processes`, body),
223
+ list: async (sandboxId, signal) => signal ? (await sdk.processes.list(sandboxId, signal)).map(row => ({ ...row })) :
224
+ (await rawRequest(sdk, 'processes', 'GET', `/sandbox/${sandboxId}/processes`)).processes ?? [],
225
+ get: (sandboxId, processId, signal) => signal ? sdk.processes.get(sandboxId, processId, signal).then(row => ({ ...row })) :
226
+ rawRequest(sdk, 'processes', 'GET', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}`),
227
+ logs: (sandboxId, processId, options = {}) => {
228
+ const params = new URLSearchParams();
229
+ if (options.stream)
230
+ params.set('stream', options.stream);
231
+ if (options.offset !== undefined)
232
+ params.set('offset', String(options.offset));
233
+ if (options.limit !== undefined)
234
+ params.set('limit', String(options.limit));
235
+ const qs = params.toString();
236
+ return rawRequest(sdk, 'processes', 'GET', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}/logs${qs ? `?${qs}` : ''}`, undefined, options.signal);
237
+ },
238
+ kill: (sandboxId, processId, graceSeconds) => rawRequest(sdk, 'processes', 'DELETE', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}`
239
+ + (graceSeconds !== undefined ? `?grace_seconds=${graceSeconds}` : '')),
240
+ stdin: (sandboxId, processId, data) => sdk.processes.stdin(sandboxId, processId, data),
241
+ },
242
+ executions: {
243
+ list: sandboxId => sdk.executions.list(sandboxId),
244
+ get: (sandboxId, executionId, signal) => sdk.executions.get(sandboxId, executionId, signal),
245
+ cancel: (sandboxId, executionId) => sdk.executions.cancel(sandboxId, executionId),
57
246
  },
58
247
  },
59
248
  checkpoints: {
@@ -100,9 +289,492 @@ export function getClient() {
100
289
  cancel: (sessionId) => sdk.cancelAgentSession(sessionId),
101
290
  execute: (sessionId, options) => sdk.executeInAgentSession(sessionId, options),
102
291
  events: (sessionId, options = {}) => sdk.getAgentSessionEvents(sessionId, options),
292
+ heartbeat: (sessionId) => sdk.agentSessionHeartbeat(sessionId),
293
+ run: async (options) => {
294
+ const { session: created } = await sdk.createAgentSession(options);
295
+ if (options.context) {
296
+ await sdk.updateAgentContext(created.id, options.context);
297
+ }
298
+ const { session: started } = await sdk.startAgentSession(created.id);
299
+ const command = options.command;
300
+ const execution = command?.length
301
+ ? await sdk.executeInAgentSession(started.id, {
302
+ ...options.exec,
303
+ command,
304
+ })
305
+ : undefined;
306
+ const stopped = options.stop_on_exit === true;
307
+ if (stopped) {
308
+ await sdk.stopAgentSession(started.id, 'command completed');
309
+ }
310
+ return {
311
+ session: stopped ? { ...started, status: 'completed' } : started,
312
+ execution,
313
+ stopped,
314
+ };
315
+ },
316
+ connect: async (options) => {
317
+ const clientId = String(options.clientId || '');
318
+ const attached = clientId ? await sdk.reattachAgentSession(clientId) : { session: null };
319
+ if (attached.session) {
320
+ if (options.context) {
321
+ await sdk.updateAgentContext(attached.session.id, options.context);
322
+ }
323
+ const session = options.resumePaused === true && attached.session.status === 'paused'
324
+ ? (await sdk.resumeAgentSession(attached.session.id)).session
325
+ : attached.session;
326
+ return { session, reattached: true, created: false, source: 'reattached', stopped: false };
327
+ }
328
+ const { session: created } = await sdk.createAgentSession(options);
329
+ if (options.context) {
330
+ await sdk.updateAgentContext(created.id, options.context);
331
+ }
332
+ const { session } = await sdk.startAgentSession(created.id);
333
+ return { session, reattached: false, created: true, source: 'created', stopped: false };
334
+ },
335
+ },
336
+ webhooks: {
337
+ list: () => {
338
+ const request = sdk.request?.bind(sdk);
339
+ if (typeof request !== 'function') {
340
+ throw new Error('Installed SDK does not support webhook endpoints');
341
+ }
342
+ return request('GET', '/webhooks');
343
+ },
344
+ create: (url, events, secret) => {
345
+ const request = sdk.request?.bind(sdk);
346
+ if (typeof request !== 'function') {
347
+ throw new Error('Installed SDK does not support webhook endpoints');
348
+ }
349
+ const body = { url, events };
350
+ if (secret)
351
+ body.secret = secret;
352
+ return request('POST', '/webhooks', body);
353
+ },
354
+ delete: (webhookId) => {
355
+ const request = sdk.request?.bind(sdk);
356
+ if (typeof request !== 'function') {
357
+ throw new Error('Installed SDK does not support webhook endpoints');
358
+ }
359
+ return request('DELETE', `/webhooks/${webhookId}`);
360
+ },
361
+ test: (webhookId) => {
362
+ const request = sdk.request?.bind(sdk);
363
+ if (typeof request !== 'function') {
364
+ throw new Error('Installed SDK does not support webhook endpoints');
365
+ }
366
+ return request('POST', `/webhooks/${webhookId}/test`);
367
+ },
368
+ deliveries: (webhookId, limit) => {
369
+ const request = sdk.request?.bind(sdk);
370
+ if (typeof request !== 'function') {
371
+ throw new Error('Installed SDK does not support webhook endpoints');
372
+ }
373
+ const params = limit ? `?limit=${limit}` : '';
374
+ return request('GET', `/webhooks/${webhookId}/deliveries${params}`);
375
+ },
376
+ },
377
+ audit: {
378
+ list: (options = {}) => {
379
+ if (typeof sdk.queryAudit !== 'function') {
380
+ throw new Error('Installed SDK does not support audit endpoints');
381
+ }
382
+ return sdk.queryAudit(options);
383
+ },
384
+ summary: (sandboxId) => {
385
+ if (typeof sdk.getAuditSummary !== 'function') {
386
+ throw new Error('Installed SDK does not support audit endpoints');
387
+ }
388
+ return sdk.getAuditSummary(sandboxId);
389
+ },
390
+ },
391
+ governance: (() => {
392
+ const raw = sdk.request?.bind(sdk);
393
+ const call = (method, path, body) => {
394
+ if (typeof raw !== 'function') {
395
+ throw new Error('Installed SDK does not support governance endpoints');
396
+ }
397
+ return body === undefined ? raw.call(sdk, method, path) : raw.call(sdk, method, path, body);
398
+ };
399
+ const qs = (params) => {
400
+ const search = new URLSearchParams();
401
+ for (const [key, value] of Object.entries(params)) {
402
+ if (value !== undefined && value !== '')
403
+ search.set(key, String(value));
404
+ }
405
+ const encoded = search.toString();
406
+ return encoded ? `?${encoded}` : '';
407
+ };
408
+ return {
409
+ timeline: (sandboxId, query = {}) => call('GET', `/sandbox/${encodeURIComponent(sandboxId)}/timeline${qs(query)}`),
410
+ sandboxCost: (sandboxId) => call('GET', `/sandbox/${encodeURIComponent(sandboxId)}/cost`),
411
+ orgCosts: (query = {}) => call('GET', `/org/costs${qs(query)}`),
412
+ getPolicy: () => call('GET', '/org/policy'),
413
+ updatePolicy: (update) => call('PUT', '/org/policy', update),
414
+ sandboxEgress: (sandboxId) => call('GET', `/sandbox/${encodeURIComponent(sandboxId)}/egress`),
415
+ updateSandboxEgress: (sandboxId, update) => call('PATCH', `/sandbox/${encodeURIComponent(sandboxId)}/egress`, update),
416
+ };
417
+ })(),
418
+ images: {
419
+ register: (options) => {
420
+ const request = sdk.request?.bind(sdk);
421
+ if (typeof request !== 'function') {
422
+ throw new Error('Installed SDK does not support image endpoints');
423
+ }
424
+ const body = { name: options.name, image: options.image };
425
+ if (options.pull_secret)
426
+ body.pull_secret = options.pull_secret;
427
+ if (options.run_image_command !== undefined)
428
+ body.run_image_command = options.run_image_command;
429
+ return request('POST', '/images', body);
430
+ },
431
+ list: () => {
432
+ const request = sdk.request?.bind(sdk);
433
+ if (typeof request !== 'function') {
434
+ throw new Error('Installed SDK does not support image endpoints');
435
+ }
436
+ return request('GET', '/images');
437
+ },
438
+ get: (name) => {
439
+ const request = sdk.request?.bind(sdk);
440
+ if (typeof request !== 'function') {
441
+ throw new Error('Installed SDK does not support image endpoints');
442
+ }
443
+ return request('GET', `/images/${encodeURIComponent(name)}`);
444
+ },
445
+ delete: (name) => {
446
+ const request = sdk.request?.bind(sdk);
447
+ if (typeof request !== 'function') {
448
+ throw new Error('Installed SDK does not support image endpoints');
449
+ }
450
+ return request('DELETE', `/images/${encodeURIComponent(name)}`);
451
+ },
452
+ },
453
+ secrets: {
454
+ list: () => {
455
+ const request = sdk.request?.bind(sdk);
456
+ if (typeof request !== 'function') {
457
+ throw new Error('Installed SDK does not support secret endpoints');
458
+ }
459
+ return request('GET', '/secrets');
460
+ },
461
+ create: (name, value, options = {}) => {
462
+ const request = sdk.request?.bind(sdk);
463
+ if (typeof request !== 'function') {
464
+ throw new Error('Installed SDK does not support secret endpoints');
465
+ }
466
+ const body = { name, value };
467
+ if (options.scope)
468
+ body.scope = options.scope;
469
+ if (options.expires_at)
470
+ body.expires_at = options.expires_at;
471
+ return request('POST', '/secrets', body);
472
+ },
473
+ delete: (name) => {
474
+ const request = sdk.request?.bind(sdk);
475
+ if (typeof request !== 'function') {
476
+ throw new Error('Installed SDK does not support secret endpoints');
477
+ }
478
+ return request('DELETE', `/secrets/${encodeURIComponent(name)}`);
479
+ },
480
+ inject: (sandboxId, secrets) => {
481
+ const request = sdk.request?.bind(sdk);
482
+ if (typeof request !== 'function') {
483
+ throw new Error('Installed SDK does not support secret endpoints');
484
+ }
485
+ return request('POST', `/sandbox/${sandboxId}/secrets/inject`, { secrets });
486
+ },
487
+ },
488
+ templates: {
489
+ list: (options = {}) => {
490
+ const request = sdk.request?.bind(sdk);
491
+ if (typeof request !== 'function') {
492
+ throw new Error('Installed SDK does not support template endpoints');
493
+ }
494
+ const params = new URLSearchParams();
495
+ if (options.category)
496
+ params.set('category', options.category);
497
+ if (options.search)
498
+ params.set('search', options.search);
499
+ const qs = params.toString();
500
+ return request('GET', `/templates${qs ? `?${qs}` : ''}`);
501
+ },
502
+ get: (templateId) => {
503
+ const request = sdk.request?.bind(sdk);
504
+ if (typeof request !== 'function') {
505
+ throw new Error('Installed SDK does not support template endpoints');
506
+ }
507
+ return request('GET', `/templates/${templateId}`);
508
+ },
509
+ },
510
+ apiKeys: {
511
+ list: () => {
512
+ const request = sdk.request?.bind(sdk);
513
+ if (typeof request !== 'function') {
514
+ throw new Error('Installed SDK does not support API key endpoints');
515
+ }
516
+ return request('GET', '/api-keys');
517
+ },
518
+ create: (name, options = {}) => {
519
+ const request = sdk.request?.bind(sdk);
520
+ if (typeof request !== 'function') {
521
+ throw new Error('Installed SDK does not support API key endpoints');
522
+ }
523
+ const body = { name };
524
+ if (options.scopes)
525
+ body.scopes = options.scopes;
526
+ if (options.expires_in_days)
527
+ body.expires_in_days = options.expires_in_days;
528
+ return request('POST', '/api-keys', body);
529
+ },
530
+ revoke: (keyId) => {
531
+ const request = sdk.request?.bind(sdk);
532
+ if (typeof request !== 'function') {
533
+ throw new Error('Installed SDK does not support API key endpoints');
534
+ }
535
+ return request('DELETE', `/api-keys/${keyId}`);
536
+ },
537
+ },
538
+ billing: {
539
+ subscription: () => {
540
+ const request = sdk.request?.bind(sdk);
541
+ if (typeof request !== 'function') {
542
+ throw new Error('Installed SDK does not support billing endpoints');
543
+ }
544
+ return request('GET', '/billing/subscription');
545
+ },
546
+ usage: () => {
547
+ const request = sdk.request?.bind(sdk);
548
+ if (typeof request !== 'function') {
549
+ throw new Error('Installed SDK does not support billing endpoints');
550
+ }
551
+ return request('GET', '/usage/current');
552
+ },
553
+ invoices: (limit) => {
554
+ const request = sdk.request?.bind(sdk);
555
+ if (typeof request !== 'function') {
556
+ throw new Error('Installed SDK does not support billing endpoints');
557
+ }
558
+ const qs = limit ? `?limit=${limit}` : '';
559
+ return request('GET', `/billing/invoices${qs}`);
560
+ },
561
+ portal: (returnUrl) => {
562
+ const request = sdk.request?.bind(sdk);
563
+ if (typeof request !== 'function') {
564
+ throw new Error('Installed SDK does not support billing endpoints');
565
+ }
566
+ return request('POST', '/billing/portal', { return_url: returnUrl });
567
+ },
568
+ },
569
+ // Snapshot management is operator-only: the controller serves it at
570
+ // /api/admin/internal/snapshots behind admin auth, not under /api/v1.
571
+ snapshots: {
572
+ list: () => adminRequest('GET', '/snapshots'),
573
+ status: () => adminRequest('GET', '/snapshots/status'),
574
+ create: (payload) => adminRequest('POST', '/snapshots', payload),
575
+ get: (profileKey) => adminRequest('GET', `/snapshots/${encodeURIComponent(profileKey)}`),
576
+ delete: (profileKey) => adminRequest('DELETE', `/snapshots/${encodeURIComponent(profileKey)}`),
577
+ restore: (profileKey) => adminRequest('POST', `/snapshots/${encodeURIComponent(profileKey)}/restore`),
578
+ warm: (payload) => adminRequest('POST', '/snapshots/warm', payload),
579
+ cleanup: (payload) => adminRequest('POST', '/snapshots/cleanup', payload),
580
+ },
581
+ computerUse: {
582
+ screenshot: (sandboxId, options = {}) => {
583
+ const request = sdk.request?.bind(sdk);
584
+ if (typeof request !== 'function') {
585
+ throw new Error('Installed SDK does not support computer use endpoints');
586
+ }
587
+ const params = new URLSearchParams();
588
+ if (options.format)
589
+ params.set('format', options.format);
590
+ if (options.quality !== undefined)
591
+ params.set('quality', options.quality.toString());
592
+ const qs = params.toString();
593
+ return request('GET', `/sandbox/${sandboxId}/screenshot${qs ? `?${qs}` : ''}`);
594
+ },
595
+ mouse: (sandboxId, action, x, y, button) => {
596
+ const request = sdk.request?.bind(sdk);
597
+ if (typeof request !== 'function') {
598
+ throw new Error('Installed SDK does not support computer use endpoints');
599
+ }
600
+ const body = { action, x, y };
601
+ if (button)
602
+ body.button = button;
603
+ return request('POST', `/sandbox/${sandboxId}/mouse`, body);
604
+ },
605
+ keyboard: (sandboxId, action, textOrKey, modifiers) => {
606
+ const request = sdk.request?.bind(sdk);
607
+ if (typeof request !== 'function') {
608
+ throw new Error('Installed SDK does not support computer use endpoints');
609
+ }
610
+ const body = { action };
611
+ if (action === 'type') {
612
+ body.text = textOrKey;
613
+ }
614
+ else {
615
+ body.key = textOrKey;
616
+ }
617
+ if (modifiers && modifiers.length > 0)
618
+ body.modifiers = modifiers;
619
+ return request('POST', `/sandbox/${sandboxId}/keyboard`, body);
620
+ },
621
+ getScreenSize: (sandboxId) => {
622
+ const request = sdk.request?.bind(sdk);
623
+ if (typeof request !== 'function') {
624
+ throw new Error('Installed SDK does not support computer use endpoints');
625
+ }
626
+ return request('GET', `/sandbox/${sandboxId}/screen`);
627
+ },
628
+ },
629
+ repl: {
630
+ create: (sandboxId, language) => {
631
+ if (typeof sdk.createReplSession !== 'function') {
632
+ throw new Error('Installed SDK does not support REPL endpoints');
633
+ }
634
+ return sdk.createReplSession(sandboxId, language ?? 'python');
635
+ },
636
+ list: (sandboxId) => {
637
+ const request = sdk.request?.bind(sdk);
638
+ if (typeof request !== 'function') {
639
+ throw new Error('Installed SDK does not support REPL endpoints');
640
+ }
641
+ return request('GET', `/sandbox/${sandboxId}/repl/sessions`);
642
+ },
643
+ get: (sandboxId, sessionId) => {
644
+ const request = sdk.request?.bind(sdk);
645
+ if (typeof request !== 'function') {
646
+ throw new Error('Installed SDK does not support REPL endpoints');
647
+ }
648
+ return request('GET', `/sandbox/${sandboxId}/repl/sessions/${sessionId}`);
649
+ },
650
+ execute: (sandboxId, sessionId, code, timeoutMs) => {
651
+ if (typeof sdk.executeReplCode !== 'function') {
652
+ throw new Error('Installed SDK does not support REPL endpoints');
653
+ }
654
+ // Preserve the SDK's cell timeout grace and unsent-only retry policy.
655
+ return sdk.executeReplCode(sandboxId, sessionId, code, timeoutMs);
656
+ },
657
+ interrupt: (sandboxId, sessionId) => {
658
+ const request = sdk.request?.bind(sdk);
659
+ if (typeof request !== 'function') {
660
+ throw new Error('Installed SDK does not support REPL endpoints');
661
+ }
662
+ return request('POST', `/sandbox/${sandboxId}/repl/sessions/${sessionId}/interrupt`);
663
+ },
664
+ delete: (sandboxId, sessionId) => {
665
+ const request = sdk.request?.bind(sdk);
666
+ if (typeof request !== 'function') {
667
+ throw new Error('Installed SDK does not support REPL endpoints');
668
+ }
669
+ return request('DELETE', `/sandbox/${sandboxId}/repl/sessions/${sessionId}`);
670
+ },
671
+ },
672
+ mcp: {
673
+ start: (sandboxId, name, command, args, env, port) => {
674
+ const request = sdk.request?.bind(sdk);
675
+ if (typeof request !== 'function') {
676
+ throw new Error('Installed SDK does not support MCP endpoints');
677
+ }
678
+ const body = { name, command };
679
+ if (args && args.length > 0)
680
+ body.args = args;
681
+ if (env && Object.keys(env).length > 0)
682
+ body.env = env;
683
+ if (port !== undefined)
684
+ body.port = port;
685
+ return request('POST', `/sandbox/${sandboxId}/mcp/start`, body);
686
+ },
687
+ stop: (sandboxId, name) => {
688
+ const request = sdk.request?.bind(sdk);
689
+ if (typeof request !== 'function') {
690
+ throw new Error('Installed SDK does not support MCP endpoints');
691
+ }
692
+ return request('POST', `/sandbox/${sandboxId}/mcp/stop`, { name });
693
+ },
694
+ list: (sandboxId) => {
695
+ const request = sdk.request?.bind(sdk);
696
+ if (typeof request !== 'function') {
697
+ throw new Error('Installed SDK does not support MCP endpoints');
698
+ }
699
+ return request('GET', `/sandbox/${sandboxId}/mcp`);
700
+ },
701
+ presets: () => {
702
+ const request = sdk.request?.bind(sdk);
703
+ if (typeof request !== 'function') {
704
+ throw new Error('Installed SDK does not support MCP endpoints');
705
+ }
706
+ return request('GET', '/mcp/presets');
707
+ },
708
+ },
709
+ egress: {
710
+ get: () => {
711
+ const request = sdk.request?.bind(sdk);
712
+ if (typeof request !== 'function') {
713
+ throw new Error('Installed SDK does not support egress endpoints');
714
+ }
715
+ return Promise.resolve(request('GET', '/settings/egress')).then(normalizeEgressPolicy);
716
+ },
717
+ set: (mode, options = {}) => {
718
+ const request = sdk.request?.bind(sdk);
719
+ if (typeof request !== 'function') {
720
+ throw new Error('Installed SDK does not support egress endpoints');
721
+ }
722
+ const body = buildEgressPolicyBody(mode, options);
723
+ return Promise.resolve(request('PUT', '/settings/egress', body)).then(normalizeEgressPolicy);
724
+ },
725
+ audit: (options = {}) => {
726
+ const request = sdk.request?.bind(sdk);
727
+ if (typeof request !== 'function') {
728
+ throw new Error('Installed SDK does not support egress endpoints');
729
+ }
730
+ const params = new URLSearchParams();
731
+ if (options.sandbox_id)
732
+ params.set('sandbox_id', options.sandbox_id);
733
+ if (options.host)
734
+ params.set('host', options.host);
735
+ if (options.decision)
736
+ params.set('decision', options.decision);
737
+ if (options.limit)
738
+ params.set('limit', options.limit.toString());
739
+ const qs = params.toString();
740
+ return request('GET', `/egress/audit${qs ? `?${qs}` : ''}`);
741
+ },
742
+ },
743
+ benchmark: {
744
+ run: (_runs) => {
745
+ const request = sdk.request?.bind(sdk);
746
+ if (typeof request !== 'function') {
747
+ throw new Error('Installed SDK does not support benchmark endpoints');
748
+ }
749
+ // GET /benchmark is read-only: it returns the latest published result
750
+ // and ignores runs, so none is sent.
751
+ return request('GET', '/benchmark');
752
+ },
753
+ history: (options = {}) => {
754
+ const request = sdk.request?.bind(sdk);
755
+ if (typeof request !== 'function') {
756
+ throw new Error('Installed SDK does not support benchmark endpoints');
757
+ }
758
+ const params = new URLSearchParams();
759
+ if (options.limit)
760
+ params.set('limit', options.limit.toString());
761
+ if (options.days)
762
+ params.set('days', options.days.toString());
763
+ if (options.region)
764
+ params.set('region', options.region);
765
+ const qs = params.toString();
766
+ return request('GET', `/benchmark/history${qs ? `?${qs}` : ''}`);
767
+ },
768
+ summary: () => {
769
+ const request = sdk.request?.bind(sdk);
770
+ if (typeof request !== 'function') {
771
+ throw new Error('Installed SDK does not support benchmark endpoints');
772
+ }
773
+ return request('GET', '/benchmark/summary');
774
+ },
103
775
  },
104
776
  };
105
- return clientInstance;
777
+ return client;
106
778
  }
107
779
  export function resetClient() {
108
780
  clientInstance = null;