Skip to content

Commit 5a59d69

Browse files
committed
fix(pricing): hide task prices left at zero when another price is set
A task plugin can offer two billing modes, such as per task for some models and per second for others. An administrator who prices a model per second leaves its per-task price at zero. The model card, the list view and the detail page then showed that unused zero price next to the real one, and it read as a free item. A usage price that is zero in every tier is now hidden when another usage price is set. A model priced at zero throughout still shows its zero prices. The card also drops the tier name when a model has a single tier, since that name was always the editor's default "base".
1 parent 3e2ce2c commit 5a59d69

4 files changed

Lines changed: 89 additions & 1 deletion

File tree

‎web/src/features/pricing/__tests__/model-cards.test.tsx‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,47 @@ describe('model cards', () => {
496496
expect(screen.queryByText(/1K|1M/)).not.toBeInTheDocument()
497497
})
498498

499+
it('hides a task usage price left at zero while another usage price is set', () => {
500+
render(
501+
<ModelCard
502+
model={pricingModel({
503+
billing_mode: 'tiered_expr',
504+
billing_expr: 'tier("base", u("count") * 0 + u("seconds") * 0.7)',
505+
billing_usage_schema: {
506+
count: {
507+
type: 'number',
508+
unit: 'count',
509+
description: { en: 'Per-task price' },
510+
},
511+
seconds: {
512+
type: 'number',
513+
unit: 'second',
514+
description: { en: 'Video generation unit price' },
515+
},
516+
},
517+
})}
518+
onClick={vi.fn()}
519+
/>
520+
)
521+
expect(screen.getByText('Video generation unit price')).toBeVisible()
522+
expect(screen.queryByText('Per-task price')).not.toBeInTheDocument()
523+
})
524+
525+
it('does not show the tier name of a single-tier task price', () => {
526+
render(
527+
<ModelCard
528+
model={pricingModel({
529+
billing_mode: 'tiered_expr',
530+
billing_expr: 'tier("base", u("seconds") * 0.4)',
531+
billing_usage_schema: { seconds: { type: 'number', unit: 'second' } },
532+
})}
533+
onClick={vi.fn()}
534+
/>
535+
)
536+
expect(screen.getByText(/^\$0\.4$/)).toBeVisible()
537+
expect(screen.queryByText('(base)')).not.toBeInTheDocument()
538+
})
539+
499540
it('shows the unconfigured usage message without inventing a token price', () => {
500541
render(
501542
<ModelCard

‎web/src/features/pricing/__tests__/task-matrix-display.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ describe('conditional task price display', () => {
140140
).toBe(true)
141141
})
142142

143+
test.each([
144+
{
145+
expression: 'tier("base", u("count") * 0 + u("seconds") * 0.7)',
146+
unitPrices: { seconds: 0.7 },
147+
},
148+
{
149+
expression: 'tier("free", u("count") * 0 + u("seconds") * 0)',
150+
unitPrices: { count: 0, seconds: 0 },
151+
},
152+
])(
153+
'shows a usage price that is zero in every tier only when no other usage price is set: $expression',
154+
({ expression, unitPrices }) => {
155+
expect(
156+
getTaskPricingDisplayTiers(expression, {
157+
count: { type: 'number', unit: 'count' },
158+
seconds: { type: 'number', unit: 'second' },
159+
}).map((tier) => tier.unitPrices)
160+
).toEqual([unitPrices])
161+
}
162+
)
163+
143164
test('treats a nested condition on an undeclared enum value as never matching', () => {
144165
const tiers = getTaskPricingDisplayTiers(expression, {
145166
...schema,

‎web/src/features/pricing/components/model-card.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export const ModelCard = memo(function ModelCard(props: ModelCardProps) {
192192
</span>
193193
)}
194194
{dynamicSummary.isTaskUsage &&
195+
dynamicSummary.tierCount > 1 &&
195196
dynamicSummary.tier?.label &&
196197
!dynamicSummary.primaryEntries.some(
197198
(entry) => entry.formattedRange

‎web/src/features/pricing/lib/task-matrix-display.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,35 @@ export function getTaskMatrixDisplayTiers(
5656
}))
5757
}
5858

59+
/** A usage price that is zero in every tier is left out while another usage
60+
* price is set, so a plugin field the model does not bill on is not listed as
61+
* free. A model priced at zero throughout keeps its zero prices.
62+
*/
63+
export function getTaskPricingDisplayTiers(
64+
expression: string | null | undefined,
65+
schema: BillingUsageSchema | null | undefined
66+
): ParsedTaskTier[] {
67+
const tiers = readTaskPricingTiers(expression, schema)
68+
const pricedFields = new Set(
69+
tiers.flatMap((tier) =>
70+
Object.keys(tier.unitPrices).filter((field) => tier.unitPrices[field] > 0)
71+
)
72+
)
73+
if (pricedFields.size === 0) return tiers
74+
return tiers.map((tier) => ({
75+
...tier,
76+
unitPrices: Object.fromEntries(
77+
Object.entries(tier.unitPrices).filter(([field]) =>
78+
pricedFields.has(field)
79+
)
80+
),
81+
}))
82+
}
83+
5984
/** Display explicit conditions for a fallback only when its complement is unique.
6085
* Unlike the editor matrix, unrelated schema fields do not expand the price table.
6186
*/
62-
export function getTaskPricingDisplayTiers(
87+
function readTaskPricingTiers(
6388
expression: string | null | undefined,
6489
schema: BillingUsageSchema | null | undefined
6590
): ParsedTaskTier[] {

0 commit comments

Comments
 (0)