@eigenpal/docx-editor-core/core-plugins

Core Plugin System

Headless plugin system for extending DocumentAgent with custom commands and exposing MCP tools for AI integration.

Functions (3)

createPluginRegistrarfunctionSource ↗

Create a plugin registration helper with options pre-configured

declare function createPluginRegistrar(options: PluginOptions): (plugin: CorePlugin) => PluginRegistrationResult;

isZodSchemafunctionSource ↗

Check if a schema is Zod-like

declare function isZodSchema(schema: unknown): schema is ZodSchemaLike;

registerPluginsfunctionSource ↗

Register multiple plugins at once

declare function registerPlugins(plugins: CorePlugin[], options?: PluginOptions): PluginRegistrationResult[];

Classes (1)

PluginRegistryclassSource ↗

Plugin Registry - manages core plugins

declare class PluginRegistry
```ts
import { pluginRegistry, docxtemplaterPlugin } from '@eigenpal/docx-editor/core-plugins';

// Register plugins
pluginRegistry.register(docxtemplaterPlugin);

// Get all MCP tools for MCP server
const tools = pluginRegistry.getMcpTools();

// Get command handler for executor
const handler = pluginRegistry.getCommandHandler('insertTemplateVariable');
```
MemberTypeSummary
addEventListenerAdd an event listener
clearClear all registered plugins
getGet a registered plugin by ID
getAllGet all registered plugins
getCommandHandlerGet a command handler for a command type
getCommandTypesGet all registered command types
getDebugInfoGet registry state for debugging
getMcpToolGet an MCP tool by name
getMcpToolsGet all MCP tools from all registered plugins
getMcpToolsForPluginGet MCP tools from a specific plugin
hasCheck if a plugin is registered
hasCommandHandlerCheck if a command type has a handler
registerRegister a plugin
removeEventListenerRemove an event listener
sizenumberGet number of registered plugins
unregisterUnregister a plugin

Interfaces (14)

CommandResultinterfaceSource ↗

Result of command execution

interface CommandResult
MemberTypeSummary
documentDocumentThe modified document
error?stringError message if failed
metadata?Record<string, unknown>Metadata about the operation
successbooleanWhether the command succeeded

CorePlugininterfaceSource ↗

Core plugin interface - headless, works in Node.js

Plugins can: - Register command handlers that DocumentAgent dispatches to - Declare MCP tools that the MCP server exposes to AI clients - Have optional initialization logic - Declare dependencies on other plugins

interface CorePlugin
MemberTypeSummary
commandHandlers?Record<string, CommandHandler>Command handlers this plugin provides. DocumentAgent dispatches commands to these handlers.
dependencies?string[]Dependencies on other plugins (by ID). The registry ensures dependencies are loaded first.
description?stringPlugin description
destroy?() => void | Promise<void>Optional cleanup when plugin is unregistered.
idstringUnique plugin identifier
initialize?() => void | Promise<void>Optional setup when plugin is registered. Called once during plugin registration.
mcpTools?McpToolDefinition[]MCP tools this plugin exposes. MCP server collects these from all plugins.
namestringHuman-readable plugin name
version?stringPlugin version (semver)

JsonSchemainterfaceSource ↗

JSON Schema definition (subset)

interface JsonSchema
MemberTypeSummary
$ref?string
additionalProperties?boolean | JsonSchema
allOf?JsonSchema[]
anyOf?JsonSchema[]
default?unknown
description?string
enum?unknown[]
format?string
items?JsonSchema
maximum?number
maxLength?number
minimum?number
minLength?number
oneOf?JsonSchema[]
pattern?string
properties?Record<string, JsonSchema>
required?string[]
type?string | string[]

LoadedDocumentinterfaceSource ↗

A loaded document in the session

interface LoadedDocument
MemberTypeSummary
buffer?ArrayBufferOriginal buffer (for repacking)
documentDocumentParsed document
idstringDocument ID
lastModifiednumberLast modified timestamp
source?stringSource filename or path

McpSessioninterfaceSource ↗

MCP session state

Maintains state across tool calls within a session.

interface McpSession
MemberTypeSummary
dataMap<string, unknown>Custom session data
documentsMap<string, LoadedDocument>Loaded documents by ID
idstringSession ID

McpToolAnnotationsinterfaceSource ↗

MCP tool annotations

