Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import * as z from 'zod'

import { combineBillingExpr } from '@/features/pricing/lib/billing-expr'

import { formatPricingNumber } from './pricing-format'
import {
formatDisplayPriceFromUSD,
formatPricingNumber,
} from './pricing-format'

export const createModelPricingSchema = (t: (key: string) => string) =>
z.object({
Expand Down Expand Up @@ -173,7 +176,10 @@ function deriveLanePrice(
return formatPricingNumber(ratioNumber * denominatorNumber)
}

export function createInitialLaneState(data?: ModelRatioData | null) {
export function createInitialLaneState(
data?: ModelRatioData | null,
exchangeRate = 1
) {
if (!data) {
return {
promptPrice: '',
Expand All @@ -182,7 +188,10 @@ export function createInitialLaneState(data?: ModelRatioData | null) {
}
}

const promptPrice = ratioToBasePrice(data.ratio)
const promptPrice = formatDisplayPriceFromUSD(
ratioToBasePrice(data.ratio),
exchangeRate
)
const audioInputPrice = deriveLanePrice(data.audioRatio, promptPrice)
const prices: Record<LaneKey, string> = {
completion: deriveLanePrice(data.completionRatio, promptPrice),
Expand Down Expand Up @@ -215,7 +224,8 @@ export function buildPreviewRows(
promptPrice: string,
lanePrices: Record<LaneKey, string>,
laneEnabled: Record<LaneKey, boolean>,
t: (key: string) => string
t: (key: string) => string,
formatPriceValue: (value: string) => string = (value) => `$${value}`
): PreviewRow[] {
if (mode === 'tiered_expr') {
const effectiveExpr = combineBillingExpr(billingExpr, requestRuleExpr)
Expand All @@ -235,7 +245,7 @@ export function buildPreviewRows(
{
key: 'price',
label: 'ModelPrice',
value: values.price || t('Empty'),
value: values.price ? formatPriceValue(values.price) : t('Empty'),
},
]
}
Expand All @@ -244,54 +254,54 @@ export function buildPreviewRows(
{
key: 'inputPrice',
label: t('Input price'),
value: promptPrice ? `$${promptPrice}` : t('Empty'),
value: promptPrice ? formatPriceValue(promptPrice) : t('Empty'),
},
{
key: 'completion',
label: t('Completion price'),
value:
laneEnabled.completion && lanePrices.completion
? `$${lanePrices.completion}`
? formatPriceValue(lanePrices.completion)
: t('Empty'),
},
{
key: 'cache',
label: t('Cache read price'),
value:
laneEnabled.cache && lanePrices.cache
? `$${lanePrices.cache}`
? formatPriceValue(lanePrices.cache)
: t('Empty'),
},
{
key: 'createCache',
label: t('Cache write price'),
value:
laneEnabled.createCache && lanePrices.createCache
? `$${lanePrices.createCache}`
? formatPriceValue(lanePrices.createCache)
: t('Empty'),
},
{
key: 'image',
label: t('Image input price'),
value:
laneEnabled.image && lanePrices.image
? `$${lanePrices.image}`
? formatPriceValue(lanePrices.image)
: t('Empty'),
},
{
key: 'audio',
label: t('Audio input price'),
value:
laneEnabled.audioInput && lanePrices.audioInput
? `$${lanePrices.audioInput}`
? formatPriceValue(lanePrices.audioInput)
: t('Empty'),
},
{
key: 'audioCompletion',
label: t('Audio output price'),
value:
laneEnabled.audioOutput && lanePrices.audioOutput
? `$${lanePrices.audioOutput}`
? formatPriceValue(lanePrices.audioOutput)
: t('Empty'),
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ export function PriceInput(props: {
value: string
placeholder?: string
disabled?: boolean
prefix?: string
suffix?: string
onChange: (value: string) => void
}) {
return (
<InputGroup>
<InputGroupAddon>$</InputGroupAddon>
<InputGroupAddon>{props.prefix ?? '$'}</InputGroupAddon>
<InputGroupInput
inputMode='decimal'
value={props.value}
placeholder={props.placeholder}
disabled={props.disabled}
onChange={(event) => props.onChange(event.target.value)}
/>
<InputGroupAddon align='inline-end'>$/1M</InputGroupAddon>
<InputGroupAddon align='inline-end'>
{props.suffix ?? '$/1M'}
</InputGroupAddon>
</InputGroup>
)
}
Expand All @@ -58,6 +62,9 @@ export function PriceLane(props: {
value: string
enabled: boolean
disabled?: boolean
prefix?: string
suffix?: string
hideUnitDescription?: boolean
onEnabledChange: (checked: boolean) => void
onChange: (value: string) => void
}) {
Expand All @@ -81,13 +88,17 @@ export function PriceLane(props: {
value={props.value}
placeholder={props.placeholder}
disabled={effectiveDisabled}
prefix={props.prefix}
suffix={props.suffix}
onChange={props.onChange}
/>
<p className='text-muted-foreground text-xs'>
{props.enabled
? t('USD price per 1M tokens.')
: t('Disabled lanes are omitted on save.')}
</p>
{!props.hideUnitDescription && (
<p className='text-muted-foreground text-xs'>
{props.enabled
? t('USD price per 1M tokens.')
: t('Disabled lanes are omitted on save.')}
</p>
)}
Comment on lines +91 to +101

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

hideUnitDescription also hides the non-currency-specific "Disabled lanes" hint.

When hideUnitDescription is true (non-USD currency), the entire <p> is omitted, including t('Disabled lanes are omitted on save.'). That message is not currency-specific and should remain visible so non-USD users still understand what happens when a lane is disabled.

🐛 Proposed fix: separate the two conditions
       />
-      {!props.hideUnitDescription && (
-        <p className='text-muted-foreground text-xs'>
-          {props.enabled
-            ? t('USD price per 1M tokens.')
-            : t('Disabled lanes are omitted on save.')}
-        </p>
-      )}
+      {props.enabled && !props.hideUnitDescription && (
+        <p className='text-muted-foreground text-xs'>
+          {t('USD price per 1M tokens.')}
+        </p>
+      )}
+      {!props.enabled && (
+        <p className='text-muted-foreground text-xs'>
+          {t('Disabled lanes are omitted on save.')}
+        </p>
+      )}
     </SettingsControlGroup>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
prefix={props.prefix}
suffix={props.suffix}
onChange={props.onChange}
/>
<p className='text-muted-foreground text-xs'>
{props.enabled
? t('USD price per 1M tokens.')
: t('Disabled lanes are omitted on save.')}
</p>
{!props.hideUnitDescription && (
<p className='text-muted-foreground text-xs'>
{props.enabled
? t('USD price per 1M tokens.')
: t('Disabled lanes are omitted on save.')}
</p>
)}
/>
{props.enabled && !props.hideUnitDescription && (
<p className='text-muted-foreground text-xs'>
{t('USD price per 1M tokens.')}
</p>
)}
{!props.enabled && (
<p className='text-muted-foreground text-xs'>
{t('Disabled lanes are omitted on save.')}
</p>
)}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/default/src/features/system-settings/models/model-pricing-inputs.tsx`
around lines 91 - 101, Update the conditional rendering around the helper text
in the model pricing input component: keep the currency-specific “USD price per
1M tokens.” text gated by `!props.hideUnitDescription`, but render the “Disabled
lanes are omitted on save.” hint whenever `props.enabled` is false, regardless
of `hideUnitDescription`.

</SettingsControlGroup>
)
}
Loading