From 0123e68ddad728760d043bdb94040722a7cea850 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Thu, 5 Jun 2025 15:24:31 -0700 Subject: [PATCH] Instrument extra files warning (#345) https://github.com/dyad-sh/dyad/issues/244 --- src/components/chat/ChatInput.tsx | 1 + src/hooks/useStreamChat.ts | 4 +++- src/lib/toast.ts | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/chat/ChatInput.tsx b/src/components/chat/ChatInput.tsx index 0ce0ea9..39ffc15 100644 --- a/src/components/chat/ChatInput.tsx +++ b/src/components/chat/ChatInput.tsx @@ -188,6 +188,7 @@ export function ChatInput({ chatId }: { chatId?: number }) { showExtraFilesToast({ files: result.extraFiles, error: result.extraFilesError, + posthog, }); } } catch (err) { diff --git a/src/hooks/useStreamChat.ts b/src/hooks/useStreamChat.ts index 2c11e74..db789fb 100644 --- a/src/hooks/useStreamChat.ts +++ b/src/hooks/useStreamChat.ts @@ -20,6 +20,7 @@ import { useSearch } from "@tanstack/react-router"; import { useRunApp } from "./useRunApp"; import { useCountTokens } from "./useCountTokens"; import { useUserBudgetInfo } from "./useUserBudgetInfo"; +import { usePostHog } from "posthog-js/react"; export function getRandomNumberId() { return Math.floor(Math.random() * 1_000_000_000_000_000); @@ -40,7 +41,7 @@ export function useStreamChat({ const { refreshAppIframe } = useRunApp(); const { countTokens } = useCountTokens(); const { refetchUserBudget } = useUserBudgetInfo(); - + const posthog = usePostHog(); let chatId: number | undefined; if (hasChatId) { @@ -93,6 +94,7 @@ export function useStreamChat({ showExtraFilesToast({ files: response.extraFiles, error: response.extraFilesError, + posthog, }); } refreshProposal(chatId); diff --git a/src/lib/toast.ts b/src/lib/toast.ts index dc95291..8ed344f 100644 --- a/src/lib/toast.ts +++ b/src/lib/toast.ts @@ -1,4 +1,5 @@ import { toast } from "sonner"; +import { PostHog } from "posthog-js"; /** * Toast utility functions for consistent notifications across the app @@ -61,19 +62,28 @@ export const showLoading = ( export const showExtraFilesToast = ({ files, error, + posthog, }: { files: string[]; error?: string; + posthog: PostHog; }) => { if (error) { showError( `Error committing files ${files.join(", ")} changed outside of Dyad: ${error}`, ); + posthog.capture("extra-files:error", { + files: files, + error, + }); } else { showWarning( `Files changed outside of Dyad have automatically been committed: \n\n${files.join("\n")}`, ); + posthog.capture("extra-files:warning", { + files: files, + }); } };