Collaboration Extension Modules
Understand how History, Thread Comment, Worktree, File, and server-side Office Exchange extend core collaboration.
History, Thread Comment, File, and Worktree are optional collaboration extension modules that extend collaboration without changing the core. Each module provides its own Service, Middleware, Event, Database Adapter, and lifecycle boundary, so an application enables only the modules that the product requires. The modules can still share the Transport, the identity system, and the same physical database.
Server-side Office Exchange builds on File and Collaboration Service. It converts between Office files and collaborative Units, and it provides its own Service, Endpoint, and Middleware.
Module relationships
| Extension module | Relationship with Core Collaboration |
|---|---|
| History | Observes Core Events to build a derived history index |
| Thread Comment | Reuses the Core Unit Room; comment anchors belong to Core content |
| File | Stores the images, attachments, and exchange files a Unit references; Unit data records only file IDs |
| Office Exchange | Creates or reads Units through Core Service and reads and writes files through File |
| Worktree | Reuses Core Unit and OT capabilities and merges drafts into the trunk |
History, Thread Comment, File, and Worktree each configure their own Middleware, Events, and Database Adapters.
Version history
History turns Unit creation and confirmed changesets into the history entries that a user sees. The index is derived: the confirmed changesets in Core Collaboration Service remain the authoritative source of Unit content.
const historyService = new UniverHistoryService({ collabService, dbAdapter: historyDatabase, userProvider,});transport.register(new UniverHistoryEndpoint(historyService));The constructor subscribes to the Core Service unitCreated and changesetCommitted Events and keeps the index current, and dispose() removes those subscriptions. By default, History groups changes by time window and by special mutations rather than writing an entry for every changeset.
History exposes read Middleware for getHistoryList, listHistoryCreators, and getHistoryChangesets. Indexing takes place inside the service. userProvider only supplies display data such as names and avatars, and it performs neither authentication nor authorization. An Event Listener failure does not roll back a Core changeset that is already confirmed, so History should be treated as derived data that can always be rebuilt.
Thread Comment
Comment Service manages comment bodies, replies, edits, deletion, and resolution status.
const commentService = new UniverCommentService({ database: commentDatabase, userProvider,});transport.register( new UniverCommentEndpoint({ service: commentService, roomHost: collabEndpoint, }),);Comment bodies belong to the Comment Adapter, while the anchors that move with Sheet or Doc content remain part of Core snapshots and changesets. The Comment Endpoint can publish comment_update through the Unit Room of the main Collaboration Endpoint, but that realtime message is not the authoritative comment state. A Client that misses the message can recover by listing the comments again.
Comment Service provides Middleware for add, list, reply, solve or reopen, edit, and delete, and it publishes a commentCommitted Event. Comment Service does not inherit the read or edit policy of the Core Service.
File storage
File stores the binary files that Univer clients upload: images and attachments inserted into a Unit, and the source and result files of import and export. Unit data records only the file ID, and the client resolves that ID to a download URL when it loads the Unit. Snapshots and changesets therefore stay small.
const fileService = new UniverFileService({ database: fileDatabase, blobStore,});transport.register(new UniverFileEndpoint(fileService));Metadata and content are two independent contracts: IFileDatabaseAdapter stores file records and IFileBlobStore stores content. Temporary exchange files are accessible only to the user who uploaded them, and the Service deletes them on a schedule. Images and attachments inside a Unit are subject to Unit permissions through the upload, signUrl, and download Middleware.
Server-side Office Exchange
Exchange Service imports Office files as collaborative Units and exports Units as files. It uses @univerjs-pro/exchange-node for the conversion, creates and reads Units through Collaboration Service, and stores the source and result files through File Service:
const exchangeService = new UniverExchangeService({ collabService, fileService });transport.register(new UniverExchangeEndpoint(exchangeService));Import and export are tasks. The client creates a task and then polls for the result. Import goes through the createUnit Middleware of the Core Service, and export goes through readUnitData. The import and export Middleware of Exchange handle rate limits, quotas, and audit.
| Unit | Import | Export |
|---|---|---|
| Sheet | xls, xlsx, csv, tsv | xlsx, csv, tsv |
| Doc | doc, docx | docx |
| Slide | ppt, pptx | pptx |
| Base | xls, xlsx, csv, tsv | xlsx, csv |
Worktree drafts and merge
Worktree adds isolated drafts, freezing, merge evaluation, and per-Unit merge for one or more Units:
create → draft → ready → merging → merged ↑ │ └ reopen┘draft / ready → discardedconst worktreeService = new UniverCollabWorktreeService({ trunk: { service: collabService, dbAdapter: coreDatabase, }, dbAdapter: worktreeDatabase,});Worktree stores its own draft changesets by (worktreeID, unitID) and reuses the Unit, OT, and submission engines of the Core Service. Only the draft state accepts further edits. markReady() freezes the current draft revision, and mergeWorktree() merges Units into the trunk one at a time.
Worktree Service has its own lifecycle, its own read Middleware, the draft submit/apply/commit Middleware, and Events for creation, status changes, merge results, and draft changeset commits. The final write to the trunk still goes through the Middleware of the Core Service.
A multi-Unit merge is not atomic across Units. The application should display the merge result for each Unit.
Independent extension points
When an application enables an extension module, each boundary requires separate evaluation:
| Boundary | Core | History | Comment | File | Worktree |
|---|---|---|---|---|---|
| Service | Independent | Independent | Independent | Independent | Independent |
| Middleware | Not shared | Does not inherit Core | Does not inherit Core | Does not inherit Core | Does not inherit Core |
| Event | Core lifecycle | Observes Core Events | commentCommitted | — | Worktree lifecycle/commit |
| Database Adapter | Core Adapter | History Adapter | Comment Adapter | File Adapter and Blob Store | Worktree Adapter |
Office Exchange reuses the storage of Core and File. After the import and export Middleware of Exchange run, import and export still pass through the Core and File Middleware.
These Adapters can share a database and still remain separate objects with separate contracts. Services and Adapters should also be disposed independently.
Choosing a capability
| Product requirement | Module | First example |
|---|---|---|
| User-facing version history | History Service, Endpoint, Adapter | pnpm example:history |
| Sheet or Doc comments | Comment Service, Endpoint, Adapter | pnpm example:comments |
| Images, attachments, and file storage | File Service, Endpoint, Adapter, Blob Store | pnpm example:file-service |
| Server-side Office import and export | Exchange Service, Endpoint + File | pnpm example:exchange |
| Isolated drafts, review, and merge | Worktree Service, Endpoint, Client, Adapter | pnpm example:worktree |
The examples index lists the full run commands and page URLs.
Connect the Web SDK history viewer
Mount the History Endpoint alongside the collaboration endpoints. In the Web SDK, historyServerUrl is the common prefix for /{unitId}/list, /{unitId}/creators, and /{unitId}/cs, and it defaults to /universer-api/history. When a different prefix is used, the host History plugin and the product History UI plugin must be configured with the same URL.
Restoring a version goes through the collaboration mutation path; there is no standalone history REST endpoint for restore. Collaboration loading, submission, and authorization must remain configured. Comparing two materialized snapshots through createUnitComparisonEngine() is a separate operation that only reads data. It does not require a running history service, and it neither persists nor restores versions.
How is this guide?