fix: checkpoint CI and provider snapshot changes

This commit is contained in:
Mohamed Boudra
2026-04-14 14:23:25 +07:00
parent 5241727b29
commit 1e0f62976d
8 changed files with 94 additions and 45 deletions
@@ -364,7 +364,7 @@ export function useAgentFormState(options: UseAgentFormStateOptions = {}): UseAg
error: snapshotError,
refresh: refreshSnapshot,
invalidate: invalidateSnapshot,
} = useProvidersSnapshot(formState.serverId);
} = useProvidersSnapshot(formState.serverId, formState.workingDir);
const allProviderEntries = useMemo(() => snapshotEntries ?? [], [snapshotEntries]);
const snapshotProviderDefinitions = useMemo(
@@ -6,8 +6,17 @@ import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-
import { useSessionForServer } from "./use-session-directory";
import { queryClient as singletonQueryClient } from "@/query/query-client";
export function providersSnapshotQueryKey(serverId: string | null) {
return ["providersSnapshot", serverId] as const;
function normalizeProvidersSnapshotCwdKey(cwd?: string | null): string | null {
const trimmed = cwd?.trim();
if (!trimmed) {
return null;
}
return trimmed.replace(/^\/(?:Users|home)\/[^/]+/, "~");
}
export function providersSnapshotQueryKey(serverId: string | null, cwd?: string | null) {
return ["providersSnapshot", serverId, normalizeProvidersSnapshotCwdKey(cwd)] as const;
}
interface UseProvidersSnapshotResult {
@@ -20,16 +29,24 @@ interface UseProvidersSnapshotResult {
invalidate: () => void;
}
export function useProvidersSnapshot(serverId: string | null): UseProvidersSnapshotResult {
export function useProvidersSnapshot(
serverId: string | null,
cwd?: string | null,
): UseProvidersSnapshotResult {
const queryClient = useQueryClient();
const client = useHostRuntimeClient(serverId ?? "");
const isConnected = useHostRuntimeIsConnected(serverId ?? "");
const normalizedCwd = cwd?.trim() || undefined;
const normalizedCwdKey = normalizeProvidersSnapshotCwdKey(normalizedCwd);
const supportsSnapshot = useSessionForServer(
serverId,
(session) => session?.serverInfo?.features?.providersSnapshot === true,
);
const queryKey = useMemo(() => providersSnapshotQueryKey(serverId), [serverId]);
const queryKey = useMemo(
() => providersSnapshotQueryKey(serverId, normalizedCwdKey),
[normalizedCwdKey, serverId],
);
const snapshotQuery = useQuery({
queryKey,
@@ -39,7 +56,7 @@ export function useProvidersSnapshot(serverId: string | null): UseProvidersSnaps
if (!client) {
throw new Error("Host is not connected");
}
return client.getProvidersSnapshot();
return client.getProvidersSnapshot({ cwd: normalizedCwd });
},
});
@@ -48,24 +65,28 @@ export function useProvidersSnapshot(serverId: string | null): UseProvidersSnaps
return;
}
return client.on("providers_snapshot_update", (message) => {
if (message.type !== "providers_snapshot_update") {
return;
}
queryClient.setQueryData(queryKey, {
entries: message.payload.entries,
generatedAt: message.payload.generatedAt,
requestId: "providers_snapshot_update",
return client.on("providers_snapshot_update", (message) => {
if (message.type !== "providers_snapshot_update") {
return;
}
const messageCwdKey = normalizeProvidersSnapshotCwdKey(message.payload.cwd);
if (messageCwdKey !== normalizedCwdKey) {
return;
}
queryClient.setQueryData(queryKey, {
entries: message.payload.entries,
generatedAt: message.payload.generatedAt,
requestId: "providers_snapshot_update",
});
});
});
}, [client, isConnected, serverId, queryClient, queryKey, supportsSnapshot]);
}, [client, isConnected, normalizedCwdKey, queryClient, queryKey, serverId, supportsSnapshot]);
const refresh = useCallback(() => {
if (!client) {
return;
}
void client.refreshProvidersSnapshot();
}, [client]);
void client.refreshProvidersSnapshot({ cwd: normalizedCwd });
}, [client, normalizedCwd]);
const invalidate = useCallback(() => {
void queryClient.invalidateQueries({ queryKey });
@@ -82,11 +103,16 @@ export function useProvidersSnapshot(serverId: string | null): UseProvidersSnaps
};
}
export function prefetchProvidersSnapshot(serverId: string, client: DaemonClient): void {
const queryKey = providersSnapshotQueryKey(serverId);
export function prefetchProvidersSnapshot(
serverId: string,
client: DaemonClient,
cwd?: string | null,
): void {
const normalizedCwd = cwd?.trim() || undefined;
const queryKey = providersSnapshotQueryKey(serverId, normalizedCwd);
void singletonQueryClient.prefetchQuery({
queryKey,
staleTime: 60_000,
queryFn: () => client.getProvidersSnapshot(),
queryFn: () => client.getProvidersSnapshot({ cwd: normalizedCwd }),
});
}