mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 08:01:40 +00:00
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:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user