@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.
- package/Dockerfile +1 -0
- package/README.md +10 -10
- package/eslint.config.mjs +7 -8
- package/knip.json +2 -8
- package/node_modules/@mycadet/assistant-client/src/__tests__/assistant-client.test.ts +40 -34
- package/node_modules/@mycadet/assistant-client/src/http-client.ts +59 -8
- package/node_modules/@mycadet/assistant-client/src/index.ts +4 -0
- package/node_modules/@mycadet/assistant-client/src/proxy-forward.ts +5 -4
- package/node_modules/@mycadet/assistant-client/src/websocket-upstream.ts +21 -31
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/package.json +18 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/endpoint.test.ts +36 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/endpoint.ts +142 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/index.ts +18 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/ipc-framing.ts +295 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/listen-options.ts +3 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.test.ts +444 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.ts +236 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/tsconfig.json +20 -0
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
- package/node_modules/@mycadet/ces-client/package.json +7 -2
- package/node_modules/@mycadet/ces-client/src/index.ts +6 -0
- package/node_modules/@mycadet/ces-client/src/ipc-credentials.ts +363 -0
- package/node_modules/@mycadet/ces-client/src/log-export.ts +187 -0
- package/node_modules/@mycadet/ces-client/src/socket-path.ts +34 -0
- package/node_modules/@mycadet/ces-client/src/test-support.ts +280 -0
- package/node_modules/@mycadet/environments/package.json +0 -1
- package/node_modules/@mycadet/environments/src/index.ts +7 -19
- package/node_modules/@mycadet/environments/src/shell.test.ts +0 -45
- package/node_modules/@mycadet/environments/src/shell.ts +0 -50
- package/node_modules/@mycadet/environments/src/test-path-guard.ts +1 -1
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
- package/node_modules/@mycadet/gateway-client/src/__tests__/gateway-client.test.ts +5 -5
- package/node_modules/@mycadet/gateway-client/src/__tests__/package-boundary.test.ts +1 -1
- package/node_modules/@mycadet/gateway-client/src/__tests__/status-contracts.test.ts +1 -20
- package/node_modules/@mycadet/gateway-client/src/admission-policy-contract.ts +1 -2
- package/node_modules/@mycadet/gateway-client/src/gateway-ipc-contracts.ts +0 -16
- package/node_modules/@mycadet/ipc-server-utils/src/socket-watchdog.test.ts +1 -1
- package/node_modules/@mycadet/service-contracts/src/__tests__/contracts.test.ts +5 -2
- package/node_modules/@mycadet/service-contracts/src/__tests__/remote-web-pairing.test.ts +17 -14
- package/node_modules/@mycadet/service-contracts/src/channels.ts +0 -1
- package/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
- package/node_modules/@mycadet/service-contracts/src/ingress.ts +7 -3
- package/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +32 -70
- package/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
- package/package.json +15 -13
- package/scripts/generate-openapi.ts +24 -32
- package/src/__tests__/actor-token-revocation.test.ts +14 -7
- package/src/__tests__/auto-approve-conversation-thresholds.test.ts +16 -16
- package/src/__tests__/auto-approve-thresholds.test.ts +22 -20
- package/src/__tests__/binding-helpers.test.ts +9 -12
- package/src/__tests__/channel-admission-policy-routes.test.ts +20 -34
- package/src/__tests__/channel-permission-overrides-routes.test.ts +20 -26
- package/src/__tests__/channel-verification-session-proxy.test.ts +36 -22
- package/src/__tests__/cli-entry-init.test.ts +103 -0
- package/src/__tests__/config.test.ts +4 -5
- package/src/__tests__/contact-handlers.test.ts +8 -10
- package/src/__tests__/contact-prompt-submit.test.ts +3 -1
- package/src/__tests__/contact-record-submit.test.ts +3 -1
- package/src/__tests__/contact-rich-read.test.ts +11 -20
- package/src/__tests__/contact-store-bind-principal.test.ts +12 -15
- package/src/__tests__/contact-store-invites.test.ts +6 -6
- package/src/__tests__/contact-store-mark-channel-verified.test.ts +8 -10
- package/src/__tests__/contact-store-merge-contacts.test.ts +7 -10
- package/src/__tests__/contact-store-mirror-op-missing.test.ts +7 -11
- package/src/__tests__/contacts-control-plane-proxy.test.ts +3 -21
- package/src/__tests__/contacts-info-client.test.ts +6 -5
- package/src/__tests__/contacts-info-joiner.test.ts +8 -13
- package/src/__tests__/contacts-scoped-route-fallthrough.test.ts +14 -12
- package/src/__tests__/credential-cache.test.ts +1 -6
- package/src/__tests__/credential-reader.test.ts +146 -157
- package/src/__tests__/credential-requests.test.ts +1 -3
- package/src/__tests__/credential-watcher-cloud-bootstrap.test.ts +57 -104
- package/src/__tests__/data-migration-m0007-backfill-ingress-invites.test.ts +14 -17
- package/src/__tests__/data-migration-m0008-upsert-acl-columns-from-assistant.test.ts +10 -13
- package/src/__tests__/data-migration-m0009-invite-fields-backfill.test.ts +20 -19
- package/src/__tests__/data-migration-m0010-drop-assistant-ingress-invites.test.ts +12 -15
- package/src/__tests__/data-migration-m0013-verification-sessions-backfill.test.ts +20 -23
- package/src/__tests__/data-migration-m0014-drop-assistant-verification-tables.test.ts +12 -15
- package/src/__tests__/data-migration-m0015-guardian-requests-backfill.test.ts +6 -9
- package/src/__tests__/data-migration-m0016-drop-assistant-guardian-tables.test.ts +16 -19
- package/src/__tests__/data-migration-m0017-coerce-escalate-policy.test.ts +6 -10
- package/src/__tests__/db-connection-isolation.test.ts +1 -2
- package/src/__tests__/db-proxy-allowlist.test.ts +25 -16
- package/src/__tests__/desktop-stream-websocket.test.ts +34 -28
- package/src/__tests__/device-identity-text.test.ts +4 -6
- package/src/__tests__/devices-mine.test.ts +12 -11
- package/src/__tests__/devices.test.ts +60 -260
- package/src/__tests__/discord-verification-contact-upgrade.test.ts +10 -13
- package/src/__tests__/edge-auth.test.ts +10 -148
- package/src/__tests__/edge-guardian-auth.test.ts +60 -44
- package/src/__tests__/guardian-binding-channel-reuse.test.ts +16 -18
- package/src/__tests__/guardian-bootstrap-binding.test.ts +7 -8
- package/src/__tests__/guardian-bootstrap-lookups.test.ts +25 -27
- package/src/__tests__/guardian-delivery-resolver.test.ts +8 -12
- package/src/__tests__/guardian-pin.test.ts +3 -1
- package/src/__tests__/handle-inbound-admission.test.ts +3 -12
- package/src/__tests__/handle-inbound-app-context.test.ts +3 -6
- package/src/__tests__/handle-inbound-invite-intercept.test.ts +3 -6
- package/src/__tests__/handle-inbound-trust-verdict.test.ts +3 -12
- package/src/__tests__/helpers/contact-route-table.ts +53 -32
- package/src/__tests__/helpers/env.ts +19 -0
- package/src/__tests__/helpers/gateway-config.ts +32 -0
- package/src/__tests__/helpers/remote-web-pairing-fixtures.ts +1 -7
- package/src/__tests__/helpers/signing-key.ts +27 -0
- package/src/__tests__/inbound-contact-seed.test.ts +7 -8
- package/src/__tests__/invite-redemption-engine-voice.test.ts +2 -3
- package/src/__tests__/invite-route-auth.test.ts +17 -15
- package/src/__tests__/ipc-contact-routes.test.ts +11 -19
- package/src/__tests__/ipc-contact-threshold.test.ts +16 -9
- package/src/__tests__/ipc-invite-routes.test.ts +6 -5
- package/src/__tests__/ipc-server-multi-client.test.ts +8 -1
- package/src/__tests__/ipc-server-watchdog.test.ts +16 -6
- package/src/__tests__/ipc-slack-thread-routes.test.ts +1 -2
- package/src/__tests__/ipc-voice-invite-routes.test.ts +3 -5
- package/src/__tests__/live-voice-websocket.test.ts +103 -95
- package/src/__tests__/load-guards.test.ts +0 -1
- package/src/__tests__/logger-retention.test.ts +11 -9
- package/src/__tests__/lum-2783-recovery-e2e.test.ts +3 -1
- package/src/__tests__/m0006-reconcile-contacts.test.ts +10 -13
- package/src/__tests__/oauth-callback.test.ts +13 -5
- package/src/__tests__/pair-origin-allowlist.test.ts +4 -118
- package/src/__tests__/rate-limit-loopback.test.ts +1 -5
- package/src/__tests__/refresh-device-binding.test.ts +3 -1
- package/src/__tests__/remote-web-pairing-challenge.test.ts +71 -132
- package/src/__tests__/remote-web-pairing-token.test.ts +16 -140
- package/src/__tests__/remote-web-pairing-verification.test.ts +17 -1
- package/src/__tests__/remote-web-public-base-url.test.ts +79 -0
- package/src/__tests__/resolve-assistant.test.ts +0 -1
- package/src/__tests__/runtime-client.test.ts +9 -9
- package/src/__tests__/runtime-health-proxy.test.ts +19 -14
- package/src/__tests__/runtime-proxy-auth.test.ts +129 -63
- package/src/__tests__/runtime-proxy-catchall-methods.test.ts +152 -0
- package/src/__tests__/runtime-proxy-device-stamp.test.ts +31 -24
- package/src/__tests__/runtime-proxy-error-body.test.ts +28 -30
- package/src/__tests__/runtime-proxy.test.ts +66 -59
- package/src/__tests__/runtime-stream-test-utils.ts +14 -3
- package/src/__tests__/seed-admission-policy.test.ts +1 -10
- package/src/__tests__/shared-invite-redeem.test.ts +7 -20
- package/src/__tests__/shared-invite-registration.test.ts +0 -34
- package/src/__tests__/slack-control-plane-proxy.test.ts +29 -17
- package/src/__tests__/slack-display-name.test.ts +3 -6
- package/src/__tests__/slack-normalize.test.ts +0 -1
- package/src/__tests__/slack-reaction-normalize.test.ts +0 -1
- package/src/__tests__/slack-socket-mode-catchup.test.ts +1 -2
- package/src/__tests__/slack-socket-mode-group-dm.test.ts +2 -3
- package/src/__tests__/slack-socket-mode-liveness.test.ts +6 -29
- package/src/__tests__/slack-socket-mode-outbound-root.test.ts +2 -3
- package/src/__tests__/slack-socket-mode-thread-tracking.test.ts +2 -3
- package/src/__tests__/sleep-wake-detector.test.ts +52 -25
- package/src/__tests__/speech-relay-websocket.test.ts +108 -100
- package/src/__tests__/stt-stream-websocket.test.ts +62 -69
- package/src/__tests__/telegram-control-plane-proxy.test.ts +36 -19
- package/src/__tests__/telegram-normalize.test.ts +1 -1
- package/src/__tests__/telegram-webhook-drop-visibility.test.ts +2 -3
- package/src/__tests__/telegram-webhook-handler.test.ts +121 -68
- package/src/__tests__/telegram-webhook-manager.test.ts +70 -90
- package/src/__tests__/test-preload.ts +21 -3
- package/src/__tests__/text-verification-helpers.test.ts +1 -1
- package/src/__tests__/trust-rules-route-auth.test.ts +16 -26
- package/src/__tests__/trust-rules-routes.test.ts +22 -25
- package/src/__tests__/twilio-media-websocket.test.ts +61 -59
- package/src/__tests__/twilio-webhooks.test.ts +5 -6
- package/src/__tests__/unversioned-api-fallthrough.test.ts +86 -0
- package/src/__tests__/upgrade-policy.test.ts +161 -0
- package/src/__tests__/upstream-transport.test.ts +20 -15
- package/src/__tests__/vercel-route-auth.test.ts +22 -36
- package/src/__tests__/watch-stream-websocket.test.ts +84 -91
- package/src/__tests__/whatsapp-download.test.ts +0 -1
- package/src/__tests__/whatsapp-webhook.test.ts +3 -3
- package/src/attachments/ingest.test.ts +0 -1
- package/src/auth/guardian-bootstrap.ts +5 -12
- package/src/auth/guardian-refresh.ts +0 -2
- package/src/auth/token-exchange.ts +23 -57
- package/src/auth/token-service.ts +69 -22
- package/src/auth-rate-limiter.ts +6 -0
- package/src/channels/inbound-event.test.ts +54 -0
- package/src/channels/inbound-event.ts +29 -3
- package/src/channels/ingress-verification.ts +10 -3
- package/src/channels/plugin-inbound.test.ts +4 -3
- package/src/channels/types.ts +0 -2
- package/src/cli/__tests__/contacts.test.ts +83 -60
- package/src/cli/__tests__/pairing.test.ts +230 -48
- package/src/cli/contacts.ts +0 -130
- package/src/cli/index.ts +20 -34
- package/src/cli/pairing.ts +118 -59
- package/src/cli/program.ts +227 -0
- package/src/cloud-features.ts +13 -0
- package/src/cloud-identity.ts +1 -1
- package/src/config-file-cache.ts +6 -0
- package/src/config-file-utils.ts +1 -1
- package/src/config-file-watcher.ts +104 -0
- package/src/config.ts +25 -23
- package/src/credential-cache.ts +6 -0
- package/src/credential-reader.ts +53 -35
- package/src/credential-watcher.ts +219 -22
- package/src/db/__tests__/session-store.test.ts +2 -1
- package/src/db/admission-policy-store.ts +1 -2
- package/src/db/connection.ts +12 -4
- package/src/db/contact-store.ts +82 -0
- package/src/db/data-migrations/m0002-actor-token-tables-to-gateway.ts +2 -7
- package/src/db/schema.ts +15 -0
- package/src/db/seed-admission-policy.ts +1 -1
- package/src/db/seed-trust-rules.ts +1 -4
- package/src/db/session-store.ts +0 -6
- package/src/discord/admission-log-visibility.test.ts +2 -2
- package/src/discord/forward.test.ts +3 -6
- package/src/discord/forward.ts +4 -8
- package/src/discord/lifecycle.ts +104 -0
- package/src/email/normalize.ts +1 -1
- package/src/email/register-callback.test.ts +1 -2
- package/src/email/register-callback.ts +4 -11
- package/src/guardian-contract.ts +30 -0
- package/src/handlers/handle-inbound.ts +2 -2
- package/src/http/browser-auth-cookies.ts +27 -22
- package/src/http/edge-forwarded-header.ts +0 -39
- package/src/http/loopback-guard.ts +0 -47
- package/src/http/middleware/auth.ts +35 -188
- package/src/http/middleware/cors.test.ts +66 -0
- package/src/http/middleware/cors.ts +23 -2
- package/src/http/router.ts +188 -151
- package/src/http/routes/assistant-handle.test.ts +133 -0
- package/src/http/routes/assistant-handle.ts +94 -0
- package/src/http/routes/audio-proxy.ts +49 -39
- package/src/http/routes/auto-approve-thresholds.ts +308 -230
- package/src/http/routes/brain-graph-proxy.ts +61 -52
- package/src/http/routes/channel-admission-policy.ts +219 -154
- package/src/http/routes/channel-ingress.test.ts +24 -19
- package/src/http/routes/channel-ingress.ts +255 -137
- package/src/http/routes/channel-permission-overrides.ts +189 -112
- package/src/http/routes/channel-readiness-proxy.ts +66 -45
- package/src/http/routes/channel-verification-session-proxy.test.ts +33 -82
- package/src/http/routes/channel-verification-session-proxy.ts +100 -455
- package/src/http/routes/cloud-hop.ts +138 -0
- package/src/http/routes/cloud-push-proxy.test.ts +34 -33
- package/src/http/routes/cloud-push-proxy.ts +56 -127
- package/src/http/routes/contacts-control-plane-proxy.ts +0 -12
- package/src/http/routes/contacts-control-plane-route-table.ts +372 -119
- package/src/http/routes/credential-entry-page.ts +12 -0
- package/src/http/routes/credential-requests.ts +10 -4
- package/src/http/routes/desktop-setup-proxy.ts +21 -11
- package/src/http/routes/desktop-stream-websocket.ts +67 -41
- package/src/http/routes/devices-mine.ts +11 -0
- package/src/http/routes/devices.ts +7 -63
- package/src/http/routes/email-webhook.test.ts +4 -20
- package/src/http/routes/guardian-channel-create.test.ts +6 -9
- package/src/http/routes/guardian-pin.ts +1 -1
- package/src/http/routes/guardian-refresh.ts +65 -2
- package/src/http/routes/index.ts +88 -0
- package/src/http/routes/ingress-domains.test.ts +57 -2
- package/src/http/routes/ingress-domains.ts +46 -14
- package/src/http/routes/integrations-status.ts +18 -0
- package/src/http/routes/ipc-runtime-proxy.test.ts +31 -6
- package/src/http/routes/ipc-runtime-proxy.ts +6 -3
- package/src/http/routes/live-voice-websocket.ts +159 -148
- package/src/http/routes/log-export.test.ts +61 -87
- package/src/http/routes/log-export.ts +143 -150
- package/src/http/routes/log-tail.test.ts +49 -32
- package/src/http/routes/log-tail.ts +31 -21
- package/src/http/routes/migration-rollback-proxy.ts +38 -32
- package/src/http/routes/oauth-apps-proxy.ts +109 -62
- package/src/http/routes/oauth-providers-proxy.ts +60 -51
- package/src/http/routes/pair.ts +23 -346
- package/src/http/routes/plugin-webhook-websocket.test.ts +73 -77
- package/src/http/routes/plugin-webhook-websocket.ts +210 -215
- package/src/http/routes/plugin-webhook.test.ts +3 -1
- package/src/http/routes/plugin-webhook.ts +0 -3
- package/src/http/routes/ps.ts +25 -20
- package/src/http/routes/regex-to-openapi-path.ts +39 -0
- package/src/http/routes/remote-web-pairing-challenge.ts +35 -81
- package/src/http/routes/remote-web-pairing-routes.ts +39 -0
- package/src/http/routes/remote-web-pairing-token.ts +6 -11
- package/src/http/routes/remote-web-pairing-verification.ts +7 -7
- package/src/http/routes/runtime-audio-stream.ts +147 -147
- package/src/http/routes/runtime-health-proxy.ts +43 -32
- package/src/http/routes/runtime-proxy.ts +54 -20
- package/src/http/routes/shared-invite-redeem.ts +1 -7
- package/src/http/routes/slack-control-plane-proxy.ts +57 -46
- package/src/http/routes/speech-relay-websocket.ts +310 -270
- package/src/http/routes/stt-stream-websocket.ts +102 -107
- package/src/http/routes/telegram-control-plane-proxy.ts +87 -58
- package/src/http/routes/telegram-webhook.test.ts +3 -19
- package/src/http/routes/telegram-webhook.ts +3 -2
- package/src/http/routes/terminal.test.ts +165 -0
- package/src/http/routes/terminal.ts +123 -0
- package/src/http/routes/trust-rules.suggest.test.ts +14 -22
- package/src/http/routes/trust-rules.ts +432 -246
- package/src/http/routes/tunnel-status.ts +26 -13
- package/src/http/routes/twilio-control-plane-proxy.ts +105 -64
- package/src/http/routes/twilio-media-websocket.ts +157 -147
- package/src/http/routes/twilio-voice-webhook.test.ts +14 -43
- package/src/http/routes/types.ts +92 -10
- package/src/http/routes/upgrade-broadcast-proxy.ts +38 -32
- package/src/http/routes/upgrade-policy.ts +186 -0
- package/src/http/routes/user-profile.test.ts +129 -0
- package/src/http/routes/user-profile.ts +204 -0
- package/src/http/routes/vercel-control-plane-proxy.ts +74 -52
- package/src/http/routes/watch-stream-websocket.ts +99 -138
- package/src/http/routes/webhook-routes.ts +214 -0
- package/src/http/routes/whatsapp-webhook.test.ts +3 -19
- package/src/http/routes/whatsapp-webhook.ts +2 -1
- package/src/http/routes/workspace-commit-proxy.ts +38 -30
- package/src/index.ts +298 -2481
- package/src/ipc/__tests__/admission-policy-handlers.test.ts +4 -18
- package/src/ipc/__tests__/guardian-request-routes.test.ts +7 -3
- package/src/ipc/__tests__/invite-ipc-routes.test.ts +13 -5
- package/src/ipc/__tests__/verification-session-routes.test.ts +5 -3
- package/src/ipc/admission-policy-handlers.ts +2 -2
- package/src/ipc/channel-socket-health-handlers.test.ts +56 -41
- package/src/ipc/channel-socket-health-handlers.ts +41 -31
- package/src/ipc/credential-request-handlers.ts +43 -19
- package/src/ipc/log-tail-handlers.test.ts +8 -35
- package/src/ipc/log-tail-handlers.ts +8 -11
- package/src/ipc/risk-classification-handlers.test.ts +0 -3
- package/src/ipc/risk-classification-handlers.ts +4 -4
- package/src/ipc/routes.ts +37 -0
- package/src/ipc/server.ts +13 -43
- package/src/ipc/trust-rules-handlers.test.ts +1 -2
- package/src/ipc/tunnel-handlers.ts +18 -18
- package/src/ipc/webhook-route-handlers.test.ts +5 -27
- package/src/ipc/webhook-route-handlers.ts +35 -39
- package/src/logger.ts +6 -26
- package/src/paths.ts +4 -4
- package/src/remote-web/pairing-challenge-store.ts +6 -35
- package/src/remote-web/pairing-mint.ts +2 -6
- package/src/remote-web/public-base-url.ts +65 -0
- package/src/risk/admission-policy-cache.ts +5 -12
- package/src/risk/bash-risk-classifier.test.ts +5 -6
- package/src/risk/bash-risk-classifier.ts +0 -3
- package/src/risk/command-registry/commands/gateway.ts +2 -1
- package/src/risk/file-risk-classifier.test.ts +1 -8
- package/src/risk/project-boundary.test.ts +3 -1
- package/src/risk/shell-identity.ts +1 -4
- package/src/risk/shell-parser.ts +1 -5
- package/src/risk/skill-risk-classifier.ts +1 -2
- package/src/runtime/client.ts +33 -27
- package/src/schema.ts +725 -163
- package/src/slack/errors.ts +1 -2
- package/src/slack/lifecycle.ts +327 -0
- package/src/slack/message-schemas.ts +1 -1
- package/src/slack/slack-web.ts +0 -1
- package/src/slack/socket-mode.ts +1 -1
- package/src/sleep-wake-detector.ts +62 -33
- package/src/telegram/normalize.test.ts +1 -1
- package/src/telegram/normalize.ts +1 -1
- package/src/telegram/send.test.ts +3 -19
- package/src/telegram/webhook-manager.ts +16 -31
- package/src/tunnel/allowed-paths.test.ts +27 -65
- package/src/tunnel/allowed-paths.ts +2 -27
- package/src/tunnel/binary-websocket.ts +1 -2
- package/src/tunnel/bridge-utils.ts +3 -8
- package/src/tunnel/client.test.ts +80 -67
- package/src/tunnel/client.ts +36 -28
- package/src/tunnel/http-bridge.test.ts +13 -40
- package/src/tunnel/websocket-bridge.test.ts +11 -2
- package/src/tunnel/websocket-bridge.ts +3 -1
- package/src/twilio/webhook-sync-trigger.ts +4 -4
- package/src/twilio/webhook-sync.test.ts +1 -33
- package/src/twilio/webhook-sync.ts +0 -4
- package/src/verification/code-parsing.ts +0 -3
- package/src/verification/rate-limit-helpers.ts +6 -2
- package/src/verification/session-service.ts +1 -1
- package/src/verification/shared-invite-registration.ts +3 -13
- package/src/verification/text-verification.ts +1 -1
- package/src/whatsapp/normalize.ts +1 -1
- package/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -38
- package/node_modules/@mycadet/environments/src/seeds.ts +0 -99
- package/node_modules/@mycadet/environments/src/types.ts +0 -70
- package/openapi.json +0 -2325
- package/src/__tests__/feature-flag-defaults-sync.test.ts +0 -44
- package/src/__tests__/feature-flag-resolver.test.ts +0 -151
- package/src/__tests__/feature-flag-watcher-callback.test.ts +0 -63
- package/src/__tests__/feature-flags-route.test.ts +0 -764
- package/src/__tests__/guardian-init-lockfile.test.ts +0 -883
- package/src/__tests__/ipc-feature-flag-routes.test.ts +0 -240
- package/src/__tests__/pair-device-bound.test.ts +0 -296
- package/src/__tests__/remote-web-ingress-denylist.test.ts +0 -113
- package/src/__tests__/remote-web-pairing-requests.test.ts +0 -277
- package/src/__tests__/route-schema-guard.test.ts +0 -489
- package/src/cloud-user-id.ts +0 -12
- package/src/feature-flag-defaults.ts +0 -197
- package/src/feature-flag-env-overrides.test.ts +0 -166
- package/src/feature-flag-env-overrides.ts +0 -58
- package/src/feature-flag-registry.json +0 -506
- package/src/feature-flag-resolver.ts +0 -47
- package/src/feature-flag-store.ts +0 -115
- package/src/feature-flag-watcher.ts +0 -105
- package/src/http/routes/a2a-routes.test.ts +0 -146
- package/src/http/routes/a2a-routes.ts +0 -126
- package/src/http/routes/auto-approve-thresholds-routes.ts +0 -92
- package/src/http/routes/channel-admission-policy-routes.ts +0 -67
- package/src/http/routes/channel-ingress-routes.ts +0 -135
- package/src/http/routes/channel-permission-overrides-routes.ts +0 -92
- package/src/http/routes/contacts-control-plane-routes.ts +0 -278
- package/src/http/routes/feature-flags.ts +0 -185
- package/src/http/routes/remote-web-pairing-requests.ts +0 -123
- package/src/http/routes/trust-rules-routes.ts +0 -188
- package/src/ipc/feature-flag-handlers.ts +0 -63
- package/src/types.ts +0 -11
package/Dockerfile
CHANGED
|
@@ -18,6 +18,7 @@ COPY --parents clients/*/package.json ./
|
|
|
18
18
|
COPY cli/package.json ./cli/
|
|
19
19
|
COPY gateway/package.json ./gateway/
|
|
20
20
|
COPY credential-executor/package.json ./credential-executor/
|
|
21
|
+
COPY qa/package.json ./qa/
|
|
21
22
|
COPY assistant/package.json ./assistant/
|
|
22
23
|
COPY assistant/src/api/package.json ./assistant/src/api/
|
|
23
24
|
COPY --parents packages/*/package.json ./
|
package/README.md
CHANGED
|
@@ -26,11 +26,11 @@ bun run dev
|
|
|
26
26
|
|
|
27
27
|
## Configuration
|
|
28
28
|
|
|
29
|
-
| Variable | Required | Default | Description
|
|
30
|
-
| ------------------------- | -------- | ------- |
|
|
29
|
+
| Variable | Required | Default | Description |
|
|
30
|
+
| ------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
31
|
| `TELEGRAM_BOT_TOKEN` | No | — | Bot token from @BotFather (Telegram disabled when unset). When not set as an env var, the gateway reads from the assistant's secure credential store: CES HTTP API first (when `CES_CREDENTIAL_URL` is configured), then the encrypted file store (`~/.cadet/protected/keys.enc`). |
|
|
32
|
-
| `TELEGRAM_WEBHOOK_SECRET` | No | — | Secret for verifying webhook requests (Telegram disabled when unset). Same credential reader fallback behavior as `TELEGRAM_BOT_TOKEN`.
|
|
33
|
-
| `GATEWAY_PORT` | No | `7830` | Port for the gateway HTTP server
|
|
32
|
+
| `TELEGRAM_WEBHOOK_SECRET` | No | — | Secret for verifying webhook requests (Telegram disabled when unset). Same credential reader fallback behavior as `TELEGRAM_BOT_TOKEN`. |
|
|
33
|
+
| `GATEWAY_PORT` | No | `7830` | Port for the gateway HTTP server |
|
|
34
34
|
|
|
35
35
|
Most gateway behavior is now configured via hardcoded defaults or workspace config (`$CADET_WORKSPACE_DIR/config.json`) rather than environment variables. Channel operational settings (Telegram API base URL, timeouts, deliver auth bypass flags, runtime base URL, routing, proxy settings, attachment limits, shutdown drain) are managed via `workspace/config.json` through `ConfigFileCache`. See the channel-specific sections in `ARCHITECTURE.md` for details.
|
|
36
36
|
|
|
@@ -48,7 +48,7 @@ Routing is configured via workspace config. See `ARCHITECTURE.md` for details.
|
|
|
48
48
|
|
|
49
49
|
Webhook registration is now handled automatically by the gateway. On startup, the gateway reconciles the Telegram webhook by registering it at `${ingress.publicBaseUrl}/webhooks/telegram` with the configured secret and allowed updates. This also runs whenever the credential watcher detects changes to the bot token or webhook secret (e.g., secret rotation). If the ingress URL changes (e.g., tunnel restart), the config file watcher detects the change and triggers webhook reconciliation directly — no daemon involvement or gateway restart is needed.
|
|
50
50
|
|
|
51
|
-
A managed platform pod owns no ingress of its own, so with the `tunnel-webhooks` flag off it registers a
|
|
51
|
+
A managed platform pod owns no ingress of its own, so with the `tunnel-webhooks` flag off it registers a cloud-hosted callback route instead of using an ingress URL. With the flag on, a pod claims `/webhooks/telegram` in the webhook ingress route registry and registers its published Tunnel URL, keeping the cloud callback route as the fallback; flipping the flag re-runs the reconcile in either direction. See [`ARCHITECTURE.md`](ARCHITECTURE.md) for the full resolution order.
|
|
52
52
|
|
|
53
53
|
For manual setup (or reference), register the webhook with Telegram using the `setWebhook` API method. Pass:
|
|
54
54
|
|
|
@@ -127,7 +127,7 @@ The gateway does not send approval prompts. The assistant's Telegram transport (
|
|
|
127
127
|
|
|
128
128
|
The gateway serves as the single public ingress point for all external callbacks. The following routes are handled directly by the gateway before any proxy forwarding:
|
|
129
129
|
|
|
130
|
-
Control-plane routes are listed with their flat paths. Clients emit assistant-scoped URLs (`/v1/assistants/{id}/...`) because multi-tenant cloud routing needs the id; the deployment boundary strips the prefix before the request reaches the gateway — cloud's
|
|
130
|
+
Control-plane routes are listed with their flat paths. Clients emit assistant-scoped URLs (`/v1/assistants/{id}/...`) because multi-tenant cloud routing needs the id; the deployment boundary strips the prefix before the request reaches the gateway — cloud's runtime proxy strips it for every route, and the self-hosted web client's ingress rewrite (`rewriteForSelfHostedIngress` in `clients/web/src/lib/api-interceptors.ts`) flattens the contact family (`contacts`, `contact-channels`) while forwarding other segments scoped, verbatim. Contacts are therefore served flat-only, while gateway-global families that self-hosted clients still reach with scoped paths (trust-rules, channel-admission-policy, channel-permission-overrides, backups) also register assistant-scoped variants that match and discard the id. The flattening spans the whole `contacts`/`contact-channels` segment family: self-hosted invites requests land on the gateway's flat edge-scoped invite routes (the same invite engine the assistant relays to), and assistant-only subpaths (`contacts/search`, `contacts/prompt`) fall through the runtime-proxy catch-all to the assistant verbatim. Never remove a flat control-plane route — the flat family is the load-bearing cloud path.
|
|
131
131
|
|
|
132
132
|
| Route | Method | Description |
|
|
133
133
|
| ----------------------------------------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -156,7 +156,7 @@ Control-plane routes are listed with their flat paths. Clients emit assistant-sc
|
|
|
156
156
|
| `/v1/contacts/invites/:id` | DELETE | Gateway-native invite revoke |
|
|
157
157
|
| `/v1/contacts/invites/:id/call` | POST | Gateway-native invite-call relay — validates the invite row, then delegates the provider call to the assistant |
|
|
158
158
|
| `/v1/contacts/invites/redeem` | POST | Gateway-native invite redemption (voice code and link token) |
|
|
159
|
-
| `/v1/shared/invites/redeem` | POST | Unauthenticated `cadet-shared` invite redemption for a contact principal and token pair
|
|
159
|
+
| `/v1/shared/invites/redeem` | POST | Unauthenticated `cadet-shared` invite redemption for a contact principal and token pair |
|
|
160
160
|
| `/v1/health` | GET | Authenticated runtime health proxy (`/v1/health` on runtime) |
|
|
161
161
|
| `/healthz` | GET | Liveness probe |
|
|
162
162
|
| `/readyz` | GET | Readiness probe |
|
|
@@ -168,7 +168,7 @@ Which of the `/webhooks/*` routes above an assistant actually answers through th
|
|
|
168
168
|
|
|
169
169
|
Three layers admit a request, each narrower than the last: Tunnel drops anything matching none of the RE2 rules the gateway advertises on the tunnel upgrade, the gateway's Tunnel bridge re-checks the registry as the frame arrives, and the route itself runs its own authentication (Telegram's `secret_token`, Twilio's signature, a plugin webhook's token).
|
|
170
170
|
|
|
171
|
-
Claims are rows in `webhook_ingress_routes` in `gateway.sqlite`, which lives in `GATEWAY_SECURITY_DIR` and therefore survives a pod restart. The daemon claims over IPC for plugin webhooks; the gateway claims in-process for Telegram and Twilio. A claim that is unavailable, because the flag is off, no tunnel URL is published, or the write failed, falls back to registering a
|
|
171
|
+
Claims are rows in `webhook_ingress_routes` in `gateway.sqlite`, which lives in `GATEWAY_SECURITY_DIR` and therefore survives a pod restart. The daemon claims over IPC for plugin webhooks; the gateway claims in-process for Telegram and Twilio. A claim that is unavailable, because the flag is off, no tunnel URL is published, or the write failed, falls back to registering a cloud-hosted callback route, which is also the flag-off path. A new claim triggers a debounced tunnel reconnect so the edge rules catch up, so a path is always claimed before its URL is given to a provider.
|
|
172
172
|
|
|
173
173
|
The `/webhooks/twilio/` subtree is still admitted by a static prefix rule, because the media-stream path carries per-call segments an exact-match row cannot express. See [`ARCHITECTURE.md`](ARCHITECTURE.md) for the full lifecycle.
|
|
174
174
|
|
|
@@ -264,7 +264,7 @@ The gateway acts as the single ingress point for all traffic. Dedicated gateway
|
|
|
264
264
|
|
|
265
265
|
### Auth behavior
|
|
266
266
|
|
|
267
|
-
By default, proxied requests must
|
|
267
|
+
By default, proxied requests must present a valid edge credential — a JWT (aud `cadet-gateway`) signed with the gateway's signing key. The gateway verifies it and forwards the verified identity to the runtime in `x-cadet-*` headers (the runtime verifies no tokens). Setting `RUNTIME_PROXY_REQUIRE_AUTH=false` in the gateway process environment drops that requirement; workspace config is not consulted.
|
|
268
268
|
|
|
269
269
|
`OPTIONS` requests are always allowed without auth (CORS preflight). Telegram webhook requests use their own secret-based verification and are not affected by proxy auth.
|
|
270
270
|
|
|
@@ -367,7 +367,7 @@ See [`benchmarking/gateway/README.md`](../benchmarking/gateway/README.md) for lo
|
|
|
367
367
|
| Inbound messages silently dropped | Routing only drops events with no conversation _and_ no actor id (`"No routable identity"` in the `routing` logger). Anything else resolves; if it still never reaches the assistant, check the channel's admission policy floor. |
|
|
368
368
|
| Runtime errors | Is the assistant runtime reachable? Check runtime logs. |
|
|
369
369
|
| No reply from assistant | Is the assistant runtime processing messages? Check that the runtime HTTP server is running. |
|
|
370
|
-
| 403 on channel inbound | The runtime
|
|
370
|
+
| 403 on channel inbound | The runtime refused the forwarded request. Check the gateway's signing key (`GATEWAY_SECURITY_DIR/actor-token-signing-key`) — a replaced key invalidates existing credentials until clients re-pair. |
|
|
371
371
|
|
|
372
372
|
### Guardian-Specific Troubleshooting
|
|
373
373
|
|
package/eslint.config.mjs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { defineConfig
|
|
2
|
-
|
|
1
|
+
import { defineConfig } from "eslint/config";
|
|
2
|
+
|
|
3
|
+
import { baseEslintConfig } from "@mycadet/shared/eslint/base";
|
|
3
4
|
|
|
4
5
|
const eslintConfig = defineConfig([
|
|
5
|
-
...
|
|
6
|
-
globalIgnores(["dist/**"]),
|
|
6
|
+
...baseEslintConfig(),
|
|
7
7
|
{
|
|
8
8
|
rules: {
|
|
9
|
-
"@
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
],
|
|
9
|
+
"@mycadet/imports-first": "error",
|
|
10
|
+
// Lone blocks pretend to scope — they hide nothing and read like a bug.
|
|
11
|
+
"no-lone-blocks": "error",
|
|
13
12
|
},
|
|
14
13
|
},
|
|
15
14
|
{
|
package/knip.json
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"entry": [
|
|
3
|
-
|
|
4
|
-
"src/**/__tests__/**/*.ts",
|
|
5
|
-
"src/cli/index.ts"
|
|
6
|
-
],
|
|
7
|
-
"project": [
|
|
8
|
-
"src/**/*.ts"
|
|
9
|
-
],
|
|
2
|
+
"entry": ["src/**/*.test.ts", "src/**/__tests__/**/*.ts", "src/cli/index.ts"],
|
|
3
|
+
"project": ["src/**/*.ts"],
|
|
10
4
|
"ignoreDependencies": [
|
|
11
5
|
"@mycadet/assistant-client",
|
|
12
6
|
"@mycadet/ces-client",
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createTimeoutController,
|
|
8
8
|
isTimeoutError,
|
|
9
9
|
isConnectionError,
|
|
10
|
+
GATEWAY_SERVICE_IDENTITY,
|
|
10
11
|
} from "../http-client.js";
|
|
11
12
|
|
|
12
13
|
import { proxyForward } from "../proxy-forward.js";
|
|
@@ -105,22 +106,39 @@ describe("stripHopByHop", () => {
|
|
|
105
106
|
// ---------------------------------------------------------------------------
|
|
106
107
|
|
|
107
108
|
describe("prepareUpstreamHeaders", () => {
|
|
108
|
-
test("injects
|
|
109
|
+
test("injects the forwarded identity as x-cadet headers", () => {
|
|
109
110
|
const source = new Headers({ "content-type": "application/json" });
|
|
110
|
-
const prepared = prepareUpstreamHeaders(
|
|
111
|
-
|
|
111
|
+
const prepared = prepareUpstreamHeaders(
|
|
112
|
+
source,
|
|
113
|
+
GATEWAY_SERVICE_IDENTITY,
|
|
114
|
+
);
|
|
115
|
+
expect(prepared.get("x-cadet-subject")).toBe(
|
|
116
|
+
GATEWAY_SERVICE_IDENTITY.subject,
|
|
117
|
+
);
|
|
118
|
+
expect(prepared.get("x-cadet-principal-type")).toBe(
|
|
119
|
+
GATEWAY_SERVICE_IDENTITY.principalType,
|
|
120
|
+
);
|
|
121
|
+
expect(prepared.get("x-cadet-scope-profile")).toBe(
|
|
122
|
+
GATEWAY_SERVICE_IDENTITY.scopeProfile,
|
|
123
|
+
);
|
|
112
124
|
});
|
|
113
125
|
|
|
114
126
|
test("removes incoming host header", () => {
|
|
115
127
|
const source = new Headers({ host: "gateway.example.com" });
|
|
116
|
-
const prepared = prepareUpstreamHeaders(source,
|
|
128
|
+
const prepared = prepareUpstreamHeaders(source, GATEWAY_SERVICE_IDENTITY);
|
|
117
129
|
expect(prepared.has("host")).toBe(false);
|
|
118
130
|
});
|
|
119
131
|
|
|
120
|
-
test("
|
|
121
|
-
const source = new Headers({
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
test("a caller-supplied identity header never survives the hop", () => {
|
|
133
|
+
const source = new Headers({
|
|
134
|
+
authorization: "Bearer old-edge-token",
|
|
135
|
+
"x-cadet-subject": "user:attacker",
|
|
136
|
+
});
|
|
137
|
+
const prepared = prepareUpstreamHeaders(source, GATEWAY_SERVICE_IDENTITY);
|
|
138
|
+
expect(prepared.has("authorization")).toBe(false);
|
|
139
|
+
expect(prepared.get("x-cadet-subject")).toBe(
|
|
140
|
+
GATEWAY_SERVICE_IDENTITY.subject,
|
|
141
|
+
);
|
|
124
142
|
});
|
|
125
143
|
|
|
126
144
|
test("strips hop-by-hop headers from source", () => {
|
|
@@ -129,7 +147,7 @@ describe("prepareUpstreamHeaders", () => {
|
|
|
129
147
|
"keep-alive": "timeout=5",
|
|
130
148
|
"x-custom": "preserved",
|
|
131
149
|
});
|
|
132
|
-
const prepared = prepareUpstreamHeaders(source,
|
|
150
|
+
const prepared = prepareUpstreamHeaders(source, GATEWAY_SERVICE_IDENTITY);
|
|
133
151
|
expect(prepared.has("connection")).toBe(false);
|
|
134
152
|
expect(prepared.has("keep-alive")).toBe(false);
|
|
135
153
|
expect(prepared.get("x-custom")).toBe("preserved");
|
|
@@ -206,7 +224,6 @@ describe("proxyForward", () => {
|
|
|
206
224
|
const result = await proxyForward(req, {
|
|
207
225
|
baseUrl: "http://localhost:7821",
|
|
208
226
|
path: "/v1/health",
|
|
209
|
-
serviceToken: "tok",
|
|
210
227
|
timeoutMs: 5000,
|
|
211
228
|
fetchImpl: () => {
|
|
212
229
|
throw new DOMException("timeout", "TimeoutError");
|
|
@@ -222,7 +239,6 @@ describe("proxyForward", () => {
|
|
|
222
239
|
const result = await proxyForward(req, {
|
|
223
240
|
baseUrl: "http://localhost:7821",
|
|
224
241
|
path: "/v1/health",
|
|
225
|
-
serviceToken: "tok",
|
|
226
242
|
timeoutMs: 5000,
|
|
227
243
|
fetchImpl: () => {
|
|
228
244
|
throw new Error("ECONNREFUSED");
|
|
@@ -238,7 +254,6 @@ describe("proxyForward", () => {
|
|
|
238
254
|
const result = await proxyForward(req, {
|
|
239
255
|
baseUrl: "http://localhost:7821",
|
|
240
256
|
path: "/v1/data",
|
|
241
|
-
serviceToken: "tok",
|
|
242
257
|
timeoutMs: 5000,
|
|
243
258
|
fetchImpl: async () =>
|
|
244
259
|
new Response('{"ok":true}', {
|
|
@@ -260,7 +275,6 @@ describe("proxyForward", () => {
|
|
|
260
275
|
const result = await proxyForward(req, {
|
|
261
276
|
baseUrl: "http://localhost:7821",
|
|
262
277
|
path: "/v1/missing",
|
|
263
|
-
serviceToken: "tok",
|
|
264
278
|
timeoutMs: 5000,
|
|
265
279
|
fetchImpl: async () =>
|
|
266
280
|
new Response("Not Found", { status: 404 }),
|
|
@@ -283,7 +297,6 @@ describe("proxyForward", () => {
|
|
|
283
297
|
await proxyForward(req, {
|
|
284
298
|
baseUrl: "http://localhost:7821",
|
|
285
299
|
path: "/v1/inbound",
|
|
286
|
-
serviceToken: "tok",
|
|
287
300
|
timeoutMs: 5000,
|
|
288
301
|
fetchImpl: async (_url, init) => {
|
|
289
302
|
capturedHeaders = new Headers(init?.headers as HeadersInit);
|
|
@@ -297,7 +310,9 @@ describe("proxyForward", () => {
|
|
|
297
310
|
expect(capturedHeaders?.get("content-length")).toBe(
|
|
298
311
|
String(JSON.stringify({ message: "hello" }).length),
|
|
299
312
|
);
|
|
300
|
-
expect(capturedHeaders?.get("
|
|
313
|
+
expect(capturedHeaders?.get("x-cadet-subject")).toBe(
|
|
314
|
+
GATEWAY_SERVICE_IDENTITY.subject,
|
|
315
|
+
);
|
|
301
316
|
expect(capturedBody).not.toBeNull();
|
|
302
317
|
});
|
|
303
318
|
});
|
|
@@ -329,21 +344,19 @@ describe("httpToWs", () => {
|
|
|
329
344
|
// ---------------------------------------------------------------------------
|
|
330
345
|
|
|
331
346
|
describe("buildWsUpstreamUrl", () => {
|
|
332
|
-
test("builds URL
|
|
347
|
+
test("builds a clean URL — identity rides headers, not the query", () => {
|
|
333
348
|
const result = buildWsUpstreamUrl({
|
|
334
349
|
baseUrl: "http://localhost:7821",
|
|
335
350
|
path: "/v1/browser-relay",
|
|
336
|
-
serviceToken: "service-jwt-123",
|
|
337
351
|
});
|
|
338
|
-
expect(result.url).
|
|
339
|
-
expect(result.
|
|
352
|
+
expect(result.url).toBe("ws://localhost:7821/v1/browser-relay");
|
|
353
|
+
expect(result.logSafeUrl).toBe(result.url);
|
|
340
354
|
});
|
|
341
355
|
|
|
342
356
|
test("includes extra params in URL", () => {
|
|
343
357
|
const result = buildWsUpstreamUrl({
|
|
344
358
|
baseUrl: "http://localhost:7821",
|
|
345
359
|
path: "/v1/browser-relay",
|
|
346
|
-
serviceToken: "tok",
|
|
347
360
|
extraParams: {
|
|
348
361
|
guardianId: "guardian-abc",
|
|
349
362
|
clientInstanceId: "inst-xyz",
|
|
@@ -353,28 +366,23 @@ describe("buildWsUpstreamUrl", () => {
|
|
|
353
366
|
expect(result.url).toContain("clientInstanceId=inst-xyz");
|
|
354
367
|
});
|
|
355
368
|
|
|
356
|
-
test("produces log-safe URL
|
|
369
|
+
test("produces a log-safe URL — the URL carries no secret to redact", () => {
|
|
357
370
|
const result = buildWsUpstreamUrl({
|
|
358
371
|
baseUrl: "http://localhost:7821",
|
|
359
372
|
path: "/v1/calls/media-stream",
|
|
360
|
-
serviceToken: "secret-jwt-value",
|
|
361
373
|
extraParams: { callSessionId: "sess-1" },
|
|
362
374
|
});
|
|
363
|
-
expect(result.logSafeUrl).
|
|
364
|
-
expect(result.logSafeUrl).not.toContain("secret-jwt-value");
|
|
365
|
-
expect(result.logSafeUrl).toContain("callSessionId=sess-1");
|
|
375
|
+
expect(result.logSafeUrl).toBe("ws://localhost:7821/v1/calls/media-stream?callSessionId=sess-1");
|
|
366
376
|
});
|
|
367
377
|
|
|
368
|
-
test("
|
|
378
|
+
test("passes a caller token param through untouched", () => {
|
|
369
379
|
const result = buildWsUpstreamUrl({
|
|
370
380
|
baseUrl: "http://localhost:7821",
|
|
371
381
|
path: "/v1/stt/stream",
|
|
372
|
-
|
|
373
|
-
extraParams: { token: "should-be-ignored", mimeType: "audio/webm" },
|
|
382
|
+
extraParams: { token: "caller-supplied", mimeType: "audio/webm" },
|
|
374
383
|
});
|
|
375
|
-
// The token should be the service token, not the extra param
|
|
376
384
|
const url = new URL(result.url);
|
|
377
|
-
expect(url.searchParams.get("token")).toBe("
|
|
385
|
+
expect(url.searchParams.get("token")).toBe("caller-supplied");
|
|
378
386
|
expect(url.searchParams.get("mimeType")).toBe("audio/webm");
|
|
379
387
|
});
|
|
380
388
|
|
|
@@ -382,9 +390,8 @@ describe("buildWsUpstreamUrl", () => {
|
|
|
382
390
|
const result = buildWsUpstreamUrl({
|
|
383
391
|
baseUrl: "http://localhost:7821/",
|
|
384
392
|
path: "/v1/browser-relay",
|
|
385
|
-
serviceToken: "tok",
|
|
386
393
|
});
|
|
387
|
-
expect(result.url).
|
|
394
|
+
expect(result.url).toBe("ws://localhost:7821/v1/browser-relay");
|
|
388
395
|
expect(result.url).not.toContain("//v1");
|
|
389
396
|
});
|
|
390
397
|
|
|
@@ -392,8 +399,7 @@ describe("buildWsUpstreamUrl", () => {
|
|
|
392
399
|
const result = buildWsUpstreamUrl({
|
|
393
400
|
baseUrl: "https://runtime.example.com",
|
|
394
401
|
path: "/v1/calls/media-stream",
|
|
395
|
-
serviceToken: "tok",
|
|
396
402
|
});
|
|
397
|
-
expect(result.url).toStartWith("wss://runtime.example.com/v1/calls/media-stream
|
|
403
|
+
expect(result.url).toStartWith("wss://runtime.example.com/v1/calls/media-stream");
|
|
398
404
|
});
|
|
399
405
|
});
|
|
@@ -80,25 +80,76 @@ export function buildUpstreamUrl(
|
|
|
80
80
|
// Auth header injection
|
|
81
81
|
// ---------------------------------------------------------------------------
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* The identity a dial asserts to the assistant runtime.
|
|
85
|
+
*
|
|
86
|
+
* The daemon verifies no tokens — it resolves the caller from these
|
|
87
|
+
* forwarded headers, so the gateway (the only remote ingress) sets them
|
|
88
|
+
* from claims it verified itself, and never passes a caller's own
|
|
89
|
+
* identity headers through.
|
|
90
|
+
*/
|
|
91
|
+
export type ForwardedIdentity = {
|
|
92
|
+
/** The verified token's `sub` (or the service subject). */
|
|
93
|
+
subject: string;
|
|
94
|
+
/** The principal type the subject parses to. */
|
|
95
|
+
principalType: string;
|
|
96
|
+
/** The scope profile the verified token carried. */
|
|
97
|
+
scopeProfile: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** The gateway's own service identity for runtime dials. */
|
|
101
|
+
export const GATEWAY_SERVICE_IDENTITY: ForwardedIdentity = {
|
|
102
|
+
subject: "svc:gateway:self",
|
|
103
|
+
principalType: "svc_gateway",
|
|
104
|
+
scopeProfile: "gateway_service_v1",
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** The gateway's identity for webhook-ingress dials. */
|
|
108
|
+
export const GATEWAY_INGRESS_IDENTITY: ForwardedIdentity = {
|
|
109
|
+
subject: "svc:gateway:self",
|
|
110
|
+
principalType: "svc_gateway",
|
|
111
|
+
scopeProfile: "gateway_ingress_v1",
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The `x-cadet-*` headers a forwarded identity travels in. Defaults to the
|
|
116
|
+
* gateway's service identity — the common case for runtime dials; pass an
|
|
117
|
+
* explicit identity for the rare ingress assertion.
|
|
118
|
+
*/
|
|
119
|
+
export function forwardedIdentityHeaders(
|
|
120
|
+
identity: ForwardedIdentity = GATEWAY_SERVICE_IDENTITY,
|
|
121
|
+
): Record<string, string> {
|
|
122
|
+
return {
|
|
123
|
+
"x-cadet-subject": identity.subject,
|
|
124
|
+
"x-cadet-principal-type": identity.principalType,
|
|
125
|
+
"x-cadet-scope-profile": identity.scopeProfile,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
83
129
|
/**
|
|
84
130
|
* Prepare request headers for an upstream call to the assistant runtime.
|
|
85
131
|
*
|
|
86
132
|
* - Strips hop-by-hop headers from the source
|
|
87
|
-
* - Removes the incoming `host` and `authorization` headers
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* agnostic to the token minting mechanism so it can be used without
|
|
92
|
-
* importing gateway auth internals.
|
|
133
|
+
* - Removes the incoming `host` and `authorization` headers — the daemon
|
|
134
|
+
* resolves identity from the forwarded `x-cadet-*` headers, never from
|
|
135
|
+
* a bearer, and a caller-supplied identity header must never survive
|
|
136
|
+
* - Injects the forwarded identity headers
|
|
93
137
|
*/
|
|
94
138
|
export function prepareUpstreamHeaders(
|
|
95
139
|
source: Headers,
|
|
96
|
-
|
|
140
|
+
identity: ForwardedIdentity,
|
|
97
141
|
): Headers {
|
|
98
142
|
const cleaned = stripHopByHop(source);
|
|
99
143
|
cleaned.delete("host");
|
|
100
144
|
cleaned.delete("authorization");
|
|
101
|
-
cleaned.
|
|
145
|
+
cleaned.delete("x-cadet-subject");
|
|
146
|
+
cleaned.delete("x-cadet-principal-type");
|
|
147
|
+
cleaned.delete("x-cadet-scope-profile");
|
|
148
|
+
for (const [name, value] of Object.entries(
|
|
149
|
+
forwardedIdentityHeaders(identity),
|
|
150
|
+
)) {
|
|
151
|
+
cleaned.set(name, value);
|
|
152
|
+
}
|
|
102
153
|
return cleaned;
|
|
103
154
|
}
|
|
104
155
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Encapsulates the common pattern of:
|
|
6
6
|
* 1. Buffering the request body
|
|
7
|
-
* 2. Forwarding to the assistant runtime with
|
|
7
|
+
* 2. Forwarding to the assistant runtime with forwarded-identity headers
|
|
8
8
|
* 3. Mapping timeouts to 504 Gateway Timeout
|
|
9
9
|
* 4. Mapping connection failures to 502 Bad Gateway
|
|
10
10
|
* 5. Sanitizing response headers (hop-by-hop stripping)
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import {
|
|
14
14
|
buildUpstreamUrl,
|
|
15
15
|
createTimeoutController,
|
|
16
|
+
GATEWAY_SERVICE_IDENTITY,
|
|
16
17
|
isTimeoutError,
|
|
17
18
|
prepareUpstreamHeaders,
|
|
18
19
|
stripHopByHop,
|
|
@@ -29,8 +30,6 @@ export type ProxyForwardOptions = {
|
|
|
29
30
|
path: string;
|
|
30
31
|
/** Query string to append, including the leading `?` (e.g. `?foo=bar`). */
|
|
31
32
|
search?: string;
|
|
32
|
-
/** Service token for upstream auth. */
|
|
33
|
-
serviceToken: string;
|
|
34
33
|
/** Timeout in milliseconds for the upstream request. */
|
|
35
34
|
timeoutMs: number;
|
|
36
35
|
/**
|
|
@@ -77,9 +76,11 @@ export async function proxyForward(
|
|
|
77
76
|
): Promise<ProxyForwardResult> {
|
|
78
77
|
const upstream = buildUpstreamUrl(opts.baseUrl, opts.path, opts.search);
|
|
79
78
|
|
|
79
|
+
// Every proxy route asserts the gateway's service identity — the constant
|
|
80
|
+
// lives here so no call site repeats it.
|
|
80
81
|
const reqHeaders = prepareUpstreamHeaders(
|
|
81
82
|
new Headers(req.headers),
|
|
82
|
-
|
|
83
|
+
GATEWAY_SERVICE_IDENTITY,
|
|
83
84
|
);
|
|
84
85
|
|
|
85
86
|
// Buffer the body to get an accurate Content-Length
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* WebSocket upstream URL
|
|
2
|
+
* WebSocket upstream URL helpers for gateway-to-assistant
|
|
3
3
|
* WebSocket connections.
|
|
4
4
|
*
|
|
5
|
-
* Used by
|
|
6
|
-
* construct
|
|
5
|
+
* Used by twilio relay/media, STT stream, watch and desktop stream routes
|
|
6
|
+
* to construct upstream WebSocket URLs to the assistant runtime; the
|
|
7
|
+
* dials assert the gateway's service identity in forwarded headers.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
// ---------------------------------------------------------------------------
|
|
@@ -25,33 +26,27 @@ export function httpToWs(httpBaseUrl: string): string {
|
|
|
25
26
|
export type WsUpstreamOptions = {
|
|
26
27
|
/** HTTP base URL of the assistant runtime (e.g. `http://localhost:7821`). */
|
|
27
28
|
baseUrl: string;
|
|
28
|
-
/** Path on the upstream WS server (e.g. `/v1/
|
|
29
|
+
/** Path on the upstream WS server (e.g. `/v1/stt/stream`). */
|
|
29
30
|
path: string;
|
|
30
|
-
/** Service token injected as the `token` query parameter. */
|
|
31
|
-
serviceToken: string;
|
|
32
31
|
/**
|
|
33
|
-
* Additional query parameters to forward to the upstream.
|
|
34
|
-
* param is always set from `serviceToken` and should not be included
|
|
35
|
-
* here.
|
|
32
|
+
* Additional query parameters to forward to the upstream.
|
|
36
33
|
*/
|
|
37
|
-
extraParams?: Record<string,
|
|
34
|
+
extraParams?: Record<string, unknown>;
|
|
38
35
|
};
|
|
39
36
|
|
|
40
37
|
export type WsUpstreamResult = {
|
|
41
|
-
/** Full upstream WebSocket URL with
|
|
38
|
+
/** Full upstream WebSocket URL with the extra params. */
|
|
42
39
|
url: string;
|
|
43
|
-
/** A version of the URL
|
|
40
|
+
/** A version of the URL safe to log. */
|
|
44
41
|
logSafeUrl: string;
|
|
45
42
|
};
|
|
46
43
|
|
|
47
44
|
/**
|
|
48
|
-
* Build
|
|
45
|
+
* Build the upstream WebSocket URL for the assistant runtime.
|
|
49
46
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* Returns both the real URL and a log-safe variant with the token redacted.
|
|
47
|
+
* No token: the dialer authenticates with forwarded-identity headers on
|
|
48
|
+
* the upgrade request (Bun's server-side WebSocket client can set
|
|
49
|
+
* headers; the browser-facing edge it proxies for cannot).
|
|
55
50
|
*/
|
|
56
51
|
export function buildWsUpstreamUrl(opts: WsUpstreamOptions): WsUpstreamResult {
|
|
57
52
|
const wsBase = httpToWs(opts.baseUrl.replace(/\/+$/, ""));
|
|
@@ -62,19 +57,14 @@ export function buildWsUpstreamUrl(opts: WsUpstreamOptions): WsUpstreamResult {
|
|
|
62
57
|
const query = new URLSearchParams();
|
|
63
58
|
if (opts.extraParams) {
|
|
64
59
|
for (const [key, value] of Object.entries(opts.extraParams)) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
// Scalars ride the dial — numbers included: the runtime's watch route
|
|
61
|
+
// reads numeric capture ids (and stt its sample rate) off this query.
|
|
62
|
+
// Anything structured (the upstream socket, pending frames) does not.
|
|
63
|
+
if (typeof value !== "string" && typeof value !== "number") continue;
|
|
64
|
+
query.set(key, String(value));
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
query.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Build log-safe URL by replacing the token value
|
|
75
|
-
const logQuery = new URLSearchParams(query);
|
|
76
|
-
logQuery.set("token", "<redacted>");
|
|
77
|
-
const logSafeUrl = `${wsBase}${normalizedPath}?${logQuery.toString()}`;
|
|
78
|
-
|
|
79
|
-
return { url, logSafeUrl };
|
|
67
|
+
const qs = query.size > 0 ? `?${query.toString()}` : "";
|
|
68
|
+
const url = `${wsBase}${normalizedPath}${qs}`;
|
|
69
|
+
return { url, logSafeUrl: url };
|
|
80
70
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mycadet/ipc-server-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"typecheck": "bunx tsc --noEmit",
|
|
12
|
+
"test": "bun test src/"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/bun": "1.3.10",
|
|
16
|
+
"typescript": "5.9.3"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/node_modules/@mycadet/ces-client/node_modules/@mycadet/ipc-server-utils/src/endpoint.test.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { removeIpcEndpointFile, resolveIpcEndpoint } from "./endpoint.js";
|
|
6
|
+
const windowsEndpoint = (name: string, workspaceDir: string) => resolveIpcEndpoint(name, { workspaceDir, platform: "win32" });
|
|
7
|
+
describe("resolveIpcEndpoint", () => {
|
|
8
|
+
test("keeps long POSIX fallbacks deterministic and bounded", () => {
|
|
9
|
+
const options = {
|
|
10
|
+
workspaceDir: `/tmp/${"a".repeat(120)}`,
|
|
11
|
+
platform: "darwin" as const,
|
|
12
|
+
};
|
|
13
|
+
const endpoint = resolveIpcEndpoint("assistant", options);
|
|
14
|
+
expect(resolveIpcEndpoint("assistant", options)).toEqual(endpoint);
|
|
15
|
+
expect(Buffer.byteLength(endpoint.path)).toBeLessThanOrEqual(103);
|
|
16
|
+
});
|
|
17
|
+
test("returns normalized, isolated, bounded Windows pipes", () => {
|
|
18
|
+
const first = windowsEndpoint("assistant", "C:\\one");
|
|
19
|
+
expect(resolveIpcEndpoint("assistant", { workspaceDir: "c:\\ONE\\", platform: "win32", env: { ASSISTANT_IPC_SOCKET_DIR: "C:\\ignored" } })).toEqual(first);
|
|
20
|
+
expect(first.path.length).toBeLessThanOrEqual(256);
|
|
21
|
+
expect(windowsEndpoint("assistant", "C:\\two").path).not.toBe(first.path);
|
|
22
|
+
expect(windowsEndpoint("gateway", "C:\\one").path).not.toBe(first.path);
|
|
23
|
+
});
|
|
24
|
+
test("cleans socket files but skips named pipes", () => {
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), "cadet-ipc-cleanup-"));
|
|
26
|
+
const socketPath = join(dir, "assistant.sock");
|
|
27
|
+
try {
|
|
28
|
+
writeFileSync(socketPath, "stale");
|
|
29
|
+
removeIpcEndpointFile(socketPath);
|
|
30
|
+
expect(existsSync(socketPath)).toBe(false);
|
|
31
|
+
removeIpcEndpointFile("\\\\.\\pipe\\mycadet-test");
|
|
32
|
+
} finally {
|
|
33
|
+
rmSync(dir, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|