deepline 0.3.520 → 0.3.521

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 (184) 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/fixture-behavior.ts +24 -0
  6. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +1 -54
  7. package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +2 -7
  8. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +0 -13
  9. package/dist/bundling-sources/shared_libs/play-runtime/run-identity.ts +0 -56
  10. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +10 -21
  11. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-heartbeat.ts +1 -1
  12. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-progress-push.ts +2 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +1 -1
  14. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +2 -37
  15. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +3 -74
  16. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-runtime-watchdog.ts +2 -226
  17. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +3 -36
  18. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api-paths.ts +0 -26
  19. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +1 -9
  20. package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +0 -5
  21. package/dist/bundling-sources/shared_libs/play-runtime/runtime-environment.ts +9 -49
  22. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-oidc.ts +11 -447
  23. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +5 -4
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +12 -207
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +3 -17
  26. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-progress-registry.ts +0 -9
  27. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +2 -18
  28. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +15 -175
  29. package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +0 -4
  30. package/dist/cli/{artifacts-4DSPSIU5.js → artifacts-JGH464N2.js} +20 -20
  31. package/dist/cli/{artifacts-D6PU7SBC.mjs → artifacts-TYPU37IU.mjs} +8 -8
  32. package/dist/cli/auth-JWR3VSNT.js +43 -0
  33. package/dist/cli/{auth-MXKNPUXW.mjs → auth-XPQT6NUB.mjs} +5 -5
  34. package/dist/cli/{billing-SQ26NKGH.mjs → billing-47AMHOMP.mjs} +8 -8
  35. package/dist/cli/{billing-WEYCNJIR.js → billing-6D4KXBFJ.js} +81 -81
  36. package/dist/cli/{chunk-TQTQ3YYA.mjs → chunk-2DQPB5HT.mjs} +5 -5
  37. package/dist/cli/{chunk-6Y3DDRRN.js → chunk-2KHUFWTK.js} +3 -3
  38. package/dist/cli/{chunk-2BJILUE3.js → chunk-3Q7HEEH2.js} +10 -10
  39. package/dist/cli/{chunk-NWSKBWQM.mjs → chunk-4DB6JV7X.mjs} +2 -2
  40. package/dist/cli/{chunk-M6YHS5V7.mjs → chunk-4GGXAYKI.mjs} +3 -3
  41. package/dist/cli/{chunk-V6BUWQBI.mjs → chunk-4I7I5CGB.mjs} +1 -1
  42. package/dist/cli/{chunk-ORAWUIMN.js → chunk-4MN65FRF.js} +53 -53
  43. package/dist/cli/{chunk-U5646OVV.mjs → chunk-4MONKWYE.mjs} +5 -5
  44. package/dist/cli/{chunk-KKSMHTQO.mjs → chunk-5T7QKHQL.mjs} +1 -1
  45. package/dist/cli/{chunk-XXDY7K7F.js → chunk-6DCBTJZP.js} +3 -3
  46. package/dist/cli/{chunk-LUIPBI6P.js → chunk-6N72GHAV.js} +2 -2
  47. package/dist/cli/{chunk-ASGGZ6BI.mjs → chunk-6UHYXNCP.mjs} +2 -2
  48. package/dist/cli/{chunk-YVQLXMJU.mjs → chunk-6V2RI3AL.mjs} +3 -3
  49. package/dist/cli/{chunk-6GI7BYSL.mjs → chunk-7AUXX6M5.mjs} +1 -1
  50. package/dist/cli/{chunk-6T2LB43P.mjs → chunk-7IYDCHTG.mjs} +2 -2
  51. package/dist/cli/{chunk-NNUJQ5O2.mjs → chunk-7LRALARF.mjs} +1 -1
  52. package/dist/cli/{chunk-5TEXJM6F.mjs → chunk-A2B5AAU3.mjs} +11 -11
  53. package/dist/cli/{chunk-NLIO6QLP.mjs → chunk-A6USUS4L.mjs} +2 -2
  54. package/dist/cli/{chunk-3YHS4BLB.js → chunk-AMVKLEPH.js} +2 -2
  55. package/dist/cli/{chunk-YP3G2CP6.mjs → chunk-CBBCUYIN.mjs} +2 -2
  56. package/dist/cli/{chunk-QQGRQRCS.mjs → chunk-DQURY3WH.mjs} +1 -1
  57. package/dist/cli/{chunk-7VJKHJY7.js → chunk-DY6634MN.js} +14 -14
  58. package/dist/cli/{chunk-XU57CH42.mjs → chunk-E4ZS2B2J.mjs} +1 -1
  59. package/dist/cli/{chunk-UA4MXESL.js → chunk-EILHJRPW.js} +3 -3
  60. package/dist/cli/{chunk-AM7HMWNA.js → chunk-EW3EAEWZ.js} +5 -5
  61. package/dist/cli/{chunk-NPRSGUHB.mjs → chunk-EZNZDOAG.mjs} +5 -5
  62. package/dist/cli/{chunk-HT675XNR.mjs → chunk-FKD3KL5Q.mjs} +1 -1
  63. package/dist/cli/{chunk-SHB2BNI6.mjs → chunk-FQJFONFT.mjs} +37 -90
  64. package/dist/cli/{chunk-FWGTBR3W.js → chunk-FTZX4QZN.js} +2 -2
  65. package/dist/cli/{chunk-5ECMRQCL.js → chunk-GNYSODBR.js} +1 -1
  66. package/dist/cli/{chunk-Y5QYWFRI.js → chunk-HD3KYCDC.js} +7 -7
  67. package/dist/cli/{chunk-6VY2SJ6B.mjs → chunk-HHBJJYKL.mjs} +5 -5
  68. package/dist/cli/{chunk-DQQ6FDE6.mjs → chunk-HRWVEIAX.mjs} +1 -1
  69. package/dist/cli/{chunk-BHAP6FIZ.js → chunk-HSFLMTED.js} +4 -4
  70. package/dist/cli/{chunk-KTAOVRXT.js → chunk-JFQJNYTB.js} +16 -16
  71. package/dist/cli/{chunk-JO2MQ6XR.js → chunk-LGU2NIOT.js} +98 -98
  72. package/dist/cli/{chunk-QSWPDYOP.mjs → chunk-LNBMEFOI.mjs} +4 -4
  73. package/dist/cli/{chunk-GVTHFDKN.js → chunk-MD43YAL6.js} +6 -6
  74. package/dist/cli/{chunk-AVW2LKRF.js → chunk-MRU4N33M.js} +6 -6
  75. package/dist/cli/{chunk-2EDGA7OE.mjs → chunk-NNDAVVBG.mjs} +2 -2
  76. package/dist/cli/{chunk-4VR5OTYP.js → chunk-PUKWFJXW.js} +44 -44
  77. package/dist/cli/{chunk-VSPNBBRT.js → chunk-QGTWGHYD.js} +66 -119
  78. package/dist/cli/{chunk-A5VR463F.mjs → chunk-TBIWR7M2.mjs} +1 -1
  79. package/dist/cli/{chunk-I4GBCKBL.js → chunk-UAZKOH3J.js} +5 -5
  80. package/dist/cli/{chunk-BMCRTI6Z.mjs → chunk-UBKA33KY.mjs} +1 -22
  81. package/dist/cli/{chunk-6XJA23MZ.js → chunk-ULW2KBKL.js} +26 -26
  82. package/dist/cli/{chunk-D5VTWJ7K.js → chunk-VSH3AE5E.js} +16 -16
  83. package/dist/cli/{chunk-74MOIEDC.js → chunk-VYY5V4M5.js} +11 -11
  84. package/dist/cli/{chunk-YHHLLONU.js → chunk-WL6WPW6X.js} +14 -14
  85. package/dist/cli/{chunk-WSGXBROE.js → chunk-XDVT3GOM.js} +1 -22
  86. package/dist/cli/{chunk-7QAX5VBT.js → chunk-Y23TOHNV.js} +41 -41
  87. package/dist/cli/{chunk-VSLU4JZV.mjs → chunk-Y7IR4LBU.mjs} +3 -3
  88. package/dist/cli/{chunk-LYIJ3YUP.js → chunk-YROP3H6T.js} +22 -22
  89. package/dist/cli/{chunk-KCISDDNK.mjs → chunk-ZO2XJVFH.mjs} +6 -6
  90. package/dist/cli/{csv-VJNR6FOZ.js → csv-5TM2OSYP.js} +13 -13
  91. package/dist/cli/{csv-T7HIELZ2.mjs → csv-PM3WDXDF.mjs} +4 -4
  92. package/dist/cli/{db-JF2I54V7.js → db-3LJ32FZM.js} +29 -29
  93. package/dist/cli/{db-OE2EXZXL.mjs → db-5P72NPRL.mjs} +8 -8
  94. package/dist/cli/describe-GRS3IRSX.js +50 -0
  95. package/dist/cli/{describe-HXZZC3LC.mjs → describe-ZLCMBGHG.mjs} +20 -20
  96. package/dist/cli/describe-core.d.mts +2 -2
  97. package/dist/cli/describe-core.d.ts +2 -2
  98. package/dist/cli/{executions-UQ2H6MJZ.js → executions-4AJ5TQVY.js} +10 -10
  99. package/dist/cli/{executions-4BXRIJFF.mjs → executions-JMFL6AV7.mjs} +8 -8
  100. package/dist/cli/{feedback-TXF5CQKA.mjs → feedback-DKMG2QB7.mjs} +5 -5
  101. package/dist/cli/{feedback-MKFN7DYY.js → feedback-I2BLXMGH.js} +10 -10
  102. package/dist/cli/git-2LNT43A2.js +25 -0
  103. package/dist/cli/{git-MG3NAV65.mjs → git-ARG223MY.mjs} +5 -5
  104. package/dist/cli/index.js +141 -141
  105. package/dist/cli/index.mjs +43 -43
  106. package/dist/cli/{legacy-noops-XSDY46XD.mjs → legacy-noops-24LOAOZN.mjs} +6 -6
  107. package/dist/cli/{legacy-noops-R76I2OWW.js → legacy-noops-N7SVA7PL.js} +9 -9
  108. package/dist/cli/{monitors-NVT5YQKV.mjs → monitors-RYQFWM2T.mjs} +9 -9
  109. package/dist/cli/{monitors-FS3DIDM7.js → monitors-XNCYLOJM.js} +102 -102
  110. package/dist/cli/{org-SBI6FC6D.js → org-I33TKZXF.js} +74 -74
  111. package/dist/cli/{org-XU7JONWS.mjs → org-ORIH56E5.mjs} +8 -8
  112. package/dist/cli/{pages-2CZFJJV6.js → pages-2UXXGIMF.js} +20 -20
  113. package/dist/cli/{pages-AFB5DVBR.mjs → pages-ME43HSBL.mjs} +8 -8
  114. package/dist/cli/{play-WZH72UGC.js → play-F4QOFU37.js} +338 -338
  115. package/dist/cli/{play-EQEIT5S4.mjs → play-XEKNY46M.mjs} +21 -21
  116. package/dist/cli/{providers-SHSVUQA3.js → providers-E7DPCBNX.js} +11 -11
  117. package/dist/cli/{providers-3VXTATHF.mjs → providers-XKU44G74.mjs} +8 -8
  118. package/dist/cli/{quickstart-KPVPK3VL.js → quickstart-ICLF2F6A.js} +6 -6
  119. package/dist/cli/{quickstart-45YS4SOD.mjs → quickstart-J7NVEXV5.mjs} +4 -4
  120. package/dist/cli/{run-U5RWBX5J.js → run-HJMHUQBN.js} +43 -43
  121. package/dist/cli/{run-XEHRZT57.mjs → run-MQ5ZONGL.mjs} +25 -25
  122. package/dist/cli/run-identity-G257GQED.js +25 -0
  123. package/dist/cli/{run-identity-MNRZS2N3.mjs → run-identity-MRNCEGV2.mjs} +3 -9
  124. package/dist/cli/{search-V7XIWBQ2.mjs → search-GGRC77CV.mjs} +10 -10
  125. package/dist/cli/search-V6IBJ4TX.js +33 -0
  126. package/dist/cli/{search-output-ZNIICV5Z.js → search-output-MXZTZI2P.js} +6 -6
  127. package/dist/cli/{search-output-3KAJUV2A.mjs → search-output-NY4GDBRU.mjs} +4 -4
  128. package/dist/cli/{secrets-SCSG3QXJ.mjs → secrets-FA37G4Q2.mjs} +8 -8
  129. package/dist/cli/{secrets-53TUV6JK.js → secrets-PFESG72B.js} +17 -17
  130. package/dist/cli/{sessions-MCTHLLK3.mjs → sessions-BLLXPETU.mjs} +6 -6
  131. package/dist/cli/sessions-DNFTQOQH.js +18 -0
  132. package/dist/cli/{settings-ZNOXOIX2.js → settings-32VPG4Z2.js} +88 -88
  133. package/dist/cli/{settings-Q2HKACSE.mjs → settings-U26S7MPH.mjs} +15 -15
  134. package/dist/cli/{setup-WKM35SZJ.mjs → setup-4AXBCX7C.mjs} +10 -10
  135. package/dist/cli/{setup-GO4EULLY.js → setup-R6NSENH7.js} +50 -50
  136. package/dist/cli/skills-G4ZE3OS5.js +37 -0
  137. package/dist/cli/{skills-DZZLW6OV.mjs → skills-JUH7AVUL.mjs} +8 -8
  138. package/dist/cli/tools-27LHZFJD.js +57 -0
  139. package/dist/cli/{tools-EKVSK6X4.mjs → tools-FOYLU3FH.mjs} +19 -19
  140. package/dist/cli/{update-FPHYVHSC.mjs → update-FUVX22VM.mjs} +10 -10
  141. package/dist/cli/update-KNZ7N242.js +35 -0
  142. package/dist/cli/{workflow-27H3NCNY.js → workflow-JACZW4GJ.js} +19 -19
  143. package/dist/cli/{workflow-5YAZK5EI.mjs → workflow-QLT22BLT.mjs} +9 -9
  144. package/dist/{client-DhEOE19l.d.ts → client-B-2Am2y6.d.ts} +1 -1
  145. package/dist/{client-lJmz2QwF.d.mts → client-DA71-2_u.d.mts} +1 -1
  146. package/dist/{client-core-BGiSMrBD.d.mts → client-core-BXbds1cb.d.mts} +0 -19
  147. package/dist/{client-core-DYCGaRBZ.d.ts → client-core-C0IzDKMJ.d.ts} +0 -19
  148. package/dist/index.d.mts +3 -3
  149. package/dist/index.d.ts +3 -3
  150. package/dist/index.js +19 -19
  151. package/dist/index.mjs +8 -8
  152. package/dist/install-integrity.json +114 -122
  153. package/dist/plays/play-description.d.mts +1 -1
  154. package/dist/plays/play-description.d.ts +1 -1
  155. package/dist/plays/run-request.d.mts +1 -1
  156. package/dist/plays/run-request.d.ts +1 -1
  157. package/dist/plays/run-request.js +3 -3
  158. package/dist/plays/run-request.mjs +2 -2
  159. package/dist/release.d.mts +1 -1
  160. package/dist/release.d.ts +1 -1
  161. package/dist/release.js +2 -2
  162. package/dist/release.mjs +1 -1
  163. package/dist/server.d.mts +2 -2
  164. package/dist/server.d.ts +2 -2
  165. package/dist/server.js +7 -7
  166. package/dist/server.mjs +5 -5
  167. package/package.json +1 -1
  168. package/dist/bundling-sources/shared_libs/play-runtime/runtime-app-transport.ts +0 -374
  169. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-egress.ts +0 -55
  170. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-profile.ts +0 -329
  171. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-sandbox-credential.ts +0 -338
  172. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-staging.ts +0 -417
  173. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-attempt.ts +0 -81
  174. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-staging-journal.ts +0 -708
  175. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-gateway-staging-teardown.ts +0 -160
  176. package/dist/cli/auth-TH4JV6BH.js +0 -43
  177. package/dist/cli/describe-4FLGKRCA.js +0 -50
  178. package/dist/cli/git-B2QO3SLK.js +0 -25
  179. package/dist/cli/run-identity-HFYABUJS.js +0 -31
  180. package/dist/cli/search-Z2V43OPM.js +0 -33
  181. package/dist/cli/sessions-BOJCVLR7.js +0 -18
  182. package/dist/cli/skills-B4BAH2B2.js +0 -37
  183. package/dist/cli/tools-Z5NCKIAB.js +0 -57
  184. package/dist/cli/update-XCL7F5T6.js +0 -35
