From a8c30624faaf2b337b3ce23dc7878cf9730addba 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 2b649ec96d..4bb5c21a89 100644 --- a/api/server/controllers/agents/client.js +++ b/api/server/controllers/agents/client.js @@ -328,9 +328,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; @@ -343,7 +340,6 @@ class AgentClient extends BaseClient { } const result = { - tokenCountMap, prompt: payload, promptTokens, messages, @@ -905,14 +901,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 {