MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / useAgentValidation

Function useAgentValidation

cli/src/hooks/use-agent-validation.ts:28–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 * Call validate() manually to trigger validation (e.g., on message send).
27 */
28export const useAgentValidation = (): UseAgentValidationResult => {
29 const [validationErrors, setValidationErrors] = useState<ValidationError[]>(
30 [],
31 )
32 const [isValidating, setIsValidating] = useState(false)
33
34 // Validate agents and update state
35 // Returns validation result with success status and any errors
36 const validate = useCallback(async (): Promise<ValidationCheckResult> => {
37 setIsValidating(true)
38
39 try {
40 const agentDefinitions = loadAgentDefinitions()
41
42 const validationResult = await validateAgents(agentDefinitions, {
43 remote: true,
44 })
45
46 if (validationResult.success) {
47 setValidationErrors([])
48 return { success: true, errors: [] }
49 } else {
50 const filteredValidationErrors = filterNetworkErrors(
51 validationResult.validationErrors,
52 )
53 setValidationErrors(filteredValidationErrors)
54 return { success: false, errors: filteredValidationErrors }
55 }
56 } catch (error) {
57 logger.error({ error }, 'Agent validation failed with exception')
58 // Don't update validation errors on exception - keep previous state
59 // Return failure to block message sending on validation errors
60 return { success: false, errors: [] }
61 } finally {
62 setIsValidating(false)
63 }
64 }, [])
65
66 return {
67 validationErrors,
68 isValidating,
69 validate,
70 }
71}

Callers 1

ChatFunction · 0.90

Calls 3

loadAgentDefinitionsFunction · 0.90
validateAgentsFunction · 0.90
filterNetworkErrorsFunction · 0.90

Tested by

no test coverage detected