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

@@ -9,6 +9,7 @@ import { createReplyDispatcher } from "../../auto-reply/reply/reply-dispatcher.j
import type { MsgContext } from "../../auto-reply/templating.js";
import { createReplyPrefixOptions } from "../../channels/reply-prefix.js";
import { resolveSessionFilePath } from "../../config/sessions.js";
import { jsonUtf8Bytes } from "../../infra/json-utf8-bytes.js";
import { resolveSendPolicy } from "../../sessions/send-policy.js";
import {
stripInlineDirectiveTagsForDisplay,
@@ -198,14 +199,6 @@ function sanitizeChatHistoryMessages(messages: unknown[]): unknown[] {
return changed ? next : messages;
}
function jsonUtf8Bytes(value: unknown): number {
try {
return Buffer.byteLength(JSON.stringify(value), "utf8");
} catch {
return Buffer.byteLength(String(value), "utf8");
}
}
function buildOversizedHistoryPlaceholder(message?: unknown): Record<string, unknown> {
const role =
message &&