I’ve lately shared some code that colors a face on click. You can use the raycasting code as a basis for you own project.
Instead of updating the color buffer attribute, you extract the vertices from the position attribute with the given indices. These vertices can then be used to build your new triangle.