mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 18:16:37 +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:
73
src/infra/outbound/channel-resolution.ts
Normal file
73
src/infra/outbound/channel-resolution.ts
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user