重构: 巨函数拆分 + 清理历史标记注释 + custom_prompt/停止按钮/tunnel 改进
This commit is contained in:
@@ -45,6 +45,24 @@ let _startPromise: Promise<void> | null = null
|
||||
// 上一次 AiTextDelta 的内容(单窗口内 LLM 重复 delta 防御用,见 handleStreamingEvent)
|
||||
let _lastDelta = ''
|
||||
|
||||
// 文本空闲信号(reactive ref):streaming=true 且 300ms 无新 delta 时=true。
|
||||
// 按钮据此显「发送」(idle)而非「停止」。不动 streaming(streaming 是渲染态,
|
||||
// 控制 MessageList 流式 block 显隐,不能在文本中途翻转,否则闪掉)。
|
||||
export const textIdle = ref(true)
|
||||
let _textIdleTimer: ReturnType<typeof setTimeout> | null = null
|
||||
function resetTextIdleTimer(): void {
|
||||
if (_textIdleTimer) clearTimeout(_textIdleTimer)
|
||||
textIdle.value = false // 有新 delta → 文本活跃
|
||||
_textIdleTimer = setTimeout(() => {
|
||||
textIdle.value = true // 300ms 无新 delta → 文本空闲
|
||||
_textIdleTimer = null
|
||||
}, 300)
|
||||
}
|
||||
function clearTextIdleTimer(): void {
|
||||
if (_textIdleTimer) { clearTimeout(_textIdleTimer); _textIdleTimer = null }
|
||||
textIdle.value = true // 整轮结束/新轮开始 → 默认空闲
|
||||
}
|
||||
|
||||
const appSettings = useAppSettingsStore()
|
||||
|
||||
// B-260616-17: 看门狗不重置的事件集合(审批等待/完成/错误由各自 case 内 clear)。
|
||||
@@ -298,6 +316,8 @@ function handleStreamingEvent(event: AiChatEvent): boolean {
|
||||
}
|
||||
_lastDelta = event.delta
|
||||
state.currentText += event.delta
|
||||
// 重置文本空闲定时器:每次 delta 重置 300ms。无新 delta 到 300ms → textIdle=true → 按钮白。
|
||||
resetTextIdleTimer()
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -305,6 +325,10 @@ function handleStreamingEvent(event: AiChatEvent): boolean {
|
||||
// Agent 循环新一轮:保存当前文本到上一条 assistant 消息,新建空 assistant 消息
|
||||
flushCurrentText()
|
||||
state.currentText = ''
|
||||
// 文本已刷新完毕 → 清空闲定时器(按钮白,等下一轮 deltas 来再红)
|
||||
// 不设 streaming=false:streaming 管渲染,多轮间需持续 true 让 MessageList 渲染后续 deltas。
|
||||
// 按钮白由 textIdle 独立控制,无需翻转 streaming。
|
||||
clearTextIdleTimer()
|
||||
state.completedTools = 0 // 新轮重置工具计数器
|
||||
state.messages.push({
|
||||
id: `ai-${nextMsgId()}` as MessageId,
|
||||
@@ -603,6 +627,7 @@ function handleUserMessageEvent(event: AiChatEvent): boolean {
|
||||
function cleanupTerminatedConversation(convId: string, reason: 'AiCompleted' | 'AiError' | 'AiHelpRequired') {
|
||||
clearStreamWatchdog(convId || undefined)
|
||||
clearAllToolSlowTimers() // B-260616-12: 整轮/错误/求助结束清全部工具慢执行计时器与已提示集合
|
||||
clearTextIdleTimer() // 清文本空闲定时器 + 置 textIdle=true(整轮结束不该有活跃信号残留)
|
||||
flushCurrentText()
|
||||
state.currentText = ''
|
||||
setStreaming(false, { convId: convId || null, reason })
|
||||
|
||||
Reference in New Issue
Block a user