beeos-claw 0.5.65-staging.3 → 0.5.65-staging.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beeos-claw",
3
- "version": "0.5.65-staging.3",
3
+ "version": "0.5.65-staging.4",
4
4
  "description": "OpenClaw plugin that bridges the BeeOS platform with the local OpenClaw Gateway, providing file transfer, ACP bridge, and observability.",
5
5
  "license": "MIT",
6
6
  "author": "BeeOS <dev@beeos.ai>",
@@ -38,14 +38,7 @@ export async function withinDeadline(run, deadline) {
38
38
  * invoking start() again would create competing reconnect loops.
39
39
  */
40
40
  export async function startGatewayWithinDeadline(gateway, deadline) {
41
- try {
42
- await withinDeadline(() => gateway.start(), deadline);
43
- return;
44
- } catch (error) {
45
- if (!isRetryableGatewayHandshake(error)) throw error;
46
- }
47
-
48
- await withinDeadline((signal) => waitForGatewayConnection(gateway, signal), deadline);
41
+ await withinDeadline((signal) => startAndObserveGateway(gateway, signal), deadline);
49
42
  }
50
43
 
51
44
  export async function closeRuntimeResources({ consumer, gateway }, cleanupTimeoutMs = 5_000) {
@@ -116,13 +109,15 @@ function isRetryableGatewayHandshake(error) {
116
109
  ((error.retryable === true) || error.code === "UNAVAILABLE");
117
110
  }
118
111
 
119
- function waitForGatewayConnection(gateway, signal) {
112
+ function startAndObserveGateway(gateway, signal) {
120
113
  return new Promise((resolve, reject) => {
121
114
  let settled = false;
115
+ let observedTransportFailure = false;
122
116
  const cleanup = () => {
123
117
  gateway.off("connected", onConnected);
124
118
  gateway.off("auth-failed", onAuthFailed);
125
119
  gateway.off("error", onError);
120
+ gateway.off("disconnected", onDisconnected);
126
121
  signal.removeEventListener("abort", onAbort);
127
122
  };
128
123
  const settle = (callback, value) => {
@@ -138,10 +133,12 @@ function waitForGatewayConnection(gateway, signal) {
138
133
  : "Gateway authentication failed";
139
134
  settle(reject, new Error(reason));
140
135
  };
141
- // GatewayClient emits `error` for each failed reconnect before scheduling
142
- // the next one. Keep an error listener while waiting so EventEmitter does
143
- // not crash the worker; auth-failed remains the immediate terminal signal.
144
- const onError = () => {};
136
+ // GatewayClient owns reconnect scheduling for a WebSocket-level startup
137
+ // failure. Install this observer before `start()` so its first error cannot
138
+ // become EventEmitter's fatal unhandled `error` event. The subsequent
139
+ // `start()` rejection is intentionally held open for that owned retry.
140
+ const onError = () => { observedTransportFailure = true; };
141
+ const onDisconnected = () => { observedTransportFailure = true; };
145
142
  const onAbort = () => settle(reject, signal.reason ?? new Error("Gateway connection aborted"));
146
143
 
147
144
  if (signal.aborted) {
@@ -151,7 +148,22 @@ function waitForGatewayConnection(gateway, signal) {
151
148
  gateway.on("connected", onConnected);
152
149
  gateway.on("auth-failed", onAuthFailed);
153
150
  gateway.on("error", onError);
151
+ gateway.on("disconnected", onDisconnected);
154
152
  signal.addEventListener("abort", onAbort, { once: true });
153
+
154
+ Promise.resolve()
155
+ .then(() => gateway.start())
156
+ .then(
157
+ () => settle(resolve),
158
+ (error) => {
159
+ // Typed handshake UNAVAILABLE and a pre-auth transport failure both
160
+ // leave GatewayClient's single bounded reconnect loop authoritative.
161
+ // A nonretryable handshake instead emits auth-failed and settles
162
+ // above without waiting for the worker deadline.
163
+ if (isRetryableGatewayHandshake(error) || observedTransportFailure) return;
164
+ settle(reject, error);
165
+ },
166
+ );
155
167
  });
156
168
  }
157
169