@buda-ai/connector 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/cli.js +25 -7
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -2145,6 +2145,7 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
2145
2145
  let pingTimer = null;
2146
2146
  let pongTimer = null;
2147
2147
  let stopped = false;
2148
+ let suspendedForAccessRevocation = false;
2148
2149
  let reconnectDelayMs = RELAY_RECONNECT_INTERVAL_MS;
2149
2150
  let hadOpenConnection = false;
2150
2151
  let activeRelayProtocol = relayProtocol;
@@ -2171,7 +2172,7 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
2171
2172
  return Math.max(reconnectingEstablishedSocket ? 250 : 500, Math.round(base + jitter));
2172
2173
  };
2173
2174
  const scheduleReconnect = (reason) => {
2174
- if (stopped || reconnectTimer) return;
2175
+ if (stopped || suspendedForAccessRevocation || reconnectTimer) return;
2175
2176
  const delay = nextReconnectDelay();
2176
2177
  void writeLog("info", `relay reconnecting in ${delay}ms (${reason})`);
2177
2178
  clearTimers();
@@ -2186,7 +2187,7 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
2186
2187
  }, delay);
2187
2188
  };
2188
2189
  const connect = () => {
2189
- if (stopped) return;
2190
+ if (stopped || suspendedForAccessRevocation) return;
2190
2191
  const relayUrl = getConnectorRelayUrl(config.serverUrl, config.connectorId);
2191
2192
  const oauthToken = launchConfig?.oauthToken?.trim();
2192
2193
  const token = config.token?.trim() || getConnectorToken(launchConfig);
@@ -2250,11 +2251,14 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
2250
2251
  ws.on("close", (code) => {
2251
2252
  detach();
2252
2253
  if (!shouldReconnectConnectorRelay(code)) {
2253
- stopped = true;
2254
- void writeLog(
2255
- "warn",
2256
- code === CONNECTOR_SOCKET_REPLACED_CLOSE_CODE ? "relay replaced by another process for this connector" : "relay access revoked; restore access and restart the Connector to reconnect"
2257
- );
2254
+ clearTimers();
2255
+ if (code === CONNECTOR_SOCKET_REPLACED_CLOSE_CODE) {
2256
+ stopped = true;
2257
+ void writeLog("warn", "relay replaced by another process for this connector");
2258
+ } else {
2259
+ suspendedForAccessRevocation = true;
2260
+ void writeLog("warn", "relay access revoked; waiting for access to be restored");
2261
+ }
2258
2262
  return;
2259
2263
  }
2260
2264
  void writeLog("warn", "relay disconnected");
@@ -2280,6 +2284,19 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
2280
2284
  void writeLog("info", `relay protocol key updated ${nextRelayProtocol.keyId}`);
2281
2285
  }
2282
2286
  },
2287
+ resumeAfterAccessRestore() {
2288
+ if (stopped || !suspendedForAccessRevocation) return;
2289
+ suspendedForAccessRevocation = false;
2290
+ reconnectDelayMs = RELAY_RECONNECT_INTERVAL_MS;
2291
+ hadOpenConnection = false;
2292
+ void writeLog("info", "relay access restored; reconnecting");
2293
+ try {
2294
+ connect();
2295
+ } catch (error) {
2296
+ void writeLog("warn", `relay reconnect threw: ${formatConnectorRelayError(error)}`);
2297
+ scheduleReconnect("access-restored");
2298
+ }
2299
+ },
2283
2300
  stop() {
2284
2301
  stopped = true;
2285
2302
  if (reconnectTimer) {
@@ -3045,6 +3062,7 @@ async function runConnectorDaemon(launchConfig) {
3045
3062
  const interval = setInterval(() => {
3046
3063
  heartbeatConnector(config, launchConfig, activeBunnyDaemon).then(({ relayProtocol: nextRelayProtocol }) => {
3047
3064
  relay.updateRelayProtocol(nextRelayProtocol);
3065
+ relay.resumeAfterAccessRestore();
3048
3066
  }).catch((error) => {
3049
3067
  void writeLog(
3050
3068
  "warn",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buda-ai/connector",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "publishConfig": {