-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from openchatai/staging
Staging
- Loading branch information
Showing
58 changed files
with
1,919 additions
and
328 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 28 additions & 15 deletions
43
dashboard/app/(copilot)/copilot/[copilot_id]/CopilotWidget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
import { Button } from '@/components/ui/button'; | ||
import { | ||
CopilotWidget, | ||
Root | ||
} from '@openchatai/copilot-widget'; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
export default function Widget({ | ||
token | ||
}: { | ||
token: string | ||
}) { | ||
return <Root | ||
options={{ | ||
apiUrl: "http://localhost:8888/backend/api", | ||
token, | ||
initialMessage: "Hey Pal!", | ||
headers: { | ||
"X-Copilot": "copilot" | ||
}, | ||
}} | ||
> | ||
<div className="[&>div]:static [&>div]:!max-h-full [&>div]:!h-full h-full overflow-hidden border-border border rounded-lg"> | ||
<CopilotWidget | ||
triggerSelector="#triggerSelector" | ||
/> | ||
return <ErrorBoundary FallbackComponent={({ resetErrorBoundary }) => { | ||
return <div className="flex flex-col items-center justify-center h-full"> | ||
<div className="flex flex-col gap-3 items-center justify-center"> | ||
<h1 className="text-2xl font-semibold text-gray-700">Something went wrong</h1> | ||
<Button onClick={() => resetErrorBoundary()} variant='destructive'>Try again</Button> | ||
</div> | ||
</div> | ||
</Root> | ||
}}> | ||
|
||
<Root | ||
options={{ | ||
apiUrl: "http://localhost:8888/backend/api", | ||
defaultOpen: true, | ||
token, | ||
initialMessage: "Hey Pal!", | ||
headers: { | ||
"X-Copilot": "copilot" | ||
}, | ||
}} | ||
> | ||
<div className="[&>div]:static [&>div]:!max-h-full [&>div]:!h-full h-full overflow-hidden [&>div]:!border-border [&>div]:!border rounded-lg"> | ||
<CopilotWidget | ||
triggerSelector="#triggerSelector" | ||
/> | ||
</div> | ||
</Root> | ||
</ErrorBoundary> | ||
} |
76 changes: 76 additions & 0 deletions
76
dashboard/app/(copilot)/copilot/[copilot_id]/conversations/_parts/ChatScreen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use client'; | ||
import { Avatar, AvatarFallback } from "@/components/ui/avatar"; | ||
import { useAtomValue } from "jotai"; | ||
import { activeSessionId } from "./atoms"; | ||
import useSWR from "swr"; | ||
import { ChatMessageType, getConversationBySessionId } from "@/data/conversations"; | ||
import Loader from "@/components/ui/Loader"; | ||
import { format } from 'timeago.js'; | ||
import { EmptyBlock } from "@/components/domain/EmptyBlock"; | ||
|
||
function UserMessage({ message, created_at }: ChatMessageType) { | ||
return ( | ||
<div className="flex w-full flex-row items-center justify-end gap-2"> | ||
<div className="flex flex-col items-end"> | ||
<p className="w-fit max-w-sm rounded-lg bg-primary px-4 py-3 text-sm select-none text-white"> | ||
{message} | ||
</p> | ||
<span className="text-xs"> | ||
{format(created_at)} | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
function CopilotMessage({ message, created_at }: ChatMessageType) { | ||
return ( | ||
<div className="flex w-full flex-row items-start justify-start gap-2 relative"> | ||
<Avatar size="large" className="sticky top-0"> | ||
<AvatarFallback>C</AvatarFallback> | ||
</Avatar> | ||
<div className="flex items-start flex-col gap-1.5"> | ||
<p className="w-fit max-w-sm rounded-lg bg-secondary px-4 py-3 text-sm text-accent-foreground select-none"> | ||
{message} | ||
</p> | ||
<span className="text-xs">{format(created_at)}</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
function ChatDivider({ content }: { content: string }) { | ||
return ( | ||
<div className="relative my-4 block h-px w-full bg-secondary"> | ||
<span className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-white px-4 text-xs"> | ||
{content} | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
export function ChatScreen() { | ||
const activeid = useAtomValue(activeSessionId); | ||
const { | ||
data: chat, | ||
isLoading | ||
} = useSWR(activeid, getConversationBySessionId) | ||
return ( | ||
<div className="flex-1 space-y-3 overflow-auto p-4 font-medium"> | ||
{ | ||
isLoading && <Loader className="h-full flex-center" /> | ||
} | ||
{ | ||
chat ? chat?.data.map((c, i) => { | ||
if (c.from_user) { | ||
return <UserMessage key={i} {...c} /> | ||
} else if (!c.from_user) { | ||
return <CopilotMessage key={i} {...c} /> | ||
} | ||
}) : <EmptyBlock> | ||
<p className="text-center text-sm"> | ||
Select a conversation to start chatting | ||
</p> | ||
</EmptyBlock> | ||
} | ||
</div> | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
dashboard/app/(copilot)/copilot/[copilot_id]/conversations/_parts/ConversationAside.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use client"; | ||
import { Avatar, AvatarFallback } from "@/components/ui/avatar"; | ||
import { useAtomValue } from "jotai"; | ||
import { Bookmark, CheckCircle, Trash2 } from "lucide-react"; | ||
import { activeSessionId } from "./atoms"; | ||
|
||
export function ConversationAside() { | ||
const activeid = useAtomValue(activeSessionId); | ||
|
||
return ( | ||
activeid && | ||
<aside className="animate-in slide-in-from-right fade-in h-full w-full max-w-xs border-l border-border xl:inline"> | ||
<section className="border-y border-border"> | ||
<div className="px-4 py-8 text-center"> | ||
<div className="flex-center -space-x-2"> | ||
<Avatar size="large"> | ||
<AvatarFallback className="bg-accent-foreground text-white select-none"> | ||
U | ||
</AvatarFallback> | ||
</Avatar> | ||
<Avatar size="large"> | ||
<AvatarFallback className="bg-accent select-none">CO</AvatarFallback> | ||
</Avatar> | ||
</div> | ||
<h2 className="mt-2 text-sm font-semibold"> | ||
Conversation between your assistant and Unknown User | ||
</h2> | ||
</div> | ||
</section> | ||
<section className="border-y border-border bg-white"> | ||
<div className="p-4"> | ||
<span className="text-xs font-semibold uppercase text-secondary-foreground"> | ||
actions | ||
</span> | ||
<div className="mt-2 w-full space-y-2 text-accent-foreground/80 "> | ||
<button className="flex w-full items-center justify-between px-1 py-2 text-sm"> | ||
<span className="text-xs font-semibold">Mark as Reviewed</span> | ||
<CheckCircle className="h-4 w-4" /> | ||
</button> | ||
<button className="flex w-full items-center justify-between px-1 py-2 text-sm"> | ||
<span className="text-xs font-semibold">Save for Later</span> | ||
<Bookmark className="h-4 w-4" /> | ||
</button> | ||
<button className="flex w-full items-center justify-between px-1 py-2 text-sm text-destructive"> | ||
<span className="text-xs font-semibold">Delete</span> | ||
<Trash2 className="h-4 w-4" /> | ||
</button> | ||
</div> | ||
</div> | ||
</section> | ||
</aside> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
dashboard/app/(copilot)/copilot/[copilot_id]/conversations/_parts/ConversationHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
import { HeaderShell } from "@/components/domain/HeaderShell"; | ||
|
||
export function ConversationHeader() { | ||
return ( | ||
<HeaderShell className="items-center justify-between"> | ||
<h1 className="max-w-md flex-1 text-start text-base font-semibold text-secondary-foreground"> | ||
Conversation | ||
</h1> | ||
</HeaderShell> | ||
); | ||
} |
48 changes: 48 additions & 0 deletions
48
dashboard/app/(copilot)/copilot/[copilot_id]/conversations/_parts/ListConverations.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use client"; | ||
import { useAtom } from "jotai"; | ||
import { activeSessionId } from "./atoms"; | ||
import { cn } from "@/lib/utils"; | ||
import useSWR from "swr"; | ||
import { useCopilot } from "../../../_context/CopilotProvider"; | ||
import { ConversationType, getSessionsByBotId } from "@/data/conversations"; | ||
import { format } from 'timeago.js'; | ||
function Conversation(props: ConversationType) { | ||
const [activeid, setActiveId] = useAtom(activeSessionId); | ||
const isActive = activeid === props.session_id; | ||
return ( | ||
<li | ||
onClick={() => setActiveId(props.session_id)} | ||
role="button" | ||
className={cn( | ||
"w-full border border-l-[3px] p-4 transition-colors last-of-type:mb-2", | ||
isActive | ||
? "sticky bottom-0 left-0 top-0 !border-l-primary bg-accent" | ||
: "border-x-transparent bg-white border-border", | ||
)} | ||
> | ||
<div | ||
className="h-full w-full text-start"> | ||
<p className="line-clamp-1 text-base">{props.first_message.message}</p> | ||
<p className="text-[10px]">{format(props.first_message.created_at)}</p> | ||
</div> | ||
</li> | ||
); | ||
} | ||
|
||
export function ListConversations() { | ||
const { | ||
id: copilotId, | ||
} = useCopilot(); | ||
const { | ||
data: conversations | ||
} = useSWR(copilotId + "/conversations", async () => (await getSessionsByBotId(copilotId))?.data) | ||
return ( | ||
<div className="w-full flex-1 overflow-hidden"> | ||
<ul className="h-full overflow-auto"> | ||
{conversations?.map((c, i) => ( | ||
<Conversation {...c} key={i} /> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
dashboard/app/(copilot)/copilot/[copilot_id]/conversations/_parts/atoms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { atom } from "jotai"; | ||
|
||
export const activeSessionId = atom<string | null>(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
dashboard/app/(copilot)/copilot/[copilot_id]/conversations/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.