@openclaw/gateway-client 0.0.0 → 2026.7.2-beta.4
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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +133 -2
- package/dist/browser-device-auth-Bp297Rtf.d.mts +130 -0
- package/dist/browser.d.mts +20 -0
- package/dist/browser.mjs +8 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +1781 -0
- package/dist/protocol-client-Cj1WAoMt.d.mts +180 -0
- package/dist/readiness-CPiKyi1s.d.mts +201 -0
- package/dist/readiness-CrWxd4TI.mjs +105 -0
- package/dist/readiness.d.mts +2 -0
- package/dist/readiness.mjs +3 -0
- package/dist/reconnect-policy-CkzLe1_K.mjs +850 -0
- package/dist/timeouts.d.mts +39 -0
- package/dist/timeouts.mjs +77 -0
- package/npm-shrinkwrap.json +50 -0
- package/package.json +69 -6
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region packages/gateway-client/src/timeouts.d.ts
|
|
2
|
+
/** Maximum delay Node timers can represent without overflow warnings. */
|
|
3
|
+
declare const MAX_SAFE_TIMEOUT_DELAY_MS = 2147483647;
|
|
4
|
+
/** Default server-side window for gateway preauth handshakes. */
|
|
5
|
+
declare const DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = 15000;
|
|
6
|
+
/** Default deadline for a single non-streaming Gateway request. */
|
|
7
|
+
declare const DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS = 30000;
|
|
8
|
+
/** Minimum client watchdog delay for connect challenge setup. */
|
|
9
|
+
declare const MIN_CONNECT_CHALLENGE_TIMEOUT_MS = 250;
|
|
10
|
+
/** Default maximum client watchdog delay, aligned with the preauth server timeout. */
|
|
11
|
+
declare const MAX_CONNECT_CHALLENGE_TIMEOUT_MS = 15000;
|
|
12
|
+
/** Clamps arbitrary timer delays to Node's safe range and an optional floor. */
|
|
13
|
+
declare function resolveSafeTimeoutDelayMs(delayMs: number, opts?: {
|
|
14
|
+
minMs?: number;
|
|
15
|
+
}): number;
|
|
16
|
+
/** Adds grace time while preserving safe timer bounds if inputs overflow or are invalid. */
|
|
17
|
+
declare function addSafeTimeoutDelayGraceMs(delayMs: number, graceMs: number, opts?: {
|
|
18
|
+
minMs?: number;
|
|
19
|
+
}): number;
|
|
20
|
+
/** Resolves optional timeout values through a fallback and safe timer clamp. */
|
|
21
|
+
declare function resolveFiniteTimeoutDelayMs(delayMs: number | null | undefined, fallbackMs: number, opts?: {
|
|
22
|
+
minMs?: number;
|
|
23
|
+
}): number;
|
|
24
|
+
/** Clamps connect challenge watchdog timeouts to the gateway-supported range. */
|
|
25
|
+
declare function clampConnectChallengeTimeoutMs(timeoutMs: number, maxTimeoutMs?: number): number;
|
|
26
|
+
/** Reads the connect challenge watchdog override from the process environment. */
|
|
27
|
+
declare function getConnectChallengeTimeoutMsFromEnv(env?: NodeJS.ProcessEnv): number | undefined;
|
|
28
|
+
/** Resolves the client watchdog timeout using explicit, env, then preauth defaults. */
|
|
29
|
+
declare function resolveConnectChallengeTimeoutMs(timeoutMs?: number | null, params?: {
|
|
30
|
+
env?: NodeJS.ProcessEnv;
|
|
31
|
+
configuredTimeoutMs?: number | null;
|
|
32
|
+
}): number;
|
|
33
|
+
/** Resolves the server preauth timeout from env, explicit config, or default. */
|
|
34
|
+
declare function resolvePreauthHandshakeTimeoutMs(params?: {
|
|
35
|
+
env?: NodeJS.ProcessEnv;
|
|
36
|
+
configuredTimeoutMs?: number | null;
|
|
37
|
+
}): number;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, MAX_CONNECT_CHALLENGE_TIMEOUT_MS, MAX_SAFE_TIMEOUT_DELAY_MS, MIN_CONNECT_CHALLENGE_TIMEOUT_MS, addSafeTimeoutDelayGraceMs, clampConnectChallengeTimeoutMs, getConnectChallengeTimeoutMsFromEnv, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region packages/gateway-client/src/timeouts.ts
|
|
2
|
+
function parseStrictPositiveInteger(value) {
|
|
3
|
+
const trimmed = value.trim();
|
|
4
|
+
if (!/^\+?\d+$/u.test(trimmed)) return;
|
|
5
|
+
const parsed = Number(trimmed);
|
|
6
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
7
|
+
}
|
|
8
|
+
function isTestRuntimeEnv(env) {
|
|
9
|
+
return env.VITEST === "true" || env.VITEST === "1" || env.VITEST_POOL_ID !== void 0 || env.VITEST_WORKER_ID !== void 0 || env.NODE_ENV === "test" || env !== process.env && (process.env.VITEST === "true" || process.env.VITEST === "1" || process.env.VITEST_POOL_ID !== void 0 || process.env.VITEST_WORKER_ID !== void 0 || false);
|
|
10
|
+
}
|
|
11
|
+
/** Maximum delay Node timers can represent without overflow warnings. */
|
|
12
|
+
const MAX_SAFE_TIMEOUT_DELAY_MS = 2147483647;
|
|
13
|
+
/** Default server-side window for gateway preauth handshakes. */
|
|
14
|
+
const DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = 15e3;
|
|
15
|
+
/** Default deadline for a single non-streaming Gateway request. */
|
|
16
|
+
const DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS = 3e4;
|
|
17
|
+
/** Minimum client watchdog delay for connect challenge setup. */
|
|
18
|
+
const MIN_CONNECT_CHALLENGE_TIMEOUT_MS = 250;
|
|
19
|
+
/** Default maximum client watchdog delay, aligned with the preauth server timeout. */
|
|
20
|
+
const MAX_CONNECT_CHALLENGE_TIMEOUT_MS = DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS;
|
|
21
|
+
/** Clamps arbitrary timer delays to Node's safe range and an optional floor. */
|
|
22
|
+
function resolveSafeTimeoutDelayMs(delayMs, opts) {
|
|
23
|
+
const rawMinMs = opts?.minMs ?? 1;
|
|
24
|
+
const minMs = Math.min(MAX_SAFE_TIMEOUT_DELAY_MS, Math.max(0, Number.isFinite(rawMinMs) ? Math.floor(rawMinMs) : 1));
|
|
25
|
+
return Math.min(MAX_SAFE_TIMEOUT_DELAY_MS, Math.max(minMs, Number.isFinite(delayMs) ? Math.floor(delayMs) : minMs));
|
|
26
|
+
}
|
|
27
|
+
/** Adds grace time while preserving safe timer bounds if inputs overflow or are invalid. */
|
|
28
|
+
function addSafeTimeoutDelayGraceMs(delayMs, graceMs, opts) {
|
|
29
|
+
if (!Number.isFinite(delayMs) || !Number.isFinite(graceMs)) return resolveSafeTimeoutDelayMs(MAX_SAFE_TIMEOUT_DELAY_MS, opts);
|
|
30
|
+
const withGrace = delayMs + graceMs;
|
|
31
|
+
return resolveSafeTimeoutDelayMs(Number.isFinite(withGrace) ? withGrace : MAX_SAFE_TIMEOUT_DELAY_MS, opts);
|
|
32
|
+
}
|
|
33
|
+
/** Resolves optional timeout values through a fallback and safe timer clamp. */
|
|
34
|
+
function resolveFiniteTimeoutDelayMs(delayMs, fallbackMs, opts) {
|
|
35
|
+
return resolveSafeTimeoutDelayMs(typeof delayMs === "number" && Number.isFinite(delayMs) ? delayMs : fallbackMs, opts);
|
|
36
|
+
}
|
|
37
|
+
/** Clamps connect challenge watchdog timeouts to the gateway-supported range. */
|
|
38
|
+
function clampConnectChallengeTimeoutMs(timeoutMs, maxTimeoutMs = MAX_CONNECT_CHALLENGE_TIMEOUT_MS) {
|
|
39
|
+
return Math.max(250, Math.min(Math.max(250, maxTimeoutMs), timeoutMs));
|
|
40
|
+
}
|
|
41
|
+
/** Reads the connect challenge watchdog override from the process environment. */
|
|
42
|
+
function getConnectChallengeTimeoutMsFromEnv(env = process.env) {
|
|
43
|
+
const raw = env.OPENCLAW_CONNECT_CHALLENGE_TIMEOUT_MS;
|
|
44
|
+
if (raw) {
|
|
45
|
+
const parsed = parseStrictPositiveInteger(raw);
|
|
46
|
+
if (parsed !== void 0) return resolveSafeTimeoutDelayMs(parsed);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function normalizePositiveTimeoutMs(timeoutMs) {
|
|
50
|
+
return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? resolveSafeTimeoutDelayMs(timeoutMs) : void 0;
|
|
51
|
+
}
|
|
52
|
+
/** Resolves the client watchdog timeout using explicit, env, then preauth defaults. */
|
|
53
|
+
function resolveConnectChallengeTimeoutMs(timeoutMs, params) {
|
|
54
|
+
const configuredPreauthTimeoutMs = resolvePreauthHandshakeTimeoutMs({
|
|
55
|
+
env: params?.env,
|
|
56
|
+
configuredTimeoutMs: params?.configuredTimeoutMs
|
|
57
|
+
});
|
|
58
|
+
const maxTimeoutMs = Math.max(DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, configuredPreauthTimeoutMs);
|
|
59
|
+
if (typeof timeoutMs === "number" && Number.isFinite(timeoutMs)) return clampConnectChallengeTimeoutMs(timeoutMs, maxTimeoutMs);
|
|
60
|
+
const envOverride = getConnectChallengeTimeoutMsFromEnv(params?.env);
|
|
61
|
+
if (envOverride !== void 0) return clampConnectChallengeTimeoutMs(envOverride, Math.max(maxTimeoutMs, envOverride));
|
|
62
|
+
return clampConnectChallengeTimeoutMs(configuredPreauthTimeoutMs, maxTimeoutMs);
|
|
63
|
+
}
|
|
64
|
+
/** Resolves the server preauth timeout from env, explicit config, or default. */
|
|
65
|
+
function resolvePreauthHandshakeTimeoutMs(params) {
|
|
66
|
+
const env = params?.env ?? process.env;
|
|
67
|
+
const configuredTimeout = env.OPENCLAW_HANDSHAKE_TIMEOUT_MS || (isTestRuntimeEnv(env) ? env.OPENCLAW_TEST_HANDSHAKE_TIMEOUT_MS : void 0);
|
|
68
|
+
if (configuredTimeout) {
|
|
69
|
+
const parsed = parseStrictPositiveInteger(configuredTimeout);
|
|
70
|
+
if (parsed !== void 0) return resolveSafeTimeoutDelayMs(parsed);
|
|
71
|
+
}
|
|
72
|
+
const configured = normalizePositiveTimeoutMs(params?.configuredTimeoutMs);
|
|
73
|
+
if (configured !== void 0) return configured;
|
|
74
|
+
return DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, MAX_CONNECT_CHALLENGE_TIMEOUT_MS, MAX_SAFE_TIMEOUT_DELAY_MS, MIN_CONNECT_CHALLENGE_TIMEOUT_MS, addSafeTimeoutDelayGraceMs, clampConnectChallengeTimeoutMs, getConnectChallengeTimeoutMsFromEnv, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openclaw/gateway-client",
|
|
3
|
+
"version": "2026.7.2-beta.4",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "@openclaw/gateway-client",
|
|
9
|
+
"version": "2026.7.2-beta.4",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"ipaddr.js": "2.4.0",
|
|
13
|
+
"ws": "8.21.1"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.19.0"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"node_modules/ipaddr.js": {
|
|
20
|
+
"version": "2.4.0",
|
|
21
|
+
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.4.0.tgz",
|
|
22
|
+
"integrity": "sha512-9VGk3HGanVE6JoZXHiCpnGy5X0jYDnN4EA4lntFPj+1vIWlFhIylq2CrrCOJH9EAhc5CYhq18F2Av2tgoAPsYQ==",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">= 10"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"node_modules/ws": {
|
|
29
|
+
"version": "8.21.1",
|
|
30
|
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.1.tgz",
|
|
31
|
+
"integrity": "sha512-+0NTnW77fFN/DjQi6k/Sq/Yvk4Sgajw7urW8V+asjXnRgDs9gyGkdb7EzgfhA4goXsRIZKE28fzIXBHEzhuiWw==",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=10.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"bufferutil": "^4.0.1",
|
|
38
|
+
"utf-8-validate": ">=5.0.2"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"bufferutil": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"utf-8-validate": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/gateway-client",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2026.7.2-beta.4",
|
|
4
|
+
"description": "Reference WebSocket client for the OpenClaw Gateway protocol",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"client",
|
|
7
|
+
"gateway",
|
|
8
|
+
"openclaw",
|
|
9
|
+
"websocket"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/openclaw/openclaw#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/openclaw/openclaw/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "OpenClaw Foundation (https://openclaw.org)",
|
|
5
17
|
"repository": {
|
|
6
18
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/openclaw/openclaw"
|
|
19
|
+
"url": "git+https://github.com/openclaw/openclaw.git",
|
|
20
|
+
"directory": "packages/gateway-client"
|
|
8
21
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"npm-shrinkwrap.json",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md",
|
|
27
|
+
"CHANGELOG.md"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"type": "module",
|
|
31
|
+
"main": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.mts",
|
|
36
|
+
"import": "./dist/index.mjs",
|
|
37
|
+
"default": "./dist/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./browser": {
|
|
40
|
+
"types": "./dist/browser.d.mts",
|
|
41
|
+
"import": "./dist/browser.mjs",
|
|
42
|
+
"default": "./dist/browser.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./readiness": {
|
|
45
|
+
"types": "./dist/readiness.d.mts",
|
|
46
|
+
"import": "./dist/readiness.mjs",
|
|
47
|
+
"default": "./dist/readiness.mjs"
|
|
48
|
+
},
|
|
49
|
+
"./timeouts": {
|
|
50
|
+
"types": "./dist/timeouts.d.mts",
|
|
51
|
+
"import": "./dist/timeouts.mjs",
|
|
52
|
+
"default": "./dist/timeouts.mjs"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"ipaddr.js": "2.4.0",
|
|
57
|
+
"ws": "8.21.1",
|
|
58
|
+
"@openclaw/gateway-protocol": "2026.7.2-beta.4"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=22.19.0"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"openclaw": {
|
|
67
|
+
"release": {
|
|
68
|
+
"publishToNpm": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsdown src/index.ts src/browser.ts src/readiness.ts src/timeouts.ts --no-config --platform node --format esm --dts --out-dir dist --clean"
|
|
73
|
+
}
|
|
74
|
+
}
|