@openclaw/gateway-client 2026.8.1-beta.3 → 2026.9.1-beta.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.
@@ -1,5 +1,4 @@
1
1
  import { ConnectParams, HelloOk } from "@openclaw/gateway-protocol";
2
-
3
2
  //#region packages/gateway-client/src/connect-auth.d.ts
4
3
  type GatewayConnectAuthSelection = {
5
4
  authToken?: string;
@@ -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-CKF7acYN.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-Dz6H7eXy.mjs";
3
- import { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-D4mVhLxE.mjs";
4
- import { a as GatewayProtocolTiming, i as GatewayProtocolSocketHandlers, n as GatewayProtocolCloseContext, o as GatewayProtocolRequestTiming, r as GatewayProtocolSocket, t as GatewayProtocolClient } from "./protocol-client-BbN-I582.mjs";
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-DNKXLO-Z.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-r0jkQ1XE.mjs";
4
+ import { a as GatewayProtocolTiming, i as GatewayProtocolSocketHandlers, n as GatewayProtocolCloseContext, o as GatewayProtocolRequestTiming, r as GatewayProtocolSocket, t as GatewayProtocolClient } from "./protocol-client-C-viHJgO.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,7 +9,6 @@ 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
13
  declare function shouldPauseGatewayReconnect(params: {
15
14
  details?: unknown;
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as resolveGatewayConnectScopes, D as buildDeviceAuthPayloadV3, E as buildDeviceAuthPayload, O as normalizeDeviceMetadataForAuth, S as buildGatewayConnectAuth, T as shouldRetryGatewayWithDeviceToken, _ as GatewayProtocolRequestError, a as createSessionProjection, b as gatewayOriginScope, c as projectLiveSessionMessage, d as reduceSessionProjectionRunEvent, f as normalizeSessionProjectionRunId, g as GatewayProtocolClient, h as shouldPauseGatewayReconnect, i as resetGatewaySessionMessageSubscriptionCoordinator, 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 GatewayProtocolRequestTimeoutError, w as selectGatewayConnectAuth, x as GatewayBrowserDeviceAuthLifecycle, y as gatewayCredentialScope } from "./session-subscriptions-OJnDJHPL.mjs";
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-Uxa34zU5.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,9 +1,8 @@
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-CKF7acYN.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-Dz6H7eXy.mjs";
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-DNKXLO-Z.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-JllUDKLg.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-CJ1QsCtR.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
7
  declare const CF_ACCESS_CLIENT_ID_HEADER = "CF-Access-Client-Id";
9
8
  declare const CF_ACCESS_CLIENT_SECRET_HEADER = "CF-Access-Client-Secret";
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as resolveGatewayConnectScopes, D as buildDeviceAuthPayloadV3, E as buildDeviceAuthPayload, O as normalizeDeviceMetadataForAuth, S as buildGatewayConnectAuth, T as shouldRetryGatewayWithDeviceToken, _ as GatewayProtocolRequestError, a as createSessionProjection, b as gatewayOriginScope, c as projectLiveSessionMessage, d as reduceSessionProjectionRunEvent, f as normalizeSessionProjectionRunId, g as GatewayProtocolClient, h as shouldPauseGatewayReconnect, i as resetGatewaySessionMessageSubscriptionCoordinator, 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 GatewayProtocolRequestTimeoutError, w as selectGatewayConnectAuth, x as GatewayBrowserDeviceAuthLifecycle, y as gatewayCredentialScope } from "./session-subscriptions-OJnDJHPL.mjs";
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-Uxa34zU5.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";
@@ -703,6 +703,11 @@ var GatewayClient = class {
703
703
  },
704
704
  notifyStoppedClose: true,
705
705
  onConnectError: (error) => this.notifyConnectError(error),
706
+ onReconnectStopped: (error) => this.notifyReconnectPaused({
707
+ code: 1008,
708
+ reason: error.message,
709
+ detailCode: null
710
+ }),
706
711
  onParseError: (error) => this.logDebug(`gateway client parse error: ${formatGatewayClientErrorForLog(error)}`),
707
712
  onEvent: (event) => this.opts.onEvent?.(event),
708
713
  onGap: (info) => this.opts.onGap?.(info),
@@ -810,6 +815,12 @@ var GatewayClient = class {
810
815
  ws.on("unexpected-response", (request, response) => {
811
816
  readUpgradeErrorBody(response).then((body) => {
812
817
  const statusCode = response.statusCode;
818
+ let gatewayError;
819
+ try {
820
+ const parsed = JSON.parse(body);
821
+ const parsedError = isRecord(parsed) ? parsed.error : void 0;
822
+ gatewayError = isRecord(parsedError) ? parsedError : void 0;
823
+ } catch {}
813
824
  const rawLocation = response.headers.location;
814
825
  const location = rawLocation ? redactSensitiveUrlLikeString(Array.isArray(rawLocation) ? rawLocation[0] ?? "" : rawLocation) : void 0;
815
826
  upgradeError = new GatewayClientRequestError({
@@ -819,7 +830,11 @@ var GatewayClient = class {
819
830
  details: {
820
831
  reason: "websocket-upgrade-rejected",
821
832
  ...statusCode === void 0 ? {} : { httpStatus: statusCode },
822
- ...location ? { location } : {}
833
+ ...location ? { location } : {},
834
+ ...typeof gatewayError?.type === "string" ? {
835
+ gatewayErrorType: gatewayError.type,
836
+ ...typeof gatewayError.message === "string" ? { gatewayErrorMessage: gatewayError.message } : {}
837
+ } : {}
823
838
  }
824
839
  });
825
840
  handlers.error(upgradeError);
@@ -1,6 +1,5 @@
1
- import { n as GatewayProtocolRequestOptions, t as GatewayProtocolRequestError } from "./protocol-request-D4mVhLxE.mjs";
1
+ import { n as GatewayProtocolRequestOptions, t as GatewayProtocolRequestError } from "./protocol-request-r0jkQ1XE.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;
@@ -1,7 +1,7 @@
1
- import { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-D4mVhLxE.mjs";
1
+ import { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-r0jkQ1XE.mjs";
2
+ import "./protocol-client-C-viHJgO.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; /** Already-resolved edge-proxy auth headers (identity-aware proxy in front of the Gateway). */
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; /** Prefer one setup credential for the first successful device-auth exchange. */
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"]; /** @deprecated Compatibility for the shipped v1 node-host connect envelope. */
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; /** Report retryable startup closes for clients that present connection progress. */
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"]; /** @deprecated Compatibility for the shipped v1 node-host connect envelope. */
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;
@@ -1,2 +1,2 @@
1
- import { a as startGatewayClientWithReadinessWait, i as startGatewayClientWhenEventLoopReady, n as GatewayClientStartReadinessOptions, r as GatewayClientStartable, t as EventLoopReadyWaiter } from "./readiness-JllUDKLg.mjs";
1
+ import { a as startGatewayClientWithReadinessWait, i as startGatewayClientWhenEventLoopReady, n as GatewayClientStartReadinessOptions, r as GatewayClientStartable, t as EventLoopReadyWaiter } from "./readiness-CJ1QsCtR.mjs";
2
2
  export { EventLoopReadyWaiter, GatewayClientStartReadinessOptions, GatewayClientStartable, startGatewayClientWhenEventLoopReady, startGatewayClientWithReadinessWait };
@@ -1,6 +1,5 @@
1
- import { a as GatewayBrowserDeviceTokenStore } from "./browser-device-auth-Dz6H7eXy.mjs";
2
- import { n as GatewayProtocolRequestOptions } from "./protocol-request-D4mVhLxE.mjs";
3
-
1
+ import { a as GatewayBrowserDeviceTokenStore } from "./browser-device-auth-DoPo-sPB.mjs";
2
+ import { n as GatewayProtocolRequestOptions } from "./protocol-request-r0jkQ1XE.mjs";
4
3
  //#region packages/gateway-client/src/scope-upgrade.d.ts
5
4
  type ScopeUpgradeBinding = {
6
5
  clientId: string;
@@ -1,5 +1,4 @@
1
- import { n as GatewayProtocolRequestOptions } from "./protocol-request-D4mVhLxE.mjs";
2
-
1
+ import { n as GatewayProtocolRequestOptions } from "./protocol-request-r0jkQ1XE.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 = {
@@ -562,13 +562,14 @@ var GatewayPendingRequests = class {
562
562
  pending.reject(this.opts.createRequestError?.(frame.error ?? {}) ?? new GatewayProtocolRequestError(frame.error ?? {}));
563
563
  }
564
564
  flush(error) {
565
- for (const [id, pending] of this.pending) {
566
- this.finishTiming(id, pending, false, "CLIENT_CLOSED");
565
+ const retired = [...this.pending];
566
+ this.pending.clear();
567
+ this.requestSequence = 0;
568
+ for (const [id, pending] of retired) {
567
569
  pending.cleanup?.();
570
+ this.finishTiming(id, pending, false, "CLIENT_CLOSED");
568
571
  pending.reject(error);
569
572
  }
570
- this.pending.clear();
571
- this.requestSequence = 0;
572
573
  }
573
574
  allocateRequestId() {
574
575
  this.requestSequence += 1;
@@ -730,8 +731,12 @@ var GatewayProtocolClient = class {
730
731
  const normalized = error instanceof Error ? error : new Error(String(error));
731
732
  this.opts.onSocketFactoryError?.(normalized);
732
733
  this.opts.onConnectError?.(normalized);
733
- if (this.opts.rethrowSocketFactoryError?.(normalized)) throw normalized;
734
+ if (this.opts.rethrowSocketFactoryError?.(normalized)) {
735
+ if (this.generation > 0 && !this.stopped && !this.socket && !this.reconnectSignal) this.opts.onReconnectStopped?.(normalized);
736
+ throw normalized;
737
+ }
734
738
  if (this.opts.shouldRetrySocketFactoryError?.(normalized) && !this.stopped && !this.socket && !this.reconnectSignal) this.scheduleReconnect();
739
+ else if (this.generation > 0 && !this.stopped && !this.socket && !this.reconnectSignal) this.opts.onReconnectStopped?.(normalized);
735
740
  return;
736
741
  }
737
742
  this.generation = generation;
@@ -924,7 +929,7 @@ var GatewayProtocolClient = class {
924
929
  const decision = this.opts.resolveClose(context);
925
930
  this.requests.flush(decision.pendingError ?? context.connectFailure?.error ?? /* @__PURE__ */ new Error(`gateway closed (${code}): ${reason}`));
926
931
  this.invoke("close", () => this.opts.onClose?.(context, decision));
927
- if (decision.retry && !this.stopped) this.scheduleReconnect(decision.reconnectDelayMs ?? context.connectFailure?.reconnectDelayMs);
932
+ if (decision.retry && !this.stopped && !this.socket && !this.reconnectSignal) this.scheduleReconnect(decision.reconnectDelayMs ?? context.connectFailure?.reconnectDelayMs);
928
933
  }
929
934
  handleSocketError(socket, generation, error) {
930
935
  if (!this.isActive(socket, generation) || this.connectSent) return;
@@ -939,7 +944,7 @@ var GatewayProtocolClient = class {
939
944
  sleepWithAbort(retry.delayMs, retry.signal).then(() => {
940
945
  if (this.reconnectSignal !== retry.signal) return;
941
946
  this.reconnectSignal = null;
942
- this.connect();
947
+ this.invoke("reconnect", () => this.connect());
943
948
  }, () => {
944
949
  if (this.reconnectSignal === retry.signal) this.reconnectSignal = null;
945
950
  });
@@ -1451,7 +1456,7 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
1451
1456
  if (this.#retired) throw new Error("Session message subscription belongs to a replaced Gateway connection");
1452
1457
  const existing = [...this.#entries].find((candidate) => candidate.agentId === agentId && (this.#areKeysEquivalent(candidate.key, normalizedKey) || [...candidate.requestedKeys].some((requestedKey) => this.#areKeysEquivalent(requestedKey, normalizedKey))));
1453
1458
  if (!existing) {
1454
- const provisional = [...this.#entries].find((candidate) => candidate.agentId === agentId && !candidate.canonicalSettled);
1459
+ const provisional = [...this.#entries].find((candidate) => candidate.agentId === agentId && !candidate.canonicalSettled && this.#couldShareCanonicalIdentity(candidate.key, normalizedKey));
1455
1460
  if (provisional) {
1456
1461
  await (provisional.plainFallback ?? provisional.ready).catch(() => void 0);
1457
1462
  continue;
@@ -1611,6 +1616,11 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
1611
1616
  #areKeysEquivalent(left, right) {
1612
1617
  return left === right || this.#keysEquivalent?.(left, right) === true;
1613
1618
  }
1619
+ #couldShareCanonicalIdentity(left, right) {
1620
+ const leftBody = left.replace(/^agent:[^:]+:/i, "").toLowerCase();
1621
+ const rightBody = right.replace(/^agent:[^:]+:/i, "").toLowerCase();
1622
+ return leftBody === rightBody || leftBody === "main" || rightBody === "main" || leftBody === "global" || rightBody === "global";
1623
+ }
1614
1624
  };
1615
1625
  const sessionMessageSubscriptionOwners = /* @__PURE__ */ new WeakMap();
1616
1626
  const sessionMessageSubscriptionCoordinators = /* @__PURE__ */ new WeakMap();
@@ -1629,4 +1639,4 @@ function releaseGatewaySessionMessageSubscription(subscription) {
1629
1639
  return sessionMessageSubscriptionOwners.get(subscription)?.coordinator.release(subscription) ?? Promise.resolve();
1630
1640
  }
1631
1641
  //#endregion
1632
- export { resolveGatewayConnectScopes as C, buildDeviceAuthPayloadV3 as D, buildDeviceAuthPayload as E, normalizeDeviceMetadataForAuth as O, buildGatewayConnectAuth as S, shouldRetryGatewayWithDeviceToken as T, GatewayProtocolRequestError as _, createSessionProjection as a, gatewayOriginScope as b, projectLiveSessionMessage as c, reduceSessionProjectionRunEvent as d, normalizeSessionProjectionRunId as f, GatewayProtocolClient as g, shouldPauseGatewayReconnect as h, resetGatewaySessionMessageSubscriptionCoordinator as i, 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, GatewayProtocolRequestTimeoutError as v, selectGatewayConnectAuth as w, GatewayBrowserDeviceAuthLifecycle as x, gatewayCredentialScope as y };
1642
+ 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
1
  import { RawData } from "ws";
2
-
3
2
  //#region packages/gateway-client/src/websocket-data.d.ts
4
3
  declare function rawDataToString(data: RawData, encoding?: BufferEncoding): string;
5
4
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/gateway-client",
3
- "version": "2026.8.1-beta.3",
3
+ "version": "2026.9.1-beta.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
- "ipaddr.js": "2.4.0",
66
- "ws": "8.21.1",
67
- "@openclaw/gateway-protocol": "2026.8.1-beta.3"
65
+ "ipaddr.js": "2.5.0",
66
+ "ws": "8.21.3",
67
+ "@openclaw/gateway-protocol": "2026.9.1-beta.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@openclaw/normalization-core": "0.0.0-private"