An open-source, faster Devin alternative
TypeScript
Billing: 3-day trial and a more prominent trial pill
Mohamed Habib via Computer8cfda2775f23
diff --git a/cli/src/api.test.ts b/cli/src/api.test.tsindex be5881ed..4784976e 100644--- a/cli/src/api.test.ts+++ b/cli/src/api.test.ts@@ -359,7 +359,7 @@ test("a 402 carries the halt reason and prefers the action link", async (context{error: {code: "insufficient_credits",- message: "Your 7-day trial has ended.",+ message: "Your 3-day trial has ended.",haltReason: "trial_days",actionUrl: "https://app.opencomputer.dev/billing",upgradeUrl: "https://app.opencomputer.dev/billing?plan=max",diff --git a/cli/src/billing.test.ts b/cli/src/billing.test.tsindex 02406dd4..2bd2bb82 100644--- a/cli/src/billing.test.ts+++ b/cli/src/billing.test.ts@@ -70,7 +70,7 @@ const trial: CreditsStatus = { ...base, workMinutes: true, haltReason: null, biltest("run footer names the work-minute halt and links Billing with no plan forced", () => {const cases: Record<string, RegExp> = {- trial_days: /Your 7-day trial has ended\. Pick a plan to keep going/,+ trial_days: /Your 3-day trial has ended\. Pick a plan to keep going/,trial_minutes: /trial's 600 work minutes/,trial_tokens: /trial's model credit/,credits_empty: /Buy credits or upgrade/,diff --git a/cli/src/billing.ts b/cli/src/billing.tsindex 5abbec2f..15e44300 100644--- a/cli/src/billing.ts+++ b/cli/src/billing.ts@@ -29,7 +29,7 @@ const PLAN_NAME: Record<"pro" | "max", string> = {// rule ("credits_exhausted", or an older API with no reason) keeps the copy// below.const PAYWALL: Record<string, { why: string; action: string }> = {- trial_days: { why: "Your 7-day trial has ended.", action: "Pick a plan to keep going" },+ trial_days: { why: "Your 3-day trial has ended.", action: "Pick a plan to keep going" },trial_minutes: { why: "You've used your trial's 600 work minutes.", action: "Pick a plan to keep going" },trial_tokens: { why: "You've used your trial's model credit.", action: "Pick a plan to keep going" },credits_empty: {@@ -48,7 +48,7 @@ export function paywallFor(reason: string | null | undefined): { why: string; ac// Before the stop: orgs.billing_warning, by reason.const WARNINGS: Record<string, string> = {trial_minutes: "Your trial is almost out of work minutes. Pick a plan to keep going",- trial_days: "Your 7-day trial ends soon. Pick a plan to keep going",+ trial_days: "Your 3-day trial ends soon. Pick a plan to keep going",trial_tokens: "Your trial's model credit is almost used. Pick a plan to keep going",allowance_80: "You've used 80% of this month's work minutes. Buy credits or upgrade so work doesn't stop",credits_low: "Your credits are running low. Buy credits so work doesn't stop",diff --git a/cli/src/errors.test.ts b/cli/src/errors.test.tsindex ec77550b..e29de516 100644--- a/cli/src/errors.test.ts+++ b/cli/src/errors.test.ts@@ -69,7 +69,7 @@ test("out-of-credits responses tell the agent to stop and surface the upgrade litest("a work-minute 402 says why and links Billing", () => {const trial = structuredError(new APIError(- "Your 7-day trial has ended.",+ "Your 3-day trial has ended.",402,"insufficient_credits","https://app.opencomputer.dev/billing",@@ -77,7 +77,7 @@ test("a work-minute 402 says why and links Billing", () => {),);assert.equal(trial.code, "insufficient_credits");- assert.match(trial.hint, /^Your 7-day trial has ended\. Pick a plan to keep going at https:\/\/app\.opencomputer\.dev\/billing,/);+ assert.match(trial.hint, /^Your 3-day trial has ended\. Pick a plan to keep going at https:\/\/app\.opencomputer\.dev\/billing,/);assert.match(trial.hint, /Do not retry/);assert.deepEqual(trial.details, {status: 402,diff --git a/cloudflare-workers/api-edge/src/agent_runtime_usage.test.ts b/cloudflare-workers/api-edge/src/agent_runtime_usage.test.tsindex 19e8083e..7cc39717 100644--- a/cloudflare-workers/api-edge/src/agent_runtime_usage.test.ts+++ b/cloudflare-workers/api-edge/src/agent_runtime_usage.test.ts@@ -101,9 +101,9 @@ describe("managed-agent runtime usage billing", () => {});it("replaces a trial_days warning once the minutes are the nearer limit", async () => {- // Day 6: 100/600 minutes ranks behind 1/7 days; 80/600 ranks ahead of it.- const daySix = Math.floor(Date.now() / 1000) - 6 * 86_400;- const { db, writes } = orgDB({ trial_started_at: daySix, billing_warning: "trial_days" });+ // 0.45 days of 3 left (15%): 100/600 minutes ranks behind it; 80/600 ranks ahead.+ const lastDay = Math.floor(Date.now() / 1000) - 2.55 * 86_400;+ const { db, writes } = orgDB({ trial_started_at: lastDay, billing_warning: "trial_days" });vi.spyOn(globalThis, "fetch").mockResolvedValueOnce(trial(100)).mockResolvedValueOnce(Response.json({ balance: { remaining: 80 } }))diff --git a/cloudflare-workers/api-edge/src/autumn_webhook.test.ts b/cloudflare-workers/api-edge/src/autumn_webhook.test.tsindex 1186d683..70d68676 100644--- a/cloudflare-workers/api-edge/src/autumn_webhook.test.ts+++ b/cloudflare-workers/api-edge/src/autumn_webhook.test.ts@@ -570,21 +570,21 @@ describe("warnings before the stop", () => {expect(billingWarning(customer(["base"], { credits: 10 }), { ...fresh, trialStartedAt: now - 6 * day }, now)).toBeNull();});- it("warns a trial at 480 minutes, 2 days left or $8 spent", () => {+ it("warns a trial at 480 minutes, 1 day left or $8 spent", () => {expect(billingWarning(customer(["trial"], { minutes: 121, credits: 2.5 }), fresh, now)).toBeNull();expect(billingWarning(customer(["trial"], { minutes: 120, credits: 5 }), fresh, now)).toBe("trial_minutes");expect(billingWarning(customer(["trial"], { minutes: 300, credits: 2 }), fresh, now)).toBe("trial_tokens");expect(- billingWarning(customer(["trial"], { minutes: 300, credits: 5 }), { ...fresh, trialStartedAt: now - 5 * day }, now),+ billingWarning(customer(["trial"], { minutes: 300, credits: 5 }), { ...fresh, trialStartedAt: now - 2 * day }, now),).toBe("trial_days");});it("names the trial limit closest to stopping", () => {- const day6 = { ...fresh, trialStartedAt: now - 6 * day };- // 1 day of 7 left (14%) against 100 of 600 minutes (17%).- expect(billingWarning(customer(["trial"], { minutes: 100, credits: 5 }), day6, now)).toBe("trial_days");- expect(billingWarning(customer(["trial"], { minutes: 30, credits: 5 }), day6, now)).toBe("trial_minutes");- expect(billingWarning(customer(["trial"], { minutes: 100, credits: 0.5 }), day6, now)).toBe("trial_tokens");+ const lastDay = { ...fresh, trialStartedAt: now - 2.6 * day };+ // 0.4 days of 3 left (13%) against 100 of 600 minutes (17%).+ expect(billingWarning(customer(["trial"], { minutes: 100, credits: 5 }), lastDay, now)).toBe("trial_days");+ expect(billingWarning(customer(["trial"], { minutes: 30, credits: 5 }), lastDay, now)).toBe("trial_minutes");+ expect(billingWarning(customer(["trial"], { minutes: 100, credits: 0.5 }), lastDay, now)).toBe("trial_tokens");});it("warns a paid org at 80% of its minutes, then about low credits", () => {diff --git a/cloudflare-workers/api-edge/src/autumn_webhook.ts b/cloudflare-workers/api-edge/src/autumn_webhook.tsindex 814cd4e9..3541ca43 100644--- a/cloudflare-workers/api-edge/src/autumn_webhook.ts+++ b/cloudflare-workers/api-edge/src/autumn_webhook.ts@@ -640,7 +640,7 @@ export async function selfHealHalt(env: AutumnEnv, orgID: string): Promise<boole// ── halt rules (serverless-agents-ws 086, step 4) ───────────────────────────-export const TRIAL_DAYS = 7;+export const TRIAL_DAYS = 3;// A paid org whose payment is failing keeps working this long before it halts.export const PAYMENT_GRACE_DAYS = 3;const DAY_SEC = 86_400;@@ -710,9 +710,9 @@ export type BillingWarning =const TRIAL_MINUTES = 600;const TRIAL_CREDITS = 10;-// Trial: warn at 480 of 600 minutes, 2 days left, or $8 of the $10 spent.+// Trial: warn at 480 of 600 minutes, 1 day left, or $8 of the $10 spent.const TRIAL_WARN_MINUTES_LEFT = 120;-const TRIAL_WARN_DAYS_LEFT = 2;+const TRIAL_WARN_DAYS_LEFT = 1;const TRIAL_WARN_CREDITS_LEFT = 2;// Paid: warn at 80% of the month's minutes, and when the credits that pay past// them run under $5 with no auto top-up to refill them.@@ -1146,7 +1146,7 @@ export async function autumnUsagePlanPurchase(},): Promise<{ url: string | null }> {const customer = await getAutumnCustomer(env, params.customerId);- // Only the pre-trial `base` grant carries. The 7-day trial's minutes and $10+ // Only the pre-trial `base` grant carries. The 3-day trial's minutes and $10// token credit do not (serverless-agents-ws 086 "Plan changes": trial → paid// starts the paid allowance fresh).const upgradingFromUsage = (customer?.subscriptions ?? []).some(diff --git a/cloudflare-workers/api-edge/src/billing_clock.test.ts b/cloudflare-workers/api-edge/src/billing_clock.test.tsindex 162f8d74..ad81c522 100644--- a/cloudflare-workers/api-edge/src/billing_clock.test.ts+++ b/cloudflare-workers/api-edge/src/billing_clock.test.ts@@ -24,7 +24,7 @@ describe("billing clock", () => {expect(await runBillingClock(env, 1_800_000_000_000)).toBe(2);// Least recently updated first, so orgs that stay unhalted can't fill every batch.expect(sql).toMatch(/ORDER BY updated_at\s+LIMIT/);- expect(bound).toEqual([1_800_000_000 - 7 * 86_400, 1_800_000_000 - 3 * 86_400, 50, 1_800_000_000 - 5 * 86_400, 1_800_000_000 - 3_600]);+ expect(bound).toEqual([1_800_000_000 - 3 * 86_400, 1_800_000_000 - 3 * 86_400, 50, 1_800_000_000 - 2 * 86_400, 1_800_000_000 - 3_600]);// A trial warned about minutes or credits is re-checked hourly, so trial_days can replace it.expect(sql).toMatch(/billing_warning IS NULL OR \(billing_warning <> 'trial_days' AND updated_at <= \?5\)/);expect(project.mock.calls.map((c) => c[1])).toEqual(["org_a", "org_b"]);diff --git a/cloudflare-workers/api-edge/src/billing_clock.ts b/cloudflare-workers/api-edge/src/billing_clock.tsindex a9862b8b..00b2e5a9 100644--- a/cloudflare-workers/api-edge/src/billing_clock.ts+++ b/cloudflare-workers/api-edge/src/billing_clock.ts@@ -1,8 +1,8 @@// Billing clock (serverless-agents-ws 086, step 4): the halts that come from-// time passing rather than usage. A trial ends on day 7 and a failing payment+// time passing rather than usage. A trial ends on day 3 and a failing payment// halts after its grace even when the org does nothing, so the */5 cron// re-projects the orgs whose clock has run out; projectOrg decides and halts.-// It also re-projects a trial reaching 2 days left that is not yet warned, so+// It also re-projects a trial reaching 1 day left that is not yet warned, so// the trial_days warning goes out on time rather than on the next activity,// and hourly one warned about minutes or credits, which the days can outrank.// A halted, warned or paid-up org no longer matches. One that matches but stays@@ -13,7 +13,7 @@import { type AutumnEnv, PAYMENT_GRACE_DAYS, TRIAL_DAYS, TRIAL_WARN_AFTER_SEC, projectOrg } from "./autumn_webhook";const DAY_SEC = 86_400;-// A trial in its last 2 days already warned about minutes or credits is+// A trial in its last day already warned about minutes or credits is// re-projected at most this often, so trial_days replaces that warning once the// days left are the smaller share, even while the org is idle.const WARNED_TRIAL_RECHECK_SEC = 3_600;diff --git a/cloudflare-workers/api-edge/src/billing_onramp.test.ts b/cloudflare-workers/api-edge/src/billing_onramp.test.tsindex af1572aa..2e8915a6 100644--- a/cloudflare-workers/api-edge/src/billing_onramp.test.ts+++ b/cloudflare-workers/api-edge/src/billing_onramp.test.ts@@ -119,7 +119,7 @@ describe("billing_onramp", () => {it("402 names the work-minute halt reason, links Billing with no plan forced", async () => {const cases = {- trial_days: "Your 7-day trial has ended. Ask the user to pick a plan",+ trial_days: "Your 3-day trial has ended. Ask the user to pick a plan",trial_minutes: "You've used your trial's 600 work minutes.",trial_tokens: "You've used your trial's model credit.",credits_empty: "buy credits or upgrade",diff --git a/cloudflare-workers/api-edge/src/billing_onramp.ts b/cloudflare-workers/api-edge/src/billing_onramp.tsindex 6047a126..40b2831a 100644--- a/cloudflare-workers/api-edge/src/billing_onramp.ts+++ b/cloudflare-workers/api-edge/src/billing_onramp.ts@@ -67,7 +67,7 @@ export function billingLinks(request: Request): BillingLinks {// failed payment updates its card. Wording follows blue's Slack paywall// (src/computer/admission.ts outOfCreditsNotice).const WORK_MINUTE_PAYWALL: Record<Exclude<HaltReason, "credits_exhausted">, (billingUrl: string) => string> = {- trial_days: (u) => `Your 7-day trial has ended. Ask the user to pick a plan at ${u} to keep going`,+ trial_days: (u) => `Your 3-day trial has ended. Ask the user to pick a plan at ${u} to keep going`,trial_minutes: (u) => `You've used your trial's 600 work minutes. Ask the user to pick a plan at ${u} to keep going`,trial_tokens: (u) => `You've used your trial's model credit. Ask the user to pick a plan at ${u} to keep going`,credits_empty: (u) =>diff --git a/cloudflare-workers/api-edge/src/billing_summary.test.ts b/cloudflare-workers/api-edge/src/billing_summary.test.tsindex 4d00d5fc..ad4d3f75 100644--- a/cloudflare-workers/api-edge/src/billing_summary.test.ts+++ b/cloudflare-workers/api-edge/src/billing_summary.test.ts@@ -69,8 +69,8 @@ describe("plan changes", () => {expect(planSchedule("trial", "max")).toBe("immediate");});- it("ends the trial seven days after it starts", () => {- expect(trialEndsAt(1_790_000_000)).toBe(new Date((1_790_000_000 + 7 * 86_400) * 1_000).toISOString());+ it("ends the trial three days after it starts", () => {+ expect(trialEndsAt(1_790_000_000)).toBe(new Date((1_790_000_000 + 3 * 86_400) * 1_000).toISOString());expect(trialEndsAt(null)).toBeNull();});});diff --git a/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.ts b/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.tsindex e8cd2842..e51ccfee 100644--- a/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.ts@@ -324,7 +324,7 @@ describe("managed-agent credit admission", () => {haltReason: "trial_days",actionUrl: "https://mo-oc-dev.com/billing",});- expect(body.error.message).toContain("7-day trial has ended");+ expect(body.error.message).toContain("3-day trial has ended");expect(waits).toHaveLength(1);});diff --git a/scripts/autumn/autumn.config.ts b/scripts/autumn/autumn.config.tsindex f9f4e354..34284a9e 100644--- a/scripts/autumn/autumn.config.ts+++ b/scripts/autumn/autumn.config.ts@@ -225,7 +225,7 @@ export const trial = plan({id: "trial",name: "Trial",autoEnable: true,- description: "7 days, 600 work minutes and $10 of model credits.",+ description: "3 days, 600 work minutes and $10 of model credits.",group: "usage_plan",items: [item({diff --git a/web/src/api/mock.ts b/web/src/api/mock.tsindex a2525046..03cf548c 100644--- a/web/src/api/mock.ts+++ b/web/src/api/mock.ts@@ -368,7 +368,7 @@ function autumnMock() {currency: 'usd',paymentPastDueAt: null,trialStartedAt: fromNow(-2),- trialEndsAt: fromNow(4.9),+ trialEndsAt: fromNow(2.9),workMinutes: { granted: 600, remaining: 412, resetsAt: null },periodEndsAt: null as string | null,scheduledChange: null as { to: 'pro' | 'cancel'; at: string | null } | null,diff --git a/web/src/api/schemas.ts b/web/src/api/schemas.tsindex 363eac10..c5e0b8a5 100644--- a/web/src/api/schemas.ts+++ b/web/src/api/schemas.ts@@ -240,7 +240,7 @@ export const AutumnBillingSchema = z.object({}),maxConcurrentSandboxes: z.number(),concurrencyPlan: z.string(),- // `trial` is the 7-day trial; `base` is the pre-trial free tier, kept until+ // `trial` is the 3-day trial; `base` is the pre-trial free tier, kept until// every free org is migrated (serverless-agents-ws 086).usagePlan: z.enum(['trial', 'base', 'pro', 'max']),isHalted: z.boolean(),diff --git a/web/src/components/billing-surfaces.tsx b/web/src/components/billing-surfaces.tsxindex a3d58f15..5ddb577c 100644--- a/web/src/components/billing-surfaces.tsx+++ b/web/src/components/billing-surfaces.tsx@@ -36,16 +36,27 @@ export function BillingPill({ className }: { className?: string }) {const { billing } = useCreditState()const text = billing ? billingPillText(billing) : nullif (!billingOnrampV2Enabled || !text) return null+ // The trial pill is filled and asks to upgrade, so a trial org can't miss it;+ // a paid org's stays quiet.+ const trial = billing?.usagePlan === 'trial' && !billing.isHaltedreturn (<Linkto="/billing"className={cn(- 'text-muted-foreground hover:text-foreground hover:border-foreground/30 rounded-full border px-3 py-1 font-mono text-[11px] whitespace-nowrap transition-colors',+ 'rounded-full border font-mono whitespace-nowrap transition-colors',+ trial+ ? 'bg-primary text-primary-foreground border-primary inline-flex items-center gap-2 py-1 pr-1 pl-3 text-xs font-medium hover:opacity-90'+ : 'text-muted-foreground hover:text-foreground hover:border-foreground/30 px-3 py-1 text-[11px]',billing?.isHalted && 'border-destructive/40 text-destructive',className,)}>{text}+ {trial && (+ <span className="bg-primary-foreground text-primary rounded-full px-2 py-0.5 font-sans font-semibold">+ Upgrade+ </span>+ )}</Link>)}diff --git a/web/src/lib/billing-onramp.test.ts b/web/src/lib/billing-onramp.test.tsindex 71111973..70e741cc 100644--- a/web/src/lib/billing-onramp.test.ts+++ b/web/src/lib/billing-onramp.test.ts@@ -116,7 +116,7 @@ describe('haltNotice', () => {it('words the trial halts as the end of the trial', () => {const notice = haltNotice('trial_days')expect(notice.title).toBe('Your free trial is over')- expect(notice.body).toContain('7-day trial has ended')+ expect(notice.body).toContain('3-day trial has ended')expect(notice.body).toContain('$20')})})diff --git a/web/src/lib/billing-onramp.ts b/web/src/lib/billing-onramp.tsindex 05732a7a..c3c15797 100644--- a/web/src/lib/billing-onramp.ts+++ b/web/src/lib/billing-onramp.ts@@ -10,11 +10,11 @@ export const billingOnrampV2Enabled =export type UsagePlanId = 'trial' | 'base' | 'pro' | 'max'export type PaidPlanId = 'pro' | 'max'-// Work-minute plans (serverless-agents-ws 086): a 7-day trial with 600 work+// Work-minute plans (serverless-agents-ws 086): a 3-day trial with 600 work// minutes and $10 of model credits, then Pro ($20/mo, 2,000 min) or Max// ($200/mo, 25,000 min). Past the allowance, work draws prepaid credits at// $0.01/min, bought in packs.-export const TRIAL_DAYS = 7+export const TRIAL_DAYS = 3export const TRIAL_MINUTES = 600export const TRIAL_CREDITS_USD = 10export const OVERAGE_USD_PER_MINUTE = 0.01@@ -141,7 +141,7 @@ interface PillSource {trialEndsAt?: string | null}-// The header pill: "Trial · 412 min · 5 days left" or+// The header pill: "Trial · 412 min · 2 days left" or// "1,240 / 2,000 min · $12 credits" (minutes left of the month's allowance).export function billingPillText(b: PillSource,diff --git a/web/src/lib/plan-label.ts b/web/src/lib/plan-label.tsindex 9764d1ef..47c18cab 100644--- a/web/src/lib/plan-label.ts+++ b/web/src/lib/plan-label.ts@@ -1,5 +1,5 @@// Display names of the Autumn usage plans (serverless-agents-ws 086): the-// 7-day trial, Pro ($20/mo, 2,000 work minutes) and Max ($200/mo, 25,000).+// 3-day trial, Pro ($20/mo, 2,000 work minutes) and Max ($200/mo, 25,000).// `base` is the pre-trial free tier, until those orgs are migrated.export const USAGE_PLAN_NAMES: Record<'trial' | 'base' | 'pro' | 'max',