优化: aichat 打磨收尾(切换信任保留 + save并发串行 + 后台授权守卫 + 分离窗口失效 + 气泡截图复制)

This commit is contained in:
lxy
2026-08-08 21:08:25 +08:00
parent 65c0f6b2b6
commit 6ba6daf188
14 changed files with 196 additions and 27 deletions
+15 -6
View File
@@ -204,12 +204,21 @@ export async function restoreGeneratingState(opts?: { fromMainPanel?: boolean; c
if (!fromMainPanel) {
state.currentText = (opts?.convId && localStorage.getItem(textKey(opts.convId))) || localStorage.getItem('df-ai-text') || ''
}
state.messages.push({
id: `ai-${nextMsgId()}` as MessageId,
role: 'assistant',
content: '',
timestamp: Date.now(),
})
// 双占位去重:末条已是空 assistant 占位(本会话流式占位)则复用,不重复 push。
const lastMsg = state.messages[state.messages.length - 1]
const lastIsStreamingPlaceholder = !!lastMsg
&& lastMsg.role === 'assistant'
&& !lastMsg.content?.trim()
&& !lastMsg.isError
&& !(lastMsg.toolCalls && lastMsg.toolCalls.length)
if (!lastIsStreamingPlaceholder) {
state.messages.push({
id: `ai-${nextMsgId()}` as MessageId,
role: 'assistant',
content: '',
timestamp: Date.now(),
})
}
setStreaming(true, { convId: gen, reason: 'restoreGeneratingState' })
// 批4 双轨收口:恢复生成中态写 convStates(enum 真相源),替代旧 generatingConvs.add。
// setStreaming 联动已退役(批4),streaming 单值与 convStates 项并行写无冲突。