diff --git a/src/cron/isolated-agent/delivery-dispatch.ts b/src/cron/isolated-agent/delivery-dispatch.ts index 2c6748a99ae..9bc1dfaad62 100644 --- a/src/cron/isolated-agent/delivery-dispatch.ts +++ b/src/cron/isolated-agent/delivery-dispatch.ts @@ -21,6 +21,21 @@ import { waitForDescendantSubagentSummary, } from "./subagent-followup.js"; +function normalizeDeliveryTarget(channel: string, to: string): string { + const channelLower = channel.trim().toLowerCase(); + const toTrimmed = to.trim(); + if (channelLower === "feishu" || channelLower === "lark") { + const lowered = toTrimmed.toLowerCase(); + if (lowered.startsWith("user:")) { + return toTrimmed.slice("user:".length).trim(); + } + if (lowered.startsWith("chat:")) { + return toTrimmed.slice("chat:".length).trim(); + } + } + return toTrimmed; +} + export function matchesMessagingToolDeliveryTarget( target: { provider?: string; to?: string; accountId?: string }, delivery: { channel?: string; to?: string; accountId?: string }, @@ -36,7 +51,8 @@ export function matchesMessagingToolDeliveryTarget( if (target.accountId && delivery.accountId && target.accountId !== delivery.accountId) { return false; } - return target.to === delivery.to; + const normalizedDeliveryTo = normalizeDeliveryTarget(channel, delivery.to); + return target.to === normalizedDeliveryTo; } export function resolveCronDeliveryBestEffort(job: CronJob): boolean {