mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:21:23 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -51,12 +51,16 @@ type ChatMessage = {
|
||||
|
||||
function stripExistingContext(text: string) {
|
||||
const index = text.indexOf(REMINDER_CONTEXT_MARKER);
|
||||
if (index === -1) return text;
|
||||
if (index === -1) {
|
||||
return text;
|
||||
}
|
||||
return text.slice(0, index).trim();
|
||||
}
|
||||
|
||||
function truncateText(input: string, maxLen: number) {
|
||||
if (input.length <= maxLen) return input;
|
||||
if (input.length <= maxLen) {
|
||||
return input;
|
||||
}
|
||||
const truncated = truncateUtf16Safe(input, Math.max(0, maxLen - 3)).trimEnd();
|
||||
return `${truncated}...`;
|
||||
}
|
||||
@@ -67,17 +71,25 @@ function normalizeContextText(raw: string) {
|
||||
|
||||
function extractMessageText(message: ChatMessage): { role: string; text: string } | null {
|
||||
const role = typeof message.role === "string" ? message.role : "";
|
||||
if (role !== "user" && role !== "assistant") return null;
|
||||
if (role !== "user" && role !== "assistant") {
|
||||
return null;
|
||||
}
|
||||
const content = message.content;
|
||||
if (typeof content === "string") {
|
||||
const normalized = normalizeContextText(content);
|
||||
return normalized ? { role, text: normalized } : null;
|
||||
}
|
||||
if (!Array.isArray(content)) return null;
|
||||
if (!Array.isArray(content)) {
|
||||
return null;
|
||||
}
|
||||
const chunks: string[] = [];
|
||||
for (const block of content) {
|
||||
if (!block || typeof block !== "object") continue;
|
||||
if ((block as { type?: unknown }).type !== "text") continue;
|
||||
if (!block || typeof block !== "object") {
|
||||
continue;
|
||||
}
|
||||
if ((block as { type?: unknown }).type !== "text") {
|
||||
continue;
|
||||
}
|
||||
const text = (block as { text?: unknown }).text;
|
||||
if (typeof text === "string" && text.trim()) {
|
||||
chunks.push(text);
|
||||
@@ -96,9 +108,13 @@ async function buildReminderContextLines(params: {
|
||||
REMINDER_CONTEXT_MESSAGES_MAX,
|
||||
Math.max(0, Math.floor(params.contextMessages)),
|
||||
);
|
||||
if (maxMessages <= 0) return [];
|
||||
if (maxMessages <= 0) {
|
||||
return [];
|
||||
}
|
||||
const sessionKey = params.agentSessionKey?.trim();
|
||||
if (!sessionKey) return [];
|
||||
if (!sessionKey) {
|
||||
return [];
|
||||
}
|
||||
const cfg = loadConfig();
|
||||
const { mainKey, alias } = resolveMainSessionAlias(cfg);
|
||||
const resolvedKey = resolveInternalSessionKey({ key: sessionKey, alias, mainKey });
|
||||
@@ -112,7 +128,9 @@ async function buildReminderContextLines(params: {
|
||||
.map((msg) => extractMessageText(msg as ChatMessage))
|
||||
.filter((msg): msg is { role: string; text: string } => Boolean(msg));
|
||||
const recent = parsed.slice(-maxMessages);
|
||||
if (recent.length === 0) return [];
|
||||
if (recent.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const lines: string[] = [];
|
||||
let total = 0;
|
||||
for (const entry of recent) {
|
||||
@@ -120,7 +138,9 @@ async function buildReminderContextLines(params: {
|
||||
const text = truncateText(entry.text, REMINDER_CONTEXT_PER_MESSAGE_MAX);
|
||||
const line = `- ${label}: ${text}`;
|
||||
total += line.length;
|
||||
if (total > REMINDER_CONTEXT_TOTAL_MAX) break;
|
||||
if (total > REMINDER_CONTEXT_TOTAL_MAX) {
|
||||
break;
|
||||
}
|
||||
lines.push(line);
|
||||
}
|
||||
return lines;
|
||||
|
||||
Reference in New Issue
Block a user