Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): hide prices from model menu (#734)

bobo6f92004061c8
diff --git a/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts b/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts
index 7ae6b84187..6e2c7c5552 100644
--- a/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts
+++ b/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts
@@ -359,9 +359,10 @@ describe('ModelSelector trigger variants', () => {
expect(modelListMaxHeightForRows()).toBeUndefined();
expect(modelListMaxHeightForRows(Number.NaN)).toBeUndefined();
expect(modelListMaxHeightForRows(Number.POSITIVE_INFINITY)).toBeUndefined();
- expect(modelListMaxHeightForRows(0)).toBe(44);
- expect(modelListMaxHeightForRows(6)).toBe(274);
- expect(modelListMaxHeightForRows(7)).toBe(300);
+ expect(modelListMaxHeightForRows(0)).toBe(36);
+ expect(modelListMaxHeightForRows(6)).toBe(226);
+ expect(modelListMaxHeightForRows(7)).toBe(264);
+ expect(modelListMaxHeightForRows(8)).toBe(300);
expect(modelListMaxHeightForRows(100)).toBe(300);
});
@@ -991,7 +992,7 @@ describe('ModelSelector trigger variants', () => {
expect(screen.getByTestId('model-options-popover').className).toContain('z-[10020]');
});
- it('keeps non-Gateway prices in their source currency without an approximate marker', () => {
+ it('keeps non-Gateway prices in model details without repeating them in the primary row', () => {
vi.useFakeTimers();
render(
React.createElement(ModelSelectorContent, {
@@ -1016,7 +1017,7 @@ describe('ModelSelector trigger variants', () => {
expect(within(options).getByText('Source: Anthropic')).toBeTruthy();
expect(within(options).getByText('200K context')).toBeTruthy();
const priceTitle = within(options).getByText('newChat.modelSelector.pricing.title');
- expect(row.textContent).toContain('$3 / $15');
+ expect(row.textContent).not.toContain('$3 / $15');
expect(row.textContent).not.toContain('¥');
expect(row.textContent).not.toContain('≈');
expect(within(options).getByText('$3')).toBeTruthy();
@@ -1051,7 +1052,41 @@ describe('ModelSelector trigger variants', () => {
vi.useRealTimers();
});
- it('keeps discounted Gateway prices aligned between the row and model details', () => {
+ it('keeps non-price access labels in the primary model row', () => {
+ providersRef.providers = [
+ {
+ ...(providersRef.DEFAULT_PROVIDERS[0] as Record<string, unknown>),
+ access: { kind: 'subscription', product: 'Claude Pro' },
+ },
+ ];
+
+ try {
+ render(
+ React.createElement(ModelSelectorContent, {
+ modelId: 'claude-opus-4-8',
+ effort: 'high',
+ onModelChange: vi.fn(),
+ onEffortChange: vi.fn(),
+ vendorKey: 'cc',
+ currentProviderId: 'anthropic',
+ onProviderChange: vi.fn(),
+ }),
+ );
+
+ const row = screen.getByRole('option', { name: /Opus 4\.8/ });
+ const tags = row.querySelector('[data-model-tags]');
+ expect(tags).not.toBeNull();
+ expect(
+ within(tags as HTMLElement).getByText('settings.providers.models.subscription'),
+ ).toBeTruthy();
+ expect(row.textContent).not.toContain('$3 / $15');
+ expect(row.querySelector('[data-model-promotion-badge]')).toBeNull();
+ } finally {
+ providersRef.providers = providersRef.DEFAULT_PROVIDERS;
+ }
+ });
+
+ it('keeps discounted Gateway prices in details while retaining the primary-row label', () => {
providersRef.providers = [
{
id: 'xd',
@@ -1103,21 +1138,17 @@ describe('ModelSelector trigger variants', () => {
}),
);
- // 行内折后价在上、标准价划线在下,折价徽标挂在模型名一侧的 tags 区。
+ // 一级菜单保持单行并保留折价标签;折后价和标准价只在完整详情展示。
const row = screen.getByRole('option', { name: /Qwen 3\.7/ });
- expect(row.className).toContain('min-h-11');
- expect(screen.getByRole('listbox', { name: 'Model list' }).style.maxHeight).toBe('274px');
- expect(row.textContent).toContain('¥6 / ¥18');
- expect(row.textContent).toContain('¥12 / ¥36');
+ expect(row.className).toContain('min-h-9');
+ expect(within(row).getByText('Qwen 3.7').className).toContain('leading-5');
+ expect(screen.getByRole('listbox', { name: 'Model list' }).style.maxHeight).toBe('226px');
+ expect(row.textContent).not.toContain('¥6 / ¥18');
+ expect(row.textContent).not.toContain('¥12 / ¥36');
const rowBadge = within(row).getByText('立省 50%');
expect(rowBadge.hasAttribute('data-model-promotion-badge')).toBe(true);
expect(rowBadge.parentElement?.hasAttribute('data-model-tags')).toBe(true);
- const priceStack = within(row).getByText('¥6 / ¥18').parentElement;
- expect(priceStack?.getAttribute('data-model-price-stack')).toBe('true');
- expect(priceStack).not.toBe(rowBadge.parentElement);
- expect(rowBadge.compareDocumentPosition(priceStack as Node)).toBe(
- Node.DOCUMENT_POSITION_FOLLOWING,
- );
+ expect(row.querySelector('[data-model-price-stack]')).toBeNull();
fireEvent.pointerEnter(row);
const details = screen.getByRole('group', { name: /Qwen 3\.7/ });
@@ -1139,7 +1170,7 @@ describe('ModelSelector trigger variants', () => {
}
});
- it('shows explicit double-zero Gateway models as free in the row and model details', () => {
+ it('keeps explicit free labels in the row while leaving full information in details', () => {
providersRef.providers = [
{
id: 'xd',
diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
index 3606c825f2..c0ced8a319 100644
--- a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
@@ -27,7 +27,6 @@ import { useModelPricing } from '@/hooks/useModelPricing';
import { useProviders } from '@/hooks/useProviders';
import { useDeviceProviders } from '@/hooks/useDeviceProviders';
import {
- formatModelPricePair,
modelPriceDiscountLabelValues,
modelPriceDetailRows,
modelPricePresentation,
@@ -92,8 +91,8 @@ const PROVIDER_TITLE_KEY: Record<string, string> = {
// 配置面板锚在主菜单内缩 8px 的模型行上;补偿这段内缩,让两块面板贴边但不重叠。
const MODEL_OPTIONS_SIDE_OFFSET = 8;
const MODEL_LIST_DEFAULT_MAX_HEIGHT_PX = 300;
-// 折扣模型的价格会叠成两行:27.5px 价格栈 + 16px 纵向 padding,向上取整为 44px。
-const MODEL_LIST_CONSTRAINED_ROW_HEIGHT_PX = 44;
+// 一级菜单只保留单行模型信息与必要标签:20px 内容 + 16px 纵向 padding。
+const MODEL_LIST_ROW_HEIGHT_PX = 36;
const MODEL_LIST_ROW_GAP_PX = 2;
export function modelListMaxHeightForRows(maxVisibleRows?: number): number | undefined {
@@ -101,7 +100,7 @@ export function modelListMaxHeightForRows(maxVisibleRows?: number): number | und
const rows = Math.max(1, Math.floor(maxVisibleRows));
return Math.min(
MODEL_LIST_DEFAULT_MAX_HEIGHT_PX,
- rows * MODEL_LIST_CONSTRAINED_ROW_HEIGHT_PX + Math.max(0, rows - 1) * MODEL_LIST_ROW_GAP_PX,
+ rows * MODEL_LIST_ROW_HEIGHT_PX + Math.max(0, rows - 1) * MODEL_LIST_ROW_GAP_PX,
);
}
@@ -1272,7 +1271,7 @@ function ModelSelectorContentView({
}}
className={cn(
'flex w-full cursor-pointer items-center justify-between rounded-[8px] px-3 py-2',
- constrainedListMaxHeight !== undefined && 'min-h-11',
+ constrainedListMaxHeight !== undefined && 'min-h-9',
'transition-colors duration-100 hover:bg-[var(--model-item-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]',
isSelected && 'bg-[var(--model-item-hover)]',
isEditingThis &&
@@ -1295,7 +1294,7 @@ function ModelSelectorContentView({
)}
<span className="flex min-w-0 flex-1 items-center gap-1.5">
<span className="flex min-w-0 flex-1 items-center gap-1.5">
- <span className="truncate text-14 font-medium text-[var(--model-item-text)]">
+ <span className="truncate text-14 font-medium leading-5 text-[var(--model-item-text)]">
{model.displayName}
</span>
{rowEffort && (
@@ -1330,29 +1329,9 @@ function ModelSelectorContentView({
)}
</span>
</span>
- {(rowPrice?.kind === 'priced' || isSelected) && (
- <span className="ml-2 flex shrink-0 items-center gap-1.5">
- {rowPrice?.kind === 'priced' && (
- <span
- data-model-price-stack={rowPrice.original ? 'true' : undefined}
- className={cn(
- 'flex tabular-nums text-11 font-normal leading-[1.25]',
- rowPrice.original ? 'flex-col items-end' : 'items-center',
- )}
- >
- <span className="text-[var(--text-secondary)]">
- {formatModelPricePair(rowPrice.current)}
- </span>
- {rowPrice.original && (
- <span className="text-[var(--text-tertiary)] line-through">
- {formatModelPricePair(rowPrice.original)}
- </span>
- )}
- </span>
- )}
- {isSelected && (
- <Check size={15} className="shrink-0 text-[var(--model-item-check)]" />
- )}
+ {isSelected && (
+ <span className="ml-2 flex shrink-0 items-center">
+ <Check size={15} className="shrink-0 text-[var(--model-item-check)]" />
</span>
)}
</div>