diff --git a/src/components/OnboardingDialog.tsx b/src/components/OnboardingDialog.tsx index 3a17b9f2..bd576a85 100644 --- a/src/components/OnboardingDialog.tsx +++ b/src/components/OnboardingDialog.tsx @@ -5,7 +5,7 @@ import { nip19 } from 'nostr-tools'; import { Bot, Check, Sparkles, ArrowRight, ArrowLeft, ExternalLink } from 'lucide-react'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; -import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { Card, CardHeader, CardTitle } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; import { Checkbox } from '@/components/ui/checkbox'; import { PasswordInput } from '@/components/ui/password-input'; @@ -138,13 +138,20 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps) onOpenChange(false); }; - const formatPrice = (pricing: { prompt: Decimal; completion: Decimal }) => { - if (!pricing) return 'unknown'; - if (pricing.prompt.equals(0) && pricing.completion.equals(0)) return 'Free'; - const prompt = pricing.prompt.times(1_000_000).toFixed(2).toString().replace(/\.00$/, ''); - const completion = pricing.completion.times(1_000_000).toFixed(2).toString().replace(/\.00$/, ''); - return `$${prompt}/M↑ $${completion}/M↓`; - }; + const renderPrice = (pricing: { prompt: Decimal; completion: Decimal }) => { + const normalizedPrice = getNormalizedModelPrice(pricing).times(1_000_000).toNumber(); + if (normalizedPrice === 0) { + return Free; + } else if (normalizedPrice < 10) { + return $; + } else if (normalizedPrice >= 10 && normalizedPrice < 15) { + return $$; + } else if (normalizedPrice >= 15 && normalizedPrice < 50) { + return $$$; + } else if (normalizedPrice >= 50) { + return $$$$; + } + } // Reset state when dialog opens/closes useEffect(() => { @@ -524,8 +531,9 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
- - {modelName} + + {modelName} + {model.pricing && renderPrice(model.pricing)} {model.description && (

@@ -542,18 +550,6 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps) )}

- {(model.pricing || model.contextLength) && ( - -
- {model.pricing && ( - {formatPrice(model.pricing)} - )} - {model.contextLength && ( - Context: {model.contextLength.toLocaleString()} tokens - )} -
-
- )} ); }) @@ -612,4 +608,29 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps) )} ); +} + +/** + * Get a single normalized "price per token" for a model, + * combining input and output pricing with agentic-coding-aware weights. + * + * Default behavior: + * - Uses inputWeight = 0.20 (based on typical 3–5x output premium seen in practice). + * + * Optional behavior: + * - If you pass observed token usage, the function will compute the weight + * as the observed share of spend from inputs over total spend. + */ +function getNormalizedModelPrice( + pricing: { prompt: Decimal; completion: Decimal }, + inputWeight = 0.2, +): Decimal { + if (!(inputWeight >= 0 && inputWeight <= 1)) { + throw new Error("Computed inputWeight is out of range [0,1]. Check inputs."); + } + if (pricing.prompt.equals(0) && pricing.completion.equals(0)) { + return new Decimal(0); + } + const outputWeight = 1 - inputWeight; + return pricing.prompt.times(inputWeight).plus(pricing.completion.times(outputWeight)); } \ No newline at end of file