🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: add speech recognition usage labels and icon (#19397)
Tsuki8bb802a8be18
diff --git a/locales/en-US/spend.json b/locales/en-US/spend.jsonindex 4067c894e4c..2d0fd42e853 100644--- a/locales/en-US/spend.json+++ b/locales/en-US/spend.json@@ -7,7 +7,9 @@"duration.stage.firstToken": "First Token","duration.stage.start": "Start","table.agentShareDesc": "Every model call a visitor of this share triggered, billed to your account.",+ "table.billableSeconds": "{{count}} s","table.columns.TTFT.tooltip": "Time To First Token, unit: seconds",+ "table.columns.billableDuration": "Billable Duration","table.columns.duration": "Duration","table.columns.model": "Model","table.columns.spend": "Credits",@@ -37,6 +39,7 @@"table.columns.type.enums.chat": "Text Generation","table.columns.type.enums.embedding": "Embedding","table.columns.type.enums.imageGeneration": "Image Generation",+ "table.columns.type.enums.speechRecognition": "Voice Transcription","table.columns.type.enums.videoGeneration": "Video Generation","table.columns.type.title": "Type","table.desc": "Details of credit usage for text generation, embedding, image generation, etc.",diff --git a/locales/zh-CN/spend.json b/locales/zh-CN/spend.jsonindex cd51564b775..8c9525d6f87 100644--- a/locales/zh-CN/spend.json+++ b/locales/zh-CN/spend.json@@ -7,7 +7,9 @@"duration.stage.firstToken": "首个令牌","duration.stage.start": "开始","table.agentShareDesc": "访客通过这个分享触发的每一次模型调用,费用记在你的账户上。",+ "table.billableSeconds": "{{count}} 秒","table.columns.TTFT.tooltip": "首令牌时间,单位:秒",+ "table.columns.billableDuration": "计费时长","table.columns.duration": "耗时","table.columns.model": "模型","table.columns.spend": "消耗积分",@@ -37,6 +39,7 @@"table.columns.type.enums.chat": "文本生成","table.columns.type.enums.embedding": "嵌入","table.columns.type.enums.imageGeneration": "图像生成",+ "table.columns.type.enums.speechRecognition": "语音转写","table.columns.type.enums.videoGeneration": "视频生成","table.columns.type.title": "类型","table.desc": "展示文本生成、嵌入、图像生成等功能的计算积分使用详情。",diff --git a/packages/locales/src/default/spend.ts b/packages/locales/src/default/spend.tsindex 84148363f80..8975dec7a3b 100644--- a/packages/locales/src/default/spend.ts+++ b/packages/locales/src/default/spend.ts@@ -7,6 +7,8 @@ export default {'duration.stage.firstToken': 'First Token','duration.stage.start': 'Start','table.columns.TTFT.tooltip': 'Time To First Token, unit: seconds',+ 'table.billableSeconds': '{{count}} s',+ 'table.columns.billableDuration': 'Billable Duration','table.columns.duration': 'Duration','table.columns.model': 'Model','table.columns.spend': 'Credits',@@ -36,6 +38,7 @@ export default {'table.columns.type.enums.chat': 'Text Generation','table.columns.type.enums.embedding': 'Embedding','table.columns.type.enums.imageGeneration': 'Image Generation',+ 'table.columns.type.enums.speechRecognition': 'Voice Transcription','table.columns.type.enums.videoGeneration': 'Video Generation','table.columns.type.title': 'Type','table.agentShareDesc':diff --git a/src/components/SpendType/index.tsx b/src/components/SpendType/index.tsxindex 6010db3027e..d4d72939dda 100644--- a/src/components/SpendType/index.tsx+++ b/src/components/SpendType/index.tsx@@ -1,6 +1,6 @@import { Icon, Tooltip } from '@lobehub/ui';import { createStaticStyles } from 'antd-style';-import { CircleDotDashed, Database, ImagePlus, MessageSquareText, Video } from 'lucide-react';+import { CircleDotDashed, Database, ImagePlus, MessageSquareText, Mic, Video } from 'lucide-react';import { memo, type ReactNode } from 'react';const styles = createStaticStyles(({ css, cssVar }) => ({@@ -13,12 +13,16 @@ const styles = createStaticStyles(({ css, cssVar }) => ({imageGeneration: css`color: ${cssVar.colorSuccess};`,+ speechRecognition: css`+ color: ${cssVar.colorInfo};+ `,videoGeneration: css`color: ${cssVar.colorWarning};`,}));-export type SpendTypeValue = 'chat' | 'embedding' | 'imageGeneration' | 'videoGeneration';+export type SpendTypeValue =+ 'chat' | 'embedding' | 'imageGeneration' | 'speechRecognition' | 'videoGeneration';interface SpendTypeProps {/** The readable label — shown on hover, since the cell itself is icon-only. */@@ -37,6 +41,9 @@ const getIcon = (type: string) => {case 'imageGeneration': {return ImagePlus;}+ case 'speechRecognition': {+ return Mic;+ }case 'videoGeneration': {return Video;}diff --git a/src/features/Settings/stats/features/usage/UsageTable.test.tsx b/src/features/Settings/stats/features/usage/UsageTable.test.tsxindex 915db8b4d8b..d26dd02b2c9 100644--- a/src/features/Settings/stats/features/usage/UsageTable.test.tsx+++ b/src/features/Settings/stats/features/usage/UsageTable.test.tsx@@ -1,14 +1,22 @@/*** @vitest-environment happy-dom*/+import { TooltipGroup } from '@lobehub/ui';import { render, screen } from '@testing-library/react';import userEvent from '@testing-library/user-event';+import { createInstance } from 'i18next';import type { ReactNode } from 'react';+import { I18nextProvider } from 'react-i18next';import { MemoryRouter } from 'react-router';import { describe, expect, it, vi } from 'vitest';+import spend from '@/locales/default/spend';++import zhSpend from '../../../../../../locales/zh-CN/spend.json';import UsageTable from './UsageTable';+vi.unmock('react-i18next');+vi.mock('@/components/LobeIcons', () => ({ProviderIcon: ({ provider }: { provider: string }) => <span>{provider}</span>,}));@@ -24,7 +32,7 @@ const rows = Array.from({ length: 12 }, (_, index) => ({totalTokens: index * 2,tps: 1,ttft: 1,- type: 'chat',+ type: index === 0 ? 'speechRecognition' : 'chat',}));vi.mock('@/libs/swr', () => ({@@ -35,11 +43,23 @@ vi.mock('@/services/usage', () => ({usageService: { findByMonth: vi.fn() },}));-// The rows on screen are the assertion, so the table only has to report which-// slice it was handed.+// Keep pagination lightweight while exercising the actual type column renderer.vi.mock('@/components/InlineTable', () => ({- default: ({ dataSource }: { dataSource?: { id: string }[] }) => (- <div data-testid="rows">{dataSource?.map((row) => row.id).join(',')}</div>+ default: ({+ columns,+ dataSource,+ }: {+ columns: { dataIndex: string; render?: (value: string) => ReactNode }[];+ dataSource?: { id: string; type: string }[];+ }) => (+ <div>+ <div data-testid="rows">{dataSource?.map((row) => row.id).join(',')}</div>+ {dataSource?.map((row) => (+ <div data-testid={`type-${row.id}`} key={row.id}>+ {columns.find((column) => column.dataIndex === 'type')?.render?.(row.type)}+ </div>+ ))}+ </div>),}));@@ -74,6 +94,32 @@ const renderTable = () =>);describe('UsageTable', () => {+ it.each([+ ['en-US', 'Voice Transcription'],+ ['zh-CN', '语音转写'],+ ])('renders the speech-recognition icon and label in %s', async (lng, label) => {+ const i18n = createInstance();+ await i18n.init({+ lng,+ resources: { 'en-US': { spend }, 'zh-CN': { spend: zhSpend } },+ });+ render(+ <I18nextProvider i18n={i18n}>+ <TooltipGroup popupContainer={document.body}>+ <MemoryRouter>+ <UsageTable />+ </MemoryRouter>+ </TooltipGroup>+ </I18nextProvider>,+ );++ const cell = screen.getByTestId('type-row-1');+ expect(cell.querySelector('svg.lucide-mic')).toBeInTheDocument();+ expect(cell.querySelector('svg.lucide-circle-dot-dashed')).not.toBeInTheDocument();+ await userEvent.hover(cell.querySelector('svg')!);+ expect(await screen.findByText(label)).toBeInTheDocument();+ });+it('moves to the next page when only the page changes', async () => {renderTable();expect(screen.getByTestId('rows')).toHaveTextContent('row-1,row-2,row-3,row-4,row-5');