deepline 0.3.497 → 0.3.498

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 (131) hide show
  1. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  2. package/dist/bundling-sources/shared_libs/monitors/billing/policy-builders.ts +2 -0
  3. package/dist/bundling-sources/shared_libs/monitors/billing/state.ts +8 -1
  4. package/dist/bundling-sources/shared_libs/monitors/billing/tamradar.ts +23 -5
  5. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-upstream-identity.ts +4 -3
  6. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +1 -1
  7. package/dist/bundling-sources/shared_libs/observability/scheduled-work-control.ts +2 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/play-admission-outcome.ts +8 -3
  9. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-oidc.ts +470 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/runtime-gateway-profile.ts +318 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +7 -4
  12. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +4 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +19 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +138 -0
  15. package/dist/cli/auth-NYYFDCMT.js +43 -0
  16. package/dist/cli/{auth-OAKBFUQD.mjs → auth-TNYYAPIX.mjs} +5 -5
  17. package/dist/cli/{billing-AM6D2KN5.mjs → billing-G6QBOZAE.mjs} +6 -6
  18. package/dist/cli/{billing-FUB6HQZ5.js → billing-MP43H3ZK.js} +79 -79
  19. package/dist/cli/{chunk-UETGYJYH.mjs → chunk-2QS3MCJ2.mjs} +2 -2
  20. package/dist/cli/{chunk-3IVAGF4P.mjs → chunk-3XNYGMPZ.mjs} +10 -10
  21. package/dist/cli/{chunk-IURXJPGH.mjs → chunk-4RSOYJ67.mjs} +3 -3
  22. package/dist/cli/{chunk-5IBHSACU.mjs → chunk-4TVN2676.mjs} +2 -2
  23. package/dist/cli/{chunk-HRODQDTB.mjs → chunk-6JVJZ7YG.mjs} +1 -1
  24. package/dist/cli/{chunk-WKCMARFR.js → chunk-BQIEYWGQ.js} +94 -94
  25. package/dist/cli/{chunk-LPCK5KK5.mjs → chunk-C7BH7T3T.mjs} +2 -2
  26. package/dist/cli/{chunk-YUEFDOME.js → chunk-DB7SJKGI.js} +6 -6
  27. package/dist/cli/{chunk-SLS3HUVC.js → chunk-EAQXRAVF.js} +4 -4
  28. package/dist/cli/{chunk-M2WIEW2E.mjs → chunk-EHOC6NCN.mjs} +1 -1
  29. package/dist/cli/{chunk-XNLXHU6L.mjs → chunk-ELZYHPE7.mjs} +5 -5
  30. package/dist/cli/{chunk-6TA2H7CY.js → chunk-FPRS3FP4.js} +26 -26
  31. package/dist/cli/{chunk-FISH2MI2.mjs → chunk-H7YR4EYF.mjs} +2 -2
  32. package/dist/cli/{chunk-BRUDMG56.js → chunk-IBCROFZW.js} +41 -41
  33. package/dist/cli/{chunk-3DHPKENA.mjs → chunk-IE6FYMUS.mjs} +1 -1
  34. package/dist/cli/{chunk-OEI6HXMK.js → chunk-IUCAVYXR.js} +16 -16
  35. package/dist/cli/{chunk-KUX3HYJI.mjs → chunk-KLA4IUOI.mjs} +1 -1
  36. package/dist/cli/{chunk-SJM7MKOE.js → chunk-KRR2Z2FH.js} +2 -2
  37. package/dist/cli/{chunk-SJID5WMV.mjs → chunk-KV4RNW2H.mjs} +4 -4
  38. package/dist/cli/{chunk-KFJV3BZX.mjs → chunk-LGE6ZOEO.mjs} +1 -1
  39. package/dist/cli/{chunk-WZ3A35ZD.mjs → chunk-MRHMC33S.mjs} +1 -1
  40. package/dist/cli/{chunk-YQ66NC4J.mjs → chunk-O4H53SJ4.mjs} +2 -2
  41. package/dist/cli/{chunk-VMOVB2FN.mjs → chunk-OFNXUDEC.mjs} +5 -5
  42. package/dist/cli/{chunk-B4Q3EBQX.js → chunk-OL2QEEXF.js} +5 -5
  43. package/dist/cli/{chunk-XX7WLKOQ.mjs → chunk-PAHFVOFZ.mjs} +1 -1
  44. package/dist/cli/{chunk-ZLYKN4AJ.js → chunk-PHBJ2VDS.js} +7 -7
  45. package/dist/cli/{chunk-7RBIOOCQ.js → chunk-PKTJN6PF.js} +3 -3
  46. package/dist/cli/{chunk-DKSTMQ3F.js → chunk-QDNP6KOF.js} +21 -21
  47. package/dist/cli/{chunk-UV7AT2D4.js → chunk-QERMP4TW.js} +2 -2
  48. package/dist/cli/{chunk-FVS5MJQ5.js → chunk-QUIJUNXX.js} +3 -3
  49. package/dist/cli/{chunk-EWQ3KY5U.mjs → chunk-RZA6HSXX.mjs} +6 -6
  50. package/dist/cli/{chunk-4MR7LZXF.mjs → chunk-RZO743TC.mjs} +2 -2
  51. package/dist/cli/{chunk-5GXYXU45.mjs → chunk-SR3PRGWB.mjs} +1 -1
  52. package/dist/cli/{chunk-WXW7YJDO.js → chunk-TDUTNTA5.js} +53 -53
  53. package/dist/cli/{chunk-A66Y2LCW.js → chunk-TLG75Q77.js} +53 -53
  54. package/dist/cli/{chunk-XLYJ7MJX.js → chunk-TPQFCUPV.js} +7 -7
  55. package/dist/cli/{chunk-3KG2FUU4.js → chunk-UA2GU7NB.js} +7 -7
  56. package/dist/cli/{chunk-THD6KA67.mjs → chunk-UUFZFJL4.mjs} +4 -4
  57. package/dist/cli/{chunk-MBOAXLWC.mjs → chunk-VETP54NO.mjs} +4 -4
  58. package/dist/cli/{chunk-V2EVSEUD.js → chunk-VFYKFPZD.js} +16 -16
  59. package/dist/cli/{chunk-JDFYCHNV.js → chunk-VUNAIAMX.js} +5 -5
  60. package/dist/cli/{chunk-77IAUCTB.js → chunk-XGUGFGCF.js} +3 -3
  61. package/dist/cli/{chunk-OWDK2PVH.js → chunk-XNYAIV4E.js} +8 -8
  62. package/dist/cli/{chunk-BBHGJE73.js → chunk-XUTIBRKF.js} +1 -1
  63. package/dist/cli/{chunk-7FFNSYMJ.js → chunk-YCGVVUGX.js} +9 -9
  64. package/dist/cli/{chunk-TGAYN34A.mjs → chunk-ZEYB6QPW.mjs} +2 -2
  65. package/dist/cli/{csv-U2GOFP3M.mjs → csv-LBUOESU2.mjs} +4 -4
  66. package/dist/cli/{csv-PMBYKVUU.js → csv-SCXUWRVV.js} +13 -13
  67. package/dist/cli/{db-DKFOTZGZ.mjs → db-3SI2OXIV.mjs} +6 -6
  68. package/dist/cli/{db-GREVTMIR.js → db-CC2D2GSL.js} +27 -27
  69. package/dist/cli/describe-DAUL3SDQ.js +50 -0
  70. package/dist/cli/{describe-SWXA6L62.mjs → describe-ZK5CMT4M.mjs} +17 -17
  71. package/dist/cli/{executions-EBRFC5JR.mjs → executions-DVPHIG2I.mjs} +6 -6
  72. package/dist/cli/{executions-2RRAESQK.js → executions-YKYQIRPP.js} +8 -8
  73. package/dist/cli/{feedback-N6ML7IRH.js → feedback-BVLYZ3BM.js} +8 -8
  74. package/dist/cli/{feedback-4A57QLX2.mjs → feedback-UQRMPU2S.mjs} +4 -4
  75. package/dist/cli/git-MFIJCRX6.js +25 -0
  76. package/dist/cli/{git-6D2WQPOS.mjs → git-WTMZ66HP.mjs} +5 -5
  77. package/dist/cli/index.js +137 -137
  78. package/dist/cli/index.mjs +40 -40
  79. package/dist/cli/{legacy-noops-CL5QWXGH.mjs → legacy-noops-RUQT6DB3.mjs} +5 -5
  80. package/dist/cli/{legacy-noops-DXRJARNC.js → legacy-noops-TVJ5WOBD.js} +8 -8
  81. package/dist/cli/{monitors-XWKDVHYL.js → monitors-UYYJBO6U.js} +95 -95
  82. package/dist/cli/{monitors-SGMEGGJO.mjs → monitors-ZQBZMFUL.mjs} +7 -7
  83. package/dist/cli/{org-QKQ57PDN.js → org-4TZED2IF.js} +72 -72
  84. package/dist/cli/{org-55BI5RQF.mjs → org-UACQHFY6.mjs} +6 -6
  85. package/dist/cli/{pages-FOIR5UH4.js → pages-HDYYGZOT.js} +18 -18
  86. package/dist/cli/{pages-LM4QACOM.mjs → pages-R2KSZCYK.mjs} +6 -6
  87. package/dist/cli/{play-7VA26O6E.mjs → play-DQ4AZ2NV.mjs} +17 -17
  88. package/dist/cli/{play-S44FXGD7.js → play-ZMYWHAV3.js} +314 -314
  89. package/dist/cli/{providers-RDSHID7C.js → providers-I7GXTYG4.js} +9 -9
  90. package/dist/cli/{providers-QAVIR5E2.mjs → providers-X53WCX46.mjs} +6 -6
  91. package/dist/cli/{quickstart-IL4HQYE4.mjs → quickstart-DKVF32MY.mjs} +4 -4
  92. package/dist/cli/{quickstart-EREQPM3G.js → quickstart-GKW46HUR.js} +6 -6
  93. package/dist/cli/{run-4XZNJR7N.mjs → run-A36EBVLD.mjs} +22 -22
  94. package/dist/cli/{run-TBUUV5EG.js → run-VLX775L5.js} +36 -36
  95. package/dist/cli/{search-SYT5UT5G.mjs → search-QHO4AYS2.mjs} +7 -7
  96. package/dist/cli/search-STXZIGVB.js +32 -0
  97. package/dist/cli/{search-output-5F3EEQ34.js → search-output-P7GWSTNO.js} +6 -6
  98. package/dist/cli/{search-output-Y3IKZ3TX.mjs → search-output-YF5HCWKU.mjs} +4 -4
  99. package/dist/cli/{secrets-PZWJ2ES5.js → secrets-3X56AV2F.js} +15 -15
  100. package/dist/cli/{secrets-AKAU2N3K.mjs → secrets-XTHBAX26.mjs} +6 -6
  101. package/dist/cli/{sessions-Z5C26IS7.mjs → sessions-4ZVZABXN.mjs} +5 -5
  102. package/dist/cli/{sessions-UMHA7K23.js → sessions-AJUQJR4G.js} +6 -6
  103. package/dist/cli/{settings-S5BM3SVI.mjs → settings-AX5JF47R.mjs} +11 -11
  104. package/dist/cli/{settings-WGJYWTJZ.js → settings-R7RQC5Z3.js} +78 -78
  105. package/dist/cli/{setup-E4HRXP2X.mjs → setup-DTXQODYK.mjs} +9 -9
  106. package/dist/cli/{setup-6K6ERKOH.js → setup-QB62E6K5.js} +49 -49
  107. package/dist/cli/skills-IEP5L5MQ.js +36 -0
  108. package/dist/cli/{skills-HIZA7YAN.mjs → skills-N6OY5ABC.mjs} +7 -7
  109. package/dist/cli/{tools-FS5S6BT7.mjs → tools-3T4GKGS4.mjs} +16 -16
  110. package/dist/cli/tools-JWBXEZKY.js +57 -0
  111. package/dist/cli/{update-4CJPTG3L.mjs → update-QDT4SFW3.mjs} +9 -9
  112. package/dist/cli/update-QME3C2VP.js +34 -0
  113. package/dist/cli/{workflow-TYSZ5JWS.js → workflow-FW3FPOWU.js} +17 -17
  114. package/dist/cli/{workflow-UMSXOIOS.mjs → workflow-Q7LQETNW.mjs} +7 -7
  115. package/dist/index.js +9 -9
  116. package/dist/index.mjs +6 -6
  117. package/dist/install-integrity.json +100 -98
  118. package/dist/release.d.mts +1 -1
  119. package/dist/release.d.ts +1 -1
  120. package/dist/release.js +2 -2
  121. package/dist/release.mjs +1 -1
  122. package/dist/server.js +5 -5
  123. package/dist/server.mjs +3 -3
  124. package/package.json +1 -1
  125. package/dist/cli/auth-553ZBCPJ.js +0 -43
  126. package/dist/cli/describe-BL5NNHV5.js +0 -50
  127. package/dist/cli/git-7TSX5V57.js +0 -25
  128. package/dist/cli/search-GCANFVVZ.js +0 -32
  129. package/dist/cli/skills-J3GQHHHL.js +0 -36
  130. package/dist/cli/tools-RZYKMOUX.js +0 -57
  131. package/dist/cli/update-CATZW7GA.js +0 -34
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
205
205
  // getters keep their established compatibility behavior.
