Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 1x 1x 1x 1x 35x 35x 35x 35x 35x 22x 22x 22x 35x 35x 35x 35x 35x 35x 22x 22x 22x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 30x 30x 35x 6x 6x 35x 35x 35x 35x 35x 35x 35x 35x | import type { Skill } from '@shared/types/data';
import { isSkillReady } from '@shared/utils/skill-validation';
import { useQuery } from '@tanstack/react-query';
import {
getSkillEvaluations,
getSkillModels,
} from '@web/api/v1/super-agents/skills';
export interface UseSkillValidationResult {
isReady: boolean;
modelsCount: number;
evaluationsCount: number;
isLoading: boolean;
missingRequirements: string[];
}
/**
* Hook to check if a skill is ready (has required models and evaluations).
* Fetches the models and evaluations count for the skill and returns validation status.
*
* @param skill - The skill to validate
* @returns Validation result with readiness status, counts, and loading state
*/
export function useSkillValidation(
skill: Skill | null | undefined,
): UseSkillValidationResult {
const { data: models = [], isLoading: isLoadingModels } = useQuery({
queryKey: ['skill-validation-models', skill?.id],
queryFn: async () => {
if (!skill) return [];
return await getSkillModels(skill.id);
},
enabled: !!skill,
staleTime: 30 * 1000, // Cache for 30 seconds
});
const { data: evaluations = [], isLoading: isLoadingEvaluations } = useQuery({
queryKey: ['skill-validation-evaluations', skill?.id],
queryFn: async () => {
if (!skill) return [];
return await getSkillEvaluations(skill.id);
},
enabled: !!skill,
staleTime: 30 * 1000, // Cache for 30 seconds
});
const modelsCount = models.length;
const evaluationsCount = evaluations.length;
const optimize = skill?.optimize ?? false;
const isLoading = isLoadingModels || isLoadingEvaluations;
const ready = isSkillReady(modelsCount, evaluationsCount, optimize);
const missingRequirements: string[] = [];
if (modelsCount === 0) {
missingRequirements.push('At least one model must be configured');
}
if (optimize && evaluationsCount === 0) {
missingRequirements.push('At least one evaluation must be configured');
}
return {
isReady: ready,
modelsCount,
evaluationsCount,
isLoading,
missingRequirements,
};
}
|