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

@@ -1,30 +1,29 @@
import crypto from "node:crypto";
import fs from "node:fs";
import type { ClawdbotConfig } from "../../config/config.js";
import { resolveProviderDefaultAccountId } from "../../providers/plugins/helpers.js";
import { listProviderPlugins } from "../../providers/plugins/index.js";
import { resolveChannelDefaultAccountId } from "../../channels/plugins/helpers.js";
import { listChannelPlugins } from "../../channels/plugins/index.js";
import type {
ProviderAccountSnapshot,
ProviderId,
ProviderPlugin,
} from "../../providers/plugins/types.js";
ChannelAccountSnapshot,
ChannelId,
ChannelPlugin,
} from "../../channels/plugins/types.js";
import type { ClawdbotConfig } from "../../config/config.js";
import { formatAge } from "./format.js";
export type ProviderRow = {
id: ProviderId;
provider: string;
export type ChannelRow = {
id: ChannelId;
label: string;
enabled: boolean;
state: "ok" | "setup" | "warn" | "off";
detail: string;
};
type ProviderAccountRow = {
type ChannelAccountRow = {
accountId: string;
account: unknown;
enabled: boolean;
configured: boolean;
snapshot: ProviderAccountSnapshot;
snapshot: ChannelAccountSnapshot;
};
const asRecord = (value: unknown): Record<string, unknown> =>
@@ -81,7 +80,7 @@ const formatAccountLabel = (params: { accountId: string; name?: string }) => {
};
const resolveAccountEnabled = (
plugin: ProviderPlugin,
plugin: ChannelPlugin,
account: unknown,
cfg: ClawdbotConfig,
): boolean => {
@@ -91,7 +90,7 @@ const resolveAccountEnabled = (
};
const resolveAccountConfigured = async (
plugin: ProviderPlugin,
plugin: ChannelPlugin,
account: unknown,
cfg: ClawdbotConfig,
): Promise<boolean> => {
@@ -103,13 +102,13 @@ const resolveAccountConfigured = async (
};
const buildAccountSnapshot = (params: {
plugin: ProviderPlugin;
plugin: ChannelPlugin;
account: unknown;
cfg: ClawdbotConfig;
accountId: string;
enabled: boolean;
configured: boolean;
}): ProviderAccountSnapshot => {
}): ChannelAccountSnapshot => {
const described = params.plugin.config.describeAccount?.(
params.account,
params.cfg,
@@ -123,7 +122,7 @@ const buildAccountSnapshot = (params: {
};
const formatAllowFrom = (params: {
plugin: ProviderPlugin;
plugin: ChannelPlugin;
cfg: ClawdbotConfig;
accountId?: string | null;
allowFrom: Array<string | number>;
@@ -139,9 +138,9 @@ const formatAllowFrom = (params: {
};
const buildAccountNotes = (params: {
plugin: ProviderPlugin;
plugin: ChannelPlugin;
cfg: ClawdbotConfig;
entry: ProviderAccountRow;
entry: ChannelAccountRow;
}) => {
const { plugin, cfg, entry } = params;
const notes: string[] = [];
@@ -192,7 +191,7 @@ function resolveLinkFields(summary: unknown): {
return { linked, authAgeMs, selfE164 };
}
function collectMissingPaths(accounts: ProviderAccountRow[]): string[] {
function collectMissingPaths(accounts: ChannelAccountRow[]): string[] {
const missing: string[] = [];
for (const entry of accounts) {
const accountRec = asRecord(entry.account);
@@ -216,9 +215,9 @@ function collectMissingPaths(accounts: ProviderAccountRow[]): string[] {
}
function summarizeTokenConfig(params: {
plugin: ProviderPlugin;
plugin: ChannelPlugin;
cfg: ClawdbotConfig;
accounts: ProviderAccountRow[];
accounts: ChannelAccountRow[];
showSecrets: boolean;
}): { state: "ok" | "setup" | "warn" | null; detail: string | null } {
const enabled = params.accounts.filter((a) => a.enabled);
@@ -308,13 +307,13 @@ function summarizeTokenConfig(params: {
};
}
// `status --all` providers table.
// Keep this generic: provider-specific rules belong in the provider plugin.
export async function buildProvidersTable(
// `status --all` channels table.
// Keep this generic: channel-specific rules belong in the channel plugin.
export async function buildChannelsTable(
cfg: ClawdbotConfig,
opts?: { showSecrets?: boolean },
): Promise<{
rows: ProviderRow[];
rows: ChannelRow[];
details: Array<{
title: string;
columns: string[];
@@ -322,16 +321,16 @@ export async function buildProvidersTable(
}>;
}> {
const showSecrets = opts?.showSecrets === true;
const rows: ProviderRow[] = [];
const rows: ChannelRow[] = [];
const details: Array<{
title: string;
columns: string[];
rows: Array<Record<string, string>>;
}> = [];
for (const plugin of listProviderPlugins()) {
for (const plugin of listChannelPlugins()) {
const accountIds = plugin.config.listAccountIds(cfg);
const defaultAccountId = resolveProviderDefaultAccountId({
const defaultAccountId = resolveChannelDefaultAccountId({
plugin,
cfg,
accountIds,
@@ -339,7 +338,7 @@ export async function buildProvidersTable(
const resolvedAccountIds =
accountIds.length > 0 ? accountIds : [defaultAccountId];
const accounts: ProviderAccountRow[] = [];
const accounts: ChannelAccountRow[] = [];
for (const accountId of resolvedAccountIds) {
const account = plugin.config.resolveAccount(cfg, accountId);
const enabled = resolveAccountEnabled(plugin, account, cfg);
@@ -361,14 +360,14 @@ export async function buildProvidersTable(
const defaultEntry =
accounts.find((a) => a.accountId === defaultAccountId) ?? accounts[0];
const summary = plugin.status?.buildProviderSummary
? await plugin.status.buildProviderSummary({
const summary = plugin.status?.buildChannelSummary
? await plugin.status.buildChannelSummary({
account: defaultEntry?.account ?? {},
cfg,
defaultAccountId,
snapshot:
defaultEntry?.snapshot ??
({ accountId: defaultAccountId } as ProviderAccountSnapshot),
({ accountId: defaultAccountId } as ChannelAccountSnapshot),
})
: undefined;
@@ -440,7 +439,7 @@ export async function buildProvidersTable(
rows.push({
id: plugin.id,
provider: label,
label,
enabled: anyEnabled,
state,
detail,