@@ -1,329 +0,0 @@
1
- import { RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES } from './output-size-limits';
2
-
3
- /**
4
- * Named, versioned Runtime gateway profiles. A profile decides where a run's
5
- * receipt and execution gateways are served. Absence keeps today's Fly
6
- * gateways. Changing what a profile means creates a new version: a queued
7
- * launch keeps the meaning it was admitted with.
8
- */
9
- export const RUNTIME_GATEWAY_PROFILE_IDS = {
10
- vercelApp: 'vercel_app@1',
11
- } as const;
12
-
13
- export type RuntimeGatewayProfileId =
14
- (typeof RUNTIME_GATEWAY_PROFILE_IDS)[keyof typeof RUNTIME_GATEWAY_PROFILE_IDS];
15
-
16
- export type RuntimeGatewayProfile = Readonly<{
17
- id: RuntimeGatewayProfileId;
18
- /** Gateways run inside the immutable app deployment that admitted the run. */
19
- hosting: 'admitting_app_deployment';
20
- receiptPath: '/api/receipt';
21
- executionPath: '/api/execution';
22
- /**
23
- * Oldest pin a new attempt or resumed sandbox may still use.
24
- *
25
- * Contract (`vercel_app@1`: 6 hours): the pin is checked only when an
26
- * attempt starts or a sandbox resumes, never while one runs, so it must
27
- * outlive the longest single attempt. A pinned run resumed or retried more
28
- * than 6 hours after it was pinned (a long durable wait, a late retry)
29
- * fails loudly with `runtime_gateway_pin_expired` instead of running on a
30
- * deployment that may be gone; the Play must be re-run. The profile is
31
- * Preview-only today. Enabling it in Production must revisit this bound
32
- * against Production wait and retry horizons.
33
- */
34
- maxPinAgeMs: number;
35
- /** Scheduler Postgres clients one gateway function instance may hold. */
36
- poolMaxClients: number;
37
- /** Same request ceiling as the Fly gateway contract. */
38
- requestBodyMaxBytes: number;
39
- }>;
40
-
41
- export const RUNTIME_GATEWAY_PROFILES: Readonly<
42
- Record<RuntimeGatewayProfileId, RuntimeGatewayProfile>
43
- > = Object.freeze({
44
- [RUNTIME_GATEWAY_PROFILE_IDS.vercelApp]: Object.freeze({
45
- id: RUNTIME_GATEWAY_PROFILE_IDS.vercelApp,
46
- hosting: 'admitting_app_deployment',
47
- receiptPath: '/api/receipt',
48
- executionPath: '/api/execution',
49
- maxPinAgeMs: 6 * 60 * 60 * 1_000,
50
- poolMaxClients: 2,
51
- requestBodyMaxBytes: RUNNER_TERMINAL_PUSH_MAX_BODY_BYTES,
52
- }),
53
- });
54
-
55
- const RUNTIME_GATEWAY_PROFILE_ID_SET: ReadonlySet<string> = new Set(
56
- Object.values(RUNTIME_GATEWAY_PROFILE_IDS),
57
- );
58
-
59
- export function normalizeRuntimeGatewayProfileId(
60
- value: unknown,
61
- ): RuntimeGatewayProfileId | undefined {
62
- if (typeof value !== 'string') return undefined;
63
- const normalized = value.trim();
64
- return RUNTIME_GATEWAY_PROFILE_ID_SET.has(normalized)
65
- ? (normalized as RuntimeGatewayProfileId)
66
- : undefined;
67
- }
68
-
69
- export function resolveRuntimeGatewayProfile(
70
- id: string,
71
- ): RuntimeGatewayProfile {
72
- const normalized = normalizeRuntimeGatewayProfileId(id);
73
- if (!normalized) {
74
- throw new RuntimeGatewayLaunchError(
75
- 'runtime_gateway_profile_unknown',
76
- `Unknown Runtime gateway profile ${JSON.stringify(id)}.`,
77
- );
78
- }
79
- return RUNTIME_GATEWAY_PROFILES[normalized];
80
- }
81
-
82
- /** Optional executor-token request field advertising pinned-launch support. */
83
- export const RUNTIME_GATEWAY_PROFILE_READER_FIELD =
84
- 'runtimeGatewayProfileReader';
85
- /** Presence flag value (the contract's `1`); never compared as a version. */
86
- export const RUNTIME_GATEWAY_PROFILE_READER_FLAG = 1;
87
- /** 409 body `error` when a pinned launch's worker does not advertise the reader. */
88
- export const RUNTIME_GATEWAY_PROFILE_READER_REQUIRED_ERROR =
89
- 'runtime_gateway_profile_reader_required';
90
-
91
- export type RuntimeGatewayLaunchErrorCode =
92
- | 'runtime_gateway_pin_expired'
93
- | 'runtime_gateway_pin_invalid'
94
- | 'runtime_gateway_profile_unknown'
95
- | typeof RUNTIME_GATEWAY_PROFILE_READER_REQUIRED_ERROR
96
- | 'runtime_gateway_executor_token_unpinned'
97
- | 'runtime_gateway_oidc_unavailable';
98
-
99
- /**
100
- * A pinned launch that cannot run on its pinned gateway. Deterministic: a
101
- * retry cannot fix it, and falling back to Fly gateways would silently drop
102
- * the pin, so callers terminalize the attempt with this code.
103
- */
104
- export class RuntimeGatewayLaunchError extends Error {
105
- constructor(
106
- readonly code: RuntimeGatewayLaunchErrorCode,
107
- message: string,
108
- ) {
109
- super(`${code}: ${message}`);
110
- this.name = 'RuntimeGatewayLaunchError';
111
- }
112
- }
113
-
114
- export function isRuntimeGatewayLaunchError(
115
- error: unknown,
116
- ): error is RuntimeGatewayLaunchError {
117
- return error instanceof RuntimeGatewayLaunchError;
118
- }
119
-
120
- /** Optional launch fields. Every one is absent on unpinned launches. */
121
- export type RuntimeGatewayLaunchFields = {
122
- runtimeGatewayProfileId?: string | null;
123
- runtimeReceiptGatewayBaseUrl?: string | null;
124
- runtimeExecutionGatewayBaseUrl?: string | null;
125
- runtimeGatewayDeploymentId?: string | null;
126
- runtimeGatewayPinnedAtMs?: number | null;
127
- };
128
-
129
- export const RUNTIME_GATEWAY_LAUNCH_FIELD_NAMES = [
130
- 'runtimeGatewayProfileId',
131
- 'runtimeReceiptGatewayBaseUrl',
132
- 'runtimeExecutionGatewayBaseUrl',
133
- 'runtimeGatewayDeploymentId',
134
- 'runtimeGatewayPinnedAtMs',
135
- ] as const satisfies readonly (keyof RuntimeGatewayLaunchFields)[];
136
-
137
- export type RuntimeGatewayLaunchPin = Readonly<{
138
- profile: RuntimeGatewayProfile;
139
- deploymentId: string;
140
- /** `https://<immutable deployment host>` with no path. */
141
- origin: string;
142
- receiptGatewayBaseUrl: string;
143
- executionGatewayBaseUrl: string;
144
- pinnedAtMs: number;
145
- }>;
146
-
147
- const VERCEL_DEPLOYMENT_ID_PATTERN = /^dpl_[A-Za-z0-9]+$/;
148
-
149
- export function isRuntimeGatewayDeploymentId(value: unknown): value is string {
150
- return typeof value === 'string' && VERCEL_DEPLOYMENT_ID_PATTERN.test(value);
151
- }
152
-
153
- function deploymentOrigin(host: string): string {
154
- const trimmed = host.trim();
155
- let url: URL;
156
- try {
157
- url = new URL(`https://${trimmed}`);
158
- } catch {
159
- throw new RuntimeGatewayLaunchError(
160
- 'runtime_gateway_pin_invalid',
161
- 'Runtime gateway deployment host is not a hostname.',
162
- );
163
- }
164
- if (
165
- url.host !== trimmed.toLowerCase() ||
166
- url.port ||
167
- url.username ||
168
- url.password ||
169
- url.pathname !== '/' ||
170
- url.search ||
171
- url.hash
172
- ) {
173
- throw new RuntimeGatewayLaunchError(
174
- 'runtime_gateway_pin_invalid',
175
- 'Runtime gateway deployment host must be a bare hostname.',
176
- );
177
- }
178
- return url.origin;
179
- }
180
-
181
- /**
182
- * Build the launch fields that pin a run to the admitting deployment. The app
183
- * passes its own immutable deployment host and id (VERCEL_URL and
184
- * VERCEL_DEPLOYMENT_ID of the admitting deployment), never request data.
185
- */
186
- export function buildRuntimeGatewayLaunchPin(input: {
187
- profileId: RuntimeGatewayProfileId;
188
- deploymentHost: string;
189
- deploymentId: string;
190
- nowMs: number;
191
- }): Required<{
192
- [K in keyof RuntimeGatewayLaunchFields]: NonNullable<
193
- RuntimeGatewayLaunchFields[K]
194
- >;
195
- }> {
196
- const profile = resolveRuntimeGatewayProfile(input.profileId);
197
- if (!isRuntimeGatewayDeploymentId(input.deploymentId)) {
198
- throw new RuntimeGatewayLaunchError(
199
- 'runtime_gateway_pin_invalid',
200
- 'Runtime gateway deployment id is invalid.',
201
- );
202
- }
203
- if (!Number.isSafeInteger(input.nowMs) || input.nowMs <= 0) {
204
- throw new RuntimeGatewayLaunchError(
205
- 'runtime_gateway_pin_invalid',
206
- 'Runtime gateway pin time is invalid.',
207
- );
208
- }
209
- const origin = deploymentOrigin(input.deploymentHost);
210
- return {
211
- runtimeGatewayProfileId: profile.id,
212
- runtimeReceiptGatewayBaseUrl: `${origin}${profile.receiptPath}`,
213
- runtimeExecutionGatewayBaseUrl: `${origin}${profile.executionPath}`,
214
- runtimeGatewayDeploymentId: input.deploymentId,
215
- runtimeGatewayPinnedAtMs: input.nowMs,
216
- };
217
- }
218
-
219
- /**
220
- * Read a launch's gateway pin. Returns null only when no pin field is
221
- * present (older or unpinned launches). Any partial, malformed, or unknown
222
- * pin fails loudly: a reader that cannot honor a pin must never fall back to
223
- * the worker's configured gateways.
224
- */
225
- export function readRuntimeGatewayLaunchPin(
226
- launch: RuntimeGatewayLaunchFields,
227
- ): RuntimeGatewayLaunchPin | null {
228
- const present = RUNTIME_GATEWAY_LAUNCH_FIELD_NAMES.filter(
229
- (field) => launch[field] !== undefined && launch[field] !== null,
230
- );
231
- if (present.length === 0) return null;
232
- if (present.length !== RUNTIME_GATEWAY_LAUNCH_FIELD_NAMES.length) {
233
- throw new RuntimeGatewayLaunchError(
234
- 'runtime_gateway_pin_invalid',
235
- `Runtime gateway pin is incomplete (present: ${present.join(', ')}).`,
236
- );
237
- }
238
- const profile = resolveRuntimeGatewayProfile(
239
- String(launch.runtimeGatewayProfileId),
240
- );
241
- const deploymentId = launch.runtimeGatewayDeploymentId;
242
- const pinnedAtMs = launch.runtimeGatewayPinnedAtMs;
243
- if (!isRuntimeGatewayDeploymentId(deploymentId)) {
244
- throw new RuntimeGatewayLaunchError(
245
- 'runtime_gateway_pin_invalid',
246
- 'Runtime gateway deployment id is invalid.',
247
- );
248
- }
249
- if (
250
- typeof pinnedAtMs !== 'number' ||
251
- !Number.isSafeInteger(pinnedAtMs) ||
252
- pinnedAtMs <= 0
253
- ) {
254
- throw new RuntimeGatewayLaunchError(
255
- 'runtime_gateway_pin_invalid',
256
- 'Runtime gateway pin time is invalid.',
257
- );
258
- }
259
- let receipt: URL;
260
- let execution: URL;
261
- try {
262
- receipt = new URL(String(launch.runtimeReceiptGatewayBaseUrl));
263
- execution = new URL(String(launch.runtimeExecutionGatewayBaseUrl));
264
- } catch {
265
- throw new RuntimeGatewayLaunchError(
266
- 'runtime_gateway_pin_invalid',
267
- 'Runtime gateway URLs are not absolute URLs.',
268
- );
269
- }
270
- const origin = receipt.origin;
271
- if (
272
- receipt.protocol !== 'https:' ||
273
- receipt.port ||
274
- receipt.username ||
275
- receipt.password ||
276
- execution.origin !== origin ||
277
- launch.runtimeReceiptGatewayBaseUrl !== `${origin}${profile.receiptPath}` ||
278
- launch.runtimeExecutionGatewayBaseUrl !==
279
- `${origin}${profile.executionPath}`
280
- ) {
281
- throw new RuntimeGatewayLaunchError(
282
- 'runtime_gateway_pin_invalid',
283
- `Runtime gateway URLs do not match profile ${profile.id}.`,
284
- );
285
- }
286
- return Object.freeze({
287
- profile,
288
- deploymentId,
289
- origin,
290
- receiptGatewayBaseUrl: `${origin}${profile.receiptPath}`,
291
- executionGatewayBaseUrl: `${origin}${profile.executionPath}`,
292
- pinnedAtMs,
293
- });
294
- }
295
-
296
- /** A new attempt or resumed sandbox may not start on an expired pin. */
297
- export function assertRuntimeGatewayPinFresh(
298
- pin: RuntimeGatewayLaunchPin,
299
- nowMs: number,
300
- ): void {
301
- const ageMs = nowMs - pin.pinnedAtMs;
302
- if (ageMs > pin.profile.maxPinAgeMs) {
303
- throw new RuntimeGatewayLaunchError(
304
- 'runtime_gateway_pin_expired',
305
- `Runtime gateway pin to ${pin.deploymentId} is ${ageMs} ms old; profile ${pin.profile.id} allows ${pin.profile.maxPinAgeMs} ms. Re-run the Play to pin a current deployment.`,
306
- );
307
- }
308
- }
309
-
310
- /**
311
- * True only for a code-owned gateway request to the pinned origin under the
312
- * profile's receipt or execution prefix. Signed object URLs, other origins,
313
- * and other app paths never receive the gateway credential.
314
- */
315
- export function isRuntimeGatewayCredentialTarget(
316
- pin: Pick<RuntimeGatewayLaunchPin, 'origin' | 'profile'>,
317
- target: string | URL,
318
- ): boolean {
319
- let url: URL;
320
- try {
321
- url = new URL(target);
322
- } catch {
323
- return false;
324
- }
325
- if (url.origin !== pin.origin || url.username || url.password) return false;
326
- return [pin.profile.receiptPath, pin.profile.executionPath].some(
327
- (path) => url.pathname === path || url.pathname.startsWith(`${path}/`),
328
- );
329
- }
@@ -1,338 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import type { RuntimeGatewayLaunchPin } from './runtime-gateway-profile';
3
- import {
4
- RUNTIME_GATEWAY_OIDC_APP_HEADER,
5
- RUNTIME_GATEWAY_OIDC_EDGE_HEADER,
6
- } from './runtime-gateway-oidc';
7
- import {
8
- runtimeGatewayStagedSend,
9
- runtimeGatewayStagingClientLimits,
10
- } from './runtime-gateway-staging';
11
-
12
- /**
13
- * Where a sandbox may present its Runtime gateway OIDC credential: one exact
14
- * origin (the pinned immutable deployment) and its gateway path prefixes.
15
- * Derived by the worker from a validated launch pin, never by the sandbox.
16
- */
17
- export type RuntimeGatewayCredentialScope = Readonly<{
18
- origin: string;
19
- pathPrefixes: readonly string[];
20
- }>;
21
-
22
- /** Sandbox-side context fields for a pinned run. All absent when unpinned. */
23
- export type RuntimeGatewaySandboxContext = {
24
- runtimeGatewayCredentialScope?: RuntimeGatewayCredentialScope | null;
25
- runtimeGatewayOidcToken?: string | null;
26
- };
27
-
28
- export const RUNTIME_GATEWAY_OIDC_FILE_SUFFIX = '.runtime-gateway-oidc';
29
-
30
- /** File the watchdog rewrites with each renewed token, beside the runner config. */
31
- export function runtimeGatewayOidcFilePath(configPath: string): string {
32
- return `${configPath}${RUNTIME_GATEWAY_OIDC_FILE_SUFFIX}`;
33
- }
34
-
35
- export function runtimeGatewayCredentialScopeFromPin(
36
- pin: Pick<RuntimeGatewayLaunchPin, 'origin' | 'profile'>,
37
- ): RuntimeGatewayCredentialScope {
38
- return Object.freeze({
39
- origin: pin.origin,
40
- pathPrefixes: Object.freeze([
41
- pin.profile.receiptPath,
42
- pin.profile.executionPath,
43
- ]),
44
- });
45
- }
46
-
47
- /**
48
- * Headers for one request, or null when the target is outside the scope.
49
- *
50
- * Self-contained on purpose: generated sandbox scripts (watchdog, crash
51
- * terminal pusher) embed this function's source, so it must not reference
52
- * imports or module state. `tests/shared/play-runtime/runtime-gateway-sandbox-credential.test.ts`
53
- * pins the header literals to the OIDC module constants.
54
- */
55
- export function runtimeGatewayOidcRequestHeaders(
56
- scope: unknown,
57
- token: unknown,
58
- target: unknown,
59
- ): Record<string, string> | null {
60
- if (!scope || typeof scope !== 'object') return null;
61
- const origin = (scope as { origin?: unknown }).origin;
62
- const prefixes = (scope as { pathPrefixes?: unknown }).pathPrefixes;
63
- if (
64
- typeof origin !== 'string' ||
65
- !Array.isArray(prefixes) ||
66
- prefixes.length === 0 ||
67
- typeof token !== 'string' ||
68
- token.length === 0 ||
69
- token.length > 4096 ||
70
- !/^[\w-]+\.[\w-]+\.[\w-]+$/.test(token)
71
- ) {
72
- return null;
73
- }
74
- let url: URL;
75
- try {
76
- url = new URL(String(target));
77
- } catch {
78
- return null;
79
- }
80
- if (
81
- url.protocol !== 'https:' ||
82
- url.origin !== origin ||
83
- url.username ||
84
- url.password
85
- ) {
86
- return null;
87
- }
88
- const inScope = prefixes.some(
89
- (prefix) =>
90
- typeof prefix === 'string' &&
91
- prefix.startsWith('/') &&
92
- (url.pathname === prefix || url.pathname.startsWith(prefix + '/')),
93
- );
94
- if (!inScope) return null;
95
- return {
96
- 'x-vercel-trusted-oidc-idp-token': token,
97
- 'x-deepline-runtime-oidc': token,
98
- };
99
- }
100
-
101
- /** Header names used by `runtimeGatewayOidcRequestHeaders`. */
102
- export const RUNTIME_GATEWAY_OIDC_REQUEST_HEADER_NAMES = [
103
- RUNTIME_GATEWAY_OIDC_EDGE_HEADER,
104
- RUNTIME_GATEWAY_OIDC_APP_HEADER,
105
- ] as const;
106
-
107
- /** Latest renewed token from the watchdog's file, else the initial token. */
108
- export function currentRuntimeGatewayOidcToken(
109
- initial: string | null | undefined,
110
- filePath: string | null | undefined,
111
- readFile: (path: string) => string = (path) => readFileSync(path, 'utf8'),
112
- ): string | null {
113
- if (!initial) return null;
114
- if (!filePath) return initial;
115
- try {
116
- const current = readFile(filePath).trim();
117
- if (current.length <= 4096 && /^[\w-]+\.[\w-]+\.[\w-]+$/.test(current))
118
- return current;
119
- } catch {
120
- // The watchdog creates the file at its first renewal.
121
- }
122
- return initial;
123
- }
124
-
125
- function requestTarget(input: Parameters<typeof fetch>[0]): string {
126
- if (typeof input === 'string') return input;
127
- if (input instanceof URL) return input.href;
128
- return input.url;
129
- }
130
-
131
- /**
132
- * Wrap a fetch so code-owned gateway requests to the pinned origin carry the
133
- * OIDC credential. Every other target, including signed object URLs on other
134
- * origins and app paths outside the gateway prefixes, passes through
135
- * untouched. Credentialed requests never follow redirects.
136
- *
137
- * Credentialed requests given as a URL plus init also use staged bodies
138
- * (`runtime-gateway-staging.ts`), so an app-hosted gateway keeps the Fly
139
- * gateway's 16 MiB request and response contract under Vercel's body cap.
140
- */
141
- export function createRuntimeGatewayCredentialFetch(input: {
142
- scope: RuntimeGatewayCredentialScope;
143
- send: typeof fetch;
144
- currentToken: () => string | null;
145
- }): typeof fetch {
146
- const { scope } = input;
147
- const stagingLimits = runtimeGatewayStagingClientLimits(scope.pathPrefixes);
148
- const wrapped = async (
149
- request: Parameters<typeof fetch>[0],
150
- init?: Parameters<typeof fetch>[1],
151
- ): Promise<Response> => {
152
- const headers = runtimeGatewayOidcRequestHeaders(
153
- scope,
154
- input.currentToken(),
155
- requestTarget(request),
156
- );
157
- if (!headers) return await input.send(request, init);
158
- const merged = new Headers(
159
- init?.headers ??
160
- (request instanceof Request ? request.headers : undefined),
161
- );
162
- for (const [name, value] of Object.entries(headers))
163
- merged.set(name, value);
164
- if (!(request instanceof Request)) {
165
- return await runtimeGatewayStagedSend(
166
- input.send,
167
- requestTarget(request),
168
- { ...init, headers: merged, redirect: 'manual' },
169
- stagingLimits,
170
- );
171
- }
172
- return await input.send(request, {
173
- ...init,
174
- headers: merged,
175
- redirect: 'manual',
176
- });
177
- };
178
- return wrapped as typeof fetch;
179
- }
180
-
181
- /**
182
- * Whether a renewal failure is definitive: a 401/403/404/409 refusal by the
183
- * gateway, with or without its named reason (`http_403_attempt_cancelled`,
184
- * `_attempt_superseded`, `_lease_mismatch`, `_scope_mismatch`,
185
- * `_attempt_not_found`, `_no_lease`), or a renewed token for another scope.
186
- * Transport failures, 5xx, and `http_403_attempt_not_live` (a stale heartbeat
187
- * while the runner catches up after a network cut) are retried.
188
- * Self-contained: the generated watchdog embeds its source.
189
- */
190
- export function isRuntimeGatewayOidcRenewalFatal(errorCode: unknown): boolean {
191
- return /^(?:http_(?:401|403|404|409)(?:_(?!attempt_not_live$)[a-z_]+)?|renewal_scope_mismatch)$/.test(
192
- String(errorCode),
193
- );
194
- }
195
-
196
- /** First retry delay after a failed renewal; doubles per failure. */
197
- export const RUNTIME_GATEWAY_OIDC_RENEW_RETRY_BASE_MS = 5_000;
198
- /** Longest delay between renewal retries. */
199
- export const RUNTIME_GATEWAY_OIDC_RENEW_RETRY_MAX_MS = 60_000;
200
-
201
- export type RuntimeGatewayOidcRenewalLoopOptions = {
202
- /** The credential in hand: issued-at and expiry, in epoch seconds. */
203
- initial: { iatS: number; expS: number };
204
- renewAfterSeconds: number;
205
- /** Stop retrying, loudly, once less than this remains. */
206
- expiryMarginSeconds: number;
207
- retryBaseMs: number;
208
- retryMaxMs: number;
209
- now: () => number;
210
- random: () => number;
211
- setTimer: (run: () => void, delayMs: number) => unknown;
212
- clearTimer: (timer: unknown) => void;
213
- /** Renew once; resolves with the new credential's times. */
214
- renew: () => Promise<{ iatS: number; expS: number }>;
215
- /** A definitive refusal (lost lease, wrong scope): no retry. */
216
- isFatal: (error: unknown) => boolean;
217
- isStopped: () => boolean;
218
- onRetry: (
219
- error: unknown,
220
- diagnostic: RuntimeGatewayOidcRenewalDiagnostic,
221
- ) => void;
222
- onFatal: (
223
- error: unknown,
224
- diagnostic: RuntimeGatewayOidcRenewalDiagnostic,
225
- ) => void;
226
- };
227
-
228
- export type RuntimeGatewayOidcRenewalDiagnostic = {
229
- failures: number;
230
- remainingSeconds: number;
231
- nextRetryMs: number | null;
232
- };
233
-
234
- /**
235
- * The renewal loop for the whole life of a sandbox (4 hours and more).
236
- *
237
- * Timing uses the sandbox's own clock. A renewed credential is taken to have
238
- * been issued at the local time its renewal response arrived, and to live
239
- * its server-stated lifetime (`expS - iatS`) from then, so once one renewal
240
- * has succeeded, sandbox clock skew in either direction can neither spin the
241
- * loop nor fail it early. The initial credential arrived before the loop
242
- * started, so its age is judged from its issue time, corrected by the
243
- * gateway clock whenever a renewal failure carries one (`serverNowMs`, from
244
- * the response `Date` header); with no server time seen yet it is judged by
245
- * the sandbox clock. Its first renewal is due at most `renewAfterSeconds`
246
- * after the loop starts, so a skewed clock delays it by no more than that.
247
- *
248
- * Every renewal waits at least `retryBaseMs`. A failed renewal retries with
249
- * capped exponential backoff and full jitter in its upper half, never past
250
- * the expiry safety margin, so an outage shorter than the credential's
251
- * remaining life is survived. A definitive refusal, or a credential inside
252
- * the margin, stops the loop and calls `onFatal` once. Nothing here has its
253
- * own deadline: the loop runs until `stop` or a fatal outcome.
254
- *
255
- * Self-contained on purpose: the generated watchdog embeds this function's
256
- * source, so it must not reference imports, module state, or nested named
257
- * functions.
258
- */
259
- export function startRuntimeGatewayOidcRenewalLoop(
260
- options: RuntimeGatewayOidcRenewalLoopOptions,
261
- ): { stop: () => void } {
262
- const renewAfterMs = options.renewAfterSeconds * 1_000;
263
- const initial = options.initial;
264
- let lifetimeMs = Math.max(0, (initial.expS - initial.iatS) * 1_000);
265
- /** Local issue time of the current credential; null for the initial one. */
266
- let localIssuedMs: number | null = null;
267
- /** Gateway clock minus sandbox clock, once a failure reported it. */
268
- let skewMs = 0;
269
- let failures = 0;
270
- let timer: unknown = null;
271
- let stopped = false;
272
- const schedule = (delayMs: number) => {
273
- if (stopped || options.isStopped()) return;
274
- timer = options.setTimer(() => void tick(), Math.max(0, delayMs));
275
- };
276
- const remainingMs = () =>
277
- localIssuedMs === null
278
- ? initial.expS * 1_000 - (options.now() + skewMs)
279
- : localIssuedMs + lifetimeMs - options.now();
280
- const tick = async () => {
281
- timer = null;
282
- if (stopped || options.isStopped()) return;
283
- try {
284
- const next = await options.renew();
285
- if (stopped || options.isStopped()) return;
286
- failures = 0;
287
- localIssuedMs = options.now();
288
- lifetimeMs = Math.max(0, (next.expS - next.iatS) * 1_000);
289
- schedule(Math.max(options.retryBaseMs, renewAfterMs));
290
- } catch (error) {
291
- if (stopped || options.isStopped()) return;
292
- failures += 1;
293
- const serverNowMs =
294
- error && typeof error === 'object'
295
- ? (error as { serverNowMs?: unknown }).serverNowMs
296
- : undefined;
297
- if (typeof serverNowMs === 'number' && Number.isFinite(serverNowMs)) {
298
- skewMs = serverNowMs - options.now();
299
- }
300
- const left = remainingMs();
301
- const untilMarginMs = left - options.expiryMarginSeconds * 1_000;
302
- const diagnostic = {
303
- failures,
304
- remainingSeconds: Math.floor(left / 1_000),
305
- nextRetryMs: null as number | null,
306
- };
307
- if (options.isFatal(error) || untilMarginMs <= 0) {
308
- stopped = true;
309
- options.onFatal(error, diagnostic);
310
- return;
311
- }
312
- const backoffMs = Math.min(
313
- options.retryMaxMs,
314
- options.retryBaseMs * 2 ** Math.min(failures - 1, 30),
315
- );
316
- const jitteredMs = backoffMs / 2 + options.random() * (backoffMs / 2);
317
- // The last retry lands at the margin, where a failure is fatal.
318
- diagnostic.nextRetryMs = Math.round(Math.min(jitteredMs, untilMarginMs));
319
- options.onRetry(error, diagnostic);
320
- schedule(diagnostic.nextRetryMs);
321
- }
322
- };
323
- schedule(
324
- Math.min(
325
- renewAfterMs,
326
- Math.max(
327
- options.retryBaseMs,
328
- initial.iatS * 1_000 + renewAfterMs - options.now(),
329
- ),
330
- ),
331
- );
332
- return {
333
- stop: () => {
334
- stopped = true;
335
- if (timer !== null) options.clearTimer(timer);
336
- },
337
- };
338
- }