@openclaw/gateway-client 2026.9.2 → 2026.9.3

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,12 +1,12 @@
1
- import { A as readSessionMessageSequence, C as reduceSessionProjection, D as normalizeSessionProjectionRunId, E as SessionMessageIdentity, F as normalizeDeviceMetadataForAuth, M as gatewayOriginScope, N as buildDeviceAuthPayload, O as readAssistantStreamSegmentIdentity, P as buildDeviceAuthPayloadV3, 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 gatewayCredentialScope, k as readSessionMessageIdentity, 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-D2UdeJ0u.mjs";
1
+ import { A as readAssistantStreamSegmentIdentity, C as isSessionProjectionErrorMessage, D as SessionMessageEnvelope, E as reduceSessionProjectionRunEvent, F as buildDeviceAuthPayload, I as buildDeviceAuthPayloadV3, L as normalizeDeviceMetadataForAuth, M as readSessionMessageSequence, N as gatewayCredentialScope, O as SessionMessageIdentity, P as gatewayOriginScope, S as reduceSessionProjection, T as SessionProjectionRunTransition, _ as hasSessionProjectionAcceptedFinal, a as GatewaySessionMessageSubscriptionOptions, b as readSessionProjectionFinalMessageIdentity, c as resetGatewaySessionMessageSubscriptionCoordinator, d as SessionProjectionRun, f as SessionProjectionRunStatus, g as createSessionProjection, h as SessionProjectionState, i as GatewaySessionMessageSubscriptionCoordinatorOptions, j as readSessionMessageIdentity, k as normalizeSessionProjectionRunId, l as SessionProjectionEntry, m as SessionProjectionSnapshotOptions, n as GatewaySessionMessageSubscription, o as getGatewaySessionMessageSubscriptionCoordinator, p as SessionProjectionScope, r as GatewaySessionMessageSubscriptionCoordinator, s as releaseGatewaySessionMessageSubscription, t as GatewaySessionMessageRequestClient, u as SessionProjectionEvent, v as isLocallyOptimisticSessionMessage, w as SessionProjectionGatewayRunEvent, x as reconcileSessionProjectionSnapshot, y as projectLiveSessionMessage } from "./session-subscriptions-C3M4jnCd.mjs";
2
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 { n as GatewayProtocolRequestOptions, r as GatewayProtocolRequestTimeoutError, t as GatewayProtocolRequestError } from "./protocol-request-B5gBmLgq.mjs";
4
4
  import { a as GatewayProtocolTiming, i as GatewayProtocolSocketHandlers, n as GatewayProtocolCloseContext, o as GatewayProtocolRequestTiming, r as GatewayProtocolSocket, t as GatewayProtocolClient } from "./protocol-client-DbX7wQED.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";
8
- export * from "@openclaw/gateway-protocol/client-info";
9
8
  export * from "@openclaw/gateway-protocol/gateway-error-details";
9
+ export * from "@openclaw/gateway-protocol/client-info";
10
10
  export * from "@openclaw/gateway-protocol/startup-unavailable";
11
11
  export * from "@openclaw/gateway-protocol/version";
12
12
  //#region packages/gateway-client/src/reconnect-policy.d.ts
@@ -18,4 +18,4 @@ export declare function shouldPauseGatewayReconnect(params: {
18
18
  clientVersionMismatchIsTerminal?: boolean;
19
19
  }): boolean;
20
20
  //#endregion
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, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveGatewayConnectScopes, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken };
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, type SessionProjectionGatewayRunEvent, SessionProjectionRun, SessionProjectionRunStatus, type SessionProjectionRunTransition, SessionProjectionScope, SessionProjectionSnapshotOptions, SessionProjectionState, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isLocallyOptimisticSessionMessage, isSessionProjectionErrorMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, readSessionProjectionFinalMessageIdentity, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveGatewayConnectScopes, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken };
package/dist/browser.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { A as buildDeviceAuthPayloadV3, C as gatewayOriginScope, D as selectGatewayConnectAuth, E as resolveGatewayConnectScopes, O as shouldRetryGatewayWithDeviceToken, S as gatewayCredentialScope, T as buildGatewayConnectAuth, _ as shouldPauseGatewayReconnect, a as createSessionProjection, b as GatewayProtocolRequestTimeoutError, c as projectLiveSessionMessage, d as reduceSessionProjectionRunEvent, f as normalizeSessionProjectionRunId, h as readSessionMessageSequence, i as resetGatewaySessionMessageSubscriptionCoordinator, j as normalizeDeviceMetadataForAuth, k as buildDeviceAuthPayload, l as reconcileSessionProjectionSnapshot, m as readSessionMessageIdentity, n as getGatewaySessionMessageSubscriptionCoordinator, o as hasSessionProjectionAcceptedFinal, p as readAssistantStreamSegmentIdentity, r as releaseGatewaySessionMessageSubscription, s as isLocallyOptimisticSessionMessage, t as GatewaySessionMessageSubscriptionCoordinator, u as reduceSessionProjection, v as GatewayProtocolClient, w as GatewayBrowserDeviceAuthLifecycle, y as GatewayProtocolRequestError } from "./session-subscriptions-C0VxZerW.mjs";
1
+ import { A as shouldRetryGatewayWithDeviceToken, D as buildGatewayConnectAuth, E as GatewayBrowserDeviceAuthLifecycle, M as buildDeviceAuthPayloadV3, N as normalizeDeviceMetadataForAuth, O as resolveGatewayConnectScopes, S as GatewayProtocolRequestTimeoutError, T as gatewayOriginScope, _ as readSessionMessageSequence, a as createSessionProjection, b as GatewayProtocolClient, c as projectLiveSessionMessage, d as reduceSessionProjection, f as reduceSessionProjectionRunEvent, g as readSessionMessageIdentity, h as readAssistantStreamSegmentIdentity, i as resetGatewaySessionMessageSubscriptionCoordinator, j as buildDeviceAuthPayload, k as selectGatewayConnectAuth, l as readSessionProjectionFinalMessageIdentity, m as normalizeSessionProjectionRunId, n as getGatewaySessionMessageSubscriptionCoordinator, o as hasSessionProjectionAcceptedFinal, p as isSessionProjectionErrorMessage, r as releaseGatewaySessionMessageSubscription, s as isLocallyOptimisticSessionMessage, t as GatewaySessionMessageSubscriptionCoordinator, u as reconcileSessionProjectionSnapshot, w as gatewayCredentialScope, x as GatewayProtocolRequestError, y as shouldPauseGatewayReconnect } from "./session-subscriptions-DwU8T0CH.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
- export * from "@openclaw/gateway-protocol/client-info";
5
4
  export * from "@openclaw/gateway-protocol/gateway-error-details";
