修复: AI工具OOM/路径遍历+续跑锁收敛+UX交互批
This commit is contained in:
@@ -9,10 +9,15 @@ import { useAppSettingsStore } from '@/stores/appSettings'
|
||||
import { state } from '@/stores/ai'
|
||||
import { notifyConversationChanged } from './useAiEvents'
|
||||
import { persistUiState } from './useAiPanel'
|
||||
import type { AiToolCallInfo } from '@/api/types'
|
||||
import { nextMsgId } from './aiShared'
|
||||
import i18n from '@/i18n'
|
||||
import type { AiMessage, AiToolCallInfo } from '@/api/types'
|
||||
|
||||
const appSettings = useAppSettingsStore()
|
||||
|
||||
// composable 无组件上下文,借全局 i18n 实例翻译错误文案(同 useAiSend/aiShared 模式)
|
||||
const t = ((i18n as any).global.t as (k: string, named?: Record<string, unknown>) => string).bind((i18n as any).global)
|
||||
|
||||
/** 拉取会话列表;首次加载时若 appSettings 仍有有效 active-conv 且当前无活跃对话则恢复 */
|
||||
async function loadConversations() {
|
||||
try {
|
||||
@@ -22,8 +27,21 @@ async function loadConversations() {
|
||||
if (pending && !state.activeConversationId && state.conversations.some(c => c.id === pending)) {
|
||||
await switchConversation(pending)
|
||||
}
|
||||
} catch {
|
||||
// 静默失败,不影响主流程
|
||||
} catch (e) {
|
||||
// UX-260617-08:网络抖动/IPC 断开时原静默失败,列表可能突空用户不知原因。
|
||||
// 此处保留旧列表(赋值语句抛出,旧 state.conversations 不被覆盖)+ 推错误气泡反馈。
|
||||
// 仅首次加载(state.conversations 为空)时推气泡,避免拉取/侧栏刷新重试时反复弹错。
|
||||
console.error('[AI] 加载会话列表失败:', e)
|
||||
if (state.conversations.length === 0) {
|
||||
state.messages.push({
|
||||
id: `load-conv-fail-${nextMsgId()}`,
|
||||
role: 'assistant',
|
||||
content: t('ai.loadConvFail'),
|
||||
isError: true,
|
||||
timestamp: Date.now(),
|
||||
} as AiMessage)
|
||||
notifyConversationChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +132,17 @@ export async function switchConversation(id: string) {
|
||||
}
|
||||
}),
|
||||
}))
|
||||
} catch {
|
||||
state.messages = []
|
||||
} catch (e) {
|
||||
// UX-260617-08:历史消息解析/映射失败原仅 state.messages=[] → 切换后空白用户不知原因。
|
||||
// 改为推错误气泡提示 + 控制台日志(保留 state.messages 不再清空,避免空白无反馈)。
|
||||
console.error('[AI] 切换对话历史消息解析失败:', e)
|
||||
state.messages.push({
|
||||
id: `switch-conv-fail-${nextMsgId()}`,
|
||||
role: 'assistant',
|
||||
content: t('ai.switchConvFail'),
|
||||
isError: true,
|
||||
timestamp: Date.now(),
|
||||
} as AiMessage)
|
||||
}
|
||||
|
||||
// 加载历史对话 token 总量(来自 DB summary);切换对话清空实时值
|
||||
|
||||
Reference in New Issue
Block a user