refactor(agents): unify subagent announce delivery pipeline

Co-authored-by: Smith Labs <SmithLabsLLC@users.noreply.github.com>
Co-authored-by: Do Cao Hieu <docaohieu2808@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-02-26 00:30:19 +00:00
parent aedf62ac7e
commit 4258a3307f
14 changed files with 623 additions and 132 deletions

View File

@@ -1,4 +1,3 @@
import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js";
import type { OpenClawConfig } from "../../config/config.js";
import { loadConfig } from "../../config/config.js";
import { callGatewayLeastPrivilege, randomIdempotencyKey } from "../../gateway/call.js";
@@ -10,6 +9,10 @@ import {
type GatewayClientMode,
type GatewayClientName,
} from "../../utils/message-channel.js";
import {
normalizeDeliverableOutboundChannel,
resolveOutboundChannelPlugin,
} from "./channel-resolution.js";
import { resolveMessageChannelSelection } from "./channel-selection.js";
import {
deliverOutboundPayloads,
@@ -107,17 +110,18 @@ async function resolveRequiredChannel(params: {
cfg: OpenClawConfig;
channel?: string;
}): Promise<string> {
const channel = params.channel?.trim()
? normalizeChannelId(params.channel)
: (await resolveMessageChannelSelection({ cfg: params.cfg })).channel;
if (!channel) {
throw new Error(`Unknown channel: ${params.channel}`);
if (params.channel?.trim()) {
const normalized = normalizeDeliverableOutboundChannel(params.channel);
if (!normalized) {
throw new Error(`Unknown channel: ${params.channel}`);
}
return normalized;
}
return channel;
return (await resolveMessageChannelSelection({ cfg: params.cfg })).channel;
}
function resolveRequiredPlugin(channel: string) {
const plugin = getChannelPlugin(channel);
function resolveRequiredPlugin(channel: string, cfg: OpenClawConfig) {
const plugin = resolveOutboundChannelPlugin({ channel, cfg });
if (!plugin) {
throw new Error(`Unknown channel: ${channel}`);
}
@@ -166,7 +170,7 @@ async function callMessageGateway<T>(params: {
export async function sendMessage(params: MessageSendParams): Promise<MessageSendResult> {
const cfg = params.cfg ?? loadConfig();
const channel = await resolveRequiredChannel({ cfg, channel: params.channel });
const plugin = resolveRequiredPlugin(channel);
const plugin = resolveRequiredPlugin(channel, cfg);
const deliveryMode = plugin.outbound?.deliveryMode ?? "direct";
const normalizedPayloads = normalizeReplyPayloadsForDelivery([
{
@@ -279,7 +283,7 @@ export async function sendPoll(params: MessagePollParams): Promise<MessagePollRe
durationSeconds: params.durationSeconds,
durationHours: params.durationHours,
};
const plugin = resolveRequiredPlugin(channel);
const plugin = resolveRequiredPlugin(channel, cfg);
const outbound = plugin?.outbound;
if (!outbound?.sendPoll) {
throw new Error(`Unsupported poll channel: ${channel}`);