deepline 0.3.520 → 0.3.522

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 (185) hide show
  1. package/dist/bundling-sources/sdk/src/plays/client-core.ts +16 -45
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +0 -18
  4. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +0 -155
  5. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +8 -1
  6. package/dist/bundling-sources/shared_libs/play-runtime/fixture-behavior.ts +24 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +1 -54
  8. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +2 -7
  9. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +0 -13
  10. package/dist/bundling-sources/shared_libs/play-runtime/run-identity.ts +0 -56
  11. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +10 -21
  12. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-heartbeat.ts +1 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-progress-push.ts +2 -1
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +1 -1
  15. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +2 -37
  16. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +3 -74
  17. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +2 -226
  18. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +3 -36
  19. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api-paths.ts +0 -26
  20. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +1 -9
  21. package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +0 -5
  22. package/dist/bundling-sources/shared_libs/play-runtime/runtime-environment.ts +9 -49
  23. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-oidc.ts +11 -447
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -4
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +12 -207
  26. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -17
  27. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-progress-registry.ts +0 -9
  28. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +2 -18
  29. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +15 -175
  30. package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +0 -4
  31. package/dist/cli/{artifacts-4DSPSIU5.js → artifacts-GIZZH5VA.js} +20 -20
  32. package/dist/cli/{artifacts-D6PU7SBC.mjs → artifacts-RY2MK74N.mjs} +8 -8
  33. package/dist/cli/auth-JSES2JOQ.js +43 -0
  34. package/dist/cli/{auth-MXKNPUXW.mjs → auth-YIBY5IKT.mjs} +5 -5
  35. package/dist/cli/{billing-SQ26NKGH.mjs → billing-G3IX3SNY.mjs} +8 -8
  36. package/dist/cli/{billing-WEYCNJIR.js → billing-UDKL53GI.js} +81 -81
  37. package/dist/cli/{chunk-6Y3DDRRN.js → chunk-2KHUFWTK.js} +3 -3
  38. package/dist/cli/{chunk-4VR5OTYP.js → chunk-37SXIFIU.js} +44 -44
  39. package/dist/cli/{chunk-QSWPDYOP.mjs → chunk-3KMGVOBM.mjs} +4 -4
  40. package/dist/cli/{chunk-7VJKHJY7.js → chunk-4DFWDA2Q.js} +14 -14
  41. package/dist/cli/{chunk-VSPNBBRT.js → chunk-4MF44THR.js} +66 -119
  42. package/dist/cli/{chunk-NLIO6QLP.mjs → chunk-4TUMKJZX.mjs} +2 -2
  43. package/dist/cli/{chunk-KKSMHTQO.mjs → chunk-52MHE7B4.mjs} +1 -1
  44. package/dist/cli/{chunk-AVW2LKRF.js → chunk-534YYHIF.js} +6 -6
  45. package/dist/cli/{chunk-QQGRQRCS.mjs → chunk-5477PEHL.mjs} +1 -1
  46. package/dist/cli/{chunk-YHHLLONU.js → chunk-5BQPEHEP.js} +14 -14
  47. package/dist/cli/{chunk-GVTHFDKN.js → chunk-5H22VJPE.js} +6 -6
  48. package/dist/cli/{chunk-LUIPBI6P.js → chunk-6SJPZV5E.js} +2 -2
  49. package/dist/cli/{chunk-NNUJQ5O2.mjs → chunk-7J5PLHII.mjs} +1 -1
  50. package/dist/cli/{chunk-I4GBCKBL.js → chunk-7JEN3FX4.js} +5 -5
  51. package/dist/cli/{chunk-VSLU4JZV.mjs → chunk-BONXEWYF.mjs} +3 -3
  52. package/dist/cli/{chunk-AM7HMWNA.js → chunk-BZY335JP.js} +5 -5
  53. package/dist/cli/{chunk-YP3G2CP6.mjs → chunk-C6WGMODR.mjs} +2 -2
  54. package/dist/cli/{chunk-V6BUWQBI.mjs → chunk-CFXERH7F.mjs} +1 -1
  55. package/dist/cli/{chunk-ORAWUIMN.js → chunk-DARD7TJ7.js} +53 -53
  56. package/dist/cli/{chunk-BHAP6FIZ.js → chunk-DLDWAPA5.js} +4 -4
  57. package/dist/cli/{chunk-FWGTBR3W.js → chunk-DNJJ3ULJ.js} +2 -2
  58. package/dist/cli/{chunk-Y5QYWFRI.js → chunk-DRDZBRXV.js} +7 -7
  59. package/dist/cli/{chunk-JO2MQ6XR.js → chunk-EJBW7Y6Z.js} +98 -98
  60. package/dist/cli/{chunk-2EDGA7OE.mjs → chunk-ENWJFUWK.mjs} +2 -2
  61. package/dist/cli/{chunk-6XJA23MZ.js → chunk-F5D623KO.js} +26 -26
  62. package/dist/cli/{chunk-HT675XNR.mjs → chunk-FKD3KL5Q.mjs} +1 -1
  63. package/dist/cli/{chunk-2BJILUE3.js → chunk-FNHUDCJE.js} +10 -10
  64. package/dist/cli/{chunk-XU57CH42.mjs → chunk-FQQAAR3Q.mjs} +1 -1
  65. package/dist/cli/{chunk-6T2LB43P.mjs → chunk-G65FJ5JX.mjs} +2 -2
  66. package/dist/cli/{chunk-UA4MXESL.js → chunk-GMYDVW7Z.js} +3 -3
  67. package/dist/cli/{chunk-74MOIEDC.js → chunk-GVKW3LCA.js} +11 -11
  68. package/dist/cli/{chunk-D5VTWJ7K.js → chunk-ISUUSSS4.js} +16 -16
  69. package/dist/cli/{chunk-KTAOVRXT.js → chunk-KMBF3N2Z.js} +16 -16
  70. package/dist/cli/{chunk-5TEXJM6F.mjs → chunk-LFSOBW7E.mjs} +11 -11
  71. package/dist/cli/{chunk-A5VR463F.mjs → chunk-MD524MRB.mjs} +1 -1
  72. package/dist/cli/{chunk-NPRSGUHB.mjs → chunk-NDNG3MAT.mjs} +5 -5
  73. package/dist/cli/{chunk-NWSKBWQM.mjs → chunk-OAQIVJFY.mjs} +2 -2
  74. package/dist/cli/{chunk-6VY2SJ6B.mjs → chunk-PDLRUZ42.mjs} +5 -5
  75. package/dist/cli/{chunk-M6YHS5V7.mjs → chunk-RDJTCW3I.mjs} +3 -3
  76. package/dist/cli/{chunk-3YHS4BLB.js → chunk-RI672VNY.js} +2 -2
  77. package/dist/cli/{chunk-TQTQ3YYA.mjs → chunk-RKE5YTHY.mjs} +5 -5
  78. package/dist/cli/{chunk-SHB2BNI6.mjs → chunk-SFMCKB57.mjs} +37 -90
  79. package/dist/cli/{chunk-BMCRTI6Z.mjs → chunk-UBKA33KY.mjs} +1 -22
  80. package/dist/cli/{chunk-6GI7BYSL.mjs → chunk-UV6XCHOZ.mjs} +1 -1
  81. package/dist/cli/{chunk-U5646OVV.mjs → chunk-VFCVH2LV.mjs} +5 -5
  82. package/dist/cli/{chunk-7QAX5VBT.js → chunk-VIM6I7RC.js} +41 -41
  83. package/dist/cli/{chunk-WSGXBROE.js → chunk-XDVT3GOM.js} +1 -22
  84. package/dist/cli/{chunk-KCISDDNK.mjs → chunk-XR6TN5DT.mjs} +6 -6
  85. package/dist/cli/{chunk-XXDY7K7F.js → chunk-XT25FX6T.js} +3 -3
  86. package/dist/cli/{chunk-ASGGZ6BI.mjs → chunk-XXY4E57R.mjs} +2 -2
  87. package/dist/cli/{chunk-YVQLXMJU.mjs → chunk-Y3LDRCMB.mjs} +3 -3
  88. package/dist/cli/{chunk-5ECMRQCL.js → chunk-ZUAKRBZB.js} +1 -1
  89. package/dist/cli/{chunk-DQQ6FDE6.mjs → chunk-ZZ7U4YJS.mjs} +1 -1
  90. package/dist/cli/{chunk-LYIJ3YUP.js → chunk-ZZLZCO6Y.js} +22 -22
  91. package/dist/cli/{csv-VJNR6FOZ.js → csv-3HIE4VCO.js} +13 -13
  92. package/dist/cli/{csv-T7HIELZ2.mjs → csv-PE35WGRO.mjs} +4 -4
  93. package/dist/cli/{db-OE2EXZXL.mjs → db-L7ZMMQKW.mjs} +8 -8
  94. package/dist/cli/{db-JF2I54V7.js → db-O2YRTTDO.js} +29 -29
  95. package/dist/cli/describe-EB336DAO.js +50 -0
  96. package/dist/cli/{describe-HXZZC3LC.mjs → describe-NI324Y2M.mjs} +20 -20
  97. package/dist/cli/describe-core.d.mts +2 -2
  98. package/dist/cli/describe-core.d.ts +2 -2
  99. package/dist/cli/{executions-4BXRIJFF.mjs → executions-T6KU2OKK.mjs} +8 -8
  100. package/dist/cli/{executions-UQ2H6MJZ.js → executions-VH4DKLFI.js} +10 -10
  101. package/dist/cli/{feedback-TXF5CQKA.mjs → feedback-SCSJC3FX.mjs} +5 -5
  102. package/dist/cli/{feedback-MKFN7DYY.js → feedback-ZLC6G5OK.js} +10 -10
  103. package/dist/cli/git-23T7TXAH.js +25 -0
  104. package/dist/cli/{git-MG3NAV65.mjs → git-I4LVQCID.mjs} +5 -5
  105. package/dist/cli/index.js +141 -141
  106. package/dist/cli/index.mjs +43 -43
  107. package/dist/cli/{legacy-noops-XSDY46XD.mjs → legacy-noops-44FQ2256.mjs} +6 -6
  108. package/dist/cli/{legacy-noops-R76I2OWW.js → legacy-noops-UPFWEHPG.js} +9 -9
  109. package/dist/cli/{monitors-FS3DIDM7.js → monitors-JN6IQGK6.js} +102 -102
  110. package/dist/cli/{monitors-NVT5YQKV.mjs → monitors-LMSASWXE.mjs} +9 -9
  111. package/dist/cli/{org-SBI6FC6D.js → org-F7O3ZU5O.js} +74 -74
  112. package/dist/cli/{org-XU7JONWS.mjs → org-QYLVEE7A.mjs} +8 -8
  113. package/dist/cli/{pages-AFB5DVBR.mjs → pages-5XE4LBZN.mjs} +8 -8
  114. package/dist/cli/{pages-2CZFJJV6.js → pages-KEL3Y4L4.js} +20 -20
  115. package/dist/cli/{play-EQEIT5S4.mjs → play-MWQG3G32.mjs} +21 -21
  116. package/dist/cli/{play-WZH72UGC.js → play-OURHH6KV.js} +338 -338
  117. package/dist/cli/{providers-3VXTATHF.mjs → providers-IQY7LUBB.mjs} +8 -8
  118. package/dist/cli/{providers-SHSVUQA3.js → providers-ZCBWPE3C.js} +11 -11
  119. package/dist/cli/{quickstart-45YS4SOD.mjs → quickstart-L45NGRMI.mjs} +4 -4
  120. package/dist/cli/{quickstart-KPVPK3VL.js → quickstart-O53OXTN6.js} +6 -6
  121. package/dist/cli/{run-XEHRZT57.mjs → run-VCSIWLEU.mjs} +25 -25
  122. package/dist/cli/{run-U5RWBX5J.js → run-W745Z3Z5.js} +43 -43
  123. package/dist/cli/run-identity-G257GQED.js +25 -0
  124. package/dist/cli/{run-identity-MNRZS2N3.mjs → run-identity-MRNCEGV2.mjs} +3 -9
  125. package/dist/cli/search-R6K7ZAMU.js +33 -0
  126. package/dist/cli/{search-V7XIWBQ2.mjs → search-THELKULN.mjs} +10 -10
  127. package/dist/cli/{search-output-3KAJUV2A.mjs → search-output-N7MJLYYD.mjs} +4 -4
  128. package/dist/cli/{search-output-ZNIICV5Z.js → search-output-SJW7LEOM.js} +6 -6
  129. package/dist/cli/{secrets-SCSG3QXJ.mjs → secrets-44ST3FJH.mjs} +8 -8
  130. package/dist/cli/{secrets-53TUV6JK.js → secrets-GDXPX3KB.js} +17 -17
  131. package/dist/cli/sessions-2V5ZFOWL.js +18 -0
  132. package/dist/cli/{sessions-MCTHLLK3.mjs → sessions-LYCBI77S.mjs} +6 -6
  133. package/dist/cli/{settings-ZNOXOIX2.js → settings-3WOFF642.js} +88 -88
  134. package/dist/cli/{settings-Q2HKACSE.mjs → settings-GXPDMJFG.mjs} +15 -15
  135. package/dist/cli/{setup-GO4EULLY.js → setup-YHLMBJP4.js} +50 -50
  136. package/dist/cli/{setup-WKM35SZJ.mjs → setup-YM6JEB64.mjs} +10 -10
  137. package/dist/cli/{skills-DZZLW6OV.mjs → skills-WX4XWEAT.mjs} +8 -8
  138. package/dist/cli/skills-XNGADDO6.js +37 -0
  139. package/dist/cli/{tools-EKVSK6X4.mjs → tools-K24VSQ7S.mjs} +19 -19
  140. package/dist/cli/tools-ROUMCB7B.js +57 -0
  141. package/dist/cli/{update-FPHYVHSC.mjs → update-PSSCF5AT.mjs} +10 -10
  142. package/dist/cli/update-RXURGIRW.js +35 -0
  143. package/dist/cli/{workflow-5YAZK5EI.mjs → workflow-DGOPYATO.mjs} +9 -9
  144. package/dist/cli/{workflow-27H3NCNY.js → workflow-FPVI3NIA.js} +19 -19
  145. package/dist/{client-DhEOE19l.d.ts → client-B-2Am2y6.d.ts} +1 -1
  146. package/dist/{client-lJmz2QwF.d.mts → client-DA71-2_u.d.mts} +1 -1
  147. package/dist/{client-core-BGiSMrBD.d.mts → client-core-BXbds1cb.d.mts} +0 -19
  148. package/dist/{client-core-DYCGaRBZ.d.ts → client-core-C0IzDKMJ.d.ts} +0 -19
  149. package/dist/index.d.mts +3 -3
  150. package/dist/index.d.ts +3 -3
  151. package/dist/index.js +19 -19
  152. package/dist/index.mjs +8 -8
  153. package/dist/install-integrity.json +114 -122
  154. package/dist/plays/play-description.d.mts +1 -1
  155. package/dist/plays/play-description.d.ts +1 -1
  156. package/dist/plays/run-request.d.mts +1 -1
  157. package/dist/plays/run-request.d.ts +1 -1
  158. package/dist/plays/run-request.js +3 -3
  159. package/dist/plays/run-request.mjs +2 -2
  160. package/dist/release.d.mts +1 -1
  161. package/dist/release.d.ts +1 -1
  162. package/dist/release.js +2 -2
  163. package/dist/release.mjs +1 -1
  164. package/dist/server.d.mts +2 -2
  165. package/dist/server.d.ts +2 -2
  166. package/dist/server.js +7 -7
  167. package/dist/server.mjs +5 -5
  168. package/package.json +1 -1
  169. package/dist/bundling-sources/shared_libs/play-runtime/runtime-app-transport.ts +0 -374
  170. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-egress.ts +0 -55
  171. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-profile.ts +0 -329
  172. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-sandbox-credential.ts +0 -338
  173. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-staging.ts +0 -417
  174. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-attempt.ts +0 -81
  175. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-staging-journal.ts +0 -708
  176. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-staging-teardown.ts +0 -160
  177. package/dist/cli/auth-TH4JV6BH.js +0 -43
  178. package/dist/cli/describe-4FLGKRCA.js +0 -50
  179. package/dist/cli/git-B2QO3SLK.js +0 -25
  180. package/dist/cli/run-identity-HFYABUJS.js +0 -31
  181. package/dist/cli/search-Z2V43OPM.js +0 -33
  182. package/dist/cli/sessions-BOJCVLR7.js +0 -18
  183. package/dist/cli/skills-B4BAH2B2.js +0 -37
  184. package/dist/cli/tools-Z5NCKIAB.js +0 -57
  185. package/dist/cli/update-XCL7F5T6.js +0 -35
