+
- {logoUrl ? : null}
-
+ {logoUrl ? (
+
+ ) : null}
+
+
+
-
-
{name}
- {description ?
{description}
: null}
+
+
{name}
+ {description ? (
+
{description}
+ ) : null}
);
-}
\ No newline at end of file
+};
diff --git a/components/modules/apps/app-side-bar/AppSideBarList.tsx b/components/modules/apps/app-side-bar/AppSideBarList.tsx
index 20f83e2..6c0c540 100644
--- a/components/modules/apps/app-side-bar/AppSideBarList.tsx
+++ b/components/modules/apps/app-side-bar/AppSideBarList.tsx
@@ -1,25 +1,30 @@
import { App } from "@/lib/db";
+
import { AppSideBarItem } from "./AppSideBarItem";
type AppSideBarListProps = {
apps: App[] | null;
-}
+};
export const AppSideBarList = ({ apps }: AppSideBarListProps) => {
if (!apps?.length) {
- return (
-
No apps found
- )
+ return
No apps found
;
}
return (
{apps.map((app) => {
- const { id, name, description, slug, logoUrl } = app
+ const { id, name, description, slug, logoUrl } = app;
return (
-
- )
+
+ );
})}
- )
-}
\ No newline at end of file
+ );
+};
diff --git a/components/modules/apps/app-side-bar/AppSidebarSection.tsx b/components/modules/apps/app-side-bar/AppSidebarSection.tsx
index 8c381b7..88d9dd1 100644
--- a/components/modules/apps/app-side-bar/AppSidebarSection.tsx
+++ b/components/modules/apps/app-side-bar/AppSidebarSection.tsx
@@ -1,16 +1,20 @@
-import { Heading5 } from '@/components/ui/typography';
-import React from 'react';
+import React from "react";
+
+import { Heading5 } from "@/components/ui/typography";
type AppSidebarSectionProps = {
- title: string;
- children: React.ReactNode;
-}
+ title: string;
+ children: React.ReactNode;
+};
-export const AppSidebarSection = ({ title, children }: AppSidebarSectionProps) => {
- return(
+export const AppSidebarSection = ({
+ title,
+ children,
+}: AppSidebarSectionProps) => {
+ return (
- {title}
+ {title}
{children}
);
-}
\ No newline at end of file
+};
diff --git a/components/modules/apps/app-side-bar/index.ts b/components/modules/apps/app-side-bar/index.ts
index 15cdf4e..d1bd14f 100644
--- a/components/modules/apps/app-side-bar/index.ts
+++ b/components/modules/apps/app-side-bar/index.ts
@@ -1 +1 @@
-export * from './AppSideBar'
\ No newline at end of file
+export * from "./AppSideBar";
diff --git a/components/modules/apps/chat/ChatHistory.tsx b/components/modules/apps/chat/ChatHistory.tsx
index 94ba79c..7ee9adc 100644
--- a/components/modules/apps/chat/ChatHistory.tsx
+++ b/components/modules/apps/chat/ChatHistory.tsx
@@ -1,36 +1,49 @@
-'use client'
+"use client";
-import { Chat } from "@/lib/db"
-import { usePathname } from "next/navigation"
-import { NewChatButton } from "./NewChatButton"
-import React from "react"
-import { ChatHistoryItem } from "./ChatHistoryItem"
-import { Separator } from "@/components/ui/Separator"
+import React from "react";
+import { usePathname } from "next/navigation";
+
+import { Chat } from "@/lib/db";
+import { Separator } from "@/components/ui/Separator";
+
+import { ChatHistoryItem } from "./ChatHistoryItem";
+import { NewChatButton } from "./NewChatButton";
type ChatHistoryProps = {
- data: Chat[] | null
- closeDrawer?: () => void
-}
+ data: Chat[] | null;
+ closeDrawer?: () => void;
+};
export const ChatHistory = ({ data, closeDrawer }: ChatHistoryProps) => {
- const pathname = usePathname()
- const chatId = pathname.split('/').pop()
+ const pathname = usePathname();
+ const chatId = pathname.split("/").pop();
return (
- )
-}
+ );
+};
diff --git a/components/modules/apps/chat/ChatHistoryDrawer.tsx b/components/modules/apps/chat/ChatHistoryDrawer.tsx
index 42721bb..76e6b72 100644
--- a/components/modules/apps/chat/ChatHistoryDrawer.tsx
+++ b/components/modules/apps/chat/ChatHistoryDrawer.tsx
@@ -1,42 +1,48 @@
-'use client'
+"use client";
-import { Button } from '@/components/ui/Button';
-import { Chat } from '@/lib/db';
-import { cn } from '@/lib/utils';
-import { History } from 'lucide-react';
-import React from 'react';
-import { Drawer } from 'vaul';
-import { ChatHistory } from './ChatHistory';
+import React from "react";
+import { History } from "lucide-react";
+import { Drawer } from "vaul";
+
+import { Chat } from "@/lib/db";
+import { cn } from "@/lib/utils";
+import { Button } from "@/components/ui/Button";
+
+import { ChatHistory } from "./ChatHistory";
type ChatHistoryDrawerProps = {
- data: Chat[] | null
-}
+ data: Chat[] | null;
+};
export const ChatHistoryDrawer = ({ data }: ChatHistoryDrawerProps) => {
- const [drawerOpen, setDrawerOpen] = React.useState(false)
+ const [drawerOpen, setDrawerOpen] = React.useState(false);
const onHistoryButtonClick = () => {
- setDrawerOpen(true)
- }
+ setDrawerOpen(true);
+ };
const closeDrawer = React.useCallback(() => {
- setDrawerOpen(false)
- }, [])
+ setDrawerOpen(false);
+ }, []);
return (
-
+
-
+
);
-}
\ No newline at end of file
+};
diff --git a/components/modules/apps/chat/ChatHistoryItem.tsx b/components/modules/apps/chat/ChatHistoryItem.tsx
index cb21ff9..5f26eaa 100644
--- a/components/modules/apps/chat/ChatHistoryItem.tsx
+++ b/components/modules/apps/chat/ChatHistoryItem.tsx
@@ -1,50 +1,74 @@
-import { Chat } from '@/lib/db';
-import { cn } from '@/lib/utils';
-import { MessageCircle } from 'lucide-react';
-import Link from 'next/link';
-import React from 'react';
-import { DeleteChatAction } from './DeleteChatAction';
-import { EditChatAction } from './EditChatAction';
+import React from "react";
+import Link from "next/link";
+import { MessageCircle } from "lucide-react";
+
+import { Chat } from "@/lib/db";
+import { cn } from "@/lib/utils";
+
+import { DeleteChatAction } from "./DeleteChatAction";
+import { EditChatAction } from "./EditChatAction";
type ChatHistoryItemProps = {
- chat: Chat
- isActive: boolean
- closeDrawer?: () => void
-}
+ chat: Chat;
+ isActive: boolean;
+ closeDrawer?: () => void;
+};
-export const ChatHistoryItem = ({ chat, isActive, closeDrawer }: ChatHistoryItemProps) => {
+export const ChatHistoryItem = ({
+ chat,
+ isActive,
+ closeDrawer,
+}: ChatHistoryItemProps) => {
const renderActionButtons = () => {
return (
-
-
-
+
- )
- }
+ );
+ };
return (
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
{chat.name}
+
+ {chat.name}
+
{renderActionButtons()}
- )
-}
\ No newline at end of file
+ );
+};
diff --git a/components/modules/apps/chat/ChatPanel.tsx b/components/modules/apps/chat/ChatPanel.tsx
index 451d538..f7b9a58 100644
--- a/components/modules/apps/chat/ChatPanel.tsx
+++ b/components/modules/apps/chat/ChatPanel.tsx
@@ -1,181 +1,229 @@
-'use client'
-
-import React from 'react'
-import { Message, useChat } from 'ai/react'
-import { zodResolver } from '@hookform/resolvers/zod';
-
-import { ChatScrollAnchor } from '@/components/ui/common/ChatScrollAnchor'
-import { Button } from '@/components/ui/Button'
-import { SendHorizonal, Settings } from 'lucide-react'
-import { useEnterSubmit } from '@/hooks/useEnterSubmit'
-import { toast } from '@/components/ui/use-toast'
-import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/Sheet"
-import { ControlSidebar } from './control-side-bar'
-import { FormProvider, useForm } from 'react-hook-form';
-import { ChatInput, ChatList } from '@/components/ui/chat'
-import { ChatParams } from './types'
-import { ChatParamSchema } from './schema';
-import { defaultSystemPrompt } from './control-side-bar/data/models';
-import { Header } from './Header';
-import { Separator } from '@/components/ui/Separator';
-import { buildChatRequestParams } from './utils';
-import { Chat, Message as SupabaseMessage } from '@/lib/db';
-import { v4 as uuidv4 } from 'uuid';
-import { useRouter } from 'next/navigation';
-import { revalidateChatLayout } from './action';
-import { ChatHistoryDrawer } from './ChatHistoryDrawer';
+"use client";
+
+import React from "react";
+import { useRouter } from "next/navigation";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { Message, useChat } from "ai/react";
+import { SendHorizonal, Settings } from "lucide-react";
+import { FormProvider, useForm } from "react-hook-form";
+import { v4 as uuidv4 } from "uuid";
+
+import { Chat, Message as SupabaseMessage } from "@/lib/db";
+import { useEnterSubmit } from "@/hooks/useEnterSubmit";
+import { Button } from "@/components/ui/Button";
+import { Separator } from "@/components/ui/Separator";
+import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/Sheet";
+import { ChatInput, ChatList } from "@/components/ui/chat";
+import { ChatScrollAnchor } from "@/components/ui/common/ChatScrollAnchor";
+import { toast } from "@/components/ui/use-toast";
+
+import { ChatHistoryDrawer } from "./ChatHistoryDrawer";
+import { Header } from "./Header";
+import { revalidateChatLayout } from "./action";
+import { ControlSidebar } from "./control-side-bar";
+import { defaultSystemPrompt } from "./control-side-bar/data/models";
+import { ChatParamSchema } from "./schema";
+import { ChatParams } from "./types";
+import { buildChatRequestParams } from "./utils";
const defaultValues: ChatParams = {
description: defaultSystemPrompt,
- model: 'gpt-3.5-turbo',
+ model: "gpt-3.5-turbo",
temperature: [1],
topP: [0.5],
maxTokens: [250],
frequencyPenalty: [0],
presencePenalty: [0],
-}
+};
type ChatPanelProps = {
- chatId: Chat['id']
- initialMessages: Message[]
- chats: Chat[] | null
- chatParams?: ChatParams
- isNewChat?: boolean
-}
-
-export const ChatPanel = ({ chatId, chats, initialMessages, chatParams, isNewChat }: ChatPanelProps) => {
- const scrollAreaRef = React.useRef(null)
+ chatId: Chat["id"];
+ initialMessages: Message[];
+ chats: Chat[] | null;
+ chatParams?: ChatParams;
+ isNewChat?: boolean;
+};
+
+export const ChatPanel = ({
+ chatId,
+ chats,
+ initialMessages,
+ chatParams,
+ isNewChat,
+}: ChatPanelProps) => {
+ const scrollAreaRef = React.useRef(null);
const [sidebarSheetOpen, setSidebarSheetOpen] = React.useState(false);
- const { formRef, onKeyDown } = useEnterSubmit()
- const router = useRouter()
-
- const { messages, input, setInput, handleInputChange, isLoading, stop, reload, error, setMessages, append } = useChat({
+ const { formRef, onKeyDown } = useEnterSubmit();
+ const router = useRouter();
+
+ const {
+ messages,
+ input,
+ setInput,
+ handleInputChange,
+ isLoading,
+ stop,
+ reload,
+ error,
+ setMessages,
+ append,
+ } = useChat({
id: chatId,
- api: '/api/chat',
+ api: "/api/chat",
initialMessages,
sendExtraMessageFields: true,
onFinish: async () => {
if (isNewChat) {
- await revalidateChatLayout()
- router.replace(`/apps/chat/${chatId}`)
+ await revalidateChatLayout();
+ router.replace(`/apps/chat/${chatId}`);
}
- }
- })
+ },
+ });
const formReturn = useForm({
defaultValues: chatParams || defaultValues,
- mode: 'onChange',
+ mode: "onChange",
resolver: zodResolver(ChatParamSchema),
});
const getChatRequestParams = () => {
- const formValues = formReturn.getValues()
- return buildChatRequestParams(formValues)
- }
+ const formValues = formReturn.getValues();
+ return buildChatRequestParams(formValues);
+ };
React.useEffect(() => {
if (error) {
toast({
title: "Error",
- description: "AI Assistant is not available at the moment. Please try again later.",
+ description:
+ "AI Assistant is not available at the moment. Please try again later.",
variant: "destructive",
- })
+ });
}
- }, [error])
+ }, [error]);
React.useEffect(() => {
if (!messages.length) {
- return
+ return;
}
scrollAreaRef.current?.scrollTo({
top: scrollAreaRef.current.scrollHeight,
- })
+ });
window.scrollTo({ top: document.body.scrollHeight });
- }, [messages.length])
+ }, [messages.length]);
React.useEffect(() => {
scrollAreaRef.current?.scrollTo({
top: scrollAreaRef.current.scrollHeight,
- })
+ });
window.scrollTo({ top: document.body.scrollHeight });
- }, [])
+ }, []);
- const handleOnChange = (e: React.ChangeEvent | React.ChangeEvent) => {
- handleInputChange(e)
- }
+ const handleOnChange = (
+ e:
+ | React.ChangeEvent
+ | React.ChangeEvent
+ ) => {
+ handleInputChange(e);
+ };
- const handleReloadMessages = (id: SupabaseMessage['id']) => {
+ const handleReloadMessages = (id: SupabaseMessage["id"]) => {
reload({
options: {
body: {
...getChatRequestParams(),
chatId,
isRegenerate: true,
- regenerateMessageId: id
- }
- }
- })
- }
+ regenerateMessageId: id,
+ },
+ },
+ });
+ };
const onSubmit = (e: React.FormEvent) => {
- e.preventDefault()
+ e.preventDefault();
if (!input || isLoading) {
- return
+ return;
}
- append({
- content: input,
- role: 'user',
- id: uuidv4(),
- }, {
- options: {
- body: {
- ...getChatRequestParams(),
- chatId,
- isNewChat
- }
+ append(
+ {
+ content: input,
+ role: "user",
+ id: uuidv4(),
+ },
+ {
+ options: {
+ body: {
+ ...getChatRequestParams(),
+ chatId,
+ isNewChat,
+ },
+ },
}
- })
- setInput('')
- }
+ );
+ setInput("");
+ };
const closeSidebarSheet = () => {
- setSidebarSheetOpen(false)
- }
+ setSidebarSheetOpen(false);
+ };
const renderControlSidebar = () => {
- return
- }
-
+ return (
+
+ );
+ };
+
return (
-