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.
This commit is contained in:
Danny Avila 2026-03-11 22:35:52 -04:00
parent 07f1998109
commit 1bfc9bfa3a
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956

View file

@ -329,9 +329,6 @@ class AgentClient extends BaseClient {
const sharedRunContext = sharedRunContextParts.join('\n\n');
/** @type {Record<string, number> | 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 {