mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 21:10:54 +00:00
* refactor: remove channel shim directories, point all imports to extensions
Delete the 6 backward-compat shim directories (src/telegram, src/discord,
src/slack, src/signal, src/imessage, src/web) that were re-exporting from
extensions. Update all 112+ source files to import directly from
extensions/{channel}/src/ instead of through the shims.
Also:
- Move src/channels/telegram/ (allow-from, api) to extensions/telegram/src/
- Fix outbound adapters to use resolveOutboundSendDep (fixes 5 pre-existing TS errors)
- Update cross-extension imports (src/web/media.js → extensions/whatsapp/src/media.js)
- Update vitest, tsdown, knip, labeler, and script configs for new paths
- Update guard test allowlists for extension paths
After this, src/ has zero channel-specific implementation code — only the
generic plugin framework remains.
* fix: update raw-fetch guard allowlist line numbers after shim removal
* refactor: document direct extension channel imports
* test: mock transcript module in delivery helpers
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import { listEnabledDiscordAccounts } from "../../extensions/discord/src/accounts.js";
|
|
import { isDiscordExecApprovalClientEnabled } from "../../extensions/discord/src/exec-approvals.js";
|
|
import { listEnabledTelegramAccounts } from "../../extensions/telegram/src/accounts.js";
|
|
import { isTelegramExecApprovalClientEnabled } from "../../extensions/telegram/src/exec-approvals.js";
|
|
import { loadConfig, type OpenClawConfig } from "../config/config.js";
|
|
import { INTERNAL_MESSAGE_CHANNEL, normalizeMessageChannel } from "../utils/message-channel.js";
|
|
|
|
export type ExecApprovalInitiatingSurfaceState =
|
|
| { kind: "enabled"; channel: string | undefined; channelLabel: string }
|
|
| { kind: "disabled"; channel: string; channelLabel: string }
|
|
| { kind: "unsupported"; channel: string; channelLabel: string };
|
|
|
|
function labelForChannel(channel?: string): string {
|
|
switch (channel) {
|
|
case "discord":
|
|
return "Discord";
|
|
case "telegram":
|
|
return "Telegram";
|
|
case "tui":
|
|
return "terminal UI";
|
|
case INTERNAL_MESSAGE_CHANNEL:
|
|
return "Web UI";
|
|
default:
|
|
return channel ? channel[0]?.toUpperCase() + channel.slice(1) : "this platform";
|
|
}
|
|
}
|
|
|
|
export function resolveExecApprovalInitiatingSurfaceState(params: {
|
|
channel?: string | null;
|
|
accountId?: string | null;
|
|
cfg?: OpenClawConfig;
|
|
}): ExecApprovalInitiatingSurfaceState {
|
|
const channel = normalizeMessageChannel(params.channel);
|
|
const channelLabel = labelForChannel(channel);
|
|
if (!channel || channel === INTERNAL_MESSAGE_CHANNEL || channel === "tui") {
|
|
return { kind: "enabled", channel, channelLabel };
|
|
}
|
|
|
|
const cfg = params.cfg ?? loadConfig();
|
|
if (channel === "telegram") {
|
|
return isTelegramExecApprovalClientEnabled({ cfg, accountId: params.accountId })
|
|
? { kind: "enabled", channel, channelLabel }
|
|
: { kind: "disabled", channel, channelLabel };
|
|
}
|
|
if (channel === "discord") {
|
|
return isDiscordExecApprovalClientEnabled({ cfg, accountId: params.accountId })
|
|
? { kind: "enabled", channel, channelLabel }
|
|
: { kind: "disabled", channel, channelLabel };
|
|
}
|
|
return { kind: "unsupported", channel, channelLabel };
|
|
}
|
|
|
|
function hasExecApprovalDmRoute(
|
|
accounts: Array<{
|
|
config: {
|
|
execApprovals?: {
|
|
enabled?: boolean;
|
|
approvers?: unknown[];
|
|
target?: string;
|
|
};
|
|
};
|
|
}>,
|
|
): boolean {
|
|
for (const account of accounts) {
|
|
const execApprovals = account.config.execApprovals;
|
|
if (!execApprovals?.enabled || (execApprovals.approvers?.length ?? 0) === 0) {
|
|
continue;
|
|
}
|
|
const target = execApprovals.target ?? "dm";
|
|
if (target === "dm" || target === "both") {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function hasConfiguredExecApprovalDmRoute(cfg: OpenClawConfig): boolean {
|
|
return (
|
|
hasExecApprovalDmRoute(listEnabledDiscordAccounts(cfg)) ||
|
|
hasExecApprovalDmRoute(listEnabledTelegramAccounts(cfg))
|
|
);
|
|
}
|