diff --git a/src/routing/resolve-route.ts b/src/routing/resolve-route.ts index a33049931..381a90f01 100644 --- a/src/routing/resolve-route.ts +++ b/src/routing/resolve-route.ts @@ -68,8 +68,12 @@ function normalizeAccountId(value: string | undefined | null): string { function matchesAccountId(match: string | undefined, actual: string): boolean { const trimmed = (match ?? "").trim(); - if (!trimmed) return actual === DEFAULT_ACCOUNT_ID; - if (trimmed === "*") return true; + if (!trimmed) { + return actual === DEFAULT_ACCOUNT_ID; + } + if (trimmed === "*") { + return true; + } return trimmed === actual; } @@ -103,12 +107,18 @@ function listAgents(cfg: OpenClawConfig) { function pickFirstExistingAgentId(cfg: OpenClawConfig, agentId: string): string { const trimmed = (agentId ?? "").trim(); - if (!trimmed) return sanitizeAgentId(resolveDefaultAgentId(cfg)); + if (!trimmed) { + return sanitizeAgentId(resolveDefaultAgentId(cfg)); + } const normalized = normalizeAgentId(trimmed); 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); - if (match?.id?.trim()) return sanitizeAgentId(match.id.trim()); + if (match?.id?.trim()) { + return sanitizeAgentId(match.id.trim()); + } return sanitizeAgentId(resolveDefaultAgentId(cfg)); } @@ -117,7 +127,9 @@ function matchesChannel( channel: string, ): boolean { const key = normalizeToken(match?.channel); - if (!key) return false; + if (!key) { + return false; + } return key === channel; } @@ -132,7 +144,9 @@ function matchesPeer( // Backward compat: normalize "dm" to "direct" in config match rules const kind = normalizeChatType(m.kind); const id = normalizeId(m.id); - if (!kind || !id) return false; + if (!kind || !id) { + return false; + } return kind === peer.kind && id === peer.id; } @@ -141,13 +155,17 @@ function matchesGuild( guildId: string, ): boolean { const id = normalizeId(match?.guildId); - if (!id) return false; + if (!id) { + return false; + } return id === guildId; } function matchesTeam(match: { teamId?: string | undefined } | undefined, teamId: string): boolean { const id = normalizeId(match?.teamId); - if (!id) return false; + if (!id) { + return false; + } return id === teamId; } @@ -159,8 +177,12 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR const teamId = normalizeId(input.teamId); const bindings = listBindings(input.cfg).filter((binding) => { - if (!binding || typeof binding !== "object") return false; - if (!matchesChannel(binding.match, channel)) return false; + if (!binding || typeof binding !== "object") { + return false; + } + if (!matchesChannel(binding.match, channel)) { + return false; + } return matchesAccountId(binding.match?.accountId, accountId); }); @@ -193,14 +215,18 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR if (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) { const guildRolesMatch = bindings.find( (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 @@ -223,20 +249,26 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR if (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( (b) => 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( (b) => 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"); }