AI replies
When a user chats one-to-one with an AI bot, the bot's reply is a message of type ai whose content is pushed while it is being generated. The client in UI windows provides the same client.ai as the Web SDK: the engine receives the live content, joins it in order and resumes after disconnects, then passes it on to each UI window; once the reply ends the message body is authoritative. The APIs, fields and events are described fully in the Web SDK's AI replies. Bots and replies are created by your server, see AI conversations.
Version
AI replies come from @deeprespond/im-web 1.0.6. @deeprespond/im-tauri 1.1.1 depends on @deeprespond/im-web in the ~1.1.1 range; upgrade both the npm package and the Rust plugin to 1.1.1 to use it.
Display in a UI window
import { aiView } from '@deeprespond/im-web/render';
function renderAI(message: MessageView) {
const body = client.ai.bodyOf(message);
if (!body) return;
// 生成中取实时内容,结束后取消息正文
const live = body.status === 'streaming' ? client.ai.state(body.stream_id) : null;
const view = aiView(message, live);
draw(view); // 思考过程、工具调用、正文块(rich-text 节点)、附件、错误说明
}
client.on('ai.streamUpdated', (state) => redrawByStream(state.stream_id));
client.on('ai.streamEnded', ({ stream_id }) => redrawByStream(stream_id));
// 停止生成:只有接收回复的用户可以停止;已结束的返回当前状态,不报错
await client.ai.stop(body.stream_id);The fields of aiView are listed in the mini program SDK's AI replies. Since the WebView can render HTML, you can also render the text in parts with your own Markdown component.
- Every UI window can subscribe to
ai.*events; after reconnecting, the SDK fills in content still being generated. - While generating, redraw only this message; do not rebuild the whole message list on every update. Pushes are merged into one every 50 ms or 2 KB.
- Regenerate: send the answered question again and the bot's server starts a new reply.
Example app
The chat page of the example app already displays AI replies (src/features/ai.ts): reasoning, tool-call progress, the Markdown body (tables, code blocks), files, stop generating, copying, and notices for stopped and interrupted replies; the conversation preview shows "Replying…" while generating.
