🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(cloud): improve open/close state of support chat (#4815)
Marc Klingen5381c5f19b5a
diff --git a/web/src/features/setup/components/SetupPage.tsx b/web/src/features/setup/components/SetupPage.tsxindex f13eafd657..93bfe4a2eb 100644--- a/web/src/features/setup/components/SetupPage.tsx+++ b/web/src/features/setup/components/SetupPage.tsx@@ -22,6 +22,7 @@ import {inviteMembersRoute,setupTracingRoute,} from "@/src/features/setup/setupRoutes";+import { showChat } from "@/src/features/support-chat/chat";import { api } from "@/src/utils/api";import { cn } from "@/src/utils/tailwind";import { type RouterOutput } from "@/src/utils/types";@@ -226,7 +227,10 @@ const TracingSetup = ({>(null);const utils = api.useUtils();const mutCreateApiKey = api.apiKeys.create.useMutation({- onSuccess: () => utils.apiKeys.invalidate(),+ onSuccess: () => {+ utils.apiKeys.invalidate();+ showChat();+ },});const isLoadingRef = useRef(false);diff --git a/web/src/features/support-chat/chat.tsx b/web/src/features/support-chat/chat.tsxindex 5048a7f19e..5ed8cb9208 100644--- a/web/src/features/support-chat/chat.tsx+++ b/web/src/features/support-chat/chat.tsx@@ -11,6 +11,14 @@ const CrispChat = () => {useEffect(() => {if (env.NEXT_PUBLIC_CRISP_WEBSITE_ID) {Crisp.configure(env.NEXT_PUBLIC_CRISP_WEBSITE_ID);++ // Check session storage for chat visibility+ // Expires at end of session+ const shouldShowChat =+ sessionStorage.getItem("supportChatVisible") === "true";+ if (!shouldShowChat) {+ Crisp.chat.hide();+ }Crisp.chat.onChatInitiated(() => {capture("support_chat:initiated");});@@ -20,13 +28,24 @@ const CrispChat = () => {Crisp.message.onMessageSent(() => {capture("support_chat:message_sent");});+ Crisp.message.onMessageReceived(() => {+ showChat();+ });+ try {+ if (Crisp.chat.unreadCount() > 0) {+ showChat();+ }+ } catch (e) {+ // do nothing, this throws unnecessary errors that cannot be fixed+ }return () => {Crisp.chat.offChatInitiated();Crisp.chat.offChatOpened();Crisp.message.offMessageSent();};}- }, [capture]);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, []);return null;};@@ -78,7 +97,22 @@ export const showAgentChatMessage = (message: string) => {};export const openChat = () => {+ showChat();if (chatAvailable) Crisp.chat.open();};+export const hideChat = () => {+ if (chatAvailable) {+ sessionStorage.setItem("supportChatVisible", "false");+ Crisp.chat.hide();+ }+};++export const showChat = () => {+ if (chatAvailable) {+ sessionStorage.setItem("supportChatVisible", "true");+ Crisp.chat.show();+ }+};+export const chatAvailable = !!process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID;