withruntime 0.49.0 → 1.0.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 (491) hide show
  1. package/dist/generated/apps.d.ts +309 -0
  2. package/dist/generated/apps.js +333 -0
  3. package/dist/generated/audit.d.ts +47 -0
  4. package/dist/generated/audit.js +14 -0
  5. package/dist/generated/browsers.d.ts +309 -0
  6. package/dist/generated/browsers.js +333 -0
  7. package/dist/generated/builds.d.ts +309 -0
  8. package/dist/generated/builds.js +333 -0
  9. package/dist/generated/ci.d.ts +309 -0
  10. package/dist/generated/ci.js +333 -0
  11. package/dist/generated/containers.d.ts +309 -0
  12. package/dist/generated/containers.js +333 -0
  13. package/dist/generated/desktops.d.ts +309 -0
  14. package/dist/generated/desktops.js +333 -0
  15. package/dist/generated/domains.d.ts +80 -0
  16. package/dist/generated/domains.js +58 -0
  17. package/dist/generated/egressIps.d.ts +36 -0
  18. package/dist/generated/egressIps.js +14 -0
  19. package/dist/generated/events.d.ts +37 -0
  20. package/dist/generated/events.js +14 -0
  21. package/dist/generated/feedback.d.ts +44 -0
  22. package/dist/generated/feedback.js +13 -0
  23. package/dist/generated/functions.d.ts +309 -0
  24. package/dist/generated/functions.js +333 -0
  25. package/dist/generated/identities.d.ts +36 -0
  26. package/dist/generated/identities.js +22 -0
  27. package/dist/generated/images.d.ts +200 -0
  28. package/dist/generated/images.js +65 -0
  29. package/dist/generated/index.d.ts +143 -0
  30. package/dist/generated/index.js +184 -0
  31. package/dist/generated/jobRuns.d.ts +68 -0
  32. package/dist/generated/jobRuns.js +22 -0
  33. package/dist/generated/jobs.d.ts +144 -0
  34. package/dist/generated/jobs.js +85 -0
  35. package/dist/generated/keys.d.ts +105 -0
  36. package/dist/generated/keys.js +26 -0
  37. package/dist/generated/me.d.ts +33 -0
  38. package/dist/generated/me.js +13 -0
  39. package/dist/generated/networks.d.ts +32 -0
  40. package/dist/generated/networks.js +14 -0
  41. package/dist/generated/notebooks.d.ts +309 -0
  42. package/dist/generated/notebooks.js +333 -0
  43. package/dist/generated/otel.d.ts +46 -0
  44. package/dist/generated/otel.js +22 -0
  45. package/dist/generated/ports.d.ts +55 -0
  46. package/dist/generated/ports.js +22 -0
  47. package/dist/generated/previews.d.ts +86 -0
  48. package/dist/generated/previews.js +67 -0
  49. package/dist/generated/projects.d.ts +47 -0
  50. package/dist/generated/projects.js +26 -0
  51. package/dist/generated/roles.d.ts +36 -0
  52. package/dist/generated/roles.js +22 -0
  53. package/dist/generated/routes.d.ts +3 -0
  54. package/dist/generated/routes.js +4 -0
  55. package/dist/generated/runtime.d.ts +176 -0
  56. package/dist/generated/runtime.js +416 -0
  57. package/dist/generated/sandboxes.d.ts +952 -0
  58. package/dist/generated/sandboxes.js +342 -0
  59. package/dist/generated/secrets.d.ts +116 -0
  60. package/dist/generated/secrets.js +54 -0
  61. package/dist/generated/sessions.d.ts +47 -0
  62. package/dist/generated/sessions.js +17 -0
  63. package/dist/generated/signing.d.ts +68 -0
  64. package/dist/generated/signing.js +187 -0
  65. package/dist/generated/sites.d.ts +309 -0
  66. package/dist/generated/sites.js +333 -0
  67. package/dist/generated/snapshots.d.ts +27 -0
  68. package/dist/generated/snapshots.js +22 -0
  69. package/dist/generated/tunnels.d.ts +68 -0
  70. package/dist/generated/tunnels.js +14 -0
  71. package/dist/generated/usage.d.ts +155 -0
  72. package/dist/generated/usage.js +17 -0
  73. package/dist/generated/volumes.d.ts +36 -0
  74. package/dist/generated/volumes.js +26 -0
  75. package/dist/generated/webhooks.d.ts +44 -0
  76. package/dist/generated/webhooks.js +22 -0
  77. package/dist/generated/workspaces.d.ts +309 -0
  78. package/dist/generated/workspaces.js +333 -0
  79. package/dist/v2/cli.d.ts +7 -0
  80. package/dist/v2/cli.js +283 -0
  81. package/dist/v2/index.d.ts +1 -0
  82. package/dist/v2/index.js +4 -0
  83. package/dist/v2/login.d.ts +35 -0
  84. package/dist/v2/login.js +225 -0
  85. package/dist/v2/mcp.d.ts +1 -0
  86. package/dist/v2/mcp.js +49 -0
  87. package/dist/v2/openapi.json +75750 -0
  88. package/dist/v2/shims/base.d.ts +33 -0
  89. package/dist/v2/shims/base.js +54 -0
  90. package/dist/v2/shims/blaxel.d.ts +60 -0
  91. package/dist/v2/shims/blaxel.js +71 -0
  92. package/dist/v2/shims/cloudflare.d.ts +52 -0
  93. package/dist/v2/shims/cloudflare.js +55 -0
  94. package/dist/v2/shims/daytona.d.ts +58 -0
  95. package/dist/v2/shims/daytona.js +74 -0
  96. package/dist/v2/shims/e2b.d.ts +142 -0
  97. package/dist/v2/shims/e2b.js +238 -0
  98. package/dist/v2/shims/fly.d.ts +6 -0
  99. package/dist/v2/shims/fly.js +91 -0
  100. package/dist/v2/shims/modal.d.ts +54 -0
  101. package/dist/v2/shims/modal.js +79 -0
  102. package/dist/v2/shims/morph.d.ts +60 -0
  103. package/dist/v2/shims/morph.js +87 -0
  104. package/dist/v2/shims/vercel.d.ts +53 -0
  105. package/dist/v2/shims/vercel.js +90 -0
  106. package/dist/v2/table.d.ts +53 -0
  107. package/dist/v2/table.js +122 -0
  108. package/package.json +20 -310
  109. package/BLAXEL.md +0 -290
  110. package/COMPATIBILITY.md +0 -447
  111. package/DAYTONA.md +0 -237
  112. package/E2B.md +0 -314
  113. package/README.md +0 -331
  114. package/README.src.md +0 -333
  115. package/VERCEL.md +0 -230
  116. package/agent-platforms-inventory.json +0 -387
  117. package/compatibility-lock.json +0 -305
  118. package/dist/agents/browser.d.ts +0 -12
  119. package/dist/agents/browser.js +0 -12
  120. package/dist/agents/index.d.ts +0 -11
  121. package/dist/agents/index.js +0 -11
  122. package/dist/agents-cli.d.ts +0 -16
  123. package/dist/agents-cli.js +0 -1237
  124. package/dist/agents-deploy.d.ts +0 -196
  125. package/dist/agents-deploy.js +0 -872
  126. package/dist/agents-file.d.ts +0 -19
  127. package/dist/agents-file.js +0 -135
  128. package/dist/ai/index.d.ts +0 -49
  129. package/dist/ai/index.js +0 -31
  130. package/dist/ai-harness/index.d.ts +0 -194
  131. package/dist/ai-harness/index.js +0 -522
  132. package/dist/api-defaults.d.ts +0 -17
  133. package/dist/api-defaults.js +0 -22
  134. package/dist/apps/index.d.ts +0 -10
  135. package/dist/apps/index.js +0 -11
  136. package/dist/apps-cli.d.ts +0 -16
  137. package/dist/apps-cli.js +0 -1021
  138. package/dist/billing-cli.d.ts +0 -23
  139. package/dist/billing-cli.js +0 -264
  140. package/dist/blaxel/client.d.ts +0 -59
  141. package/dist/blaxel/client.js +0 -86
  142. package/dist/blaxel/context.d.ts +0 -59
  143. package/dist/blaxel/context.js +0 -162
  144. package/dist/blaxel/errors.d.ts +0 -130
  145. package/dist/blaxel/errors.js +0 -315
  146. package/dist/blaxel/filesystem.d.ts +0 -147
  147. package/dist/blaxel/filesystem.js +0 -585
  148. package/dist/blaxel/index.d.ts +0 -287
  149. package/dist/blaxel/index.js +0 -351
  150. package/dist/blaxel/interpreter.d.ts +0 -71
  151. package/dist/blaxel/interpreter.js +0 -256
  152. package/dist/blaxel/lookup.d.ts +0 -39
  153. package/dist/blaxel/lookup.js +0 -84
  154. package/dist/blaxel/pagination.d.ts +0 -39
  155. package/dist/blaxel/pagination.js +0 -88
  156. package/dist/blaxel/preview.d.ts +0 -136
  157. package/dist/blaxel/preview.js +0 -304
  158. package/dist/blaxel/process.d.ts +0 -126
  159. package/dist/blaxel/process.js +0 -581
  160. package/dist/blaxel/sandbox.d.ts +0 -198
  161. package/dist/blaxel/sandbox.js +0 -856
  162. package/dist/blaxel/session.d.ts +0 -31
  163. package/dist/blaxel/session.js +0 -136
  164. package/dist/blaxel/snapshot.d.ts +0 -123
  165. package/dist/blaxel/snapshot.js +0 -199
  166. package/dist/blaxel/types.d.ts +0 -145
  167. package/dist/blaxel/types.js +0 -60
  168. package/dist/blaxel/unsupported.d.ts +0 -20
  169. package/dist/blaxel/unsupported.js +0 -32
  170. package/dist/browser-stub.d.ts +0 -1
  171. package/dist/browser-stub.js +0 -1
  172. package/dist/browsers/index.d.ts +0 -9
  173. package/dist/browsers/index.js +0 -10
  174. package/dist/browsers-cli.d.ts +0 -13
  175. package/dist/browsers-cli.js +0 -279
  176. package/dist/builds/index.d.ts +0 -10
  177. package/dist/builds/index.js +0 -11
  178. package/dist/ci/index.d.ts +0 -13
  179. package/dist/ci/index.js +0 -14
  180. package/dist/ci-cli.d.ts +0 -20
  181. package/dist/ci-cli.js +0 -537
  182. package/dist/ci-import.d.ts +0 -23
  183. package/dist/ci-import.js +0 -565
  184. package/dist/claude-agent-sdk/index.d.ts +0 -7
  185. package/dist/claude-agent-sdk/index.js +0 -65
  186. package/dist/cli/logs.d.ts +0 -21
  187. package/dist/cli/logs.js +0 -188
  188. package/dist/cli-extras.d.ts +0 -39
  189. package/dist/cli-extras.js +0 -267
  190. package/dist/cli-name.d.ts +0 -6
  191. package/dist/cli-name.js +0 -8
  192. package/dist/cli-update.d.ts +0 -11
  193. package/dist/cli-update.js +0 -46
  194. package/dist/cli-words.d.ts +0 -36
  195. package/dist/cli-words.js +0 -167
  196. package/dist/cli.d.ts +0 -92
  197. package/dist/cli.js +0 -5463
  198. package/dist/client.d.ts +0 -189
  199. package/dist/client.js +0 -205
  200. package/dist/cloudflare/errors.d.ts +0 -166
  201. package/dist/cloudflare/errors.js +0 -183
  202. package/dist/cloudflare/identity.d.ts +0 -7
  203. package/dist/cloudflare/identity.js +0 -13
  204. package/dist/cloudflare/index.d.ts +0 -545
  205. package/dist/cloudflare/index.js +0 -1106
  206. package/dist/cloudflare/interpreter.d.ts +0 -119
  207. package/dist/cloudflare/interpreter.js +0 -232
  208. package/dist/cloudflare/mime.d.ts +0 -1
  209. package/dist/cloudflare/mime.js +0 -66
  210. package/dist/cloudflare/streams.d.ts +0 -46
  211. package/dist/cloudflare/streams.js +0 -175
  212. package/dist/cloudflare/types.d.ts +0 -338
  213. package/dist/cloudflare/types.js +0 -80
  214. package/dist/cloudflare/watch.d.ts +0 -9
  215. package/dist/cloudflare/watch.js +0 -24
  216. package/dist/cloudflare/worker.d.ts +0 -706
  217. package/dist/cloudflare/worker.js +0 -633
  218. package/dist/codesandbox/guest-service.d.ts +0 -31
  219. package/dist/codesandbox/guest-service.js +0 -490
  220. package/dist/codesandbox/index.d.ts +0 -574
  221. package/dist/codesandbox/index.js +0 -1747
  222. package/dist/compat/core.d.ts +0 -58
  223. package/dist/compat/core.js +0 -267
  224. package/dist/compat/files.d.ts +0 -27
  225. package/dist/compat/files.js +0 -157
  226. package/dist/compat/lease.d.ts +0 -37
  227. package/dist/compat/lease.js +0 -93
  228. package/dist/compat/shell.d.ts +0 -4
  229. package/dist/compat/shell.js +0 -165
  230. package/dist/containers/index.d.ts +0 -10
  231. package/dist/containers/index.js +0 -11
  232. package/dist/credentials.d.ts +0 -71
  233. package/dist/credentials.js +0 -340
  234. package/dist/daytona/client.d.ts +0 -48
  235. package/dist/daytona/client.js +0 -45
  236. package/dist/daytona/computer-use.d.ts +0 -171
  237. package/dist/daytona/computer-use.js +0 -382
  238. package/dist/daytona/context.d.ts +0 -41
  239. package/dist/daytona/context.js +0 -50
  240. package/dist/daytona/daytona.d.ts +0 -213
  241. package/dist/daytona/daytona.js +0 -578
  242. package/dist/daytona/errors.d.ts +0 -117
  243. package/dist/daytona/errors.js +0 -201
  244. package/dist/daytona/filesystem.d.ts +0 -99
  245. package/dist/daytona/filesystem.js +0 -300
  246. package/dist/daytona/git.d.ts +0 -33
  247. package/dist/daytona/git.js +0 -128
  248. package/dist/daytona/image.d.ts +0 -49
  249. package/dist/daytona/image.js +0 -146
  250. package/dist/daytona/index.d.ts +0 -87
  251. package/dist/daytona/index.js +0 -102
  252. package/dist/daytona/process.d.ts +0 -143
  253. package/dist/daytona/process.js +0 -565
  254. package/dist/daytona/sandbox.d.ts +0 -222
  255. package/dist/daytona/sandbox.js +0 -505
  256. package/dist/desktops/index.d.ts +0 -9
  257. package/dist/desktops/index.js +0 -10
  258. package/dist/domains/index.d.ts +0 -9
  259. package/dist/domains/index.js +0 -10
  260. package/dist/e2b/client.d.ts +0 -76
  261. package/dist/e2b/client.js +0 -124
  262. package/dist/e2b/code-interpreter.d.ts +0 -134
  263. package/dist/e2b/code-interpreter.js +0 -239
  264. package/dist/e2b/commands.d.ts +0 -135
  265. package/dist/e2b/commands.js +0 -452
  266. package/dist/e2b/errors.d.ts +0 -125
  267. package/dist/e2b/errors.js +0 -247
  268. package/dist/e2b/filesystem.d.ts +0 -111
  269. package/dist/e2b/filesystem.js +0 -374
  270. package/dist/e2b/index.d.ts +0 -35
  271. package/dist/e2b/index.js +0 -69
  272. package/dist/e2b/pty.d.ts +0 -24
  273. package/dist/e2b/pty.js +0 -83
  274. package/dist/e2b/sandbox.d.ts +0 -248
  275. package/dist/e2b/sandbox.js +0 -781
  276. package/dist/e2b/unsupported.d.ts +0 -38
  277. package/dist/e2b/unsupported.js +0 -48
  278. package/dist/e2b/users.d.ts +0 -39
  279. package/dist/e2b/users.js +0 -207
  280. package/dist/errors.d.ts +0 -100
  281. package/dist/errors.js +0 -198
  282. package/dist/file-source.d.ts +0 -16
  283. package/dist/file-source.js +0 -162
  284. package/dist/fly/index.d.ts +0 -102
  285. package/dist/fly/index.js +0 -930
  286. package/dist/freestyle/index.d.ts +0 -629
  287. package/dist/freestyle/index.js +0 -1187
  288. package/dist/functions/index.d.ts +0 -10
  289. package/dist/functions/index.js +0 -11
  290. package/dist/identity.d.ts +0 -30
  291. package/dist/identity.js +0 -141
  292. package/dist/image-context.d.ts +0 -39
  293. package/dist/image-context.js +0 -176
  294. package/dist/images/index.d.ts +0 -9
  295. package/dist/images/index.js +0 -10
  296. package/dist/index.d.ts +0 -87
  297. package/dist/index.js +0 -51
  298. package/dist/inngest/index.d.ts +0 -96
  299. package/dist/inngest/index.js +0 -183
  300. package/dist/ips/index.d.ts +0 -9
  301. package/dist/ips/index.js +0 -10
  302. package/dist/jobs/index.d.ts +0 -9
  303. package/dist/jobs/index.js +0 -10
  304. package/dist/jobs-code/cron.d.ts +0 -12
  305. package/dist/jobs-code/cron.js +0 -93
  306. package/dist/jobs-code/registry.d.ts +0 -31
  307. package/dist/jobs-code/registry.js +0 -30
  308. package/dist/jobs-code/runner.d.ts +0 -1
  309. package/dist/jobs-code/runner.js +0 -74
  310. package/dist/jobs-deploy.d.ts +0 -22
  311. package/dist/jobs-deploy.js +0 -247
  312. package/dist/jobs-import.d.ts +0 -15
  313. package/dist/jobs-import.js +0 -231
  314. package/dist/keys.d.ts +0 -55
  315. package/dist/keys.js +0 -211
  316. package/dist/login.d.ts +0 -88
  317. package/dist/login.js +0 -369
  318. package/dist/machine.d.ts +0 -222
  319. package/dist/machine.js +0 -578
  320. package/dist/mcp.d.ts +0 -16
  321. package/dist/mcp.js +0 -377
  322. package/dist/modal/index.d.ts +0 -532
  323. package/dist/modal/index.js +0 -1284
  324. package/dist/morph/index.d.ts +0 -255
  325. package/dist/morph/index.js +0 -641
  326. package/dist/network-cli.d.ts +0 -17
  327. package/dist/network-cli.js +0 -523
  328. package/dist/networks/index.d.ts +0 -11
  329. package/dist/networks/index.js +0 -10
  330. package/dist/openai-agents/index.d.ts +0 -132
  331. package/dist/openai-agents/index.js +0 -738
  332. package/dist/page.d.ts +0 -13
  333. package/dist/page.js +0 -39
  334. package/dist/ports/index.d.ts +0 -9
  335. package/dist/ports/index.js +0 -10
  336. package/dist/product-names.d.ts +0 -52
  337. package/dist/product-names.js +0 -174
  338. package/dist/product-renames.d.ts +0 -103
  339. package/dist/product-renames.js +0 -189
  340. package/dist/products/agents.d.ts +0 -935
  341. package/dist/products/agents.js +0 -581
  342. package/dist/products/api-keys.d.ts +0 -113
  343. package/dist/products/api-keys.js +0 -32
  344. package/dist/products/apps.d.ts +0 -409
  345. package/dist/products/apps.js +0 -231
  346. package/dist/products/audit.d.ts +0 -51
  347. package/dist/products/audit.js +0 -10
  348. package/dist/products/balancers.d.ts +0 -87
  349. package/dist/products/balancers.js +0 -8
  350. package/dist/products/billing.d.ts +0 -76
  351. package/dist/products/billing.js +0 -26
  352. package/dist/products/browser.d.ts +0 -73
  353. package/dist/products/browser.js +0 -29
  354. package/dist/products/browsers.d.ts +0 -184
  355. package/dist/products/browsers.js +0 -180
  356. package/dist/products/builds.d.ts +0 -175
  357. package/dist/products/builds.js +0 -234
  358. package/dist/products/ci.d.ts +0 -406
  359. package/dist/products/ci.js +0 -133
  360. package/dist/products/containers.d.ts +0 -71
  361. package/dist/products/containers.js +0 -6
  362. package/dist/products/desktop.d.ts +0 -141
  363. package/dist/products/desktop.js +0 -83
  364. package/dist/products/desktops.d.ts +0 -71
  365. package/dist/products/desktops.js +0 -27
  366. package/dist/products/functions.d.ts +0 -2
  367. package/dist/products/functions.js +0 -5
  368. package/dist/products/images.d.ts +0 -229
  369. package/dist/products/images.js +0 -235
  370. package/dist/products/index.d.ts +0 -84
  371. package/dist/products/index.js +0 -105
  372. package/dist/products/interpreter.d.ts +0 -97
  373. package/dist/products/interpreter.js +0 -106
  374. package/dist/products/jobs.d.ts +0 -408
  375. package/dist/products/jobs.js +0 -256
  376. package/dist/products/limits.d.ts +0 -61
  377. package/dist/products/limits.js +0 -10
  378. package/dist/products/logs.d.ts +0 -245
  379. package/dist/products/logs.js +0 -274
  380. package/dist/products/mcp.d.ts +0 -88
  381. package/dist/products/mcp.js +0 -58
  382. package/dist/products/mounts.d.ts +0 -49
  383. package/dist/products/mounts.js +0 -21
  384. package/dist/products/network-products.d.ts +0 -268
  385. package/dist/products/network-products.js +0 -127
  386. package/dist/products/network.d.ts +0 -62
  387. package/dist/products/network.js +0 -19
  388. package/dist/products/observability.d.ts +0 -264
  389. package/dist/products/observability.js +0 -123
  390. package/dist/products/plans.d.ts +0 -133
  391. package/dist/products/plans.js +0 -24
  392. package/dist/products/previews.d.ts +0 -70
  393. package/dist/products/previews.js +0 -39
  394. package/dist/products/private-network.d.ts +0 -22
  395. package/dist/products/private-network.js +0 -10
  396. package/dist/products/queues.d.ts +0 -149
  397. package/dist/products/queues.js +0 -213
  398. package/dist/products/referrals.d.ts +0 -50
  399. package/dist/products/referrals.js +0 -8
  400. package/dist/products/reservations.d.ts +0 -108
  401. package/dist/products/reservations.js +0 -41
  402. package/dist/products/resources.d.ts +0 -55
  403. package/dist/products/resources.js +0 -122
  404. package/dist/products/secrets.d.ts +0 -316
  405. package/dist/products/secrets.js +0 -333
  406. package/dist/products/signed-requests.d.ts +0 -21
  407. package/dist/products/signed-requests.js +0 -11
  408. package/dist/products/sso.d.ts +0 -44
  409. package/dist/products/sso.js +0 -8
  410. package/dist/products/streams.d.ts +0 -73
  411. package/dist/products/streams.js +0 -17
  412. package/dist/products/switching.d.ts +0 -123
  413. package/dist/products/switching.js +0 -26
  414. package/dist/products/tailscale.d.ts +0 -57
  415. package/dist/products/tailscale.js +0 -17
  416. package/dist/products/uptime.d.ts +0 -97
  417. package/dist/products/uptime.js +0 -42
  418. package/dist/products/volumes.d.ts +0 -190
  419. package/dist/products/volumes.js +0 -114
  420. package/dist/products/watch.d.ts +0 -112
  421. package/dist/products/watch.js +0 -249
  422. package/dist/proxy.d.ts +0 -30
  423. package/dist/proxy.js +0 -200
  424. package/dist/record-cli.d.ts +0 -23
  425. package/dist/record-cli.js +0 -308
  426. package/dist/renamed-products.d.ts +0 -38
  427. package/dist/renamed-products.js +0 -34
  428. package/dist/resumable.d.ts +0 -32
  429. package/dist/resumable.js +0 -201
  430. package/dist/runloop/index.d.ts +0 -333
  431. package/dist/runloop/index.js +0 -560
  432. package/dist/runloop/pagination.d.ts +0 -46
  433. package/dist/runloop/pagination.js +0 -82
  434. package/dist/runloop/sdk.d.ts +0 -131
  435. package/dist/runloop/sdk.js +0 -167
  436. package/dist/runloop/snapshots.d.ts +0 -52
  437. package/dist/runloop/snapshots.js +0 -244
  438. package/dist/sandbox.d.ts +0 -371
  439. package/dist/sandbox.js +0 -1500
  440. package/dist/sandboxes/index.d.ts +0 -11
  441. package/dist/sandboxes/index.js +0 -12
  442. package/dist/sealing.d.ts +0 -6
  443. package/dist/sealing.js +0 -14
  444. package/dist/snapshots/index.d.ts +0 -9
  445. package/dist/snapshots/index.js +0 -11
  446. package/dist/snapshots.d.ts +0 -82
  447. package/dist/snapshots.js +0 -65
  448. package/dist/sprites/index.d.ts +0 -563
  449. package/dist/sprites/index.js +0 -1370
  450. package/dist/ssh.d.ts +0 -56
  451. package/dist/ssh.js +0 -416
  452. package/dist/switched-off.d.ts +0 -5
  453. package/dist/switched-off.js +0 -8
  454. package/dist/tar.d.ts +0 -15
  455. package/dist/tar.js +0 -526
  456. package/dist/terminal.d.ts +0 -24
  457. package/dist/terminal.js +0 -32
  458. package/dist/tools/index.d.ts +0 -62
  459. package/dist/tools/index.js +0 -181
  460. package/dist/transport.d.ts +0 -165
  461. package/dist/transport.js +0 -883
  462. package/dist/trigger/index.d.ts +0 -202
  463. package/dist/trigger/index.js +0 -244
  464. package/dist/tunnel.d.ts +0 -70
  465. package/dist/tunnel.js +0 -316
  466. package/dist/types.d.ts +0 -574
  467. package/dist/types.js +0 -1
  468. package/dist/vercel/client.d.ts +0 -40
  469. package/dist/vercel/client.js +0 -39
  470. package/dist/vercel/command.d.ts +0 -117
  471. package/dist/vercel/command.js +0 -391
  472. package/dist/vercel/errors.d.ts +0 -53
  473. package/dist/vercel/errors.js +0 -131
  474. package/dist/vercel/filesystem.d.ts +0 -153
  475. package/dist/vercel/filesystem.js +0 -297
  476. package/dist/vercel/index.d.ts +0 -24
  477. package/dist/vercel/index.js +0 -36
  478. package/dist/vercel/sandbox-user.d.ts +0 -70
  479. package/dist/vercel/sandbox-user.js +0 -207
  480. package/dist/vercel/sandbox.d.ts +0 -372
  481. package/dist/vercel/sandbox.js +0 -1037
  482. package/dist/vercel/snapshot.d.ts +0 -94
  483. package/dist/vercel/snapshot.js +0 -137
  484. package/dist/volumes/index.d.ts +0 -9
  485. package/dist/volumes/index.js +0 -10
  486. package/dist/wait.d.ts +0 -12
  487. package/dist/wait.js +0 -47
  488. package/dist/wallet.d.ts +0 -45
  489. package/dist/wallet.js +0 -56
  490. package/dist/wireguard.d.ts +0 -7
  491. package/dist/wireguard.js +0 -13
