优化: aichat效率批(save无变化捷径/断路器尾窗/system缓存指纹/会话列表刷新收敛) + 新增 LLM prompt caching(cache_control开关默认关/system稳定段易变段分离治缓存命中率) + 销账
This commit is contained in:
@@ -18,7 +18,7 @@ import { state } from '@/stores/ai'
|
||||
import { nextMsgId, setConvState, convStates, switchingConvs, getConvStreamState, setConvCurrentText, setConvStreaming, clearConvStreamState, clearAllApprovalTimers, clearAllToolSlowTimers, flushCurrentText, friendlyError, notifyConversationChanged } from './aiShared'
|
||||
import { resetStreamWatchdog, clearAllStreamWatchdogs } from './useAiStream'
|
||||
import { setStreaming } from './streamingGuard'
|
||||
import { loadConversations } from './useAiConversations'
|
||||
import { scheduleConversationsRefresh } from './useAiConversations'
|
||||
import { handleStreamingEvent } from './useAiStreamingEvents'
|
||||
import { handleToolEvent } from './useAiToolEvents'
|
||||
import { handleLifecycleEvent } from './useAiLifecycleEvents'
|
||||
@@ -61,7 +61,8 @@ function handleUserMessageEvent(event: AiChatEvent): boolean {
|
||||
// 多会话并行隔离:AiUserMessage 必带 conversation_id;非当前会话不污染当前视图,仅刷新列表
|
||||
const uc = event.conversation_id ?? null
|
||||
if (uc && state.activeConversationId && uc !== state.activeConversationId) {
|
||||
void loadConversations()
|
||||
// FE1:非当前会话的用户消息只刷新列表(走防抖调度,与收尾 notify 合并为一次)。
|
||||
scheduleConversationsRefresh()
|
||||
return true
|
||||
}
|
||||
const last = state.messages[state.messages.length - 1]
|
||||
@@ -96,7 +97,8 @@ export function handleEvent(event: AiChatEvent) {
|
||||
if (event.type === 'AiCompleted' || event.type === 'AiError' || event.type === 'AiHelpRequired') {
|
||||
// 非当前会话终止:收敛会话状态(删 Map 项回不在生成)
|
||||
convStates.delete(convId || '')
|
||||
void loadConversations()
|
||||
// FE1:后台会话终止只刷新列表(防抖调度,避免与 AiCompleted 收尾的 notify 双拉)。
|
||||
scheduleConversationsRefresh()
|
||||
// 后台会话终止也触发队列续发/清队(完成续发;错误清该会话队列)
|
||||
if (event.type === 'AiCompleted') {
|
||||
emit('ai-drain-queue', { conversationId: event.conversation_id })
|
||||
@@ -142,7 +144,8 @@ export async function startListener() {
|
||||
try {
|
||||
_unlistenAiEvent = await aiApi.onEvent(handleEvent)
|
||||
_unlistenConvChanged = await listen('ai-conversation-changed', (e) => {
|
||||
void loadConversations()
|
||||
// FE1:notify 自触发的刷新走防抖调度,同窗口内多次 notify 合并为一次列表拉取。
|
||||
scheduleConversationsRefresh()
|
||||
// 主窗口删除了本窗口当前展示的会话:清空视图防陈旧幽灵(分离窗口独立 JS context,经事件同步)。
|
||||
const deleted = (e.payload as { deletedConvId?: string } | undefined)?.deletedConvId
|
||||
if (deleted && state.activeConversationId === deleted) {
|
||||
|
||||
Reference in New Issue
Block a user