An open-source, faster Devin alternative
TypeScript
Show credit balances and allowances as credits, not dollars
Mohamed Habib via Computer55724cc1a41a
diff --git a/cli/src/billing.test.ts b/cli/src/billing.test.tsindex 13116907..24daf1d2 100644--- a/cli/src/billing.test.ts+++ b/cli/src/billing.test.ts@@ -21,7 +21,7 @@ const base: CreditsStatus = {};test("run footer nudges free orgs, warns when low, and is silent for healthy paid plans", () => {- assert.match(creditsFooter(base), /\$3\.40 free credits left/);+ assert.match(creditsFooter(base), /3.4 free credits left/);assert.match(creditsFooter(base), /plan=max/);assert.match(creditsFooter(base), /Pro \(\$200\/mo\)/);assert.match(@@ -68,7 +68,7 @@ test("json credits block carries a machine-readable warning", () => {test("billing table lists only Pro ($200) unless the org is on legacy Pro", () => {const free = formatBilling(base);assert.match(free, /Plan\s+Free/);- assert.match(free, /Pro\s+\$200\/mo — \$2,000/);+ assert.match(free, /Pro\s+\$200\/mo — 2,000 credits every month/);assert.doesNotMatch(free, /\$20\/mo|top.?up|Max \(/i);const legacy = formatBilling({diff --git a/cli/src/billing.ts b/cli/src/billing.tsindex efb73480..996621bc 100644--- a/cli/src/billing.ts+++ b/cli/src/billing.ts@@ -1,7 +1,11 @@import type { CreditsStatus, OpenComputerClient } from "./api.js";-export function formatUsd(cents: number): string {- return `$${(cents / 100).toFixed(2)}`;+// Cents of usage per credit (1 credit = $1 in the Autumn catalog today).+const CENTS_PER_CREDIT = 100;++/** Credit count for display; balances are shown as credits, never dollars. */+export function formatCreditCount(cents: number): string {+ return (cents / CENTS_PER_CREDIT).toLocaleString("en-US", { maximumFractionDigits: 2 });}// The plan on sale is Pro ($200/mo); its billing id stays `max`. The old $20@@ -24,14 +28,14 @@ const PLAN_NAME: Record<"pro" | "max", string> = {export function formatBilling(status: CreditsStatus): string {const lines = [`Plan ${PLAN_LABEL[status.usagePlan]}`,- `Credits left ${formatUsd(status.creditsRemainingCents)}${+ `Credits left ${formatCreditCount(status.creditsRemainingCents)}${status.isHalted ? " (exhausted — sessions paused)" : status.isLow ? " (running low)" : ""}`,"","Plans:",...status.plans.map((p) =>- ` ${(p.name ?? PLAN_NAME[p.id]).padEnd(12)} $${p.priceUsd}/mo — $${p.creditsUsd.toLocaleString("en-US")} in credits every month` ++ ` ${(p.name ?? PLAN_NAME[p.id]).padEnd(12)} $${p.priceUsd}/mo — ${p.creditsUsd.toLocaleString("en-US")} credits every month` +(p.id === status.usagePlan ? " (current)" : ""),),"",@@ -48,7 +52,7 @@ export function formatBilling(status: CreditsStatus): string {*/export function creditsFooter(status: CreditsStatus | null): string {if (!status) return "";- const left = formatUsd(status.creditsRemainingCents);+ const left = formatCreditCount(status.creditsRemainingCents);const onPro = status.usagePlan === UPGRADE_PLAN;if (status.isHalted) {if (onPro) {diff --git a/web/src/components/app-shell.tsx b/web/src/components/app-shell.tsxindex a33be523..51b4eaee 100644--- a/web/src/components/app-shell.tsx+++ b/web/src/components/app-shell.tsx@@ -59,7 +59,7 @@ import {UPGRADE_PLAN,UPGRADE_PLAN_LABEL,billingOnrampV2Enabled,- formatUsd,+ formatCredits,trackUpsellClicked,trackUpsellShown,upgradeHref,@@ -497,7 +497,7 @@ function SidebarCreditMeter({ onNavigate }: { onNavigate?: () => void }) {isLow && 'text-amber-600',)}>- {formatUsd(creditsRemainingCents)} left+ {formatCredits(creditsRemainingCents)} left</span></div><div className="bg-secondary mt-1.5 h-1 overflow-hidden rounded-full">@@ -580,10 +580,10 @@ function HaltBanner() {<div className="flex items-center justify-center gap-2 border-b border-amber-500/40 bg-amber-500/10 px-4 py-2.5 text-center text-sm font-medium text-amber-700 sm:px-8 dark:text-amber-400"><CircleAlert className="size-4 shrink-0" /><span>- {formatUsd(creditsRemainingCents ?? 0)}{' '}+ {formatCredits(creditsRemainingCents ?? 0)}{' '}{usagePlan === 'base'- ? 'of free credits left — sessions pause at $0.'- : "of this month's credits left."}+ ? 'of free credits left — sessions pause at 0.'+ : 'left this month.'}{upgradePlan ? (<>{' '}diff --git a/web/src/components/post-session-upsell.tsx b/web/src/components/post-session-upsell.tsxindex 2af807fa..6dc9fe4d 100644--- a/web/src/components/post-session-upsell.tsx+++ b/web/src/components/post-session-upsell.tsx@@ -9,7 +9,7 @@ import {UPGRADE_PLAN,UPGRADE_PLAN_LABEL,billingOnrampV2Enabled,- formatUsd,+ formatCredits,trackFirstSessionCompleted,trackUpsellClicked,trackUpsellShown,@@ -92,9 +92,9 @@ export function PostSessionUpsell({<Sparkles className="text-muted-foreground mt-0.5 size-4 shrink-0" /><div className="text-sm"><p className="font-medium">- You've used {formatUsd(spentCents)} of your{' '}- {formatUsd(BASE_GRANT_CENTS)} free credits —{' '}- {formatUsd(creditsRemainingCents ?? 0)} left.+ You've used {formatCredits(spentCents)} of your{' '}+ {formatCredits(BASE_GRANT_CENTS)} free —{' '}+ {formatCredits(creditsRemainingCents ?? 0)} left.</p><p className="text-muted-foreground mt-0.5">Upgrade to {UPGRADE_PLAN_LABEL} to keep going when they run out.diff --git a/web/src/lib/billing-onramp.test.ts b/web/src/lib/billing-onramp.test.tsindex 8326d27a..b2873b61 100644--- a/web/src/lib/billing-onramp.test.ts+++ b/web/src/lib/billing-onramp.test.ts@@ -5,6 +5,7 @@ import {UPGRADE_PLAN,UPGRADE_PLAN_LABEL,deepLinkedPlanFor,+ formatCredits,selectablePaidPlans,upgradeHref,upgradePlanFor,@@ -50,3 +51,12 @@ describe('billing on-ramp plans', () => {expect(FREE_CREDITS_PAYWALL).not.toMatch(/top.?up|\$5\b|\$10\b/i)})})++describe('formatCredits', () => {+ it('shows balances as credits, never dollars', () => {+ expect(formatCredits(229)).toBe('2.29 credits')+ expect(formatCredits(200_000)).toBe('2,000 credits')+ expect(formatCredits(100)).toBe('1 credit')+ expect(formatCredits(0)).toBe('0 credits')+ })+})diff --git a/web/src/lib/billing-onramp.ts b/web/src/lib/billing-onramp.tsindex fa415deb..2912b93b 100644--- a/web/src/lib/billing-onramp.ts+++ b/web/src/lib/billing-onramp.ts@@ -77,8 +77,21 @@ export function deepLinkedPlanFor(return current === UPGRADE_PLAN ? null : UPGRADE_PLAN}-export function formatUsd(cents: number): string {- return `$${(cents / 100).toFixed(2)}`+// Cents of usage per credit (1 credit = $1 in the Autumn catalog today).+export const CENTS_PER_CREDIT = 100++const creditNumber = new Intl.NumberFormat('en-US', {+ maximumFractionDigits: 2,+})++// Balances and allowances are shown as credits, never dollars.+export function formatCreditCount(cents: number): string {+ return creditNumber.format(cents / CENTS_PER_CREDIT)+}++export function formatCredits(cents: number): string {+ const count = formatCreditCount(cents)+ return `${count} ${count === '1' ? 'credit' : 'credits'}`}export type UpsellSurface =diff --git a/web/src/pages/Billing.tsx b/web/src/pages/Billing.tsxindex 97088ee1..35aaf9fe 100644--- a/web/src/pages/Billing.tsx+++ b/web/src/pages/Billing.tsx@@ -37,10 +37,13 @@ import {FREE_CREDITS_PAYWALL,PLAN_NAMES,PLAN_OFFERS,+ CENTS_PER_CREDIT,UPGRADE_PLAN,UPGRADE_PLAN_LABEL,billingOnrampV2Enabled,deepLinkedPlanFor,+ formatCreditCount,+ formatCredits,selectablePaidPlans,trackCheckoutStarted,trackPlanActivated,@@ -285,14 +288,14 @@ const USAGE_PLANS: Array<{label: PLAN_NAMES.pro,price: PLAN_OFFERS.pro.priceUsd,credits: PLAN_OFFERS.pro.creditsUsd,- description: `$${PLAN_OFFERS.pro.creditsUsd} in shared credits added every month. No longer offered to new customers.`,+ description: `${formatCredits(PLAN_OFFERS.pro.creditsUsd * CENTS_PER_CREDIT)} added every month. No longer offered to new customers.`,},{id: 'max',label: PLAN_NAMES.max,price: PLAN_OFFERS.max.priceUsd,credits: PLAN_OFFERS.max.creditsUsd,- description: `$${PLAN_OFFERS.max.creditsUsd.toLocaleString()} in shared credits added every month.`,+ description: `${formatCredits(PLAN_OFFERS.max.creditsUsd * CENTS_PER_CREDIT)} added every month.`,},]@@ -304,10 +307,6 @@ function visibleUsagePlans(current: UsagePlanId) {)}-function formatCreditAmount(cents: number) {- return `$${(cents / 100).toFixed(2)}`-}-function formatResetDate(value: string) {return new Intl.DateTimeFormat(undefined, {month: 'long',@@ -429,7 +428,6 @@ function PrepaidPlan() {if (isLoading) return <Skeleton className="h-64 max-w-2xl" />- const credits = (autumn?.creditsRemainingCents ?? 0) / 100const creditBreakdown = autumn?.creditBreakdownconst halted = autumn?.isHalted ?? falseconst currentPlan = autumn?.concurrencyPlan ?? 'base'@@ -477,10 +475,10 @@ function PrepaidPlan() {halted ? 'text-status-error' : 'text-status-running',)}>- ${credits.toFixed(2)}+ {formatCreditCount(autumn?.creditsRemainingCents ?? 0)}</span><span className="text-muted-foreground text-xs">- total available+ credits available</span></div>{creditBreakdown?.available ? (@@ -494,12 +492,12 @@ function PrepaidPlan() {</p><p className="text-muted-foreground mt-0.5 text-xs">{creditBreakdown.planResetsAt- ? `Used first · resets to $${USAGE_PLANS.find((plan) => plan.id === autumn?.usagePlan)?.credits?.toLocaleString() ?? '0'} on ${formatResetDate(creditBreakdown.planResetsAt)}`+ ? `Used first · resets to ${formatCredits((USAGE_PLANS.find((plan) => plan.id === autumn?.usagePlan)?.credits ?? 0) * CENTS_PER_CREDIT)} on ${formatResetDate(creditBreakdown.planResetsAt)}`: 'One-time included balance'}</p></div><span className="font-mono font-medium">- {formatCreditAmount(creditBreakdown.planRemainingCents)}+ {formatCredits(creditBreakdown.planRemainingCents)}</span></div>{creditBreakdown.topupRemainingCents > 0 ? (@@ -511,7 +509,7 @@ function PrepaidPlan() {</p></div><span className="font-mono font-medium">- {formatCreditAmount(creditBreakdown.topupRemainingCents)}+ {formatCredits(creditBreakdown.topupRemainingCents)}</span></div>) : null}@@ -526,7 +524,7 @@ function PrepaidPlan() {</p></div><span className="font-mono font-medium">- {formatCreditAmount(creditBreakdown.otherRemainingCents)}+ {formatCredits(creditBreakdown.otherRemainingCents)}</span></div>) : null}@@ -636,7 +634,7 @@ function PrepaidPlan() {title={`Switch to ${selectedUsagePlan?.label ?? ''}`}description={selectedUsagePlan- ? `${selectedUsagePlan.label} costs $${selectedUsagePlan.price}/month and adds $${selectedUsagePlan.credits?.toLocaleString()} in shared credits each month. Autumn applies the plan change and any required proration through Stripe.`+ ? `${selectedUsagePlan.label} costs $${selectedUsagePlan.price}/month and adds ${formatCredits((selectedUsagePlan.credits ?? 0) * CENTS_PER_CREDIT)} each month. Autumn applies the plan change and any required proration through Stripe.`: ''}confirmLabel={