Skip to content

Commit f451118

Browse files
Jinyu XuJinyu Xu
authored andcommitted
fix: align mobile AI streaming fallback
1 parent 616e3c6 commit f451118

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ export const klineApi = {
724724
}
725725

726726
export const aiChatApi = {
727-
sendMessage: (payload) => http.post('/api/ai/chat/message', payload, { timeout: 180000 }),
727+
sendMessage: (payload) => http.post('/api/ai/chat/message', payload, { timeout: 600000 }),
728728
streamMessage: async (payload, onEvent) => {
729729
const language = payload?.language || 'zh-CN'
730730
const headers = {

src/views/ai-hub/index.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ export default {
827827
selected_task: task?.key || null
828828
}
829829
}
830-
await this.sendMessageStream(payload, pendingMsg)
830+
await this.sendMessageReliable(payload, pendingMsg)
831831
}
832832
} catch (err) {
833833
if (pendingMsg.reportLoading) {
@@ -925,6 +925,35 @@ export default {
925925
throw new Error(this.text.generateFailed)
926926
}
927927
},
928+
async sendMessageReliable(payload, pendingMsg) {
929+
try {
930+
await this.sendMessageStream(payload, pendingMsg)
931+
return
932+
} catch (_) {
933+
this.updatePendingMessage(pendingMsg, {
934+
content: this.text.sending,
935+
loading: true,
936+
actions: []
937+
})
938+
}
939+
940+
const response = await aiChatApi.sendMessage({
941+
...payload,
942+
session_id: this.sessionId || payload.session_id
943+
})
944+
const data = response?.data || {}
945+
const reply = String(data.reply || data.answer || '').trim()
946+
if (!reply) throw new Error(this.text.generateFailed)
947+
948+
this.sessionId = data.session_id || this.sessionId
949+
this.updatePendingMessage(pendingMsg, {
950+
id: data.message_id || pendingMsg.id,
951+
content: '',
952+
loading: false,
953+
actions: this.filterMobileActions(data.actions || [])
954+
})
955+
await this.revealStreamText(pendingMsg, reply)
956+
},
928957
isUnsupportedMobileAction(action) {
929958
const payload = action?.payload || {}
930959
const signature = [

tests/unit/mobile-usage-boundary.test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,16 @@ test('market, chart, and accounts provide a complete mobile path', () => {
195195

196196
test('AI composer stays at the bottom and uses a text send action', () => {
197197
const aiHub = read('src/views/ai-hub/index.vue')
198+
const api = read('src/api/index.js')
198199

199200
assert.match(aiHub, /\{\{ text\.send \}\}/)
200201
assert.match(aiHub, /\.bottom-suggestions\s*\{\s*margin-top: auto;/)
201202
assert.doesNotMatch(aiHub, /copilot-body\.empty \.bottom-suggestions/)
202203
assert.match(aiHub, /\.send-action[\s\S]*min-width: 72px/)
204+
assert.match(aiHub, /sendMessageReliable\(payload, pendingMsg\)/)
205+
assert.match(aiHub, /await this\.sendMessageStream\(payload, pendingMsg\)[\s\S]*aiChatApi\.sendMessage\(\{/)
206+
assert.match(api, /sendMessage: \(payload\) => http\.post\('\/api\/ai\/chat\/message', payload, \{ timeout: 600000 \}\)/)
207+
assert.match(api, /streamMessage:[\s\S]*\/api\/ai\/chat\/message\/stream/)
203208
})
204209

205210
test('signal chart supports mobile history navigation and candle inspection', () => {

0 commit comments

Comments
 (0)