diff --git a/app/main.py b/app/main.py index 05b5e28..c3bb35e 100644 --- a/app/main.py +++ b/app/main.py @@ -8,8 +8,12 @@ Security model: every request to the logged-in member. Environment (all provided by Cloudron env vars): - PORTAL_BASE — base URL of the member portal (e.g. https://portal.inference.coop) - BROKER_SECRET — shared secret for the portal's broker endpoints + PORTAL_BASE — base URL of the member portal (e.g. https://portal.inference.coop) + BROKER_SECRET — shared secret for the portal's broker endpoints + CREDIT_PACK_URL — where the "Buy a credit pack" link sends members (defaults to + the Open Collective contribute page, which is what actually + credits a member). Configuration, not code, because the + destination can move (a future pack page) without a deploy here. """ import os @@ -28,6 +32,14 @@ logger = logging.getLogger("member-dashboard") PORTAL_BASE = os.environ.get("PORTAL_BASE", "").rstrip("/") BROKER_SECRET = os.environ.get("BROKER_SECRET", "") +# Where the always-visible "Buy a credit pack" link points. Configuration, not a +# constant in the template: the co-op sets this per app (same convention the +# portal uses) so the destination changes in one place. The Open Collective +# contribution page is the default because that is what actually credits a +# member today (the webhook settles contributions into credits). +DEFAULT_CREDIT_PACK_URL = "https://opencollective.com/inference-cooperative/contribute" +CREDIT_PACK_URL = (os.environ.get("CREDIT_PACK_URL") or "").strip() or DEFAULT_CREDIT_PACK_URL + app = FastAPI() @@ -296,7 +308,10 @@ def _esc(s: str) -> str: def render_page(identity: str) -> str: - return PAGE_HTML.replace("@@IDENTITY@@", _esc(identity)) + return ( + PAGE_HTML.replace("@@IDENTITY@@", _esc(identity)) + .replace("@@CREDIT_PACK_URL@@", _esc(CREDIT_PACK_URL)) + ) PAGE_HTML = """ @@ -357,6 +372,20 @@ PAGE_HTML = """ .bar .fill { height: 100%; background: var(--green-mid); border-radius: 6px; transition: width .3s ease; } .bar .fill.warn { background: #d99a3e; } .meta { color: var(--muted); font-size: 13px; margin-top: 8px; } + /* Always-visible buy path: members could not find a way to add usage. + A green button (same green + radius as the other buttons) out to the + configured pack page, plus the member's real credit status and a link + to the docs section that explains allowance vs. credits. */ + .buy-row { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; } + a.buy-btn { + display: inline-block; background: var(--green-deep); color: #fff; + border-radius: 8px; font-size: 14px; font-weight: 600; + padding: 8px 16px; text-decoration: none; transition: background .15s ease; + } + a.buy-btn:hover { background: #4e7a4d; } + .buy-hint { color: var(--muted); font-size: 12px; } + a.buy-docs { color: var(--green-deep); font-weight: 600; text-decoration: none; white-space: nowrap; } + a.buy-docs:hover { text-decoration: underline; } .models { margin-top: 16px; } .model-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; @@ -557,6 +586,12 @@ PAGE_HTML = """
Shared across chat and API.
+
+ Buy a credit pack + Credit packs never expire · used after your monthly allowance + More about allowance & credits → + +
@@ -685,9 +720,14 @@ async function load() { if (d.reset_at) { const d2 = new Date(d.reset_at); const opts = { year: 'numeric', month: 'long', day: 'numeric' }; - let meta = 'Shared across chat and API · Allowance renews ' + d2.toLocaleDateString(undefined, opts); - if (creditsTotal > 0) meta += ' · Credits never expire (' + fmtMoney(creditsTotal) + ' purchased all-time)'; - $('meta').textContent = meta + '.'; + $('meta').textContent = 'Shared across chat and API · Allowance renews ' + d2.toLocaleDateString(undefined, opts) + '.'; + } + + // Credit status lives next to the buy button, not in the meta line: with a + // pack bought it reads the real all-time figure, otherwise it stays the + // static "credit packs never expire" line already in the markup. + if (creditsTotal > 0) { + $('buy-credits').textContent = 'Credits never expire (' + fmtMoney(creditsTotal) + ' purchased all-time)'; } const calls = (d.models || []).reduce((s, m) => s + (m.calls || 0), 0);