Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

Support chat for cloud.langfuse.com & fix session after creating project (#64)

Marc Klingen219e3905d5e9
diff --git a/README.md b/README.md
index 8f903aa42f..b407a480ce 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
<div align="center">
<a href="https://langfuse.com">
- <h1>🪢 langfuse</h1>
+ <h1>🪢 Langfuse</h1>
</a>
<h3>
Open-source analytics for LLM-based applications
@@ -11,7 +11,7 @@
</br></br>
<div>
<a href="https://discord.gg/7NXusRtqYU">
- <strong>Join the langfuse Discord »</strong>
+ <strong>Join the Langfuse Discord »</strong>
</a>
</br>
<a href="#roadmap">
@@ -42,11 +42,13 @@ Reach out if you are interested to join the alpha: [email protected]
# Integrations
Monitor backend executions of LLM app to create nested traces
+
- Python SDK
- Typescript SDK (node, edge)
- API
Collect user feedback and attach it to backend traces
+
- Typescript/JS SDK
- API
@@ -54,25 +56,25 @@ More details: [langfuse.com/integrations](https://langfuse.com/integrations)
# Data exploration
-langfuse offers an admin UI to explore the ingested data.
+Langfuse offers an admin UI to explore the ingested data.
- Nested view of LLM app executions
- Segment execution traces by user feedback
# Get started
-Follow the [quickstart](https://langfuse.com/docs/get-started) with instructions to setup langfuse locally, self-hosted or using langfuse cloud
+Follow the [quickstart](https://langfuse.com/docs/get-started) with instructions to setup Langfuse locally, self-hosted or using Langfuse cloud
# Roadmap
- [x] Integrations: [langfuse.com/integrations](https://langfuse.com/integrations)
- [x] Data exploration
-- [ ] langfuse analytics (in alpha)
- - Analytics engine
- - Detailed reports on latency, cost, quality
- - Evals
+- [ ] Langfuse analytics (in alpha)
+ - Analytics engine
+ - Detailed reports on latency, cost, quality
+ - Evals
-# Contributing to langfuse
+# Contributing to Langfuse
Join the community [on Discord](https://discord.gg/7NXusRtqYU).
@@ -80,4 +82,4 @@ To contribute, send us a PR, raise a github issue, or email at contributing@lang
# License
-langfuse is MIT licensed, except for `ee/` folder. See [LICENSE](LICENSE) and [docs](https://langfuse.com/docs/open-source) for more details.
+Langfuse is MIT licensed, except for `ee/` folder. See [LICENSE](LICENSE) and [docs](https://langfuse.com/docs/open-source) for more details.
diff --git a/package-lock.json b/package-lock.json
index d84ac372a5..003210a5a8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -45,6 +45,7 @@
"clsx": "^1.2.1",
"cmdk": "^0.2.0",
"cors": "^2.8.5",
+ "crisp-sdk-web": "*",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"lucide-react": "^0.257.0",
@@ -89,6 +90,9 @@
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.6"
+ },
+ "optionalDependencies": {
+ "crisp-sdk-web": "^1.0.19"
}
},
"node_modules/@aashutoshrathi/word-wrap": {
@@ -4065,6 +4069,12 @@
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
"devOptional": true
},
+ "node_modules/crisp-sdk-web": {
+ "version": "1.0.19",
+ "resolved": "https://registry.npmjs.org/crisp-sdk-web/-/crisp-sdk-web-1.0.19.tgz",
+ "integrity": "sha512-kV/MyXVnQrVUwO9Stb7bUYr34BnslVhb5UZTUAa/qz1LvTrKtCBu5SYHyIYDiC29CHKrVXPenVyerpH/ZvuF/g==",
+ "optional": true
+ },
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
diff --git a/package.json b/package.json
index fe009511ba..e2e5505d65 100644
--- a/package.json
+++ b/package.json
@@ -102,5 +102,8 @@
},
"ct3aMetadata": {
"initVersion": "7.13.0"
+ },
+ "optionalDependencies": {
+ "crisp-sdk-web": "^1.0.19"
}
}
diff --git a/src/features/projects/components/NewProjectButton.tsx b/src/features/projects/components/NewProjectButton.tsx
index a42ab5eca7..106e525f89 100644
--- a/src/features/projects/components/NewProjectButton.tsx
+++ b/src/features/projects/components/NewProjectButton.tsx
@@ -24,6 +24,7 @@ import { api } from "@/src/utils/api";
import { useRouter } from "next/router";
import { cn } from "@/src/utils/tailwind";
import { useState } from "react";
+import { useSession } from "next-auth/react";
const formSchema = z.object({
name: z.string().min(3, "Must have at least 3 characters"),
@@ -34,6 +35,7 @@ interface NewProjectButtonProps {
}
export function NewProjectButton({ size = "default" }: NewProjectButtonProps) {
const [open, setOpen] = useState(false);
+ const { update: updateSession } = useSession();
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
@@ -45,6 +47,7 @@ export function NewProjectButton({ size = "default" }: NewProjectButtonProps) {
const router = useRouter();
const createProjectMutation = api.projects.create.useMutation({
onSuccess: (newProject) => {
+ void updateSession();
void router.push(`/project/${newProject.id}/settings`);
void utils.projects.invalidate();
},
diff --git a/src/features/support-chat/chat.tsx b/src/features/support-chat/chat.tsx
new file mode 100644
index 0000000000..23a3587fbd
--- /dev/null
+++ b/src/features/support-chat/chat.tsx
@@ -0,0 +1,31 @@
+"use client";
+
+import { useEffect } from "react";
+import { Crisp } from "crisp-sdk-web";
+
+const CrispChat = () => {
+ useEffect(() => {
+ if (process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID)
+ Crisp.configure(process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID);
+ });
+
+ return null;
+};
+
+export default CrispChat;
+
+export const chatSetUser = ({
+ name,
+ email,
+ data,
+}: {
+ name: string;
+ email: string;
+ data: object;
+}) => {
+ if (process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID) {
+ Crisp.user.setEmail(email);
+ Crisp.user.setNickname(name);
+ Crisp.session.setData(data);
+ }
+};
diff --git a/src/features/support-chat/index.tsx b/src/features/support-chat/index.tsx
new file mode 100644
index 0000000000..e90e0b53c8
--- /dev/null
+++ b/src/features/support-chat/index.tsx
@@ -0,0 +1,7 @@
+import dynamic from "next/dynamic";
+
+export { chatSetUser } from "./chat";
+
+export const CrispWidget = dynamic(() => import("./chat"), {
+ ssr: false,
+});
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index f363ecc0f2..1545f18cc4 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -13,6 +13,7 @@ import { useRouter } from "next/router";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
+import { CrispWidget, chatSetUser } from "@/src/features/support-chat";
// Check that PostHog is client-side (used to handle Next.js SSR) and that env vars are set
if (
@@ -36,7 +37,7 @@ const MyApp: AppType<{ session: Session | null }> = ({
const router = useRouter();
useEffect(() => {
- // PostHog
+ // PostHog (cloud.langfuse.com)
if (
process.env.NEXT_PUBLIC_POSTHOG_KEY &&
process.env.NEXT_PUBLIC_POSTHOG_HOST
@@ -58,6 +59,7 @@ const MyApp: AppType<{ session: Session | null }> = ({
<Component {...pageProps} />
<UserTracking />
</Layout>
+ <CrispWidget />
</SessionProvider>
</PostHogProvider>
);
@@ -86,6 +88,17 @@ function UserTracking() {
email: session.data.user?.email ?? undefined,
id: session.data.user?.id ?? undefined,
});
+ // Chat
+ chatSetUser({
+ name: session.data.user?.name ?? "undefined",
+ email: session.data.user?.email ?? "undefined",
+ data: {
+ userId: session.data.user?.id ?? "undefined",
+ projects: JSON.stringify(session.data.user?.projects) ?? "undefined",
+ featureFlags:
+ JSON.stringify(session.data.user?.featureFlags) ?? "undefined",
+ },
+ });
} else {
// PostHog
if (