From 1bfc9bfa3a9c2a206aaa964bb084dea3b5fb10a3 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Wed, 11 Mar 2026 22:35:52 -0400 Subject: [PATCH] refactor(agents): remove unused tokenCountMap and streamline calibration ratio handling Eliminated the unused tokenCountMap variable from the AgentClient class to enhance code clarity. Additionally, streamlined the logic for capturing the calibration ratio by using optional chaining and a fallback value, ensuring that context metadata is consistently defined. This change improves maintainability and reduces potential confusion in the codebase. --- api/server/controllers/agents/client.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.js index 80ae2cf916..f44d01ca79 100644 --- a/api/server/controllers/agents/client.js +++ b/api/server/controllers/agents/client.js @@ -329,9 +329,6 @@ class AgentClient extends BaseClient { const sharedRunContext = sharedRunContextParts.join('\n\n'); - /** @type {Record | undefined} */ - let tokenCountMap; - /** Preserve canonical pre-format token counts for all history entering graph formatting */ this.indexTokenCountMap = canonicalTokenCountMap; @@ -344,7 +341,6 @@ class AgentClient extends BaseClient { } const result = { - tokenCountMap, prompt: payload, promptTokens, messages, @@ -907,14 +903,14 @@ class AgentClient extends BaseClient { } finally { /** Capture calibration ratio from the run for persistence on the response message. * Runs in finally so the ratio is captured even on abort. */ - if (this.run) { - const ratio = this.run.getCalibrationRatio(); - if (ratio > 0 && ratio !== 1) { - this.contextMeta = { - calibrationRatio: Math.round(ratio * 1000) / 1000, - encoding: this.getEncoding(), - }; - } + const ratio = this.run?.getCalibrationRatio() ?? 0; + if (ratio > 0 && ratio !== 1) { + this.contextMeta = { + calibrationRatio: Math.round(ratio * 1000) / 1000, + encoding: this.getEncoding(), + }; + } else { + this.contextMeta = undefined; } try {