🪢 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
fix(assistant): make message feedback optimistic (#16306)
Ben Bachemf147487dc5d8
diff --git a/web/src/features/in-app-agent/components/InAppAgentMessage.stories.tsx b/web/src/features/in-app-agent/components/InAppAgentMessage.stories.tsxindex 1488557b00..ff02d491a6 100644--- a/web/src/features/in-app-agent/components/InAppAgentMessage.stories.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentMessage.stories.tsx@@ -637,6 +637,34 @@ export const FeedbackPopoverInteraction = meta.story({},});+export const OptimisticFeedbackInteraction = meta.story({+ name: "(Test) Optimistic Feedback",+ args: {+ role: "assistant",+ content: {+ type: "text",+ text: "Langfuse tracks traces, observations, scores, and metadata so teams can debug LLM applications.",+ },+ onSubmitFeedback: fn(+ () => new Promise<void>((resolve) => setTimeout(resolve, 1_000)),+ ),+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const goodResponseButton = await canvas.findByRole("button", {+ name: "Good response",+ });++ await userEvent.click(goodResponseButton);++ expect(goodResponseButton).toHaveAttribute("aria-pressed", "true");+ await expect(+ body.findByPlaceholderText("Optional feedback comment"),+ ).resolves.toBeInTheDocument();+ },+});+export const CopyMessageInteraction = meta.story({name: "(Test) Copy Whole Message",args: {diff --git a/web/src/features/in-app-agent/components/InAppAgentMessage.tsx b/web/src/features/in-app-agent/components/InAppAgentMessage.tsxindex 337e2c974f..03eab6b123 100644--- a/web/src/features/in-app-agent/components/InAppAgentMessage.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentMessage.tsx@@ -516,26 +516,37 @@ function MessageFeedbackControls({};const handleSelectFeedback = (value: InAppAgentMessageFeedbackValue) => {+ const previousValue = selectedValue;+ const previousComment = comment;+ const previousCommittedComment = committedComment;+ const previousPopoverOpen = isCommentPopoverOpen;+if (selectedValue === value) {- submitFeedback(null, "")- .then(() => {- setSelectedValue(undefined);- setComment("");- setCommittedComment("");- setIsCommentPopoverOpen(false);- })- .catch(() => undefined);+ setSelectedValue(undefined);+ setComment("");+ setCommittedComment("");+ setIsCommentPopoverOpen(false);++ submitFeedback(null, "").catch(() => {+ setSelectedValue(previousValue);+ setComment(previousComment);+ setCommittedComment(previousCommittedComment);+ setIsCommentPopoverOpen(previousPopoverOpen);+ });return;}- submitFeedback(value, "")- .then(() => {- setSelectedValue(value);- setComment("");- setCommittedComment("");- setIsCommentPopoverOpen(!isFeedbackDisabledRef.current);- })- .catch(() => undefined);+ setSelectedValue(value);+ setComment("");+ setCommittedComment("");+ setIsCommentPopoverOpen(!isFeedbackDisabledRef.current);++ submitFeedback(value, "").catch(() => {+ setSelectedValue(previousValue);+ setComment(previousComment);+ setCommittedComment(previousCommittedComment);+ setIsCommentPopoverOpen(previousPopoverOpen);+ });};const commentButtonText = `Comment: ${committedComment}`;