Conversation
|
So, @rooney011 here's the info: I think you're stuck with the Vercel AI Gateway thing. You can skip it by using the API keys obtained directly from the actual providers (Gemini, ChatGPT, Claude, etc.). We're aiming for multiple models support in this chatbot anyway, so, incorporate all those models. But, for testing, stick to Gemini, use the Gemini API Key and the smallest gemini model (mayb 2.5 flash or flash lite if that's still available) for basic testing, and use the pro model only when you want to test longer wait times, visualize more complicated outputs from the model, etc. Here's a perplexity doc I made for you to understand a little bit about AI SDK, and why we need to care about it: https://www.perplexity.ai/search/tell-me-what-is-it-about-ai-sd-p3vvzaSoQgahCd7Un85XVA#0 Let me know if you have any doubts. Sorry for keeping you waiting too long. |
|
No issues at all. I’ll ask if anything comes up. |
graph TB
subgraph "Frontend Routing"
A["/chat<br/>(New Chat State)"] -->|User sends first message| B[useChat Hook]
C["/chat/[sessionId]<br/>(Active Chat State)"] -->|Load existing| D[Fetch DB Messages]
D -->|Hydrate| B
B -->|Session created| E[window.history.replaceState]
E -->|Update URL| C
end
subgraph "UI Components"
F[ChatHistorySidebar] -->|Display| G[Conversation List]
F -->|Actions| H[New Chat Button]
F -->|Actions| I[Delete Session]
G -->|Click| C
end
subgraph "API Layer (/api/chat)"
J["POST Request<br/>messages, sessionId"] -->|1. Validate Auth| K[supabase.auth.getUser]
K -->|2. Save User Message| L[Insert to chat_messages]
L -->|3. Start Streaming| M[streamText - Gemini Flash 001]
M -->|4. Stream to Client| N[Real-time Response]
M -->|5. onFinish Callback| O[Save AI Response]
O -->|6. waitUntil| P[Ensure DB Write Completes]
end
subgraph "Database Schema (Supabase)"
Q[(chat_sessions<br/>---<br/>id: uuid PK<br/>user_id: uuid FK<br/>title: text<br/>created_at: timestamptz)]
R[(chat_messages<br/>---<br/>id: uuid PK<br/>session_id: uuid FK<br/>role: text<br/>content: text<br/>created_at: timestamptz)]
Q -->|ON DELETE CASCADE| R
Q -.->|RLS Policy| S[auth.users]
end
subgraph "Context Management"
T["Full Message History<br/>Display Only"] -->|Frontend| U[Chat UI Shows All]
V["Sliding Window<br/>Last 15-20 messages"] -->|Backend| M
T -.->|Subset| V
end
subgraph "Security Layer"
W[Row Level Security] -->|Enforce| Q
W -->|Enforce| R
K -->|Validates| S
end
B -->|API Call| J
L -->|Write| R
O -->|Write| R
D -->|Read| R
I -->|DELETE| Q
classDef frontend fill:#e1f5ff,stroke:#01579b,stroke-width:2px
classDef backend fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef database fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
classDef security fill:#ffebee,stroke:#b71c1c,stroke-width:2px
class A,B,C,D,E,F,G,H,I,U frontend
class J,K,L,M,N,O,P,V backend
class Q,R,T database
class S,W security
style M fill:#fff9c4,stroke:#f57f17,stroke-width:3px
style P fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px
|
|
I created a new clean branch because the previous one became messy. This PR includes the updated chat UI, including changes to the sidebar components, chat layout, and route files.