perf: short-circuit exact reply suppression targets

This commit is contained in:
Peter Steinberger
2026-04-11 07:25:44 +01:00
parent 9d45866038
commit be9b70c815

View File

@@ -1,6 +1,7 @@
import { isMessagingToolDuplicate } from "../../agents/pi-embedded-helpers.js";
import type { MessagingToolSend } from "../../agents/pi-embedded-runner.js";
import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js";
import { getChannelPlugin } from "../../channels/plugins/index.js";
import { normalizeAnyChannelId } from "../../channels/registry.js";
import { normalizeTargetForProvider } from "../../infra/outbound/target-normalization.js";
import { normalizeOptionalAccountId } from "../../routing/account-id.js";
import {
@@ -70,7 +71,7 @@ function normalizeProviderForComparison(value?: string): string | undefined {
return undefined;
}
const lowered = normalizeLowercaseStringOrEmpty(trimmed);
const normalizedChannel = normalizeChannelId(trimmed);
const normalizedChannel = normalizeAnyChannelId(trimmed);
if (normalizedChannel) {
return normalizedChannel;
}
@@ -126,10 +127,7 @@ export function shouldSuppressMessagingToolReplies(params: {
if (!provider) {
return false;
}
const originTarget = normalizeTargetForProvider(provider, params.originatingTo);
if (!originTarget) {
return false;
}
const originRawTarget = normalizeOptionalString(params.originatingTo);
const originAccount = normalizeOptionalAccountId(params.accountId);
const sentTargets = params.messagingToolSentTargets ?? [];
if (sentTargets.length === 0) {
@@ -143,14 +141,22 @@ export function shouldSuppressMessagingToolReplies(params: {
if (targetProvider !== provider) {
return false;
}
const targetKey = normalizeTargetForProvider(targetProvider, target.to);
if (!targetKey) {
return false;
}
const targetAccount = normalizeOptionalAccountId(target.accountId);
if (originAccount && targetAccount && originAccount !== targetAccount) {
return false;
}
const targetRaw = normalizeOptionalString(target.to);
if (originRawTarget && targetRaw === originRawTarget && !target.threadId) {
return true;
}
const originTarget = normalizeTargetForProvider(provider, originRawTarget);
if (!originTarget) {
return false;
}
const targetKey = normalizeTargetForProvider(targetProvider, targetRaw);
if (!targetKey) {
return false;
}
return targetsMatchForSuppression({
provider,
originTarget,