mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 10:42:43 +00:00
refactor: dedupe cli config cron and install flows
This commit is contained in:
15
src/commands/status-all/channel-issues.ts
Normal file
15
src/commands/status-all/channel-issues.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function groupChannelIssuesByChannel<T extends { channel: string }>(
|
||||
issues: readonly T[],
|
||||
): Map<string, T[]> {
|
||||
const byChannel = new Map<string, T[]>();
|
||||
for (const issue of issues) {
|
||||
const key = issue.channel;
|
||||
const list = byChannel.get(key);
|
||||
if (list) {
|
||||
list.push(issue);
|
||||
} else {
|
||||
byChannel.set(key, [issue]);
|
||||
}
|
||||
}
|
||||
return byChannel;
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import fs from "node:fs";
|
||||
import {
|
||||
buildChannelAccountSnapshot,
|
||||
formatChannelAllowFrom,
|
||||
resolveChannelAccountConfigured,
|
||||
resolveChannelAccountEnabled,
|
||||
} from "../../channels/account-summary.js";
|
||||
import { resolveChannelDefaultAccountId } from "../../channels/plugins/helpers.js";
|
||||
import { listChannelPlugins } from "../../channels/plugins/index.js";
|
||||
@@ -85,30 +87,6 @@ const formatAccountLabel = (params: { accountId: string; name?: string }) => {
|
||||
return base;
|
||||
};
|
||||
|
||||
const resolveAccountEnabled = (
|
||||
plugin: ChannelPlugin,
|
||||
account: unknown,
|
||||
cfg: OpenClawConfig,
|
||||
): boolean => {
|
||||
if (plugin.config.isEnabled) {
|
||||
return plugin.config.isEnabled(account, cfg);
|
||||
}
|
||||
const enabled = asRecord(account).enabled;
|
||||
return enabled !== false;
|
||||
};
|
||||
|
||||
const resolveAccountConfigured = async (
|
||||
plugin: ChannelPlugin,
|
||||
account: unknown,
|
||||
cfg: OpenClawConfig,
|
||||
): Promise<boolean> => {
|
||||
if (plugin.config.isConfigured) {
|
||||
return await plugin.config.isConfigured(account, cfg);
|
||||
}
|
||||
const configured = asRecord(account).configured;
|
||||
return configured !== false;
|
||||
};
|
||||
|
||||
const buildAccountNotes = (params: {
|
||||
plugin: ChannelPlugin;
|
||||
cfg: OpenClawConfig;
|
||||
@@ -343,8 +321,13 @@ export async function buildChannelsTable(
|
||||
const accounts: ChannelAccountRow[] = [];
|
||||
for (const accountId of resolvedAccountIds) {
|
||||
const account = plugin.config.resolveAccount(cfg, accountId);
|
||||
const enabled = resolveAccountEnabled(plugin, account, cfg);
|
||||
const configured = await resolveAccountConfigured(plugin, account, cfg);
|
||||
const enabled = resolveChannelAccountEnabled({ plugin, account, cfg });
|
||||
const configured = await resolveChannelAccountConfigured({
|
||||
plugin,
|
||||
account,
|
||||
cfg,
|
||||
readAccountConfiguredField: true,
|
||||
});
|
||||
const snapshot = buildChannelAccountSnapshot({
|
||||
plugin,
|
||||
cfg,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ProgressReporter } from "../../cli/progress.js";
|
||||
import { renderTable } from "../../terminal/table.js";
|
||||
import { isRich, theme } from "../../terminal/theme.js";
|
||||
import { groupChannelIssuesByChannel } from "./channel-issues.js";
|
||||
import { appendStatusAllDiagnosis } from "./diagnosis.js";
|
||||
import { formatTimeAgo } from "./format.js";
|
||||
|
||||
@@ -81,19 +82,7 @@ export async function buildStatusAllReportLines(params: {
|
||||
: theme.accentDim("SETUP"),
|
||||
Detail: row.detail,
|
||||
}));
|
||||
const channelIssuesByChannel = (() => {
|
||||
const map = new Map<string, ChannelIssueLike[]>();
|
||||
for (const issue of params.channelIssues) {
|
||||
const key = issue.channel;
|
||||
const list = map.get(key);
|
||||
if (list) {
|
||||
list.push(issue);
|
||||
} else {
|
||||
map.set(key, [issue]);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
})();
|
||||
const channelIssuesByChannel = groupChannelIssuesByChannel(params.channelIssues);
|
||||
const channelRowsWithIssues = channelRows.map((row) => {
|
||||
const issues = channelIssuesByChannel.get(row.channelId) ?? [];
|
||||
if (issues.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user