@mycadet/gateway 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/Dockerfile +1 -0
  2. package/README.md +10 -10
  3. package/eslint.config.mjs +7 -8
  4. package/knip.json +2 -8
  5. package/node_modules/@mycadet/assistant-client/src/__tests__/assistant-client.test.ts +40 -34
  6. package/node_modules/@mycadet/assistant-client/src/http-client.ts +59 -8
  7. package/node_modules/@mycadet/assistant-client/src/index.ts +4 -0
  8. package/node_modules/@mycadet/assistant-client/src/proxy-forward.ts +5 -4
  9. package/node_modules/@mycadet/assistant-client/src/websocket-upstream.ts +21 -31
  10. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/package.json +18 -0
  11. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/endpoint.test.ts +36 -0
  12. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/endpoint.ts +142 -0
  13. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/index.ts +18 -0
  14. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/ipc-framing.ts +295 -0
  15. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/listen-options.ts +3 -0
  16. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.test.ts +444 -0
  17. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.ts +236 -0
  18. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/tsconfig.json +20 -0
  19. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
  20. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
  21. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
  22. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
  23. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
  24. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
  25. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
  26. package/node_modules/@mycadet/ces-client/package.json +7 -2
  27. package/node_modules/@mycadet/ces-client/src/index.ts +6 -0
  28. package/node_modules/@mycadet/ces-client/src/ipc-credentials.ts +363 -0
  29. package/node_modules/@mycadet/ces-client/src/log-export.ts +187 -0
  30. package/node_modules/@mycadet/ces-client/src/socket-path.ts +34 -0
  31. package/node_modules/@mycadet/ces-client/src/test-support.ts +280 -0
  32. package/node_modules/@mycadet/environments/package.json +0 -1
  33. package/node_modules/@mycadet/environments/src/index.ts +7 -19
  34. package/node_modules/@mycadet/environments/src/shell.test.ts +0 -45
  35. package/node_modules/@mycadet/environments/src/shell.ts +0 -50
  36. package/node_modules/@mycadet/environments/src/test-path-guard.ts +1 -1
  37. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
  38. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
  39. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
  40. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
  41. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
  42. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
  43. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
  44. package/node_modules/@mycadet/gateway-client/src/__tests__/gateway-client.test.ts +5 -5
  45. package/node_modules/@mycadet/gateway-client/src/__tests__/package-boundary.test.ts +1 -1
  46. package/node_modules/@mycadet/gateway-client/src/__tests__/status-contracts.test.ts +1 -20
  47. package/node_modules/@mycadet/gateway-client/src/admission-policy-contract.ts +1 -2
  48. package/node_modules/@mycadet/gateway-client/src/gateway-ipc-contracts.ts +0 -16
  49. package/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.test.ts +1 -1
  50. package/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
  51. package/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
  52. package/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
  53. package/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
  54. package/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
  55. package/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
  56. package/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
  57. package/package.json +15 -13
  58. package/scripts/generate-openapi.ts +24 -32
  59. package/src/__tests__/actor-token-revocation.test.ts +14 -7
  60. package/src/__tests__/auto-approve-conversation-thresholds.test.ts +16 -16
  61. package/src/__tests__/auto-approve-thresholds.test.ts +22 -20
  62. package/src/__tests__/binding-helpers.test.ts +9 -12
  63. package/src/__tests__/channel-admission-policy-routes.test.ts +20 -34
  64. package/src/__tests__/channel-permission-overrides-routes.test.ts +20 -26
  65. package/src/__tests__/channel-verification-session-proxy.test.ts +36 -22
  66. package/src/__tests__/cli-entry-init.test.ts +103 -0
  67. package/src/__tests__/config.test.ts +4 -5
  68. package/src/__tests__/contact-handlers.test.ts +8 -10
  69. package/src/__tests__/contact-prompt-submit.test.ts +3 -1
  70. package/src/__tests__/contact-record-submit.test.ts +3 -1
  71. package/src/__tests__/contact-rich-read.test.ts +11 -20
  72. package/src/__tests__/contact-store-bind-principal.test.ts +12 -15
  73. package/src/__tests__/contact-store-invites.test.ts +6 -6
  74. package/src/__tests__/contact-store-mark-channel-verified.test.ts +8 -10
  75. package/src/__tests__/contact-store-merge-contacts.test.ts +7 -10
  76. package/src/__tests__/contact-store-mirror-op-missing.test.ts +7 -11
  77. package/src/__tests__/contacts-control-plane-proxy.test.ts +3 -21
  78. package/src/__tests__/contacts-info-client.test.ts +6 -5
  79. package/src/__tests__/contacts-info-joiner.test.ts +8 -13
  80. package/src/__tests__/contacts-scoped-route-fallthrough.test.ts +14 -12
  81. package/src/__tests__/credential-cache.test.ts +1 -6
  82. package/src/__tests__/credential-reader.test.ts +146 -157
  83. package/src/__tests__/credential-requests.test.ts +1 -3
  84. package/src/__tests__/credential-watcher-cloud-bootstrap.test.ts +57 -104
  85. package/src/__tests__/data-migration-m0007-backfill-ingress-invites.test.ts +14 -17
  86. package/src/__tests__/data-migration-m0008-upsert-acl-columns-from-assistant.test.ts +10 -13
  87. package/src/__tests__/data-migration-m0009-invite-fields-backfill.test.ts +20 -19
  88. package/src/__tests__/data-migration-m0010-drop-assistant-ingress-invites.test.ts +12 -15
  89. package/src/__tests__/data-migration-m0013-verification-sessions-backfill.test.ts +20 -23
  90. package/src/__tests__/data-migration-m0014-drop-assistant-verification-tables.test.ts +12 -15
  91. package/src/__tests__/data-migration-m0015-guardian-requests-backfill.test.ts +6 -9
  92. package/src/__tests__/data-migration-m0016-drop-assistant-guardian-tables.test.ts +16 -19
  93. package/src/__tests__/data-migration-m0017-coerce-escalate-policy.test.ts +6 -10
  94. package/src/__tests__/db-connection-isolation.test.ts +1 -2
  95. package/src/__tests__/db-proxy-allowlist.test.ts +25 -16
  96. package/src/__tests__/desktop-stream-websocket.test.ts +34 -28
  97. package/src/__tests__/device-identity-text.test.ts +4 -6
  98. package/src/__tests__/devices-mine.test.ts +12 -11
  99. package/src/__tests__/devices.test.ts +60 -260
  100. package/src/__tests__/discord-verification-contact-upgrade.test.ts +10 -13
  101. package/src/__tests__/edge-auth.test.ts +10 -148
  102. package/src/__tests__/edge-guardian-auth.test.ts +60 -44
  103. package/src/__tests__/guardian-binding-channel-reuse.test.ts +16 -18
  104. package/src/__tests__/guardian-bootstrap-binding.test.ts +7 -8
  105. package/src/__tests__/guardian-bootstrap-lookups.test.ts +25 -27
  106. package/src/__tests__/guardian-delivery-resolver.test.ts +8 -12
  107. package/src/__tests__/guardian-pin.test.ts +3 -1
  108. package/src/__tests__/handle-inbound-admission.test.ts +3 -12
  109. package/src/__tests__/handle-inbound-app-context.test.ts +3 -6
  110. package/src/__tests__/handle-inbound-invite-intercept.test.ts +3 -6
  111. package/src/__tests__/handle-inbound-trust-verdict.test.ts +3 -12
  112. package/src/__tests__/helpers/contact-route-table.ts +53 -32
  113. package/src/__tests__/helpers/env.ts +19 -0
  114. package/src/__tests__/helpers/gateway-config.ts +32 -0
  115. package/src/__tests__/helpers/remote-web-pairing-fixtures.ts +1 -7
  116. package/src/__tests__/helpers/signing-key.ts +27 -0
  117. package/src/__tests__/inbound-contact-seed.test.ts +7 -8
  118. package/src/__tests__/invite-redemption-engine-voice.test.ts +2 -3
  119. package/src/__tests__/invite-route-auth.test.ts +17 -15
  120. package/src/__tests__/ipc-contact-routes.test.ts +11 -19
  121. package/src/__tests__/ipc-contact-threshold.test.ts +16 -9
  122. package/src/__tests__/ipc-invite-routes.test.ts +6 -5
  123. package/src/__tests__/ipc-server-multi-client.test.ts +8 -1
  124. package/src/__tests__/ipc-server-watchdog.test.ts +16 -6
  125. package/src/__tests__/ipc-slack-thread-routes.test.ts +1 -2
  126. package/src/__tests__/ipc-voice-invite-routes.test.ts +3 -5
  127. package/src/__tests__/live-voice-websocket.test.ts +103 -95
  128. package/src/__tests__/load-guards.test.ts +0 -1
  129. package/src/__tests__/logger-retention.test.ts +11 -9
  130. package/src/__tests__/lum-2783-recovery-e2e.test.ts +3 -1
  131. package/src/__tests__/m0006-reconcile-contacts.test.ts +10 -13
  132. package/src/__tests__/oauth-callback.test.ts +13 -5
  133. package/src/__tests__/pair-origin-allowlist.test.ts +4 -118
  134. package/src/__tests__/rate-limit-loopback.test.ts +1 -5
  135. package/src/__tests__/refresh-device-binding.test.ts +3 -1
  136. package/src/__tests__/remote-web-pairing-challenge.test.ts +71 -132
  137. package/src/__tests__/remote-web-pairing-token.test.ts +16 -140
  138. package/src/__tests__/remote-web-pairing-verification.test.ts +17 -1
  139. package/src/__tests__/remote-web-public-base-url.test.ts +79 -0
  140. package/src/__tests__/resolve-assistant.test.ts +0 -1
  141. package/src/__tests__/runtime-client.test.ts +9 -9
  142. package/src/__tests__/runtime-health-proxy.test.ts +19 -14
  143. package/src/__tests__/runtime-proxy-auth.test.ts +129 -63
  144. package/src/__tests__/runtime-proxy-catchall-methods.test.ts +152 -0
  145. package/src/__tests__/runtime-proxy-device-stamp.test.ts +31 -24
  146. package/src/__tests__/runtime-proxy-error-body.test.ts +28 -30
  147. package/src/__tests__/runtime-proxy.test.ts +66 -59
  148. package/src/__tests__/runtime-stream-test-utils.ts +14 -3
  149. package/src/__tests__/seed-admission-policy.test.ts +1 -10
  150. package/src/__tests__/shared-invite-redeem.test.ts +7 -20
  151. package/src/__tests__/shared-invite-registration.test.ts +0 -34
  152. package/src/__tests__/slack-control-plane-proxy.test.ts +29 -17
  153. package/src/__tests__/slack-display-name.test.ts +3 -6
  154. package/src/__tests__/slack-normalize.test.ts +0 -1
  155. package/src/__tests__/slack-reaction-normalize.test.ts +0 -1
  156. package/src/__tests__/slack-socket-mode-catchup.test.ts +1 -2
  157. package/src/__tests__/slack-socket-mode-group-dm.test.ts +2 -3
  158. package/src/__tests__/slack-socket-mode-liveness.test.ts +6 -29
  159. package/src/__tests__/slack-socket-mode-outbound-root.test.ts +2 -3
  160. package/src/__tests__/slack-socket-mode-thread-tracking.test.ts +2 -3
  161. package/src/__tests__/sleep-wake-detector.test.ts +52 -25
  162. package/src/__tests__/speech-relay-websocket.test.ts +108 -100
  163. package/src/__tests__/stt-stream-websocket.test.ts +62 -69
  164. package/src/__tests__/telegram-control-plane-proxy.test.ts +36 -19
  165. package/src/__tests__/telegram-normalize.test.ts +1 -1
  166. package/src/__tests__/telegram-webhook-drop-visibility.test.ts +2 -3
  167. package/src/__tests__/telegram-webhook-handler.test.ts +121 -68
  168. package/src/__tests__/telegram-webhook-manager.test.ts +70 -90
  169. package/src/__tests__/test-preload.ts +21 -3
  170. package/src/__tests__/text-verification-helpers.test.ts +1 -1
  171. package/src/__tests__/trust-rules-route-auth.test.ts +16 -26
  172. package/src/__tests__/trust-rules-routes.test.ts +22 -25
  173. package/src/__tests__/twilio-media-websocket.test.ts +61 -59
  174. package/src/__tests__/twilio-webhooks.test.ts +5 -6
  175. package/src/__tests__/unversioned-api-fallthrough.test.ts +86 -0
  176. package/src/__tests__/upgrade-policy.test.ts +161 -0
  177. package/src/__tests__/upstream-transport.test.ts +20 -15
  178. package/src/__tests__/vercel-route-auth.test.ts +22 -36
  179. package/src/__tests__/watch-stream-websocket.test.ts +84 -91
  180. package/src/__tests__/whatsapp-download.test.ts +0 -1
  181. package/src/__tests__/whatsapp-webhook.test.ts +3 -3
  182. package/src/attachments/ingest.test.ts +0 -1
  183. package/src/auth/guardian-bootstrap.ts +5 -12
  184. package/src/auth/guardian-refresh.ts +0 -2
  185. package/src/auth/token-exchange.ts +23 -57
  186. package/src/auth/token-service.ts +69 -22
  187. package/src/auth-rate-limiter.ts +6 -0
  188. package/src/channels/inbound-event.test.ts +54 -0
  189. package/src/channels/inbound-event.ts +29 -3
  190. package/src/channels/ingress-verification.ts +10 -3
  191. package/src/channels/plugin-inbound.test.ts +4 -3
  192. package/src/channels/types.ts +0 -2
  193. package/src/cli/__tests__/contacts.test.ts +83 -60
  194. package/src/cli/__tests__/pairing.test.ts +230 -48
  195. package/src/cli/contacts.ts +0 -130
  196. package/src/cli/index.ts +20 -34
  197. package/src/cli/pairing.ts +118 -59
  198. package/src/cli/program.ts +227 -0
  199. package/src/cloud-features.ts +13 -0
  200. package/src/cloud-identity.ts +1 -1
  201. package/src/config-file-cache.ts +6 -0
  202. package/src/config-file-utils.ts +1 -1
  203. package/src/config-file-watcher.ts +104 -0
  204. package/src/config.ts +25 -23
  205. package/src/credential-cache.ts +6 -0
  206. package/src/credential-reader.ts +53 -35
  207. package/src/credential-watcher.ts +219 -22
  208. package/src/db/__tests__/session-store.test.ts +2 -1
  209. package/src/db/admission-policy-store.ts +1 -2
  210. package/src/db/connection.ts +12 -4
  211. package/src/db/contact-store.ts +82 -0
  212. package/src/db/data-migrations/m0002-actor-token-tables-to-gateway.ts +2 -7
  213. package/src/db/schema.ts +15 -0
  214. package/src/db/seed-admission-policy.ts +1 -1
  215. package/src/db/seed-trust-rules.ts +1 -4
  216. package/src/db/session-store.ts +0 -6
  217. package/src/discord/admission-log-visibility.test.ts +2 -2
  218. package/src/discord/forward.test.ts +3 -6
  219. package/src/discord/forward.ts +4 -8
  220. package/src/discord/lifecycle.ts +104 -0
  221. package/src/email/normalize.ts +1 -1
  222. package/src/email/register-callback.test.ts +1 -2
  223. package/src/email/register-callback.ts +4 -11
  224. package/src/guardian-contract.ts +30 -0
  225. package/src/handlers/handle-inbound.ts +2 -2
  226. package/src/http/browser-auth-cookies.ts +27 -22
  227. package/src/http/edge-forwarded-header.ts +0 -39
  228. package/src/http/loopback-guard.ts +0 -47
  229. package/src/http/middleware/auth.ts +35 -188
  230. package/src/http/middleware/cors.test.ts +66 -0
  231. package/src/http/middleware/cors.ts +23 -2
  232. package/src/http/router.ts +188 -151
  233. package/src/http/routes/assistant-handle.test.ts +133 -0
  234. package/src/http/routes/assistant-handle.ts +94 -0
  235. package/src/http/routes/audio-proxy.ts +49 -39
  236. package/src/http/routes/auto-approve-thresholds.ts +308 -230
  237. package/src/http/routes/brain-graph-proxy.ts +61 -52
  238. package/src/http/routes/channel-admission-policy.ts +219 -154
  239. package/src/http/routes/channel-ingress.test.ts +24 -19
  240. package/src/http/routes/channel-ingress.ts +255 -137
  241. package/src/http/routes/channel-permission-overrides.ts +189 -112
  242. package/src/http/routes/channel-readiness-proxy.ts +66 -45
  243. package/src/http/routes/channel-verification-session-proxy.test.ts +33 -82
  244. package/src/http/routes/channel-verification-session-proxy.ts +100 -455
  245. package/src/http/routes/cloud-hop.ts +138 -0
  246. package/src/http/routes/cloud-push-proxy.test.ts +34 -33
  247. package/src/http/routes/cloud-push-proxy.ts +56 -127
  248. package/src/http/routes/contacts-control-plane-proxy.ts +0 -12
  249. package/src/http/routes/contacts-control-plane-route-table.ts +372 -119
  250. package/src/http/routes/credential-entry-page.ts +12 -0
  251. package/src/http/routes/credential-requests.ts +10 -4
  252. package/src/http/routes/desktop-setup-proxy.ts +21 -11
  253. package/src/http/routes/desktop-stream-websocket.ts +67 -41
  254. package/src/http/routes/devices-mine.ts +11 -0
  255. package/src/http/routes/devices.ts +7 -63
  256. package/src/http/routes/email-webhook.test.ts +4 -20
  257. package/src/http/routes/guardian-channel-create.test.ts +6 -9
  258. package/src/http/routes/guardian-pin.ts +1 -1
  259. package/src/http/routes/guardian-refresh.ts +65 -2
  260. package/src/http/routes/index.ts +88 -0
  261. package/src/http/routes/ingress-domains.test.ts +57 -2
  262. package/src/http/routes/ingress-domains.ts +46 -14
  263. package/src/http/routes/integrations-status.ts +18 -0
  264. package/src/http/routes/ipc-runtime-proxy.test.ts +31 -6
  265. package/src/http/routes/ipc-runtime-proxy.ts +6 -3
  266. package/src/http/routes/live-voice-websocket.ts +159 -148
  267. package/src/http/routes/log-export.test.ts +61 -87
  268. package/src/http/routes/log-export.ts +143 -150
  269. package/src/http/routes/log-tail.test.ts +49 -32
  270. package/src/http/routes/log-tail.ts +31 -21
  271. package/src/http/routes/migration-rollback-proxy.ts +38 -32
  272. package/src/http/routes/oauth-apps-proxy.ts +109 -62
  273. package/src/http/routes/oauth-providers-proxy.ts +60 -51
  274. package/src/http/routes/pair.ts +23 -346
  275. package/src/http/routes/plugin-webhook-websocket.test.ts +73 -77
  276. package/src/http/routes/plugin-webhook-websocket.ts +210 -215
  277. package/src/http/routes/plugin-webhook.test.ts +3 -1
  278. package/src/http/routes/plugin-webhook.ts +0 -3
  279. package/src/http/routes/ps.ts +25 -20
  280. package/src/http/routes/regex-to-openapi-path.ts +39 -0
  281. package/src/http/routes/remote-web-pairing-challenge.ts +35 -81
  282. package/src/http/routes/remote-web-pairing-routes.ts +39 -0
  283. package/src/http/routes/remote-web-pairing-token.ts +6 -11
  284. package/src/http/routes/remote-web-pairing-verification.ts +7 -7
  285. package/src/http/routes/runtime-audio-stream.ts +147 -147
  286. package/src/http/routes/runtime-health-proxy.ts +43 -32
  287. package/src/http/routes/runtime-proxy.ts +54 -20
  288. package/src/http/routes/shared-invite-redeem.ts +1 -7
  289. package/src/http/routes/slack-control-plane-proxy.ts +57 -46
  290. package/src/http/routes/speech-relay-websocket.ts +310 -270
  291. package/src/http/routes/stt-stream-websocket.ts +102 -107
  292. package/src/http/routes/telegram-control-plane-proxy.ts +87 -58
  293. package/src/http/routes/telegram-webhook.test.ts +3 -19
  294. package/src/http/routes/telegram-webhook.ts +3 -2
  295. package/src/http/routes/terminal.test.ts +165 -0
  296. package/src/http/routes/terminal.ts +123 -0
  297. package/src/http/routes/trust-rules.suggest.test.ts +14 -22
  298. package/src/http/routes/trust-rules.ts +432 -246
  299. package/src/http/routes/tunnel-status.ts +26 -13
  300. package/src/http/routes/twilio-control-plane-proxy.ts +105 -64
  301. package/src/http/routes/twilio-media-websocket.ts +157 -147
  302. package/src/http/routes/twilio-voice-webhook.test.ts +14 -43
  303. package/src/http/routes/types.ts +92 -10
  304. package/src/http/routes/upgrade-broadcast-proxy.ts +38 -32
  305. package/src/http/routes/upgrade-policy.ts +186 -0
  306. package/src/http/routes/user-profile.test.ts +129 -0
  307. package/src/http/routes/user-profile.ts +204 -0
  308. package/src/http/routes/vercel-control-plane-proxy.ts +74 -52
  309. package/src/http/routes/watch-stream-websocket.ts +99 -138
  310. package/src/http/routes/webhook-routes.ts +214 -0
  311. package/src/http/routes/whatsapp-webhook.test.ts +3 -19
  312. package/src/http/routes/whatsapp-webhook.ts +2 -1
  313. package/src/http/routes/workspace-commit-proxy.ts +38 -30
  314. package/src/index.ts +298 -2481
  315. package/src/ipc/__tests__/admission-policy-handlers.test.ts +4 -18
  316. package/src/ipc/__tests__/guardian-request-routes.test.ts +7 -3
  317. package/src/ipc/__tests__/invite-ipc-routes.test.ts +13 -5
  318. package/src/ipc/__tests__/verification-session-routes.test.ts +5 -3
  319. package/src/ipc/admission-policy-handlers.ts +2 -2
  320. package/src/ipc/channel-socket-health-handlers.test.ts +56 -41
  321. package/src/ipc/channel-socket-health-handlers.ts +41 -31
  322. package/src/ipc/credential-request-handlers.ts +43 -19
  323. package/src/ipc/log-tail-handlers.test.ts +8 -35
  324. package/src/ipc/log-tail-handlers.ts +8 -11
  325. package/src/ipc/risk-classification-handlers.test.ts +0 -3
  326. package/src/ipc/risk-classification-handlers.ts +4 -4
  327. package/src/ipc/routes.ts +37 -0
  328. package/src/ipc/server.ts +13 -43
  329. package/src/ipc/trust-rules-handlers.test.ts +1 -2
  330. package/src/ipc/tunnel-handlers.ts +18 -18
  331. package/src/ipc/webhook-route-handlers.test.ts +5 -27
  332. package/src/ipc/webhook-route-handlers.ts +35 -39
  333. package/src/logger.ts +6 -26
  334. package/src/paths.ts +4 -4
  335. package/src/remote-web/pairing-challenge-store.ts +6 -35
  336. package/src/remote-web/pairing-mint.ts +2 -6
  337. package/src/remote-web/public-base-url.ts +65 -0
  338. package/src/risk/admission-policy-cache.ts +5 -12
  339. package/src/risk/bash-risk-classifier.test.ts +5 -6
  340. package/src/risk/bash-risk-classifier.ts +0 -3
  341. package/src/risk/command-registry/commands/gateway.ts +2 -1
  342. package/src/risk/file-risk-classifier.test.ts +1 -8
  343. package/src/risk/project-boundary.test.ts +3 -1
  344. package/src/risk/shell-identity.ts +1 -4
  345. package/src/risk/shell-parser.ts +1 -5
  346. package/src/risk/skill-risk-classifier.ts +1 -2
  347. package/src/runtime/client.ts +33 -27
  348. package/src/schema.ts +725 -163
  349. package/src/slack/errors.ts +1 -2
  350. package/src/slack/lifecycle.ts +327 -0
  351. package/src/slack/message-schemas.ts +1 -1
  352. package/src/slack/slack-web.ts +0 -1
  353. package/src/slack/socket-mode.ts +1 -1
  354. package/src/sleep-wake-detector.ts +62 -33
  355. package/src/telegram/normalize.test.ts +1 -1
  356. package/src/telegram/normalize.ts +1 -1
  357. package/src/telegram/send.test.ts +3 -19
  358. package/src/telegram/webhook-manager.ts +16 -31
  359. package/src/tunnel/allowed-paths.test.ts +27 -65
  360. package/src/tunnel/allowed-paths.ts +2 -27
  361. package/src/tunnel/binary-websocket.ts +1 -2
  362. package/src/tunnel/bridge-utils.ts +3 -8
  363. package/src/tunnel/client.test.ts +80 -67
  364. package/src/tunnel/client.ts +36 -28
  365. package/src/tunnel/http-bridge.test.ts +13 -40
  366. package/src/tunnel/websocket-bridge.test.ts +11 -2
  367. package/src/tunnel/websocket-bridge.ts +3 -1
  368. package/src/twilio/webhook-sync-trigger.ts +4 -4
  369. package/src/twilio/webhook-sync.test.ts +1 -33
  370. package/src/twilio/webhook-sync.ts +0 -4
  371. package/src/verification/code-parsing.ts +0 -3
  372. package/src/verification/rate-limit-helpers.ts +6 -2
  373. package/src/verification/session-service.ts +1 -1
  374. package/src/verification/shared-invite-registration.ts +3 -13
  375. package/src/verification/text-verification.ts +1 -1
  376. package/src/whatsapp/normalize.ts +1 -1
  377. package/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -38
  378. package/node_modules/@mycadet/environments/src/seeds.ts +0 -99
  379. package/node_modules/@mycadet/environments/src/types.ts +0 -70
  380. package/openapi.json +0 -2325
  381. package/src/__tests__/feature-flag-defaults-sync.test.ts +0 -44
  382. package/src/__tests__/feature-flag-resolver.test.ts +0 -151
  383. package/src/__tests__/feature-flag-watcher-callback.test.ts +0 -63
  384. package/src/__tests__/feature-flags-route.test.ts +0 -764
  385. package/src/__tests__/guardian-init-lockfile.test.ts +0 -883
  386. package/src/__tests__/ipc-feature-flag-routes.test.ts +0 -240
  387. package/src/__tests__/pair-device-bound.test.ts +0 -296
  388. package/src/__tests__/remote-web-ingress-denylist.test.ts +0 -113
  389. package/src/__tests__/remote-web-pairing-requests.test.ts +0 -277
  390. package/src/__tests__/route-schema-guard.test.ts +0 -489
  391. package/src/cloud-user-id.ts +0 -12
  392. package/src/feature-flag-defaults.ts +0 -197
  393. package/src/feature-flag-env-overrides.test.ts +0 -166
  394. package/src/feature-flag-env-overrides.ts +0 -58
  395. package/src/feature-flag-registry.json +0 -506
  396. package/src/feature-flag-resolver.ts +0 -47
  397. package/src/feature-flag-store.ts +0 -115
  398. package/src/feature-flag-watcher.ts +0 -105
  399. package/src/http/routes/a2a-routes.test.ts +0 -146
  400. package/src/http/routes/a2a-routes.ts +0 -126
  401. package/src/http/routes/auto-approve-thresholds-routes.ts +0 -92
  402. package/src/http/routes/channel-admission-policy-routes.ts +0 -67
  403. package/src/http/routes/channel-ingress-routes.ts +0 -135
  404. package/src/http/routes/channel-permission-overrides-routes.ts +0 -92
  405. package/src/http/routes/contacts-control-plane-routes.ts +0 -278
  406. package/src/http/routes/feature-flags.ts +0 -185
  407. package/src/http/routes/remote-web-pairing-requests.ts +0 -123
  408. package/src/http/routes/trust-rules-routes.ts +0 -188
  409. package/src/ipc/feature-flag-handlers.ts +0 -63
  410. package/src/types.ts +0 -11
