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(models): simplify pricing lists and preserve detail discounts

fmfsaisaiababe511563d
diff --git a/apps/desktop/scripts/fixtures/display-pricing/display-pricing-fixture.tsx b/apps/desktop/scripts/fixtures/display-pricing/display-pricing-fixture.tsx
index 0355e171f7..8fa995a9d1 100644
--- a/apps/desktop/scripts/fixtures/display-pricing/display-pricing-fixture.tsx
+++ b/apps/desktop/scripts/fixtures/display-pricing/display-pricing-fixture.tsx
@@ -1,9 +1,6 @@
import { mountPage, subscription } from '../../ui-page/harness';
import { ModelAdvancedDrawer } from '../../../src/renderer/components/settings/ModelAdvancedDrawer';
-import {
- buildUnionRows,
- UnifiedModelList,
-} from '../../../src/renderer/components/settings/UnifiedModelList';
+import { buildUnionRows } from '../../../src/renderer/components/settings/UnifiedModelList';
import {
BUNDLED_CATALOG,
type ProviderView,
@@ -26,18 +23,19 @@ const image: ModelDisplayPricing = {
};
const video: ModelDisplayPricing = {
items: [
- { label: 'Video generation', price: 6, tier: '480P', unit: 'token', quantity: 1000000 },
- { label: 'Video generation', price: 10, tier: '720P', unit: 'token', quantity: 1000000 },
+ { label: 'Video generation', price: 0.05, tier: '480P', unit: 'second', quantity: 1 },
+ { label: 'Video generation', price: 0.1, tier: '720P', unit: 'second', quantity: 1 },
+ { label: 'Video generation', price: 0.2, tier: '1080P', unit: 'second', quantity: 1 },
],
notes: ['Billed by generated resolution.'],
summary: {
output: [
{
- price: 6,
- maxPrice: 10,
- tier: '480P/720P',
- unit: 'token',
- quantity: 1000000,
+ price: 0.05,
+ maxPrice: 0.2,
+ tier: '480P/720P/1080P',
+ unit: 'second',
+ quantity: 1,
priceType: 'starting_at',
},
],
@@ -92,7 +90,6 @@ void mountPage({
name: 'Qwen Speech',
mode: 'audio_speech',
currency: 'CNY',
- costDiscount: 0.2,
displayPricing: ctx.case === 'legacy' ? quote : speech,
modalities: { input: ['text'], output: ['audio'] },
},
@@ -103,7 +100,6 @@ void mountPage({
name: 'Seedream',
mode: 'image_generation',
currency: 'USD',
- costDiscount: 0.2,
displayPricing: image,
modalities: { input: ['text', 'image'], output: ['image'] },
},
@@ -114,18 +110,12 @@ void mountPage({
name: 'Video',
mode: 'video_generation',
currency: 'CNY',
- costDiscount: 0.2,
- displayPricing: ctx.case === 'list' ? video : quote,
+ costDiscount: 0.4,
+ displayPricing: quote,
modalities: { input: ['text'], output: ['video'] },
},
],
};
- if (ctx.case === 'list')
- return (
- <main className="p-5">
- <UnifiedModelList provider={provider} />
- </main>
- );
const rowId = ['speech', 'legacy'].includes(ctx.case) ? 'speech' : ctx.case === 'image' ? 'image' : 'video';
return (
<ModelAdvancedDrawer
diff --git a/apps/desktop/scripts/fixtures/display-pricing/ui-page.mjs b/apps/desktop/scripts/fixtures/display-pricing/ui-page.mjs
index cdb47f6f91..cd973df695 100644
--- a/apps/desktop/scripts/fixtures/display-pricing/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/display-pricing/ui-page.mjs
@@ -2,7 +2,7 @@ export default {
name: 'display-pricing',
entry: './display-pricing-fixture.tsx',
viewport: { width: 800, height: 800 },
- real: 'ModelAdvancedDrawer, UnifiedModelList, DisplayPricingDetails, localized roles, quantities, ranges and discounts',
+ real: 'ModelAdvancedDrawer, DisplayPricingDetails, localized roles, quantities, ranges and discounts',
notCovered:
'Live Gateway responses, account permissions and actual billing; prices are fixture inputs',
cases: {
@@ -11,30 +11,44 @@ export default {
video: { about: 'Resolution tier with discounted range and starting price' },
default: { about: 'Multiple units, all four roles and supplementary conditions' },
legacy: { about: 'Existing table without summary' },
- list: {
- about: 'Media list selects output first, then input',
- viewport: { width: 800, height: 600 },
- },
},
async check(page, ui) {
- if (ui.case === 'list') {
- const groups = page.locator('button[aria-expanded="false"]:not([aria-haspopup])');
- while (await groups.count()) await groups.first().click();
- await page.getByText('¥112', { exact: false }).waitFor();
- if (!(await page.locator('body').textContent()).includes('¥4.8–¥8'))
- throw Error('Missing discounted video summary');
+ const pricing = page.getByText(await ui.t('settings.providers.models.advanced.pricing'), {
+ exact: true,
+ });
+ await pricing.scrollIntoViewIfNeeded();
+ if (ui.case !== 'legacy') {
+ const role = ui.case === 'video' ? 'output' : 'input';
+ await page
+ .getByText(await ui.t(`settings.providers.models.advanced.price.${role}`), {
+ exact: true,
+ })
+ .waitFor();
+ }
+ const discount = page.getByText(await ui.t('settings.providers.models.advanced.discount'), { exact: true });
+ if (['speech', 'image', 'legacy'].includes(ui.case)) {
+ if (await discount.count()) throw Error('Unexpected discount on an undiscounted model');
} else {
- const pricing = page.getByText(await ui.t('settings.providers.models.advanced.pricing'), {
- exact: true,
+ await discount.waitFor();
+ await page.getByText('↓40%', { exact: true }).waitFor();
+ }
+ // Browser regression: the original range split across lines in the real video drawer.
+ // Measure rendered text, not Tailwind classes; tier must sit above the amount group.
+ if (ui.case === 'video') {
+ const layout = await page.getByText('¥0.05–¥0.2', { exact: true }).evaluate(original => {
+ const amounts = original.parentElement;
+ const tier = amounts.previousElementSibling;
+ return {
+ lines: Array.from(amounts.children, part => {
+ const range = document.createRange();
+ range.selectNodeContents(part);
+ return range.getClientRects().length;
+ }),
+ tierBelowAmounts: tier.getBoundingClientRect().bottom > amounts.getBoundingClientRect().top,
+ };
});
- await pricing.scrollIntoViewIfNeeded();
- if (ui.case !== 'legacy') {
- const role = ['video'].includes(ui.case) ? 'output' : 'input';
- await page
- .getByText(await ui.t(`settings.providers.models.advanced.price.${role}`), {
- exact: true,
- })
- .waitFor();
+ if (layout.lines.some(count => count !== 1) || layout.tierBelowAmounts) {
+ throw Error(`Broken video quote wrapping: ${JSON.stringify(layout)}`);
}
}
await ui.capture('pricing');
diff --git a/apps/desktop/src/renderer/__tests__/modelManagementActions.test.tsx b/apps/desktop/src/renderer/__tests__/modelManagementActions.test.tsx
index 563e966659..2c7f1ec319 100644
--- a/apps/desktop/src/renderer/__tests__/modelManagementActions.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/modelManagementActions.test.tsx
@@ -141,26 +141,3 @@ it('waits for the shared lock and reports asynchronous write failures', async ()
expect(enabled('pi')).toBe(true);
} finally { vi.unstubAllGlobals(); }
});
-
-// Unit regression: real list rows previously hid all displayPricing. Summary chooses output, then input;
-// cache-only or absent summaries retain the previous behavior. Existing tests only covered visibility actions.
-it.each(['output', 'input', 'cacheRead', 'absent'] as const)('shows the first eligible %s summary quote in a media row', role => {
- const quote = { price: 6, maxPrice: 10, unit: 'token', quantity: 1000000, tier: '480P/720P', priceType: 'starting_at' as const };
- const summary = role === 'absent' ? undefined : {
- [role]: [quote, { ...quote, price: 15, maxPrice: 20, unit: 'second' }],
- ...(role === 'output' ? { input: [{ price: 140, unit: 'character', quantity: 1000000 }] } : {}),
- };
- render(<UnifiedModelList provider={{ ...provider, models: {}, videoModels: [{
- id: 'video', name: 'Video', mode: 'video_generation', currency: 'CNY', costDiscount: 0.2,
- modalities: { input: ['text'], output: ['video'] },
- displayPricing: { items: [{ ...quote, label: 'Supplier quote' }], summary },
- }] }} />);
- if (role === 'cacheRead' || role === 'absent') {
- expect(screen.queryByText(/¥/)).toBeNull();
- } else {
- expect(screen.getByText(/480P\/720P/).textContent).toContain('¥4.8–¥8');
- expect(screen.getByText('¥6–¥10').tagName).toBe('S');
- expect(screen.queryByText(/¥112|¥12/)).toBeNull();
- expect(screen.getByText(/480P\/720P/).textContent).toContain('newChat.modelSelector.displayPricing.startingAt');
- }
-});
diff --git a/apps/desktop/src/renderer/components/DisplayPricingDetails.tsx b/apps/desktop/src/renderer/components/DisplayPricingDetails.tsx
index 73129754dc..74f7f85a5d 100644
--- a/apps/desktop/src/renderer/components/DisplayPricingDetails.tsx
+++ b/apps/desktop/src/renderer/components/DisplayPricingDetails.tsx
@@ -46,12 +46,14 @@ export function DisplayPricingQuote({
? t('newChat.modelSelector.displayPricing.startingAt', { price })
: price;
return (
- <span className="min-w-0 break-words tabular-nums">
- {quote.tier && <>{quote.tier} </>}
- {qualifiedPrice}
- {amount.original && <s className="ml-1.5 text-[var(--text-tertiary)]">{amount.original}</s>}
- <span className="ml-1 text-[var(--text-tertiary)]">
- {denominator}
+ <span className="inline-flex min-w-0 max-w-full flex-col gap-1 tabular-nums">
+ {quote.tier && <span className="break-words text-[var(--text-secondary)]">{quote.tier}</span>}
+ <span className="flex flex-wrap items-baseline justify-end gap-x-1.5 gap-y-1">
+ <span className="whitespace-nowrap">{qualifiedPrice}</span>
+ {amount.original && <s className="whitespace-nowrap text-[var(--text-tertiary)]">{amount.original}</s>}
+ <span className="whitespace-nowrap text-[var(--text-tertiary)]">
+ {denominator}
+ </span>
</span>
</span>
);
diff --git a/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx b/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx
index a210b3e07d..c24870258c 100644
--- a/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx
+++ b/apps/desktop/src/renderer/components/settings/ModelAdvancedDrawer.tsx
@@ -442,6 +442,10 @@ export function ModelAdvancedDrawer({
);
const description = localizedModelDescription(primaryModel, t);
const price = pricePresentationOf(primaryAgent, primaryModel);
+ // Ordinary Gateway chat models carry effective cost; keep their inferred discount.
+ const discount =
+ (!primaryModel.displayPricing && price?.kind === 'priced' ? price.discount : undefined) ??
+ primaryModel.costDiscount;
const protocols = modelProtocolComparison(provider, row.byAgent);
const protocolLabel = (api: PiModelApi | null) =>
api ? MODEL_PROTOCOL_LABEL[api] ?? null : t('settings.providers.models.advanced.undeclared');
@@ -1005,16 +1009,18 @@ export function ModelAdvancedDrawer({
key={role}
label={t(`settings.providers.models.advanced.price.${role === 'cacheWrite' ? 'cacheCreate' : role}`)}
>
- {quotes.map((quote, index) => (
- <span key={index}>
- {index > 0 && ' · '}
- <DisplayPricingQuote
- quote={quote}
- currency={primaryModel.currency!}
- costDiscount={primaryModel.costDiscount}
- />
- </span>
- ))}
+ <span className="flex flex-wrap items-start justify-end gap-x-2 gap-y-2">
+ {quotes.map((quote, index) => (
+ <span key={index} className="inline-flex min-w-0 max-w-full items-start gap-x-2">
+ {index > 0 && <span aria-hidden> · </span>}
+ <DisplayPricingQuote
+ quote={quote}
+ currency={primaryModel.currency!}
+ costDiscount={discount}
+ />
+ </span>
+ ))}
+ </span>
</Row>
);
})}
@@ -1057,7 +1063,7 @@ export function ModelAdvancedDrawer({
</Row>
))
)}
- {!primaryModel.displayPricing && price?.kind === 'priced' && price.discount !== undefined && (
+ {discount !== undefined && discount > 0 && discount <= 1 && (
<Row label={t('settings.providers.models.advanced.discount')}>
<span
className="inline-flex items-center rounded-full px-2 py-[1px] text-10 font-medium"
@@ -1066,7 +1072,7 @@ export function ModelAdvancedDrawer({
backgroundColor: `color-mix(in srgb, ${EFFORT_TIER_COLORS.low} 14%, transparent)`,
}}
>
- {`↓${Math.round(price.discount * 100)}%`}
+ {`↓${Math.round(discount * 100)}%`}
</span>
</Row>
)}
diff --git a/apps/desktop/src/renderer/components/settings/UnifiedModelList.tsx b/apps/desktop/src/renderer/components/settings/UnifiedModelList.tsx
index 14cee635ce..80145ffecf 100644
--- a/apps/desktop/src/renderer/components/settings/UnifiedModelList.tsx
+++ b/apps/desktop/src/renderer/components/settings/UnifiedModelList.tsx
@@ -1,4 +1,3 @@
-import { DisplayPricingQuote } from '@/components/DisplayPricingDetails';
import { Button } from '@/components/ui/button';
import { localizedModelName, localizedBrandName, matchesModelName } from '@/lib/modelDisplayNames';
import { modelManagementState } from './modelManagementState';
@@ -992,15 +991,7 @@ export function UnifiedModelList({
是用来在读到某个模型名时顺手知道它贵不贵。拿不到报价就整个
不渲染 —— 不画假的「$」也不画「—」。 */}
{(() => {
- if (rep.displayPricing && rep.currency) {
- const summary = rep.displayPricing.summary;
- const quote = summary?.output?.[0] ?? summary?.input?.[0];
- return quote ? (
- <span className="min-w-0 text-11 text-[var(--text-secondary)]">
- <DisplayPricingQuote quote={quote} currency={rep.currency} costDiscount={rep.costDiscount} />
- </span>
- ) : null;
- }
+ if (rep.displayPricing) return null;
const display = rowPriceDisplay(row);
if (!display) return null;
if (display.kind === 'free') {
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx
index 9776e3ae7c..021ebdea6d 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/ModelAdvancedDrawer.test.tsx
@@ -47,6 +47,7 @@ vi.mock('../ModelPriceOverrideDialog', () => ({ ModelPriceOverrideDialog: () =>
import { ModelAdvancedDrawer } from '../ModelAdvancedDrawer';
import { setModelVisibility } from '@/state/modelVisibilityPrefs';
import { setProviderModelEffort, getProviderModelEffort, clearProviderModelEffort } from '@/state/providerModelMemory';
+import { modelPricePresentation } from '@/lib/modelPriceFormat';
const model: CatalogModel = {
id: 'gpt-6',
@@ -809,7 +810,8 @@ it.each([{ hasSummary: true, withNotes: true }, { hasSummary: true, withNotes: f
expect(input.textContent).toContain('¥112');
expect(input.querySelector('s')?.textContent).toBe('¥0.02');
const output = screen.getByText('settings.providers.models.advanced.price.output').parentElement!;
- expect(output.textContent).toContain('480P/720P ¥4.8–¥8');
+ expect(screen.getByText('480P/720P')).toBeTruthy();
+ expect(output.textContent).toContain('¥4.8–¥8');
expect(output.querySelector('s')?.textContent).toBe('¥6–¥10');
expect(screen.getByText('settings.providers.models.advanced.price.cacheRead')).toBeTruthy();
expect(screen.getByText('settings.providers.models.advanced.price.cacheCreate')).toBeTruthy();
@@ -827,3 +829,41 @@ it.each([false, true])('omits only a fully redundant supplementary table (notes=
expect(screen.queryByText('Text input') !== null).toBe(withNotes);
expect(screen.queryByText('Provider billing condition') !== null).toBe(withNotes);
});
+
+// Unit regression: the real drawer hid the discount row for displayPricing models.
+// Existing summary tests checked discounted amounts but not the separate discount row.
+// Minimal failure: one video quote with costDiscount=0.4 and no token price presentation.
+it.each([
+ { costDiscount: 0.4, pricing: 'summary', expected: '↓40%' },
+ { costDiscount: 0.4, pricing: 'table', expected: '↓40%' },
+ { costDiscount: 0.4, pricing: 'chat', expected: '↓40%' },
+ { costDiscount: 1, pricing: 'summary', expected: '↓100%' },
+ ...[undefined, 0, -0.1, 1.1, NaN].map(costDiscount => ({ costDiscount, pricing: 'summary', expected: null })),
+])('shows a discount row only for valid model discounts: %j', ({ costDiscount, pricing, expected }) => {
+ const quote = { price: 0.05, maxPrice: 0.2, unit: 'second', quantity: 1 };
+ draw({ ...model, currency: 'CNY', costDiscount,
+ ...(pricing === 'chat' ? {} : { displayPricing: {
+ items: [{ label: 'Generated video', price: 0.05, unit: 'second', quantity: 1 }],
+ ...(pricing === 'summary' ? { summary: { output: [quote] } } : {}),
+ } }),
+ });
+ const label = screen.queryByText('settings.providers.models.advanced.discount');
+ if (expected) expect(label?.parentElement?.textContent).toContain(expected);
+ else expect(label).toBeNull();
+});
+
+// Unit regression found during review: ordinary Gateway chat projections carry effective cost,
+// not costDiscount. Direct-field cases above cannot cover the existing inferred-discount path.
+it('retains the chat discount inferred from standard and effective prices', () => {
+ const primary = { ...model, cost: { input: 1.2, output: 6 } };
+ render(<ModelAdvancedDrawer
+ provider={{ ...provider, id: 'xd' }}
+ row={{ id: primary.id, name: primary.name, avail: ['codex'], byAgent: { codex: primary } }}
+ open onOpenChange={vi.fn()} onDisable={vi.fn()} disabled={false} paymentRequired={false}
+ pricePresentationOf={() => modelPricePresentation({
+ providerId: 'xd', modelId: primary.id, source: 'gateway', approximate: false,
+ currency: 'CNY', inputPerMtok: 2, outputPerMtok: 10,
+ }, primary.cost)}
+ />);
+ expect(screen.getByText('settings.providers.models.advanced.discount').parentElement?.textContent).toContain('↓40%');
+});
diff --git a/docs/dev-rules/model-catalog-maintenance.md b/docs/dev-rules/model-catalog-maintenance.md
index 4ede040cb8..859f4eebe1 100644
--- a/docs/dev-rules/model-catalog-maintenance.md
+++ b/docs/dev-rules/model-catalog-maintenance.md
@@ -114,13 +114,14 @@ Desktop 设置页模型详情有 `displayPricing.summary` 时优先按输入、
沿用原价目表;summary 无效只清除摘要,不丢价目表。补充价目表仅在以下条件全部满足时隐藏:
有 summary 且没有 notes;所有 item 都没有 tier,priceType 缺省或 exact;item 总数等于
所有角色报价段数,且每个 item 能按 unit、quantity、price 一一匹配不同的摘要报价,
-匹配报价没有 maxPrice 或 tier。其余情况保留在摘要下方。设置页列表取 output 首段,没有则取
-input 首段;不从混合单位挑最低价。选择器、浮层和聊天价格档位逻辑保持原样。
+匹配报价没有 maxPrice 或 tier。其余情况保留在摘要下方。设置页列表对带 displayPricing 的
+模型不显示价格;选择器、浮层和聊天价格档位逻辑保持原样。详情中的有效折扣仍单列显示。
+摘要的 tier 单独一行使用次要文字,金额、原价区间和单位分别保持完整,多段报价允许换行。
`price` / `maxPrice` 为每 `quantity` 个 `unit` 的折扣前报价,只在展示时应用一次折扣,保留币种
与“约/起价”语义;角色和已知单位本地化,label、tier、notes 仅按纯文本呈现,未知单位不猜换算。
数量 1 省略,百万按语言简写,其余按本地数字格式显示。共享目录可传递这些可选展示字段,旧端
缺字段仍合法,不新增能力声明;此 UI 仅覆盖 Desktop 设置页。解析与展示回归见
-`modelDisplayPricing.test.ts`、`DisplayPricingDetails.test.tsx` 与 `modelManagementActions.test.tsx`。
+`modelDisplayPricing.test.ts`、`DisplayPricingDetails.test.tsx` 与 `ModelAdvancedDrawer.test.tsx`。
### 覆盖顺序