fix(dashboard): support unified config in overview and file watcher

- overview-routes: Use ProfileRegistry for account count, merge both
  legacy and unified sources
- file-watcher: Add config.yaml to watch list for real-time updates
  in unified mode

Related to #203
This commit is contained in:
kaitranntt
2025-12-25 14:35:31 -05:00
parent 8d7845d67f
commit 25f0ddb9dd
2 changed files with 13 additions and 9 deletions
+3 -2
View File
@@ -22,7 +22,8 @@ export function createFileWatcher(onChange: FileChangeCallback): FSWatcher {
const watcher = chokidar.watch(
[
path.join(ccsDir, 'config.json'),
path.join(ccsDir, 'config.json'), // Legacy config
path.join(ccsDir, 'config.yaml'), // Unified config
path.join(ccsDir, '*.settings.json'),
path.join(ccsDir, 'profiles.json'),
path.join(ccsDir, 'cliproxy', 'sessions.json'), // Proxy session tracking
@@ -41,7 +42,7 @@ export function createFileWatcher(onChange: FileChangeCallback): FSWatcher {
const basename = path.basename(filePath);
let type: FileChangeEvent['type'];
if (basename === 'config.json') {
if (basename === 'config.json' || basename === 'config.yaml') {
type = 'config-changed';
} else if (basename === 'profiles.json') {
type = 'profiles-changed';
+10 -7
View File
@@ -5,12 +5,11 @@
*/
import { Router, Request, Response } from 'express';
import * as fs from 'fs';
import * as path from 'path';
import { getCcsDir, loadConfig } from '../utils/config-manager';
import { loadConfig } from '../utils/config-manager';
import { runHealthChecks } from './health-service';
import { getAllAuthStatus, initializeAccounts } from '../cliproxy/auth-handler';
import { getVersion } from '../utils/version';
import ProfileRegistry from '../auth/profile-registry';
export const overviewRoutes = Router();
@@ -64,12 +63,16 @@ overviewRoutes.get('/', async (_req: Request, res: Response) => {
function getAccountCount(): number {
try {
const profilesPath = path.join(getCcsDir(), 'profiles.json');
const registry = new ProfileRegistry();
if (!fs.existsSync(profilesPath)) return 0;
// Merge legacy (profiles.json) and unified (config.yaml) accounts
const legacyProfiles = registry.getAllProfiles();
const unifiedAccounts = registry.getAllAccountsUnified();
const data = JSON.parse(fs.readFileSync(profilesPath, 'utf8'));
return Object.keys(data.profiles || {}).length;
// Count unique accounts (unified takes precedence for duplicates)
const allNames = new Set([...Object.keys(legacyProfiles), ...Object.keys(unifiedAccounts)]);
return allNames.size;
} catch {
return 0;
}