diff --git a/frontend/scripts/main.js b/frontend/scripts/main.js index baef621..19593ed 100644 --- a/frontend/scripts/main.js +++ b/frontend/scripts/main.js @@ -268,25 +268,46 @@ const eventListeners = { logger.info('任务已结束,正在自动重新激活...', data); state.isChatting = false; state.jobInfo = null; + updateUIState(); if (state.keepAliveActive) { setTimeout(async () => { try { - logger.info('正在调用 activeInteractionMode...'); - await HwICSUiSdk.activeInteractionMode(); - logger.info('自动激活成功'); - state.isChatting = true; - updateUIState(); + logger.info('正在调用 startChat 重新开始对话...'); + const chatResult = await HwICSUiSdk.startChat({ + interactionMode: InteractionMode.AUDIO, + wakeupType: WakeupType.VOICE, + preCheckPermissions: false + }); + if (chatResult.result) { + logger.info('重新开始对话成功', chatResult); + state.isChatting = true; + updateUIState(); + } else { + logger.warn('重新开始对话返回失败', chatResult); + if (chatResult.errorCode === '999400004') { + logger.info('对话已存在,尝试 activeInteractionMode'); + await HwICSUiSdk.activeInteractionMode(); + state.isChatting = true; + updateUIState(); + } + } } catch (error) { - logger.error('自动激活失败', error); + logger.error('重新激活失败', error); + try { + await HwICSUiSdk.activeInteractionMode(); + state.isChatting = true; + updateUIState(); + } catch (e) { + logger.error('activeInteractionMode 也失败', e); + } } - }, 1000); + }, 2000); } - updateUIState(); } }; let keepAliveTimer = null; -const KEEP_ALIVE_INTERVAL = 20000; +const KEEP_ALIVE_INTERVAL = 10000; function startKeepAlive() { if (keepAliveTimer) return;