Skip to content

Commit

Permalink
ensure assistant response parsed correctly (#2823)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx authored Oct 16, 2024
1 parent 0a0215c commit f3fb7c5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions web/src/app/chat/shared/[chatId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { redirect } from "next/navigation";
import { BackendChatSession } from "../../interfaces";
import { SharedChatDisplay } from "./SharedChatDisplay";
import { Persona } from "@/app/admin/assistants/interfaces";
import { fetchAssistantsSS } from "@/lib/assistants/fetchAssistantsSS";
import {
FetchAssistantsResponse,
fetchAssistantsSS,
} from "@/lib/assistants/fetchAssistantsSS";
import FunctionalHeader from "@/components/chat_search/Header";
import { defaultPersona } from "@/app/admin/assistants/lib";

Expand Down Expand Up @@ -44,7 +47,8 @@ export default async function Page({ params }: { params: { chatId: string } }) {
const authTypeMetadata = results[0] as AuthTypeMetadata | null;
const user = results[1] as User | null;
const chatSession = results[2] as BackendChatSession | null;
const availableAssistants = results[3] as Persona[] | null;
const assistantsResponse = results[3] as FetchAssistantsResponse | null;
const [availableAssistants, _] = assistantsResponse ?? [[], null];

const authDisabled = authTypeMetadata?.authType === "disabled";
if (!authDisabled && !user) {
Expand All @@ -54,11 +58,12 @@ export default async function Page({ params }: { params: { chatId: string } }) {
if (user && !user.is_verified && authTypeMetadata?.requiresVerification) {
return redirect("/auth/waiting-on-verification");
}
const persona = chatSession?.persona_id
? (availableAssistants?.find((p) => p.id === chatSession.persona_id) ??
availableAssistants?.[0] ??
null)
: (availableAssistants?.[0] ?? defaultPersona);

const persona: Persona =
chatSession?.persona_id && availableAssistants?.length
? (availableAssistants.find((p) => p.id === chatSession.persona_id) ??
defaultPersona)
: (availableAssistants?.[0] ?? defaultPersona);

return (
<div>
Expand Down

0 comments on commit f3fb7c5

Please sign in to comment.