206
206
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
207
207
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
208
- version: '0.3.497',
208
+ version: '0.3.498',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -593,6 +593,8 @@ export function defineTamradarMonitorBillingPolicy(
593
593
  'No Deepline base reactivate charge',
594
594
  );
595
595
  const customerUsageCharges: MonitorRetailCharge[] = [];
596
+ // Not currently used: no TamRadar radar type is priced as a subscription
597
+ // since job changes moved to per-finding pricing (2026-11-10).
596
598
  if (subscriptionEntries.length > 0) {
597
599
  customerUsageCharges.push(
598
600
  retailCharge({
@@ -191,7 +191,8 @@ export function monitorBillingRequiresExplicitReactivation(
191
191
  * Whether a monthly-billed monitor is still inside the period it has already
192
192
  * paid for (KAR-43 decision 8).
193
193
  *
194
- * A subscription monitor (TamRadar `contact_job_changes`) is billed per month,
194
+ * A subscription monitor (TamRadar `contact_job_changes` until it moved to
195
+ * per-finding pricing on 2026-11-10; no radar type today) is billed per month,
195
196
  * not per finding: the first month at create, then renewed by the
196
197
  * `charge-reconcile` cron 24 hours before the provider's `next_charge_at`.
197
198
  * That renewal is its funding gate. Until the paid period ends, a negative
@@ -199,6 +200,12 @@ export function monitorBillingRequiresExplicitReactivation(
199
200
  * charges, the customer keeps the month they paid for, and a recreate would
200
201
  * charge Deepline again (TamRadar has no reactivate endpoint).
201
202
  *
203
+ * Since 2026-11-10 that premise no longer holds for a job-change monitor
204
+ * bought monthly and not yet converted: its findings DO charge per finding,
205
+ * so finding admission, not this exemption, is what stops it at a zero
206
+ * balance. The renewal pass or `monitors billing resync-period` clears the
207
+ * period, after which this returns false for it.
208
+ *
202
209
  * `provider_next_charge_at` is the provider-owned period end; `next_renewal_at`
203
210
  * is Deepline's own periodic renewal. Either one in the future proves a paid
204
211
  * period. An unparseable anchor proves nothing.
@@ -3,6 +3,7 @@ import type {
3
3
  MonitorCommercialModel,
4
4
  MonitorPayloadPricingEntry,
5
5
  MonitorPayloadPricingMap,
6
+ MonitorPayloadPricingMode,
6
7
  } from '@deepline/monitors/billing/types';
7
8
  import { publicMonitorPricingEntry } from '@deepline/monitors/billing/public-pricing';
8
9
 
@@ -64,13 +65,17 @@ export const TAMRADAR_RADAR_TYPE_PRICING = {
64
65
  providerCostUsd: 0.025,
65
66
  unitLabel: 'finding',
66
67
  },
68
+ // Source: TAMRadar per-update pricing (confidential/internal). TAMRadar
69
+ // moved job changes from $0.07/month to $0.13 per delivered change, with no
70
+ // monthly renewal, on 2026-11-10. Monitors created as subscriptions convert
71
+ // through the renewal pass (`reconcile.ts`).
72
+ // https://tamradar.mintlify.app/api-reference/create-contact-radar (job_changes).
67
73
  contact_job_changes: {
68
74
  capability: 'contact_radar',
69
75
  label: 'Contact job changes',
70
- mode: 'monitor_subscription',
71
- providerCostUsd: 0.07,
72
- unitLabel: 'month',
73
- periodDays: 30,
76
+ mode: 'monitor_usage',
77
+ providerCostUsd: 0.13,
78
+ unitLabel: 'finding',
74
79
  },
75
80
  // Source: TAMRadar per-update pricing (confidential/internal),
76
81
  // https://tamradar.mintlify.app/api-reference/create-contact-radar (social_posts).
@@ -181,10 +186,23 @@ export function tamradarProviderCostKey(input: {
181
186
  return `deepline_native.${input.capability}.${input.radarType}`;
182
187
  }
183
188
 
189
+ // Every mode a registry entry may take. Read through this rather than the
190
+ // registry's literal type: no entry is a subscription today, so the literal
191
+ // type would reject the subscription branch below.
192
+ type TamradarRadarTypePricingConfig = {
193
+ capability: string;
194
+ label: string;
195
+ mode: MonitorPayloadPricingMode;
196
+ providerCostUsd: number;
197
+ unitLabel: string;
198
+ periodDays?: number;
199
+ };
200
+
184
201
  function entryForRadarType(
185
202
  radarType: TamradarRadarType,
186
203
  ): MonitorPayloadPricingEntry {
187
- const config = TAMRADAR_RADAR_TYPE_PRICING[radarType];
204
+ const config: TamradarRadarTypePricingConfig =
205
+ TAMRADAR_RADAR_TYPE_PRICING[radarType];
188
206
  return {
189
207
  label: config.label,
190
208
  mode: config.mode,
@@ -46,9 +46,10 @@ type ProviderMonitorUpstreamIdentityDefinition = {
46
46
  * Payload fields that never change which findings the provider resource
47
47
  * delivers. `updates_since` only sets how far back the first delivery
48
48
  * replays, so two monitors that differ only there watch the same feed.
49
- * New claim keys omit them. Keys stored before that still carry them until
50
- * the `normalizeProviderMonitorIdentityClaimKeys` migration rewrites them;
51
- * readers resolve both through `canonicalProviderMonitorIdentityClaimKey`.
49
+ * Claim keys omit them; the `normalizeProviderMonitorIdentityClaimKeys`
50
+ * migration rewrote every key stored before that. An older app build can
51
+ * still send a key that carries them, so readers pass incoming keys through
52
+ * `canonicalProviderMonitorIdentityClaimKey`.
52
53
  */
53
54
  nonConfigurationFields?: readonly string[];
54
55
  };
@@ -93,7 +93,7 @@
93
93
  "id": "github.ci-health-analytics",
94
94
  "name": "CI Health Analytics",
95
95
  "scheduler": "github_actions",
96
- "cadence": "7 * * * *",
96
+ "cadence": "20 * * * *",
97
97
  "timezone": "UTC",
98
98
  "source": ".github/workflows/ci-health-analytics.yml",
99
99
  "locator": "schedule:",
@@ -61,6 +61,8 @@ export type ScheduledWorkControlContext = {
61
61
  */
62
62
  readonly orgScope?: readonly string[];
63
63
  readonly historicalSettlementManifest?: HistoricalSettlementManifest;
64
+ /** Maximum settlement batch width for `settlement-batch-width` activate. */
65
+ readonly settlementBatchWidth?: number;
64
66
  readonly requestedByUserId: string;
65
67
  readonly requestedByEmail: string;
66
68
  readonly reason: string;
@@ -47,7 +47,10 @@ export const PLAY_RUNTIME_CALLBACK_UNCONFIGURED =
47
47
  */
48
48
  export const PLAY_RUN_RATE_LIMITED = 'PLAY_RUN_RATE_LIMITED' as const;
49
49
 
50
- export type PlayAdmissionSkippedCode = typeof PLAY_RUN_RATE_LIMITED;
50
+ export const WORKSPACE_TRIGGER_RETIRED = 'WORKSPACE_TRIGGER_RETIRED' as const;
51
+ export type PlayAdmissionSkippedCode =
52
+ | typeof PLAY_RUN_RATE_LIMITED
53
+ | typeof WORKSPACE_TRIGGER_RETIRED;
51
54
 
52
55
  export type PlayAdmissionBlockedCode =
53
56
  | typeof PLAY_ADMISSION_PAYLOAD_UNREADABLE
@@ -112,6 +115,8 @@ const PLAY_RUN_RATE_LIMITED_MESSAGE =
112
115
  * code alone, so the reason must be derivable from the stable code.
113
116
  */
114
117
  export function playAdmissionBlockedMessage(code: string): string {
118
+ if (code === WORKSPACE_TRIGGER_RETIRED)
119
+ return 'Workspace was archived after this delivery was queued.';
115
120
  return code === PLAY_RUN_RATE_LIMITED
116
121
  ? PLAY_RUN_RATE_LIMITED_MESSAGE
117
122
  : code === PLAY_SECRET_UNAVAILABLE
@@ -159,11 +164,11 @@ export function classifyPlayAdmissionFailure(
159
164
  return blocked(PLAY_SECRET_UNAVAILABLE);
160
165
  }
161
166
  const code = stableErrorCode(error);
162
- if (code === PLAY_RUN_RATE_LIMITED) {
167
+ if (code === PLAY_RUN_RATE_LIMITED || code === WORKSPACE_TRIGGER_RETIRED) {
163
168
  return {
164
169
  disposition: 'skipped',
165
170
  code,
166
- message: PLAY_RUN_RATE_LIMITED_MESSAGE,
171
+ message: playAdmissionBlockedMessage(code),
167
172
  };
168
173
  }
169
174
  if (
@@ -0,0 +1,470 @@
1
+ import {
2
+ createPrivateKey,
3
+ createPublicKey,
4
+ sign,
5
+ verify,
6
+ type JsonWebKey,
7
+ type KeyObject,
8
+ } from 'node:crypto';
9
+ import { isRuntimeGatewayDeploymentId } from './runtime-gateway-profile';
10
+ import { isTestOnlyRuntime } from './runtime-env';
11
+
12
+ /**
13
+ * Edge credential for sandbox -> pinned app-deployment gateway traffic.
14
+ *
15
+ * One durable, code-owned issuer signs short-lived RS256 tokens scoped to one
16
+ * deployment, run and attempt. Vercel Trusted Sources admits the request at
17
+ * the edge from `x-vercel-trusted-oidc-idp-token`; the gateway handler checks
18
+ * the same token from `x-deepline-runtime-oidc` against the exact run and
19
+ * deployment. The executor token remains the request's authorization.
20
+ *
21
+ * Preview and Production never accept each other's tokens. Every token
22
+ * carries `deepline_env`; each environment signs with and trusts only its
23
+ * own kids, and verification requires the deployment's own environment in
24
+ * both the kid and the claim. The published JWKS is the union of both
25
+ * environments' keys, so one issuer serves both.
26
+ */
27
+ export const RUNTIME_GATEWAY_OIDC_ISSUER =
28
+ 'https://code.deepline.com/runtime-gateway-oidc';
29
+ export const RUNTIME_GATEWAY_OIDC_SUBJECT = 'deepline:runtime-gateway:daytona';
30
+ export const RUNTIME_GATEWAY_OIDC_AUDIENCE = 'deepline:runtime-gateway';
31
+ export const RUNTIME_GATEWAY_OIDC_MAX_AGE_SECONDS = 15 * 60;
32
+ export const RUNTIME_GATEWAY_OIDC_RENEW_AFTER_SECONDS = 2 * 60;
33
+ /** Appended to the pinned receipt gateway base URL. */
34
+ export const RUNTIME_GATEWAY_OIDC_RENEW_PATH = '/renew-oidc';
35
+ /** Header Vercel Trusted Sources reads at the edge. */
36
+ export const RUNTIME_GATEWAY_OIDC_EDGE_HEADER =
37
+ 'x-vercel-trusted-oidc-idp-token';
38
+ /** Header the app verifies, independent of edge header handling. */
39
+ export const RUNTIME_GATEWAY_OIDC_APP_HEADER = 'x-deepline-runtime-oidc';
40
+ export const RUNTIME_GATEWAY_OIDC_DISCOVERY_PATH =
41
+ '/.well-known/openid-configuration';
42
+ export const RUNTIME_GATEWAY_OIDC_JWKS_PATH = '/.well-known/jwks.json';
43
+ /** Secret env (base64 DER PKCS#8 RSA key) and its key id. */
44
+ export const RUNTIME_GATEWAY_OIDC_PRIVATE_KEY_ENV =
45
+ 'DEEPLINE_RUNTIME_GATEWAY_OIDC_PRIVATE_KEY';
46
+ export const RUNTIME_GATEWAY_OIDC_KID_ENV = 'DEEPLINE_RUNTIME_GATEWAY_OIDC_KID';
47
+ /** Sandbox-local file the watchdog rewrites with each renewed token. */
48
+ export const RUNTIME_GATEWAY_OIDC_FILE_ENV =
49
+ 'DEEPLINE_RUNTIME_GATEWAY_OIDC_FILE';
50
+ /** Renewal response body field. */
51
+ export const RUNTIME_GATEWAY_OIDC_RENEW_RESPONSE_FIELD = 'oidcToken';
52
+ const RUNTIME_GATEWAY_OIDC_MAX_TOKEN_LENGTH = 4_096;
53
+ const RUNTIME_GATEWAY_OIDC_CLOCK_SKEW_SECONDS = 30;
54
+
55
+ export type RuntimeGatewayOidcPublicJwk = JsonWebKey & {
56
+ kty: 'RSA';
57
+ kid: string;
58
+ alg: 'RS256';
59
+ use: 'sig';
60
+ n: string;
61
+ e: string;
62
+ };
63
+
64
+ /**
65
+ * Public keys trusted for verification. Rotation: add the new key first and
66
+ * keep the previous one until every token it signed has expired (15 min),
67
+ * then switch the signing secret, then remove the previous key.
68
+ */
69
+ export const RUNTIME_GATEWAY_OIDC_PUBLIC_JWKS: Readonly<{
70
+ keys: readonly RuntimeGatewayOidcPublicJwk[];
71
+ }> = Object.freeze({
72
+ keys: Object.freeze([
73
+ Object.freeze({
74
+ kty: 'RSA',
75
+ kid: 'rgw-oidc-2026-11-10',
76
+ alg: 'RS256',
77
+ use: 'sig',
78
+ n: 'rx63Q0lYpf56t-9Ab1UZMdlvEHvA2HeaJP95XtXhD65C4CZexNgUBiC9TGmqBKyCIVJK2sd9nHzhikSiAch8Wwjuo_zqU_L5te1YbfuVDi-0klnCyKqjCai8V8Td0IQ4yJaTAyO0DQNsnMKxayyxWs3N-dQ12C51wx1BNGm_Xx8Y3T_KfLU2lyam0RhEyl5D7S4cdtdITVqQMPjWVhxNb_iIz1PYP6VH3AKATOo5g4TuWXpz3WJcuATlSLCg-oW07pfdDCi2BTSL0kcBoe4SdrWcBCb8ja3xn3L-bMwVOB3-6L0G6uHC68Qp4zK0RQK_esZWb9L9nlbvqNDysVqX2w',
79
+ e: 'AQAB',
80
+ }),
81
+ Object.freeze({
82
+ kty: 'RSA',
83
+ kid: 'rgw-oidc-preview-2026-11-10',
84
+ alg: 'RS256',
85
+ use: 'sig',
86
+ n: 'wnlW_8K4tn3KDmpl6CHhsHnlewnbxMORijZal1Ft8f94Z_hrKQxV7uzl6xv-iYzc1vGh7SSWsTcctO1Hig489U78BZzIz07D1oHtl7NbVsncip8jV5E-EIhi6X159kzPKsj1PTSwihvEpN0x91GGHQORZKuQEPPN923kWN8omkia3Fr4sRwV79qXKm_Bp_jMWwX_7YklVaviyCiT0nQbxt9x289HyS1lOUhtu4jsha19L2tqSt7on1lYizSq5BHCBqHMd7hjlfiC2QWXu74mqUQil88VUFySUFQXndXodwvquSdga6vGBmfggfffQrS-Oh2IBdQln96--XnJWlszKw',
87
+ e: 'AQAB',
88
+ }),
89
+ ]),
90
+ });
91
+
92
+ /** Which deployment class signs or accepts a token. */
93
+ export type RuntimeGatewayOidcEnvironment = 'preview' | 'production';
94
+
95
+ /**
96
+ * The published kids each environment may sign with and accept. Disjoint, so
97
+ * a Preview private key can never produce a token a Production deployment
98
+ * accepts, and the reverse. Rotation adds the new kid to its environment
99
+ * here and to the JWKS above in the same change.
100
+ */
101
+ export const RUNTIME_GATEWAY_OIDC_ENVIRONMENT_KIDS: Readonly<
102
+ Record<RuntimeGatewayOidcEnvironment, readonly string[]>
103
+ > = Object.freeze({
104
+ production: Object.freeze(['rgw-oidc-2026-11-10']),
105
+ preview: Object.freeze(['rgw-oidc-preview-2026-11-10']),
106
+ });
107
+
108
+ /**
109
+ * This process's environment, from the same canonical test the internal
110
+ * capabilities use (`isTestOnlyRuntime`): anything that is not Production is
111
+ * Preview for this credential.
112
+ */
113
+ export function resolveRuntimeGatewayOidcEnvironment(): RuntimeGatewayOidcEnvironment {
114
+ return isTestOnlyRuntime() ? 'preview' : 'production';
115
+ }
116
+
117
+ /** Key material a caller trusts; defaults to the code-owned constants. */
118
+ export type RuntimeGatewayOidcTrust = Readonly<{
119
+ jwks: Readonly<{ keys: readonly RuntimeGatewayOidcPublicJwk[] }>;
120
+ environmentKids: Readonly<
121
+ Record<RuntimeGatewayOidcEnvironment, readonly string[]>
122
+ >;
123
+ }>;
124
+
125
+ export const RUNTIME_GATEWAY_OIDC_TRUST: RuntimeGatewayOidcTrust =
126
+ Object.freeze({
127
+ jwks: RUNTIME_GATEWAY_OIDC_PUBLIC_JWKS,
128
+ environmentKids: RUNTIME_GATEWAY_OIDC_ENVIRONMENT_KIDS,
129
+ });
130
+
131
+ function environmentJwk(
132
+ trust: RuntimeGatewayOidcTrust,
133
+ environment: RuntimeGatewayOidcEnvironment,
134
+ kid: string,
135
+ ): RuntimeGatewayOidcPublicJwk | null {
136
+ if (!trust.environmentKids[environment].includes(kid)) return null;
137
+ return trust.jwks.keys.find((candidate) => candidate.kid === kid) ?? null;
138
+ }
139
+
140
+ export type RuntimeGatewayOidcClaims = {
141
+ iss: string;
142
+ aud: string;
143
+ sub: string;
144
+ deployment_id: string;
145
+ run_id: string;
146
+ run_attempt: number;
147
+ deepline_env: RuntimeGatewayOidcEnvironment;
148
+ iat: number;
149
+ exp: number;
150
+ };
151
+
152
+ export type RuntimeGatewayOidcSigningKey = Readonly<{
153
+ kid: string;
154
+ /** Base64 DER PKCS#8 RSA private key. */
155
+ privateKeyPkcs8Base64: string;
156
+ }>;
157
+
158
+ export class RuntimeGatewayOidcError extends Error {
159
+ constructor(
160
+ readonly code:
161
+ | 'signing_key_unavailable'
162
+ | 'signing_key_invalid'
163
+ | 'signing_key_not_published'
164
+ | 'claims_invalid',
165
+ message: string,
166
+ ) {
167
+ super(message);
168
+ this.name = 'RuntimeGatewayOidcError';
169
+ }
170
+ }
171
+
172
+ /** Read the secret signing key. Missing or partial configuration is null. */
173
+ export function resolveRuntimeGatewayOidcSigningKey(
174
+ env: Readonly<Record<string, string | undefined>>,
175
+ ): RuntimeGatewayOidcSigningKey | null {
176
+ const privateKeyPkcs8Base64 =
177
+ env[RUNTIME_GATEWAY_OIDC_PRIVATE_KEY_ENV]?.trim();
178
+ const kid = env[RUNTIME_GATEWAY_OIDC_KID_ENV]?.trim();
179
+ if (!privateKeyPkcs8Base64 || !kid) return null;
180
+ return { kid, privateKeyPkcs8Base64 };
181
+ }
182
+
183
+ function rsaPrivateKey(signingKey: RuntimeGatewayOidcSigningKey): KeyObject {
184
+ let key: KeyObject;
185
+ try {
186
+ key = createPrivateKey({
187
+ key: Buffer.from(signingKey.privateKeyPkcs8Base64, 'base64'),
188
+ format: 'der',
189
+ type: 'pkcs8',
190
+ });
191
+ } catch {
192
+ throw new RuntimeGatewayOidcError(
193
+ 'signing_key_invalid',
194
+ 'Runtime gateway OIDC signing key is not a PKCS#8 private key.',
195
+ );
196
+ }
197
+ if (
198
+ key.asymmetricKeyType !== 'rsa' ||
199
+ (key.asymmetricKeyDetails?.modulusLength ?? 0) < 2048
200
+ ) {
201
+ throw new RuntimeGatewayOidcError(
202
+ 'signing_key_invalid',
203
+ 'Runtime gateway OIDC signing key must be RSA with at least 2048 bits.',
204
+ );
205
+ }
206
+ return key;
207
+ }
208
+
209
+ function encodeSegment(value: object): string {
210
+ return Buffer.from(JSON.stringify(value)).toString('base64url');
211
+ }
212
+
213
+ /**
214
+ * Refuse to sign unless `kid` is published for this environment and the
215
+ * private key's public half is exactly that published key. A wrong or
216
+ * stale secret fails here, loudly, instead of minting tokens every gateway
217
+ * rejects.
218
+ */
219
+ function assertSigningKeyPublished(
220
+ signingKey: RuntimeGatewayOidcSigningKey,
221
+ key: KeyObject,
222
+ environment: RuntimeGatewayOidcEnvironment,
223
+ trust: RuntimeGatewayOidcTrust,
224
+ ): void {
225
+ const published = environmentJwk(trust, environment, signingKey.kid);
226
+ if (!published) {
227
+ throw new RuntimeGatewayOidcError(
228
+ 'signing_key_not_published',
229
+ `${RUNTIME_GATEWAY_OIDC_KID_ENV} "${signingKey.kid}" is not a published ${environment} Runtime gateway OIDC key id (published for ${environment}: ${trust.environmentKids[environment].join(', ') || 'none'}).`,
230
+ );
231
+ }
232
+ const derived = createPublicKey(key).export({ format: 'jwk' });
233
+ if (derived.n !== published.n || derived.e !== published.e) {
234
+ throw new RuntimeGatewayOidcError(
235
+ 'signing_key_not_published',
236
+ `${RUNTIME_GATEWAY_OIDC_PRIVATE_KEY_ENV} does not match the published ${environment} key "${signingKey.kid}".`,
237
+ );
238
+ }
239
+ }
240
+
241
+ export function mintRuntimeGatewayOidcToken(input: {
242
+ signingKey: RuntimeGatewayOidcSigningKey;
243
+ deploymentId: string;
244
+ runId: string;
245
+ attempt: number;
246
+ nowMs: number;
247
+ /** Defaults to this process's environment. */
248
+ environment?: RuntimeGatewayOidcEnvironment;
249
+ /** Defaults to the code-owned keys. */
250
+ trust?: RuntimeGatewayOidcTrust;
251
+ }): string {
252
+ if (
253
+ !isRuntimeGatewayDeploymentId(input.deploymentId) ||
254
+ !input.runId.trim() ||
255
+ !Number.isSafeInteger(input.attempt) ||
256
+ input.attempt < 0 ||
257
+ !Number.isFinite(input.nowMs)
258
+ ) {
259
+ throw new RuntimeGatewayOidcError(
260
+ 'claims_invalid',
261
+ 'Runtime gateway OIDC claims are invalid.',
262
+ );
263
+ }
264
+ const environment =
265
+ input.environment ?? resolveRuntimeGatewayOidcEnvironment();
266
+ const key = rsaPrivateKey(input.signingKey);
267
+ assertSigningKeyPublished(
268
+ input.signingKey,
269
+ key,
270
+ environment,
271
+ input.trust ?? RUNTIME_GATEWAY_OIDC_TRUST,
272
+ );
273
+ const iat = Math.floor(input.nowMs / 1_000);
274
+ const claims: RuntimeGatewayOidcClaims = {
275
+ iss: RUNTIME_GATEWAY_OIDC_ISSUER,
276
+ aud: RUNTIME_GATEWAY_OIDC_AUDIENCE,
277
+ sub: RUNTIME_GATEWAY_OIDC_SUBJECT,
278
+ deployment_id: input.deploymentId,
279
+ run_id: input.runId,
280
+ run_attempt: input.attempt,
281
+ deepline_env: environment,
282
+ iat,
283
+ exp: iat + RUNTIME_GATEWAY_OIDC_MAX_AGE_SECONDS,
284
+ };
285
+ const signingInput = `${encodeSegment({
286
+ alg: 'RS256',
287
+ kid: input.signingKey.kid,
288
+ typ: 'JWT',
289
+ })}.${encodeSegment(claims)}`;
290
+ const signature = sign('RSA-SHA256', Buffer.from(signingInput), key);
291
+ return `${signingInput}.${signature.toString('base64url')}`;
292
+ }
293
+
294
+ function decodeSegment(segment: string): Record<string, unknown> | null {
295
+ try {
296
+ const value = JSON.parse(Buffer.from(segment, 'base64url').toString());
297
+ return value && typeof value === 'object' && !Array.isArray(value)
298
+ ? (value as Record<string, unknown>)
299
+ : null;
300
+ } catch {
301
+ return null;
302
+ }
303
+ }
304
+
305
+ function isTokenShape(token: unknown): token is string {
306
+ return (
307
+ typeof token === 'string' &&
308
+ token.length <= RUNTIME_GATEWAY_OIDC_MAX_TOKEN_LENGTH &&
309
+ /^[\w-]+\.[\w-]+\.[\w-]+$/.test(token)
310
+ );
311
+ }
312
+
313
+ /** Unverified claim read for schedulers deciding when to renew. */
314
+ export function readRuntimeGatewayOidcClaimsUnverified(
315
+ token: unknown,
316
+ ): RuntimeGatewayOidcClaims | null {
317
+ if (!isTokenShape(token)) return null;
318
+ const claims = decodeSegment(token.split('.')[1]!);
319
+ return claims && isClaimsShape(claims) ? claims : null;
320
+ }
321
+
322
+ function isClaimsShape(
323
+ claims: Record<string, unknown>,
324
+ ): claims is RuntimeGatewayOidcClaims {
325
+ return (
326
+ typeof claims.iss === 'string' &&
327
+ typeof claims.aud === 'string' &&
328
+ typeof claims.sub === 'string' &&
329
+ typeof claims.deployment_id === 'string' &&
330
+ typeof claims.run_id === 'string' &&
331
+ Number.isSafeInteger(claims.run_attempt) &&
332
+ (claims.deepline_env === 'preview' ||
333
+ claims.deepline_env === 'production') &&
334
+ Number.isSafeInteger(claims.iat) &&
335
+ Number.isSafeInteger(claims.exp)
336
+ );
337
+ }
338
+
339
+ export type RuntimeGatewayOidcVerification =
340
+ | { ok: true; claims: RuntimeGatewayOidcClaims }
341
+ | {
342
+ ok: false;
343
+ reason:
344
+ | 'malformed'
345
+ | 'unknown_key'
346
+ | 'bad_signature'
347
+ | 'wrong_issuer'
348
+ | 'wrong_audience'
349
+ | 'wrong_subject'
350
+ | 'wrong_scope'
351
+ | 'wrong_environment'
352
+ | 'expired'
353
+ | 'not_yet_valid'
354
+ | 'lifetime_too_long';
355
+ };
356
+
357
+ /**
358
+ * Verify a token for one exact deployment, run and attempt, in this
359
+ * deployment's environment: the kid must be one this environment trusts and
360
+ * the `deepline_env` claim must name it. `environment` defaults to this
361
+ * process's; `trust` defaults to the code-owned keys.
362
+ */
363
+ export function verifyRuntimeGatewayOidcToken(
364
+ token: unknown,
365
+ expected: { deploymentId: string; runId: string; attempt: number },
366
+ options: {
367
+ nowMs?: number;
368
+ environment?: RuntimeGatewayOidcEnvironment;
369
+ trust?: RuntimeGatewayOidcTrust;
370
+ } = {},
371
+ ): RuntimeGatewayOidcVerification {
372
+ if (!isTokenShape(token)) return { ok: false, reason: 'malformed' };
373
+ const [headerPart, claimsPart, signaturePart] = token.split('.') as [
374
+ string,
375
+ string,
376
+ string,
377
+ ];
378
+ const header = decodeSegment(headerPart);
379
+ const claims = decodeSegment(claimsPart);
380
+ if (
381
+ !header ||
382
+ !claims ||
383
+ header.alg !== 'RS256' ||
384
+ typeof header.kid !== 'string' ||
385
+ !isClaimsShape(claims)
386
+ ) {
387
+ return { ok: false, reason: 'malformed' };
388
+ }
389
+ const environment =
390
+ options.environment ?? resolveRuntimeGatewayOidcEnvironment();
391
+ const jwk = environmentJwk(
392
+ options.trust ?? RUNTIME_GATEWAY_OIDC_TRUST,
393
+ environment,
394
+ header.kid,
395
+ );
396
+ if (!jwk) return { ok: false, reason: 'unknown_key' };
397
+ let signatureValid = false;
398
+ try {
399
+ signatureValid = verify(
400
+ 'RSA-SHA256',
401
+ Buffer.from(`${headerPart}.${claimsPart}`),
402
+ createPublicKey({ key: jwk as JsonWebKey, format: 'jwk' }),
403
+ Buffer.from(signaturePart, 'base64url'),
404
+ );
405
+ } catch {
406
+ signatureValid = false;
407
+ }
408
+ if (!signatureValid) return { ok: false, reason: 'bad_signature' };
409
+ if (claims.iss !== RUNTIME_GATEWAY_OIDC_ISSUER)
410
+ return { ok: false, reason: 'wrong_issuer' };
411
+ if (claims.aud !== RUNTIME_GATEWAY_OIDC_AUDIENCE)
412
+ return { ok: false, reason: 'wrong_audience' };
413
+ if (claims.sub !== RUNTIME_GATEWAY_OIDC_SUBJECT)
414
+ return { ok: false, reason: 'wrong_subject' };
415
+ if (
416
+ claims.deployment_id !== expected.deploymentId ||
417
+ claims.run_id !== expected.runId ||
418
+ claims.run_attempt !== expected.attempt
419
+ ) {
420
+ return { ok: false, reason: 'wrong_scope' };
421
+ }
422
+ if (claims.deepline_env !== environment)
423
+ return { ok: false, reason: 'wrong_environment' };
424
+ if (claims.exp - claims.iat > RUNTIME_GATEWAY_OIDC_MAX_AGE_SECONDS)
425
+ return { ok: false, reason: 'lifetime_too_long' };
426
+ const now = Math.floor((options.nowMs ?? Date.now()) / 1_000);
427
+ if (claims.iat > now + RUNTIME_GATEWAY_OIDC_CLOCK_SKEW_SECONDS)
428
+ return { ok: false, reason: 'not_yet_valid' };
429
+ if (claims.exp <= now) return { ok: false, reason: 'expired' };
430
+ return { ok: true, claims };
431
+ }
432
+
433
+ /** Discovery document served at `${ISSUER}/.well-known/openid-configuration`. */
434
+ export function runtimeGatewayOidcDiscoveryDocument(): Readonly<{
435
+ issuer: string;
436
+ jwks_uri: string;
437
+ subject_types_supported: readonly string[];
438
+ id_token_signing_alg_values_supported: readonly string[];
439
+ response_types_supported: readonly string[];
440
+ claims_supported: readonly string[];
441
+ }> {
442
+ return {
443
+ issuer: RUNTIME_GATEWAY_OIDC_ISSUER,
444
+ jwks_uri: `${RUNTIME_GATEWAY_OIDC_ISSUER}${RUNTIME_GATEWAY_OIDC_JWKS_PATH}`,
445
+ subject_types_supported: ['public'],
446
+ id_token_signing_alg_values_supported: ['RS256'],
447
+ response_types_supported: ['id_token'],
448
+ claims_supported: [
449
+ 'iss',
450
+ 'aud',
451
+ 'sub',
452
+ 'iat',
453
+ 'exp',
454
+ 'deployment_id',
455
+ 'run_id',
456
+ 'run_attempt',
457
+ 'deepline_env',
458
+ ],
459
+ };
460
+ }
461
+
462
+ /** True once a token is old enough that the watchdog should renew it. */
463
+ export function shouldRenewRuntimeGatewayOidcToken(
464
+ token: unknown,
465
+ nowMs: number,
466
+ ): boolean {
467
+ const claims = readRuntimeGatewayOidcClaimsUnverified(token);
468
+ if (!claims) return true;
469
+ return nowMs / 1_000 >= claims.iat + RUNTIME_GATEWAY_OIDC_RENEW_AFTER_SECONDS;
470
+ }