快速接入
本章目标是让开发者从“完全不了解”到“可以在 demo 跑起来并看到 AI 回复”,并知道后端需要实现什么。
必须提供的能力(否则必然报错 / 不可用):
- 至少一个 AI 模型配置:
ai.models.length > 0,Umo Editor Next 会读取ai.models[0]作为默认模型; - 一个可访问的后端 endpoint(推荐 SSE):
ai.models[].endpoint,前端会向该 endpoint 发起请求,你可以先行连接到 Umo Editor Server 提供的默认 SSE 示例服务/mock/sse/normal或/mock/sse/agui进行测试,见:接口列表。
默认配置
最小可用配置:
const options = {
ai: {
models: [
{
value: 'default',
label: { zh_CN: '默认模型', en_US: 'Default Model' },
avatar: '/images/ai.svg',
protocol: 'default', // 或 'agui'
endpoint: 'http://127.0.0.1:1235/mock/sse/normal', // Umo Editor Server 的 SSE 示例接口
stream: true,
reasoning: true,
},
],
chat: { enabled: true }, // 侧边栏聊天
assistant: { enabled: true }, // 文档气泡助手
},
}协议选择
协议解释详见 支持的协议。此处给出选择建议:
- 后端只做“把大模型输出以 SSE 发回来”,并且愿意自定义数据结构:用
protocol: 'default'。 - 已有 / 准备实现 AG-UI 协议(包含工具调用、状态等事件):用
protocol: 'agui'。
当 protocol: 'agui' 时,前端不会走 ai.callbacks.onMessage 的自定义解析,而是交给内置的 AG-UI 解析与渲染。后端必须输出 AG-UI 事件流(详见 支持的协议)。
验证
可以直接:
- 打开“文档助手”入口(气泡菜单)或右下角聊天入口
- 输入任意内容发送
- 观察是否能出现 assistant 回复消息
若无输出,优先阅读 故障排除。