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。

feat(mobile): show discounted model prices in the options sheet (#3624)

Yecheng Fu51dd21a60251
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/authStatusUsageHandlers.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/authStatusUsageHandlers.test.ts
index 473308efff..be8fb61d5e 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/authStatusUsageHandlers.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/authStatusUsageHandlers.test.ts
@@ -3,7 +3,7 @@ import { describe, expect, it, vi } from 'vitest';
import { parseCodexDeviceCodeProgress, registerMakerAuthHandlers } from '../authHandlers';
import { MAKER_INVOKE, MAKER_PUSH } from '../channels';
import { registerMakerStatusHandlers } from '../statusHandlers';
-import { registerMakerUsageHandlers } from '../usageHandlers';
+import { registerMakerUsageHandlers, toLegacyUsdModelPricing } from '../usageHandlers';
import { CodexRateLimitResetRejectedError } from '../../usage/codexRateLimitReset';
import { IpcHarness } from './helpers/ipcHarness';
import { zeroUsageMoney } from '../../../shared/regionalMoney';
@@ -1304,6 +1304,55 @@ describe('maker usage IPC handlers', () => {
expect(readModelPricing).toHaveBeenCalledTimes(2);
});
+ it('appends a valid Gateway costDiscount onto the legacy USD pricing channel', () => {
+ expect(
+ toLegacyUsdModelPricing({
+ xd: {
+ 'grok-4.6': {
+ providerId: 'xd',
+ modelId: 'grok-4.6',
+ currency: 'USD',
+ source: 'gateway',
+ approximate: false,
+ inputPerMtok: 2,
+ outputPerMtok: 6,
+ costDiscount: 0.4,
+ },
+ 'invalid-discount': {
+ providerId: 'xd',
+ modelId: 'invalid-discount',
+ currency: 'USD',
+ source: 'gateway',
+ approximate: false,
+ inputPerMtok: 3,
+ outputPerMtok: 15,
+ costDiscount: 1.2,
+ },
+ 'cny-discounted': {
+ providerId: 'xd',
+ modelId: 'cny-discounted',
+ currency: 'CNY',
+ source: 'gateway',
+ approximate: false,
+ inputPerMtok: 5,
+ outputPerMtok: 25,
+ costDiscount: 0.5,
+ },
+ },
+ }),
+ ).toEqual({
+ 'grok-4.6': {
+ inputUsdPerMtok: 2,
+ outputUsdPerMtok: 6,
+ costDiscount: 0.4,
+ },
+ 'invalid-discount': {
+ inputUsdPerMtok: 3,
+ outputUsdPerMtok: 15,
+ },
+ });
+ });
+
it('serves non-XD reference prices on a channel independent from XD pricing', async () => {
const harness = new IpcHarness();
const referencePricing = {
diff --git a/apps/desktop/src/main/maker-ipc/usageHandlers.ts b/apps/desktop/src/main/maker-ipc/usageHandlers.ts
index 0d1dd0f8f1..98c631e819 100644
--- a/apps/desktop/src/main/maker-ipc/usageHandlers.ts
+++ b/apps/desktop/src/main/maker-ipc/usageHandlers.ts
@@ -26,13 +26,22 @@ export interface LegacyUsdModelPrice {
outputUsdPerMtok: number;
cacheReadUsdPerMtok?: number;
cacheCreateUsdPerMtok?: number;
+ /** Gateway 折扣比例 0..1;旧控制端忽略。计费金额 = 原价 × (1 - costDiscount)。 */
+ costDiscount?: number;
}
export type LegacyUsdModelPricingMap = Record<string, LegacyUsdModelPrice>;
+function normalizedCostDiscount(value: unknown): number | undefined {
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 && value <= 1
+ ? value
+ : undefined;
+}
+
/**
* device-link v1 兼容投影。旧控制端只能表达扁平 USD 价格,因此只投影真实 USD quote;
* CNY 不能反算或写进 *Usd,旧端按既有“无价隐藏”语义降级。
+ * costDiscount 是 append-only:新控制端用来算折后价,旧端忽略未知字段。
*/
export function toLegacyUsdModelPricing(
pricing: ModelPricingMap | null,
@@ -40,6 +49,7 @@ export function toLegacyUsdModelPricing(
const out: LegacyUsdModelPricingMap = {};
for (const [modelId, quote] of Object.entries(pricing?.xd ?? {})) {
if (quote.currency !== 'USD') continue;
+ const costDiscount = normalizedCostDiscount(quote.costDiscount);
out[modelId] = {
inputUsdPerMtok: quote.inputPerMtok,
outputUsdPerMtok: quote.outputPerMtok,
@@ -49,6 +59,7 @@ export function toLegacyUsdModelPricing(
...(quote.cacheCreatePerMtok !== undefined
? { cacheCreateUsdPerMtok: quote.cacheCreatePerMtok }
: {}),
+ ...(costDiscount !== undefined ? { costDiscount } : {}),
};
}
return Object.keys(out).length > 0 ? out : null;
diff --git a/apps/mobile/src/__tests__/modelPickerRows.test.ts b/apps/mobile/src/__tests__/modelPickerRows.test.ts
index 6ca7752124..9546f866fe 100644
--- a/apps/mobile/src/__tests__/modelPickerRows.test.ts
+++ b/apps/mobile/src/__tests__/modelPickerRows.test.ts
@@ -18,6 +18,7 @@ import {
formatContextWindow,
formatPriceLine,
modelRowAccessibilityLabel,
+ presentPickerPrice,
providerDisplayTitle,
rowEffortOf,
rowFastEditable,
@@ -75,23 +76,142 @@ describe('providerDisplayTitle / formatPriceLine / buildRowMetaLine', () => {
expect(formatPriceLine(undefined)).toBeNull();
});
- it('元信息行 = 供应商 · 上下文 · 单价 · 快速;全空 → null', () => {
+ it('元信息行 = 供应商 · 上下文 · 快速;单价改走独立价格块;全空 → null', () => {
const full = buildRowMetaLine({
provider: { id: 'xd', name: 'XD Gateway' },
model: { id: 'gpt-5.5', contextWindow: 272_000, supportsFastMode: true },
- pricing: { 'gpt-5.5': { inputUsdPerMtok: 3, outputUsdPerMtok: 15 } },
});
- expect(full).toBe('Cindy AI · 272K 上下文 · 输入 $3 · 输出 $15 / 百万 token · 快速');
+ expect(full).toBe('Cindy AI · 272K 上下文 · 快速');
const minimal = buildRowMetaLine({
provider: null,
model: { id: 'm', contextWindow: 0 },
- pricing: null,
});
expect(minimal).toBeNull();
});
});
+function xdProviderWithCost(
+ modelId: string,
+ cost: { input: number; output: number },
+): ProviderView {
+ return {
+ id: 'xd',
+ name: 'Cindy AI',
+ agents: ['codex'],
+ connected: true,
+ models: { codex: [{ id: modelId, cost }] },
+ } as unknown as ProviderView;
+}
+
+describe('presentPickerPrice', () => {
+ it('无报价 → null;有报价无折扣 → 标准价', () => {
+ expect(
+ presentPickerPrice({
+ pricing: null,
+ provider: null,
+ modelId: 'grok-4.6',
+ agentKind: 'codex',
+ }),
+ ).toBeNull();
+ expect(
+ presentPickerPrice({
+ pricing: { 'grok-4.6': { inputUsdPerMtok: 2, outputUsdPerMtok: 6 } },
+ provider: null,
+ modelId: 'grok-4.6',
+ agentKind: 'codex',
+ }),
+ ).toEqual({
+ title: '每百万 token',
+ amountsLine: '输入 $2 · 输出 $6',
+ discountLabel: null,
+ });
+ });
+
+ it('目录折后价与标准价同比例时展示折后价 + 折扣说明', () => {
+ expect(
+ presentPickerPrice({
+ pricing: { 'grok-4.6': { inputUsdPerMtok: 2, outputUsdPerMtok: 6 } },
+ provider: xdProviderWithCost('grok-4.6', { input: 0.3, output: 0.9 }),
+ modelId: 'grok-4.6',
+ agentKind: 'codex',
+ }),
+ ).toEqual({
+ title: '每百万 token',
+ amountsLine: '输入 $0.3 · 输出 $0.9',
+ discountLabel: '折扣中,较标准价省 85%',
+ discountPct: 85,
+ });
+ });
+
+ it('目录缺失时回退报价 costDiscount', () => {
+ expect(
+ presentPickerPrice({
+ pricing: {
+ 'grok-4.6': { inputUsdPerMtok: 2, outputUsdPerMtok: 6, costDiscount: 0.4 },
+ },
+ provider: null,
+ modelId: 'grok-4.6',
+ agentKind: 'codex',
+ }),
+ ).toEqual({
+ title: '每百万 token',
+ amountsLine: '输入 $1.2 · 输出 $3.6',
+ discountLabel: '折扣中,较标准价省 40%',
+ discountPct: 40,
+ });
+ });
+
+ it('目录折后价比例不一致时不挂折扣,保持标准价', () => {
+ expect(
+ presentPickerPrice({
+ pricing: { 'grok-4.6': { inputUsdPerMtok: 2, outputUsdPerMtok: 6 } },
+ provider: xdProviderWithCost('grok-4.6', { input: 1, output: 6 }),
+ modelId: 'grok-4.6',
+ agentKind: 'codex',
+ }),
+ ).toEqual({
+ title: '每百万 token',
+ amountsLine: '输入 $2 · 输出 $6',
+ discountLabel: null,
+ });
+ });
+
+ it('非 XD 供应商即使 modelId 撞车也不套用 XD 报价', () => {
+ const openai = {
+ id: 'openai',
+ name: 'OpenAI',
+ agents: ['codex'],
+ connected: true,
+ models: { codex: [{ id: 'gpt-5.5', cost: { input: 1, output: 5 } }] },
+ } as unknown as ProviderView;
+ expect(
+ presentPickerPrice({
+ pricing: { 'gpt-5.5': { inputUsdPerMtok: 3, outputUsdPerMtok: 15, costDiscount: 0.4 } },
+ provider: openai,
+ modelId: 'gpt-5.5',
+ agentKind: 'codex',
+ }),
+ ).toBeNull();
+ });
+
+ it('折后价小于 1 分时保留最多 4 位小数,不显示成 $0', () => {
+ expect(
+ presentPickerPrice({
+ pricing: { cheap: { inputUsdPerMtok: 0.04, outputUsdPerMtok: 0.04, costDiscount: 0.9 } },
+ provider: null,
+ modelId: 'cheap',
+ agentKind: 'codex',
+ }),
+ ).toEqual({
+ title: '每百万 token',
+ amountsLine: '输入 $0.004 · 输出 $0.004',
+ discountLabel: '折扣中,较标准价省 90%',
+ discountPct: 90,
+ });
+ });
+});
+
describe('effortLabelFor —— 五级优先(i18n → 模型覆盖 → capabilities → 兼容词表 → 原 id)', () => {
it('已知档位优先使用当前界面的本地化文案', () => {
expect(effortLabelFor({ effortDisplayNames: { xhigh: '特高' } }, 'xhigh', capabilities)).toBe('超高');
diff --git a/apps/mobile/src/device-link/mobileMakerTransport.ts b/apps/mobile/src/device-link/mobileMakerTransport.ts
index 9478f95f70..1578abc52b 100644
--- a/apps/mobile/src/device-link/mobileMakerTransport.ts
+++ b/apps/mobile/src/device-link/mobileMakerTransport.ts
@@ -278,6 +278,8 @@ export interface MobileActiveSessionSnapshot {
export interface MobileModelPrice {
inputUsdPerMtok: number;
outputUsdPerMtok: number;
+ /** Gateway 折扣比例 0..1;旧被控端不下发。计费金额 = 原价 × (1 - costDiscount)。 */
+ costDiscount?: number;
}
export type MobileModelPricingMap = Record<string, MobileModelPrice>;
diff --git a/apps/mobile/src/i18n/locales/en/models.json b/apps/mobile/src/i18n/locales/en/models.json
index b4da734842..3929b243c1 100644
--- a/apps/mobile/src/i18n/locales/en/models.json
+++ b/apps/mobile/src/i18n/locales/en/models.json
@@ -18,6 +18,9 @@
"configureAccessibility": "Configure {{model}}",
"budgetDisabledHint": "This model needs an API key configured on the controlled device first",
"priceLine": "Input {{input}} · Output {{output}} / million tokens",
+ "priceTitle": "Per 1M tokens",
+ "priceAmounts": "Input {{input}} · Output {{output}}",
+ "discountedVsStandard": "Discounted · {{percent}}% off standard",
"contextSuffix": "{{size}} context",
"fastTag": "Fast"
},
diff --git a/apps/mobile/src/i18n/locales/ja/models.json b/apps/mobile/src/i18n/locales/ja/models.json
index 7defb7c1d8..240a32f054 100644
--- a/apps/mobile/src/i18n/locales/ja/models.json
+++ b/apps/mobile/src/i18n/locales/ja/models.json
@@ -18,6 +18,9 @@
"configureAccessibility": "{{model}} を設定",
"budgetDisabledHint": "このモデルを使うには、先に操作対象のデバイスで API キーを設定してください",
"priceLine": "入力 {{input}} · 出力 {{output}} / 100万トークン",
+ "priceTitle": "100万トークンあたり",
+ "priceAmounts": "入力 {{input}} · 出力 {{output}}",
+ "discountedVsStandard": "割引中 · 標準価格から {{percent}}% お得",
"contextSuffix": "{{size}} コンテキスト",
"fastTag": "高速"
},
diff --git a/apps/mobile/src/i18n/locales/ko/models.json b/apps/mobile/src/i18n/locales/ko/models.json
index b8316ce834..6f4326b897 100644
--- a/apps/mobile/src/i18n/locales/ko/models.json
+++ b/apps/mobile/src/i18n/locales/ko/models.json
@@ -18,6 +18,9 @@
"configureAccessibility": "{{model}} 구성",
"budgetDisabledHint": "이 모델을 사용하려면 먼저 제어 대상 기기에서 API 키를 설정해야 합니다",
"priceLine": "입력 {{input}} · 출력 {{output}} / 100만 토큰",
+ "priceTitle": "100만 토큰당",
+ "priceAmounts": "입력 {{input}} · 출력 {{output}}",
+ "discountedVsStandard": "할인 중 · 표준가 대비 {{percent}}% 절약",
"contextSuffix": "{{size}} 컨텍스트",
"fastTag": "빠름"
},
diff --git a/apps/mobile/src/i18n/locales/zh-CN/models.json b/apps/mobile/src/i18n/locales/zh-CN/models.json
index f976ebcc19..cb6431aae2 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/models.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/models.json
@@ -18,6 +18,9 @@
"configureAccessibility": "配置 {{model}}",
"budgetDisabledHint": "该模型需先在被控设备配置 API key 才能使用",
"priceLine": "输入 {{input}} · 输出 {{output}} / 百万 token",
+ "priceTitle": "每百万 token",
+ "priceAmounts": "输入 {{input}} · 输出 {{output}}",
+ "discountedVsStandard": "折扣中,较标准价省 {{percent}}%",
"contextSuffix": "{{size}} 上下文",
"fastTag": "快速"
},
diff --git a/apps/mobile/src/i18n/locales/zh-TW/models.json b/apps/mobile/src/i18n/locales/zh-TW/models.json
index 440d5ca65e..603765a31b 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/models.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/models.json
@@ -18,6 +18,9 @@
"configureAccessibility": "配置 {{model}}",
"budgetDisabledHint": "該模型需先在被控裝置配置 API key 才能使用",
"priceLine": "輸入 {{input}} · 輸出 {{output}} / 百萬 token",
+ "priceTitle": "每百萬 token",
+ "priceAmounts": "輸入 {{input}} · 輸出 {{output}}",
+ "discountedVsStandard": "折扣中,較標準價省 {{percent}}%",
"contextSuffix": "{{size}} 上下文",
"fastTag": "快速"
},
diff --git a/apps/mobile/src/session/ModelOptionsSheetView.tsx b/apps/mobile/src/session/ModelOptionsSheetView.tsx
index eff6eb9564..b3110e322f 100644
--- a/apps/mobile/src/session/ModelOptionsSheetView.tsx
+++ b/apps/mobile/src/session/ModelOptionsSheetView.tsx
@@ -1,8 +1,9 @@
/**
* ModelOptionsSheetView —— 模型浮窗二级「模型选项」视图的内容(SheetSurface 的 children)。
*
- * 承接原先行内 accordion 的配置区语义:顶部元信息行(供应商全名 · 上下文 · 单价 · 极速,
- * 对齐桌面 hover tooltip 口径)+ 「快速模式」Switch + 「推理强度」竖排单选。
+ * 承接原先行内 accordion 的配置区语义:顶部元信息行(供应商全名 · 上下文 · 极速)+
+ * 价格块(折后价 + 可选折扣说明,对齐桌面 ModelConfigFlyout)+
+ * 「快速模式」Switch + 「推理强度」竖排单选。
* 读写语义与桌面完全一致:目标行是**选中行** → 改 live(onChangeSelectedEffort/FastMode);
* **非选中行** → 写注入记忆(草稿 = draftModelMemory / 会话 = sessionModelMirror 写穿被控端)。
* effort 点击后停留(可连续调 Fast),返回/把手下拉由浮窗层负责。
@@ -23,6 +24,7 @@ import { useSessionModelMirrorVersion } from "@/session/sessionModelMirror";
import {
buildRowMetaLine,
effortLabelFor,
+ presentPickerPrice,
rowEffortOf,
rowFastOn,
type PickerRowModel,
@@ -69,12 +71,34 @@ export interface ModelOptionsSheetViewProps {
const makeStyles = (c: ThemeColors) =>
StyleSheet.create({
+ headerBlock: {
+ gap: spacing.xs,
+ paddingBottom: spacing.sm,
+ paddingTop: spacing.xs,
+ },
metaLine: {
color: c.textTertiary,
fontSize: typeScale.footnote,
lineHeight: lineHeight.caption,
- paddingBottom: spacing.sm,
- paddingTop: spacing.xs,
+ },
+ priceBlock: {
+ gap: spacing.xs,
+ },
+ priceTitle: {
+ color: c.textTertiary,
+ fontSize: typeScale.footnote,
+ lineHeight: lineHeight.caption,
+ },
+ // 折扣说明用 statusDone(#2AAE5B),与桌面 EFFORT_TIER_COLORS.low / «省 X%» 绿色加粗同源。
+ priceDiscount: {
+ color: c.statusDone,
+ fontWeight: fontWeight.semibold,
+ },
+ priceAmounts: {
+ color: c.textPrimary,
+ fontSize: typeScale.footnote,
+ fontWeight: fontWeight.medium,
+ lineHeight: lineHeight.caption,
},
// 与推理强度选项行同一水平内边距(effortOptionRow 的 pill 内距):
// label 与选项文字左对齐,Switch 与选项行的 Check 右对齐。
@@ -154,7 +178,12 @@ export function ModelOptionsSheetView({
contextWindow,
supportsFastMode: model.supportsFastMode,
},
+ });
+ const price = presentPickerPrice({
pricing,
+ provider,
+ modelId: model.id,
+ agentKind,
});
const currentEffort = rowEffortOf({
model,
@@ -195,10 +224,32 @@ export function ModelOptionsSheetView({
return (
<View testID={testID}>
- {metaLine ? (
- <Text style={styles.metaLine} testID={`${testID}.meta`}>
- {metaLine}
- </Text>
+ {metaLine || price ? (
+ <View style={styles.headerBlock}>
+ {metaLine ? (
+ <Text style={styles.metaLine} testID={`${testID}.meta`}>
+ {metaLine}
+ </Text>
+ ) : null}
+ {price ? (
+ <View style={styles.priceBlock} testID={`${testID}.price`}>
+ <Text style={styles.priceTitle}>
+ {price.title}
+ {price.discountLabel ? (
+ <Text style={styles.priceDiscount}>
+ {` · ${price.discountLabel}`}
+ </Text>
+ ) : null}
+ </Text>
+ <Text
+ style={styles.priceAmounts}
+ testID={`${testID}.priceAmounts`}
+ >
+ {price.amountsLine}
+ </Text>
+ </View>
+ ) : null}
+ </View>
) : null}
{fastEditable ? (
<View style={styles.fastRow}>
diff --git a/apps/mobile/src/session/modelPickerRows.ts b/apps/mobile/src/session/modelPickerRows.ts
index 52be09a72e..a6ee78f1df 100644
--- a/apps/mobile/src/session/modelPickerRows.ts
+++ b/apps/mobile/src/session/modelPickerRows.ts
@@ -6,7 +6,7 @@
* (mobile i18n 化后由 models.json catalog 供文案,在使用点求值 i18n.t)。组件只做渲染,
* 这里可 node 单测。
*/
-import { modelSupportsFastMode, type ProviderView } from '@cindy/model-providers/registry';
+import { getModel, modelSupportsFastMode, type ProviderView } from '@cindy/model-providers/registry';
import type { SectionModel } from '@cindy/model-providers/sections';
import type { AgentKind } from '@cindy/model-providers/types';
@@ -64,34 +64,161 @@ export function providerDisplayTitle(p: Pick<ProviderView, 'id' | 'name'>): stri
return PROVIDER_TITLE[p.id] ?? p.name;
}
+function isNonNegativeFinite(value: unknown): value is number {
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0;
+}
+
+function normalizedCostDiscount(value: unknown): number | undefined {
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 && value <= 1
+ ? value
+ : undefined;
+}
+
+/** 对齐桌面 formatModelPriceAmount:小于 1 分保留最多 4 位,否则最多 2 位,不补零。 */
+function compactNumber(value: number): string {
+ return new Intl.NumberFormat('en-US', {
+ maximumFractionDigits: value > 0 && value < 0.01 ? 4 : 2,
+ useGrouping: false,
+ }).format(value);
+}
+
+function formatUsd(value: number): string {
+ return `$${compactNumber(value)}`;
+}
+
+function compactPercent(discount: number): string {
+ return new Intl.NumberFormat('en-US', {
+ maximumFractionDigits: 2,
+ useGrouping: false,
+ }).format(discount * 100);
+}
+
+// 各价格维度的缩放比例小于这个阈值时视为浮点噪声,按标准价展示。对齐桌面 modelPriceFormat。
+const MIN_EFFECTIVE_PRICE_GAP = 0.0005;
+
+function inferInputOutputDiscount(
+ standardInput: number,
+ standardOutput: number,
+ effectiveInput: number,
+ effectiveOutput: number,
+): number | undefined {
+ const gaps: number[] = [];
+ for (const [standard, effective] of [
+ [standardInput, effectiveInput],
+ [standardOutput, effectiveOutput],
+ ] as const) {
+ if (standard === 0) {
+ if (effective !== 0) return undefined;
+ continue;
+ }
+ const gap = 1 - effective / standard;
+ if (gap < MIN_EFFECTIVE_PRICE_GAP || gap > 1) return undefined;
+ gaps.push(gap);
+ }
+ if (gaps.length === 0) return undefined;
+ return gaps.every((gap) => Math.abs(gap - gaps[0]) < 1e-9) ? gaps[0] : undefined;
+}
+
/** 单价行(对齐桌面 zh-CN priceTip:「输入 $3 · 输出 $15 / 百万 token」);无价返回 null。 */
export function formatPriceLine(
price: { inputUsdPerMtok: number; outputUsdPerMtok: number } | undefined,
): string | null {
if (!price) return null;
- const fmt = (v: number) => `$${Number(v.toFixed(2))}`;
return i18n.t('models.picker.priceLine', {
- input: fmt(price.inputUsdPerMtok),
- output: fmt(price.outputUsdPerMtok),
+ input: formatUsd(price.inputUsdPerMtok),
+ output: formatUsd(price.outputUsdPerMtok),
});
}
+/** 模型选项页的价格块:折后价 + 可选折扣说明。无报价 → null。 */
+export interface PickerPricePresentation {
+ title: string;
+ amountsLine: string;
+ discountLabel: string | null;
+ discountPct?: number;
+}
+
/**
- * 行展开区顶部的元信息行(对齐桌面 hover tooltip 的拼接口径:
- * 供应商完整名 · {contextWindow} 上下文 · 单价 · 快速)。全部缺失 → null(不渲染)。
+ * 模型选项页价格展示。报价表给标准价;目录 CatalogModel.cost 给折后价(桌面同口径)。
+ * 目录缺失时回退报价上的 costDiscount。比例不一致时不挂折扣,避免把混用价当成折后价。
+ * v1 通道只有 XD USD 扁平表:明确非 xd 的供应商行不读这张表(对齐桌面 provider-aware
+ * 查找);provider === null 是旧被控端扁平回退,仍可用。
+ */
+export function presentPickerPrice(args: {
+ pricing: MobileModelPricingMap | null;
+ provider: ProviderView | null;
+ modelId: string;
+ agentKind: AgentKind | null;
+}): PickerPricePresentation | null {
+ if (args.provider && args.provider.id !== 'xd') return null;
+ const quote = args.pricing?.[args.modelId];
+ if (
+ !quote ||
+ !isNonNegativeFinite(quote.inputUsdPerMtok) ||
+ !isNonNegativeFinite(quote.outputUsdPerMtok)
+ ) {
+ return null;
+ }
+
+ let currentInput = quote.inputUsdPerMtok;
+ let currentOutput = quote.outputUsdPerMtok;
+ let discount: number | undefined;
+
+ const catalogCost =
+ args.provider && args.agentKind
+ ? getModel(args.provider, args.modelId, args.agentKind)?.cost
+ : undefined;
+ const catalogInput = catalogCost?.input;
+ const catalogOutput = catalogCost?.output;
+
+ if (isNonNegativeFinite(catalogInput) && isNonNegativeFinite(catalogOutput)) {
+ discount = inferInputOutputDiscount(
+ quote.inputUsdPerMtok,
+ quote.outputUsdPerMtok,
+ catalogInput,
+ catalogOutput,
+ );
+ if (discount !== undefined) {
+ currentInput = catalogInput;
+ currentOutput = catalogOutput;
+ }
+ } else {
+ const fromQuote = normalizedCostDiscount(quote.costDiscount);
+ if (fromQuote !== undefined) {
+ discount = fromQuote;
+ currentInput = quote.inputUsdPerMtok * (1 - fromQuote);
+ currentOutput = quote.outputUsdPerMtok * (1 - fromQuote);
+ }
+ }
+
+ const discountLabel =
+ discount !== undefined
+ ? i18n.t('models.picker.discountedVsStandard', { percent: compactPercent(discount) })
+ : null;
+ return {
+ title: i18n.t('models.picker.priceTitle'),
+ amountsLine: i18n.t('models.picker.priceAmounts', {
+ input: formatUsd(currentInput),
+ output: formatUsd(currentOutput),
+ }),
+ discountLabel,
+ ...(discount !== undefined ? { discountPct: Math.round(discount * 100) } : {}),
+ };
+}
+
+/**
+ * 行展开区顶部的元信息行(供应商完整名 · {contextWindow} 上下文 · 快速)。
+ * 单价改由 presentPickerPrice 单独成块,对齐桌面 ModelConfigFlyout。全部缺失 → null。
*/
export function buildRowMetaLine(args: {
provider: Pick<ProviderView, 'id' | 'name'> | null;
model: Pick<SectionModel, 'id' | 'contextWindow' | 'supportsFastMode'>;
- pricing: MobileModelPricingMap | null;
}): string | null {
const parts: string[] = [];
if (args.provider) parts.push(providerDisplayTitle(args.provider));
if (args.model.contextWindow > 0) {
parts.push(i18n.t('models.picker.contextSuffix', { size: formatContextWindow(args.model.contextWindow) }));
}
- const price = formatPriceLine(args.pricing?.[args.model.id]);
- if (price) parts.push(price);
if (args.model.supportsFastMode) parts.push(i18n.t('models.picker.fastTag'));
return parts.length > 0 ? parts.join(' · ') : null;
}