UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.6 kB
import{m as parseStrictPositiveInteger}from"./number-coercion-DIhBGkET.mjs"; //!packages/gateway-client/src/timeouts.ts function isTestRuntimeEnv(e){return e.VITEST===`true`||e.VITEST===`1`||e.VITEST_POOL_ID!==void 0||e.VITEST_WORKER_ID!==void 0||e.NODE_ENV===`test`||e!==process.env&&isTestRuntimeEnv(process.env)}const MAX_SAFE_TIMEOUT_DELAY_MS=2147483647;const DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS=3e4;function startGatewayConnectTimeout(e){const t=setTimeout(e,DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS);t.unref?.();return t}function clearGatewayConnectTimeout(e){if(e!==null)clearTimeout(e);return null}const DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS=3e4;const MIN_CONNECT_CHALLENGE_TIMEOUT_MS=250;const MAX_CONNECT_CHALLENGE_TIMEOUT_MS=DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS;function resolveSafeTimeoutDelayMs(e,t){const n=t?.minMs??1;const r=Math.min(MAX_SAFE_TIMEOUT_DELAY_MS,Math.max(0,Number.isFinite(n)?Math.floor(n):1));return Math.min(MAX_SAFE_TIMEOUT_DELAY_MS,Math.max(r,Number.isFinite(e)?Math.floor(e):r))}function resolveFiniteTimeoutDelayMs(e,t,n){return resolveSafeTimeoutDelayMs(typeof e===`number`&&Number.isFinite(e)?e:t,n)}function clampConnectChallengeTimeoutMs(e,t=MAX_CONNECT_CHALLENGE_TIMEOUT_MS){return Math.max(250,Math.min(Math.max(250,t),e))}function getConnectChallengeTimeoutMsFromEnv(e=process.env){const t=e.OPENCLAW_CONNECT_CHALLENGE_TIMEOUT_MS;if(t){const e=parseStrictPositiveInteger(t);if(e!==void 0)return resolveSafeTimeoutDelayMs(e)}}function resolveConnectChallengeTimeoutMs(e,t){const n=resolvePreauthHandshakeTimeoutMs({env:t?.env,configuredTimeoutMs:t?.configuredTimeoutMs});const r=Math.max(DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS,n);if(typeof e===`number`&&Number.isFinite(e))return clampConnectChallengeTimeoutMs(e,r);const i=getConnectChallengeTimeoutMsFromEnv(t?.env);if(i!==void 0)return clampConnectChallengeTimeoutMs(i,Math.max(r,i));return clampConnectChallengeTimeoutMs(n,r)}function resolvePreauthHandshakeTimeoutMs(e){const t=e?.env??process.env;const n=t.OPENCLAW_HANDSHAKE_TIMEOUT_MS||(isTestRuntimeEnv(t)?t.OPENCLAW_TEST_HANDSHAKE_TIMEOUT_MS:void 0);if(n){const e=parseStrictPositiveInteger(n);if(e!==void 0)return resolveSafeTimeoutDelayMs(e)}const r=e?.configuredTimeoutMs;if(typeof r===`number`&&Number.isFinite(r)&&r>0)return resolveSafeTimeoutDelayMs(r);return DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS}export{resolvePreauthHandshakeTimeoutMs as a,resolveFiniteTimeoutDelayMs as i,clearGatewayConnectTimeout as n,resolveSafeTimeoutDelayMs as o,resolveConnectChallengeTimeoutMs as r,startGatewayConnectTimeout as s,DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS as t};