refactor: extend channel plugin boundary

This commit is contained in:
Peter Steinberger
2026-01-20 11:49:31 +00:00
parent 439044068a
commit 9a2bf57e1c
31 changed files with 234 additions and 162 deletions

View File

@@ -244,7 +244,7 @@ extension ChannelsSettings {
} }
var orderedChannels: [ChannelItem] { var orderedChannels: [ChannelItem] {
let fallback = ["whatsapp", "telegram", "discord", "slack", "signal", "imessage", "bluebubbles"] let fallback = ["whatsapp", "telegram", "discord", "slack", "signal", "imessage"]
let order = self.store.snapshot?.channelOrder ?? fallback let order = self.store.snapshot?.channelOrder ?? fallback
let channels = order.enumerated().map { index, id in let channels = order.enumerated().map { index, id in
ChannelItem( ChannelItem(
@@ -433,29 +433,17 @@ extension ChannelsSettings {
} }
private func resolveChannelDetailTitle(_ id: String) -> String { private func resolveChannelDetailTitle(_ id: String) -> String {
switch id { if let detail = self.store.snapshot?.channelDetailLabels?[id], !detail.isEmpty {
case "whatsapp": "WhatsApp Web" return detail
case "telegram": "Telegram Bot"
case "discord": "Discord Bot"
case "slack": "Slack Bot"
case "signal": "Signal REST"
case "imessage": "iMessage"
case "bluebubbles": "BlueBubbles"
default: self.resolveChannelTitle(id)
} }
return self.resolveChannelTitle(id)
} }
private func resolveChannelSystemImage(_ id: String) -> String { private func resolveChannelSystemImage(_ id: String) -> String {
switch id { if let symbol = self.store.snapshot?.channelSystemImages?[id], !symbol.isEmpty {
case "whatsapp": "message" return symbol
case "telegram": "paperplane"
case "discord": "bubble.left.and.bubble.right"
case "slack": "number"
case "signal": "antenna.radiowaves.left.and.right"
case "imessage": "message.fill"
case "bluebubbles": "bubble.left.and.text.bubble.right"
default: "message"
} }
return "message"
} }
private func channelStatusDictionary(_ id: String) -> [String: AnyCodable]? { private func channelStatusDictionary(_ id: String) -> [String: AnyCodable]? {

View File

@@ -156,6 +156,8 @@ struct ChannelsStatusSnapshot: Codable {
let ts: Double let ts: Double
let channelOrder: [String] let channelOrder: [String]
let channelLabels: [String: String] let channelLabels: [String: String]
let channelDetailLabels: [String: String]? = nil
let channelSystemImages: [String: String]? = nil
let channels: [String: AnyCodable] let channels: [String: AnyCodable]
let channelAccounts: [String: [ChannelAccountSnapshot]] let channelAccounts: [String: [ChannelAccountSnapshot]]
let channelDefaultAccountId: [String: String] let channelDefaultAccountId: [String: String]

View File

@@ -42,7 +42,8 @@ extension CronJobEditor {
self.thinking = thinking ?? "" self.thinking = thinking ?? ""
self.timeoutSeconds = timeoutSeconds.map(String.init) ?? "" self.timeoutSeconds = timeoutSeconds.map(String.init) ?? ""
self.deliver = deliver ?? false self.deliver = deliver ?? false
self.channel = GatewayAgentChannel(raw: channel) let trimmed = (channel ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
self.channel = trimmed.isEmpty ? "last" : trimmed
self.to = to ?? "" self.to = to ?? ""
self.bestEffortDeliver = bestEffortDeliver ?? false self.bestEffortDeliver = bestEffortDeliver ?? false
} }
@@ -210,7 +211,8 @@ extension CronJobEditor {
if let n = Int(self.timeoutSeconds), n > 0 { payload["timeoutSeconds"] = n } if let n = Int(self.timeoutSeconds), n > 0 { payload["timeoutSeconds"] = n }
payload["deliver"] = self.deliver payload["deliver"] = self.deliver
if self.deliver { if self.deliver {
payload["channel"] = self.channel.rawValue let trimmed = self.channel.trimmingCharacters(in: .whitespacesAndNewlines)
payload["channel"] = trimmed.isEmpty ? "last" : trimmed
let to = self.to.trimmingCharacters(in: .whitespacesAndNewlines) let to = self.to.trimmingCharacters(in: .whitespacesAndNewlines)
if !to.isEmpty { payload["to"] = to } if !to.isEmpty { payload["to"] = to }
payload["bestEffortDeliver"] = self.bestEffortDeliver payload["bestEffortDeliver"] = self.bestEffortDeliver

View File

@@ -14,7 +14,7 @@ extension CronJobEditor {
self.payloadKind = .agentTurn self.payloadKind = .agentTurn
self.agentMessage = "Run diagnostic" self.agentMessage = "Run diagnostic"
self.deliver = true self.deliver = true
self.channel = .last self.channel = "last"
self.to = "+15551230000" self.to = "+15551230000"
self.thinking = "low" self.thinking = "low"
self.timeoutSeconds = "90" self.timeoutSeconds = "90"

View File

@@ -1,10 +1,12 @@
import ClawdbotProtocol import ClawdbotProtocol
import Observation
import SwiftUI import SwiftUI
struct CronJobEditor: View { struct CronJobEditor: View {
let job: CronJob? let job: CronJob?
@Binding var isSaving: Bool @Binding var isSaving: Bool
@Binding var error: String? @Binding var error: String?
@Bindable var channelsStore: ChannelsStore
let onCancel: () -> Void let onCancel: () -> Void
let onSave: ([String: AnyCodable]) -> Void let onSave: ([String: AnyCodable]) -> Void
@@ -45,13 +47,30 @@ struct CronJobEditor: View {
@State var systemEventText: String = "" @State var systemEventText: String = ""
@State var agentMessage: String = "" @State var agentMessage: String = ""
@State var deliver: Bool = false @State var deliver: Bool = false
@State var channel: GatewayAgentChannel = .last @State var channel: String = "last"
@State var to: String = "" @State var to: String = ""
@State var thinking: String = "" @State var thinking: String = ""
@State var timeoutSeconds: String = "" @State var timeoutSeconds: String = ""
@State var bestEffortDeliver: Bool = false @State var bestEffortDeliver: Bool = false
@State var postPrefix: String = "Cron" @State var postPrefix: String = "Cron"
var channelOptions: [String] {
let snapshot = self.channelsStore.snapshot
let ordered = snapshot?.channelOrder ?? []
var options = ["last"] + ordered
let trimmed = self.channel.trimmingCharacters(in: .whitespacesAndNewlines)
if !trimmed.isEmpty, !options.contains(trimmed) {
options.append(trimmed)
}
var seen = Set<String>()
return options.filter { seen.insert($0).inserted }
}
func channelLabel(for id: String) -> String {
if id == "last" { return "last" }
return self.channelsStore.snapshot?.channelLabels[id] ?? id
}
var body: some View { var body: some View {
VStack(alignment: .leading, spacing: 16) { VStack(alignment: .leading, spacing: 16) {
VStack(alignment: .leading, spacing: 6) { VStack(alignment: .leading, spacing: 6) {
@@ -333,14 +352,9 @@ struct CronJobEditor: View {
GridRow { GridRow {
self.gridLabel("Channel") self.gridLabel("Channel")
Picker("", selection: self.$channel) { Picker("", selection: self.$channel) {
Text("last").tag(GatewayAgentChannel.last) ForEach(self.channelOptions, id: \.self) { channel in
Text("whatsapp").tag(GatewayAgentChannel.whatsapp) Text(self.channelLabel(for: channel)).tag(channel)
Text("telegram").tag(GatewayAgentChannel.telegram) }
Text("discord").tag(GatewayAgentChannel.discord)
Text("slack").tag(GatewayAgentChannel.slack)
Text("signal").tag(GatewayAgentChannel.signal)
Text("imessage").tag(GatewayAgentChannel.imessage)
Text("bluebubbles").tag(GatewayAgentChannel.bluebubbles)
} }
.labelsHidden() .labelsHidden()
.pickerStyle(.segmented) .pickerStyle(.segmented)

View File

@@ -8,13 +8,20 @@ extension CronSettings {
self.content self.content
Spacer(minLength: 0) Spacer(minLength: 0)
} }
.onAppear { self.store.start() } .onAppear {
.onDisappear { self.store.stop() } self.store.start()
self.channelsStore.start()
}
.onDisappear {
self.store.stop()
self.channelsStore.stop()
}
.sheet(isPresented: self.$showEditor) { .sheet(isPresented: self.$showEditor) {
CronJobEditor( CronJobEditor(
job: self.editingJob, job: self.editingJob,
isSaving: self.$isSaving, isSaving: self.$isSaving,
error: self.$editorError, error: self.$editorError,
channelsStore: self.channelsStore,
onCancel: { onCancel: {
self.showEditor = false self.showEditor = false
self.editingJob = nil self.editingJob = nil

View File

@@ -47,7 +47,7 @@ struct CronSettings_Previews: PreviewProvider {
durationMs: 1234, durationMs: 1234,
nextRunAtMs: nil), nextRunAtMs: nil),
] ]
return CronSettings(store: store) return CronSettings(store: store, channelsStore: ChannelsStore(isPreview: true))
.frame(width: SettingsTab.windowWidth, height: SettingsTab.windowHeight) .frame(width: SettingsTab.windowWidth, height: SettingsTab.windowHeight)
} }
} }
@@ -103,7 +103,7 @@ extension CronSettings {
store.selectedJobId = job.id store.selectedJobId = job.id
store.runEntries = [run] store.runEntries = [run]
let view = CronSettings(store: store) let view = CronSettings(store: store, channelsStore: ChannelsStore(isPreview: true))
_ = view.body _ = view.body
_ = view.jobRow(job) _ = view.jobRow(job)
_ = view.jobContextMenu(job) _ = view.jobContextMenu(job)

View File

@@ -3,13 +3,15 @@ import SwiftUI
struct CronSettings: View { struct CronSettings: View {
@Bindable var store: CronJobsStore @Bindable var store: CronJobsStore
@Bindable var channelsStore: ChannelsStore
@State var showEditor = false @State var showEditor = false
@State var editingJob: CronJob? @State var editingJob: CronJob?
@State var editorError: String? @State var editorError: String?
@State var isSaving = false @State var isSaving = false
@State var confirmDelete: CronJob? @State var confirmDelete: CronJob?
init(store: CronJobsStore = .shared) { init(store: CronJobsStore = .shared, channelsStore: ChannelsStore = .shared) {
self.store = store self.store = store
self.channelsStore = channelsStore
} }
} }

View File

@@ -1312,6 +1312,8 @@ public struct ChannelsStatusResult: Codable, Sendable {
public let ts: Int public let ts: Int
public let channelorder: [String] public let channelorder: [String]
public let channellabels: [String: AnyCodable] public let channellabels: [String: AnyCodable]
public let channeldetaillabels: [String: AnyCodable]?
public let channelsystemimages: [String: AnyCodable]?
public let channels: [String: AnyCodable] public let channels: [String: AnyCodable]
public let channelaccounts: [String: AnyCodable] public let channelaccounts: [String: AnyCodable]
public let channeldefaultaccountid: [String: AnyCodable] public let channeldefaultaccountid: [String: AnyCodable]
@@ -1320,6 +1322,8 @@ public struct ChannelsStatusResult: Codable, Sendable {
ts: Int, ts: Int,
channelorder: [String], channelorder: [String],
channellabels: [String: AnyCodable], channellabels: [String: AnyCodable],
channeldetaillabels: [String: AnyCodable]?,
channelsystemimages: [String: AnyCodable]?,
channels: [String: AnyCodable], channels: [String: AnyCodable],
channelaccounts: [String: AnyCodable], channelaccounts: [String: AnyCodable],
channeldefaultaccountid: [String: AnyCodable] channeldefaultaccountid: [String: AnyCodable]
@@ -1327,6 +1331,8 @@ public struct ChannelsStatusResult: Codable, Sendable {
self.ts = ts self.ts = ts
self.channelorder = channelorder self.channelorder = channelorder
self.channellabels = channellabels self.channellabels = channellabels
self.channeldetaillabels = channeldetaillabels
self.channelsystemimages = channelsystemimages
self.channels = channels self.channels = channels
self.channelaccounts = channelaccounts self.channelaccounts = channelaccounts
self.channeldefaultaccountid = channeldefaultaccountid self.channeldefaultaccountid = channeldefaultaccountid
@@ -1335,6 +1341,8 @@ public struct ChannelsStatusResult: Codable, Sendable {
case ts case ts
case channelorder = "channelOrder" case channelorder = "channelOrder"
case channellabels = "channelLabels" case channellabels = "channelLabels"
case channeldetaillabels = "channelDetailLabels"
case channelsystemimages = "channelSystemImages"
case channels case channels
case channelaccounts = "channelAccounts" case channelaccounts = "channelAccounts"
case channeldefaultaccountid = "channelDefaultAccountId" case channeldefaultaccountid = "channelDefaultAccountId"

View File

@@ -375,6 +375,8 @@ Notes:
- Put config under `channels.<id>` (not `plugins.entries`). - Put config under `channels.<id>` (not `plugins.entries`).
- `meta.label` is used for labels in CLI/UI lists. - `meta.label` is used for labels in CLI/UI lists.
- `meta.aliases` adds alternate ids for normalization and CLI inputs. - `meta.aliases` adds alternate ids for normalization and CLI inputs.
- `meta.preferOver` lists channel ids to skip auto-enable when both are configured.
- `meta.detailLabel` and `meta.systemImage` let UIs show richer channel labels/icons.
### Write a new messaging channel (stepbystep) ### Write a new messaging channel (stepbystep)
@@ -388,6 +390,8 @@ Model provider docs live under `/providers/*`.
2) Define the channel metadata 2) Define the channel metadata
- `meta.label`, `meta.selectionLabel`, `meta.docsPath`, `meta.blurb` control CLI/UI lists. - `meta.label`, `meta.selectionLabel`, `meta.docsPath`, `meta.blurb` control CLI/UI lists.
- `meta.docsPath` should point at a docs page like `/channels/<id>`. - `meta.docsPath` should point at a docs page like `/channels/<id>`.
- `meta.preferOver` lets a plugin replace another channel (auto-enable prefers it).
- `meta.detailLabel` and `meta.systemImage` are used by UIs for detail text/icons.
3) Implement the required adapters 3) Implement the required adapters
- `config.listAccountIds` + `config.resolveAccount` - `config.listAccountIds` + `config.resolveAccount`

View File

@@ -9,9 +9,17 @@
"id": "bluebubbles", "id": "bluebubbles",
"label": "BlueBubbles", "label": "BlueBubbles",
"selectionLabel": "BlueBubbles (macOS app)", "selectionLabel": "BlueBubbles (macOS app)",
"detailLabel": "BlueBubbles",
"docsPath": "/channels/bluebubbles", "docsPath": "/channels/bluebubbles",
"docsLabel": "bluebubbles", "docsLabel": "bluebubbles",
"blurb": "iMessage via the BlueBubbles mac app + REST API.", "blurb": "iMessage via the BlueBubbles mac app + REST API.",
"aliases": [
"bb"
],
"preferOver": [
"imessage"
],
"systemImage": "bubble.left.and.text.bubble.right",
"order": 75 "order": 75
}, },
"install": { "install": {

View File

@@ -6,10 +6,10 @@ import {
DEFAULT_ACCOUNT_ID, DEFAULT_ACCOUNT_ID,
deleteAccountFromConfigSection, deleteAccountFromConfigSection,
formatPairingApproveHint, formatPairingApproveHint,
getChatChannelMeta,
migrateBaseNameToDefaultAccount, migrateBaseNameToDefaultAccount,
normalizeAccountId, normalizeAccountId,
PAIRING_APPROVED_MESSAGE, PAIRING_APPROVED_MESSAGE,
resolveBlueBubblesGroupRequireMention,
setAccountEnabledInConfigSection, setAccountEnabledInConfigSection,
} from "clawdbot/plugin-sdk"; } from "clawdbot/plugin-sdk";
@@ -32,11 +32,18 @@ import { monitorBlueBubblesProvider, resolveWebhookPathFromConfig } from "./moni
import { blueBubblesOnboardingAdapter } from "./onboarding.js"; import { blueBubblesOnboardingAdapter } from "./onboarding.js";
import { sendBlueBubblesMedia } from "./media-send.js"; import { sendBlueBubblesMedia } from "./media-send.js";
// Use core registry meta for consistency (Gate A: core registry).
// BlueBubbles is positioned before imessage per Gate C preference.
const meta = { const meta = {
...getChatChannelMeta("bluebubbles"), id: "bluebubbles",
label: "BlueBubbles",
selectionLabel: "BlueBubbles (macOS app)",
detailLabel: "BlueBubbles",
docsPath: "/channels/bluebubbles",
docsLabel: "bluebubbles",
blurb: "iMessage via the BlueBubbles mac app + REST API.",
systemImage: "bubble.left.and.text.bubble.right",
aliases: ["bb"],
order: 75, order: 75,
preferOver: ["imessage"],
}; };
export const bluebubblesPlugin: ChannelPlugin<ResolvedBlueBubblesAccount> = { export const bluebubblesPlugin: ChannelPlugin<ResolvedBlueBubblesAccount> = {
@@ -52,6 +59,16 @@ export const bluebubblesPlugin: ChannelPlugin<ResolvedBlueBubblesAccount> = {
effects: true, effects: true,
groupManagement: true, groupManagement: true,
}, },
groups: {
resolveRequireMention: resolveBlueBubblesGroupRequireMention,
},
threading: {
buildToolContext: ({ context, hasRepliedRef }) => ({
currentChannelId: context.To?.trim() || undefined,
currentThreadTs: context.ReplyToId,
hasRepliedRef,
}),
},
reload: { configPrefixes: ["channels.bluebubbles"] }, reload: { configPrefixes: ["channels.bluebubbles"] },
configSchema: buildChannelConfigSchema(BlueBubblesConfigSchema), configSchema: buildChannelConfigSchema(BlueBubblesConfigSchema),
onboarding: blueBubblesOnboardingAdapter, onboarding: blueBubblesOnboardingAdapter,

View File

@@ -10,6 +10,24 @@
"clawdbot": { "clawdbot": {
"extensions": [ "extensions": [
"./index.ts" "./index.ts"
] ],
"channel": {
"id": "zalouser",
"label": "Zalo Personal",
"selectionLabel": "Zalo (Personal Account)",
"docsPath": "/channels/zalouser",
"docsLabel": "zalouser",
"blurb": "Zalo personal account via QR code login.",
"aliases": [
"zlu"
],
"order": 85,
"quickstartAllowFrom": true
},
"install": {
"npmSpec": "@clawdbot/zalouser",
"localPath": "extensions/zalouser",
"defaultChoice": "npm"
}
} }
} }

View File

@@ -9,7 +9,6 @@ import { resolveWhatsAppAccount } from "../web/accounts.js";
import { normalizeWhatsAppTarget } from "../whatsapp/normalize.js"; import { normalizeWhatsAppTarget } from "../whatsapp/normalize.js";
import { requireActivePluginRegistry } from "../plugins/runtime.js"; import { requireActivePluginRegistry } from "../plugins/runtime.js";
import { import {
resolveBlueBubblesGroupRequireMention,
resolveDiscordGroupRequireMention, resolveDiscordGroupRequireMention,
resolveIMessageGroupRequireMention, resolveIMessageGroupRequireMention,
resolveSlackGroupRequireMention, resolveSlackGroupRequireMention,
@@ -68,27 +67,6 @@ const formatLower = (allowFrom: Array<string | number>) =>
const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); 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. // Channel docks: lightweight channel metadata/behavior for shared code paths.
// //
// Rules: // 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: { imessage: {
id: "imessage", id: "imessage",
capabilities: { capabilities: {

View File

@@ -33,17 +33,21 @@ function toChannelMeta(params: {
const label = params.channel.label?.trim(); const label = params.channel.label?.trim();
if (!label) return null; if (!label) return null;
const selectionLabel = params.channel.selectionLabel?.trim() || label; const selectionLabel = params.channel.selectionLabel?.trim() || label;
const detailLabel = params.channel.detailLabel?.trim();
const docsPath = params.channel.docsPath?.trim() || `/channels/${params.id}`; const docsPath = params.channel.docsPath?.trim() || `/channels/${params.id}`;
const blurb = params.channel.blurb?.trim() || ""; const blurb = params.channel.blurb?.trim() || "";
const systemImage = params.channel.systemImage?.trim();
return { return {
id: params.id, id: params.id,
label, label,
selectionLabel, selectionLabel,
...(detailLabel ? { detailLabel } : {}),
docsPath, docsPath,
docsLabel: params.channel.docsLabel?.trim() || undefined, docsLabel: params.channel.docsLabel?.trim() || undefined,
blurb, blurb,
...(params.channel.aliases ? { aliases: params.channel.aliases } : {}), ...(params.channel.aliases ? { aliases: params.channel.aliases } : {}),
...(params.channel.preferOver ? { preferOver: params.channel.preferOver } : {}),
...(params.channel.order !== undefined ? { order: params.channel.order } : {}), ...(params.channel.order !== undefined ? { order: params.channel.order } : {}),
...(params.channel.selectionDocsPrefix ...(params.channel.selectionDocsPrefix
? { selectionDocsPrefix: params.channel.selectionDocsPrefix } ? { selectionDocsPrefix: params.channel.selectionDocsPrefix }
@@ -52,6 +56,7 @@ function toChannelMeta(params: {
? { selectionDocsOmitLabel: params.channel.selectionDocsOmitLabel } ? { selectionDocsOmitLabel: params.channel.selectionDocsOmitLabel }
: {}), : {}),
...(params.channel.selectionExtras ? { selectionExtras: params.channel.selectionExtras } : {}), ...(params.channel.selectionExtras ? { selectionExtras: params.channel.selectionExtras } : {}),
...(systemImage ? { systemImage } : {}),
...(params.channel.showConfigured !== undefined ...(params.channel.showConfigured !== undefined
? { showConfigured: params.channel.showConfigured } ? { showConfigured: params.channel.showConfigured }
: {}), : {}),

View File

@@ -74,10 +74,13 @@ export type ChannelMeta = {
selectionDocsPrefix?: string; selectionDocsPrefix?: string;
selectionDocsOmitLabel?: boolean; selectionDocsOmitLabel?: boolean;
selectionExtras?: string[]; selectionExtras?: string[];
detailLabel?: string;
systemImage?: string;
showConfigured?: boolean; showConfigured?: boolean;
quickstartAllowFrom?: boolean; quickstartAllowFrom?: boolean;
forceAccountBinding?: boolean; forceAccountBinding?: boolean;
preferSessionLookupForAnnounceTarget?: boolean; preferSessionLookupForAnnounceTarget?: boolean;
preferOver?: string[];
}; };
export type ChannelAccountSnapshot = { export type ChannelAccountSnapshot = {

View File

@@ -4,15 +4,12 @@ import { requireActivePluginRegistry } from "../plugins/runtime.js";
// Channel docking: add new core channels here (order + meta + aliases), then // Channel docking: add new core channels here (order + meta + aliases), then
// register the plugin in its extension entrypoint and keep protocol IDs in sync. // 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 = [ export const CHAT_CHANNEL_ORDER = [
"telegram", "telegram",
"whatsapp", "whatsapp",
"discord", "discord",
"slack", "slack",
"signal", "signal",
"bluebubbles",
"imessage", "imessage",
] as const; ] as const;
@@ -31,9 +28,11 @@ const CHAT_CHANNEL_META: Record<ChatChannelId, ChannelMeta> = {
id: "telegram", id: "telegram",
label: "Telegram", label: "Telegram",
selectionLabel: "Telegram (Bot API)", selectionLabel: "Telegram (Bot API)",
detailLabel: "Telegram Bot",
docsPath: "/channels/telegram", docsPath: "/channels/telegram",
docsLabel: "telegram", docsLabel: "telegram",
blurb: "simplest way to get started — register a bot with @BotFather and get going.", blurb: "simplest way to get started — register a bot with @BotFather and get going.",
systemImage: "paperplane",
selectionDocsPrefix: "", selectionDocsPrefix: "",
selectionDocsOmitLabel: true, selectionDocsOmitLabel: true,
selectionExtras: [WEBSITE_URL], selectionExtras: [WEBSITE_URL],
@@ -42,55 +41,56 @@ const CHAT_CHANNEL_META: Record<ChatChannelId, ChannelMeta> = {
id: "whatsapp", id: "whatsapp",
label: "WhatsApp", label: "WhatsApp",
selectionLabel: "WhatsApp (QR link)", selectionLabel: "WhatsApp (QR link)",
detailLabel: "WhatsApp Web",
docsPath: "/channels/whatsapp", docsPath: "/channels/whatsapp",
docsLabel: "whatsapp", docsLabel: "whatsapp",
blurb: "works with your own number; recommend a separate phone + eSIM.", blurb: "works with your own number; recommend a separate phone + eSIM.",
systemImage: "message",
}, },
discord: { discord: {
id: "discord", id: "discord",
label: "Discord", label: "Discord",
selectionLabel: "Discord (Bot API)", selectionLabel: "Discord (Bot API)",
detailLabel: "Discord Bot",
docsPath: "/channels/discord", docsPath: "/channels/discord",
docsLabel: "discord", docsLabel: "discord",
blurb: "very well supported right now.", blurb: "very well supported right now.",
systemImage: "bubble.left.and.bubble.right",
}, },
slack: { slack: {
id: "slack", id: "slack",
label: "Slack", label: "Slack",
selectionLabel: "Slack (Socket Mode)", selectionLabel: "Slack (Socket Mode)",
detailLabel: "Slack Bot",
docsPath: "/channels/slack", docsPath: "/channels/slack",
docsLabel: "slack", docsLabel: "slack",
blurb: "supported (Socket Mode).", blurb: "supported (Socket Mode).",
systemImage: "number",
}, },
signal: { signal: {
id: "signal", id: "signal",
label: "Signal", label: "Signal",
selectionLabel: "Signal (signal-cli)", selectionLabel: "Signal (signal-cli)",
detailLabel: "Signal REST",
docsPath: "/channels/signal", docsPath: "/channels/signal",
docsLabel: "signal", docsLabel: "signal",
blurb: 'signal-cli linked device; more setup (David Reagans: "Hop on Discord.").', blurb: 'signal-cli linked device; more setup (David Reagans: "Hop on Discord.").',
}, systemImage: "antenna.radiowaves.left.and.right",
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.",
}, },
imessage: { imessage: {
id: "imessage", id: "imessage",
label: "iMessage", label: "iMessage",
selectionLabel: "iMessage (imsg)", selectionLabel: "iMessage (imsg)",
detailLabel: "iMessage",
docsPath: "/channels/imessage", docsPath: "/channels/imessage",
docsLabel: "imessage", docsLabel: "imessage",
blurb: "this is still a work in progress.", blurb: "this is still a work in progress.",
systemImage: "message.fill",
}, },
}; };
export const CHAT_CHANNEL_ALIASES: Record<string, ChatChannelId> = { export const CHAT_CHANNEL_ALIASES: Record<string, ChatChannelId> = {
imsg: "imessage", imsg: "imessage",
bb: "bluebubbles",
}; };
const normalizeChannelKey = (raw?: string | null): string | undefined => { const normalizeChannelKey = (raw?: string | null): string | undefined => {

View File

@@ -1,7 +1,8 @@
import type { ChannelId } from "../channels/plugins/types.js";
import { normalizeAccountId } from "../routing/session-key.js"; import { normalizeAccountId } from "../routing/session-key.js";
import type { ClawdbotConfig } from "./config.js"; import type { ClawdbotConfig } from "./config.js";
export type GroupPolicyChannel = "whatsapp" | "telegram" | "imessage" | "bluebubbles"; export type GroupPolicyChannel = ChannelId;
export type ChannelGroupConfig = { export type ChannelGroupConfig = {
requireMention?: boolean; requireMention?: boolean;

View File

@@ -60,7 +60,7 @@ describe("applyPluginAutoEnable", () => {
expect(result.changes).toEqual([]); expect(result.changes).toEqual([]);
}); });
describe("BlueBubbles over imessage prioritization", () => { describe("preferOver channel prioritization", () => {
it("prefers bluebubbles: skips imessage auto-enable when both are configured", () => { it("prefers bluebubbles: skips imessage auto-enable when both are configured", () => {
const result = applyPluginAutoEnable({ const result = applyPluginAutoEnable({
config: { config: {

View File

@@ -1,6 +1,10 @@
import type { ClawdbotConfig } from "./config.js"; 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 { normalizeProviderId } from "../agents/model-selection.js";
import { listChatChannels } from "../channels/registry.js";
import { hasAnyWhatsAppAuth } from "../web/accounts.js"; import { hasAnyWhatsAppAuth } from "../web/accounts.js";
type PluginEnableChange = { type PluginEnableChange = {
@@ -13,6 +17,13 @@ export type PluginAutoEnableResult = {
changes: string[]; 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 }> = [ const PROVIDER_PLUGIN_IDS: Array<{ pluginId: string; providerId: string }> = [
{ pluginId: "google-antigravity-auth", providerId: "google-antigravity" }, { pluginId: "google-antigravity-auth", providerId: "google-antigravity" },
{ pluginId: "google-gemini-cli-auth", providerId: "google-gemini-cli" }, { pluginId: "google-gemini-cli-auth", providerId: "google-gemini-cli" },
@@ -226,10 +237,7 @@ function resolveConfiguredPlugins(
env: NodeJS.ProcessEnv, env: NodeJS.ProcessEnv,
): PluginEnableChange[] { ): PluginEnableChange[] {
const changes: PluginEnableChange[] = []; const changes: PluginEnableChange[] = [];
const channelIds = new Set<string>(); const channelIds = new Set(CHANNEL_PLUGIN_IDS);
for (const meta of listChatChannels()) {
channelIds.add(meta.id);
}
const configuredChannels = cfg.channels as Record<string, unknown> | undefined; const configuredChannels = cfg.channels as Record<string, unknown> | undefined;
if (configuredChannels && typeof configuredChannels === "object") { if (configuredChannels && typeof configuredChannels === "object") {
for (const key of Object.keys(configuredChannels)) { 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); return Array.isArray(deny) && deny.includes(pluginId);
} }
/** function resolvePreferredOverIds(pluginId: string): string[] {
* When both BlueBubbles and iMessage are configured, prefer BlueBubbles: const normalized = normalizeChatChannelId(pluginId);
* skip auto-enabling iMessage unless BlueBubbles is explicitly disabled/denied. if (normalized) {
* This is non-destructive: if iMessage is already enabled, it won't be touched. return getChatChannelMeta(normalized).preferOver ?? [];
*/ }
function shouldSkipImsgForBlueBubbles( const catalogEntry = getChannelPluginCatalogEntry(pluginId);
return catalogEntry?.meta.preferOver ?? [];
}
function shouldSkipPreferredPluginAutoEnable(
cfg: ClawdbotConfig, cfg: ClawdbotConfig,
pluginId: string, entry: PluginEnableChange,
configured: PluginEnableChange[], configured: PluginEnableChange[],
): boolean { ): boolean {
if (pluginId !== "imessage") return false; for (const other of configured) {
const blueBubblesConfigured = configured.some((e) => e.pluginId === "bluebubbles"); if (other.pluginId === entry.pluginId) continue;
if (!blueBubblesConfigured) return false; if (isPluginDenied(cfg, other.pluginId)) continue;
// Skip imessage auto-enable if bluebubbles is configured and not blocked if (isPluginExplicitlyDisabled(cfg, other.pluginId)) continue;
return !isPluginExplicitlyDisabled(cfg, "bluebubbles") && !isPluginDenied(cfg, "bluebubbles"); const preferOver = resolvePreferredOverIds(other.pluginId);
if (preferOver.includes(entry.pluginId)) {
return true;
}
}
return false;
} }
function ensureAllowlisted(cfg: ClawdbotConfig, pluginId: string): ClawdbotConfig { function ensureAllowlisted(cfg: ClawdbotConfig, pluginId: string): ClawdbotConfig {
@@ -334,8 +351,7 @@ export function applyPluginAutoEnable(params: {
for (const entry of configured) { for (const entry of configured) {
if (isPluginDenied(next, entry.pluginId)) continue; if (isPluginDenied(next, entry.pluginId)) continue;
if (isPluginExplicitlyDisabled(next, entry.pluginId)) continue; if (isPluginExplicitlyDisabled(next, entry.pluginId)) continue;
// Prefer BlueBubbles over imessage: skip imsg auto-enable if bluebubbles is configured if (shouldSkipPreferredPluginAutoEnable(next, entry, configured)) continue;
if (shouldSkipImsgForBlueBubbles(next, entry.pluginId, configured)) continue;
const allow = next.plugins?.allow; const allow = next.plugins?.allow;
const allowMissing = Array.isArray(allow) && !allow.includes(entry.pluginId); const allowMissing = Array.isArray(allow) && !allow.includes(entry.pluginId);
const alreadyEnabled = next.plugins?.entries?.[entry.pluginId]?.enabled === true; const alreadyEnabled = next.plugins?.entries?.[entry.pluginId]?.enabled === true;

View File

@@ -60,6 +60,8 @@ export const ChannelsStatusResultSchema = Type.Object(
ts: Type.Integer({ minimum: 0 }), ts: Type.Integer({ minimum: 0 }),
channelOrder: Type.Array(NonEmptyString), channelOrder: Type.Array(NonEmptyString),
channelLabels: Type.Record(NonEmptyString, 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()), channels: Type.Record(NonEmptyString, Type.Unknown()),
channelAccounts: Type.Record(NonEmptyString, Type.Array(ChannelAccountSnapshotSchema)), channelAccounts: Type.Record(NonEmptyString, Type.Array(ChannelAccountSnapshotSchema)),
channelDefaultAccountId: Type.Record(NonEmptyString, NonEmptyString), channelDefaultAccountId: Type.Record(NonEmptyString, NonEmptyString),

View File

@@ -188,10 +188,24 @@ export const channelsHandlers: GatewayRequestHandlers = {
return { accounts, defaultAccountId, defaultAccount, resolvedAccounts }; 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> = { const payload: Record<string, unknown> = {
ts: Date.now(), ts: Date.now(),
channelOrder: plugins.map((plugin) => plugin.id), 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>, channels: {} as Record<string, unknown>,
channelAccounts: {} as Record<string, unknown>, channelAccounts: {} as Record<string, unknown>,
channelDefaultAccountId: {} as Record<string, unknown>, channelDefaultAccountId: {} as Record<string, unknown>,

View File

@@ -95,11 +95,14 @@ export type PluginPackageChannel = {
id?: string; id?: string;
label?: string; label?: string;
selectionLabel?: string; selectionLabel?: string;
detailLabel?: string;
docsPath?: string; docsPath?: string;
docsLabel?: string; docsLabel?: string;
blurb?: string; blurb?: string;
order?: number; order?: number;
aliases?: string[]; aliases?: string[];
preferOver?: string[];
systemImage?: string;
selectionDocsPrefix?: string; selectionDocsPrefix?: string;
selectionDocsOmitLabel?: boolean; selectionDocsOmitLabel?: boolean;
selectionExtras?: string[]; selectionExtras?: string[];

View File

@@ -264,6 +264,8 @@ export function renderApp(state: AppViewState) {
error: state.cronError, error: state.cronError,
busy: state.cronBusy, busy: state.cronBusy,
form: state.cronForm, form: state.cronForm,
channels: state.channelsSnapshot?.channelOrder ?? [],
channelLabels: state.channelsSnapshot?.channelLabels ?? {},
runsJobId: state.cronRunsJobId, runsJobId: state.cronRunsJobId,
runs: state.cronRuns, runs: state.cronRuns,
onFormChange: (patch) => (state.cronForm = { ...state.cronForm, ...patch }), onFormChange: (patch) => (state.cronForm = { ...state.cronForm, ...patch }),

View File

@@ -307,6 +307,7 @@ export async function loadChannelsTab(host: SettingsHost) {
export async function loadCron(host: SettingsHost) { export async function loadCron(host: SettingsHost) {
await Promise.all([ await Promise.all([
loadChannels(host as unknown as ClawdbotApp, false),
loadCronStatus(host as unknown as ClawdbotApp), loadCronStatus(host as unknown as ClawdbotApp),
loadCronJobs(host as unknown as ClawdbotApp), loadCronJobs(host as unknown as ClawdbotApp),
]); ]);

View File

@@ -73,16 +73,7 @@ export function buildCronPayload(form: CronFormState) {
kind: "agentTurn"; kind: "agentTurn";
message: string; message: string;
deliver?: boolean; deliver?: boolean;
channel?: channel?: string;
| "last"
| "whatsapp"
| "telegram"
| "discord"
| "slack"
| "signal"
| "imessage"
| "msteams"
| "bluebubbles";
to?: string; to?: string;
timeoutSeconds?: number; timeoutSeconds?: number;
} = { kind: "agentTurn", message }; } = { kind: "agentTurn", message };

View File

@@ -2,11 +2,15 @@ export type ChannelsStatusSnapshot = {
ts: number; ts: number;
channelOrder: string[]; channelOrder: string[];
channelLabels: Record<string, string>; channelLabels: Record<string, string>;
channelDetailLabels?: Record<string, string>;
channelSystemImages?: Record<string, string>;
channels: Record<string, unknown>; channels: Record<string, unknown>;
channelAccounts: Record<string, ChannelAccountSnapshot[]>; channelAccounts: Record<string, ChannelAccountSnapshot[]>;
channelDefaultAccountId: Record<string, string>; channelDefaultAccountId: Record<string, string>;
}; };
export const CRON_CHANNEL_LAST = "last";
export type ChannelAccountSnapshot = { export type ChannelAccountSnapshot = {
accountId: string; accountId: string;
name?: string | null; name?: string | null;
@@ -324,16 +328,8 @@ export type CronPayload =
thinking?: string; thinking?: string;
timeoutSeconds?: number; timeoutSeconds?: number;
deliver?: boolean; deliver?: boolean;
provider?: channel?: string;
| "last" provider?: string;
| "whatsapp"
| "telegram"
| "discord"
| "slack"
| "signal"
| "imessage"
| "msteams"
| "bluebubbles";
to?: string; to?: string;
bestEffortDeliver?: boolean; bestEffortDeliver?: boolean;
}; };

View File

@@ -4,6 +4,8 @@ export type ChatQueueItem = {
createdAt: number; createdAt: number;
}; };
export const CRON_CHANNEL_LAST = "last";
export type CronFormState = { export type CronFormState = {
name: string; name: string;
description: string; description: string;
@@ -20,16 +22,7 @@ export type CronFormState = {
payloadKind: "systemEvent" | "agentTurn"; payloadKind: "systemEvent" | "agentTurn";
payloadText: string; payloadText: string;
deliver: boolean; deliver: boolean;
channel: channel: string;
| "last"
| "whatsapp"
| "telegram"
| "discord"
| "slack"
| "signal"
| "imessage"
| "msteams"
| "bluebubbles";
to: string; to: string;
timeoutSeconds: string; timeoutSeconds: string;
postToMainPrefix: string; postToMainPrefix: string;

View File

@@ -88,7 +88,7 @@ function resolveChannelOrder(snapshot: ChannelsStatusSnapshot | null): ChannelKe
if (snapshot?.channelOrder?.length) { if (snapshot?.channelOrder?.length) {
return snapshot.channelOrder; return snapshot.channelOrder;
} }
return ["whatsapp", "telegram", "discord", "slack", "signal", "imessage", "bluebubbles"]; return ["whatsapp", "telegram", "discord", "slack", "signal", "imessage"];
} }
function renderChannel( function renderChannel(

View File

@@ -27,6 +27,8 @@ function createProps(overrides: Partial<CronProps> = {}): CronProps {
error: null, error: null,
busy: false, busy: false,
form: { ...DEFAULT_CRON_FORM }, form: { ...DEFAULT_CRON_FORM },
channels: [],
channelLabels: {},
runsJobId: null, runsJobId: null,
runs: [], runs: [],
onFormChange: () => undefined, onFormChange: () => undefined,

View File

@@ -17,6 +17,8 @@ export type CronProps = {
error: string | null; error: string | null;
busy: boolean; busy: boolean;
form: CronFormState; form: CronFormState;
channels: string[];
channelLabels?: Record<string, string>;
runsJobId: string | null; runsJobId: string | null;
runs: CronRunLogEntry[]; runs: CronRunLogEntry[];
onFormChange: (patch: Partial<CronFormState>) => void; onFormChange: (patch: Partial<CronFormState>) => void;
@@ -28,7 +30,27 @@ export type CronProps = {
onLoadRuns: (jobId: string) => void; onLoadRuns: (jobId: string) => void;
}; };
function buildChannelOptions(props: CronProps): string[] {
const options = ["last", ...props.channels.filter(Boolean)];
const current = props.form.channel?.trim();
if (current && !options.includes(current)) {
options.push(current);
}
const seen = new Set<string>();
return options.filter((value) => {
if (seen.has(value)) return false;
seen.add(value);
return true;
});
}
function resolveChannelLabel(props: CronProps, channel: string): string {
if (channel === "last") return "last";
return props.channelLabels?.[channel] ?? channel;
}
export function renderCron(props: CronProps) { export function renderCron(props: CronProps) {
const channelOptions = buildChannelOptions(props);
return html` return html`
<section class="grid grid-cols-2"> <section class="grid grid-cols-2">
<div class="card"> <div class="card">
@@ -185,21 +207,18 @@ export function renderCron(props: CronProps) {
<label class="field"> <label class="field">
<span>Channel</span> <span>Channel</span>
<select <select
.value=${props.form.channel} .value=${props.form.channel || "last"}
@change=${(e: Event) => @change=${(e: Event) =>
props.onFormChange({ props.onFormChange({
channel: (e.target as HTMLSelectElement).value as CronFormState["channel"], channel: (e.target as HTMLSelectElement).value as CronFormState["channel"],
})} })}
> >
<option value="last">Last</option> ${channelOptions.map(
<option value="whatsapp">WhatsApp</option> (channel) =>
<option value="telegram">Telegram</option> html`<option value=${channel}>
<option value="discord">Discord</option> ${resolveChannelLabel(props, channel)}
<option value="slack">Slack</option> </option>`,
<option value="signal">Signal</option> )}
<option value="imessage">iMessage</option>
<option value="msteams">MS Teams</option>
<option value="bluebubbles">BlueBubbles</option>
</select> </select>
</label> </label>
<label class="field"> <label class="field">