Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(models): deduplicate pricing tables and align localized units
fmfsaisai816079efdcf3
diff --git a/apps/desktop/src/renderer/components/DisplayPricingDetails.tsx b/apps/desktop/src/renderer/components/DisplayPricingDetails.tsxindex 99a458b7a9..73129754dc 100644--- a/apps/desktop/src/renderer/components/DisplayPricingDetails.tsx+++ b/apps/desktop/src/renderer/components/DisplayPricingDetails.tsx@@ -1,6 +1,6 @@import { useTranslation } from 'react-i18next';import type { CatalogModel, ModelDisplayPricing, SummaryQuote } from '@cindy/model-providers';-import { displayPricingAmount, displayPricingQuantity } from '@/lib/displayPricingFormat';+import { displayPricingAmount, displayPricingDenominator, displayPricingQuantity } from '@/lib/displayPricingFormat';type PricingModel = Pick<CatalogModel, 'displayPricing' | 'currency' | 'costDiscount'>;const UNIT_KEYS = {@@ -35,6 +35,9 @@ export function DisplayPricingQuote({locale,t('newChat.modelSelector.displayPricing.million'),);+ const denominator = quote.unit === 'token' && quote.quantity === 1_000_000+ ? t('settings.providers.models.advanced.perMtok')+ : displayPricingDenominator(quantity, unit, locale);const price = amount.free ? t('newChat.modelSelector.displayPricing.free') : amount.current;const qualifiedPrice =quote.priceType === 'estimated'@@ -48,8 +51,7 @@ export function DisplayPricingQuote({{qualifiedPrice}{amount.original && <s className="ml-1.5 text-[var(--text-tertiary)]">{amount.original}</s>}<span className="ml-1 text-[var(--text-tertiary)]">- / {quantity ? `${quantity} ` : ''}- {unit}+ {denominator}</span></span>);diff --git a/apps/desktop/src/renderer/components/__tests__/DisplayPricingDetails.test.tsx b/apps/desktop/src/renderer/components/__tests__/DisplayPricingDetails.test.tsxindex 796e67edc7..6b687c9d7b 100644--- a/apps/desktop/src/renderer/components/__tests__/DisplayPricingDetails.test.tsx+++ b/apps/desktop/src/renderer/components/__tests__/DisplayPricingDetails.test.tsx@@ -52,7 +52,7 @@ describe('DisplayPricingDetails', () => {expect(within(output).getByText('$0.5').tagName).toBe('S');expect(within(output).getByText('/ second')).toBeTruthy();expect(within(output).getByText('/ 3 custom-unit')).toBeTruthy();- expect(within(input).getByText('/ 1M tokens')).toBeTruthy();+ expect(within(input).getByText('/ million tokens')).toBeTruthy();expect(screen.getByText('Billed by output duration.')).toBeTruthy();expect(screen.getByText('<b>Provider terms</b>')).toBeTruthy();expect(container.querySelector('b')).toBeNull();@@ -92,12 +92,20 @@ describe('DisplayPricingDetails', () => {expect(container.textContent).toContain('480P/720P');expect(container.textContent).toContain((priceType === 'estimated' ? copy.estimated : copy.startingAt).replace('{{price}}', '¥4.8–¥8'));expect(container.querySelector('s')?.textContent).toBe('¥6–¥10');- expect(screen.getByText(`/ ${copy.million} ${copy.units.token}`)).toBeTruthy();+ expect(screen.getByText(locales[locale].settings.providers.models.advanced.perMtok)).toBeTruthy();});it('uses the same million denominator in the supplementary price table', async () => {await renderPricing({ currency: 'CNY', displayPricing: { items: [{ ...item, unit: 'character', quantity: 1000000 }] } }, locale);const copy = locales[locale].newChat.modelSelector.displayPricing;- expect(screen.getByText(`/ ${copy.million} ${copy.units.character}`)).toBeTruthy();+ const separator = locale === 'en' || locale === 'ko' ? ' ' : '';+ expect(screen.getByText(`/ ${copy.million}${separator}${copy.units.character}`)).toBeTruthy();+ });++ // Unit: token spelling must agree with chat prices for both quote surfaces in all five languages.+ it.each([false, true])('uses the chat token wording (summary=%s)', async summary => {+ const quote = { ...item, unit: 'token', quantity: 1000000 };+ await renderPricing({ currency: 'USD', displayPricing: { items: [quote], summary: { output: [quote] } } }, locale, summary);+ expect(screen.getByText(locales[locale].settings.providers.models.advanced.perMtok)).toBeTruthy();});it('localizes known image units and keeps unknown provider units unchanged', async () => {diff --git a/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx b/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsxindex 2e4492cc70..a210b3e07d 100644--- a/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx+++ b/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx@@ -1,3 +1,4 @@+import { isDisplayPricingTableRedundant } from '@/lib/displayPricingFormat';import { DisplayPricingDetails, DisplayPricingQuote } from '@/components/DisplayPricingDetails';import { Button } from '@/components/ui/button';import { localizedModelDescription } from '@/lib/modelDescriptions';@@ -1017,10 +1018,12 @@ export function ModelAdvancedDrawer({</Row>);})}- {/* Item labels may carry conditions absent from summary; retain the supplier's full table. */}- <div className={primaryModel.displayPricing.summary ? 'pt-3' : undefined}>- <DisplayPricingDetails model={primaryModel} />- </div>+ {/* Keep conditions and notes; omit a plain table fully covered by the summary. */}+ {!isDisplayPricingTableRedundant(primaryModel.displayPricing) && (+ <div className={primaryModel.displayPricing.summary ? 'pt-3' : undefined}>+ <DisplayPricingDetails model={primaryModel} />+ </div>+ )}</>) : price === null ? (<Row label={t('settings.providers.models.advanced.pricingLabel')} muted>diff --git a/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsxindex 3e40b15199..9776e3ae7c 100644--- a/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx+++ b/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx@@ -788,7 +788,7 @@ it('keeps enterprise reference prices read-only in the model drawer', () => {// Unit contract: drawer summary must show translated roles while retaining supplier conditions below.// Previous drawer tests had no displayPricing; one input quote previously showed only the English table.-it.each([{ hasSummary: true, withNotes: true }, { hasSummary: true, withNotes: false }, { hasSummary: false, withNotes: false }])('keeps supplier detail labels even without tiers or notes: %j', ({ hasSummary, withNotes }) => {+it.each([{ hasSummary: true, withNotes: true }, { hasSummary: true, withNotes: false }, { hasSummary: false, withNotes: false }])('keeps supplementary items when they do not match the summary: %j', ({ hasSummary, withNotes }) => {const quote = { price: 0.02, unit: 'image', quantity: 1 };const summary = { input: [quote, { price: 140, unit: 'character', quantity: 1000000 }],output: [{ ...quote, price: 6, maxPrice: 10, tier: '480P/720P' }],@@ -815,3 +815,15 @@ it.each([{ hasSummary: true, withNotes: true }, { hasSummary: true, withNotes: fexpect(screen.getByText('settings.providers.models.advanced.price.cacheCreate')).toBeTruthy();expect(output.compareDocumentPosition(screen.getByText('Supplier-specific charge')) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();});++// Unit: a plain speech table used to repeat the primary quote; notes must still keep the table visible.+it.each([false, true])('omits only a fully redundant supplementary table (notes=%s)', withNotes => {+ const quote = { price: 140, unit: 'character', quantity: 1000000 };+ draw({ ...model, currency: 'CNY', displayPricing: {+ items: [{ ...quote, label: 'Text input' }], summary: { input: [quote] },+ ...(withNotes ? { notes: ['Provider billing condition'] } : {}),+ } });+ expect(screen.getByText('settings.providers.models.advanced.price.input').parentElement!.textContent).toContain('¥140');+ expect(screen.queryByText('Text input') !== null).toBe(withNotes);+ expect(screen.queryByText('Provider billing condition') !== null).toBe(withNotes);+});diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 479b19724c..8493ea9573 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -10785,7 +10785,7 @@"estimated": "約 {{price}}","startingAt": "{{price}} から","units": {- "token": "トークン",+ "token": "tokens","character": "文字","image": "枚","second": "秒",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex a3fef6ace8..242f46ca01 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -10785,7 +10785,7 @@"estimated": "약 {{price}}","startingAt": "{{price}}부터","units": {- "token": "토큰",+ "token": "tokens","character": "문자","image": "장","second": "초",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 7d4ae18020..479625b37a 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -10785,7 +10785,7 @@"estimated": "约 {{price}}","startingAt": "{{price}} 起","units": {- "token": "token",+ "token": "tokens","character": "字符","image": "张","second": "秒",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 89233c6a09..02ec040c1a 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -10785,7 +10785,7 @@"estimated": "約 {{price}}","startingAt": "{{price}} 起","units": {- "token": "token",+ "token": "tokens","character": "字元","image": "張","second": "秒",diff --git a/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.ts b/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.tsindex 21d4d3d848..3bb7154835 100644--- a/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/displayPricingFormat.test.ts@@ -1,5 +1,6 @@import { describe, expect, it } from 'vitest';-import { displayPricingAmount, displayPricingQuantity } from '../displayPricingFormat';+import type { ModelDisplayPricing } from '@cindy/model-providers';+import { displayPricingAmount, displayPricingDenominator, displayPricingQuantity, isDisplayPricingTableRedundant } from '../displayPricingFormat';const row = { label: 'Output', price: 0.5, unit: 'second', quantity: 1 };describe('display pricing amounts', () => {it('applies the provider discount once while retaining the quoted basis', () => {@@ -43,3 +44,51 @@ it.each([])('formats quantity %s in %s', (quantity, locale, million, expected) => {expect(displayPricingQuantity(quantity as number, locale as string, million as string)).toBe(expected);});++// Unit: a redundant table hid role distinctions or repeated the summary. Existing tests covered only amounts.+// Minimum input: two identical items must consume two distinct quotes, not reuse a single match.+describe('supplementary price table deduplication', () => {+ const quote = { price: 0.5, unit: 'image', quantity: 1 };+ const item = { ...quote, label: 'Supplier label' };+ it('matches across roles regardless of order, without mutating the summary', () => {+ const pricing: ModelDisplayPricing = {+ items: [{ ...item, price: 2, priceType: 'exact' }, item], notes: [],+ summary: { input: [quote], output: [{ ...quote, price: 2, priceType: 'starting_at' }] },+ };+ expect(isDisplayPricingTableRedundant(pricing)).toBe(true);+ expect(pricing.summary!.input).toEqual([quote]);+ expect(pricing.summary!.output).toHaveLength(1);+ expect(isDisplayPricingTableRedundant({ items: [item, item], summary: { input: [quote], output: [quote] } })).toBe(true);+ });+ it.each([+ { items: [item] },+ { items: [item], notes: ['Billing condition'], summary: { input: [quote] } },+ { items: [{ ...item, tier: 'HD' }], summary: { input: [quote] } },+ { items: [{ ...item, priceType: 'estimated' as const }], summary: { input: [quote] } },+ { items: [{ ...item, priceType: 'starting_at' as const }], summary: { input: [quote] } },+ { items: [item], summary: { input: [quote], output: [quote] } },+ { items: [item, item], summary: { input: [quote] } },+ { items: [item, item], summary: { input: [quote], output: [{ ...quote, price: 2 }] } },+ { items: [item], summary: { input: [{ ...quote, unit: 'second' }] } },+ { items: [item], summary: { input: [{ ...quote, quantity: 2 }] } },+ { items: [item], summary: { input: [{ ...quote, maxPrice: 2 }] } },+ { items: [item], summary: { input: [{ ...quote, tier: 'HD' }] } },+ ])('keeps a table with additional or different information: %j', pricing => {+ expect(isDisplayPricingTableRedundant(pricing)).toBe(false);+ });+});++// Unit: the previous unconditional separator produced “百万 字符”; Latin/custom units must keep spacing.+it.each([+ ['百万', '字符', 'zh-CN', '/ 百万字符'],+ ['百萬', '字元', 'zh-TW', '/ 百萬字元'],+ ['100万', '文字', 'ja', '/ 100万文字'],+ ['100万', 'リクエスト', 'ja', '/ 100万リクエスト'],+ ['100만', '자', 'ko', '/ 100만 자'],+ ['1M', 'characters', 'en', '/ 1M characters'],+ ['百万', 'tokens', 'zh-CN', '/ 百万 tokens'],+ ['1,234.5', '次', 'zh-CN', '/ 1,234.5次'],+ ['', '张', 'zh-CN', '/ 张'],+])('joins %s and %s in %s', (quantity, unit, locale, expected) => {+ expect(displayPricingDenominator(quantity, unit, locale)).toBe(expected);+});diff --git a/apps/desktop/src/renderer/lib/displayPricingFormat.ts b/apps/desktop/src/renderer/lib/displayPricingFormat.tsindex 8f830e456b..e8776c247a 100644--- a/apps/desktop/src/renderer/lib/displayPricingFormat.ts+++ b/apps/desktop/src/renderer/lib/displayPricingFormat.ts@@ -1,4 +1,4 @@-import type { SummaryQuote } from '@cindy/model-providers';+import type { ModelDisplayPricing, SummaryQuote } from '@cindy/model-providers';/** Keep the quoted basis; do not convert mixed units or infer a model-wide starting price. */export function displayPricingAmount(@@ -38,3 +38,27 @@ export function displayPricingQuantity(quantity: number, locale: string, millionif (quantity === 1_000_000) return million;return new Intl.NumberFormat(locale, { maximumSignificantDigits: 12 }).format(quantity);}++/** Hide only a plain table whose items match distinct summary quotes exactly. */+export function isDisplayPricingTableRedundant(pricing: ModelDisplayPricing): boolean {+ if (!pricing.summary || pricing.notes?.length) return false;+ const unmatched = Object.values(pricing.summary).flat();+ if (pricing.items.length !== unmatched.length) return false;+ for (const item of pricing.items) {+ if (item.tier || (item.priceType && item.priceType !== 'exact')) return false;+ const index = unmatched.findIndex(quote =>+ quote.unit === item.unit && quote.quantity === item.quantity && quote.price === item.price &&+ quote.maxPrice === undefined && !quote.tier,+ );+ if (index === -1) return false;+ unmatched.splice(index, 1);+ }+ return true;+}++/** Chinese/Japanese counters join CJK units; Latin units and other locales keep a space. */+export function displayPricingDenominator(quantity: string, unit: string, locale: string): string {+ if (!quantity) return `/ ${unit}`;+ const join = /^(zh|ja)(-|$)/i.test(locale) && /^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(unit);+ return `/ ${quantity}${join ? '' : ' '}${unit}`;+}diff --git a/docs/dev-rules/model-catalog-maintenance.md b/docs/dev-rules/model-catalog-maintenance.mdindex e39e7f11ae..4ede040cb8 100644--- a/docs/dev-rules/model-catalog-maintenance.md+++ b/docs/dev-rules/model-catalog-maintenance.md@@ -111,8 +111,10 @@ Registry/defaults、ModelPriceQuote 或 token 成本估算,不跨供应商补Desktop 设置页模型详情有 `displayPricing.summary` 时优先按输入、输出、缓存读取、缓存写入展示主报价,每个角色允许 1–4 段、各带单位与数量,可带最高价形成区间。summary 缺失或无效时-沿用原价目表;summary 无效只清除摘要,不丢价目表。详细价目表保留在摘要下方,因为供应商-label 可能包含摘要没有的条件,不能仅凭金额相同判断重复。设置页列表取 output 首段,没有则取+沿用原价目表;summary 无效只清除摘要,不丢价目表。补充价目表仅在以下条件全部满足时隐藏:+有 summary 且没有 notes;所有 item 都没有 tier,priceType 缺省或 exact;item 总数等于+所有角色报价段数,且每个 item 能按 unit、quantity、price 一一匹配不同的摘要报价,+匹配报价没有 maxPrice 或 tier。其余情况保留在摘要下方。设置页列表取 output 首段,没有则取input 首段;不从混合单位挑最低价。选择器、浮层和聊天价格档位逻辑保持原样。`price` / `maxPrice` 为每 `quantity` 个 `unit` 的折扣前报价,只在展示时应用一次折扣,保留币种与“约/起价”语义;角色和已知单位本地化,label、tier、notes 仅按纯文本呈现,未知单位不猜换算。