优化: aichat 体验收尾(useAiEvents拆分4子域 + AIC-FIX P1队列/mutex/缓存 + i18n残留抽取)

This commit is contained in:
lxy
2026-08-08 20:38:33 +08:00
parent 4092a8d5bb
commit 65c0f6b2b6
21 changed files with 882 additions and 913 deletions
+9 -3
View File
@@ -20,7 +20,7 @@
//! - state 为模块级单例,全应用共享同一引用
import { computed, reactive, watch } from 'vue'
import type { AiChatEvent, AiConversationSummary, AiMessage, AiProviderConfig, AiToolCallInfo, ContentPart, SkillInfo } from '@/api/types'
import type { AiChatEvent, AiConversationSummary, AiMessage, AiProviderConfig, AiToolCallInfo, ContentPart, MentionSpan, SkillInfo } from '@/api/types'
/**
* 单对话 messages 软上限(滚动淘汰)。
@@ -52,7 +52,7 @@ import { useAiEvents } from '@/composables/ai/useAiEvents'
import { useAiStream } from '@/composables/ai/useAiStream'
// 批4 双轨收口:getConvState 从 aiShared 取(下沉破环,避免 stores/ai↔useAiEvents 反向环)。
// F-09 per-conv streaming/currentText(DEC-07a 父④):convStreamStates Map + 辅助函数亦从 aiShared 取。
import { getConvState, getConvStreamState, setConvStreaming, setConvCurrentText, __bindMessages } from '@/composables/ai/aiShared'
import { getConvState, getConvStreamState, setConvStreaming, setConvCurrentText, __bindMessages, __bindState } from '@/composables/ai/aiShared'
import { useAiSend, initDrainQueueListener } from '@/composables/ai/useAiSend'
import { useAiApproval } from '@/composables/ai/useAiApproval'
import { useAiConversations } from '@/composables/ai/useAiConversations'
@@ -101,7 +101,7 @@ const _stateBase: {
detached: boolean
docked: boolean
skills: SkillInfo[]
queue: { text: string; skill?: string; enqueuedAt: number; parts?: ContentPart[]; conversationId?: string | null }[]
queue: { text: string; skill?: string; enqueuedAt: number; parts?: ContentPart[]; spans?: MentionSpan[]; conversationId?: string | null }[]
agentRound: number
/// 已完成工具调用数(本轮累计,AiToolCallCompleted 时 +1,AiAgentRound 时重置)
completedTools: number
@@ -203,6 +203,12 @@ try {
// aiShared 模块初始化中(ES module 循环),延迟到微任务里重试
Promise.resolve().then(() => __bindMessages(() => state.messages))
}
// 注入 state getter 到 aiShared 共享层(flushCurrentText 惰性读 state,破 aiShared ↔ 本模块循环)
try {
__bindState(() => state)
} catch (e) {
Promise.resolve().then(() => __bindState(() => state))
}
// 旁注:此处不再保留 type-only 导出(AiChatEvent 等),因组件直接从 api/types import。
// 若有外部模块仍从本文件 import 这些类型,下方 re-export 兜底: