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

@@ -0,0 +1,73 @@
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../../agents/agent-scope.js";
import { getChannelPlugin } from "../../channels/plugins/index.js";
import type { ChannelPlugin } from "../../channels/plugins/types.js";
import type { OpenClawConfig } from "../../config/config.js";
import { applyPluginAutoEnable } from "../../config/plugin-auto-enable.js";
import { loadOpenClawPlugins } from "../../plugins/loader.js";
import { getActivePluginRegistry, getActivePluginRegistryKey } from "../../plugins/runtime.js";
import {
isDeliverableMessageChannel,
normalizeMessageChannel,
type DeliverableMessageChannel,
} from "../../utils/message-channel.js";
const bootstrapAttempts = new Set<string>();
export function normalizeDeliverableOutboundChannel(
raw?: string | null,
): DeliverableMessageChannel | undefined {
const normalized = normalizeMessageChannel(raw);
if (!normalized || !isDeliverableMessageChannel(normalized)) {
return undefined;
}
return normalized;
}
function maybeBootstrapChannelPlugin(params: {
channel: DeliverableMessageChannel;
cfg?: OpenClawConfig;
}): void {
const cfg = params.cfg;
if (!cfg) {
return;
}
const activeRegistry = getActivePluginRegistry();
if ((activeRegistry?.channels?.length ?? 0) > 0) {
return;
}
const registryKey = getActivePluginRegistryKey() ?? "<none>";
const attemptKey = `${registryKey}:${params.channel}`;
if (bootstrapAttempts.has(attemptKey)) {
return;
}
bootstrapAttempts.add(attemptKey);
const autoEnabled = applyPluginAutoEnable({ config: cfg }).config;
const defaultAgentId = resolveDefaultAgentId(autoEnabled);
const workspaceDir = resolveAgentWorkspaceDir(autoEnabled, defaultAgentId);
loadOpenClawPlugins({
config: autoEnabled,
workspaceDir,
});
}
export function resolveOutboundChannelPlugin(params: {
channel: string;
cfg?: OpenClawConfig;
}): ChannelPlugin | undefined {
const normalized = normalizeDeliverableOutboundChannel(params.channel);
if (!normalized) {
return undefined;
}
const resolve = () => getChannelPlugin(normalized);
const current = resolve();
if (current) {
return current;
}
maybeBootstrapChannelPlugin({ channel: normalized, cfg: params.cfg });
return resolve();
}