@eigenpal/docx-editor-agents
Subpaths
@eigenpal/docx-editor-agents/bridge
Editor bridge that connects agent tools to a live
DocxEditorinstance. Framework-agnostic. The React adapter lives in@eigenpal/docx-editor-agents/react.@eigenpal/docx-editor-agents/server
Server entry for API routes, Node.js, serverless functions, and Workers.
@eigenpal/docx-editor-agents/react
React entry. Hooks, components, and types that need React as a peer dependency. Pair with
/server(or/ai-sdk/server) for the API route that drives the LLM.@eigenpal/docx-editor-agents/vue
Vue entry. Components and composables that need Vue as a peer dependency.
@eigenpal/docx-editor-agents/mcp
Model Context Protocol (MCP) server for the docx editor agent bridge.
@eigenpal/docx-editor-agents/ai-sdk/server
Vercel AI SDK adapter (server side). Opt-in.
@eigenpal/docx-editor-agents/ai-sdk/react
Vercel AI SDK adapter (React side). Opt-in.
@eigenpal/docx-editor-agents/ai-sdk/vue
Vercel AI SDK adapter (Vue side). Opt-in.
Package root: @eigenpal/docx-editor-agents
Functions(3)
createReviewerBridge
Create an EditorBridge backed by a DocxReviewer. The agent (or MCP client) can read, comment, propose changes, etc., against a parsed DOCX file on disk. Call `reviewer.toBuffer()` afterwards to get the modified DOCX.
declare function createReviewerBridge(reviewer: DocxReviewer): EditorBridge;executeToolCall
Execute a tool call against an EditorBridge. Returns the result (never throws).
declare function executeToolCall(toolName: string, input: Record<string, unknown>, bridge: EditorBridge): AgentToolResult;getToolSchemas
Get tool schemas in OpenAI function-calling format. Works directly with the OpenAI SDK and Anthropic's tools API. For Vercel AI SDK, LangChain, or other agent runtimes, transform this output to that runtime's required shape — see `examples/agent-chat-demo/` for a Vercel AI SDK example. The package stays runtime-agnostic.
declare function getToolSchemas(): {
type: "function";
function: {
name: string;
description: string;
parameters: Record<string, unknown>;
};
}[];Classes(5)
ChangeNotFoundError
declare class ChangeNotFoundError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `ChangeNotFoundError` class |
CommentNotFoundError
declare class CommentNotFoundError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `CommentNotFoundError` class |
DocxReviewer
Headless DOCX reviewer — parse a file, read/comment/track changes against the document model, write the modified DOCX back out. No DOM, no editor instance. Pair with `createReviewerBridge()` to drive the built-in agent tools against a file on disk.
declare class DocxReviewer```ts
const reviewer = await DocxReviewer.fromBuffer(buffer, 'AI Reviewer');
reviewer.addComment(5, 'Fix this paragraph.');
reviewer.replace(5, '$50k', '$500k');
const output = await reviewer.toBuffer();
```| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Create a reviewer from a parsed Document. |
| acceptAll | — | Accept all tracked changes. Returns count accepted. |
| acceptChange | — | Accept a tracked change by its revision ID. Operates on the document body only. |
| addComment | — | Add a comment on a paragraph. |
| addComment | — | Add a comment with full options (custom author, anchored to specific text). |
| applyReview | — | Apply multiple review operations in one call. Uses the reviewer's default author. Individual failures are collected, not thrown. |
| author | string | Default author for comments and tracked changes. Set once, used everywhere. |
| fromBuffer | — | Create a reviewer from a DOCX file buffer. |
| getChanges | — | Get all tracked changes in the document. Pass `includeFootnotes` / `includeEndnotes` in the filter to also report changes inside note bodies (each such change carries `noteId` / `noteType`). |
| getComments | — | Get all comments with their replies. |
| getContent | — | Get document content as structured blocks (headings, paragraphs, tables, lists). |
| getContentAsText | — | Get document content as plain text for LLM prompts. Each paragraph is prefixed with its index: `[0] text`, `[1] text`, etc. Table cells include position: `[5] (table, row 1, col 2) cell text`. Avoids JSON quote-escaping issues — LLMs can copy text verbatim. |
| proposeDeletion | — | Delete text as a tracked change. |
| proposeInsertion | — | Insert text as a tracked change. |
| proposeReplacement | — | |
| rejectAll | — | Reject all tracked changes. Returns count rejected. |
| rejectChange | — | Reject a tracked change by its revision ID. Operates on the document body only. |
| removeComment | — | Remove a comment by ID. Removing a top-level comment also removes its replies and the anchored range markers. Removing a reply only removes that reply. |
| replace | — | Replace text in a paragraph. Creates a tracked change (deletion + insertion). |
| replace | — | Replace text with full options. |
| replyTo | — | Reply to an existing comment. |
| replyTo | — | Reply to an existing comment with full options. |
| toBuffer | — | Serialize back to a DOCX buffer. Requires the original buffer. |
| toDocument | — | Get the modified Document model. |
NoteChangeNotEditableError
Thrown when accept/reject resolves a tracked change to a footnote or endnote body. accept/reject operate on the document body only, and a tracked-change `w:id` is unique only within its part (document.xml / footnotes.xml / endnotes.xml), so a note change cannot be mutated through this reviewer yet. Fails closed rather than silently no-op'ing or mis-reporting the change as not-found.
declare class NoteChangeNotEditableError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `NoteChangeNotEditableError` class |
TextNotFoundError
Error classes for eigenpal/docx-editor-agents
declare class TextNotFoundError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | — | Constructs a new instance of the `TextNotFoundError` class |
Interfaces(9)
AgentToolDefinition
Definition of an agent tool — name, JSON-schema input, handler. Use this to build custom tools alongside the built-in `agentTools`.
interface AgentToolDefinition<TInput = Record<string, unknown>>| Member | Type | Summary |
|---|---|---|
| description | string | Human-readable description for the LLM |
| displayName? | string | Friendly UI label for the tool. Shown in the agent panel's timeline (e.g. "Reading document"). Falls back to a sentence-case version of `name` if omitted, so consumer-defined tools render readably without specifying this. |
| handler | (input: TInput, bridge: EditorBridge) => AgentToolResult | Handler — receives parsed input + bridge, returns result |
| inputSchema | Record<string, unknown> | JSON Schema for the input parameters |
| name | string | Tool name (used in tool_use blocks) |
AgentToolResult
Result returned by a tool handler. `success: false` carries an `error` message; `success: true` may carry tool-specific `data`.
interface AgentToolResult| Member | Type | Summary |
|---|---|---|
| data? | unknown | |
| error? | string | |
| success | boolean |
BatchError
interface BatchError| Member | Type | Summary |
|---|---|---|
| error | string | |
| id? | number | |
| operation | string | |
| search? | string |
BatchResult
interface BatchResult| Member | Type | Summary |
|---|---|---|
| accepted | number | |
| commentsAdded | number | |
| errors | BatchError[] | |
| proposalsAdded | number | |
| rejected | number | |
| repliesAdded | number |
BatchReviewOptions
interface BatchReviewOptions| Member | Type | Summary |
|---|---|---|
| accept? | number[] | |
| comments? | AddCommentOptions[] | |
| proposals? | ProposeReplacementOptions[] | |
| reject? | number[] | |
| replies? | (ReplyOptions & {
commentId: number;
})[] |
GetContentOptions
interface GetContentOptions| Member | Type | Summary |
|---|---|---|
| fromIndex? | number | |
| includeCommentAnchors? | boolean | Annotate comments inline. Default: true |
| includeTrackedChanges? | boolean | Annotate tracked changes inline. Default: true |
| toIndex? | number |
ReviewChange
interface ReviewChange| Member | Type | Summary |
|---|---|---|
| author | string | |
| context | string | |
| date | string | null | |
| id | number | |
| noteId? | number | Set when the change lives inside a footnote or endnote. Such changes are surfaced for discovery only — accept/reject operate on the body, so an id that resolves *only* to a note change throws `NoteChangeNotEditableError` (an id also present on a body change resolves to the body change). The raw `id` is not namespaced across parts, so pair it with `noteId` / `noteType` to identify the change. |
| noteType? | 'footnote' | 'endnote' | Which note store the change came from. Absent for body changes. |
| paragraphIndex | number | Index of the containing paragraph. For body changes this is the document-wide paragraph index; for note changes it is the paragraph index *within that note* (note bodies have their own numbering), so pair it with `noteId` / `noteType` rather than reading it as a body index. |
| text | string | |
| type | 'insertion' | 'deletion' | 'moveFrom' | 'moveTo' |
ReviewComment
interface ReviewComment| Member | Type | Summary |
|---|---|---|
| anchoredText | string | |
| author | string | |
| date | string | null | |
| done | boolean | |
| id | number | |
| paragraphIndex | number | |
| replies | ReviewCommentReply[] | |
| text | string |
WordCompatBridge
The formal Word-JS-API parity surface. Each method maps to one or more Word API methods (named in the JSDoc above each member).
If you change the EditorBridge surface, this interface must change too — the static assertion at the bottom of the file enforces it.
interface WordCompatBridge| Member | Type | Summary |
|---|---|---|
| addComment | — | Word: `range.insertComment(text)`. Anchored by paraId (Range handle). |
| applyFormatting | — | Word: `range.font.bold = true` / `range.font.italic = true` / etc. Applied to a paragraph or to a unique phrase within it. Direct edit, not a tracked change. |
| findText | — | Word: `body.search(text)` returning Range[]. |
| getChanges | — | Word: `revisionCollection.getItems()`. |
| getComments | — | Word: `commentCollection.getItems()`. |
| getContent | — | Word: `body.paragraphs.getItems()`. |
| getContentAsText | — | Word: `document.body.text` (stringified, indexed lines). |
| getPage | — | Read one rendered page (1-indexed). Word's JS API does not expose pages as first-class objects; we do because the editor is paged. |
| getPages | — | Read a range of rendered pages (1-indexed, inclusive). |
| getSelection | — | Word: `document.getSelection()`. |
| getTotalPages | — | Total number of pages currently rendered. |
| onContentChange | — | Word: `Document.onContentChanged.add(handler)`. Returns unsubscribe. |
| onSelectionChange | — | Word: `Document.onSelectionChanged.add(handler)`. Returns unsubscribe. |
| proposeChange | — | Word: `range.insertText(text, location)` collapsed into one verb. - replacement: search non-empty, replaceWith non-empty - deletion: search non-empty, replaceWith "" - insertion: search "", replaceWith non-empty (paragraph end) |
| replyTo | — | Word: `comment.reply(text)`. |
| resolveComment | — | Word: `comment.resolved = true`. |
| scrollTo | — | Word: `range.scrollIntoView()`. |
| setParagraphStyle | — | Word: `paragraph.styleBuiltIn = ...` / `paragraph.style = 'Heading 1'`. |
Type aliases(1)
ContentBlock
type ContentBlock = HeadingBlock | ParagraphBlock | TableBlock | ListItemBlock;Variables(1)
agentTools
All built-in agent tools — read/write document content, comments, and tracked changes. Use `getToolSchemas()` to feed them to an LLM and `executeToolCall()` to run the handlers against an `EditorBridge`.
agentTools: AgentToolDefinition<any>[]