@cfio/cohort-sync 0.11.1 → 0.11.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.
package/dist/index.js CHANGED
@@ -12034,7 +12034,7 @@ async function injectNotification(port, hooksToken, n, agentId = "main") {
12034
12034
  }
12035
12035
  var deliveryFailures = /* @__PURE__ */ new Map();
12036
12036
  var MAX_DELIVERY_ATTEMPTS = 3;
12037
- async function startNotificationSubscription(port, cfg, hooksToken, logger, gwClient) {
12037
+ async function startNotificationSubscription(port, cfg, hooksToken, logger, gwClient, resolvedNameMap) {
12038
12038
  const c = getClient();
12039
12039
  if (!c) {
12040
12040
  logger.warn("cohort-sync: no ConvexClient \u2014 notification subscription skipped");
@@ -12045,13 +12045,12 @@ async function startNotificationSubscription(port, cfg, hooksToken, logger, gwCl
12045
12045
  `cohort-sync: hooks.token not configured \u2014 real-time notifications disabled (telemetry will still be pushed).`
12046
12046
  );
12047
12047
  }
12048
- const agentNames = cfg.agentNameMap ? Object.values(cfg.agentNameMap) : ["main"];
12048
+ const sourceMap = resolvedNameMap ?? cfg.agentNameMap ?? { main: "main" };
12049
12049
  const reverseNameMap = {};
12050
- if (cfg.agentNameMap) {
12051
- for (const [openclawId, cohortName] of Object.entries(cfg.agentNameMap)) {
12052
- reverseNameMap[cohortName] = openclawId;
12053
- }
12050
+ for (const [openclawId, cohortName] of Object.entries(sourceMap)) {
12051
+ reverseNameMap[cohortName] = openclawId;
12054
12052
  }
12053
+ const agentNames = Array.from(new Set(Object.values(sourceMap)));
12055
12054
  for (const agentName of agentNames) {
12056
12055
  const openclawAgentId = reverseNameMap[agentName] ?? agentName;
12057
12056
  logger.info(`cohort-sync: subscribing to notifications for agent "${agentName}" (openclawId: "${openclawAgentId}")`);
@@ -13334,7 +13333,7 @@ function dumpCtx(ctx) {
13334
13333
  function dumpEvent(event) {
13335
13334
  return dumpCtx(event);
13336
13335
  }
13337
- var PLUGIN_VERSION = true ? "0.11.1" : "unknown";
13336
+ var PLUGIN_VERSION = true ? "0.11.3" : "unknown";
13338
13337
  function resolveGatewayToken(api) {
13339
13338
  const token = api.config?.gateway?.auth?.token;
13340
13339
  return typeof token === "string" ? token : null;
@@ -13465,11 +13464,9 @@ function initGatewayClient(port, token, cfg, resolveAgentName, logger) {
13465
13464
  }
13466
13465
  async function handleGatewayStart(event, state) {
13467
13466
  if (!state) {
13468
- console.log("[cohort-sync] handleGatewayStart: state is null, skipping");
13469
13467
  return;
13470
13468
  }
13471
13469
  const { cfg, tracker, logger, config, api } = state;
13472
- logger.info("cohort-sync: handleGatewayStart ENTERED", { port: event.port, hasConfig: !!config, hasCfg: !!cfg });
13473
13470
  try {
13474
13471
  checkForUpdate(PLUGIN_VERSION, logger).catch(() => {
13475
13472
  });
@@ -13517,16 +13514,21 @@ async function handleGatewayStart(event, state) {
13517
13514
  logger.debug("cohort-sync: no gateway token");
13518
13515
  logger.warn("cohort-sync: no gateway auth token \u2014 cron operations disabled");
13519
13516
  }
13517
+ const allAgentIds = ["main", ...(config?.agents?.list ?? []).map((a) => a.id)];
13518
+ const resolvedNameMap = {};
13519
+ for (const agentId of allAgentIds) {
13520
+ resolvedNameMap[agentId] = state.resolveAgentName(agentId);
13521
+ }
13520
13522
  await startNotificationSubscription(
13521
13523
  event.port,
13522
13524
  cfg,
13523
13525
  api.config.hooks?.token,
13524
13526
  logger,
13525
- state.persistentGwClient
13527
+ state.persistentGwClient,
13528
+ resolvedNameMap
13526
13529
  ).catch((err) => {
13527
13530
  logger.error(`cohort-sync: subscription init failed: ${String(err)}`);
13528
13531
  });
13529
- const allAgentIds = ["main", ...(config?.agents?.list ?? []).map((a) => a.id)];
13530
13532
  for (const agentId of allAgentIds) {
13531
13533
  const agentName = state.resolveAgentName(agentId);
13532
13534
  try {
@@ -13664,16 +13666,6 @@ function registerHookHandlers(api, logger, getState) {
13664
13666
  const contextTokens = (usage.input ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
13665
13667
  const model = event.model ?? state.resolveModel(ctx.agentId ?? "main");
13666
13668
  const contextLimit = state.getModelContextLimit(model);
13667
- log.debug("cohort-sync: hook: llm_output", {
13668
- ctx: dumpCtx(ctx),
13669
- model,
13670
- tokensIn: usage.input,
13671
- tokensOut: usage.output,
13672
- cacheRead: usage.cacheRead,
13673
- cacheWrite: usage.cacheWrite,
13674
- contextTokens,
13675
- contextLimit
13676
- });
13677
13669
  const agentId = ctx.agentId ?? "main";
13678
13670
  const agentName = state.resolveAgentName(agentId);
13679
13671
  try {
@@ -14152,6 +14144,7 @@ var POCKET_GUIDE = `# Cohort Agent Guide (Pocket Version)
14152
14144
  function textResult(text, details) {
14153
14145
  return { content: [{ type: "text", text }], details: details ?? void 0 };
14154
14146
  }
14147
+ var sharedHookState = null;
14155
14148
  var plugin = {
14156
14149
  id: "cohort-sync",
14157
14150
  name: "Cohort Sync",
@@ -14174,18 +14167,16 @@ var plugin = {
14174
14167
  );
14175
14168
  return;
14176
14169
  }
14177
- let hookState = null;
14178
- registerHookHandlers(api, api.logger, () => hookState);
14170
+ registerHookHandlers(api, api.logger, () => sharedHookState);
14179
14171
  const gatewayPort = api.config?.gateway?.port ?? 18789;
14180
14172
  api.registerHook(
14181
14173
  "gateway:startup",
14182
14174
  async (...args) => {
14183
14175
  const event = args[0] ?? {};
14184
14176
  const port = event?.port ?? gatewayPort;
14185
- api.logger.info(`cohort-sync: gateway:startup hook fired (port=${port}, hookState=${hookState ? "SET" : "NULL"})`);
14177
+ api.logger.info(`cohort-sync: gateway:startup hook fired (port=${port})`);
14186
14178
  try {
14187
- await handleGatewayStart({ ...event, port }, hookState);
14188
- api.logger.info("cohort-sync: handleGatewayStart completed");
14179
+ await handleGatewayStart({ ...event, port }, sharedHookState);
14189
14180
  } catch (err) {
14190
14181
  api.logger.error(`cohort-sync: handleGatewayStart THREW: ${err instanceof Error ? err.stack : String(err)}`);
14191
14182
  }
@@ -14435,15 +14426,17 @@ Do not attempt more comments until tomorrow.`);
14435
14426
  return;
14436
14427
  }
14437
14428
  api.logger.info(`cohort-sync: activated (api: ${apiUrl2})`);
14438
- hookState = initializeHookState(api, {
14439
- apiUrl: apiUrl2,
14440
- apiKey: apiKey2,
14441
- stateDir: svcCtx.stateDir,
14442
- agentNameMap: cfg?.agentNameMap
14443
- });
14429
+ if (!sharedHookState) {
14430
+ sharedHookState = initializeHookState(api, {
14431
+ apiUrl: apiUrl2,
14432
+ apiKey: apiKey2,
14433
+ stateDir: svcCtx.stateDir,
14434
+ agentNameMap: cfg?.agentNameMap
14435
+ });
14436
+ }
14444
14437
  },
14445
14438
  async stop() {
14446
- hookState = null;
14439
+ sharedHookState = null;
14447
14440
  closeBridge();
14448
14441
  api.logger.info("cohort-sync: service stopped");
14449
14442
  }
@@ -55,5 +55,5 @@
55
55
  }
56
56
  }
57
57
  },
58
- "version": "0.11.1"
58
+ "version": "0.11.3"
59
59
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
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.11.1",
3
+ "version": "0.11.3",
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",