Add dashboard token usage history (#240)

This commit is contained in:
Lingxuan Zuo
2026-03-02 13:20:33 +08:00
committed by GitHub
Unverified
parent 0bc4b7cbc2
commit 62108bdc23
10 changed files with 718 additions and 6 deletions

View File

@@ -49,6 +49,7 @@ import { updateSkillConfig, getSkillConfig, getAllSkillConfigs } from '../utils/
import { whatsAppLoginManager } from '../utils/whatsapp-login';
import { getProviderConfig } from '../utils/provider-registry';
import { deviceOAuthManager, OAuthProviderType } from '../utils/device-oauth';
import { getRecentTokenUsageHistory } from '../utils/token-usage';
/**
* For custom/ollama providers, derive a unique key for OpenClaw config files
@@ -105,6 +106,9 @@ export function registerIpcHandlers(
// Log handlers (for UI to read gateway/app logs)
registerLogHandlers();
// Usage handlers
registerUsageHandlers();
// Skill config handlers (direct file access, no Gateway RPC)
registerSkillConfigHandlers();
@@ -1751,6 +1755,14 @@ function registerAppHandlers(): void {
});
}
function registerUsageHandlers(): void {
ipcMain.handle('usage:recentTokenHistory', async (_, limit?: number) => {
const safeLimit = typeof limit === 'number' && Number.isFinite(limit)
? Math.min(Math.max(Math.floor(limit), 1), 100)
: 20;
return await getRecentTokenUsageHistory(safeLimit);
});
}
/**
* Window control handlers (for custom title bar on Windows/Linux)
*/