2025-07-23 18:25:15 +00:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { ResizablePanel } from "@/components/ui/resizable";
|
|
|
|
|
import { ChatBox } from "@/features/chat/components/chatBox";
|
|
|
|
|
import { ChatBoxToolbar } from "@/features/chat/components/chatBox/chatBoxToolbar";
|
|
|
|
|
import { CustomSlateEditor } from "@/features/chat/customSlateEditor";
|
|
|
|
|
import { useCreateNewChatThread } from "@/features/chat/useCreateNewChatThread";
|
2025-07-29 01:12:21 +00:00
|
|
|
import { LanguageModelInfo, SearchScope } from "@/features/chat/types";
|
2025-07-26 23:16:07 +00:00
|
|
|
import { RepositoryQuery, SearchContextQuery } from "@/lib/types";
|
2025-07-23 18:25:15 +00:00
|
|
|
import { useCallback, useState } from "react";
|
|
|
|
|
import { Descendant } from "slate";
|
|
|
|
|
import { useLocalStorage } from "usehooks-ts";
|
|
|
|
|
|
|
|
|
|
interface NewChatPanelProps {
|
|
|
|
|
languageModels: LanguageModelInfo[];
|
|
|
|
|
repos: RepositoryQuery[];
|
2025-07-26 23:16:07 +00:00
|
|
|
searchContexts: SearchContextQuery[];
|
2025-07-23 18:25:15 +00:00
|
|
|
order: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const NewChatPanel = ({
|
|
|
|
|
languageModels,
|
|
|
|
|
repos,
|
2025-07-26 23:16:07 +00:00
|
|
|
searchContexts,
|
2025-07-23 18:25:15 +00:00
|
|
|
order,
|
|
|
|
|
}: NewChatPanelProps) => {
|
2025-07-29 01:12:21 +00:00
|
|
|
const [selectedSearchScopes, setSelectedSearchScopes] = useLocalStorage<SearchScope[]>("selectedSearchScopes", [], { initializeWithValue: false });
|
2025-07-23 18:25:15 +00:00
|
|
|
const { createNewChatThread, isLoading } = useCreateNewChatThread();
|
2025-07-26 23:16:07 +00:00
|
|
|
const [isContextSelectorOpen, setIsContextSelectorOpen] = useState(false);
|
2025-07-23 18:25:15 +00:00
|
|
|
|
|
|
|
|
const onSubmit = useCallback((children: Descendant[]) => {
|
2025-07-29 01:12:21 +00:00
|
|
|
createNewChatThread(children, selectedSearchScopes);
|
|
|
|
|
}, [createNewChatThread, selectedSearchScopes]);
|
2025-07-23 18:25:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ResizablePanel
|
|
|
|
|
order={order}
|
|
|
|
|
id="new-chat-panel"
|
|
|
|
|
defaultSize={85}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex flex-col h-full w-full items-center justify-start pt-[20vh]">
|
|
|
|
|
<h2 className="text-4xl font-bold mb-8">What can I help you understand?</h2>
|
|
|
|
|
<div className="border rounded-md w-full max-w-3xl mx-auto mb-8 shadow-sm">
|
|
|
|
|
<CustomSlateEditor>
|
|
|
|
|
<ChatBox
|
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
|
className="min-h-[80px]"
|
|
|
|
|
preferredSuggestionsBoxPlacement="bottom-start"
|
|
|
|
|
isRedirecting={isLoading}
|
|
|
|
|
languageModels={languageModels}
|
2025-07-29 01:12:21 +00:00
|
|
|
selectedSearchScopes={selectedSearchScopes}
|
2025-07-26 23:16:07 +00:00
|
|
|
searchContexts={searchContexts}
|
2025-07-23 18:25:15 +00:00
|
|
|
/>
|
|
|
|
|
<div className="w-full flex flex-row items-center bg-accent rounded-b-md px-2">
|
|
|
|
|
<ChatBoxToolbar
|
|
|
|
|
languageModels={languageModels}
|
|
|
|
|
repos={repos}
|
2025-07-26 23:16:07 +00:00
|
|
|
searchContexts={searchContexts}
|
2025-07-29 01:12:21 +00:00
|
|
|
selectedSearchScopes={selectedSearchScopes}
|
|
|
|
|
onSelectedSearchScopesChange={setSelectedSearchScopes}
|
2025-07-26 23:16:07 +00:00
|
|
|
isContextSelectorOpen={isContextSelectorOpen}
|
|
|
|
|
onContextSelectorOpenChanged={setIsContextSelectorOpen}
|
2025-07-23 18:25:15 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</CustomSlateEditor>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</ResizablePanel>
|
|
|
|
|
)
|
|
|
|
|
}
|