feat(usage): 用量明细——/api/usage 加 week 窗口+runs 计数,新增 /api/usage/detail
costSummary 顶层补 runs 计数、period 扩 day|week|month;新增 usageDetail(day|week|month) 返回时间序列分桶 + 分项目下钻(token/花费/任务数/模型,model 维度沿用 usage JSON 近似口径)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+8
-1
@@ -196,12 +196,19 @@ export function buildServer(opts: ApiOptions): FastifyInstance {
|
||||
// ?period=day|month(默认 month);?project=<id> 限定单项目成本。
|
||||
app.get('/api/usage', async (req) => {
|
||||
const q = req.query as { period?: string; project?: string };
|
||||
const period = q.period === 'day' ? 'day' : 'month';
|
||||
const period = q.period === 'day' ? 'day' : q.period === 'week' ? 'week' : 'month';
|
||||
const quota = await getUsage();
|
||||
const cost = store.costSummary(period, q.project && q.project.trim() ? q.project.trim() : undefined);
|
||||
return { ...(quota ?? {}), cost };
|
||||
});
|
||||
|
||||
// 用量详情:时间序列(按天/按月)+ 分项目下钻,供侧栏「详情」弹框。
|
||||
app.get('/api/usage/detail', (req) => {
|
||||
const q = req.query as { granularity?: string };
|
||||
const granularity = q.granularity === 'month' ? 'month' : q.granularity === 'week' ? 'week' : 'day';
|
||||
return store.usageDetail(granularity);
|
||||
});
|
||||
|
||||
// 健康检查:daemon 存活 + DB 可读 + 在途 run 数。
|
||||
app.get('/api/health', () => {
|
||||
let db = true;
|
||||
|
||||
Reference in New Issue
Block a user