@@ -2,9 +2,13 @@ import type { OutgoingHttpHeaders } from "node:http";
2
2
 
3
3
  import { normalizeHttpPublicBaseUrl } from "@mycadet/service-contracts/ingress";
4
4
 
5
+ import { getGatewayInternalBaseUrl } from "../config.js";
5
6
  import type { GatewayConfig } from "../config.js";
7
+ import { getConfig } from "../config.js";
6
8
  import type { ConfigFileCache } from "../config-file-cache.js";
9
+ import { getConfigFileCache } from "../config-file-cache.js";
7
10
  import type { CredentialCache } from "../credential-cache.js";
11
+ import { getCredentials } from "../credential-cache.js";
8
12
  import { credentialKey } from "../credential-key.js";
9
13
  import { mutateConfigFile } from "../config-file-utils.js";
10
14
  import { getLogger } from "../logger.js";
@@ -33,7 +37,6 @@ import {
33
37
  TUNNEL_BINARY_WEBSOCKET_HEADER,
34
38
  } from "./binary-websocket.js";
35
39
  import { TunnelWebSocketBridge } from "./websocket-bridge.js";
36
- import { getIsCloud } from "../cloud-url.js";
37
40
 
38
41
  const log = getLogger("tunnel-client");
39
42
 
@@ -65,7 +68,7 @@ export type WebSocketConstructorWithOptions = {
65
68
  };
