feat: load channel plugins

This commit is contained in:
Peter Steinberger
2026-01-15 02:42:41 +00:00
parent b1e3d79eaa
commit 2b4a68e276
49 changed files with 494 additions and 159 deletions

View File

@@ -1,4 +1,6 @@
import type { AnyAgentTool } from "../agents/tools/common.js";
import type { ChannelDock } from "../channels/dock.js";
import type { ChannelPlugin } from "../channels/plugins/types.js";
import type {
GatewayRequestHandler,
GatewayRequestHandlers,
@@ -6,6 +8,7 @@ import type {
import { resolveUserPath } from "../utils.js";
import type {
ClawdbotPluginApi,
ClawdbotPluginChannelRegistration,
ClawdbotPluginCliRegistrar,
ClawdbotPluginService,
ClawdbotPluginToolContext,
@@ -30,6 +33,13 @@ export type PluginCliRegistration = {
source: string;
};
export type PluginChannelRegistration = {
pluginId: string;
plugin: ChannelPlugin;
dock?: ChannelDock;
source: string;
};
export type PluginServiceRegistration = {
pluginId: string;
service: ClawdbotPluginService;
@@ -48,6 +58,7 @@ export type PluginRecord = {
status: "loaded" | "disabled" | "error";
error?: string;
toolNames: string[];
channelIds: string[];
gatewayMethods: string[];
cliCommands: string[];
services: string[];
@@ -58,6 +69,7 @@ export type PluginRecord = {
export type PluginRegistry = {
plugins: PluginRecord[];
tools: PluginToolRegistration[];
channels: PluginChannelRegistration[];
gatewayHandlers: GatewayRequestHandlers;
cliRegistrars: PluginCliRegistration[];
services: PluginServiceRegistration[];
@@ -73,6 +85,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
const registry: PluginRegistry = {
plugins: [],
tools: [],
channels: [],
gatewayHandlers: {},
cliRegistrars: [],
services: [],
@@ -129,6 +142,34 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
record.gatewayMethods.push(trimmed);
};
const registerChannel = (
record: PluginRecord,
registration: ClawdbotPluginChannelRegistration | ChannelPlugin,
) => {
const normalized =
typeof (registration as ClawdbotPluginChannelRegistration).plugin === "object"
? (registration as ClawdbotPluginChannelRegistration)
: { plugin: registration as ChannelPlugin };
const plugin = normalized.plugin;
const id = typeof plugin?.id === "string" ? plugin.id.trim() : String(plugin?.id ?? "").trim();
if (!id) {
pushDiagnostic({
level: "error",
pluginId: record.id,
source: record.source,
message: "channel registration missing id",
});
return;
}
record.channelIds.push(id);
registry.channels.push({
pluginId: record.id,
plugin,
dock: normalized.dock,
source: record.source,
});
};
const registerCli = (
record: PluginRecord,
registrar: ClawdbotPluginCliRegistrar,
@@ -179,6 +220,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
pluginConfig: params.pluginConfig,
logger: normalizeLogger(registryParams.logger),
registerTool: (tool, opts) => registerTool(record, tool, opts),
registerChannel: (registration) => registerChannel(record, registration),
registerGatewayMethod: (method, handler) => registerGatewayMethod(record, method, handler),
registerCli: (registrar, opts) => registerCli(record, registrar, opts),
registerService: (service) => registerService(record, service),
@@ -191,6 +233,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
createApi,
pushDiagnostic,
registerTool,
registerChannel,
registerGatewayMethod,
registerCli,
registerService,