Feat/perf dashboard (#770)

This commit is contained in:
paisley
2026-04-07 11:04:57 +08:00
committed by GitHub
Unverified
parent 413244522e
commit d8750e135b
9 changed files with 135 additions and 39 deletions

View File

@@ -2,6 +2,7 @@ import { access, copyFile, mkdir, readdir, rm } from 'fs/promises';
import { constants } from 'fs';
import { join, normalize } from 'path';
import { deleteAgentChannelAccounts, listConfiguredChannels, readOpenClawConfig, writeOpenClawConfig } from './channel-config';
import type { OpenClawConfig } from './channel-config';
import { withConfigLock } from './config-mutex';
import { expandPath, getOpenClawConfigDir } from './paths';
import * as logger from './logger';
@@ -450,9 +451,9 @@ function listConfiguredAccountIdsForChannel(config: AgentConfigDocument, channel
});
}
async function buildSnapshotFromConfig(config: AgentConfigDocument): Promise<AgentsSnapshot> {
async function buildSnapshotFromConfig(config: AgentConfigDocument, preloadedChannels?: string[]): Promise<AgentsSnapshot> {
const { entries, defaultAgentId } = normalizeAgentsConfig(config);
const configuredChannels = await listConfiguredChannels();
const configuredChannels = preloadedChannels ?? await listConfiguredChannels();
const { channelToAgent, accountToAgent } = getChannelBindingMap(config.bindings);
const defaultAgentIdNorm = normalizeAgentIdForBinding(defaultAgentId);
const channelOwners: Record<string, string> = {};
@@ -539,6 +540,10 @@ export async function listAgentsSnapshot(): Promise<AgentsSnapshot> {
return buildSnapshotFromConfig(config);
}
export async function listAgentsSnapshotFromConfig(config: OpenClawConfig, configuredChannels?: string[]): Promise<AgentsSnapshot> {
return buildSnapshotFromConfig(config as AgentConfigDocument, configuredChannels);
}
export async function listConfiguredAgentIds(): Promise<string[]> {
const config = await readOpenClawConfig() as AgentConfigDocument;
const { entries } = normalizeAgentsConfig(config);

View File

@@ -966,8 +966,7 @@ function channelHasAnyAccount(channelSection: ChannelConfigData): boolean {
return false;
}
export async function listConfiguredChannels(): Promise<string[]> {
const config = await readOpenClawConfig();
export async function listConfiguredChannelsFromConfig(config: OpenClawConfig): Promise<string[]> {
const channels: string[] = [];
if (config.channels) {
@@ -1005,13 +1004,17 @@ export async function listConfiguredChannels(): Promise<string[]> {
return channels;
}
export async function listConfiguredChannels(): Promise<string[]> {
const config = await readOpenClawConfig();
return listConfiguredChannelsFromConfig(config);
}
export interface ConfiguredChannelAccounts {
defaultAccountId: string;
accountIds: string[];
}
export async function listConfiguredChannelAccounts(): Promise<Record<string, ConfiguredChannelAccounts>> {
const config = await readOpenClawConfig();
export function listConfiguredChannelAccountsFromConfig(config: OpenClawConfig): Record<string, ConfiguredChannelAccounts> {
const result: Record<string, ConfiguredChannelAccounts> = {};
if (!config.channels) {
@@ -1059,6 +1062,11 @@ export async function listConfiguredChannelAccounts(): Promise<Record<string, Co
return result;
}
export async function listConfiguredChannelAccounts(): Promise<Record<string, ConfiguredChannelAccounts>> {
const config = await readOpenClawConfig();
return listConfiguredChannelAccountsFromConfig(config);
}
export async function setChannelDefaultAccount(channelType: string, accountId: string): Promise<void> {
return withConfigLock(async () => {
const resolvedChannelType = resolveStoredChannelType(channelType);