Skip to content

Commit

Permalink
Revert "Convert conversationId int to string before making api reques…
Browse files Browse the repository at this point in the history
…t to bulk update file filters"

This reverts commit c9665fb.

Revert "Fix handling for new conversation in agents page"

This reverts commit 3466f04.

Revert "Add a unique_id field for identifiying conversations (#914)"

This reverts commit ece2ec2.
  • Loading branch information
sabaimran committed Sep 19, 2024
1 parent bb2bd77 commit 0a56824
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 178 deletions.
12 changes: 7 additions & 5 deletions src/interface/web/app/agents/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ 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 @@ -56,10 +55,13 @@ async function openChat(slug: string, userData: UserProfile | null) {
return;
}

try {
const response = await createNewConversation(slug);
window.location.href = `/chat?v=${response.conversationUniqueId}`;
} catch (error) {
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 {
alert("Failed to start chat session");
}
}
Expand Down
38 changes: 2 additions & 36 deletions src/interface/web/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ interface ChatBodyDataProps {

function ChatBodyData(props: ChatBodyDataProps) {
const searchParams = useSearchParams();
const conversationUniqueId = searchParams.get("v");
const [conversationId, setConversationId] = useState<string | null>("");
const conversationId = searchParams.get("conversationId");
const [message, setMessage] = useState("");
const [image, setImage] = useState<string | null>(null);
const [processingMessage, setProcessingMessage] = useState(false);
Expand Down Expand Up @@ -61,11 +60,6 @@ function ChatBodyData(props: ChatBodyDataProps) {
setProcessingMessage(true);
setQueryToProcess(storedMessage);
}

const conversationId = localStorage.getItem("conversationId");
if (conversationId) {
setConversationId(conversationId);
}
}, [setQueryToProcess]);

useEffect(() => {
Expand All @@ -75,30 +69,6 @@ function ChatBodyData(props: ChatBodyDataProps) {
}
}, [message, setQueryToProcess]);

useEffect(() => {
if (!conversationUniqueId) {
return;
}

fetch(
`/api/chat/metadata?conversation_unique_id=${encodeURIComponent(conversationUniqueId)}`,
)
.then((response) => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json();
})
.then((data) => {
setConversationId(data.conversationId);
})
.catch((err) => {
console.error(err);
setConversationId(null);
return;
});
});

