fix(messageThunk): handle missing user message in response creation (#7375)

* fix(messageThunk): handle missing user message in response creation

* fix(i18n): add missing user message translations

* fix(messageThunk): show error popup for missing user message instead of creating error block

* fix(messageThunk): validate askId and show error popup for missing user message

---------

Co-authored-by: suyao <sy20010504@gmail.com>
This commit is contained in:
Tristan Zhang 2025-07-03 17:03:45 +08:00 committed by GitHub
parent e35b4d9cd1
commit 870f794796
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 38 additions and 3 deletions

View File

@ -447,6 +447,7 @@
"504": "Gateway timeout. Please try again later"
},
"model.exists": "Model already exists",
"missing_user_message": "Cannot switch model response: The original user message has been deleted. Please send a new message to get a response with this model.",
"no_api_key": "API key is not configured",
"provider_disabled": "Model provider is not enabled",
"render": {

View File

@ -447,6 +447,7 @@
"504": "ゲートウェイタイムアウトが発生しました。後でもう一度試してください"
},
"model.exists": "モデルが既に存在します",
"missing_user_message": "モデル応答を切り替えられません:元のユーザーメッセージが削除されました。このモデルで応答を得るには、新しいメッセージを送信してください",
"no_api_key": "APIキーが設定されていません",
"provider_disabled": "モデルプロバイダーが有効になっていません",
"render": {

View File

@ -447,6 +447,7 @@
"504": "Серверная ошибка. Пожалуйста, попробуйте позже"
},
"model.exists": "Модель уже существует",
"missing_user_message": "Невозможно изменить модель ответа: исходное сообщение пользователя было удалено. Пожалуйста, отправьте новое сообщение, чтобы получить ответ от этой модели",
"no_api_key": "Ключ API не настроен",
"provider_disabled": "Провайдер моделей не включен",
"render": {

View File

@ -447,6 +447,7 @@
"504": "网关超时,请稍后再试"
},
"model.exists": "模型已存在",
"missing_user_message": "无法切换模型响应:原始用户消息已被删除。请发送新消息以获取此模型的响应",
"no_api_key": "API 密钥未配置",
"provider_disabled": "模型提供商未启用",
"render": {

View File

@ -447,6 +447,7 @@
"504": "閘道器超時,請稍後再試"
},
"model.exists": "模型已存在",
"missing_user_message": "無法切換模型回應:原始用戶訊息已被刪除。請發送新訊息以獲得此模型回應。",
"no_api_key": "API 金鑰未設定",
"provider_disabled": "模型供應商未啟用",
"render": {

View File

@ -1165,6 +1165,29 @@ export const regenerateAssistantResponseThunk =
// 1. Use selector to get all messages for the topic
const allMessagesForTopic = selectMessagesForTopic(state, topicId)
const askId = assistantMessageToRegenerate.askId
if (!askId) {
console.error(
`[appendAssistantResponseThunk] Existing assistant message ${assistantMessageToRegenerate.id} does not have an askId.`
)
return // Stop if askId is missing
}
if (!state.messages.entities[askId]) {
console.error(
`[appendAssistantResponseThunk] Original user query (askId: ${askId}) not found in entities. Cannot create assistant response without corresponding user message.`
)
// Show error popup instead of creating error message block
window.message.error({
content: t('error.missing_user_message'),
key: 'missing-user-message-error'
})
return
}
// 2. Find the original user query (Restored Logic)
const originalUserQuery = allMessagesForTopic.find((m) => m.id === assistantMessageToRegenerate.askId)
if (!originalUserQuery) {
@ -1375,10 +1398,17 @@ export const appendAssistantResponseThunk =
// (Optional but recommended) Verify the original user query exists
if (!state.messages.entities[askId]) {
console.warn(
`[appendAssistantResponseThunk] Original user query (askId: ${askId}) not found in entities. Proceeding, but state might be inconsistent.`
console.error(
`[appendAssistantResponseThunk] Original user query (askId: ${askId}) not found in entities. Cannot create assistant response without corresponding user message.`
)
// Decide whether to proceed or return based on requirements
// Show error popup instead of creating error message block
window.message.error({
content: t('error.missing_user_message'),
key: 'missing-user-message-error'
})
return
}
// 2. Create the new assistant message stub