🪢 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): tools list with a Called / Not called switch (#18909)
Trang Nguyenfaed32649fe7
diff --git a/web/src/components/design-system/Tabs/Tabs.tsx b/web/src/components/design-system/Tabs/Tabs.tsxindex 6495eb8164..edf1bd773c 100644--- a/web/src/components/design-system/Tabs/Tabs.tsx+++ b/web/src/components/design-system/Tabs/Tabs.tsx@@ -303,6 +303,8 @@ type TabsTriggerProps = {| {/** Preferred for plain-text trigger content. */label: string;+ /** Shown after the label in regular weight, e.g. "Called 6". */+ count?: number;/** Rich tooltip on the label; replaces the native title. */tooltip?: string;children?: never;@@ -310,6 +312,7 @@ type TabsTriggerProps = {}| {label?: never;+ count?: never;tooltip?: never;/** Rich-content escape hatch. */children: React.ReactNode;@@ -330,14 +333,16 @@ type TabsTriggerProps = {function TabsTrigger(props: TabsTriggerProps) {// Outside a Tabs.List, fall back to the underline look instead of crashing.const list = React.use(TabsListContext) ?? { look: "underline" as const };- const { children, disabled, icon, internal, label, title, tooltip } = props;+ const { children, count, disabled, icon, internal, label, title, tooltip } =+ props;const className = tabsTriggerVariants({ look: list.look, size: list.size });- const nativeTitle = tooltip ? undefined : (label ?? title);+ const nativeTitle = tooltip ? undefined : (labelText(label, count) ?? title);const content = (<TabsTriggerContenticon={icon}internal={internal}label={label}+ count={count}tooltip={tooltip}>{children}@@ -375,13 +380,14 @@ function TabsTrigger(props: TabsTriggerProps) {function TabsTriggerContent({children,+ count,icon: Icon,internal,label,tooltip,}: Pick<TabsTriggerProps,- "children" | "icon" | "internal" | "label" | "tooltip"+ "children" | "count" | "icon" | "internal" | "label" | "tooltip">) {return (<>@@ -389,7 +395,7 @@ function TabsTriggerContent({{label === undefined ? (children) : (- <TabsTriggerLabel label={label} tooltip={tooltip} />+ <TabsTriggerLabel label={label} count={count} tooltip={tooltip} />)}{/* In a tight row the badge gives way before the label. */}{internal ? (@@ -403,12 +409,25 @@ function TabsTriggerContent({function TabsTriggerLabel({label,+ count,tooltip,-}: Pick<TabsTriggerProps, "tooltip"> & { label: string }) {+}: Pick<TabsTriggerProps, "count" | "tooltip"> & { label: string }) {+ const text = (+ <>+ {label}+ {count !== undefined ? (+ <span className="font-normal tabular-nums"> {count}</span>+ ) : null}+ </>+ );+if (!tooltip) {return (- <span className={tabsTriggerLabelClassName} title={label}>- {label}+ <span+ className={tabsTriggerLabelClassName}+ title={labelText(label, count)}+ >+ {text}</span>);}@@ -417,13 +436,18 @@ function TabsTriggerLabel({<Tooltip label={tooltip}>{({ getTriggerProps }) => (<span {...getTriggerProps()} className={tabsTriggerLabelClassName}>- {label}+ {text}</span>)}</Tooltip>);}+function labelText(label: string | undefined, count: number | undefined) {+ if (label === undefined || count === undefined) return label;+ return `${label} ${count}`;+}+function TabsInternalBadge() {return <Badge text="Internal" color="yellow" size="sm" />;}@@ -442,7 +466,9 @@ function TabsOverflowList({const measureKey = JSON.stringify(triggers.map((trigger) => [trigger.props.value,- trigger.props.label ?? trigger.props.title ?? null,+ labelText(trigger.props.label, trigger.props.count) ??+ trigger.props.title ??+ null,]),);const { availableRef, measureRef, visibleIndices } = useTabsOverflow<@@ -488,6 +514,7 @@ function TabsOverflowList({icon={trigger.props.icon}internal={trigger.props.internal}label={trigger.props.label}+ count={trigger.props.count}>{trigger.props.children}</TabsTriggerContent>@@ -520,7 +547,7 @@ function TabsOverflowList({id: trigger.props.value,onClick: () => selectFromMenu(trigger.props.value),title:- trigger.props.label ??+ labelText(trigger.props.label, trigger.props.count) ??trigger.props.title ??trigger.props.value,tooltip: trigger.props.tooltip,diff --git a/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsx b/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsxindex 4c988b55ad..76a5935d8b 100644--- a/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsx+++ b/web/src/features/traces/components/IOPreview/IOPreviewPretty.tsx@@ -214,7 +214,6 @@ export function IOPreviewPretty({toolCallCounts,toolCallsByName,messageToToolCallNumbers,- toolNameToDefinitionNumber,inputMessageCount,} = parserResult;@@ -298,7 +297,6 @@ export function IOPreviewPretty({tools={allTools}toolCallCounts={toolCallCounts}toolCallsByName={toolCallsByName}- toolNameToDefinitionNumber={toolNameToDefinitionNumber}/>) : null}diff --git a/web/src/features/traces/components/IOPreview/components/SectionToolDefinitions.tsx b/web/src/features/traces/components/IOPreview/components/SectionToolDefinitions.tsxindex 717504c3b0..336ec125ff 100644--- a/web/src/features/traces/components/IOPreview/components/SectionToolDefinitions.tsx+++ b/web/src/features/traces/components/IOPreview/components/SectionToolDefinitions.tsx@@ -9,33 +9,23 @@ export interface SectionToolDefinitionsProps {tools: ToolDefinition[];toolCallCounts: Map<string, number>;toolCallsByName: Map<string, ToolCallInvocation[]>;- toolNameToDefinitionNumber: Map<string, number>;}/**- * SectionToolDefinitions renders tool definition cards at the top of IOPreview.- *- * Shows available tools with their call counts and definition numbers.+ * SectionToolDefinitions renders the tool definitions section at the top of IOPreview.*/export function SectionToolDefinitions({tools,toolCallCounts,toolCallsByName,- toolNameToDefinitionNumber,}: SectionToolDefinitionsProps) {return (- <div className="border-border mb-4 border-b pb-4">- <div className="io-message-header px-1 py-1 text-base font-bold capitalize">- Tools- </div>- {tools.length > 0 && (- <ToolCallDefinitionCard- tools={tools}- toolCallCounts={toolCallCounts}- toolCallsByName={toolCallsByName}- toolNameToDefinitionNumber={toolNameToDefinitionNumber}- />- )}+ <div className="mb-4 pb-4">+ <ToolCallDefinitionCard+ tools={tools}+ toolCallCounts={toolCallCounts}+ toolCallsByName={toolCallsByName}+ /></div>);}diff --git a/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.clienttest.tsx b/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.clienttest.tsxindex bf437ee133..2aec2f02f3 100644--- a/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.clienttest.tsx+++ b/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.clienttest.tsx@@ -1,5 +1,5 @@/* eslint-disable @repo/prefer-stories-over-client-tests */-import { fireEvent, render, screen } from "@testing-library/react";+import { fireEvent, render, screen, within } from "@testing-library/react";import { vi } from "vitest";import {@@ -35,26 +35,21 @@ const makeTool = (name: string): ToolDefinition => ({function renderTools({calledToolCount,- availableToolCount,+ notCalledToolCount,}: {calledToolCount: number;- availableToolCount: number;+ notCalledToolCount: number;}) {const calledTools = Array.from({ length: calledToolCount }, (_, index) =>makeTool(`called_tool_${index + 1}`),);- const availableTools = Array.from(- { length: availableToolCount },- (_, index) => makeTool(`available_tool_${index + 1}`),+ const notCalledTools = Array.from(+ { length: notCalledToolCount },+ (_, index) => makeTool(`not_called_tool_${index + 1}`),);- const tools = [...calledTools, ...availableTools];+ const tools = [...calledTools, ...notCalledTools];const toolCallCounts = new Map<string, number>();const toolCallsByName = new Map<string, ToolCallInvocation[]>();- const toolNameToDefinitionNumber = new Map<string, number>();-- tools.forEach((tool, index) => {- toolNameToDefinitionNumber.set(tool.name, index + 1);- });calledTools.forEach((tool, index) => {toolCallCounts.set(tool.name, 1);@@ -73,88 +68,120 @@ function renderTools({tools={tools}toolCallCounts={toolCallCounts}toolCallsByName={toolCallsByName}- toolNameToDefinitionNumber={toolNameToDefinitionNumber}/>,);}+// Row buttons are named "N.<tool name>"; strip the number and match the name exactly.+const rowFor = (toolName: string) =>+ screen.queryByRole("button", {+ name: (accessibleName) =>+ accessibleName.replace(/^\d+\.\s*/, "") === toolName,+ });+const rowNumberOf = (toolName: string) =>+ within(rowFor(toolName)!).getByText(/^\d+\.$/).textContent;+describe("ToolCallDefinitionCard", () => {beforeEach(() => {vi.stubGlobal("localStorage", createMemoryStorage());vi.stubGlobal("sessionStorage", createMemoryStorage());});- it("renders up to five called tools individually", () => {- renderTools({ calledToolCount: 5, availableToolCount: 0 });+ it("starts long lists collapsed and keeps the user's choice for the session", () => {+ const first = renderTools({ calledToolCount: 2, notCalledToolCount: 4 });+ const header = screen.getByRole("button", { name: "Tools" });- expect(- screen.queryByRole("button", { name: /tools were called/i }),- ).not.toBeInTheDocument();- expect(screen.getByText(/called_tool_1/)).toBeInTheDocument();- expect(screen.getByText(/called_tool_5/)).toBeInTheDocument();+ expect(header).toHaveAttribute("aria-expanded", "false");+ expect(rowFor("called_tool_1")).not.toBeInTheDocument();+ expect(screen.queryByRole("tab")).not.toBeInTheDocument();++ fireEvent.click(header);+ expect(header).toHaveAttribute("aria-expanded", "true");+ expect(rowFor("called_tool_1")).toBeInTheDocument();+ first.unmount();++ renderTools({ calledToolCount: 2, notCalledToolCount: 4 });+ expect(screen.getByRole("button", { name: "Tools" })).toHaveAttribute(+ "aria-expanded",+ "true",+ );+ expect(rowFor("called_tool_1")).toBeInTheDocument();});- it("collapses more than five called tools and expands them on click", () => {- renderTools({ calledToolCount: 6, availableToolCount: 0 });+ it("starts short lists expanded", () => {+ renderTools({ calledToolCount: 2, notCalledToolCount: 3 });+ expect(screen.getByRole("button", { name: "Tools" })).toHaveAttribute(+ "aria-expanded",+ "true",+ );+ });++ it("shows the Called / Not called switch only when both sides have tools", () => {+ const both = renderTools({ calledToolCount: 2, notCalledToolCount: 3 });+ expect(+ screen.getByRole("tab", { name: /^Called\s*2$/ }),+ ).toBeInTheDocument();expect(- screen.getByRole("button", { name: /6 tools were called/i }),+ screen.getByRole("tab", { name: /^Not called\s*3$/ }),).toBeInTheDocument();- expect(screen.queryByText(/called_tool_1/)).not.toBeInTheDocument();+ both.unmount();- fireEvent.click(- screen.getByRole("button", { name: /6 tools were called/i }),- );+ const noneCalled = renderTools({+ calledToolCount: 0,+ notCalledToolCount: 3,+ });+ expect(screen.queryByRole("tab")).not.toBeInTheDocument();+ expect(rowFor("not_called_tool_3")).toBeInTheDocument();+ noneCalled.unmount();- expect(screen.getByText(/called_tool_1/)).toBeInTheDocument();- expect(screen.getByText(/called_tool_6/)).toBeInTheDocument();+ renderTools({ calledToolCount: 2, notCalledToolCount: 0 });+ expect(screen.queryByRole("tab")).not.toBeInTheDocument();+ expect(rowFor("called_tool_2")).toBeInTheDocument();});- it("persists called tool group expansion in session storage", () => {- const { unmount } = renderTools({- calledToolCount: 6,- availableToolCount: 0,- });+ it("defaults to the Called tab", () => {+ renderTools({ calledToolCount: 2, notCalledToolCount: 3 });- fireEvent.click(- screen.getByRole("button", { name: /6 tools were called/i }),+ expect(screen.getByRole("tab", { name: /^Called\s*2$/ })).toHaveAttribute(+ "aria-selected",+ "true",);- unmount();+ expect(rowFor("called_tool_1")).toBeInTheDocument();+ expect(rowFor("not_called_tool_1")).not.toBeInTheDocument();+ });- renderTools({ calledToolCount: 6, availableToolCount: 0 });+ it("numbers each tab from 1", () => {+ renderTools({ calledToolCount: 2, notCalledToolCount: 3 });- expect(screen.getByText(/called_tool_1/)).toBeInTheDocument();- });+ expect(rowNumberOf("called_tool_1")).toBe("1.");- it("renders up to three available tools individually", () => {- renderTools({ calledToolCount: 0, availableToolCount: 3 });+ fireEvent.mouseDown(screen.getByRole("tab", { name: /^Not called\s*3$/ }), {+ button: 0,+ });- expect(- screen.queryByRole("button", {- name: /available tools were not called/i,- }),- ).not.toBeInTheDocument();- expect(screen.getByText(/available_tool_1/)).toBeInTheDocument();- expect(screen.getByText(/available_tool_3/)).toBeInTheDocument();+ expect(rowFor("called_tool_1")).not.toBeInTheDocument();+ expect(rowNumberOf("not_called_tool_1")).toBe("1.");+ expect(rowNumberOf("not_called_tool_3")).toBe("3.");});- it("collapses more than three available tools and expands them on click", () => {- renderTools({ calledToolCount: 0, availableToolCount: 4 });+ it("toggles a row's details on click", () => {+ renderTools({ calledToolCount: 1, notCalledToolCount: 0 });+ const row = rowFor("called_tool_1")!;+ expect(row).toHaveAttribute("aria-expanded", "false");expect(- screen.getByRole("button", {- name: /4 available tools were not called/i,- }),- ).toBeInTheDocument();- expect(screen.queryByText(/available_tool_1/)).not.toBeInTheDocument();+ screen.queryByText("called_tool_1 description"),+ ).not.toBeInTheDocument();- fireEvent.click(- screen.getByRole("button", {- name: /4 available tools were not called/i,- }),- );+ fireEvent.click(row);+ expect(row).toHaveAttribute("aria-expanded", "true");+ expect(screen.getByText("called_tool_1 description")).toBeInTheDocument();- expect(screen.getByText(/available_tool_1/)).toBeInTheDocument();- expect(screen.getByText(/available_tool_4/)).toBeInTheDocument();+ fireEvent.click(row);+ expect(row).toHaveAttribute("aria-expanded", "false");+ expect(+ screen.queryByText("called_tool_1 description"),+ ).not.toBeInTheDocument();});});diff --git a/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.stories.tsx b/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.stories.tsxindex 12fa07e117..4ae94ab36f 100644--- a/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.stories.tsx+++ b/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.stories.tsx@@ -1,4 +1,4 @@-import { expect, userEvent, waitFor, within } from "storybook/test";+import { expect, userEvent, within } from "storybook/test";import preview from "../../../../../../.storybook/preview";import {@@ -51,7 +51,6 @@ export const Default = meta.story({tools: baseTools,toolCallCounts: new Map([["search_docs", 0]]),toolCallsByName: new Map(),- toolNameToDefinitionNumber: new Map([["search_docs", 1]]),},});@@ -60,7 +59,6 @@ export const Called = meta.story({tools: baseTools,toolCallCounts: new Map([["search_docs", 1]]),toolCallsByName: baseToolCalls,- toolNameToDefinitionNumber: new Map([["search_docs", 1]]),},});@@ -122,11 +120,6 @@ export const MultipleTools = meta.story({],],]),- toolNameToDefinitionNumber: new Map([- ["search_docs", 1],- ["create_ticket", 2],- ["notify_team", 3],- ]),},});@@ -173,16 +166,6 @@ export const WithLongToolNames = meta.story({],],]),- toolNameToDefinitionNumber: new Map([- [- "search_enterprise_customer_documentation_for_multistep_api_rate_limit_troubleshooting_and_backoff_recommendations",- 1,- ],- [- "create_cross_functional_incident_escalation_ticket_with_customer_context_and_internal_follow_up_requirements",- 2,- ],- ]),},});@@ -208,30 +191,82 @@ const manyToolNames = [];const calledNames = new Set(manyToolNames.slice(12));-/** Both groups collapse: more than five called, more than three not called. */+const TOOLS_COLLAPSED_KEY = "toolsSectionCollapsed";++/** Opens the section so stories with many tools show their rows. */+const startExpanded = () => {+ sessionStorage.setItem(TOOLS_COLLAPSED_KEY, "false");+ return () => sessionStorage.removeItem(TOOLS_COLLAPSED_KEY);+};++/** Both sides have tools, so the header shows the Called / Not called switch. */export const ManyTools = meta.story({+ beforeEach: startExpanded,args: {tools: manyToolNames.map((name) => ({ name })),toolCallCounts: new Map(manyToolNames.map((name) => [name, calledNames.has(name) ? 1 : 0]),),toolCallsByName: new Map(),- toolNameToDefinitionNumber: new Map(- manyToolNames.map((name, index) => [name, index + 1]),- ),},});-export const NotCalledListOpen = meta.story({- name: "(Test) Not Called List Open",+/** Nothing called: no switch, one muted list. */+export const NoneCalled = meta.story({+ beforeEach: startExpanded,+ args: {+ tools: manyToolNames.map((name) => ({ name })),+ toolCallCounts: new Map(manyToolNames.map((name) => [name, 0])),+ toolCallsByName: new Map(),+ },+});++/** Everything called: no switch, one list. */+export const AllCalled = meta.story({+ beforeEach: startExpanded,+ args: {+ tools: manyToolNames.map((name) => ({ name })),+ toolCallCounts: new Map(manyToolNames.map((name) => [name, 1])),+ toolCallsByName: new Map(),+ },+});++export const NotCalledTab = meta.story({+ name: "(Test) Not Called Tab",+ beforeEach: startExpanded,args: ManyTools.input.args,play: async ({ canvasElement }) => {const canvas = within(canvasElement);- await userEvent.hover(- canvas.getByRole("button", { name: /available tools were not called/i }),+ await expect(+ canvas.getByRole("tab", { name: /^Called\s*6$/ }),+ ).toHaveAttribute("aria-selected", "true");+ await userEvent.click(+ canvas.getByRole("tab", { name: /^Not called\s*12$/ }),);- const body = within(canvasElement.ownerDocument.body);- await waitFor(() => expect(body.getByText("Not called")).toBeVisible());- await expect(body.queryByText("not called")).toBeNull();+ const firstRow = canvas.getByRole("button", {+ name: /langfuse_getPrompt$/,+ });+ await expect(within(firstRow).getByText("1.")).toBeVisible();+ await expect(canvas.queryByText("langfuse_getSession")).toBeNull();+ },+});++/** More than five tools: the section starts collapsed to its header. */+export const CollapsedByDefault = meta.story({+ name: "(Test) Collapsed By Default",+ beforeEach: () => sessionStorage.removeItem(TOOLS_COLLAPSED_KEY),+ args: ManyTools.input.args,+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const header = canvas.getByRole("button", { name: "Tools" });+ await expect(header).toHaveAttribute("aria-expanded", "false");+ await expect(canvas.queryByRole("tab")).toBeNull();++ await userEvent.click(header);+ await expect(header).toHaveAttribute("aria-expanded", "true");+ await expect(+ canvas.getByRole("tab", { name: /^Called\s*6$/ }),+ ).toBeVisible();+ sessionStorage.removeItem(TOOLS_COLLAPSED_KEY);},});diff --git a/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.tsx b/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.tsxindex a89de446fa..2238b5631f 100644--- a/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.tsx+++ b/web/src/features/traces/components/IOPreview/components/ToolCallDefinitionCard.tsx@@ -1,14 +1,11 @@/* eslint-disable @repo/no-style-props */-import { Wrench } from "lucide-react";-import { DropdownIndicator } from "@/src/components/design-system/DropdownIndicator/DropdownIndicator";-import { Badge } from "@/src/components/ui/badge";+import { ChevronDown, ChevronRight, Wrench } from "lucide-react";import { cn } from "@/src/utils/tailwind";import { PrettyJsonView } from "@/src/components/ui/PrettyJsonView";import { Tabs } from "@/src/components/design-system/Tabs/Tabs";import useLocalStorage from "@/src/components/useLocalStorage";import useSessionStorage from "@/src/components/useSessionStorage";import { useMemo, useState } from "react";-import { HoverCard } from "@/src/components/design-system/HoverCard/HoverCard";import type { ToolCallInvocation } from "../../../hooks/useChatMLParser";// Tool definition extracted from messages@@ -23,20 +20,13 @@ export interface ToolCallDefinitionCardProps {tools: ToolDefinition[];toolCallCounts: Map<string, number>;toolCallsByName?: Map<string, ToolCallInvocation[]>;- toolNameToDefinitionNumber?: Map<string, number>;className?: string;}-const CALLED_TOOLS_COLLAPSE_THRESHOLD = 5;-const AVAILABLE_TOOLS_COLLAPSE_THRESHOLD = 3;-const TOOL_GROUP_EXPANSION_STORAGE_KEY = "trace2-expansion:tools";+type ToolTab = "called" | "not-called";-type ToolGroupExpansionState = {- calledToolsExpanded: boolean;- availableToolsExpanded: boolean;-};--type ToolGroupKind = "called" | "available";+/** Above this many tools the section starts collapsed. */+const TOOLS_COLLAPSE_THRESHOLD = 5;function parseToolCallArguments(argumentsValue: unknown): unknown {if (typeof argumentsValue !== "string") {@@ -76,7 +66,7 @@ function ToolCallArgumentsList({className="min-w-0"><div className="mb-1.5 flex min-w-0 items-center justify-between gap-2">- <div className="text-foreground font-mono text-xs font-bold">+ <div className="text-muted-foreground text-xs font-bold">Call {toolCall.invocationNumber}</div>{toolCall.id && (@@ -106,360 +96,115 @@ function ToolCallArgumentsList({);}-function getStatusText(callCount: number) {- if (callCount === 0) return "not called";- if (callCount === 1) return "called";- return `called ${callCount}x`;-}--function ToolGroupHoverContent({- kind,- tools,- toolCallCounts,- toolNameToDefinitionNumber,-}: {- kind: ToolGroupKind;- tools: ToolDefinition[];- toolCallCounts: Map<string, number>;- toolNameToDefinitionNumber?: Map<string, number>;-}) {- const isNotCalledGroup = kind !== "called";- return (- <>- {isNotCalledGroup && (- <div className="flex items-center justify-between gap-2 border-b px-4 py-2">- <span className="text-foreground text-sm font-bold">Not called</span>- <span className="text-foreground-tertiary font-mono text-xs">- {tools.length} {tools.length === 1 ? "tool" : "tools"}- </span>- </div>- )}- <div className="flex flex-col gap-1 p-2">- {tools.map((tool, index) => {- const callCount = toolCallCounts.get(tool.name) ?? 0;- const toolDefinitionNumber = toolNameToDefinitionNumber?.get(- tool.name,- );-- return (- <div- key={`${tool.name}-${index}`}- className="flex min-w-0 items-center justify-between gap-2 rounded-sm px-2 py-1"- >- <div className="flex min-w-0 items-center gap-2">- <Wrench className="text-muted-foreground icon-base shrink-0" />- <span- className={cn(- "ph-no-capture text-foreground block truncate text-sm",- !isNotCalledGroup && "font-bold",- )}- title={tool.name}- >- {toolDefinitionNumber !== undefined && (- <span className="mr-1">{toolDefinitionNumber}.</span>- )}- {tool.name}- </span>- </div>- {!isNotCalledGroup && (- <Badge- variant={callCount > 0 ? undefined : "secondary"}- className={cn(- "shrink-0 text-xs font-bold",- callCount > 0 &&- "bg-light-green text-dark-green hover:bg-light-green border-transparent select-none",- )}- >- {getStatusText(callCount)}- </Badge>- )}- </div>- );- })}- </div>- </>- );-}--function ToolGroupSummary({- kind,- tools,- expanded,- onToggle,- toolCallCounts,- toolNameToDefinitionNumber,-}: {- kind: ToolGroupKind;- tools: ToolDefinition[];- expanded: boolean;- onToggle: () => void;- toolCallCounts: Map<string, number>;- toolNameToDefinitionNumber?: Map<string, number>;-}) {- const isCalledGroup = kind === "called";- const summaryText = isCalledGroup- ? `${tools.length} ${tools.length === 1 ? "tool was" : "tools were"} called`- : `${tools.length} available ${tools.length === 1 ? "tool was" : "tools were"} not called`;-- const summaryButton = (- <button- type="button"- className={cn(- "hover:bg-muted/20 flex w-full items-center justify-between gap-2 rounded-sm border px-3 py-2 text-left",- isCalledGroup &&- "border-dark-green/60 bg-accent-light-green hover:bg-accent-light-green/80",- )}- aria-expanded={expanded}- onClick={onToggle}- >- <div className="flex min-w-0 items-center gap-2">- <Wrench- className={cn(- "text-muted-foreground icon-base shrink-0",- isCalledGroup && "text-dark-green",- )}- />- <span- className={cn(- "truncate text-sm font-bold",- isCalledGroup ? "text-dark-green" : "text-foreground",- )}- title={summaryText}- >- {summaryText}- </span>- </div>- <div className="flex shrink-0 items-center gap-1.5">- <Badge- variant={isCalledGroup ? undefined : "secondary"}- className={cn(- "text-xs font-bold",- isCalledGroup &&- "bg-light-green text-dark-green hover:bg-light-green border-transparent select-none",- )}- >- {expanded ? "hide" : "show"}- </Badge>- {expanded ? (- <DropdownIndicator />- ) : (- <DropdownIndicator direction="right" />- )}- </div>- </button>- );-- if (expanded) {- return summaryButton;- }-- return (- <HoverCard- openDelay={200}- closeDelay={100}- placement="bottom-start"- sideOffset={6}- content={- <div className="max-h-96 w-80 max-w-[calc(100vw-2rem)] overflow-auto">- <ToolGroupHoverContent- kind={kind}- tools={tools}- toolCallCounts={toolCallCounts}- toolNameToDefinitionNumber={toolNameToDefinitionNumber}- />- </div>- }- >- {({ getTriggerProps }) => (- <div {...getTriggerProps()}>{summaryButton}</div>- )}- </HoverCard>- );-}--function ToolCallStatusBadge({- isCalled,- statusText,- toolCalls,-}: {- isCalled: boolean;- statusText: string;- toolCalls: ToolCallInvocation[];-}) {- const badge = (- <Badge- variant={isCalled ? undefined : "secondary"}- className={cn(- "text-xs font-bold whitespace-nowrap",- isCalled &&- "bg-light-green text-dark-green hover:bg-light-green border-transparent select-none",- )}- >- {statusText}- </Badge>- );-- if (!isCalled || toolCalls.length === 0) {- return badge;- }-- return (- <HoverCard- openDelay={200}- closeDelay={100}- placement="bottom-end"- sideOffset={6}- content={- <div className="max-h-96 w-96 max-w-[calc(100vw-2rem)] overflow-auto">- <div className="border-border border-b px-3 py-2">- <div className="text-foreground text-xs font-bold">- Tool call arguments- </div>- <div className="text-muted-foreground text-xs">- {toolCalls.length === 1 ? "1 call" : `${toolCalls.length} calls`}- </div>- </div>- <ToolCallArgumentsList toolCalls={toolCalls} className="p-3" />- </div>- }- >- {({ getTriggerProps }) => (- <div className="inline-flex" tabIndex={0} {...getTriggerProps()}>- {badge}- </div>- )}- </HoverCard>- );-}-function ToolDefinitionRow({tool,isExpanded,onToggle,- callCount,+ isCalled,toolCalls,- toolDefinitionNumber,+ rowNumber,currentView,setCurrentView,}: {tool: ToolDefinition;isExpanded: boolean;onToggle: () => void;- callCount: number;+ isCalled: boolean;toolCalls: ToolCallInvocation[];- toolDefinitionNumber?: number;+ rowNumber: number;currentView: "formatted" | "json";setCurrentView: (value: "formatted" | "json") => void;}) {- const isCalled = callCount > 0;- const statusText = getStatusText(callCount);+ const Caret = isExpanded ? ChevronDown : ChevronRight;return (- <div className="w-full overflow-hidden rounded-sm border">+ <div className="group/tool-row w-full"><buttontype="button"- className="hover:bg-muted/20 flex w-full cursor-pointer items-center justify-between gap-2 px-3 py-1.5 text-left"+ className={cn(+ "hover:bg-muted/20 flex w-full cursor-pointer items-center gap-2 py-1.5 text-left group-first/tool-row:pt-0",+ // Expanded details draw their own top border; keep the gap above it.+ !isExpanded && "group-last/tool-row:pb-0",+ )}onClick={onToggle}aria-expanded={isExpanded}>- <div className="flex min-w-0 items-center gap-2">- <Wrench className="text-muted-foreground icon-base shrink-0" />- <span- className="ph-no-capture text-foreground block truncate text-sm font-bold"- title={tool.name}- >- {toolDefinitionNumber !== undefined && (- <span className="mr-1">{toolDefinitionNumber}.</span>- )}- {tool.name}- </span>- </div>-- <div className="flex shrink-0 items-center gap-1.5">- <ToolCallStatusBadge- isCalled={isCalled}- statusText={statusText}- toolCalls={toolCalls}- />-- {isExpanded ? (- <DropdownIndicator />- ) : (- <DropdownIndicator direction="right" />+ <Caret+ className="icon-base text-icon-foreground shrink-0"+ aria-hidden+ />+ <Wrench className="text-muted-foreground icon-base shrink-0" />+ <span+ className={cn(+ "ph-no-capture block truncate text-sm",+ isCalled ? "text-foreground" : "text-muted-foreground",)}- </div>+ title={tool.name}+ >+ <span className="mr-1">{rowNumber}.</span>+ {tool.name}+ </span></button>{isExpanded && (- <div className="border-border bg-muted/30 relative border-t px-4 py-3">- <div className="absolute top-1 right-4">- <div className="h-fit py-0.5">- <Tabs- value={currentView}- onValueChange={(value) =>- setCurrentView(value as "formatted" | "json")- }- >- <Tabs.List variant="inset" size="sm">- <Tabs.Trigger value="formatted" label="Formatted" />- <Tabs.Trigger value="json" label="Raw" />- </Tabs.List>- </Tabs>- </div>- </div>-- {currentView === "formatted" && (- <div className="space-y-4">- {tool.description && (- <div>- <div className="text-muted-foreground mb-1.5 text-xs font-bold">- Description- </div>- <div className="ph-no-capture text-foreground text-sm">- {tool.description}- </div>+ // Indented to the tool name (caret + wrench + gaps).+ <div className="border-border border-t py-3 pl-11">+ <div className="space-y-4">+ {tool.description && (+ <div>+ <div className="text-muted-foreground mb-1.5 text-xs font-bold">+ Description</div>- )}+ <div className="ph-no-capture text-muted-foreground text-sm">+ {tool.description}+ </div>+ </div>+ )}- {tool.parameters && (- <div>- <div className="text-muted-foreground mb-1.5 text-xs font-bold">+ {tool.parameters && (+ <div>+ <div className="mb-1.5 flex items-center justify-between gap-2">+ <div className="text-muted-foreground text-xs font-bold">Parameters</div>- <PrettyJsonView- json={tool.parameters}- currentView="pretty"- codeClassName="text-xs"- />+ {/* Switches the parameters table only. */}+ <Tabs+ value={currentView}+ onValueChange={(value) =>+ setCurrentView(value as "formatted" | "json")+ }+ >+ <Tabs.List variant="inset" size="sm">+ <Tabs.Trigger value="formatted" label="Formatted" />+ <Tabs.Trigger value="json" label="Raw" />+ </Tabs.List>+ </Tabs></div>- )}+ <PrettyJsonView+ json={tool.parameters}+ currentView={currentView === "json" ? "json" : "pretty"}+ codeClassName="text-xs"+ />+ </div>+ )}- {toolCalls.length > 0 && (- <div>- <div className="text-muted-foreground mb-1.5 text-xs font-bold">- Tool call arguments- </div>- <ToolCallArgumentsList toolCalls={toolCalls} />+ {toolCalls.length > 0 && (+ <div>+ <div className="text-muted-foreground mb-1.5 text-xs font-bold">+ Tool call arguments</div>- )}-- {!tool.description &&- !tool.parameters &&- toolCalls.length === 0 && (- <div className="text-muted-foreground text-sm">- No additional details available- </div>- )}- </div>- )}+ <ToolCallArgumentsList toolCalls={toolCalls} />+ </div>+ )}- {currentView === "json" && (- <PrettyJsonView- json={tool}- currentView="json"- codeClassName="text-xs"- />- )}+ {!tool.description &&+ !tool.parameters &&+ toolCalls.length === 0 && (+ <div className="text-muted-foreground text-sm">+ No additional details available+ </div>+ )}+ </div></div>)}</div>@@ -467,129 +212,115 @@ function ToolDefinitionRow({}/**- * ToolCallDefinitionCard renders expandable cards for tool definitions.- *- * Features:- * - Accordion-style expansion (one tool at a time)- * - Status badges showing call count- * - Formatted/JSON view toggle for parameters- * - Definition numbers for reference+ * ToolCallDefinitionCard renders the Tools section: a header with a+ * collapse caret and a Called / Not called switch (only when both sides+ * have tools), and the active tab's tools as expandable rows numbered+ * from 1. Long lists start collapsed; the user's choice lasts the session.*/export function ToolCallDefinitionCard({tools,toolCallCounts,toolCallsByName,- toolNameToDefinitionNumber,className,}: ToolCallDefinitionCardProps) {const [expandedToolKey, setExpandedToolKey] = useState<string | null>(null);- const [toolGroupExpansion, setToolGroupExpansion] =- useSessionStorage<ToolGroupExpansionState>(- TOOL_GROUP_EXPANSION_STORAGE_KEY,- {- calledToolsExpanded: false,- availableToolsExpanded: false,- },- );+ const [activeTab, setActiveTab] = useState<ToolTab>("called");+ const [collapsedPreference, setCollapsedPreference] = useSessionStorage<+ boolean | null+ >("toolsSectionCollapsed", null);const [currentView, setCurrentView] = useLocalStorage<"formatted" | "json">("toolCallPillViewPreference","formatted",);- const { calledTools, availableTools } = useMemo(+ const { calledTools, notCalledTools } = useMemo(() =>tools.reduce((groups, tool) => {- const callCount = toolCallCounts.get(tool.name) ?? 0;- if (callCount > 0) {+ if ((toolCallCounts.get(tool.name) ?? 0) > 0) {groups.calledTools.push(tool);} else {- groups.availableTools.push(tool);+ groups.notCalledTools.push(tool);}return groups;},{calledTools: [] as ToolDefinition[],- availableTools: [] as ToolDefinition[],+ notCalledTools: [] as ToolDefinition[],},),[tools, toolCallCounts],);- const calledToolsShouldCollapse =- calledTools.length > CALLED_TOOLS_COLLAPSE_THRESHOLD;- const availableToolsShouldCollapse =- availableTools.length > AVAILABLE_TOOLS_COLLAPSE_THRESHOLD;- const showCalledTools =- !calledToolsShouldCollapse || toolGroupExpansion.calledToolsExpanded;- const showAvailableTools =- !availableToolsShouldCollapse || toolGroupExpansion.availableToolsExpanded;+ const hasSwitch = calledTools.length > 0 && notCalledTools.length > 0;+ const tabTools = activeTab === "called" ? calledTools : notCalledTools;+ const visibleTools = hasSwitch ? tabTools : tools;+ const isCollapsed =+ collapsedPreference ?? tools.length > TOOLS_COLLAPSE_THRESHOLD;+ const Caret = isCollapsed ? ChevronRight : ChevronDown;- const renderToolRows = (- toolsToRender: ToolDefinition[],- groupKind: ToolGroupKind,- ) =>- toolsToRender.map((tool, index) => {- const callCount = toolCallCounts.get(tool.name) || 0;- const toolCalls = toolCallsByName?.get(tool.name) ?? [];- const toolDefinitionNumber = toolNameToDefinitionNumber?.get(tool.name);- const toolKey = `${groupKind}-${tool.name}-${index}`;- const isExpanded = expandedToolKey === toolKey;-- return (- <ToolDefinitionRow- key={toolKey}- tool={tool}- isExpanded={isExpanded}- onToggle={() =>- setExpandedToolKey((current) =>- current === toolKey ? null : toolKey,- )- }- callCount={callCount}- toolCalls={toolCalls}- toolDefinitionNumber={toolDefinitionNumber}- currentView={currentView}- setCurrentView={setCurrentView}- />- );- });+ const handleCollapseToggle = () => setCollapsedPreference(!isCollapsed);return (- <div className={cn("flex flex-col gap-2", className)}>- {calledToolsShouldCollapse && (- <ToolGroupSummary- kind="called"- tools={calledTools}- expanded={toolGroupExpansion.calledToolsExpanded}- onToggle={() =>- setToolGroupExpansion((current) => ({- ...current,- calledToolsExpanded: !current.calledToolsExpanded,- }))- }- toolCallCounts={toolCallCounts}- toolNameToDefinitionNumber={toolNameToDefinitionNumber}- />- )}- {showCalledTools && renderToolRows(calledTools, "called")}-- {availableToolsShouldCollapse && (- <ToolGroupSummary- kind="available"- tools={availableTools}- expanded={toolGroupExpansion.availableToolsExpanded}- onToggle={() =>- setToolGroupExpansion((current) => ({- ...current,- availableToolsExpanded: !current.availableToolsExpanded,- }))- }- toolCallCounts={toolCallCounts}- toolNameToDefinitionNumber={toolNameToDefinitionNumber}- />+ <div className={cn("flex flex-col", className)}>+ <div className="io-message-header flex items-center justify-between gap-2 px-1 py-1">+ <button+ type="button"+ onClick={handleCollapseToggle}+ aria-expanded={!isCollapsed}+ className="focus-visible:ring-ring flex items-center gap-1.5 rounded-sm text-base font-bold focus-visible:ring-2 focus-visible:outline-hidden"+ >+ <Caret+ aria-hidden="true"+ className="icon-base text-icon-foreground shrink-0"+ />+ Tools+ </button>+ {hasSwitch && !isCollapsed && (+ <Tabs+ value={activeTab}+ onValueChange={(value) => setActiveTab(value as ToolTab)}+ >+ <Tabs.List variant="inset" size="sm">+ <Tabs.Trigger+ value="called"+ label="Called"+ count={calledTools.length}+ />+ <Tabs.Trigger+ value="not-called"+ label="Not called"+ count={notCalledTools.length}+ />+ </Tabs.List>+ </Tabs>+ )}+ </div>+ {!isCollapsed && (+ <div className="divide-border flex flex-col divide-y">+ {visibleTools.map((tool, index) => {+ const toolKey = `${activeTab}-${tool.name}-${index}`;++ return (+ <ToolDefinitionRow+ key={toolKey}+ tool={tool}+ isExpanded={expandedToolKey === toolKey}+ onToggle={() =>+ setExpandedToolKey((current) =>+ current === toolKey ? null : toolKey,+ )+ }+ isCalled={(toolCallCounts.get(tool.name) ?? 0) > 0}+ toolCalls={toolCallsByName?.get(tool.name) ?? []}+ rowNumber={index + 1}+ currentView={currentView}+ setCurrentView={setCurrentView}+ />+ );+ })}+ </div>)}- {showAvailableTools && renderToolRows(availableTools, "available")}</div>);}diff --git a/web/src/features/traces/hooks/useChatMLParser.clienttest.ts b/web/src/features/traces/hooks/useChatMLParser.clienttest.tsindex 073e9ea5df..e50b468a59 100644--- a/web/src/features/traces/hooks/useChatMLParser.clienttest.ts+++ b/web/src/features/traces/hooks/useChatMLParser.clienttest.ts@@ -232,7 +232,6 @@ describe("useChatMLParser", () => {toolCallCounts: new Map(),toolCallsByName: new Map(),messageToToolCallNumbers: new Map(),- toolNameToDefinitionNumber: new Map(),inputMessageCount: 0,};diff --git a/web/src/features/traces/hooks/useChatMLParser.ts b/web/src/features/traces/hooks/useChatMLParser.tsindex 99a33a4ad0..551b2dd155 100644--- a/web/src/features/traces/hooks/useChatMLParser.ts+++ b/web/src/features/traces/hooks/useChatMLParser.ts@@ -33,7 +33,6 @@ export interface ToolCallBookkeeping {toolCallCounts: Map<string, number>;toolCallsByName: Map<string, ToolCallInvocation[]>;messageToToolCallNumbers: Map<number, number[]>;- toolNameToDefinitionNumber: Map<string, number>;}// Result from ChatML parsing hook@@ -45,7 +44,6 @@ export interface ChatMLParserResult {toolCallCounts: Map<string, number>;toolCallsByName: Map<string, ToolCallInvocation[]>;messageToToolCallNumbers: Map<number, number[]>;- toolNameToDefinitionNumber: Map<string, number>;inputMessageCount: number;}@@ -169,17 +167,11 @@ export function computeToolCallBookkeeping(return callCountB - callCountA;});- const toolNameToDefinitionNumber = new Map<string, number>();- sortedTools.forEach((tool, index) => {- toolNameToDefinitionNumber.set(tool.name, index + 1);- });-return {allTools: sortedTools,toolCallCounts,toolCallsByName,messageToToolCallNumbers,- toolNameToDefinitionNumber,};}@@ -198,7 +190,6 @@ function emptyChatMLParserResult(): ChatMLParserResult {toolCallCounts: new Map(),toolCallsByName: new Map(),messageToToolCallNumbers: new Map(),- toolNameToDefinitionNumber: new Map(),inputMessageCount: 0,};}diff --git a/web/src/features/traces/parsers/toIOPreview.clienttest.ts b/web/src/features/traces/parsers/toIOPreview.clienttest.tsindex bad497b110..a09534b31b 100644--- a/web/src/features/traces/parsers/toIOPreview.clienttest.ts+++ b/web/src/features/traces/parsers/toIOPreview.clienttest.ts@@ -89,7 +89,6 @@ describe("toIOPreview", () => {]);expect(result.inputMessageCount).toBe(0);expect(result.toolCallCounts.get("search")).toBe(1);- expect(result.toolNameToDefinitionNumber.get("search")).toBe(1);});it("keeps unmatched tool results standalone and unanswered calls at null", () => {