feat: 实现聊天取消功能,提升用户交互体验
- 在教练页面中添加用户取消发送或终止回复的能力 - 更新发送按钮状态,支持发送和取消状态切换 - 在流式回复中显示取消按钮,允许用户中断助手的生成 - 增强请求管理,添加请求序列号和有效性验证,防止延迟响应影响用户体验 - 优化错误处理,区分用户主动取消和网络错误,提升系统稳定性 - 更新相关文档,详细描述取消功能的实现和用户体验设计
This commit is contained in:
@@ -102,8 +102,13 @@ export type TextStreamOptions = {
|
||||
export function postTextStream(path: string, body: any, callbacks: TextStreamCallbacks, options: TextStreamOptions = {}) {
|
||||
const url = buildApiUrl(path);
|
||||
const token = getAuthToken();
|
||||
|
||||
// 生成请求ID用于追踪和取消
|
||||
const requestId = `req_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
|
||||
const requestHeaders: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Request-Id': requestId,
|
||||
...(options.headers || {}),
|
||||
};
|
||||
if (token) {
|
||||
@@ -227,7 +232,7 @@ export function postTextStream(path: string, body: any, callbacks: TextStreamCal
|
||||
}
|
||||
}
|
||||
|
||||
return { abort };
|
||||
return { abort, requestId };
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user