feat(schedules): per-check cost and model summary on GET /schedules (INT-3)

agent_check items carry agentRuns (last 100 sessions: last/avg cost, 7-day count and cost,
models, recent 3); plan page and home plan band use it instead of fetching agent runs.
Migration 0052 indexes agent_run(created_by, created_at).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-29 17:55:47 +08:00
1 parent 82df5662f0
commit e681fcedf6
9 files changed
+200 -78

No files matched your search

-28
View File
@@ -413,31 +413,3 @@ export function useRunInvocationAudit(runId: string, enabled: boolean, version =
},
});
}
/**
* 巡检触发的最近会话(trigger=schedule,createdBy = schedule:<定时任务 id>):
* 计划页的巡检卡片、首页计划带按定时任务分组取费用、模型与最近结果。一次取最近 100 条。
*/
export function useScheduleAgentRuns() {
return useQuery({
queryKey: [...agentKeys.runs(undefined, "schedule"), "plan"],
queryFn: ({ signal }) =>
apiParsed(RunPage, AGENT_BASE, { params: cleanParams({ trigger: "schedule", limit: 100 }), signal }),
select: (page) => page.items,
staleTime: 30 * TTL_SECOND,
refetchInterval: 60 * TTL_SECOND,
});
}
/** 按定时任务 id 分组(新 → 旧,保持接口顺序) */
export function groupRunsBySchedule(runs: AgentRun[]): Map<string, AgentRun[]> {
const out = new Map<string, AgentRun[]>();
for (const r of runs) {
const id = r.createdBy?.startsWith("schedule:") ? r.createdBy.slice("schedule:".length) : null;
if (!id) continue;
const list = out.get(id);
if (list) list.push(r);
else out.set(id, [r]);
}
return out;
}