Start chat with public and protected agents when shared via link

This commit is contained in:
Debanjum Singh Solanky
2024-10-08 22:07:23 -07:00
parent 80212c50fd
commit dd770cf1b9
2 changed files with 5 additions and 3 deletions

View File

@@ -137,7 +137,9 @@ async function openChat(slug: string, userData: UserProfile | null) {
return;
}
const response = await fetch(`/api/chat/sessions?agent_slug=${slug}`, { method: "POST" });
const response = await fetch(`/api/chat/sessions?agent_slug=${encodeURIComponent(slug)}`, {
method: "POST",
});
const data = await response.json();
if (response.status == 200) {
window.location.href = `/chat?conversationId=${data.conversation_id}`;

View File

@@ -826,7 +826,7 @@ class ConversationAdapters:
user: KhojUser, client_application: ClientApplication = None, agent_slug: str = None, title: str = None
):
if agent_slug:
agent = await AgentAdapters.aget_agent_by_slug(agent_slug, user)
agent = await AgentAdapters.aget_readonly_agent_by_slug(agent_slug, user)
if agent is None:
raise HTTPException(status_code=400, detail="No such agent currently exists.")
return await Conversation.objects.acreate(user=user, client=client_application, agent=agent, title=title)
@@ -838,7 +838,7 @@ class ConversationAdapters:
user: KhojUser, client_application: ClientApplication = None, agent_slug: str = None, title: str = None
):
if agent_slug:
agent = AgentAdapters.get_agent_by_slug(agent_slug, user)
agent = AgentAdapters.aget_readonly_agent_by_slug(agent_slug, user)
if agent is None:
raise HTTPException(status_code=400, detail="No such agent currently exists.")
return Conversation.objects.create(user=user, client=client_application, agent=agent, title=title)