@eigenpal/docx-editor-agents/bridge

Editor bridge that connects agent tools to a live DocxEditor instance. Framework-agnostic. The React adapter lives in @eigenpal/docx-editor-agents/react.

Functions (4)

createEditorBridgefunctionSource ↗

Create an EditorBridge from a DocxEditorRef.

declare function createEditorBridge(editorRef: EditorRefLike, author?: string): EditorBridge;

createReviewerBridgefunctionSource ↗

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;

executeToolCallfunctionSource ↗

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

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

getToolSchemasfunctionSource ↗

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

Interfaces (7)

AgentToolDefinitioninterfaceSource ↗

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)

AgentToolResultinterfaceSource ↗

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

ContentChangeEventinterfaceSource ↗

Event payload for onContentChange.

interface ContentChangeEvent
MemberTypeSummary
changeCountnumberTotal tracked changes after the change.
changesReviewChange[]Snapshot of all current tracked changes.
commentCountnumberTotal comments in the document after the change.
commentsReviewComment[]Snapshot of all current comments.

EditorBridgeinterfaceSource ↗

High-level agent surface over a live editor (or a headless reviewer). Every built-in tool calls into this contract — implement it once and the agent toolkit works against your editor.

interface EditorBridge
MemberTypeSummary
addCommentAdd a comment, anchored to a paragraph by paraId.
applyFormattingApply character formatting (bold / italic / color / size / font / etc.) to a paragraph, or to a unique phrase within it. This is a direct edit — not a tracked change.
findTextLocate text in the document. Returns one handle per matching paragraph.
getChangesGet all tracked changes in the document.
getCommentsGet all comments in the document.
getContentGet document content as structured blocks (each paragraph carries its `paraId`).
getContentAsTextGet document content as paraId-tagged text lines for LLM prompts.
getCurrentPage1-indexed page the user's cursor / selection is on. 0 if unknown.
getPageRead a single page (1-indexed). Returns null if the page does not exist.
getPagesRead a range of pages (1-indexed, inclusive). Out-of-range pages are skipped.
getSelectionRead the user's current cursor / selection.
getTotalPagesTotal number of pages currently rendered in the editor.
insertBreakInsert a page or section break after a paragraph, by paraId. `page` adds a page break; `sectionNextPage` / `sectionContinuous` start a new section on a new page / the same page. Direct edit, not a tracked change.
onContentChangeSubscribe to document content changes. Returns an unsubscribe function.
onSelectionChangeSubscribe to selection changes (cursor moves / selection changes). Returns an unsubscribe function.
proposeChangeSuggest a tracked change. `replaceWith=''` deletes; `search=''` inserts at paragraph end.
replyToReply to an existing comment. Returns the reply ID or null.
resolveCommentResolve a comment (mark as done).
scrollToScroll the editor to a paragraph by paraId, optionally flashing it.
setParagraphStyleApply a paragraph style by styleId (e.g. `'Heading1'`, `'Quote'`). Direct edit, not a tracked change.

EditorRefLikeinterfaceSource ↗

Agent-bridge contract every editor adapter (React, Vue, future) MUST satisfy. Versioning: additions are coordinated minor bumps across the fixed group; signature changes / removals are major. See openspec/changes/vue-editor-robust-implementation/design.md Decision 18.

interface EditorRefLike
MemberTypeSummary
addComment
applyFormattingApply character formatting to a paragraph or sub-range. Returns false on missing paraId / ambiguous search.
findInDocument
getComments
getCurrentPage1-indexed page the user's cursor / selection is on. 0 if unknown.
getDocument
getEditorRef
getPageContentRead a single page's paragraphs (1-indexed). Returns null if the page does not exist.
getSelectionInfo
getTotalPagesTotal number of pages currently rendered.
insertBreakInsert a page or section break after the paragraph. Returns false if paraId is unknown.
onContentChange
onSelectionChange
proposeChange
replyToComment
resolveComment
scrollToParaId
setParagraphStyleApply a paragraph style by styleId. Returns false if paraId is unknown.

ParagraphHighlightOptionsinterface

Customization for the transient paragraph flash applied by scrollToParaId(paraId, { highlight }).

interface ParagraphHighlightOptions
MemberTypeSummary
color?stringCSS color used for the transient paragraph flash. Defaults to yellow.
durationMs?numberHow long the flash remains visible before it is removed. Defaults to 1200ms.

ScrollToParaIdOptionsinterface

Optional reveal behavior for scrollToParaId.

interface ScrollToParaIdOptions
MemberTypeSummary
highlight?ParagraphHighlightOptionsFlash rendered paragraph fragments after scrolling to the paragraph.

Type aliases (1)

SelectionChangeEventtypeSource ↗

Event payload for onSelectionChange.

type SelectionChangeEvent = SelectionInfo | null;

Variables (1)

agentToolsconstSource ↗

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

On this page