aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/(dash)/chat
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/app/(dash)/chat')
-rw-r--r--apps/web/app/(dash)/chat/[chatid]/loading.tsx10
-rw-r--r--apps/web/app/(dash)/chat/[chatid]/page.tsx4
-rw-r--r--apps/web/app/(dash)/chat/chatWindow.tsx48
-rw-r--r--apps/web/app/(dash)/chat/route.ts5
4 files changed, 61 insertions, 6 deletions
diff --git a/apps/web/app/(dash)/chat/[chatid]/loading.tsx b/apps/web/app/(dash)/chat/[chatid]/loading.tsx
index d28961a6..422adb8e 100644
--- a/apps/web/app/(dash)/chat/[chatid]/loading.tsx
+++ b/apps/web/app/(dash)/chat/[chatid]/loading.tsx
@@ -7,9 +7,15 @@ async function Page({
}: {
searchParams: Record<string, string | string[] | undefined>;
}) {
- const q = (searchParams?.q as string) ?? "from_loading";
+ const q = (searchParams?.q as string) ?? "";
return (
- <ChatWindow q={q} spaces={[]} initialChat={undefined} threadId={"idk"} />
+ <ChatWindow
+ proMode={false}
+ q={q}
+ spaces={[]}
+ initialChat={undefined}
+ threadId={"idk"}
+ />
);
}
diff --git a/apps/web/app/(dash)/chat/[chatid]/page.tsx b/apps/web/app/(dash)/chat/[chatid]/page.tsx
index 87fd0b19..29ffb3d8 100644
--- a/apps/web/app/(dash)/chat/[chatid]/page.tsx
+++ b/apps/web/app/(dash)/chat/[chatid]/page.tsx
@@ -9,7 +9,8 @@ async function Page({
params: { chatid: string };
searchParams: Record<string, string | string[] | undefined>;
}) {
- const { firstTime, q, spaces } = chatSearchParamsCache.parse(searchParams);
+ const { firstTime, q, spaces, proMode } =
+ chatSearchParamsCache.parse(searchParams);
let chat: Awaited<ReturnType<typeof getFullChatThread>>;
@@ -31,6 +32,7 @@ async function Page({
spaces={spaces ?? []}
initialChat={chat.data.length > 0 ? chat.data : undefined}
threadId={params.chatid}
+ proMode={proMode}
/>
);
}
diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx
index 28b99c9d..ed65bf7a 100644
--- a/apps/web/app/(dash)/chat/chatWindow.tsx
+++ b/apps/web/app/(dash)/chat/chatWindow.tsx
@@ -35,14 +35,19 @@ function ChatWindow({
parts: [],
sources: [],
},
+ proModeProcessing: {
+ queries: [],
+ },
},
],
threadId,
+ proMode,
}: {
q: string;
spaces: { id: number; name: string }[];
initialChat?: ChatHistory[];
threadId: string;
+ proMode: boolean;
}) {
const [layout, setLayout] = useState<"chat" | "initial">("chat");
const [chatHistory, setChatHistory] = useState<ChatHistory[]>(initialChat);
@@ -63,13 +68,17 @@ function ChatWindow({
const router = useRouter();
- const getAnswer = async (query: string, spaces: string[]) => {
+ const getAnswer = async (
+ query: string,
+ spaces: string[],
+ proMode: boolean = false,
+ ) => {
if (query.trim() === "from_loading" || query.trim().length === 0) {
return;
}
const sourcesFetch = await fetch(
- `/api/chat?q=${query}&spaces=${spaces}&sourcesOnly=true&threadId=${threadId}`,
+ `/api/chat?q=${query}&spaces=${spaces}&sourcesOnly=true&threadId=${threadId}&proMode=${proMode}`,
{
method: "POST",
body: JSON.stringify({ chatHistory }),
@@ -91,6 +100,8 @@ function ChatWindow({
behavior: "smooth",
});
+ let proModeListedQueries: string[] = [];
+
const updateChatHistoryAndFetch = async () => {
// Step 1: Update chat history with the assistant's response
await new Promise((resolve) => {
@@ -123,6 +134,11 @@ function ChatWindow({
).length,
}));
+ lastAnswer.proModeProcessing.queries =
+ sourcesParsed.data.proModeListedQueries ?? [];
+
+ proModeListedQueries = lastAnswer.proModeProcessing.queries;
+
resolve(newChatHistory);
return newChatHistory;
});
@@ -130,7 +146,7 @@ function ChatWindow({
// Step 2: Fetch data from the API
const resp = await fetch(
- `/api/chat?q=${query}&spaces=${spaces}&threadId=${threadId}`,
+ `/api/chat?q=${(query += proModeListedQueries.join(" "))}&spaces=${spaces}&threadId=${threadId}`,
{
method: "POST",
body: JSON.stringify({ chatHistory, sources: sourcesParsed.data }),
@@ -181,6 +197,7 @@ function ChatWindow({
getAnswer(
q,
spaces.map((s) => `${s.id}`),
+ proMode,
);
}
} else {
@@ -224,6 +241,28 @@ function ChatWindow({
{chat.question}
</h2>
+ {chat.proModeProcessing?.queries?.length > 0 && (
+ <div className="flex flex-col mt-2">
+ <div className="text-foreground-menu py-2">
+ Pro Mode
+ </div>
+ <div className="text-base">
+ <div className="flex gap-2 text-base">
+ {chat.proModeProcessing.queries.map(
+ (query, idx) => (
+ <div
+ className="bg-secondary rounded-md p-2"
+ key={`promode-query-${idx}`}
+ >
+ {query}
+ </div>
+ ),
+ )}
+ </div>
+ </div>
+ </div>
+ )}
+
<div className="flex flex-col mt-2">
<div>
<div className="text-foreground-menu py-2">Answer</div>
@@ -407,6 +446,9 @@ function ChatWindow({
parts: [],
sources: [],
},
+ proModeProcessing: {
+ queries: [],
+ },
},
];
});
diff --git a/apps/web/app/(dash)/chat/route.ts b/apps/web/app/(dash)/chat/route.ts
new file mode 100644
index 00000000..94f250ff
--- /dev/null
+++ b/apps/web/app/(dash)/chat/route.ts
@@ -0,0 +1,5 @@
+import { redirect } from "next/navigation";
+
+export async function GET() {
+ return redirect("/home");
+}