优化: aichat 体验收尾(useAiEvents拆分4子域 + AIC-FIX P1队列/mutex/缓存 + i18n残留抽取)
This commit is contained in:
@@ -7,10 +7,9 @@
|
||||
import { aiApi } from '@/api'
|
||||
import { useAppSettingsStore } from '@/stores/appSettings'
|
||||
import { state } from '@/stores/ai'
|
||||
import { notifyConversationChanged } from './useAiEvents'
|
||||
import { persistUiState } from './useAiPanel'
|
||||
import { setStreaming } from './streamingGuard'
|
||||
import { nextMsgId, getConvState, clearConvStreamState, startApprovalTimer, clearAllApprovalTimers, switchingConvs, getConvStreamState, setConvCurrentText } from './aiShared'
|
||||
import { nextMsgId, getConvState, clearConvStreamState, clearLastDelta, startApprovalTimer, clearAllApprovalTimers, switchingConvs, getConvStreamState, setConvCurrentText, notifyConversationChanged } from './aiShared'
|
||||
import { t } from '@/i18n/i18n-helpers'
|
||||
import type { AiConversationDetail, AiMessage, AiToolCallInfo, ConvId } from '@/api/types'
|
||||
|
||||
@@ -425,14 +424,16 @@ export async function switchConversation(id: string, force = false) {
|
||||
/** 删除会话;若删的是当前活跃会话则清空消息+移除活跃 id 持久化。
|
||||
* G3.4:收敛进 withConvOp(乐观移除列表 + 失败回滚 + 错误气泡),原裸 await 失败抛 unhandled rejection。 */
|
||||
async function deleteConversation(id: string) {
|
||||
// AIC-FIX-17-P0-2:删除会话时清空所有审批计时器(防已删会话的过期 timer 到期误拒审批 +
|
||||
// 错误气泡推错视图)。
|
||||
// 删除会话时清空所有审批计时器(防已删会话的过期 timer 到期误拒审批 + 错误气泡推错视图)
|
||||
clearAllApprovalTimers()
|
||||
const conv = state.conversations.find(c => c.id === id)
|
||||
const prevIndex = conv ? state.conversations.indexOf(conv) : -1
|
||||
const wasActive = state.activeConversationId === id
|
||||
const prevActive = state.activeConversationId
|
||||
const prevMessages = state.messages
|
||||
// 删活跃会话前捕获相邻会话(删除后回落,避免空白无引导)
|
||||
const neighbor = wasActive ? (state.conversations[prevIndex + 1] ?? state.conversations[prevIndex - 1]) : null
|
||||
const neighborId = neighbor?.id ?? null
|
||||
const ok = await withConvOp(
|
||||
() => {
|
||||
// 乐观:从列表移除 + 若删的是活跃会话则清空视图
|
||||
@@ -459,18 +460,20 @@ async function deleteConversation(id: string) {
|
||||
)
|
||||
// 注意:op 返回 void,成功=undefined、失败=null(不能 `!ok`——undefined 也 falsy 会误判失败)
|
||||
if (ok === null) return // 失败已回滚 + 推气泡,保持原视图
|
||||
// F-09 per-conv:清该会话的 stream state(streaming/currentText),防 convStreamStates Map 无限增长
|
||||
// (与 convStates/待审批等 per-conv 资源同款会话级清理语义)。
|
||||
// 清该会话的 stream state 与 delta 去重记录,防 per-conv Map 无限增长
|
||||
clearConvStreamState(id)
|
||||
clearLastDelta(id)
|
||||
if (wasActive) {
|
||||
void appSettings.remove('df-ai-active-conv')
|
||||
// G3.5:删除活跃会话 → load_more 游标复位(无 active 视图)
|
||||
// 删除活跃会话 → load_more 游标复位(无 active 视图)
|
||||
loadMoreCursor.hasMore = false
|
||||
loadMoreCursor.earliestSeq = null
|
||||
loadMoreCursor.convId = null
|
||||
loadMoreCursor.loading = false
|
||||
}
|
||||
await loadConversations()
|
||||
// 删的是活跃会话:回落相邻会话作为新活跃视图
|
||||
if (neighborId) await switchConversation(neighborId)
|
||||
notifyConversationChanged()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user