diff --git a/apps/sim/app/api/copilot/chat/route.ts b/apps/sim/app/api/copilot/chat/route.ts index c6a7d9737..7595c454c 100644 --- a/apps/sim/app/api/copilot/chat/route.ts +++ b/apps/sim/app/api/copilot/chat/route.ts @@ -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: { diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-modal/copilot-modal.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-modal/copilot-modal.tsx index 36780049c..69c4a547b 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-modal/copilot-modal.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-modal/copilot-modal.tsx @@ -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 diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx index f4c19b6ef..0a88eb4d5 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx @@ -277,7 +277,7 @@ export const Copilot = forwardRef( // Reload chats in background to get the updated list loadChats() } - + // Mark stream as complete to exit outer loop streamComplete = true break