5
+ export * from "@openclaw/gateway-protocol/client-info";
6
6
  export * from "@openclaw/gateway-protocol/startup-unavailable";
7
7
  export * from "@openclaw/gateway-protocol/version";
8
- export { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, GatewayBrowserDeviceAuthLifecycle, GatewayProtocolClient, GatewayProtocolRequestError, GatewayProtocolRequestTimeoutError, GatewaySessionMessageSubscriptionCoordinator, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isLocallyOptimisticSessionMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveGatewayConnectScopes, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldPauseGatewayReconnect, shouldRetryGatewayWithDeviceToken };
8
+ export { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, GatewayBrowserDeviceAuthLifecycle, GatewayProtocolClient, GatewayProtocolRequestError, GatewayProtocolRequestTimeoutError, GatewaySessionMessageSubscriptionCoordinator, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isLocallyOptimisticSessionMessage, isSessionProjectionErrorMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, readSessionProjectionFinalMessageIdentity, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveGatewayConnectScopes, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldPauseGatewayReconnect, shouldRetryGatewayWithDeviceToken };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as readSessionMessageSequence, C as reduceSessionProjection, D as normalizeSessionProjectionRunId, E as SessionMessageIdentity, F as normalizeDeviceMetadataForAuth, M as gatewayOriginScope, N as buildDeviceAuthPayload, O as readAssistantStreamSegmentIdentity, P as buildDeviceAuthPayloadV3, 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 gatewayCredentialScope, k as readSessionMessageIdentity, 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-D2UdeJ0u.mjs";
1
+ import { A as readAssistantStreamSegmentIdentity, C as isSessionProjectionErrorMessage, D as SessionMessageEnvelope, E as reduceSessionProjectionRunEvent, F as buildDeviceAuthPayload, I as buildDeviceAuthPayloadV3, L as normalizeDeviceMetadataForAuth, M as readSessionMessageSequence, N as gatewayCredentialScope, O as SessionMessageIdentity, P as gatewayOriginScope, S as reduceSessionProjection, T as SessionProjectionRunTransition, _ as hasSessionProjectionAcceptedFinal, a as GatewaySessionMessageSubscriptionOptions, b as readSessionProjectionFinalMessageIdentity, c as resetGatewaySessionMessageSubscriptionCoordinator, d as SessionProjectionRun, f as SessionProjectionRunStatus, g as createSessionProjection, h as SessionProjectionState, i as GatewaySessionMessageSubscriptionCoordinatorOptions, j as readSessionMessageIdentity, k as normalizeSessionProjectionRunId, l as SessionProjectionEntry, m as SessionProjectionSnapshotOptions, n as GatewaySessionMessageSubscription, o as getGatewaySessionMessageSubscriptionCoordinator, p as SessionProjectionScope, r as GatewaySessionMessageSubscriptionCoordinator, s as releaseGatewaySessionMessageSubscription, t as GatewaySessionMessageRequestClient, u as SessionProjectionEvent, v as isLocallyOptimisticSessionMessage, w as SessionProjectionGatewayRunEvent, x as reconcileSessionProjectionSnapshot, y as projectLiveSessionMessage } from "./session-subscriptions-C3M4jnCd.mjs";
2
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 { i as isGatewayProtocolResponseError } from "./protocol-request-B5gBmLgq.mjs";
4
4
  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";
@@ -14,4 +14,4 @@ export type CloudflareAccessCredentials = Readonly<{
14
14
  /** Build only the two headers Cloudflare Access defines for service-token auth. */
15
15
  export declare function buildCloudflareAccessHeaders(credentials: CloudflareAccessCredentials): Record<string, string>;
16
16
  //#endregion
17
- 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, isGatewayProtocolResponseError, isLocallyOptimisticSessionMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolveGatewayConnectScopes, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken, startGatewayClientWhenEventLoopReady, startGatewayClientWithReadinessWait, startGatewayConnectTimeout, waitForEventLoopReady };
17
+ 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, type SessionProjectionGatewayRunEvent, SessionProjectionRun, SessionProjectionRunStatus, type SessionProjectionRunTransition, SessionProjectionScope, SessionProjectionSnapshotOptions, SessionProjectionState, addSafeTimeoutDelayGraceMs, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, clampConnectChallengeTimeoutMs, clearGatewayConnectTimeout, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getConnectChallengeTimeoutMsFromEnv, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isGatewayConnectAssemblyError, isGatewayProtocolResponseError, isLocallyOptimisticSessionMessage, isSessionProjectionErrorMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, readSessionProjectionFinalMessageIdentity, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolveGatewayConnectScopes, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken, startGatewayClientWhenEventLoopReady, startGatewayClientWithReadinessWait, startGatewayConnectTimeout, waitForEventLoopReady };
package/dist/index.mjs CHANGED
@@ -1,16 +1,17 @@
1
- import { A as buildDeviceAuthPayloadV3, C as gatewayOriginScope, D as selectGatewayConnectAuth, E as resolveGatewayConnectScopes, O as shouldRetryGatewayWithDeviceToken, S as gatewayCredentialScope, T as buildGatewayConnectAuth, _ as shouldPauseGatewayReconnect, a as createSessionProjection, b as GatewayProtocolRequestTimeoutError, c as projectLiveSessionMessage, d as reduceSessionProjectionRunEvent, f as normalizeSessionProjectionRunId, g as isRecord, h as readSessionMessageSequence, i as resetGatewaySessionMessageSubscriptionCoordinator, j as normalizeDeviceMetadataForAuth, k as buildDeviceAuthPayload, l as reconcileSessionProjectionSnapshot, m as readSessionMessageIdentity, n as getGatewaySessionMessageSubscriptionCoordinator, o as hasSessionProjectionAcceptedFinal, p as readAssistantStreamSegmentIdentity, r as releaseGatewaySessionMessageSubscription, s as isLocallyOptimisticSessionMessage, t as GatewaySessionMessageSubscriptionCoordinator, u as reduceSessionProjection, v as GatewayProtocolClient, w as GatewayBrowserDeviceAuthLifecycle, x as isGatewayProtocolResponseError, y as GatewayProtocolRequestError } from "./session-subscriptions-C0VxZerW.mjs";
1
+ import { A as shouldRetryGatewayWithDeviceToken, C as isGatewayProtocolResponseError, D as buildGatewayConnectAuth, E as GatewayBrowserDeviceAuthLifecycle, M as buildDeviceAuthPayloadV3, N as normalizeDeviceMetadataForAuth, O as resolveGatewayConnectScopes, S as GatewayProtocolRequestTimeoutError, T as gatewayOriginScope, _ as readSessionMessageSequence, a as createSessionProjection, b as GatewayProtocolClient, c as projectLiveSessionMessage, d as reduceSessionProjection, f as reduceSessionProjectionRunEvent, g as readSessionMessageIdentity, h as readAssistantStreamSegmentIdentity, i as resetGatewaySessionMessageSubscriptionCoordinator, j as buildDeviceAuthPayload, k as selectGatewayConnectAuth, l as readSessionProjectionFinalMessageIdentity, m as normalizeSessionProjectionRunId, n as getGatewaySessionMessageSubscriptionCoordinator, o as hasSessionProjectionAcceptedFinal, p as isSessionProjectionErrorMessage, r as releaseGatewaySessionMessageSubscription, s as isLocallyOptimisticSessionMessage, t as GatewaySessionMessageSubscriptionCoordinator, u as reconcileSessionProjectionSnapshot, v as isRecord, w as gatewayCredentialScope, x as GatewayProtocolRequestError, y as shouldPauseGatewayReconnect } from "./session-subscriptions-DwU8T0CH.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";
5
5
  import { GatewayScopeUpgrade } from "./scope-upgrade.mjs";
