negotium 0.21.2 → 0.21.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.
@@ -5199,7 +5199,7 @@ var init_codex = __esm(async () => {
5199
5199
  });
5200
5200
 
5201
5201
  // ../../packages/core/src/version.ts
5202
- var NEGOTIUM_VERSION = "0.21.2";
5202
+ var NEGOTIUM_VERSION = "0.21.3";
5203
5203
 
5204
5204
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
5205
5205
  import { spawn as spawn2 } from "child_process";
@@ -13940,6 +13940,30 @@ function isQueryRecord(value) {
13940
13940
  const record = value;
13941
13941
  return record.schemaVersion === 2 && typeof record.timestamp === "string" && typeof record.session === "string" && typeof record.topicId === "string" && typeof record.agent === "string" && typeof record.model === "string" && typeof record.inputTokens === "number" && typeof record.outputTokens === "number" && typeof record.cacheCreationInputTokens === "number" && typeof record.cacheReadInputTokens === "number" && typeof record.estimatedCostUsd === "number";
13942
13942
  }
13943
+ function previousCumulativeCost(userId, providerSessionId) {
13944
+ let lines;
13945
+ try {
13946
+ lines = readJsonlLines(queriesPath(userId));
13947
+ } catch {
13948
+ return 0;
13949
+ }
13950
+ for (let i = lines.length - 1;i >= 0; i--) {
13951
+ let parsed;
13952
+ try {
13953
+ parsed = JSON.parse(lines[i]);
13954
+ } catch {
13955
+ continue;
13956
+ }
13957
+ if (parsed.providerSessionId !== providerSessionId)
13958
+ continue;
13959
+ if (typeof parsed.cumulativeCostUsd === "number")
13960
+ return parsed.cumulativeCostUsd;
13961
+ if (typeof parsed.estimatedCostUsd === "number")
13962
+ return parsed.estimatedCostUsd;
13963
+ return 0;
13964
+ }
13965
+ return 0;
13966
+ }
13943
13967
  function recordUsage(userId, session, usage, context) {
13944
13968
  const cacheReadInputTokens = usage.cacheReadInputTokens ?? 0;
13945
13969
  const inputTokens = context.agent === "claude" ? usage.inputTokens : Math.max(0, usage.inputTokens - cacheReadInputTokens);
@@ -13949,6 +13973,15 @@ function recordUsage(userId, session, usage, context) {
13949
13973
  cacheCreationInputTokens: usage.cacheCreationInputTokens ?? 0,
13950
13974
  cacheReadInputTokens
13951
13975
  };
13976
+ let estimatedCostUsd;
13977
+ let cumulativeCostUsd;
13978
+ if (usage.costUsd !== undefined) {
13979
+ const previous = context.providerSessionId ? previousCumulativeCost(userId, context.providerSessionId) : 0;
13980
+ estimatedCostUsd = Math.max(0, usage.costUsd - previous);
13981
+ cumulativeCostUsd = usage.costUsd;
13982
+ } else {
13983
+ estimatedCostUsd = estimateUsageCost(context.agent, context.model, normalized);
13984
+ }
13952
13985
  const record = {
13953
13986
  schemaVersion: 2,
13954
13987
  timestamp: new Date().toISOString(),
@@ -13960,7 +13993,8 @@ function recordUsage(userId, session, usage, context) {
13960
13993
  ...normalized,
13961
13994
  ...usage.contextTokens !== undefined ? { contextTokens: usage.contextTokens } : {},
13962
13995
  ...usage.contextWindow !== undefined ? { contextWindow: usage.contextWindow } : {},
13963
- estimatedCostUsd: usage.costUsd ?? estimateUsageCost(context.agent, context.model, normalized)
13996
+ estimatedCostUsd,
13997
+ ...cumulativeCostUsd !== undefined ? { cumulativeCostUsd } : {}
13964
13998
  };
13965
13999
  try {
13966
14000
  appendJsonlEntry(queriesPath(userId), record);
@@ -22793,4 +22827,4 @@ export {
22793
22827
  DEFAULT_SELF_CONFIG_PRODUCT
22794
22828
  };
22795
22829
 
22796
- //# debugId=6956D5C85128E56E64756E2164756E21
22830
+ //# debugId=10C6EC28EC08FE1364756E2164756E21