feat(automations): implement model eligibility checks for automation creation

- Added model eligibility checks to ensure automations can only use billable models (premium or BYOK).
- Introduced new API endpoint to report model eligibility status for search spaces.
- Updated frontend components to display eligibility alerts and disable creation options when models are not billable.
- Enhanced automation creation forms to reflect model eligibility, preventing users from submitting invalid configurations.
- Implemented server-side logic to capture and preserve model preferences across automation edits, ensuring consistent behavior during execution.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-05-29 03:13:46 -07:00
parent 5d90fbe99f
commit 409fec94c3
32 changed files with 1451 additions and 67 deletions

View file

@ -0,0 +1,25 @@
"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<ModelEligibility, Error>({
queryKey: cacheKeys.automations.modelEligibility(searchSpaceId ?? 0),
queryFn: () => automationsApiService.getModelEligibility(searchSpaceId as number),
enabled: !!searchSpaceId,
staleTime: 60_000,
});
}