@cfio/cohort-sync 0.10.1 → 0.10.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 +68 -52
- package/dist/openclaw.plugin.json +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13381,7 +13381,7 @@ function dumpCtx(ctx) {
|
|
|
13381
13381
|
function dumpEvent(event) {
|
|
13382
13382
|
return dumpCtx(event);
|
|
13383
13383
|
}
|
|
13384
|
-
var PLUGIN_VERSION = true ? "0.10.
|
|
13384
|
+
var PLUGIN_VERSION = true ? "0.10.3" : "unknown";
|
|
13385
13385
|
var _gatewayStartHandler = null;
|
|
13386
13386
|
async function handleGatewayStart(event) {
|
|
13387
13387
|
if (_gatewayStartHandler) {
|
|
@@ -13543,6 +13543,11 @@ function registerHooks(api, cfg) {
|
|
|
13543
13543
|
initGatewayClient(gatewayPort, gatewayToken, cfg, resolveAgentName, logger);
|
|
13544
13544
|
}
|
|
13545
13545
|
const cronStorePath = api.config?.cron?.store ?? path2.join(os2.homedir(), ".openclaw", "cron", "jobs.json");
|
|
13546
|
+
for (const eventType of ["agent", "session", "command", "gateway", "message"]) {
|
|
13547
|
+
api.registerHook(eventType, async (event) => {
|
|
13548
|
+
logger.info(`cohort-sync: [DIAG] event=${eventType} action=${event?.action} sessionKey=${event?.sessionKey} ctxKeys=${Object.keys(event?.context ?? {}).join(",")}`);
|
|
13549
|
+
}, { name: `cohort-sync.diag-${eventType}`, description: `Diagnostic: catch all ${eventType} events` });
|
|
13550
|
+
}
|
|
13546
13551
|
logger.info(`cohort-sync: registerHooks v${PLUGIN_VERSION}`);
|
|
13547
13552
|
logger.info("cohort-sync: hooks registered", {
|
|
13548
13553
|
PLUGIN_VERSION,
|
|
@@ -13779,8 +13784,9 @@ function registerHooks(api, cfg) {
|
|
|
13779
13784
|
}, KEEPALIVE_INTERVAL_MS);
|
|
13780
13785
|
logger.info(`cohort-sync: keepalive interval started (${KEEPALIVE_INTERVAL_MS / 1e3}s)`);
|
|
13781
13786
|
};
|
|
13782
|
-
api.
|
|
13783
|
-
|
|
13787
|
+
api.registerHook("agent_end", async (event) => {
|
|
13788
|
+
const ctx = event.context ?? {};
|
|
13789
|
+
logger.debug("cohort-sync: hook: agent_end", { ctx: dumpCtx(ctx), success: ctx.success, error: ctx.error, durationMs: ctx.durationMs });
|
|
13784
13790
|
const agentId = ctx.agentId ?? "main";
|
|
13785
13791
|
const agentName = resolveAgentName(agentId);
|
|
13786
13792
|
try {
|
|
@@ -13806,11 +13812,11 @@ function registerHooks(api, cfg) {
|
|
|
13806
13812
|
logger.debug("cohort-sync: cron agent end push failed", { error: String(err) });
|
|
13807
13813
|
}
|
|
13808
13814
|
}
|
|
13809
|
-
if (
|
|
13815
|
+
if (ctx.success === false) {
|
|
13810
13816
|
const entry = buildActivityEntry(agentName, "agent_end", {
|
|
13811
13817
|
success: false,
|
|
13812
|
-
error:
|
|
13813
|
-
durationMs:
|
|
13818
|
+
error: ctx.error,
|
|
13819
|
+
durationMs: ctx.durationMs,
|
|
13814
13820
|
sessionKey: ctx.sessionKey
|
|
13815
13821
|
});
|
|
13816
13822
|
if (entry) activityBatch.add(entry);
|
|
@@ -13818,11 +13824,12 @@ function registerHooks(api, cfg) {
|
|
|
13818
13824
|
} catch (err) {
|
|
13819
13825
|
logger.warn(`cohort-sync: agent_end sync failed: ${String(err)}`);
|
|
13820
13826
|
}
|
|
13821
|
-
});
|
|
13822
|
-
api.
|
|
13823
|
-
const
|
|
13827
|
+
}, { name: "cohort-sync.agent_end", description: "Mark idle, push telemetry, emit activity on failure" });
|
|
13828
|
+
api.registerHook("llm_output", async (event) => {
|
|
13829
|
+
const ctx = event.context ?? {};
|
|
13830
|
+
const usage = ctx.usage ?? {};
|
|
13824
13831
|
const contextTokens = (usage.input ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
|
|
13825
|
-
const model =
|
|
13832
|
+
const model = ctx.model ?? resolveModel(ctx.agentId ?? "main");
|
|
13826
13833
|
const contextLimit = getModelContextLimit(model);
|
|
13827
13834
|
logger.debug("cohort-sync: hook: llm_output", {
|
|
13828
13835
|
ctx: dumpCtx(ctx),
|
|
@@ -13867,14 +13874,15 @@ function registerHooks(api, cfg) {
|
|
|
13867
13874
|
} catch (err) {
|
|
13868
13875
|
logger.warn(`cohort-sync: llm_output telemetry failed: ${String(err)}`);
|
|
13869
13876
|
}
|
|
13870
|
-
});
|
|
13871
|
-
api.
|
|
13872
|
-
|
|
13877
|
+
}, { name: "cohort-sync.llm_output", description: "Accumulate token usage, push telemetry and sessions" });
|
|
13878
|
+
api.registerHook("after_compaction", async (event) => {
|
|
13879
|
+
const ctx = event.context ?? {};
|
|
13880
|
+
logger.debug("cohort-sync: hook: after_compaction", { ctx: dumpCtx(ctx), messageCount: ctx.messageCount, tokenCount: ctx.tokenCount });
|
|
13873
13881
|
const agentId = ctx.agentId ?? "main";
|
|
13874
13882
|
const agentName = resolveAgentName(agentId);
|
|
13875
13883
|
try {
|
|
13876
13884
|
tracker2.updateFromCompaction(agentName, {
|
|
13877
|
-
contextTokens:
|
|
13885
|
+
contextTokens: ctx.tokenCount ?? 0,
|
|
13878
13886
|
contextLimit: getModelContextLimit(resolveModel(agentId))
|
|
13879
13887
|
});
|
|
13880
13888
|
if (tracker2.shouldPushTelemetry(agentName)) {
|
|
@@ -13885,17 +13893,18 @@ function registerHooks(api, cfg) {
|
|
|
13885
13893
|
}
|
|
13886
13894
|
}
|
|
13887
13895
|
const entry = buildActivityEntry(agentName, "after_compaction", {
|
|
13888
|
-
messageCount:
|
|
13889
|
-
compactedCount:
|
|
13896
|
+
messageCount: ctx.messageCount,
|
|
13897
|
+
compactedCount: ctx.compactedCount,
|
|
13890
13898
|
sessionKey: ctx.sessionKey
|
|
13891
13899
|
});
|
|
13892
13900
|
if (entry) activityBatch.add(entry);
|
|
13893
13901
|
} catch (err) {
|
|
13894
13902
|
logger.warn(`cohort-sync: after_compaction telemetry failed: ${String(err)}`);
|
|
13895
13903
|
}
|
|
13896
|
-
});
|
|
13897
|
-
api.
|
|
13898
|
-
|
|
13904
|
+
}, { name: "cohort-sync.after_compaction", description: "Increment compaction count, push telemetry" });
|
|
13905
|
+
api.registerHook("before_agent_start", async (event) => {
|
|
13906
|
+
const ctx = event.context ?? {};
|
|
13907
|
+
logger.debug("cohort-sync: hook: before_agent_start", { ctx: dumpCtx(ctx), event: dumpEvent(event) });
|
|
13899
13908
|
const agentId = ctx.agentId ?? "main";
|
|
13900
13909
|
const agentName = resolveAgentName(agentId);
|
|
13901
13910
|
logger.debug("cohort-sync: hook: before_agent_start resolved", { agentId, agentName, ctxChannelId: ctx.channelId, ctxMessageProvider: ctx.messageProvider, ctxSessionKey: ctx.sessionKey, ctxAccountId: ctx.accountId });
|
|
@@ -13945,8 +13954,9 @@ function registerHooks(api, cfg) {
|
|
|
13945
13954
|
} catch (err) {
|
|
13946
13955
|
logger.warn(`cohort-sync: before_agent_start telemetry failed: ${String(err)}`);
|
|
13947
13956
|
}
|
|
13948
|
-
});
|
|
13949
|
-
api.
|
|
13957
|
+
}, { name: "cohort-sync.before_agent_start", description: "Mark working, infer sessions, populate channel bridge" });
|
|
13958
|
+
api.registerHook("session_start", async (event) => {
|
|
13959
|
+
const ctx = event.context ?? {};
|
|
13950
13960
|
logger.debug("cohort-sync: hook: session_start", { ctx: dumpCtx(ctx), event: dumpEvent(event) });
|
|
13951
13961
|
const agentId = ctx.agentId ?? "main";
|
|
13952
13962
|
const agentName = resolveAgentName(agentId);
|
|
@@ -13962,14 +13972,15 @@ function registerHooks(api, cfg) {
|
|
|
13962
13972
|
const entry = buildActivityEntry(agentName, "session_start", {
|
|
13963
13973
|
channel: parsed.channel,
|
|
13964
13974
|
sessionKey,
|
|
13965
|
-
resumedFrom:
|
|
13975
|
+
resumedFrom: ctx.resumedFrom
|
|
13966
13976
|
});
|
|
13967
13977
|
if (entry) activityBatch.add(entry);
|
|
13968
13978
|
} catch (err) {
|
|
13969
13979
|
logger.warn(`cohort-sync: session_start tracking failed: ${String(err)}`);
|
|
13970
13980
|
}
|
|
13971
|
-
});
|
|
13972
|
-
api.
|
|
13981
|
+
}, { name: "cohort-sync.session_start", description: "Track session start, push sessions" });
|
|
13982
|
+
api.registerHook("session_end", async (event) => {
|
|
13983
|
+
const ctx = event.context ?? {};
|
|
13973
13984
|
logger.debug("cohort-sync: hook: session_end", { ctx: dumpCtx(ctx), event: dumpEvent(event) });
|
|
13974
13985
|
const agentId = ctx.agentId ?? "main";
|
|
13975
13986
|
const agentName = resolveAgentName(agentId);
|
|
@@ -13983,23 +13994,24 @@ function registerHooks(api, cfg) {
|
|
|
13983
13994
|
}
|
|
13984
13995
|
const entry = buildActivityEntry(agentName, "session_end", {
|
|
13985
13996
|
sessionKey,
|
|
13986
|
-
messageCount:
|
|
13987
|
-
durationMs:
|
|
13997
|
+
messageCount: ctx.messageCount,
|
|
13998
|
+
durationMs: ctx.durationMs
|
|
13988
13999
|
});
|
|
13989
14000
|
if (entry) activityBatch.add(entry);
|
|
13990
14001
|
} catch (err) {
|
|
13991
14002
|
logger.warn(`cohort-sync: session_end tracking failed: ${String(err)}`);
|
|
13992
14003
|
}
|
|
13993
|
-
});
|
|
13994
|
-
api.
|
|
13995
|
-
|
|
14004
|
+
}, { name: "cohort-sync.session_end", description: "Remove session, push sessions" });
|
|
14005
|
+
api.registerHook("after_tool_call", async (event) => {
|
|
14006
|
+
const ctx = event.context ?? {};
|
|
14007
|
+
logger.debug("cohort-sync: hook: after_tool_call", { ctx: dumpCtx(ctx), toolName: ctx.toolName, error: ctx.error });
|
|
13996
14008
|
const agentName = resolveAgentFromContext(ctx);
|
|
13997
14009
|
try {
|
|
13998
14010
|
const entry = buildActivityEntry(agentName, "after_tool_call", {
|
|
13999
|
-
toolName:
|
|
14000
|
-
params:
|
|
14001
|
-
error:
|
|
14002
|
-
durationMs:
|
|
14011
|
+
toolName: ctx.toolName,
|
|
14012
|
+
params: ctx.params,
|
|
14013
|
+
error: ctx.error,
|
|
14014
|
+
durationMs: ctx.durationMs,
|
|
14003
14015
|
sessionKey: ctx.sessionKey,
|
|
14004
14016
|
model: resolveModel(ctx.agentId ?? "main")
|
|
14005
14017
|
});
|
|
@@ -14007,11 +14019,12 @@ function registerHooks(api, cfg) {
|
|
|
14007
14019
|
} catch (err) {
|
|
14008
14020
|
logger.warn(`cohort-sync: after_tool_call activity failed: ${String(err)}`);
|
|
14009
14021
|
}
|
|
14010
|
-
});
|
|
14011
|
-
api.
|
|
14022
|
+
}, { name: "cohort-sync.after_tool_call", description: "Emit activity entry for tool calls" });
|
|
14023
|
+
api.registerHook("message_received", async (event) => {
|
|
14024
|
+
const ctx = event.context ?? {};
|
|
14012
14025
|
logger.debug("cohort-sync: hook: message_received raw", {
|
|
14013
14026
|
ctx: dumpCtx(ctx),
|
|
14014
|
-
event: dumpEvent(
|
|
14027
|
+
event: dumpEvent(event),
|
|
14015
14028
|
bridgeStateBefore: Object.fromEntries(getChannelAgentBridge())
|
|
14016
14029
|
});
|
|
14017
14030
|
const agentName = resolveAgentFromContext(ctx);
|
|
@@ -14021,7 +14034,7 @@ function registerHooks(api, cfg) {
|
|
|
14021
14034
|
channel,
|
|
14022
14035
|
accountId: ctx.accountId,
|
|
14023
14036
|
conversationId: ctx.conversationId,
|
|
14024
|
-
from:
|
|
14037
|
+
from: ctx.from
|
|
14025
14038
|
});
|
|
14026
14039
|
try {
|
|
14027
14040
|
const entry = buildActivityEntry(agentName, "message_received", {
|
|
@@ -14031,8 +14044,9 @@ function registerHooks(api, cfg) {
|
|
|
14031
14044
|
} catch (err) {
|
|
14032
14045
|
logger.warn(`cohort-sync: message_received activity failed: ${String(err)}`);
|
|
14033
14046
|
}
|
|
14034
|
-
});
|
|
14035
|
-
api.
|
|
14047
|
+
}, { name: "cohort-sync.message_received", description: "Emit activity entry for received messages" });
|
|
14048
|
+
api.registerHook("message_sent", async (event) => {
|
|
14049
|
+
const ctx = event.context ?? {};
|
|
14036
14050
|
logger.debug("cohort-sync: hook: message_sent raw", {
|
|
14037
14051
|
ctx: dumpCtx(ctx),
|
|
14038
14052
|
event: dumpEvent(event),
|
|
@@ -14045,22 +14059,23 @@ function registerHooks(api, cfg) {
|
|
|
14045
14059
|
channel,
|
|
14046
14060
|
accountId: ctx.accountId,
|
|
14047
14061
|
conversationId: ctx.conversationId,
|
|
14048
|
-
to:
|
|
14049
|
-
success:
|
|
14050
|
-
error:
|
|
14062
|
+
to: ctx.to,
|
|
14063
|
+
success: ctx.success,
|
|
14064
|
+
error: ctx.error
|
|
14051
14065
|
});
|
|
14052
14066
|
try {
|
|
14053
14067
|
const entry = buildActivityEntry(agentName, "message_sent", {
|
|
14054
14068
|
channel: channel ?? "unknown",
|
|
14055
|
-
success:
|
|
14056
|
-
error:
|
|
14069
|
+
success: ctx.success,
|
|
14070
|
+
error: ctx.error
|
|
14057
14071
|
});
|
|
14058
14072
|
if (entry) activityBatch.add(entry);
|
|
14059
14073
|
} catch (err) {
|
|
14060
14074
|
logger.warn(`cohort-sync: message_sent activity failed: ${String(err)}`);
|
|
14061
14075
|
}
|
|
14062
|
-
});
|
|
14063
|
-
api.
|
|
14076
|
+
}, { name: "cohort-sync.message_sent", description: "Emit activity entry for sent messages" });
|
|
14077
|
+
api.registerHook("before_compaction", async (event) => {
|
|
14078
|
+
const ctx = event.context ?? {};
|
|
14064
14079
|
logger.debug("cohort-sync: hook: before_compaction", { ctx: dumpCtx(ctx) });
|
|
14065
14080
|
const agentId = ctx.agentId ?? "main";
|
|
14066
14081
|
const agentName = resolveAgentName(agentId);
|
|
@@ -14072,22 +14087,23 @@ function registerHooks(api, cfg) {
|
|
|
14072
14087
|
} catch (err) {
|
|
14073
14088
|
logger.warn(`cohort-sync: before_compaction activity failed: ${String(err)}`);
|
|
14074
14089
|
}
|
|
14075
|
-
});
|
|
14076
|
-
api.
|
|
14090
|
+
}, { name: "cohort-sync.before_compaction", description: "Emit activity entry before compaction" });
|
|
14091
|
+
api.registerHook("before_reset", async (event) => {
|
|
14092
|
+
const ctx = event.context ?? {};
|
|
14077
14093
|
logger.debug("cohort-sync: hook: before_reset", { ctx: dumpCtx(ctx), event: dumpEvent(event) });
|
|
14078
14094
|
const agentId = ctx.agentId ?? "main";
|
|
14079
14095
|
const agentName = resolveAgentName(agentId);
|
|
14080
14096
|
try {
|
|
14081
14097
|
const entry = buildActivityEntry(agentName, "before_reset", {
|
|
14082
|
-
reason:
|
|
14098
|
+
reason: ctx.reason,
|
|
14083
14099
|
sessionKey: ctx.sessionKey
|
|
14084
14100
|
});
|
|
14085
14101
|
if (entry) activityBatch.add(entry);
|
|
14086
14102
|
} catch (err) {
|
|
14087
14103
|
logger.warn(`cohort-sync: before_reset activity failed: ${String(err)}`);
|
|
14088
14104
|
}
|
|
14089
|
-
});
|
|
14090
|
-
api.
|
|
14105
|
+
}, { name: "cohort-sync.before_reset", description: "Emit activity entry before reset" });
|
|
14106
|
+
api.registerHook("gateway_stop", async () => {
|
|
14091
14107
|
logger.debug("cohort-sync: hook: gateway_stop", { bridgeState: Object.fromEntries(getChannelAgentBridge()) });
|
|
14092
14108
|
if (keepaliveInterval) {
|
|
14093
14109
|
clearInterval(keepaliveInterval);
|
|
@@ -14121,7 +14137,7 @@ function registerHooks(api, cfg) {
|
|
|
14121
14137
|
tracker2.clear();
|
|
14122
14138
|
closeBridge();
|
|
14123
14139
|
logger.info("cohort-sync: gateway stopped, all resources cleaned up");
|
|
14124
|
-
});
|
|
14140
|
+
}, { name: "cohort-sync.gateway_stop", description: "Cleanup, final telemetry, mark unreachable" });
|
|
14125
14141
|
}
|
|
14126
14142
|
|
|
14127
14143
|
// index.ts
|
package/dist/package.json
CHANGED
package/package.json
CHANGED