新增: Phase2 阶段收尾(Sprint 1-20)

重构:删 5 零引用 crate(df-evolve/plugin/stages/task/traceability)+ 清死模块、ai.rs 拆 11 子 module、ai.ts 拆 6 composable、i18n 拆目录
功能:知识库全栈(df-project/scan + CRUD + 时间线 + 前端)、Settings 拆分、appSettings KV 迁移、模型池、LLM 并发 Semaphore
修复:审批持久化根治、ConditionEngine 默认拒绝、NodeRegistry unimplemented 清除、promote 补偿删除、工具结果截断 50KB、路径校验防 symlink 逃逸
文档:B-03 人工审批设计、决策记录三分档、规格契约自检、经验记录、todo 看板、PROGRESS 更新

详见 PROGRESS.md。src-tauri/儿童每日打卡应用/ 与本项目无关,已排除。
This commit is contained in:
2026-06-14 14:08:20 +08:00
parent 98393b4908
commit cf017f81e2
167 changed files with 19549 additions and 6886 deletions

View File

@@ -0,0 +1,52 @@
//! 流式看门狗 — 无数据超时兜底
//!
//! 后端断连/异常不发 AiCompleted/AiError 时,前端自动收尾+提示,
//! 避免 streaming 永久 true 卡死对话(用户报"流式文字停在中途"即此类)。
//!
//! 耦合说明:
//! - sendMessage 启动生成时 resetStreamWatchdog() 启动计时
//! - handleEvent 每个活跃事件(delta/工具/新轮/审批结果)重置;审批等待/完成/错误 clear
//! - 超时回调 onStreamTimeout 直接改 state 并补一条错误消息
import { state } from '../../stores/ai'
import { nextMsgId } from './useAiEvents'
/// ≥ 后端 STREAM_IDLE_TIMEOUT(120s, ai.rs:848)+余量;
/// 前端若短于后端,慢首 token 会被前端先误杀
export const STREAM_TIMEOUT_MS = 130000
let _streamWatchdog: ReturnType<typeof setTimeout> | null = null
/** 看门狗超时回调:收尾 streaming 态并补错误消息 */
export function onStreamTimeout() {
state.streaming = false
state.generatingConvId = null
state.currentText = ''
clearStreamWatchdog()
state.messages.push({
id: `timeout-${nextMsgId()}`,
role: 'assistant',
content: '⚠ 响应中断(长时间无数据流)。可能是网络断连或后端异常,请重试。',
isError: true,
timestamp: Date.now(),
})
}
/** 启动/重置看门狗(活跃事件或 sendMessage 时调用) */
export function resetStreamWatchdog() {
if (_streamWatchdog) clearTimeout(_streamWatchdog)
_streamWatchdog = setTimeout(onStreamTimeout, STREAM_TIMEOUT_MS)
}
/** 清除看门狗(完成/错误/审批等待时调用) */
export function clearStreamWatchdog() {
if (_streamWatchdog) { clearTimeout(_streamWatchdog); _streamWatchdog = null }
}
export function useAiStream() {
return {
onStreamTimeout,
resetStreamWatchdog,
clearStreamWatchdog,
}
}