Skip to content

An AI-powered search engine with a generative UI

fix: address Copilot review comments

Yoshiki Miuraa0dc96b4a416
diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts
index d7072957..a2a9ef2b 100644
--- a/app/api/chat/route.ts
+++ b/app/api/chat/route.ts
@@ -22,18 +22,20 @@ export async function POST(req: Request) {
const { message, chatId, trigger, messageId } = body
// Handle different triggers
- if (trigger === 'regenerate-assistant-message' && !messageId) {
- return new Response('messageId is required for regeneration', {
- status: 400,
- statusText: 'Bad Request'
- })
- }
-
- if (trigger === 'submit-user-message' && !message) {
- return new Response('message is required for submission', {
- status: 400,
- statusText: 'Bad Request'
- })
+ if (trigger === 'regenerate-assistant-message') {
+ if (!messageId) {
+ return new Response('messageId is required for regeneration', {
+ status: 400,
+ statusText: 'Bad Request'
+ })
+ }
+ } else if (trigger === 'submit-user-message') {
+ if (!message) {
+ return new Response('message is required for submission', {
+ status: 400,
+ statusText: 'Bad Request'
+ })
+ }
}
const referer = req.headers.get('referer')
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.ts
index 84b3e6ff..4e504f1d 100644
--- a/lib/streaming/create-chat-stream-response.ts
+++ b/lib/streaming/create-chat-stream-response.ts
@@ -92,9 +92,12 @@ export async function createChatStreamResponse(
}
// Get updated messages including the edited one
const updatedChat = await getChatAction(chatId, userId)
- messagesToModel =
- updatedChat?.messages ||
- currentChat.messages.slice(0, messageIndex + 1)
+ if (updatedChat?.messages) {
+ messagesToModel = updatedChat.messages
+ } else {
+ // Fallback: use current messages up to and including the edited message
+ messagesToModel = currentChat.messages.slice(0, messageIndex + 1)
+ }
}
} else {
// Handle normal message submission