@cfio/cohort-sync 0.11.4 → 0.12.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 +46 -19
- package/dist/openclaw.plugin.json +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2670,15 +2670,18 @@ async function checkForUpdate(currentVersion, logger) {
|
|
|
2670
2670
|
const res = await fetch("https://registry.npmjs.org/@cfio/cohort-sync/latest", {
|
|
2671
2671
|
signal: AbortSignal.timeout(5e3)
|
|
2672
2672
|
});
|
|
2673
|
-
if (!res.ok) return;
|
|
2673
|
+
if (!res.ok) return null;
|
|
2674
2674
|
const data = await res.json();
|
|
2675
2675
|
const latest = data.version;
|
|
2676
2676
|
if (latest && latest !== currentVersion && isNewerVersion(latest, currentVersion)) {
|
|
2677
2677
|
logger.warn(
|
|
2678
2678
|
`cohort-sync: update available (${currentVersion} \u2192 ${latest}) \u2014 run "openclaw plugins install @cfio/cohort-sync" to update`
|
|
2679
2679
|
);
|
|
2680
|
+
return latest;
|
|
2680
2681
|
}
|
|
2682
|
+
return null;
|
|
2681
2683
|
} catch {
|
|
2684
|
+
return null;
|
|
2682
2685
|
}
|
|
2683
2686
|
}
|
|
2684
2687
|
async function syncAgentStatus(agentName, status, model, cfg, logger) {
|
|
@@ -2722,6 +2725,22 @@ async function reconcileRoster(openClawAgents, cfg, logger) {
|
|
|
2722
2725
|
const agentName = (cfg.agentNameMap?.[oc.id] ?? oc.identity?.name ?? oc.id).toLowerCase();
|
|
2723
2726
|
const existing = cohortByName.get(agentName);
|
|
2724
2727
|
if (!existing) {
|
|
2728
|
+
if (agentName === oc.id.toLowerCase() && oc.identity?.name) {
|
|
2729
|
+
const identityName = oc.identity.name.toLowerCase();
|
|
2730
|
+
if (cohortByName.has(identityName)) {
|
|
2731
|
+
logger.info(`cohort-sync: skipping phantom "${agentName}" \u2014 agent exists as "${identityName}"`);
|
|
2732
|
+
continue;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
if (agentName === oc.id.toLowerCase() && cohortByName.size > 0) {
|
|
2736
|
+
const alreadyRegistered = cohortAgents.some(
|
|
2737
|
+
(ca) => openClawNames.has(ca.name.toLowerCase()) && ca.name.toLowerCase() !== agentName
|
|
2738
|
+
);
|
|
2739
|
+
if (alreadyRegistered) {
|
|
2740
|
+
logger.info(`cohort-sync: skipping raw-ID agent "${agentName}" \u2014 identity-resolved agent already exists`);
|
|
2741
|
+
continue;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2725
2744
|
try {
|
|
2726
2745
|
await v1Post(cfg.apiUrl, cfg.apiKey, "/api/v1/agents", {
|
|
2727
2746
|
name: agentName,
|
|
@@ -13334,7 +13353,7 @@ function dumpCtx(ctx) {
|
|
|
13334
13353
|
function dumpEvent(event) {
|
|
13335
13354
|
return dumpCtx(event);
|
|
13336
13355
|
}
|
|
13337
|
-
var PLUGIN_VERSION = true ? "0.
|
|
13356
|
+
var PLUGIN_VERSION = true ? "0.12.0" : "unknown";
|
|
13338
13357
|
function resolveGatewayToken(api) {
|
|
13339
13358
|
const token = api.config?.gateway?.auth?.token;
|
|
13340
13359
|
return typeof token === "string" ? token : null;
|
|
@@ -13469,8 +13488,10 @@ async function handleGatewayStart(event, state) {
|
|
|
13469
13488
|
}
|
|
13470
13489
|
const { cfg, tracker, logger, config, api } = state;
|
|
13471
13490
|
try {
|
|
13472
|
-
checkForUpdate(PLUGIN_VERSION, logger)
|
|
13473
|
-
|
|
13491
|
+
const latestVersion = await checkForUpdate(PLUGIN_VERSION, logger);
|
|
13492
|
+
if (latestVersion) {
|
|
13493
|
+
state.latestPluginVersion = latestVersion;
|
|
13494
|
+
}
|
|
13474
13495
|
} catch {
|
|
13475
13496
|
}
|
|
13476
13497
|
try {
|
|
@@ -13515,7 +13536,8 @@ async function handleGatewayStart(event, state) {
|
|
|
13515
13536
|
logger.debug("cohort-sync: no gateway token");
|
|
13516
13537
|
logger.warn("cohort-sync: no gateway auth token \u2014 cron operations disabled");
|
|
13517
13538
|
}
|
|
13518
|
-
const
|
|
13539
|
+
const configIds = (config?.agents?.list ?? []).map((a) => a.id);
|
|
13540
|
+
const allAgentIds = configIds.includes("main") ? configIds : ["main", ...configIds];
|
|
13519
13541
|
const resolvedNameMap = {};
|
|
13520
13542
|
for (const agentId of allAgentIds) {
|
|
13521
13543
|
resolvedNameMap[agentId] = state.resolveAgentName(agentId);
|
|
@@ -13537,7 +13559,7 @@ async function handleGatewayStart(event, state) {
|
|
|
13537
13559
|
tracker.updateStatus(agentName, "idle");
|
|
13538
13560
|
const snapshot = tracker.getTelemetrySnapshot(agentName);
|
|
13539
13561
|
if (snapshot) {
|
|
13540
|
-
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION });
|
|
13562
|
+
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
|
|
13541
13563
|
tracker.markTelemetryPushed(agentName);
|
|
13542
13564
|
}
|
|
13543
13565
|
} catch (err) {
|
|
@@ -13551,7 +13573,7 @@ async function handleGatewayStart(event, state) {
|
|
|
13551
13573
|
const agentName = state.resolveAgentName(agentId);
|
|
13552
13574
|
const snapshot = tracker.getTelemetrySnapshot(agentName);
|
|
13553
13575
|
if (snapshot) {
|
|
13554
|
-
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION }).catch(() => {
|
|
13576
|
+
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} }).catch(() => {
|
|
13555
13577
|
});
|
|
13556
13578
|
}
|
|
13557
13579
|
}
|
|
@@ -13629,7 +13651,7 @@ function registerHookHandlers(api, logger, getState) {
|
|
|
13629
13651
|
if (tracker.shouldPushTelemetry(agentName)) {
|
|
13630
13652
|
const snapshot = tracker.getTelemetrySnapshot(agentName);
|
|
13631
13653
|
if (snapshot) {
|
|
13632
|
-
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION });
|
|
13654
|
+
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
|
|
13633
13655
|
tracker.markTelemetryPushed(agentName);
|
|
13634
13656
|
}
|
|
13635
13657
|
}
|
|
@@ -13688,7 +13710,7 @@ function registerHookHandlers(api, logger, getState) {
|
|
|
13688
13710
|
if (tracker.shouldPushTelemetry(agentName)) {
|
|
13689
13711
|
const snapshot = tracker.getTelemetrySnapshot(agentName);
|
|
13690
13712
|
if (snapshot) {
|
|
13691
|
-
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION });
|
|
13713
|
+
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
|
|
13692
13714
|
tracker.markTelemetryPushed(agentName);
|
|
13693
13715
|
}
|
|
13694
13716
|
}
|
|
@@ -13716,7 +13738,7 @@ function registerHookHandlers(api, logger, getState) {
|
|
|
13716
13738
|
if (tracker.shouldPushTelemetry(agentName)) {
|
|
13717
13739
|
const snapshot = tracker.getTelemetrySnapshot(agentName);
|
|
13718
13740
|
if (snapshot) {
|
|
13719
|
-
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION });
|
|
13741
|
+
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
|
|
13720
13742
|
tracker.markTelemetryPushed(agentName);
|
|
13721
13743
|
}
|
|
13722
13744
|
}
|
|
@@ -13758,7 +13780,7 @@ function registerHookHandlers(api, logger, getState) {
|
|
|
13758
13780
|
if (tracker.shouldPushTelemetry(agentName)) {
|
|
13759
13781
|
const snapshot = tracker.getTelemetrySnapshot(agentName);
|
|
13760
13782
|
if (snapshot) {
|
|
13761
|
-
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION });
|
|
13783
|
+
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
|
|
13762
13784
|
tracker.markTelemetryPushed(agentName);
|
|
13763
13785
|
}
|
|
13764
13786
|
}
|
|
@@ -13954,14 +13976,15 @@ function registerHookHandlers(api, logger, getState) {
|
|
|
13954
13976
|
state.keepaliveInterval = null;
|
|
13955
13977
|
}
|
|
13956
13978
|
state.activityBatch.drain();
|
|
13957
|
-
const
|
|
13979
|
+
const shutdownConfigIds = (config?.agents?.list ?? []).map((a) => a.id);
|
|
13980
|
+
const allAgentIds = shutdownConfigIds.includes("main") ? shutdownConfigIds : ["main", ...shutdownConfigIds];
|
|
13958
13981
|
for (const agentId of allAgentIds) {
|
|
13959
13982
|
const agentName = state.resolveAgentName(agentId);
|
|
13960
13983
|
try {
|
|
13961
13984
|
tracker.updateStatus(agentName, "unreachable");
|
|
13962
13985
|
const snapshot = tracker.getTelemetrySnapshot(agentName);
|
|
13963
13986
|
if (snapshot) {
|
|
13964
|
-
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION });
|
|
13987
|
+
await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
|
|
13965
13988
|
}
|
|
13966
13989
|
} catch (err) {
|
|
13967
13990
|
log.warn(`cohort-sync: final unreachable push failed for ${agentName}: ${String(err)}`);
|
|
@@ -13992,16 +14015,19 @@ function initializeHookState(api, cfg) {
|
|
|
13992
14015
|
createClient(convexUrl);
|
|
13993
14016
|
setLogger(logger);
|
|
13994
14017
|
const identityNameMap = {};
|
|
13995
|
-
const mainIdentity = parseIdentityFile(process.cwd());
|
|
13996
|
-
if (mainIdentity?.name) {
|
|
13997
|
-
identityNameMap["main"] = mainIdentity.name.toLowerCase();
|
|
13998
|
-
}
|
|
13999
14018
|
for (const agent of config?.agents?.list ?? []) {
|
|
14000
|
-
const
|
|
14019
|
+
const workspaceDir = agent.workspace ?? (agent.id === "main" ? process.cwd() : void 0);
|
|
14020
|
+
const identity = resolveIdentity(agent.identity, workspaceDir);
|
|
14001
14021
|
if (identity?.name) {
|
|
14002
14022
|
identityNameMap[agent.id] = identity.name.toLowerCase();
|
|
14003
14023
|
}
|
|
14004
14024
|
}
|
|
14025
|
+
if (!identityNameMap["main"]) {
|
|
14026
|
+
const mainIdentity = parseIdentityFile(process.cwd());
|
|
14027
|
+
if (mainIdentity?.name) {
|
|
14028
|
+
identityNameMap["main"] = mainIdentity.name.toLowerCase();
|
|
14029
|
+
}
|
|
14030
|
+
}
|
|
14005
14031
|
logger.debug("cohort-sync: identity name map", { identityNameMap });
|
|
14006
14032
|
function resolveAgentName(agentId) {
|
|
14007
14033
|
return (nameMap?.[agentId] ?? identityNameMap[agentId] ?? agentId).toLowerCase();
|
|
@@ -14090,7 +14116,8 @@ function initializeHookState(api, cfg) {
|
|
|
14090
14116
|
gwClientInitialized,
|
|
14091
14117
|
keepaliveInterval: null,
|
|
14092
14118
|
commandUnsubscriber: commandUnsub,
|
|
14093
|
-
api
|
|
14119
|
+
api,
|
|
14120
|
+
latestPluginVersion: null
|
|
14094
14121
|
};
|
|
14095
14122
|
}
|
|
14096
14123
|
|
package/dist/package.json
CHANGED
package/package.json
CHANGED