useEffect(() => {
if (conversationId) {
onConversationIdChange?.(conversationId);
Expand All @@ -117,15 +87,11 @@ function ChatBodyData(props: ChatBodyDataProps) {
}
}, [props.streamedMessages]);

if (!conversationUniqueId || conversationId === null) {
if (!conversationId) {
window.location.href = "/";
return;
}

if (!conversationId) {
return <Loading />;
}

return (
<>
<div className={false ? styles.chatBody : styles.chatBodyFull}>
Expand Down
19 changes: 5 additions & 14 deletions src/interface/web/app/common/chatFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function modifyFileFilterForConversation(
const method = mode === "add" ? "POST" : "DELETE";

const body = {
conversation_id: String(conversationId),
conversation_id: conversationId,
filenames: filenames,
};
const addUrl = `/api/chat/conversation/file-filters/bulk`;
Expand All @@ -177,6 +177,7 @@ export function modifyFileFilterForConversation(
})
.then((response) => response.json())
.then((data) => {
console.log("ADDEDFILES DATA: ", data);
setAddedFiles(data);
})
.catch((err) => {
Expand All @@ -185,11 +186,6 @@ 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}`, {
Expand All @@ -198,14 +194,9 @@ 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 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: conversationId,
conversationUniqueId: uniqueId,
} as NewConversationMetadata;
const conversationID = data.conversation_id;
if (!conversationID) throw new Error("Conversation ID not found in response");
return conversationID;
} catch (error) {
console.error("Error creating new conversation:", error);
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ interface ChatHistory {
compressed: boolean;
created: string;
updated: string;
unique_id: string;
showSidePanel: (isEnabled: boolean) => void;
selectedConversationId: string | null;
}

import {
Expand Down Expand Up @@ -400,7 +398,6 @@ interface SessionsAndFilesProps {
conversationId: string | null;
uploadedFiles: string[];
isMobileWidth: boolean;
selectedConversationId: string | null;
}

function SessionsAndFiles(props: SessionsAndFilesProps) {
Expand Down Expand Up @@ -438,10 +435,6 @@ function SessionsAndFiles(props: SessionsAndFilesProps) {
agent_avatar={chatHistory.agent_avatar}
agent_name={chatHistory.agent_name}
showSidePanel={props.setEnabled}
unique_id={chatHistory.unique_id}
selectedConversationId={
props.selectedConversationId
}
/>
),
)}
Expand All @@ -453,7 +446,6 @@ function SessionsAndFiles(props: SessionsAndFilesProps) {
<ChatSessionsModal
data={props.organizedData}
showSidePanel={props.setEnabled}
selectedConversationId={props.selectedConversationId}
/>
)}
</div>
Expand Down Expand Up @@ -648,18 +640,20 @@ function ChatSessionActionMenu(props: ChatSessionActionMenuProps) {
function ChatSession(props: ChatHistory) {
const [isHovered, setIsHovered] = useState(false);
const [title, setTitle] = useState(props.slug || "New Conversation 🌱");
var currConversationId =
props.conversation_id &&
props.selectedConversationId &&
parseInt(props.conversation_id) === parseInt(props.selectedConversationId);
var currConversationId = parseInt(
new URLSearchParams(window.location.search).get("conversationId") || "-1",
);
return (
<div
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
key={props.conversation_id}
className={`${styles.session} ${props.compressed ? styles.compressed : "!max-w-full"} ${isHovered ? `${styles.sessionHover}` : ""} ${currConversationId ? "dark:bg-neutral-800 bg-white" : ""}`}
className={`${styles.session} ${props.compressed ? styles.compressed : "!max-w-full"} ${isHovered ? `${styles.sessionHover}` : ""} ${currConversationId === parseInt(props.conversation_id) && currConversationId != -1 ? "dark:bg-neutral-800 bg-white" : ""}`}
>
<Link href={`/chat?v=${props.unique_id}`} onClick={() => props.showSidePanel(false)}>
<Link
href={`/chat?conversationId=${props.conversation_id}`}
onClick={() => props.showSidePanel(false)}
>
<p className={styles.session}>{title}</p>
</Link>
<ChatSessionActionMenu conversationId={props.conversation_id} setTitle={setTitle} />
Expand All @@ -670,14 +664,9 @@ function ChatSession(props: ChatHistory) {
interface ChatSessionsModalProps {
data: GroupedChatHistory | null;
showSidePanel: (isEnabled: boolean) => void;
selectedConversationId: string | null;
}

function ChatSessionsModal({
data,
showSidePanel,
selectedConversationId,
}: ChatSessionsModalProps) {
function ChatSessionsModal({ data, showSidePanel }: ChatSessionsModalProps) {
return (
<Dialog>
<DialogTrigger className="flex text-left text-medium text-gray-500 hover:text-gray-300 cursor-pointer my-4 text-sm p-[0.5rem]">
Expand Down Expand Up @@ -709,8 +698,6 @@ function ChatSessionsModal({
agent_avatar={chatHistory.agent_avatar}
agent_name={chatHistory.agent_name}
showSidePanel={showSidePanel}
unique_id={chatHistory.unique_id}
selectedConversationId={selectedConversationId}
/>
))}
</div>
Expand Down Expand Up @@ -832,7 +819,6 @@ export default function SidePanel(props: SidePanelProps) {
userProfile={authenticatedData}
conversationId={props.conversationId}
isMobileWidth={props.isMobileWidth}
selectedConversationId={props.conversationId}
/>
</div>
) : (
Expand Down Expand Up @@ -901,7 +887,6 @@ export default function SidePanel(props: SidePanelProps) {
userProfile={authenticatedData}
conversationId={props.conversationId}
isMobileWidth={props.isMobileWidth}
selectedConversationId={props.conversationId}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export const suggestionsData: Suggestion[] = [
link: "",
},
{
type: SuggestionType.Interviewing,
type: SuggestionType.Code,
color: suggestionToColorMap[SuggestionType.Interviewing] || DEFAULT_COLOR,
description: "Provide tips for writing an effective resume.",
link: "",
Expand Down
9 changes: 3 additions & 6 deletions src/interface/web/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,10 @@ function ChatBodyData(props: ChatBodyDataProps) {
if (message && !processingMessage) {
setProcessingMessage(true);
try {
const newConversationMetadata = await createNewConversation(
selectedAgent || "khoj",
);
onConversationIdChange?.(newConversationMetadata.conversationId);
window.location.href = `/chat?v=${newConversationMetadata.conversationUniqueId}`;
const newConversationId = await createNewConversation(selectedAgent || "khoj");
onConversationIdChange?.(newConversationId);
window.location.href = `/chat?conversationId=${newConversationId}`;
localStorage.setItem("message", message);
localStorage.setItem("conversationId", newConversationMetadata.conversationId);
if (image) {
localStorage.setItem("image", image);
}
Expand Down
4 changes: 0 additions & 4 deletions src/khoj/database/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,6 @@ def get_conversation_by_user(

return conversation

@staticmethod
def get_conversation_by_unique_id(user: KhojUser, unique_id: str):
return Conversation.objects.filter(unique_id=unique_id, user=user).first()

@staticmethod
def get_conversation_sessions(user: KhojUser, client_application: ClientApplication = None):
return (
Expand Down

This file was deleted.

20 changes: 0 additions & 20 deletions src/khoj/database/migrations/0064_populate_unique_id.py

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/khoj/database/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ class Conversation(BaseModel):
title = models.CharField(max_length=200, default=None, null=True, blank=True)
agent = models.ForeignKey(Agent, on_delete=models.SET_NULL, default=None, null=True, blank=True)
file_filters = models.JSONField(default=list)
unique_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)


class PublicConversation(BaseModel):
Expand Down
Loading

0 comments on commit 0a56824

Please sign in to comment.