Appearance
消息类型速查
客户端 → 服务端
| 类型值 | 说明 | 何时发送 |
|---|---|---|
append_message | 追加用户消息/工具响应 | 用户发送消息、回复工具提问 |
request_completion | 请求 AI 生成回复 | 发送消息后触发补全 |
stop_completion | 中断 AI 回复 | 用户点击"停止" |
tool_confirmation_response | 确认/拒绝工具调用 | 用户回应工具确认弹窗 |
服务端 → 客户端
文本与补全
| 类型值 | 字段 | 说明 |
|---|---|---|
llm_text_chunk | chunk: string | 单个 token 级别的文本片段 |
llm_text_sentence | sentence: string, index: int | 完整句子(按标点符号切分) |
llm_thinking_chunk | chunk: string | 推理过程的 token 片段(仅 reasoning 模式) |
llm_thinking_sentence | sentence: string, index: int | 推理过程的完整句子 |
text_echo | text: string | 完整文本回显 |
工具调用
| 类型值 | 字段 | 说明 |
|---|---|---|
tool_call_chunk | index, id, function, confirmation_state | 工具调用流式片段 |
tool_call | id, result, show_result | 工具执行结果 |
tool_confirmation_processed | tool_call_id, action | 确认响应已处理 |
system_notification | message: string | 系统通知(工具执行产生的提示) |
补全流程控制
| 类型值 | 字段 | 说明 |
|---|---|---|
completion_init | conversation_id, user_character_config_id | 补全开始 |
assistant_message_complete | content, tool_calls, thinking, finish_reason | 完整的 AI 回复 |
completion_done | finish_reason | 单轮补全结束 |
stop_completion | partial_text | 补全被用户中断 |
对话管理
| 类型值 | 字段 | 说明 |
|---|---|---|
message_appended | — | append_message 确认 |
conversation_title_update | conversation_id, title | 标题自动生成/更新 |
音频
| 类型值 | 说明 |
|---|---|
audio_playback_start | 音频播放开始 |
audio_playback_end | 音频播放结束 |
错误与生命周期
| 类型值 | 字段 | 说明 |
|---|---|---|
error | message, code | 错误消息 |
user_disconnect | — | 用户断开连接 |
详细结构
tool_call_chunk
工具调用以流式方式推送,参数逐步累积:
json
// 第一个 chunk:包含 id 和函数名
{
"type": "tool_call_chunk",
"index": 0,
"id": "call_abc123",
"function": {
"name": "WebSearchFunction",
"arguments": ""
},
"show_name": true,
"show_arguments": true,
"show_result": true,
"confirmation_state": "none"
}
// 后续 chunk:只包含参数增量
{
"type": "tool_call_chunk",
"index": 0,
"id": null,
"function": {
"name": null,
"arguments": "{\"query\": \"搜索"
},
"show_name": true,
"show_arguments": true,
"show_result": true,
"confirmation_state": "none"
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
累积规则:客户端需要将所有 chunk 的 function.arguments 字符串拼接起来,得到完整的 JSON 参数。
可见性字段:
| 字段 | 说明 |
|---|---|
show_name | 是否在 UI 中显示工具名称 |
show_arguments | 是否显示工具参数 |
show_result | 后续 tool_call 消息是否显示结果 |
确认状态:
| 值 | 说明 |
|---|---|
none | 无需确认,直接执行 |
pending | 需要用户确认后才执行 |
awaiting_input | 已执行,等待用户输入 |
assistant_message_complete
每轮补全结束时推送完整的 AI 回复:
json
{
"type": "assistant_message_complete",
"content": "根据搜索结果,我找到了以下信息...",
"thinking": "用户想要了解...(仅 reasoning 模式)",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "WebSearchFunction",
"arguments": "{\"query\": \"搜索关键词\"}"
},
"show_name": true,
"show_arguments": true,
"show_result": true,
"confirmation_state": "none"
}
],
"finish_reason": "stop",
"source_message_id": null
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
finish_reason 值
| 值 | 说明 |
|---|---|
stop | 正常完成 |
length | 达到最大 Token 限制 |
tool_calls | 有工具调用(可能需要确认或后续处理) |
content_filter | 内容被安全过滤 |
error | 发生错误 |
error
json
{
"type": "error",
"message": "用户友好的错误描述",
"code": "error_code_string",
"request_id": "关联的请求ID"
}1
2
3
4
5
6
2
3
4
5
6
错误码列表详见 错误码与状态码。