fix: 修复部分逻辑漏洞

This commit is contained in:
digua
2026-04-28 22:45:49 +08:00
committed by digua
parent dd1fdfe923
commit 78689b2650
2 changed files with 7 additions and 3 deletions
+2 -2
View File
@@ -499,9 +499,9 @@ export function buildPiModel(config: AIServiceConfig): PiModel<PiApi> {
}
}
// openai-compatible + openai-completions:自动补全 /v1(用户经常忘记)
// openai-compatible + openai-completions/openai-responses:自动补全 /v1(用户经常忘记)
const resolvedBaseUrl =
config.provider === 'openai-compatible' && apiFormat === 'openai-completions'
config.provider === 'openai-compatible' && (apiFormat === 'openai-completions' || apiFormat === 'openai-responses')
? normalizeOpenAICompatibleBaseUrl(baseUrl)
: baseUrl
+5 -1
View File
@@ -564,6 +564,8 @@ export const useAIChatStore = defineStore('aiChatRuntime', () => {
const initialBufferKey = getDisplayedBufferKey(state)
let resolvedConversationId = initialBufferKey === DRAFT_CONVERSATION_KEY ? null : initialBufferKey
const targetBuffer = getOrCreateBuffer(state, initialBufferKey, state.selectedAssistantId)
// 在 try 外部声明,以便 catch 块能正确引用当前轮次的用户消息
let currentUserMessage: ChatMessage | undefined
targetBuffer.assistantId = state.selectedAssistantId
targetBuffer.loaded = true
@@ -622,6 +624,7 @@ export const useAIChatStore = defineStore('aiChatRuntime', () => {
timestamp: Date.now(),
toolCalls: [],
}
currentUserMessage = userMessage
targetBuffer.messages.push(userMessage)
const aiMessage: ChatMessage = {
@@ -945,7 +948,8 @@ export const useAIChatStore = defineStore('aiChatRuntime', () => {
lastMessage.contentBlocks = [...blocks]
lastMessage.isStreaming = false
const userMsg = targetBuffer.messages.find((m) => m.role === 'user')
// 优先使用当前轮次的用户消息,避免多轮对话取到第一条历史消息
const userMsg = currentUserMessage || targetBuffer.messages.findLast((m) => m.role === 'user')
if (userMsg) {
await saveConversation(resolvedConversationId, userMsg, lastMessage)
}