Skip to content

Commit

Permalink
Fix handling for new conversation in agents page
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaimran committed Sep 16, 2024
1 parent ece2ec2 commit 3466f04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/interface/web/app/agents/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { getIconFromIconName } from "../common/iconUtils";
import { convertColorToTextClass } from "../common/colorUtils";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { useIsMobileWidth } from "../common/utils";
import { createNewConversation } from "../common/chatFunctions";

export interface AgentData {
slug: string;
Expand All @@ -55,13 +56,10 @@ async function openChat(slug: string, userData: UserProfile | null) {
return;
}

const response = await fetch(`/api/chat/sessions?agent_slug=${slug}`, { method: "POST" });
const data = await response.json();
if (response.status == 200) {
window.location.href = `/chat?conversationId=${data.conversation_id}`;
} else if (response.status == 403 || response.status == 401) {
window.location.href = unauthenticatedRedirectUrl;
} else {
try {
const response = await createNewConversation(slug);
window.location.href = `/chat?v=${response.conversationUniqueId}`;
} catch (error) {
alert("Failed to start chat session");
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/interface/web/app/common/chatFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ export async function createNewConversation(slug: string) {
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;
return {
conversationId: conversationId,
conversationUniqueId: uniqueId,
} as NewConversationMetadata;
} catch (error) {
console.error("Error creating new conversation:", error);
throw error;
Expand Down

0 comments on commit 3466f04

Please sign in to comment.