6
+ import { createRequire } from "node:module";
6
7
  import { ConnectErrorDetailCodes, formatConnectErrorMessage, readConnectErrorDetailCode } from "@openclaw/gateway-protocol/connect-error-details";
7
8
  import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "@openclaw/gateway-protocol/client-info";
8
9
  import { resolveGatewayStartupRetryAfterMs } from "@openclaw/gateway-protocol/startup-unavailable";
9
10
  import { MIN_CLIENT_PROTOCOL_VERSION, MIN_NODE_PROTOCOL_VERSION, MIN_PROBE_PROTOCOL_VERSION, PROTOCOL_VERSION } from "@openclaw/gateway-protocol/version";
10
11
  import { randomUUID } from "node:crypto";
11
- import { WebSocket } from "ws";
12
12
  import ipaddr from "ipaddr.js";
13
13
  import { TLSSocket } from "node:tls";
14
+ import path from "node:path";
14
15
  //#region packages/normalization-core/src/string-coerce.ts
15
16
  /** Trims string input and returns null for non-strings or empty strings. */
16
17
  function normalizeNullableString(value) {
@@ -535,6 +536,10 @@ function applyGatewayWebSocketTlsPin(options, expectedFingerprint, normalize = n
535
536
  };
536
537
  }
537
538
  //#endregion
539
+ //#region packages/gateway-client/src/websocket.ts
540
+ const require = createRequire(import.meta.url);
541
+ const { WebSocket } = require(path.join(path.dirname(require.resolve("ws/package.json")), "index.js"));
542
+ //#endregion
538
543
  //#region packages/gateway-client/src/client.ts
539
544
  const DEFAULT_HOST_DEPS = {
540
545
  loadOrCreateDeviceIdentity: () => void 0,
@@ -1344,4 +1349,4 @@ function buildCloudflareAccessHeaders(credentials) {
1344
1349
  };
1345
1350
  }
1346
1351
  //#endregion
1347
- export { CF_ACCESS_CLIENT_ID_HEADER, CF_ACCESS_CLIENT_SECRET_HEADER, DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, GatewayBrowserDeviceAuthLifecycle, GatewayClient, GatewayClientRequestError, GatewayClientRequestTimeoutError, GatewayScopeUpgrade, GatewaySessionMessageSubscriptionCoordinator, MAX_CONNECT_CHALLENGE_TIMEOUT_MS, MAX_SAFE_TIMEOUT_DELAY_MS, MIN_CONNECT_CHALLENGE_TIMEOUT_MS, addSafeTimeoutDelayGraceMs, buildCloudflareAccessHeaders, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, clampConnectChallengeTimeoutMs, clearGatewayConnectTimeout, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getConnectChallengeTimeoutMsFromEnv, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isGatewayConnectAssemblyError, isGatewayProtocolResponseError, isLocallyOptimisticSessionMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolveGatewayConnectScopes, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken, startGatewayClientWhenEventLoopReady, startGatewayClientWithReadinessWait, startGatewayConnectTimeout, waitForEventLoopReady };
1352
+ export { CF_ACCESS_CLIENT_ID_HEADER, CF_ACCESS_CLIENT_SECRET_HEADER, DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS, GatewayBrowserDeviceAuthLifecycle, GatewayClient, GatewayClientRequestError, GatewayClientRequestTimeoutError, GatewayScopeUpgrade, GatewaySessionMessageSubscriptionCoordinator, MAX_CONNECT_CHALLENGE_TIMEOUT_MS, MAX_SAFE_TIMEOUT_DELAY_MS, MIN_CONNECT_CHALLENGE_TIMEOUT_MS, addSafeTimeoutDelayGraceMs, buildCloudflareAccessHeaders, buildDeviceAuthPayload, buildDeviceAuthPayloadV3, buildGatewayConnectAuth, clampConnectChallengeTimeoutMs, clearGatewayConnectTimeout, createSessionProjection, gatewayCredentialScope, gatewayOriginScope, getConnectChallengeTimeoutMsFromEnv, getGatewaySessionMessageSubscriptionCoordinator, hasSessionProjectionAcceptedFinal, isGatewayConnectAssemblyError, isGatewayProtocolResponseError, isLocallyOptimisticSessionMessage, isSessionProjectionErrorMessage, normalizeDeviceMetadataForAuth, normalizeSessionProjectionRunId, projectLiveSessionMessage, readAssistantStreamSegmentIdentity, readSessionMessageIdentity, readSessionMessageSequence, readSessionProjectionFinalMessageIdentity, reconcileSessionProjectionSnapshot, reduceSessionProjection, reduceSessionProjectionRunEvent, releaseGatewaySessionMessageSubscription, resetGatewaySessionMessageSubscriptionCoordinator, resolveConnectChallengeTimeoutMs, resolveFiniteTimeoutDelayMs, resolveGatewayConnectScopes, resolvePreauthHandshakeTimeoutMs, resolveSafeTimeoutDelayMs, selectGatewayConnectAuth, shouldRetryGatewayWithDeviceToken, startGatewayClientWhenEventLoopReady, startGatewayClientWithReadinessWait, startGatewayConnectTimeout, waitForEventLoopReady };
@@ -57,6 +57,24 @@ declare function readAssistantStreamSegmentIdentity(message: unknown): {
57
57
  runId?: string;
58
58
  } | undefined;
