diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 02645faa69..bc63d6132c 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -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": { diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index f2f802cd26..4180e7b20e 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -447,6 +447,7 @@ "504": "ゲートウェイタイムアウトが発生しました。後でもう一度試してください" }, "model.exists": "モデルが既に存在します", + "missing_user_message": "モデル応答を切り替えられません:元のユーザーメッセージが削除されました。このモデルで応答を得るには、新しいメッセージを送信してください", "no_api_key": "APIキーが設定されていません", "provider_disabled": "モデルプロバイダーが有効になっていません", "render": { diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index b5b5bfbd11..9efc0c7cc0 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -447,6 +447,7 @@ "504": "Серверная ошибка. Пожалуйста, попробуйте позже" }, "model.exists": "Модель уже существует", + "missing_user_message": "Невозможно изменить модель ответа: исходное сообщение пользователя было удалено. Пожалуйста, отправьте новое сообщение, чтобы получить ответ от этой модели", "no_api_key": "Ключ API не настроен", "provider_disabled": "Провайдер моделей не включен", "render": { diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 3fec012014..76f1bfcee3 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -447,6 +447,7 @@ "504": "网关超时,请稍后再试" }, "model.exists": "模型已存在", + "missing_user_message": "无法切换模型响应:原始用户消息已被删除。请发送新消息以获取此模型的响应", "no_api_key": "API 密钥未配置", "provider_disabled": "模型提供商未启用", "render": { diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 9e1a74d5e8..531210b660 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -447,6 +447,7 @@ "504": "閘道器超時,請稍後再試" }, "model.exists": "模型已存在", + "missing_user_message": "無法切換模型回應:原始用戶訊息已被刪除。請發送新訊息以獲得此模型回應。", "no_api_key": "API 金鑰未設定", "provider_disabled": "模型供應商未啟用", "render": { diff --git a/src/renderer/src/store/thunk/messageThunk.ts b/src/renderer/src/store/thunk/messageThunk.ts index eaf658aa13..0360022a54 100644 --- a/src/renderer/src/store/thunk/messageThunk.ts +++ b/src/renderer/src/store/thunk/messageThunk.ts @@ -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