diff --git a/surfsense_backend/app/tasks/chat/stream_new_chat.py b/surfsense_backend/app/tasks/chat/stream_new_chat.py index 060dd23c6..ecc727b47 100644 --- a/surfsense_backend/app/tasks/chat/stream_new_chat.py +++ b/surfsense_backend/app/tasks/chat/stream_new_chat.py @@ -1581,7 +1581,7 @@ async def stream_new_chat( ) else: yield streaming_service.format_error( - "Buy more tokens to continue with this model, or switch to a free model.", + "Buy more tokens to continue with this model, or switch to a free model", error_code="PREMIUM_QUOTA_EXHAUSTED", ) yield streaming_service.format_done() @@ -2349,7 +2349,7 @@ async def stream_resume_chat( ) else: yield streaming_service.format_error( - "Buy more tokens to continue with this model, or switch to a free model.", + "Buy more tokens to continue with this model, or switch to a free model", error_code="PREMIUM_QUOTA_EXHAUSTED", ) yield streaming_service.format_done() diff --git a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx index f775e1f06..6ec587f91 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx @@ -1032,6 +1032,7 @@ export default function NewChatPage() { setPremiumAlertForThread({ threadId: currentThreadId, message: premiumQuotaAlertMessage, + userId: currentUser?.id ?? null, }); } else { toast.error("Failed to get response. Please try again."); @@ -1334,6 +1335,7 @@ export default function NewChatPage() { setPremiumAlertForThread({ threadId: resumeThreadId, message: premiumQuotaAlertMessage, + userId: currentUser?.id ?? null, }); } else { toast.error("Failed to resume. Please try again."); @@ -1692,6 +1694,7 @@ export default function NewChatPage() { setPremiumAlertForThread({ threadId, message: premiumQuotaAlertMessage, + userId: currentUser?.id ?? null, }); } else { toast.error("Failed to regenerate response. Please try again."); diff --git a/surfsense_web/atoms/chat/premium-alert.atom.ts b/surfsense_web/atoms/chat/premium-alert.atom.ts index c0efc174f..1c837dd65 100644 --- a/surfsense_web/atoms/chat/premium-alert.atom.ts +++ b/surfsense_web/atoms/chat/premium-alert.atom.ts @@ -14,13 +14,25 @@ export const setPremiumAlertForThreadAtom = atom( payload: { threadId: number; message: string; + userId?: string | null; } ) => { + const storageKey = `surfsense-premium-alert-seen-v1:${payload.userId ?? "anonymous"}`; + + if (typeof window !== "undefined") { + const hasSeen = localStorage.getItem(storageKey) === "true"; + if (hasSeen) return; + } + const current = get(premiumAlertByThreadAtom); set(premiumAlertByThreadAtom, { ...current, [payload.threadId]: { message: payload.message }, }); + + if (typeof window !== "undefined") { + localStorage.setItem(storageKey, "true"); + } } ); diff --git a/surfsense_web/components/assistant-ui/thread.tsx b/surfsense_web/components/assistant-ui/thread.tsx index cb063fac3..3095556dc 100644 --- a/surfsense_web/components/assistant-ui/thread.tsx +++ b/surfsense_web/components/assistant-ui/thread.tsx @@ -161,15 +161,15 @@ const PremiumQuotaPinnedAlert: FC = () => { if (!alert) return null; return ( -
-
- +
+
+

{alert.message}