2026-05-29 03:13:46 -07:00
|
|
|
"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";
|
|
|
|
|
|
|
|
|
|
/**
|
2026-07-06 15:12:40 +05:30
|
|
|
* Whether the workspace's configured models are billable for automations.
|
2026-05-29 03:13:46 -07:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2026-07-06 15:12:40 +05:30
|
|
|
* Keyed by workspace id (not the jotai "current scope" atom) so it can be
|
2026-05-29 03:13:46 -07:00
|
|
|
* used on the create route as well as the list page.
|
|
|
|
|
*/
|
2026-07-06 15:12:40 +05:30
|
|
|
export function useAutomationModelEligibility(workspaceId: number | undefined) {
|
2026-05-29 03:13:46 -07:00
|
|
|
return useQuery<ModelEligibility, Error>({
|
2026-07-06 15:12:40 +05:30
|
|
|
queryKey: cacheKeys.automations.modelEligibility(workspaceId ?? 0),
|
|
|
|
|
queryFn: () => automationsApiService.getModelEligibility(workspaceId as number),
|
|
|
|
|
enabled: !!workspaceId,
|
2026-05-29 03:13:46 -07:00
|
|
|
staleTime: 60_000,
|
|
|
|
|
});
|
|
|
|
|
}
|