mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-21 14:12:42 +02:00
Session id: int -> UUID (#2814)
* session id: int -> UUID * nit * validated * validated downgrade + upgrade + all functionality * nit * minor nit * fix test case
This commit is contained in:
@@ -145,19 +145,17 @@ export function ChatPage({
|
||||
const existingChatIdRaw = searchParams.get("chatId");
|
||||
const currentPersonaId = searchParams.get(SEARCH_PARAM_NAMES.PERSONA_ID);
|
||||
|
||||
const existingChatSessionId = existingChatIdRaw
|
||||
? parseInt(existingChatIdRaw)
|
||||
: null;
|
||||
const existingChatSessionId = existingChatIdRaw ? existingChatIdRaw : null;
|
||||
|
||||
const selectedChatSession = chatSessions.find(
|
||||
(chatSession) => chatSession.id === existingChatSessionId
|
||||
);
|
||||
|
||||
const chatSessionIdRef = useRef<number | null>(existingChatSessionId);
|
||||
const chatSessionIdRef = useRef<string | null>(existingChatSessionId);
|
||||
|
||||
// Only updates on session load (ie. rename / switching chat session)
|
||||
// Useful for determining which session has been loaded (i.e. still on `new, empty session` or `previous session`)
|
||||
const loadedIdSessionRef = useRef<number | null>(existingChatSessionId);
|
||||
const loadedIdSessionRef = useRef<string | null>(existingChatSessionId);
|
||||
|
||||
// Assistants in order
|
||||
const { finalAssistants } = useMemo(() => {
|
||||
@@ -448,11 +446,11 @@ export function ChatPage({
|
||||
);
|
||||
|
||||
const [completeMessageDetail, setCompleteMessageDetail] = useState<
|
||||
Map<number | null, Map<number, Message>>
|
||||
Map<string | null, Map<number, Message>>
|
||||
>(new Map());
|
||||
|
||||
const updateCompleteMessageDetail = (
|
||||
sessionId: number | null,
|
||||
sessionId: string | null,
|
||||
messageMap: Map<number, Message>
|
||||
) => {
|
||||
setCompleteMessageDetail((prevState) => {
|
||||
@@ -463,13 +461,13 @@ export function ChatPage({
|
||||
};
|
||||
|
||||
const currentMessageMap = (
|
||||
messageDetail: Map<number | null, Map<number, Message>>
|
||||
messageDetail: Map<string | null, Map<number, Message>>
|
||||
) => {
|
||||
return (
|
||||
messageDetail.get(chatSessionIdRef.current) || new Map<number, Message>()
|
||||
);
|
||||
};
|
||||
const currentSessionId = (): number => {
|
||||
const currentSessionId = (): string => {
|
||||
return chatSessionIdRef.current!;
|
||||
};
|
||||
|
||||
@@ -484,7 +482,7 @@ export function ChatPage({
|
||||
// if calling this function repeatedly with short delay, stay may not update in time
|
||||
// and result in weird behavipr
|
||||
completeMessageMapOverride?: Map<number, Message> | null;
|
||||
chatSessionId?: number;
|
||||
chatSessionId?: string;
|
||||
replacementsMap?: Map<number, number> | null;
|
||||
makeLatestChildMessage?: boolean;
|
||||
}) => {
|
||||
@@ -559,23 +557,23 @@ export function ChatPage({
|
||||
|
||||
const [submittedMessage, setSubmittedMessage] = useState("");
|
||||
|
||||
const [chatState, setChatState] = useState<Map<number | null, ChatState>>(
|
||||
const [chatState, setChatState] = useState<Map<string | null, ChatState>>(
|
||||
new Map([[chatSessionIdRef.current, "input"]])
|
||||
);
|
||||
|
||||
const [regenerationState, setRegenerationState] = useState<
|
||||
Map<number | null, RegenerationState | null>
|
||||
Map<string | null, RegenerationState | null>
|
||||
>(new Map([[null, null]]));
|
||||
|
||||
const [abortControllers, setAbortControllers] = useState<
|
||||
Map<number | null, AbortController>
|
||||
Map<string | null, AbortController>
|
||||
>(new Map());
|
||||
|
||||
// Updates "null" session values to new session id for
|
||||
// regeneration, chat, and abort controller state, messagehistory
|
||||
const updateStatesWithNewSessionId = (newSessionId: number) => {
|
||||
const updateStatesWithNewSessionId = (newSessionId: string) => {
|
||||
const updateState = (
|
||||
setState: Dispatch<SetStateAction<Map<number | null, any>>>,
|
||||
setState: Dispatch<SetStateAction<Map<string | null, any>>>,
|
||||
defaultValue?: any
|
||||
) => {
|
||||
setState((prevState) => {
|
||||
@@ -610,7 +608,7 @@ export function ChatPage({
|
||||
chatSessionIdRef.current = newSessionId;
|
||||
};
|
||||
|
||||
const updateChatState = (newState: ChatState, sessionId?: number | null) => {
|
||||
const updateChatState = (newState: ChatState, sessionId?: string | null) => {
|
||||
setChatState((prevState) => {
|
||||
const newChatState = new Map(prevState);
|
||||
newChatState.set(
|
||||
@@ -635,7 +633,7 @@ export function ChatPage({
|
||||
|
||||
const updateRegenerationState = (
|
||||
newState: RegenerationState | null,
|
||||
sessionId?: number | null
|
||||
sessionId?: string | null
|
||||
) => {
|
||||
setRegenerationState((prevState) => {
|
||||
const newRegenerationState = new Map(prevState);
|
||||
@@ -647,18 +645,18 @@ export function ChatPage({
|
||||
});
|
||||
};
|
||||
|
||||
const resetRegenerationState = (sessionId?: number | null) => {
|
||||
const resetRegenerationState = (sessionId?: string | null) => {
|
||||
updateRegenerationState(null, sessionId);
|
||||
};
|
||||
|
||||
const currentRegenerationState = (): RegenerationState | null => {
|
||||
return regenerationState.get(currentSessionId()) || null;
|
||||
};
|
||||
const [canContinue, setCanContinue] = useState<Map<number | null, boolean>>(
|
||||
const [canContinue, setCanContinue] = useState<Map<string | null, boolean>>(
|
||||
new Map([[null, false]])
|
||||
);
|
||||
|
||||
const updateCanContinue = (newState: boolean, sessionId?: number | null) => {
|
||||
const updateCanContinue = (newState: boolean, sessionId?: string | null) => {
|
||||
setCanContinue((prevState) => {
|
||||
const newCanContinueState = new Map(prevState);
|
||||
newCanContinueState.set(
|
||||
@@ -1003,7 +1001,7 @@ export function ChatPage({
|
||||
|
||||
setAlternativeGeneratingAssistant(alternativeAssistantOverride);
|
||||
clientScrollToBottom();
|
||||
let currChatSessionId: number;
|
||||
let currChatSessionId: string;
|
||||
const isNewSession = chatSessionIdRef.current === null;
|
||||
const searchParamBasedChatSessionName =
|
||||
searchParams.get(SEARCH_PARAM_NAMES.TITLE) || null;
|
||||
@@ -1014,7 +1012,7 @@ export function ChatPage({
|
||||
searchParamBasedChatSessionName
|
||||
);
|
||||
} else {
|
||||
currChatSessionId = chatSessionIdRef.current as number;
|
||||
currChatSessionId = chatSessionIdRef.current as string;
|
||||
}
|
||||
frozenSessionId = currChatSessionId;
|
||||
|
||||
@@ -1598,7 +1596,7 @@ export function ChatPage({
|
||||
}
|
||||
|
||||
const [visibleRange, setVisibleRange] = useState<
|
||||
Map<number | null, VisibleRange>
|
||||
Map<string | null, VisibleRange>
|
||||
>(() => {
|
||||
const initialRange: VisibleRange = {
|
||||
start: 0,
|
||||
|
@@ -30,7 +30,7 @@ const FolderItem = ({
|
||||
initiallySelected,
|
||||
}: {
|
||||
folder: Folder;
|
||||
currentChatId?: number;
|
||||
currentChatId?: string;
|
||||
isInitiallyExpanded: boolean;
|
||||
initiallySelected: boolean;
|
||||
}) => {
|
||||
@@ -145,10 +145,7 @@ const FolderItem = ({
|
||||
const handleDrop = async (event: React.DragEvent<HTMLDivElement>) => {
|
||||
event.preventDefault();
|
||||
setIsDragOver(false);
|
||||
const chatSessionId = parseInt(
|
||||
event.dataTransfer.getData(CHAT_SESSION_ID_KEY),
|
||||
10
|
||||
);
|
||||
const chatSessionId = event.dataTransfer.getData(CHAT_SESSION_ID_KEY);
|
||||
try {
|
||||
await addChatToFolder(folder.folder_id, chatSessionId);
|
||||
router.refresh(); // Refresh to show the updated folder contents
|
||||
@@ -302,7 +299,7 @@ export const FolderList = ({
|
||||
newFolderId,
|
||||
}: {
|
||||
folders: Folder[];
|
||||
currentChatId?: number;
|
||||
currentChatId?: string;
|
||||
openedFolders?: { [key: number]: boolean };
|
||||
newFolderId: number | null;
|
||||
}) => {
|
||||
|
@@ -17,7 +17,7 @@ export async function createFolder(folderName: string): Promise<number> {
|
||||
// Function to add a chat session to a folder
|
||||
export async function addChatToFolder(
|
||||
folderId: number,
|
||||
chatSessionId: number
|
||||
chatSessionId: string
|
||||
): Promise<void> {
|
||||
const response = await fetch(`/api/folder/${folderId}/add-chat-session`, {
|
||||
method: "POST",
|
||||
@@ -34,7 +34,7 @@ export async function addChatToFolder(
|
||||
// Function to remove a chat session from a folder
|
||||
export async function removeChatFromFolder(
|
||||
folderId: number,
|
||||
chatSessionId: number
|
||||
chatSessionId: string
|
||||
): Promise<void> {
|
||||
const response = await fetch(`/api/folder/${folderId}/remove-chat-session`, {
|
||||
method: "POST",
|
||||
|
@@ -86,7 +86,7 @@ export function ChatInputBar({
|
||||
setFiles: (files: FileDescriptor[]) => void;
|
||||
handleFileUpload: (files: File[]) => void;
|
||||
textAreaRef: React.RefObject<HTMLTextAreaElement>;
|
||||
chatSessionId?: number;
|
||||
chatSessionId?: string;
|
||||
refreshUser: () => void;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
|
@@ -60,7 +60,7 @@ export interface ToolCallFinalResult {
|
||||
}
|
||||
|
||||
export interface ChatSession {
|
||||
id: number;
|
||||
id: string;
|
||||
name: string;
|
||||
persona_id: number;
|
||||
time_created: string;
|
||||
@@ -70,7 +70,7 @@ export interface ChatSession {
|
||||
}
|
||||
|
||||
export interface SearchSession {
|
||||
search_session_id: number;
|
||||
search_session_id: string;
|
||||
documents: SearchDanswerDocument[];
|
||||
messages: BackendMessage[];
|
||||
description: string;
|
||||
@@ -97,7 +97,7 @@ export interface Message {
|
||||
}
|
||||
|
||||
export interface BackendChatSession {
|
||||
chat_session_id: number;
|
||||
chat_session_id: string;
|
||||
description: string;
|
||||
persona_id: number;
|
||||
persona_name: string;
|
||||
@@ -110,7 +110,7 @@ export interface BackendChatSession {
|
||||
export interface BackendMessage {
|
||||
message_id: number;
|
||||
comments: any;
|
||||
chat_session_id: number;
|
||||
chat_session_id: string;
|
||||
parent_message: number | null;
|
||||
latest_child_message: number | null;
|
||||
message: string;
|
||||
|
@@ -55,7 +55,7 @@ export function getChatRetentionInfo(
|
||||
}
|
||||
|
||||
export async function updateModelOverrideForChatSession(
|
||||
chatSessionId: number,
|
||||
chatSessionId: string,
|
||||
newAlternateModel: string
|
||||
) {
|
||||
const response = await fetch("/api/chat/update-chat-session-model", {
|
||||
@@ -74,7 +74,7 @@ export async function updateModelOverrideForChatSession(
|
||||
export async function createChatSession(
|
||||
personaId: number,
|
||||
description: string | null
|
||||
): Promise<number> {
|
||||
): Promise<string> {
|
||||
const createChatSessionResponse = await fetch(
|
||||
"/api/chat/create-chat-session",
|
||||
{
|
||||
@@ -131,7 +131,7 @@ export async function* sendMessage({
|
||||
message: string;
|
||||
fileDescriptors: FileDescriptor[];
|
||||
parentMessageId: number | null;
|
||||
chatSessionId: number;
|
||||
chatSessionId: string;
|
||||
promptId: number | null | undefined;
|
||||
filters: Filters | null;
|
||||
selectedDocumentIds: number[] | null;
|
||||
@@ -203,7 +203,7 @@ export async function* sendMessage({
|
||||
yield* handleSSEStream<PacketType>(response);
|
||||
}
|
||||
|
||||
export async function nameChatSession(chatSessionId: number, message: string) {
|
||||
export async function nameChatSession(chatSessionId: string, message: string) {
|
||||
const response = await fetch("/api/chat/rename-chat-session", {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
@@ -252,7 +252,7 @@ export async function handleChatFeedback(
|
||||
return response;
|
||||
}
|
||||
export async function renameChatSession(
|
||||
chatSessionId: number,
|
||||
chatSessionId: string,
|
||||
newName: string
|
||||
) {
|
||||
const response = await fetch(`/api/chat/rename-chat-session`, {
|
||||
@@ -269,7 +269,7 @@ export async function renameChatSession(
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function deleteChatSession(chatSessionId: number) {
|
||||
export async function deleteChatSession(chatSessionId: string) {
|
||||
const response = await fetch(
|
||||
`/api/chat/delete-chat-session/${chatSessionId}`,
|
||||
{
|
||||
@@ -348,6 +348,7 @@ export function getCitedDocumentsFromMessage(message: Message) {
|
||||
}
|
||||
|
||||
export function groupSessionsByDateRange(chatSessions: ChatSession[]) {
|
||||
console.log(chatSessions);
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0); // Set to start of today for accurate comparison
|
||||
|
||||
@@ -584,7 +585,7 @@ const PARAMS_TO_SKIP = [
|
||||
|
||||
export function buildChatUrl(
|
||||
existingSearchParams: ReadonlyURLSearchParams,
|
||||
chatSessionId: number | null,
|
||||
chatSessionId: string | null,
|
||||
personaId: number | null,
|
||||
search?: boolean
|
||||
) {
|
||||
|
@@ -6,12 +6,12 @@ import { ChatSessionSharedStatus } from "../interfaces";
|
||||
import { FiCopy } from "react-icons/fi";
|
||||
import { CopyButton } from "@/components/CopyButton";
|
||||
|
||||
function buildShareLink(chatSessionId: number) {
|
||||
function buildShareLink(chatSessionId: string) {
|
||||
const baseUrl = `${window.location.protocol}//${window.location.host}`;
|
||||
return `${baseUrl}/chat/shared/${chatSessionId}`;
|
||||
}
|
||||
|
||||
async function generateShareLink(chatSessionId: number) {
|
||||
async function generateShareLink(chatSessionId: string) {
|
||||
const response = await fetch(`/api/chat/chat-session/${chatSessionId}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
@@ -26,7 +26,7 @@ async function generateShareLink(chatSessionId: number) {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function deleteShareLink(chatSessionId: number) {
|
||||
async function deleteShareLink(chatSessionId: string) {
|
||||
const response = await fetch(`/api/chat/chat-session/${chatSessionId}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
@@ -44,7 +44,7 @@ export function ShareChatSessionModal({
|
||||
onShare,
|
||||
onClose,
|
||||
}: {
|
||||
chatSessionId: number;
|
||||
chatSessionId: string;
|
||||
existingSharedStatus: ChatSessionSharedStatus;
|
||||
onShare?: (shared: boolean) => void;
|
||||
onClose: () => void;
|
||||
|
@@ -14,7 +14,7 @@ interface LlmTabProps {
|
||||
llmOverrideManager: LlmOverrideManager;
|
||||
currentLlm: string;
|
||||
openModelSettings: () => void;
|
||||
chatSessionId?: number;
|
||||
chatSessionId?: string;
|
||||
close: () => void;
|
||||
currentAssistant: Persona;
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ export function PagesTab({
|
||||
}: {
|
||||
page: pageType;
|
||||
existingChats?: ChatSession[];
|
||||
currentChatId?: number;
|
||||
currentChatId?: string;
|
||||
folders?: Folder[];
|
||||
openedFolders?: { [key: number]: boolean };
|
||||
closeSidebar?: () => void;
|
||||
@@ -44,10 +44,7 @@ export function PagesTab({
|
||||
) => {
|
||||
event.preventDefault();
|
||||
setIsDragOver(false); // Reset drag over state on drop
|
||||
const chatSessionId = parseInt(
|
||||
event.dataTransfer.getData(CHAT_SESSION_ID_KEY),
|
||||
10
|
||||
);
|
||||
const chatSessionId = event.dataTransfer.getData(CHAT_SESSION_ID_KEY);
|
||||
const folderId = event.dataTransfer.getData(FOLDER_ID_KEY);
|
||||
|
||||
if (folderId) {
|
||||
|
@@ -48,7 +48,7 @@ export default async function Page({ params }: { params: { chatId: string } }) {
|
||||
const user = results[1] as User | null;
|
||||
const chatSession = results[2] as BackendChatSession | null;
|
||||
const assistantsResponse = results[3] as FetchAssistantsResponse | null;
|
||||
const [availableAssistants, _] = assistantsResponse ?? [[], null];
|
||||
const [availableAssistants, error] = assistantsResponse ?? [[], null];
|
||||
|
||||
const authDisabled = authTypeMetadata?.authType === "disabled";
|
||||
if (!authDisabled && !user) {
|
||||
@@ -58,7 +58,6 @@ export default async function Page({ params }: { params: { chatId: string } }) {
|
||||
if (user && !user.is_verified && authTypeMetadata?.requiresVerification) {
|
||||
return redirect("/auth/waiting-on-verification");
|
||||
}
|
||||
|
||||
const persona: Persona =
|
||||
chatSession?.persona_id && availableAssistants?.length
|
||||
? (availableAssistants.find((p) => p.id === chatSession.persona_id) ??
|
||||
@@ -72,7 +71,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} persona={persona!} />
|
||||
<SharedChatDisplay chatSession={chatSession} persona={persona} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@@ -168,13 +168,10 @@ export const SearchSection = ({
|
||||
});
|
||||
|
||||
const searchParams = useSearchParams();
|
||||
const existingSearchIdRaw = searchParams.get("searchId");
|
||||
const existingSearchessionId = existingSearchIdRaw
|
||||
? parseInt(existingSearchIdRaw)
|
||||
: null;
|
||||
const existingSearchessionId = searchParams.get("searchId");
|
||||
|
||||
useEffect(() => {
|
||||
if (existingSearchIdRaw == null) {
|
||||
if (existingSearchessionId == null) {
|
||||
return;
|
||||
}
|
||||
function extractFirstMessageByType(
|
||||
@@ -207,7 +204,7 @@ export const SearchSection = ({
|
||||
quotes: null,
|
||||
selectedDocIndices: null,
|
||||
error: null,
|
||||
messageId: existingSearchIdRaw ? parseInt(existingSearchIdRaw) : null,
|
||||
messageId: searchSession.messages[0].message_id,
|
||||
suggestedFlowType: null,
|
||||
additional_relevance: undefined,
|
||||
};
|
||||
@@ -219,7 +216,7 @@ export const SearchSection = ({
|
||||
}
|
||||
}
|
||||
initialSessionFetch();
|
||||
}, [existingSearchessionId, existingSearchIdRaw]);
|
||||
}, [existingSearchessionId]);
|
||||
|
||||
// Overrides for default behavior that only last a single query
|
||||
const [defaultOverrides, setDefaultOverrides] =
|
||||
@@ -328,7 +325,7 @@ export const SearchSection = ({
|
||||
};
|
||||
const updateMessageAndThreadId = (
|
||||
messageId: number,
|
||||
chat_session_id: number
|
||||
chat_session_id: string
|
||||
) => {
|
||||
setSearchResponse((prevState) => ({
|
||||
...(prevState || initialSearchResponse),
|
||||
|
@@ -136,8 +136,10 @@ export async function fetchChatData(searchParams: {
|
||||
);
|
||||
}
|
||||
|
||||
// Larger ID -> created later
|
||||
chatSessions.sort((a, b) => (a.id > b.id ? -1 : 1));
|
||||
chatSessions.sort(
|
||||
(a, b) =>
|
||||
new Date(b.time_created).getTime() - new Date(a.time_created).getTime()
|
||||
);
|
||||
|
||||
let documentSets: DocumentSet[] = [];
|
||||
if (documentSetsResponse?.ok) {
|
||||
|
@@ -152,7 +152,7 @@ export interface SearchRequestArgs {
|
||||
updateError: (error: string) => void;
|
||||
updateMessageAndThreadId: (
|
||||
messageId: number,
|
||||
chat_session_id: number
|
||||
chat_session_id: string
|
||||
) => void;
|
||||
finishedSearching: () => void;
|
||||
updateComments: (comments: any) => void;
|
||||
|
Reference in New Issue
Block a user