perf(outbound): narrow loaded target channel reads

This commit is contained in:
Vincent Koc
2026-04-13 17:34:27 +01:00
parent eed595bba9
commit be68309e7b
2 changed files with 9 additions and 6 deletions

View File

@@ -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");
});
});

View File

@@ -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;
}