@stateset/sandbox-cli 1.0.6 → 3.4.0

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