@cfio/cohort-sync 0.12.1 → 0.13.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
@@ -13110,6 +13110,9 @@ var AgentStateTracker = class {
13110
13110
  contextTokens: 0,
13111
13111
  contextLimit: 0,
13112
13112
  compactions: 0,
13113
+ cacheReadTokens: 0,
13114
+ cacheWriteTokens: 0,
13115
+ lastSessionKey: void 0,
13113
13116
  sessions: /* @__PURE__ */ new Map(),
13114
13117
  lastPushedTelemetry: null,
13115
13118
  lastPushedSessions: null
@@ -13170,6 +13173,8 @@ var AgentStateTracker = class {
13170
13173
  if (data.model) state.model = data.model;
13171
13174
  if (data.tokensIn !== void 0) state.tokensIn += data.tokensIn;
13172
13175
  if (data.tokensOut !== void 0) state.tokensOut += data.tokensOut;
13176
+ if (data.cacheReadTokens !== void 0) state.cacheReadTokens += data.cacheReadTokens;
13177
+ if (data.cacheWriteTokens !== void 0) state.cacheWriteTokens += data.cacheWriteTokens;
13173
13178
  if (data.contextTokens !== void 0) state.contextTokens = data.contextTokens;
13174
13179
  if (data.contextLimit !== void 0) state.contextLimit = data.contextLimit;
13175
13180
  state.status = "working";
@@ -13183,6 +13188,15 @@ var AgentStateTracker = class {
13183
13188
  }
13184
13189
  }
13185
13190
  }
13191
+ /**
13192
+ * Set the last-observed session key for cost attribution. The server extracts
13193
+ * the Cohort task number from this key. Called from the llm_output hook.
13194
+ */
13195
+ updateSessionKey(agentName, sessionKey) {
13196
+ if (!sessionKey) return;
13197
+ const state = this.getOrCreate(agentName);
13198
+ state.lastSessionKey = sessionKey;
13199
+ }
13186
13200
  updateFromCompaction(agentName, data) {
13187
13201
  const state = this.getOrCreate(agentName);
13188
13202
  state.compactions += 1;
@@ -13205,7 +13219,10 @@ var AgentStateTracker = class {
13205
13219
  tokensIn: state.tokensIn,
13206
13220
  tokensOut: state.tokensOut,
13207
13221
  compactions: state.compactions,
13208
- activeSessions: state.sessions.size
13222
+ activeSessions: state.sessions.size,
13223
+ cacheReadTokens: state.cacheReadTokens,
13224
+ cacheWriteTokens: state.cacheWriteTokens,
13225
+ sessionKey: state.lastSessionKey
13209
13226
  };
13210
13227
  }
13211
13228
  getSessionsSnapshot(agentName) {
@@ -13353,7 +13370,7 @@ function dumpCtx(ctx) {
13353
13370
  function dumpEvent(event) {
13354
13371
  return dumpCtx(event);
13355
13372
  }
13356
- var PLUGIN_VERSION = true ? "0.12.1" : "unknown";
13373
+ var PLUGIN_VERSION = true ? "0.13.0" : "unknown";
13357
13374
  function resolveGatewayToken(api) {
13358
13375
  const token = api.config?.gateway?.auth?.token;
13359
13376
  return typeof token === "string" ? token : null;
@@ -13697,9 +13714,12 @@ function registerHookHandlers(api, logger, getState) {
13697
13714
  model,
13698
13715
  tokensIn: usage.input ?? 0,
13699
13716
  tokensOut: usage.output ?? 0,
13717
+ cacheReadTokens: usage.cacheRead ?? 0,
13718
+ cacheWriteTokens: usage.cacheWrite ?? 0,
13700
13719
  contextTokens,
13701
13720
  contextLimit
13702
13721
  });
13722
+ tracker.updateSessionKey(agentName, sessionKey);
13703
13723
  if (sessionKey && !tracker.hasSession(agentName, sessionKey)) {
13704
13724
  tracker.addSession(agentName, sessionKey);
13705
13725
  log.info(`cohort-sync: inferred session for ${agentName} from llm_output (${sessionKey})`);
@@ -55,5 +55,5 @@
55
55
  }
56
56
  }
57
57
  },
58
- "version": "0.12.1"
58
+ "version": "0.13.0"
59
59
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.12.1",
3
+ "version": "0.13.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.12.1",
3
+ "version": "0.13.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",
@@ -24,6 +24,7 @@
24
24
  "postinstall": "node scripts/postinstall.mjs",
25
25
  "prepublishOnly": "node scripts/build.mjs",
26
26
  "typecheck": "echo 'Skipped: openclaw types loosely pinned, build uses esbuild not tsc'",
27
+ "pretest": "node scripts/build.mjs",
27
28
  "test": "vitest run"
28
29
  },
29
30
  "files": [