diff --git a/packages/core/package.json b/packages/core/package.json index 3fa25b646f..a8ada0bf17 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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", diff --git a/packages/core/runtimes/hooks.ts b/packages/core/runtimes/hooks.ts deleted file mode 100644 index f77304f963..0000000000 --- a/packages/core/runtimes/hooks.ts +++ /dev/null @@ -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 { - 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(); - const ids = new Set(); - for (const rt of runtimes) { - if (runtimeNeedsUpdate(rt, latestVersion, userId)) { - ids.add(rt.id); - } - } - return ids; - }, [runtimes, latestVersion, userId]); -} diff --git a/packages/core/runtimes/index.ts b/packages/core/runtimes/index.ts index 1287d6ac18..09f8a0d47f 100644 --- a/packages/core/runtimes/index.ts +++ b/packages/core/runtimes/index.ts @@ -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"; diff --git a/packages/core/runtimes/queries.ts b/packages/core/runtimes/queries.ts index 47d0aaf187..851c0d10fc 100644 --- a/packages/core/runtimes/queries.ts +++ b/packages/core/runtimes/queries.ts @@ -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 => { - 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 - }); -}