🪢 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(web): system message keeps one expand control (#17623)
Trang Nguyen7954a4e7a3a2
diff --git a/web/src/components/ui/MarkdownJsonView.tsx b/web/src/components/ui/MarkdownJsonView.tsxindex 3bb6d2c8a0..388edf46c1 100644--- a/web/src/components/ui/MarkdownJsonView.tsx+++ b/web/src/components/ui/MarkdownJsonView.tsx@@ -1,4 +1,3 @@-/* eslint-disable no-nested-ternary *//* eslint-disable @repo/no-style-props */import {OpenAIContentSchema,@@ -8,7 +7,7 @@ import { Button } from "@/src/components/ui/button";import { PrettyJsonView } from "@/src/components/ui/PrettyJsonView";import { MarkdownView } from "@/src/components/ui/MarkdownViewer";import { type MediaReturnType } from "@/src/features/media";-import { Check, ChevronDown, Copy } from "lucide-react";+import { Check, Copy } from "lucide-react";import { useMemo, useState } from "react";import { type z } from "zod";import { useMarkdownRenderCharacterLimit } from "@/src/hooks/useMarkdownRenderCharacterLimit";@@ -19,14 +18,6 @@ type MarkdownJsonViewHeaderProps = {titleIcon?: React.ReactNode;handleOnCopy: (event?: React.MouseEvent<HTMLButtonElement>) => void;controlButtons?: React.ReactNode;- /** When set, the header hosts expand/collapse so a long body is not the- only place to find the control. `subject` names what collapses in the- accessible labels (defaults to "system prompt", its original use). */- collapseControl?: {- isCollapsed: boolean;- onToggle: () => void;- subject?: string;- };inset?: boolean;/** Hosts that render their own copy control (e.g. inside the content box)suppress the header's. */@@ -41,36 +32,14 @@ export function MarkdownJsonViewHeader({titleIcon,handleOnCopy,controlButtons,- collapseControl,inset = false,hideCopyButton = false,hoverRevealControls = false,}: MarkdownJsonViewHeaderProps) {const [isCopied, setIsCopied] = useState(false);- const collapseSubject = collapseControl?.subject ?? "system prompt";- const collapseLabel = collapseControl- ? collapseControl.isCollapsed- ? `Expand ${collapseSubject}`- : `Collapse ${collapseSubject}`- : undefined;- // Keep the visible title in the title-button name (WCAG 2.5.3). A generic- // aria-label would hide message `name`s from assistive tech.- const titleButtonLabel =- typeof title === "string" && collapseLabel- ? `${title}, ${collapseLabel}`- : collapseLabel;const titleContent = (<>- {collapseControl ? (- <ChevronDown- className={cn(- "h-3.5 w-3.5 shrink-0 transition-transform",- collapseControl.isCollapsed && "-rotate-90",- )}- aria-hidden- />- ) : null}{titleIcon}{title}</>@@ -86,19 +55,7 @@ export function MarkdownJsonViewHeader({{/* Masked from session recordings: the title can be a customer-providedmessage `name` (or tool name) rather than a fixed role string. */}<div className="ph-no-capture flex items-center gap-2">- {collapseControl ? (- <button- type="button"- onClick={collapseControl.onToggle}- aria-expanded={!collapseControl.isCollapsed}- aria-label={titleButtonLabel}- className="hover:text-foreground/80 flex items-center gap-1.5"- >- {titleContent}- </button>- ) : (- titleContent- )}+ {titleContent}</div><divclassName={cn(@@ -109,18 +66,6 @@ export function MarkdownJsonViewHeader({"opacity-0 transition-opacity group-hover/iosection:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100",)}>- {collapseControl ? (- <Button- variant="ghost"- size="xs"- type="button"- onClick={collapseControl.onToggle}- aria-label={collapseLabel}- className="text-muted-foreground hover:bg-border w-fit text-xs"- >- {collapseControl.isCollapsed ? "Expand" : "Collapse"}- </Button>- ) : null}{controlButtons}{!hideCopyButton && (<Buttondiff --git a/web/src/components/ui/MarkdownViewer.tsx b/web/src/components/ui/MarkdownViewer.tsxindex 3a624cdff2..7901e75cc2 100644--- a/web/src/components/ui/MarkdownViewer.tsx+++ b/web/src/components/ui/MarkdownViewer.tsx@@ -568,14 +568,6 @@ export function MarkdownView({handleOnCopy={handleOnCopy}hoverRevealControlscontrolButtons={controlButtons}- collapseControl={- shouldBeCollapsible- ? {- isCollapsed,- onToggle: () => toggleCollapsed("header"),- }- : undefined- }/></>) : null}diff --git a/web/src/components/ui/PrettyJsonView.tsx b/web/src/components/ui/PrettyJsonView.tsxindex 21f16cbbd0..f167365e3e 100644--- a/web/src/components/ui/PrettyJsonView.tsx+++ b/web/src/components/ui/PrettyJsonView.tsx@@ -19,7 +19,6 @@ import { copyTextToClipboard } from "@/src/utils/clipboard";import { JSONView } from "@/src/components/ui/CodeJsonViewer";import { Button } from "@/src/components/ui/button";import { useClickWithoutSelection } from "@/src/hooks/useClickWithoutSelection";-import { useCollapsibleSystemPrompt } from "@/src/hooks/useCollapsibleSystemPrompt";import {ChevronDown,ChevronRight,@@ -884,28 +883,6 @@ export function PrettyJsonView(props: {[parsedJson, largeStringValue, characterLimit],);- // Nested MarkdownView is rendered without a title (this view owns the- // header), so the header must host the same collapse control that- // MarkdownView would show when it has a title. Skip gated large strings:- // they render through LargeStringFallback, and splitting them for a- // preview would undo the main-thread guard that gate exists for.- const systemPromptCollapsibleContent =- largeStringValue !== null- ? ""- : typeof markdownContent === "string"- ? markdownContent- : typeof parsedJson === "string"- ? parsedJson- : "";- const {- shouldBeCollapsible: shouldCollapseSystemPrompt,- isCollapsed: isSystemPromptCollapsed,- toggleCollapsed: toggleSystemPromptCollapsed,- } = useCollapsibleSystemPrompt({- isSystemPrompt: Boolean(props.isSystemPrompt),- content: systemPromptCollapsibleContent,- });-const baseTableData = useMemo(() => {try {if (@@ -1450,16 +1427,6 @@ export function PrettyJsonView(props: {title={props.title}titleIcon={props.titleIcon}handleOnCopy={handleOnCopy}- collapseControl={- shouldCollapseSystemPrompt &&- isMarkdownMode &&- !shouldRenderStandaloneMedia- ? {- isCollapsed: isSystemPromptCollapsed,- onToggle: () => toggleSystemPromptCollapsed("header"),- }- : undefined- }inset={props.inset}hoverRevealControlscontrolButtons={diff --git a/web/src/features/traces/components/IOPreview/components/ChatMessage.clienttest.tsx b/web/src/features/traces/components/IOPreview/components/ChatMessage.clienttest.tsxindex e9a867fcec..7edb084829 100644--- a/web/src/features/traces/components/IOPreview/components/ChatMessage.clienttest.tsx+++ b/web/src/features/traces/components/IOPreview/components/ChatMessage.clienttest.tsx@@ -1,4 +1,4 @@-import { fireEvent, render, screen, within } from "@testing-library/react";+import { fireEvent, render, screen } from "@testing-library/react";import { vi } from "vitest";const { copyTextToClipboard } = vi.hoisted(() => ({@@ -116,8 +116,6 @@ describe("ChatMessage content modes", () => {// getByRole ignores elements hidden via display:none, so queries only see the// active render path (markdown vs json), even though ChatMessage mounts both.-// Header + inline controls share the same accessible name, so look them up-// as a set rather than assuming a single toggle.const expandButtons = () =>screen.queryAllByRole("button", { name: /expand system prompt/i });const collapseButtons = () =>@@ -125,15 +123,6 @@ const collapseButtons = () =>const expandButton = () => expandButtons()[0] ?? null;const collapseButton = () => collapseButtons()[0] ?? null;-const systemMessageHeader = () => {- const headers = screen- .getAllByText("system")- .map((node) => node.closest(".io-message-header"))- .filter((node): node is HTMLElement => node instanceof HTMLElement);- expect(headers.length).toBeGreaterThan(0);- return headers[0];-};-describe("ChatMessage system prompt collapse", () => {beforeEach(() => {vi.stubGlobal("localStorage", createMemoryStorage());@@ -146,17 +135,10 @@ describe("ChatMessage system prompt collapse", () => {content: longSystemPrompt,} as ChatMlMessage);- expect(expandButtons().length).toBeGreaterThan(0);- expect(- within(systemMessageHeader()).getAllByRole("button", {- name: /expand system prompt/i,- }).length,- ).toBeGreaterThan(0);- expect(- within(systemMessageHeader()).getByRole("button", {- name: /system, expand system prompt/i,- }),- ).toBeInTheDocument();+ // One control only, and it sits with the prompt body rather than being+ // duplicated into the message header.+ expect(expandButtons()).toHaveLength(1);+ expect(expandButtons()[0].closest(".io-message-header")).toBeNull();});it("collapses a long system message that carries a name", () => {@@ -192,7 +174,7 @@ describe("ChatMessage system prompt collapse", () => {expect(localStorage.getItem("collapseSystemPrompt")).toBe("false");});- it("respects a persisted expanded preference and does not force-collapse", () => {+ it("respects a persisted expanded preference and collapses back on click", () => {localStorage.setItem("collapseSystemPrompt", "false");renderChatMessage({@@ -200,42 +182,11 @@ describe("ChatMessage system prompt collapse", () => {content: longSystemPrompt,} as ChatMlMessage);- // rendered expanded, with the option to collapse still offered+ // rendered expanded, with a single collapse control still offeredexpect(expandButtons()).toHaveLength(0);- expect(collapseButtons().length).toBeGreaterThan(0);- });-- it("puts a collapse control on the system message header so it is reachable without scrolling", () => {- // The inline "Collapse system prompt" control lives after the prompt body,- // so an expanded long prompt hid it below the fold. The header must offer- // the same action.- localStorage.setItem("collapseSystemPrompt", "false");-- renderChatMessage({- role: "system",- content: longSystemPrompt,- } as ChatMlMessage);+ expect(collapseButtons()).toHaveLength(1);- expect(- within(systemMessageHeader()).getAllByRole("button", {- name: /collapse system prompt/i,- }).length,- ).toBeGreaterThan(0);- });-- it("collapses from the system message header", () => {- localStorage.setItem("collapseSystemPrompt", "false");-- renderChatMessage({- role: "system",- content: longSystemPrompt,- } as ChatMlMessage);-- fireEvent.click(- within(systemMessageHeader()).getAllByRole("button", {- name: /collapse system prompt/i,- })[0],- );+ fireEvent.click(collapseButton()!);expect(expandButtons().length).toBeGreaterThan(0);expect(localStorage.getItem("collapseSystemPrompt")).toBe("true");