"use client"; import { useQuery } from "@tanstack/react-query"; import type { ModelEligibility } from "@/contracts/types/automation.types"; import { automationsApiService } from "@/lib/apis/automations-api.service"; import { cacheKeys } from "@/lib/query-client/cache-keys"; /** * Whether the search space's configured models are billable for automations. * * Automations may only run on premium global models or user-provided (BYOK) * models; free global models and Auto mode are blocked so every run is metered * in premium credits. Creation surfaces use this to gate their CTAs before the * user invests effort drafting an automation that can't be saved. * * Keyed by search space id (not the jotai "current scope" atom) so it can be * used on the create route as well as the list page. */ export function useAutomationModelEligibility(searchSpaceId: number | undefined) { return useQuery({ queryKey: cacheKeys.automations.modelEligibility(searchSpaceId ?? 0), queryFn: () => automationsApiService.getModelEligibility(searchSpaceId as number), enabled: !!searchSpaceId, staleTime: 60_000, }); }