@openclaw/gateway-client 2026.8.1-beta.3 → 2026.8.1
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/dist/{browser-device-auth-Dz6H7eXy.d.mts → browser-device-auth-DoPo-sPB.d.mts} +0 -1
- package/dist/browser.d.mts +6 -7
- package/dist/browser.mjs +1 -1
- package/dist/index.d.mts +8 -9
- package/dist/index.mjs +51 -33
- package/dist/{protocol-client-BbN-I582.d.mts → protocol-client-BfrZgB1l.d.mts} +2 -2
- package/dist/{protocol-request-D4mVhLxE.d.mts → protocol-request-CcYZeK09.d.mts} +1 -1
- package/dist/{readiness-JllUDKLg.d.mts → readiness-bH1mOPOT.d.mts} +12 -7
- package/dist/readiness.d.mts +1 -1
- package/dist/scope-upgrade.d.mts +7 -9
- package/dist/{session-subscriptions-OJnDJHPL.mjs → session-subscriptions-BxuNBgqH.mjs} +49 -15
- package/dist/{session-subscriptions-CKF7acYN.d.mts → session-subscriptions-CZOt8niS.d.mts} +1 -2
- package/dist/timeouts.d.mts +15 -16
- package/dist/websocket-data.d.mts +2 -4
- package/package.json +4 -4
package/dist/browser.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as gatewayCredentialScope, C as reduceSessionProjection, D as normalizeSessionProjectionRunId, E as SessionMessageIdentity, M as buildDeviceAuthPayload, N as buildDeviceAuthPayloadV3, O as readSessionMessageIdentity, P as normalizeDeviceMetadataForAuth, S as reconcileSessionProjectionSnapshot, T as SessionMessageEnvelope, _ as SessionProjectionState, a as GatewaySessionMessageSubscriptionOptions, b as isLocallyOptimisticSessionMessage, c as resetGatewaySessionMessageSubscriptionCoordinator, d as SessionProjectionGatewayRunEvent, f as SessionProjectionRun, g as SessionProjectionSnapshotOptions, h as SessionProjectionScope, i as GatewaySessionMessageSubscriptionCoordinatorOptions, j as gatewayOriginScope, k as readSessionMessageSequence, l as SessionProjectionEntry, m as SessionProjectionRunTransition, n as GatewaySessionMessageSubscription, o as getGatewaySessionMessageSubscriptionCoordinator, p as SessionProjectionRunStatus, r as GatewaySessionMessageSubscriptionCoordinator, s as releaseGatewaySessionMessageSubscription, t as GatewaySessionMessageRequestClient, u as SessionProjectionEvent, v as createSessionProjection, w as reduceSessionProjectionRunEvent, x as projectLiveSessionMessage, y as hasSessionProjectionAcceptedFinal } from "./session-subscriptions-
|
|
2
|
-
import { a as GatewayBrowserDeviceTokenStore, c as resolveGatewayConnectScopes, i as GatewayBrowserDeviceTokenRecord, l as selectGatewayConnectAuth, n as GatewayBrowserDeviceAuthPlan, o as GatewayConnectAuthSelection, r as GatewayBrowserDeviceIdentity, s as buildGatewayConnectAuth, t as GatewayBrowserDeviceAuthLifecycle, u as shouldRetryGatewayWithDeviceToken } from "./browser-device-auth-
|
|
3
|
-
import { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-
|
|
4
|
-
import { a as GatewayProtocolTiming, i as GatewayProtocolSocketHandlers, n as GatewayProtocolCloseContext, o as GatewayProtocolRequestTiming, r as GatewayProtocolSocket, t as GatewayProtocolClient } from "./protocol-client-
|
|
1
|
+
import { A as gatewayCredentialScope, C as reduceSessionProjection, D as normalizeSessionProjectionRunId, E as SessionMessageIdentity, M as buildDeviceAuthPayload, N as buildDeviceAuthPayloadV3, O as readSessionMessageIdentity, P as normalizeDeviceMetadataForAuth, S as reconcileSessionProjectionSnapshot, T as SessionMessageEnvelope, _ as SessionProjectionState, a as GatewaySessionMessageSubscriptionOptions, b as isLocallyOptimisticSessionMessage, c as resetGatewaySessionMessageSubscriptionCoordinator, d as SessionProjectionGatewayRunEvent, f as SessionProjectionRun, g as SessionProjectionSnapshotOptions, h as SessionProjectionScope, i as GatewaySessionMessageSubscriptionCoordinatorOptions, j as gatewayOriginScope, k as readSessionMessageSequence, l as SessionProjectionEntry, m as SessionProjectionRunTransition, n as GatewaySessionMessageSubscription, o as getGatewaySessionMessageSubscriptionCoordinator, p as SessionProjectionRunStatus, r as GatewaySessionMessageSubscriptionCoordinator, s as releaseGatewaySessionMessageSubscription, t as GatewaySessionMessageRequestClient, u as SessionProjectionEvent, v as createSessionProjection, w as reduceSessionProjectionRunEvent, x as projectLiveSessionMessage, y as hasSessionProjectionAcceptedFinal } from "./session-subscriptions-CZOt8niS.mjs";
|
|
2
|
+
import { a as GatewayBrowserDeviceTokenStore, c as resolveGatewayConnectScopes, i as GatewayBrowserDeviceTokenRecord, l as selectGatewayConnectAuth, n as GatewayBrowserDeviceAuthPlan, o as GatewayConnectAuthSelection, r as GatewayBrowserDeviceIdentity, s as buildGatewayConnectAuth, t as GatewayBrowserDeviceAuthLifecycle, u as shouldRetryGatewayWithDeviceToken } from "./browser-device-auth-DoPo-sPB.mjs";
|
|
3
|
+
import { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-CcYZeK09.mjs";
|
|
4
|
+
import { a as GatewayProtocolTiming, i as GatewayProtocolSocketHandlers, n as GatewayProtocolCloseContext, o as GatewayProtocolRequestTiming, r as GatewayProtocolSocket, t as GatewayProtocolClient } from "./protocol-client-BfrZgB1l.mjs";
|
|
5
5
|
import { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, resolveSafeTimeoutDelayMs } from "./timeouts.mjs";
|
|
6
6
|
import { ConnectParams, ErrorShape, EventFrame, HelloOk } from "@openclaw/gateway-protocol";
|
|
7
7
|
export * from "@openclaw/gateway-protocol/connect-error-details";
|
|
@@ -9,9 +9,8 @@ export * from "@openclaw/gateway-protocol/client-info";
|
|
|
9
9
|
export * from "@openclaw/gateway-protocol/gateway-error-details";
|
|
10
10
|
export * from "@openclaw/gateway-protocol/startup-unavailable";
|
|
11
11
|
export * from "@openclaw/gateway-protocol/version";
|
|
12
|
-
|
|
13
12
|
//#region packages/gateway-client/src/reconnect-policy.d.ts
|
|
14
|
-
declare function shouldPauseGatewayReconnect(params: {
|
|
13
|
+
export declare function shouldPauseGatewayReconnect(params: {
|
|
15
14
|
details?: unknown;
|
|
16
15
|
deviceTokenRetryPending?: boolean;
|
|
17
16
|
tokenMismatchIsTerminal?: boolean;
|
|
@@ -19,4 +18,4 @@ declare function shouldPauseGatewayReconnect(params: {
|
|
|
19
18
|
clientVersionMismatchIsTerminal?: boolean;
|
|
20
19
|
}): boolean;
|
|
21
20
|
//#endregion
|
|
22
|
-
export { type ConnectParams, DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, type ErrorShape, type EventFrame, GatewayBrowserDeviceAuthLifecycle, GatewayBrowserDeviceAuthPlan, GatewayBrowserDeviceIdentity, GatewayBrowserDeviceTokenRecord, GatewayBrowserDeviceTokenStore, GatewayConnectAuthSelection, GatewayProtocolClient, type GatewayProtocolCloseContext, GatewayProtocolRequestError, type GatewayProtocolRequestOptions, GatewayProtocolRequestTimeoutError, type GatewayProtocolRequestTiming, type GatewayProtocolSocket, type GatewayProtocolSocketHandlers, type GatewayProtocolTiming, GatewaySessionMessageRequestClient, GatewaySessionMessageSubscription, GatewaySessionMessageSubscriptionCoordinator, GatewaySessionMessageSubscriptionCoordinatorOptions, GatewaySessionMessageSubscriptionOptions, type HelloOk, type SessionMessageEnvelope, type SessionMessageIdentity, SessionProjectionEntry, SessionProjectionEvent, SessionProjectionGatewayRunEvent, SessionProjectionRun, SessionProjectionRunStatus, SessionProjectionRunTransition, SessionProjectionScope, SessionProjectionSnapshotOptions, SessionProjectionState, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isLocallyOptimisticSessionMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readSessionMessageIdentity, readSessionMessageSequence, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveGatewayConnectScopes, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth,
|
|
21
|
+
export { type ConnectParams, DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, type ErrorShape, type EventFrame, GatewayBrowserDeviceAuthLifecycle, GatewayBrowserDeviceAuthPlan, GatewayBrowserDeviceIdentity, GatewayBrowserDeviceTokenRecord, GatewayBrowserDeviceTokenStore, GatewayConnectAuthSelection, GatewayProtocolClient, type GatewayProtocolCloseContext, GatewayProtocolRequestError, type GatewayProtocolRequestOptions, GatewayProtocolRequestTimeoutError, type GatewayProtocolRequestTiming, type GatewayProtocolSocket, type GatewayProtocolSocketHandlers, type GatewayProtocolTiming, GatewaySessionMessageRequestClient, GatewaySessionMessageSubscription, GatewaySessionMessageSubscriptionCoordinator, GatewaySessionMessageSubscriptionCoordinatorOptions, GatewaySessionMessageSubscriptionOptions, type HelloOk, type SessionMessageEnvelope, type SessionMessageIdentity, SessionProjectionEntry, SessionProjectionEvent, SessionProjectionGatewayRunEvent, SessionProjectionRun, SessionProjectionRunStatus, SessionProjectionRunTransition, SessionProjectionScope, SessionProjectionSnapshotOptions, SessionProjectionState, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isLocallyOptimisticSessionMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readSessionMessageIdentity, readSessionMessageSequence, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveGatewayConnectScopes, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken };
|
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as buildGatewayConnectAuth, D as buildDeviceAuthPayload, E as shouldRetryGatewayWithDeviceToken, O as buildDeviceAuthPayloadV3, S as GatewayBrowserDeviceAuthLifecycle, T as selectGatewayConnectAuth, _ as GatewayProtocolClient, a as createSessionProjection, b as gatewayCredentialScope, c as projectLiveSessionMessage, d as reduceSessionProjectionRunEvent, f as normalizeSessionProjectionRunId, g as shouldPauseGatewayReconnect, i as resetGatewaySessionMessageSubscriptionCoordinator, k as normalizeDeviceMetadataForAuth, l as reconcileSessionProjectionSnapshot, m as readSessionMessageSequence, n as getGatewaySessionMessageSubscriptionCoordinator, o as hasSessionProjectionAcceptedFinal, p as readSessionMessageIdentity, r as releaseGatewaySessionMessageSubscription, s as isLocallyOptimisticSessionMessage, t as GatewaySessionMessageSubscriptionCoordinator, u as reduceSessionProjection, v as GatewayProtocolRequestError, w as resolveGatewayConnectScopes, x as gatewayOriginScope, y as GatewayProtocolRequestTimeoutError } from "./session-subscriptions-BxuNBgqH.mjs";
|
|
2
2
|
import { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, resolveSafeTimeoutDelayMs } from "./timeouts.mjs";
|
|
3
3
|
export * from "@openclaw/gateway-protocol/connect-error-details";
|
|
4
4
|
export * from "@openclaw/gateway-protocol/client-info";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { A as gatewayCredentialScope, C as reduceSessionProjection, D as normalizeSessionProjectionRunId, E as SessionMessageIdentity, M as buildDeviceAuthPayload, N as buildDeviceAuthPayloadV3, O as readSessionMessageIdentity, P as normalizeDeviceMetadataForAuth, S as reconcileSessionProjectionSnapshot, T as SessionMessageEnvelope, _ as SessionProjectionState, a as GatewaySessionMessageSubscriptionOptions, b as isLocallyOptimisticSessionMessage, c as resetGatewaySessionMessageSubscriptionCoordinator, d as SessionProjectionGatewayRunEvent, f as SessionProjectionRun, g as SessionProjectionSnapshotOptions, h as SessionProjectionScope, i as GatewaySessionMessageSubscriptionCoordinatorOptions, j as gatewayOriginScope, k as readSessionMessageSequence, l as SessionProjectionEntry, m as SessionProjectionRunTransition, n as GatewaySessionMessageSubscription, o as getGatewaySessionMessageSubscriptionCoordinator, p as SessionProjectionRunStatus, r as GatewaySessionMessageSubscriptionCoordinator, s as releaseGatewaySessionMessageSubscription, t as GatewaySessionMessageRequestClient, u as SessionProjectionEvent, v as createSessionProjection, w as reduceSessionProjectionRunEvent, x as projectLiveSessionMessage, y as hasSessionProjectionAcceptedFinal } from "./session-subscriptions-
|
|
2
|
-
import { a as GatewayBrowserDeviceTokenStore, c as resolveGatewayConnectScopes, i as GatewayBrowserDeviceTokenRecord, l as selectGatewayConnectAuth, n as GatewayBrowserDeviceAuthPlan, o as GatewayConnectAuthSelection, r as GatewayBrowserDeviceIdentity, s as buildGatewayConnectAuth, t as GatewayBrowserDeviceAuthLifecycle, u as shouldRetryGatewayWithDeviceToken } from "./browser-device-auth-
|
|
1
|
+
import { A as gatewayCredentialScope, C as reduceSessionProjection, D as normalizeSessionProjectionRunId, E as SessionMessageIdentity, M as buildDeviceAuthPayload, N as buildDeviceAuthPayloadV3, O as readSessionMessageIdentity, P as normalizeDeviceMetadataForAuth, S as reconcileSessionProjectionSnapshot, T as SessionMessageEnvelope, _ as SessionProjectionState, a as GatewaySessionMessageSubscriptionOptions, b as isLocallyOptimisticSessionMessage, c as resetGatewaySessionMessageSubscriptionCoordinator, d as SessionProjectionGatewayRunEvent, f as SessionProjectionRun, g as SessionProjectionSnapshotOptions, h as SessionProjectionScope, i as GatewaySessionMessageSubscriptionCoordinatorOptions, j as gatewayOriginScope, k as readSessionMessageSequence, l as SessionProjectionEntry, m as SessionProjectionRunTransition, n as GatewaySessionMessageSubscription, o as getGatewaySessionMessageSubscriptionCoordinator, p as SessionProjectionRunStatus, r as GatewaySessionMessageSubscriptionCoordinator, s as releaseGatewaySessionMessageSubscription, t as GatewaySessionMessageRequestClient, u as SessionProjectionEvent, v as createSessionProjection, w as reduceSessionProjectionRunEvent, x as projectLiveSessionMessage, y as hasSessionProjectionAcceptedFinal } from "./session-subscriptions-CZOt8niS.mjs";
|
|
2
|
+
import { a as GatewayBrowserDeviceTokenStore, c as resolveGatewayConnectScopes, i as GatewayBrowserDeviceTokenRecord, l as selectGatewayConnectAuth, n as GatewayBrowserDeviceAuthPlan, o as GatewayConnectAuthSelection, r as GatewayBrowserDeviceIdentity, s as buildGatewayConnectAuth, t as GatewayBrowserDeviceAuthLifecycle, u as shouldRetryGatewayWithDeviceToken } from "./browser-device-auth-DoPo-sPB.mjs";
|
|
3
3
|
import { 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, clearGatewayConnectTimeout, getConnectChallengeTimeoutMsFromEnv, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, startGatewayConnectTimeout } from "./timeouts.mjs";
|
|
4
|
-
import { _ as GatewayClientRequestTimeoutError, a as startGatewayClientWithReadinessWait, b as GatewayClientRequestError, c as waitForEventLoopReady, d as GatewayClient, f as GatewayClientCloseInfo, g as GatewayClientRequestOptions, h as GatewayClientOptions, i as startGatewayClientWhenEventLoopReady, l as DeviceAuthTokenRecord, m as GatewayClientHostDeps, n as GatewayClientStartReadinessOptions, o as EventLoopReadyOptions, p as GatewayClientConnectionMetadata, r as GatewayClientStartable, s as EventLoopReadyResult, t as EventLoopReadyWaiter, u as DeviceIdentity, v as GatewayReconnectPausedInfo, y as isGatewayConnectAssemblyError } from "./readiness-
|
|
4
|
+
import { _ as GatewayClientRequestTimeoutError, a as startGatewayClientWithReadinessWait, b as GatewayClientRequestError, c as waitForEventLoopReady, d as GatewayClient, f as GatewayClientCloseInfo, g as GatewayClientRequestOptions, h as GatewayClientOptions, i as startGatewayClientWhenEventLoopReady, l as DeviceAuthTokenRecord, m as GatewayClientHostDeps, n as GatewayClientStartReadinessOptions, o as EventLoopReadyOptions, p as GatewayClientConnectionMetadata, r as GatewayClientStartable, s as EventLoopReadyResult, t as EventLoopReadyWaiter, u as DeviceIdentity, v as GatewayReconnectPausedInfo, y as isGatewayConnectAssemblyError } from "./readiness-bH1mOPOT.mjs";
|
|
5
5
|
import { GatewayScopeUpgrade, ScopeUpgradeBinding, ScopeUpgradeOptions, ScopeUpgradeOutcome } from "./scope-upgrade.mjs";
|
|
6
|
-
|
|
7
6
|
//#region packages/gateway-client/src/cloudflare-access.d.ts
|
|
8
|
-
declare const CF_ACCESS_CLIENT_ID_HEADER = "CF-Access-Client-Id";
|
|
9
|
-
declare const CF_ACCESS_CLIENT_SECRET_HEADER = "CF-Access-Client-Secret";
|
|
10
|
-
type CloudflareAccessCredentials = Readonly<{
|
|
7
|
+
export declare const CF_ACCESS_CLIENT_ID_HEADER = "CF-Access-Client-Id";
|
|
8
|
+
export declare const CF_ACCESS_CLIENT_SECRET_HEADER = "CF-Access-Client-Secret";
|
|
9
|
+
export type CloudflareAccessCredentials = Readonly<{
|
|
11
10
|
clientId: string;
|
|
12
11
|
clientSecret: string;
|
|
13
12
|
}>;
|
|
14
13
|
/** Build only the two headers Cloudflare Access defines for service-token auth. */
|
|
15
|
-
declare function buildCloudflareAccessHeaders(credentials: CloudflareAccessCredentials): Record<string, string>;
|
|
14
|
+
export declare function buildCloudflareAccessHeaders(credentials: CloudflareAccessCredentials): Record<string, string>;
|
|
16
15
|
//#endregion
|
|
17
|
-
export {
|
|
16
|
+
export { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, DeviceAuthTokenRecord, DeviceIdentity, EventLoopReadyOptions, EventLoopReadyResult, EventLoopReadyWaiter, GatewayBrowserDeviceAuthLifecycle, GatewayBrowserDeviceAuthPlan, GatewayBrowserDeviceIdentity, GatewayBrowserDeviceTokenRecord, GatewayBrowserDeviceTokenStore, GatewayClient, GatewayClientCloseInfo, GatewayClientConnectionMetadata, GatewayClientHostDeps, GatewayClientOptions, GatewayClientRequestError, GatewayClientRequestOptions, GatewayClientRequestTimeoutError, GatewayClientStartReadinessOptions, GatewayClientStartable, GatewayConnectAuthSelection, GatewayReconnectPausedInfo, GatewayScopeUpgrade, GatewaySessionMessageRequestClient, GatewaySessionMessageSubscription, GatewaySessionMessageSubscriptionCoordinator, GatewaySessionMessageSubscriptionCoordinatorOptions, GatewaySessionMessageSubscriptionOptions, MAX_CONNECT_CHALLENGE_TIMEOUT_MS, MAX_SAFE_TIMEOUT_DELAY_MS, MIN_CONNECT_CHALLENGE_TIMEOUT_MS, ScopeUpgradeBinding, ScopeUpgradeOptions, ScopeUpgradeOutcome, type SessionMessageEnvelope, type SessionMessageIdentity, SessionProjectionEntry, SessionProjectionEvent, SessionProjectionGatewayRunEvent, SessionProjectionRun, SessionProjectionRunStatus, SessionProjectionRunTransition, SessionProjectionScope, SessionProjectionSnapshotOptions, SessionProjectionState, addSafeTimeoutDelayGraceMs, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, clampConnectChallengeTimeoutMs, clearGatewayConnectTimeout, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getConnectChallengeTimeoutMsFromEnv, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isGatewayConnectAssemblyError, isLocallyOptimisticSessionMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readSessionMessageIdentity, readSessionMessageSequence, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolveGatewayConnectScopes, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken, startGatewayClientWhenEventLoopReady, startGatewayClientWithReadinessWait, startGatewayConnectTimeout, waitForEventLoopReady };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as buildGatewayConnectAuth, D as buildDeviceAuthPayload, E as shouldRetryGatewayWithDeviceToken, O as buildDeviceAuthPayloadV3, S as GatewayBrowserDeviceAuthLifecycle, T as selectGatewayConnectAuth, _ as GatewayProtocolClient, a as createSessionProjection, b as gatewayCredentialScope, c as projectLiveSessionMessage, d as reduceSessionProjectionRunEvent, f as normalizeSessionProjectionRunId, g as shouldPauseGatewayReconnect, h as isRecord, i as resetGatewaySessionMessageSubscriptionCoordinator, k as normalizeDeviceMetadataForAuth, l as reconcileSessionProjectionSnapshot, m as readSessionMessageSequence, n as getGatewaySessionMessageSubscriptionCoordinator, o as hasSessionProjectionAcceptedFinal, p as readSessionMessageIdentity, r as releaseGatewaySessionMessageSubscription, s as isLocallyOptimisticSessionMessage, t as GatewaySessionMessageSubscriptionCoordinator, u as reduceSessionProjection, v as GatewayProtocolRequestError, w as resolveGatewayConnectScopes, x as gatewayOriginScope, y as GatewayProtocolRequestTimeoutError } from "./session-subscriptions-BxuNBgqH.mjs";
|
|
2
2
|
import { 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, clearGatewayConnectTimeout, getConnectChallengeTimeoutMsFromEnv, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, startGatewayConnectTimeout } from "./timeouts.mjs";
|
|
3
3
|
import { rawDataToString } from "./websocket-data.mjs";
|
|
4
4
|
import { n as startGatewayClientWithReadinessWait, r as waitForEventLoopReady, t as startGatewayClientWhenEventLoopReady } from "./readiness-CrWxd4TI.mjs";
|
|
@@ -10,6 +10,7 @@ import { MIN_CLIENT_PROTOCOL_VERSION, MIN_NODE_PROTOCOL_VERSION, MIN_PROBE_PROTO
|
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { WebSocket } from "ws";
|
|
12
12
|
import ipaddr from "ipaddr.js";
|
|
13
|
+
import { TLSSocket } from "node:tls";
|
|
13
14
|
//#region packages/normalization-core/src/string-coerce.ts
|
|
14
15
|
/** Trims string input and returns null for non-strings or empty strings. */
|
|
15
16
|
function normalizeNullableString(value) {
|
|
@@ -484,6 +485,7 @@ function isSecureWebSocketUrl(rawUrl, options) {
|
|
|
484
485
|
}
|
|
485
486
|
}
|
|
486
487
|
var GatewayWebSocketTransportConfigurationError = class extends Error {};
|
|
488
|
+
var GatewayWebSocketTlsPinError = class extends Error {};
|
|
487
489
|
function resolveGatewayWebSocketTransport(params) {
|
|
488
490
|
const usesTls = isWssUrl(params.url);
|
|
489
491
|
if (params.tlsFingerprint && !usesTls) throw new GatewayWebSocketTransportConfigurationError("gateway tls fingerprint requires wss:// gateway url");
|
|
@@ -499,30 +501,37 @@ function resolveGatewayWebSocketTransport(params) {
|
|
|
499
501
|
const expectedFingerprint = params.tlsFingerprint ? normalizeTlsFingerprint(params.tlsFingerprint) : void 0;
|
|
500
502
|
if (params.tlsFingerprint && !expectedFingerprint) throw new GatewayWebSocketTransportConfigurationError("gateway tls fingerprint must be a SHA-256 fingerprint");
|
|
501
503
|
const options = { ...params.options };
|
|
502
|
-
if (usesTls && expectedFingerprint)
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
504
|
+
if (usesTls && expectedFingerprint) applyGatewayWebSocketTlsPin(options, expectedFingerprint, normalize);
|
|
505
|
+
return { options };
|
|
506
|
+
}
|
|
507
|
+
function applyGatewayWebSocketTlsPin(options, expectedFingerprint, normalize = normalizeTlsFingerprint) {
|
|
508
|
+
options.rejectUnauthorized = false;
|
|
509
|
+
const headers = { ...options.headers };
|
|
510
|
+
const deferredHeaders = Object.entries(headers).filter(([key]) => key.toLowerCase() === "expect");
|
|
511
|
+
for (const [key] of deferredHeaders) delete headers[key];
|
|
512
|
+
options.headers = headers;
|
|
513
|
+
options.finishRequest = (request) => {
|
|
514
|
+
request.once("socket", (socket) => {
|
|
515
|
+
if (!(socket instanceof TLSSocket)) {
|
|
516
|
+
request.destroy(new GatewayWebSocketTlsPinError("gateway tls fingerprint unavailable"));
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const validatePin = () => {
|
|
520
|
+
if (request.destroyed) return;
|
|
521
|
+
const canonicalFingerprint = normalizeTlsFingerprint(socket.getPeerCertificate()?.fingerprint256);
|
|
522
|
+
const fingerprint = canonicalFingerprint ? normalize(canonicalFingerprint) : "";
|
|
523
|
+
if (!fingerprint || fingerprint !== normalize(expectedFingerprint)) {
|
|
524
|
+
request.destroy(new GatewayWebSocketTlsPinError(fingerprint ? "gateway tls fingerprint mismatch" : "gateway tls fingerprint unavailable"));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
for (const [key, value] of deferredHeaders) if (value !== void 0) request.setHeader(key, value);
|
|
528
|
+
request.end();
|
|
529
|
+
};
|
|
530
|
+
if (socket.secureConnecting) {
|
|
531
|
+
socket.once("secureConnect", validatePin);
|
|
532
|
+
request.once("close", () => socket.off("secureConnect", validatePin));
|
|
533
|
+
} else validatePin();
|
|
534
|
+
});
|
|
526
535
|
};
|
|
527
536
|
}
|
|
528
537
|
//#endregion
|
|
@@ -703,6 +712,11 @@ var GatewayClient = class {
|
|
|
703
712
|
},
|
|
704
713
|
notifyStoppedClose: true,
|
|
705
714
|
onConnectError: (error) => this.notifyConnectError(error),
|
|
715
|
+
onReconnectStopped: (error) => this.notifyReconnectPaused({
|
|
716
|
+
code: 1008,
|
|
717
|
+
reason: error.message,
|
|
718
|
+
detailCode: null
|
|
719
|
+
}),
|
|
706
720
|
onParseError: (error) => this.logDebug(`gateway client parse error: ${formatGatewayClientErrorForLog(error)}`),
|
|
707
721
|
onEvent: (event) => this.opts.onEvent?.(event),
|
|
708
722
|
onGap: (info) => this.opts.onGap?.(info),
|
|
@@ -791,14 +805,8 @@ var GatewayClient = class {
|
|
|
791
805
|
this.transportValidated = false;
|
|
792
806
|
let upgradeError;
|
|
793
807
|
ws.on("open", () => {
|
|
794
|
-
handlers.open();
|
|
795
|
-
const tlsError = transport.validateSocket(ws);
|
|
796
|
-
if (tlsError) {
|
|
797
|
-
handlers.error(tlsError);
|
|
798
|
-
ws.close(1008, tlsError.message);
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
808
|
this.transportValidated = true;
|
|
809
|
+
handlers.open();
|
|
802
810
|
});
|
|
803
811
|
ws.on("message", (data) => handlers.message(rawDataToString(data)));
|
|
804
812
|
ws.on("close", (code, reason) => {
|
|
@@ -810,6 +818,12 @@ var GatewayClient = class {
|
|
|
810
818
|
ws.on("unexpected-response", (request, response) => {
|
|
811
819
|
readUpgradeErrorBody(response).then((body) => {
|
|
812
820
|
const statusCode = response.statusCode;
|
|
821
|
+
let gatewayError;
|
|
822
|
+
try {
|
|
823
|
+
const parsed = JSON.parse(body);
|
|
824
|
+
const parsedError = isRecord(parsed) ? parsed.error : void 0;
|
|
825
|
+
gatewayError = isRecord(parsedError) ? parsedError : void 0;
|
|
826
|
+
} catch {}
|
|
813
827
|
const rawLocation = response.headers.location;
|
|
814
828
|
const location = rawLocation ? redactSensitiveUrlLikeString(Array.isArray(rawLocation) ? rawLocation[0] ?? "" : rawLocation) : void 0;
|
|
815
829
|
upgradeError = new GatewayClientRequestError({
|
|
@@ -819,7 +833,11 @@ var GatewayClient = class {
|
|
|
819
833
|
details: {
|
|
820
834
|
reason: "websocket-upgrade-rejected",
|
|
821
835
|
...statusCode === void 0 ? {} : { httpStatus: statusCode },
|
|
822
|
-
...location ? { location } : {}
|
|
836
|
+
...location ? { location } : {},
|
|
837
|
+
...typeof gatewayError?.type === "string" ? {
|
|
838
|
+
gatewayErrorType: gatewayError.type,
|
|
839
|
+
...typeof gatewayError.message === "string" ? { gatewayErrorMessage: gatewayError.message } : {}
|
|
840
|
+
} : {}
|
|
823
841
|
}
|
|
824
842
|
});
|
|
825
843
|
handlers.error(upgradeError);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { n as GatewayProtocolRequestOptions, t as GatewayProtocolRequestError } from "./protocol-request-
|
|
1
|
+
import { n as GatewayProtocolRequestOptions, t as GatewayProtocolRequestError } from "./protocol-request-CcYZeK09.mjs";
|
|
2
2
|
import { ErrorShape, EventFrame, HelloOk } from "@openclaw/gateway-protocol";
|
|
3
|
-
|
|
4
3
|
//#region packages/gateway-client/src/pending-request.d.ts
|
|
5
4
|
type GatewayProtocolRequestTiming = {
|
|
6
5
|
id: string;
|
|
@@ -86,6 +85,7 @@ type GatewayProtocolClientOptions<TPlan> = {
|
|
|
86
85
|
notifyStoppedClose?: boolean;
|
|
87
86
|
onConnectError?: (error: Error) => void;
|
|
88
87
|
onSocketFactoryError?: (error: Error) => void;
|
|
88
|
+
onReconnectStopped?: (error: Error) => void;
|
|
89
89
|
onParseError?: (error: unknown) => void;
|
|
90
90
|
onEvent?: (event: EventFrame) => void;
|
|
91
91
|
onGap?: (info: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ErrorShape } from "@openclaw/gateway-protocol";
|
|
2
|
-
|
|
3
2
|
//#region packages/gateway-client/src/protocol-request.d.ts
|
|
4
3
|
type GatewayProtocolRequestOptions = {
|
|
5
4
|
timeoutMs?: number | null;
|
|
@@ -14,6 +13,7 @@ declare class GatewayProtocolRequestError extends Error {
|
|
|
14
13
|
readonly details?: unknown;
|
|
15
14
|
readonly retryable: boolean;
|
|
16
15
|
readonly retryAfterMs?: number;
|
|
16
|
+
readonly responsePayload?: unknown;
|
|
17
17
|
constructor(error: Partial<ErrorShape>);
|
|
18
18
|
}
|
|
19
19
|
/** A local transport deadline, distinct from a Gateway's authoritative rejection. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-
|
|
1
|
+
import { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-CcYZeK09.mjs";
|
|
2
|
+
import "./protocol-client-BfrZgB1l.mjs";
|
|
2
3
|
import { ConnectParams, ErrorShape, EventFrame, HelloOk } from "@openclaw/gateway-protocol/frame-guards";
|
|
3
4
|
import { GatewayClientMode, GatewayClientName } from "@openclaw/gateway-protocol/client-info";
|
|
4
|
-
|
|
5
5
|
//#region packages/gateway-client/src/request-error.d.ts
|
|
6
6
|
declare class GatewayClientRequestError extends GatewayProtocolRequestError {
|
|
7
7
|
constructor(error: Partial<ErrorShape>);
|
|
@@ -69,7 +69,8 @@ declare class GatewayClientRequestTimeoutError extends GatewayProtocolRequestTim
|
|
|
69
69
|
declare function isGatewayConnectAssemblyError(value: unknown): value is Error;
|
|
70
70
|
type GatewayClientOptions = {
|
|
71
71
|
url?: string;
|
|
72
|
-
origin?: string;
|
|
72
|
+
origin?: string;
|
|
73
|
+
/** Already-resolved edge-proxy auth headers (identity-aware proxy in front of the Gateway). */
|
|
73
74
|
edgeAuthHeaders?: Readonly<Record<string, string>>;
|
|
74
75
|
connectChallengeTimeoutMs?: number;
|
|
75
76
|
/**
|
|
@@ -81,7 +82,8 @@ type GatewayClientOptions = {
|
|
|
81
82
|
tickWatchTimeoutMs?: number;
|
|
82
83
|
requestTimeoutMs?: number;
|
|
83
84
|
token?: string;
|
|
84
|
-
bootstrapToken?: string;
|
|
85
|
+
bootstrapToken?: string;
|
|
86
|
+
/** Prefer one setup credential for the first successful device-auth exchange. */
|
|
85
87
|
preferBootstrapToken?: boolean;
|
|
86
88
|
deviceToken?: string;
|
|
87
89
|
password?: string;
|
|
@@ -99,7 +101,8 @@ type GatewayClientOptions = {
|
|
|
99
101
|
scopes?: string[];
|
|
100
102
|
caps?: string[];
|
|
101
103
|
commands?: string[];
|
|
102
|
-
computerUse?: ConnectParams["computerUse"];
|
|
104
|
+
computerUse?: ConnectParams["computerUse"];
|
|
105
|
+
/** @deprecated Compatibility for the shipped v1 node-host connect envelope. */
|
|
103
106
|
workerRuns?: ConnectParams["workerRuns"];
|
|
104
107
|
permissions?: Record<string, boolean>;
|
|
105
108
|
pathEnv?: string;
|
|
@@ -112,7 +115,8 @@ type GatewayClientOptions = {
|
|
|
112
115
|
onEvent?: (evt: EventFrame) => void;
|
|
113
116
|
onHelloOk?: (hello: HelloOk) => void;
|
|
114
117
|
onConnectError?: (err: Error) => void;
|
|
115
|
-
onReconnectPaused?: (info: GatewayReconnectPausedInfo) => void;
|
|
118
|
+
onReconnectPaused?: (info: GatewayReconnectPausedInfo) => void;
|
|
119
|
+
/** Report retryable startup closes for clients that present connection progress. */
|
|
116
120
|
notifyOnStartupRetry?: boolean;
|
|
117
121
|
onClose?: (code: number, reason: string, info?: GatewayClientCloseInfo) => void;
|
|
118
122
|
onGap?: (info: {
|
|
@@ -151,7 +155,8 @@ declare class GatewayClient {
|
|
|
151
155
|
updateNodeManifest(manifest: {
|
|
152
156
|
caps: string[];
|
|
153
157
|
commands: string[];
|
|
154
|
-
computerUse?: ConnectParams["computerUse"];
|
|
158
|
+
computerUse?: ConnectParams["computerUse"];
|
|
159
|
+
/** @deprecated Compatibility for the shipped v1 node-host connect envelope. */
|
|
155
160
|
workerRuns?: ConnectParams["workerRuns"];
|
|
156
161
|
}): void;
|
|
157
162
|
start(): void;
|
package/dist/readiness.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as startGatewayClientWithReadinessWait, i as startGatewayClientWhenEventLoopReady, n as GatewayClientStartReadinessOptions, r as GatewayClientStartable, t as EventLoopReadyWaiter } from "./readiness-
|
|
1
|
+
import { a as startGatewayClientWithReadinessWait, i as startGatewayClientWhenEventLoopReady, n as GatewayClientStartReadinessOptions, r as GatewayClientStartable, t as EventLoopReadyWaiter } from "./readiness-bH1mOPOT.mjs";
|
|
2
2
|
export { EventLoopReadyWaiter, GatewayClientStartReadinessOptions, GatewayClientStartable, startGatewayClientWhenEventLoopReady, startGatewayClientWithReadinessWait };
|
package/dist/scope-upgrade.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { a as GatewayBrowserDeviceTokenStore } from "./browser-device-auth-
|
|
2
|
-
import { n as GatewayProtocolRequestOptions } from "./protocol-request-
|
|
3
|
-
|
|
1
|
+
import { a as GatewayBrowserDeviceTokenStore } from "./browser-device-auth-DoPo-sPB.mjs";
|
|
2
|
+
import { n as GatewayProtocolRequestOptions } from "./protocol-request-CcYZeK09.mjs";
|
|
4
3
|
//#region packages/gateway-client/src/scope-upgrade.d.ts
|
|
5
|
-
type ScopeUpgradeBinding = {
|
|
4
|
+
export type ScopeUpgradeBinding = {
|
|
6
5
|
clientId: string;
|
|
7
6
|
deviceId: string;
|
|
8
7
|
role: string;
|
|
9
8
|
};
|
|
10
|
-
type ScopeUpgradeOutcome = {
|
|
9
|
+
export type ScopeUpgradeOutcome = {
|
|
11
10
|
status: "approved";
|
|
12
11
|
requestId: string;
|
|
13
12
|
scopes: string[];
|
|
@@ -15,14 +14,14 @@ type ScopeUpgradeOutcome = {
|
|
|
15
14
|
status: "rejected" | "expired";
|
|
16
15
|
requestId: string;
|
|
17
16
|
};
|
|
18
|
-
type ScopeUpgradeOptions = {
|
|
17
|
+
export type ScopeUpgradeOptions = {
|
|
19
18
|
binding: ScopeUpgradeBinding;
|
|
20
19
|
scopes: readonly string[];
|
|
21
20
|
onPending?: (requestId: string) => void;
|
|
22
21
|
};
|
|
23
22
|
type UpgradeRequester = (method: string, params?: unknown, options?: GatewayProtocolRequestOptions) => Promise<unknown>;
|
|
24
23
|
/** Runs one browser device scope upgrade and owns rotated-token persistence. */
|
|
25
|
-
declare class GatewayScopeUpgrade {
|
|
24
|
+
export declare class GatewayScopeUpgrade {
|
|
26
25
|
private readonly deps;
|
|
27
26
|
private active?;
|
|
28
27
|
constructor(deps: {
|
|
@@ -34,5 +33,4 @@ declare class GatewayScopeUpgrade {
|
|
|
34
33
|
cancelScopeUpgrade(): void;
|
|
35
34
|
private runUpgrade;
|
|
36
35
|
}
|
|
37
|
-
//#endregion
|
|
38
|
-
export { GatewayScopeUpgrade, ScopeUpgradeBinding, ScopeUpgradeOptions, ScopeUpgradeOutcome };
|
|
36
|
+
//#endregion
|
|
@@ -444,6 +444,14 @@ var GatewayProtocolRequestError = class extends Error {
|
|
|
444
444
|
this.retryAfterMs = error.retryAfterMs;
|
|
445
445
|
}
|
|
446
446
|
};
|
|
447
|
+
/** Preserve response metadata after custom factories without adding it to error JSON. */
|
|
448
|
+
function retainGatewayResponsePayload(error, payload) {
|
|
449
|
+
Object.defineProperty(error, "responsePayload", {
|
|
450
|
+
value: payload,
|
|
451
|
+
enumerable: false,
|
|
452
|
+
configurable: true
|
|
453
|
+
});
|
|
454
|
+
}
|
|
447
455
|
/** A local transport deadline, distinct from a Gateway's authoritative rejection. */
|
|
448
456
|
var GatewayProtocolRequestTimeoutError = class extends Error {
|
|
449
457
|
constructor(params, message = `gateway request timed out after ${params.timeoutMs}ms: ${params.method}`) {
|
|
@@ -544,7 +552,7 @@ var GatewayPendingRequests = class {
|
|
|
544
552
|
const pending = this.pending.get(frame.id);
|
|
545
553
|
if (!pending) return;
|
|
546
554
|
const status = frame.payload?.status;
|
|
547
|
-
if (pending.expectFinal && status === "accepted") {
|
|
555
|
+
if (frame.ok && pending.expectFinal && status === "accepted") {
|
|
548
556
|
if (!pending.acceptedNotified) {
|
|
549
557
|
pending.acceptedNotified = true;
|
|
550
558
|
this.invoke("accepted", () => pending.onAccepted?.(frame.payload));
|
|
@@ -559,16 +567,19 @@ var GatewayPendingRequests = class {
|
|
|
559
567
|
return;
|
|
560
568
|
}
|
|
561
569
|
this.finishTiming(frame.id, pending, false, frame.error?.code);
|
|
562
|
-
|
|
570
|
+
const error = this.opts.createRequestError?.(frame.error ?? {}) ?? new GatewayProtocolRequestError(frame.error ?? {});
|
|
571
|
+
retainGatewayResponsePayload(error, frame.payload);
|
|
572
|
+
pending.reject(error);
|
|
563
573
|
}
|
|
564
574
|
flush(error) {
|
|
565
|
-
|
|
566
|
-
|
|
575
|
+
const retired = [...this.pending];
|
|
576
|
+
this.pending.clear();
|
|
577
|
+
this.requestSequence = 0;
|
|
578
|
+
for (const [id, pending] of retired) {
|
|
567
579
|
pending.cleanup?.();
|
|
580
|
+
this.finishTiming(id, pending, false, "CLIENT_CLOSED");
|
|
568
581
|
pending.reject(error);
|
|
569
582
|
}
|
|
570
|
-
this.pending.clear();
|
|
571
|
-
this.requestSequence = 0;
|
|
572
583
|
}
|
|
573
584
|
allocateRequestId() {
|
|
574
585
|
this.requestSequence += 1;
|
|
@@ -730,8 +741,12 @@ var GatewayProtocolClient = class {
|
|
|
730
741
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
731
742
|
this.opts.onSocketFactoryError?.(normalized);
|
|
732
743
|
this.opts.onConnectError?.(normalized);
|
|
733
|
-
if (this.opts.rethrowSocketFactoryError?.(normalized))
|
|
744
|
+
if (this.opts.rethrowSocketFactoryError?.(normalized)) {
|
|
745
|
+
if (this.generation > 0 && !this.stopped && !this.socket && !this.reconnectSignal) this.opts.onReconnectStopped?.(normalized);
|
|
746
|
+
throw normalized;
|
|
747
|
+
}
|
|
734
748
|
if (this.opts.shouldRetrySocketFactoryError?.(normalized) && !this.stopped && !this.socket && !this.reconnectSignal) this.scheduleReconnect();
|
|
749
|
+
else if (this.generation > 0 && !this.stopped && !this.socket && !this.reconnectSignal) this.opts.onReconnectStopped?.(normalized);
|
|
735
750
|
return;
|
|
736
751
|
}
|
|
737
752
|
this.generation = generation;
|
|
@@ -820,7 +835,7 @@ var GatewayProtocolClient = class {
|
|
|
820
835
|
this.recordTiming("request-sent", generation, plan);
|
|
821
836
|
this.connectRequestSent = true;
|
|
822
837
|
this.request("connect", this.opts.buildConnectParams(plan)).then((hello) => {
|
|
823
|
-
if (!this.isActive(socket, generation)) return;
|
|
838
|
+
if (!this.isActive(socket, generation) || !socket.isOpen()) return;
|
|
824
839
|
this.helloReceived = true;
|
|
825
840
|
this.clearHandshakeTimer();
|
|
826
841
|
this.connectFailure = void 0;
|
|
@@ -924,7 +939,7 @@ var GatewayProtocolClient = class {
|
|
|
924
939
|
const decision = this.opts.resolveClose(context);
|
|
925
940
|
this.requests.flush(decision.pendingError ?? context.connectFailure?.error ?? /* @__PURE__ */ new Error(`gateway closed (${code}): ${reason}`));
|
|
926
941
|
this.invoke("close", () => this.opts.onClose?.(context, decision));
|
|
927
|
-
if (decision.retry && !this.stopped) this.scheduleReconnect(decision.reconnectDelayMs ?? context.connectFailure?.reconnectDelayMs);
|
|
942
|
+
if (decision.retry && !this.stopped && !this.socket && !this.reconnectSignal) this.scheduleReconnect(decision.reconnectDelayMs ?? context.connectFailure?.reconnectDelayMs);
|
|
928
943
|
}
|
|
929
944
|
handleSocketError(socket, generation, error) {
|
|
930
945
|
if (!this.isActive(socket, generation) || this.connectSent) return;
|
|
@@ -939,7 +954,7 @@ var GatewayProtocolClient = class {
|
|
|
939
954
|
sleepWithAbort(retry.delayMs, retry.signal).then(() => {
|
|
940
955
|
if (this.reconnectSignal !== retry.signal) return;
|
|
941
956
|
this.reconnectSignal = null;
|
|
942
|
-
this.connect();
|
|
957
|
+
this.invoke("reconnect", () => this.connect());
|
|
943
958
|
}, () => {
|
|
944
959
|
if (this.reconnectSignal === retry.signal) this.reconnectSignal = null;
|
|
945
960
|
});
|
|
@@ -1192,10 +1207,24 @@ function insertEntry(entries, incoming, runs) {
|
|
|
1192
1207
|
const candidate = entry.identity?.sequence;
|
|
1193
1208
|
return candidate !== void 0 && candidate !== null && candidate > sequence;
|
|
1194
1209
|
});
|
|
1195
|
-
if (
|
|
1210
|
+
if (sequence !== void 0 && sequence !== null && nextIndex < 0) nextIndex = entries.length;
|
|
1211
|
+
if (incoming.identity?.role === "user" && incoming.identity.runId) {
|
|
1196
1212
|
const runId = incoming.identity.runId;
|
|
1197
1213
|
const terminalMessage = runs?.[runId]?.message;
|
|
1198
|
-
|
|
1214
|
+
const belongsToRun = (entry) => entry.identity?.role === "assistant" && (entry.identity.runId === runId || entry.message === terminalMessage);
|
|
1215
|
+
if (sequence !== void 0 && sequence !== null) {
|
|
1216
|
+
const before = [];
|
|
1217
|
+
const replies = [];
|
|
1218
|
+
for (const entry of entries.slice(0, nextIndex)) (entry.identity?.sequence === null && belongsToRun(entry) ? replies : before).push(entry);
|
|
1219
|
+
return [
|
|
1220
|
+
...before,
|
|
1221
|
+
incoming,
|
|
1222
|
+
...replies,
|
|
1223
|
+
...entries.slice(nextIndex)
|
|
1224
|
+
];
|
|
1225
|
+
}
|
|
1226
|
+
const terminalIndex = entries.findIndex(belongsToRun);
|
|
1227
|
+
if (terminalIndex >= 0 && (nextIndex < 0 || terminalIndex < nextIndex)) nextIndex = terminalIndex;
|
|
1199
1228
|
}
|
|
1200
1229
|
return nextIndex < 0 ? [...entries, incoming] : [
|
|
1201
1230
|
...entries.slice(0, nextIndex),
|
|
@@ -1215,7 +1244,7 @@ function projectLiveSessionMessage(state, message, envelope, scope = {}) {
|
|
|
1215
1244
|
const existing = state.entries[existingIndex];
|
|
1216
1245
|
if (existing && existing.message === message && existing.live && !existing.pending) return state;
|
|
1217
1246
|
if (existing && !existing.pending && existing.identity?.id && !incoming.identity.id) return state;
|
|
1218
|
-
if (existing
|
|
1247
|
+
if (existing && incoming.identity.sequence !== null && (existing.pending || existing.identity?.sequence === null)) {
|
|
1219
1248
|
const sequence = incoming.identity.sequence;
|
|
1220
1249
|
return withEntries(state, state.entries.some(({ identity }, index) => identity?.sequence != null && (index < existingIndex ? identity.sequence > sequence : identity.sequence < sequence)) ? insertEntry(state.entries.filter((_, index) => index !== existingIndex), incoming, state.runs) : state.entries.toSpliced(existingIndex, 1, incoming));
|
|
1221
1250
|
}
|
|
@@ -1451,7 +1480,7 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
|
|
|
1451
1480
|
if (this.#retired) throw new Error("Session message subscription belongs to a replaced Gateway connection");
|
|
1452
1481
|
const existing = [...this.#entries].find((candidate) => candidate.agentId === agentId && (this.#areKeysEquivalent(candidate.key, normalizedKey) || [...candidate.requestedKeys].some((requestedKey) => this.#areKeysEquivalent(requestedKey, normalizedKey))));
|
|
1453
1482
|
if (!existing) {
|
|
1454
|
-
const provisional = [...this.#entries].find((candidate) => candidate.agentId === agentId && !candidate.canonicalSettled);
|
|
1483
|
+
const provisional = [...this.#entries].find((candidate) => candidate.agentId === agentId && !candidate.canonicalSettled && this.#couldShareCanonicalIdentity(candidate.key, normalizedKey));
|
|
1455
1484
|
if (provisional) {
|
|
1456
1485
|
await (provisional.plainFallback ?? provisional.ready).catch(() => void 0);
|
|
1457
1486
|
continue;
|
|
@@ -1611,6 +1640,11 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
|
|
|
1611
1640
|
#areKeysEquivalent(left, right) {
|
|
1612
1641
|
return left === right || this.#keysEquivalent?.(left, right) === true;
|
|
1613
1642
|
}
|
|
1643
|
+
#couldShareCanonicalIdentity(left, right) {
|
|
1644
|
+
const leftBody = left.replace(/^agent:[^:]+:/i, "").toLowerCase();
|
|
1645
|
+
const rightBody = right.replace(/^agent:[^:]+:/i, "").toLowerCase();
|
|
1646
|
+
return leftBody === rightBody || leftBody === "main" || rightBody === "main" || leftBody === "global" || rightBody === "global";
|
|
1647
|
+
}
|
|
1614
1648
|
};
|
|
1615
1649
|
const sessionMessageSubscriptionOwners = /* @__PURE__ */ new WeakMap();
|
|
1616
1650
|
const sessionMessageSubscriptionCoordinators = /* @__PURE__ */ new WeakMap();
|
|
@@ -1629,4 +1663,4 @@ function releaseGatewaySessionMessageSubscription(subscription) {
|
|
|
1629
1663
|
return sessionMessageSubscriptionOwners.get(subscription)?.coordinator.release(subscription) ?? Promise.resolve();
|
|
1630
1664
|
}
|
|
1631
1665
|
//#endregion
|
|
1632
|
-
export {
|
|
1666
|
+
export { buildGatewayConnectAuth as C, buildDeviceAuthPayload as D, shouldRetryGatewayWithDeviceToken as E, buildDeviceAuthPayloadV3 as O, GatewayBrowserDeviceAuthLifecycle as S, selectGatewayConnectAuth as T, GatewayProtocolClient as _, createSessionProjection as a, gatewayCredentialScope as b, projectLiveSessionMessage as c, reduceSessionProjectionRunEvent as d, normalizeSessionProjectionRunId as f, shouldPauseGatewayReconnect as g, isRecord as h, resetGatewaySessionMessageSubscriptionCoordinator as i, normalizeDeviceMetadataForAuth as k, reconcileSessionProjectionSnapshot as l, readSessionMessageSequence as m, getGatewaySessionMessageSubscriptionCoordinator as n, hasSessionProjectionAcceptedFinal as o, readSessionMessageIdentity as p, releaseGatewaySessionMessageSubscription as r, isLocallyOptimisticSessionMessage as s, GatewaySessionMessageSubscriptionCoordinator as t, reduceSessionProjection as u, GatewayProtocolRequestError as v, resolveGatewayConnectScopes as w, gatewayOriginScope as x, GatewayProtocolRequestTimeoutError as y };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as GatewayProtocolRequestOptions } from "./protocol-request-
|
|
2
|
-
|
|
1
|
+
import { n as GatewayProtocolRequestOptions } from "./protocol-request-CcYZeK09.mjs";
|
|
3
2
|
//#region packages/gateway-client/src/device-auth.d.ts
|
|
4
3
|
declare function normalizeDeviceMetadataForAuth(value?: string | null): string;
|
|
5
4
|
type DeviceAuthPayloadParams = {
|
package/dist/timeouts.d.mts
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
//#region packages/gateway-client/src/timeouts.d.ts
|
|
2
2
|
/** Maximum delay Node timers can represent without overflow warnings. */
|
|
3
|
-
declare const MAX_SAFE_TIMEOUT_DELAY_MS = 2147483647;
|
|
3
|
+
export declare const MAX_SAFE_TIMEOUT_DELAY_MS = 2147483647;
|
|
4
4
|
/** Default server-side window for gateway preauth handshakes. */
|
|
5
|
-
declare const DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = 15000;
|
|
5
|
+
export declare const DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = 15000;
|
|
6
6
|
/** Starts the browser-safe deadline that covers Gateway connect preparation and hello. */
|
|
7
|
-
declare function startGatewayConnectTimeout(onTimeout: () => void): ReturnType<typeof setTimeout>;
|
|
7
|
+
export declare function startGatewayConnectTimeout(onTimeout: () => void): ReturnType<typeof setTimeout>;
|
|
8
8
|
/** Clears either pending Gateway handshake phase without retaining its timer. */
|
|
9
|
-
declare function clearGatewayConnectTimeout(timer: ReturnType<typeof setTimeout> | null): null;
|
|
9
|
+
export declare function clearGatewayConnectTimeout(timer: ReturnType<typeof setTimeout> | null): null;
|
|
10
10
|
/** Default deadline for a single non-streaming Gateway request. */
|
|
11
|
-
declare const DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS = 30000;
|
|
11
|
+
export declare const DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS = 30000;
|
|
12
12
|
/** Minimum client watchdog delay for connect challenge setup. */
|
|
13
|
-
declare const MIN_CONNECT_CHALLENGE_TIMEOUT_MS = 250;
|
|
13
|
+
export declare const MIN_CONNECT_CHALLENGE_TIMEOUT_MS = 250;
|
|
14
14
|
/** Default maximum client watchdog delay, aligned with the preauth server timeout. */
|
|
15
|
-
declare const MAX_CONNECT_CHALLENGE_TIMEOUT_MS = 15000;
|
|
15
|
+
export declare const MAX_CONNECT_CHALLENGE_TIMEOUT_MS = 15000;
|
|
16
16
|
/** Clamps arbitrary timer delays to Node's safe range and an optional floor. */
|
|
17
|
-
declare function resolveSafeTimeoutDelayMs(delayMs: number, opts?: {
|
|
17
|
+
export declare function resolveSafeTimeoutDelayMs(delayMs: number, opts?: {
|
|
18
18
|
minMs?: number;
|
|
19
19
|
}): number;
|
|
20
20
|
/** Adds grace time while preserving safe timer bounds if inputs overflow or are invalid. */
|
|
21
|
-
declare function addSafeTimeoutDelayGraceMs(delayMs: number, graceMs: number, opts?: {
|
|
21
|
+
export declare function addSafeTimeoutDelayGraceMs(delayMs: number, graceMs: number, opts?: {
|
|
22
22
|
minMs?: number;
|
|
23
23
|
}): number;
|
|
24
24
|
/** Resolves optional timeout values through a fallback and safe timer clamp. */
|
|
25
|
-
declare function resolveFiniteTimeoutDelayMs(delayMs: number | null | undefined, fallbackMs: number, opts?: {
|
|
25
|
+
export declare function resolveFiniteTimeoutDelayMs(delayMs: number | null | undefined, fallbackMs: number, opts?: {
|
|
26
26
|
minMs?: number;
|
|
27
27
|
}): number;
|
|
28
28
|
/** Clamps connect challenge watchdog timeouts to the gateway-supported range. */
|
|
29
|
-
declare function clampConnectChallengeTimeoutMs(timeoutMs: number, maxTimeoutMs?: number): number;
|
|
29
|
+
export declare function clampConnectChallengeTimeoutMs(timeoutMs: number, maxTimeoutMs?: number): number;
|
|
30
30
|
/** Reads the connect challenge watchdog override from the process environment. */
|
|
31
|
-
declare function getConnectChallengeTimeoutMsFromEnv(env?: NodeJS.ProcessEnv): number | undefined;
|
|
31
|
+
export declare function getConnectChallengeTimeoutMsFromEnv(env?: NodeJS.ProcessEnv): number | undefined;
|
|
32
32
|
/** Resolves the client watchdog timeout using explicit, env, then preauth defaults. */
|
|
33
|
-
declare function resolveConnectChallengeTimeoutMs(timeoutMs?: number | null, params?: {
|
|
33
|
+
export declare function resolveConnectChallengeTimeoutMs(timeoutMs?: number | null, params?: {
|
|
34
34
|
env?: NodeJS.ProcessEnv;
|
|
35
35
|
configuredTimeoutMs?: number | null;
|
|
36
36
|
}): number;
|
|
37
37
|
/** Resolves the server preauth timeout from env, explicit config, or default. */
|
|
38
|
-
declare function resolvePreauthHandshakeTimeoutMs(params?: {
|
|
38
|
+
export declare function resolvePreauthHandshakeTimeoutMs(params?: {
|
|
39
39
|
env?: NodeJS.ProcessEnv;
|
|
40
40
|
configuredTimeoutMs?: number | null;
|
|
41
41
|
}): number;
|
|
42
|
-
//#endregion
|
|
43
|
-
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, clearGatewayConnectTimeout, getConnectChallengeTimeoutMsFromEnv, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, startGatewayConnectTimeout };
|
|
42
|
+
//#endregion
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { RawData } from "ws";
|
|
2
|
-
|
|
3
2
|
//#region packages/gateway-client/src/websocket-data.d.ts
|
|
4
|
-
declare function rawDataToString(data: RawData, encoding?: BufferEncoding): string;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { rawDataToString };
|
|
3
|
+
export declare function rawDataToString(data: RawData, encoding?: BufferEncoding): string;
|
|
4
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/gateway-client",
|
|
3
|
-
"version": "2026.8.1
|
|
3
|
+
"version": "2026.8.1",
|
|
4
4
|
"description": "Reference WebSocket client for the OpenClaw Gateway protocol",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"client",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
65
|
+
"@openclaw/gateway-protocol": "2026.8.1",
|
|
66
|
+
"ipaddr.js": "2.5.0",
|
|
67
|
+
"ws": "8.21.3"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@openclaw/normalization-core": "0.0.0-private"
|