New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.0.2

@eigenpal/docx-editor-agents

Word-like API for AI document review.

Functions(3)

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;

Execute a tool call against an EditorBridge. Returns the result (never throws).

declare function executeToolCall(toolName: string, input: Record<string, unknown>, bridge: EditorBridge): AgentToolResult;

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(4)

class

ChangeNotFoundError

packages/agents/src/errors.ts:14
declare class ChangeNotFoundError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `ChangeNotFoundError` class
class

CommentNotFoundError

packages/agents/src/errors.ts:21
declare class CommentNotFoundError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `CommentNotFoundError` class

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();
```
MemberTypeSummary
(constructor)Create a reviewer from a parsed Document.
acceptAllAccept all tracked changes. Returns count accepted.
acceptChangeAccept a tracked change by its revision ID.
addCommentAdd a comment on a paragraph.
addCommentAdd a comment with full options (custom author, anchored to specific text).
applyReviewApply multiple review operations in one call. Uses the reviewer's default author. Individual failures are collected, not thrown.
authorstringDefault author for comments and tracked changes. Set once, used everywhere.
fromBufferCreate a reviewer from a DOCX file buffer.
getChangesGet all tracked changes in the document.
getCommentsGet all comments with their replies.
getContentGet document content as structured blocks (headings, paragraphs, tables, lists).
getContentAsTextGet 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.
proposeDeletionDelete text as a tracked change.
proposeInsertionInsert text as a tracked change.
proposeReplacement
rejectAllReject all tracked changes. Returns count rejected.
rejectChangeReject a tracked change by its revision ID.
removeCommentRemove 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.
replaceReplace text in a paragraph. Creates a tracked change (deletion + insertion).
replaceReplace text with full options.
replyToReply to an existing comment.
replyToReply to an existing comment with full options.
toBufferSerialize back to a DOCX buffer. Requires the original buffer.
toDocumentGet the modified Document model.

Error classes for eigenpal/docx-editor-agents

declare class TextNotFoundError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `TextNotFoundError` class

Interfaces(9)

interface

AgentToolDefinition

packages/agents/src/tools/types.ts:13

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>>
MemberTypeSummary
descriptionstringHuman-readable description for the LLM
displayName?stringFriendly 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) => AgentToolResultHandler — receives parsed input + bridge, returns result
inputSchemaRecord<string, unknown>JSON Schema for the input parameters
namestringTool name (used in tool_use blocks)

Result returned by a tool handler. `success: false` carries an `error` message; `success: true` may carry tool-specific `data`.

interface AgentToolResult
MemberTypeSummary
data?unknown
error?string
successboolean
interface BatchError
MemberTypeSummary
errorstring
id?number
operationstring
interface BatchResult
MemberTypeSummary
acceptednumber
commentsAddednumber
errorsBatchError[]
proposalsAddednumber
rejectednumber
repliesAddednumber
interface

BatchReviewOptions

packages/agents/src/types.ts:263
interface BatchReviewOptions
MemberTypeSummary
accept?number[]
comments?AddCommentOptions[]
proposals?ProposeReplacementOptions[]
reject?number[]
replies?(ReplyOptions & { commentId: number; })[]
interface

GetContentOptions

packages/agents/src/types.ts:52
interface GetContentOptions
MemberTypeSummary
fromIndex?number
includeCommentAnchors?booleanAnnotate comments inline. Default: true
includeTrackedChanges?booleanAnnotate tracked changes inline. Default: true
toIndex?number
interface ReviewChange
MemberTypeSummary
authorstring
contextstring
datestring | null
idnumber
paragraphIndexnumber
textstring
type'insertion' | 'deletion' | 'moveFrom' | 'moveTo'
interface ReviewComment
MemberTypeSummary
anchoredTextstring
authorstring
datestring | null
doneboolean
idnumber
paragraphIndexnumber
repliesReviewCommentReply[]
textstring

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
MemberTypeSummary
addCommentWord: `range.insertComment(text)`. Anchored by paraId (Range handle).
applyFormattingWord: `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.
findTextWord: `body.search(text)` returning Range[].
getChangesWord: `revisionCollection.getItems()`.
getCommentsWord: `commentCollection.getItems()`.
getContentWord: `body.paragraphs.getItems()`.
getContentAsTextWord: `document.body.text` (stringified, indexed lines).
getPageRead one rendered page (1-indexed). Word's JS API does not expose pages as first-class objects; we do because the editor is paged.
getPagesRead a range of rendered pages (1-indexed, inclusive).
getSelectionWord: `document.getSelection()`.
getTotalPagesTotal number of pages currently rendered.
onContentChangeWord: `Document.onContentChanged.add(handler)`. Returns unsubscribe.
onSelectionChangeWord: `Document.onSelectionChanged.add(handler)`. Returns unsubscribe.
proposeChangeWord: `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)
replyToWord: `comment.reply(text)`.
resolveCommentWord: `comment.resolved = true`.
scrollToWord: `range.scrollIntoView()`.
setParagraphStyleWord: `paragraph.styleBuiltIn = ...` / `paragraph.style = 'Heading 1'`.

Type aliases(1)

type ContentBlock = HeadingBlock | ParagraphBlock | TableBlock | ListItemBlock;

Variables(1)

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>[]