mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-03 19:20:07 +02:00
chore(runtimes): remove obsolete update hook
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -55,7 +55,6 @@
|
||||
"./runtimes": "./runtimes/index.ts",
|
||||
"./runtimes/queries": "./runtimes/queries.ts",
|
||||
"./runtimes/mutations": "./runtimes/mutations.ts",
|
||||
"./runtimes/hooks": "./runtimes/hooks.ts",
|
||||
"./runtimes/custom-pricing-store": "./runtimes/custom-pricing-store.ts",
|
||||
"./dashboard": "./dashboard/index.ts",
|
||||
"./dashboard/queries": "./dashboard/queries.ts",
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
import { useMemo } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useAuthStore } from "../auth";
|
||||
import type { AgentRuntime } from "../types";
|
||||
import { runtimeListOptions, latestCliVersionOptions } from "./queries";
|
||||
|
||||
function stripV(v: string): string {
|
||||
return v.replace(/^v/, "");
|
||||
}
|
||||
|
||||
function isNewer(latest: string, current: string): boolean {
|
||||
const l = stripV(latest).split(".").map(Number);
|
||||
const c = stripV(current).split(".").map(Number);
|
||||
for (let i = 0; i < Math.max(l.length, c.length); i++) {
|
||||
const lv = l[i] ?? 0;
|
||||
const cv = c[i] ?? 0;
|
||||
if (lv > cv) return true;
|
||||
if (lv < cv) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function runtimeNeedsUpdate(
|
||||
rt: AgentRuntime,
|
||||
latestVersion: string,
|
||||
userId: string,
|
||||
): boolean {
|
||||
if (rt.runtime_mode !== "local") return false;
|
||||
// Only show to the user who owns this runtime.
|
||||
if (rt.owner_id !== userId) return false;
|
||||
// Desktop-managed runtimes are updated by the Desktop app's own auto-updater;
|
||||
// the platform should not surface CLI update prompts for them.
|
||||
if (rt.metadata && rt.metadata.launched_by === "desktop") {
|
||||
return false;
|
||||
}
|
||||
const cliVersion =
|
||||
rt.metadata && typeof rt.metadata.cli_version === "string"
|
||||
? rt.metadata.cli_version
|
||||
: null;
|
||||
if (!cliVersion) return false;
|
||||
return isNewer(latestVersion, cliVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of runtime IDs that belong to the current user and have updates available.
|
||||
* Accepts wsId as parameter so callers outside WorkspaceIdProvider can use it safely.
|
||||
*/
|
||||
export function useUpdatableRuntimeIds(wsId: string | undefined): Set<string> {
|
||||
const userId = useAuthStore((s) => s.user?.id);
|
||||
const { data: runtimes } = useQuery({
|
||||
...runtimeListOptions(wsId ?? ""),
|
||||
enabled: !!wsId,
|
||||
});
|
||||
const { data: latestVersion } = useQuery(latestCliVersionOptions());
|
||||
|
||||
return useMemo(() => {
|
||||
if (!runtimes || !latestVersion || !userId) return new Set<string>();
|
||||
const ids = new Set<string>();
|
||||
for (const rt of runtimes) {
|
||||
if (runtimeNeedsUpdate(rt, latestVersion, userId)) {
|
||||
ids.add(rt.id);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}, [runtimes, latestVersion, userId]);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
export * from "./queries";
|
||||
export * from "./profiles";
|
||||
export * from "./mutations";
|
||||
export * from "./hooks";
|
||||
export * from "./models";
|
||||
export * from "./local-skills";
|
||||
export * from "./types";
|
||||
|
||||
@@ -12,7 +12,6 @@ export const runtimeKeys = {
|
||||
// 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,
|
||||
latestVersion: () => ["runtimes", "latestVersion"] as const,
|
||||
};
|
||||
|
||||
// `tz` is the viewer's IANA name — all reports follow the viewer's tz.
|
||||
@@ -54,25 +53,3 @@ export function runtimeListOptions(wsId: string, owner?: "me") {
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user