@@ -1,417 +0,0 @@
1
- import { isRuntimeScopeRunId } from './run-identity';
2
- import { RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES } from './output-size-limits';
3
-
4
- /**
5
- * Staged bodies for app-hosted Runtime gateways (profile `vercel_app@1`).
6
- *
7
- * Vercel functions accept and return at most ~4.5 MB per body, while the Fly
8
- * gateway contract is 16 MiB per request (one legal 10 MiB receipt plus its
9
- * envelope) and 16 MiB per runtime response. A pinned sandbox moves any body
10
- * above the inline ceiling through object storage instead:
11
- *
12
- * - Request: the sandbox asks the gateway for a staged upload (size and
13
- * SHA-256 only). The gateway persists the upload's custody row, then returns
14
- * a create-once presigned PUT for one exact key under the run's
15
- * org/run/attempt prefix. The sandbox uploads, then sends the original
16
- * request with an empty body and the upload id. The gateway reads the
17
- * object with its own credentials, checks length and SHA-256, and only then
18
- * hands the bytes to the same gateway code the Fly gateway runs.
19
- * - Response: when the sandbox advertises staging, a response above the
20
- * inline ceiling is written to the same prefix after its custody row
21
- * exists, and the sandbox receives a short-lived presigned GET plus the
22
- * expected length and SHA-256.
23
- *
24
- * Unpinned runs never reach this code: only the pinned sandbox credential
25
- * wrapper and the app-hosted gateway routes use it.
26
- */
27
-
28
- /** Bodies up to this size travel inline; Vercel's ceiling is ~4.5 MB. */
29
- export const RUNTIME_GATEWAY_STAGING_INLINE_MAX_BYTES = 4 * 1024 * 1024;
30
- /** Same request ceiling as the Fly gateway (`EXECUTION_GATEWAY_MAX_BODY_BYTES`). */
31
- export const RUNTIME_GATEWAY_STAGED_REQUEST_MAX_BYTES =
32
- RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES;
33
- /** Same decoded-response budget the runtime client applies to a Fly gateway. */
34
- export const RUNTIME_GATEWAY_STAGED_RESPONSE_MAX_BYTES =
35
- RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES;
36
- /** Lifetime of one presigned PUT or GET. Never above 15 minutes. */
37
- export const RUNTIME_GATEWAY_STAGING_GRANT_TTL_SECONDS = 10 * 60;
38
- export const RUNTIME_GATEWAY_STAGING_GRANT_MAX_TTL_SECONDS = 15 * 60;
39
- /**
40
- * A staged object is retired only after its grant expired and any gateway
41
- * invocation that could still be reading it (maxDuration 900 s) has ended. A
42
- * create-once PUT URL can recreate a deleted key until it expires, so the
43
- * final delete and its absence readback happen after this point.
44
- */
45
- export const RUNTIME_GATEWAY_STAGING_RETIRE_GRACE_SECONDS = 15 * 60;
46
-
47
- /**
48
- * Per-attempt deadline for one staged send (reserve, PUT, gateway call):
49
- * the 10 s inline deadline plus 2 s per started MiB (a conservative
50
- * 512 KiB/s upload), capped at 45 s. A 16 MiB body gets 42 s instead of
51
- * being cut at 10 s; an inline-size body keeps 10 s.
52
- *
53
- * Self-contained on purpose: the crash terminal pusher embeds its source.
54
- */
55
- export function runtimeGatewayStagedSendTimeoutMs(byteLength: number): number {
56
- const baseMs = 10_000;
57
- const perMibMs = 2_000;
58
- const maxMs = 45_000;
59
- if (!Number.isFinite(byteLength) || byteLength <= 0) return baseMs;
60
- return Math.min(
61
- maxMs,
62
- baseMs + Math.ceil(byteLength / (1024 * 1024)) * perMibMs,
63
- );
64
- }
65
-
66
- /** Path below the profile's receipt or execution prefix. */
67
- export const RUNTIME_GATEWAY_STAGED_UPLOAD_PATH = '/staged-uploads';
68
- /** Request header: the sandbox can stage bodies and read staged responses. */
69
- export const RUNTIME_GATEWAY_STAGING_HEADER = 'x-deepline-runtime-staging';
70
- /** Request header: the body of this request is the named staged upload. */
71
- export const RUNTIME_GATEWAY_STAGED_BODY_HEADER =
72
- 'x-deepline-runtime-staged-body';
73
- /** Response header: the body is a staged-response descriptor. */
74
- export const RUNTIME_GATEWAY_STAGED_RESPONSE_HEADER =
75
- 'x-deepline-runtime-staged-response';
76
- /** Every key lives below `<prefix>/<org>/<run>/<attempt>/`. */
77
- export const RUNTIME_GATEWAY_STAGING_KEY_PREFIX = 'runtime-gateway-staging/v1';
78
-
79
- export const RUNTIME_GATEWAY_STAGING_ERROR_CODES = {
80
- /** The custody journal table is absent: staging cannot run. Not retryable. */
81
- journalMissing: 'runtime_gateway_staging_journal_missing',
82
- /** Object storage gave no definite answer. Retry with a fresh upload. */
83
- retryable: 'runtime_gateway_staging_retryable',
84
- /** The sandbox's direct PUT or GET did not succeed. Retryable. */
85
- transferFailed: 'runtime_gateway_staging_transfer_failed',
86
- /** Staged bytes differ from the declared length or SHA-256. Retryable. */
87
- integrityMismatch: 'runtime_gateway_staging_integrity_mismatch',
88
- /** The upload id is unknown for this run attempt, or already used. */
89
- uploadUnusable: 'runtime_gateway_staging_upload_unusable',
90
- /** Body above the Fly-parity ceiling. */
91
- requestTooLarge: 'runtime_gateway_request_too_large',
92
- responseTooLarge: 'runtime_gateway_response_too_large',
93
- invalidRequest: 'runtime_gateway_staging_invalid_request',
94
- } as const;
95
-
96
- export type RuntimeGatewayStagingErrorCode =
97
- (typeof RUNTIME_GATEWAY_STAGING_ERROR_CODES)[keyof typeof RUNTIME_GATEWAY_STAGING_ERROR_CODES];
98
-
99
- export type RuntimeGatewayStagingDirection = 'request' | 'response';
100
-
101
- export type RuntimeGatewayStagingScope = Readonly<{
102
- orgId: string;
103
- runId: string;
104
- attempt: number;
105
- }>;
106
-
107
- const SCOPE_ID_PATTERN = /^[A-Za-z0-9_.:@-]{1,256}$/;
108
- const UPLOAD_ID_PATTERN =
109
- /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
110
- const SHA256_PATTERN = /^[0-9a-f]{64}$/;
111
-
112
- export function isRuntimeGatewayStagingUploadId(
113
- value: unknown,
114
- ): value is string {
115
- return typeof value === 'string' && UPLOAD_ID_PATTERN.test(value);
116
- }
117
-
118
- export function isRuntimeGatewayStagingSha256(value: unknown): value is string {
119
- return typeof value === 'string' && SHA256_PATTERN.test(value);
120
- }
121
-
122
- export function assertRuntimeGatewayStagingScope(
123
- scope: RuntimeGatewayStagingScope,
124
- ): void {
125
- if (
126
- !SCOPE_ID_PATTERN.test(scope.orgId) ||
127
- // Run ids are path-shaped (`play/<name>/run/<id>`). The object key
128
- // percent-encodes the run id into one segment, so `/` cannot add a level.
129
- !isRuntimeScopeRunId(scope.runId) ||
130
- !Number.isSafeInteger(scope.attempt) ||
131
- scope.attempt < 0
132
- ) {
133
- throw new Error('Runtime gateway staging scope is invalid.');
134
- }
135
- }
136
-
137
- /** The one object key for an upload. Built from the authenticated scope only. */
138
- export function runtimeGatewayStagingObjectKey(
139
- scope: RuntimeGatewayStagingScope,
140
- direction: RuntimeGatewayStagingDirection,
141
- uploadId: string,
142
- ): string {
143
- assertRuntimeGatewayStagingScope(scope);
144
- if (!isRuntimeGatewayStagingUploadId(uploadId)) {
145
- throw new Error('Runtime gateway staging upload id is invalid.');
146
- }
147
- return [
148
- RUNTIME_GATEWAY_STAGING_KEY_PREFIX,
149
- encodeURIComponent(scope.orgId),
150
- encodeURIComponent(scope.runId),
151
- String(scope.attempt),
152
- direction,
153
- uploadId,
154
- ].join('/');
155
- }
156
-
157
- /** Bounds a presigned grant lifetime to the 15-minute ceiling. */
158
- export function assertRuntimeGatewayStagingGrantTtl(seconds: number): void {
159
- if (
160
- !Number.isSafeInteger(seconds) ||
161
- seconds < 1 ||
162
- seconds > RUNTIME_GATEWAY_STAGING_GRANT_MAX_TTL_SECONDS
163
- ) {
164
- throw new Error(
165
- `Runtime gateway staging grant lifetime must be 1-${RUNTIME_GATEWAY_STAGING_GRANT_MAX_TTL_SECONDS} seconds.`,
166
- );
167
- }
168
- }
169
-
170
- /** Limits a sandbox client applies; passed in so the client stays self-contained. */
171
- export type RuntimeGatewayStagingClientLimits = Readonly<{
172
- inlineMaxBytes: number;
173
- requestMaxBytes: number;
174
- responseMaxBytes: number;
175
- pathPrefixes: readonly string[];
176
- }>;
177
-
178
- export function runtimeGatewayStagingClientLimits(
179
- pathPrefixes: readonly string[],
180
- ): RuntimeGatewayStagingClientLimits {
181
- return Object.freeze({
182
- inlineMaxBytes: RUNTIME_GATEWAY_STAGING_INLINE_MAX_BYTES,
183
- requestMaxBytes: RUNTIME_GATEWAY_STAGED_REQUEST_MAX_BYTES,
184
- responseMaxBytes: RUNTIME_GATEWAY_STAGED_RESPONSE_MAX_BYTES,
185
- pathPrefixes: Object.freeze([...pathPrefixes]),
186
- });
187
- }
188
-
189
- /**
190
- * Send one code-owned request to a pinned app-hosted gateway, staging an
191
- * oversize body and resolving a staged response.
192
- *
193
- * `init.headers` must already carry the run's executor token and gateway
194
- * credential; they are copied onto the reserve call only. Object-storage
195
- * calls carry no Deepline credential at all. Every failure is returned as a
196
- * gateway-shaped JSON response with a named `code`: transfer failures use
197
- * 503 so existing runtime retry ladders retry them with a fresh upload, and a
198
- * missing custody journal stays non-retryable.
199
- *
200
- * Self-contained on purpose: the crash terminal pusher embeds this
201
- * function's source, so it must not reference imports, module state, or
202
- * nested named functions.
203
- */
204
- export async function runtimeGatewayStagedSend(
205
- send: typeof fetch,
206
- target: string,
207
- init: RequestInit,
208
- limits: RuntimeGatewayStagingClientLimits,
209
- ): Promise<Response> {
210
- const headers = new Headers(init.headers);
211
- headers.set('x-deepline-runtime-staging', '1');
212
- const body = init.body;
213
- let bytes: Uint8Array | null = null;
214
- if (typeof body === 'string') bytes = new TextEncoder().encode(body);
215
- else if (body instanceof Uint8Array) bytes = body;
216
- else if (body instanceof ArrayBuffer) bytes = new Uint8Array(body);
217
- let sendInit: RequestInit = { ...init, headers };
218
- if (bytes && bytes.byteLength > limits.inlineMaxBytes) {
219
- if (bytes.byteLength > limits.requestMaxBytes) {
220
- return Response.json(
221
- {
222
- error: 'Execution gateway request body is too large.',
223
- code: 'runtime_gateway_request_too_large',
224
- },
225
- { status: 413 },
226
- );
227
- }
228
- const url = new URL(target);
229
- const prefix = limits.pathPrefixes.find(
230
- (candidate) =>
231
- url.pathname === candidate || url.pathname.startsWith(candidate + '/'),
232
- );
233
- if (!prefix) {
234
- return Response.json(
235
- {
236
- error: 'Runtime gateway staging target is outside the gateway.',
237
- code: 'runtime_gateway_staging_invalid_request',
238
- },
239
- { status: 400 },
240
- );
241
- }
242
- const digest = await crypto.subtle.digest(
243
- 'SHA-256',
244
- bytes as Uint8Array<ArrayBuffer>,
245
- );
246
- const sha256 = Array.from(new Uint8Array(digest), (byte) =>
247
- byte.toString(16).padStart(2, '0'),
248
- ).join('');
249
- const reserveHeaders = new Headers(headers);
250
- reserveHeaders.delete('content-length');
251
- reserveHeaders.delete('content-encoding');
252
- reserveHeaders.set('content-type', 'application/json');
253
- const reserved = await send(url.origin + prefix + '/staged-uploads', {
254
- method: 'POST',
255
- headers: reserveHeaders,
256
- body: JSON.stringify({ byteLength: bytes.byteLength, sha256 }),
257
- redirect: 'manual',
258
- signal: init.signal,
259
- });
260
- // Refusals (journal missing, too large, capacity) reach the caller as the
261
- // gateway stated them.
262
- if (!reserved.ok) return reserved;
263
- const grant = (await reserved.json().catch(() => null)) as {
264
- uploadId?: unknown;
265
- url?: unknown;
266
- headers?: unknown;
267
- } | null;
268
- let putUrl: URL | null = null;
269
- try {
270
- putUrl = new URL(String(grant?.url));
271
- } catch {
272
- putUrl = null;
273
- }
274
- if (
275
- !grant ||
276
- typeof grant.uploadId !== 'string' ||
277
- !putUrl ||
278
- putUrl.protocol !== 'https:' ||
279
- putUrl.origin === url.origin ||
280
- !grant.headers ||
281
- typeof grant.headers !== 'object'
282
- ) {
283
- return Response.json(
284
- {
285
- error: 'Runtime gateway returned an unusable staged upload grant.',
286
- code: 'runtime_gateway_staging_transfer_failed',
287
- },
288
- { status: 503 },
289
- );
290
- }
291
- let putStatus = 0;
292
- try {
293
- const put = await send(putUrl.href, {
294
- method: 'PUT',
295
- headers: grant.headers as Record<string, string>,
296
- body: bytes as Uint8Array<ArrayBuffer>,
297
- redirect: 'manual',
298
- signal: init.signal,
299
- });
300
- putStatus = put.status;
301
- await put.text().catch(() => '');
302
- } catch (error) {
303
- if (init.signal?.aborted) throw error;
304
- putStatus = 0;
305
- }
306
- // 412: an earlier delivery of this exact create-once PUT already landed;
307
- // the gateway verifies the stored bytes before using them.
308
- if (!(putStatus >= 200 && putStatus < 300) && putStatus !== 412) {
309
- return Response.json(
310
- {
311
- error: `Runtime gateway staged upload did not reach object storage (status ${putStatus}).`,
312
- code: 'runtime_gateway_staging_transfer_failed',
313
- retry_after_ms: 1000,
314
- },
315
- { status: 503 },
316
- );
317
- }
318
- const stagedHeaders = new Headers(headers);
319
- stagedHeaders.delete('content-length');
320
- stagedHeaders.set('x-deepline-runtime-staged-body', grant.uploadId);
321
- sendInit = { ...init, headers: stagedHeaders, body: null };
322
- }
323
- const response = await send(target, sendInit);
324
- if (response.headers.get('x-deepline-runtime-staged-response') !== '1') {
325
- return response;
326
- }
327
- const descriptor = (await response.json().catch(() => null)) as {
328
- url?: unknown;
329
- sha256?: unknown;
330
- byteLength?: unknown;
331
- status?: unknown;
332
- headers?: unknown;
333
- } | null;
334
- let getUrl: URL | null = null;
335
- try {
336
- getUrl = new URL(String(descriptor?.url));
337
- } catch {
338
- getUrl = null;
339
- }
340
- if (
341
- !descriptor ||
342
- !getUrl ||
343
- getUrl.protocol !== 'https:' ||
344
- getUrl.origin === new URL(target).origin ||
345
- typeof descriptor.sha256 !== 'string' ||
346
- typeof descriptor.byteLength !== 'number' ||
347
- !Number.isSafeInteger(descriptor.byteLength) ||
348
- descriptor.byteLength < 0 ||
349
- typeof descriptor.status !== 'number' ||
350
- !descriptor.headers ||
351
- typeof descriptor.headers !== 'object'
352
- ) {
353
- return Response.json(
354
- {
355
- error: 'Runtime gateway returned an unusable staged response.',
356
- code: 'runtime_gateway_staging_transfer_failed',
357
- },
358
- { status: 503 },
359
- );
360
- }
361
- if (descriptor.byteLength > limits.responseMaxBytes) {
362
- return Response.json(
363
- {
364
- error: 'Runtime gateway staged response is too large.',
365
- code: 'runtime_gateway_response_too_large',
366
- },
367
- { status: 502 },
368
- );
369
- }
370
- let staged: Uint8Array | null = null;
371
- try {
372
- const download = await send(getUrl.href, {
373
- method: 'GET',
374
- redirect: 'manual',
375
- signal: init.signal,
376
- });
377
- if (download.ok) staged = new Uint8Array(await download.arrayBuffer());
378
- else await download.text().catch(() => '');
379
- } catch (error) {
380
- if (init.signal?.aborted) throw error;
381
- staged = null;
382
- }
383
- if (!staged) {
384
- return Response.json(
385
- {
386
- error: 'Runtime gateway staged response could not be downloaded.',
387
- code: 'runtime_gateway_staging_transfer_failed',
388
- retry_after_ms: 1000,
389
- },
390
- { status: 503 },
391
- );
392
- }
393
- const stagedDigest = await crypto.subtle.digest(
394
- 'SHA-256',
395
- staged as Uint8Array<ArrayBuffer>,
396
- );
397
- const stagedSha256 = Array.from(new Uint8Array(stagedDigest), (byte) =>
398
- byte.toString(16).padStart(2, '0'),
399
- ).join('');
400
- if (
401
- staged.byteLength !== descriptor.byteLength ||
402
- stagedSha256 !== descriptor.sha256
403
- ) {
404
- return Response.json(
405
- {
406
- error: 'Runtime gateway staged response failed its integrity check.',
407
- code: 'runtime_gateway_staging_integrity_mismatch',
408
- retry_after_ms: 1000,
409
- },
410
- { status: 503 },
411
- );
412
- }
413
- return new Response(staged as Uint8Array<ArrayBuffer>, {
414
- status: descriptor.status,
415
- headers: descriptor.headers as Record<string, string>,
416
- });
417
- }
@@ -1,81 +0,0 @@
1
- import {
2
- mintRuntimeGatewayAttemptOidcToken,
3
- readExecutorTokenClaimsUnverified,
4
- } from '../runtime-app-transport';
5
- import {
6
- assertRuntimeGatewayPinFresh,
7
- readRuntimeGatewayLaunchPin,
8
- RuntimeGatewayLaunchError,
9
- type RuntimeGatewayLaunchFields,
10
- type RuntimeGatewayLaunchPin,
11
- } from '../runtime-gateway-profile';
12
- import type { RuntimeGatewayOidcSigningKey } from '../runtime-gateway-oidc';
13
-
14
- /**
15
- * Worker-side checks for a pinned launch. Every function is a no-op (null)
16
- * for unpinned launches, so the default path is unchanged.
17
- */
18
-
19
- /** Attempt start / resume: refuse an expired or unreadable pin loudly. */
20
- export function assertRuntimeGatewayAttemptStartable(
21
- launch: RuntimeGatewayLaunchFields,
22
- nowMs: number,
23
- ): RuntimeGatewayLaunchPin | null {
24
- const pin = readRuntimeGatewayLaunchPin(launch);
25
- if (pin) assertRuntimeGatewayPinFresh(pin, nowMs);
26
- return pin;
27
- }
28
-
29
- /**
30
- * The app minted the primary executor token. For a pinned launch it must
31
- * carry `runtime_gateway_deployment_id` equal to the pin; an older app that
32
- * ignored the pin would otherwise hand the sandbox a token the pinned gateway
33
- * refuses, or quietly route the run elsewhere. The signature is verified by
34
- * the gateway on use; here only the claim's presence and value are checked.
35
- */
36
- export function assertExecutorTokenCarriesRuntimeGatewayPin(
37
- executorToken: string,
38
- pin: RuntimeGatewayLaunchPin,
39
- ): void {
40
- const claims = readExecutorTokenClaimsUnverified(executorToken);
41
- if (
42
- claims?.runtime_gateway_deployment_id !== pin.deploymentId ||
43
- claims?.runtime_gateway_profile !== pin.profile.id
44
- ) {
45
- throw new RuntimeGatewayLaunchError(
46
- 'runtime_gateway_executor_token_unpinned',
47
- `The executor token for a launch pinned to ${pin.deploymentId} (${pin.profile.id}) does not carry the matching runtime gateway claims; the issuing app does not support Runtime gateway profiles.`,
48
- );
49
- }
50
- }
51
-
52
- /**
53
- * The runner config a sandbox launch receives. Unpinned launches return the
54
- * same object. Pinned launches re-check pin age and carry a fresh credential.
55
- */
56
- export function withRuntimeGatewayAttemptCredential<
57
- T extends { context: { runtimeGatewayOidcToken?: string | null } },
58
- >(input: {
59
- config: T;
60
- launch: RuntimeGatewayLaunchFields;
61
- runId: string;
62
- attempt: number;
63
- nowMs: number;
64
- signingKey: () => RuntimeGatewayOidcSigningKey | null;
65
- }): T {
66
- const pin = assertRuntimeGatewayAttemptStartable(input.launch, input.nowMs);
67
- if (!pin) return input.config;
68
- return {
69
- ...input.config,
70
- context: {
71
- ...input.config.context,
72
- runtimeGatewayOidcToken: mintRuntimeGatewayAttemptOidcToken({
73
- pin,
74
- runId: input.runId,
75
- attempt: input.attempt,
76
- nowMs: input.nowMs,
77
- signingKey: input.signingKey(),
78
- }),
79
- },
80
- } as T;
81
- }