From be68309e7b3d3325516a44a4bbe410221d3bcd8b Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 13 Apr 2026 17:34:27 +0100 Subject: [PATCH] perf(outbound): narrow loaded target channel reads --- src/infra/outbound/targets-loaded.test.ts | 6 ++++++ src/infra/outbound/targets-loaded.ts | 9 +++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/infra/outbound/targets-loaded.test.ts b/src/infra/outbound/targets-loaded.test.ts index 87b324c8db7..be5a00def71 100644 --- a/src/infra/outbound/targets-loaded.test.ts +++ b/src/infra/outbound/targets-loaded.test.ts @@ -45,4 +45,10 @@ describe("tryResolveLoadedOutboundTarget", () => { }), ).toEqual({ ok: true, to: "123456789" }); }); + + it("trims channel ids before reading the loaded registry", () => { + tryResolveLoadedOutboundTarget({ channel: " telegram " as never, to: "123" }); + + expect(mocks.getLoadedChannelPlugin).toHaveBeenCalledWith("telegram"); + }); }); diff --git a/src/infra/outbound/targets-loaded.ts b/src/infra/outbound/targets-loaded.ts index e09b4a6b130..4f30e8668a0 100644 --- a/src/infra/outbound/targets-loaded.ts +++ b/src/infra/outbound/targets-loaded.ts @@ -2,19 +2,16 @@ import { getLoadedChannelPluginForRead } from "../../channels/plugins/registry-l import type { ChannelPlugin } from "../../channels/plugins/types.plugin.js"; import type { ChannelOutboundTargetMode } from "../../channels/plugins/types.public.js"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; +import { normalizeOptionalString } from "../../shared/string-coerce.js"; import type { GatewayMessageChannel } from "../../utils/message-channel.js"; -import { - isDeliverableMessageChannel, - normalizeMessageChannel, -} from "../../utils/message-channel.js"; import { resolveOutboundTargetWithPlugin, type OutboundTargetResolution, } from "./targets-resolve-shared.js"; function resolveLoadedOutboundChannelPlugin(channel: string): ChannelPlugin | undefined { - const normalized = normalizeMessageChannel(channel); - if (!normalized || !isDeliverableMessageChannel(normalized)) { + const normalized = normalizeOptionalString(channel); + if (!normalized) { return undefined; }