TypeScript function that fetches usage statistics from an API, handling legacy snapshots and missing fields.
// Source: https://github.com/kenz1117/dsh-ui-usage-billing | License: MIT | Copyright 2026 KenZ (kenz1117)
// Provided via justclaw.it.com; keep this notice with the code.
/**
* GET /api/billing/usage-stats:服务端聚合文档(含 byDay/byModel/bySession/...)。
* 旧快照可能缺字段(聚合升级前落盘),解析时按字段白名单接受并兜底——避免
* 渲染路径读 undefined 抛错导致整个插件 surface 被卸载。
*/
import { EMPTY_STATS } from '../constants.ts'
import type { ClientPerf } from '../PerfPanel.tsx'
import type { UsageStats } from '../domain/types.ts'
/** Path to the usage-stats endpoint served by this plugin's node half. */
export const USAGE_STATS_PATH = '/api/billing/usage-stats'
/** Try to load stats from the server; returns null when no valid JSON stats are served. */
export async function loadUsageStats(): Promise<UsageStats | null> {
try {
const
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key