replicas-engine 0.1.967 → 0.1.968

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.
@@ -5,9 +5,9 @@ import {
5
5
  getCodexAspHost,
6
6
  restartCodexAspHost,
7
7
  restartCodexAspHostIfRunning
8
- } from "./chunk-YIKQKQQI.js";
8
+ } from "./chunk-SLSO3XNE.js";
9
9
  import "./chunk-JH2UMGOT.js";
10
- import "./chunk-DMGFNUGG.js";
10
+ import "./chunk-2HETYYXG.js";
11
11
  import "./chunk-EUMRQH4J.js";
12
12
  import "./chunk-UZSNFLDQ.js";
13
13
  import "./chunk-4KMPRAV6.js";
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
240
240
  if (method === "foundry") return "azure";
241
241
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
242
242
  }
243
- var ENGINE_PACKAGE_VERSION = "0.1.967";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.968";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  AppServerProcess,
11
11
  buildCodexAgentEnv
12
- } from "./chunk-DMGFNUGG.js";
12
+ } from "./chunk-2HETYYXG.js";
13
13
  import {
14
14
  SUBPROCESS_MAX_BUFFER,
15
15
  execFileAsync
@@ -260,7 +260,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
260
260
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
261
261
  await this.applyCredentialsResponse(data);
262
262
  setAgentCredentialSnapshot("codex", data);
263
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-JUJJHJWJ.js");
263
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-5T7UXG2T.js");
264
264
  await restartCodexAspHostIfRunning2();
265
265
  });
266
266
  await this.start(true);
@@ -280,7 +280,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
280
280
  await this.applyCredentialUpdate(generation, async () => {
281
281
  await this.applyCredentialsResponse(data);
282
282
  if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
283
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-JUJJHJWJ.js");
283
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-5T7UXG2T.js");
284
284
  await restartCodexAspHostIfRunning2();
285
285
  }
286
286
  setAgentCredentialSnapshot("codex", data);
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  AppServerProcess,
9
9
  buildCodexAgentEnv
10
- } from "./chunk-DMGFNUGG.js";
10
+ } from "./chunk-2HETYYXG.js";
11
11
  import "./chunk-EUMRQH4J.js";
