Perisisting threads and chat history for your generative UI (GenUI) application using Firebase Firestore as a persistence layer.
Set up Firebase Project & SDK
firebaseConfig
object.Detailed Instructions
</>
).firebaseConfig
object. Copy this object.src/firebaseConfig.ts
):
Replace the placeholder values in firebaseConfig
with your actual credentials in src/firebaseConfig.ts
:
Create Thread Service for Firebase
src/services/threadService.ts
:1. Core CRUD Functions:
Implement functions to create, read, update, and delete threads and messages.Refer to the complete example threadService.ts
for full implementations of others like getThreadList
, getUIThreadMessages
, getLLMThreadMessages
, updateMessage
, deleteThread
, and updateThread
similarly.createThread
addMessages
Integrate Service with Frontend
src/app/page.tsx
) to use the functions in threadService.ts
for data operations.threadService
functions to the useThreadListManager
and useThreadManager
hooks.
page.tsx
for detailed hook setup with imports.
Add Backend Chat API Route
threadService.ts
for fetching historical messages and saving new ones.getLLMThreadMessages
.
on("end")
event of the LLM stream, use addMessages
to store the new user prompt and all assistant/tool messages generated in that turn.
/api/chat/route.ts
for context.
src/firebaseConfig.ts
.THESYS_API_KEY
is set in .env
.npm run dev
.