Files
multica/packages/core/runtimes/queries.ts
Multica Eve 2c482ab366 MUL-4781: move daemon update to machine page (#5434)
* fix(runtimes): move daemon update to machine

Co-authored-by: multica-agent <github@multica.ai>

* chore(runtimes): remove obsolete update hook

Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: Eve <eve@multica-ai.local>
Co-authored-by: multica-agent <github@multica.ai>
2026-07-15 12:41:26 +08:00

56 lines
1.9 KiB
TypeScript

import { queryOptions } from "@tanstack/react-query";
import { api } from "../api";
export const runtimeKeys = {
all: (wsId: string) => ["runtimes", wsId] as const,
list: (wsId: string) => [...runtimeKeys.all(wsId), "list"] as const,
listMine: (wsId: string) => [...runtimeKeys.all(wsId), "list", "mine"] as const,
usage: (rid: string, days: number, tz: string) =>
["runtimes", "usage", rid, days, tz] as const,
usageByAgent: (rid: string, days: number, tz: string) =>
["runtimes", "usage", "by-agent", rid, days, tz] as const,
// by-hour now follows the viewer's tz, like the other reports.
usageByHour: (rid: string, days: number, tz: string) =>
["runtimes", "usage", "by-hour", rid, days, tz] as const,
};
// `tz` is the viewer's IANA name — all reports follow the viewer's tz.
export function runtimeUsageOptions(
runtimeId: string,
days: number,
tz: string,
) {
return queryOptions({
queryKey: runtimeKeys.usage(runtimeId, days, tz),
queryFn: () => api.getRuntimeUsage(runtimeId, { days, tz }),
staleTime: 60 * 1000,
});
}
export function runtimeUsageByAgentOptions(
runtimeId: string,
days: number,
tz: string,
) {
return queryOptions({
queryKey: runtimeKeys.usageByAgent(runtimeId, days, tz),
queryFn: () => api.getRuntimeUsageByAgent(runtimeId, { days, tz }),
staleTime: 60 * 1000,
});
}
export function runtimeUsageByHourOptions(runtimeId: string, days: number, tz: string) {
return queryOptions({
queryKey: runtimeKeys.usageByHour(runtimeId, days, tz),
queryFn: () => api.getRuntimeUsageByHour(runtimeId, { days, tz }),
staleTime: 60 * 1000,
});
}
export function runtimeListOptions(wsId: string, owner?: "me") {
return queryOptions({
queryKey: owner === "me" ? runtimeKeys.listMine(wsId) : runtimeKeys.list(wsId),
queryFn: () => api.listRuntimes({ workspace_id: wsId, owner }),
});
}