From d2d9398093b3bd696226ab7e1f9367530b3553b6 Mon Sep 17 00:00:00 2001 From: miha-yy Date: Tue, 8 Jul 2025 07:24:09 +0200 Subject: [PATCH 1/3] show content on edit --- .../assistant/FixWithChat.tsx | 2 + apps/web/components/assistant-chat/chat.tsx | 5 + .../assistant-chat/email-display-example.tsx | 107 ++++++++++++ .../assistant-chat/multimodal-input.tsx | 154 ++++++++++++++---- apps/web/utils/email-display.ts | 87 ++++++++++ 5 files changed, 327 insertions(+), 28 deletions(-) create mode 100644 apps/web/components/assistant-chat/email-display-example.tsx create mode 100644 apps/web/utils/email-display.ts diff --git a/apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx b/apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx index bd946a5f1f..6a5b793a75 100644 --- a/apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx +++ b/apps/web/app/(app)/[emailAccountId]/assistant/FixWithChat.tsx @@ -24,6 +24,7 @@ import { ButtonList } from "@/components/ButtonList"; import type { RulesResponse } from "@/app/api/user/rules/route"; import { ProcessResultDisplay } from "@/app/(app)/[emailAccountId]/assistant/ProcessResultDisplay"; import { NONE_RULE_ID } from "@/app/(app)/[emailAccountId]/assistant/consts"; +import { createEmailDisplayValue } from "@/utils/email-display"; export function FixWithChat({ setInput, @@ -84,6 +85,7 @@ export function FixWithChat({ if (setInput) { // this is only set if we're in the correct context + // The input will automatically show as "@(Subject)" in the chat setInput(input); } else { // redirect to the assistant page diff --git a/apps/web/components/assistant-chat/chat.tsx b/apps/web/components/assistant-chat/chat.tsx index 81f0e35fce..a9d3642aa2 100644 --- a/apps/web/components/assistant-chat/chat.tsx +++ b/apps/web/components/assistant-chat/chat.tsx @@ -36,6 +36,7 @@ import { useIsMobile } from "@/hooks/use-mobile"; import { ExamplesDialog } from "@/components/assistant-chat/examples-dialog"; import { Tooltip } from "@/components/Tooltip"; import { toastError } from "@/components/Toast"; +import { createDisplayValueForInput } from "@/utils/email-display"; // Some mega hacky code used here to workaround AI SDK's use of SWR // AI SDK uses SWR too and this messes with the global SWR config @@ -180,6 +181,9 @@ function ChatUI({ chat }: { chat: ReturnType }) { reload, } = chat; + // Create display value for email data + const displayValue = createDisplayValueForInput(input); + return (
@@ -223,6 +227,7 @@ function ChatUI({ chat }: { chat: ReturnType }) { // messages={messages} setMessages={setMessages} // append={append} + displayValue={displayValue} />
diff --git a/apps/web/components/assistant-chat/email-display-example.tsx b/apps/web/components/assistant-chat/email-display-example.tsx new file mode 100644 index 0000000000..76e52aef93 --- /dev/null +++ b/apps/web/components/assistant-chat/email-display-example.tsx @@ -0,0 +1,107 @@ +import { useState } from "react"; +import { MultimodalInput } from "./multimodal-input"; +import { + createDisplayValueForInput, + extractEmailContentForTooltip, +} from "@/utils/email-display"; + +export function EmailDisplayExample() { + const [input, setInput] = useState(""); + + // Example email data input + const exampleEmailInput = `You applied the wrong rule to this email. +Fix our rules so this type of email is handled correctly in the future. + +Email details: +*From*: john@example.com +*Subject*: Meeting Tomorrow +*Content*: Hi, just wanted to confirm our meeting tomorrow at 2 PM. + +Current rule applied: Archive + +Reason the rule was chosen: +This email appears to be a meeting confirmation. + +The rule that should have been applied was: "Meeting Confirmations"`; + + // Example of what the display will look like + const exampleDisplay = `You applied the wrong rule to this email. +Fix our rules so this type of email is handled correctly in the future. + +Email details: +šŸ“§ [Meeting Tomorrow] + +Current rule applied: Archive + +Reason the rule was chosen: +This email appears to be a meeting confirmation. + +The rule that should have been applied was: "Meeting Confirmations"`; + + const displayValue = createDisplayValueForInput(input); + const emailTooltipContent = extractEmailContentForTooltip(input); + + return ( +
+

Email Display Example

+ +
+ +