mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 14:35:00 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -41,81 +41,55 @@ export type EffectiveContextPruningSettings = {
|
||||
};
|
||||
};
|
||||
|
||||
export const DEFAULT_CONTEXT_PRUNING_SETTINGS: EffectiveContextPruningSettings =
|
||||
{
|
||||
mode: "adaptive",
|
||||
keepLastAssistants: 3,
|
||||
softTrimRatio: 0.3,
|
||||
hardClearRatio: 0.5,
|
||||
minPrunableToolChars: 50_000,
|
||||
tools: {},
|
||||
softTrim: {
|
||||
maxChars: 4_000,
|
||||
headChars: 1_500,
|
||||
tailChars: 1_500,
|
||||
},
|
||||
hardClear: {
|
||||
enabled: true,
|
||||
placeholder: "[Old tool result content cleared]",
|
||||
},
|
||||
};
|
||||
export const DEFAULT_CONTEXT_PRUNING_SETTINGS: EffectiveContextPruningSettings = {
|
||||
mode: "adaptive",
|
||||
keepLastAssistants: 3,
|
||||
softTrimRatio: 0.3,
|
||||
hardClearRatio: 0.5,
|
||||
minPrunableToolChars: 50_000,
|
||||
tools: {},
|
||||
softTrim: {
|
||||
maxChars: 4_000,
|
||||
headChars: 1_500,
|
||||
tailChars: 1_500,
|
||||
},
|
||||
hardClear: {
|
||||
enabled: true,
|
||||
placeholder: "[Old tool result content cleared]",
|
||||
},
|
||||
};
|
||||
|
||||
export function computeEffectiveSettings(
|
||||
raw: unknown,
|
||||
): EffectiveContextPruningSettings | null {
|
||||
export function computeEffectiveSettings(raw: unknown): EffectiveContextPruningSettings | null {
|
||||
if (!raw || typeof raw !== "object") return null;
|
||||
const cfg = raw as ContextPruningConfig;
|
||||
if (cfg.mode !== "adaptive" && cfg.mode !== "aggressive") return null;
|
||||
|
||||
const s: EffectiveContextPruningSettings = structuredClone(
|
||||
DEFAULT_CONTEXT_PRUNING_SETTINGS,
|
||||
);
|
||||
const s: EffectiveContextPruningSettings = structuredClone(DEFAULT_CONTEXT_PRUNING_SETTINGS);
|
||||
s.mode = cfg.mode;
|
||||
|
||||
if (
|
||||
typeof cfg.keepLastAssistants === "number" &&
|
||||
Number.isFinite(cfg.keepLastAssistants)
|
||||
) {
|
||||
if (typeof cfg.keepLastAssistants === "number" && Number.isFinite(cfg.keepLastAssistants)) {
|
||||
s.keepLastAssistants = Math.max(0, Math.floor(cfg.keepLastAssistants));
|
||||
}
|
||||
if (
|
||||
typeof cfg.softTrimRatio === "number" &&
|
||||
Number.isFinite(cfg.softTrimRatio)
|
||||
) {
|
||||
if (typeof cfg.softTrimRatio === "number" && Number.isFinite(cfg.softTrimRatio)) {
|
||||
s.softTrimRatio = Math.min(1, Math.max(0, cfg.softTrimRatio));
|
||||
}
|
||||
if (
|
||||
typeof cfg.hardClearRatio === "number" &&
|
||||
Number.isFinite(cfg.hardClearRatio)
|
||||
) {
|
||||
if (typeof cfg.hardClearRatio === "number" && Number.isFinite(cfg.hardClearRatio)) {
|
||||
s.hardClearRatio = Math.min(1, Math.max(0, cfg.hardClearRatio));
|
||||
}
|
||||
if (
|
||||
typeof cfg.minPrunableToolChars === "number" &&
|
||||
Number.isFinite(cfg.minPrunableToolChars)
|
||||
) {
|
||||
if (typeof cfg.minPrunableToolChars === "number" && Number.isFinite(cfg.minPrunableToolChars)) {
|
||||
s.minPrunableToolChars = Math.max(0, Math.floor(cfg.minPrunableToolChars));
|
||||
}
|
||||
if (cfg.tools) {
|
||||
s.tools = cfg.tools;
|
||||
}
|
||||
if (cfg.softTrim) {
|
||||
if (
|
||||
typeof cfg.softTrim.maxChars === "number" &&
|
||||
Number.isFinite(cfg.softTrim.maxChars)
|
||||
) {
|
||||
if (typeof cfg.softTrim.maxChars === "number" && Number.isFinite(cfg.softTrim.maxChars)) {
|
||||
s.softTrim.maxChars = Math.max(0, Math.floor(cfg.softTrim.maxChars));
|
||||
}
|
||||
if (
|
||||
typeof cfg.softTrim.headChars === "number" &&
|
||||
Number.isFinite(cfg.softTrim.headChars)
|
||||
) {
|
||||
if (typeof cfg.softTrim.headChars === "number" && Number.isFinite(cfg.softTrim.headChars)) {
|
||||
s.softTrim.headChars = Math.max(0, Math.floor(cfg.softTrim.headChars));
|
||||
}
|
||||
if (
|
||||
typeof cfg.softTrim.tailChars === "number" &&
|
||||
Number.isFinite(cfg.softTrim.tailChars)
|
||||
) {
|
||||
if (typeof cfg.softTrim.tailChars === "number" && Number.isFinite(cfg.softTrim.tailChars)) {
|
||||
s.softTrim.tailChars = Math.max(0, Math.floor(cfg.softTrim.tailChars));
|
||||
}
|
||||
}
|
||||
@@ -123,10 +97,7 @@ export function computeEffectiveSettings(
|
||||
if (s.mode === "adaptive" && typeof cfg.hardClear.enabled === "boolean") {
|
||||
s.hardClear.enabled = cfg.hardClear.enabled;
|
||||
}
|
||||
if (
|
||||
typeof cfg.hardClear.placeholder === "string" &&
|
||||
cfg.hardClear.placeholder.trim()
|
||||
) {
|
||||
if (typeof cfg.hardClear.placeholder === "string" && cfg.hardClear.placeholder.trim()) {
|
||||
s.hardClear.placeholder = cfg.hardClear.placeholder.trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user