+ {/* Messages */}
+
+ {messages.map((m) => (
+
+ ))}
+
+ {/* Context gathering progress */}
+ {contextStatus.phase === 'gathering' && (
+
+
Gathering context...
+
+ {Object.entries(contextStatus.progress).map(([step, status]) => (
+
+
+ {status === 'completed' ? '✓' : status === 'started' ? '⋯' : '✗'}
+
+ {step.replace(/-/g, ' ')}
+
+ ))}
+
+
+ )}
+
+ {isLoading && (
+
+ )}
+
+
+ {/* Input */}
+
+ setInput(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' && !e.shiftKey) {
+ e.preventDefault();
+ handleSendMessage();
+ }
+ }}
+ placeholder="Ask a question..."
+ disabled={contextStatus.phase === 'gathering' || isLoading}
+ className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
+ />
+
+
+
+ {/* Status indicator */}
+ {contextStatus.phase === 'error' && (
+
+ Error gathering context. Please try again.
+
+ )}
+
+ );
+}
+```
+
+Update your chat API route to use the runId:
+
+```typescript
+// app/api/chatbot-stream/route.ts
+export async function POST(req: Request) {
+ const { messages, data } = await req.json();
+ const { runId, conversationId } = data;
+
+ // Forward to your Supabase edge function
+ const response = await fetch(
+ `${process.env.NEXT_PUBLIC_SUPABASE_URL}/functions/v1/chatbot-stream`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY}`,
+ },
+ body: JSON.stringify({
+ runId,
+ conversationId,
+ message: messages[messages.length - 1].content,
+ }),
+ }
+ );
+
+ return new Response(response.body, {
+ headers: {
+ 'Content-Type': 'text/event-stream',
+ 'Cache-Control': 'no-cache',
+ },
+ });
+}
+```
+
+## Deploy and Test
+
+