88 EnvironmentCloudRelayConfigResult ,
99 EnvironmentHttpApi ,
1010 EnvironmentHttpBadRequestError ,
11+ type EnvironmentCloudPreferencesRequest ,
1112 EnvironmentHttpConflictError ,
1213 EnvironmentHttpInternalServerError ,
1314 EnvironmentHttpUnauthorizedError ,
@@ -69,6 +70,7 @@ import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
6970import { requireEnvironmentScope } from "../auth/http.ts" ;
7071import * as ServerConfig from "../config.ts" ;
7172import * as ServerEnvironment from "../environment/ServerEnvironment.ts" ;
73+ import { makeRelayEnvironmentClient } from "../relay/relayEnvironmentClient.ts" ;
7274import * as AgentAwarenessRelay from "../relay/AgentAwarenessRelay.ts" ;
7375import * as ManagedEndpointRuntime from "./ManagedEndpointRuntime.ts" ;
7476import {
@@ -86,6 +88,8 @@ import {
8688 encodeEndpointRuntimeConfigJson ,
8789 encodeConfirmedOriginJson ,
8890 PUBLISH_AGENT_ACTIVITY_SECRET ,
91+ HOLD_WEBHOOKS_WHILE_OFFLINE_SECRET ,
92+ readRelayConnection ,
8993 RELAY_ENVIRONMENT_CREDENTIAL_SECRET ,
9094 RELAY_ISSUER_SECRET ,
9195 RELAY_URL_SECRET ,
@@ -1277,17 +1281,24 @@ export const releaseManagedTunnelOnShutdown = Effect.fn(
12771281const readCloudLinkState = Effect . fn ( "environment.cloud.readLinkState" ) ( function * (
12781282 dependencies : CloudHttpDependencies ,
12791283) {
1280- const [ cloudUserId , relayUrl , relayIssuer , endpointRuntimeConfig , publishAgentActivity ] =
1281- yield * Effect . all (
1282- [
1283- dependencies . secrets . get ( CLOUD_LINKED_USER_ID ) ,
1284- dependencies . secrets . get ( RELAY_URL_SECRET ) ,
1285- dependencies . secrets . get ( RELAY_ISSUER_SECRET ) ,
1286- dependencies . secrets . get ( CLOUD_ENDPOINT_RUNTIME_CONFIG ) ,
1287- dependencies . secrets . get ( PUBLISH_AGENT_ACTIVITY_SECRET ) ,
1288- ] ,
1289- { concurrency : 5 } ,
1290- ) ;
1284+ const [
1285+ cloudUserId ,
1286+ relayUrl ,
1287+ relayIssuer ,
1288+ endpointRuntimeConfig ,
1289+ publishAgentActivity ,
1290+ holdWebhooks ,
1291+ ] = yield * Effect . all (
1292+ [
1293+ dependencies . secrets . get ( CLOUD_LINKED_USER_ID ) ,
1294+ dependencies . secrets . get ( RELAY_URL_SECRET ) ,
1295+ dependencies . secrets . get ( RELAY_ISSUER_SECRET ) ,
1296+ dependencies . secrets . get ( CLOUD_ENDPOINT_RUNTIME_CONFIG ) ,
1297+ dependencies . secrets . get ( PUBLISH_AGENT_ACTIVITY_SECRET ) ,
1298+ dependencies . secrets . get ( HOLD_WEBHOOKS_WHILE_OFFLINE_SECRET ) ,
1299+ ] ,
1300+ { concurrency : 6 } ,
1301+ ) ;
12911302 return {
12921303 linked : Option . isSome ( cloudUserId ) ,
12931304 cloudUserId : Option . isSome ( cloudUserId ) ? bytesToString ( cloudUserId . value ) : null ,
@@ -1299,6 +1310,8 @@ const readCloudLinkState = Effect.fn("environment.cloud.readLinkState")(function
12991310 publishAgentActivity : Option . isSome ( publishAgentActivity )
13001311 ? bytesToString ( publishAgentActivity . value ) === "true"
13011312 : false ,
1313+ holdWebhooksWhileOffline :
1314+ Option . isSome ( holdWebhooks ) && bytesToString ( holdWebhooks . value ) === "true" ,
13021315 } satisfies EnvironmentCloudLinkStateResult ;
13031316} ) ;
13041317
@@ -1329,8 +1342,9 @@ const cloudUnlinkHandler = Effect.fn("environment.cloud.unlink")(
13291342 dependencies . secrets . remove ( CLOUD_ENDPOINT_RUNTIME_CONFIG ) ,
13301343 dependencies . secrets . remove ( CLOUD_ENDPOINT_CONFIRMED_ORIGIN ) ,
13311344 dependencies . secrets . remove ( PUBLISH_AGENT_ACTIVITY_SECRET ) ,
1345+ dependencies . secrets . remove ( HOLD_WEBHOOKS_WHILE_OFFLINE_SECRET ) ,
13321346 ] ,
1333- { concurrency : 8 } ,
1347+ { concurrency : 9 } ,
13341348 ) ;
13351349 yield * setCliDesiredCloudLink ( false ) ;
13361350 return { ok : true , endpointRuntimeStatus } satisfies EnvironmentCloudRelayConfigResult ;
@@ -1343,12 +1357,42 @@ const cloudUnlinkHandler = Effect.fn("environment.cloud.unlink")(
13431357 ) ,
13441358) ;
13451359
1360+ const pushHoldWebhooksWhileOffline = Effect . fn ( "environment.cloud.pushHoldWebhooksWhileOffline" ) (
1361+ function * ( dependencies : CloudHttpDependencies , holdWebhooksWhileOffline : boolean ) {
1362+ const connection = yield * readRelayConnection ( dependencies . secrets ) ;
1363+ if ( connection === null ) {
1364+ return yield * new EnvironmentHttpBadRequestError ( {
1365+ message : "Link this environment to T3 Connect first." ,
1366+ } ) ;
1367+ }
1368+ const environmentId = yield * dependencies . environment . getEnvironmentId ;
1369+ const client = yield * makeRelayEnvironmentClient ( connection ) ;
1370+ yield * client . server
1371+ . updateLinkPreferences ( {
1372+ params : { environmentId } ,
1373+ payload : { holdWebhooksWhileOffline } ,
1374+ } )
1375+ . pipe (
1376+ Effect . timeout ( "10 seconds" ) ,
1377+ Effect . catch (
1378+ failEnvironmentCloudInternalError ( "Could not update T3 Connect webhook settings." ) ,
1379+ ) ,
1380+ ) ;
1381+ } ,
1382+ ) ;
1383+
13461384const cloudPreferencesHandler = Effect . fn ( "environment.cloud.preferences" ) (
1347- function * (
1348- dependencies : CloudHttpDependencies ,
1349- payload : { readonly publishAgentActivity : boolean } ,
1350- ) {
1385+ function * ( dependencies : CloudHttpDependencies , payload : EnvironmentCloudPreferencesRequest ) {
13511386 yield * requireEnvironmentScope ( AuthRelayWriteScope ) ;
1387+ if ( payload . holdWebhooksWhileOffline !== undefined ) {
1388+ // The relay decides whether to hold a request, so it is told first; the
1389+ // local copy is only saved once the relay has the same value.
1390+ yield * pushHoldWebhooksWhileOffline ( dependencies , payload . holdWebhooksWhileOffline ) ;
1391+ yield * dependencies . secrets . set (
1392+ HOLD_WEBHOOKS_WHILE_OFFLINE_SECRET ,
1393+ stringToBytes ( String ( payload . holdWebhooksWhileOffline ) ) ,
1394+ ) ;
1395+ }
13521396 yield * dependencies . secrets . set (
13531397 PUBLISH_AGENT_ACTIVITY_SECRET ,
13541398 stringToBytes ( String ( payload . publishAgentActivity ) ) ,
0 commit comments