Add a unique_id field for identifiying conversations (#914)

* Add a unique_id field to the conversation object

- This helps us keep track of the unique identity of the conversation without expose the internal id
- Create three staged migrations in order to first add the field, then add unique values to pre-fill, and then set the unique constraint. Without this, it tries to initialize all the existing conversations with the same ID.

* Parse and utilize the unique_id field in the query parameters of the front-end view

- Handle the unique_id field when creating a new conversation from the home page
- Parse the id field with a lightweight parameter called v in the chat page
- Share page should not be affected, as it uses the public slug

* Fix suggested card category
This commit is contained in:
sabaimran
2024-09-16 12:19:16 -07:00
committed by GitHub
parent e6bc7a2ba2
commit ece2ec2d90
11 changed files with 169 additions and 20 deletions

View File

@@ -186,6 +186,11 @@ export function modifyFileFilterForConversation(
});
}
interface NewConversationMetadata {
conversationId: string;
conversationUniqueId: string;
}
export async function createNewConversation(slug: string) {
try {
const response = await fetch(`/api/chat/sessions?client=web&agent_slug=${slug}`, {
@@ -194,9 +199,11 @@ export async function createNewConversation(slug: string) {
if (!response.ok)
throw new Error(`Failed to fetch chat sessions with status: ${response.status}`);
const data = await response.json();
const conversationID = data.conversation_id;
if (!conversationID) throw new Error("Conversation ID not found in response");
return conversationID;
const uniqueId = data.unique_id;
const conversationId = data.conversation_id;
if (!uniqueId) throw new Error("Unique ID not found in response");
if (!conversationId) throw new Error("Conversation ID not found in response");
return { conversationId, conversationUniqueId: uniqueId } as NewConversationMetadata;
} catch (error) {
console.error("Error creating new conversation:", error);
throw error;