12
12
  import {
13
13
  AGENT,
package/dist/src/index.js CHANGED
@@ -71,7 +71,7 @@ import {
71
71
  refreshDelayMs,
72
72
  restartCodexAspHost,
73
73
  routineRefreshExclusions
74
- } from "./chunk-YIKQKQQI.js";
74
+ } from "./chunk-SLSO3XNE.js";
75
75
  import {
76
76
  ENGINE_ENV,
77
77
  monolithRequest,
@@ -83,7 +83,7 @@ import {
83
83
  import {
84
84
  AspClient,
85
85
  getCodexModelProvider
86
- } from "./chunk-DMGFNUGG.js";
86
+ } from "./chunk-2HETYYXG.js";
87
87
  import {
88
88
  SUBPROCESS_MAX_BUFFER,
89
89
  execAsync,
@@ -59384,9 +59384,10 @@ function parseCodexUsage(value) {
59384
59384
  function parseCodexUsageUpdate(value) {
59385
59385
  if (!isRecord(value)) return void 0;
59386
59386
  const turn = parseCodexTurn(value);
59387
- const usage = isRecord(value.tokenUsage) ? parseCodexUsage(value.tokenUsage.last) : void 0;
59388
- if (!turn || !usage) return void 0;
59389
- return { ...turn, usage };
59387
+ if (!turn || !isRecord(value.tokenUsage)) return void 0;
59388
+ const total = parseCodexUsage(value.tokenUsage.total);
59389
+ const last = parseCodexUsage(value.tokenUsage.last);
59390
+ return total && last ? { ...turn, total, last } : void 0;
59390
59391
  }
59391
59392
  function parseCodexModelReroute(value) {
59392
59393
  if (!isRecord(value) || !isNonEmptyString(value.toModel)) return void 0;
@@ -59445,11 +59446,20 @@ var CodexTokenUsageAdapter = class {
59445
59446
  });
59446
59447
  };
59447
59448
  };
59449
+ function toCumulativeCounts(usage) {
59450
+ return {
59451
+ inputTokens: usage.inputTokens,
59452
+ outputTokens: usage.outputTokens,
59453
+ cacheReadInputTokens: usage.cachedInputTokens,
59454
+ cacheWriteInputTokens: usage.cacheWriteInputTokens ?? 0
59455
+ };
59456
+ }
59448
59457
  function getTurnKey({ threadId, turnId }) {
59449
59458
  return `${threadId}\0${turnId}`;
59450
59459
  }
59451
59460
  var CodexTokenUsageService = class {
59452
59461
  turns = /* @__PURE__ */ new Map();
59462
+ threadTotals = /* @__PURE__ */ new Map();
59453
59463
  record(event) {
59454
59464
  switch (event.type) {
59455
59465
  case "turn-started": {
@@ -59466,11 +59476,15 @@ var CodexTokenUsageService = class {
59466
59476
  if (!update) return void 0;
59467
59477
  const key = getTurnKey(update);
59468
59478
  const turn = this.turns.get(key) ?? {
59469
- ...update,
59479
+ threadId: update.threadId,
59480
+ turnId: update.turnId,
59470
59481
  context: event.context
59471
59482
  };
59472
- turn.latestUsage = update.usage;
59483
+ const total = toCumulativeCounts(update.total);
59484
+ turn.baselineTotal ??= this.threadTotals.get(update.threadId) ?? calculateCumulativeTokenUsageDelta(total, toCumulativeCounts(update.last));
59485
+ turn.latestTotal = total;
59473
59486
  turn.occurredAt = event.occurredAt;
59487
+ this.threadTotals.set(update.threadId, total);
59474
59488
  this.turns.set(key, turn);
59475
59489
  return void 0;
59476
59490
  }
@@ -59501,19 +59515,17 @@ var CodexTokenUsageService = class {
59501
59515
  const tracked = this.turns.get(key);
59502
59516
  if (!tracked || tracked.context.chatId !== chatId) return void 0;
59503
59517
  this.turns.delete(key);
59504
- if (!tracked.latestUsage || !tracked.occurredAt) return void 0;
59505
- const cacheWriteInputTokens = tracked.latestUsage.cacheWriteInputTokens ?? 0;
59518
+ if (!tracked.baselineTotal || !tracked.latestTotal || !tracked.occurredAt) return void 0;
59519
+ const delta = calculateCumulativeTokenUsageDelta(tracked.latestTotal, tracked.baselineTotal);
59520
+ if (!Object.values(delta).some((count) => count > 0)) return void 0;
59506
59521
  return {
59507
59522
  records: [{
59508
59523
  ...tracked.context,
59509
59524
  harness: AGENT.CODEX,
59510
- inputTokens: Math.max(
59511
- 0,
59512
- tracked.latestUsage.inputTokens - tracked.latestUsage.cachedInputTokens - cacheWriteInputTokens
59513
- ),
59514
- outputTokens: tracked.latestUsage.outputTokens,
59515
- cacheReadInputTokens: tracked.latestUsage.cachedInputTokens,
59516
- cacheWriteInputTokens,
59525
+ inputTokens: Math.max(0, delta.inputTokens - delta.cacheReadInputTokens - delta.cacheWriteInputTokens),
59526
+ outputTokens: delta.outputTokens,
59527
+ cacheReadInputTokens: delta.cacheReadInputTokens,
59528
+ cacheWriteInputTokens: delta.cacheWriteInputTokens,
59517
59529
  occurredAt: tracked.occurredAt
59518
59530
  }]
59519
59531
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.967",
3
+ "version": "0.1.968",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",