Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: increase Q&A message limit to 4000 chars and surface validation errors
Cursor Agentbdd3097e6f2e
diff --git a/ee/features/conversations/api/team-conversations-route.ts b/ee/features/conversations/api/team-conversations-route.tsindex 1764e1fa..3069c72d 100644--- a/ee/features/conversations/api/team-conversations-route.ts+++ b/ee/features/conversations/api/team-conversations-route.ts@@ -564,6 +564,12 @@ const routeHandlers = {return res.status(201).json(message);} catch (error) {console.error("Error adding message:", error);+ if (+ error instanceof Error &&+ error.message.startsWith("Content cannot be")+ ) {+ return res.status(400).json({ error: error.message });+ }return res.status(500).json({ error: "Internal server error" });}},diff --git a/ee/features/conversations/components/viewer/conversation-view-sidebar.tsx b/ee/features/conversations/components/viewer/conversation-view-sidebar.tsxindex a997a790..762a216e 100644--- a/ee/features/conversations/components/viewer/conversation-view-sidebar.tsx+++ b/ee/features/conversations/components/viewer/conversation-view-sidebar.tsx@@ -11,6 +11,7 @@ import { toast } from "sonner";import useSWR, { mutate } from "swr";import { fetcher } from "@/lib/utils";+import { MAX_MESSAGE_LENGTH } from "@/lib/utils/sanitize-html";import { Button } from "@/components/ui/button";import { ScrollArea } from "@/components/ui/scroll-area";@@ -342,6 +343,7 @@ export function ConversationViewSidebar({type="text"value={newMessage}onChange={(e) => setNewMessage(e.target.value)}+ maxLength={MAX_MESSAGE_LENGTH}className="flex-1 rounded-md border border-input px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"placeholder="Type your message..."/>@@ -382,6 +384,7 @@ export function ConversationViewSidebar({id="message"value={newMessage}onChange={(e) => setNewMessage(e.target.value)}+ maxLength={MAX_MESSAGE_LENGTH}placeholder="Type your question..."className="min-h-[100px] w-full rounded-md border border-input px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"requireddiff --git a/ee/features/conversations/pages/conversation-detail.tsx b/ee/features/conversations/pages/conversation-detail.tsxindex c79e6a61..ca3ffc98 100644--- a/ee/features/conversations/pages/conversation-detail.tsx+++ b/ee/features/conversations/pages/conversation-detail.tsx@@ -24,6 +24,7 @@ import z from "zod";import { useDataroom } from "@/lib/swr/use-dataroom";import { CustomUser } from "@/lib/types";import { fetcher } from "@/lib/utils";+import { MAX_MESSAGE_LENGTH } from "@/lib/utils/sanitize-html";import { DataroomHeader } from "@/components/datarooms/dataroom-header";import { DataroomNavigation } from "@/components/datarooms/dataroom-navigation";@@ -334,7 +335,10 @@ export default function ConversationDetailPage() {},);- if (!response.ok) throw new Error("Failed to send message");+ if (!response.ok) {+ const errorData = await response.json().catch(() => ({}));+ throw new Error(errorData.error || "Failed to send message");+ }// Revalidate both the conversation and the summariesmutate(@@ -347,7 +351,9 @@ export default function ConversationDetailPage() {toast.success("Message sent");} catch (error) {console.error("Error sending message:", error);- toast.error("Failed to send message");+ toast.error(+ error instanceof Error ? error.message : "Failed to send message",+ );}};@@ -705,10 +711,11 @@ function ConversationReplyForm({}) {const [newMessage, setNewMessage] = useState("");const [isSending, setIsSending] = useState(false);+ const isOverLimit = newMessage.length > MAX_MESSAGE_LENGTH;const handleSubmit = async (e: React.FormEvent) => {e.preventDefault();- if (!newMessage.trim()) return;+ if (!newMessage.trim() || isOverLimit) return;setIsSending(true);try {@@ -724,15 +731,20 @@ function ConversationReplyForm({<form onSubmit={handleSubmit} className="flex flex-col gap-4"><Textareaplaceholder="Type your reply..."- className="min-h-[100px]"+ className={`min-h-[100px] ${isOverLimit ? "border-destructive focus-visible:ring-destructive" : ""}`}value={newMessage}onChange={(e) => setNewMessage(e.target.value)}/>- <div className="flex justify-end">+ <div className="flex items-center justify-between">+ <span+ className={`text-xs ${isOverLimit ? "font-medium text-destructive" : "text-muted-foreground"}`}+ >+ {newMessage.length > 0 &&+ `${newMessage.length} / ${MAX_MESSAGE_LENGTH}`}+ </span><Buttontype="submit"- disabled={!newMessage.trim() || isSending}- className="ml-auto"+ disabled={!newMessage.trim() || isOverLimit || isSending}>{isSending ? (<>diff --git a/lib/utils/sanitize-html.ts b/lib/utils/sanitize-html.tsindex a343a2f2..e501e695 100644--- a/lib/utils/sanitize-html.ts+++ b/lib/utils/sanitize-html.ts@@ -19,7 +19,9 @@ export function sanitizePlainText(content: string) {.trim();}-export function validateContent(html: string, length: number = 1000) {+export const MAX_MESSAGE_LENGTH = 4000;++export function validateContent(html: string, length: number = MAX_MESSAGE_LENGTH) {if (html.length > length) {throw new Error(`Content cannot be longer than ${length} characters`);}