refactor: extend channel plugin boundary
This commit is contained in:
@@ -9,7 +9,6 @@ import { resolveWhatsAppAccount } from "../web/accounts.js";
|
||||
import { normalizeWhatsAppTarget } from "../whatsapp/normalize.js";
|
||||
import { requireActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import {
|
||||
resolveBlueBubblesGroupRequireMention,
|
||||
resolveDiscordGroupRequireMention,
|
||||
resolveIMessageGroupRequireMention,
|
||||
resolveSlackGroupRequireMention,
|
||||
@@ -68,27 +67,6 @@ const formatLower = (allowFrom: Array<string | number>) =>
|
||||
|
||||
const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
|
||||
// Helper to delegate config operations to a plugin at runtime.
|
||||
// Used for BlueBubbles which is in CHAT_CHANNEL_ORDER but implemented as a plugin.
|
||||
function getPluginConfigAdapter(channelId: string) {
|
||||
return {
|
||||
resolveAllowFrom: (params: { cfg: ClawdbotConfig; accountId?: string | null }) => {
|
||||
const registry = requireActivePluginRegistry();
|
||||
const entry = registry.channels.find((e) => e.plugin.id === channelId);
|
||||
return entry?.plugin.config?.resolveAllowFrom?.(params) ?? [];
|
||||
},
|
||||
formatAllowFrom: (params: {
|
||||
cfg: ClawdbotConfig;
|
||||
accountId?: string | null;
|
||||
allowFrom: Array<string | number>;
|
||||
}) => {
|
||||
const registry = requireActivePluginRegistry();
|
||||
const entry = registry.channels.find((e) => e.plugin.id === channelId);
|
||||
return entry?.plugin.config?.formatAllowFrom?.(params) ?? params.allowFrom.map(String);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Channel docks: lightweight channel metadata/behavior for shared code paths.
|
||||
//
|
||||
// Rules:
|
||||
@@ -288,30 +266,6 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
}),
|
||||
},
|
||||
},
|
||||
// BlueBubbles is in CHAT_CHANNEL_ORDER (Gate A: core registry) but implemented as a plugin.
|
||||
// Config operations are delegated to the plugin at runtime.
|
||||
// Note: Additional capabilities (edit, unsend, reply, effects, groupManagement) are exposed
|
||||
// via the plugin's capabilities, not the dock's ChannelCapabilities type.
|
||||
bluebubbles: {
|
||||
id: "bluebubbles",
|
||||
capabilities: {
|
||||
chatTypes: ["direct", "group"],
|
||||
reactions: true,
|
||||
media: true,
|
||||
},
|
||||
outbound: { textChunkLimit: 4000 },
|
||||
config: getPluginConfigAdapter("bluebubbles"),
|
||||
groups: {
|
||||
resolveRequireMention: resolveBlueBubblesGroupRequireMention,
|
||||
},
|
||||
threading: {
|
||||
buildToolContext: ({ context, hasRepliedRef }) => ({
|
||||
currentChannelId: context.To?.trim() || undefined,
|
||||
currentThreadTs: context.ReplyToId,
|
||||
hasRepliedRef,
|
||||
}),
|
||||
},
|
||||
},
|
||||
imessage: {
|
||||
id: "imessage",
|
||||
capabilities: {
|
||||
|
||||
@@ -33,17 +33,21 @@ function toChannelMeta(params: {
|
||||
const label = params.channel.label?.trim();
|
||||
if (!label) return null;
|
||||
const selectionLabel = params.channel.selectionLabel?.trim() || label;
|
||||
const detailLabel = params.channel.detailLabel?.trim();
|
||||
const docsPath = params.channel.docsPath?.trim() || `/channels/${params.id}`;
|
||||
const blurb = params.channel.blurb?.trim() || "";
|
||||
const systemImage = params.channel.systemImage?.trim();
|
||||
|
||||
return {
|
||||
id: params.id,
|
||||
label,
|
||||
selectionLabel,
|
||||
...(detailLabel ? { detailLabel } : {}),
|
||||
docsPath,
|
||||
docsLabel: params.channel.docsLabel?.trim() || undefined,
|
||||
blurb,
|
||||
...(params.channel.aliases ? { aliases: params.channel.aliases } : {}),
|
||||
...(params.channel.preferOver ? { preferOver: params.channel.preferOver } : {}),
|
||||
...(params.channel.order !== undefined ? { order: params.channel.order } : {}),
|
||||
...(params.channel.selectionDocsPrefix
|
||||
? { selectionDocsPrefix: params.channel.selectionDocsPrefix }
|
||||
@@ -52,6 +56,7 @@ function toChannelMeta(params: {
|
||||
? { selectionDocsOmitLabel: params.channel.selectionDocsOmitLabel }
|
||||
: {}),
|
||||
...(params.channel.selectionExtras ? { selectionExtras: params.channel.selectionExtras } : {}),
|
||||
...(systemImage ? { systemImage } : {}),
|
||||
...(params.channel.showConfigured !== undefined
|
||||
? { showConfigured: params.channel.showConfigured }
|
||||
: {}),
|
||||
|
||||
@@ -74,10 +74,13 @@ export type ChannelMeta = {
|
||||
selectionDocsPrefix?: string;
|
||||
selectionDocsOmitLabel?: boolean;
|
||||
selectionExtras?: string[];
|
||||
detailLabel?: string;
|
||||
systemImage?: string;
|
||||
showConfigured?: boolean;
|
||||
quickstartAllowFrom?: boolean;
|
||||
forceAccountBinding?: boolean;
|
||||
preferSessionLookupForAnnounceTarget?: boolean;
|
||||
preferOver?: string[];
|
||||
};
|
||||
|
||||
export type ChannelAccountSnapshot = {
|
||||
|
||||
@@ -4,15 +4,12 @@ import { requireActivePluginRegistry } from "../plugins/runtime.js";
|
||||
|
||||
// Channel docking: add new core channels here (order + meta + aliases), then
|
||||
// register the plugin in its extension entrypoint and keep protocol IDs in sync.
|
||||
// BlueBubbles placed before imessage per Gate C decision: prefer BlueBubbles
|
||||
// for iMessage use cases when both are available.
|
||||
export const CHAT_CHANNEL_ORDER = [
|
||||
"telegram",
|
||||
"whatsapp",
|
||||
"discord",
|
||||
"slack",
|
||||
"signal",
|
||||
"bluebubbles",
|
||||
"imessage",
|
||||
] as const;
|
||||
|
||||
@@ -31,9 +28,11 @@ const CHAT_CHANNEL_META: Record<ChatChannelId, ChannelMeta> = {
|
||||
id: "telegram",
|
||||
label: "Telegram",
|
||||
selectionLabel: "Telegram (Bot API)",
|
||||
detailLabel: "Telegram Bot",
|
||||
docsPath: "/channels/telegram",
|
||||
docsLabel: "telegram",
|
||||
blurb: "simplest way to get started — register a bot with @BotFather and get going.",
|
||||
systemImage: "paperplane",
|
||||
selectionDocsPrefix: "",
|
||||
selectionDocsOmitLabel: true,
|
||||
selectionExtras: [WEBSITE_URL],
|
||||
@@ -42,55 +41,56 @@ const CHAT_CHANNEL_META: Record<ChatChannelId, ChannelMeta> = {
|
||||
id: "whatsapp",
|
||||
label: "WhatsApp",
|
||||
selectionLabel: "WhatsApp (QR link)",
|
||||
detailLabel: "WhatsApp Web",
|
||||
docsPath: "/channels/whatsapp",
|
||||
docsLabel: "whatsapp",
|
||||
blurb: "works with your own number; recommend a separate phone + eSIM.",
|
||||
systemImage: "message",
|
||||
},
|
||||
discord: {
|
||||
id: "discord",
|
||||
label: "Discord",
|
||||
selectionLabel: "Discord (Bot API)",
|
||||
detailLabel: "Discord Bot",
|
||||
docsPath: "/channels/discord",
|
||||
docsLabel: "discord",
|
||||
blurb: "very well supported right now.",
|
||||
systemImage: "bubble.left.and.bubble.right",
|
||||
},
|
||||
slack: {
|
||||
id: "slack",
|
||||
label: "Slack",
|
||||
selectionLabel: "Slack (Socket Mode)",
|
||||
detailLabel: "Slack Bot",
|
||||
docsPath: "/channels/slack",
|
||||
docsLabel: "slack",
|
||||
blurb: "supported (Socket Mode).",
|
||||
systemImage: "number",
|
||||
},
|
||||
signal: {
|
||||
id: "signal",
|
||||
label: "Signal",
|
||||
selectionLabel: "Signal (signal-cli)",
|
||||
detailLabel: "Signal REST",
|
||||
docsPath: "/channels/signal",
|
||||
docsLabel: "signal",
|
||||
blurb: 'signal-cli linked device; more setup (David Reagans: "Hop on Discord.").',
|
||||
},
|
||||
bluebubbles: {
|
||||
id: "bluebubbles",
|
||||
label: "BlueBubbles",
|
||||
selectionLabel: "BlueBubbles (macOS app)",
|
||||
docsPath: "/channels/bluebubbles",
|
||||
docsLabel: "bluebubbles",
|
||||
blurb: "recommended for iMessage — uses the BlueBubbles mac app + REST API.",
|
||||
systemImage: "antenna.radiowaves.left.and.right",
|
||||
},
|
||||
imessage: {
|
||||
id: "imessage",
|
||||
label: "iMessage",
|
||||
selectionLabel: "iMessage (imsg)",
|
||||
detailLabel: "iMessage",
|
||||
docsPath: "/channels/imessage",
|
||||
docsLabel: "imessage",
|
||||
blurb: "this is still a work in progress.",
|
||||
systemImage: "message.fill",
|
||||
},
|
||||
};
|
||||
|
||||
export const CHAT_CHANNEL_ALIASES: Record<string, ChatChannelId> = {
|
||||
imsg: "imessage",
|
||||
bb: "bluebubbles",
|
||||
};
|
||||
|
||||
const normalizeChannelKey = (raw?: string | null): string | undefined => {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import { normalizeAccountId } from "../routing/session-key.js";
|
||||
import type { ClawdbotConfig } from "./config.js";
|
||||
|
||||
export type GroupPolicyChannel = "whatsapp" | "telegram" | "imessage" | "bluebubbles";
|
||||
export type GroupPolicyChannel = ChannelId;
|
||||
|
||||
export type ChannelGroupConfig = {
|
||||
requireMention?: boolean;
|
||||
|
||||
@@ -60,7 +60,7 @@ describe("applyPluginAutoEnable", () => {
|
||||
expect(result.changes).toEqual([]);
|
||||
});
|
||||
|
||||
describe("BlueBubbles over imessage prioritization", () => {
|
||||
describe("preferOver channel prioritization", () => {
|
||||
it("prefers bluebubbles: skips imessage auto-enable when both are configured", () => {
|
||||
const result = applyPluginAutoEnable({
|
||||
config: {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import type { ClawdbotConfig } from "./config.js";
|
||||
import { getChatChannelMeta, listChatChannels, normalizeChatChannelId } from "../channels/registry.js";
|
||||
import {
|
||||
getChannelPluginCatalogEntry,
|
||||
listChannelPluginCatalogEntries,
|
||||
} from "../channels/plugins/catalog.js";
|
||||
import { normalizeProviderId } from "../agents/model-selection.js";
|
||||
import { listChatChannels } from "../channels/registry.js";
|
||||
import { hasAnyWhatsAppAuth } from "../web/accounts.js";
|
||||
|
||||
type PluginEnableChange = {
|
||||
@@ -13,6 +17,13 @@ export type PluginAutoEnableResult = {
|
||||
changes: string[];
|
||||
};
|
||||
|
||||
const CHANNEL_PLUGIN_IDS = Array.from(
|
||||
new Set([
|
||||
...listChatChannels().map((meta) => meta.id),
|
||||
...listChannelPluginCatalogEntries().map((entry) => entry.id),
|
||||
]),
|
||||
);
|
||||
|
||||
const PROVIDER_PLUGIN_IDS: Array<{ pluginId: string; providerId: string }> = [
|
||||
{ pluginId: "google-antigravity-auth", providerId: "google-antigravity" },
|
||||
{ pluginId: "google-gemini-cli-auth", providerId: "google-gemini-cli" },
|
||||
@@ -226,10 +237,7 @@ function resolveConfiguredPlugins(
|
||||
env: NodeJS.ProcessEnv,
|
||||
): PluginEnableChange[] {
|
||||
const changes: PluginEnableChange[] = [];
|
||||
const channelIds = new Set<string>();
|
||||
for (const meta of listChatChannels()) {
|
||||
channelIds.add(meta.id);
|
||||
}
|
||||
const channelIds = new Set(CHANNEL_PLUGIN_IDS);
|
||||
const configuredChannels = cfg.channels as Record<string, unknown> | undefined;
|
||||
if (configuredChannels && typeof configuredChannels === "object") {
|
||||
for (const key of Object.keys(configuredChannels)) {
|
||||
@@ -267,21 +275,30 @@ function isPluginDenied(cfg: ClawdbotConfig, pluginId: string): boolean {
|
||||
return Array.isArray(deny) && deny.includes(pluginId);
|
||||
}
|
||||
|
||||
/**
|
||||
* When both BlueBubbles and iMessage are configured, prefer BlueBubbles:
|
||||
* skip auto-enabling iMessage unless BlueBubbles is explicitly disabled/denied.
|
||||
* This is non-destructive: if iMessage is already enabled, it won't be touched.
|
||||
*/
|
||||
function shouldSkipImsgForBlueBubbles(
|
||||
function resolvePreferredOverIds(pluginId: string): string[] {
|
||||
const normalized = normalizeChatChannelId(pluginId);
|
||||
if (normalized) {
|
||||
return getChatChannelMeta(normalized).preferOver ?? [];
|
||||
}
|
||||
const catalogEntry = getChannelPluginCatalogEntry(pluginId);
|
||||
return catalogEntry?.meta.preferOver ?? [];
|
||||
}
|
||||
|
||||
function shouldSkipPreferredPluginAutoEnable(
|
||||
cfg: ClawdbotConfig,
|
||||
pluginId: string,
|
||||
entry: PluginEnableChange,
|
||||
configured: PluginEnableChange[],
|
||||
): boolean {
|
||||
if (pluginId !== "imessage") return false;
|
||||
const blueBubblesConfigured = configured.some((e) => e.pluginId === "bluebubbles");
|
||||
if (!blueBubblesConfigured) return false;
|
||||
// Skip imessage auto-enable if bluebubbles is configured and not blocked
|
||||
return !isPluginExplicitlyDisabled(cfg, "bluebubbles") && !isPluginDenied(cfg, "bluebubbles");
|
||||
for (const other of configured) {
|
||||
if (other.pluginId === entry.pluginId) continue;
|
||||
if (isPluginDenied(cfg, other.pluginId)) continue;
|
||||
if (isPluginExplicitlyDisabled(cfg, other.pluginId)) continue;
|
||||
const preferOver = resolvePreferredOverIds(other.pluginId);
|
||||
if (preferOver.includes(entry.pluginId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function ensureAllowlisted(cfg: ClawdbotConfig, pluginId: string): ClawdbotConfig {
|
||||
@@ -334,8 +351,7 @@ export function applyPluginAutoEnable(params: {
|
||||
for (const entry of configured) {
|
||||
if (isPluginDenied(next, entry.pluginId)) continue;
|
||||
if (isPluginExplicitlyDisabled(next, entry.pluginId)) continue;
|
||||
// Prefer BlueBubbles over imessage: skip imsg auto-enable if bluebubbles is configured
|
||||
if (shouldSkipImsgForBlueBubbles(next, entry.pluginId, configured)) continue;
|
||||
if (shouldSkipPreferredPluginAutoEnable(next, entry, configured)) continue;
|
||||
const allow = next.plugins?.allow;
|
||||
const allowMissing = Array.isArray(allow) && !allow.includes(entry.pluginId);
|
||||
const alreadyEnabled = next.plugins?.entries?.[entry.pluginId]?.enabled === true;
|
||||
|
||||
@@ -60,6 +60,8 @@ export const ChannelsStatusResultSchema = Type.Object(
|
||||
ts: Type.Integer({ minimum: 0 }),
|
||||
channelOrder: Type.Array(NonEmptyString),
|
||||
channelLabels: Type.Record(NonEmptyString, NonEmptyString),
|
||||
channelDetailLabels: Type.Optional(Type.Record(NonEmptyString, NonEmptyString)),
|
||||
channelSystemImages: Type.Optional(Type.Record(NonEmptyString, NonEmptyString)),
|
||||
channels: Type.Record(NonEmptyString, Type.Unknown()),
|
||||
channelAccounts: Type.Record(NonEmptyString, Type.Array(ChannelAccountSnapshotSchema)),
|
||||
channelDefaultAccountId: Type.Record(NonEmptyString, NonEmptyString),
|
||||
|
||||
@@ -188,10 +188,24 @@ export const channelsHandlers: GatewayRequestHandlers = {
|
||||
return { accounts, defaultAccountId, defaultAccount, resolvedAccounts };
|
||||
};
|
||||
|
||||
const channelLabels = Object.fromEntries(plugins.map((plugin) => [plugin.id, plugin.meta.label]));
|
||||
const channelDetailLabels = Object.fromEntries(
|
||||
plugins.map((plugin) => [
|
||||
plugin.id,
|
||||
plugin.meta.detailLabel ?? plugin.meta.selectionLabel ?? plugin.meta.label,
|
||||
]),
|
||||
);
|
||||
const channelSystemImages = Object.fromEntries(
|
||||
plugins.flatMap((plugin) =>
|
||||
plugin.meta.systemImage ? [[plugin.id, plugin.meta.systemImage]] : [],
|
||||
),
|
||||
);
|
||||
const payload: Record<string, unknown> = {
|
||||
ts: Date.now(),
|
||||
channelOrder: plugins.map((plugin) => plugin.id),
|
||||
channelLabels: Object.fromEntries(plugins.map((plugin) => [plugin.id, plugin.meta.label])),
|
||||
channelLabels,
|
||||
channelDetailLabels,
|
||||
channelSystemImages,
|
||||
channels: {} as Record<string, unknown>,
|
||||
channelAccounts: {} as Record<string, unknown>,
|
||||
channelDefaultAccountId: {} as Record<string, unknown>,
|
||||
|
||||
@@ -95,11 +95,14 @@ export type PluginPackageChannel = {
|
||||
id?: string;
|
||||
label?: string;
|
||||
selectionLabel?: string;
|
||||
detailLabel?: string;
|
||||
docsPath?: string;
|
||||
docsLabel?: string;
|
||||
blurb?: string;
|
||||
order?: number;
|
||||
aliases?: string[];
|
||||
preferOver?: string[];
|
||||
systemImage?: string;
|
||||
selectionDocsPrefix?: string;
|
||||
selectionDocsOmitLabel?: boolean;
|
||||
selectionExtras?: string[];
|
||||
|
||||
Reference in New Issue
Block a user