refactor(core): share JSON utf8 byte counting helper

This commit is contained in:
Peter Steinberger
2026-03-02 05:19:30 +00:00
parent 4a1be98254
commit 264599cc1d
5 changed files with 26 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ import { Type } from "@sinclair/typebox";
import { loadConfig } from "../../config/config.js";
import { callGateway } from "../../gateway/call.js";
import { capArrayByJsonBytes } from "../../gateway/session-utils.fs.js";
import { jsonUtf8Bytes } from "../../infra/json-utf8-bytes.js";
import { redactSensitiveText } from "../../logging/redact.js";
import { truncateUtf16Safe } from "../../utils.js";
import type { AnyAgentTool } from "./common.js";
@@ -140,14 +141,6 @@ function sanitizeHistoryMessage(message: unknown): {
return { message: entry, truncated, redacted };
}
function jsonUtf8Bytes(value: unknown): number {
try {
return Buffer.byteLength(JSON.stringify(value), "utf8");
} catch {
return Buffer.byteLength(String(value), "utf8");
}
}
function enforceSessionsHistoryHardCap(params: {
items: unknown[];
bytes: number;