@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)
createPluginRegistrar
Create a plugin registration helper with options pre-configured
declare function createPluginRegistrar(options: PluginOptions): (plugin: CorePlugin) => PluginRegistrationResult;isZodSchema
Check if a schema is Zod-like
declare function isZodSchema(schema: unknown): schema is ZodSchemaLike;registerPlugins
Register multiple plugins at once
declare function registerPlugins(plugins: CorePlugin[], options?: PluginOptions): PluginRegistrationResult[];Classes(1)
PluginRegistry
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');
```| Member | Type | Summary |
|---|---|---|
| addEventListener | — | Add an event listener |
| clear | — | Clear all registered plugins |
| get | — | Get a registered plugin by ID |
| getAll | — | Get all registered plugins |
| getCommandHandler | — | Get a command handler for a command type |
| getCommandTypes | — | Get all registered command types |
| getDebugInfo | — | Get registry state for debugging |
| getMcpTool | — | Get an MCP tool by name |
| getMcpTools | — | Get all MCP tools from all registered plugins |
| getMcpToolsForPlugin | — | Get MCP tools from a specific plugin |
| has | — | Check if a plugin is registered |
| hasCommandHandler | — | Check if a command type has a handler |
| register | — | Register a plugin |
| removeEventListener | — | Remove an event listener |
| size | number | Get number of registered plugins |
| unregister | — | Unregister a plugin |
Interfaces(14)
CommandResult
Result of command execution
interface CommandResult| Member | Type | Summary |
|---|---|---|
| document | Document | The modified document |
| error? | string | Error message if failed |
| metadata? | Record<string, unknown> | Metadata about the operation |
| success | boolean | Whether the command succeeded |
CorePlugin
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| Member | Type | Summary |
|---|---|---|
| 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? | string | Plugin description |
| destroy? | () => void | Promise<void> | Optional cleanup when plugin is unregistered. |
| id | string | Unique 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. |
| name | string | Human-readable plugin name |
| version? | string | Plugin version (semver) |
JsonSchema
JSON Schema definition (subset)
interface JsonSchema| Member | Type | Summary |
|---|---|---|
| $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[] |
LoadedDocument
A loaded document in the session
interface LoadedDocument| Member | Type | Summary |
|---|---|---|
| buffer? | ArrayBuffer | Original buffer (for repacking) |
| document | Document | Parsed document |
| id | string | Document ID |
| lastModified | number | Last modified timestamp |
| source? | string | Source filename or path |
McpSession
MCP session state
Maintains state across tool calls within a session.
interface McpSession| Member | Type | Summary |
|---|---|---|
| data | Map<string, unknown> | Custom session data |
| documents | Map<string, LoadedDocument> | Loaded documents by ID |
| id | string | Session ID |
McpToolAnnotations
MCP tool annotations
interface McpToolAnnotations| Member | Type | Summary |
|---|---|---|
| category? | string | Tool category for organization |
| complexity? | 'low' | 'medium' | 'high' | Estimated cost/complexity |
| examples? | McpToolExample[] | Example usage |
| readOnly? | boolean | Whether this tool modifies the document |
McpToolContext
Context passed to MCP tool handlers
interface McpToolContext| Member | Type | Summary |
|---|---|---|
| document? | Document | Current document (if loaded) |
| documentBuffer? | ArrayBuffer | Document buffer (if loaded) |
| log | (message: string, data?: unknown) => void | Logger for debugging |
| session | McpSession | Session state |
McpToolDefinition
MCP tool definition
Describes a tool that can be called by AI clients through the MCP server.
interface McpToolDefinition| Member | Type | Summary |
|---|---|---|
| annotations? | McpToolAnnotations | Optional annotations for the tool |
| description | string | Human-readable description for AI |
| handler | McpToolHandler | Handler function for the tool. Receives validated input and returns a result. |
| inputSchema | JsonSchema | ZodSchemaLike | JSON Schema for tool input validation. Can be a Zod schema or plain JSON Schema object. |
| name | string | Tool name (used in MCP protocol) |
McpToolExample
MCP tool example
interface McpToolExample| Member | Type | Summary |
|---|---|---|
| description | string | Example description |
| input | unknown | Example input |
| output? | string | Expected output description |
McpToolResult
MCP tool result
interface McpToolResult| Member | Type | Summary |
|---|---|---|
| content | McpToolContent[] | Result content |
| isError? | boolean | Whether this is an error result |
PluginCommand
Extended command type for plugins
Plugins can define custom command types beyond the built-in AgentCommand types.
interface PluginCommand| Member | Type | Summary |
|---|---|---|
| (member-0) | — | Additional command-specific data |
| id? | string | Unique command ID (for undo tracking) |
| position? | Position | Position for positional commands |
| range? | Range | Range for range-based commands |
| type | string | Command type identifier |
PluginOptions
Plugin configuration options
interface PluginOptions| Member | Type | Summary |
|---|---|---|
| config? | Record<string, unknown> | Custom configuration |
| debug? | boolean | Enable debug logging |
PluginRegistrationResult
Result of plugin registration
interface PluginRegistrationResult| Member | Type | Summary |
|---|---|---|
| error? | string | Error message (if failed) |
| plugin? | CorePlugin | Registered plugin (if successful) |
| success | boolean | Whether registration succeeded |
| warnings? | string[] | Warning messages |
ZodSchemaLike
Zod-like schema interface for compatibility
interface ZodSchemaLike| Member | Type | Summary |
|---|---|---|
| _def? | unknown | |
| parse? | (data: unknown) => unknown | |
| safeParse? | (data: unknown) => {
success: boolean;
data?: unknown;
error?: unknown;
} |
Type aliases(7)
CommandHandler
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;ExtractCommand
Extract command type from a union
type ExtractCommand<T extends AgentCommand, Type extends string> = T extends {
type: Type;
} ? T : never;McpToolContent
MCP tool content types
type McpToolContent = {
type: 'text';
text: string;
} | {
type: 'image';
data: string;
mimeType: string;
} | {
type: 'resource';
uri: string;
mimeType?: string;
text?: string;
};McpToolHandler
MCP tool handler function
type McpToolHandler = (input: unknown, context: McpToolContext) => Promise<McpToolResult> | McpToolResult;PluginEvent
Plugin lifecycle events
type PluginEvent = {
type: 'registered';
plugin: CorePlugin;
} | {
type: 'unregistered';
pluginId: string;
} | {
type: 'error';
pluginId: string;
error: Error;
};PluginEventListener
Plugin event listener
type PluginEventListener = (event: PluginEvent) => void;TypedCommandHandler
Create a typed command handler
type TypedCommandHandler<T extends PluginCommand> = (doc: Document, command: T) => Document;Variables(2)
docxtemplaterPlugin
Docxtemplater plugin for template variable functionality.
Dependency validation is handled lazily by `processTemplate` at call time, so no eager `initialize()` is needed.
docxtemplaterPlugin: CorePluginpluginRegistry
Global plugin registry instance
Use this for registering plugins and accessing their capabilities.
pluginRegistry: PluginRegistry