fix: add curly braces to resolve-route.ts for eslint(curly) compliance

This commit is contained in:
Minidoracat
2026-02-06 20:20:45 +00:00
committed by Shadow
parent 4bf06e7824
commit e1e6e3f477

View File

@@ -68,8 +68,12 @@ function normalizeAccountId(value: string | undefined | null): string {
function matchesAccountId(match: string | undefined, actual: string): boolean { function matchesAccountId(match: string | undefined, actual: string): boolean {
const trimmed = (match ?? "").trim(); const trimmed = (match ?? "").trim();
if (!trimmed) return actual === DEFAULT_ACCOUNT_ID; if (!trimmed) {
if (trimmed === "*") return true; return actual === DEFAULT_ACCOUNT_ID;
}
if (trimmed === "*") {
return true;
}
return trimmed === actual; return trimmed === actual;
} }
@@ -103,12 +107,18 @@ function listAgents(cfg: OpenClawConfig) {
function pickFirstExistingAgentId(cfg: OpenClawConfig, agentId: string): string { function pickFirstExistingAgentId(cfg: OpenClawConfig, agentId: string): string {
const trimmed = (agentId ?? "").trim(); const trimmed = (agentId ?? "").trim();
if (!trimmed) return sanitizeAgentId(resolveDefaultAgentId(cfg)); if (!trimmed) {
return sanitizeAgentId(resolveDefaultAgentId(cfg));
}
const normalized = normalizeAgentId(trimmed); const normalized = normalizeAgentId(trimmed);
const agents = listAgents(cfg); const agents = listAgents(cfg);
if (agents.length === 0) return sanitizeAgentId(trimmed); if (agents.length === 0) {
return sanitizeAgentId(trimmed);
}
const match = agents.find((agent) => normalizeAgentId(agent.id) === normalized); const match = agents.find((agent) => normalizeAgentId(agent.id) === normalized);
if (match?.id?.trim()) return sanitizeAgentId(match.id.trim()); if (match?.id?.trim()) {
return sanitizeAgentId(match.id.trim());
}
return sanitizeAgentId(resolveDefaultAgentId(cfg)); return sanitizeAgentId(resolveDefaultAgentId(cfg));
} }
@@ -117,7 +127,9 @@ function matchesChannel(
channel: string, channel: string,
): boolean { ): boolean {
const key = normalizeToken(match?.channel); const key = normalizeToken(match?.channel);
if (!key) return false; if (!key) {
return false;
}
return key === channel; return key === channel;
} }
@@ -132,7 +144,9 @@ function matchesPeer(
// Backward compat: normalize "dm" to "direct" in config match rules // Backward compat: normalize "dm" to "direct" in config match rules
const kind = normalizeChatType(m.kind); const kind = normalizeChatType(m.kind);
const id = normalizeId(m.id); const id = normalizeId(m.id);
if (!kind || !id) return false; if (!kind || !id) {
return false;
}
return kind === peer.kind && id === peer.id; return kind === peer.kind && id === peer.id;
} }
@@ -141,13 +155,17 @@ function matchesGuild(
guildId: string, guildId: string,
): boolean { ): boolean {
const id = normalizeId(match?.guildId); const id = normalizeId(match?.guildId);
if (!id) return false; if (!id) {
return false;
}
return id === guildId; return id === guildId;
} }
function matchesTeam(match: { teamId?: string | undefined } | undefined, teamId: string): boolean { function matchesTeam(match: { teamId?: string | undefined } | undefined, teamId: string): boolean {
const id = normalizeId(match?.teamId); const id = normalizeId(match?.teamId);
if (!id) return false; if (!id) {
return false;
}
return id === teamId; return id === teamId;
} }
@@ -159,8 +177,12 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR
const teamId = normalizeId(input.teamId); const teamId = normalizeId(input.teamId);
const bindings = listBindings(input.cfg).filter((binding) => { const bindings = listBindings(input.cfg).filter((binding) => {
if (!binding || typeof binding !== "object") return false; if (!binding || typeof binding !== "object") {
if (!matchesChannel(binding.match, channel)) return false; return false;
}
if (!matchesChannel(binding.match, channel)) {
return false;
}
return matchesAccountId(binding.match?.accountId, accountId); return matchesAccountId(binding.match?.accountId, accountId);
}); });
@@ -193,14 +215,18 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR
if (peer) { if (peer) {
const peerMatch = bindings.find((b) => matchesPeer(b.match, peer)); const peerMatch = bindings.find((b) => matchesPeer(b.match, peer));
if (peerMatch) return choose(peerMatch.agentId, "binding.peer"); if (peerMatch) {
return choose(peerMatch.agentId, "binding.peer");
}
} }
if (guildId && memberRoleIds.length > 0) { if (guildId && memberRoleIds.length > 0) {
const guildRolesMatch = bindings.find( const guildRolesMatch = bindings.find(
(b) => matchesGuild(b.match, guildId) && matchesRoles(b.match, memberRoleIds), (b) => matchesGuild(b.match, guildId) && matchesRoles(b.match, memberRoleIds),
); );
if (guildRolesMatch) return choose(guildRolesMatch.agentId, "binding.guild+roles"); if (guildRolesMatch) {
return choose(guildRolesMatch.agentId, "binding.guild+roles");
}
} }
// Thread parent inheritance: if peer (thread) didn't match, check parent peer binding // Thread parent inheritance: if peer (thread) didn't match, check parent peer binding
@@ -223,20 +249,26 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR
if (teamId) { if (teamId) {
const teamMatch = bindings.find((b) => matchesTeam(b.match, teamId)); const teamMatch = bindings.find((b) => matchesTeam(b.match, teamId));
if (teamMatch) return choose(teamMatch.agentId, "binding.team"); if (teamMatch) {
return choose(teamMatch.agentId, "binding.team");
}
} }
const accountMatch = bindings.find( const accountMatch = bindings.find(
(b) => (b) =>
b.match?.accountId?.trim() !== "*" && !b.match?.peer && !b.match?.guildId && !b.match?.teamId, b.match?.accountId?.trim() !== "*" && !b.match?.peer && !b.match?.guildId && !b.match?.teamId,
); );
if (accountMatch) return choose(accountMatch.agentId, "binding.account"); if (accountMatch) {
return choose(accountMatch.agentId, "binding.account");
}
const anyAccountMatch = bindings.find( const anyAccountMatch = bindings.find(
(b) => (b) =>
b.match?.accountId?.trim() === "*" && !b.match?.peer && !b.match?.guildId && !b.match?.teamId, b.match?.accountId?.trim() === "*" && !b.match?.peer && !b.match?.guildId && !b.match?.teamId,
); );
if (anyAccountMatch) return choose(anyAccountMatch.agentId, "binding.channel"); if (anyAccountMatch) {
return choose(anyAccountMatch.agentId, "binding.channel");
}
return choose(resolveDefaultAgentId(input.cfg), "default"); return choose(resolveDefaultAgentId(input.cfg), "default");
} }