mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 03:32:43 +00:00
refactor(core): share JSON utf8 byte counting helper
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user