mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-03 11:10:23 +02:00
* feat(runtime): proactive CLI update notifications with per-user filtering - Add latestCliVersionOptions query (GitHub Releases API, 10-min TanStack cache) - Add useMyRuntimesNeedUpdate / useUpdatableRuntimeIds hooks using owner_id - Show red dot on sidebar Runtimes item when user's runtimes need updates - Show update arrow icon alongside status dot in runtime list items * fix(core): add runtimes/hooks to package.json exports
39 lines
1.2 KiB
TypeScript
39 lines
1.2 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,
|
|
latestVersion: () => ["runtimes", "latestVersion"] as const,
|
|
};
|
|
|
|
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 }),
|
|
});
|
|
}
|
|
|
|
const GITHUB_RELEASES_URL =
|
|
"https://api.github.com/repos/multica-ai/multica/releases/latest";
|
|
|
|
export function latestCliVersionOptions() {
|
|
return queryOptions({
|
|
queryKey: runtimeKeys.latestVersion(),
|
|
queryFn: async (): Promise<string | null> => {
|
|
try {
|
|
const resp = await fetch(GITHUB_RELEASES_URL, {
|
|
headers: { Accept: "application/vnd.github+json" },
|
|
});
|
|
if (!resp.ok) return null;
|
|
const data = await resp.json();
|
|
return (data.tag_name as string) ?? null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
},
|
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
|
});
|
|
}
|