🦋️ SuperDoc - Modern DOCX Editor and Agent SDK
翻译准备中
正在加载完整 README。 以下为已保存的摘录。
The document engine for DOCX files.
Render and edit DOCX files in the browser. Use the same Document API for server-side automation and agent workflows.
Built directly on OOXML. Edits write back to the XML without an HTML conversion step.
SuperDoc mounts into elements you provide, so the page needs both before it
runs:
document accepts a URL, a File, or a Blob. Omit it to start with a blank
DOCX. See the documentation or the
React quick start for next
steps.查看完整 README ↗Tracked changes, threaded comments, tables, headers, and footers stay DOCX structures, and pages lay out as in Word. Edits write back to OOXML without an HTML conversion step.
npm install superdoc
SuperDoc mounts into elements you provide:
<div id="toolbar"></div>
<div id="editor"></div>
<button id="export" type="button" disabled>Export DOCX</button>
import { SuperDoc } from 'superdoc';
import 'superdoc/style.css';
const superdoc = new SuperDoc({
selector: '#editor',
document: '/sample.docx',
documentMode: 'editing',
ui: { toolbar: { container: '#toolbar' } },
onReady: () => { document.querySelector('#export').disabled = false; },
});
document.querySelector('#export').addEventListener('click', async () => {
await superdoc.export({ exportType: ['docx'], exportedName: 'sample-edited' });
});
document accepts a URL, a File, or a Blob. Omit it to start with a blank
DOCX. documentMode is 'editing', 'suggesting', or 'viewing'. The editor
needs no server of its own.
Next, follow the editor quick start for a complete vanilla JavaScript or React project, then configure the editor.
Use a headless SDK to let your own LLM review and edit DOCX files. This example uses the Node.js SDK with the Vercel AI SDK to change a contract's payment terms as tracked changes.
npm install @superdoc/sdk ai@6 @ai-sdk/anthropic@3
curl -fL https://raw.githubusercontent.com/superdoc/docx-editor/refs/heads/main/assets/sample-contract.docx -o sample-contract.docx
Set ANTHROPIC_API_KEY and ANTHROPIC_MODEL before running it.
import { SuperDocClient, createAgentToolkit } from '@superdoc/sdk';
import { anthropic } from '@ai-sdk/anthropic';
import { generateText, jsonSchema, stepCountIs } from 'ai';
const client = new SuperDocClient({
user: { name: 'Contract assistant', email: '[email protected]' },
});
try {
await client.connect();
const doc = await client.open({ doc: './sample-contract.docx' });
const toolkit = await createAgentToolkit({
provider: 'vercel', preset: 'core', enforceChangeMode: 'tracked',
});
const tools = Object.fromEntries(toolkit.tools.map(tool => [tool.name, {
description: tool.description,
inputSchema: jsonSchema(tool.inputSchema),
execute: args => toolkit.dispatch(doc, tool.name, args),
}]));
await generateText({
model: anthropic(process.env.ANTHROPIC_MODEL),
system: toolkit.systemPrompt,
prompt: 'Change payment terms from 60 to 30 days',
tools,
stopWhen: stepCountIs(10),
});
await doc.save({ out: './sample-contract-reviewed.docx' });
} finally {
await client.dispose();
}
Your LLM chooses which SuperDoc tools to call; SuperDoc runs the document
operations and, with enforceChangeMode: 'tracked', records every edit as a
tracked change. Document content sent to the model is subject to the model
provider's policies.
Before saving in production, check each edit's receipt. See Build an agent for the full loop and verification, and real-time collaboration to have agents and users edit the same document at once.
examples/: small, runnable projects for common workflows.SuperDoc reads, renders, edits, and writes DOCX files through their Office Open XML (OOXML) parts.
The same engine runs without a browser DOM, so the editor, SDKs, CLI, and MCP server share one document model.
| Package | Purpose |
|---|---|
superdoc | Browser DOCX editor for JavaScript and TypeScript. |
@superdoc/react | React wrapper for the editor. |
@superdoc/vue | Vue wrapper for the editor. |
@superdoc/sdk | Node.js SDK for headless DOCX editing and agent toolkits. |
@superdoc/cli | superdoc command-line interface. |
@superdoc/mcp | MCP server for AI agents and MCP clients. |
@superdoc/fonts | Optional metric-compatible font substitutes. |
superdoc-sdk (PyPI) | Python SDK. See the Python SDK guide. |
superdoc-sdk (crates.io) | Rust SDK. See its README. |
以上为 README 的开头部分。其余内容请阅读原文。 查看完整 README ↗