This commit is contained in:
Siddharth Ganesan
2025-07-08 18:30:44 -07:00
parent a3159bcebc
commit 4fffc66ee0
3 changed files with 15 additions and 4 deletions

View File

@@ -242,6 +242,7 @@ IMPORTANT: Always provide complete, helpful responses. If you add citations, con
})
// Store citations for later use in the main streaming handler
;(streamResponse as any)._citations = responseCitations
return streamResponse
@@ -435,7 +436,12 @@ export async function POST(req: NextRequest) {
const assistantMessage = {
id: crypto.randomUUID(),
role: 'assistant',
content: typeof response === 'string' ? response : (typeof response === 'object' && 'content' in response ? response.content : '[Error generating response]') || '[Error generating response]',
content:
typeof response === 'string'
? response
: (typeof response === 'object' && 'content' in response
? response.content
: '[Error generating response]') || '[Error generating response]',
timestamp: new Date().toISOString(),
citations: citations.length > 0 ? citations : undefined,
}
@@ -464,7 +470,12 @@ export async function POST(req: NextRequest) {
return NextResponse.json({
success: true,
response: typeof response === 'string' ? response : (typeof response === 'object' && 'content' in response ? response.content : '[Error generating response]') || '[Error generating response]',
response:
typeof response === 'string'
? response
: (typeof response === 'object' && 'content' in response
? response.content
: '[Error generating response]') || '[Error generating response]',
chatId: currentChat?.id,
citations: extractCitationsFromResponse(response),
metadata: {

View File

@@ -48,7 +48,7 @@ function ModalCopilotMessage({ message }: CopilotModalMessage) {
if (!citations || citations.length === 0) return text
let processedText = text
// Replace [1], [2], [3] etc. with clickable citation icons
processedText = processedText.replace(/\[(\d+)\]/g, (match, num) => {
const citationIndex = Number.parseInt(num) - 1

View File

@@ -277,7 +277,7 @@ export const Copilot = forwardRef<CopilotRef, CopilotProps>(
// Reload chats in background to get the updated list
loadChats()
}
// Mark stream as complete to exit outer loop
streamComplete = true
break