.docx: a Mastra agent edits the document through
Vespper, and its edits appear in
EigenPal’s docx-editor as tracked
changes.
What the example includes
- Suggestion cards to review, edit, and apply the agent’s edits
- Live document updates through the docx-editor document refresh API
- Selected text and pasted images as prompt context
- Multi-model selection
Prerequisites
- Node.js 22.13 or newer
- A Vespper account
- A model-provider API key for OpenAI, Anthropic, or Google
Set up the example
Get a Vespper API key
Sign up for Vespper, then create a key on the
API keys page. Copy the
sk_live_...
secret immediately; it is shown only once.Install the example
Clone the repository, then install the dependencies:Edit Only one model-provider key is required:By default, the agent proposes edits as suggestion cards that you accept
or reject. To have it apply edits to the document as it writes them, set:
.env and add your Vespper key plus the key for the model provider
you want to use:.env
OpenAI GPT 5.6 Sol is the default. To start with another model, set
DOCX_AGENT_MODEL in .env, for example:.env
.env
Run it
http://localhost:3001 and the web app at
http://localhost:5173. Vite proxies /api and
/health to the API server.Try an edit
- Drop a
.docxonto the right pane. - Ask the AI agent for an edit.
- Optionally select text in the document to include it as context, or paste images into the prompt.
How it works
The API server follows Vespper’s live-editing architecture: it runs an agent with the Vespper tools and handles eachold/new pair of an edit_document call
as soon as the model finishes writing it.
- Suggestion mode (the default): each pair is proposed to the user in the
chat as a suggestion card, without changing the document. Accepted cards go to
POST /api/apply, which applies them. See Suggestions. - Direct mode (
USE_SUGGESTIONS=false): each pair is applied right away.
edit_applied event that carries the complete, cumulative .docx and its
revision number.
Updating the editor
The browser loads each new file through the docx-editor document refresh API, for both agent turns and Apply:refresh.capture()snapshots the document that goes to the server.- Each
edit_appliedevent callsrefresh.applyUpdate(), which swaps in the new file and keeps the scroll position. refresh.highlightChanges()flashes the new tracked changes.refresh.finish()closes the update.
src/agent/updateQueue.ts.
Development commands
Project layout
Licensing
This example is MIT licensed. It depends on@docx-editor.dev/pro for tracked-change rendering and
the review rail, which is distributed under the
EigenPal Pro Evaluation License:
internal, non-production evaluation only. Contact EigenPal for a production
license. Without the review module, docx-editor shows revisions in their
accepted state and keeps them in the saved file.
View the complete example on GitHub
Browse the source code and standalone README.

