mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 04:02:42 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -69,8 +69,6 @@ export function maybeSendAckReaction(params: {
|
||||
},
|
||||
"failed to send ack reaction",
|
||||
);
|
||||
logVerbose(
|
||||
`WhatsApp ack reaction failed for chat ${params.msg.chatId}: ${formatError(err)}`,
|
||||
);
|
||||
logVerbose(`WhatsApp ack reaction failed for chat ${params.msg.chatId}: ${formatError(err)}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,13 +33,9 @@ export async function maybeBroadcastMessage(params: {
|
||||
if (broadcastAgents.length === 0) return false;
|
||||
|
||||
const strategy = params.cfg.broadcast?.strategy || "parallel";
|
||||
whatsappInboundLog.info(
|
||||
`Broadcasting message to ${broadcastAgents.length} agents (${strategy})`,
|
||||
);
|
||||
whatsappInboundLog.info(`Broadcasting message to ${broadcastAgents.length} agents (${strategy})`);
|
||||
|
||||
const agentIds = params.cfg.agents?.list?.map((agent) =>
|
||||
normalizeAgentId(agent.id),
|
||||
);
|
||||
const agentIds = params.cfg.agents?.list?.map((agent) => normalizeAgentId(agent.id));
|
||||
const hasKnownAgents = (agentIds?.length ?? 0) > 0;
|
||||
const groupHistorySnapshot =
|
||||
params.msg.chatType === "group"
|
||||
@@ -49,9 +45,7 @@ export async function maybeBroadcastMessage(params: {
|
||||
const processForAgent = async (agentId: string): Promise<boolean> => {
|
||||
const normalizedAgentId = normalizeAgentId(agentId);
|
||||
if (hasKnownAgents && !agentIds?.includes(normalizedAgentId)) {
|
||||
whatsappInboundLog.warn(
|
||||
`Broadcast agent ${agentId} not found in agents.list; skipping`,
|
||||
);
|
||||
whatsappInboundLog.warn(`Broadcast agent ${agentId} not found in agents.list; skipping`);
|
||||
return false;
|
||||
}
|
||||
const agentRoute = {
|
||||
@@ -72,19 +66,12 @@ export async function maybeBroadcastMessage(params: {
|
||||
};
|
||||
|
||||
try {
|
||||
return await params.processMessage(
|
||||
params.msg,
|
||||
agentRoute,
|
||||
params.groupHistoryKey,
|
||||
{
|
||||
groupHistory: groupHistorySnapshot,
|
||||
suppressGroupHistoryClear: true,
|
||||
},
|
||||
);
|
||||
return await params.processMessage(params.msg, agentRoute, params.groupHistoryKey, {
|
||||
groupHistory: groupHistorySnapshot,
|
||||
suppressGroupHistoryClear: true,
|
||||
});
|
||||
} catch (err) {
|
||||
whatsappInboundLog.error(
|
||||
`Broadcast agent ${agentId} failed: ${formatError(err)}`,
|
||||
);
|
||||
whatsappInboundLog.error(`Broadcast agent ${agentId} failed: ${formatError(err)}`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -95,12 +82,8 @@ export async function maybeBroadcastMessage(params: {
|
||||
if (await processForAgent(agentId)) didSendReply = true;
|
||||
}
|
||||
} else {
|
||||
const results = await Promise.allSettled(
|
||||
broadcastAgents.map(processForAgent),
|
||||
);
|
||||
didSendReply = results.some(
|
||||
(result) => result.status === "fulfilled" && result.value,
|
||||
);
|
||||
const results = await Promise.allSettled(broadcastAgents.map(processForAgent));
|
||||
didSendReply = results.some((result) => result.status === "fulfilled" && result.value);
|
||||
}
|
||||
|
||||
if (params.msg.chatType === "group" && didSendReply) {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
export function isStatusCommand(body: string) {
|
||||
const trimmed = body.trim().toLowerCase();
|
||||
if (!trimmed) return false;
|
||||
return (
|
||||
trimmed === "/status" ||
|
||||
trimmed === "status" ||
|
||||
trimmed.startsWith("/status ")
|
||||
);
|
||||
return trimmed === "/status" || trimmed === "status" || trimmed.startsWith("/status ");
|
||||
}
|
||||
|
||||
export function stripMentionsForCommand(
|
||||
|
||||
@@ -9,10 +9,7 @@ export type EchoTracker = {
|
||||
) => void;
|
||||
has: (key: string) => boolean;
|
||||
forget: (key: string) => void;
|
||||
buildCombinedKey: (params: {
|
||||
sessionKey: string;
|
||||
combinedBody: string;
|
||||
}) => string;
|
||||
buildCombinedKey: (params: { sessionKey: string; combinedBody: string }) => string;
|
||||
};
|
||||
|
||||
export function createEchoTracker(params: {
|
||||
|
||||
@@ -10,10 +10,7 @@ import {
|
||||
resolveStorePath,
|
||||
} from "../../../config/sessions.js";
|
||||
|
||||
export function resolveGroupPolicyFor(
|
||||
cfg: ReturnType<typeof loadConfig>,
|
||||
conversationId: string,
|
||||
) {
|
||||
export function resolveGroupPolicyFor(cfg: ReturnType<typeof loadConfig>, conversationId: string) {
|
||||
const groupId = resolveGroupSessionKey({
|
||||
From: conversationId,
|
||||
ChatType: "group",
|
||||
@@ -53,10 +50,7 @@ export function resolveGroupActivationFor(params: {
|
||||
});
|
||||
const store = loadSessionStore(storePath);
|
||||
const entry = store[params.sessionKey];
|
||||
const requireMention = resolveGroupRequireMentionFor(
|
||||
params.cfg,
|
||||
params.conversationId,
|
||||
);
|
||||
const requireMention = resolveGroupRequireMentionFor(params.cfg, params.conversationId);
|
||||
const defaultActivation = requireMention === false ? "always" : "mention";
|
||||
return normalizeGroupActivation(entry?.groupActivation) ?? defaultActivation;
|
||||
}
|
||||
|
||||
@@ -2,17 +2,10 @@ import { parseActivationCommand } from "../../../auto-reply/group-activation.js"
|
||||
import type { loadConfig } from "../../../config/config.js";
|
||||
import { normalizeE164 } from "../../../utils.js";
|
||||
import type { MentionConfig } from "../mentions.js";
|
||||
import {
|
||||
buildMentionConfig,
|
||||
debugMention,
|
||||
resolveOwnerList,
|
||||
} from "../mentions.js";
|
||||
import { buildMentionConfig, debugMention, resolveOwnerList } from "../mentions.js";
|
||||
import type { WebInboundMsg } from "../types.js";
|
||||
import { isStatusCommand, stripMentionsForCommand } from "./commands.js";
|
||||
import {
|
||||
resolveGroupActivationFor,
|
||||
resolveGroupPolicyFor,
|
||||
} from "./group-activation.js";
|
||||
import { resolveGroupActivationFor, resolveGroupPolicyFor } from "./group-activation.js";
|
||||
import { noteGroupMember } from "./group-members.js";
|
||||
|
||||
export type GroupHistoryEntry = {
|
||||
@@ -47,9 +40,7 @@ export function applyGroupGating(params: {
|
||||
}) {
|
||||
const groupPolicy = resolveGroupPolicyFor(params.cfg, params.conversationId);
|
||||
if (groupPolicy.allowlistEnabled && !groupPolicy.allowed) {
|
||||
params.logVerbose(
|
||||
`Skipping group message ${params.conversationId} (not in allowlist)`,
|
||||
);
|
||||
params.logVerbose(`Skipping group message ${params.conversationId} (not in allowlist)`);
|
||||
return { shouldProcess: false };
|
||||
}
|
||||
|
||||
@@ -69,13 +60,10 @@ export function applyGroupGating(params: {
|
||||
const activationCommand = parseActivationCommand(commandBody);
|
||||
const owner = isOwnerSender(params.baseMentionConfig, params.msg);
|
||||
const statusCommand = isStatusCommand(commandBody);
|
||||
const shouldBypassMention =
|
||||
owner && (activationCommand.hasCommand || statusCommand);
|
||||
const shouldBypassMention = owner && (activationCommand.hasCommand || statusCommand);
|
||||
|
||||
if (activationCommand.hasCommand && !owner) {
|
||||
params.logVerbose(
|
||||
`Ignoring /activation from non-owner in group ${params.conversationId}`,
|
||||
);
|
||||
params.logVerbose(`Ignoring /activation from non-owner in group ${params.conversationId}`);
|
||||
return { shouldProcess: false };
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,7 @@ export function buildInboundLine(params: {
|
||||
});
|
||||
const prefixStr = messagePrefix ? `${messagePrefix} ` : "";
|
||||
const senderLabel =
|
||||
msg.chatType === "group"
|
||||
? `${msg.senderName ?? msg.senderE164 ?? "Someone"}: `
|
||||
: "";
|
||||
msg.chatType === "group" ? `${msg.senderName ?? msg.senderE164 ?? "Someone"}: ` : "";
|
||||
const replyContext = formatReplyContext(msg);
|
||||
const baseLine = `${prefixStr}${senderLabel}${msg.body}${
|
||||
replyContext ? `\n\n${replyContext}` : ""
|
||||
@@ -34,8 +32,7 @@ export function buildInboundLine(params: {
|
||||
// Wrap with standardized envelope for the agent.
|
||||
return formatAgentEnvelope({
|
||||
channel: "WhatsApp",
|
||||
from:
|
||||
msg.chatType === "group" ? msg.from : msg.from?.replace(/^whatsapp:/, ""),
|
||||
from: msg.chatType === "group" ? msg.from : msg.from?.replace(/^whatsapp:/, ""),
|
||||
timestamp: msg.timestamp,
|
||||
body: baseLine,
|
||||
});
|
||||
|
||||
@@ -25,9 +25,7 @@ export function createWebOnMessageHandler(params: {
|
||||
echoTracker: EchoTracker;
|
||||
backgroundTasks: Set<Promise<unknown>>;
|
||||
replyResolver: typeof getReplyFromConfig;
|
||||
replyLogger: ReturnType<
|
||||
typeof import("../../../logging.js")["getChildLogger"]
|
||||
>;
|
||||
replyLogger: ReturnType<(typeof import("../../../logging.js"))["getChildLogger"]>;
|
||||
baseMentionConfig: MentionConfig;
|
||||
account: { authDir?: string; accountId?: string };
|
||||
}) {
|
||||
@@ -90,9 +88,7 @@ export function createWebOnMessageHandler(params: {
|
||||
|
||||
// Skip if this is a message we just sent (echo detection)
|
||||
if (params.echoTracker.has(msg.body)) {
|
||||
logVerbose(
|
||||
"Skipping auto-reply: detected echo (message matches recently sent text)",
|
||||
);
|
||||
logVerbose("Skipping auto-reply: detected echo (message matches recently sent text)");
|
||||
params.echoTracker.forget(msg.body);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,10 +53,7 @@ export async function processMessage(params: {
|
||||
) => void;
|
||||
echoHas: (key: string) => boolean;
|
||||
echoForget: (key: string) => void;
|
||||
buildCombinedEchoKey: (p: {
|
||||
sessionKey: string;
|
||||
combinedBody: string;
|
||||
}) => string;
|
||||
buildCombinedEchoKey: (p: { sessionKey: string; combinedBody: string }) => string;
|
||||
maxMediaTextChunkLimit?: number;
|
||||
groupHistory?: GroupHistoryEntry[];
|
||||
suppressGroupHistoryClear?: boolean;
|
||||
@@ -70,12 +67,8 @@ export async function processMessage(params: {
|
||||
let shouldClearGroupHistory = false;
|
||||
|
||||
if (params.msg.chatType === "group") {
|
||||
const history =
|
||||
params.groupHistory ??
|
||||
params.groupHistories.get(params.groupHistoryKey) ??
|
||||
[];
|
||||
const historyWithoutCurrent =
|
||||
history.length > 0 ? history.slice(0, -1) : [];
|
||||
const history = params.groupHistory ?? params.groupHistories.get(params.groupHistoryKey) ?? [];
|
||||
const historyWithoutCurrent = history.length > 0 ? history.slice(0, -1) : [];
|
||||
if (historyWithoutCurrent.length > 0) {
|
||||
const lineBreak = "\\n";
|
||||
const historyText = historyWithoutCurrent
|
||||
@@ -142,8 +135,7 @@ export async function processMessage(params: {
|
||||
"inbound web message",
|
||||
);
|
||||
|
||||
const fromDisplay =
|
||||
params.msg.chatType === "group" ? conversationId : params.msg.from;
|
||||
const fromDisplay = params.msg.chatType === "group" ? conversationId : params.msg.from;
|
||||
const kindLabel = params.msg.mediaType ? `, ${params.msg.mediaType}` : "";
|
||||
whatsappInboundLog.info(
|
||||
`Inbound message ${fromDisplay} -> ${params.msg.to} (${params.msg.chatType}${kindLabel}, ${combinedBody.length} chars)`,
|
||||
@@ -173,9 +165,7 @@ export async function processMessage(params: {
|
||||
}
|
||||
}
|
||||
|
||||
const textLimit =
|
||||
params.maxMediaTextChunkLimit ??
|
||||
resolveTextChunkLimit(params.cfg, "whatsapp");
|
||||
const textLimit = params.maxMediaTextChunkLimit ?? resolveTextChunkLimit(params.cfg, "whatsapp");
|
||||
let didLogHeartbeatStrip = false;
|
||||
let didSendReply = false;
|
||||
const responsePrefix = resolveEffectiveMessagesConfig(
|
||||
@@ -242,8 +232,7 @@ export async function processMessage(params: {
|
||||
params.rememberSentText(payload.text, {});
|
||||
return;
|
||||
}
|
||||
const shouldLog =
|
||||
info.kind === "final" && payload.text ? true : undefined;
|
||||
const shouldLog = info.kind === "final" && payload.text ? true : undefined;
|
||||
params.rememberSentText(payload.text, {
|
||||
combinedBody,
|
||||
combinedBodySessionKey: params.route.sessionKey,
|
||||
@@ -251,21 +240,12 @@ export async function processMessage(params: {
|
||||
});
|
||||
if (info.kind === "final") {
|
||||
const fromDisplay =
|
||||
params.msg.chatType === "group"
|
||||
? conversationId
|
||||
: (params.msg.from ?? "unknown");
|
||||
const hasMedia = Boolean(
|
||||
payload.mediaUrl || payload.mediaUrls?.length,
|
||||
);
|
||||
whatsappOutboundLog.info(
|
||||
`Auto-replied to ${fromDisplay}${hasMedia ? " (media)" : ""}`,
|
||||
);
|
||||
params.msg.chatType === "group" ? conversationId : (params.msg.from ?? "unknown");
|
||||
const hasMedia = Boolean(payload.mediaUrl || payload.mediaUrls?.length);
|
||||
whatsappOutboundLog.info(`Auto-replied to ${fromDisplay}${hasMedia ? " (media)" : ""}`);
|
||||
if (shouldLogVerbose()) {
|
||||
const preview =
|
||||
payload.text != null ? elide(payload.text, 400) : "<media>";
|
||||
whatsappOutboundLog.debug(
|
||||
`Reply body: ${preview}${hasMedia ? " (media)" : ""}`,
|
||||
);
|
||||
const preview = payload.text != null ? elide(payload.text, 400) : "<media>";
|
||||
whatsappOutboundLog.debug(`Reply body: ${preview}${hasMedia ? " (media)" : ""}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -294,9 +274,7 @@ export async function processMessage(params: {
|
||||
if (shouldClearGroupHistory && didSendReply) {
|
||||
params.groupHistories.set(params.groupHistoryKey, []);
|
||||
}
|
||||
logVerbose(
|
||||
"Skipping auto-reply: silent token or no text/media returned from resolver",
|
||||
);
|
||||
logVerbose("Skipping auto-reply: silent token or no text/media returned from resolver");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user