ensure shared chats are shared

This commit is contained in:
pablodanswer
2024-10-14 15:02:03 -07:00
parent 494fda906d
commit 8be887f3ee
5 changed files with 39 additions and 14 deletions

View File

@@ -239,11 +239,14 @@ def get_persona(
persona_id: int,
user: User | None = Depends(current_user),
db_session: Session = Depends(get_session),
include_non_owned: bool = Query(
False, description="If true, return persona even if user doesn't own it."
),
) -> PersonaSnapshot:
return PersonaSnapshot.from_model(
get_persona_by_id(
persona_id=persona_id,
user=user,
user=user if not include_non_owned else None,
db_session=db_session,
is_for_edit=False,
)

View File

@@ -2,7 +2,7 @@
import Prism from "prismjs";
import { humanReadableFormat } from "@/lib/time";
import { BackendChatSession } from "../../interfaces";
import { BackendChatSession, SharedChatSession } from "../../interfaces";
import {
buildLatestMessageChain,
getCitedDocumentsFromMessage,
@@ -11,10 +11,10 @@ import {
import { AIMessage, HumanMessage } from "../../message/Messages";
import { Button, Callout, Divider } from "@tremor/react";
import { useRouter } from "next/navigation";
import { Persona } from "@/app/admin/assistants/interfaces";
import { useContext, useEffect, useState } from "react";
import { SettingsContext } from "@/components/settings/SettingsProvider";
import { DanswerInitializingLoader } from "@/components/DanswerInitializingLoader";
import { Persona } from "@/app/admin/assistants/interfaces";
function BackToDanswerButton() {
const router = useRouter();
@@ -34,10 +34,10 @@ function BackToDanswerButton() {
export function SharedChatDisplay({
chatSession,
availableAssistants,
persona,
}: {
chatSession: BackendChatSession | null;
availableAssistants: Persona[];
persona: Persona;
}) {
const [isReady, setIsReady] = useState(false);
useEffect(() => {
@@ -56,9 +56,6 @@ export function SharedChatDisplay({
</div>
);
}
const currentPersona = availableAssistants.find(
(persona) => persona.id === chatSession.persona_id
);
const messages = buildLatestMessageChain(
processRawChatHistory(chatSession.messages)
@@ -96,7 +93,7 @@ export function SharedChatDisplay({
return (
<AIMessage
shared
currentPersona={currentPersona!}
currentPersona={persona}
key={message.messageId}
messageId={message.messageId}
content={message.message}

View File

@@ -11,6 +11,7 @@ import { SharedChatDisplay } from "./SharedChatDisplay";
import { Persona } from "@/app/admin/assistants/interfaces";
import { fetchAssistantsSS } from "@/lib/assistants/fetchAssistantsSS";
import FunctionalHeader from "@/components/chat_search/Header";
import { fetchAssistantSS } from "@/lib/assistants/fetchAssistantSS";
async function getSharedChat(chatId: string) {
const response = await fetchSS(
@@ -43,7 +44,16 @@ 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[], string | null];
const availableAssistants = results[3] as Persona[] | null;
let persona: Persona | null = null;
if (chatSession && chatSession.persona_id) {
try {
persona = await fetchAssistantSS(chatSession.persona_id);
} catch (e) {
console.log(`Failed to fetch persona - ${e}`);
}
}
const authDisabled = authTypeMetadata?.authType === "disabled";
if (!authDisabled && !user) {
@@ -53,6 +63,9 @@ export default async function Page({ params }: { params: { chatId: string } }) {
if (user && !user.is_verified && authTypeMetadata?.requiresVerification) {
return redirect("/auth/waiting-on-verification");
}
if (!persona) {
persona = availableAssistants?.[0] ?? null;
}
return (
<div>
@@ -61,10 +74,7 @@ export default async function Page({ params }: { params: { chatId: string } }) {
</div>
<div className="flex relative bg-background text-default overflow-hidden pt-16 h-screen">
<SharedChatDisplay
chatSession={chatSession}
availableAssistants={availableAssistants}
/>
<SharedChatDisplay chatSession={chatSession} persona={persona!} />
</div>
</div>
);

View File

@@ -37,6 +37,7 @@ export function ProviderContextProvider({
const fetchProviderInfo = useCallback(async () => {
const { providers, options, defaultCheckSuccessful } =
await checkLlmProvider(user);
setValidProviderExists(providers.length > 0 && defaultCheckSuccessful);
setProviderOptions(options);
}, [user, setValidProviderExists, setProviderOptions]);

View File

@@ -0,0 +1,14 @@
import { Persona } from "@/app/admin/assistants/interfaces";
import { fetchSS } from "../utilsSS";
export async function fetchAssistantSS(
personaId: number
): Promise<Persona | null> {
const response = await fetchSS(
`/persona/${personaId}?include_non_owned=true`
);
if (response.ok) {
return (await response.json()) as Persona;
}
return null;
}