-
Notifications
You must be signed in to change notification settings - Fork 6
Add analytics tracking and thumbs feedback to AI sidekick (V2 editor) #2441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,9 +34,19 @@ export function ChatMessageList({ | |
|
|
||
| return ( | ||
| <BlockStack gap="2" className="flex-1 overflow-y-auto p-3"> | ||
| {messages.map((msg) => ( | ||
| <ChatMessage key={msg.id} message={msg} /> | ||
| ))} | ||
| {messages.map((msg, i) => { | ||
| const precedingUserMessage = | ||
| msg.role === "assistant" && messages[i - 1]?.role === "user" | ||
| ? messages[i - 1].content | ||
| : undefined; | ||
|
Comment on lines
+38
to
+41
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If AI posted multiple messages (it may happen in theory), we're going to loose user prompt. I'm proposing another schema. That can simplify and solidify entire logic: 1. We can extend ChatMessage to carry 2. Next we need to update 3. Now we automatically have access to all required information in ChatMessage component. |
||
| return ( | ||
| <ChatMessage | ||
| key={msg.id} | ||
| message={msg} | ||
| prompt={precedingUserMessage} | ||
| /> | ||
| ); | ||
| })} | ||
| {thinkingText && <ThinkingMessage text={thinkingText} />} | ||
| <div ref={bottomRef} /> | ||
| </BlockStack> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { useState } from "react"; | ||
|
|
||
| import { Icon } from "@/components/ui/icon"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { useAnalytics } from "@/providers/AnalyticsProvider"; | ||
|
|
||
| interface ResponseFeedbackProps { | ||
| prompt: string; | ||
| response: string; | ||
| } | ||
|
|
||
| type FeedbackState = "idle" | "submitted"; | ||
|
|
||
| export function ResponseFeedback({ prompt, response }: ResponseFeedbackProps) { | ||
| const { track } = useAnalytics(); | ||
| const [state, setState] = useState<FeedbackState>("idle"); | ||
| const [showThanks, setShowThanks] = useState(false); | ||
|
|
||
| function handleFeedback(rating: "positive" | "negative") { | ||
| if (state !== "idle") return; | ||
| setState("submitted"); | ||
| track("ai_assistant.response.feedback", { rating, prompt, response }); | ||
| setTimeout(() => setShowThanks(true), 200); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="relative flex items-center h-5 mt-1.5"> | ||
| <div | ||
| className={cn( | ||
| "flex gap-0.5 transition-opacity duration-200", | ||
| state === "submitted" ? "opacity-0" : "opacity-100", | ||
| )} | ||
| aria-hidden={state === "submitted"} | ||
| > | ||
| <button | ||
| onClick={() => handleFeedback("positive")} | ||
| disabled={state !== "idle"} | ||
| className="text-muted-foreground/30 hover:text-info transition-colors duration-150 p-0.5 rounded cursor-pointer" | ||
| aria-label="Helpful response" | ||
| > | ||
| <Icon name="ThumbsUp" size="xs" /> | ||
| </button> | ||
| <button | ||
| onClick={() => handleFeedback("negative")} | ||
| disabled={state !== "idle"} | ||
| className="text-muted-foreground/30 hover:text-info transition-colors duration-150 p-0.5 rounded cursor-pointer" | ||
| aria-label="Not helpful response" | ||
| > | ||
| <Icon name="ThumbsDown" size="xs" /> | ||
| </button> | ||
| </div> | ||
| <span | ||
| className={cn( | ||
| "absolute left-0 text-xs text-muted-foreground transition-opacity duration-300", | ||
| showThanks ? "opacity-100" : "opacity-0 pointer-events-none", | ||
| )} | ||
| > | ||
| Thank you for sharing your feedback | ||
| </span> | ||
| </div> | ||
| ); | ||
|
Comment on lines
+27
to
+61
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We must use UI primitives |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Response can be pretty beefy... not sure if we need to track it