66
69
 
67
70
  export type TunnelClientOptions = {
68
- tunnelBaseUrl: string;
71
+ tunnelBaseUrl?: string;
69
72
  gatewayLoopbackBaseUrl: string;
70
73
  credentials: CredentialCache;
71
74
  configFile: ConfigFileCache;
@@ -230,7 +233,7 @@ export class TunnelClient {
230
233
  }
231
234
 
232
235
  start(): void {
233
- if (this.running) return;
236
+ if (this.running || !this.options.tunnelBaseUrl) return;
234
237
  this.running = true;
235
238
  this.lastPublicIngressDisabled = this.isPublicIngressDisabled();
236
239
  this.unsubscribeConfigInvalidation ??= this.options.configFile.onInvalidate(
@@ -238,13 +241,17 @@ export class TunnelClient {
238
241
  this.handleConfigInvalidated();
239
242
  },
240
243
  );
241
- this.startAsync().catch((err) => {
244
+ this.connect().catch((err) => {
242
245
  this.connecting = false;
243
246
  log.error({ err }, "Failed to start Tunnel client");
244
247
  this.scheduleReconnect();
245
248
  });
246
249
  }
247
250
 
251
+ isRunning(): boolean {
252
+ return this.running;
253
+ }
254
+
248
255
  async stop(): Promise<void> {
249
256
  this.running = false;
250
257
  this.connecting = false;
@@ -270,11 +277,6 @@ export class TunnelClient {
270
277
  }
271
278
  }
272
279
 
273
- private async startAsync(): Promise<void> {
274
- await clearManagedPublicBaseUrl(this.options.configFile);
275
- await this.connect();
276
- }
277
-
278
280
  /**
279
281
  * A registry read failure must never block the tunnel: fall back to an
280
282
  * empty path list, which the header builder turns into legacy or
@@ -293,7 +295,8 @@ export class TunnelClient {
293
295
  }
294
296
 
295
297
  private async connect(): Promise<void> {
296
- if (!this.running || this.connecting) {
298
+ const { tunnelBaseUrl } = this.options;
299
+ if (!this.running || this.connecting || !tunnelBaseUrl) {
297
300
  return;
298
301
  }
299
302
  this.connecting = true;
@@ -341,7 +344,7 @@ export class TunnelClient {
341
344
 
342
345
  let registerUrl: string;
343
346
  try {
344
- registerUrl = buildRegisterWebSocketUrl(this.options.tunnelBaseUrl);
347
+ registerUrl = buildRegisterWebSocketUrl(tunnelBaseUrl);
345
348
  } catch (err) {
346
349
  this.connecting = false;
347
350
  log.error({ err }, "Invalid Tunnel base URL");
@@ -792,22 +795,10 @@ export function createTunnelClient(
792
795
  credentials: CredentialCache;
793
796
  configFile: ConfigFileCache;
794
797
  },
795
- ): TunnelClient | undefined {
796
- if (!config.tunnelBaseUrl) {
797
- const isCloud = getIsCloud();
798
- if (isCloud) {
799
- log.warn(
800
- "TUNNEL_BASE_URL is not configured on a cloud pod — the assistant tunnel will not be established and inbound webhook delivery will fail",
801
- );
802
- }
803
- void clearManagedPublicBaseUrl(deps.configFile).catch((err) => {
804
- log.error({ err }, "Failed to clear disabled Tunnel public URL");
805
- });
806
- return undefined;
807
- }
798
+ ): TunnelClient {
808
799
  return new TunnelClient({
809
800
  tunnelBaseUrl: config.tunnelBaseUrl,
810
- gatewayLoopbackBaseUrl: config.gatewayInternalBaseUrl,
801
+ gatewayLoopbackBaseUrl: getGatewayInternalBaseUrl(),
811
802
  credentials: deps.credentials,
812
803
  configFile: deps.configFile,
813
804
  });
@@ -847,21 +838,22 @@ const TUNNEL_MANAGED_BY = "tunnel";
847
838
  export async function writeManagedPublicBaseUrl(
848
839
  publicUrl: string,
849
840
  configFile: ConfigFileCache,
841
+ managedBy: string = TUNNEL_MANAGED_BY,
850
842
  ): Promise<void> {
851
843
  return mutateGatewayConfigFile(
852
844
  configFile,
853
- "Cannot publish Tunnel public URL because config.json is malformed",
845
+ "Cannot publish the public URL because config.json is malformed",
854
846
  (data) => {
855
847
  const ingress = getMutableIngress(data);
856
848
  if (
857
849
  ingress.publicBaseUrl === publicUrl &&
858
- ingress.publicBaseUrlManagedBy === TUNNEL_MANAGED_BY
850
+ ingress.publicBaseUrlManagedBy === managedBy
859
851
  ) {
860
852
  return false;
861
853
  }
862
854
 
863
855
  ingress.publicBaseUrl = publicUrl;
864
- ingress.publicBaseUrlManagedBy = TUNNEL_MANAGED_BY;
856
+ ingress.publicBaseUrlManagedBy = managedBy;
865
857
  data.ingress = ingress;
866
858
  return true;
867
859
  },
@@ -953,3 +945,19 @@ function buildRegisterWebSocketUrl(baseUrl: string): string {
953
945
  }
954
946
  return url.toString();
955
947
  }
948
+
949
+ let cachedTunnelClient: TunnelClient | undefined | null = null;
950
+ /**
951
+ * The process-wide tunnel client, built on first call from the singleton
952
+ * config/credential/config-file caches. Undefined when no tunnel is
953
+ * configured. The gateway server and the tunnel-status routes share it.
954
+ */
955
+ export function getTunnelClient(): TunnelClient {
956
+ if (!cachedTunnelClient) {
957
+ return (cachedTunnelClient = createTunnelClient(getConfig(), {
958
+ credentials: getCredentials(),
959
+ configFile: getConfigFileCache(),
960
+ }));
961
+ }
962
+ return cachedTunnelClient;
963
+ }
@@ -16,14 +16,8 @@ mock.module("../fetch.js", () => ({
16
16
  fetchImpl: (...args: Parameters<FetchFn>) => fetchMock(...args),
17
17
  }));
18
18
 
19
- let tunnelWebhooksFlagEnabled = false;
20
19
  let registeredWebhookPaths = new Set<string>();
21
20
 
22
- mock.module("../feature-flag-resolver.js", () => ({
23
- isFeatureFlagEnabled: (key: string) =>
24
- key === "tunnel-webhooks" ? tunnelWebhooksFlagEnabled : false,
25
- }));
26
-
27
21
  mock.module("../db/webhook-ingress-route-store.js", () => ({
28
22
  hasWebhookIngressRoute: (path: string) => registeredWebhookPaths.has(path),
29
23
  }));
@@ -34,7 +28,6 @@ const TWILIO_EXAMPLE_PATH = "/webhooks/twilio/example";
34
28
 
35
29
  afterEach(() => {
36
30
  fetchMock = mock(async () => new Response());
37
- tunnelWebhooksFlagEnabled = false;
38
31
  registeredWebhookPaths = new Set();
39
32
  });
40
33
 
@@ -325,23 +318,7 @@ describe("Tunnel HTTP bridge webhook ingress registry", () => {
325
318
  "/v1/credential-requests/submit",
326
319
  ];
327
320
 
328
- test("flag off: a registered webhook path is still rejected", async () => {
329
- registeredWebhookPaths = new Set(["/webhooks/telegram"]);
330
- fetchMock = mock(async () => {
331
- throw new Error("should not fetch");
332
- });
333
-
334
- const response = await bridgeTunnelHttpRequest(
335
- makeFrame({ path: "/webhooks/telegram" }),
336
- "http://127.0.0.1:7830",
337
- );
338
-
339
- expect(fetchMock).not.toHaveBeenCalled();
340
- expect(response.status_code).toBe(502);
341
- });
342
-
343
- test("flag on: a registered webhook path is forwarded and its response relayed", async () => {
344
- tunnelWebhooksFlagEnabled = true;
321
+ test("a registered webhook path is forwarded and its response relayed", async () => {
345
322
  registeredWebhookPaths = new Set(["/webhooks/telegram"]);
346
323
  const captured: string[] = [];
347
324
  fetchMock = mock(async (input: string | URL | Request) => {
@@ -359,8 +336,7 @@ describe("Tunnel HTTP bridge webhook ingress registry", () => {
359
336
  expect(decodeBase64(response.body_base64)).toBe("handled");
360
337
  });
361
338
 
362
- test("flag on: an unregistered webhook path is rejected without contacting the loopback listener", async () => {
363
- tunnelWebhooksFlagEnabled = true;
339
+ test("an unregistered webhook path is rejected without contacting the loopback listener", async () => {
364
340
  registeredWebhookPaths = new Set(["/webhooks/telegram"]);
365
341
  fetchMock = mock(async () => {
366
342
  throw new Error("should not fetch");
@@ -380,20 +356,17 @@ describe("Tunnel HTTP bridge webhook ingress registry", () => {
380
356
  expect(fetchMock).not.toHaveBeenCalled();
381
357
  });
382
358
 
383
- test("static allowlist paths are forwarded regardless of the flag", async () => {
384
- for (const flagEnabled of [false, true]) {
385
- tunnelWebhooksFlagEnabled = flagEnabled;
386
- registeredWebhookPaths = new Set();
387
-
388
- for (const path of STATIC_PATHS) {
389
- fetchMock = mock(async () => new Response("ok", { status: 200 }));
390
- const response = await bridgeTunnelHttpRequest(
391
- makeFrame({ path }),
392
- "http://127.0.0.1:7830",
393
- );
394
- expect(fetchMock).toHaveBeenCalledTimes(1);
395
- expect(response.status_code).toBe(200);
396
- }
359
+ test("static allowlist paths are forwarded", async () => {
360
+ registeredWebhookPaths = new Set();
361
+
362
+ for (const path of STATIC_PATHS) {
363
+ fetchMock = mock(async () => new Response("ok", { status: 200 }));
364
+ const response = await bridgeTunnelHttpRequest(
365
+ makeFrame({ path }),
366
+ "http://127.0.0.1:7830",
367
+ );
368
+ expect(fetchMock).toHaveBeenCalledTimes(1);
369
+ expect(response.status_code).toBe(200);
397
370
  }
398
371
  });
399
372
  });
@@ -11,14 +11,23 @@ import {
11
11
  type TunnelWebSocketOpenFrame,
12
12
  } from "./protocol.js";
13
13
  import { FakeWebSocket } from "./test-fake-websocket.js";
14
- import { TunnelWebSocketBridge } from "./websocket-bridge.js";
14
+
15
+ // `isAllowedTunnelHttpPath` consults the webhook ingress registry for
16
+ // /webhooks/* paths before the static Twilio prefixes. These tests never
17
+ // register a route, so the registry reads empty and the prefixes keep
18
+ // applying — no gateway DB needed.
19
+ mock.module("../db/webhook-ingress-route-store.js", () => ({
20
+ hasWebhookIngressRoute: () => false,
21
+ }));
22
+
23
+ const { TunnelWebSocketBridge } = await import("./websocket-bridge.js");
15
24
 
16
25
  const WS_OPEN = WebSocket.OPEN;
17
26
 
18
27
  const OriginalWebSocket = globalThis.WebSocket;
19
28
  let fakeSocket: FakeWebSocket;
20
29
  let sentFrames: TunnelFrame[];
21
- let bridge: TunnelWebSocketBridge;
30
+ let bridge: InstanceType<typeof TunnelWebSocketBridge>;
22
31
  let WebSocketMock: ReturnType<typeof mock>;
23
32
 
24
33
  beforeEach(() => {
@@ -152,7 +152,9 @@ export class TunnelWebSocketBridge {
152
152
  });
153
153
  }
154
154
 
155
- message(frame: TunnelWebSocketMessageFrame | TunnelBinaryWebSocketFrame): void {
155
+ message(
156
+ frame: TunnelWebSocketMessageFrame | TunnelBinaryWebSocketFrame,
157
+ ): void {
156
158
  const connection = this.connections.get(frame.connection_id);
157
159
  if (!connection) return;
158
160
 
@@ -13,10 +13,10 @@ const TWILIO_ACCOUNT_SID_FIELD = "accountSid";
13
13
  * address the tunnel owns and can withdraw. Email callback re-registration
14
14
  * stays suppressed on that basis in every configuration.
15
15
  *
16
- * Telegram lifts the suppression while `tunnel-webhooks` is on, because the
17
- * published Tunnel URL is then the address Telegram is meant to point at and
18
- * this event is the only signal that it changed. That check lives at the call
19
- * site so this derivation stays a pure read of the event.
16
+ * Telegram still reconciles on this event, because the published Tunnel URL
17
+ * is the address Telegram is meant to point at and this event is the only
18
+ * signal that it changed. That check lives at the call site so this
19
+ * derivation stays a pure read of the event.
20
20
  */
21
21
  export function isOnlyTunnelPublicBaseUrlChange(
22
22
  event: ConfigChangeEvent,
@@ -32,7 +32,6 @@ mock.module("../fetch.js", () => ({
32
32
  fetchImpl: (...args: Parameters<FetchFn>) => fetchImpl(...args),
33
33
  }));
34
34
 
35
- let tunnelWebhooksEnabled = false;
36
35
  let claimedRoutes: { path: string; type: string; source?: string | null }[] =
37
36
  [];
38
37
  let claimError: Error | undefined;
@@ -56,19 +55,11 @@ mock.module("../db/webhook-ingress-route-store.js", () => ({
56
55
  },
57
56
  }));
58
57
 
59
- const actualFlagResolver = await import("../feature-flag-resolver.js");
60
- mock.module("../feature-flag-resolver.js", () => ({
61
- ...actualFlagResolver,
62
- isFeatureFlagEnabled: (flag: string) =>
63
- flag === "tunnel-webhooks" ? tunnelWebhooksEnabled : false,
64
- }));
65
-
66
58
  const { syncConfiguredTwilioPhoneNumberWebhooks } =
67
59
  await import("./webhook-sync.js");
68
60
 
69
61
  afterEach(() => {
70
62
  resetMockFetch();
71
- tunnelWebhooksEnabled = false;
72
63
  claimedRoutes = [];
73
64
  claimError = undefined;
74
65
  });
@@ -295,8 +286,7 @@ describe("syncConfiguredTwilioPhoneNumberWebhooks", () => {
295
286
  expect(getMockFetchCalls()).toEqual([]);
296
287
  });
297
288
 
298
- test("claims the voice and status paths before calling Twilio when the flag is on", async () => {
299
- tunnelWebhooksEnabled = true;
289
+ test("claims the voice and status paths before calling Twilio", async () => {
300
290
  mockTwilioLookupAndUpdate();
301
291
  let claimedBeforeTwilio: number | undefined;
302
292
  const realFetchImpl = fetchImpl;
@@ -329,29 +319,7 @@ describe("syncConfiguredTwilioPhoneNumberWebhooks", () => {
329
319
  expect(claimedBeforeTwilio).toBe(2);
330
320
  });
331
321
 
332
- test("claims nothing while the flag is off", async () => {
333
- mockTwilioLookupAndUpdate();
334
-
335
- await syncConfiguredTwilioPhoneNumberWebhooks(
336
- makeCaches({
337
- phoneNumber: PHONE_NUMBER,
338
- accountSid: ACCOUNT_SID,
339
- authToken: AUTH_TOKEN,
340
- publicBaseUrl: "https://generic.example.test",
341
- }),
342
- );
343
-
344
- expect(claimedRoutes).toEqual([]);
345
- const calls = getMockFetchCalls();
346
- expect(calls).toHaveLength(2);
347
- const body = new URLSearchParams(String(calls[1].init.body));
348
- expect(body.get("VoiceUrl")).toBe(
349
- "https://generic.example.test/webhooks/twilio/voice",
350
- );
351
- });
352
-
353
322
  test("syncs the provider anyway when a path claim fails", async () => {
354
- tunnelWebhooksEnabled = true;
355
323
  claimError = new Error("database disk image is malformed");
356
324
  mockTwilioLookupAndUpdate();
357
325
 
@@ -10,7 +10,6 @@ import type { ConfigFileCache } from "../config-file-cache.js";
10
10
  import type { CredentialCache } from "../credential-cache.js";
11
11
  import { credentialKey } from "../credential-key.js";
12
12
  import { registerWebhookIngressRoute } from "../db/webhook-ingress-route-store.js";
13
- import { isFeatureFlagEnabled } from "../feature-flag-resolver.js";
14
13
  import { fetchImpl } from "../fetch.js";
15
14
  import { getLogger } from "../logger.js";
16
15
 
@@ -49,9 +48,6 @@ function resolveEffectiveTwilioBaseUrl(
49
48
  * that fails is logged and the sync continues.
50
49
  */
51
50
  function claimTwilioWebhookIngressRoutes(phoneNumber: string): void {
52
- if (!isFeatureFlagEnabled("tunnel-webhooks")) {
53
- return;
54
- }
55
51
  for (const claim of TWILIO_WEBHOOK_CLAIMS) {
56
52
  try {
57
53
  registerWebhookIngressRoute({ ...claim, source: phoneNumber });
@@ -59,6 +59,3 @@ export function parseVerificationCode(content: string): string | undefined {
59
59
  // ---------------------------------------------------------------------------
60
60
  // Hashing
61
61
  // ---------------------------------------------------------------------------
62
-
63
- // Single-sourced from the shared contract; re-exported for existing callers.
64
- export { hashVerificationSecret } from "@mycadet/gateway-client";
@@ -50,7 +50,10 @@ export function getRateLimit(
50
50
  .get();
51
51
 
52
52
  return row
53
- ? { attemptTimestampsJson: row.attemptTimestampsJson, lockedUntil: row.lockedUntil }
53
+ ? {
54
+ attemptTimestampsJson: row.attemptTimestampsJson,
55
+ lockedUntil: row.lockedUntil,
56
+ }
54
57
  : null;
55
58
  }
56
59
 
@@ -136,7 +139,8 @@ export async function resetRateLimit(
136
139
  const now = Date.now();
137
140
 
138
141
  const gwDb = getGatewayDb();
139
- gwDb.update(gwRateLimits)
142
+ gwDb
143
+ .update(gwRateLimits)
140
144
  .set({
141
145
  attemptTimestampsJson: "[]",
142
146
  lockedUntil: null,
@@ -39,7 +39,7 @@ import { getGatewayDb } from "../db/connection.js";
39
39
  import type {
40
40
  IdentityBindingStatus,
41
41
  VerificationPurpose,
42
- } from "../db/session-store.js";
42
+ } from "@mycadet/gateway-client";
43
43
  import {
44
44
  claimBootstrapSession,
45
45
  consumeSession,
@@ -9,10 +9,6 @@ import { hashInviteToken } from "@mycadet/gateway-client";
9
9
  import { credentialKey } from "../credential-key.js";
10
10
  import { readCredentialResult } from "../credential-reader.js";
11
11
  import { fetchImpl } from "../fetch.js";
12
- import {
13
- areCloudFeaturesEnabled,
14
- isFeatureFlagEnabled,
15
- } from "../feature-flag-resolver.js";
16
12
  import { getLogger } from "../logger.js";
17
13
 
18
14
  const log = getLogger("shared-invite-registration");
@@ -20,7 +16,6 @@ const log = getLogger("shared-invite-registration");
20
16
  const SHARED_INVITE_CHANNEL = "cadet-shared";
21
17
  const SHARED_INVITE_REGISTRATION_PATH = "/v1/internal/shared-invites/";
22
18
 
23
- const TRUSTED_CONTACTS_FLAG = "cadet-trusted-contacts";
24
19
  const REGISTRATION_TIMEOUT_MS = 10_000;
25
20
 
26
21
  export type SharedInviteRegistrationResult =
@@ -51,20 +46,15 @@ async function readCloudCredential(
51
46
  /**
52
47
  * Register the invite's link-token hash and expiry with the cloud.
53
48
  *
54
- * Skipped for any channel other than `cadet-shared`, while the
55
- * trusted-contacts flag is off, when platform features are disabled, and when
56
- * no cloud credentials are configured.
49
+ * Skipped for any channel other than `cadet-shared`, when platform features
50
+ * are disabled, and when no cloud credentials are configured.
57
51
  */
58
52
  export async function registerSharedInvite(params: {
59
53
  sourceChannel: string;
60
54
  rawToken: string;
61
55
  expiresAt: number;
62
56
  }): Promise<SharedInviteRegistrationResult> {
63
- if (
64
- params.sourceChannel !== SHARED_INVITE_CHANNEL ||
65
- !isFeatureFlagEnabled(TRUSTED_CONTACTS_FLAG) ||
66
- !areCloudFeaturesEnabled()
67
- ) {
57
+ if (params.sourceChannel !== SHARED_INVITE_CHANNEL) {
68
58
  return { status: "skipped" };
69
59
  }
70
60
 
@@ -30,10 +30,10 @@ import {
30
30
  resolveCanonicalPrincipal,
31
31
  revokeExistingChannelGuardian,
32
32
  } from "./binding-helpers.js";
33
+ import { hashVerificationSecret } from "@mycadet/gateway-client";
33
34
  import {
34
35
  extractEmailReplyBody,
35
36
  parseVerificationCode,
36
- hashVerificationSecret,
37
37
  } from "./code-parsing.js";
38
38
  import {
39
39
  findContactChannelByAddress,
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  import { getLogger } from "../logger.js";
4
- import type { GatewayInboundEvent } from "../types.js";
4
+ import type { GatewayInboundEvent } from "../channels/inbound-event.js";
5
5
 
6
6
  // WhatsApp Cloud API webhook payloads are untrusted external input:
7
7
  // https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/payload-examples
@@ -1,38 +0,0 @@
1
- /**
2
- * Pins the environment-to-cloud-hub mapping in one place. Both consumers
3
- * (the Capacitor shell's `server.url` and the CLI remote-web edge's
4
- * `hubUrl`) read this helper, so this matrix is the single behavioral pin
5
- * for the served URLs.
6
- */
7
-
8
- import { describe, expect, test } from "bun:test";
9
-
10
- import { cloudAssistantHubUrl, SEEDS } from "../index.js";
11
-
12
- describe("cloudAssistantHubUrl", () => {
13
- test("cloud environments resolve to their own web origin", () => {
14
- expect(cloudAssistantHubUrl("production")).toBe(
15
- "https://mycadet.ai/assistant",
16
- );
17
- expect(cloudAssistantHubUrl("staging")).toBe(
18
- "https://staging.mycadet.ai/assistant",
19
- );
20
- });
21
-
22
- test("every other environment falls back to the dev SPA", () => {
23
- for (const name of ["dev", "test", "local", "unknown-env", undefined]) {
24
- expect(cloudAssistantHubUrl(name)).toBe(
25
- "https://dev.mycadet.ai/assistant",
26
- );
27
- }
28
- });
29
-
30
- test("cloud hub URLs derive from the seed web URLs", () => {
31
- for (const name of ["production", "staging"]) {
32
- expect(cloudAssistantHubUrl(name)).toBe(
33
- `${SEEDS[name].webUrl}/assistant`,
34
- );
35
- }
36
- expect(cloudAssistantHubUrl("local")).toBe(`${SEEDS.dev.webUrl}/assistant`);
37
- });
38
- });
@@ -1,99 +0,0 @@
1
- import type { EnvironmentDefinition, PortMap } from "./types.js";
2
-
3
- /**
4
- * Non-prod port blocks. Each environment gets a 1000-port window in the
5
- * 17000–21000 band. Within a block, services are spaced 100 apart so up to
6
- * 100 assistants can coexist without the scan (`findAvailablePort`) running
7
- * one service's range into the next. Band chosen to sit below Linux's
8
- * default ephemeral start (32768) and macOS's (49152), and away from the
9
- * 3000/5000/8000/9000 dev-tool swamp. Production keeps its legacy,
10
- * non-contiguous port set (7821/7830/6333/8090/8080/8765): cross-env
11
- * collision is the only problem this change targets, prod is unaffected
12
- * because only one env's assistants compete on a given machine, and
13
- * churning it would leave existing hatches on 7821 while new ones
14
- * allocated elsewhere.
15
- */
16
- function portBlock(base: number): PortMap {
17
- return {
18
- daemon: base,
19
- gateway: base + 100,
20
- qdrant: base + 200,
21
- ces: base + 300,
22
- outboundProxy: base + 400,
23
- tcp: base + 500,
24
- };
25
- }
26
-
27
- /**
28
- * Base URL of the cloud-hosted assistant SPA (the "hub") for a deployment
29
- * environment. The Capacitor mobile shell bakes this into native builds as
30
- * `server.url`, and the CLI's remote-web edge stamps it into the served
31
- * config as `hubUrl`, so the environment-to-hub mapping lives here exactly
32
- * once.
33
- *
34
- * Only the cloud deployments (production, staging) serve the hosted SPA at
35
- * their own web origin; every other environment (dev, test, local, unknown)
36
- * falls back to the dev SPA, whose host serves remote clients that cannot
37
- * reach a local or per-developer web URL.
38
- *
39
- * The `/assistant` suffix is deliberate: booting on the bare host lands on
40
- * the marketing page, whose CTA redirects to `mycadet.ai/assistant` and
41
- * bounces non-prod shells off their own host.
42
- *
43
- * NOTE: this module is loaded by Capacitor's single-file TS config loader
44
- * (via the `@mycadet/environments/seeds` subpath), which cannot follow the
45
- * package index's `.js`-suffixed runtime re-exports. Keep this file's
46
- * imports type-only so it stays loadable on its own.
47
- */
48
- export function cloudAssistantHubUrl(envName: string | undefined): string {
49
- const seed =
50
- envName === "production" || envName === "staging"
51
- ? SEEDS[envName]
52
- : SEEDS.dev;
53
- return `${seed.webUrl}/assistant`;
54
- }
55
-
56
- /**
57
- * Built-in environment definitions and the source of truth for the
58
- * set of known environment names.
59
- *
60
- * Custom environments via a user config file are a future phase — see the
61
- * "Coexisting environments" design doc. Until then, a call site that needs a
62
- * new environment must add it here and rebuild.
63
- */
64
- export const SEEDS: Record<string, EnvironmentDefinition> = {
65
- production: {
66
- name: "production",
67
- cloudUrl: "https://cloud.mycadet.ai",
68
- webUrl: "https://mycadet.ai",
69
- },
70
- staging: {
71
- name: "staging",
72
- cloudUrl: "https://staging-cloud.mycadet.ai",
73
- webUrl: "https://staging.mycadet.ai",
74
- portsOverride: portBlock(17000),
75
- },
76
- test: {
77
- name: "test",
78
- // Non-functional URL — used only by unit tests for URL resolution, never
79
- // hit in production.
80
- cloudUrl: "https://test-cloud.mycadet.ai",
81
- webUrl: "https://dev.mycadet.ai",
82
- portsOverride: portBlock(19000),
83
- },
84
- dev: {
85
- name: "dev",
86
- cloudUrl: "https://dev-cloud.mycadet.ai",
87
- webUrl: "https://dev.mycadet.ai",
88
- portsOverride: portBlock(18000),
89
- },
90
- local: {
91
- name: "local",
92
- cloudUrl: "http://localhost:8000",
93
- webUrl: "http://localhost:3000",
94
- // assistantCloudUrl: "http://host.docker.internal:8000",
95
- // ^ uncomment this once dockerized hatch path is live.
96
- // The assistant runs in a different network namespace than the host.
97
- portsOverride: portBlock(20000),
98
- },
99
- };