Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: improve chat experience

Marc Seitz398e244171d3
diff --git a/components/chat/chat-input.tsx b/components/chat/chat-input.tsx
index d48f3336..05ffb4d1 100644
--- a/components/chat/chat-input.tsx
+++ b/components/chat/chat-input.tsx
@@ -5,6 +5,7 @@ import Textarea from "react-textarea-autosize";
import { useEffect, useRef } from "react";
import { cn } from "@/lib/utils";
import { useEnterSubmit } from "@/lib/utils/use-enter-submit";
+import ArrowUp from "../shared/icons/arrow-up";
export function ChatInput({
status,
@@ -34,7 +35,7 @@ export function ChatInput({
<div className="mx-auto sm:max-w-3xl sm:px-4">
<div className="space-y-4 bg-background px-4 py-4 shadow-lg md:py-4">
<form onSubmit={submitMessage} ref={formRef}>
- <div className="relative flex max-h-60 w-full flex-col overflow-hidden bg-background pr-8 rounded-md sm:border sm:pr-12 focus-within:ring-1 focus-within:ring-foreground">
+ <div className="relative flex max-h-60 w-full flex-col overflow-hidden bg-background pr-8 rounded-xl ring-1 ring-muted-foreground/50 sm:pr-12 focus-within:ring-1 focus-within:ring-foreground">
<Textarea
ref={inputRef}
tabIndex={0}
@@ -47,14 +48,15 @@ export function ChatInput({
onChange={handleInputChange}
spellCheck={false}
/>
- <div className="absolute top-3 right-2.5">
+ <div className="absolute bottom-3 right-3">
<Button
type="submit"
- size="icon"
+ // size="icon"
disabled={status === "in_progress" || input === ""}
title="Send message"
+ className="rounded-md p-1 md:p-2 h-10 w-10"
>
- <IconArrowElbow />
+ <ArrowUp className="h-full w-full" />
<span className="sr-only">Send message</span>
</Button>
</div>
diff --git a/components/chat/chat-list.tsx b/components/chat/chat-list.tsx
index b9da0995..b840df70 100644
--- a/components/chat/chat-list.tsx
+++ b/components/chat/chat-list.tsx
@@ -2,8 +2,8 @@ import { type Message } from "ai";
import { Separator } from "@/components/ui/separator";
import { ChatMessage } from "./chat-message";
-import { cn } from "@/lib/utils";
import Skeleton from "../Skeleton";
+import PapermarkSparkle from "../shared/icons/papermark-sparkle";
export interface ChatList {
messages: Message[];
@@ -16,24 +16,24 @@ export function ChatList({ messages, status }: ChatList) {
}
return (
- <div className="relative mx-auto max-w-2xl px-4">
+ <div className="relative mx-auto max-w-xl px-4">
{messages.map((message, index) => (
<div key={index}>
<ChatMessage message={message} />
{index < messages.length - 1 && (
- <Separator className="my-4 md:my-8" />
+ <Separator className="my-4 bg-background" />
)}
</div>
))}
{status === "in_progress" && (
<>
- <Separator className="my-4 md:my-8" />
+ <Separator className="my-4 bg-background" />
<div
key={"loading-message"}
className="group relative mb-4 flex items-start md:-ml-12 whitespace-pre-wrap"
>
<div className="flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-md border shadow bg-primary text-primary-foreground">
- <IconOpenAI />
+ <PapermarkSparkle />
</div>
<div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden">
<div className="font-semibold select-none">
@@ -49,19 +49,3 @@ export function ChatList({ messages, status }: ChatList) {
</div>
);
}
-
-function IconOpenAI({ className, ...props }: React.ComponentProps<"svg">) {
- return (
- <svg
- fill="currentColor"
- viewBox="0 0 24 24"
- role="img"
- xmlns="http://www.w3.org/2000/svg"
- className={cn("h-4 w-4", className)}
- {...props}
- >
- <title>OpenAI icon</title>
- <path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z" />
- </svg>
- );
-}
diff --git a/components/chat/chat-message-actions.tsx b/components/chat/chat-message-actions.tsx
index be8e140d..1d573fb7 100644
--- a/components/chat/chat-message-actions.tsx
+++ b/components/chat/chat-message-actions.tsx
@@ -27,7 +27,7 @@ export function ChatMessageActions({
return (
<div
className={cn(
- "flex items-center justify-end md:absolute md:-right-10 md:-top-2",
+ "flex items-center justify-end md:hidden md:absolute md:right-0 md:-top-2",
className,
)}
{...props}
diff --git a/components/chat/chat-message.tsx b/components/chat/chat-message.tsx
index f775b2c8..e6d0ae1e 100644
--- a/components/chat/chat-message.tsx
+++ b/components/chat/chat-message.tsx
@@ -2,6 +2,8 @@ import { type Message } from "ai";
import { cn } from "@/lib/utils";
import { ChatMessageActions } from "./chat-message-actions";
+import UserRound from "../shared/icons/user-round";
+import PapermarkSparkle from "../shared/icons/papermark-sparkle";
export interface ChatMessageProps {
message: Message;
@@ -24,10 +26,10 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {
: "bg-primary text-primary-foreground",
)}
>
- {message.role === "user" ? <IconUser /> : <IconOpenAI />}
+ {message.role === "user" ? <UserRound /> : <PapermarkSparkle />}
</div>
<div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden">
- <div className="relative flex w-[calc(100%-50px)] flex-col lg:w-[calc(100%-115px)]">
+ <div className="relative flex w-[calc(100%-50px)] flex-col group">
<div className="font-semibold select-none">
{message.role === "user" ? "You" : "Papermark Assistant"}
</div>
@@ -35,38 +37,8 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {
<p className="mb-2 last:mb-0">{message.content}</p>
</div>
</div>
- <ChatMessageActions message={message} />
+ <ChatMessageActions className="group-hover:flex" message={message} />
</div>
</div>
);
}
-
-function IconOpenAI({ className, ...props }: React.ComponentProps<"svg">) {
- return (
- <svg
- fill="currentColor"
- viewBox="0 0 24 24"
- role="img"
- xmlns="http://www.w3.org/2000/svg"
- className={cn("h-4 w-4", className)}
- {...props}
- >
- <title>OpenAI icon</title>
- <path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z" />
- </svg>
- );
-}
-
-function IconUser({ className, ...props }: React.ComponentProps<"svg">) {
- return (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 256 256"
- fill="currentColor"
- className={cn("h-4 w-4", className)}
- {...props}
- >
- <path d="M230.92 212c-15.23-26.33-38.7-45.21-66.09-54.16a72 72 0 1 0-73.66 0c-27.39 8.94-50.86 27.82-66.09 54.16a8 8 0 1 0 13.85 8c18.84-32.56 52.14-52 89.07-52s70.23 19.44 89.07 52a8 8 0 1 0 13.85-8ZM72 96a56 56 0 1 1 56 56 56.06 56.06 0 0 1-56-56Z" />
- </svg>
- );
-}
diff --git a/components/chat/chat.tsx b/components/chat/chat.tsx
index 0c4f1ce0..415fcc7e 100644
--- a/components/chat/chat.tsx
+++ b/components/chat/chat.tsx
@@ -11,6 +11,7 @@ import { ChatInput } from "@/components/chat/chat-input";
// import { EmptyScreen } from "@/components/empty-screen";
import { ChatScrollAnchor } from "@/components/chat/chat-scroll-anchor";
import { useEffect, useState } from "react";
+import Sparkle from "../shared/icons/sparke";
export interface ChatProps extends React.ComponentProps<"div"> {
initialMessages: Message[];
@@ -76,10 +77,11 @@ function Nav() {
<div className="mx-auto px-2 sm:px-6 lg:px-8">
<div className="relative flex h-16 items-center justify-between">
<div className="flex flex-1 items-center justify-center sm:items-stretch sm:justify-start">
- <div className="flex flex-shrink-0 items-center">
+ <div className="flex flex-shrink-0 items-center gap-x-2">
<p className="text-2xl font-bold tracking-tighter text-white">
Papermark
</p>
+ <Sparkle className="h-5 w-5 text-white" />
</div>
</div>
<div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0">
diff --git a/components/shared/icons/arrow-up.tsx b/components/shared/icons/arrow-up.tsx
new file mode 100644
index 00000000..3366fd56
--- /dev/null
+++ b/components/shared/icons/arrow-up.tsx
@@ -0,0 +1,19 @@
+export default function ArrowUp({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={className}
+ shapeRendering="geometricPrecision"
+ >
+ <path d="m5 12 7-7 7 7" />
+ <path d="M12 19V5" />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/papermark-sparkle.tsx b/components/shared/icons/papermark-sparkle.tsx
new file mode 100644
index 00000000..61edf8cf
--- /dev/null
+++ b/components/shared/icons/papermark-sparkle.tsx
@@ -0,0 +1,46 @@
+export default function PapermarkSparkle({
+ className,
+}: {
+ className?: string;
+}) {
+ return (
+ <svg
+ width="24"
+ height="24"
+ viewBox="0 0 40 40"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ shapeRendering="geometricPrecision"
+ className={className}
+ >
+ <path
+ d="M31 12L29.7253 18.1359C29.6601 18.45 29.5492 18.7354 29.4016 18.9691C29.2539 19.2029 29.0737 19.3785 28.8753 19.4818L25 21.5L28.8753 23.5182C29.0737 23.6215 29.2539 23.7971 29.4016 24.0309C29.5492 24.2646 29.6601 24.55 29.7253 24.8641L31 31L32.2747 24.8641C32.3399 24.55 32.4508 24.2646 32.5984 24.0309C32.7461 23.7971 32.9263 23.6215 33.1247 23.5182L37 21.5L33.1247 19.4818C32.9263 19.3785 32.7461 19.2029 32.5984 18.9691C32.4508 18.7354 32.3399 18.45 32.2747 18.1359L31 12Z"
+ fill="currentColor"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ <path
+ d="M7.89631 31V9.18182H16.5043C18.1591 9.18182 19.5689 9.49787 20.7337 10.13C21.8984 10.755 22.7862 11.625 23.397 12.7401C24.0149 13.848 24.3239 15.1264 24.3239 16.5753C24.3239 18.0241 24.0114 19.3026 23.3864 20.4105C22.7614 21.5185 21.8558 22.3814 20.6697 22.9993C19.4908 23.6172 18.0632 23.9261 16.3871 23.9261H10.9006V20.2294H15.6413C16.5291 20.2294 17.2607 20.0767 17.8359 19.7713C18.4183 19.4588 18.8516 19.0291 19.1357 18.4822C19.4268 17.9283 19.5724 17.2926 19.5724 16.5753C19.5724 15.8509 19.4268 15.2187 19.1357 14.679C18.8516 14.1321 18.4183 13.7095 17.8359 13.4112C17.2536 13.1058 16.5149 12.9531 15.62 12.9531H12.5092V31H7.89631Z"
+ fill="currentColor"
+ />
+ <path
+ d="M26.5 5L25.9689 6.93767C25.9417 7.03684 25.8955 7.12696 25.834 7.20078C25.7725 7.2746 25.6974 7.33005 25.6147 7.36267L24 8L25.6147 8.63733C25.6974 8.66995 25.7725 8.7254 25.834 8.79922C25.8955 8.87304 25.9417 8.96316 25.9689 9.06233L26.5 11L27.0311 9.06233C27.0583 8.96316 27.1045 8.87304 27.166 8.79922C27.2275 8.7254 27.3026 8.66995 27.3853 8.63733L29 8L27.3853 7.36267C27.3026 7.33005 27.2275 7.2746 27.166 7.20078C27.1045 7.12696 27.0583 7.03684 27.0311 6.93767L26.5 5Z"
+ fill="currentColor"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ <path
+ d="M22.5 27L21.9689 28.9377C21.9417 29.0368 21.8955 29.127 21.834 29.2008C21.7725 29.2746 21.6974 29.33 21.6147 29.3627L20 30L21.6147 30.6373C21.6974 30.67 21.7725 30.7254 21.834 30.7992C21.8955 30.873 21.9417 30.9632 21.9689 31.0623L22.5 33L23.0311 31.0623C23.0583 30.9632 23.1045 30.873 23.166 30.7992C23.2275 30.7254 23.3026 30.67 23.3853 30.6373L25 30L23.3853 29.3627C23.3026 29.33 23.2275 29.2746 23.166 29.2008C23.1045 29.127 23.0583 29.0368 23.0311 28.9377L22.5 27Z"
+ fill="currentColor"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/sparke.tsx b/components/shared/icons/sparke.tsx
new file mode 100644
index 00000000..5e726e5a
--- /dev/null
+++ b/components/shared/icons/sparke.tsx
@@ -0,0 +1,25 @@
+export default function Sparkle({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ // fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={className}
+ shapeRendering="geometricPrecision"
+ >
+ <path
+ d="M12 3L10.088 8.813C9.99015 9.11051 9.82379 9.38088 9.60234 9.60234C9.38088 9.82379 9.11051 9.99015 8.813 10.088L3 12L8.813 13.912C9.11051 14.0099 9.38088 14.1762 9.60234 14.3977C9.82379 14.6191 9.99015 14.8895 10.088 15.187L12 21L13.912 15.187C14.0099 14.8895 14.1762 14.6191 14.3977 14.3977C14.6191 14.1762 14.8895 14.0099 15.187 13.912L21 12L15.187 10.088C14.8895 9.99015 14.6191 9.82379 14.3977 9.60234C14.1762 9.38088 14.0099 9.11051 13.912 8.813L12 3Z"
+ fill="currentColor"
+ />
+ <path d="M5 3V7" />
+ <path d="M19 17V21" />
+ <path d="M3 5H7" />
+ <path d="M17 19H21" />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/user-round.tsx b/components/shared/icons/user-round.tsx
new file mode 100644
index 00000000..6ec0e64e
--- /dev/null
+++ b/components/shared/icons/user-round.tsx
@@ -0,0 +1,19 @@
+export default function UserRound({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={className}
+ shapeRendering="geometricPrecision"
+ >
+ <circle cx="12" cy="8" r="5" />
+ <path d="M20 21a8 8 0 0 0-16 0" />
+ </svg>
+ );
+}
diff --git a/pages/view/[linkId]/chat.tsx b/pages/view/[linkId]/chat.tsx
index 197ac40c..c11bde77 100644
--- a/pages/view/[linkId]/chat.tsx
+++ b/pages/view/[linkId]/chat.tsx
@@ -1,25 +1,10 @@
-import { Message, experimental_useAssistant as useAssistant } from "ai/react";
-import { useEffect, useRef, useState } from "react";
+import { type Message } from "ai/react";
import prisma from "@/lib/prisma";
import { getServerSession } from "next-auth";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { CustomUser } from "@/lib/types";
import { Chat } from "@/components/chat/chat";
-const roleToColorMap: Record<Message["role"], string> = {
- system: "red",
- user: "black",
- function: "blue",
- assistant: "green",
-};
-
-const roleToNameMap: Record<Message["role"], string> = {
- system: "System",
- user: "You",
- function: "Function",
- assistant: "Papermark Assistant",
-};
-
export const getServerSideProps = async (context: any) => {
const { linkId } = context.params;
const session = await getServerSession(context.req, context.res, authOptions);
@@ -90,7 +75,9 @@ export default function ChatPage({
}) {
return (
<>
- <Chat initialMessages={messages} threadId={threadId} />
+ <div>
+ <Chat initialMessages={messages} threadId={threadId} />
+ </div>
</>
);
}