在你的 Tiptap 文本编辑器中构建 AI 副驾驶

When most SaaS teams talk about adding AI to their product, they think of a sidebar assistant that drafts text or a modal that pastes content into the editor. But a true AI copilot doesn’t live outside the editor—it lives within it. It understands the document, its structure, the user’s intent and can edit, reorganize, and reason over complex content.
当大多数 SaaS 团队谈论向产品添加 AI 时,他们想到的是侧边栏助手起草文本或模态框将内容粘贴到编辑器中。但是真正的 AI copilot 并不生活在编辑器外部——它生活在内部。它理解文档、其结构、用户的意图,并能编辑、重组和对复杂内容进行推理。
That’s what we built when working with our client, Distribute, a go-to-market platform with a collaborative document editor. Here’s what we learned while turning a traditional editor into an AI-native workspace.
这就是我们在与客户 Distribute 合作时构建的,这是一个具有协作文档编辑器的 go-to-market 平台。我们在将传统编辑器转变为 AI 原生工作空间过程中学到了什么。
Distribute’s text editor uses a structured, schema-based document system that supports custom layouts, tabbed sections, and user mentions. To make AI truly useful in that context, we needed more than a content generator. The copilot had to:
Distribute 的文本编辑器使用结构化、基于 schema 的文档系统,支持自定义布局、选项卡部分和用户提及。要使 AI 在该上下文中真正有用,我们需要的不只是内容生成器。copilot 必须:
- Understand the entire document structure (not just current selection)
- 理解整个文档结构(不仅仅是当前选区)
- Modify any part of it, from rewriting a paragraph to merging two tabs
- 修改它的任何部分,从重写一个段落到合并两个标签页
- Preserve strict schema validity and contextual placeholders
- 保持严格的 schema 有效性 和上下文占位符
- Respect the collaboration model — users must see, review, and accept changes safely
- 尊重协作模型 — 用户必须安全地查看、审查并接受更改
The result: a copilot that feels native to the editor, not bolted on top.
结果:一个感觉像是编辑器原生的 copilot,而不是附加在上面的。
Distribute’s editor runs on Tiptap, built over ProseMirror, meaning every node and mark is validated against a schema. That’s great for consistency but hard for AI, since large language models are much more comfortable producing text than tree structures.
Distribute 的编辑器运行在 Tiptap 上,建立在 ProseMirror 之上,这意味着每个节点和标记都会针对 schema 进行验证。这对一致性很好,但对 AI 来说很难,因为大型语言模型更擅长生成文本而不是树结构。
Our first idea was to ask the LLM to generate a stream of edit o...