mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-02 18:13:27 +02:00
The sidebar Runtimes nav item showed a red dot (introduced in #533) whenever the current user owned a local, CLI-launched runtime whose reported cli_version was older than the latest GitHub release. Remove the dot and the now-unused useMyRuntimesNeedUpdate hook. The per-runtime update indicator on the Runtimes page (useUpdatableRuntimeIds) is unchanged. Co-authored-by: Lambda <lambda@multica.ai> Co-authored-by: multica-agent <github@multica.ai>
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
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]);
|
|
}
|