mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:28:27 +00:00
fix: add discord routing debug logging (#16202) (thanks @jayleekr)
This commit is contained in:
@@ -2,6 +2,8 @@ import type { ChatType } from "../channels/chat-type.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import { normalizeChatType } from "../channels/chat-type.js";
|
||||
import { shouldLogVerbose } from "../globals.js";
|
||||
import { logDebug } from "../logger.js";
|
||||
import { listBindings } from "./bindings.js";
|
||||
import {
|
||||
buildAgentMainSessionKey,
|
||||
@@ -322,6 +324,29 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR
|
||||
};
|
||||
};
|
||||
|
||||
const shouldLogDebug = shouldLogVerbose();
|
||||
const formatPeer = (value?: RoutePeer | null) =>
|
||||
value?.kind && value?.id ? `${value.kind}:${value.id}` : "none";
|
||||
const formatNormalizedPeer = (value: NormalizedPeerConstraint) => {
|
||||
if (value.state === "none") {
|
||||
return "none";
|
||||
}
|
||||
if (value.state === "invalid") {
|
||||
return "invalid";
|
||||
}
|
||||
return `${value.kind}:${value.id}`;
|
||||
};
|
||||
|
||||
if (shouldLogDebug) {
|
||||
logDebug(
|
||||
`[routing] resolveAgentRoute: channel=${channel} accountId=${accountId} peer=${formatPeer(peer)} guildId=${guildId || "none"} teamId=${teamId || "none"} bindings=${bindings.length}`,
|
||||
);
|
||||
for (const entry of bindings) {
|
||||
logDebug(
|
||||
`[routing] binding: agentId=${entry.binding.agentId} accountPattern=${entry.match.accountPattern || "default"} peer=${formatNormalizedPeer(entry.match.peer)} guildId=${entry.match.guildId ?? "none"} teamId=${entry.match.teamId ?? "none"} roles=${entry.match.roles?.length ?? 0}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
// Thread parent inheritance: if peer (thread) didn't match, check parent peer binding
|
||||
const parentPeer = input.parentPeer
|
||||
? { kind: input.parentPeer.kind, id: normalizeId(input.parentPeer.id) }
|
||||
@@ -397,6 +422,9 @@ export function resolveAgentRoute(input: ResolveAgentRouteInput): ResolvedAgentR
|
||||
}),
|
||||
);
|
||||
if (matched) {
|
||||
if (shouldLogDebug) {
|
||||
logDebug(`[routing] match: matchedBy=${tier.matchedBy} agentId=${matched.binding.agentId}`);
|
||||
}
|
||||
return choose(matched.binding.agentId, tier.matchedBy);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user