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。

修复价格折扣问题

Lizi38d2f9121d35
diff --git a/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts b/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts
index e447089b3a..84ec3c7b7a 100644
--- a/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts
+++ b/apps/desktop/src/renderer/__tests__/modelSelectorTriggerVariant.test.ts
@@ -20,6 +20,8 @@ vi.mock('react-i18next', async (importOriginal) => ({
model?: string;
effort?: string;
price?: string;
+ percent?: string;
+ rate?: string;
},
) => {
const translations: Record<string, string> = {
@@ -43,6 +45,9 @@ vi.mock('react-i18next', async (importOriginal) => ({
if (key === 'newChat.modelSelector.trigger.ariaWithEffort') {
return `Select model. Current: ${options?.model}, effort: ${options?.effort}`;
}
+ if (key === 'newChat.modelSelector.pricing.discount') {
+ return `立省 ${options?.percent}%`;
+ }
return translations[key] ?? options?.defaultValue ?? key;
},
}),
@@ -460,7 +465,7 @@ describe('ModelSelector trigger variants', () => {
expect(pricingRef.renderCalls).toBe(1);
});
- it('shows only the free promotion in the selected-model trigger', () => {
+ it('shows Gateway discount and free promotions in the selected-model trigger', () => {
providersRef.providers = [
{
id: 'xd',
@@ -507,7 +512,7 @@ describe('ModelSelector trigger variants', () => {
};
try {
- const belowStandardPrice = render(
+ const discounted = render(
React.createElement(ModelSelector, {
modelId: 'claude-opus-4-8',
effort: 'high',
@@ -518,10 +523,12 @@ describe('ModelSelector trigger variants', () => {
onProviderChange: vi.fn(),
}),
);
- // 折价不再有徽标:实际价低于标准价的模型,trigger 上不挂任何促销徽标。
- const belowStandardTrigger = screen.getByRole('button', { name: /Current: Opus 4\.8/ });
- expect(belowStandardTrigger.querySelector('[data-model-promotion-badge]')).toBeNull();
- belowStandardPrice.unmount();
+ const discountTrigger = screen.getByRole('button', { name: /Current: Opus 4\.8/ });
+ const discountBadge = within(discountTrigger).getByText('立省 50%');
+ expect(discountBadge.hasAttribute('data-model-promotion-badge')).toBe(true);
+ expect(discountBadge.className).toContain('bg-[var(--accent-cta-bg)]');
+ expect(discountBadge.className).toContain('text-[var(--accent-pure-cta-fg)]');
+ discounted.unmount();
pricingRef.pricing = {};
render(
@@ -793,7 +800,7 @@ describe('ModelSelector trigger variants', () => {
vi.useRealTimers();
});
- it('shows the effective Gateway price without an original-price comparison', () => {
+ it('keeps discounted Gateway prices aligned between the row and model details', () => {
providersRef.providers = [
{
id: 'xd',
@@ -844,23 +851,34 @@ describe('ModelSelector trigger variants', () => {
}),
);
- // 行内只显示实际价:标准价不再以划线形式并排,也不再挂折价徽标。
+ // 行内折后价在上、标准价划线在下,折价徽标挂在模型名一侧的 tags 区。
const row = screen.getByRole('option', { name: /Qwen 3\.7/ });
expect(row.textContent).toContain('¥6 / ¥18');
- expect(row.textContent).not.toContain('¥12 / ¥36');
- expect(row.querySelector('[data-model-promotion-badge]')).toBeNull();
+ expect(row.textContent).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,
+ );
fireEvent.pointerEnter(row);
const details = screen.getByRole('group', { name: /Qwen 3\.7/ });
expect(within(details).getByText('¥6')).toBeTruthy();
expect(within(details).getByText('¥18')).toBeTruthy();
- expect(within(details).queryByText('¥12')).toBeNull();
- expect(within(details).queryByText('¥36')).toBeNull();
+ expect(within(details).getByText('¥12').className).toContain('line-through');
+ expect(within(details).getByText('¥36').className).toContain('line-through');
+ // 缓存价同样按折后价展示,标准缓存价并排划线。
expect(within(details).getByText('¥1.2')).toBeTruthy();
- expect(within(details).queryByText('¥2.4')).toBeNull();
+ expect(within(details).getByText('¥2.4').className).toContain('line-through');
expect(within(details).getByText('¥7.5')).toBeTruthy();
- expect(within(details).queryByText('¥15')).toBeNull();
- expect(details.querySelector('[data-model-promotion-badge]')).toBeNull();
+ expect(within(details).getByText('¥15').className).toContain('line-through');
+ const detailsBadge = within(details).getByText('立省 50%');
+ expect(detailsBadge.parentElement?.hasAttribute('data-model-tags')).toBe(true);
+ expect(detailsBadge.parentElement?.className).toContain('ml-auto');
} finally {
providersRef.providers = providersRef.DEFAULT_PROVIDERS;
pricingRef.pricing = pricingRef.DEFAULT_PRICING;
diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
index e5f95dafc6..2d97c62c8d 100644
--- a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
@@ -28,6 +28,7 @@ import { useProviders } from '@/hooks/useProviders';
import { useDeviceProviders } from '@/hooks/useDeviceProviders';
import {
formatModelPricePair,
+ modelPriceDiscountLabelValues,
modelPriceDetailRows,
modelPricePresentation,
} from '@/lib/modelPriceFormat';
@@ -914,8 +915,17 @@ function ModelSelectorContentView({
const editingPricePresentation = editingModel
? pricePresentationOf(editingProvider?.id ?? editingProviderId, editingModel.id)
: null;
+ const editingDiscount =
+ editingPricePresentation?.kind === 'priced' ? editingPricePresentation.discount : undefined;
const editingPromotionLabel =
- editingPricePresentation?.kind === 'free' ? t('newChat.modelSelector.pricing.free') : null;
+ editingPricePresentation?.kind === 'free'
+ ? t('newChat.modelSelector.pricing.free')
+ : editingDiscount !== undefined
+ ? t(
+ 'newChat.modelSelector.pricing.discount',
+ modelPriceDiscountLabelValues(editingDiscount),
+ )
+ : null;
// 每个模型行的信息 / 配置内容由一个独立的 portaled Popover 承载,而不是拼进主菜单宽度。
// 这样浮层会像 Hermes 的 Radix submenu 一样贴着当前行移动,切行不触发主菜单重排。
@@ -1017,7 +1027,10 @@ function ModelSelectorContentView({
{editingPricePresentation.kind === 'priced' && (
<>
<div className="grid grid-cols-[1fr_auto] gap-x-3 gap-y-1 text-12 leading-[1.4]">
- {modelPriceDetailRows(editingPricePresentation.current).map((row) => (
+ {modelPriceDetailRows(
+ editingPricePresentation.current,
+ editingPricePresentation.original,
+ ).map((row) => (
<div key={row.kind} className="contents">
<span className="text-[var(--text-secondary)]">
{t(`newChat.modelSelector.pricing.${row.kind}`)}
@@ -1027,6 +1040,11 @@ function ModelSelectorContentView({
{editingPricePresentation.current.approximate ? '≈' : ''}
{row.value}
</span>
+ {row.originalValue && (
+ <span className="text-[var(--text-tertiary)] line-through">
+ {row.originalValue}
+ </span>
+ )}
</span>
</div>
))}
@@ -1073,13 +1091,21 @@ function ModelSelectorContentView({
const renderModelItem = (provider: ProviderView | null, model: RowModel) => {
const providerId = provider?.id ?? null;
const isSelected = isSelectedRow(providerId, model.id);
+ const isBudgetModel = model.id.startsWith('codex/');
const isSubscriptionModel = provider?.access?.kind === 'subscription';
const disabled = modelDisabledOf(model.id);
const rowEffort = rowEffortOf(providerId, model);
const rowFastOn = fastOnOf(providerId, model);
const rowPrice = pricePresentationOf(providerId, model.id);
const rowPromotionLabel =
- rowPrice?.kind === 'free' ? t('newChat.modelSelector.pricing.free') : null;
+ rowPrice?.kind === 'free'
+ ? t('newChat.modelSelector.pricing.free')
+ : rowPrice?.kind === 'priced' && rowPrice.discount !== undefined
+ ? t(
+ 'newChat.modelSelector.pricing.discount',
+ modelPriceDiscountLabelValues(rowPrice.discount),
+ )
+ : null;
// 信息面板对所有可用模型开放;能否编辑 effort / Fast 在面板内部另行判定。
// session-agent-switch 浏览目标引擎态同样开放:选模型前正需要看描述/上下文/价格/来源;
// 面板内配置写的是**目标引擎**的 per-(来源,模型) 全局预设(currentAgentKind 已随浏览态
@@ -1191,13 +1217,18 @@ function ModelSelectorContentView({
/>
)}
</span>
- {(isSubscriptionModel || rowPromotionLabel) && (
+ {(isSubscriptionModel || isBudgetModel || rowPromotionLabel) && (
<span data-model-tags className="ml-auto flex shrink-0 items-center gap-1.5">
{isSubscriptionModel && (
<span className="inline-flex shrink-0 items-center rounded-full bg-[var(--surface-chip)] px-2 py-[1px] text-[11px] font-medium text-[var(--text-secondary)]">
{t('settings.providers.models.subscription')}
</span>
)}
+ {isBudgetModel && (
+ <span className="inline-flex shrink-0 items-center rounded-full bg-[var(--model-budget-badge-bg)] px-2 py-[1px] text-[11px] font-medium text-[var(--model-budget-badge-text)]">
+ {t('newChat.modelSelector.meta.budgetDiscount')}
+ </span>
+ )}
{rowPromotionLabel && (
<ModelPromotionBadge>{rowPromotionLabel}</ModelPromotionBadge>
)}
@@ -1208,10 +1239,21 @@ function ModelSelectorContentView({
{(rowPrice?.kind === 'priced' || isSelected) && (
<span className="ml-2 flex shrink-0 items-center gap-1.5">
{rowPrice?.kind === 'priced' && (
- <span className="flex items-center tabular-nums text-11 font-normal leading-[1.25]">
+ <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 && (
@@ -1575,7 +1617,15 @@ export function ModelSelector({
);
})();
const triggerPromotionLabel =
- triggerPricePresentation?.kind === 'free' ? t('newChat.modelSelector.pricing.free') : null;
+ triggerPricePresentation?.kind === 'free'
+ ? t('newChat.modelSelector.pricing.free')
+ : triggerPricePresentation?.kind === 'priced' &&
+ triggerPricePresentation.discount !== undefined
+ ? t(
+ 'newChat.modelSelector.pricing.discount',
+ modelPriceDiscountLabelValues(triggerPricePresentation.discount),
+ )
+ : null;
// 断开态同一规则,只是来源取「真实断开来源」(currentProviderId)。
const disconnectedProvider = currentProviderId
? providers.find((p) => p.id === currentProviderId)
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 49d8b88ac6..9e26dae1c0 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -3847,6 +3847,7 @@
"cacheRead": "Cache read",
"cacheCreate": "Cache write",
"free": "Limited-time free",
+ "discount": "Save {{percent}}%",
"perMillion": "Standard model pricing",
"fixedFx": "Estimated at the fixed rate of 1 USD = 6.7 CNY",
"subscriptionEstimate": "Value estimate, not an actual bill"
@@ -3877,7 +3878,8 @@
"meta": {
"context": "{{value}} context",
"price": "{{input}}/{{output}} per 1M",
- "fastBadge": "Fast"
+ "fastBadge": "Fast",
+ "budgetDiscount": "Special discount"
},
"source": {
"railLabel": "Source",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index e7345358e0..7e71fae1df 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -3846,6 +3846,7 @@
"cacheRead": "キャッシュ読み取り",
"cacheCreate": "キャッシュ書き込み",
"free": "期間限定無料",
+ "discount": "{{percent}}%お得",
"perMillion": "モデル標準価格",
"fixedFx": "固定レート 1 USD = 6.7 CNY による概算",
"subscriptionEstimate": "価値の推定であり、実際の請求額ではありません"
@@ -3876,7 +3877,8 @@
"meta": {
"context": "コンテキスト {{value}}",
"price": "{{input}}/{{output}} / 100万",
- "fastBadge": "高速"
+ "fastBadge": "高速",
+ "budgetDiscount": "特別割引"
},
"source": {
"railLabel": "ソース",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index c4b3bd7797..6e01db8e81 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -3846,6 +3846,7 @@
"cacheRead": "캐시 읽기",
"cacheCreate": "캐시 쓰기",
"free": "기간 한정 무료",
+ "discount": "{{percent}}% 절약",
"perMillion": "모델 표준 가격",
"fixedFx": "고정 환율 1 USD = 6.7 CNY 기준 추정",
"subscriptionEstimate": "가치 추정치이며 실제 청구 금액이 아닙니다"
@@ -3876,7 +3877,8 @@
"meta": {
"context": "컨텍스트 {{value}}",
"price": "{{input}}/{{output}} / 100만",
- "fastBadge": "고속"
+ "fastBadge": "고속",
+ "budgetDiscount": "특별 할인"
},
"source": {
"railLabel": "소스",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 3dd2c3f909..a44605f84f 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -3846,6 +3846,7 @@
"cacheRead": "缓存读取",
"cacheCreate": "缓存写入",
"free": "限时免费",
+ "discount": "立省 {{percent}}%",
"perMillion": "模型标准价格",
"fixedFx": "按固定汇率 1 USD = 6.7 CNY 约算",
"subscriptionEstimate": "价值估算,不代表实际账单"
@@ -3876,7 +3877,8 @@
"meta": {
"context": "{{value}} 上下文",
"price": "{{input}}/{{output}} / 百万",
- "fastBadge": "快速"
+ "fastBadge": "快速",
+ "budgetDiscount": "特别折扣"
},
"source": {
"railLabel": "来源",
diff --git a/apps/desktop/src/renderer/lib/__tests__/modelPriceFormat.test.ts b/apps/desktop/src/renderer/lib/__tests__/modelPriceFormat.test.ts
index 00955ec86f..093538675b 100644
--- a/apps/desktop/src/renderer/lib/__tests__/modelPriceFormat.test.ts
+++ b/apps/desktop/src/renderer/lib/__tests__/modelPriceFormat.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import type { ModelPriceQuote } from '../../../shared/regionalMoney';
import {
formatModelPricePair,
+ modelPriceDiscountLabelValues,
modelPriceDetailRows,
modelPricePresentation,
} from '../modelPriceFormat';
@@ -49,17 +50,30 @@ describe('modelPriceFormat', () => {
]);
});
- it('uses the effective price when it is a uniform scaling of the standard price', () => {
- const standard = quote({ inputPerMtok: 12, outputPerMtok: 36 });
- expect(modelPricePresentation(standard, { input: 6, output: 18 })).toEqual({
+ it('uses the effective price while retaining the original for a 50% discount', () => {
+ const original = quote({ inputPerMtok: 12, outputPerMtok: 36 });
+ expect(modelPricePresentation(original, { input: 6, output: 18 })).toEqual({
kind: 'priced',
current: quote({ inputPerMtok: 6, outputPerMtok: 18 }),
+ original,
+ discount: 0.5,
+ });
+ expect(modelPriceDiscountLabelValues(0.5)).toEqual({
+ percent: '50',
+ rate: '5',
+ });
+ expect(modelPriceDiscountLabelValues(0.2)).toEqual({
+ percent: '20',
+ rate: '8',
});
expect(
- modelPriceDetailRows(quote({ inputPerMtok: 6, outputPerMtok: 18, cacheReadPerMtok: 0.3 })),
+ modelPriceDetailRows(
+ quote({ inputPerMtok: 6, outputPerMtok: 18, cacheReadPerMtok: 0.3 }),
+ original,
+ ),
).toEqual([
- { kind: 'input', value: '¥6' },
- { kind: 'output', value: '¥18' },
+ { kind: 'input', value: '¥6', originalValue: '¥12' },
+ { kind: 'output', value: '¥18', originalValue: '¥36' },
{ kind: 'cacheRead', value: '¥0.3' },
]);
});
@@ -88,14 +102,19 @@ describe('modelPriceFormat', () => {
cacheReadPerMtok: 1.2,
cacheCreatePerMtok: 7.5,
}),
+ original: standard,
+ discount: 0.5,
});
+ // 缓存价也参与折算,所以明细四行都能给出划线原价。
expect(
- presentation?.kind === 'priced' ? modelPriceDetailRows(presentation.current) : [],
+ presentation?.kind === 'priced'
+ ? modelPriceDetailRows(presentation.current, presentation.original)
+ : [],
).toEqual([
- { kind: 'input', value: '¥6' },
- { kind: 'output', value: '¥18' },
- { kind: 'cacheRead', value: '¥1.2' },
- { kind: 'cacheCreate', value: '¥7.5' },
+ { kind: 'input', value: '¥6', originalValue: '¥12' },
+ { kind: 'output', value: '¥18', originalValue: '¥36' },
+ { kind: 'cacheRead', value: '¥1.2', originalValue: '¥2.4' },
+ { kind: 'cacheCreate', value: '¥7.5', originalValue: '¥15' },
]);
});
@@ -131,15 +150,17 @@ describe('modelPriceFormat', () => {
expect(modelPricePresentation(undefined, { input: 0, output: 0 })).toBeNull();
});
- it('shows double-zero effective prices as zero when the quote is nonzero', () => {
- const standard = quote({ inputPerMtok: 12, outputPerMtok: 36 });
- expect(modelPricePresentation(standard, { input: 0, output: 0 })).toEqual({
+ it('keeps double-zero effective prices as a 100% discount when the quote is nonzero', () => {
+ const original = quote({ inputPerMtok: 12, outputPerMtok: 36 });
+ expect(modelPricePresentation(original, { input: 0, output: 0 })).toEqual({
kind: 'priced',
current: quote({ inputPerMtok: 0, outputPerMtok: 0 }),
+ original,
+ discount: 1,
});
});
- it('preserves the standard price when the effective price matches it', () => {
+ it('preserves the standard price when there is no discount', () => {
const standard = quote({ inputPerMtok: 12, outputPerMtok: 36 });
expect(modelPricePresentation(standard, { input: 12, output: 36 })).toEqual({
kind: 'priced',
diff --git a/apps/desktop/src/renderer/lib/modelPriceFormat.ts b/apps/desktop/src/renderer/lib/modelPriceFormat.ts
index 7acc7f46ca..9faa8f0978 100644
--- a/apps/desktop/src/renderer/lib/modelPriceFormat.ts
+++ b/apps/desktop/src/renderer/lib/modelPriceFormat.ts
@@ -22,6 +22,8 @@ export type ModelPricePresentation =
| {
kind: 'priced';
current: ModelPriceQuote;
+ original?: ModelPriceQuote;
+ discount?: number;
};
function compactNumber(value: number): string {
@@ -41,19 +43,30 @@ export function formatModelPricePair(quote: ModelPriceQuote): string {
return `${quote.approximate ? '≈' : ''}${input} / ${output}`;
}
+export function modelPriceDiscountLabelValues(discount: number): {
+ percent: string;
+ rate: string;
+} {
+ return {
+ percent: compactNumber(discount * 100),
+ rate: compactNumber((1 - discount) * 10),
+ };
+}
+
function isNonNegativeFinite(value: unknown): value is number {
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
}
/**
- * effectiveCost 能否直接当展示价:要求已展示的 input / output / 缓存价格
- * 相对标准价都是同一个缩放比例。标准价中的非零缓存维度必须有实际价对应,
- * 避免在同一张明细表中混用实际价与标准价。
+ * effectiveCost 能否直接当展示价,以及折价幅度是多少:要求已展示的 input / output /
+ * 缓存价格相对标准价都是同一个缩放比例。标准价中的非零缓存维度必须有实际价对应,
+ * 避免在同一张明细表中混用实际价与标准价。比例不一致时返回 undefined —— 展示层
+ * 退回标准价,不挂折价徽标也不做原价对比。
*/
-function effectiveCostIsConsistent(
+function inferDiscount(
quote: ModelPriceQuote,
cost: CompleteEffectiveModelCost,
-): boolean {
+): number | undefined {
const gaps: number[] = [];
for (const [standard, effective] of [
[quote.inputPerMtok, cost.input],
@@ -62,24 +75,25 @@ function effectiveCostIsConsistent(
[quote.cacheCreatePerMtok, cost.cacheWrite],
] as const) {
if (standard === undefined) continue;
- if (!isNonNegativeFinite(standard)) return false;
+ if (!isNonNegativeFinite(standard)) return undefined;
if (effective === undefined && standard === 0) continue;
- if (!isNonNegativeFinite(effective)) return false;
+ if (!isNonNegativeFinite(effective)) return undefined;
if (standard === 0) {
- if (effective !== 0) return false;
+ if (effective !== 0) return undefined;
continue;
}
const gap = 1 - effective / standard;
- if (gap < MIN_EFFECTIVE_PRICE_GAP || gap > 1) return false;
+ if (gap < MIN_EFFECTIVE_PRICE_GAP || gap > 1) return undefined;
gaps.push(gap);
}
- if (gaps.length === 0) return false;
- return gaps.every((gap) => Math.abs(gap - gaps[0]) < 1e-9);
+ if (gaps.length === 0) return undefined;
+ return gaps.every((gap) => Math.abs(gap - gaps[0]) < 1e-9) ? gaps[0] : undefined;
}
/**
* 构建模型选择器的展示价格。quote 继续保留用量估算所需的标准价;
- * CatalogModel.cost 承载 XD 模型的实际展示价,一致时直接覆盖 input / output。
+ * CatalogModel.cost 承载 XD 模型的折后展示价,比例一致时覆盖 input / output /
+ * 缓存价,并把标准价留在 original 供原价对比与折价徽标使用。
*/
export function modelPricePresentation(
quote: ModelPriceQuote | null | undefined,
@@ -108,9 +122,8 @@ export function modelPricePresentation(
const cacheRead = effectiveCost?.cacheRead;
const cacheWrite = effectiveCost?.cacheWrite;
- if (!effectiveCostIsConsistent(quote, { input, output, cacheRead, cacheWrite })) {
- return { kind: 'priced', current: quote };
- }
+ const discount = inferDiscount(quote, { input, output, cacheRead, cacheWrite });
+ if (discount === undefined) return { kind: 'priced', current: quote };
return {
kind: 'priced',
current: {
@@ -124,21 +137,37 @@ export function modelPricePresentation(
? { cacheCreatePerMtok: cacheWrite ?? quote.cacheCreatePerMtok }
: {}),
},
+ original: quote,
+ discount,
};
}
-export function modelPriceDetailRows(quote: ModelPriceQuote): Array<{
+export function modelPriceDetailRows(
+ quote: ModelPriceQuote,
+ originalQuote?: ModelPriceQuote,
+): Array<{
kind: 'input' | 'output' | 'cacheRead' | 'cacheCreate';
value: string;
+ originalValue?: string;
}> {
+ // 折后价与标准价相同的维度(例如两边都是 0)不划线,避免出现「¥0 划掉 ¥0」。
+ const originalOf = (value: string, original: number | undefined) => {
+ if (!originalQuote || original === undefined) return {};
+ const originalValue = formatModelPriceAmount(original, originalQuote.currency);
+ return originalValue === value ? {} : { originalValue };
+ };
+ const inputValue = formatModelPriceAmount(quote.inputPerMtok, quote.currency);
+ const outputValue = formatModelPriceAmount(quote.outputPerMtok, quote.currency);
return [
{
kind: 'input' as const,
- value: formatModelPriceAmount(quote.inputPerMtok, quote.currency),
+ value: inputValue,
+ ...originalOf(inputValue, originalQuote?.inputPerMtok),
},
{
kind: 'output' as const,
- value: formatModelPriceAmount(quote.outputPerMtok, quote.currency),
+ value: outputValue,
+ ...originalOf(outputValue, originalQuote?.outputPerMtok),
},
...(quote.cacheReadPerMtok === undefined
? []
@@ -146,6 +175,10 @@ export function modelPriceDetailRows(quote: ModelPriceQuote): Array<{
{
kind: 'cacheRead' as const,
value: formatModelPriceAmount(quote.cacheReadPerMtok, quote.currency),
+ ...originalOf(
+ formatModelPriceAmount(quote.cacheReadPerMtok, quote.currency),
+ originalQuote?.cacheReadPerMtok,
+ ),
},
]),
...(quote.cacheCreatePerMtok === undefined
@@ -154,6 +187,10 @@ export function modelPriceDetailRows(quote: ModelPriceQuote): Array<{
{
kind: 'cacheCreate' as const,
value: formatModelPriceAmount(quote.cacheCreatePerMtok, quote.currency),
+ ...originalOf(
+ formatModelPriceAmount(quote.cacheCreatePerMtok, quote.currency),
+ originalQuote?.cacheCreatePerMtok,
+ ),
},
]),
];
diff --git a/apps/mobile/src/i18n/locales/en/models.json b/apps/mobile/src/i18n/locales/en/models.json
index 9b774ba5eb..29fd349d83 100644
--- a/apps/mobile/src/i18n/locales/en/models.json
+++ b/apps/mobile/src/i18n/locales/en/models.json
@@ -8,6 +8,7 @@
"emptyDefault": "No models available",
"loadingDefault": "Loading models…",
"subscriptionBadge": "Subscription",
+ "discountBadge": "Special discount",
"backToModels": "Back to model list",
"agentSwitchHint": "After you pick a model, the next message switches to {{agent}}",
"crossAgentEmptyHint": "Connect a {{agent}} model source on the controlled computer first",
diff --git a/apps/mobile/src/i18n/locales/ja/models.json b/apps/mobile/src/i18n/locales/ja/models.json
index cceca018c9..1ba7a13a08 100644
--- a/apps/mobile/src/i18n/locales/ja/models.json
+++ b/apps/mobile/src/i18n/locales/ja/models.json
@@ -8,6 +8,7 @@
"emptyDefault": "利用可能なモデルがありません",
"loadingDefault": "モデルを読み込み中…",
"subscriptionBadge": "サブスク",
+ "discountBadge": "特別割引",
"backToModels": "モデル一覧に戻る",
"agentSwitchHint": "モデルを選択すると、次のメッセージから {{agent}} に切り替わります",
"crossAgentEmptyHint": "先に操作対象のパソコンで {{agent}} のモデルソースを接続してください",
diff --git a/apps/mobile/src/i18n/locales/ko/models.json b/apps/mobile/src/i18n/locales/ko/models.json
index 7da7361511..c8beeb16c9 100644
--- a/apps/mobile/src/i18n/locales/ko/models.json
+++ b/apps/mobile/src/i18n/locales/ko/models.json
@@ -8,6 +8,7 @@
"emptyDefault": "사용 가능한 모델이 없습니다",
"loadingDefault": "모델을 불러오는 중…",
"subscriptionBadge": "구독",
+ "discountBadge": "특별 할인",
"backToModels": "모델 목록으로 돌아가기",
"agentSwitchHint": "모델을 선택하면 다음 메시지부터 {{agent}}(으)로 전환됩니다",
"crossAgentEmptyHint": "먼저 제어 대상 컴퓨터에서 {{agent}} 모델 소스를 연결하세요",
diff --git a/apps/mobile/src/i18n/locales/zh-CN/models.json b/apps/mobile/src/i18n/locales/zh-CN/models.json
index 047486650e..1b5ecdfc29 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/models.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/models.json
@@ -8,6 +8,7 @@
"emptyDefault": "暂无可用模型",
"loadingDefault": "正在加载模型…",
"subscriptionBadge": "订阅",
+ "discountBadge": "特别折扣",
"backToModels": "返回模型列表",
"agentSwitchHint": "选择模型后,下一条消息将切换到 {{agent}}",
"crossAgentEmptyHint": "请先在被控电脑连接 {{agent}} 的模型来源",
diff --git a/apps/mobile/src/session/MobileModelPickerList.tsx b/apps/mobile/src/session/MobileModelPickerList.tsx
index b194bf51d0..1258ea8bbf 100644
--- a/apps/mobile/src/session/MobileModelPickerList.tsx
+++ b/apps/mobile/src/session/MobileModelPickerList.tsx
@@ -3,8 +3,8 @@
* 由 ModelPickerSheet 装配)。
*
* 展现内容对齐桌面 ModelSelector 的 renderModelItem:每行 = 来源官方 mark + 模型名 +
- * `订阅`(订阅制来源)+ 当前 effort 标签 + Fast 闪电(点亮时)+
- * 选中 Check + 行内「配置」入口。折扣版不带行内徽标,靠分组标题区分。
+ * `订阅`(订阅制来源)+ `特别折扣`(折扣版)+ 当前 effort 标签 + Fast 闪电(点亮时)+
+ * 选中 Check + 行内「配置」入口。
* 触屏适配:桌面 hover「Edit」→ 每行右侧常驻配置图标,点击经 `onOpenOptions` 通知浮窗
* 打开二级「模型选项」SheetSurface(元信息 / 快速开关 / 推理强度,见 ModelOptionsSheetView),
* 本组件不再承载行内展开。折扣版被控端无 gateway key → 整行置灰 + 行内提示。
@@ -193,6 +193,7 @@ export function MobileModelPickerList({
<>
{providerRows.map((row) => {
const selected = row.model.id === activeModelId && row.provider.id === activeSourceId;
+ const isBudget = row.model.id.startsWith('codex/');
// 对齐桌面 ModelSelector:订阅制来源(Claude.ai / ChatGPT 等)的模型带「订阅」徽标。
const isSubscription = row.provider.access?.kind === 'subscription';
const rowDisabled = budgetRowDisabled(row.model.id, apiKeyStatus);
@@ -273,6 +274,11 @@ export function MobileModelPickerList({
<Text style={styles.budgetBadgeText}>{t('models.picker.subscriptionBadge')}</Text>
</View>
) : null}
+ {isBudget ? (
+ <View style={styles.budgetBadge}>
+ <Text style={styles.budgetBadgeText}>{t('models.picker.discountBadge')}</Text>
+ </View>
+ ) : null}
{rowEffort ? (
<Text numberOfLines={1} style={styles.effortLabel}>
{effortLabelFor(row.model, rowEffort, capabilities ?? null)}