@cfio/cohort-sync 0.2.2 → 0.2.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
@@ -12766,6 +12766,18 @@ function registerHooks(api, cfg) {
12766
12766
  if (m && typeof m === "object" && "primary" in m) return String(m.primary);
12767
12767
  return "unknown";
12768
12768
  }
12769
+ function getModelContextLimit(model) {
12770
+ const m = model.toLowerCase();
12771
+ if (m.includes("opus") || m.includes("sonnet") || m.includes("haiku")) return 2e5;
12772
+ if (m.includes("gpt-4o")) return 128e3;
12773
+ if (m.includes("gpt-4-turbo") || m.includes("gpt-4-1")) return 128e3;
12774
+ if (m.includes("gpt-4")) return 8192;
12775
+ if (m.includes("o3") || m.includes("o4-mini")) return 2e5;
12776
+ if (m.includes("gemini-2")) return 1e6;
12777
+ if (m.includes("gemini")) return 128e3;
12778
+ if (m.includes("deepseek")) return 128e3;
12779
+ return 2e5;
12780
+ }
12769
12781
  async function pushHeartbeat() {
12770
12782
  const allAgentIds = ["main", ...(config?.agents?.list ?? []).map((a) => a.id)];
12771
12783
  for (const agentId of allAgentIds) {
@@ -12891,19 +12903,30 @@ function registerHooks(api, cfg) {
12891
12903
  }
12892
12904
  });
12893
12905
  api.on("llm_output", async (event, ctx) => {
12894
- diag("HOOK_llm_output", { ctx: dumpCtx(ctx), model: event.model, tokensIn: event.usage?.input, tokensOut: event.usage?.output });
12906
+ const usage = event.usage ?? {};
12907
+ const contextTokens = (usage.input ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
12908
+ const model = event.model ?? resolveModel(ctx.agentId ?? "main");
12909
+ const contextLimit = getModelContextLimit(model);
12910
+ diag("HOOK_llm_output", {
12911
+ ctx: dumpCtx(ctx),
12912
+ model,
12913
+ tokensIn: usage.input,
12914
+ tokensOut: usage.output,
12915
+ cacheRead: usage.cacheRead,
12916
+ cacheWrite: usage.cacheWrite,
12917
+ contextTokens,
12918
+ contextLimit
12919
+ });
12895
12920
  const agentId = ctx.agentId ?? "main";
12896
12921
  const agentName = resolveAgentName(agentId);
12897
12922
  try {
12898
- const usage = event.usage ?? {};
12899
- const ext = event;
12900
12923
  const sessionKey = ctx.sessionKey;
12901
12924
  tracker.updateFromLlmOutput(agentName, sessionKey, {
12902
- model: event.model ?? resolveModel(agentId),
12925
+ model,
12903
12926
  tokensIn: usage.input ?? 0,
12904
12927
  tokensOut: usage.output ?? 0,
12905
- contextTokens: ext.contextTokens ?? usage.total ?? 0,
12906
- contextLimit: ext.contextLimit ?? 0
12928
+ contextTokens,
12929
+ contextLimit
12907
12930
  });
12908
12931
  if (sessionKey && !tracker.hasSession(agentName, sessionKey)) {
12909
12932
  tracker.addSession(agentName, sessionKey);
@@ -12933,10 +12956,9 @@ function registerHooks(api, cfg) {
12933
12956
  const agentId = ctx.agentId ?? "main";
12934
12957
  const agentName = resolveAgentName(agentId);
12935
12958
  try {
12936
- const ext = event;
12937
12959
  tracker.updateFromCompaction(agentName, {
12938
- contextTokens: ext.contextTokens ?? event.tokenCount ?? 0,
12939
- contextLimit: ext.contextLimit ?? 0
12960
+ contextTokens: event.tokenCount ?? 0,
12961
+ contextLimit: getModelContextLimit(resolveModel(agentId))
12940
12962
  });
12941
12963
  if (tracker.shouldPushTelemetry(agentName)) {
12942
12964
  const snapshot = tracker.getTelemetrySnapshot(agentName);
@@ -12947,7 +12969,7 @@ function registerHooks(api, cfg) {
12947
12969
  }
12948
12970
  const entry = buildActivityEntry(agentName, "after_compaction", {
12949
12971
  messageCount: event.messageCount,
12950
- compactedCount: ext.compactedCount ?? event.compactedCount,
12972
+ compactedCount: event.compactedCount,
12951
12973
  sessionKey: ctx.sessionKey
12952
12974
  });
12953
12975
  if (entry) addActivityToHot(entry);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Syncs agent status and skills to 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.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Syncs agent status and skills to Cohort dashboard",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.cohort.bot/gateway",