interface McpToolAnnotations
MemberTypeSummary
category?stringTool category for organization
complexity?'low' | 'medium' | 'high'Estimated cost/complexity
examples?McpToolExample[]Example usage
readOnly?booleanWhether this tool modifies the document

McpToolContextinterfaceSource ↗

Context passed to MCP tool handlers

interface McpToolContext
MemberTypeSummary
document?DocumentCurrent document (if loaded)
documentBuffer?ArrayBufferDocument buffer (if loaded)
log(message: string, data?: unknown) => voidLogger for debugging
sessionMcpSessionSession state

McpToolDefinitioninterfaceSource ↗

MCP tool definition

Describes a tool that can be called by AI clients through the MCP server.

interface McpToolDefinition
MemberTypeSummary
annotations?McpToolAnnotationsOptional annotations for the tool
descriptionstringHuman-readable description for AI
handlerMcpToolHandlerHandler function for the tool. Receives validated input and returns a result.
inputSchemaJsonSchema | ZodSchemaLikeJSON Schema for tool input validation. Can be a Zod schema or plain JSON Schema object.
namestringTool name (used in MCP protocol)

McpToolExampleinterfaceSource ↗

MCP tool example

interface McpToolExample
MemberTypeSummary
descriptionstringExample description
inputunknownExample input
output?stringExpected output description

McpToolResultinterfaceSource ↗

MCP tool result

interface McpToolResult
MemberTypeSummary
contentMcpToolContent[]Result content
isError?booleanWhether this is an error result

PluginCommandinterfaceSource ↗

Extended command type for plugins

Plugins can define custom command types beyond the built-in AgentCommand types.

interface PluginCommand
MemberTypeSummary
(member-0)Additional command-specific data
id?stringUnique command ID (for undo tracking)
position?PositionPosition for positional commands
range?RangeRange for range-based commands
typestringCommand type identifier

PluginOptionsinterfaceSource ↗

Plugin configuration options

interface PluginOptions
MemberTypeSummary
config?Record<string, unknown>Custom configuration
debug?booleanEnable debug logging

PluginRegistrationResultinterfaceSource ↗

Result of plugin registration

interface PluginRegistrationResult
MemberTypeSummary
error?stringError message (if failed)
plugin?CorePluginRegistered plugin (if successful)
successbooleanWhether registration succeeded
warnings?string[]Warning messages

ZodSchemaLikeinterfaceSource ↗

Zod-like schema interface for compatibility

interface ZodSchemaLike
MemberTypeSummary
_def?unknown
parse?(data: unknown) => unknown
safeParse?(data: unknown) => { success: boolean; data?: unknown; error?: unknown; }

Type aliases (7)

CommandHandlertypeSource ↗

Command handler function type

Receives a document and a command, returns a modified document. Must be pure/immutable - always return a new document.

type CommandHandler = (doc: Document, command: PluginCommand) => Document;

ExtractCommandtypeSource ↗

Extract command type from a union

type ExtractCommand<T extends AgentCommand, Type extends string> = T extends {
    type: Type;
} ? T : never;

McpToolContenttypeSource ↗

MCP tool content types

type McpToolContent = {
    type: 'text';
    text: string;
} | {
    type: 'image';
    data: string;
    mimeType: string;
} | {
    type: 'resource';
    uri: string;
    mimeType?: string;
    text?: string;
};

McpToolHandlertypeSource ↗

MCP tool handler function

type McpToolHandler = (input: unknown, context: McpToolContext) => Promise<McpToolResult> | McpToolResult;

PluginEventtypeSource ↗

Plugin lifecycle events

type PluginEvent = {
    type: 'registered';
    plugin: CorePlugin;
} | {
    type: 'unregistered';
    pluginId: string;
} | {
    type: 'error';
    pluginId: string;
    error: Error;
};

PluginEventListenertypeSource ↗

Plugin event listener

type PluginEventListener = (event: PluginEvent) => void;

TypedCommandHandlertypeSource ↗

Create a typed command handler

type TypedCommandHandler<T extends PluginCommand> = (doc: Document, command: T) => Document;

Variables (2)

docxtemplaterPluginconstSource ↗

Docxtemplater plugin for template variable functionality.

Dependency validation is handled lazily by processTemplate at call time, so no eager initialize() is needed.

docxtemplaterPlugin: CorePlugin

pluginRegistryconstSource ↗

Global plugin registry instance

Use this for registering plugins and accessing their capabilities.

pluginRegistry: PluginRegistry

On this page