Update files

This commit is contained in:
Mohamed Boudra
2026-01-24 16:10:58 +07:00
parent 1b61fabde5
commit b86075040d
2 changed files with 144 additions and 9 deletions
@@ -9,9 +9,9 @@ import {
nextCheckoutStatusRefetchDecision,
} from "./checkout-status-revalidation";
const CHECKOUT_STATUS_STALE_TIME = 15_000;
export const CHECKOUT_STATUS_STALE_TIME = 15_000;
function checkoutStatusQueryKey(serverId: string, agentId: string) {
export function checkoutStatusQueryKey(serverId: string, agentId: string) {
return ["checkoutStatus", serverId, agentId] as const;
}
@@ -22,6 +22,13 @@ interface UseCheckoutStatusQueryOptions {
export type CheckoutStatusPayload = CheckoutStatusResponse["payload"];
function fetchCheckoutStatus(
client: { getCheckoutStatus: (agentId: string) => Promise<CheckoutStatusPayload> },
agentId: string
): Promise<CheckoutStatusPayload> {
return client.getCheckoutStatus(agentId);
}
export function useCheckoutStatusQuery({ serverId, agentId }: UseCheckoutStatusQueryOptions) {
const client = useSessionStore(
(state) => state.sessions[serverId]?.client ?? null
@@ -42,7 +49,7 @@ export function useCheckoutStatusQuery({ serverId, agentId }: UseCheckoutStatusQ
if (!client) {
throw new Error("Daemon client not available");
}
return await client.getCheckoutStatus(agentId);
return await fetchCheckoutStatus(client, agentId);
},
enabled: !!client && isConnected && !!agentId,
staleTime: CHECKOUT_STATUS_STALE_TIME,
@@ -73,3 +80,26 @@ export function useCheckoutStatusQuery({ serverId, agentId }: UseCheckoutStatusQ
refresh: query.refetch,
};
}
/**
* Subscribe to checkout status updates from the React Query cache without
* initiating a fetch. Useful for list rows where a parent component prefetches
* only the visible agents.
*/
export function useCheckoutStatusCacheOnly({ serverId, agentId }: UseCheckoutStatusQueryOptions) {
const client = useSessionStore(
(state) => state.sessions[serverId]?.client ?? null
);
return useQuery({
queryKey: checkoutStatusQueryKey(serverId, agentId),
queryFn: async () => {
if (!client) {
throw new Error("Daemon client not available");
}
return await fetchCheckoutStatus(client, agentId);
},
enabled: false,
staleTime: CHECKOUT_STATUS_STALE_TIME,
});
}