Public: anyone can read this; the crew can change it.
/pricing says in plain words what a plan's included credit buys #16161
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16132-pricing-says-in-plain-words-what-a-plan → main 0 commits fork 3 threads · 3 unresolved
15 files
changed +148
−36
docs/features/pricing.md +2 −1
| @@ -4,8 +4,9 @@ row: Buy a forge at /pricing | ||
| 4 | 4 | --- |
| 5 | 5 | # Buy a forge at /pricing (#11138) |
| 6 | 6 | |
| 7 | Open `/pricing` with no account. Each plan shows its size, price, monthly crew credit (left out when it is $0) and forge count, read from the same plans as `GET /api/v1/plans` (`test/pricing-plans-agree.test.ts`). Type the forge's name and an email, press the paid plan's button, pay at the provider's checkout, and the page you return to (`/pricing/done`) shows the claim link once. Open it to take the forge over. | |
| 7 | Open `/pricing` with no account. Each plan shows its size, price, crew credit said as a count of ordinary asks ("Crew credit for 10 ordinary asks each month."; the free plan's is "…once, to start"; left out when it is under one ask) and forge count, read from the same plans as `GET /api/v1/plans` (`test/pricing-plans-agree.test.ts`). Type the forge's name and an email, press the paid plan's button, pay at the provider's checkout, and the page you return to (`/pricing/done`) shows the claim link once. Open it to take the forge over. | |
| 8 | 8 | |
| 9 | - **Asks, not dollars (#16132):** an ask costs the `billing.ask_cents` limit (default 50 cents; the operator sets it from the crew's ledger, under Limits), and a credit is shown as whole asks, rounded down. `creditWords` in `src/billing/plan_words.ts` builds the sentence for /pricing, the home's plans, the terminal's plans screen and the owner's plan row (the host writes the ask price into the forge's `plan.json`). `GET /api/v1/plans` and the structured data on /pricing stay in dollars (`creditUsd`, "Crew credit (USD a month)"). Test: `bun test test/pricing-words.test.ts`. | |
| 9 | 10 | - **Free plan:** its button goes to `/forges/new`. |
| 10 | 11 | - **Closed the tab?** `/pricing/resend`: name and email you bought with; a new link is mailed there (needs mail configured) and the old one stops. |
| 11 | 12 | - **No provider connected:** paid plans show their price and one muted phrase, "not on sale yet · ask the operator". |
src/billing/notice.ts +8
| @@ -14,6 +14,7 @@ import type { App } from "../app.ts"; | ||
| 14 | 14 | import { readPrivate, writePrivate } from "../kernel/file_modes.ts"; |
| 15 | 15 | import { childDirOf, listChildrenNow } from "../actions/spawn.ts"; |
| 16 | 16 | import { getPortalUrl, parseLink } from "../settings/billing.ts"; |
| 17 | import { limitValue } from "../settings/limits.ts"; | |
| 17 | 18 | import { getPlan } from "../settings/plans.ts"; |
| 18 | 19 | import { lapseFor } from "./lapse.ts"; |
| 19 | 20 | import { entitlementOf, getStored } from "./store.ts"; |
| @@ -24,6 +25,11 @@ export interface PlanNotice { | ||
| 24 | 25 | readonly size: string; |
| 25 | 26 | readonly priceUsd: number; |
| 26 | 27 | readonly creditUsd: number; |
| 28 | /** | |
| 29 | * Dollars one ordinary ask costs on the host (`billing.ask_cents`); absent in a notice from | |
| 30 | * before it. | |
| 31 | */ | |
| 32 | readonly askUsd?: number; | |
| 27 | 33 | readonly status: EntitlementStatus; |
| 28 | 34 | /** Unix seconds the paid period ends (and a past-due forge sleeps), when known. */ |
| 29 | 35 | readonly periodEnd?: number; |
| @@ -60,6 +66,7 @@ export function noticeOf(dataDir: string): PlanNotice | undefined { | ||
| 60 | 66 | size, |
| 61 | 67 | priceUsd: money(r["priceUsd"]), |
| 62 | 68 | creditUsd: money(r["creditUsd"]), |
| 69 | ...(money(r["askUsd"]) > 0 ? { askUsd: money(r["askUsd"]) } : {}), | |
| 63 | 70 | status: r["status"] as EntitlementStatus, |
| 64 | 71 | ...(typeof r["periodEnd"] === "number" && Number.isFinite(r["periodEnd"]) && r["periodEnd"] > 0 ? { periodEnd: r["periodEnd"] } : {}), |
| 65 | 72 | ...(portal === undefined || portal === "" ? {} : { portalUrl: portal }), |
| @@ -98,6 +105,7 @@ export function tellPlan(app: App, forge: string): boolean { | ||
| 98 | 105 | size: plan?.size ?? child.size, |
| 99 | 106 | priceUsd: plan?.priceUsd ?? 0, |
| 100 | 107 | creditUsd: plan?.creditUsd ?? 0, |
| 108 | askUsd: limitValue(app.db, "billing.ask_cents") / 100, | |
| 101 | 109 | status: e.status, |
| 102 | 110 | ...(periodEnd === undefined ? {} : { periodEnd }), |
| 103 | 111 | ...(paysAtProvider && portal !== "" ? { portalUrl: portal } : {}), |
src/billing/plan_words.ts +28 −8
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | import type { BillingLinks } from "../settings/billing.ts"; |
| 11 | 11 | import { sizeWords } from "../settings/billing.ts"; |
| 12 | import { LIMITS } from "../settings/limits.ts"; | |
| 12 | 13 | import type { Plan } from "../settings/plans.ts"; |
| 13 | 14 | |
| 14 | 15 | export interface PlanWords { |
| @@ -25,13 +26,32 @@ export interface PlanWords { | ||
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | * A plan's crew credit in one sentence, the same on every surface: a paid plan's monthly credit, or | |
| 29 | * the free plan's start credit, lent once (`startUsd`, the `spawn.included_credit_usd` limit). | |
| 29 | * What one ordinary ask costs the crew, in dollars: the unit a plan's credit is counted in. It is | |
| 30 | * the `billing.ask_cents` limit (an operator's setting, read where the page is made and passed in); | |
| 31 | * this default is the limit's own, so a caller with no forge to ask says what a fresh one says. | |
| 32 | * Nothing in the repository measures an ask: the operator sets it from the crew's ledger. | |
| 30 | 33 | */ |
| 31 | export function creditWords(p: Pick<Plan, "priceUsd" | "creditUsd">, startUsd: number): string { | |
| 32 | if (p.priceUsd > 0) return p.creditUsd > 0 ? `$${p.creditUsd} of crew credit each month.` : "No crew credit included."; | |
| 33 | return startUsd > 0 | |
| 34 | ? `$${startUsd} of crew credit once, to start. Then your own AI account key.` | |
| 34 | export const ASK_USD = LIMITS["billing.ask_cents"].default / 100; | |
| 35 | ||
outdated
A positive credit below one ask yields "0 ordinary asks". Say "No crew credit" instead, or round up to at least 1. |
||
| 36 | /** | |
| 37 | * "10 ordinary asks", "1 ordinary ask": whole asks a credit buys, rounded down; 0 when under one. | |
| 38 | */ | |
| 39 | export function asksWords(usd: number, askUsd: number = ASK_USD): string { | |
| 40 | const n = Math.max(0, Math.floor((usd + 1e-9) / askUsd)); | |
| 41 | return `${n} ordinary ${n === 1 ? "ask" : "asks"}`; | |
| 42 | } | |
| 43 | ||
| 44 | const asksOf = (usd: number, askUsd: number): number => Math.floor((usd + 1e-9) / askUsd); | |
| 45 | ||
| 46 | /** | |
| 47 | * A plan's crew credit in one sentence, the same on every surface (/pricing, the home, the | |
| 48 | * terminal, the owner's plan row): a paid plan's monthly credit, or the free plan's start credit, | |
| 49 | * lent once (`startUsd`, the `spawn.included_credit_usd` limit), as a count of ordinary asks. | |
| 50 | */ | |
| 51 | export function creditWords(p: Pick<Plan, "priceUsd" | "creditUsd">, startUsd: number, askUsd: number = ASK_USD): string { | |
| 52 | if (p.priceUsd > 0) return asksOf(p.creditUsd, askUsd) > 0 ? `Crew credit for ${asksWords(p.creditUsd, askUsd)} each month.` : "No crew credit included."; | |
| 53 | return asksOf(startUsd, askUsd) > 0 | |
| 54 | ? `Crew credit for ${asksWords(startUsd, askUsd)}, once, to start. Then your own AI account key.` | |
| 35 | 55 | : "No crew credit: the crew runs on your own AI account key."; |
| 36 | 56 | } |
| 37 | 57 | |
| @@ -41,13 +61,13 @@ export function creditWords(p: Pick<Plan, "priceUsd" | "creditUsd">, startUsd: n | ||
| 41 | 61 | */ |
| 42 | 62 | export const monthlyPrice = (usd: number): string => (usd === 0 ? "Free" : `$${usd} a month`); |
| 43 | 63 | |
| 44 | export function planWords(p: Plan, links: BillingLinks = {}, startUsd = 0): PlanWords { | |
| 64 | export function planWords(p: Plan, links: BillingLinks = {}, startUsd = 0, askUsd: number = ASK_USD): PlanWords { | |
| 45 | 65 | const free = p.priceUsd === 0; |
| 46 | 66 | const buy = free ? undefined : links[p.size]; |
| 47 | 67 | return { |
| 48 | 68 | name: p.name, |
| 49 | 69 | price: monthlyPrice(p.priceUsd), |
| 50 | is: `${sizeWords(p.size)}. ${p.says} ${creditWords(p, startUsd)}`, | |
| 70 | is: `${sizeWords(p.size)}. ${p.says} ${creditWords(p, startUsd, askUsd)}`, | |
| 51 | 71 | buy, |
| 52 | 72 | }; |
| 53 | 73 | } |
src/settings/door.ts +12 −4
| @@ -14,6 +14,7 @@ import { SIGNUP_DEFAULT, parseSignup, type SignupMode } from "./signup.ts"; | ||
| 14 | 14 | |
| 15 | 15 | const SIGNUP_KEY = "signup"; |
| 16 | 16 | const START_CREDIT = "spawn.included_credit_usd"; |
| 17 | const ASK_COST = "billing.ask_cents"; | |
| 17 | 18 | |
| 18 | 19 | export interface DoorSettings { |
| 19 | 20 | readonly mode: SignupMode; |
| @@ -21,25 +22,32 @@ export interface DoorSettings { | ||
| 21 | 22 | readonly links: BillingLinks; |
| 22 | 23 | /** Dollars of crew credit lent once to a new free forge that brings no key (`spawn.included_credit_usd`). */ |
| 23 | 24 | readonly startUsd: number; |
| 25 | /** Dollars one ordinary ask costs (`billing.ask_cents`), the unit a plan's credit is said in. */ | |
| 26 | readonly askUsd: number; | |
| 24 | 27 | } |
| 25 | 28 | |
| 29 | /** Dollars from whole cents; absent stays absent. */ | |
| 30 | const centsToUsd = (cents: number | undefined): number | undefined => (cents === undefined ? undefined : cents / 100); | |
| 31 | ||
| 26 | 32 | export function getDoorSettings(db: Database): DoorSettings { |
| 27 | 33 | let mode: SignupMode = SIGNUP_DEFAULT; |
| 28 | 34 | let plans: string | undefined; |
| 29 | 35 | let links: BillingLinks = {}; |
| 30 | 36 | let startUsd: number | undefined; |
| 37 | let askUsd: number | undefined; | |
| 31 | 38 | const rows = db |
| 32 | .query<{ key: string; value: string }, [string, string, string, string]>( | |
| 33 | "SELECT key, value FROM forge_setting WHERE key IN (?1, ?2, ?3, ?4)", | |
| 39 | .query<{ key: string; value: string }, [string, string, string, string, string]>( | |
| 40 | "SELECT key, value FROM forge_setting WHERE key IN (?1, ?2, ?3, ?4, ?5)", | |
| 34 | 41 | ) |
| 35 | .all(SIGNUP_KEY, PLANS_KEY, BILLING_LINKS_KEY, storeKey(START_CREDIT)); | |
| 42 | .all(SIGNUP_KEY, PLANS_KEY, BILLING_LINKS_KEY, storeKey(START_CREDIT), storeKey(ASK_COST)); | |
| 36 | 43 | for (const row of rows) { |
| 37 | 44 | if (row.key === SIGNUP_KEY) { |
| 38 | 45 | const m = parseSignup(row.value); |
| 39 | 46 | if (m.ok) mode = m.value; |
| 40 | 47 | } else if (row.key === PLANS_KEY) plans = row.value; |
| 41 | 48 | else if (row.key === BILLING_LINKS_KEY) links = decodeLinks(row.value); |
| 49 | else if (row.key === storeKey(ASK_COST)) askUsd = centsToUsd(decodeLimit(ASK_COST, row.value)); | |
| 42 | 50 | else startUsd = decodeLimit(START_CREDIT, row.value); |
| 43 | 51 | } |
| 44 | return { mode, plans: decodePlans(plans), links, startUsd: startUsd ?? LIMITS[START_CREDIT].default }; | |
| 52 | return { mode, plans: decodePlans(plans), links, startUsd: startUsd ?? LIMITS[START_CREDIT].default, askUsd: askUsd ?? LIMITS[ASK_COST].default / 100 }; | |
| 45 | 53 | } |
src/settings/limits.ts +9
| @@ -69,6 +69,7 @@ export type LimitKey = | ||
| 69 | 69 | | "model_review.slack_pct" |
| 70 | 70 | | "shell_idle_minutes" |
| 71 | 71 | | "billing.grace_days" |
| 72 | | "billing.ask_cents" | |
| 72 | 73 | | "billing.retention_days" |
| 73 | 74 | | "retention.event_days" |
| 74 | 75 | | "retention.deploy_pull_days" |
| @@ -417,6 +418,14 @@ export const LIMITS: Record<LimitKey, LimitDef> = { | ||
| 417 | 418 | max: 1440, |
| 418 | 419 | reason: "A shell nobody types in and that prints nothing holds a process and memory for no reason; one that prints, like a build, is never stopped.", |
| 419 | 420 | }, |
| 421 | "billing.ask_cents": { | |
| 422 | label: "Cents one ordinary crew ask costs, for saying a plan credit in asks", | |
| 423 | unit: "cents", | |
| 424 | default: 50, | |
| 425 | min: 1, | |
| 426 | max: 100_000, | |
| 427 | reason: "A plan's credit is said on /pricing as a count of ordinary asks, so this is the price of one; the operator sets it from the crew's own ledger, and a plan that sells more asks than the crew can do for it is a promise broken.", | |
| 428 | }, | |
| 420 | 429 | "billing.grace_days": { |
| 421 | 430 | label: "Days a forge keeps working after its payment fails", |
| 422 | 431 | unit: "days", |
src/tui/screens/getforge.ts +2 −2
| @@ -22,9 +22,9 @@ import { Scroll } from "./common.ts"; | ||
| 22 | 22 | /** The screen as text lines, read fresh on every draw. */ |
| 23 | 23 | export function getForgeLines(app: App, width = 80): string[] { |
| 24 | 24 | const w = Math.max(20, width); |
| 25 | const { plans, links, startUsd } = getDoorSettings(app.db); | |
| 25 | const { plans, links, startUsd, askUsd } = getDoorSettings(app.db); | |
| 26 | 26 | const origin = (app.config.url ?? "").replace(/\/$/, ""); |
| 27 | const words = publicPlans(plans).map((p) => planWords(p, links, startUsd)); | |
| 27 | const words = publicPlans(plans).map((p) => planWords(p, links, startUsd, askUsd)); | |
| 28 | 28 | return [ |
| 29 | 29 | "Get your own forge", |
| 30 | 30 | ...wrap("Hosted for you, or free and open source on a machine you keep.", w), |
src/web/pages/new-forge.ts +4 −3
| @@ -209,8 +209,8 @@ function freshError(errors: Errors, repoCount: number): string | undefined { | ||
| 209 | 209 | * The line under the heading: the crew starts on the included credit when there is one, else on the |
| 210 | 210 | * person's AI account. |
| 211 | 211 | */ |
| 212 | function hostingTerms(includedUsd: number): string { | |
| 213 | return `Free within limits: it sleeps when idle. ${creditWords({ priceUsd: 0, creditUsd: 0 }, includedUsd)}`; | |
| 212 | function hostingTerms(includedUsd: number, askUsd: number): string { | |
| 213 | return `Free within limits: it sleeps when idle. ${creditWords({ priceUsd: 0, creditUsd: 0 }, includedUsd, askUsd)}`; | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | function formView( |
| @@ -235,6 +235,7 @@ function formView( | ||
| 235 | 235 | </div>`; |
| 236 | 236 | const anon = user === undefined; |
| 237 | 237 | const includedUsd = limitValue(ctx.app.db, "spawn.included_credit_usd"); |
| 238 | const askUsd = limitValue(ctx.app.db, "billing.ask_cents") / 100; | |
| 238 | 239 | const freshErr = freshError(errors, repos.length); |
| 239 | 240 | const lead = repos.length === 0 ? "Pick a name, and say what it is for if you like" : "Pick a name and the apps to start from"; |
| 240 | 241 | return html`<div class="narrow-wide" data-forges> |
| @@ -439,7 +440,7 @@ function formView( | ||
| 439 | 440 | </div> |
| 440 | 441 | </form> |
| 441 | 442 | </section> |
| 442 | <p class="muted small" id="hosting-terms">${hostingTerms(includedUsd)}</p> | |
| 443 | <p class="muted small" id="hosting-terms">${hostingTerms(includedUsd, askUsd)}</p> | |
| 443 | 444 | <p class="muted small"><a href="/terms">Terms of a paid forge</a></p> |
| 444 | 445 | </div>`; |
| 445 | 446 | } |
src/web/pages/pricing.ts +3 −3
| @@ -55,11 +55,11 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 55 | 55 | const plans = door.plans; |
| 56 | 56 | const rule = lapseRule(ctx.app.db); |
| 57 | 57 | const links = selling ? {} : door.links; |
| 58 | const buyable = selling || plans.some((p) => planWords(p, links).buy !== undefined); | |
| 58 | const buyable = selling || plans.some((p) => planWords(p, links, 0, door.askUsd).buy !== undefined); | |
| 59 | 59 | const rows = plans.map((p: Plan) => { |
| 60 | 60 | const free = p.key === FREE; |
| 61 | 61 | const paid = !free && selling; |
| 62 | const words = planWords(p, links); | |
| 62 | const words = planWords(p, links, 0, door.askUsd); | |
| 63 | 63 | const buy = words.buy; |
| 64 | 64 | const price = free |
| 65 | 65 | ? html`<span data-price>${words.price}</span>` |
| @@ -70,7 +70,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 70 | 70 | : html`<span data-price>${words.price}</span> <span class="muted">ask the operator · for organizations, <a href="https://www.espodev.com">EspoDev</a></span>`; |
| 71 | 71 | const act = free ? btn(START_BUTTON, { formaction: "/forges/start" }) : paid ? btn(`Get ${p.name}`, { name: "plan", value: p.key, variant: "primary" }) : null; |
| 72 | 72 | const count = ` Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}.`; |
| 73 | return planOfferRow({ key: p.key, name: p.name, says: `${planWords(p, links, door.startUsd).is}${count}`, price, action: act }); | |
| 73 | return planOfferRow({ key: p.key, name: p.name, says: `${planWords(p, links, door.startUsd, door.askUsd).is}${count}`, price, action: act }); | |
| 74 | 74 | }); |
| 75 | 75 | return html`<div class="narrow-wide" id="pricing" data-pricing> |
| 76 | 76 | ${pageHead("Get your own forge", { sub: !selling ? "Pick a size and name it." : ctx.auth.user === undefined ? `${priceLine(plans)}.` : "Pick a plan, name it, pay." })} |
src/web/plan_row.ts +3 −1
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | import { noticeOf, type PlanNotice } from "../billing/notice.ts"; |
| 13 | 13 | import { fundingOf } from "../spawn/funding.ts"; |
| 14 | 14 | import { uncountedWords } from "../actions/crew_means.ts"; |
| 15 | import { creditWords } from "../billing/plan_words.ts"; | |
| 15 | 16 | import { usdWords } from "../spawn/credit.ts"; |
| 16 | 17 | import { sizeWords } from "../settings/billing.ts"; |
| 17 | 18 | import { isSize } from "../spawn/sizes.ts"; |
| @@ -43,7 +44,8 @@ export function planLine(dataDir: string): string | undefined { | ||
| 43 | 44 | // when the host lent no cap. |
| 44 | 45 | const cap = f?.capUsd ?? n.creditUsd; |
| 45 | 46 | const credit = cap > 0 && f?.spentUsd != null ? ` ${usdWords(f.spentUsd)} of ${usdWords(cap)} crew credit used this month.${uncountedWords(f.uncountedUsd ?? 0)}` : ""; |
| 46 | return `${n.name}${size}. ${statusWords(n)}.${credit}`; | |
| 47 | const buys = n.priceUsd > 0 && n.creditUsd > 0 ? ` ${creditWords(n, 0, n.askUsd)}` : ""; | |
| 48 | return `${n.name}${size}. ${statusWords(n)}.${credit}${buys}`; | |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | 51 | /** |
src/web/plans_row.ts +2 −2
| @@ -10,8 +10,8 @@ import type { BillingLinks } from "../settings/billing.ts"; | ||
| 10 | 10 | import type { Plan } from "../settings/plans.ts"; |
| 11 | 11 | import { html, type Html } from "./html.ts"; |
| 12 | 12 | |
| 13 | export function plansRow(plans: readonly Plan[], links: BillingLinks = {}, startUsd = 0): Html { | |
| 14 | const words = plans.map((p) => planWords(p, links, startUsd)); | |
| 13 | export function plansRow(plans: readonly Plan[], links: BillingLinks = {}, startUsd = 0, askUsd?: number): Html { | |
| 14 | const words = plans.map((p) => planWords(p, links, startUsd, askUsd)); | |
| 15 | 15 | const list = html`<ul class="door-plans">${words.map((w) => { |
| 16 | 16 | const action = |
| 17 | 17 | w.buy !== undefined |
src/web/studio/home.ts +3 −3
| @@ -731,7 +731,7 @@ export function studioDoor(ctx: Ctx): Response { | ||
| 731 | 731 | const featured = front.featured; |
| 732 | 732 | const all = [...(featured === undefined ? [] : [featured]), ...front.shelf]; |
| 733 | 733 | const made = all.slice(0, Math.max(DOOR_TILES, all.filter((e) => e.pinned).length)); |
| 734 | const { mode, plans: allPlans, links, startUsd } = getDoorSettings(ctx.app.db); | |
| 734 | const { mode, plans: allPlans, links, startUsd, askUsd } = getDoorSettings(ctx.app.db); | |
| 735 | 735 | const accounts = !accountsClosedIn(ctx.app.db, mode); |
| 736 | 736 | const drawTiles = (): Html[] => |
| 737 | 737 | timePhase(ctx.request, "tiles", () => made.map((e, at) => tile(e, at, accounts, e === featured ? html`role="region" aria-label="Featured"` : undefined))); |
| @@ -756,7 +756,7 @@ export function studioDoor(ctx: Ctx): Response { | ||
| 756 | 756 | // holds it gets a 304 and no render. The ages in "Just finished" are inputs, as is the page's own |
| 757 | 757 | // script (the tag is of the whole document); `/front` is an admin's and never tagged. |
| 758 | 758 | const script = `${liveClientJs}\n${liveRegionsJs}\n${funnelJs}\n${startNameJs}`; |
| 759 | const tag = visitor && ctx.url.pathname === "/" ? pageTag(ctx, [front, front.pulse.changes.map((c) => timeAgo(c.mergedAt)), mode, allPlans, links, startUsd, accounts, refusal ?? null, keptName, startWaitIn(ctx.url.searchParams) ?? null, origin, signup, catalog().packs, running().version], script) : undefined; | |
| 759 | const tag = visitor && ctx.url.pathname === "/" ? pageTag(ctx, [front, front.pulse.changes.map((c) => timeAgo(c.mergedAt)), mode, allPlans, links, startUsd, askUsd, accounts, refusal ?? null, keptName, startWaitIn(ctx.url.searchParams) ?? null, origin, signup, catalog().packs, running().version], script) : undefined; | |
| 760 | 760 | const held = heldCopy(ctx, tag, script); |
| 761 | 761 | if (held !== undefined) { |
| 762 | 762 | notePhaseRest(ctx.request, "render", rendering, []); |
| @@ -870,7 +870,7 @@ export function studioDoor(ctx: Ctx): Response { | ||
| 870 | 870 | <p class="door-support"> |
| 871 | 871 | Hosted for you, or free and open source on a machine you keep. |
| 872 | 872 | </p> |
| 873 | ${plansRow(publicPlans(allPlans), links, startUsd)} | |
| 873 | ${plansRow(publicPlans(allPlans), links, startUsd, askUsd)} | |
| 874 | 874 | <div class="bar" data-plan="${freePlanName(allPlans)}">${btn("Get a forge", { href: visitor ? "#start-forge" : GET_A_FORGE_PATH, variant: "primary", size: "lg" })}</div> |
| 875 | 875 | <p class="door-support">Or run it yourself, free and open source: <a href="${FORGE_REPO}">read the step-by-step guide</a>.</p> |
| 876 | 876 | <pre class="door-code"><code>${selfHostCommands(FORGE_REPO).join("\n")}</code></pre> |
test/new-forge-language.test.ts +1 −1
| @@ -56,7 +56,7 @@ test("the hosting line says the crew starts on the included credit only when the | ||
| 56 | 56 | const id = app.db.query<{ id: string }, []>("SELECT id FROM user LIMIT 1").get()!.id; |
| 57 | 57 | setLimit(app.db, "spawn.included_credit_usd", 3, id); |
| 58 | 58 | expect(await say()).toBe( |
| 59 | "Free within limits: it sleeps when idle. $3 of crew credit once, to start. Then your own AI account key.", | |
| 59 | "Free within limits: it sleeps when idle. Crew credit for 6 ordinary asks, once, to start. Then your own AI account key.", | |
| 60 | 60 | ); |
| 61 | 61 | setLimit(app.db, "spawn.included_credit_usd", 0, id); |
| 62 | 62 | expect(await say()).toBe( |
test/plans-row.test.ts +6 −6
| @@ -30,7 +30,7 @@ test("every plan shows its price from the plans setting, the free plan Free; no | ||
| 30 | 30 | expect(row).toContain(p.name); |
| 31 | 31 | expect(row).toContain(sizeWords(p.size)); |
| 32 | 32 | } |
| 33 | for (const t of ["$19 a month", "$49 a month", "$149 a month", "$5 of crew credit each month"]) expect(row).toContain(t); | |
| 33 | for (const t of ["$19 a month", "$49 a month", "$149 a month", "Crew credit for 10 ordinary asks each month"]) expect(row).toContain(t); | |
| 34 | 34 | expect(row).not.toContain("Paid"); |
| 35 | 35 | expect(planWords(FREE).price).toBe("Free"); |
| 36 | 36 | expect(planWords(SMALL).price).toBe("$19 a month"); |
| @@ -113,7 +113,7 @@ test("getDoorSettings: the start credit is the spawn.included_credit_usd limit, | ||
| 113 | 113 | |
| 114 | 114 | test("getDoorSettings: nothing stored, or a stored value that does not parse, reads as the defaults", () => { |
| 115 | 115 | const empty = getDoorSettings(app.db); |
| 116 | expect(empty).toEqual({ mode: SIGNUP_DEFAULT, plans: DEFAULT_PLANS.map((p) => ({ ...p })), links: {}, startUsd: 2 }); | |
| 116 | expect(empty).toEqual({ mode: SIGNUP_DEFAULT, plans: DEFAULT_PLANS.map((p) => ({ ...p })), links: {}, startUsd: 2, askUsd: 0.5 }); | |
| 117 | 117 | put("signup", "sometimes"); |
| 118 | 118 | put("plans", "{not json"); |
| 119 | 119 | put("billing.links", "[1]"); |
| @@ -135,8 +135,8 @@ test("a guest in the terminal is offered Get your own forge", () => { | ||
| 135 | 135 | }); |
| 136 | 136 | |
| 137 | 137 | test("a paid plan keeps its own sentence and adds its monthly credit; the free plan says its start credit, once", () => { |
| 138 | expect(planWords(SMALL).is).toBe(`${sizeWords(SMALL.size)}. ${SMALL.says} $${SMALL.creditUsd} of crew credit each month.`); | |
| 139 | expect(planWords(FREE, {}, 2).is).toBe(`${sizeWords(FREE.size)}. ${FREE.says} $2 of crew credit once, to start. Then your own AI account key.`); | |
| 138 | expect(planWords(SMALL).is).toBe(`${sizeWords(SMALL.size)}. ${SMALL.says} Crew credit for 10 ordinary asks each month.`); | |
| 139 | expect(planWords(FREE, {}, 2).is).toBe(`${sizeWords(FREE.size)}. ${FREE.says} Crew credit for 4 ordinary asks, once, to start. Then your own AI account key.`); | |
| 140 | 140 | expect(planWords(FREE, {}, 0).is).toBe(`${sizeWords(FREE.size)}. ${FREE.says} No crew credit: the crew runs on your own AI account key.`); |
| 141 | 141 | }); |
| 142 | 142 | |
| @@ -160,7 +160,7 @@ test("with buy links set the plans show price, credit, Get anchors and the after | ||
| 160 | 160 | put("signup", "closed"); |
| 161 | 161 | put("billing.links", JSON.stringify({ small: "https://buy.example/s", medium: "https://buy.example/m", large: "https://buy.example/l" })); |
| 162 | 162 | const section = await yours(); |
| 163 | for (const t of ["$19 a month", "$49 a month", "$149 a month", "$5 of crew credit each month", "$15 of crew credit each month", "$50 of crew credit each month", "Your forge is created"]) | |
| 163 | for (const t of ["$19 a month", "$49 a month", "$149 a month", "Crew credit for 10 ordinary asks each month", "Crew credit for 30 ordinary asks each month", "Crew credit for 100 ordinary asks each month", "Your forge is created"]) | |
| 164 | 164 | expect(section).toContain(t); |
| 165 | 165 | for (const n of ["Small", "Medium", "Large"]) expect(section).toContain(`>Get ${n}</a>`); |
| 166 | 166 | expect(section).not.toContain("Get Free"); |
| @@ -175,7 +175,7 @@ test("changing a price in the plans setting changes the page", async () => { | ||
| 175 | 175 | put("plans", JSON.stringify(DEFAULT_PLANS.map((p) => (p.key === "small" ? { ...p, priceUsd: 23, creditUsd: 7 } : p)))); |
| 176 | 176 | const section = await yours(); |
| 177 | 177 | expect(section).toContain("$23 a month"); |
| 178 | expect(section).toContain("$7 of crew credit each month"); | |
| 178 | expect(section).toContain("Crew credit for 14 ordinary asks each month"); | |
| 179 | 179 | expect(section).not.toContain("$19 a month"); |
| 180 | 180 | }); |
| 181 | 181 |
test/pricing-plans-agree.test.ts +3 −2
| @@ -7,6 +7,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 7 | 7 | import { serve, type Servers } from "../src/http/server.ts"; |
| 8 | 8 | import { setBillingLinks } from "../src/settings/billing.ts"; |
| 9 | 9 | import { getPlans } from "../src/settings/plans.ts"; |
| 10 | import { asksWords } from "../src/billing/plan_words.ts"; | |
| 10 | 11 | |
| 11 | 12 | let dir: string; |
| 12 | 13 | let app: App; |
| @@ -32,8 +33,8 @@ test("every plan's card shows the price, credit and forge count the API lists", | ||
| 32 | 33 | expect(start).toBeGreaterThan(-1); |
| 33 | 34 | const card = text.slice(start, text.indexOf("</div>", start)); |
| 34 | 35 | expect(card).toContain(p.priceUsd === 0 ? ">Free<" : `$${p.priceUsd} a month`); |
| 35 | if (p.priceUsd === 0) expect(card).toContain(`$${api.startCreditUsd} of crew credit once, to start`); | |
| 36 | else if (p.creditUsd > 0) expect(card).toContain(`$${p.creditUsd} of crew credit each month`); | |
| 36 | if (p.priceUsd === 0) expect(card).toContain(`Crew credit for ${asksWords(api.startCreditUsd)}, once, to start`); | |
| 37 | else if (p.creditUsd > 0) expect(card).toContain(`Crew credit for ${asksWords(p.creditUsd)} each month`); | |
| 37 | 38 | else expect(card).toContain("No crew credit included"); |
| 38 | 39 | expect(card).toContain(`Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}`); |
| 39 | 40 | if (p.priceUsd > 0) { |
test/pricing-words.test.ts added +62
| @@ -0,0 +1,62 @@ | ||
| 1 | /** | |
| 2 | * A plan's credit is said as a count of ordinary asks, the same words on /pricing and the owner's | |
| 3 | * plan row. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, writeFile } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { ASK_USD, asksWords, creditWords } from "../src/billing/plan_words.ts"; | |
| 12 | import { getForgeLines } from "../src/tui/screens/getforge.ts"; | |
| 13 | import { setLimit } from "../src/settings/limits.ts"; | |
| 14 | import { planLine } from "../src/web/plan_row.ts"; | |
| 15 | ||
| 16 | let dir: string; | |
| 17 | let app: App; | |
| 18 | let servers: Servers; | |
| 19 | beforeAll(async () => { | |
| 20 | dir = await mkdtemp(join(tmpdir(), "forge-pricing-words-")); | |
| 21 | app = createApp({ dataDir: dir, port: 0 }); | |
| 22 | servers = await serve(app); | |
| 23 | }); | |
| 24 | afterAll(() => { | |
| 25 | servers.stop(); | |
| 26 | app.close(); | |
| 27 | }); | |
| 28 | ||
| 29 | test("a credit is a count of asks, rounded down, singular at one", () => { | |
| 30 | expect(asksWords(5)).toBe("10 ordinary asks"); | |
| 31 | expect(asksWords(ASK_USD)).toBe("1 ordinary ask"); | |
| 32 | expect(asksWords(0.7)).toBe("1 ordinary ask"); | |
| 33 | expect(asksWords(0.1)).toBe("0 ordinary asks"); | |
| 34 | }); | |
| 35 | ||
| 36 | test("/pricing says the credit in asks, no raw dollars of credit", async () => { | |
| 37 | const text = await (await fetch(`${servers.url}/pricing`)).text(); | |
| 38 | expect(text).toContain("Crew credit for 10 ordinary asks each month."); | |
| 39 | expect(text).toContain("Crew credit for 4 ordinary asks, once, to start."); | |
| 40 | expect(text).not.toMatch(/\$\d+ of crew credit/); | |
| 41 | }); | |
| 42 | ||
| 43 | test("the owner's plan row says the same sentence /pricing says", async () => { | |
| 44 | await writeFile(join(dir, "plan.json"), JSON.stringify({ name: "Small", size: "small", priceUsd: 19, creditUsd: 5, status: "active" })); | |
| 45 | const line = planLine(dir) ?? ""; | |
| 46 | expect(line).toContain(creditWords({ priceUsd: 19, creditUsd: 5 }, 0)); | |
| 47 | }); | |
| 48 | ||
| 49 | test("a credit under one ask says no crew credit, not 0 asks", () => { | |
| 50 | expect(creditWords({ priceUsd: 19, creditUsd: 0.4 }, 0)).toBe("No crew credit included."); | |
| 51 | expect(creditWords({ priceUsd: 0, creditUsd: 0 }, 0.4)).toBe("No crew credit: the crew runs on your own AI account key."); | |
| 52 | }); | |
| 53 | ||
| 54 | test("an ask costs what billing.ask_usd says: /pricing, the terminal and the plan row follow it", async () => { | |
| 55 | const set = setLimit(app.db, "billing.ask_cents", 100, "test"); | |
| 56 | expect(set.ok).toBe(true); | |
| 57 | const text = await (await fetch(`${servers.url}/pricing`)).text(); | |
Non-blocking: the title says billing.ask_usd but the limit is now billing.ask_cents. |
||
| 58 | expect(text).toContain("Crew credit for 5 ordinary asks each month."); | |
| 59 | expect(getForgeLines(app, 200).join("\n")).toContain("Crew credit for 5 ordinary asks each month."); | |
| 60 | await writeFile(join(dir, "plan.json"), JSON.stringify({ name: "Small", size: "small", priceUsd: 19, creditUsd: 5, askUsd: 1, status: "active" })); | |
| 61 | expect(planLine(dir)).toContain("Crew credit for 5 ordinary asks each month."); | |
| 62 | }); |
new above
offline
ASK_USD = 0.5 is unmeasured. Source it from something real (a limit or measured median) and say where it comes from, or the page promises a guess.