diff --git a/.changeset/llm-badges-click-ui.md b/.changeset/llm-badges-click-ui.md new file mode 100644 index 0000000000..8a7d098518 --- /dev/null +++ b/.changeset/llm-badges-click-ui.md @@ -0,0 +1,6 @@ +--- +'@hyperdx/app': patch +--- + +feat: use the click-ui `Badge` for the model, provider, tool, agent, and chat +role badges in the LLM span panel, session drawer, and dashboard. diff --git a/packages/app/src/llm/__tests__/ChatMessageItem.test.tsx b/packages/app/src/llm/__tests__/ChatMessageItem.test.tsx new file mode 100644 index 0000000000..1856018564 --- /dev/null +++ b/packages/app/src/llm/__tests__/ChatMessageItem.test.tsx @@ -0,0 +1,44 @@ +import { screen } from '@testing-library/react'; + +import { ChatMessageItem } from '@/llm/components/ChatMessageItem'; + +// click-ui encodes state only in hashed CSS module class names, so the mock +// exposes the props as attributes to assert on. +jest.mock('@clickhouse/click-ui', () => ({ + ...jest.requireActual('@clickhouse/click-ui'), + Badge: ({ + text, + state, + 'data-testid': testId, + }: { + text: React.ReactNode; + state?: string; + 'data-testid'?: string; + }) => ( + + {text} + + ), +})); + +describe('ChatMessageItem', () => { + it.each([ + ['system', 'neutral'], + ['developer', 'neutral'], + ['user', 'info'], + ['Assistant', 'success'], + ['tool', 'warning'], + ['function', 'warning'], + ['other', 'neutral'], + ])('renders the %s role with the %s state', (role, badgeState) => { + renderWithMantine( + , + ); + + const badge = screen.getByTestId('llm-chat-message-role'); + expect(badge).toHaveTextContent(role.toLowerCase()); + expect(badge).toHaveAttribute('data-state', badgeState); + }); +}); diff --git a/packages/app/src/llm/__tests__/LLMSpanSubpanel.test.tsx b/packages/app/src/llm/__tests__/LLMSpanSubpanel.test.tsx new file mode 100644 index 0000000000..5258a9d859 --- /dev/null +++ b/packages/app/src/llm/__tests__/LLMSpanSubpanel.test.tsx @@ -0,0 +1,53 @@ +import { screen } from '@testing-library/react'; + +import { LLMSpanSubpanel } from '@/llm/components/LLMSpanSubpanel'; + +// click-ui encodes state only in hashed CSS module class names, so the mock +// exposes the props as attributes to assert on. +jest.mock('@clickhouse/click-ui', () => ({ + ...jest.requireActual('@clickhouse/click-ui'), + Badge: ({ text, state }: { text: React.ReactNode; state?: string }) => ( + + {text} + + ), +})); + +describe('LLMSpanSubpanel', () => { + it('renders a badge with a distinct state for each span attribute', () => { + renderWithMantine( + , + ); + + const badges = screen.getAllByTestId('badge'); + expect( + badges.map(b => [b.textContent, b.getAttribute('data-state')]), + ).toEqual([ + ['claude-fable-5', 'info'], + ['anthropic', 'neutral'], + ['chat', null], + ['get_weather', 'warning'], + ['planner', 'success'], + ]); + }); + + it('omits badges for missing attributes', () => { + renderWithMantine( + , + ); + + expect(screen.getAllByTestId('badge')).toHaveLength(1); + }); +}); diff --git a/packages/app/src/llm/components/ChatMessageItem.tsx b/packages/app/src/llm/components/ChatMessageItem.tsx index 800c7a0038..78a66cc862 100644 --- a/packages/app/src/llm/components/ChatMessageItem.tsx +++ b/packages/app/src/llm/components/ChatMessageItem.tsx @@ -1,7 +1,8 @@ import { useState } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; -import { Badge, Box, Code, Group, Paper, Text } from '@mantine/core'; +import { Badge, BadgeProps } from '@clickhouse/click-ui'; +import { Box, Code, Group, Paper, Text } from '@mantine/core'; import { IconChevronDown, IconChevronRight, @@ -10,15 +11,15 @@ import { import { ChatToolCall, ConversationMessage } from '@/llm/lib/types'; -// Categorical role → badge color. Chat roles are categories, not statuses, -// so plain Mantine palette colors are appropriate here. -const ROLE_COLORS: Record = { - system: 'gray', - developer: 'gray', - user: 'blue', - assistant: 'green', - tool: 'orange', - function: 'orange', +// Chat roles are categories, not statuses. click-ui only has semantic badge +// states, so these states are for color only and do not signal a problem. +const ROLE_BADGE_STATES: Record = { + system: 'neutral', + developer: 'neutral', + user: 'info', + assistant: 'success', + tool: 'warning', + function: 'warning', }; function tryPrettyJson(value: string): string { @@ -76,13 +77,11 @@ export function ChatMessageItem({ message }: { message: ConversationMessage }) { - {role} - + /> {message.name != null && ( {message.name} diff --git a/packages/app/src/llm/components/LLMSpanSubpanel.tsx b/packages/app/src/llm/components/LLMSpanSubpanel.tsx index 34d284bbb6..f3987d3a39 100644 --- a/packages/app/src/llm/components/LLMSpanSubpanel.tsx +++ b/packages/app/src/llm/components/LLMSpanSubpanel.tsx @@ -1,5 +1,6 @@ import { useMemo } from 'react'; -import { Badge, Group, Stack, Table, Text } from '@mantine/core'; +import { Badge } from '@clickhouse/click-ui'; +import { Group, Stack, Table, Text } from '@mantine/core'; import { IS_LLM_COST_ENABLED } from '@/config'; import { resolveSpanCostUsd } from '@/llm/lib/cost'; @@ -26,30 +27,16 @@ export function LLMSpanSubpanel({ info }: { info: LLMSpanInfo }) { return ( - {info.model != null && ( - - {info.model} - - )} + {info.model != null && } {info.provider != null && ( - - {info.provider} - - )} - {info.operation != null && ( - - {info.operation} - + )} + {info.operation != null && } {info.toolName != null && ( - - {info.toolName} - + )} {info.agentName != null && ( - - {info.agentName} - + )} diff --git a/packages/app/src/llm/dashboard/LLMDashboardPage.tsx b/packages/app/src/llm/dashboard/LLMDashboardPage.tsx index 12f4bef3a1..06f4bb7d20 100644 --- a/packages/app/src/llm/dashboard/LLMDashboardPage.tsx +++ b/packages/app/src/llm/dashboard/LLMDashboardPage.tsx @@ -9,11 +9,11 @@ import { useQueryStates, } from 'nuqs'; import { useForm, useWatch } from 'react-hook-form'; +import { Badge } from '@clickhouse/click-ui'; import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata'; import { SourceKind } from '@hyperdx/common-utils/dist/types'; import { Anchor, - Badge, Box, Breadcrumbs, Button, @@ -222,9 +222,7 @@ function LLMDashboardPage() { LLM - - Beta - + {row.model != null && ( - - {row.model} - + )} {row.toolName != null && ( - - {row.toolName} - + )} {row.totalTokens != null && row.totalTokens > 0 && (