How emend Works
What happens between typing a request and seeing the AI's change in your editor.
emend is made of four parts. Each one has a single job, so you can change one without touching the others.
The four parts
@emend/aiSends your text to the server and shows the AI's suggestion.- Your Tiptap editor. It holds your document, the undo history, and saving. emend never takes this over.
- The
@emend/aipackage. It reads the text the AI needs, sends it to your server, receives the answer, shows the preview, and applies the change when you accept it. - The AI components. The Bubble Menu, Composer, and AI Assistant. These are the buttons and inputs people see. Their source is copied into your app, so you can restyle or change them.
- Your server route. It checks who is making the request, calls the AI model, and streams the answer back.
The components do not include the AI logic themselves. They all use the
@emend/ai package.
Ask and Edit
There are two kinds of requests: Ask and Edit.
| Request | What you get | Does it change your document? |
|---|---|---|
| Ask | An answer to read | Never |
| Edit | A suggested change to review | Only after you click Accept |
You do not pick the kind yourself. If you select text and choose an action, it is an Edit. If you just type a question, it is an Ask.
What the AI reads and what it changes
emend keeps these two things separate:
- What the AI reads. Text it can look at to give a better answer: the selected text, the current paragraph, or the whole document.
- What the AI changes. The exact piece of text an edit is allowed to replace.
Letting the AI read the whole document does not let it change the whole document. For example, the AI can read the whole page to understand it, but only rewrite the one sentence you selected.
Built-in actions such as Improve, Shorten, or Fix grammar already decide both of these for you, so they show no options. In the Composer and the AI Assistant, you can only choose them yourself with Custom instruction. When you just type a question, you can choose what the AI reads.
What happens during an edit
- emend saves a snapshot of the text you selected and what the AI can read.
- Your server sends that to the AI model, and the answer streams back.
- emend checks that your editor can display the answer.
- The suggested change shows up as a preview. Your document has not changed yet.
- Accept replaces the text with the suggestion. Reject removes the preview.
If the document changes while a suggestion is showing, the suggestion is out of date and can no longer be accepted. Moving the cursor or changing the selection does not count as a change.
Why the server route is yours
Only your app knows who your users are, which AI provider you pay for, and how much each user is allowed to use. So the server route lives in your app. emend gives you a handler to build it and a ready-made Vercel AI Gateway recipe. emend does not run a server for you.
Next, read Content and Proposals to learn how suggestions are checked and applied.