mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-05-19 08:48:01 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
178 lines
5.3 KiB
TypeScript
178 lines
5.3 KiB
TypeScript
import { resolveChannelDefaultAccountId } from "../../channels/plugins/helpers.js";
|
|
import {
|
|
getChannelPlugin,
|
|
listChannelPlugins,
|
|
normalizeChannelId,
|
|
} from "../../channels/plugins/index.js";
|
|
import { type OpenClawConfig, writeConfigFile } from "../../config/config.js";
|
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../routing/session-key.js";
|
|
import { defaultRuntime, type RuntimeEnv } from "../../runtime.js";
|
|
import { createClackPrompter } from "../../wizard/clack-prompter.js";
|
|
import { resolveInstallableChannelPlugin } from "../channel-setup/channel-plugin-resolution.js";
|
|
import { type ChatChannel, channelLabel, requireValidConfig, shouldUseWizard } from "./shared.js";
|
|
|
|
export type ChannelsRemoveOptions = {
|
|
channel?: string;
|
|
account?: string;
|
|
delete?: boolean;
|
|
};
|
|
|
|
function listAccountIds(cfg: OpenClawConfig, channel: ChatChannel): string[] {
|
|
const plugin = getChannelPlugin(channel);
|
|
if (!plugin) {
|
|
return [];
|
|
}
|
|
return plugin.config.listAccountIds(cfg);
|
|
}
|
|
|
|
export async function channelsRemoveCommand(
|
|
opts: ChannelsRemoveOptions,
|
|
runtime: RuntimeEnv = defaultRuntime,
|
|
params?: { hasFlags?: boolean },
|
|
) {
|
|
const loadedCfg = await requireValidConfig(runtime);
|
|
if (!loadedCfg) {
|
|
return;
|
|
}
|
|
let cfg = loadedCfg;
|
|
|
|
const useWizard = shouldUseWizard(params);
|
|
const prompter = useWizard ? createClackPrompter() : null;
|
|
const rawChannel = opts.channel?.trim() ?? "";
|
|
let channel: ChatChannel | null = normalizeChannelId(rawChannel);
|
|
let accountId = normalizeAccountId(opts.account);
|
|
const deleteConfig = Boolean(opts.delete);
|
|
|
|
if (useWizard && prompter) {
|
|
await prompter.intro("Remove channel account");
|
|
const selectedChannel = await prompter.select({
|
|
message: "Channel",
|
|
options: listChannelPlugins().map((plugin) => ({
|
|
value: plugin.id,
|
|
label: plugin.meta.label,
|
|
})),
|
|
});
|
|
channel = selectedChannel;
|
|
|
|
accountId = await (async () => {
|
|
const ids = listAccountIds(cfg, selectedChannel);
|
|
const choice = await prompter.select({
|
|
message: "Account",
|
|
options: ids.map((id) => ({
|
|
value: id,
|
|
label: id === DEFAULT_ACCOUNT_ID ? "default (primary)" : id,
|
|
})),
|
|
initialValue: ids[0] ?? DEFAULT_ACCOUNT_ID,
|
|
});
|
|
return normalizeAccountId(choice);
|
|
})();
|
|
|
|
const wantsDisable = await prompter.confirm({
|
|
message: `Disable ${channelLabel(selectedChannel)} account "${accountId}"? (keeps config)`,
|
|
initialValue: true,
|
|
});
|
|
if (!wantsDisable) {
|
|
await prompter.outro("Cancelled.");
|
|
return;
|
|
}
|
|
} else {
|
|
if (!rawChannel) {
|
|
runtime.error("Channel is required. Use --channel <name>.");
|
|
runtime.exit(1);
|
|
return;
|
|
}
|
|
if (!deleteConfig) {
|
|
const confirm = createClackPrompter();
|
|
const channelPromptLabel = channel ? channelLabel(channel) : rawChannel;
|
|
const ok = await confirm.confirm({
|
|
message: `Disable ${channelPromptLabel} account "${accountId}"? (keeps config)`,
|
|
initialValue: true,
|
|
});
|
|
if (!ok) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
const resolvedPluginState =
|
|
!useWizard && rawChannel
|
|
? await resolveInstallableChannelPlugin({
|
|
cfg,
|
|
runtime,
|
|
rawChannel,
|
|
allowInstall: true,
|
|
})
|
|
: null;
|
|
if (resolvedPluginState?.configChanged) {
|
|
cfg = resolvedPluginState.cfg;
|
|
}
|
|
const resolvedChannel = resolvedPluginState?.channelId ?? channel;
|
|
if (!resolvedChannel) {
|
|
runtime.error(`Unknown channel: ${rawChannel}`);
|
|
runtime.exit(1);
|
|
return;
|
|
}
|
|
channel = resolvedChannel;
|
|
const plugin = resolvedPluginState?.plugin ?? getChannelPlugin(resolvedChannel);
|
|
if (!plugin) {
|
|
runtime.error(`Unknown channel: ${resolvedChannel}`);
|
|
runtime.exit(1);
|
|
return;
|
|
}
|
|
const resolvedChannelId: ChatChannel = resolvedChannel;
|
|
const resolvedAccountId =
|
|
normalizeAccountId(accountId) ?? resolveChannelDefaultAccountId({ plugin, cfg });
|
|
const accountKey = resolvedAccountId || DEFAULT_ACCOUNT_ID;
|
|
|
|
let next = { ...cfg };
|
|
const prevCfg = cfg;
|
|
if (deleteConfig) {
|
|
if (!plugin.config.deleteAccount) {
|
|
runtime.error(`Channel ${channel} does not support delete.`);
|
|
runtime.exit(1);
|
|
return;
|
|
}
|
|
next = plugin.config.deleteAccount({
|
|
cfg: next,
|
|
accountId: resolvedAccountId,
|
|
});
|
|
await plugin.lifecycle?.onAccountRemoved?.({
|
|
prevCfg,
|
|
accountId: resolvedAccountId,
|
|
runtime,
|
|
});
|
|
} else {
|
|
if (!plugin.config.setAccountEnabled) {
|
|
runtime.error(`Channel ${channel} does not support disable.`);
|
|
runtime.exit(1);
|
|
return;
|
|
}
|
|
next = plugin.config.setAccountEnabled({
|
|
cfg: next,
|
|
accountId: resolvedAccountId,
|
|
enabled: false,
|
|
});
|
|
await plugin.lifecycle?.onAccountConfigChanged?.({
|
|
prevCfg,
|
|
nextCfg: next,
|
|
accountId: resolvedAccountId,
|
|
runtime,
|
|
});
|
|
}
|
|
|
|
await writeConfigFile(next);
|
|
if (useWizard && prompter) {
|
|
await prompter.outro(
|
|
deleteConfig
|
|
? `Deleted ${channelLabel(resolvedChannelId)} account "${accountKey}".`
|
|
: `Disabled ${channelLabel(resolvedChannelId)} account "${accountKey}".`,
|
|
);
|
|
} else {
|
|
runtime.log(
|
|
deleteConfig
|
|
? `Deleted ${channelLabel(resolvedChannelId)} account "${accountKey}".`
|
|
: `Disabled ${channelLabel(resolvedChannelId)} account "${accountKey}".`,
|
|
);
|
|
}
|
|
}
|