package/dist/transport.js DELETED
@@ -1,883 +0,0 @@
1
- import { ConnectionError, DELIBERATE, errorFor, NOTHING_RAN, RuntimeError, WAITS_FOR_ROOM, } from "./errors.js";
2
- import { describeRoute, envFetch, openWebSocket, untrustedCertificate } from "./proxy.js";
3
- import { warningText } from "./product-renames.js";
4
- export const VERSION = "0.49.0";
5
- export const DEFAULT_BASE_URL = "https://api.withruntime.com";
6
- /** Runtime's API as code inside a Runtime sandbox reaches it: the sandbox's
7
- * own host sends each request on to DEFAULT_BASE_URL over HTTPS. The API runs
8
- * on that host, whose addresses a sandbox cannot reach directly. Plain HTTP
9
- * because the hop never leaves the machine: it goes from the program to the
10
- * guest's own proxy and over the sandbox's private channel to its host. */
11
- export const SANDBOX_BASE_URL = "http://runtime.internal";
12
- /** How a Runtime secret's placeholder starts, the value a sandbox sees in its
13
- * place (packages/cloud-guide/docs/security.md). */
14
- export const PLACEHOLDER = "rtsec_";
15
- /** Every Runtime sandbox has this file; guest-net.py keeps it current. Tests
16
- * move it, so the machine running them does not decide what they see. */
17
- export const sandboxMarker = { path: "/run/runtime/environment.json" };
18
- /** True in a Runtime sandbox. Node and Bun only; a browser is never one. */
19
- export function inRuntimeSandbox(marker = sandboxMarker.path) {
20
- try {
21
- const host = globalThis.process;
22
- return host?.getBuiltinModule?.("node:fs")?.existsSync?.(marker) === true;
23
- }
24
- catch {
25
- return false;
26
- }
27
- }
28
- /** Where calls go when no base URL is given: RUNTIME_API_URL, then Runtime's
29
- * public API, which `reachable` turns into runtime.internal in a sandbox. */
30
- export function defaultBaseUrl(env = processEnv(), inSandbox = inRuntimeSandbox) {
31
- return reachable(env.RUNTIME_API_URL || DEFAULT_BASE_URL, inSandbox);
32
- }
33
- /** The origin calls for `origin` are sent to from here. In a sandbox the
34
- * public API is its own host, which it cannot reach directly, so calls for it
35
- * go to runtime.internal; every other origin is left as it is. */
36
- export function reachable(origin, inSandbox = inRuntimeSandbox) {
37
- return apiOrigin(origin) === DEFAULT_BASE_URL && inSandbox() ? SANDBOX_BASE_URL : origin;
38
- }
39
- function processEnv() {
40
- return (globalThis.process?.env ?? {});
41
- }
42
- /** The W3C trace context of the caller's active OpenTelemetry span, when the
43
- * program uses OpenTelemetry for JavaScript: version 1 of @opentelemetry/api
44
- * keeps its registered context manager and propagator on globalThis under
45
- * this symbol, so the SDK reads them without depending on the package. With
46
- * it, Runtime's span of the call (an export with "traces") is a child of the
47
- * caller's, in the caller's own trace. Nothing without OpenTelemetry, and
48
- * never a reason for a call to fail. */
49
- const OTEL_API = Symbol.for("opentelemetry.js.api.1");
50
- export function traceHeaders() {
51
- try {
52
- const otel = globalThis[OTEL_API];
53
- const active = otel?.context?.active?.();
54
- if (!active || !otel?.propagation?.inject)
55
- return {};
56
- const carrier = {};
57
- otel.propagation.inject(active, carrier, {
58
- set: (into, key, value) => {
59
- into[key.toLowerCase()] = String(value);
60
- },
61
- });
62
- const headers = {};
63
- for (const name of ["traceparent", "tracestate"])
64
- if (typeof carrier[name] === "string" && carrier[name].length <= 512)
65
- headers[name] = carrier[name];
66
- return headers;
67
- }
68
- catch {
69
- return {};
70
- }
71
- }
72
- /** How long an answer that ran nothing (NOTHING_RAN) is retried for a call
73
- * that has no deadline of its own. */
74
- const NOTHING_RAN_MS = 300_000;
75
- /** The longest wait the SDK sleeps on for a retry. A refusal that names a
76
- * longer one (a daily cap, about an hour) is thrown at once, still
77
- * retryable and with its `retryAfterMs`, for the caller to schedule. */
78
- const LONGEST_RETRY_WAIT_MS = 60_000;
79
- /** How long one attempt waits for its answer to start. The API starts every
80
- * answer within 120 s: Caddy answers 503 itself past that, and a longer call
81
- * gets its 200 at 90 s and then its JSON (runtime-late-answer). An attempt
82
- * with no answer by then is talking to a server that is gone, such as a
83
- * controller that died with the call in flight while its address moved to
84
- * the new leader: a client that only waits sends nothing the new leader could
85
- * refuse, so it waited out the whole deadline and failed (a controller
86
- * failover drill, 4 October 2026). It is sent again under the same key. */
87
- export const ANSWER_START_MS = 125_000;
88
- export function apiOrigin(value) {
89
- const url = new URL(value);
90
- // runtime.internal is reserved and never resolves outside a sandbox, so a
91
- // key sent there in plain HTTP never leaves the sandbox's host.
92
- const local = ["localhost", "127.0.0.1", "[::1]", "runtime.internal"].includes(url.hostname);
93
- if ((url.protocol !== "https:" && !(local && url.protocol === "http:")) ||
94
- (url.hostname === "runtime.internal" && (url.protocol !== "http:" || url.port !== "")) ||
95
- url.username ||
96
- url.password ||
97
- url.search ||
98
- url.hash ||
99
- url.pathname !== "/")
100
- throw new Error("Use an HTTPS API origin (or http://runtime.internal inside a sandbox, http://localhost for tests).");
101
- return url.origin;
102
- }
103
- export function encodeQuery(query) {
104
- if (!query)
105
- return "";
106
- const params = new URLSearchParams();
107
- for (const [key, value] of Object.entries(query)) {
108
- if (value === undefined)
109
- continue;
110
- if (Array.isArray(value))
111
- for (const item of value)
112
- params.append(key, item);
113
- else
114
- params.set(key, String(value));
115
- }
116
- const text = params.toString();
117
- return text ? `?${text}` : "";
118
- }
119
- const sleep = (ms, signal) => new Promise((resolve, reject) => {
120
- const timer = setTimeout(done, ms);
121
- function done() {
122
- signal?.removeEventListener("abort", abort);
123
- resolve();
124
- }
125
- function abort() {
126
- clearTimeout(timer);
127
- reject(signal?.reason instanceof Error ? signal.reason : new Error("Aborted"));
128
- }
129
- if (signal?.aborted)
130
- abort();
131
- else
132
- signal?.addEventListener("abort", abort, { once: true });
133
- });
134
- /** A credential lookup can finish independently, but must not keep its
135
- * caller waiting after cancellation or hold that caller's queue slot. */
136
- function untilAborted(pending, signal) {
137
- if (!signal)
138
- return pending;
139
- return new Promise((resolve, reject) => {
140
- const abort = () => reject(abortReason(signal));
141
- if (signal.aborted)
142
- abort();
143
- else
144
- signal.addEventListener("abort", abort, { once: true });
145
- pending.then((value) => {
146
- signal.removeEventListener("abort", abort);
147
- resolve(value);
148
- }, (cause) => {
149
- signal.removeEventListener("abort", abort);
150
- reject(cause instanceof Error ? cause : new Error("Credential lookup failed.", { cause }));
151
- });
152
- });
153
- }
154
- function abortReason(signal) {
155
- return signal?.reason instanceof Error
156
- ? signal.reason
157
- : new Error("Aborted", { cause: signal?.reason });
158
- }
159
- /** At most `maximum` holders at once; the rest wait their turn, first come
160
- * first served. */
161
- function slots(maximum, onWait) {
162
- let active = 0;
163
- const waiting = [];
164
- return {
165
- async take(signal) {
166
- signal?.throwIfAborted();
167
- if (active < maximum) {
168
- active++;
169
- return;
170
- }
171
- onWait?.();
172
- await new Promise((resolve, reject) => {
173
- const ready = () => {
174
- signal?.removeEventListener("abort", abort);
175
- resolve();
176
- };
177
- const abort = () => {
178
- const at = waiting.indexOf(ready);
179
- if (at >= 0)
180
- waiting.splice(at, 1);
181
- reject(abortReason(signal));
182
- };
183
- waiting.push(ready);
184
- signal?.addEventListener("abort", abort, { once: true });
185
- });
186
- },
187
- give() {
188
- const next = waiting.shift();
189
- if (next)
190
- next();
191
- else
192
- active--;
193
- },
194
- };
195
- }
196
- /** Connections a client holds at once by default: under the 64 one address
197
- * may hold to the API (api.md, "Limits"), with room for a second client. */
198
- export const DEFAULT_MAX_CONNECTIONS = 48;
199
- /** Connections a client keeps for answers read whole, however many streams
200
- * are open: a stream's reader that makes a call (an output callback writing a
201
- * file) never waits behind streams, its own included. */
202
- const KEPT_FOR_CALLS = 8;
203
- /** One connection pool, one retry policy, one error shape for every product.
204
- * Node's and Bun's fetch keep connections alive, so a client reused across
205
- * calls pays TLS once. Over HTTP/1.1 every call in flight holds its own
206
- * connection, and one address may hold 64 to the API before it has used a
207
- * valid key: past that the API's edge holds new ones back until one closes.
208
- * So a client holds at most `maxConnections` at once,
209
- * answers and streams together, and the rest queue here, first come first
210
- * served, and wait rather than fail. Streams (a command's output, a download,
211
- * a watch) take at most `maxConnections` less KEPT_FOR_CALLS of them. A
212
- * terminal or tunnel's WebSocket is not counted. */
213
- /** AbortSignal.timeout in whole milliseconds, rounded up, never under 1.
214
- * Node throws ERR_OUT_OF_RANGE on a fraction (Bun accepts one), so a
215
- * customer's timeoutMs of 1500.5 would be a RangeError instead of a request;
216
- * the live promise probe broke this way on 9 October 2026. Every
217
- * deadline the SDK makes from a customer's or a computed value goes through
218
- * this. */
219
- export function timeoutSignal(ms) {
220
- return AbortSignal.timeout(Math.max(1, Math.ceil(ms)));
221
- }
222
- /** A deadline `ms` from now that `extend` moves later; it aborts with a
223
- * TimeoutError, as AbortSignal.timeout does. */
224
- function movableDeadline(ms) {
225
- const controller = new AbortController();
226
- let at = performance.now() + ms;
227
- let timer;
228
- const arm = () => {
229
- timer = setTimeout(() => controller.abort(new DOMException("The operation timed out.", "TimeoutError")), Math.max(1, Math.ceil(at - performance.now())));
230
- // Never keeps a process alive by itself, as AbortSignal.timeout does not.
231
- timer.unref?.();
232
- };
233
- arm();
234
- return {
235
- signal: controller.signal,
236
- at: () => at,
237
- extend: (by) => {
238
- if (controller.signal.aborted || by <= 0)
239
- return;
240
- at += by;
241
- clearTimeout(timer);
242
- arm();
243
- },
244
- };
245
- }
246
- export class Transport {
247
- baseUrl;
248
- #apiKey;
249
- #findKey;
250
- #fetch;
251
- /** Whether calls go through envFetch, so a failure can name its proxy. */
252
- #routed;
253
- #timeoutMs;
254
- #answerStartMs;
255
- #maxRetries;
256
- #client;
257
- #slots;
258
- #streams;
259
- /** What `sandboxes.create` waits for room by default. */
260
- waitForCapacityMs;
261
- constructor(options) {
262
- if (typeof options.apiKey === "function")
263
- this.#findKey = options.apiKey;
264
- else if (!options.apiKey || /\s/.test(options.apiKey))
265
- throw missingKey();
266
- else
267
- this.#apiKey = options.apiKey;
268
- // A secret's placeholder becomes the key only on its way out through the
269
- // sandbox's proxy; runtime.internal goes to the host without it, so the
270
- // API sees the placeholder and answers 401 (land-lander, 11 October 2026:
271
- // every worker's `check --remote`). Such a key's calls take the public API.
272
- const placeholder = this.#apiKey?.startsWith(PLACEHOLDER) === true;
273
- const origin = options.baseUrl || processEnv().RUNTIME_API_URL || DEFAULT_BASE_URL;
274
- this.baseUrl = apiOrigin(placeholder ? origin : reachable(origin));
275
- // The environment's proxy (HTTPS_PROXY, NO_PROXY) on Node and Bun alike;
276
- // a fetch passed in is used as it is.
277
- this.#fetch = options.fetch ?? envFetch;
278
- this.#routed = options.fetch === undefined;
279
- this.#timeoutMs = options.timeoutMs ?? 300_000;
280
- this.#answerStartMs = options.answerStartMs ?? ANSWER_START_MS;
281
- this.#maxRetries = options.maxRetries ?? 4;
282
- this.#client = options.client ?? `sdk-js/${VERSION}`;
283
- const most = Math.max(1, options.maxConnections ?? DEFAULT_MAX_CONNECTIONS);
284
- const queued = options.onQueued && (() => options.onQueued(most));
285
- this.#slots = slots(most, queued);
286
- this.#streams = slots(Math.max(1, most - KEPT_FOR_CALLS), queued);
287
- this.waitForCapacityMs = Math.max(0, options.waitForCapacityMs ?? 120_000);
288
- }
289
- /** The key, found once on first use when it was not given. */
290
- async #key() {
291
- if (this.#apiKey === undefined) {
292
- const found = await this.#findKey();
293
- if (!found || /\s/.test(found))
294
- throw missingKey();
295
- this.#apiKey = found;
296
- }
297
- return this.#apiKey;
298
- }
299
- #headers(call, key, apiKey) {
300
- return {
301
- ...call.headers,
302
- authorization: `Bearer ${apiKey}`,
303
- accept: call.accept ?? "application/json",
304
- "x-runtime-client": this.#client,
305
- ...(call.bytes
306
- ? { "content-type": "application/octet-stream" }
307
- : call.body === undefined
308
- ? {}
309
- : { "content-type": "application/json" }),
310
- ...(key ? { "idempotency-key": key } : {}),
311
- ...(call.wait ? { prefer: `wait=${Math.min(120, Math.ceil(call.wait))}` } : {}),
312
- ...traceHeaders(),
313
- };
314
- }
315
- /** Sends a call and returns the raw Response once it succeeded. Retries
316
- * transport failures, 429, 502, 503 and 504 with backoff and jitter, with
317
- * the same key every time, and waits out a full house for a call that sets
318
- * waitForCapacityMs. */
319
- async send(call) {
320
- return this.#send(this.#prepare(call), async (response) => response);
321
- }
322
- /** Start the deadline before waiting for a connection; keep one key and
323
- * signal through every retry and the complete response body. */
324
- #prepare(call) {
325
- const timeoutMs = call.timeoutMs ?? this.#timeoutMs;
326
- // The deadline is the caller's timeoutMs plus only the time actually
327
- // spent waiting for room (WAITS_FOR_ROOM), which moves it on as it waits:
328
- // a wake given timeoutMs 20 on a server that never answers still ends at
329
- // 20 ms, not two minutes later (lifecycle-deadlines.test.ts).
330
- const deadline = timeoutMs === 0 ? undefined : movableDeadline(timeoutMs);
331
- const signal = deadline
332
- ? call.signal
333
- ? AbortSignal.any([call.signal, deadline.signal])
334
- : deadline.signal
335
- : call.signal;
336
- const prepared = {
337
- ...call,
338
- timeoutMs: 0,
339
- ...(signal ? { signal } : {}),
340
- ...(call.method !== "GET"
341
- ? { idempotencyKey: call.idempotencyKey ?? crypto.randomUUID() }
342
- : {}),
343
- };
344
- if (deadline) {
345
- prepared.deadlineAt = deadline.at;
346
- prepared.extendDeadline = deadline.extend;
347
- }
348
- return prepared;
349
- }
350
- #connectionError(call, cause) {
351
- const cancelled = call.signal?.aborted === true;
352
- const route = this.#routed && !cancelled
353
- ? describeRoute(`${this.baseUrl}${call.path}`, cause)
354
- : { via: "" };
355
- // A certificate this machine does not trust answered, most often a proxy
356
- // that inspects TLS: said as that, never as "no answer" (18 October 2026,
357
- // the published CLI on Node behind such a proxy, where Bun trusted it).
358
- const certificate = cancelled ? undefined : untrustedCertificate(cause);
359
- if (certificate)
360
- return new ConnectionError({
361
- message: `Runtime at ${this.baseUrl}${route.via} could not be reached: the TLS certificate presented is not one this machine trusts (${certificate}).`,
362
- hint: "A proxy or firewall that inspects TLS signs with its own authority: point NODE_EXTRA_CA_CERTS at its certificate (Node), or add it to the system's trusted certificates.",
363
- code: "connection_error",
364
- status: 0,
365
- ...(call.idempotencyKey ? { idempotencyKey: call.idempotencyKey } : {}),
366
- cause,
367
- });
368
- return new ConnectionError({
369
- message: cancelled
370
- ? "The call was cancelled or ran past its deadline."
371
- : call.method !== "GET"
372
- ? `No answer from Runtime at ${this.baseUrl}${route.via}. The change may have happened; retrying with the same idempotencyKey is safe.`
373
- : `No answer from Runtime at ${this.baseUrl}${route.via}.`,
374
- hint: cancelled
375
- ? "Raise timeoutMs for a long call, or retry with the same idempotencyKey."
376
- : (route.hint ?? "Check the network, and RUNTIME_API_URL if you set it."),
377
- code: cancelled ? "timeout" : "connection_error",
378
- status: 0,
379
- ...(call.idempotencyKey ? { idempotencyKey: call.idempotencyKey } : {}),
380
- cause,
381
- });
382
- }
383
- /** Sleeps between tries. A call holding a connection slot (`gate`) lends
384
- * it out while it sleeps, since a sleep holds no connection, and takes a
385
- * slot again before it sends: a thousand creates waiting out a full region
386
- * or a 429 would otherwise keep every other call of this client, the stop
387
- * that frees room included, queued behind them. */
388
- async #rest(ms, signal, gate) {
389
- gate?.lend();
390
- await sleep(ms, signal);
391
- await gate?.take();
392
- }
393
- /** Wait before sending a refused call again. When the call's deadline
394
- * ends the wait, the refusal stands: on a loaded machine bun can fire
395
- * AbortSignal.timeout before a shorter setTimeout, and the call then
396
- * failed as a timeout although the transport had judged the wait to fit
397
- * (11 October 2026). A caller's own cancel still ends it as a cancel. */
398
- async #retryAfter(refusal, ms, signal, gate) {
399
- await this.#rest(ms, signal, gate).catch((cause) => {
400
- throw signal?.reason?.name === "TimeoutError"
401
- ? refusal
402
- : cause;
403
- });
404
- }
405
- async #send(call, consume, gate) {
406
- let apiKey;
407
- try {
408
- call.signal?.throwIfAborted();
409
- apiKey = call.bearer ?? (await untilAborted(this.#key(), call.signal));
410
- }
411
- catch (cause) {
412
- if (call.signal?.aborted)
413
- throw this.#connectionError(call, cause);
414
- throw cause;
415
- }
416
- const key = call.method !== "GET" ? call.idempotencyKey : undefined;
417
- const roomMs = Math.max(0, call.waitForCapacityMs ?? 0);
418
- const roomUntil = performance.now() + roomMs;
419
- let roomAttempt = 0;
420
- const signal = call.signal;
421
- const url = `${this.baseUrl}${call.path}${encodeQuery(call.query)}`;
422
- const body = call.bytes ?? (call.body === undefined ? undefined : JSON.stringify(call.body));
423
- const retry = call.retry ?? true;
424
- let attempt = 0;
425
- // An answer that ran nothing is sent again until the call's deadline.
426
- // Read at each use: a wait for room moves the call's deadline on.
427
- const idleFallback = performance.now() + NOTHING_RAN_MS;
428
- const idleUntil = () => call.deadlineAt?.() ?? idleFallback;
429
- let idleAttempt = 0;
430
- // The last try never left, and was sent again at once.
431
- let resentAtOnce = false;
432
- for (;;) {
433
- let response;
434
- let inCallback = false;
435
- // Called as a plain function: Cloudflare Workers' fetch throws "Illegal
436
- // invocation" when called as a method of another object (this.#fetch()).
437
- const send = this.#fetch;
438
- try {
439
- // "manual", not "error": Workers accept only "follow" and "manual".
440
- // The API never redirects, so a redirect is refused here exactly as
441
- // "error" refused it: thrown, retried, then a connection_error.
442
- signal?.throwIfAborted();
443
- const started = new AbortController();
444
- const unanswered = setTimeout(() => started.abort(new DOMException("No answer started.", "TimeoutError")), this.#answerStartMs);
445
- try {
446
- response = await send(url, {
447
- method: call.method,
448
- headers: this.#headers(call, key, apiKey),
449
- redirect: "manual",
450
- signal: signal ? AbortSignal.any([signal, started.signal]) : started.signal,
451
- ...(body === undefined ? {} : { body: body }),
452
- });
453
- }
454
- finally {
455
- clearTimeout(unanswered);
456
- }
457
- if (response.type === "opaqueredirect" ||
458
- (response.status >= 300 && response.status < 400)) {
459
- await response.body?.cancel().catch(() => { });
460
- throw new TypeError(`fetch failed: Runtime answered a redirect (${response.status}).`);
461
- }
462
- sayRenamed(response.headers.get("warning"));
463
- /* An answer that took longer than the API holds its headers (90 s)
464
- comes as a 200 sent early, and then its JSON: the answer, or
465
- {"error": ...} when the work failed after the status went
466
- (runtime-late-answer, api.md). Either way it is read here, so a
467
- failure is thrown as the error it is, never returned as a success. */
468
- let late;
469
- if (response.ok && response.headers.get("runtime-late-answer") === "true") {
470
- const text = await response.text();
471
- const failed = lateFailure(text);
472
- if (failed === undefined)
473
- return await consume(new Response(text, { headers: response.headers }));
474
- late = { status: failed, text };
475
- }
476
- else if (response.ok) {
477
- inCallback = true;
478
- call.onResponse?.(response);
479
- inCallback = false;
480
- return await consume(response);
481
- }
482
- const status = late?.status ?? response.status;
483
- // Runtime never answers 407: it is a proxy refusing the tunnel, which
484
- // Bun's fetch hands back as a response rather than an error.
485
- if (response.status === 407 && this.#routed) {
486
- await response.body?.cancel();
487
- const route = describeRoute(url, 407);
488
- throw new ConnectionError({
489
- message: `No answer from Runtime at ${this.baseUrl}${route.via}.`,
490
- code: "connection_error",
491
- status: 0,
492
- ...(route.hint ? { hint: route.hint } : {}),
493
- ...(key ? { idempotencyKey: key } : {}),
494
- });
495
- }
496
- const text = late?.text ?? (await response.text());
497
- let parsed = null;
498
- try {
499
- parsed = JSON.parse(text);
500
- }
501
- catch {
502
- parsed = { error: { message: text.slice(0, 500) || `HTTP ${status}` } };
503
- }
504
- const error = errorFor(status, parsed, key);
505
- const header = Number(response.headers.get("retry-after"));
506
- const headerMs = Number.isFinite(header) && header > 0 ? header * 1000 : undefined;
507
- // A full house: wait for a slot or for room, then send the same call
508
- // again. A request that can never fit (a fork of more copies than the
509
- // trial runs) is not waited for.
510
- if (retry &&
511
- roomMs > 0 &&
512
- WAITS_FOR_ROOM.has(error.code) &&
513
- error.details?.field !== "count" &&
514
- // A quota on what is kept says it never clears by waiting.
515
- error.sentRetryable !== false) {
516
- const left = roomUntil - performance.now();
517
- if (left <= 0)
518
- throw error;
519
- const pause = Math.min(left, error.retryAfterMs ?? roomBackoff(roomAttempt++));
520
- inCallback = true;
521
- call.onCapacityWait?.(error, pause);
522
- inCallback = false;
523
- call.extendDeadline?.(pause);
524
- await this.#retryAfter(error, pause, signal, gate);
525
- continue;
526
- }
527
- // Nothing ran: safe to send again for any call, past maxRetries,
528
- // with growing waits, until the deadline; then this refusal stands.
529
- // A late answer's failure came after the work began, so only a
530
- // guest's own refusal (`guest_busy`, before anything is journaled)
531
- // still says nothing ran.
532
- if ([429, 503].includes(status) &&
533
- NOTHING_RAN.has(error.code) &&
534
- error.sentRetryable !== false &&
535
- (!late || error.code === "guest_busy")) {
536
- const named = error.retryAfterMs ?? headerMs;
537
- if (named !== undefined && named > LONGEST_RETRY_WAIT_MS)
538
- throw withWait(error, named);
539
- const base = named ?? 250;
540
- const pause = Math.min(30_000, base * 2 ** Math.min(idleAttempt++, 3)) * (0.9 + Math.random() * 0.2);
541
- if (pause >= idleUntil() - performance.now())
542
- throw error;
543
- await this.#retryAfter(error, pause, signal, gate);
544
- continue;
545
- }
546
- // The API says whether the same request may succeed; an older
547
- // server is judged by its status. A refusal for room or for the
548
- // account's own limit is the room wait's above on a create, wake or
549
- // restart, which set waitForCapacityMs (0 fails at once); any other
550
- // call retries what the answer says.
551
- const retryable = (error.sentRetryable ??
552
- ([429, 502, 503, 504].includes(status) && !DELIBERATE.has(error.code))) &&
553
- !(call.waitForCapacityMs !== undefined && WAITS_FOR_ROOM.has(error.code));
554
- if (!retry || !retryable || attempt >= this.#maxRetries)
555
- throw error;
556
- const named = error.retryAfterMs ?? headerMs;
557
- if (named !== undefined && named > LONGEST_RETRY_WAIT_MS)
558
- throw withWait(error, named);
559
- const wait = named ?? backoff(attempt);
560
- await this.#rest(Math.min(30_000, wait) * (0.9 + Math.random() * 0.2), signal, gate);
561
- }
562
- catch (cause) {
563
- // Deliberate API refusals and unusable proxy settings cannot be
564
- // fixed by repeating the request. Body failures are transport
565
- // failures too: a write replays under its original key.
566
- if (inCallback) {
567
- await response?.body?.cancel().catch(() => undefined);
568
- throw cause;
569
- }
570
- if (cause instanceof RuntimeError)
571
- throw cause;
572
- if (signal?.aborted || !retry || attempt >= this.#maxRetries)
573
- throw this.#connectionError(call, cause);
574
- // A connection that never opened sent no byte of the request, so
575
- // the next try, which may reach another server, goes at once; once
576
- // in a row, so an API that is down is not hammered. Anything that
577
- // may have reached a server (a reset, a timeout, a cut answer)
578
- // keeps the backoff and its key's rules.
579
- const atOnce = response === undefined && neverSent(cause) && !resentAtOnce;
580
- resentAtOnce = atOnce;
581
- await this.#rest(atOnce ? Math.random() * 50 : backoff(attempt), signal, gate).catch((cause) => {
582
- throw cause instanceof RuntimeError ? cause : this.#connectionError(call, cause);
583
- });
584
- }
585
- attempt++;
586
- }
587
- }
588
- /** A hold on `kinds` of slot, taken in order and given back together. */
589
- #gate(call, kinds) {
590
- let held = 0;
591
- const lend = () => {
592
- while (held > 0)
593
- kinds[--held].give();
594
- };
595
- return {
596
- take: async () => {
597
- try {
598
- for (; held < kinds.length; held++)
599
- await kinds[held].take(call.signal);
600
- }
601
- catch (cause) {
602
- lend();
603
- throw this.#connectionError(call, cause);
604
- }
605
- },
606
- lend,
607
- };
608
- }
609
- async #queued(call, consume) {
610
- const gate = this.#gate(call, [this.#slots]);
611
- await gate.take();
612
- try {
613
- return await this.#send(call, consume, gate);
614
- }
615
- finally {
616
- gate.lend();
617
- }
618
- }
619
- async json(call) {
620
- return this.#queued(this.#prepare(call), async (response) => {
621
- const text = await response.text();
622
- return (text ? JSON.parse(text) : null);
623
- });
624
- }
625
- async bytes(call) {
626
- return this.#queued(this.#prepare(call), async (response) => new Uint8Array(await response.arrayBuffer()));
627
- }
628
- /** A file's bytes, read whole and checked against its promised length and
629
- * SHA-256. A short or different body is read again twice, within the same
630
- * call deadline. */
631
- async fileBytes(call) {
632
- call = this.#prepare(call);
633
- for (let attempt = 0;; attempt++) {
634
- const { body, problem } = await this.#queued(call, async (response) => {
635
- const body = new Uint8Array(await response.arrayBuffer());
636
- return { body, problem: await checkBody(response.headers, body) };
637
- });
638
- if (!problem)
639
- return body;
640
- if (attempt >= 2)
641
- throw problem;
642
- await sleep(backoff(attempt), call.signal).catch((cause) => {
643
- throw this.#connectionError(call, cause);
644
- });
645
- }
646
- }
647
- /** A file's bytes as they arrive, for files too big to hold. The stream
648
- * errors with `download_incomplete` if it ends short of the length the API
649
- * promised; it is never retried part way. */
650
- async fileStream(call) {
651
- const { response, release } = await this.#opened(this.#prepare(call));
652
- const expected = promisedLength(response.headers);
653
- const body = response.body ?? new ReadableStream({ start: (c) => c.close() });
654
- let got = 0;
655
- const reader = body
656
- .pipeThrough(new TransformStream({
657
- transform(chunk, controller) {
658
- got += chunk.byteLength;
659
- if (expected !== undefined && got > expected)
660
- controller.error(incompleteDownload(got, expected));
661
- else
662
- controller.enqueue(chunk);
663
- },
664
- flush(controller) {
665
- if (expected !== undefined && got !== expected)
666
- controller.error(incompleteDownload(got, expected));
667
- },
668
- }))
669
- .getReader();
670
- // The connection is given back when the body ends, fails or is cancelled.
671
- return new ReadableStream({
672
- async pull(controller) {
673
- try {
674
- const { value, done } = await reader.read();
675
- if (done) {
676
- release();
677
- controller.close();
678
- }
679
- else
680
- controller.enqueue(value);
681
- }
682
- catch (error) {
683
- release();
684
- controller.error(error);
685
- }
686
- },
687
- async cancel(reason) {
688
- release();
689
- await reader.cancel(reason);
690
- },
691
- });
692
- }
693
- /** Sends a call whose answer is a stream, holding a stream slot and a
694
- * connection slot from before it is sent until `release`: once its body is
695
- * read, failed or cancelled, or its deadline or signal ends it, whichever
696
- * comes first, so a stream nobody finishes still gives its slots back at
697
- * its deadline. */
698
- async #opened(call) {
699
- const gate = this.#gate(call, [this.#streams, this.#slots]);
700
- await gate.take();
701
- let released = false;
702
- const release = () => {
703
- if (released)
704
- return;
705
- released = true;
706
- call.signal?.removeEventListener("abort", release);
707
- gate.lend();
708
- };
709
- try {
710
- const response = await this.#send(call, async (response) => response, gate);
711
- if (call.signal?.aborted)
712
- release();
713
- else
714
- call.signal?.addEventListener("abort", release, { once: true });
715
- return { response, release };
716
- }
717
- catch (error) {
718
- release();
719
- throw error;
720
- }
721
- }
722
- /** Newline-delimited JSON events, as they arrive. */
723
- async *events(call) {
724
- const { response, release } = await this.#opened(this.#prepare({ ...call, accept: "application/x-ndjson" }));
725
- if (!response.body)
726
- return release();
727
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
728
- let buffer = "";
729
- try {
730
- for (;;) {
731
- call.signal?.throwIfAborted();
732
- const { value, done } = await reader.read();
733
- if (done)
734
- break;
735
- buffer += value;
736
- let newline = buffer.indexOf("\n");
737
- while (newline >= 0) {
738
- call.signal?.throwIfAborted();
739
- const line = buffer.slice(0, newline).trim();
740
- buffer = buffer.slice(newline + 1);
741
- if (line)
742
- yield JSON.parse(line);
743
- newline = buffer.indexOf("\n");
744
- }
745
- }
746
- call.signal?.throwIfAborted();
747
- if (buffer.trim())
748
- yield JSON.parse(buffer);
749
- }
750
- finally {
751
- // Returning early from the iterator must close the HTTP stream too.
752
- // Cleanup must not replace a parse, network or callback error.
753
- await reader.cancel().catch(() => undefined);
754
- reader.releaseLock();
755
- release();
756
- }
757
- }
758
- /** The key calls are made with: the one given, RUNTIME_API_KEY, or the
759
- * connection `runtime login` saved. For another platform's SDK pointed at
760
- * Runtime (`runtime.agents.anthropic()`). */
761
- async apiKey() {
762
- return this.#key();
763
- }
764
- /** A WebSocket to an API path, authenticated with the same key. */
765
- async websocket(path, query) {
766
- const apiKey = await this.#key();
767
- const url = `${this.baseUrl.replace(/^http/, "ws")}${path}${encodeQuery(query)}`;
768
- return openWebSocket(url, {
769
- authorization: `Bearer ${apiKey}`,
770
- "x-runtime-client": this.#client,
771
- });
772
- }
773
- }
774
- /** The status a late answer's body failed with, or undefined when it is an
775
- * answer. The body is the error the API would have sent as its status. */
776
- const said = new Set();
777
- /** CLOUD.md section 4: a call under a renamed product word is answered with a
778
- * Warning naming the new word. It is printed once per process, to stderr, so
779
- * a loop does not drown its own output and stdout stays the caller's. */
780
- export function sayRenamed(header, say = console.warn) {
781
- const text = warningText(header);
782
- if (text === undefined || said.has(text))
783
- return;
784
- said.add(text);
785
- say(`Runtime: ${text}`);
786
- }
787
- function lateFailure(text) {
788
- let body;
789
- try {
790
- body = JSON.parse(text);
791
- }
792
- catch {
793
- return 502;
794
- }
795
- // An API error is a body of `error` alone, with a code; an answer may carry
796
- // an `error` of its own (a code cell's exception), next to other fields.
797
- if (!body || typeof body !== "object" || Object.keys(body).length !== 1)
798
- return undefined;
799
- const error = body.error;
800
- if (!error || typeof error !== "object" || typeof error.code !== "string")
801
- return undefined;
802
- const status = error.status;
803
- return typeof status === "number" && status >= 400 ? status : 500;
804
- }
805
- function promisedLength(headers) {
806
- const value = headers.get("x-content-length");
807
- return value !== null && /^\d+$/.test(value) ? Number(value) : undefined;
808
- }
809
- /** A download that ended short of (or past) the length the API promised. */
810
- export function incompleteDownload(got, expected) {
811
- return new RuntimeError({
812
- message: `The download ended at ${got} of ${expected} bytes.`,
813
- code: "download_incomplete",
814
- status: 0,
815
- hint: "Read the file again; nothing was written for this read. If it keeps happening, report it with `npx withruntime feedback`.",
816
- details: { received: got, expected },
817
- });
818
- }
819
- /** Why a whole body cannot be trusted, or undefined when it can. */
820
- async function checkBody(headers, body) {
821
- const expected = promisedLength(headers);
822
- if (expected !== undefined && body.byteLength !== expected)
823
- return incompleteDownload(body.byteLength, expected);
824
- const sha256 = headers.get("x-content-sha256");
825
- if (!sha256)
826
- return undefined;
827
- const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", body));
828
- const hex = Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("");
829
- if (hex === sha256.toLowerCase())
830
- return undefined;
831
- return new RuntimeError({
832
- message: "The file's bytes did not match the SHA-256 the API sent with them.",
833
- code: "download_incomplete",
834
- status: 0,
835
- hint: "Read the file again. If it keeps happening, report it with `npx withruntime feedback`.",
836
- });
837
- }
838
- /** No key given, none in RUNTIME_API_KEY, and none saved by `runtime login`. */
839
- export function missingKey() {
840
- return new RuntimeError({
841
- message: "No Runtime key found: RUNTIME_API_KEY is not set and this machine is not connected.",
842
- code: "missing_api_key",
843
- status: 0,
844
- hint: "Run `npx -y withruntime login` (a browser approval; nothing to copy), set RUNTIME_API_KEY to a key from https://withruntime.com/account/keys, or pass { apiKey }.",
845
- });
846
- }
847
- /** Error codes of a connection that never opened (Node's and Bun's), so no
848
- * byte of the request left this machine. */
849
- const NEVER_OPENED = new Set([
850
- "ECONNREFUSED",
851
- "ENOENT",
852
- "EHOSTUNREACH",
853
- "ENETUNREACH",
854
- "EADDRNOTAVAIL",
855
- "ConnectionRefused",
856
- "FailedToOpenSocket",
857
- ]);
858
- /** Whether a fetch failure is a connection that never opened: its code, or
859
- * one of its causes', says so. A timeout or a reset never counts. */
860
- export function neverSent(cause) {
861
- for (let at = cause, depth = 0; at && depth < 5; depth++) {
862
- const code = at.code;
863
- if (typeof code === "string" && NEVER_OPENED.has(code))
864
- return true;
865
- at = at.cause;
866
- }
867
- return false;
868
- }
869
- /** `error` thrown for a wait too long to sleep on, carrying that wait as
870
- * `retryAfterMs` when only the Retry-After header named it. */
871
- function withWait(error, ms) {
872
- if (error.retryAfterMs === undefined)
873
- error.retryAfterMs = Math.round(ms);
874
- return error;
875
- }
876
- function backoff(attempt) {
877
- return Math.min(8000, 250 * 2 ** attempt) * (0.5 + Math.random());
878
- }
879
- /** Between tries for room: 0.5 s, 1 s, 2 s, 4 s, then every 8 s, jittered, so
880
- * a queue of CI jobs spreads out instead of knocking at once. */
881
- function roomBackoff(attempt) {
882
- return Math.min(8000, 500 * 2 ** attempt) * (0.75 + Math.random() * 0.5);
883
- }