@cfio/cohort-sync 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11826,7 +11826,13 @@ function createClient(convexUrl) {
11826
11826
  }
11827
11827
  savedConvexUrl = convexUrl;
11828
11828
  authCircuitOpen = false;
11829
- client = new ConvexClient(convexUrl);
11829
+ const nativeWS = globalThis.WebSocket;
11830
+ delete globalThis.WebSocket;
11831
+ try {
11832
+ client = new ConvexClient(convexUrl);
11833
+ } finally {
11834
+ if (nativeWS) globalThis.WebSocket = nativeWS;
11835
+ }
11830
11836
  return client;
11831
11837
  }
11832
11838
  function getClient() {
@@ -13372,7 +13378,7 @@ function dumpCtx(ctx) {
13372
13378
  function dumpEvent(event) {
13373
13379
  return dumpCtx(event);
13374
13380
  }
13375
- var PLUGIN_VERSION = true ? "0.14.0" : "unknown";
13381
+ var PLUGIN_VERSION = true ? "0.16.0" : "unknown";
13376
13382
  function resolveGatewayToken(api) {
13377
13383
  const token = api.config?.gateway?.auth?.token;
13378
13384
  return typeof token === "string" ? token : null;
@@ -13988,28 +13994,36 @@ function registerHookHandlers(api, logger, getState) {
13988
13994
  state.logger.warn(`cohort-sync: before_reset activity failed: ${String(err)}`);
13989
13995
  }
13990
13996
  });
13991
- api.on("gateway_stop", async (_event, _ctx) => {
13997
+ api.on("gateway_stop", async (event, _ctx) => {
13992
13998
  const state = getState();
13993
13999
  if (!state) return;
13994
14000
  const { cfg, tracker, logger: log, config } = state;
13995
- log.debug("cohort-sync: hook: gateway_stop", { bridgeState: Object.fromEntries(getChannelAgentBridge()) });
14001
+ const reason = typeof event?.reason === "string" ? event.reason : "";
14002
+ const isRestart = reason.toLowerCase().includes("restart");
14003
+ log.debug("cohort-sync: hook: gateway_stop", {
14004
+ reason,
14005
+ isRestart,
14006
+ bridgeState: Object.fromEntries(getChannelAgentBridge())
14007
+ });
13996
14008
  if (state.keepaliveInterval) {
13997
14009
  clearInterval(state.keepaliveInterval);
13998
14010
  state.keepaliveInterval = null;
13999
14011
  }
14000
14012
  state.activityBatch.drain();
14001
- const shutdownConfigIds = (config?.agents?.list ?? []).map((a) => a.id);
14002
- const allAgentIds = shutdownConfigIds.includes("main") ? shutdownConfigIds : ["main", ...shutdownConfigIds];
14003
- for (const agentId of allAgentIds) {
14004
- const agentName = state.resolveAgentName(agentId);
14005
- try {
14006
- tracker.updateStatus(agentName, "unreachable");
14007
- const snapshot = tracker.getTelemetrySnapshot(agentName);
14008
- if (snapshot) {
14009
- await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, commandsRestartEnabled: cfg.commandsRestartEnabled, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
14013
+ if (!isRestart) {
14014
+ const shutdownConfigIds = (config?.agents?.list ?? []).map((a) => a.id);
14015
+ const allAgentIds = shutdownConfigIds.includes("main") ? shutdownConfigIds : ["main", ...shutdownConfigIds];
14016
+ for (const agentId of allAgentIds) {
14017
+ const agentName = state.resolveAgentName(agentId);
14018
+ try {
14019
+ tracker.updateStatus(agentName, "unreachable");
14020
+ const snapshot = tracker.getTelemetrySnapshot(agentName);
14021
+ if (snapshot) {
14022
+ await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, commandsRestartEnabled: cfg.commandsRestartEnabled, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
14023
+ }
14024
+ } catch (err) {
14025
+ log.warn(`cohort-sync: final unreachable push failed for ${agentName}: ${String(err)}`);
14010
14026
  }
14011
- } catch (err) {
14012
- log.warn(`cohort-sync: final unreachable push failed for ${agentName}: ${String(err)}`);
14013
14027
  }
14014
14028
  }
14015
14029
  saveSessionsToDisk(tracker, state.stateFilePath);
@@ -14018,14 +14032,18 @@ function registerHookHandlers(api, logger, getState) {
14018
14032
  state.persistentGwClient = null;
14019
14033
  state.gwClientInitialized = false;
14020
14034
  }
14021
- try {
14022
- await markAllUnreachable(cfg, log);
14023
- } catch (err) {
14024
- log.warn(`cohort-sync: markAllUnreachable failed: ${String(err)}`);
14035
+ if (!isRestart) {
14036
+ try {
14037
+ await markAllUnreachable(cfg, log);
14038
+ } catch (err) {
14039
+ log.warn(`cohort-sync: markAllUnreachable failed: ${String(err)}`);
14040
+ }
14025
14041
  }
14026
14042
  tracker.clear();
14027
14043
  closeBridge();
14028
- log.info("cohort-sync: gateway stopped, all resources cleaned up");
14044
+ log.info(
14045
+ isRestart ? "cohort-sync: gateway restarting, resources cleaned up (agents kept online)" : "cohort-sync: gateway stopped, all resources cleaned up"
14046
+ );
14029
14047
  });
14030
14048
  }
14031
14049
  function initializeHookState(api, cfg) {
@@ -55,5 +55,5 @@
55
55
  }
56
56
  }
57
57
  },
58
- "version": "0.14.0"
58
+ "version": "0.16.0"
59
59
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "OpenClaw plugin — syncs agent telemetry, sessions, and activity to the Cohort dashboard",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "OpenClaw plugin — syncs agent telemetry, sessions, and activity to the Cohort dashboard",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.cohort.bot/gateway",