AI SDK

Understand how AI SDK adds a Node.js CLI and agent entry point to a Univer application.

Univer Office SDK consists of three parts. Web SDK runs editors in the browser and can process content without a UI. Server SDK adds collaboration and file exchange. AI SDK, which this section covers, is a TypeScript SDK for building Office CLIs; it provides agents and automation with a Node.js entry point for loading, understanding, changing, and checking Univer Units1.

AI SDK is not a finished CLI product. It provides the individual capabilities, and the application decides how they fit together: the command names, the arguments each command takes, the target each command operates on, how identity and authorization work, the output format, and where the application runs.

The examples in this section assume a CLI + Web + Server setup:

100%
  • An agent or a person uses the CLI to tell Univer what to do.
  • Web displays the page itself, so people can edit it directly and review the result that the agent produced.
  • Server stores the Units, revisions, and collaboration state that the CLI and Web share.

The three parts can be deployed separately or run on a single machine. Making Web and Server work with the Collaboration SDK first and then adding the CLI is the suggested learning path, but it is not a deployment requirement.

A CLI-only application is also supported

AI SDK can work on local Units without a server. The result can be inspected through structured output, by having the agent look at a screenshot, or by exporting an Office file. Live Web pages, shared revisions, History, and Worktree require the Web and collaboration capabilities.

Organize the CLI with Commander

The base packages provide plain TypeScript APIs. Preset packages wrap the common capabilities as ordinary Commander Command objects, so they can be added to a program that the application owns:

TypeScript
import { Command } from "commander";const program = new Command("my-cli");program.addCommand(presetCommand);program.addCommand(applicationCommand);await program.parseAsync();
  • A command preset defines its own arguments and help text and prints either text or JSON.
  • An application command combines Runtime2, the application's business targets, identity, and commit or file policy.
  • Both are ordinary Commander Command objects, so they can be mixed in the same program.

Each following page starts with the base capability and then shows how it integrates with Commander.

Build capabilities progressively

The section adds capabilities in layers. It starts with reading and writing Unit content, then adds file handling, visual checks, collaboration, and process management:

text
load and edit a Unit→ Office file import and export→ visual inspection→ isolated Worktree editing and review→ Runtime reuse and Daemon

1. Load and edit a Unit

Start with a minimal working flow: load a Unit through Collaboration Runtime, inspect its structure, run Facade code against it, and look up Facade APIs that have not been used before.

2. Connect the Office file boundary

Exchange converts between Office files and UnitData. After an import, the Unit resides on the Collaboration Server; on export, Collaboration Runtime fetches the latest UnitData before writing the file.

3. Add visual inspection

Structured output cannot fully describe a rendered page. Screenshot provides the agent with a rendered image, and Layout Lint reports layout problems in a form that the agent can act on.

4. Isolate changes with Worktree

An agent can complete several edit-and-check rounds in a Worktree draft without modifying the live document. When the work is complete, a person reviews the draft in Web and either merges it or sends it back.

5. Reuse expensive runtimes

Start with one runtime per command and close it afterwards. Add a pool, workers, or a daemon only when startup cost, concurrency, or sharing across CLI processes becomes a real problem.

  1. Document loading and content operations
  2. Office file import and export
  3. Visual inspection
  4. Worktree: agent editing and human review
  5. Runtime reuse and Daemon
  6. Package catalog
  7. Examples

Footnotes

  1. A Unit is one document instance, such as a workbook or a text document. A worksheet is part of a workbook, not a separate Unit. ↩

  2. Here, Runtime means the live Univer instance and the resources used to operate on a loaded Unit, not the Node.js executable or the saved document snapshot. ↩

How is this guide?

© 2026 DreamNum Co., Ltd.