Take a look at this for ideas on how to add AI commands to a document editor:
https://news.ycombinator.com/item?id=35442103