feat(ai): 对话页接入实时语音、图片识别与失败重试

- 聊天 WebSocket 提到 app 级,语音分片与对话共用连接,补齐心跳、重连与连接单飞
- 语音输入走 asr_start/asr_chunk/asr_stop,中间结果实时回填,链路异常退回整段转写
- 图片选完先上屏再 OCR,识别原文以 format 消息并入对话
- 失败状态挂在原提问上可点击重试,401 静默重登后原样重发
- 消息区改为暖白纸面与头像+时间布局,常见问题与清空收进更多菜单
This commit is contained in:
lik
2026-11-18 22:34:17 +08:00
parent 8e508d6934
commit 6da802cff9
9 changed files with 1931 additions and 717 deletions
+26 -2
View File
@@ -3,10 +3,34 @@ class Request {
constructor(baseURL = 'https://api.huashengtec.com') {
//constructor(baseURL = 'http://127.0.0.1:9004') {
this.baseURL = baseURL
// 401 兜底回调由 app.js 注入(静默重登),避免各页面自己处理登录
this.onUnauthorized = null
}
async request(options) {
const { url, method = 'GET', data = {}, header = {}, skipAuthWait = false, ...rest } = options
setUnauthorizedHandler(handler) {
this.onUnauthorized = handler
}
request(options) {
return this.send(options).then((body) => this.recoverUnauthorized(body, options))
}
// token 失效时后端返回 HTTP 200 + code 401:静默重登一次再重试原请求。
// 登录请求自身(skipAuthWait)不再触发重登,避免递归
recoverUnauthorized(body, options) {
if (!body || body.code !== 401 || options._retried || options.skipAuthWait || !this.onUnauthorized) {
return body
}
const notLoggedIn = { code: 401, msg: '请先登录', data: null }
return Promise.resolve()
.then(() => this.onUnauthorized())
.then((ok) => (ok ? this.request({ ...options, _retried: true }) : notLoggedIn))
.catch(() => notLoggedIn)
}
async send(options) {
const { url, method = 'GET', data = {}, header = {}, skipAuthWait = false, _retried, ...rest } = options
// 等待登录完成后再携带 token,避免页面请求早于 app.js 登录的竞态
// skipAuthWait: 登录请求自身使用,否则会等待自己导致死锁