59
59
  //#endregion
60
+ //#region packages/gateway-client/src/session-projection-run-event.d.ts
61
+ type SessionProjectionGatewayRunEvent = {
62
+ state?: unknown;
63
+ yielded?: unknown;
64
+ seq?: unknown;
65
+ } & Partial<Record<"runId" | "message" | "stopReason" | "errorKind" | "errorMessage", unknown>>;
66
+ type SessionProjectionRunTransition = {
67
+ projection: SessionProjectionState;
68
+ previousRun: SessionProjectionRun | undefined;
69
+ currentRun: SessionProjectionRun | undefined;
70
+ };
71
+ /** Normalizes Gateway run envelopes once for every browser and terminal adapter. */
72
+ declare function reduceSessionProjectionRunEvent(projection: SessionProjectionState, event: SessionProjectionGatewayRunEvent, scope?: SessionProjectionScope): SessionProjectionRunTransition | null;
73
+ //#endregion
74
+ //#region packages/gateway-client/src/session-projection-message-content.d.ts
75
+ /** Diagnostic-only error projections can be retired when their run resumes. */
76
+ declare function isSessionProjectionErrorMessage(message: unknown, errorMessage?: string): boolean;
77
+ //#endregion
60
78
  //#region packages/gateway-client/src/session-projection.d.ts
