mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-23 15:11:42 +00:00
refactor: install optional channels for directory
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { Command } from "commander";
|
||||
import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
|
||||
import { getChannelPlugin } from "../channels/plugins/index.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { resolveInstallableChannelPlugin } from "../commands/channel-setup/channel-plugin-resolution.js";
|
||||
import { loadConfig, writeConfigFile } from "../config/config.js";
|
||||
import { danger } from "../globals.js";
|
||||
import { resolveMessageChannelSelection } from "../infra/outbound/channel-selection.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
@@ -96,13 +97,32 @@ export function registerDirectoryCli(program: Command) {
|
||||
.option("--json", "Output JSON", false);
|
||||
|
||||
const resolve = async (opts: { channel?: string; account?: string }) => {
|
||||
const cfg = loadConfig();
|
||||
const selection = await resolveMessageChannelSelection({
|
||||
cfg,
|
||||
channel: opts.channel ?? null,
|
||||
});
|
||||
let cfg = loadConfig();
|
||||
const explicitChannel = opts.channel?.trim();
|
||||
const resolvedExplicit = explicitChannel
|
||||
? await resolveInstallableChannelPlugin({
|
||||
cfg,
|
||||
runtime: defaultRuntime,
|
||||
rawChannel: explicitChannel,
|
||||
allowInstall: true,
|
||||
supports: (plugin) => Boolean(plugin.directory),
|
||||
})
|
||||
: null;
|
||||
if (resolvedExplicit?.configChanged) {
|
||||
cfg = resolvedExplicit.cfg;
|
||||
await writeConfigFile(cfg);
|
||||
}
|
||||
const selection = explicitChannel
|
||||
? {
|
||||
channel: resolvedExplicit?.channelId,
|
||||
}
|
||||
: await resolveMessageChannelSelection({
|
||||
cfg,
|
||||
channel: opts.channel ?? null,
|
||||
});
|
||||
const channelId = selection.channel;
|
||||
const plugin = getChannelPlugin(channelId);
|
||||
const plugin =
|
||||
resolvedExplicit?.plugin ?? (channelId ? getChannelPlugin(channelId) : undefined);
|
||||
if (!plugin) {
|
||||
throw new Error(`Unsupported channel: ${String(channelId)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user