refactor!: rename chat providers to channels

This commit is contained in:
Peter Steinberger
2026-01-13 06:16:43 +00:00
parent 0cd632ba84
commit 90342a4f3a
393 changed files with 8004 additions and 6737 deletions

View File

@@ -15,7 +15,7 @@ export type ResolvedSignalAccount = {
};
function listConfiguredAccountIds(cfg: ClawdbotConfig): string[] {
const accounts = cfg.signal?.accounts;
const accounts = cfg.channels?.signal?.accounts;
if (!accounts || typeof accounts !== "object") return [];
return Object.keys(accounts).filter(Boolean);
}
@@ -36,7 +36,7 @@ function resolveAccountConfig(
cfg: ClawdbotConfig,
accountId: string,
): SignalAccountConfig | undefined {
const accounts = cfg.signal?.accounts;
const accounts = cfg.channels?.signal?.accounts;
if (!accounts || typeof accounts !== "object") return undefined;
return accounts[accountId] as SignalAccountConfig | undefined;
}
@@ -45,7 +45,7 @@ function mergeSignalAccountConfig(
cfg: ClawdbotConfig,
accountId: string,
): SignalAccountConfig {
const { accounts: _ignored, ...base } = (cfg.signal ??
const { accounts: _ignored, ...base } = (cfg.channels?.signal ??
{}) as SignalAccountConfig & { accounts?: unknown };
const account = resolveAccountConfig(cfg, accountId) ?? {};
return { ...base, ...account };
@@ -56,7 +56,7 @@ export function resolveSignalAccount(params: {
accountId?: string | null;
}): ResolvedSignalAccount {
const accountId = normalizeAccountId(params.accountId);
const baseEnabled = params.cfg.signal?.enabled !== false;
const baseEnabled = params.cfg.channels?.signal?.enabled !== false;
const merged = mergeSignalAccountConfig(params.cfg, accountId);
const accountEnabled = merged.enabled !== false;
const enabled = baseEnabled && accountEnabled;

View File

@@ -34,9 +34,9 @@ vi.mock("./send.js", () => ({
}));
vi.mock("../pairing/pairing-store.js", () => ({
readProviderAllowFromStore: (...args: unknown[]) =>
readChannelAllowFromStore: (...args: unknown[]) =>
readAllowFromStoreMock(...args),
upsertProviderPairingRequest: (...args: unknown[]) =>
upsertChannelPairingRequest: (...args: unknown[]) =>
upsertPairingRequestMock(...args),
}));
@@ -65,7 +65,9 @@ beforeEach(() => {
resetInboundDedupe();
config = {
messages: { responsePrefix: "PFX" },
signal: { autoStart: false, dmPolicy: "open", allowFrom: ["*"] },
channels: {
signal: { autoStart: false, dmPolicy: "open", allowFrom: ["*"] },
},
};
sendMock.mockReset().mockResolvedValue(undefined);
replyMock.mockReset();
@@ -122,7 +124,15 @@ describe("monitorSignalProvider tool results", () => {
it("replies with pairing code when dmPolicy is pairing and no allowFrom is set", async () => {
config = {
...config,
signal: { autoStart: false, dmPolicy: "pairing", allowFrom: [] },
channels: {
...config.channels,
signal: {
...config.channels?.signal,
autoStart: false,
dmPolicy: "pairing",
allowFrom: [],
},
},
};
const abortController = new AbortController();
@@ -241,11 +251,15 @@ describe("monitorSignalProvider tool results", () => {
it("enqueues system events for reaction notifications", async () => {
config = {
...config,
signal: {
autoStart: false,
dmPolicy: "open",
allowFrom: ["*"],
reactionNotifications: "all",
channels: {
...config.channels,
signal: {
...config.channels?.signal,
autoStart: false,
dmPolicy: "open",
allowFrom: ["*"],
reactionNotifications: "all",
},
},
};
const abortController = new AbortController();
@@ -280,7 +294,7 @@ describe("monitorSignalProvider tool results", () => {
const route = resolveAgentRoute({
cfg: config as ClawdbotConfig,
provider: "signal",
channel: "signal",
accountId: "default",
peer: { kind: "dm", id: normalizeE164("+15550001111") },
});
@@ -293,12 +307,16 @@ describe("monitorSignalProvider tool results", () => {
it("notifies on own reactions when target includes uuid + phone", async () => {
config = {
...config,
signal: {
autoStart: false,
dmPolicy: "open",
allowFrom: ["*"],
account: "+15550002222",
reactionNotifications: "own",
channels: {
...config.channels,
signal: {
...config.channels?.signal,
autoStart: false,
dmPolicy: "open",
allowFrom: ["*"],
account: "+15550002222",
reactionNotifications: "own",
},
},
};
const abortController = new AbortController();
@@ -334,7 +352,7 @@ describe("monitorSignalProvider tool results", () => {
const route = resolveAgentRoute({
cfg: config as ClawdbotConfig,
provider: "signal",
channel: "signal",
accountId: "default",
peer: { kind: "dm", id: normalizeE164("+15550001111") },
});
@@ -386,7 +404,15 @@ describe("monitorSignalProvider tool results", () => {
it("does not resend pairing code when a request is already pending", async () => {
config = {
...config,
signal: { autoStart: false, dmPolicy: "pairing", allowFrom: [] },
channels: {
...config.channels,
signal: {
...config.channels?.signal,
autoStart: false,
dmPolicy: "pairing",
allowFrom: [],
},
},
};
const abortController = new AbortController();
upsertPairingRequestMock
@@ -432,7 +458,15 @@ describe("monitorSignalProvider tool results", () => {
it("pairs uuid-only senders with a uuid allowlist entry", async () => {
config = {
...config,
signal: { autoStart: false, dmPolicy: "pairing", allowFrom: [] },
channels: {
...config.channels,
signal: {
...config.channels?.signal,
autoStart: false,
dmPolicy: "pairing",
allowFrom: [],
},
},
};
const abortController = new AbortController();
const uuid = "123e4567-e89b-12d3-a456-426614174000";
@@ -465,7 +499,11 @@ describe("monitorSignalProvider tool results", () => {
expect(replyMock).not.toHaveBeenCalled();
expect(upsertPairingRequestMock).toHaveBeenCalledWith(
expect.objectContaining({ provider: "signal", id: `uuid:${uuid}` }),
expect.objectContaining({
channel: "signal",
id: `uuid:${uuid}`,
meta: expect.objectContaining({ name: "Ada" }),
}),
);
expect(sendMock).toHaveBeenCalledTimes(1);
expect(sendMock.mock.calls[0]?.[0]).toBe(`signal:${uuid}`);

View File

@@ -23,8 +23,8 @@ import { mediaKindFromMime } from "../media/constants.js";
import { saveMediaBuffer } from "../media/store.js";
import { buildPairingReply } from "../pairing/pairing-messages.js";
import {
readProviderAllowFromStore,
upsertProviderPairingRequest,
readChannelAllowFromStore,
upsertChannelPairingRequest,
} from "../pairing/pairing-store.js";
import { resolveAgentRoute } from "../routing/resolve-route.js";
import type { RuntimeEnv } from "../runtime.js";
@@ -462,7 +462,7 @@ export async function monitorSignalProvider(
const senderPeerId = resolveSignalPeerId(sender);
const route = resolveAgentRoute({
cfg,
provider: "signal",
channel: "signal",
accountId: accountInfo.accountId,
peer: {
kind: isGroup ? "group" : "dm",
@@ -510,7 +510,7 @@ export async function monitorSignalProvider(
const groupId = dataMessage.groupInfo?.groupId ?? undefined;
const groupName = dataMessage.groupInfo?.groupName ?? undefined;
const isGroup = Boolean(groupId);
const storeAllowFrom = await readProviderAllowFromStore("signal").catch(
const storeAllowFrom = await readChannelAllowFromStore("signal").catch(
() => [],
);
const effectiveDmAllow = [...allowFrom, ...storeAllowFrom];
@@ -525,8 +525,8 @@ export async function monitorSignalProvider(
if (!dmAllowed) {
if (dmPolicy === "pairing") {
const senderId = senderAllowId;
const { code, created } = await upsertProviderPairingRequest({
provider: "signal",
const { code, created } = await upsertChannelPairingRequest({
channel: "signal",
id: senderId,
meta: {
name: envelope.sourceName ?? undefined,
@@ -538,7 +538,7 @@ export async function monitorSignalProvider(
await sendMessageSignal(
`signal:${senderRecipient}`,
buildPairingReply({
provider: "signal",
channel: "signal",
idLine: senderIdLine,
code,
}),
@@ -627,7 +627,7 @@ export async function monitorSignalProvider(
? `${groupName ?? "Signal Group"} id:${groupId}`
: `${envelope.sourceName ?? senderDisplay} id:${senderDisplay}`;
const body = formatAgentEnvelope({
provider: "Signal",
channel: "Signal",
from: fromLabel,
timestamp: envelope.timestamp ?? undefined,
body: bodyText,
@@ -651,7 +651,7 @@ export async function monitorSignalProvider(
currentMessage: combinedBody,
formatEntry: (entry) =>
formatAgentEnvelope({
provider: "Signal",
channel: "Signal",
from: fromLabel,
timestamp: entry.timestamp,
body: `${entry.sender}: ${entry.body}${
@@ -663,7 +663,7 @@ export async function monitorSignalProvider(
const route = resolveAgentRoute({
cfg,
provider: "signal",
channel: "signal",
accountId: accountInfo.accountId,
peer: {
kind: isGroup ? "group" : "dm",
@@ -708,7 +708,7 @@ export async function monitorSignalProvider(
await updateLastRoute({
storePath,
sessionKey: route.mainSessionKey,
provider: "signal",
channel: "signal",
to: senderRecipient,
accountId: route.accountId,
});