61
79
  type SessionProjectionScope = {
62
80
  sessionKey?: string;
@@ -71,6 +89,7 @@ type SessionProjectionSnapshotOptions = {
71
89
  type SessionProjectionRunStatus = "streaming" | "completed" | "error" | "aborted" | "timeout" | "yielded";
72
90
  type SessionProjectionRun = {
73
91
  runId: string;
92
+ seq?: number;
74
93
  status: SessionProjectionRunStatus;
75
94
  message?: unknown;
76
95
  acceptedFinalMessageIdentities?: readonly string[];
@@ -78,15 +97,6 @@ type SessionProjectionRun = {
78
97
  errorKind?: string;
79
98
  errorMessage?: string;
80
99
  };
81
- type SessionProjectionGatewayRunEvent = {
82
- state?: unknown;
83
- yielded?: unknown;
84
- } & Partial<Record<"runId" | "message" | "stopReason" | "errorKind" | "errorMessage", unknown>>;
85
- type SessionProjectionRunTransition = {
86
- projection: SessionProjectionState;
87
- previousRun: SessionProjectionRun | undefined;
88
- currentRun: SessionProjectionRun | undefined;
89
- };
90
100
  type SessionProjectionEntry = {
91
101
  message: unknown;
92
102
  identity: SessionMessageIdentity | null;
@@ -129,6 +139,7 @@ type SessionProjectionEvent = ScopedSessionProjectionEvent & ({
129
139
  } | {
130
140
  type: "runDelta";
131
141
  runId: string;
142
+ seq?: number;
132
143
  message?: unknown;
133
144
  } | (Omit<SessionProjectionRun, "acceptedFinalMessageIdentities"> & {
134
145
  type: "runTerminal";
@@ -146,12 +157,11 @@ declare function createSessionProjection(scope?: SessionProjectionScope, message
146
157
  declare function projectLiveSessionMessage(state: SessionProjectionState, message: unknown, envelope?: SessionMessageEnvelope, scope?: SessionProjectionScope): SessionProjectionState;
147
158
  /** Only observed live events and this client's pending turns may survive an older snapshot. */
148
159
  declare function reconcileSessionProjectionSnapshot(state: SessionProjectionState, messages: readonly unknown[], scope?: SessionProjectionScope, options?: SessionProjectionSnapshotOptions): SessionProjectionState;
160
+ declare function readSessionProjectionFinalMessageIdentity(message: unknown): string | null;
149
161
  /** Replayed finals are recognized against this run's bounded canonical terminal history. */
150
162
  declare function hasSessionProjectionAcceptedFinal(run: SessionProjectionRun | undefined, message: unknown): boolean;
151
163
  /** Reduces durable events, snapshots, and transport lifecycle without client-specific policy. */
152
164
  declare function reduceSessionProjection(state: SessionProjectionState, event: SessionProjectionEvent): SessionProjectionState;
153
- /** Normalizes Gateway run envelopes once for every browser and terminal adapter. */
154
- declare function reduceSessionProjectionRunEvent(projection: SessionProjectionState, event: SessionProjectionGatewayRunEvent, scope?: SessionProjectionScope): SessionProjectionRunTransition | null;
155
165
  //#endregion
156
166
  //#region packages/gateway-client/src/session-subscriptions.d.ts
157
167
  type GatewaySessionMessageRequestClient = {
@@ -187,4 +197,4 @@ declare function getGatewaySessionMessageSubscriptionCoordinator(client: Gateway
187
197
  declare function resetGatewaySessionMessageSubscriptionCoordinator(client: GatewaySessionMessageRequestClient): void;
188
198
  declare function releaseGatewaySessionMessageSubscription(subscription: GatewaySessionMessageSubscription): Promise<void>;
189
199
  //#endregion
190
- export { readSessionMessageSequence as A, reduceSessionProjection as C, normalizeSessionProjectionRunId as D, SessionMessageIdentity as E, normalizeDeviceMetadataForAuth as F, gatewayOriginScope as M, buildDeviceAuthPayload as N, readAssistantStreamSegmentIdentity as O, buildDeviceAuthPayloadV3 as P, reconcileSessionProjectionSnapshot as S, SessionMessageEnvelope as T, SessionProjectionState as _, GatewaySessionMessageSubscriptionOptions as a, isLocallyOptimisticSessionMessage as b, resetGatewaySessionMessageSubscriptionCoordinator as c, SessionProjectionGatewayRunEvent as d, SessionProjectionRun as f, SessionProjectionSnapshotOptions as g, SessionProjectionScope as h, GatewaySessionMessageSubscriptionCoordinatorOptions as i, gatewayCredentialScope as j, readSessionMessageIdentity as k, SessionProjectionEntry as l, SessionProjectionRunTransition as m, GatewaySessionMessageSubscription as n, getGatewaySessionMessageSubscriptionCoordinator as o, SessionProjectionRunStatus as p, GatewaySessionMessageSubscriptionCoordinator as r, releaseGatewaySessionMessageSubscription as s, GatewaySessionMessageRequestClient as t, SessionProjectionEvent as u, createSessionProjection as v, reduceSessionProjectionRunEvent as w, projectLiveSessionMessage as x, hasSessionProjectionAcceptedFinal as y };
200
+ export { readAssistantStreamSegmentIdentity as A, isSessionProjectionErrorMessage as C, SessionMessageEnvelope as D, reduceSessionProjectionRunEvent as E, buildDeviceAuthPayload as F, buildDeviceAuthPayloadV3 as I, normalizeDeviceMetadataForAuth as L, readSessionMessageSequence as M, gatewayCredentialScope as N, SessionMessageIdentity as O, gatewayOriginScope as P, reduceSessionProjection as S, SessionProjectionRunTransition as T, hasSessionProjectionAcceptedFinal as _, GatewaySessionMessageSubscriptionOptions as a, readSessionProjectionFinalMessageIdentity as b, resetGatewaySessionMessageSubscriptionCoordinator as c, SessionProjectionRun as d, SessionProjectionRunStatus as f, createSessionProjection as g, SessionProjectionState as h, GatewaySessionMessageSubscriptionCoordinatorOptions as i, readSessionMessageIdentity as j, normalizeSessionProjectionRunId as k, SessionProjectionEntry as l, SessionProjectionSnapshotOptions as m, GatewaySessionMessageSubscription as n, getGatewaySessionMessageSubscriptionCoordinator as o, SessionProjectionScope as p, GatewaySessionMessageSubscriptionCoordinator as r, releaseGatewaySessionMessageSubscription as s, GatewaySessionMessageRequestClient as t, SessionProjectionEvent as u, isLocallyOptimisticSessionMessage as v, SessionProjectionGatewayRunEvent as w, reconcileSessionProjectionSnapshot as x, projectLiveSessionMessage as y };
@@ -1,6 +1,7 @@
1
1
  import { DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS, clearGatewayConnectTimeout, resolveSafeTimeoutDelayMs, startGatewayConnectTimeout } from "./timeouts.mjs";
2
2
  import { ConnectErrorDetailCodes, readConnectErrorDetailCode, readConnectErrorRecoveryAdvice, readPairingConnectErrorDetails } from "@openclaw/gateway-protocol/connect-error-details";
3
3
  import { isGatewayEventFrame, isGatewayResponseFrame } from "@openclaw/gateway-protocol/frame-guards";
4
+ import { GATEWAY_ASSISTANT_ERROR_FALLBACK_TEXT } from "@openclaw/gateway-protocol/gateway-error-details";
4
5
  //#region packages/gateway-client/src/device-auth.ts
5
6
  function normalizeDeviceMetadataForAuth(value) {
6
7
  if (typeof value !== "string") return "";
@@ -482,7 +483,8 @@ var GatewayPendingRequests = class {
482
483
  return this.pending.size > 0;
483
484
  }
484
485
  get hasUnboundedPending() {
485
- return [...this.pending.values()].some((pending) => pending.unbounded);
486
+ for (const pending of this.pending.values()) if (pending.unbounded) return true;
487
+ return false;
486
488
  }
487
489
  request(sender, method, params, options) {
488
490
  let id;
@@ -578,8 +580,8 @@ var GatewayPendingRequests = class {
578
580
  pending.reject(error);
579
581
  }
580
582
  flush(error) {
581
- const retired = [...this.pending];
582
- this.pending.clear();
583
+ const retired = this.pending;
584
+ this.pending = /* @__PURE__ */ new Map();
583
585
  this.requestSequence = 0;
584
586
  for (const [id, pending] of retired) {
585
587
  pending.cleanup?.();
@@ -594,9 +596,7 @@ var GatewayPendingRequests = class {
594
596
  finishTiming(id, pending, ok, errorCode) {
595
597
  const endedAtMs = this.opts.nowMs();
596
598
  try {
597
- const onTiming = this.opts.onTiming;
598
- if (onTiming === void 0 || onTiming === null) return;
599
- Reflect.apply(onTiming, this.opts, [{
599
+ this.opts.onTiming?.({
600
600
  id,
601
601
  method: pending.method,
602
602
  ok,
@@ -604,7 +604,7 @@ var GatewayPendingRequests = class {
604
604
  startedAtMs: pending.startedAtMs,
605
605
  endedAtMs,
606
606
  errorCode
607
- }]);
607
+ });
608
608
  } catch (error) {
609
609
  this.opts.onCallbackError?.("request timing", error);
610
610
  }
@@ -1094,11 +1094,47 @@ function readAssistantStreamSegmentIdentity(message) {
1094
1094
  } : void 0;
1095
1095
  }
1096
1096
  //#endregion
1097
+ //#region packages/gateway-client/src/session-projection-message-content.ts
1098
+ function readSessionMessageDisplayContent(message) {
1099
+ const record = asNullableRecord(message);
1100
+ const content = typeof message === "string" ? message : record?.content;
1101
+ const media = asNullableRecord(record?.["__openclaw"])?.media;
1102
+ let hasNonText = Array.isArray(media) && media.length > 0;
1103
+ const texts = [];
1104
+ for (const block of Array.isArray(content) ? content : [content]) {
1105
+ const entry = asNullableRecord(block);
1106
+ if (entry && entry.type !== "text" && entry.type !== "input_text" && entry.type !== "output_text") {
1107
+ hasNonText ||= entry.type !== "thinking" && entry.type !== "reasoning" && entry.type !== "redacted_thinking";
1108
+ continue;
1109
+ }
1110
+ const text = readSessionProjectionString(entry ? entry.text : block);
1111
+ if (text) texts.push(text);
1112
+ }
1113
+ const fallback = texts.length === 0 ? readSessionProjectionString(record?.text) : null;
1114
+ return {
1115
+ text: fallback ?? texts.join("\n"),
1116
+ hasNonText,
1117
+ usesFallbackText: fallback !== null
1118
+ };
1119
+ }
1120
+ function normalizeChatErrorComparisonText(text) {
1121
+ return text.trim().replace(/^⚠️\s*/u, "").replace(/^Error:\s*/iu, "").replace(/\s+/gu, " ").trim();
1122
+ }
1123
+ /** Diagnostic-only error projections can be retired when their run resumes. */
1124
+ function isSessionProjectionErrorMessage(message, errorMessage) {
1125
+ const role = asNullableRecord(message)?.role;
1126
+ if (typeof role === "string" && role.trim().toLowerCase() !== "assistant") return false;
1127
+ const { text, hasNonText } = readSessionMessageDisplayContent(message);
1128
+ const normalizedText = normalizeChatErrorComparisonText(text);
1129
+ return !hasNonText && (!normalizedText || normalizedText === "[assistant turn failed before producing content]" || normalizedText === GATEWAY_ASSISTANT_ERROR_FALLBACK_TEXT || normalizedText === normalizeChatErrorComparisonText(errorMessage ?? ""));
1130
+ }
1131
+ //#endregion
1097
1132
  //#region packages/gateway-client/src/session-projection-run-event.ts
1098
1133
  function readNonemptyString(value) {
1099
1134
  return typeof value === "string" ? value.trim() || null : null;
1100
1135
  }
1101
- function reduceSessionProjectionRunEventImpl(projection, event, scope = {}) {
1136
+ /** Normalizes Gateway run envelopes once for every browser and terminal adapter. */
1137
+ function reduceSessionProjectionRunEvent(projection, event, scope = {}) {
1102
1138
  const runId = readNonemptyString(event.runId);
1103
1139
  if (!runId || typeof event.state !== "string" || ![
1104
1140
  "delta",
@@ -1112,6 +1148,7 @@ function reduceSessionProjectionRunEventImpl(projection, event, scope = {}) {
1112
1148
  const errorKind = readNonemptyString(event.errorKind);
1113
1149
  const base = {
1114
1150
  runId,
1151
+ seq: typeof event.seq === "number" ? event.seq : void 0,
1115
1152
  ...message === void 0 ? {} : { message },
1116
1153
  scope
1117
1154
  };
@@ -1304,18 +1341,12 @@ function reconcileSessionProjectionSnapshot(state, messages, scope = {}, options
1304
1341
  };
1305
1342
  }
1306
1343
  function hasDisplayableSessionMessage(message) {
1307
- if (typeof message === "string") return message.trim().length > 0;
1308
- const record = asNullableRecord(message);
1309
- if (!record) return false;
1310
- const displayableBlocks = Array.isArray(record.content) && record.content.some((block) => {
1311
- const entry = asNullableRecord(block);
1312
- return entry ? entry.type !== "text" || readSessionProjectionString(entry.text) !== null : typeof block === "string" && block.trim().length > 0;
1313
- });
1314
- const media = asNullableRecord(record["__openclaw"])?.media;
1315
- return Boolean(typeof record.content === "string" && record.content.trim() || displayableBlocks || Array.isArray(media) && media.length > 0);
1344
+ const { text, hasNonText } = readSessionMessageDisplayContent(message);
1345
+ return Boolean(text) || hasNonText;
1316
1346
  }
1317
1347
  function readSessionProjectionFinalMessageIdentity(message) {
1318
- if (!hasDisplayableSessionMessage(message)) return null;
1348
+ const display = readSessionMessageDisplayContent(message);
1349
+ if (!display.text && !display.hasNonText) return null;
1319
1350
  const identity = readSessionMessageIdentity(message);
1320
1351
  if (identity?.externalSource) return `import:${identity.role}:${identity.externalSource}`;
1321
1352
  if (identity?.id && !identity.isImported) return `id:${identity.role}:${identity.id}`;
@@ -1331,7 +1362,8 @@ function readSessionProjectionFinalMessageIdentity(message) {
1331
1362
  metadata?.importedFrom ?? null,
1332
1363
  metadata?.cliSessionId ?? null,
1333
1364
  metadata?.externalId ?? null
1334
- ] : null
1365
+ ] : null,
1366
+ ...display.usesFallbackText ? [record?.text] : []
1335
1367
  ])}`;
1336
1368
  } catch {
1337
1369
  return null;
@@ -1353,18 +1385,24 @@ function retainSessionProjectionRuns(runs) {
1353
1385
  }
1354
1386
  function updateRun(state, incoming) {
1355
1387
  const incomingErrorMessage = readSessionProjectionString(incoming.errorMessage);
1356
- const normalizedIncoming = { ...incoming };
1388
+ const incomingSeq = typeof incoming.seq === "number" && Number.isSafeInteger(incoming.seq) && incoming.seq >= 0 ? incoming.seq : void 0;
1389
+ const normalizedIncoming = {
1390
+ ...incoming,
1391
+ seq: incomingSeq
1392
+ };
1357
1393
  if (incomingErrorMessage) normalizedIncoming.errorMessage = incomingErrorMessage;
1358
1394
  else delete normalizedIncoming.errorMessage;
1359
1395
  const current = state.runs[incoming.runId];
1360
- if (current && current.status !== "streaming") {
1396
+ const resumesErrorProjection = current?.status === "error" && incoming.status === "streaming" && current.seq !== void 0 && incomingSeq !== void 0 && incomingSeq > current.seq && isSessionProjectionErrorMessage(current.message, current.errorMessage);
1397
+ if (current && current.status !== "streaming" && !resumesErrorProjection) {
1361
1398
  const incomingFinalIdentity = readSessionProjectionFinalMessageIdentity(incoming.message);
1362
1399
  const incomingIsFinal = incoming.status === "completed" || incoming.status === "yielded";
1363
1400
  const canRecoverFinal = !hasDisplayableSessionMessage(current.message) || (current.acceptedFinalMessageIdentities?.length ?? 0) > 0;
1364
1401
  const acceptFinal = incomingIsFinal && (current.status === incoming.status || canRecoverFinal) && incomingFinalIdentity !== null && !hasSessionProjectionAcceptedFinal(current, incoming.message);
1365
1402
  const recoverMessage = acceptFinal && !hasDisplayableSessionMessage(current.message);
1366
1403
  const recoverError = readSessionProjectionString(current.errorMessage) === null && incomingErrorMessage !== null;
1367
- if (!acceptFinal && !recoverError) return state;
1404
+ const updateTerminalSequence = incoming.status !== "streaming" && (incomingSeq === void 0 ? current.seq !== void 0 : current.seq === void 0 || incomingSeq > current.seq);
1405
+ if (!acceptFinal && !recoverError && !updateTerminalSequence) return state;
1368
1406
  const firstFinalIdentity = readSessionProjectionFinalMessageIdentity(current.message);
1369
1407
  const previousFinalIdentities = current.acceptedFinalMessageIdentities ?? (firstFinalIdentity ? [firstFinalIdentity] : []);
1370
1408
  return {
@@ -1373,6 +1411,7 @@ function updateRun(state, incoming) {
1373
1411
  ...state.runs,
1374
1412
  [incoming.runId]: {
1375
1413
  ...current,
1414
+ ...updateTerminalSequence ? { seq: incomingSeq } : {},
1376
1415
  ...recoverMessage ? { message: incoming.message } : {},
1377
1416
  ...acceptFinal && incomingFinalIdentity ? { acceptedFinalMessageIdentities: [...previousFinalIdentities, incomingFinalIdentity].slice(-32) } : {},
1378
1417
  ...recoverError && incomingErrorMessage ? {
@@ -1383,17 +1422,18 @@ function updateRun(state, incoming) {
1383
1422
  }
1384
1423
  };
1385
1424
  }
1425
+ const resumedState = resumesErrorProjection ? withEntries(state, state.entries.filter((entry) => !((entry.identity?.runId === incoming.runId || entry.message === current.message) && (asNullableRecord(entry.message)?.stopReason === "error" || entry.message === current.message) && isSessionProjectionErrorMessage(entry.message, current.errorMessage)))) : state;
1386
1426
  const previousRuns = current && current.status === "streaming" && incoming.status !== "streaming" ? Object.fromEntries(Object.entries(state.runs).filter(([runId]) => runId !== incoming.runId)) : state.runs;
1387
1427
  const acceptedFinalIdentity = incoming.status === "completed" || incoming.status === "yielded" ? readSessionProjectionFinalMessageIdentity(incoming.message) : null;
1388
1428
  return {
1389
- ...state,
1429
+ ...resumedState,
1390
1430
  runs: retainSessionProjectionRuns({
1391
1431
  ...previousRuns,
1392
1432
  [incoming.runId]: {
1393
- ...current,
1433
+ ...resumesErrorProjection ? {} : current,
1394
1434
  ...normalizedIncoming,
1395
1435
  ...acceptedFinalIdentity ? { acceptedFinalMessageIdentities: [acceptedFinalIdentity] } : {},
1396
- ...incoming.message === void 0 && current?.message !== void 0 ? { message: current.message } : {}
1436
+ ...!resumesErrorProjection && incoming.message === void 0 && current?.message !== void 0 ? { message: current.message } : {}
1397
1437
  }
1398
1438
  })
1399
1439
  };
@@ -1451,11 +1491,13 @@ function reduceSessionProjection(state, event) {
1451
1491
  }
1452
1492
  case "runDelta": return updateRun(state, {
1453
1493
  runId: event.runId,
1494
+ seq: event.seq,
1454
1495
  status: "streaming",
1455
1496
  ...event.message === void 0 ? {} : { message: event.message }
1456
1497
  });
1457
1498
  case "runTerminal": return updateRun(state, {
1458
1499
  runId: event.runId,
1500
+ seq: event.seq,
1459
1501
  status: event.status,
1460
1502
  ...event.message === void 0 ? {} : { message: event.message },
1461
1503
  ...event.stopReason === void 0 ? {} : { stopReason: event.stopReason },
@@ -1470,10 +1512,6 @@ function reduceSessionProjection(state, event) {
1470
1512
  default: return state;
1471
1513
  }
1472
1514
  }
1473
- /** Normalizes Gateway run envelopes once for every browser and terminal adapter. */
1474
- function reduceSessionProjectionRunEvent(projection, event, scope = {}) {
1475
- return reduceSessionProjectionRunEventImpl(projection, event, scope);
1476
- }
1477
1515
  //#endregion
1478
1516
  //#region packages/gateway-client/src/session-subscriptions.ts
1479
1517
  function sessionSubscriptionParams(key, agentId) {
@@ -1591,34 +1629,26 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
1591
1629
  agentId,
1592
1630
  ready: Promise.resolve({ key }),
1593
1631
  approvalRequest: null,
1594
- approvalResponse: null,
1595
1632
  plainFallback: null,
1596
1633
  canonicalSettled: false,
1597
1634
  handles: /* @__PURE__ */ new Set(),
1598
1635
  pendingOwners: 0,
1599
1636
  release: null
1600
1637
  };
1601
- entry.ready = this.#requestSubscribe(entry, includeApprovals).then((result) => {
1602
- entry.key = result.key;
1603
- entry.canonicalSettled = true;
1604
- if (includeApprovals) entry.approvalResponse = result;
1605
- return result;
1606
- });
1607
- if (includeApprovals) entry.approvalRequest = entry.ready;
1638
+ entry.ready = this.#requestSubscribe(entry, includeApprovals);
1639
+ if (includeApprovals) entry.ready = this.#trackApprovalRequest(entry, entry.ready);
1608
1640
  entry.ready.catch(() => void 0);
1609
1641
  this.#entries.add(entry);
1610
1642
  return entry;
1611
1643
  }
1612
1644
  #acquireCapability(entry, includeApprovals) {
1613
1645
  if (!includeApprovals) {
1614
- if (entry.approvalRequest === entry.ready && !entry.approvalResponse) {
1646
+ if (entry.approvalRequest === entry.ready) {
1615
1647
  if (!entry.plainFallback) {
1616
1648
  const approvalRequest = entry.ready;
1617
1649
  entry.plainFallback = approvalRequest.catch(async (error) => {
1618
1650
  if (this.#retired) throw error;
1619
1651
  const result = await this.#requestSubscribe(entry, false);
1620
- entry.key = result.key;
1621
- entry.canonicalSettled = true;
1622
1652
  entry.ready = Promise.resolve(result);
1623
1653
  if (entry.approvalRequest === approvalRequest) entry.approvalRequest = null;
1624
1654
  return result;
@@ -1628,18 +1658,15 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
1628
1658
  }
1629
1659
  return entry.ready;
1630
1660
  }
1631
- if (entry.approvalResponse) return Promise.resolve(entry.approvalResponse);
1632
1661
  if (entry.approvalRequest) return entry.approvalRequest;
1633
- const upgrade = entry.ready.then(() => this.#requestSubscribe(entry, true)).then((result) => {
1634
- entry.key = result.key;
1635
- entry.approvalResponse = result;
1636
- return result;
1637
- });
1638
- entry.approvalRequest = upgrade;
1639
- upgrade.catch(() => {
1640
- if (entry.approvalRequest === upgrade) entry.approvalRequest = null;
1662
+ return this.#trackApprovalRequest(entry, entry.ready.then(() => this.#requestSubscribe(entry, true)));
1663
+ }
1664
+ #trackApprovalRequest(entry, request) {
1665
+ const tracked = request.finally(() => {
1666
+ if (entry.approvalRequest === tracked) entry.approvalRequest = null;
1641
1667
  });
1642
- return upgrade;
1668
+ entry.approvalRequest = tracked;
1669
+ return tracked;
1643
1670
  }
1644
1671
  async #requestSubscribe(entry, includeApprovals) {
1645
1672
  const params = sessionSubscriptionParams(entry.key, entry.agentId);
@@ -1649,7 +1676,11 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
1649
1676
  } : params, { timeoutMs: DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS }).catch(async (error) => {
1650
1677
  if (!(error instanceof GatewayProtocolRequestTimeoutError) || !error.requestSent || this.#retired) throw error;
1651
1678
  try {
1652
- await this.#client.request(entry.handles.size > 0 ? "sessions.messages.subscribe" : "sessions.messages.unsubscribe", params, { timeoutMs: DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS });
1679
+ const retainedApprovals = [...entry.handles].some((handle) => handle.includeApprovals);
1680
+ await this.#client.request(entry.handles.size > 0 ? "sessions.messages.subscribe" : "sessions.messages.unsubscribe", retainedApprovals ? {
1681
+ ...params,
1682
+ includeApprovals: true
1683
+ } : params, { timeoutMs: DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS });
1653
1684
  } catch (recoveryError) {
1654
1685
  if (!this.#retired) throw new AggregateError([error, recoveryError], "session message subscription recovery failed", { cause: recoveryError });
1655
1686
  }
@@ -1657,8 +1688,10 @@ var GatewaySessionMessageSubscriptionCoordinator = class {
1657
1688
  });
1658
1689
  const response = result && typeof result === "object" ? result : null;
1659
1690
  const responseKey = response && "key" in response ? response.key : void 0;
1691
+ entry.key = typeof responseKey === "string" && responseKey.trim() ? responseKey.trim() : entry.key;
1692
+ entry.canonicalSettled = true;
1660
1693
  return {
1661
- key: typeof responseKey === "string" && responseKey.trim() ? responseKey.trim() : entry.key,
1694
+ key: entry.key,
1662
1695
  ...response && "approvalReplay" in response ? { approvalReplay: response.approvalReplay } : {}
1663
1696
  };
1664
1697
  }
@@ -1694,4 +1727,4 @@ function releaseGatewaySessionMessageSubscription(subscription) {
1694
1727
  return sessionMessageSubscriptionOwners.get(subscription)?.coordinator.release(subscription) ?? Promise.resolve();
1695
1728
  }
1696
1729
  //#endregion
1697
- export { buildDeviceAuthPayloadV3 as A, gatewayOriginScope as C, selectGatewayConnectAuth as D, resolveGatewayConnectScopes as E, shouldRetryGatewayWithDeviceToken as O, gatewayCredentialScope as S, buildGatewayConnectAuth as T, shouldPauseGatewayReconnect as _, createSessionProjection as a, GatewayProtocolRequestTimeoutError as b, projectLiveSessionMessage as c, reduceSessionProjectionRunEvent as d, normalizeSessionProjectionRunId as f, isRecord as g, readSessionMessageSequence as h, resetGatewaySessionMessageSubscriptionCoordinator as i, normalizeDeviceMetadataForAuth as j, buildDeviceAuthPayload as k, reconcileSessionProjectionSnapshot as l, readSessionMessageIdentity as m, getGatewaySessionMessageSubscriptionCoordinator as n, hasSessionProjectionAcceptedFinal as o, readAssistantStreamSegmentIdentity as p, releaseGatewaySessionMessageSubscription as r, isLocallyOptimisticSessionMessage as s, GatewaySessionMessageSubscriptionCoordinator as t, reduceSessionProjection as u, GatewayProtocolClient as v, GatewayBrowserDeviceAuthLifecycle as w, isGatewayProtocolResponseError as x, GatewayProtocolRequestError as y };
1730
+ export { shouldRetryGatewayWithDeviceToken as A, isGatewayProtocolResponseError as C, buildGatewayConnectAuth as D, GatewayBrowserDeviceAuthLifecycle as E, buildDeviceAuthPayloadV3 as M, normalizeDeviceMetadataForAuth as N, resolveGatewayConnectScopes as O, GatewayProtocolRequestTimeoutError as S, gatewayOriginScope as T, readSessionMessageSequence as _, createSessionProjection as a, GatewayProtocolClient as b, projectLiveSessionMessage as c, reduceSessionProjection as d, reduceSessionProjectionRunEvent as f, readSessionMessageIdentity as g, readAssistantStreamSegmentIdentity as h, resetGatewaySessionMessageSubscriptionCoordinator as i, buildDeviceAuthPayload as j, selectGatewayConnectAuth as k, readSessionProjectionFinalMessageIdentity as l, normalizeSessionProjectionRunId as m, getGatewaySessionMessageSubscriptionCoordinator as n, hasSessionProjectionAcceptedFinal as o, isSessionProjectionErrorMessage as p, releaseGatewaySessionMessageSubscription as r, isLocallyOptimisticSessionMessage as s, GatewaySessionMessageSubscriptionCoordinator as t, reconcileSessionProjectionSnapshot as u, isRecord as v, gatewayCredentialScope as w, GatewayProtocolRequestError as x, shouldPauseGatewayReconnect as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/gateway-client",
3
- "version": "2026.9.2",
3
+ "version": "2026.9.3",
4
4
  "description": "Reference WebSocket client for the OpenClaw Gateway protocol",
5
5
  "keywords": [
6
6
  "client",
@@ -62,7 +62,7 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@openclaw/gateway-protocol": "2026.9.2",
65
+ "@openclaw/gateway-protocol": "2026.9.3",
66
66
  "ipaddr.js": "2.5.0",
67
67
  "ws": "8.21.3"
68
68
  },